-
-
Notifications
You must be signed in to change notification settings - Fork 89
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: compatibility with Prisma's "omit" feature #1432
Conversation
WalkthroughWalkthroughThe recent updates across various packages primarily introduce the Changes
This table groups files with similar changes, focusing on the introduction of new functions, enhancement of existing functionalities, and ensuring data integrity through immutability. 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 (
|
Fixes #1278 |
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
Out of diff range and nitpick comments (1)
packages/schema/src/plugins/zod/transformer.ts (1)
Line range hint
393-493
: Review the methodgenerateInputSchemas
. The method handles the generation of input schemas for various operations likefindUnique
,findFirst
,findMany
, etc., based on model operations. It uses conditional checks to determine which schemas to generate and includes handling for both checked and unchecked scenarios.
- The method is quite large and complex, consider refactoring to improve readability and maintainability.
- Ensure that the use of
supportCreateMany
is consistent and correctly checks the container's support for batch operations.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/sdk/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!pnpm-lock.yaml
,!**/*.yaml
Files selected for processing (17)
- packages/plugins/openapi/src/rpc-generator.ts (4 hunks)
- packages/plugins/swr/src/generator.ts (2 hunks)
- packages/plugins/tanstack-query/src/generator.ts (2 hunks)
- packages/plugins/trpc/src/generator.ts (5 hunks)
- packages/plugins/trpc/src/helpers.ts (1 hunks)
- packages/runtime/src/enhancements/policy/policy-utils.ts (2 hunks)
- packages/schema/src/plugins/enhancer/enhance/index.ts (1 hunks)
- packages/schema/src/plugins/zod/generator.ts (2 hunks)
- packages/schema/src/plugins/zod/transformer.ts (4 hunks)
- packages/schema/src/plugins/zod/types.ts (1 hunks)
- packages/sdk/src/dmmf-helpers/include-helpers.ts (1 hunks)
- packages/sdk/src/dmmf-helpers/model-helpers.ts (1 hunks)
- packages/sdk/src/dmmf-helpers/modelArgs-helpers.ts (1 hunks)
- packages/sdk/src/dmmf-helpers/select-helpers.ts (2 hunks)
- packages/sdk/src/utils.ts (4 hunks)
- packages/testtools/src/schema.ts (2 hunks)
- tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (1 hunks)
Files not reviewed due to errors (1)
- packages/runtime/src/enhancements/policy/policy-utils.ts (no review received)
Files skipped from review due to trivial changes (1)
- tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts
Additional comments not posted (31)
packages/schema/src/plugins/zod/types.ts (3)
5-5
: Ensure immutability by usingreadonly
inenumTypes
.
6-6
: Ensure immutability by usingreadonly
infields
.
8-8
: Ensure immutability by usingreadonly
inmodels
.packages/sdk/src/dmmf-helpers/model-helpers.ts (1)
34-34
: Ensure immutability by usingreadonly
inmodels
parameter offindModelByName
.packages/sdk/src/dmmf-helpers/modelArgs-helpers.ts (2)
4-7
: Ensure immutability by usingreadonly
inmodels
parameter ofaddMissingInputObjectTypesForModelArgs
.
14-14
: Ensure immutability by usingreadonly
inmodels
parameter ofgenerateModelArgsInputObjectTypes
.packages/sdk/src/dmmf-helpers/include-helpers.ts (2)
4-7
: Ensure immutability by usingreadonly
inmodels
parameter ofaddMissingInputObjectTypesForInclude
.
15-15
: Ensure immutability by usingreadonly
inmodels
parameter ofgenerateModelIncludeInputObjectTypes
.packages/sdk/src/dmmf-helpers/select-helpers.ts (2)
7-7
: Ensure immutability by usingreadonly
inmodels
parameter ofaddMissingInputObjectTypesForSelect
.
92-118
: Optimize the generation of model select input object types by usingreadonly
inmodels
parameter.packages/testtools/src/schema.ts (2)
100-100
: Ensure conditional handling of preview features in schema generation.
137-137
: Ensure proper handling of preview features by making it a part ofSchemaLoadOptions
.packages/plugins/trpc/src/helpers.ts (1)
330-330
: Enhance handling of model comments to determine hidden models.packages/plugins/trpc/src/generator.ts (4)
10-10
: Ensure support forcreateMany
operation based on model capabilities.
Line range hint
83-176
: Enhance the app router creation to handle model operations more dynamically, including conditional generation based on model visibility and actions.
246-247
: Optimize model router creation by dynamically generating routes based on model operations and client helper requirements.
304-307
: Correctly handle the conditional generation ofcreateMany
operation based on model support.packages/plugins/swr/src/generator.ts (1)
89-89
: Use ofsupportCreateMany
correctly implements conditional feature generation based on Prisma version.Verification successful
The search results confirm the presence and usage of the
supportCreateMany
function across various parts of the codebase, including the specific file and line in question (packages/plugins/swr/src/generator.ts
). The function is defined inpackages/sdk/src/utils.ts
and is imported and used in several modules to conditionally enable features based on the model's capabilities, which aligns with the intended functionality described in the review comment.Given this information, the use of
supportCreateMany
in thegenerator.ts
file of the SWR plugin is consistent with its usage in other parts of the codebase and is implemented correctly to handle different versions of Prisma as intended.Conclusion:
- The implementation of
supportCreateMany
is verified to be correct and is used appropriately across the codebase to handle feature compatibility based on the model's capabilities.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `supportCreateMany`. # Test: Search for the function implementation. Expect: Proper handling of Prisma versions. rg --type typescript $'supportCreateMany'Length of output: 75
Script:
#!/bin/bash # Description: Re-verify the implementation of `supportCreateMany`. # Test: Search for the function implementation without specifying file type. Expect: Proper handling of Prisma versions. rg 'supportCreateMany'Length of output: 1162
packages/sdk/src/utils.ts (2)
541-551
: Implementation ofgetDataSourceProvider
correctly handles potential absence of data source or provider field.
556-561
: Implementation ofsupportCreateMany
correctly determines support forcreateMany
based on Prisma version and provider.Verification successful
The implementations of
getPrismaVersion
andgetDataSourceProvider
are correctly defined and used across the codebase. The functions are essential for determining the support forcreateMany
based on the Prisma version and provider, and they are implemented as expected.
getPrismaVersion
is defined inpackages/sdk/src/prisma.ts
getDataSourceProvider
is defined inpackages/sdk/src/utils.ts
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementations of `getPrismaVersion` and `getDataSourceProvider`. # Test: Search for the function implementations. Expect: Correct handling of versions and providers. rg --type typescript $'getPrismaVersion|getDataSourceProvider'Length of output: 98
Script:
#!/bin/bash # Description: Re-verify the implementations of `getPrismaVersion` and `getDataSourceProvider`. # Test: Search for the function implementations in TypeScript files. Expect: Correct handling of versions and providers. rg 'getPrismaVersion|getDataSourceProvider' -g '*.ts' -g '*.tsx'Length of output: 1226
packages/schema/src/plugins/zod/generator.ts (2)
192-195
: Changes togenerateEnumSchemas
correctly handle both Prisma and model-specific enums.
110-110
: Addition of the model parameter togenerateInputSchemas
enhances schema generation capabilities.packages/schema/src/plugins/enhancer/enhance/index.ts (1)
59-59
: Ensure the return typePromise<{ dmmf: DMMF.Document | undefined }>
aligns with the intended usage of thegenerate
method across the application.packages/plugins/tanstack-query/src/generator.ts (1)
352-352
: Verify the implementation ofsupportCreateMany
to ensure it correctly determines when thecreateMany
method should be generated based on the Prisma version.Verification successful
The implementation of the
supportCreateMany
function has been successfully retrieved and reviewed. The function checks if thecreateMany
method is supported based on the Prisma version and the data source provider. Specifically, it supportscreateMany
for SQLite from Prisma version 5.12.0 onwards. This aligns with the expected functionality as described in the review comment, ensuring that thecreateMany
method is generated conditionally based on the Prisma version.
- The function correctly retrieves the Prisma version using
getPrismaVersion
.- It checks the data source provider with
getDataSourceProvider
.- It conditionally supports
createMany
for SQLite if the Prisma version is 5.12.0 or higher.This confirms that the implementation is as expected and correctly integrates version checking for feature support.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `supportCreateMany`. # Test: Search for the function implementation. Expect: Correct logic for Prisma version check. rg --type typescript $'function supportCreateMany'Length of output: 86
Script:
#!/bin/bash # Description: Re-verify the implementation of `supportCreateMany`. # Test: Search for the function implementation using a broader file type. Expect: Correct logic for Prisma version check. rg --type js,ts $'function supportCreateMany'Length of output: 76
Script:
#!/bin/bash # Description: Re-verify the implementation of `supportCreateMany`. # Test: Search for the function implementation using correct file type specification. Expect: Correct logic for Prisma version check. rg --type js --type ts 'function supportCreateMany'Length of output: 129
Script:
#!/bin/bash # Description: Retrieve the implementation of `supportCreateMany`. # Test: Display the implementation of `supportCreateMany`. Expect: Detailed function logic. cat packages/sdk/src/utils.ts | grep -A 10 'function supportCreateMany'Length of output: 382
packages/schema/src/plugins/zod/transformer.ts (4)
15-15
: Ensure immutability by usingreadonly
forfields
.
17-17
: Ensure immutability by usingreadonly
formodels
.
20-20
: Ensure immutability by usingreadonly
forenumTypes
.
493-493
: Verify the conditional generation ofcreateMany
method. This is crucial for compatibility with different versions of Prisma.Verification successful
The conditional generation of the
createMany
method appears to be implemented correctly across the codebase, particularly in relation to compatibility with different versions of Prisma. Notably, inpackages/schema/src/plugins/zod/transformer.ts
, the method's generation is conditioned on the result ofsupportCreateMany(zmodel)
, which is a good practice for ensuring compatibility.
- File:
packages/schema/src/plugins/zod/transformer.ts
- Context: Conditional generation based on
supportCreateMany(zmodel)
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the conditional generation of `createMany` method across the codebase. # Test: Search for the usage of `createMany`. Expect: Conditional checks before usage. rg --type typescript $'createMany'Length of output: 68
Script:
#!/bin/bash # Description: Verify the conditional generation of `createMany` method across the codebase. # Test: Search for the usage of `createMany`. Expect: Conditional checks before usage. rg --type ts $'createMany'Length of output: 10863
packages/plugins/openapi/src/rpc-generator.ts (3)
3-3
: Ensure that the import ofsupportCreateMany
is used appropriately for conditional feature generation.
6-6
: Review the import ofAggregateOperationSupport
and related helper functions. These are crucial for handling aggregate operations in the OpenAPI specification generation.
169-169
: Review the conditional generation ofcreateMany
method in theRPCOpenAPIGenerator
class. This method should only be generated ifsupportCreateMany
returns true for the given model container, ensuring compatibility with Prisma versions that do not support batch operations.
- Verify that
supportCreateMany
is correctly implemented and used across the codebase.Verification successful
The verification process has successfully identified the implementation and usage of the
supportCreateMany
function across various parts of the codebase. Here are the key findings:
- The function
supportCreateMany
is defined inpackages/sdk/src/utils.ts
.- It is used in several generator files across different plugins (
trpc
,swr
,tanstack-query
,openapi
) to conditionally generate methods based on the model's compatibility with batch operations.- The usage pattern consistently checks the capability of the model container before proceeding with batch operations like
createMany
.This confirms that the function is implemented and utilized correctly to ensure compatibility with Prisma versions that do not support batch operations, as intended in the original review comment.
Locations where
supportCreateMany
is used:
packages/schema/src/plugins/zod/transformer.ts
packages/plugins/trpc/src/generator.ts
packages/plugins/swr/src/generator.ts
packages/plugins/tanstack-query/src/generator.ts
packages/plugins/openapi/src/rpc-generator.ts
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct implementation and usage of `supportCreateMany` across the codebase. # Test: Search for the implementation and usage of `supportCreateMany`. Expect: Correct checks and usage patterns. rg --type typescript $'supportCreateMany'Length of output: 75
Script:
#!/bin/bash # Description: Re-verify the correct implementation and usage of `supportCreateMany` across the codebase using corrected file type specifications. # Test: Search for the implementation and usage of `supportCreateMany` in TypeScript files. Expect: Correct checks and usage patterns. rg 'supportCreateMany' --glob '*.ts' --glob '*.tsx'Length of output: 1191
@prisma/internals
and@prisma/generator-helper
to latest.omit
clause when reading entities.createMany
based on Prisma version.