-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure
entity
declaration is not used in the Wasp file (#2152)
- Loading branch information
Showing
8 changed files
with
136 additions
and
8 deletions.
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
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