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(zod): field with auth() and @default() should be generated as optional #1266

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Apr 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced CLI descriptions to clarify the usage of core plugins.
    • Introduced new test cases for plugin generation and schema regression scenarios.
  • Refactor

    • Simplified and clarified internal naming and import paths for better alignment with project standards.
    • Adjusted schema generation logic to handle default values with authentication more effectively.
  • Documentation

    • Updated terminology from "built-in plugins" to "core plugins" across documentation and tool tips.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2024

Walkthrough

Walkthrough

This update involves renaming parameters, refining descriptions, adjusting imports, and modifying schema generation logic across several components in the ZenStack project. The changes aim to enhance clarity, maintainability, and functionality in handling schemas, plugins, and Prisma client specifications.

Changes

Files Change Summary
.../trpc/src/generator.ts Renamed zmodel parameter to _zmodel.
.../schema/src/cli/index.ts Updated option descriptions to refer to "core plugins".
.../schema/src/plugins/enhancer/index.ts Updated prismaClientPath to use .zenstack/models.
.../schema/src/plugins/zod/generator.ts Removed true argument from makeFieldSchema call.
.../schema/src/plugins/zod/utils/schema-gen.ts Removed respectDefault parameter; fields using auth() in @default() now optional.
.../sdk/src/prisma.ts Introduced DEFAULT_RUNTIME_LOAD_PATH import; updated getPrismaClientImportSpec function logic.
.../tests/cli/plugins.test.ts Added optional output parameter and new test case for custom core output paths.
.../tests/regression/issue-1241.test.ts Reformatted schema definitions without altering logic.
.../tests/regression/issue-1265.test.ts Added test case for schema loading and validation regression.

Possibly related issues


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c557dc9 and 902a3dc.
Files selected for processing (9)
  • packages/plugins/trpc/src/generator.ts (1 hunks)
  • packages/schema/src/cli/index.ts (1 hunks)
  • packages/schema/src/plugins/enhancer/index.ts (2 hunks)
  • packages/schema/src/plugins/zod/generator.ts (1 hunks)
  • packages/schema/src/plugins/zod/utils/schema-gen.ts (2 hunks)
  • packages/sdk/src/prisma.ts (2 hunks)
  • tests/integration/tests/cli/plugins.test.ts (2 hunks)
  • tests/integration/tests/regression/issue-1241.test.ts (1 hunks)
  • tests/integration/tests/regression/issue-1265.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/integration/tests/regression/issue-1241.test.ts
Additional comments not posted (10)
tests/integration/tests/regression/issue-1265.test.ts (2)

5-21: Ensure the schema definition in the test aligns with the intended changes in the PR.


24-25: Verify that the test assertions correctly evaluate the success of the schema parsing.

Verification successful

The test assertions in the file tests/integration/tests/regression/issue-1265.test.ts are correctly evaluating the success of the schema parsing as indicated by the use of .safeParse().success followed by .toBeTruthy(). This pattern is correctly implemented in lines 24 and 25 of the specified test file, confirming that the test logic is as intended.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the test assertions are correctly evaluating the success of the schema parsing.
ast-grep --lang javascript --pattern $'expect($_.safeParse($_).success).toBeTruthy()'

Length of output: 86



Script:

#!/bin/bash
# Adjusting the script to specifically target the test file and ensure it captures the pattern correctly.
ast-grep --lang javascript --pattern $'expect($_.safeParse($_).success).toBeTruthy()' tests/integration/tests/regression/issue-1265.test.ts

Length of output: 477

packages/schema/src/plugins/enhancer/index.ts (1)

34-34: Ensure the hardcoded path .zenstack/models is correctly resolved relative to the schema path.

packages/sdk/src/prisma.ts (1)

18-21: Verify that the new conditions for prismaClientPath correctly handle both the old runtime package path and the new default runtime load path.

packages/schema/src/cli/index.ts (1)

112-114: Ensure the updated option descriptions for output directories and plugin compilation are clear and accurately reflect the intended functionality.

Verification successful

The updated option descriptions in the index.ts file of the CLI package have been successfully verified. The descriptions for the options related to output directories and plugin compilation are clear and accurately reflect the intended functionality. The options specifically mention "core plugins," which aligns with the updated terminology discussed in the review comment.

  • The -o, --output <path> option clearly states it's the "default output directory for core plugins."
  • The --no-default-plugins and --no-compile options are straightforward in their description regarding the handling of core plugins.

