From ba683d09691b3069e12fff55a7736ae7c8dfe645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Sodi=C4=87?= Date: Wed, 12 Jul 2023 17:51:33 +0200 Subject: [PATCH] Add extendedWhereUnique to Wasp AI --- .../AI/GenerateNewProject/Common/Prompts.hs | 10 +++++++++- .../Wasp/AI/GenerateNewProject/Operation.hs | 18 ------------------ .../AI/GenerateNewProject/OperationsJsFile.hs | 3 --- .../src/Wasp/AI/GenerateNewProject/Skeleton.hs | 5 +++++ waspc/src/Wasp/Psl/Format.hs | 4 ++-- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/waspc/src/Wasp/AI/GenerateNewProject/Common/Prompts.hs b/waspc/src/Wasp/AI/GenerateNewProject/Common/Prompts.hs index 9656da1fa..6b1109fdc 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/Common/Prompts.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/Common/Prompts.hs @@ -72,7 +72,15 @@ waspFileExample = userEntity: User, methods: { usernameAndPassword: {} }, onAuthFailedRedirectTo: "/login" - } + }, + client: { + rootComponent: import { Layout } from "@client/Layout.jsx", + }, + db: { + prisma: { + clientPreviewFeatures: ["extendedWhereUnique"] + } + }, } route SignupRoute { path: "/signup", to: SignupPage } diff --git a/waspc/src/Wasp/AI/GenerateNewProject/Operation.hs b/waspc/src/Wasp/AI/GenerateNewProject/Operation.hs index 7b8083a93..b20bbc0e8 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/Operation.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/Operation.hs @@ -109,24 +109,6 @@ generateOperation operationType newProjectDetails entityPlans operationPlan = do Also, make sure to use full import statement for `fn:`: `import { getTasks } from "@server/actions.js"`, don't provide just the file path. - In NodeJS implementation, you will typically want to check if user is authenticated, by doing `if (!context.user) { throw new HttpError(401) }` at the start of the operation. - - DO NOT specify more than one field in the `where` clause of `update()` and `findUnique()` Prisma methods. - Unlike other Prisma methods, these two can accept only one, unique field in their `where` clause. - WRONG: - ```js - const task = await context.entities.Task.findUnique({ - where: { - id: args.id, - userId: context.user.id - } - }); - ``` - CORRECT: - ```js - const task = await context.entities.Task.findUnique({ - where: { id: args.id } - }); - if (task.userId !== context.user.id) { throw new HttpError(403) }; - ``` ${appDescriptionStartMarkerLine} diff --git a/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs b/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs index 11404f9ad..37f675a47 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs @@ -71,9 +71,6 @@ fixOperationsJsFile newProjectDetails waspFilePath opJsFilePath = do - Duplicate imports. If there are any, make sure to remove them. - js imports of local modules (`from "./`, `from "../`). If there are any, remove them and instead add the needed implementation directly into the file we are fixing right now. - - Providing more than one field in the `where` clause of `update()` and `findUnique()` Prisma methods. - Unlike other Prisma methods, these two can accept only one, unique field in their `where` clause. - If this mistake is present, refactor the code so that it still works as intended but has just one field in the `where` clause. - Redundant imports of prisma client or of prisma entities. Those imports are not needed -> remove them! We are not using PrismaClient directly, we are using it through the context. For example: `context.entities.Task.findMany({})` diff --git a/waspc/src/Wasp/AI/GenerateNewProject/Skeleton.hs b/waspc/src/Wasp/AI/GenerateNewProject/Skeleton.hs index d0cfb7a10..117f071cf 100644 --- a/waspc/src/Wasp/AI/GenerateNewProject/Skeleton.hs +++ b/waspc/src/Wasp/AI/GenerateNewProject/Skeleton.hs @@ -87,6 +87,11 @@ generateBaseWaspFile newProjectDetails = ((path, content), planRules) client: { rootComponent: import { Layout } from "@client/Layout.jsx", }, + db: { + prisma: { + clientPreviewFeatures: ["extendedWhereUnique"] + } + }, ${appAuth} } diff --git a/waspc/src/Wasp/Psl/Format.hs b/waspc/src/Wasp/Psl/Format.hs index 452ffb797..fc662be19 100644 --- a/waspc/src/Wasp/Psl/Format.hs +++ b/waspc/src/Wasp/Psl/Format.hs @@ -14,7 +14,7 @@ import Data.Text (Text) import qualified Data.Text as T import System.Exit (ExitCode (..)) import qualified System.Process as P -import qualified Wasp.Package as WP +import qualified Wasp.NodePackageFFI as WP import Wasp.Util.Aeson (decodeFromString) -- | For given prisma schema source, returns formatted schema + any warnings/errors, @@ -25,7 +25,7 @@ import Wasp.Util.Aeson (decodeFromString) -- It works even for a prisma schema that has only model declarations! prismaFormat :: Text -> IO PrismaFormatResult prismaFormat prismaSchema = do - cp <- WP.getPackageProc WP.PrismaPackage ["format"] + cp <- WP.getPackageProcessOptions WP.PrismaPackage ["format"] (exitCode, response, stderr) <- P.readCreateProcessWithExitCode cp $ T.unpack prismaSchema case exitCode of ExitSuccess ->