Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 9, 2024

No description provided.

benjamintd and others added 18 commits June 27, 2024 19:24
Co-authored-by: Yiming <yiming@whimslab.io>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
@gitguardian
Copy link

gitguardian bot commented Jul 9, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

Walkthrough

This update primarily involves the version upgrade of Node.js and pnpm across several workflow files and documentation. It also introduces various enhancements and bug fixes in the codebase, including improvements in object cloning, generation of model hooks, and reordering of enhancements for better processing flow. Additionally, a new contributor is acknowledged, and the description of ZenStack is refined.

Changes

File(s) Summary of Changes
.github/.../build-test.yml, .github/.../integration-test.yml, .github/.../regression-test.yml Updated pnpm version to 9.4.0 from ^7.15.0.
CONTRIBUTING.md Updated Node.js version requirement to v20 and pnpm to v9.4.0.
README.md Enhanced ZenStack description and added a new contributor, Ulric.
packages/ide/.../build.gradle.kts Updated version from "2.2.4" to "2.3.0".
packages/plugins/swr/.../generator.ts, packages/plugins/tanstack-query/.../generator.ts, packages/plugins/trpc/.../generator.ts Added checks for delegate models to exclude certain operations during model hook generation.
packages/plugins/tanstack-query/.../plugin.test.ts Added options to functions calls to enhance testing capabilities.
packages/runtime/.../clone.ts Implemented deep cloning logic for arrays and plain objects.
packages/runtime/.../index.ts Added clone module export.
packages/runtime/.../mutator.ts, packages/runtime/.../default-auth.ts, packages/runtime/.../delegate.ts, packages/runtime/.../proxy.ts Replaced deepcopy with clone.
packages/runtime/.../create-enhancement.ts Reordered password and policy enhancements for better processing flow.
packages/runtime/.../policy/handler.ts, packages/runtime/.../policy/policy-utils.ts Updated argument handling and validation logic, replaced clone with safeClone for argument safety.
packages/runtime/.../query-utils.ts Added safeClone method to QueryUtils.
packages/runtime/.../utils.ts Removed clone function.
packages/schema/.../actions/generate.ts Modified task execution logic for plugins and version checks.
packages/schema/.../actions/info.ts Improved error handling for fetching the latest version.
packages/sdk/.../index.ts Added export for names module.
packages/sdk/.../model-meta-generator.ts, packages/sdk/.../utils.ts Added getInheritedFromDelegate function.
packages/testtools/.../schema.ts Added prismaClientOptions to SchemaLoadOptions.
script/test-scaffold.ts Updated package versions for prisma and @prisma/client.

Possibly related issues


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 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.
    • @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 as 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.

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.

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

Outside diff range and nitpick comments (4)
packages/sdk/src/typescript-expression-transformer.ts (1)

279-279: Add a comment to explain the purpose of the check function.

Adding a comment will help future developers understand the function's purpose and usage.

packages/schema/src/plugins/enhancer/policy/utils.ts (3)

123-123: Add a comment to explain the purpose of the generateSelectForRules function.

Adding a comment will help future developers understand the function's purpose and usage.


129-129: Use a more descriptive variable name than result.

Using a more descriptive name will improve readability.

-    let result: any = {};
+    let selectObject: any = {};

267-291: Add a comment to explain the purpose of the generateConstantQueryGuardFunction function.

Adding a comment will help future developers understand the function's purpose and usage.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b06cee6 and 366d6a6.

