Closed krisgrm closed 10 months ago
found the issue problem is with zod enum.. works:
const schema = z.object({
a: z.boolean(),
b: z.string(),
c: z.string(),
d: z.string(),
e: z.string(),
f: z.string(),
g: z.string(),
h: z.array(
z.object({
ha: z.number(),
hb: z.string(),
hc: z.boolean(),
hd: z.string(),
}),
),
i: z.object({
ia: z.number(),
}),
});
const schemaKeys = parseZodSchema(schema);
Doesn't work
const schema = z.object({
a: z.boolean(),
b: z.string(),
c: z.enum(["a", "b", "c"]),
d: z.string(),
e: z.string(),
f: z.string(),
g: z.string(),
h: z.array(
z.object({
ha: z.number(),
hb: z.string(),
hc: z.boolean(),
hd: z.string(),
}),
),
i: z.object({
ia: z.number(),
}),
});
const schemaKeys = parseZodSchema(schema);
on another note, my idea / what i am trying to achieve is that I'd like to build a library, with a function that exposes:
zodSchema: union of available zod schemas
field: which-field-in-scheam (this should autocomplete based on zodSchema selected above)
operator: operator-based-on-field-data-type
value: value, which should be type of the selected field
I'd like to achieve all of this with zod, so i can also use zod.parse when I get this data objects from "unreliable".. i could build a type (maybe it would be easier)..
what would you suggest?
Well, i haven't test Zod Enum yet, i think that's the problem haha 😅
As of now, the supported zod type was as stated below:
ZodUnion, ZodIntersection, ZodArray, ZodOptional, ZodNullable, and ZodObject also of course the basic type like string, boolean and so on
But don't worry i'm planning on supporting the other things such as the Zod enum too
Let me know if I can help somehow. I can look into the source code ofcourse but if you have some pointers go ahead.
Also did you see my 2nd part of message, do you have any suggestions?
Feel free to ignore me completely hehe, we are all busy
Oops sorry missed it, do you mean other than keys
and prismaKeys
, you wanted other key such as zodSchema, field, operator and value?
I'm currently working on the field
one, it'd list all the primitive zod keys inside it, but i just kinda confuse if there is a zod union inside the schema and there's the same key on between union but with different type, what key should i use?
Also for zodSchema
do you mean a collection of zod objects from the input model?
And I don't quite understand for the operator and value one, can you tell me more about that?
Thanks!
Hi @krisgrm, just wanted to let you know, as per v1.5.0 the ZodEnum is supported! and also to make me possible to fulfill your request, can you provide some details as i asked above?
i have a rather big but simple zod schema (and i get error below when calling
parseZodSchema
)