These updates should help users understand the functionality related to core plugins more clearly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the updated option descriptions for output directories and plugin compilation are clear and accurately reflect the intended functionality.
ast-grep --lang javascript --pattern $'new Option($_, $_)'

Length of output: 59



Script:

#!/bin/bash
# Specifically target the index.ts file to check the instantiation of new Option
fd index.ts packages/schema/src/cli --exec cat {} \; | grep 'new Option'

Length of output: 907

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

29-32: Verify that the new output parameter for the zenstackGenerate function is correctly handled and does not introduce any regressions.

Verification successful

The search results confirm that the zenstackGenerate function is defined with two parameters (pm and output) in plugins.test.ts. The function is used multiple times in the same file. In most cases, it is called with only the pm parameter, but there is at least one instance where it is called with both pm and output parameters (zenstackGenerate(pm, './zen')). This indicates that the function is capable of handling calls both with and without the output parameter, as intended.

Given this information, it appears that the new output parameter for the zenstackGenerate function is correctly handled and does not introduce any regressions related to its usage. The function is flexible enough to be called with or without the output parameter, which aligns with the expectations from the review comment.

Conclusion: The new output parameter in the zenstackGenerate function is implemented correctly and is being used as expected in the test cases.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the new `output` parameter for the `zenstackGenerate` function is correctly handled and does not introduce any regressions.
ast-grep --lang javascript --pattern $'zenstackGenerate($_, $_)'

Length of output: 65



Script:

#!/bin/bash
# Search for any occurrence of the `zenstackGenerate` function to understand its definition and usage.
rg "zenstackGenerate" --multiline

Length of output: 486


279-311: Ensure the new test case for custom core output paths accurately tests the intended functionality and correctly handles the new output parameter.

packages/schema/src/plugins/zod/utils/schema-gen.ts (1)

143-148: Verify that the modification to handle fields with auth() in @default() by making them optional instead of using .default() is correctly implemented and does not introduce any regressions.

packages/plugins/trpc/src/generator.ts (1)

86-86: Verify that the renaming of the zmodel parameter to _zmodel in the createAppRouter function is correctly implemented and does not introduce any regressions.

Verification successful

The renaming of the zmodel parameter to _zmodel in the createAppRouter function has been correctly implemented. There are no occurrences of the old zmodel name within the function, ensuring that the renaming does not introduce any regressions. This change appears to be consistent and correctly applied.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the renaming of the `zmodel` parameter to `_zmodel` in the `createAppRouter` function is correctly implemented and does not introduce any regressions.
ast-grep --lang javascript --pattern $'function createAppRouter($_, $_, $_, $_, $_, $_, $_, $_) { $$$ }'

Length of output: 105



Script:

#!/bin/bash
# First, find the location and structure of the createAppRouter function to adjust our search pattern
rg "function createAppRouter" -A 10 packages/plugins/trpc/src/generator.ts

Length of output: 437



Script:

#!/bin/bash
# Check for any occurrences of the old 'zmodel' name within the 'createAppRouter' function to ensure complete renaming
rg "zmodel" -A 3 -B 3 packages/plugins/trpc/src/generator.ts

Length of output: 266

packages/schema/src/plugins/zod/generator.ts (1)

308-308: Ensure the removal of the true argument from makeFieldSchema aligns with the new schema generation logic.

Verification successful

The shell script execution did not find any instances of the makeFieldSchema function being called with two arguments in the codebase. This supports the conclusion that the removal of the true argument from the makeFieldSchema call in the generateModelSchema method is consistent with the intended behavior of the function across the codebase. No further issues are found related to this change.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new behavior of makeFieldSchema without the true argument is consistent across all usages in the codebase.
ast-grep --lang javascript --pattern $'makeFieldSchema($_, $_)'

Length of output: 64


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:

Note: Auto-reply has been disabled for this repository by the repository owner. 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@ymc9
Copy link
Member Author

ymc9 commented Apr 17, 2024

Fixes #1265

@ymc9 ymc9 merged commit b19bbab into v2 Apr 17, 2024
12 checks passed
@ymc9 ymc9 deleted the issue/1265 branch April 17, 2024 03:38
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