Files ignored due to path filters (18)
  • 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/server/tsconfig.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 (54)
  • .github/workflows/build-test.yml (1 hunks)
  • .github/workflows/integration-test.yml (1 hunks)
  • .github/workflows/regression-test.yml (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • README.md (2 hunks)
  • packages/ide/jetbrains/build.gradle.kts (1 hunks)
  • packages/plugins/swr/src/generator.ts (3 hunks)
  • packages/plugins/tanstack-query/src/generator.ts (5 hunks)
  • packages/plugins/tanstack-query/tests/plugin.test.ts (3 hunks)
  • packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx (1 hunks)
  • packages/plugins/tanstack-query/tests/react-hooks.test.tsx (1 hunks)
  • packages/plugins/trpc/src/generator.ts (2 hunks)
  • packages/runtime/src/cross/clone.ts (1 hunks)
  • packages/runtime/src/cross/index.ts (1 hunks)
  • packages/runtime/src/cross/mutator.ts (3 hunks)
  • packages/runtime/src/enhancements/create-enhancement.ts (2 hunks)
  • packages/runtime/src/enhancements/default-auth.ts (2 hunks)
  • packages/runtime/src/enhancements/delegate.ts (17 hunks)
  • packages/runtime/src/enhancements/policy/handler.ts (17 hunks)
  • packages/runtime/src/enhancements/policy/policy-utils.ts (9 hunks)
  • packages/runtime/src/enhancements/proxy.ts (2 hunks)
  • packages/runtime/src/enhancements/query-utils.ts (3 hunks)
  • packages/runtime/src/enhancements/utils.ts (2 hunks)
  • packages/schema/src/cli/actions/generate.ts (1 hunks)
  • packages/schema/src/cli/actions/info.ts (2 hunks)
  • packages/schema/src/cli/cli-util.ts (3 hunks)
  • packages/schema/src/cli/plugin-runner.ts (1 hunks)
  • packages/schema/src/language-server/validator/attribute-application-validator.ts (1 hunks)
  • packages/schema/src/language-server/validator/function-invocation-validator.ts (4 hunks)
  • packages/schema/src/language-server/zmodel-formatter.ts (1 hunks)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
  • packages/schema/src/plugins/enhancer/policy/expression-writer.ts (10 hunks)
  • packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts (13 hunks)
  • packages/schema/src/plugins/enhancer/policy/utils.ts (10 hunks)
  • packages/schema/src/plugins/prisma/index.ts (2 hunks)
  • packages/schema/src/plugins/prisma/schema-generator.ts (2 hunks)
  • packages/schema/src/res/stdlib.zmodel (1 hunks)
  • packages/schema/src/utils/ast-utils.ts (1 hunks)
  • packages/schema/tests/generator/expression-writer.test.ts (1 hunks)
  • packages/sdk/src/index.ts (1 hunks)
  • packages/sdk/src/model-meta-generator.ts (3 hunks)
  • packages/sdk/src/names.ts (1 hunks)
  • packages/sdk/src/typescript-expression-transformer.ts (4 hunks)
  • packages/sdk/src/utils.ts (1 hunks)
  • packages/testtools/src/schema.ts (2 hunks)
  • script/test-scaffold.ts (1 hunks)
  • tests/integration/tests/cli/format.test.ts (4 hunks)
  • tests/integration/tests/cli/plugins.test.ts (2 hunks)
  • tests/integration/tests/enhancements/with-delegate/plugin-interaction.test.ts (1 hunks)
  • tests/integration/tests/enhancements/with-password/with-password.test.ts (2 hunks)
  • tests/integration/tests/enhancements/with-policy/field-validation.test.ts (1 hunks)
  • tests/integration/tests/enhancements/with-policy/postgres.test.ts (1 hunks)
  • tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2 hunks)
  • tests/integration/tests/enhancements/with-policy/relation-check.test.ts (1 hunks)
Files not processed due to max files limit (8)
  • tests/integration/tests/enhancements/with-policy/todo-sample.test.ts
  • tests/integration/tests/frameworks/nextjs/generation.test.ts
  • tests/integration/tests/frameworks/trpc/generation.test.ts
  • tests/regression/tests/issue-1493.test.ts
  • tests/regression/tests/issue-1530.test.ts
  • tests/regression/tests/issue-1533.test.ts
  • tests/regression/tests/issue-1560.test.ts
  • tests/regression/tests/issue-925.test.ts
Files skipped from review due to trivial changes (12)
  • .github/workflows/build-test.yml
  • .github/workflows/integration-test.yml
  • .github/workflows/regression-test.yml
  • packages/ide/jetbrains/build.gradle.kts
  • packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx
  • packages/plugins/tanstack-query/tests/react-hooks.test.tsx
  • packages/runtime/src/enhancements/default-auth.ts
  • packages/runtime/src/enhancements/utils.ts
  • packages/schema/src/language-server/validator/attribute-application-validator.ts
  • packages/sdk/src/index.ts
  • tests/integration/tests/cli/plugins.test.ts
  • tests/integration/tests/enhancements/with-policy/postgres.test.ts
Additional context used
LanguageTool
CONTRIBUTING.md

[uncategorized] ~12-~12: Loose punctuation mark.
Context: ...commands. - ZENSTACK_TEST_DB_USER`: The postgres username, for a user with ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~13-~13: Loose punctuation mark.
Context: ... postgres. - ZENSTACK_TEST_DB_PASS: Password for said user. Default: `abc12...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~14-~14: Loose punctuation mark.
Context: ...t: abc123. - ZENSTACK_TEST_DB_NAME: Default database to connect onto. This ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~15-~15: Loose punctuation mark.
Context: ... postgres. - ZENSTACK_TEST_DB_HOST: Hostname or IP to connect onto. Default...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~16-~16: Loose punctuation mark.
Context: ...localhost. - ZENSTACK_TEST_DB_PORT: Port number to connect onto. Default: `...

(UNLIKELY_OPENING_PUNCTUATION)

Biome
packages/runtime/src/enhancements/policy/handler.ts

[error] 1203-1203: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

Additional comments not posted (124)
packages/runtime/src/cross/index.ts (1)

1-1: Export of clone function added.

The addition of the clone function to the exports is straightforward and aligns with the context of replacing the deepcopy function.

script/test-scaffold.ts (1)

22-22: Updated package versions for test scaffold.

The change ensures that the test scaffold uses specific versions of prisma and @prisma/client, which helps maintain consistency in testing.

packages/runtime/src/cross/clone.ts (1)

1-25: Introduction of clone function for deep cloning.

The clone function is well-implemented to handle cloning of arrays and plain objects, ensuring deeper and safer cloning.

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

1-25: Introduction of functions for generating function names.

The functions getQueryGuardFunctionName and getEntityCheckerFunctionName are well-implemented to generate consistent and descriptive function names based on model and field details.

tests/integration/tests/enhancements/with-delegate/plugin-interaction.test.ts (3)

Line range hint 1-24:
Verify the plugin path and dependencies.

Ensure that the tanstackPlugin path and extraDependencies are correct and exist in the project.


26-40: Verify the plugin provider and dependencies.

Ensure that the provider and extraDependencies for the swr plugin are correct and exist in the project.


42-57: Verify the plugin provider and dependencies.

Ensure that the provider and extraDependencies for the trpc plugin are correct and exist in the project.

packages/schema/src/cli/actions/info.ts (2)

4-4: Verify the correctness of the import statement.

Ensure that getLatestVersion is correctly imported from cli-util and is used properly in the code.


28-45: Verify the correctness of the version check logic.

Ensure that the logic for checking the latest version of ZenStack packages is correct and handles errors properly.

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

Line range hint 25-38:
Verify the correctness of the schema setup and expected output.

Ensure that the schema setup and expected output for the basic format test case are correct.


Line range hint 52-65:
Verify the correctness of the schema setup and expected output.

Ensure that the schema setup and expected output for the prisma format test case are correct.

packages/schema/src/cli/actions/generate.ts (2)

46-46: Verify the correctness of the plugin runner logic.

Ensure that the logic for running plugins is correct and handles errors properly.


49-51: Verify the correctness of the version check logic.

Ensure that the logic for checking the new version of ZenStack packages is correct and handles errors properly.

tests/integration/tests/enhancements/with-password/with-password.test.ts (2)

Line range hint 16-42:
LGTM!

The password tests verify the creation and update of a user password correctly.


43-95: LGTM!

The length tests verify the password length and prefix constraints correctly.

tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2)

Line range hint 4-57:
LGTM!

The per query test case verifies the omit functionality on a per-query basis correctly.


58-122: LGTM!

The global test case verifies the omit functionality on a global basis correctly.

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

64-69: LGTM!

The warning message is clear and informative, ensuring users are aware of the potential impact of skipping Prisma client generation.

CONTRIBUTING.md (1)

7-8: LGTM!

The updated prerequisites for Node.js and pnpm versions are correct and align with the new requirements.

packages/schema/src/language-server/zmodel-formatter.ts (1)

108-120: LGTM!

The changes in the method getFieldTypeLength correctly handle different scenarios for determining the length of a field's type.

packages/runtime/src/enhancements/create-enhancement.ts (1)

151-156: LGTM!

The changes ensure that password enhancement is applied before policy enhancements, which is logical to prevent validation issues due to field length changes.

packages/runtime/src/cross/mutator.ts (1)

203-203: LGTM!

The use of clone to ensure new object identity is a good practice to prevent unintended side effects.

packages/runtime/src/enhancements/query-utils.ts (1)

214-216: LGTM!

The safeClone method correctly clones an object and ensures it's not empty.

packages/schema/src/language-server/validator/function-invocation-validator.ts (5)

3-3: Imports look good.

The added imports for DataModel, DataModelAttribute, and DataModelFieldAttribute are appropriate.


11-11: Imports look good.

The added imports for isDataModel, isDataModelAttribute, and isDataModelFieldAttribute are appropriate.


20-20: Import looks good.

The added import for getDataModelFieldReference is appropriate.


124-129: LGTM! But verify the function usage in the codebase.

The added logic for validating function invocation context and arguments is well-implemented.

However, ensure that all function invocations match the new validation rules.


193-264: LGTM! But verify the function usage in the codebase.

The added function _checkCheck with the @func('check') decorator is well-implemented.

However, ensure that all check function invocations match the new validation rules.

packages/schema/src/utils/ast-utils.ts (1)

154-156: Function isCheckInvocation looks good.

The function correctly checks if a node is a check function invocation.

README.md (2)

29-29: Documentation update looks good.

The updated README clearly emphasizes ZenStack's enhanced features for Prisma ORM.


237-237: Acknowledgment update looks good.

The new contributor Ulric is appropriately added to the acknowledgments section.

packages/plugins/tanstack-query/tests/plugin.test.ts (4)

57-57: Function call update looks good.

The additional options for useFindFirstpost_Item enhance its functionality.


65-65: Function call update looks good.

The additional options for useInfiniteFindManypost_Item enhance its functionality.


146-146: Function call update looks good.

The additional options for useFindFirstpost_Item enhance its functionality.


153-153: Function call update looks good.

The additional options for useInfiniteFindManypost_Item enhance its functionality.

packages/runtime/src/enhancements/proxy.ts (1)

5-5: LGTM! Verify the functionality of the clone function.

The deepcopy function has been replaced with the clone function. Ensure that clone provides the necessary deep cloning functionality.
[approved, verify]

Also applies to: 77-77

packages/testtools/src/schema.ts (2)

137-137: LGTM! Addition of prismaClientOptions to SchemaLoadOptions.

The addition of prismaClientOptions to SchemaLoadOptions is correctly implemented.


258-263: LGTM! Handling of prismaClientOptions in loadSchema.

The loadSchema function has been correctly updated to handle prismaClientOptions.

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

22-23: LGTM! Addition of CHECK_VERSION_TIMEOUT.

The addition of the CHECK_VERSION_TIMEOUT constant is correctly implemented.


271-278: LGTM! Updates to checkNewVersion function.

The updates to the checkNewVersion function, including the try-catch block and handling the latest version, are correctly implemented.


284-300: LGTM! Implementation of getLatestVersion function.

The getLatestVersion function is correctly implemented to fetch the latest version from the npm registry.

packages/schema/src/cli/plugin-runner.ts (1)

346-350: LGTM! Updates to getPluginModulePath method.

The updates to the getPluginModulePath method to handle a test environment are correctly implemented.

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

4-4: Import Addition: isDelegateModel

The isDelegateModel import was added. This function is used to check if a model is a delegate model.


291-295: Addition of Delegate Model Check

The generateModelCreateRouter function now includes a check for delegate models to exclude create and upsert operations.


300-304: Conditional Exclusion of Create and Upsert Operations

The code now conditionally excludes create and upsert operations for delegate models, ensuring that these operations are not generated where they are not supported.

packages/plugins/swr/src/generator.ts (4)

8-8: Import Addition: isDelegateModel

The isDelegateModel import was added. This function is used to check if a model is a delegate model.


81-85: Addition of Delegate Model Check for Create Operation

The generateModelHooks function now includes a check for delegate models to exclude the create operation, ensuring that this operation is not generated where it is not supported.


91-91: Addition of Delegate Model Check for CreateMany Operation

The generateModelHooks function now includes a check for delegate models to exclude the createMany operation, ensuring that this operation is not generated where it is not supported.


144-144: Addition of Delegate Model Check for Upsert Operation

The generateModelHooks function now includes a check for delegate models to exclude the upsert operation, ensuring that this operation is not generated where it is not supported.

packages/sdk/src/model-meta-generator.ts (2)

270-273: Handling of Fields Inherited from Delegate Models

The writeFields function now includes logic to handle fields inherited from delegate models, ensuring that these fields are correctly included in the metadata.


Line range hint 561-571:
Addition of getInheritedFromDelegate Function

The getInheritedFromDelegate function was added to find the original delegate base model that defines a given field. This is useful for accurate metadata generation.

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

561-571: Addition of getInheritedFromDelegate Function

The getInheritedFromDelegate function was added to find the original delegate base model that defines a given field. This is useful for accurate metadata generation.

packages/sdk/src/typescript-expression-transformer.ts (1)

308-309: Ensure the checker function name is correctly generated.

The function name generation seems correct, but ensure that getEntityCheckerFunctionName handles all edge cases.

packages/schema/src/plugins/enhancer/policy/utils.ts (2)

237-257: Ensure the handling of check calls is correct.

The handling of check calls seems correct, but ensure that generateSelectForRules is correctly handling nested check calls.


287-287: Ensure the return type is correct.

The return type is currently any. Ensure this is intentional and consider using a more specific type if possible.

packages/schema/src/res/stdlib.zmodel (1)

669-677: Verify the missing implementation of check function.

The function check is declared but not implemented. Ensure this is intentional, or provide the implementation.

packages/plugins/tanstack-query/src/generator.ts (3)

9-9: Import addition looks good.

The import isDelegateModel is correctly added.


345-349: LGTM! Verify the correct usage of isDelegateModel.

The check for delegate models before generating create mutations is correctly implemented.

Ensure that isDelegateModel is correctly used throughout the codebase.


428-428: LGTM! Verify the correct usage of isDelegateModel.

The check for delegate models before generating upsert mutations is correctly implemented.

Ensure that isDelegateModel is correctly used throughout the codebase.

packages/schema/src/plugins/enhancer/policy/policy-guard-generator.ts (4)

248-248: LGTM!

The addition of operationContext to the transformer in generateCreateInputCheckerFunction is appropriate.


325-325: LGTM!

The addition of preUpdateSelector in writePostUpdatePreValueSelector is necessary and correctly implemented.


434-435: LGTM!

The addition of selector in writeEntityChecker is appropriate and correctly implemented.


Line range hint 372-413: LGTM!

The updates to shouldUseEntityChecker for checking cross-model comparisons are necessary and correctly implemented.

tests/integration/tests/enhancements/with-policy/field-validation.test.ts (5)

12-12: Ensure proper password validation.

The password validation rule @password @length(8, 16) is applied correctly, but make sure that all edge cases, such as minimum and maximum lengths, are covered in your tests.


Line range hint 287-287:
Verify model-level validation rules.

The validation rules for the Model are applied correctly. Ensure that all edge cases are covered in your tests, especially for optional fields and complex expressions.


Line range hint 492-492:
Ensure proper interaction between policy and validation rules.

The interaction between policy and validation rules for the User model is tested correctly. Ensure that all edge cases, such as conflicting rules, are covered in your tests.


Line range hint 442-442:
Ensure proper validation for array fields.

The validation rules for array fields in the Model are applied correctly. Ensure that all edge cases, such as empty arrays and null values, are covered in your tests.


Line range hint 392-392:
Ensure proper validation for scalar fields.

The validation rules for scalar fields in the Model are applied correctly. Ensure that all edge cases, such as invalid values and null values, are covered in your tests.

packages/schema/src/plugins/enhancer/policy/expression-writer.ts (1)

789-821: LGTM! Added function writeRelationCheck is well-implemented.

The function correctly validates the arguments and generates the appropriate query guard function call.

packages/schema/src/plugins/prisma/schema-generator.ts (1)

265-268: LGTM! Changes in generateModel correctly handle fields inherited from delegate models.

The function now properly excludes these fields from the physical schema while retaining them in the logical schema.

packages/schema/tests/generator/expression-writer.test.ts (1)

Line range hint 372-372:
LGTM!

The addition of operationContext: 'read' to the ExpressionWriter initialization enhances the context specificity.

packages/runtime/src/enhancements/delegate.ts (16)

16-16: LGTM!

The import statement correctly adds the clone function from ../cross.


75-75: LGTM!

The replacement of deepcopy with clone in the doFind method improves the object handling.


145-145: LGTM!

The replacement of deepcopy with clone in the buildWhereHierarchy method improves the object handling.


220-220: LGTM!

The replacement of deepcopy with clone in the buildSelectIncludeHierarchy method improves the object handling.


411-411: LGTM!

The replacement of deepcopy with clone in the doCreate method improves the object handling.


627-627: LGTM!

The replacement of deepcopy with clone in the upsert method improves the object handling.


645-645: LGTM!

The replacement of deepcopy with clone in the doUpdate method improves the object handling.


665-665: LGTM!

The replacement of deepcopy with clone in the doUpdateMany method improves the object handling.


675-675: LGTM!

The replacement of deepcopy with clone in the doUpdateMany method improves the object handling.


686-686: LGTM!

The replacement of deepcopy with clone in the doUpdateMany method improves the object handling.


852-852: LGTM!

The replacement of deepcopy with clone in the delete method improves the object handling.


868-868: LGTM!

The replacement of deepcopy with clone in the doDeleteMany method improves the object handling.


921-921: LGTM!

The replacement of deepcopy with clone in the aggregate method improves the object handling.


949-949: LGTM!

The replacement of deepcopy with clone in the count method improves the object handling.


989-989: LGTM!

The replacement of deepcopy with clone in the groupBy method improves the object handling.


1030-1030: LGTM!

The replacement of deepcopy with clone in the extractSelectInclude method improves the object handling.

packages/runtime/src/enhancements/policy/policy-utils.ts (7)

6-6: LGTM!

The import statements for z, ZodError, ZodObject, and ZodSchema from zod are correct and consistent with the usage in the file.


561-561: LGTM! Verify correctness of clone function usage.

The change from deepcopy to clone is consistent with the replacement across the codebase. Ensure that the clone function is correctly imported and used.


817-817: LGTM! Verify correctness of safeClone function usage.

The change from deepcopy to safeClone is consistent with the replacement across the codebase. Ensure that the safeClone function is correctly implemented and used.


854-862: LGTM! Verify correctness of Zod schema validation.

The validateZodSchema method correctly uses the getZodSchema method for validation. Ensure that the schema validation logic is correctly implemented and handles errors appropriately.


1268-1301: LGTM! Verify correctness of schema fetching and modification.

The getZodSchema method correctly fetches and optionally modifies the Zod schema to exclude password fields. Ensure that the schema fetching and modification logic is correctly implemented.


1345-1345: LGTM! Verify correctness of safeClone function usage.

The change from deepcopy to safeClone is consistent with the replacement across the codebase. Ensure that the safeClone function is correctly implemented and used.


1007-1007: LGTM! Verify correctness of safeClone function usage.

The change from deepcopy to safeClone is consistent with the replacement across the codebase. Ensure that the safeClone function is correctly implemented and used.

packages/runtime/src/enhancements/policy/handler.ts (15)

28-28: LGTM!

The import statement is correct.


130-130: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


141-141: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


179-179: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


413-425: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


443-443: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


686-686: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1149-1149: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1236-1236: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1346-1346: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1439-1439: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1495-1495: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1513-1513: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1528-1528: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.


1564-1564: LGTM!

The use of clone to replace deepcopy for deep cloning objects is appropriate.

tests/integration/tests/enhancements/with-policy/relation-check.test.ts (13)

4-46: LGTM!

The test case for read permissions is correctly implemented.


48-87: LGTM!

The test case for simple create permissions is correctly implemented.


89-148: LGTM!

The test case for nested create permissions is correctly implemented.


150-206: LGTM!

The test case for update permissions is correctly implemented.


208-264: LGTM!

The test case for delete permissions is correctly implemented.


266-324: LGTM!

The test case for field-level read permissions is correctly implemented.


326-383: LGTM!

The test case for field-level read permissions with an override is correctly implemented.


385-441: LGTM!

The test case for cross-model field comparison is correctly implemented.


443-503: LGTM!

The test case for implicit specific operations is correctly implemented.


505-563: LGTM!

The test case for implicit all operations is correctly implemented.


565-637: LGTM!

The test case for error reporting with invalid arguments is correctly implemented.


639-671: LGTM!

The test case for error reporting with cyclic relation checks is correctly implemented.


673-702: LGTM!

The test case for error reporting with indirect cyclic relation checks is correctly implemented.

packages/schema/src/plugins/enhancer/enhance/index.ts (2)

150-150: LGTM!

The import statement for InternalArgs and DynamicClientExtensionThis from Prisma's runtime library is correctly implemented.


Line range hint 157-177:
LGTM!

The code for checking Prisma version and adjusting type definitions is correctly implemented.

ymc9 and others added 2 commits July 8, 2024 23:20
…nding polymorphic relations (#1572)

Co-authored-by: Yiming <yiming@whimslab.io>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 366d6a6 and 4c6cde6.

Files ignored due to path filters (6)
  • packages/plugins/trpc/package.json is excluded by !**/*.json
  • packages/server/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
  • tests/integration/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 (3)
  • packages/schema/src/plugins/prisma/schema-generator.ts (4 hunks)
  • packages/server/tests/adapter/next.test.ts (1 hunks)
  • tests/regression/tests/issue-1575.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/schema/src/plugins/prisma/schema-generator.ts
Additional comments not posted (5)
tests/regression/tests/issue-1575.test.ts (1)

1-28: LGTM!

The regression test for issue 1575 appears to be well-formed and correctly uses the loadSchema function to validate the model setup.

packages/server/tests/adapter/next.test.ts (4)

Line range hint 18-102:
LGTM!

The test case for simple CRUD operations appears to be comprehensive and correctly validates the functionality of the Next.js adapter.


Line range hint 104-128:
LGTM!

The test case for custom load paths appears to be well-formed and correctly validates the functionality of the Next.js adapter.


Line range hint 130-198:
LGTM!

The test case for access policy CRUD operations appears to be comprehensive and correctly validates the functionality of the Next.js adapter.


Line range hint 200-272:
LGTM!

The test case for REST handler operations appears to be comprehensive and correctly validates the functionality of the Next.js adapter.

@ymc9 ymc9 added this pull request to the merge queue Jul 12, 2024
Merged via the queue into main with commit 06e87f8 Jul 12, 2024
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.

5 participants