-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
typescript types broken on zod schema plugin on delegated tables in zenstack v2.5.1 #1693
Comments
Thanks for reporting this @tmax22 . I'll look into it. |
I've encountered an issue with custom Zod plugins in ZenStack's CLI. The generation order is incorrect, causing Zod type checks to fail.
After analyzing the At the same time, This leads to two issues:
I propose a simple code modification (without breaking the let { corePlugins, userPlugins } = this.calculateAllPlugins(runnerOptions, plugins);
// filter prisma plugin
const prismaPlugin = corePlugins.find((p) => p.provider === CorePlugins.Prisma);
// filter core zod plugin
const coreZodPlugin = corePlugins.find((p) => p.provider === CorePlugins.Zod);
// filter enhancer plugin
const enhancerPlugin = corePlugins.find((p) => p.provider === CorePlugins.Enhancer);
// filter zod plugin in userPlugins
const userZodPlugin = userPlugins.find((p) => p.provider === CorePlugins.Zod);
const zodPlugin = userZodPlugin ?? coreZodPlugin;
// filter not zod plugin in userPlugins
const notZodPlugin = userPlugins.filter((p) => p.provider !== CorePlugins.Zod);
corePlugins = [prismaPlugin, zodPlugin, enhancerPlugin] as PluginInfo[];
userPlugins = notZodPlugin; This execution order ensures that Note: When I linked ZenStack locally and ran |
Hi @zysam , thanks for the information. Do you have a user-defined zod plugin in ZModel? Do you mind sharing the plugin sections of your model? Thanks! |
@ymc9 Sure.
Note:
P.S.: suggest using custom output dir in the workspace which use pnpm. |
…ator field has default value Fixes #1693
I think my issue is related to this. If I use delegate, zod typechecking fails during generation, but only when I use the --output flag. It works properly when I don't specify an output. Here is the delegated model in the simplest form:
Deleting ListItemApp fixes the problem so that I can use the output flag. |
Hi @zysam , thanks for the detailed repro. It's a problematic design that each core plugin (enhancer, zod) allows to specify its own output dir, since they are not really independent - this can result in combinations that are confusing and not working. What you need can be achieved by using CLI options instead: npx zenstack --no-compile --output ./generated The I think in V3 we'll probably deprecate the "output" and "compile" options from the core plugin level and only allow to control them from the CLI. |
Hi @bbozzay , do you have settings for core plugins in your zmodel? I tried to reproduce the issue with your models and `npx zenstack generate --output generated" but couldn't see the error. |
i don't have this specific error anymore in the newer versions of zenstack, (about --output flag: i didn't tried), from my perspective this issue can be closed |
I should add to my previous response: If I set an output path, I get a type checking error and generate stops early. If I don't specify output, the generate command completes without error. However, my sveltekit dev server is unable to find "enhance." Both issues were resolved when I dropped the delegated tables. Another important note is that this is within a mono-repo (turbo repo with pnpm). Here are the current plugin configurations:
|
Thanks for giving more context @bbozzay . Is it possible to share a minimum repro that resembles your setup? |
i dont have a repro anymore unfortunately, but I will attempt this upgrade again in the coming weeks and can share if I encounter the issue again. |
Closing for now. Please reactive if you run into it again. |
zenstack v2.5.1 introduces new error.
for example for this schema:
you get the following error:
removing zod plugin or @@DeleGate field would relax this issue. currently we decided not to upgrade because we are using zod schemas in our app.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: