Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented May 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of table aliases in policy enforcement, ensuring accurate access control in complex queries.
    • Enhanced default value provider handling for schema fields, supporting more robust and expressive schema definitions.
  • Refactor

    • Streamlined internal logic for model context tracking, query transformation, and expression handling to improve maintainability and consistency.
    • Updated test setups to use in-memory databases for faster and more isolated test runs.
  • Tests

    • Expanded and refactored policy tests for todo lists and related entities, providing more comprehensive coverage of authorization scenarios.
    • Updated test schemas and utilities to align with new default value handling and database configuration.

@coderabbitai
Copy link

coderabbitai bot commented May 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces several improvements across the codebase. Default value expressions in schemas and tests are refactored to use the Expression.call API. Policy enforcement logic is enhanced to support table aliases, with related changes in the expression transformer and policy handler. Name mapping logic now uses a stack-based model context for nested queries. SQLite and test schemas are updated to use in-memory databases.

Changes

Files/Groups Change Summary
packages/cli/test/ts-schema-gen.test.ts, packages/runtime/test/client-api/default-value-providers.test.ts, packages/runtime/test/client-api/name-mapping.test.ts Refactored schema default value expressions to use Expression.call instead of object literals for function calls (e.g., uuid(), cuid()).
packages/runtime/src/client/crud/dialects/sqlite.ts Replaced inner expression builder parameter in buildRelationJSON with usage of the outer parameter, simplifying the method.
packages/runtime/src/client/crud/operations/find.ts Removed unnecessary runQuery method; handle now calls read directly.
packages/runtime/src/client/executor/name-mapper.ts Switched from a single currentModel property to a stack-based modelStack for nested model context tracking; updated all relevant methods.
packages/runtime/src/plugins/policy/expression-transformer.ts Added alias support to the expression transformer context and column reference creation; refactored relation and member handling for alias awareness.
packages/runtime/src/plugins/policy/policy-handler.ts Enhanced policy filter and condition building to support table aliases; updated table name extraction and related method signatures.
packages/runtime/test/policy/todo-sample.test.ts Refactored and expanded policy tests for todo app, adding comprehensive CRUD and authorization scenarios, new helpers, and standardized client setup.
packages/runtime/test/schemas/todo.zmodel, packages/testtools/src/schema.ts Changed SQLite datasource URLs from file-based to in-memory databases for transient testing.
packages/sdk/src/ts-schema-generator.ts Refined TypeScript code generation to conditionally include arguments for default value calls and handle in-memory SQLite database paths appropriately.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PolicyHandler
    participant ExpressionTransformer

    Client->>PolicyHandler: transformSelectQuery(query)
    PolicyHandler->>PolicyHandler: extractTableName(from)
    PolicyHandler->>PolicyHandler: buildPolicyFilter(model, alias, operation)
    PolicyHandler->>ExpressionTransformer: transformPolicyCondition(model, alias, policy)
    ExpressionTransformer->>ExpressionTransformer: createColumnRef(column, context with alias)
    ExpressionTransformer-->>PolicyHandler: returns transformed condition
    PolicyHandler-->>Client: returns transformed query with policy filters
Loading

Possibly related PRs

  • zenstackhq/zenstack-v3#2: Introduces support for auth() in field defaults and changes expression handling, related to default value expression representation.

Poem

🐇
In memory now our data lives,
With Expression.call, new power it gives.
Policies know aliases, fields map with care,
Tests hop further, permissions laid bare.
Stacks for models, helpers in tow—
A garden of code where new features grow!
🌱

Tip

⚡️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e6e52c and 4c605eb.

📒 Files selected for processing (12)
  • packages/cli/test/ts-schema-gen.test.ts (4 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (5 hunks)
  • packages/runtime/src/client/crud/operations/find.ts (1 hunks)
  • packages/runtime/src/client/executor/name-mapper.ts (10 hunks)
  • packages/runtime/src/plugins/policy/expression-transformer.ts (10 hunks)
  • packages/runtime/src/plugins/policy/policy-handler.ts (9 hunks)
  • packages/runtime/test/client-api/default-value-providers.test.ts (2 hunks)
  • packages/runtime/test/client-api/name-mapping.test.ts (2 hunks)
  • packages/runtime/test/policy/todo-sample.test.ts (4 hunks)
  • packages/runtime/test/schemas/todo.zmodel (1 hunks)
  • packages/sdk/src/ts-schema-generator.ts (2 hunks)
  • packages/testtools/src/schema.ts (1 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 e35a0ae into dev May 13, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 1, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jun 13, 2025
@ymc9 ymc9 deleted the feat/policy-3 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