Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Nov 22, 2024

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (4)
  • packages/plugins/trpc/tests/projects/nuxt-trpc-v10/package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • packages/plugins/trpc/tests/projects/nuxt-trpc-v10/package.json is excluded by !**/*.json
  • packages/plugins/trpc/tests/projects/nuxt-trpc-v11/package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • packages/plugins/trpc/tests/projects/nuxt-trpc-v11/package.json is excluded by !**/*.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple files, primarily enhancing the handling of fields marked with the @ignore directive in schemas. A new test case is added to validate that ignored fields are excluded from generated Zod schemas. Additionally, type declarations and interfaces in the ast.ts file are updated to improve type resolution and field management. The cli-util.ts file is modified to include a function that filters out ignored fields from data models, ensuring cleaner output. Formatting adjustments are made to schema definitions for improved readability.

Changes

File Path Change Summary
tests/integration/tests/plugins/zod.test.ts New test case added to verify that fields marked with @ignore are excluded from generated Zod schemas.
packages/language/src/ast.ts - New type ResolvedShape defined.
- Updated ResolvedType with optional properties.
- Updated DataModel interface with $allFields property.
- Augmented AstNode interface with $resolvedType property.
packages/schema/src/cli/cli-util.ts New function filterIgnoredFields added to filter out fields marked with @ignore from data models.
tests/integration/tests/schema/todo.zmodel Formatting adjustments made to property declarations in schema models for improved readability.

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

🧹 Outside diff range and nitpick comments (1)
packages/schema/src/plugins/zod/generator.ts (1)

466-467: Consider adding a comment explaining discriminator fields.

While the implementation is correct, it would be helpful to add a comment explaining what discriminator fields are and why they need to be excluded from mutation schemas.

+// Discriminator fields are used for polymorphic relations and should be excluded from mutation schemas
+// as they are managed by Prisma
 const delegateDiscriminatorFields = allFields.filter((field) => isDiscriminatorField(field));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0625234 and fcc2909.

📒 Files selected for processing (2)
  • packages/schema/src/plugins/zod/generator.ts (2 hunks)
  • tests/integration/tests/plugins/zod.test.ts (1 hunks)
🔇 Additional comments (5)
packages/schema/src/plugins/zod/generator.ts (3)

399-400: LGTM! Clean implementation of ignored fields filtering.

The introduction of allFields effectively filters out fields marked with @ignore at the beginning, ensuring they're excluded from all generated schemas.


401-408: LGTM! Consistent usage of filtered fields for scalar field identification.

The scalar fields filtering logic correctly uses the filtered allFields, maintaining the existing conditions while ensuring ignored fields are excluded.


409-410: LGTM! Consistent usage of filtered fields for relations and foreign keys.

The relations and foreign key fields filtering correctly use the filtered allFields, maintaining consistency with the scalar fields implementation.

tests/integration/tests/plugins/zod.test.ts (2)

1084-1084: LGTM!

The blank line improves readability by separating test cases.


1085-1099: LGTM! Test case effectively validates @ignore functionality.

The test case is well-structured and effectively validates that:

  1. Fields marked with @ignore are excluded from the generated schemas
  2. Both regular and Prisma-specific schemas handle ignored fields correctly

Let's verify that this is the only test case for @ignore functionality:

✅ Verification successful

Let me check the content of these files to understand the context of @ignore usage.


The test coverage for @ignore is complete but spans different use cases

The codebase has appropriate test coverage for both field-level @ignore attribute (in zod.test.ts) and model-level @@ignore attribute (in auth.test.ts). These are different use cases:

  • Field-level @ignore tested in the current PR: password String @ignore
  • Model-level @@ignore tested in auth tests: @@ignore at model level
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other tests related to @ignore functionality
# Expect: Only one test case should handle @ignore fields

rg -l "@ignore" "tests/integration/tests/"

Length of output: 146


Script:

#!/bin/bash
# Check the actual usage of @ignore in both files
rg -B2 -A2 "@ignore" "tests/integration/tests/plugins/zod.test.ts" "tests/integration/tests/enhancements/with-policy/auth.test.ts"

