@parziva-1/zod-mongoose 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +320 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.js +703 -0
- package/dist/index.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["kind","zmAssert","dateField","arrayField","mapField"],"sources":["../src/assertions/custom.ts","../src/assertions/kind.ts","../src/assertions/assertions.ts","../src/extension.ts","../src/index.ts"],"sourcesContent":["import type { ZodType } from \"zod\";\n\nexport namespace zmAssertIds {\n export function objectId(f: ZodType): f is ZodType<string> {\n return \"__zm_type\" in f && f.__zm_type === \"ObjectId\";\n }\n\n export function uuid(f: ZodType): f is ZodType<string> {\n return \"__zm_type\" in f && f.__zm_type === \"UUID\";\n }\n}\n","import type { ZodType } from \"zod\";\nimport type { IAsserts } from \"./types\";\n\n/**\n * Kind assertions (Zod v4)\n * @internal\n *\n * Zod v4 exposes a stable, bundler-safe runtime discriminator for every\n * schema via `field._zod.def.type` (e.g. `\"string\"`, `\"object\"`, `\"pipe\"`, ...).\n * This replaces the three-strategy (constructor name / instanceof / manual\n * prototype tagging) approach that was needed under Zod v3, where none of\n * those signals were reliably safe across bundlers on their own.\n */\nexport const zmAssert: IAsserts = {\n string(f: ZodType): f is any {\n return f._zod.def.type === \"string\";\n },\n\n number(f: ZodType): f is any {\n return f._zod.def.type === \"number\";\n },\n\n object(f: ZodType): f is any {\n return f._zod.def.type === \"object\";\n },\n\n array(f: ZodType): f is any {\n return f._zod.def.type === \"array\";\n },\n\n boolean(f: ZodType): f is any {\n return f._zod.def.type === \"boolean\";\n },\n\n enumerable(f: ZodType): f is any {\n return f._zod.def.type === \"enum\";\n },\n\n date(f: ZodType): f is any {\n return f._zod.def.type === \"date\";\n },\n\n def(f: ZodType): f is any {\n return f._zod.def.type === \"default\";\n },\n\n optional(f: ZodType): f is any {\n return f._zod.def.type === \"optional\";\n },\n\n nullable(f: ZodType): f is any {\n return f._zod.def.type === \"nullable\";\n },\n\n union(f: ZodType): f is any {\n return f._zod.def.type === \"union\";\n },\n\n any(f: ZodType): f is any {\n // `z.any()` and `z.unknown()` carry no meaningful runtime constraints of\n // their own and map to the exact same Mongoose representation\n // (`SchemaTypes.Mixed`), so they're treated as one case here.\n const type = f._zod.def.type;\n return type === \"any\" || type === \"unknown\";\n },\n\n mapOrRecord(f: ZodType): f is any {\n return f._zod.def.type === \"map\" || f._zod.def.type === \"record\";\n },\n\n pipe(f: ZodType): f is any {\n return f._zod.def.type === \"pipe\";\n },\n\n tuple(f: ZodType): f is any {\n return f._zod.def.type === \"tuple\";\n },\n\n literal(f: ZodType): f is any {\n return f._zod.def.type === \"literal\";\n },\n\n /**\n * `z.discriminatedUnion()` is represented by Zod v4 as a plain `ZodUnion`\n * (`_zod.def.type === \"union\"`) that additionally carries a `discriminator`\n * key on its def. It must be checked for *before* the generic `union`\n * assertion in `parseField`, since a discriminated union also satisfies\n * that check.\n */\n discriminatedUnion(f: ZodType): f is any {\n return (\n f._zod.def.type === \"union\" && typeof (f._zod.def as any).discriminator === \"string\"\n );\n },\n\n intersection(f: ZodType): f is any {\n return f._zod.def.type === \"intersection\";\n },\n\n lazy(f: ZodType): f is any {\n return f._zod.def.type === \"lazy\";\n },\n\n catch(f: ZodType): f is any {\n return f._zod.def.type === \"catch\";\n },\n};\n","import { zmAssertIds } from \"./custom\";\nimport { zmAssert as kind } from \"./kind\";\n\nexport default {\n ...kind,\n ...zmAssertIds,\n};\n","import { isValidObjectId, Types } from \"mongoose\";\nimport { z } from \"zod\";\n\ndeclare module \"zod\" {\n interface ZodString {\n unique: (arg?: boolean) => ZodString;\n sparse: (arg?: boolean) => ZodString;\n }\n\n interface ZodNumber {\n unique: (arg?: boolean) => ZodNumber;\n sparse: (arg?: boolean) => ZodNumber;\n }\n\n interface ZodDate {\n unique: (arg?: boolean) => ZodDate;\n sparse: (arg?: boolean) => ZodDate;\n }\n\n interface ZodType {\n __zm_type?: string;\n __zm_ref?: string;\n __zm_refPath?: string;\n }\n}\n\nlet zod_extended = false;\n/**\n * Extends the Zod library with additional functionality.\n *\n * This function modifies the Zod library to add custom mongoose-specific\n * metadata methods. It ensures that the extension is only applied once.\n *\n * @param z_0 - The Zod library to extend.\n *\n * @remarks\n * - Adds a `unique` method to `ZodString`, `ZodNumber`, and `ZodDate` to mark them as unique.\n * - Adds a `sparse` method to `ZodString`, `ZodNumber`, and `ZodDate` to mark them as sparse.\n *\n * As of Zod v4, refinement metadata (validator + message) no longer needs to\n * be captured via a `refine()` override: Zod's own internal `checks` array\n * already exposes the validator function and error message directly, so\n * `zodSchema()` reads that straight off the schema instead.\n *\n * @example\n * ```typescript\n * import { z } from \"zod\";\n * import { extendZod } from \"./extension\";\n *\n * extendZod(z);\n *\n * const schema = z.object({\n * name: z.string().unique();\n * });\n * ```\n */\nexport function extendZod(z_0: typeof z) {\n // Prevent zod from being extended multiple times\n if (zod_extended) return;\n zod_extended = true;\n\n // Unique / sparse support\n //\n // Metadata is stored via Zod v4's built-in `.meta()` registry rather than\n // as an ad-hoc instance property. `.meta()` merges with anything already\n // registered and - crucially - survives subsequent native builder calls\n // (`.refine()`, `.min()`, `.optional()`, ...), each of which returns a new\n // cloned schema instance under Zod v4. A plain property assignment (as\n // used under Zod v3) would be silently dropped by that clone.\n const UNIQUE_SUPPORT_LIST = [z_0.ZodString, z_0.ZodNumber, z_0.ZodDate] as const;\n\n for (const type of UNIQUE_SUPPORT_LIST) {\n (<any>type.prototype).unique = function (arg = true) {\n return this.meta({ ...this.meta(), __zm_unique: arg });\n };\n\n (<any>type.prototype).sparse = function (arg = true) {\n return this.meta({ ...this.meta(), __zm_sparse: arg });\n };\n }\n}\n\nexport type TzmId = ReturnType<typeof createId> & {\n unique: (arg?: boolean) => TzmId;\n sparse: (arg?: boolean) => TzmId;\n ref: (arg: string) => TzmId;\n refPath: (arg: string) => TzmId;\n};\n\nconst createId = () => {\n return z\n .string()\n .refine((v) => isValidObjectId(v), { message: \"Invalid ObjectId\" })\n .or(z.instanceof(Types.ObjectId));\n};\n\nexport const zId = (ref?: string): TzmId => {\n const output = createId();\n\n (<any>output).__zm_type = \"ObjectId\";\n (<any>output).__zm_ref = ref;\n\n (<any>output).ref = function (ref: string) {\n (<any>this).__zm_ref = ref;\n return this;\n };\n\n (<any>output).refPath = function (ref: string) {\n (<any>this).__zm_refPath = ref;\n return this;\n };\n\n (<any>output).unique = function (val = true) {\n (<any>this).__zm_unique = val;\n return this;\n };\n\n (<any>output).sparse = function (val = true) {\n (<any>this).__zm_sparse = val;\n return this;\n };\n\n return output as TzmId;\n};\n\nexport type TzmUUID = ReturnType<typeof createUUID> & {\n unique: (arg?: boolean) => TzmUUID;\n sparse: (arg?: boolean) => TzmUUID;\n ref: (arg: string) => TzmUUID;\n refPath: (arg: string) => TzmUUID;\n};\n\nconst createUUID = () => {\n return z.string().uuid({ message: \"Invalid UUID\" }).or(z.instanceof(Types.UUID));\n};\n\nexport const zUUID = (ref?: string): TzmUUID => {\n const output = createUUID();\n\n (<any>output).__zm_type = \"UUID\";\n (<any>output).__zm_ref = ref;\n\n (<any>output).ref = function (ref: string) {\n (<any>this).__zm_ref = ref;\n return this;\n };\n\n (<any>output).refPath = function (ref: string) {\n (<any>this).__zm_refPath = ref;\n return this;\n };\n\n (<any>output).unique = function (val = true) {\n (<any>this).__zm_unique = val;\n return this;\n };\n\n (<any>output).sparse = function (val = true) {\n (<any>this).__zm_sparse = val;\n return this;\n };\n\n return output as TzmUUID;\n};\n","import { Schema, type SchemaOptions, SchemaTypes, type Types } from \"mongoose\";\nimport type { ZodNumber, ZodObject, ZodRawShape, ZodString, ZodType, z } from \"zod\";\n\nimport zmAssert from \"./assertions/assertions.js\";\nimport type { zm } from \"./mongoose.types.js\";\n\nexport * from \"./extension.js\";\n\n/**\n * Maximum number of times `parseField` will follow a given `z.lazy()`\n * getter into itself before bottoming out at `SchemaTypes.Mixed`. Guards\n * against unbounded recursion when parsing a genuinely self-referencing\n * schema (e.g. a comment type whose `replies` field is `z.array(z.lazy(() =>\n * CommentSchema))`) - Mongoose has no native equivalent of an infinitely\n * recursive embedded subdocument, so the structure has to be unrolled to a\n * finite depth. Keyed per-getter (not globally) via `lazyDepth` below, so\n * unrelated lazy schemas in the same document don't share a budget.\n */\nconst LAZY_DEPTH_LIMIT = 5;\nconst lazyDepth = new WeakMap<() => ZodType, number>();\n\n/**\n * Converts a Zod schema to a Mongoose schema\n * @param schema zod schema to parse\n * @returns mongoose schema\n *\n * @example\n * import { extendZod, zodSchema } from '@zodyac/zod-mongoose';\n * import { model } from 'mongoose';\n * import { z } from 'zod';\n *\n * extendZod(z);\n *\n * const zUser = z.object({\n * name: z.string().min(3).max(255),\n * age: z.number().min(18).max(100),\n * active: z.boolean().default(false),\n * access: z.enum(['admin', 'user']).default('user'),\n * companyId: zId('Company'),\n * address: z.object({\n * street: z.string(),\n * city: z.string(),\n * state: z.enum(['CA', 'NY', 'TX']),\n * }),\n * tags: z.array(z.string()),\n * createdAt: z.date(),\n * updatedAt: z.date(),\n * });\n *\n * const schema = zodSchema(zDoc);\n * const userModel = model('User', schema);\n */\nexport function zodSchema<T extends ZodRawShape>(\n schema: ZodObject<T>,\n options?: SchemaOptions<any>, // TODO: Fix any\n): Schema<z.infer<typeof schema>> {\n const definition = parseObject(schema, true);\n return new Schema<z.infer<typeof schema>>(definition, options);\n}\n\n/**\n * Converts a Zod schema to a raw Mongoose schema object\n * @param schema zod schema to parse\n * @returns mongoose schema\n *\n * @example\n * import { extendZod, zodSchemaRaw } from '@zodyac/zod-mongoose';\n * import { model, Schema } from 'mongoose';\n * import { z } from 'zod';\n *\n * extendZod(z);\n *\n * const zUser = z.object({\n * name: z.string().min(3).max(255),\n * age: z.number().min(18).max(100),\n * active: z.boolean().default(false),\n * access: z.enum(['admin', 'user']).default('user'),\n * companyId: zId('Company'),\n * address: z.object({\n * street: z.string(),\n * city: z.string(),\n * state: z.enum(['CA', 'NY', 'TX']),\n * }),\n * tags: z.array(z.string()),\n * createdAt: z.date(),\n * updatedAt: z.date(),\n * });\n *\n * const rawSchema = zodSchemaRaw(zDoc);\n * const schema = new Schema(rawSchema);\n * const userModel = model('User', schema);\n */\nexport function zodSchemaRaw<T extends ZodRawShape>(schema: ZodObject<T>): zm._Schema<T> {\n return parseObject(schema, true) as zm._Schema<T>;\n}\n\n// Helpers\nfunction parseObject<T extends ZodRawShape>(obj: ZodObject<T>): zm._Schema<T>;\nfunction parseObject<T extends ZodRawShape>(\n obj: ZodObject<T>,\n required: true,\n def?: undefined,\n): zm._Schema<T>;\nfunction parseObject<T extends ZodRawShape>(\n obj: ZodObject<T>,\n required: true,\n def: zm.mDefault<T>,\n): zm.mSubdocument<T>;\nfunction parseObject<T extends ZodRawShape>(\n obj: ZodObject<T>,\n required: false,\n def?: zm.mDefault<T>,\n): zm.mSubdocument<T>;\nfunction parseObject<T extends ZodRawShape>(\n obj: ZodObject<T>,\n required: boolean,\n def?: zm.mDefault<T>,\n): zm._Schema<T> | zm.mSubdocument<T>;\nfunction parseObject<T extends ZodRawShape>(\n obj: ZodObject<T>,\n required = true,\n def?: zm.mDefault<T>,\n): zm._Schema<T> | zm.mSubdocument<T> {\n const object: any = parseShape(obj.shape as ZodRawShape);\n\n // A nested `z.object().default({})` needs its default threaded onto the\n // Mongoose subdocument path itself - Mongoose has no way to express a\n // default for a bare nested-shape object, so as soon as a `def` is\n // present the object must be wrapped in the `{ type, default, required }`\n // form (the same form already used for a non-required/optional object),\n // even when the object itself is otherwise required.\n if (!required || typeof def !== \"undefined\") {\n return {\n type: object,\n required,\n default: def,\n } as zm.mSubdocument<T>;\n }\n\n return object;\n}\n\n/**\n * Parses a raw Zod shape (a plain `{ key: ZodType }` map, as found on\n * `ZodObject.shape`) into a Mongoose field-definition object. Shared between\n * `parseObject` (which operates on an actual `ZodObject`) and the\n * `z.intersection()` handler, which needs to merge two shapes into one flat\n * object without constructing a synthetic `ZodObject` instance.\n */\nfunction parseShape(shape: ZodRawShape): Record<string, unknown> {\n const object: any = {};\n for (const [key, field] of Object.entries(shape)) {\n if (zmAssert.object(field as ZodType)) {\n object[key] = parseObject(field as ZodObject<any>, true);\n } else {\n const f = parseField(field as ZodType);\n if (!f)\n throw new Error(`Unsupported field type: ${(field as ZodType).constructor}`);\n\n object[key] = f;\n }\n }\n return object;\n}\n\n/**\n * Walks a schema's own `checks` array (Zod v4) and returns the metadata for\n * *every* `.refine()` custom check found on it, in declaration order.\n *\n * Zod v4 no longer wraps refined schemas in a `ZodEffects`-like type: calling\n * `.refine()` simply appends a `\"custom\"` check to the schema's own\n * `_zod.def.checks` array (or, when chained after `.transform()`, to the\n * resulting `ZodPipe`'s own `checks` array). The check object itself already\n * carries the validator function (`fn`) and a normalized error accessor\n * (`error`), so there is no need to monkey-patch `refine()` to capture this\n * metadata as was necessary under Zod v3.\n *\n * A single Zod type can carry multiple `.refine()` checks (e.g.\n * `z.string().refine(a).refine(b)`), and `parseField` also needs to combine\n * checks found on *different* nodes of a `ZodPipe` (a pre-transform refine on\n * the pipe's `in` side plus a post-transform refine on the pipe itself) - so\n * this returns all matches rather than just the last one, leaving the\n * caller free to merge them with refinements collected elsewhere.\n */\nfunction extractRefinements<T>(field: ZodType): zm.EffectValidator<T>[] {\n const checks = (field as any)._zod?.def?.checks as any[] | undefined;\n if (!checks || checks.length === 0) return [];\n\n const refinements: zm.EffectValidator<T>[] = [];\n for (const check of checks) {\n const checkDef = check?._zod?.def;\n if (!checkDef || checkDef.check !== \"custom\") continue;\n\n let message: string | undefined;\n if (typeof checkDef.error === \"function\") {\n try {\n message = checkDef.error({});\n } catch {\n message = undefined;\n }\n } else if (typeof checkDef.error === \"string\") {\n message = checkDef.error;\n }\n\n refinements.push({\n validator: checkDef.fn,\n message,\n });\n }\n\n return refinements;\n}\n\nfunction toRefinementArray<T>(\n refinement: zm.EffectValidator<T> | zm.EffectValidator<T>[] | undefined,\n): zm.EffectValidator<T>[] {\n if (!refinement) return [];\n return Array.isArray(refinement) ? refinement : [refinement];\n}\n\nfunction parseField<T>(\n field: ZodType,\n required = true,\n def?: zm.mDefault<T>,\n refinement?: zm.EffectValidator<T> | zm.EffectValidator<T>[],\n): zm.mField | null {\n if (zmAssert.objectId(field)) {\n const ref = (<any>field).__zm_ref;\n const refPath = (<any>field).__zm_refPath;\n const unique = (<any>field).__zm_unique;\n const sparse = (<any>field).__zm_sparse;\n return parseObjectId(required, ref, unique, refPath, sparse, def as zm.mDefault<any>);\n }\n\n if (zmAssert.uuid(field)) {\n const ref = (<any>field).__zm_ref;\n const refPath = (<any>field).__zm_refPath;\n const unique = (<any>field).__zm_unique;\n const sparse = (<any>field).__zm_sparse;\n return parseUUID(required, ref, unique, refPath, sparse, def as zm.mDefault<any>);\n }\n\n if (zmAssert.object(field)) {\n return parseObject(field as ZodObject<any>, required, def as zm.mDefault<any>);\n }\n\n // Combine any `.refine()` checks found directly on this node with any\n // passed down from an outer node (e.g. a post-transform refine on the\n // enclosing `ZodPipe`), so refinements on *both* sides of a `.transform()`\n // survive instead of the outer one silently overwriting the inner one.\n const combinedRefinements = [\n ...extractRefinements<T>(field),\n ...toRefinementArray(refinement),\n ];\n const ownRefinement: zm.EffectValidator<T> | zm.EffectValidator<T>[] | undefined =\n combinedRefinements.length === 0\n ? undefined\n : combinedRefinements.length === 1\n ? combinedRefinements[0]\n : combinedRefinements;\n\n if (zmAssert.number(field)) {\n const numberField = field as ZodNumber;\n const meta = numberField.meta() as any;\n const isUnique = meta?.__zm_unique ?? false;\n const isSparse = meta?.__zm_sparse ?? false;\n return parseNumber(\n numberField,\n required,\n def as zm.mDefault<number>,\n isUnique,\n ownRefinement as zm.mValidate<number> | undefined,\n isSparse,\n );\n }\n\n if (zmAssert.string(field)) {\n const stringField = field as ZodString;\n const meta = stringField.meta() as any;\n const isUnique = meta?.__zm_unique ?? false;\n const isSparse = meta?.__zm_sparse ?? false;\n return parseString(\n stringField,\n required,\n def as zm.mDefault<string>,\n isUnique,\n ownRefinement as zm.mValidate<string> | undefined,\n isSparse,\n );\n }\n\n if (zmAssert.enumerable(field)) {\n // Zod v4 represents both `z.enum()` and `z.nativeEnum()` as `ZodEnum`,\n // exposing the same values via the `.enum` map in both cases.\n return parseEnum(\n Object.values((<any>field).enum),\n required,\n def as zm.mDefault<string>,\n );\n }\n\n if (zmAssert.boolean(field)) {\n return parseBoolean(required, def as zm.mDefault<boolean>);\n }\n\n if (zmAssert.date(field)) {\n const dateField = field as any;\n const meta = dateField.meta?.() as any;\n const isUnique = meta?.__zm_unique ?? false;\n const isSparse = meta?.__zm_sparse ?? false;\n return parseDate(\n required,\n def as zm.mDefault<Date>,\n ownRefinement as zm.mValidate<Date> | undefined,\n isUnique,\n isSparse,\n );\n }\n\n if (zmAssert.array(field)) {\n const arrayField = field as any;\n return parseArray(\n arrayField.element,\n required,\n def as zm.mDefault<T extends Array<infer K> ? K[] : never>,\n );\n }\n\n if (zmAssert.def(field)) {\n const defField = field as any;\n const innerType = defField._zod.def.innerType as ZodType;\n // Zod v4 stores `defaultValue` behind a getter, re-evaluating any factory\n // function passed to `.default()` on every access - wrap it the same way\n // so a fresh value is produced per document, matching Zod v3 behavior\n // (where `_def.defaultValue` was already a `() => T` callback).\n return parseField(innerType, required, () => defField._zod.def.defaultValue);\n }\n\n if (zmAssert.optional(field)) {\n const innerType = (field as any)._zod.def.innerType as ZodType;\n // Forward whatever `def` this call already carries (e.g. from an outer\n // `.default()` in a `.optional().default(x)` chain) instead of always\n // discarding it - Mongoose's `default` must survive regardless of\n // whether `.optional()` or `.default()` comes first in the chain.\n return parseField(innerType, false, def);\n }\n\n if (zmAssert.nullable(field)) {\n const innerType = (field as any)._zod.def.innerType as ZodType;\n return parseField(\n innerType,\n false,\n (typeof def !== \"undefined\" ? def : () => null) as zm.mDefault<null>,\n );\n }\n\n // Must run before the generic `union` check below - Zod v4 represents\n // `z.discriminatedUnion()` as a `ZodUnion` with an extra `discriminator`\n // key, so it would otherwise match the plain-union branch and silently\n // collapse to its first variant.\n if (zmAssert.discriminatedUnion(field)) {\n return parseDiscriminatedUnion(field, required, def);\n }\n\n if (zmAssert.union(field)) {\n const options = (field as any)._zod.def.options as ZodType[];\n const firstOption = options[0];\n if (!firstOption) throw new Error(\"Union type must have at least one option\");\n return parseField(firstOption);\n }\n\n if (zmAssert.any(field)) {\n return parseMixed(required, def);\n }\n\n if (zmAssert.tuple(field)) {\n return parseTuple(field, required, def);\n }\n\n if (zmAssert.literal(field)) {\n const values = (field as any)._zod.def.values as unknown[];\n return parseLiteral(values, required, def);\n }\n\n if (zmAssert.intersection(field)) {\n const { left, right } = (field as any)._zod.def as { left: ZodType; right: ZodType };\n if (!zmAssert.object(left) || !zmAssert.object(right)) {\n throw new Error(\n \"Unsupported intersection: zod-mongoose can only merge two object-shape schemas (z.object(...).and(z.object(...))) into a flat Mongoose sub-schema\",\n );\n }\n const mergedShape = {\n ...(left as ZodObject<any>).shape,\n ...(right as ZodObject<any>).shape,\n };\n const merged = parseShape(mergedShape as ZodRawShape);\n if (!required) {\n return { type: merged, required: false } as unknown as zm.mField;\n }\n return merged as unknown as zm.mField;\n }\n\n if (zmAssert.lazy(field)) {\n const getter = (field as any)._zod.def.getter as () => ZodType;\n const depth = lazyDepth.get(getter) ?? 0;\n if (depth >= LAZY_DEPTH_LIMIT) {\n // Bottom out recursive/self-referencing schemas at a fixed depth.\n // Mongoose has no native concept of an infinitely recursive embedded\n // subdocument (unlike Zod, which can describe one lazily); beyond this\n // depth we fall back to Mixed rather than recursing forever. This is a\n // pragmatic compromise, not a full solution - documents nested deeper\n // than the limit still round-trip through Mongo, they just lose\n // structural validation past that point.\n return parseMixed(required, def);\n }\n lazyDepth.set(getter, depth + 1);\n try {\n const inner = getter();\n return parseField(inner, required, def, refinement);\n } finally {\n lazyDepth.set(getter, depth);\n }\n }\n\n if (zmAssert.catch(field)) {\n const catchField = field as any;\n const innerType = catchField._zod.def.innerType as ZodType;\n const catchValueFn = catchField._zod.def.catchValue as (ctx: {\n value: unknown;\n issues: unknown[];\n error?: unknown;\n }) => unknown;\n\n const inner = parseField(innerType, required, def, refinement);\n if (!inner) return inner;\n\n // Emulate Zod's `.catch()` semantics (fall back to a computed/static\n // value when parsing the input fails) via Mongoose's `set` transform.\n // Mongoose's own `default` only applies when a path is `undefined`, not\n // when a *present* value fails validation - which is the actual\n // `.catch()` contract, so `default` alone can't represent it.\n const previousSet = (inner as any).set as ((v: unknown) => unknown) | undefined;\n (inner as any).set = (v: unknown) => {\n const result = innerType.safeParse(v);\n const resolved = result.success\n ? result.data\n : catchValueFn({ value: v, issues: result.error.issues, error: result.error });\n return previousSet ? previousSet(resolved) : resolved;\n };\n return inner;\n }\n\n if (zmAssert.mapOrRecord(field)) {\n const mapField = field as any;\n return parseMap(\n mapField.valueType,\n required,\n def as zm.mDefault<\n Map<\n zm.UnwrapZodType<typeof mapField.keyType>,\n zm.UnwrapZodType<typeof mapField.valueType>\n >\n >,\n );\n }\n\n if (zmAssert.pipe(field)) {\n // Zod v4 represents both `.transform()` and `z.preprocess()` as a\n // `ZodPipe` under the hood:\n // - `.transform()` -> pipe(originalSchema, ZodTransform)\n // - `z.preprocess()` -> pipe(ZodTransform, targetSchema)\n // In both cases, the side that is NOT a `ZodTransform` carries the real\n // structural type (string/number/date/...) we need to introspect.\n const pipeDef = (field as any)._zod.def as { in: ZodType; out: ZodType };\n const inIsTransform = (pipeDef.in as any)._zod.def.type === \"transform\";\n const target = inIsTransform ? pipeDef.out : pipeDef.in;\n\n return parseField(target, required, def, ownRefinement);\n }\n\n return null;\n}\n\nfunction parseNumber(\n field: ZodNumber,\n required = true,\n def?: zm.mDefault<number>,\n unique = false,\n validate?: zm.mValidate<number>,\n sparse = false,\n): zm.mNumber {\n const output: zm.mNumber = {\n type: Number,\n default: def,\n // Zod v4's `minValue`/`maxValue` getters default to `-Infinity`/`Infinity`\n // (not `null`, as in Zod v3) when no `.min()`/`.max()` check is present.\n min: Number.isFinite(field.minValue) ? (field.minValue ?? undefined) : undefined,\n max: Number.isFinite(field.maxValue) ? (field.maxValue ?? undefined) : undefined,\n required,\n unique,\n sparse,\n };\n\n if (validate) output.validate = validate;\n return output;\n}\n\nfunction parseString(\n field: ZodString,\n required = true,\n def?: zm.mDefault<string>,\n unique = false,\n validate?: zm.mValidate<string>,\n sparse = false,\n): zm.mString {\n const output: zm.mString = {\n type: String,\n default: def,\n required,\n minLength: field.minLength ?? undefined,\n maxLength: field.maxLength ?? undefined,\n unique,\n sparse,\n };\n\n if (validate) output.validate = validate;\n return output;\n}\n\nfunction parseEnum(\n values: string[],\n required = true,\n def?: zm.mDefault<string>,\n): zm.mString {\n return {\n type: String,\n unique: false,\n sparse: false,\n default: def,\n enum: values,\n required,\n };\n}\n\nfunction parseBoolean(required = true, def?: zm.mDefault<boolean>): zm.mBoolean {\n return {\n type: Boolean,\n default: def,\n required,\n };\n}\n\nfunction parseDate(\n required = true,\n def?: zm.mDefault<Date>,\n validate?: zm.mValidate<Date>,\n unique = false,\n sparse = false,\n): zm.mDate {\n const output: zm.mDate = {\n type: Date,\n default: def,\n required,\n unique,\n sparse,\n };\n\n if (validate) output.validate = validate;\n return output;\n}\n\nfunction parseObjectId(\n required = true,\n ref?: string,\n unique = false,\n refPath?: string,\n sparse = false,\n def?: zm.mDefault<Types.ObjectId | null>,\n): zm.mObjectId {\n const output: zm.mObjectId = {\n type: SchemaTypes.ObjectId,\n required,\n unique,\n sparse,\n default: def as zm.mDefault<Types.ObjectId> | undefined,\n };\n\n if (ref) output.ref = ref;\n if (refPath) output.refPath = refPath;\n return output;\n}\n\nfunction parseArray<T>(\n element: ZodType,\n required = true,\n def?: zm.mDefault<T[]>,\n): zm.mArray<T> {\n const innerType = parseField(element);\n if (!innerType) throw new Error(\"Unsupported array type\");\n return {\n type: [innerType as zm._Field<T>],\n default: def,\n required,\n };\n}\n\nfunction parseMap<T, K>(\n valueType: ZodType,\n required = true,\n def?: zm.mDefault<Map<NoInfer<T>, K>>,\n): zm.mMap<T, K> {\n const pointer = parseMapValue(valueType);\n\n return {\n type: Map,\n of: pointer as zm._Field<K>,\n default: def,\n required,\n };\n}\n\n/**\n * Resolves a `z.map()`/`z.record()` value type into a Mongoose field\n * definition for the Map's `of`.\n *\n * A plain `z.union([...])` value type (e.g. `z.record(z.string(),\n * z.union([z.string(), z.number()]))`, the real production `params` shape)\n * must NOT go through the generic `parseField` union handling, which\n * collapses to the *first* union member's type - for a `Map<string, string\n * | number>` that silently coerces every numeric value to a string on save\n * (Mongoose's `Map`/`String` casting), which is silent data corruption, not\n * just a missing feature. Instead, the value is stored as `Mixed` (so all\n * union member types round-trip untouched) with a `validate` that re-checks\n * each value against the original union schema via `.safeParse()`, so an\n * invalid value is rejected rather than silently narrowed/coerced.\n */\nfunction parseMapValue(valueType: ZodType): zm.mField {\n if (zmAssert.union(valueType) && !zmAssert.discriminatedUnion(valueType)) {\n return {\n type: SchemaTypes.Mixed,\n required: false,\n validate: {\n validator: (v: unknown) => valueType.safeParse(v).success,\n message: \"Value does not match any member of the declared union value type\",\n },\n } as zm.mMixed<unknown>;\n }\n\n const pointer = parseField(valueType);\n if (!pointer) throw new Error(\"Unsupported map value type\");\n return pointer;\n}\n\nfunction parseUUID(\n required = true,\n ref?: string,\n unique = false,\n refPath?: string,\n sparse = false,\n def?: zm.mDefault<Types.UUID | null>,\n): zm.mUUID {\n const output: zm.mUUID = {\n type: SchemaTypes.UUID,\n required,\n unique,\n sparse,\n default: def as zm.mDefault<Types.UUID> | undefined,\n };\n if (ref) output.ref = ref;\n if (refPath) output.refPath = refPath;\n return output;\n}\n\nfunction parseMixed(required = true, def?: unknown): zm.mMixed<unknown> {\n return {\n type: SchemaTypes.Mixed,\n default: def as unknown as any,\n required,\n };\n}\n\n/**\n * `z.tuple()` has no native Mongoose equivalent (Mongoose arrays are\n * homogeneous and unbounded). It's represented as a Mongoose array of\n * `Mixed` - so it still round-trips through Mongo as a JSON array - with a\n * `validate` that enforces the tuple's actual contract (exact arity, or a\n * minimum arity plus a rest type, and the correct type at each position).\n * Rather than re-deriving per-position type checks by hand, the validator\n * reuses the original Zod item schemas' own `.safeParse()`, which is both\n * simpler and guaranteed to match Zod's own validation semantics exactly.\n */\nfunction parseTuple(field: ZodType, required = true, def?: unknown): zm.mArray<unknown> {\n const tupleDef = (field as any)._zod.def as { items: ZodType[]; rest: ZodType | null };\n const items = tupleDef.items;\n const rest = tupleDef.rest;\n\n const validator = (value: unknown): boolean => {\n if (!Array.isArray(value)) return false;\n if (rest) {\n if (value.length < items.length) return false;\n } else if (value.length !== items.length) {\n return false;\n }\n\n for (let i = 0; i < items.length; i++) {\n const itemSchema = items[i];\n if (!itemSchema || !itemSchema.safeParse(value[i]).success) return false;\n }\n if (rest) {\n for (let i = items.length; i < value.length; i++) {\n if (!rest.safeParse(value[i]).success) return false;\n }\n }\n return true;\n };\n\n const message = rest\n ? `Expected a tuple of at least ${items.length} element(s) matching the declared types`\n : `Expected a tuple of exactly ${items.length} element(s) matching the declared types`;\n\n return {\n type: [{ type: SchemaTypes.Mixed, required: false }] as unknown as [\n zm._Field<unknown>,\n ],\n default: def as zm.mDefault<unknown[]>,\n required,\n validate: { validator, message },\n };\n}\n\n/**\n * Maps `z.literal()` to the closest native Mongoose representation of its\n * value(s):\n * - all-string values -> `String` with Mongoose's native `enum` constraint\n * - all-number / all-boolean values -> that primitive type plus a\n * `validate` enforcing membership (Mongoose has no native `enum` for\n * non-string types)\n * - anything else (mixed types, or types Mongoose has no primitive for,\n * e.g. `bigint`) -> `Mixed` plus the same membership `validate`\n * `z.literal()` supports multiple values in Zod v4 (`z.literal([\"a\", \"b\"])`),\n * which is why this always validates against the full `values` array rather\n * than assuming a single value.\n */\nfunction parseLiteral(values: unknown[], required = true, def?: unknown): zm.mField {\n const types = new Set(values.map((v) => typeof v));\n const message = `Value must be one of: ${values.map((v) => JSON.stringify(v)).join(\", \")}`;\n\n if (types.size === 1 && types.has(\"string\")) {\n return parseEnum(values as string[], required, def as zm.mDefault<string>);\n }\n\n if (types.size === 1 && types.has(\"number\")) {\n return {\n type: Number,\n required,\n unique: false,\n sparse: false,\n default: def as zm.mDefault<number>,\n validate: { validator: (v: number) => values.includes(v), message },\n };\n }\n\n if (types.size === 1 && types.has(\"boolean\")) {\n return {\n type: Boolean,\n required,\n default: def as zm.mDefault<boolean>,\n validate: { validator: (v: boolean) => values.includes(v), message },\n };\n }\n\n return {\n type: SchemaTypes.Mixed,\n required,\n default: def as unknown as any,\n validate: { validator: (v: unknown) => values.includes(v), message },\n };\n}\n\n/**\n * `z.discriminatedUnion()` models real polymorphic documents (variants that\n * share a discriminant key but otherwise diverge in shape), which Mongoose\n * has no first-class support for on a plain nested field (Mongoose's own\n * \"discriminator\" feature only applies to top-level models / array\n * subdocuments, not to an arbitrary object-valued field). Rather than pick\n * one variant's shape and lose the others (as the plain `union` handling\n * does), this maps the field to `Mixed` and validates it against the\n * *entire* original discriminated-union schema via `.safeParse()` - which\n * already implements exactly the \"dispatch on the discriminant, then\n * validate against the matching variant\" behavior this needs, so there is no\n * reason to reimplement it.\n */\nfunction parseDiscriminatedUnion(\n field: ZodType,\n required = true,\n def?: unknown,\n): zm.mMixed<unknown> {\n return {\n type: SchemaTypes.Mixed,\n required,\n default: def as unknown as any,\n validate: {\n validator: (v: unknown) => field.safeParse(v).success,\n message: \"Value does not match any variant of the discriminated union\",\n },\n };\n}\n\nexport default zodSchema;\n"],"mappings":";;;AAEO,IAAU;CAAV,SAAA,cAAA;CACE,SAAS,SAAS,GAAkC;EACzD,OAAO,eAAe,KAAK,EAAE,cAAc;CAC7C;;CAEO,SAAS,KAAK,GAAkC;EACrD,OAAO,eAAe,KAAK,EAAE,cAAc;CAC7C;;AACD,EAAA,CAAA,gBAAA,cAAA,CAAA,EAAD;;;AEPA,IAAA,qBAAe;CDWb,OAAO,GAAsB;EAC3B,OAAO,EAAE,KAAK,IAAI,SAAS;CAC7B;CAEA,OAAO,GAAsB;EAC3B,OAAO,EAAE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yBAAyB,OAAO,KAAK,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;CAEvF,IAAI,MAAM,SAAS,KAAK,MAAM,IAAI,QAAQ,GACxC,OAAO,UAAU,QAAoB,UAAU,GAA0B;CAG3E,IAAI,MAAM,SAAS,KAAK,MAAM,IAAI,QAAQ,GACxC,OAAO;EACL,MAAM;EACN;EACA,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,UAAU;GAAE,YAAY,MAAc,OAAO,SAAS,CAAC;GAAG;EAAQ;CACpE;CAGF,IAAI,MAAM,SAAS,KAAK,MAAM,IAAI,SAAS,GACzC,OAAO;EACL,MAAM;EACN;EACA,SAAS;EACT,UAAU;GAAE,YAAY,MAAe,OAAO,SAAS,CAAC;GAAG;EAAQ;CACrE;CAGF,OAAO;EACL,MAAM,YAAY;EAClB;EACA,SAAS;EACT,UAAU;GAAE,YAAY,MAAe,OAAO,SAAS,CAAC;GAAG;EAAQ;CACrE;AACF;;;;;;;;;;;;;;AAeA,SAAS,wBACP,OACA,WAAW,MACX,KACoB;CACpB,OAAO;EACL,MAAM,YAAY;EAClB;EACA,SAAS;EACT,UAAU;GACR,YAAY,MAAe,MAAM,UAAU,CAAC,CAAC,CAAC;GAC9C,SAAS;EACX;CACF;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parziva-1/zod-mongoose",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "A library that allows you to generate mongoose schemas from zod objects. Fork of @zodyac/zod-mongoose with Zod v4 support.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "jest",
|
|
7
|
+
"test:run": "node test.js",
|
|
8
|
+
"test:badges": "jest --coverage && make-coverage-badge --report-path ./artifacts/coverage/coverage-summary.json --output-path ./badges/coverage.svg",
|
|
9
|
+
"build": "tsdown",
|
|
10
|
+
"lint": "biome check",
|
|
11
|
+
"lint:fix": "biome check --write .",
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"check:types": "attw --pack . --ignore-rules cjs-resolves-to-esm",
|
|
14
|
+
"check:pack": "publint",
|
|
15
|
+
"check": "npm run lint && npm run typecheck && npm run test && npm run build && npm run check:types && npm run check:pack",
|
|
16
|
+
"changeset": "changeset",
|
|
17
|
+
"version-packages": "changeset version",
|
|
18
|
+
"release": "npm run build && changeset publish"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"typings": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"private": false,
|
|
33
|
+
"sideEffects": true,
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"author": "bebrasmell",
|
|
38
|
+
"contributors": [
|
|
39
|
+
"Jaime Linares <jaime.linares@innovaitors.ai> (https://github.com/parziva-1)"
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"homepage": "https://github.com/parziva-1/zod-mongoose#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/parziva-1/zod-mongoose/issues"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/parziva-1/zod-mongoose.git"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"zod",
|
|
52
|
+
"mongoose",
|
|
53
|
+
"schema",
|
|
54
|
+
"validation",
|
|
55
|
+
"typescript",
|
|
56
|
+
"type",
|
|
57
|
+
"types",
|
|
58
|
+
"type-safe",
|
|
59
|
+
"validation",
|
|
60
|
+
"mongodb",
|
|
61
|
+
"mongo",
|
|
62
|
+
"database",
|
|
63
|
+
"db",
|
|
64
|
+
"orm",
|
|
65
|
+
"odm",
|
|
66
|
+
"document"
|
|
67
|
+
],
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
70
|
+
"@biomejs/biome": "2.3.8",
|
|
71
|
+
"@changesets/changelog-github": "^1.0.0",
|
|
72
|
+
"@changesets/cli": "^3.0.1",
|
|
73
|
+
"@swc/core": "1.15.3",
|
|
74
|
+
"@swc/jest": "0.2.39",
|
|
75
|
+
"@types/jest": "30.0.0",
|
|
76
|
+
"@types/node": "24.10.1",
|
|
77
|
+
"jest": "30.2.0",
|
|
78
|
+
"make-coverage-badge": "1.2.0",
|
|
79
|
+
"mongoose": "8.24.3",
|
|
80
|
+
"publint": "^0.3.24",
|
|
81
|
+
"tsdown": "^0.22.14",
|
|
82
|
+
"typescript": "5.9.2",
|
|
83
|
+
"zod": "^4.4.3"
|
|
84
|
+
},
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"mongoose": "^8.20.2 || ^9.0.0",
|
|
87
|
+
"zod": "^4.0.0"
|
|
88
|
+
},
|
|
89
|
+
"packageManager": "npm@12.0.2",
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": ">=20"
|
|
92
|
+
}
|
|
93
|
+
}
|