-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: use enhanced prisma to support Polymorphism (#28) #29
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,10 @@ export interface ServerOptions { | |||||||||
| logLevel?: string[] | ||||||||||
| } | ||||||||||
|
|
||||||||||
| type EnhancementKind = 'password' | 'omit' | 'policy' | 'validation' | 'delegate' | 'encryption' | ||||||||||
| // enable all enhancements except policy | ||||||||||
| const Enhancements: EnhancementKind[] = ['password', 'omit', 'validation', 'delegate', 'encryption'] | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Resolve the absolute path to the Prisma schema directory | ||||||||||
| */ | ||||||||||
|
|
@@ -136,6 +140,7 @@ async function loadZenStackModules( | |||||||||
| let enums: any | ||||||||||
| // Load Prisma Client - either from custom output or default @prisma/client | ||||||||||
| let PrismaClient: any | ||||||||||
| let enhanceFunc: any | ||||||||||
|
|
||||||||||
| const generator = zmodelConfig.generator | ||||||||||
| if (generator.output) { | ||||||||||
|
|
@@ -174,17 +179,17 @@ async function loadZenStackModules( | |||||||||
| : path.join(process.cwd(), zenstackPath) | ||||||||||
| : undefined | ||||||||||
|
|
||||||||||
| let modelMetaPath: string | undefined | ||||||||||
| try { | ||||||||||
| if (zenstackAbsPath) { | ||||||||||
| modelMetaPath = path.join(zenstackAbsPath, 'model-meta') | ||||||||||
| modelMeta = require(path.join(zenstackAbsPath, 'model-meta')).default | ||||||||||
| enhanceFunc = require(path.join(zenstackAbsPath, 'enhance')).enhance | ||||||||||
| } else { | ||||||||||
| modelMetaPath = '@zenstackhq/runtime/model-meta' | ||||||||||
| modelMeta = require('@zenstackhq/runtime/model-meta').default | ||||||||||
| enhanceFunc = require('@zenstackhq/runtime').enhance | ||||||||||
| } | ||||||||||
| modelMeta = require(modelMetaPath).default | ||||||||||
| } catch { | ||||||||||
| throw new CliError( | ||||||||||
| `Failed to load ZenStack generated model meta from: ${modelMetaPath}\n` + | ||||||||||
| `Failed to load ZenStack generated model meta from: ${zenstackAbsPath || '@zenstackhq/runtime'}\n` + | ||||||||||
|
||||||||||
| `Failed to load ZenStack generated model meta from: ${zenstackAbsPath || '@zenstackhq/runtime'}\n` + | |
| `Failed to load ZenStack generated modules (model meta and enhance function) from: ${ | |
| zenstackAbsPath || '@zenstackhq/runtime' | |
| }\n` + |
Copilot
AI
Feb 3, 2026
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.
The enhance function is called with an empty object ({}) as the context parameter. This might be intentional for a stateless proxy server, but verify that this is the correct usage. If the enhance function is designed to receive request-specific context (e.g., user information for policy enforcement), this empty context could bypass important security or access control features.
Copilot
AI
Feb 3, 2026
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.
The getPrisma function creates a new enhanced Prisma instance on every invocation. Depending on how frequently ZenStackMiddleware calls getPrisma and how the enhance function works internally, this could create performance overhead. Consider caching the enhanced Prisma instance if enhance() is expensive, or verify that enhance() is designed to be called on every request. If enhance() is a lightweight wrapper that should be called per-request (e.g., for request-specific context), this is fine and can be ignored.
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.
The EnhancementKind type and Enhancements constant define which enhancements are enabled, notably excluding 'policy'. Consider adding more detailed documentation explaining why 'policy' is specifically excluded from the enhancements, as this is a significant configuration decision that affects the behavior of the proxy server.