Skip to content
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

Merged
merged 3 commits into from
Sep 27, 2024
Merged

merge dev to main (v2.6.2) #1752

merged 3 commits into from
Sep 27, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 27, 2024

No description provided.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

📝 Walkthrough

Walkthrough

The 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 smartUnion function to improve schema compatibility, updates to the ZodSchemaGenerator and Transformer classes to accommodate a new operational mode, and enhancements to existing test files to ensure robust validation of schema behaviors.

Changes

File Change Summary
packages/ide/jetbrains/build.gradle.kts Version updated from "2.6.1" to "2.6.2".
packages/runtime/src/zod-utils.ts New utility functions added for Zod schema handling, including smartUnion and related helpers.
packages/runtime/tests/zod/smart-union.test.ts New unit tests for the smartUnion function covering various schema scenarios.
packages/schema/src/plugins/zod/generator.ts Added mode property to ZodSchemaGenerator, integrating validation into the constructor.
packages/schema/src/plugins/zod/transformer.ts Introduced ObjectMode type, updated transformer methods to utilize the new mode functionality.
packages/schema/src/plugins/zod/types.ts Added ObjectMode type and updated TransformerParams to include the new mode property.
script/test-scaffold.ts Updated prisma and @prisma/client versions from 5.19.x to 5.20.x.
tests/integration/tests/cli/plugins.test.ts Updated @prisma/client and prisma versions from 5.19.x to 5.20.x.
tests/regression/tests/issue-1746.test.ts New regression tests for Zod schema validation in a Prisma context.

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 the mode property in TransformerParams.

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 case

In 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 test

Similarly, 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() within generateInputSchemas 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

📥 Commits

Files that changed from the base of the PR and between 6f30022 and 46d6a63.

⛔ 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:

  1. Ensure all Prisma-related scripts (generate, migrate, etc.) work as expected.
  2. Run the test suite to catch any potential issues.
  3. 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 to TransformerParams 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 uses TransformerParams.

Please run the following script to identify potential areas that might need updates:

Review the results to ensure all usages of TransformerParams include the new mode property.

✅ Verification successful

Verification Successful

All usages of TransformerParams have been updated to include the required mode 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 and prisma from version 5.19.x to 5.20.x. While these are minor version updates and should maintain backwards compatibility, it's crucial to:

  1. Run all integration tests to ensure no breaking changes were introduced.
  2. Verify that the Prisma CLI functions correctly in the development environment.
  3. 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 from 5.19.x to 5.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 generate

If 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 from 5.19.x to 5.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 in identifyCandidate

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 in unwrapLazy

The unwrapLazy function effectively handles ZodLazy 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 suite

The 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 the smartUnion implementation.

tests/regression/tests/issue-1746.test.ts (1)

1-149: Comprehensive test coverage for comment creation validation

The 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: Importing ObjectMode

The import of ObjectMode from './types' is necessary and correctly added for type definitions.


32-32: Adding mode property to ZodSchemaGenerator

The mode property is appropriately added to the class, allowing the generator to utilize the specified object mode throughout.


46-54: Validating options.mode in the constructor

The 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: Passing mode to Transformer in generate() method

The mode is correctly passed to the Transformer instance, ensuring consistent schema generation according to the specified mode.


223-223: Passing mode to Transformer in generateEnumSchemas()

Including mode: this.mode when creating the Transformer ensures that enum schema generation respects the specified object mode.


252-252: Passing mode to Transformer in generateObjectSchemas()

The addition of mode: this.mode when initializing Transformer in generateObjectSchemas 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 correctly

The logic for conditionally importing smartUnion when mode is 'strip' is correctly implemented. This ensures that smartUnion is only imported when necessary.


220-232: Updated union generation logic enhances runtime parsing

The 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' operation

The use of wrapWithSmartUnion to handle CreateInput and UncheckedCreateInput types in the create operation ensures proper parsing at runtime. This change is appropriate and enhances schema flexibility.


589-592: Correct usage of 'wrapWithSmartUnion' in 'update' operation

Applying wrapWithSmartUnion for the update operation with UpdateInput and UncheckedUpdateInput types improves runtime parsing. The implementation is suitable for handling different input types effectively.


610-613: Correct usage of 'wrapWithSmartUnion' in 'updateMany' operation

The use of wrapWithSmartUnion in the updateMany operation to combine UpdateManyMutationInput and UncheckedUpdateManyInput 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, using wrapWithSmartUnion for combining CreateInput and UncheckedCreateInput types in the create 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 the upsert operation, the application of wrapWithSmartUnion with UpdateInput and UncheckedUpdateInput types is appropriate and enhances runtime parsing capabilities.

packages/runtime/src/zod-utils.ts Show resolved Hide resolved
packages/runtime/src/zod-utils.ts Show resolved Hide resolved
tests/regression/tests/issue-1746.test.ts Show resolved Hide resolved
packages/schema/src/plugins/zod/generator.ts Show resolved Hide resolved
packages/schema/src/plugins/zod/generator.ts Show resolved Hide resolved
@ymc9 ymc9 merged commit be8c1c4 into main Sep 27, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant