-
-
Notifications
You must be signed in to change notification settings - Fork 116
fix: improve support for new prisma-client
generator
#2171
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
Conversation
📝 WalkthroughWalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant EnhancerGenerator
participant FileSystem
participant ModelProcessor
EnhancerGenerator->>FileSystem: Generate shared json-types.ts with all JSON type definitions
loop For each model file
EnhancerGenerator->>ModelProcessor: Extract type aliases and JSON field usage
ModelProcessor-->>EnhancerGenerator: Return usage details
EnhancerGenerator->>FileSystem: Generate model type file
alt $Types used
EnhancerGenerator->>FileSystem: Add import for $Types from runtime.Types
end
alt JSON type aliases used
EnhancerGenerator->>FileSystem: Add import for relevant JSON types from json-types.ts
end
end
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Warning Review ran into problems🔥 ProblemsCheck-run timed out after 90 seconds. Some checks/pipelines were still in progress when the timeout was reached. Consider increasing the reviews.tools.github-checks.timeout_ms value in your CodeRabbit configuration to allow more time for checks to complete. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Graph Analysis (1)tests/regression/tests/issue-2168.test.ts (1)
⏰ 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)
🔇 Additional comments (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
Plan: Pro
📒 Files selected for processing (1)
packages/schema/src/plugins/enhancer/enhance/index.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: OSSAR-Scan
- GitHub Check: build-test (20.x)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: build-test (20.x)
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
🔇 Additional comments (3)
packages/schema/src/plugins/enhancer/enhance/index.ts (3)
124-127
: LGTM! Good approach to centralize JSON field types.The conditional export of the
json-fields
module for the new Prisma client generator aligns well with the centralized type definition strategy.
497-510
: Well-structured centralization of JSON type definitions.Creating a shared
json-fields.ts
file is a good architectural decision that reduces duplication and improves maintainability. The implementation correctly generates all TypeDef types in one place.
523-545
: Smart conditional import logic for $Types.The implementation thoroughly checks for
$Types
usage both in the original type and after transformation, ensuring the import is added only when necessary. This prevents missing imports while avoiding unnecessary ones.
Thanks for making the fix @genu ! These types can indeed be imported directly from "@prisma/client/runtime/library" instead. The code changes look good to me, and I'll make some minor tweaks and add a test then merge. Thank you! |
- Change the file name containing json types from "json-fields.ts" to "json-types.ts" - Fixed the import path of `DynamicClientExtensionThis` etc. to "@prisma/client/runtime/library" - Removed an unnecessary async modifier - Added a regression test case
@ymc9 From my observation, this partly resolved the issue. type inference is lost when using prisma extensions: const prisma = new PrismaClient()
const db = enhance(prisma)
db.user.find() // <-- db.user is properly typed With Enhanced client: const prisma = new PrismaClient().$extends({})
const db = enhance(prisma)
db.user.find() // <-- db.user is any |
Fixes #2168
Improves support for new
prisma-client
generator.@ymc9 What I think needs some attention, which I wasn't able to figure out. The
enhance.ts
that is generated imports these:import type { InternalArgs, DynamicClientExtensionThis } from '../prisma/client/runtime/library';
But I don't believe these exist anymore with the new
prisma-client
or they are relocated. I'm not exactly sure here.This impacts the types when we do: