Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented May 15, 2025

Summary by CodeRabbit

  • New Features

    • Added support for the "Bytes" data type, including filtering, schema mapping, and result transformation.
    • Introduced built-in and custom policy functions, such as string matching (contains, startsWith, endsWith), array operations, and the now() function for time-based policies.
    • Enabled cross-field and cross-model field comparisons in policy rules.
  • Bug Fixes

    • Improved enforcement and error handling for policy rejections, ensuring proper errors are thrown when update or delete operations are denied.
  • Documentation

    • Updated breaking changes and new features documentation to reflect new policy behaviors and capabilities.
    • Expanded TODOs to track upcoming improvements in access policy and database schema handling.
  • Tests

    • Added comprehensive tests for new data types, policy functions, cross-model comparisons, and connect/disconnect operations under policy enforcement.
    • Enhanced type coverage and updated assertions for timestamp and update behaviors.
  • Refactor

    • Standardized primitive value transformation and improved policy enforcement logic for bulk operations and updates.
    • Refined expression transformation to better support arrays, function calls, and null handling.
  • Chores

    • Updated dependencies and improved internal type handling for consistency across dialects.

@coderabbitai
Copy link

coderabbitai bot commented May 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces support for new data types (notably Bytes), new filter and validation logic, and expands the query and policy function capabilities of the system. It adds comprehensive test coverage for new features, including policy enforcement on connect/disconnect operations, cross-model field comparisons, and policy-driven query functions. Several internal refactorings and type expansions are included.

Changes

File(s) Change Summary
BREAKINGCHANGES.md Updated to document that rejected update or delete policies now throw NotFoundError.
NEW-FEATURES.md Documented new features: cross-field comparison and custom policy functions.
TODO.md Added subtasks for scalar-only pre-create checks and PostgreSQL schema support.
packages/language/src/validators/expression-validator.ts Removed cross-model field comparison validation logic and associated method.
packages/language/src/validators/function-invocation-validator.ts Removed argument validation for functions in access policy/validation rule contexts.
packages/runtime/package.json Removed decimal.js-light dependency; reordered devDependencies.
packages/runtime/src/client/client-impl.ts Ensured built-in functions are included in client options, allowing user overrides.
packages/runtime/src/client/contract.ts Changed Decimal type import to use decimal.js instead of decimal.js-light.
packages/runtime/src/client/crud-types.ts Added new type alias BytesFilter for binary data filtering.
packages/runtime/src/client/crud/dialects/base.ts Added support for "Bytes" filter, new abstract getter provider, and abstract method buildArrayLength.
packages/runtime/src/client/crud/dialects/postgresql.ts Implemented provider getter and buildArrayLength for PostgreSQL.
packages/runtime/src/client/crud/dialects/sqlite.ts Implemented provider getter, buildArrayLength, and primitive transformation for Decimal and Bytes.
packages/runtime/src/client/crud/operations/base.ts Standardized primitive transformation in bulk create/update; improved timestamp handling; update returns only ID fields.
packages/runtime/src/client/crud/operations/update.ts Unified update logic into a transaction, added explicit policy rejection error, simplified result handling.
packages/runtime/src/client/crud/validator.ts Enhanced validator to support Decimal, BigInt, and new Bytes type with corresponding filter schemas.
packages/runtime/src/client/functions.ts New module exporting built-in policy/query functions (e.g., contains, startsWith, isEmpty, now).
packages/runtime/src/client/helpers/schema-db-pusher.ts Added "Bytes" field type mapping for PostgreSQL and SQLite.
packages/runtime/src/client/options.ts Added ZModelFunction type and functions property to ClientOptions.
packages/runtime/src/client/result-processor.ts Added scalar transformation for Bytes, Decimal, and BigInt types.
packages/runtime/src/plugins/policy/expression-transformer.ts Enhanced expression transformer: supports array expressions, 'in' operator, refined call/member handling, and null logic.
packages/runtime/src/plugins/policy/policy-handler.ts Refactored pre-create policy enforcement for multi-row inserts, improved value unwrapping and typing.
packages/runtime/src/schema/expression.ts Added 'in' to BinaryOperator type.
packages/runtime/src/schema/schema.ts Added 'Bytes' to BuiltinType union.
packages/runtime/test/client-api/default-values.test.ts Added test for DateTime default value using now function.
packages/runtime/test/client-api/filter.test.ts Added TODO comment for bigint, decimal, and bytes filter tests.
packages/runtime/test/client-api/name-mapping.test.ts, packages/runtime/test/plugin/kysely-on-query.test.ts, packages/runtime/test/policy/auth.test.ts Removed query logging from client instantiation in tests.
packages/runtime/test/client-api/type-coverage.test.ts Added comprehensive test for all supported types, including Bytes.
packages/runtime/test/client-api/update.test.ts Enhanced update tests with timestamp assertions, commented out cascade delete tests.
packages/runtime/test/policy/connect-disconnect.test.ts New test suite for connect/disconnect operations with policy enforcement across various relation types.
packages/runtime/test/policy/create-many-and-return.test.ts New test suite for createManyAndReturn under policy enforcement, including field-level and model-level policies.
packages/runtime/test/policy/cross-model-field-comparison.test.ts New test suite for cross-model field comparison policy enforcement across CRUD operations.
packages/runtime/test/policy/policy-functions.test.ts New test suite for policy function behavior (contains, startsWith, endsWith, in, now).
packages/runtime/test/policy/todo-sample.test.ts Renamed suite, removed logging, added skipped test for post-update checks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant BuiltinFunctions
    participant Dialect
    participant PolicyHandler
    participant Database

    User->>Client: Initiates create/update/read/delete
    Client->>BuiltinFunctions: Uses built-in or custom functions for query
    Client->>Dialect: Transforms values (Bytes, Decimal, BigInt, etc.)
    Client->>PolicyHandler: Applies policy enforcement (pre-create, update, etc.)
    PolicyHandler->>Database: Executes query if policy passes
    Database-->>PolicyHandler: Returns result or error
    PolicyHandler-->>Client: Returns result or throws error (e.g., NotFoundError)
    Client-->>User: Returns result or error
Loading
sequenceDiagram
    participant Test
    participant Client
    participant PolicyHandler
    participant Database

    Test->>Client: Perform connect/disconnect/createMany/cross-model op
    Client->>PolicyHandler: Enforce policies (including cross-model/field)
    PolicyHandler->>Database: Execute query if allowed
    Database-->>PolicyHandler: Return query result
    PolicyHandler-->>Client: Pass/fail based on policy
    Client-->>Test: Assert outcome (success or rejection)
Loading

Poem

🐇
New types and filters hop into play,
Bytes and Decimals lead the way.
Policies now compare fields afar,
And functions shine like a guiding star.
Tests abound for every case,
Ensuring the code keeps up the pace!
— A rabbit’s hop through features new and bright.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e35a0ae and 801d34c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (35)
  • BREAKINGCHANGES.md (1 hunks)
  • NEW-FEATURES.md (1 hunks)
  • TODO.md (1 hunks)
  • packages/language/src/validators/expression-validator.ts (0 hunks)
  • packages/language/src/validators/function-invocation-validator.ts (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/src/client/client-impl.ts (2 hunks)
  • packages/runtime/src/client/contract.ts (1 hunks)
  • packages/runtime/src/client/crud-types.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/base.ts (5 hunks)
  • packages/runtime/src/client/crud/dialects/postgresql.ts (2 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (4 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (6 hunks)
  • packages/runtime/src/client/crud/operations/update.ts (2 hunks)
  • packages/runtime/src/client/crud/validator.ts (5 hunks)
  • packages/runtime/src/client/functions.ts (1 hunks)
  • packages/runtime/src/client/helpers/schema-db-pusher.ts (1 hunks)
  • packages/runtime/src/client/options.ts (3 hunks)
  • packages/runtime/src/client/result-processor.ts (3 hunks)
  • packages/runtime/src/plugins/policy/expression-transformer.ts (13 hunks)
  • packages/runtime/src/plugins/policy/policy-handler.ts (7 hunks)
  • packages/runtime/src/schema/expression.ts (1 hunks)
  • packages/runtime/src/schema/schema.ts (1 hunks)
  • packages/runtime/test/client-api/default-values.test.ts (3 hunks)
  • packages/runtime/test/client-api/filter.test.ts (1 hunks)
  • packages/runtime/test/client-api/name-mapping.test.ts (2 hunks)
  • packages/runtime/test/client-api/type-coverage.test.ts (1 hunks)
  • packages/runtime/test/client-api/update.test.ts (5 hunks)
  • packages/runtime/test/plugin/kysely-on-query.test.ts (1 hunks)
  • packages/runtime/test/policy/auth.test.ts (1 hunks)
  • packages/runtime/test/policy/connect-disconnect.test.ts (1 hunks)
  • packages/runtime/test/policy/create-many-and-return.test.ts (1 hunks)
  • packages/runtime/test/policy/cross-model-field-comparison.test.ts (1 hunks)
  • packages/runtime/test/policy/policy-functions.test.ts (1 hunks)
  • packages/runtime/test/policy/todo-sample.test.ts (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

@ymc9 ymc9 merged commit 0450d8b into dev May 15, 2025
1 check passed
@ymc9 ymc9 deleted the feat/policy-4 branch November 25, 2025 00:27
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