Skip to content

Conversation

@jasonmacdonald
Copy link
Contributor

Support for receiving the property used to trigger getEnhancedPrisma for the NestJS module. This is in relation to feature request #1537

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

Walkthrough

The recent updates to the ZenStackModuleOptions interface in zenstack.module.ts involve adding an optional parameter to the getEnhancedPrisma function signature. Consequently, the ZenStackModule class has been modified to pass this parameter when calling getEnhancedPrisma. A new test case was added to ensure the proper functioning of this change during service initialization.

Changes

File Path Change Summary
packages/server/src/nestjs/zenstack.module.ts Updated ZenStackModuleOptions interface and ZenStackModule class to include and use an optional parameter in getEnhancedPrisma.
packages/server/tests/adapter/nestjs.test.ts Added a new test case to verify the functionality of passing a property during service initialization.

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

Outside diff range and nitpick comments (1)
packages/server/src/nestjs/zenstack.module.ts (1)

Line range hint 53-98: Consider refactoring to avoid static-only class structure.

The static analysis tool has flagged the ZenStackModule as a class that only contains static members, which is generally discouraged as it can limit testing and flexibility.

Consider converting the static methods to top-level functions if feasible, or introducing instance methods or properties to justify the use of a class structure.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3e77974 and aee73cc.

Files selected for processing (2)
  • packages/server/src/nestjs/zenstack.module.ts (2 hunks)
  • packages/server/tests/adapter/nestjs.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/server/tests/adapter/nestjs.test.ts
Additional context used
Biome
packages/server/src/nestjs/zenstack.module.ts

[error] 53-98: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

Additional comments not posted (2)
packages/server/src/nestjs/zenstack.module.ts (2)

15-15: Update to ZenStackModuleOptions interface approved.

The addition of the optional parameter prop to getEnhancedPrisma method aligns with the PR objectives and enhances flexibility in the usage of the method.


82-82: Correct implementation of dynamic property handling in getEnhancedPrisma.

The implementation correctly uses the prop parameter to enhance the Prisma client dynamically. This should allow for more flexible and powerful usage scenarios.

@jasonmacdonald
Copy link
Contributor Author

Hmm, I'm not sure why those regressions are failing. I didn't touch anything related to the generated enhance file.

* A callback for getting an enhanced `PrismaClient`.
*/
getEnhancedPrisma: () => unknown;
getEnhancedPrisma: (prop?: string | symbol) => unknown;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we rename prop to model instead so it's meaning is clearer? Also, I think in this case it's always typed as string. Maybe remove the | symbol part so the user can have a simpler callback signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll update this in this tomorrow and push it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Contributor Author

@jasonmacdonald jasonmacdonald Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it looks like not including symbol causes a type error.

 Error: packages/server build: src/nestjs/zenstack.module.ts(82,83): error TS2345: Argument of type 'string | symbol' is not assignable to parameter of type 'string | undefined'.

https://github.com/zenstackhq/zenstack/actions/runs/9877836393/job/27280399900?pr=1538

This is likely because the prop from Proxy is typed as string | symbol, which is why I think I had set that earlier. I'll revert that change for now.

@ymc9
Copy link
Member

ymc9 commented Jun 27, 2024

Hi @jasonmacdonald , thanks for implementing this FR. The change looks good to me, and I've left a comment about the callback signature. Could you take a look?

I think the test failure is due to the current test scaffolding not pinning Prisma dependencies to their minor versions. Prisma 5.16 introduced a breaking change. I've made a fix to the dev branch. Could you merge it to your branch and push again? The errors should go awai then.

@jasonmacdonald
Copy link
Contributor Author

@ymc9 I pushed the requested update. Sorry for the delay.

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 aee73cc and 970f481.

Files selected for processing (1)
  • packages/server/src/nestjs/zenstack.module.ts (2 hunks)
Additional comments not posted (2)
packages/server/src/nestjs/zenstack.module.ts (2)

15-15: LGTM! The optional parameter addition is well-implemented.

This update makes the model parameter optional, providing flexibility while maintaining backward compatibility.


82-82: LGTM! The optional parameter is correctly integrated.

The getEnhancedPrisma method is called with the prop argument, ensuring the optional parameter is passed correctly.

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 970f481 and ff00b25.

Files selected for processing (1)
  • packages/server/src/nestjs/zenstack.module.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/server/src/nestjs/zenstack.module.ts

@ymc9 ymc9 merged commit 4672875 into zenstackhq:dev 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.

2 participants