git-zodyac / mongoose

Converts your Zod schemas into fully-functional Mongoose schemas
https://www.npmjs.com/package/@zodyac/zod-mongoose
31 stars 5 forks source link

zodSchema's returned Schema DocType is in zod form #3

Closed hollandjake closed 9 months ago

hollandjake commented 9 months ago

Expected Behaviour

When using the zodSchema function, it should generate a zod agnostic mongoose schema.

Current Behaviour

When using the zodSchema function, it generates a mongoose Schema of which its raw type is still the zod schema types.

Context

https://github.com/git-zodyac/mongoose/blob/506bc0e304ffc0f239ffed92f9b124cd24562a2a/src/index.ts#L50-L55

Possible Solution

export function zodSchema<T extends AnyZodObject>(
  schema: T
): Schema<z.infer<T>> {
  const definition = parseObject(schema);
  return new Schema(definition);
}
bebrasmell commented 9 months ago

Hey, @hollandjake! Thanks for reaching out with an issue.

This issue will be fixed with the next iteration of library asap.

bebrasmell commented 9 months ago

Done!

A newer version, @zodyac/zod-mongoose 1.1.2, now generates a Zod agnostic schema. I also added an experimental support for UUIDs.

Please let me know if there's anything else we could improve. Enjoy your day!