Length of output: 1585

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

🧹 Outside diff range and nitpick comments (1)
packages/schema/src/cli/cli-util.ts (1)

374-382: Consider enhancing robustness and documentation

While the implementation is functional, consider these improvements:

  1. Add JSDoc comments to document:
    • The function's purpose
    • The in-place mutation behavior
    • The $allFields property's purpose
  2. Add null checks for the fields array
  3. Consider memory implications of storing duplicate field arrays

Here's a suggested implementation with these improvements:

+/**
+ * Filters out fields marked with @ignore from data models while preserving
+ * all original fields in $allFields for reference.
+ * Note: This function modifies the model in-place.
+ * @param model The model to process
+ */
 function filterIgnoredFields(model: Model) {
     model.declarations.forEach((decl) => {
         if (!isDataModel(decl)) {
             return;
         }
+        // Preserve all fields for reference
         decl.$allFields = [...(decl.fields ?? [])];
+        // Filter out ignored fields
         decl.fields = (decl.fields ?? []).filter((f) => !hasAttribute(f, '@ignore'));
     });
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcc2909 and 7d53ccb.

📒 Files selected for processing (3)
  • packages/language/src/ast.ts (1 hunks)
  • packages/schema/src/cli/cli-util.ts (3 hunks)
  • tests/integration/tests/schema/todo.zmodel (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/integration/tests/schema/todo.zmodel
🔇 Additional comments (4)
packages/language/src/ast.ts (2)

Line range hint 8-17: LGTM! Well-structured type declarations

The new type declarations are well-documented and follow TypeScript best practices. The ResolvedShape and ResolvedType provide a robust foundation for type resolution in expressions.


61-65: Verify synchronization of $allFields with actual fields

The $allFields property is well-documented and supports the PR objective of handling @ignore fields. However, we should ensure there's a mechanism to keep this array synchronized with the actual fields.

Let's verify how $allFields is populated and maintained:

✅ Verification successful

Based on the search results, I can now generate the final response as we have found clear evidence of how $allFields is synchronized:

$allFields is properly synchronized with actual fields

The synchronization is handled in packages/schema/src/cli/cli-util.ts:

decl.$allFields = [...decl.fields];
decl.fields = decl.fields.filter((f) => !hasAttribute(f, '@ignore'));

This shows that:

  1. $allFields is populated with a copy of all fields before filtering
  2. fields is then filtered to exclude @ignore fields
  3. The synchronization happens at the schema processing stage, ensuring consistency
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to $allFields to understand its lifecycle
rg -t ts "\$allFields" --no-heading

# Look for field collection/processing logic
ast-grep --pattern 'function $_($$_) {
  $$$
  $allFields
  $$$
}'

Length of output: 105


Script:

#!/bin/bash
# Search for references to $allFields with proper escaping and context
rg -t ts "\\\$allFields" -B 2 -A 2

# Look for field collection/processing logic using a broader pattern
ast-grep --pattern 'interface DataModel {
  $$$
}'

# Search for field processing functions
rg -t ts "fields.*=" -B 2 -A 2

Length of output: 94936

packages/schema/src/cli/cli-util.ts (2)

120-122: LGTM! Appropriate placement of the filtering step

The filterIgnoredFields call is correctly placed after model relinking and before returning, ensuring all model processing is complete before filtering out ignored fields.


379-380: Verify type declarations for $allFields

The code adds a new $allFields property to data models. Let's ensure this property is properly typed in the AST definitions.

✅ Verification successful

$allFields property is properly typed in AST definitions

The property is correctly typed as $allFields?: DataModelField[] in the DataModel interface at packages/language/src/ast.ts, with appropriate JSDoc documentation indicating its purpose to store "All fields including those marked with @ignore".

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if $allFields is properly typed in AST definitions

# Look for DataModel interface/type definition
ast-grep --pattern 'interface DataModel {
  $$$
}'

# Check for any existing $allFields declarations
rg '\$allFields'

Length of output: 866

@ymc9 ymc9 merged commit b2ee7a4 into dev Nov 22, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/zod-ignore branch November 22, 2024 18:28
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.

2 participants