-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
fix: support for Prisma 5.16.0 #1541
Conversation
WalkthroughWalkthroughThe changes primarily focus on integrating support for Prisma version 5.16.0 and dynamically handling Prisma client initialization options. This includes modifying the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Script[test-scaffold.ts]
participant Enhance[enhance/index.ts]
participant Schema[schema.ts]
participant PrismaClient[@prisma/client]
User->>Script: Run tests with updated Prisma versions
Script->>PrismaClient: Install Prisma 5.16.x
Note over Script,PrismaClient: Updated dependencies
User->>Enhance: Call `enhance` function
Note right of Enhance: Checks Prisma version
Enhance-->>User: Returns enhanced object
Note over User,Enhance: Conditional ClientOptions
User->>Schema: Call `loadSchema` with options
Schema->>PrismaClient: Initialize with `prismaClientOptions`
PrismaClient->>Schema: Return Prisma Client instance
Schema-->>User: Returns loaded schema
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
Line range hint
511-511
: Optimization suggestion: ReplaceflatMap
withflat
.The static analysis tool identified an unnecessary use of
flatMap
whereflat
would be sufficient. This change will simplify the code and potentially improve performance.- .flatMap(...) + .flat()
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (7)
packages/runtime/package.json
is excluded by!**/*.json
packages/schema/package.json
is excluded by!**/*.json
packages/sdk/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
,!**/*.yaml
tests/integration/test-run/package.json
is excluded by!**/*.json
tests/integration/tests/frameworks/nextjs/test-project/package.json
is excluded by!**/*.json
tests/integration/tests/frameworks/trpc/test-project/package.json
is excluded by!**/*.json
Files selected for processing (4)
- packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
- script/test-scaffold.ts (1 hunks)
- tests/integration/tests/cli/plugins.test.ts (2 hunks)
- tests/regression/tests/issue-925.test.ts (1 hunks)
Files skipped from review due to trivial changes (2)
- script/test-scaffold.ts
- tests/integration/tests/cli/plugins.test.ts
Additional context used
Biome
packages/schema/src/plugins/enhancer/enhance/index.ts
[error] 511-511: Avoid unnecessary callback in flatMap call.
You can just use flat to flatten the array.
Safe fix: Replace unnecessary flatMap call to flat instead.(lint/correctness/noFlatMapIdentity)
Additional comments not posted (2)
tests/regression/tests/issue-925.test.ts (1)
38-38
: Test case re-enabled: "reference with this".The test case has been re-enabled to verify behavior with the usage of
this
in model references. Ensure that this test passes with the new Prisma version and that it accurately reflects the intended behavior.packages/schema/src/plugins/enhancer/enhance/index.ts (1)
Line range hint
162-182
: Updated function signature inenhance
to support Prisma 5.16.0.The function now conditionally includes a
ClientOptions
type parameter based on the Prisma version. This change is crucial for supporting new features in Prisma 5.16.0. Ensure that the version check usingsemver.gte
is robust and correctly identifies versions >= 5.16.0.Verification successful
Updated function signature in
enhance
to support Prisma 5.16.0The function now conditionally includes a
ClientOptions
type parameter based on the Prisma version. This change is crucial for supporting new features in Prisma 5.16.0. Ensure that the version check usingsemver.gte
is robust and correctly identifies versions >= 5.16.0.
- The
hasClientOptions
boolean is correctly implemented to check for Prisma version >= 5.16.0.- The function signatures correctly include or exclude the
ClientOptions
parameter based on this boolean.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter. # Test: Check for correct conditional inclusion of `ClientOptions` in different Prisma versions. ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs${ $$$}>(prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs$$$>, context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs$$$>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.tsLength of output: 946
Script:
#!/bin/bash # Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter. # Test: Check for the function signature without `ClientOptions`. ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs>( prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs>, context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.ts # Test: Check for the function signature with `ClientOptions`. ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs, ClientOptions>( prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs, ClientOptions>, context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs, ClientOptions>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.tsLength of output: 1931
Script:
#!/bin/bash # Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter. # Test: Check for the function signature without `ClientOptions`. ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs>( prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs>, context?: EnhancementContext<any>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs>;' packages/schema/src/plugins/enhancer/enhance/index.ts # Test: Check for the function signature with `ClientOptions`. ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs, ClientOptions>( prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs, ClientOptions>, context?: EnhancementContext<any>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs, ClientOptions>;' packages/schema/src/plugins/enhancer/enhance/index.tsLength of output: 928
Script:
#!/bin/bash # Description: Output the content of the index.ts file to manually verify the function signatures. cat packages/schema/src/plugins/enhancer/enhance/index.tsLength of output: 25323
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.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
packages/testtools/src/schema.ts (1)
Line range hint
72-74
: Remove unnecessary else clause as indicated by static analysis.The static analysis tool has flagged an unnecessary else clause. This can be simplified to enhance code readability and maintainability.
- else { - // code block - }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/testtools/src/schema.ts (2 hunks)
- tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2 hunks)
Additional context used
Biome
packages/testtools/src/schema.ts
[error] 72-74: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
Additional comments not posted (4)
tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2)
58-122
: Ensure global settings foromit
are correctly applied and tested.This test case is crucial as it tests the global application of the
omit
settings. Verify that the settings are correctly applied to the Prisma client and that the test assertions accurately reflect these settings. This includes checking that omitted fields do not appear in the results and that non-omitted fields are handled correctly.Verification successful
Verified: Global settings for
omit
are correctly applied and tested.The
prismaClientOptions
are correctly merged with the default options and used to instantiate thePrismaClient
. The test case accurately reflects these settings, ensuring that omitted fields do not appear in the results and non-omitted fields are handled correctly.
packages/testtools/src/schema.ts
: Correct application ofprismaClientOptions
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the global settings for `omit` in Prisma client. # Test: Search for global settings application. Expect: Correct application in client configurations. rg --type python $'prismaClientOptions'Length of output: 69
Script:
#!/bin/bash # Description: Verify the global settings for `omit` in Prisma client. # Test: Search for global settings application. Expect: Correct application in client configurations. rg --type js,ts 'prismaClientOptions'Length of output: 67
Script:
#!/bin/bash # Description: Verify the global settings for `omit` in Prisma client. # Test: Search for global settings application. Expect: Correct application in client configurations. rg --type-add 'js:*.{js,jsx}' --type-add 'ts:*.{ts,tsx}' --type js --type ts 'prismaClientOptions'Length of output: 457
Script:
#!/bin/bash # Description: Verify the implementation of `prismaClientOptions` in the client configuration. # Fetch lines around the usage of `prismaClientOptions` in `schema.ts` to ensure correct application. rg --type ts --context 5 'prismaClientOptions' packages/testtools/src/schema.tsLength of output: 871
Line range hint
4-57
: Check for potential issues with dynamic schema loading and test logic.The test case dynamically loads a schema and performs operations using Prisma. Ensure that all operations and expectations are correctly implemented and align with the intended use cases of the
omit
feature. Additionally, confirm that the schema provided matches the expected format and fields for the Prisma models being used.packages/testtools/src/schema.ts (2)
137-137
: Approve addition ofprismaClientOptions
inSchemaLoadOptions
.The addition of
prismaClientOptions
toSchemaLoadOptions
is aligned with the PR objectives to enhance schema loading capabilities. This change allows for dynamic configuration of Prisma client options, which is essential for supporting different versions and features of Prisma.
259-263
: Validate dynamic assignment of Prisma client options.The logic for dynamically assigning Prisma client options based on provided settings appears correct. However, ensure that this functionality is covered by tests to prevent regressions or unexpected behaviors in future updates.
Verification successful
Test coverage for dynamic assignment of Prisma client options is adequate.
The test file
tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts
includes tests that cover the dynamic assignment ofprismaClientOptions
. This ensures that the functionality is being tested and helps prevent regressions or unexpected behaviors in future updates.
- File:
tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify dynamic assignment of Prisma client options. # Test: Search for test coverage of dynamic assignment. Expect: Adequate test coverage. rg --type python $'prismaClientOptions'Length of output: 69
Script:
#!/bin/bash # Description: Verify dynamic assignment of Prisma client options in TypeScript test files. # Test: Search for test coverage of dynamic assignment. Expect: Adequate test coverage. rg --type ts 'prismaClientOptions'Length of output: 393
Script:
#!/bin/bash # Display the content of the test file that references `prismaClientOptions` to verify test coverage. cat tests/integration/tests/enhancements/with-policy/prisma-omit.test.tsLength of output: 3642
Fixes #1536