-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure entity
declaration is not used in the Wasp file
#2152
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ddb265d
Adds AST validation
infomiho 0abfd21
Cleanup
infomiho 0d18813
Merge branch 'main' into miho-no-entities-in-wasp-file
infomiho 96523f9
Explain why we validate the AST
infomiho f1869e7
Don't hardcode the entity declaration type
infomiho 1886f6a
Update comment
infomiho afd108f
Formatting
infomiho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Wasp.Analyzer.Parser.Valid | ||
( validateAst, | ||
) | ||
where | ||
|
||
import Data.List (find) | ||
import qualified Wasp.Analyzer.Parser as P | ||
import Wasp.Analyzer.StdTypeDefinitions.Entity (entityDeclTypeName) | ||
|
||
validateAst :: P.AST -> Either (String, P.Ctx) P.AST | ||
validateAst = validateNoEntityDeclInWaspFile | ||
|
||
validateNoEntityDeclInWaspFile :: P.AST -> Either (String, P.Ctx) P.AST | ||
validateNoEntityDeclInWaspFile ast@(P.AST stmts) = case findEntityStmt stmts of | ||
Just (P.WithCtx ctx _) -> Left (entitiesNoLongerSupportedError, ctx) | ||
Nothing -> Right ast | ||
where | ||
findEntityStmt :: [P.WithCtx P.Stmt] -> Maybe (P.WithCtx P.Stmt) | ||
findEntityStmt = | ||
find | ||
( \(P.WithCtx _ (P.Decl declTypeName _ _)) -> declTypeName == entityDeclTypeName | ||
) | ||
|
||
entitiesNoLongerSupportedError :: String | ||
entitiesNoLongerSupportedError = | ||
"Entities can no longer be defined in the .wasp file. You should migrate your entities to the schema.prisma file. Read more: https://wasp-lang.dev/docs/migrate-from-0-13-to-0-14#migrate-to-the-new-schemaprisma-file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,15 +27,15 @@ data TypeError' | |
-- We use "unify" in the TypeChecker when trying to infer the common type for | ||
-- typed expressions that we know should be of the same type (e.g. for | ||
-- elements in the list). | ||
= UnificationError TypeCoercionError | ||
= UnificationError TypeCoercionError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting |
||
-- | Type coercion error that occurs when trying to use the typed expression | ||
-- of type T1 where T2 is expected. If T2 is a super type of T1 and T1 can be | ||
-- safely coerced to T2, no problem, but if not, we get this error. | ||
| CoercionError TypeCoercionError | ||
| NoDeclarationType TypeName | ||
| UndefinedIdentifier Identifier | ||
| QuoterUnknownTag QuoterTag | ||
| DictDuplicateField DictFieldName | ||
| CoercionError TypeCoercionError | ||
| NoDeclarationType TypeName | ||
| UndefinedIdentifier Identifier | ||
| QuoterUnknownTag QuoterTag | ||
| DictDuplicateField DictFieldName | ||
deriving (Eq, Show) | ||
{- ORMOLU_ENABLE -} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
module Analyzer.ValidTest where | ||
|
||
import Data.Either (fromRight, isRight) | ||
import Test.Tasty.Hspec | ||
import Wasp.Analyzer.Parser hiding (withCtx) | ||
import qualified Wasp.Analyzer.Parser as P | ||
import Wasp.Analyzer.Parser.Valid (validateAst) | ||
import qualified Wasp.Version as WV | ||
|
||
spec_ValidateAst :: Spec | ||
spec_ValidateAst = do | ||
it "Returns an error when entities are used" $ do | ||
validateAndParseSource (waspSourceLines ++ entityDeclarationLines) | ||
`shouldBe` Left | ||
( "Entities can no longer be defined in the .wasp file. You should migrate your entities to the schema.prisma file. Read more: https://wasp-lang.dev/docs/migrate-from-0-13-to-0-14#migrate-to-the-new-schemaprisma-file", | ||
P.Ctx | ||
( P.SourceRegion | ||
(P.SourcePosition 34 1) | ||
(P.SourcePosition 37 5) | ||
) | ||
) | ||
|
||
it "Returns AST when everything is correct" $ do | ||
isRight (validateAndParseSource waspSourceLines) `shouldBe` True | ||
where | ||
validateAndParseSource = validateAst . parseSource | ||
|
||
parseSource = fromRight (error "Parsing went wrong") . parseStatements . unlines | ||
|
||
waspSourceLines = | ||
[ "app Todo {", | ||
" wasp: {", | ||
" version: \"^" ++ show WV.waspVersion ++ "\",", | ||
" },", | ||
" title: \"Todo App\",", | ||
" head: [\"foo\", \"bar\"],", | ||
" auth: {", | ||
" userEntity: User,", | ||
" methods: {", | ||
" usernameAndPassword: {", | ||
" userSignupFields: import { getUserFields } from \"@src/auth/signup.js\",", | ||
" }", | ||
" },", | ||
" onAuthFailedRedirectTo: \"/\",", | ||
" },", | ||
"}", | ||
"", | ||
"page HomePage {", | ||
" component: import Home from \"@src/pages/Main\"", | ||
"}", | ||
"", | ||
"route HomeRoute { path: \"/\", to: HomePage }", | ||
"", | ||
"query getUsers {", | ||
" fn: import { getAllUsers } from \"@src/foo.js\",", | ||
" entities: [User]", | ||
"}", | ||
"", | ||
"action updateUser {", | ||
" fn: import { updateUser } from \"@src/foo.js\",", | ||
" entities: [User],", | ||
" auth: true", | ||
"}" | ||
] | ||
|
||
entityDeclarationLines = | ||
[ "entity User {=psl", | ||
" id Int @id @default(autoincrement())", | ||
" email String @unique", | ||
"psl=}" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine opening up this PR after reviewing and writing TypeScript all day. And the first thing you see is this line here.
Oh well, time to gaslight myself into thinking Haskell is readable again 😄