-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
merge dev to main (v2.6.2) #1752
Conversation
📝 WalkthroughWalkthroughThe changes include updates to version numbers in various files, the introduction of utility functions for Zod schema handling, and the addition of regression tests. Key modifications involve the implementation of a Changes
Possibly related PRs
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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: 7
🧹 Outside diff range and nitpick comments (4)
packages/schema/src/plugins/zod/types.ts (1)
30-30
: LGTM. Consider adding documentation for each mode.The introduction of the
ObjectMode
type with clear, descriptive options is a good addition. It provides a well-defined set of choices for themode
property inTransformerParams
.To improve clarity for developers, consider adding a brief comment explaining what each mode does. For example:
/** * Defines the operational mode for object handling. * - 'strict': Throws an error if any unknown properties are present. * - 'strip': Removes any unknown properties from the object. * - 'passthrough': Allows unknown properties to pass through unchanged. */ export type ObjectMode = 'strict' | 'strip' | 'passthrough';tests/regression/tests/issue-1746.test.ts (2)
81-91
: Add assertions for error messages in failing test caseIn the test case where parsing is expected to fail due to mixed inputs (lines 82-90), consider adding assertions to check the specific error messages returned by Zod. This ensures that the validation fails for the expected reasons and improves test robustness.
For example:
expect(parsed.success).toBe(false); if (!parsed.success) { expect(parsed.error.errors).toContainEqual( expect.objectContaining({ code: 'custom', message: 'Cannot mix userId and user object in the same input', }) ); }
140-148
: Add assertions for error details in mixed input array testSimilarly, in the array test case where parsing is expected to fail due to mixed inputs (lines 141-147), adding checks for the specific error messages will help ensure that the validation fails for the intended reasons.
For example:
expect(parsed.success).toBe(false); if (!parsed.success) { expect(parsed.error.errors).toContainEqual( expect.objectContaining({ code: 'custom', message: 'Mixed input types are not allowed in the create array', }) ); }packages/schema/src/plugins/zod/transformer.ts (1)
482-482
: Avoid potential duplicate imports in 'generateInputSchemas'Calling
this.generateImportZodStatement()
withingenerateInputSchemas
might lead to duplicate import statements if not managed carefully. Ensure that imports are consolidated to prevent redundancy.Consider modifying the imports handling to prevent duplicates:
const importsSet = new Set<string>([ this.generateImportZodStatement(), // ... other imports ... ]); - imports = [...new Set(imports)]; + imports = Array.from(importsSet);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (17)
package.json
is excluded by!**/*.json
packages/ide/jetbrains/package.json
is excluded by!**/*.json
packages/language/package.json
is excluded by!**/*.json
packages/misc/redwood/package.json
is excluded by!**/*.json
packages/plugins/openapi/package.json
is excluded by!**/*.json
packages/plugins/swr/package.json
is excluded by!**/*.json
packages/plugins/tanstack-query/package.json
is excluded by!**/*.json
packages/plugins/trpc/package.json
is excluded by!**/*.json
packages/runtime/package.json
is excluded by!**/*.json
packages/schema/package.json
is excluded by!**/*.json
packages/sdk/package.json
is excluded by!**/*.json
packages/server/package.json
is excluded by!**/*.json
packages/testtools/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 (9)
- packages/ide/jetbrains/build.gradle.kts (1 hunks)
- packages/runtime/src/zod-utils.ts (1 hunks)
- packages/runtime/tests/zod/smart-union.test.ts (1 hunks)
- packages/schema/src/plugins/zod/generator.ts (5 hunks)
- packages/schema/src/plugins/zod/transformer.ts (11 hunks)
- packages/schema/src/plugins/zod/types.ts (2 hunks)
- script/test-scaffold.ts (1 hunks)
- tests/integration/tests/cli/plugins.test.ts (2 hunks)
- tests/regression/tests/issue-1746.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/ide/jetbrains/build.gradle.kts
🔇 Additional comments (22)
script/test-scaffold.ts (1)
22-22
: LGTM! Prisma packages updated to latest minor version.The update of Prisma packages from version 5.19.x to 5.20.x aligns with the PR objective of merging dev to main for version 2.6.2. This change keeps the project up-to-date with the latest minor version of Prisma.
To ensure this update doesn't introduce any breaking changes, please verify compatibility with the rest of the project. Consider running the following checks:
- Ensure all Prisma-related scripts (generate, migrate, etc.) work as expected.
- Run the test suite to catch any potential issues.
- Review the Prisma 5.20.x changelog for any breaking changes or deprecations.
Would you like me to generate a script to help verify the impact of this change across the codebase?
packages/schema/src/plugins/zod/types.ts (1)
17-17
: LGTM. Verify impact on existing code.The addition of the
mode
property toTransformerParams
is a good enhancement for specifying the operational mode of the transformer. However, as this is a required property in an existing type, it may impact existing code that usesTransformerParams
.Please run the following script to identify potential areas that might need updates:
Review the results to ensure all usages of
TransformerParams
include the newmode
property.✅ Verification successful
Verification Successful
All usages of
TransformerParams
have been updated to include the requiredmode
property. No existing code is impacted by this change.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find usages of TransformerParams that might need updating # Search for TransformerParams usage echo "Searching for TransformerParams usage:" rg --type typescript "TransformerParams" -C 3 # Search for object literals that might be creating TransformerParams echo "\nSearching for potential TransformerParams object creations:" rg --type typescript "\{(\s*\w+\s*:\s*[^}]+,?\s*)*\}" -C 3 | rg "project\s*:|inputObjectTypes\s*:|zmodel\s*:"Length of output: 447
Script:
#!/bin/bash # Description: Find usages of TransformerParams that might need updating # Search for TransformerParams usage in .ts and .tsx files echo "Searching for TransformerParams usage in TypeScript files:" rg "TransformerParams" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx -C 3 # Search for object literals that might be creating TransformerParams echo "\nSearching for potential TransformerParams object creations in TypeScript files:" rg "\{(\s*\w+\s*:\s*[^}]+,?\s*)*\}" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx -C 3 | rg "mode\s*:"Length of output: 620
Script:
#!/bin/bash # Description: Find usages of TransformerParams that might need updating # Add TypeScript file types correctly rg --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' # Search for TransformerParams usage in .ts and .tsx files echo "Searching for TransformerParams usage in TypeScript files:" rg "TransformerParams" -t ts -t tsx -C 3 # Search for object literals that might be creating TransformerParams with the new 'mode' property echo "\nSearching for potential TransformerParams object creations in TypeScript files:" rg "\{(\s*\w+\s*:\s*[^}]+,?\s*)*\}" -t ts -t tsx -C 3 | rg "mode\s*:"Length of output: 914
Script:
#!/bin/bash # Description: Find usages of TransformerParams that might need updating # Search for TransformerParams usage in .ts and .tsx files echo "Searching for TransformerParams usage in TypeScript files:" rg "TransformerParams" --glob "*.ts" --glob "*.tsx" -C 3 # Search for object literals that might be creating TransformerParams with the new 'mode' property echo "\nSearching for potential TransformerParams object creations in TypeScript files:" rg "\{(\s*\w+\s*:\s*[^}]+,?\s*)*\}" --glob "*.ts" --glob "*.tsx" -C 3 | rg "mode\s*:"Length of output: 3158
tests/integration/tests/cli/plugins.test.ts (3)
78-78
: Summary: Prisma package updates require thorough testing.The changes update both
@prisma/client
andprisma
from version5.19.x
to5.20.x
. While these are minor version updates and should maintain backwards compatibility, it's crucial to:
- Run all integration tests to ensure no breaking changes were introduced.
- Verify that the Prisma CLI functions correctly in the development environment.
- Check the Prisma 5.20.x changelog for any relevant updates or potential impacts on your test suite or development workflow.
These updates are good for keeping the project up-to-date, but caution is advised to maintain the stability of your testing and development processes.
Also applies to: 88-88
88-88
: LGTM. Ensure development environment compatibility with the updated Prisma CLI version.The update of
prisma
from5.19.x
to5.20.x
aligns the Prisma CLI version with the Prisma client version. This consistency is good practice and should help prevent version mismatch issues.To verify the impact of this change on the development environment, please run the following commands:
#!/bin/bash # Description: Verify Prisma CLI functionality with the updated version. # Check Prisma CLI version npx prisma --version # Run a Prisma CLI command (e.g., generate) to ensure it works correctly npx prisma generateIf these commands execute successfully without any errors, it indicates that the updated Prisma CLI version is compatible with the development environment.
78-78
: LGTM. Verify test compatibility with the updated Prisma client version.The update of
@prisma/client
from5.19.x
to5.20.x
is a minor version bump, which should maintain backwards compatibility. However, it's important to ensure that this change doesn't introduce any unexpected behavior in the tests.To verify the impact of this change, please run the following command:
If all tests pass successfully, this change can be confidently merged.
packages/runtime/src/zod-utils.ts (2)
88-110
: Efficient identification of the best candidate schema inidentifyCandidate
The function
identifyCandidate
correctly identifies the candidate schema with the fewest unrecognized keys, ensuring accurate parsing. The use of sorting based on unrecognized key count is effective and well-implemented.
119-121
: Proper handling of lazy schemas inunwrapLazy
The
unwrapLazy
function effectively handlesZodLazy
schemas by unwrapping them to access the underlying schema, ensuring correct parsing behavior.packages/runtime/tests/zod/smart-union.test.ts (1)
1-109
: Well-structured and comprehensive test suiteThe test cases are well-designed and cover a diverse range of scenarios for the
smartUnion
function. They effectively validate the handling of scalar types, non-ambiguous and ambiguous object unions, array unions, lazy schemas, and mixed object and array unions. Each test ensures that both successful validations and failure cases are appropriately tested, providing confidence in the robustness of thesmartUnion
implementation.tests/regression/tests/issue-1746.test.ts (1)
1-149
: Comprehensive test coverage for comment creation validationThe test suite effectively covers a wide range of scenarios for input validation of comment creation, including unchecked inputs, checked inputs, mixed inputs, nested creates, and array unions. This thorough testing ensures that the schema behaves as expected under various conditions.
packages/schema/src/plugins/zod/generator.ts (6)
26-26
: ImportingObjectMode
The import of
ObjectMode
from './types' is necessary and correctly added for type definitions.
32-32
: Addingmode
property toZodSchemaGenerator
The
mode
property is appropriately added to the class, allowing the generator to utilize the specified object mode throughout.
46-54
: Validatingoptions.mode
in the constructorThe validation logic for
options.mode
is correctly implemented. Moving the validation to the constructor ensures that invalid options are caught early, promoting robustness.
127-127
: Passingmode
toTransformer
ingenerate()
methodThe
mode
is correctly passed to theTransformer
instance, ensuring consistent schema generation according to the specified mode.
223-223
: Passingmode
toTransformer
ingenerateEnumSchemas()
Including
mode: this.mode
when creating theTransformer
ensures that enum schema generation respects the specified object mode.
252-252
: Passingmode
toTransformer
ingenerateObjectSchemas()
The addition of
mode: this.mode
when initializingTransformer
ingenerateObjectSchemas
method ensures that object schema generation adheres to the selected mode.packages/schema/src/plugins/zod/transformer.ts (7)
78-83
: Conditional import of 'smartUnion' implemented correctlyThe logic for conditionally importing
smartUnion
whenmode
is'strip'
is correctly implemented. This ensures thatsmartUnion
is only imported when necessary.
220-232
: Updated union generation logic enhances runtime parsingThe modification to use
wrapWithSmartUnion
when alternatives include'Unchecked'
types improves runtime parsing by selecting the best candidate. This change is appropriate and enhances the flexibility of schema generation.
541-544
: Correct usage of 'wrapWithSmartUnion' in 'create' operationThe use of
wrapWithSmartUnion
to handleCreateInput
andUncheckedCreateInput
types in thecreate
operation ensures proper parsing at runtime. This change is appropriate and enhances schema flexibility.
589-592
: Correct usage of 'wrapWithSmartUnion' in 'update' operationApplying
wrapWithSmartUnion
for theupdate
operation withUpdateInput
andUncheckedUpdateInput
types improves runtime parsing. The implementation is suitable for handling different input types effectively.
610-613
: Correct usage of 'wrapWithSmartUnion' in 'updateMany' operationThe use of
wrapWithSmartUnion
in theupdateMany
operation to combineUpdateManyMutationInput
andUncheckedUpdateManyInput
types is appropriate and enhances the schema's ability to parse inputs accurately.
633-636
: Correct usage of 'wrapWithSmartUnion' in 'upsert' operation (create part)In the
upsert
operation, usingwrapWithSmartUnion
for combiningCreateInput
andUncheckedCreateInput
types in thecreate
field ensures proper parsing and flexibility. This implementation is correct.
639-642
: Correct usage of 'wrapWithSmartUnion' in 'upsert' operation (update part)For the
update
field in theupsert
operation, the application ofwrapWithSmartUnion
withUpdateInput
andUncheckedUpdateInput
types is appropriate and enhances runtime parsing capabilities.
No description provided.