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

Fix(JSON): Allow JSON types to be skipped through Prisma.skip #2064

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

diesal11
Copy link
Contributor

@diesal11 diesal11 commented Apr 1, 2025

Another JSON edge case!

When the strictUndefinedChecks Prisma Preview feature is enabled, Prisma.skip is required to be used over undefined. The types generated for @Json fields misses this typing in cases where the field is optional in the Prisma type, for example within UpdateInput types

Note this doesn't allow using Prisma.skip on a field within the JSON type, as that doesn't appear to be supported by Prisma.

Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

📝 Walkthrough

Walkthrough

The changes update the logic in the replacePrismaJson function to more robustly handle optional JSON fields by checking for a ? in the field name with a regular expression. If a field is identified as optional—either through the source definition or its type definition—the replacement string is modified to include | $Types.Skip. Additionally, a new integration test has been added to validate the behavior of Prisma's skip functionality when performing CRUD operations on JSON fields.

Changes

File(s) Summary of Changes
packages/schema/src/plugins/enhancer/enhance/index.ts Enhanced the replacePrismaJson function. Added regex logic to detect optional fields and conditionally append `
tests/integration/tests/enhancements/json/crud.test.ts Introduced a new test case ("works with Prisma.skip") to verify that Prisma.skip behaves correctly for JSON fields, ensuring that type errors and updates are handled as expected.

Suggested reviewers

  • ymc9

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed71b1 and 87b0128.

📒 Files selected for processing (2)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (1 hunks)
  • tests/integration/tests/enhancements/json/crud.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/schema/src/plugins/enhancer/enhance/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build-test (20.x)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
🔇 Additional comments (1)
tests/integration/tests/enhancements/json/crud.test.ts (1)

433-493: Well-structured test for Prisma.skip functionality with JSON fields

This test effectively validates the behavior of Prisma.skip with JSON fields in both creation and update scenarios. I particularly like:

  • The explicit type-checking with @ts-expect-error to confirm that non-optional JSON fields cannot be skipped during creation
  • The verification that skipping during updates preserves the original JSON data
  • The approach of including a sample application file to test the TypeScript behavior

The test aligns perfectly with the PR objective of allowing JSON types to be skipped through Prisma.skip.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@diesal11 diesal11 force-pushed the fix/add-skip-to-json-types branch from 9ed71b1 to 87b0128 Compare April 1, 2025 08:35
@ymc9 ymc9 changed the base branch from main to dev April 3, 2025 05:57
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @diesal11 ! Thanks for making the fix. I'm merging it and will publish a new release.

@ymc9 ymc9 merged commit 9ed6a92 into zenstackhq:dev Apr 4, 2025
11 of 13 checks passed
@diesal11 diesal11 deleted the fix/add-skip-to-json-types branch April 4, 2025 07:35
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