Comments (6)
Hi @levipro , I've implemented it and would like to see how well it'll solve your problem. The tricky part is, given a whitelist of models to generate Zod schema for, we need to build a transitive closure and include all model types that have a relation with the whitelisted ones. The reason is Prisma allows relation filtering in queries and allows you to traverse related models in query conditions.
This can be problematic when, say, you have a "hub" model like User
, which transitively reaches all other models. Do you mind sharing some basic structure of your zmodel so I can check it? Thank you!
from zenstack.
When I do run prismas introspection on my database it creates quite a large schema file. I certainly have a few hub models throughout as well.
I can see how this is a complex issue to solve for. Is there a way to automatically exclude a relation if the model for that relation is not in the whitelist as well?
Do you have a branch I can try running this from to help test things? That would be the easiest way for me to try and help. Cleaning up my schema file and removing sensitive structures would take a lot of time.
from zenstack.
When I do run prismas introspection on my database it creates quite a large schema file. I certainly have a few hub models throughout as well.
I can see how this is a complex issue to solve for. Is there a way to automatically exclude a relation if the model for that relation is not in the whitelist as well?
Do you have a branch I can try running this from to help test things? That would be the easiest way for me to try and help. Cleaning up my schema file and removing sensitive structures would take a lot of time.
That's a good idea. You can install the v1.1 package from the preview registry:
npm i -D --registry https://preview.registry.zenstack.dev zenstack @zenstackhq/trpc
The updated trpc plugin has a "generateModels" option, you can pass a comma-separated list of model names to whitelist. It'll pass it down to the zod plugin that it implicitly activates. If you've also manually declared a zod plugin in your zmodel, you need to put the same option in it.
plugin trpc {
...
generateModels = 'User,Post'
}
from zenstack.
Adding the above trpc setting did work to only generate the User/Post routers, but all the zod files were still generated. I also tried adding this but the same files were generated:
plugin zod {
provider = '@core/zod'
generateModels = 'User,Post'
}
I also had to add the node options -stack-size=2048 --max-old-space-size=12288
for this to complete
from zenstack.
Got it. I believe it's due to the transitive closure, as we discussed previously ... I think it's possible to exclude relation - a bit more work to do. I'm trying to wrap up v1.1 release and probably have to postpone it.
I'll keep thinking about this and hopefully get a complete resolution in the next one.
from zenstack.
Probably a real solution is to infer zod schemas instead of generating them.
from zenstack.
Related Issues (20)
- Model inheritance doesn't check for cycles
- LSP VSCode: Linter doesn't complain when using `previewFeatures = ["multiSchema"]` but not including `@@schema` on models / enums
- Polymorphic extends using `enum` for the type when using @@delegate HOT 5
- Update permission buggy when used in @@deny HOT 1
- [ZModel] Insufficient type checking for "in" operator
- Two one-to-many relations on the same model generated wrong model meta data
- Issue using @@index with @@delegate HOT 2
- false error on @relation in vscode extension when using multiple schemas HOT 6
- auth() with import causes linking-error HOT 2
- [Feature Request] Provide Migrations API HOT 1
- [Zod] Field with `auth()` in `@default()` should be generated as optional in zod schemas HOT 1
- Allow accessing all fields through auth() when @@auth is applied on model with @@delegate HOT 3
- Typecasting "Bytes" Fields HOT 2
- [Feature Request] Honojs server adapter support
- Zenstack having problems with upserting relations with compound keys HOT 2
- [Feature Request] Compatibility with Prisma "omit" feature
- Prisma --no-engine CLI option is not available until 5.2.0
- Zod schemas should use `.optional()` instead of `.nullish()` to represent optional fields HOT 1
- [Feature Request] Disable hooks that generates files outside of node_modules in CLI HOT 1
- Policy compilation errors with deep nested post-update rules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zenstack.