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

feat(enhance): Prisma Pulse support #1658

Merged
merged 1 commit into from
Aug 24, 2024
Merged

feat(enhance): Prisma Pulse support #1658

merged 1 commit into from
Aug 24, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Aug 23, 2024

Fixes #1473

Copy link
Contributor

coderabbitai bot commented Aug 23, 2024

Walkthrough

Walkthrough

The code changes involve significant modifications to several classes and methods related to data handling and processing logic in a Prisma-based application. Key updates include the introduction of a new streaming capability, enhancements to the existing subscription methods, and refinements to authorization logic. Additionally, new tests have been implemented to validate policy enforcement and data integrity across various scenarios.

Changes

File Change Summary
packages/runtime/src/enhancements/omit.ts Updated OmitHandler.processResultEntity to accept an additional method parameter, enhancing data processing.
packages/runtime/src/enhancements/policy/handler.ts Refactored subscribe and stream methods into handleSubscribeStream to reduce redundancy and improve maintainability.
packages/runtime/src/enhancements/policy/policy-utils.ts Modified authorization logic to set args.where to makeFalse() when injectAuthGuardAsWhere returns false.
packages/runtime/src/enhancements/proxy.ts Added stream method to PrismaProxyHandler and updated related methods for enhanced data handling.
packages/runtime/src/types.ts Introduced stream method to DbOperations interface for streaming operations.
packages/testtools/src/schema.ts Updated the loadSchema function for dynamic module loading and command execution with a new option to allow data loss.
tests/integration/tests/enhancements/with-policy/prisma-pulse.test.ts Added tests for policy enforcement in a Prisma application, covering various scenarios and ensuring security measures.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PrismaProxyHandler
    participant OmitHandler
    participant PolicyProxyHandler
    participant DbOperations

    User->>PrismaProxyHandler: Call stream(args)
    PrismaProxyHandler->>PolicyProxyHandler: handleSubscribeStream('stream', args)
    PolicyProxyHandler->>OmitHandler: processResultEntity(method, data)
    OmitHandler-->>PolicyProxyHandler: Return processed data
    PolicyProxyHandler-->>PrismaProxyHandler: Return subscription data
    PrismaProxyHandler-->>User: Return results
Loading

Assessment against linked issues

Objective Addressed Explanation
Access control for Prisma Pulse (Issue #1473)

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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40ea9fa and 5c85c24.

Files selected for processing (7)
  • packages/runtime/src/enhancements/omit.ts (1 hunks)
  • packages/runtime/src/enhancements/policy/handler.ts (1 hunks)
  • packages/runtime/src/enhancements/policy/policy-utils.ts (1 hunks)
  • packages/runtime/src/enhancements/proxy.ts (4 hunks)
  • packages/runtime/src/types.ts (1 hunks)
  • packages/testtools/src/schema.ts (3 hunks)
  • tests/integration/tests/enhancements/with-policy/prisma-pulse.test.ts (1 hunks)
Additional comments not posted (15)
packages/runtime/src/types.ts (1)

26-26: Addition of stream method is appropriate.

The introduction of the stream method in the DbOperations interface is consistent with the existing method signatures and aligns with the PR objectives.

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

29-60: Enhanced handling of subscribe and stream methods is effective.

The changes to the processResultEntity method improve its ability to handle different data processing scenarios based on the method parameter. This enhances the functionality and control flow.

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

58-58: Addition of stream method to PrismaProxyHandler is appropriate.

The introduction of the stream method enhances the interface's functionality and aligns with the PR objectives.


169-190: Implementation of doSubscribeStream method is well-structured.

The doSubscribeStream method effectively handles both subscription and streaming, ensuring proper processing of iteration results.

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

240-240: Caution: Potential data loss with --accept-data-loss.

The addition of --accept-data-loss in the prisma db push command allows for data loss during the operation. Ensure that this is intentional and properly documented to avoid unintended consequences.


392-395: LGTM: Dynamic module loading with loadModule.

The loadModule function enhances modularity by dynamically resolving module paths. This approach improves error handling and path resolution.

tests/integration/tests/enhancements/with-policy/prisma-pulse.test.ts (6)

20-77: LGTM: Comprehensive authorization check test.

The test case effectively verifies authorization checks for the stream API, covering both anonymous and authenticated user scenarios.


79-132: LGTM: Thorough model-level policy test.

The test case effectively validates model-level policies using the stream API, ensuring policy enforcement based on model attributes.


134-187: LGTM: Effective partial subscription test.

The test case successfully validates the partial subscription functionality of the stream API.


189-257: LGTM: Comprehensive policy and filter combination test.

The test case thoroughly evaluates the interaction between policies and user-provided filters using the stream API.


259-309: LGTM: Field-level policy enforcement test.

The test case effectively validates field-level policy enforcement using the stream API.


311-364: LGTM: @omit directive test.

The test case successfully verifies the functionality of the @omit directive using the stream API.

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

598-598: LGTM! Explicitly setting args.where to false enhances clarity.

The change ensures that no records are returned when authorization fails, improving the robustness of the authorization logic.

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

1542-1543: Refactored subscribe method looks good.

The refactoring to use handleSubscribeStream improves maintainability by centralizing logic.


1546-1547: Refactored stream method looks good.

The refactoring to use handleSubscribeStream improves maintainability by centralizing logic.

@ymc9 ymc9 merged commit 32c258c into dev Aug 24, 2024
13 checks passed
@ymc9 ymc9 deleted the feat/prisma-pulse branch August 24, 2024 00:15
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