Skip to content

fix: Update re-exports for new prisma-client generator #2184

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

Merged
merged 3 commits into from
Jul 15, 2025

Conversation

mhodgson
Copy link
Contributor

This should update the re-exporting of the Prisma logical client when using the new prisma-client generator, consistent with discussions here

Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

📝 Walkthrough

Walkthrough

The update refactors the EnhancerGenerator's generate() method into two distinct private methods to separately handle the new "prisma-client" and old "prisma-client-js" generators. It adjusts import paths, splits generated export files (models.ts, enums.ts, client.ts) for the new client, and refactors enhancement file generation for both node and edge targets. The loadSchema function and related schema compilation logic were modularized in the testtools package. Integration tests were parameterized to run against both Prisma client generator variants.

Changes

File(s) Change Summary
packages/schema/src/plugins/enhancer/enhance/index.ts Refactored generate() into generateForNewClientGenerator() and generateForOldClientGenerator(). Adjusted Prisma import paths and split exports into models.ts, enums.ts, client.ts for new client. Refactored generateEnhance() to accept parameters for import paths and target runtime. Updated import helper methods to accept optional target parameter. Generated enhancement files adjusted for logical client usage and runtime target. No core logic or error handling changes.
packages/testtools/src/schema.ts Extracted project creation and TypeScript compilation logic from loadSchema into new createProjectAndCompile function. loadSchema now handles Prisma client instantiation and runtime artifact loading separately. Modularized schema loading and project setup.
tests/integration/tests/misc/prisma-client-generator.test.ts Refactored tests to parameterize over two Prisma client generator configurations ("prisma-client-js" and "prisma-client"). Used describe.each to run tests against both variants, adapting imports and runtime verification accordingly. Unified and extended test coverage for both generator types.

Possibly related PRs

  • zenstackhq/zenstack#2177: Refactors generate() method in EnhancerGenerator with separate handling for new and old Prisma client generators, modifying the same file but focusing on performance improvements.
  • zenstackhq/zenstack#2151: Adds support and detection logic for the new "prisma-client" generator within the enhancer plugin, directly related to handling generator variants.
  • zenstackhq/zenstack#2078: Modifies logical client exports and generated model files in the EnhancerGenerator class, closely related to import path and export structure changes.

Suggested reviewers

  • ymc9
✨ 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:

‼️ 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 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
Copy link
Member

ymc9 commented Jul 15, 2025

Thanks for continuing to work on this @mhodgson . I feel this part of logic has become deeply entangled. It started when we introduced the logical client, and now with two flavors of generators 😂.

I've decided to do a local refactor based on your PR. Will make the changes, test and merge then.

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

🧹 Nitpick comments (2)
tests/integration/tests/misc/prisma-client-generator.test.ts (2)

75-76: Consider using template literals for better readability.

The conditional imports work correctly but could be more readable using template literals.

-${config.isNewGenerator ? "import type { UserModel } from '" + config.modelsLoadPath + "';" : ''}
+${config.isNewGenerator ? `import type { UserModel } from '${config.modelsLoadPath}';` : ''}
-${config.isNewGenerator ? "const user1: UserModel = { id: 1, name: 'Alice', role: 'USER' };\nconsole.log(user1);" : ''}
+${config.isNewGenerator ? `const user1: UserModel = { id: 1, name: 'Alice', role: 'USER' };\nconsole.log(user1);` : ''}

Also applies to: 81-82


168-169: Apply the same template literal improvement here for consistency.

-${config.isNewGenerator ? "import type { UserModel } from '" + config.modelsLoadPath + "';" : ''}
+${config.isNewGenerator ? `import type { UserModel } from '${config.modelsLoadPath}';` : ''}
-${config.isNewGenerator ? "const user1: UserModel = { id: 1, name: 'Alice', role: 'USER' };\nconsole.log(user1);" : ''}
+${config.isNewGenerator ? `const user1: UserModel = { id: 1, name: 'Alice', role: 'USER' };\nconsole.log(user1);` : ''}

Also applies to: 174-175

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85f8e1c and be3f72f.

📒 Files selected for processing (3)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (6 hunks)
  • packages/testtools/src/schema.ts (3 hunks)
  • tests/integration/tests/misc/prisma-client-generator.test.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/schema/src/plugins/enhancer/enhance/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/testtools/src/schema.ts (3)
packages/runtime/src/enhancements/node/types.ts (1)
  • PolicyDef (106-115)
packages/runtime/src/constants.ts (1)
  • DEFAULT_RUNTIME_LOAD_PATH (4-4)
packages/runtime/src/types.ts (2)
  • AuthUser (50-50)
  • EnhancementOptions (108-148)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: dependency-review
  • GitHub Check: build-test (20.x)
🔇 Additional comments (6)
tests/integration/tests/misc/prisma-client-generator.test.ts (3)

3-25: LGTM! Generator configurations are well-defined.

The two generator configurations correctly represent the legacy "prisma-client-js" and new "prisma-client" generators with appropriate settings for testing.


27-48: Well-structured test parameterization.

The configuration objects clearly differentiate between the two generator types with appropriate load paths and options.


49-335: Comprehensive test coverage for both generator types.

The test suite thoroughly covers module exports, client extensions, auth functionality, and delegate models for both generator configurations. The use of createProjectAndCompile helper maintains consistency across tests.

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

173-249: Clean refactoring of loadSchema function.

The separation of concerns between project compilation and runtime loading improves modularity and maintainability. The function correctly handles various configuration options including custom Prisma load paths and Pulse extension.


251-381: Well-extracted project compilation logic.

The createProjectAndCompile function effectively consolidates all project setup and compilation tasks. The extraction improves code organization and enables reuse.


363-363: Good fix: Compilation now triggers when extra source files are provided.

This change ensures that TypeScript compilation occurs whenever extraSourceFiles are provided, preventing potential runtime errors from uncompiled TypeScript files.

@ymc9 ymc9 merged commit 828a056 into zenstackhq:dev Jul 15, 2025
12 checks passed
@mhodgson
Copy link
Contributor Author

thanks! This looks great.

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