zod-nest 3.2.1 → 3.2.3
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/README.md +1 -0
- package/dist/{chunk-RTWHQFNA.mjs → chunk-47ML6LKE.mjs} +5 -5
- package/dist/{chunk-RTWHQFNA.mjs.map → chunk-47ML6LKE.mjs.map} +1 -1
- package/dist/{chunk-LXRBMFWD.js → chunk-4LOFWANL.js} +6 -6
- package/dist/{chunk-LXRBMFWD.js.map → chunk-4LOFWANL.js.map} +1 -1
- package/dist/{chunk-KSDHVGMB.js → chunk-6FL3HR4I.js} +45 -45
- package/dist/{chunk-KSDHVGMB.js.map → chunk-6FL3HR4I.js.map} +1 -1
- package/dist/{chunk-BAG3BDRM.mjs → chunk-7IPDYJNI.mjs} +37 -57
- package/dist/chunk-7IPDYJNI.mjs.map +1 -0
- package/dist/{chunk-T4KTFCJW.js → chunk-DUQLL62I.js} +94 -114
- package/dist/chunk-DUQLL62I.js.map +1 -0
- package/dist/chunk-EV5I5HGT.js +127 -0
- package/dist/chunk-EV5I5HGT.js.map +1 -0
- package/dist/{chunk-WI4JKXT6.mjs → chunk-IMEFMJTS.mjs} +3 -3
- package/dist/{chunk-WI4JKXT6.mjs.map → chunk-IMEFMJTS.mjs.map} +1 -1
- package/dist/chunk-MPNAA53V.mjs +119 -0
- package/dist/chunk-MPNAA53V.mjs.map +1 -0
- package/dist/express/index.js +20 -20
- package/dist/express/index.mjs +5 -5
- package/dist/fastify/index.js +11 -11
- package/dist/fastify/index.mjs +5 -5
- package/dist/helpers/index.js +24 -24
- package/dist/helpers/index.mjs +3 -3
- package/dist/index.js +203 -203
- package/dist/index.mjs +4 -4
- package/package.json +26 -33
- package/dist/chunk-4RXGLSPP.js +0 -73
- package/dist/chunk-4RXGLSPP.js.map +0 -1
- package/dist/chunk-BAG3BDRM.mjs.map +0 -1
- package/dist/chunk-T4KTFCJW.js.map +0 -1
- package/dist/chunk-ZZW54ETO.mjs +0 -67
- package/dist/chunk-ZZW54ETO.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/constants.ts","../src/schema/discover-dependents.ts","../src/schema/registry.ts","../src/schema/composition.ts","../src/schema/errors.ts","../src/schema/override.ts","../src/schema/post-process.ts","../src/schema/engine.ts","../src/dto/symbols.ts","../src/dto/predicates.ts","../src/exceptions/validation.exception.ts","../src/schema/anon-id.ts","../src/decorators/internal/zod-schema-ref.ts","../src/decorators/internal/zod-param-expand.ts","../src/decorators/internal/flatten-intersection.ts"],"names":["COMPONENTS_SCHEMAS_PREFIX","DEFS_PREFIX","ZOD_NEST_ERROR_EXTENSION","ZOD_NEST_ERROR_DUPLICATE_ID","ZOD_NEST_DTO_EXTENSION","INNER_TYPE_WRAPPERS","Set","resolveLazyTarget","getter","error","ReferenceError","collectChildren","schema","def","_zod","type","shape","out","Object","values","catchall","undefined","push","element","options","map","opt","left","right","items","it","rest","keyType","valueType","in","has","innerType","discoverDependents","visited","WeakSet","stack","length","current","pop","add","child","named","findRefTarget","owner","id","createRegistry","__name","seen","Map","forceExposed","anonymous","pendingRoots","recordOnce","set","get","flushPendingDiscovery","root","splice","childId","zodRegistry","z","globalRegistry","register","flags","expose","existing","hasCollision","size","getCollisions","ids","keys","forceExposedIds","anonymousIds","defaultRegistry","singleton","registerSchema","registry","explicit","findIdOwner","lineageMap","WeakMap","OPTIONAL_WRAPPER_TYPES","isOptionalProp","propSchema","computeShapeKeys","entries","properties","key","required","filter","computeOverriddenKeys","parent","overriddenKeys","parentProp","extend","build","result","op","getLineage","DEFAULT_BUILD_REF","createCompositionOverride","opts","buildRef","ctx","jsonSchema","zodSchema","entry","parentCache","parentId","childProps","childRequired","parentPropSet","parentReqSet","deltaProps","value","deltaRequired","delta","additionalProperties","allOf","$ref","unevaluatedProperties","ZodNestError","Error","message","name","ZodNestUnrepresentableError","path","zodType","formatPath","String","join","primitiveOverride","format","combine","overrides","list","candidate","o","rewriteRefs","node","rootRef","Array","isArray","item","obj","ref","startsWith","slice","refsIn","rootDefId","raw","isReferenced","defs","ownRef","referencesRoot","stripEnvelope","$schema","$defs","resolveRoot","refs","liftedId","body","delete","rootId","strict","postProcess","rawDefs","STRICT_REQUIRES_OVERRIDE","ANNOTATION_ONLY_KEYS","isStrictlyUnrepresentable","every","descentTarget","$in","io","traits","markPipeCoverage","covered","target","buildToJsonSchemaOptions","params","compositionOverride","uri","customOverride","createCustomOverride","merged","override","unrepresentableHits","coveredByPipe","wrapped","record","peekRegistration","unrepresentable","metadata","cycles","reused","consumeUnrepresentable","firstHit","find","hit","resolveRootId","toOpenApi","built","toJSONSchema","description","ZOD_DTO_SYMBOL","Symbol","for","isZodDto","isZodSchema","ZodType","ZodValidationException","BadRequestException","zodError","argMetadata","statusCode","HttpStatus","BAD_REQUEST","errors","treeifyError","cause","ANON_RESPONSE_PREFIX","ANON_BODY_PREFIX","anonIdCache","counterRef","resolveAnonId","prefix","cached","resolveSchemaRef","kind","deferAnonInline","anonId","isZodObject","expandObjectSchema","decoratorName","resolution","forceRequired","paramSchemaBody","intersectionArms","unionOptions","collectObjectShapes","shapes","unionCrossed","allShapes","variant","variantResult","arms","flattenObjectIntersection","collected","mergedShape","assign","optional","object"],"mappings":";;;;;;;AACO,IAAMA,yBAAAA,GAA4B;AAGlC,IAAMC,WAAAA,GAAc,UAAA;AAGpB,IAAMC,wBAAAA,GAA2B;AAGjC,IAAMC,2BAAAA,GAA8B;AAQpC,IAAMC,sBAAAA,GAAyB;;;ACZtC,IAAMC,mBAAAA,uBAA0BC,GAAAA,CAAI;AAClC,EAAA,UAAA;AACA,EAAA,UAAA;AACA,EAAA,SAAA;AACA,EAAA,UAAA;AACA,EAAA,OAAA;AACA,EAAA,aAAA;AACA,EAAA,SAAA;AACA,EAAA,UAAA;AACA,EAAA;AACD,CAAA,CAAA;AAKD,IAAMC,iBAAAA,4CAAqBC,MAAAA,KAAAA;AACzB,EAAA,IAAI;AACF,IAAA,OAAO;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tC,EAAA,IAAIgP,cAAc,IAAA,EAAM;AACtB,IAAA,MAAM,IAAI9H,YAAAA,CACR,CAAA,EAAGgH,aAAAA,CAAAA,mSAAAA,CAG2E,CAAA;AAElF,EAAA;AACA,EAAA,MAAMe,cAAyC,EAAC;AAChD,EAAA,KAAA,MAAW7O,KAAAA,IAAS4O,UAAUP,MAAAA,EAAQ;AACpCnO,IAAAA,MAAAA,CAAO4O,MAAAA,CAAOD,aAAa7O,KAAAA,CAAAA;AAC7B,EAAA;AACA,EAAA,IAAI4O,UAAUN,YAAAA,EAAc;AAK1B,IAAA,KAAA,MAAW,CAAC1J,GAAAA,EAAK2B,KAAAA,KAAUrG,MAAAA,CAAOwE,OAAAA,CAAQmK,WAAAA,CAAAA,EAAc;AACtDA,MAAAA,WAAAA,CAAYjK,GAAAA,CAAAA,GAAO2B,KAAAA,CAAMwI,QAAAA,EAAQ;AACnC,IAAA;AACF,EAAA;AACA,EAAA,MAAMlE,MAAAA,GAAS5H,KAAAA,CAAE+L,MAAAA,CAAOH,WAAAA,CAAAA;AAOxB7K,EAAAA,cAAAA,CAAepE,QAAQqE,QAAAA,CAAAA;AAKvB,EAAA,KAAA,MAAW,CAACpC,KAAAA,EAAOkB,OAAAA,CAAAA,IAAY1B,kBAAAA,CAAmBzB,MAAAA,CAAAA,EAAS;AACzDqE,IAAAA,QAAAA,CAASd,QAAAA,CAAStB,OAAOkB,OAAAA,CAAAA;AAC3B,EAAA;AACA,EAAA,MAAM,EAAEnD,MAAAA,EAAQ0J,IAAAA,EAAI,GAAKuC,UAAUhB,MAAAA,EAAQ;IAAEX,EAAAA,EAAI,OAAA;AAASjG,IAAAA;GAAS,CAAA;AACnE,EAAA,OAAOqF,IAAAA;AACT,CAAA,EA5CyC,2BAAA","file":"chunk-DUQLL62I.js","sourcesContent":["/** OpenAPI 3.1 `$ref` prefix for entries in `components.schemas`. */\nexport const COMPONENTS_SCHEMAS_PREFIX = '#/components/schemas/';\n\n/** JSON Schema `$ref` prefix for entries in `$defs` (single-schema emission). */\nexport const DEFS_PREFIX = '#/$defs/';\n\n/** OpenAPI extension key zod-nest uses to surface engine errors inside emitted schemas. */\nexport const ZOD_NEST_ERROR_EXTENSION = 'x-zod-nest-error';\n\n/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */\nexport const ZOD_NEST_ERROR_DUPLICATE_ID = 'duplicate-id';\n\n/**\n * OpenAPI extension key used by `createZodDto` to mark a class for `applyZodNest`.\n * The marker carries `{ __zodNestDto: true, dtoId, io }` so `applyZodNest` can\n * locate every zod-nest DTO in the @nestjs/swagger document and inject the\n * real Zod-derived schema.\n */\nexport const ZOD_NEST_DTO_EXTENSION = 'x-zod-nest-dto';\n","import { z } from 'zod';\n\nimport type { $ZodType, $ZodTypes } from 'zod/v4/core';\n\nimport { findRefTarget } from './clone-chain.js';\n\nconst INNER_TYPE_WRAPPERS = new Set([\n 'optional',\n 'nullable',\n 'default',\n 'prefault',\n 'catch',\n 'nonoptional',\n 'success',\n 'readonly',\n 'promise',\n]);\n\n// A `z.lazy` getter can close over a `const` still in its temporal dead zone\n// (mutual recursion under ESM). Treat that as \"no child yet\" — `toOpenApi`\n// calls the getter again and reports a genuinely broken reference then.\nconst resolveLazyTarget = (getter: () => $ZodType): z.ZodType[] => {\n try {\n return [getter() as unknown as z.ZodType];\n } catch (error) {\n if (error instanceof ReferenceError) {\n return [];\n }\n throw error;\n }\n};\n\nconst collectChildren = (schema: z.ZodType): z.ZodType[] => {\n const def = (schema as unknown as $ZodTypes)._zod.def;\n if (def.type === 'object') {\n const shape = def.shape as Record<string, z.ZodType>;\n const out: z.ZodType[] = [...Object.values(shape)];\n if (def.catchall !== undefined) {\n out.push(def.catchall as unknown as z.ZodType);\n }\n return out;\n }\n if (def.type === 'array') {\n return [def.element as unknown as z.ZodType];\n }\n if (def.type === 'union') {\n return (def.options as readonly $ZodType[]).map((opt) => opt as unknown as z.ZodType);\n }\n if (def.type === 'intersection') {\n return [def.left as unknown as z.ZodType, def.right as unknown as z.ZodType];\n }\n if (def.type === 'tuple') {\n const out: z.ZodType[] = (def.items as readonly $ZodType[]).map(\n (it) => it as unknown as z.ZodType,\n );\n if (def.rest !== null) {\n out.push(def.rest as unknown as z.ZodType);\n }\n return out;\n }\n if (def.type === 'record' || def.type === 'map') {\n return [def.keyType as unknown as z.ZodType, def.valueType as unknown as z.ZodType];\n }\n if (def.type === 'set') {\n return [def.valueType as unknown as z.ZodType];\n }\n if (def.type === 'pipe') {\n return [def.in as unknown as z.ZodType, def.out as unknown as z.ZodType];\n }\n if (def.type === 'lazy') {\n return resolveLazyTarget(() => def.getter());\n }\n if (INNER_TYPE_WRAPPERS.has(def.type)) {\n return [(def as { innerType: $ZodType }).innerType as unknown as z.ZodType];\n }\n return [];\n};\n\n/**\n * Returns every named descendant of `schema` — sub-schemas carrying\n * `.meta({ id })` reachable through the Zod composition tree, at any depth.\n *\n * Cycle-safe via a visited `WeakSet` keyed by Zod schema identity; safe for\n * `z.lazy` schemas that close over themselves. Leaf types (string, number,\n * enum, literal, custom, transform, …) have no children and are skipped.\n */\nexport const discoverDependents = (schema: z.ZodType): ReadonlyArray<[z.ZodType, string]> => {\n const visited = new WeakSet<z.ZodType>();\n const out: [z.ZodType, string][] = [];\n const stack: z.ZodType[] = [schema];\n while (stack.length > 0) {\n const current = stack.pop() as z.ZodType;\n if (visited.has(current)) {\n continue;\n }\n visited.add(current);\n for (const child of collectChildren(current)) {\n // Defensive: a malformed/in-progress schema can yield an undefined slot\n // (sparse object shape, undefined tuple item, etc.). The walker treats\n // such slots as \"no child here\" rather than crashing — the user's\n // schema may still emit fine through `toJSONSchema`.\n if (child === undefined || visited.has(child)) {\n continue;\n }\n // Zod emits `$ref` to a named *ancestor* of a `.describe()` / `.refine()`\n // / `z.compile()` clone, so the ancestor is the document dependency.\n const named = findRefTarget(child);\n if (named !== undefined) {\n out.push([named.owner, named.id]);\n }\n stack.push(child);\n }\n }\n return out;\n};\n","import { z } from 'zod';\n\nimport { findIdOwner } from './clone-chain.js';\nimport { discoverDependents } from './discover-dependents.js';\nimport { singleton } from './singleton.js';\n\n/**\n * Per-registration flags carried alongside the id.\n *\n * - `expose` — force the id into the emitted document even when no endpoint\n * references it. The author deliberately wants it in `components.schemas`\n * (e.g. for out-of-band client codegen). Default exposure is otherwise\n * reachability-scoped, so an unreferenced schema is pruned unless flagged.\n * - `anonymous` — the id is a synthetic placeholder for a schema with no\n * resolvable id (passed inline to `@ZodResponse` / `@ZodBody`). It exists\n * only to carry the body through bulk emission under the document's\n * `strict` / `override` options; `inlineAnonymousBodies` later inlines the\n * body at each `$ref` site and prunes the component, so the synthetic id\n * never reaches the final document.\n *\n * Both flags are sticky — once set for an id they stay set, so a later plain\n * `register` of the same id (e.g. the idempotent re-register inside\n * `createZodDto`) doesn't clear them.\n */\nexport interface RegisterFlags {\n readonly expose?: boolean;\n readonly anonymous?: boolean;\n}\n\nexport interface ZodNestRegistry {\n readonly zodRegistry: typeof z.globalRegistry;\n register(schema: z.ZodType, id: string, flags?: RegisterFlags): void;\n hasCollision(id: string): boolean;\n getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;\n /**\n * Snapshot of every id registered through this `ZodNestRegistry`. The\n * underlying Zod registry is `z.globalRegistry`, which may hold third-party\n * entries — bulk emission filters its output against this snapshot to keep\n * only zod-nest-known ids.\n *\n * Includes ids discovered transitively via `.meta({ id })` on descendants\n * of explicitly-registered schemas.\n */\n ids(): readonly string[];\n /** Ids registered with `{ expose: true }` — exposed regardless of usage. */\n forceExposedIds(): readonly string[];\n /** Ids registered with `{ anonymous: true }` — inlined + pruned by `applyZodNest`. */\n anonymousIds(): readonly string[];\n}\n\nexport const createRegistry = (): ZodNestRegistry => {\n const seen = new Map<string, Set<z.ZodType>>();\n const forceExposed = new Set<string>();\n const anonymous = new Set<string>();\n const pendingRoots: z.ZodType[] = [];\n\n const recordOnce = (schema: z.ZodType, id: string): boolean => {\n let set = seen.get(id);\n if (set === undefined) {\n set = new Set<z.ZodType>();\n seen.set(id, set);\n }\n if (set.has(schema)) {\n return false;\n }\n set.add(schema);\n return true;\n };\n\n const flushPendingDiscovery = (): void => {\n for (const root of pendingRoots.splice(0)) {\n for (const [child, childId] of discoverDependents(root)) {\n recordOnce(child, childId);\n }\n }\n };\n\n return {\n zodRegistry: z.globalRegistry,\n register: (schema, id, flags) => {\n // Flags are sticky: a later plain re-register of the same id (e.g. the\n // idempotent call inside `createZodDto`) must not clear an earlier\n // `expose` / `anonymous`.\n if (flags?.expose === true) {\n forceExposed.add(id);\n }\n if (flags?.anonymous === true) {\n anonymous.add(id);\n }\n // `globalRegistry.add` overwrites the schema's entire meta entry; we\n // must merge so user-supplied fields (`title`, `description`,\n // anything else in `.meta({...})`) survive registration. The `has`\n // gate avoids promoting parent-inherited meta into a local entry\n // — `get()` returns parent-merged metadata when the schema has no\n // local entry, and writing that back here would freeze the\n // inherited fields against the schema.\n if (z.globalRegistry.has(schema)) {\n // `?? {}` is unreachable — the `has` gate guarantees a local entry —\n // but the return type is optional, so the fallback satisfies it.\n const existing = z.globalRegistry.get(schema) ?? {};\n if (existing.id !== id) {\n z.globalRegistry.add(schema, { ...existing, id });\n }\n } else {\n z.globalRegistry.add(schema, { id });\n }\n if (!recordOnce(schema, id)) {\n return;\n }\n // Queue, don't walk: forcing `z.lazy` getters here reads forward\n // references still in their temporal dead zone (throws under ESM,\n // yields `undefined` under CJS). Draining on first read is always safe.\n pendingRoots.push(schema);\n },\n hasCollision: (id) => {\n flushPendingDiscovery();\n const set = seen.get(id);\n return set !== undefined && set.size > 1;\n },\n getCollisions: () => {\n flushPendingDiscovery();\n const out = new Map<string, Set<z.ZodType>>();\n for (const [id, set] of seen) {\n if (set.size <= 1) {\n continue;\n }\n out.set(id, set);\n }\n return out;\n },\n ids: () => {\n flushPendingDiscovery();\n return [...seen.keys()];\n },\n forceExposedIds: () => [...forceExposed],\n anonymousIds: () => [...anonymous],\n };\n};\n\n/** Process-wide default registry. Shared so subpath ids reach `applyZodNest`. */\nexport const defaultRegistry: ZodNestRegistry = singleton('default-registry', createRegistry);\n\nexport interface RegisterSchemaOptions {\n /** Forces this id, overriding any `.meta({ id })` already on the schema. */\n readonly id?: string;\n /**\n * Force the schema into the emitted document even when no endpoint\n * references it. Default exposure is reachability-scoped — see\n * {@link RegisterFlags.expose}.\n */\n readonly expose?: boolean;\n /**\n * Mark the resolved id as a synthetic anonymous placeholder — inlined and\n * pruned by `applyZodNest`. See {@link RegisterFlags.anonymous}.\n */\n readonly anonymous?: boolean;\n}\n\n/**\n * Register a schema with the given registry, resolving its id from (in order):\n * an explicit `options.id`, then `.meta({ id })` on the schema. Returns the\n * resolved id, or `undefined` when neither source yields one (the call is then\n * a no-op — callers with their own fallback path handle that case).\n *\n * Shared by `createZodDto` and `extend` so a schema named via `.meta({ id })`\n * gets its body emitted into `components.schemas` even when it never flows\n * through `createZodDto` (e.g. used only as an `extend()` parent — Zod's\n * `.extend()` produces a flat object, so the parent isn't a transitive\n * descendant of the child and would otherwise be missed by `discoverDependents`).\n *\n * Idempotent — `registry.register` already deduplicates repeat calls.\n */\nexport const registerSchema = (\n schema: z.ZodType,\n registry: ZodNestRegistry = defaultRegistry,\n options?: RegisterSchemaOptions,\n): string | undefined => {\n const flags: RegisterFlags = { expose: options?.expose, anonymous: options?.anonymous };\n const explicit = options?.id;\n if (typeof explicit === 'string' && explicit !== '') {\n registry.register(schema, explicit, flags);\n return explicit;\n }\n // Registers the *owner*, never the clone: two instances under one id read as\n // a collision (`recordOnce`), and the clone already emits `$ref` to the owner.\n const named = findIdOwner(schema, registry.zodRegistry);\n if (named === undefined) {\n return undefined;\n }\n registry.register(named.owner, named.id, flags);\n return named.id;\n};\n","/**\n * Composition layer — emits OpenAPI `allOf` for schemas derived via `extend`.\n *\n * **EXPERIMENTAL**: output shape may change as edge cases surface.\n */\n\nimport { z } from 'zod';\n\nimport type { $ZodType } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { DEFS_PREFIX } from './constants.js';\nimport { registerSchema } from './registry.js';\nimport { singleton } from './singleton.js';\n\n/**\n * Lineage record for a composition-derived schema. Read by the override to\n * emit `allOf` instead of a flat body.\n *\n * @experimental — shape may change.\n */\nexport interface LineageEntry {\n readonly op: 'extend';\n readonly parent: z.ZodObject;\n /**\n * Keys the child redeclared with a *different* schema than the parent's\n * (e.g. narrowing `type: SomeEnum` to `type: z.literal('A')`). Computed by\n * reference comparison at `extend()` time — Zod's `.extend()` keeps the same\n * shape reference for untouched keys and assigns a fresh one for overrides.\n * The composition override keeps these in the delta instead of dropping them\n * as parent-owned, so the narrowing survives in the emitted `allOf`.\n */\n readonly overriddenKeys: ReadonlySet<string>;\n}\n\n// `WeakMap` (not `z.registry`) so transient derived schemas can GC — Zod's\n// own docs warn against long-running registries pinning short-lived schemas.\nconst lineageMap = singleton('lineage-map', () => new WeakMap<$ZodType, LineageEntry>());\n\n/** Zod's wrapper types that make a property optional in JSON Schema's `required` sense. */\nexport const OPTIONAL_WRAPPER_TYPES: ReadonlySet<string> = new Set(['optional', 'default']);\n\nexport const isOptionalProp = (propSchema: z.ZodType): boolean =>\n OPTIONAL_WRAPPER_TYPES.has(propSchema._zod.def.type);\n\nconst computeShapeKeys = (\n schema: z.ZodObject,\n): { properties: readonly string[]; required: readonly string[] } => {\n const entries = Object.entries(schema.shape);\n return {\n properties: entries.map(([key]) => key),\n required: entries.filter(([, propSchema]) => !isOptionalProp(propSchema)).map(([key]) => key),\n };\n};\n\n/**\n * Keys the child shares with the parent by name but redeclares with a\n * different schema. Relies on Zod's `.extend()` reference semantics: untouched\n * keys keep the parent's shape reference, overridden keys get a fresh one.\n */\nconst computeOverriddenKeys = (parent: z.ZodObject, child: z.ZodObject): ReadonlySet<string> => {\n const overriddenKeys = new Set<string>();\n for (const key of Object.keys(child.shape)) {\n const parentProp = parent.shape[key];\n if (parentProp !== undefined && parentProp !== child.shape[key]) {\n overriddenKeys.add(key);\n }\n }\n return overriddenKeys;\n};\n\n/**\n * Wraps a derived `z.ZodObject` and records the parent → child link so\n * emission rewrites the body to `allOf: [{ $ref: <parent> }, <delta>]`.\n *\n * @experimental — output shape may change as the surface stabilizes.\n *\n * @example\n * const Base = z.object({ id: z.string() }).meta({ id: 'Base' });\n * const Child = extend(Base, (s) => s.extend({ role: z.string() }).meta({ id: 'Child' }));\n */\nexport const extend = <P extends z.ZodObject, S extends z.ZodObject>(\n parent: P,\n build: (p: P) => S,\n): S => {\n const result = build(parent);\n lineageMap.set(result, {\n op: 'extend',\n parent,\n overriddenKeys: computeOverriddenKeys(parent, result),\n });\n // Auto-register named parent/result so their bodies land in\n // `components.schemas`. Zod's `.extend()` produces a flat object, so the\n // parent isn't a transitive descendant of the result — without this, a\n // parent named only via `.meta({ id })` would be referenced by `$ref` but\n // never emitted, yielding `DANGLING_REF`. No-op when the schema is\n // anonymous. The composition override (below) re-registers against the\n // active registry at emit time as a backstop for custom-registry users.\n registerSchema(parent);\n registerSchema(result);\n return result;\n};\n\n/**\n * Read the lineage entry for a composition-derived schema, or `undefined`.\n *\n * @experimental — `LineageEntry` shape may change.\n */\nexport const getLineage = (schema: z.ZodType): LineageEntry | undefined => lineageMap.get(schema);\n\n/**\n * Default ref builder for single-schema mode (`toOpenApi`) — refs land in\n * `#/$defs/<id>` and `post-process` rewrites them to `#/components/schemas/<id>`.\n * Bulk mode passes its own `uri` callback so refs land at the final location.\n */\nexport const DEFAULT_BUILD_REF = (id: string): string => `${DEFS_PREFIX}${id}`;\n\nexport interface CreateCompositionOverrideOptions {\n /** Shape the `$ref` string for a parent id. Defaults to `#/$defs/<id>`. */\n buildRef: (id: string) => string;\n /** Registry to resolve parent ids against. Use the same instance the engine emits with. */\n registry: ZodNestRegistry;\n}\n\n/**\n * Factory for the composition override. Returns an `Override` that rewrites\n * composition-derived schemas to `allOf` form, falling back to Zod's flat\n * emission when no lineage entry exists or the parent has no registered id.\n *\n * Mutation happens in-place — Zod's override doesn't propagate\n * `ctx.jsonSchema = newBody` reassignments; only mutations on the existing\n * object reference reach the caller.\n */\nexport const createCompositionOverride = (opts: CreateCompositionOverrideOptions): Override => {\n const { buildRef, registry } = opts;\n return (ctx) => {\n const { jsonSchema, zodSchema } = ctx;\n const entry = lineageMap.get(zodSchema);\n if (entry === undefined) {\n return;\n }\n\n const parentCache = computeShapeKeys(entry.parent);\n\n // Backstop the eager `extend()` registration above: that only writes to\n // `defaultRegistry`, so custom-registry users need the parent surfaced\n // here too. Idempotent against the eager call.\n const parentId = registerSchema(entry.parent, registry);\n if (parentId === undefined) {\n // Anonymous parent — fall back to Zod's flat emission.\n return;\n }\n\n const childProps = jsonSchema.properties ?? {};\n const childRequired = jsonSchema.required ?? [];\n const parentPropSet = new Set(parentCache.properties);\n const parentReqSet = new Set(parentCache.required);\n\n const deltaProps: NonNullable<SchemaObject['properties']> = {};\n for (const [key, value] of Object.entries(childProps)) {\n // Drop parent-owned keys, but keep any the child overrode with a\n // different schema — otherwise the narrowing (e.g. enum → literal) is\n // lost and `allOf` would only carry the parent's wider constraint.\n if (parentPropSet.has(key) && !entry.overriddenKeys.has(key)) {\n continue;\n }\n deltaProps[key] = value;\n }\n // Mirror the properties logic: drop parent-required keys, but keep any the\n // child overrode and still requires — its narrowed body now lives in the\n // delta, so the `required` marker must travel with it (otherwise the\n // overridden field reads as optional in the delta arm, e.g. breaking a\n // discriminated union whose discriminator must be required on each arm).\n const deltaRequired = childRequired.filter(\n (key) => !parentReqSet.has(key) || entry.overriddenKeys.has(key),\n );\n\n const delta: SchemaObject = { type: 'object', properties: deltaProps };\n if (deltaRequired.length > 0) {\n delta.required = deltaRequired;\n }\n\n delete jsonSchema.properties;\n delete jsonSchema.required;\n delete jsonSchema.additionalProperties;\n // Keep `type: 'object'` on the wrapper rather than deleting it: every arm of\n // the `allOf` is an object, so the wrapper is unambiguously an object, and\n // the explicit `type` is the more correct / tool-friendly emission.\n // `type: 'object'` + `allOf` is valid (the instance must be an object AND\n // satisfy every arm); `unevaluatedProperties: false` still closes the shape.\n jsonSchema.type = 'object';\n jsonSchema.allOf = [{ $ref: buildRef(parentId) }, delta];\n jsonSchema.unevaluatedProperties = false;\n };\n};\n","export class ZodNestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ZodNestError';\n }\n}\n\nexport class ZodNestUnrepresentableError extends ZodNestError {\n readonly path: ReadonlyArray<string | number>;\n readonly zodType: string;\n\n constructor(path: ReadonlyArray<string | number>, zodType: string) {\n super(\n `Unrepresentable Zod schema \\`${zodType}\\` at ${formatPath(path)}: no override produced ` +\n `a JSON Schema body. Set strict: false to emit \\`{}\\` instead, or supply an \\`override\\` ` +\n `that handles this Zod type.`,\n );\n this.name = 'ZodNestUnrepresentableError';\n this.path = path;\n this.zodType = zodType;\n }\n}\n\nconst formatPath = (path: ReadonlyArray<string | number>): string => {\n if (path.length === 0) {\n return '<root>';\n }\n return '/' + path.map(String).join('/');\n};\n","import type { $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\n\nexport interface OverrideContext {\n zodSchema: $ZodTypes;\n jsonSchema: SchemaObject;\n path: (string | number)[];\n}\n\nexport type Override = (ctx: OverrideContext) => void;\n\n/**\n * Type-driven override for primitive Zod constructs that JSON Schema can't\n * represent directly (bigint → integer, date → string + date-time format).\n * Composition's `allOf`-form emission lives in `composition.ts`; the engine\n * combines both into the full override chain per call site (since composition\n * needs a uri-aware `buildRef` that differs between single-schema and bulk\n * emission).\n */\nexport const primitiveOverride: Override = ({ zodSchema, jsonSchema }) => {\n const type = zodSchema._zod.def.type;\n if (type === 'bigint') {\n jsonSchema.type = 'integer';\n return;\n }\n if (type === 'date') {\n jsonSchema.type = 'string';\n jsonSchema.format = 'date-time';\n return;\n }\n};\n\nexport const combine = (...overrides: ReadonlyArray<Override | undefined>): Override => {\n const list: Override[] = [];\n for (const candidate of overrides) {\n if (typeof candidate !== 'function') {\n continue;\n }\n list.push(candidate);\n }\n return (ctx) => {\n for (const o of list) {\n o(ctx);\n }\n };\n};\n","import type { SchemaObject } from './openapi.types.js';\n\nimport { COMPONENTS_SCHEMAS_PREFIX, DEFS_PREFIX } from './constants.js';\nimport { ZodNestError } from './errors.js';\n\nexport interface PostProcessResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\nexport interface PostProcessOptions {\n /** Component id of the emitted root, when it has one. Resolves `'#'` refs. */\n rootId?: string;\n strict?: boolean;\n}\n\n// Zod emits '#' for a cycle back to the document root, so it resolves to the\n// root's own component — never to whichever def happens to contain it.\nconst rewriteRefs = (node: unknown, rootRef: string | undefined): void => {\n if (Array.isArray(node)) {\n for (const item of node) {\n rewriteRefs(item, rootRef);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string' && ref.startsWith(DEFS_PREFIX)) {\n obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);\n } else if (ref === '#' && rootRef !== undefined) {\n obj.$ref = rootRef;\n }\n for (const value of Object.values(obj)) {\n rewriteRefs(value, rootRef);\n }\n};\n\nconst refsIn = function* (node: unknown): Generator<string> {\n if (Array.isArray(node)) {\n for (const item of node) {\n yield* refsIn(item);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n if (typeof obj.$ref === 'string') {\n yield obj.$ref;\n }\n for (const value of Object.values(obj)) {\n yield* refsIn(value);\n }\n};\n\nconst rootDefId = (raw: SchemaObject): string | undefined => {\n const ref = raw.$ref;\n if (typeof ref !== 'string' || !ref.startsWith(DEFS_PREFIX)) {\n return undefined;\n }\n return ref.slice(DEFS_PREFIX.length);\n};\n\nconst isReferenced = (defs: SchemaObject['$defs'], id: string): boolean => {\n const ownRef = `${DEFS_PREFIX}${id}`;\n for (const ref of refsIn(defs)) {\n if (ref === '#' || ref === ownRef) {\n return true;\n }\n }\n return false;\n};\n\nconst referencesRoot = (raw: SchemaObject): boolean => {\n for (const ref of refsIn(raw)) {\n if (ref === '#') {\n return true;\n }\n }\n return false;\n};\n\nconst stripEnvelope = (raw: SchemaObject): SchemaObject => {\n const root: SchemaObject = { ...raw };\n delete root.$schema;\n delete root.$defs;\n return root;\n};\n\ninterface ResolvedRoot {\n schema: SchemaObject;\n rootRef: string | undefined;\n}\n\n// A referenced root has to be addressable, so it keeps (or gains) a component\n// entry and the caller gets a `$ref`. Inlining an unreferenced one keeps zod\n// 4.4 and 4.5 emitting the same shape.\nconst resolveRoot = (\n raw: SchemaObject,\n refs: Map<string, SchemaObject>,\n options: PostProcessOptions | undefined,\n): ResolvedRoot => {\n const liftedId = rootDefId(raw);\n if (liftedId !== undefined) {\n const body = refs.get(liftedId);\n if (body !== undefined && !isReferenced(raw.$defs, liftedId)) {\n refs.delete(liftedId);\n return { schema: body, rootRef: undefined };\n }\n return { schema: stripEnvelope(raw), rootRef: `${COMPONENTS_SCHEMAS_PREFIX}${liftedId}` };\n }\n\n const root = stripEnvelope(raw);\n if (!referencesRoot(raw)) {\n return { schema: root, rootRef: undefined };\n }\n\n const rootId = options?.rootId;\n if (rootId === undefined) {\n if (options?.strict ?? true) {\n throw new ZodNestError(\n 'A schema referenced from inside its own emission has no id, so the reference ' +\n 'cannot be resolved. Add `.meta({ id: \"…\" })` to the root schema, or set ' +\n 'strict: false to leave the reference unresolved.',\n );\n }\n return { schema: root, rootRef: undefined };\n }\n\n refs.set(rootId, root);\n const rootRef = `${COMPONENTS_SCHEMAS_PREFIX}${rootId}`;\n return { schema: { $ref: rootRef }, rootRef };\n};\n\nexport const postProcess = (raw: SchemaObject, options?: PostProcessOptions): PostProcessResult => {\n const refs = new Map<string, SchemaObject>();\n const rawDefs = raw.$defs;\n if (rawDefs !== undefined) {\n for (const [id, body] of Object.entries(rawDefs)) {\n refs.set(id, body);\n }\n }\n\n const { schema, rootRef } = resolveRoot(raw, refs, options);\n rewriteRefs(schema, rootRef);\n\n for (const body of refs.values()) {\n rewriteRefs(body, rootRef);\n }\n\n return { schema, refs };\n};\n","import { z } from 'zod';\n\nimport type { $ZodType, $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { findIdOwner } from './clone-chain.js';\nimport { createCompositionOverride, DEFAULT_BUILD_REF } from './composition.js';\nimport { ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './constants.js';\nimport { createCustomOverride, peekRegistration } from './custom-override.js';\nimport { ZodNestUnrepresentableError } from './errors.js';\nimport { combine, primitiveOverride } from './override.js';\nimport { postProcess } from './post-process.js';\n\n/**\n * Zod constructs that JSON Schema can't represent without an override. When\n * one of these shows up and our combined override chain didn't produce any\n * body for it, strict mode collects the hit and surfaces it as a\n * `ZodNestUnrepresentableError`. Bound to `engine.ts` since the strict-hit\n * collection lives here too.\n */\nconst STRICT_REQUIRES_OVERRIDE: ReadonlySet<string> = new Set([\n 'bigint',\n 'date',\n 'symbol',\n 'undefined',\n 'void',\n 'map',\n 'set',\n 'transform',\n 'nan',\n 'custom',\n]);\n\n/**\n * Keywords that annotate a schema without describing its shape. A body made\n * only of these has no type, so it's as unrepresentable as an empty one —\n * `.meta({ title })` on an unregistered schema emits exactly that, and\n * checking emptiness alone let it through as a valid annotation-only body.\n *\n * Deliberately an allow-list of annotations rather than a deny-list of\n * structural keywords: an unrecognised keyword counts as structural, so a\n * future JSON Schema addition can't turn into a spurious build failure.\n */\nconst ANNOTATION_ONLY_KEYS: ReadonlySet<string> = new Set([\n 'title',\n 'description',\n 'deprecated',\n 'examples',\n 'default',\n 'readOnly',\n 'writeOnly',\n '$id',\n '$schema',\n '$comment',\n 'id',\n]);\n\nconst isStrictlyUnrepresentable = (jsonSchema: SchemaObject, zodSchema: $ZodTypes): boolean => {\n if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {\n return false;\n }\n return Object.keys(jsonSchema).every((key) => ANNOTATION_ONLY_KEYS.has(key));\n};\n\nexport interface ToOpenApiOptions {\n io: 'input' | 'output';\n registry: ZodNestRegistry;\n override?: Override;\n strict?: boolean;\n}\n\nexport interface ToOpenApiResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\ninterface UnrepresentableHit {\n path: (string | number)[];\n zodType: string;\n /**\n * Schema instance that emitted empty. Kept so `consumeUnrepresentable`\n * can drop hits whose outer pipe later marked them covered — pipes process\n * inner before outer in reverse-seen order, so the inner's hit fires\n * before the outer pipe gets to declare coverage.\n */\n zodSchema: $ZodType;\n}\n\nconst descentTarget = ($in: $ZodType, out: $ZodType, io: 'input' | 'output'): $ZodType => {\n if (io === 'output') {\n return out;\n }\n // A transform emits its output shape, so its input side is never the target.\n if ($in._zod.traits.has('$ZodTransform')) {\n return out;\n }\n return $in;\n};\n\n/**\n * Mark a pipe's descent target as covered by an outer registration when\n * the override for the outer pipe fires. Recurses for nested\n * pipe-of-pipe chains (e.g. `pipe(pipe2, transform)`) so the deep inner\n * descent target also has its strict-mode hit suppressed.\n *\n * Mirrors Zod's `pipeProcessor` descent rules (`json-schema-processors.js`):\n * - `io === 'output'` → cover `def.out`\n * - `io === 'input'` → cover `def.out` when `def.in` is a `$ZodTransform`\n * (Zod skips preprocessing on input emission), else `def.in`.\n */\nconst markPipeCoverage = (\n schema: $ZodType,\n io: 'input' | 'output',\n covered: WeakSet<$ZodType>,\n): void => {\n const def = schema._zod.def as { type: string; in?: $ZodType; out?: $ZodType };\n if (def.type !== 'pipe' || def.in === undefined || def.out === undefined) {\n return;\n }\n const target = descentTarget(def.in, def.out, io);\n if (covered.has(target)) {\n return;\n }\n covered.add(target);\n markPipeCoverage(target, io, covered);\n};\n\n/**\n * Parameters for `buildToJsonSchemaOptions` — the shared option-bag builder\n * used by both `toOpenApi` (single-schema mode) and `bulkEmit` (registry-mode).\n * Centralizes the override chain, unrepresentable detection,\n * metadata wiring, and target/cycles defaults so both paths emit equivalent\n * JSON Schema for the same input.\n */\nexport interface BuildToJsonSchemaOptionsParams {\n registry: ZodNestRegistry;\n io: 'input' | 'output';\n override?: Override;\n strict?: boolean;\n /**\n * Zod's strategy for anonymous reused sub-schemas. Both single-schema and\n * bulk modes use `'inline'` — `'ref'` extracts anonymous reused branches\n * into a virtual `__shared/$defs` table whose refs don't resolve against\n * `components.schemas`, producing dangling refs. Registered schemas\n * (`metadata.id` present) always go through the `uri` callback regardless,\n * so DTO-to-DTO `$ref`s are unaffected.\n */\n reused: 'inline' | 'ref';\n /** Bulk-mode only — shapes internal `$ref`s to `#/components/schemas/<id>`. */\n uri?: (id: string) => string;\n}\n\nexport interface BuiltJsonSchemaOptions {\n options: NonNullable<Parameters<typeof z.toJSONSchema>[1]>;\n /** Throws `ZodNestUnrepresentableError` if any strict-unrepresentable hit was collected during emission. */\n consumeUnrepresentable(): void;\n}\n\nexport const buildToJsonSchemaOptions = (\n params: BuildToJsonSchemaOptionsParams,\n): BuiltJsonSchemaOptions => {\n const strict = params.strict ?? true;\n // Composition's `buildRef` differs between single-schema and bulk modes:\n // single-schema emits `#/$defs/<id>` (post-process rewrites to\n // `#/components/schemas/<id>`); bulk emits `#/components/schemas/<id>`\n // directly via the configured `uri` callback (post-process is skipped).\n const compositionOverride = createCompositionOverride({\n buildRef: params.uri ?? DEFAULT_BUILD_REF,\n registry: params.registry,\n });\n // Chain order matches precedence (left → right, last-write-wins mutation\n // semantics). Caller's `params.override` runs last so per-call overrides\n // remain the ultimate escape hatch; `customOverride` consults the\n // `overrideJSONSchema(...)` registration map (parameterized by `io` so it\n // can pick divergent input/output fragments) and clobbers the built-in\n // primitive/composition mappings for the registered schema instance.\n const customOverride = createCustomOverride(params.io);\n const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);\n const unrepresentableHits: UnrepresentableHit[] = [];\n // Inner descent targets shadowed by an outer pipe registration. Populated\n // JIT during traversal: Zod processes inner-before-outer in reverse-seen\n // order, but `consumeUnrepresentable` runs only after traversal completes,\n // so by then the outer pipe's coverage declaration has landed.\n const coveredByPipe = new WeakSet<$ZodType>();\n\n const wrapped: Override = (ctx) => {\n merged(ctx);\n if (ctx.zodSchema._zod.def.type === 'pipe') {\n const record = peekRegistration(ctx.zodSchema);\n if (record !== undefined && record[params.io] !== undefined) {\n markPipeCoverage(ctx.zodSchema, params.io, coveredByPipe);\n }\n }\n if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {\n return;\n }\n unrepresentableHits.push({\n path: [...ctx.path],\n zodType: ctx.zodSchema._zod.def.type,\n zodSchema: ctx.zodSchema,\n });\n };\n\n const options: NonNullable<Parameters<typeof z.toJSONSchema>[1]> = {\n target: 'draft-2020-12',\n io: params.io,\n unrepresentable: 'any',\n metadata: params.registry.zodRegistry,\n override: wrapped,\n cycles: 'ref',\n reused: params.reused,\n };\n if (params.uri !== undefined) {\n options.uri = params.uri;\n }\n\n return {\n options,\n consumeUnrepresentable: () => {\n const firstHit = unrepresentableHits.find((hit) => !coveredByPipe.has(hit.zodSchema));\n if (firstHit !== undefined) {\n throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);\n }\n },\n };\n};\n\n// Covers both `.meta({ id })` and `registry.register(schema, id)` — the latter\n// writes the id through to the zod registry.\nconst resolveRootId = (schema: z.ZodType, registry: ZodNestRegistry): string | undefined =>\n findIdOwner(schema, registry.zodRegistry)?.id;\n\nexport const toOpenApi = (schema: z.ZodType, opts: ToOpenApiOptions): ToOpenApiResult => {\n const built = buildToJsonSchemaOptions({\n registry: opts.registry,\n io: opts.io,\n override: opts.override,\n strict: opts.strict,\n reused: 'inline',\n });\n const raw = z.toJSONSchema(schema, built.options);\n built.consumeUnrepresentable();\n\n const result = postProcess(raw, {\n rootId: resolveRootId(schema, opts.registry),\n strict: opts.strict,\n });\n\n for (const [id] of opts.registry.getCollisions()) {\n if (!result.refs.has(id)) {\n continue;\n }\n result.refs.set(id, {\n description: `ERROR: duplicate zod-nest id <${id}>`,\n [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID,\n });\n }\n\n return result;\n};\n","/** Runtime tag placed on every class returned by `createZodDto`. */\nexport const ZOD_DTO_SYMBOL: unique symbol = Symbol.for('zod-nest.dto');\n","import { z } from 'zod';\n\nimport type { ZodDto } from './dto.types.js';\n\nimport { ZOD_DTO_SYMBOL } from './symbols.js';\n\n/**\n * Runtime guard: is `value` a class returned by `createZodDto`?\n *\n * Used by `ZodValidationPipe`, `ZodSerializerInterceptor`, and `applyZodNest`\n * to discriminate zod-nest DTOs from plain\n * constructors, class-validator DTOs, primitives, and any other metatypes\n * NestJS exposes via `ArgumentMetadata`.\n */\nexport const isZodDto = (value: unknown): value is ZodDto =>\n typeof value === 'function' &&\n (value as unknown as Record<symbol, unknown>)[ZOD_DTO_SYMBOL] === true;\n\n/**\n * Runtime guard: is `value` a Zod schema (any `z.*` type)?\n *\n * Used by `@ZodResponse` to accept a raw schema in place of a DTO — including\n * `z.discriminatedUnion` / `z.union` / `z.intersection`, which can't be wrapped\n * with `createZodDto` (their `z.infer` is a union, so `class … extends\n * createZodDto(schema)` fails to typecheck with TS2509). `instanceof z.ZodType`\n * holds for every schema built through the same `zod` module instance.\n */\nexport const isZodSchema = (value: unknown): value is z.ZodType => value instanceof z.ZodType;\n","import { BadRequestException, HttpStatus } from '@nestjs/common';\nimport { z } from 'zod';\n\nimport type { ArgumentMetadata } from '@nestjs/common';\n\n/**\n * Default exception thrown by `ZodValidationPipe` when input fails to parse.\n *\n * Body shape (returned by `getResponse()`):\n * ```\n * {\n * statusCode: 400,\n * message: 'Validation failed',\n * errors: z.treeifyError(zodError),\n * }\n * ```\n *\n * Carries `zodError` and `argMetadata` so custom exception filters can\n * introspect the original validation failure.\n */\nexport class ZodValidationException extends BadRequestException {\n readonly zodError: z.ZodError;\n readonly argMetadata?: ArgumentMetadata;\n\n constructor(zodError: z.ZodError, argMetadata?: ArgumentMetadata) {\n super(\n {\n statusCode: HttpStatus.BAD_REQUEST,\n message: 'Validation failed',\n errors: z.treeifyError(zodError),\n },\n { cause: zodError },\n );\n this.zodError = zodError;\n this.argMetadata = argMetadata;\n }\n}\n","import type { z } from 'zod';\n\nimport { singleton } from './singleton.js';\n\n/** Synthetic-id prefix for an anonymous `@ZodResponse` body. */\nexport const ANON_RESPONSE_PREFIX = '_AnonResponseSchema_';\n/** Synthetic-id prefix for an anonymous `@ZodBody` body. */\nexport const ANON_BODY_PREFIX = '_AnonBodySchema_';\n\n/**\n * One synthetic id per schema instance, cached so the same un-named schema\n * reused across routes maps to a single id (and therefore a single registry\n * entry) rather than minting a fresh one per decoration. WeakMap so the id is\n * GC'd with the schema. Mirrors the cache pattern in `output-dto.ts` /\n * `normalize-type.ts`.\n *\n * The counter is module-global so ids are unique across both prefixes; the\n * prefix is only chosen on first sight of a schema, so a schema passed to both\n * `@ZodBody` and `@ZodResponse` keeps whichever id it got first — harmless,\n * since the id is internal and inlined away.\n */\nconst anonIdCache = singleton('anon-id-cache', () => new WeakMap<z.ZodType, string>());\nconst counterRef = singleton('anon-id-counter', () => ({ value: 0 }));\n\nexport const resolveAnonId = (schema: z.ZodType, prefix: string): string => {\n const cached = anonIdCache.get(schema);\n if (cached !== undefined) {\n return cached;\n }\n counterRef.value += 1;\n const id = `${prefix}${counterRef.value}`;\n anonIdCache.set(schema, id);\n return id;\n};\n","import { z } from 'zod';\n\nimport type { ZodNestRegistry } from '../../schema/registry.js';\n\nimport { ANON_BODY_PREFIX, resolveAnonId } from '../../schema/anon-id.js';\nimport { COMPONENTS_SCHEMAS_PREFIX } from '../../schema/constants.js';\nimport { discoverDependents } from '../../schema/discover-dependents.js';\nimport { toOpenApi } from '../../schema/engine.js';\nimport { defaultRegistry, registerSchema } from '../../schema/registry.js';\n\n/**\n * Resolution of a schema used by `@ZodBody` / `@ZodQuery` / `@ZodParam` /\n * `@ZodHeaders` / `@ZodCookies`.\n *\n * - `ref` — the schema (or property's schema) has an id via `.meta({ id })`\n * or via the explicit `id` option. It's registered in the registry so\n * `applyZodNest`'s bulk-emit pass writes its body to `components.schemas`,\n * and the decorator references it as `{ $ref: '#/components/schemas/<id>' }`.\n * - `inline` — no id was resolvable; the JSON Schema body is embedded\n * directly into the operation. Named descendants are still registered so\n * any nested `$ref`s inside the inline body resolve at doc-build time.\n */\nexport interface SchemaRefResolutionRef {\n readonly kind: 'ref';\n readonly ref: { readonly $ref: string };\n}\nexport interface SchemaRefResolutionInline {\n readonly kind: 'inline';\n readonly schema: Record<string, unknown>;\n}\nexport type SchemaRefResolution = SchemaRefResolutionRef | SchemaRefResolutionInline;\n\nexport interface ResolveSchemaRefOptions {\n /** Forces this id, overriding any `.meta({ id })` already on the schema. */\n readonly id?: string;\n /** Registry to register into. Defaults to `defaultRegistry`. */\n readonly registry?: ZodNestRegistry;\n /**\n * When `true`, an anonymous (un-named) schema is registered under a synthetic\n * `anonymous` id and returned as a `$ref` instead of being rendered inline\n * here. `applyZodNest`'s `inlineAnonymousBodies` pass then inlines the body\n * (emitted by bulk-emit under the document's `strict` / `override`) and\n * prunes the component. Used by `@ZodBody`, where the body is emitted as a\n * full schema; left `false` for per-property param expansion, which inlines\n * the (usually primitive) property body directly.\n */\n readonly deferAnonInline?: boolean;\n}\n\n/**\n * Resolve a schema for embedding in an OpenAPI operation. If the schema is\n * named (has `.meta({ id })` or an explicit `options.id`), it's registered\n * and a `$ref` is returned. Otherwise:\n *\n * - with `deferAnonInline`, the schema is registered under a synthetic\n * `anonymous` id and a `$ref` to it is returned — `applyZodNest` inlines and\n * prunes it later, so the body honors the document's `strict` / `override`;\n * - without it, the schema is rendered inline here via `toOpenApi(...)`, and\n * any *named descendants* are registered so refs inside the inline body\n * resolve at doc-build time.\n */\n// With `deferAnonInline: true`, an anonymous schema is registered and returned\n// as a `$ref` too, so the result is always a `ref` — narrow the return so\n// callers (e.g. `@ZodBody`) don't carry a dead `inline` branch.\nexport function resolveSchemaRef(\n schema: z.ZodType,\n options: ResolveSchemaRefOptions & { readonly deferAnonInline: true },\n): SchemaRefResolutionRef;\nexport function resolveSchemaRef(\n schema: z.ZodType,\n options?: ResolveSchemaRefOptions,\n): SchemaRefResolution;\nexport function resolveSchemaRef(\n schema: z.ZodType,\n options?: ResolveSchemaRefOptions,\n): SchemaRefResolution {\n const registry = options?.registry ?? defaultRegistry;\n const id = registerSchema(schema, registry, { id: options?.id });\n if (id !== undefined) {\n return { kind: 'ref', ref: { $ref: `${COMPONENTS_SCHEMAS_PREFIX}${id}` } };\n }\n if (options?.deferAnonInline === true) {\n // `registerSchema` registers the schema and (via `register`) its named\n // descendants, so nested `$ref`s inside the emitted body resolve.\n const anonId = resolveAnonId(schema, ANON_BODY_PREFIX);\n registerSchema(schema, registry, { id: anonId, anonymous: true });\n return { kind: 'ref', ref: { $ref: `${COMPONENTS_SCHEMAS_PREFIX}${anonId}` } };\n }\n for (const [child, childId] of discoverDependents(schema)) {\n registry.register(child, childId);\n }\n const { schema: body } = toOpenApi(schema, { io: 'input', registry });\n return { kind: 'inline', schema: body as Record<string, unknown> };\n}\n","import { z } from 'zod';\n\nimport type { ZodNestRegistry } from '../../schema/registry.js';\nimport type { SchemaRefResolution } from './zod-schema-ref.js';\n\nimport { isOptionalProp } from '../../schema/composition.js';\nimport { ZodNestError } from '../../schema/errors.js';\nimport { defaultRegistry, registerSchema } from '../../schema/registry.js';\nimport { resolveSchemaRef } from './zod-schema-ref.js';\n\nexport const isZodObject = (schema: z.ZodType): schema is z.ZodObject =>\n schema._zod.def.type === 'object';\n\nexport interface ExpandedParam {\n readonly name: string;\n readonly required: boolean;\n readonly resolution: SchemaRefResolution;\n}\n\nexport interface ExpandObjectSchemaOptions {\n readonly id?: string;\n readonly registry?: ZodNestRegistry;\n /**\n * When `true`, every expanded property is marked `required` regardless of\n * its Zod optionality — path params can't be optional in OpenAPI.\n */\n readonly forceRequired?: boolean;\n /** Decorator name used in error messages, e.g. `@ZodQuery`. */\n readonly decoratorName: string;\n}\n\n/**\n * Expand a Zod object schema into one parameter entry per property. Used by\n * `@ZodQuery`, `@ZodParam`, `@ZodHeaders`, and `@ZodCookies` — they all\n * project an object schema onto N named OpenAPI parameters.\n *\n * Registers the root schema (when it has an id) so `components.schemas[id]`\n * holds the full object body for cross-referencing. Each property's schema\n * goes through `resolveSchemaRef` independently: named properties become\n * `$ref`s, anonymous properties inline.\n *\n * Throws `ZodNestError` when the schema is not a `z.object` — non-object\n * schemas can't be represented as a flat list of named params in OpenAPI.\n */\nexport const expandObjectSchema = (\n schema: z.ZodType,\n options: ExpandObjectSchemaOptions,\n): ExpandedParam[] => {\n if (!isZodObject(schema)) {\n throw new ZodNestError(\n `${options.decoratorName} requires a \\`z.object({...})\\` schema (got \\`${schema._zod.def.type}\\`). ` +\n `Each property of the object becomes one OpenAPI parameter. ` +\n `For non-object body shapes (intersections, unions, primitives), use \\`@ZodBody\\` instead.`,\n );\n }\n const registry = options.registry ?? defaultRegistry;\n // Register the root if it has an id — it isn't referenced by the per-property\n // expansion below, so it'll only land in `components.schemas` when something\n // else references it (`@ZodBody`, another decorator, a manual `$ref`).\n // Idempotent + harmless when the schema is anonymous.\n registerSchema(schema, registry, { id: options.id });\n const result: ExpandedParam[] = [];\n for (const [name, propSchema] of Object.entries(schema.shape)) {\n const resolution = resolveSchemaRef(propSchema, { registry });\n const required = options.forceRequired === true || !isOptionalProp(propSchema);\n result.push({ name, required, resolution });\n }\n return result;\n};\n\n/**\n * Resolve the JSON Schema body for a single expanded parameter. `$ref` for\n * named property schemas, otherwise the inline JSON Schema body.\n */\nexport const paramSchemaBody = (\n resolution: SchemaRefResolution,\n): { $ref: string } | Record<string, unknown> =>\n resolution.kind === 'ref' ? resolution.ref : resolution.schema;\n","import { z } from 'zod';\n\nimport type { ZodNestRegistry } from '../../schema/registry.js';\n\nimport { discoverDependents } from '../../schema/discover-dependents.js';\nimport { toOpenApi } from '../../schema/engine.js';\nimport { ZodNestError } from '../../schema/errors.js';\nimport { registerSchema } from '../../schema/registry.js';\nimport { isZodObject } from './zod-param-expand.js';\n\n/**\n * Runtime shape of Zod v4's `$ZodIntersectionDef`. The upstream `.left` /\n * `.right` are typed as Zod's internal `$ZodType` base, not the public\n * `z.ZodType`; the structures are runtime-equivalent. The cast at the\n * boundary keeps the rest of this module on the public type.\n */\ninterface IntersectionDef {\n readonly type: 'intersection';\n readonly left: z.ZodType;\n readonly right: z.ZodType;\n}\n\ninterface UnionDef {\n readonly type: 'union';\n readonly options: ReadonlyArray<z.ZodType>;\n}\n\nconst intersectionArms = (\n schema: z.ZodType,\n): { readonly left: z.ZodType; readonly right: z.ZodType } | null => {\n if (schema._zod.def.type !== 'intersection') {\n return null;\n }\n // Zod-internal → public-type boundary: `$ZodType` vs `z.ZodType`.\n const def = schema._zod.def as unknown as IntersectionDef;\n return { left: def.left, right: def.right };\n};\n\nconst unionOptions = (schema: z.ZodType): ReadonlyArray<z.ZodType> | null => {\n if (schema._zod.def.type !== 'union') {\n return null;\n }\n // Zod-internal → public-type boundary. `discriminatedUnion` also uses\n // `type: 'union'` and shares the `options` field shape.\n const def = schema._zod.def as unknown as UnionDef;\n return def.options;\n};\n\ninterface CollectedShapes {\n readonly shapes: ReadonlyArray<Record<string, z.ZodType>>;\n /**\n * `true` when the walk traversed a union arm at any depth — signals that\n * the merged shape should mark all properties optional, since no single\n * property is guaranteed across the original variants.\n */\n readonly unionCrossed: boolean;\n}\n\n/**\n * Walk an intersection / union tree and collect every `z.object` shape\n * reachable. Returns `null` as soon as a non-object leaf is hit (a\n * primitive, a tuple, a transform — anything that isn't an object and\n * isn't a composite of objects). Single-object input returns one shape.\n */\nconst collectObjectShapes = (schema: z.ZodType): CollectedShapes | null => {\n if (isZodObject(schema)) {\n return { shapes: [schema.shape], unionCrossed: false };\n }\n const options = unionOptions(schema);\n if (options !== null) {\n const allShapes: Array<Record<string, z.ZodType>> = [];\n for (const variant of options) {\n const variantResult = collectObjectShapes(variant);\n if (variantResult === null) {\n return null;\n }\n allShapes.push(...variantResult.shapes);\n }\n return { shapes: allShapes, unionCrossed: true };\n }\n const arms = intersectionArms(schema);\n if (arms === null) {\n return null;\n }\n const left = collectObjectShapes(arms.left);\n if (left === null) {\n return null;\n }\n const right = collectObjectShapes(arms.right);\n if (right === null) {\n return null;\n }\n return {\n shapes: [...left.shapes, ...right.shapes],\n unionCrossed: left.unionCrossed || right.unionCrossed,\n };\n};\n\n/**\n * Merge an intersection / union tree of `z.object` arms into a single\n * anonymous `z.object`, emit it inline, and return the JSON Schema body.\n * Used by `@ZodBody({ flatten: true })` so Swagger UI's\n * `multipart/form-data` `try-it-out` form renders correctly — the UI\n * doesn't follow `$ref` or unwrap `allOf` / `oneOf`, so it needs a flat\n * object literal at the operation's `schema` site.\n *\n * Supported shapes:\n * - `z.object({...})` — single-arm case, identity merge.\n * - `z.intersection(obj, obj)` — merges both arms' properties.\n * - Nested intersections (`intersection(intersection(A, B), C)`) — all\n * reachable arms merged in source order.\n * - `z.union([obj, obj, ...])` / `z.discriminatedUnion(...)` — merges all\n * variant properties. **All merged properties become optional** because\n * no single property is guaranteed across the original variants.\n * - `intersection(union(...), union(...))` — combines the above; any\n * property reachable through a union is optional in the result.\n *\n * Rejected shapes (throws `ZodNestError`):\n * - Any non-object leaf at any depth: primitives, tuples, transforms,\n * nullable/optional wrappers around non-objects.\n *\n * Behavior details:\n * - Property collisions resolve right-arm-wins (mirrors `z.object`'s spread\n * semantics; for unions, later variants override earlier ones).\n * - The original schema's `.meta({ id })` on the root is *not* preserved —\n * the merged object is anonymous and lives only in the operation body.\n * - Per-property `.meta({ id })` schemas keep their `$ref` emission via\n * normal `toOpenApi` traversal.\n * - The spec emission becomes less precise (a union arm's \"you must supply\n * variant A or variant B\" becomes \"any subset of all variants' fields\").\n * This is the documented trade-off for Swagger UI compatibility — runtime\n * validation via `ZodValidationPipe(originalSchema)` still enforces the\n * precise shape.\n */\nexport const flattenObjectIntersection = (\n schema: z.ZodType,\n registry: ZodNestRegistry,\n decoratorName: string,\n): Record<string, unknown> => {\n const collected = collectObjectShapes(schema);\n if (collected === null) {\n throw new ZodNestError(\n `${decoratorName} \\`flatten: true\\` requires every leaf of the schema to be a ` +\n `\\`z.object({...})\\` — intersections and unions of objects are supported, but ` +\n `primitives, tuples, transforms, and other non-object leaves are not. Drop ` +\n `\\`flatten: true\\` to emit the original schema with its composition intact.`,\n );\n }\n const mergedShape: Record<string, z.ZodType> = {};\n for (const shape of collected.shapes) {\n Object.assign(mergedShape, shape);\n }\n if (collected.unionCrossed) {\n // Wrap each property in `.optional()` — no single property is guaranteed\n // across the original union variants, so the merged spec must allow any\n // subset. Runtime validation against the original schema still enforces\n // the precise variant shape.\n for (const [key, value] of Object.entries(mergedShape)) {\n mergedShape[key] = value.optional();\n }\n }\n const merged = z.object(mergedShape);\n // Register the root if it has a `.meta({ id })` so the schema's natural\n // (non-flattened) emission lands in `components.schemas[id]` via the\n // exposure-by-registration rule in `applyZodNest`. The inline operation\n // body remains the flat merged form for Swagger UI compatibility — the\n // catalog gets the structural composition (`allOf` / `oneOf`). No-op\n // when the schema is anonymous.\n registerSchema(schema, registry);\n // Walk named descendants of the *original* schema so per-property $refs\n // resolve when bulk-emit runs. `toOpenApi` below will also register\n // descendants of the merged shape, but the original may carry meta entries\n // on nodes that the merged object's shape doesn't directly reference.\n for (const [child, childId] of discoverDependents(schema)) {\n registry.register(child, childId);\n }\n const { schema: body } = toOpenApi(merged, { io: 'input', registry });\n return body as Record<string, unknown>;\n};\n"]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var sharesDef = /* @__PURE__ */ __name((child, parent) => child._zod.def === parent._zod.def, "sharesDef");
|
|
8
|
+
var resolveThroughClones = /* @__PURE__ */ __name((schema, lookup) => {
|
|
9
|
+
let current = schema;
|
|
10
|
+
for (; ; ) {
|
|
11
|
+
const hit = lookup(current);
|
|
12
|
+
if (hit !== void 0) {
|
|
13
|
+
return hit;
|
|
14
|
+
}
|
|
15
|
+
const parent = current._zod.parent;
|
|
16
|
+
if (parent === void 0 || !sharesDef(current, parent)) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
current = parent;
|
|
20
|
+
}
|
|
21
|
+
}, "resolveThroughClones");
|
|
22
|
+
var readOwnId = /* @__PURE__ */ __name((schema, metadata) => {
|
|
23
|
+
const id = metadata.get(schema)?.id;
|
|
24
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
25
|
+
}, "readOwnId");
|
|
26
|
+
var asZodType = /* @__PURE__ */ __name((schema) => schema, "asZodType");
|
|
27
|
+
var findIdOwner = /* @__PURE__ */ __name((schema, metadata = zod.z.globalRegistry) => resolveThroughClones(schema, (candidate) => {
|
|
28
|
+
const id = readOwnId(candidate, metadata);
|
|
29
|
+
return id === void 0 ? void 0 : {
|
|
30
|
+
owner: asZodType(candidate),
|
|
31
|
+
id
|
|
32
|
+
};
|
|
33
|
+
}), "findIdOwner");
|
|
34
|
+
var findRefTarget = /* @__PURE__ */ __name((schema, metadata = zod.z.globalRegistry) => {
|
|
35
|
+
let current = schema;
|
|
36
|
+
while (current !== void 0) {
|
|
37
|
+
const id = readOwnId(current, metadata);
|
|
38
|
+
if (id !== void 0) {
|
|
39
|
+
return {
|
|
40
|
+
owner: asZodType(current),
|
|
41
|
+
id
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
current = current._zod.parent;
|
|
45
|
+
}
|
|
46
|
+
return void 0;
|
|
47
|
+
}, "findRefTarget");
|
|
48
|
+
|
|
49
|
+
// src/schema/singleton.ts
|
|
50
|
+
var SINGLETONS = /* @__PURE__ */ Symbol.for("zod-nest.singletons");
|
|
51
|
+
var host = globalThis;
|
|
52
|
+
var store = /* @__PURE__ */ __name(() => {
|
|
53
|
+
const existing = host[SINGLETONS];
|
|
54
|
+
if (existing !== void 0) {
|
|
55
|
+
return existing;
|
|
56
|
+
}
|
|
57
|
+
const created = /* @__PURE__ */ new Map();
|
|
58
|
+
host[SINGLETONS] = created;
|
|
59
|
+
return created;
|
|
60
|
+
}, "store");
|
|
61
|
+
var singleton = /* @__PURE__ */ __name((key, create) => {
|
|
62
|
+
const values = store();
|
|
63
|
+
const existing = values.get(key);
|
|
64
|
+
if (existing !== void 0) {
|
|
65
|
+
return existing;
|
|
66
|
+
}
|
|
67
|
+
const created = create();
|
|
68
|
+
values.set(key, created);
|
|
69
|
+
return created;
|
|
70
|
+
}, "singleton");
|
|
71
|
+
|
|
72
|
+
// src/schema/custom-override.ts
|
|
73
|
+
var customOverrideMap = singleton("custom-override-map", () => /* @__PURE__ */ new WeakMap());
|
|
74
|
+
var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
|
|
75
|
+
var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
|
|
76
|
+
const overrideSchema = isWrapper(arg) ? {
|
|
77
|
+
...arg
|
|
78
|
+
} : {
|
|
79
|
+
input: arg,
|
|
80
|
+
output: arg
|
|
81
|
+
};
|
|
82
|
+
const schemaDescription = schema.description;
|
|
83
|
+
if (typeof schemaDescription === "string") {
|
|
84
|
+
overrideSchema.description = schemaDescription;
|
|
85
|
+
}
|
|
86
|
+
customOverrideMap.set(schema, overrideSchema);
|
|
87
|
+
return schema;
|
|
88
|
+
}, "overrideJSONSchema");
|
|
89
|
+
var peekRegistration = /* @__PURE__ */ __name((schema) => resolveThroughClones(schema, (candidate) => customOverrideMap.get(candidate)), "peekRegistration");
|
|
90
|
+
var createCustomOverride = /* @__PURE__ */ __name((io) => {
|
|
91
|
+
return ({ zodSchema, jsonSchema }) => {
|
|
92
|
+
const own = customOverrideMap.get(zodSchema);
|
|
93
|
+
const record = own ?? resolveThroughClones(zodSchema, (candidate) => customOverrideMap.get(candidate));
|
|
94
|
+
if (record === void 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const fragment = record[io];
|
|
98
|
+
if (fragment === void 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const isInherited = own === void 0;
|
|
102
|
+
if (isInherited && jsonSchema.$ref !== void 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const ownDescription = isInherited ? jsonSchema.description : void 0;
|
|
106
|
+
for (const key of Object.keys(jsonSchema)) {
|
|
107
|
+
Reflect.deleteProperty(jsonSchema, key);
|
|
108
|
+
}
|
|
109
|
+
Object.assign(jsonSchema, fragment);
|
|
110
|
+
if (fragment.description === void 0) {
|
|
111
|
+
const inherited = ownDescription ?? record.description;
|
|
112
|
+
if (inherited !== void 0) {
|
|
113
|
+
jsonSchema.description = inherited;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}, "createCustomOverride");
|
|
118
|
+
|
|
119
|
+
exports.__name = __name;
|
|
120
|
+
exports.createCustomOverride = createCustomOverride;
|
|
121
|
+
exports.findIdOwner = findIdOwner;
|
|
122
|
+
exports.findRefTarget = findRefTarget;
|
|
123
|
+
exports.overrideJSONSchema = overrideJSONSchema;
|
|
124
|
+
exports.peekRegistration = peekRegistration;
|
|
125
|
+
exports.singleton = singleton;
|
|
126
|
+
//# sourceMappingURL=chunk-EV5I5HGT.js.map
|
|
127
|
+
//# sourceMappingURL=chunk-EV5I5HGT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/clone-chain.ts","../src/schema/singleton.ts","../src/schema/custom-override.ts"],"names":["sharesDef","child","parent","_zod","def","resolveThroughClones","schema","lookup","current","hit","undefined","readOwnId","metadata","id","get","asZodType","findIdOwner","z","globalRegistry","candidate","owner","findRefTarget","SINGLETONS","Symbol","for","host","globalThis","store","existing","created","Map","singleton","key","create","values","set","customOverrideMap","WeakMap","isWrapper","arg","overrideJSONSchema","overrideSchema","input","output","schemaDescription","description","peekRegistration","createCustomOverride","io","zodSchema","jsonSchema","own","record","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BAAkBJ,MAAAA,CAAOP,WAAAA;AAC3C,MAAA,IAAIiB,cAAcpD,MAAAA,EAAW;AAC3BwC,QAAAA,UAAAA,CAAWL,WAAAA,GAAciB,SAAAA;AAC3B,MAAA;AACF,IAAA;AACF,EAAA,CAAA;AACF,CAAA,EAjCoC,sBAAA","file":"chunk-EV5I5HGT.js","sourcesContent":["import { z } from 'zod';\n\nimport type { $ZodType } from 'zod/v4/core';\n\n/**\n * A schema carrying an `id`, plus the id itself. The owner is the instance the\n * id is registered against — never the clone the lookup started from.\n */\nexport interface IdOwner {\n readonly owner: z.ZodType;\n readonly id: string;\n}\n\ntype ZodMetadataRegistry = typeof z.globalRegistry;\n\n// Metadata-only clones (`.meta()`, `.describe()`, `z.compile()`) reuse the def\n// by reference. `.check()` derivatives (`.min()`, `.refine()`, …) merge a new\n// def and emit a different body, so they must not inherit the ancestor's entry.\nconst sharesDef = (child: $ZodType, parent: $ZodType): boolean =>\n child._zod.def === parent._zod.def;\n\n/**\n * First non-`undefined` `lookup` result walking `schema` and its annotation\n * clones. Stops at the first clone that changed the emitted body.\n */\nexport const resolveThroughClones = <T>(\n schema: $ZodType,\n lookup: (candidate: $ZodType) => T | undefined,\n): T | undefined => {\n let current = schema;\n for (;;) {\n const hit = lookup(current);\n if (hit !== undefined) {\n return hit;\n }\n const parent = current._zod.parent;\n if (parent === undefined || !sharesDef(current, parent)) {\n return undefined;\n }\n current = parent;\n }\n};\n\nconst readOwnId = (schema: $ZodType, metadata: ZodMetadataRegistry): string | undefined => {\n const id = metadata.get(schema)?.id;\n return typeof id === 'string' && id !== '' ? id : undefined;\n};\n\n// Every value reaching this module is a classic `z.ZodType`; the core\n// `$ZodType` the walker is typed on can't express that.\nconst asZodType = (schema: $ZodType): z.ZodType => schema as z.ZodType;\n\n/**\n * Nearest ancestor whose id the schema may legitimately claim as its own name.\n *\n * Stops at the first clone that changed the emitted body, so\n * `createZodDto(Named.min(3))` stays a distinct component instead of\n * collapsing onto `Named` and losing `minLength`.\n */\nexport const findIdOwner = (\n schema: z.ZodType,\n metadata: ZodMetadataRegistry = z.globalRegistry,\n): IdOwner | undefined =>\n resolveThroughClones(schema, (candidate) => {\n const id = readOwnId(candidate, metadata);\n return id === undefined ? undefined : { owner: asZodType(candidate), id };\n });\n\n/**\n * Nearest named ancestor of any kind — the instance Zod's own `toJSONSchema`\n * parent walk emits a `$ref` to. Ungated: `.refine()` and `.min()` clones also\n * emit `$ref` to their ancestor, so the ancestor is a real document dependency\n * and must be registered or the ref dangles.\n */\nexport const findRefTarget = (\n schema: z.ZodType,\n metadata: ZodMetadataRegistry = z.globalRegistry,\n): IdOwner | undefined => {\n let current: $ZodType | undefined = schema;\n while (current !== undefined) {\n const id = readOwnId(current, metadata);\n if (id !== undefined) {\n return { owner: asZodType(current), id };\n }\n current = current._zod.parent;\n }\n return undefined;\n};\n","// Process-wide module state: each entry point is its own bundle, so a\n// module-level WeakMap would exist once per bundle, and once per copy of\n// the package in a consumer's tree.\nconst SINGLETONS = Symbol.for('zod-nest.singletons');\n\ninterface SingletonHost {\n [SINGLETONS]?: Map<string, unknown>;\n}\n\n// `globalThis` has no type for symbol keys and a Map's values are `unknown`.\n// Both assertions live here so every call site stays cast-free.\nconst host = globalThis as SingletonHost;\n\nconst store = (): Map<string, unknown> => {\n const existing = host[SINGLETONS];\n if (existing !== undefined) {\n return existing;\n }\n const created = new Map<string, unknown>();\n host[SINGLETONS] = created;\n return created;\n};\n\n// Callers own the key namespace and are the only writers, so the stored\n// type is theirs by construction. `create` must not return `undefined`.\nexport const singleton = <T>(key: string, create: () => T): T => {\n const values = store();\n const existing = values.get(key);\n if (existing !== undefined) {\n return existing as T;\n }\n const created = create();\n values.set(key, created);\n return created;\n};\n","import type { z } from 'zod';\nimport type { $ZodType } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\n\nimport { resolveThroughClones } from './clone-chain.js';\nimport { singleton } from './singleton.js';\n\n/**\n * Argument shape for {@link overrideJSONSchema}. Two forms:\n *\n * - A raw `SchemaObject` — applied to both input and output emission.\n * - A `{ input?, output? }` wrapper — distinct fragments per emission side,\n * for coercion shapes where input and output diverge (e.g.\n * `z.union([z.array(item), item.transform((v) => [v])])` accepts\n * `T | T[]` on input but always emits `T[]` on output).\n *\n * The wrapper form is detected by the presence of an `input` or `output`\n * key. Neither is a JSON Schema / OpenAPI 3.1 keyword, so the discriminator\n * is unambiguous in practice.\n */\nexport type OverrideJSONSchemaArg = SchemaObject | { input?: SchemaObject; output?: SchemaObject };\n\nexport interface StoredFragments {\n input?: SchemaObject;\n output?: SchemaObject;\n /**\n * Description captured from the Zod schema at `overrideJSONSchema(...)` call\n * time (`.describe(...)` / `.meta({ description })` both write to\n * `z.globalRegistry`). Applied as a fallback at emission time when the\n * per-direction fragment doesn't supply its own `description`. Fragment-\n * supplied descriptions still win.\n */\n description?: string;\n}\n\n/**\n * Per-instance JSON Schema registration store. Keyed by the Zod core type\n * (`$ZodType`) because that's what the override sees on `ctx.zodSchema`;\n * `z.ZodType` widens to `$ZodType` without a cast at the public API boundary.\n * Same WeakMap pattern as `composition.ts`'s `lineageMap`\n * (CLAUDE.md: \"transient, per-instance → WeakMap\").\n *\n * Value holds the per-direction fragments separately so the override factory\n * can pick the right one without surfacing `io` on `OverrideContext`.\n */\nconst customOverrideMap = singleton(\n 'custom-override-map',\n () => new WeakMap<$ZodType, StoredFragments>(),\n);\n\nconst isWrapper = (\n arg: OverrideJSONSchemaArg,\n): arg is { input?: SchemaObject; output?: SchemaObject } => 'input' in arg || 'output' in arg;\n\n/**\n * Register a fixed JSON Schema fragment for a specific Zod schema instance.\n *\n * Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and\n * `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,\n * tripping `ZodNestUnrepresentableError` in strict mode. Also useful for\n * coercion shapes where input and output diverge (`singleOrArray`-style\n * helpers).\n *\n * Two call shapes:\n *\n * ```ts\n * // 1. Single fragment — applied verbatim to both input and output emission.\n * overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });\n *\n * // 2. Divergent fragments — separate fragments per emission side. Omit a\n * // side to leave Zod's default emission untouched on that side.\n * overrideJSONSchema(arrayOrItem, {\n * input: { anyOf: [arrFrag, itemFrag] },\n * output: arrFrag,\n * });\n * ```\n *\n * Idempotent: subsequent calls for the same schema overwrite the prior\n * registration (last-write-wins).\n */\nexport const overrideJSONSchema = <T extends z.ZodType>(\n schema: T,\n arg: OverrideJSONSchemaArg,\n): T => {\n const overrideSchema: StoredFragments = isWrapper(arg) ? { ...arg } : { input: arg, output: arg };\n\n const schemaDescription = schema.description;\n if (typeof schemaDescription === 'string') {\n overrideSchema.description = schemaDescription;\n }\n\n customOverrideMap.set(schema, overrideSchema);\n\n return schema;\n};\n\n/**\n * Read-only lookup into the registration store. Used by the engine to detect\n * when a pipe-typed schema covers its inner descent target with a relevant-io\n * fragment — see `buildToJsonSchemaOptions` in `engine.ts`. Returning a\n * possibly-`undefined` `StoredFragments` keeps the engine ignorant of the\n * underlying WeakMap.\n */\nexport const peekRegistration = (schema: $ZodType): StoredFragments | undefined =>\n resolveThroughClones(schema, (candidate) => customOverrideMap.get(candidate));\n\n/**\n * Internal override factory consulted by the engine. Closes over the current\n * emission direction so the lookup can pick the right registered fragment\n * without surfacing `io` on the `OverrideContext` public contract. Mirrors\n * `createCompositionOverride` at `engine.ts:98`.\n *\n * Mutates `ctx.jsonSchema` in-place (clears existing keys, then assigns the\n * fragment) because Zod's override pipeline doesn't propagate\n * `ctx.jsonSchema = newObj` reassignments — only mutations on the existing\n * object reach the caller (see `composition.ts` for the same constraint).\n *\n * Falls back to the schema's captured `description` (from `.describe(...)` /\n * `.meta({ description })`) when the per-direction fragment doesn't supply\n * one. Captured at `overrideJSONSchema(...)` call time so the inheritance\n * doesn't depend on Zod's emission-time metadata pass. `title` is\n * deliberately not inherited.\n *\n * No-ops if the schema isn't registered, or if the registered record has no\n * fragment for the current `io` direction.\n */\nexport const createCustomOverride = (io: 'input' | 'output'): Override => {\n return ({ zodSchema, jsonSchema }) => {\n const own = customOverrideMap.get(zodSchema);\n const record =\n own ?? resolveThroughClones(zodSchema, (candidate) => customOverrideMap.get(candidate));\n if (record === undefined) {\n return;\n }\n const fragment = record[io];\n if (fragment === undefined) {\n return;\n }\n const isInherited = own === undefined;\n // An inherited record on a `$ref` body would inline a duplicate of the\n // component the ref already points at. A schema's own record still wins:\n // Zod stamps the ancestor's `$ref` onto it before overrides run.\n if (isInherited && jsonSchema.$ref !== undefined) {\n return;\n }\n // Only when inherited: the clone's own `.describe()` outranks the\n // ancestor's. A schema's own record keeps its capture-at-call-time value.\n const ownDescription = isInherited ? jsonSchema.description : undefined;\n for (const key of Object.keys(jsonSchema)) {\n Reflect.deleteProperty(jsonSchema, key);\n }\n Object.assign(jsonSchema, fragment);\n if (fragment.description === undefined) {\n const inherited = ownDescription ?? record.description;\n if (inherited !== undefined) {\n jsonSchema.description = inherited;\n }\n }\n };\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from './chunk-
|
|
1
|
+
import { __name } from './chunk-MPNAA53V.mjs';
|
|
2
2
|
|
|
3
3
|
// src/helpers/fragments.ts
|
|
4
4
|
var dateTimeFragment = {
|
|
@@ -79,5 +79,5 @@ var opaque = /* @__PURE__ */ __name((opts) => ({
|
|
|
79
79
|
}), "opaque");
|
|
80
80
|
|
|
81
81
|
export { binary, binaryFragment, byteFragment, dateFragment, dateTimeFragment, doubleFragment, emailFragment, enrich, floatFragment, hostnameFragment, int32Fragment, int64Fragment, ipv4Fragment, ipv6Fragment, opaque, opaqueFragment, timeFragment, uriFragment, uuidFragment };
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-IMEFMJTS.mjs.map
|
|
83
|
+
//# sourceMappingURL=chunk-IMEFMJTS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/fragments.ts"],"names":["dateTimeFragment","type","format","dateFragment","timeFragment","uuidFragment","emailFragment","uriFragment","hostnameFragment","ipv4Fragment","ipv6Fragment","binaryFragment","byteFragment","int32Fragment","int64Fragment","floatFragment","doubleFragment","opaqueFragment","additionalProperties","enrich","base","extras","binary","opts","opaque"],"mappings":";;;AAsBO,IAAMA,gBAAAA,GAAmB;EAC9BC,IAAAA,EAAM,QAAA;EACNC,MAAAA,EAAQ;AACV;AACO,IAAMC,YAAAA,GAAe;EAAEF,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAME,YAAAA,GAAe;EAAEH,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAMG,YAAAA,GAAe;EAAEJ,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAMI,aAAAA,GAAgB;EAAEL,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAQ;AACxD,IAAMK,WAAAA,GAAc;EAAEN,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAM;AACpD,IAAMM,gBAAAA,GAAmB;EAC9BP,IAAAA,EAAM,QAAA;EACNC,MAAAA,EAAQ;AACV;AACO,IAAMO,YAAAA,GAAe;EAAER,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAMQ,YAAAA,GAAe;EAAET,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AAGtD,IAAMS,cAAAA,GAAiB;EAAEV,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAS;AAC1D,IAAMU,YAAAA,GAAe;EAAEX,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AAGtD,IAAMW,aAAAA,GAAgB;EAAEZ,IAAAA,EAAM,SAAA;EAAWC,MAAAA,EAAQ;AAAQ;AACzD,IAAMY,aAAAA,GAAgB;EAAEb,IAAAA,EAAM,SAAA;EAAWC,MAAAA,EAAQ;AAAQ;AACzD,IAAMa,aAAAA,GAAgB;EAAEd,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAQ;AACxD,IAAMc,cAAAA,GAAiB;EAAEf,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAS;AAG1D,IAAMe,cAAAA,GAAiB;EAC5BhB,IAAAA,EAAM,QAAA;EACNiB,oBAAAA,EAAsB;AACxB;AAsEO,IAAMC,MAAAA,mBAAS,MAAA,CAAA,CAAyBC,IAAAA,EAASC,MAAAA,MAAyC;EAC/F,GAAGD,IAAAA;EACH,GAAGC;AACL,CAAA,CAAA,EAHsB,QAAA;AAmBf,IAAMC,MAAAA,2BAAUC,IAAAA,MAAgD;EACrE,GAAGZ,cAAAA;EACH,GAAGY;AACL,CAAA,CAAA,EAHsB,QAAA;AAcf,IAAMC,MAAAA,2BAAUD,IAAAA,MAAgD;EACrE,GAAGN,cAAAA;EACH,GAAGM;AACL,CAAA,CAAA,EAHsB,QAAA","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../src/helpers/fragments.ts"],"names":["dateTimeFragment","type","format","dateFragment","timeFragment","uuidFragment","emailFragment","uriFragment","hostnameFragment","ipv4Fragment","ipv6Fragment","binaryFragment","byteFragment","int32Fragment","int64Fragment","floatFragment","doubleFragment","opaqueFragment","additionalProperties","enrich","base","extras","binary","opts","opaque"],"mappings":";;;AAsBO,IAAMA,gBAAAA,GAAmB;EAC9BC,IAAAA,EAAM,QAAA;EACNC,MAAAA,EAAQ;AACV;AACO,IAAMC,YAAAA,GAAe;EAAEF,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAME,YAAAA,GAAe;EAAEH,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAMG,YAAAA,GAAe;EAAEJ,IAAAA,EAAM,QAAA;EAAUC,MAAAA,EAAQ;AAAO;AACtD,IAAM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,IAAMC,MAAAA,2BAAUD,IAAAA,MAAgD;EACrE,GAAGN,cAAAA;EACH,GAAGM;AACL,CAAA,CAAA,EAHsB,QAAA","file":"chunk-IMEFMJTS.mjs","sourcesContent":["import type { SchemaObject } from '../schema/openapi.types.js';\n\n/**\n * Common JSON Schema fragment catalog — reusable building blocks for assembling\n * fragments by hand: alongside `z.custom<T>()`, in `overrideJSONSchema` calls,\n * in custom override callbacks, in tests that build expected fragments.\n *\n * The catalog overlaps with what Zod constructs already emit (`z.uuid()` →\n * `uuidFragment` shape, `z.email()` → `emailFragment` shape, etc.) — the\n * helpers don't *replace* those Zod constructs; they're a parallel catalog\n * for programmatic fragment assembly.\n *\n * Each fragment is `as const satisfies SchemaObject` so its literal type\n * powers the dispatch in {@link enrich} — passing wrong-family options\n * fails at compile time.\n */\n\n// ---------------------------------------------------------------------------\n// Layer 1 — Fragment catalog\n// ---------------------------------------------------------------------------\n\n// String formats (RFC-defined)\nexport const dateTimeFragment = {\n type: 'string',\n format: 'date-time',\n} as const satisfies SchemaObject;\nexport const dateFragment = { type: 'string', format: 'date' } as const satisfies SchemaObject;\nexport const timeFragment = { type: 'string', format: 'time' } as const satisfies SchemaObject;\nexport const uuidFragment = { type: 'string', format: 'uuid' } as const satisfies SchemaObject;\nexport const emailFragment = { type: 'string', format: 'email' } as const satisfies SchemaObject;\nexport const uriFragment = { type: 'string', format: 'uri' } as const satisfies SchemaObject;\nexport const hostnameFragment = {\n type: 'string',\n format: 'hostname',\n} as const satisfies SchemaObject;\nexport const ipv4Fragment = { type: 'string', format: 'ipv4' } as const satisfies SchemaObject;\nexport const ipv6Fragment = { type: 'string', format: 'ipv6' } as const satisfies SchemaObject;\n\n// Binary / encoded payloads\nexport const binaryFragment = { type: 'string', format: 'binary' } as const satisfies SchemaObject;\nexport const byteFragment = { type: 'string', format: 'byte' } as const satisfies SchemaObject;\n\n// Numeric formats (OpenAPI 3.1)\nexport const int32Fragment = { type: 'integer', format: 'int32' } as const satisfies SchemaObject;\nexport const int64Fragment = { type: 'integer', format: 'int64' } as const satisfies SchemaObject;\nexport const floatFragment = { type: 'number', format: 'float' } as const satisfies SchemaObject;\nexport const doubleFragment = { type: 'number', format: 'double' } as const satisfies SchemaObject;\n\n// Object passthrough\nexport const opaqueFragment = {\n type: 'object',\n additionalProperties: true,\n} as const satisfies SchemaObject;\n\n// ---------------------------------------------------------------------------\n// Layer 2 — Per-family option types\n// ---------------------------------------------------------------------------\n\nexport interface StringFormatOptions {\n description?: string;\n examples?: string[];\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n}\n\nexport interface BinaryFragmentOptions {\n description?: string;\n contentMediaType?: string;\n contentEncoding?: string;\n}\n\nexport interface NumberFormatOptions {\n description?: string;\n examples?: number[];\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n multipleOf?: number;\n}\n\nexport interface OpaqueFragmentOptions {\n description?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Layer 3 — Type-strict generic enrich\n// ---------------------------------------------------------------------------\n\n// `binary` discriminates before the generic string-format branch because its\n// option set diverges (contentMediaType / contentEncoding instead of length\n// constraints). Order matters here.\ntype OptionsFor<T> = T extends { readonly format: 'binary' }\n ? BinaryFragmentOptions\n : T extends {\n readonly format:\n | 'date-time'\n | 'date'\n | 'time'\n | 'uuid'\n | 'email'\n | 'uri'\n | 'hostname'\n | 'ipv4'\n | 'ipv6'\n | 'byte';\n }\n ? StringFormatOptions\n : T extends { readonly format: 'int32' | 'int64' | 'float' | 'double' }\n ? NumberFormatOptions\n : T extends { readonly type: 'object'; readonly additionalProperties: true }\n ? OpaqueFragmentOptions\n : never;\n\n/**\n * Merge a catalog fragment with extras whose shape is dictated by the base\n * fragment's family. Passing wrong-family extras (e.g. a `contentMediaType`\n * onto `uuidFragment`) is a compile-time error.\n *\n * Returns a fresh `SchemaObject` — the original fragment is never mutated.\n */\nexport const enrich = <T extends SchemaObject>(base: T, extras: OptionsFor<T>): SchemaObject => ({\n ...base,\n ...extras,\n});\n\n// ---------------------------------------------------------------------------\n// Layer 3b — Sugar functions\n// ---------------------------------------------------------------------------\n\n/**\n * Binary-content fragment with typed enrichment. Sugar for\n * `enrich(binaryFragment, opts)` — exists because the `binary` option set\n * (`contentMediaType` / `contentEncoding`) is nuanced enough to deserve a\n * dedicated entry point and discoverable via auto-complete.\n *\n * @example\n * overrideJSONSchema(z.instanceof(File), binary());\n * overrideJSONSchema(z.instanceof(File), binary({ contentMediaType: 'application/pdf' }));\n */\nexport const binary = (opts?: BinaryFragmentOptions): SchemaObject => ({\n ...binaryFragment,\n ...opts,\n});\n\n/**\n * Opaque-object fragment with typed enrichment. Sugar for\n * `enrich(opaqueFragment, opts)` — exists for parity with {@link binary}\n * and because opaque passthrough payloads commonly carry a description\n * explaining why the API doesn't introspect them.\n *\n * @example\n * overrideJSONSchema(z.unknown(), opaque({ description: 'JWT passthrough' }));\n */\nexport const opaque = (opts?: OpaqueFragmentOptions): SchemaObject => ({\n ...opaqueFragment,\n ...opts,\n});\n"]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
var sharesDef = /* @__PURE__ */ __name((child, parent) => child._zod.def === parent._zod.def, "sharesDef");
|
|
6
|
+
var resolveThroughClones = /* @__PURE__ */ __name((schema, lookup) => {
|
|
7
|
+
let current = schema;
|
|
8
|
+
for (; ; ) {
|
|
9
|
+
const hit = lookup(current);
|
|
10
|
+
if (hit !== void 0) {
|
|
11
|
+
return hit;
|
|
12
|
+
}
|
|
13
|
+
const parent = current._zod.parent;
|
|
14
|
+
if (parent === void 0 || !sharesDef(current, parent)) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
current = parent;
|
|
18
|
+
}
|
|
19
|
+
}, "resolveThroughClones");
|
|
20
|
+
var readOwnId = /* @__PURE__ */ __name((schema, metadata) => {
|
|
21
|
+
const id = metadata.get(schema)?.id;
|
|
22
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
23
|
+
}, "readOwnId");
|
|
24
|
+
var asZodType = /* @__PURE__ */ __name((schema) => schema, "asZodType");
|
|
25
|
+
var findIdOwner = /* @__PURE__ */ __name((schema, metadata = z.globalRegistry) => resolveThroughClones(schema, (candidate) => {
|
|
26
|
+
const id = readOwnId(candidate, metadata);
|
|
27
|
+
return id === void 0 ? void 0 : {
|
|
28
|
+
owner: asZodType(candidate),
|
|
29
|
+
id
|
|
30
|
+
};
|
|
31
|
+
}), "findIdOwner");
|
|
32
|
+
var findRefTarget = /* @__PURE__ */ __name((schema, metadata = z.globalRegistry) => {
|
|
33
|
+
let current = schema;
|
|
34
|
+
while (current !== void 0) {
|
|
35
|
+
const id = readOwnId(current, metadata);
|
|
36
|
+
if (id !== void 0) {
|
|
37
|
+
return {
|
|
38
|
+
owner: asZodType(current),
|
|
39
|
+
id
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
current = current._zod.parent;
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}, "findRefTarget");
|
|
46
|
+
|
|
47
|
+
// src/schema/singleton.ts
|
|
48
|
+
var SINGLETONS = /* @__PURE__ */ Symbol.for("zod-nest.singletons");
|
|
49
|
+
var host = globalThis;
|
|
50
|
+
var store = /* @__PURE__ */ __name(() => {
|
|
51
|
+
const existing = host[SINGLETONS];
|
|
52
|
+
if (existing !== void 0) {
|
|
53
|
+
return existing;
|
|
54
|
+
}
|
|
55
|
+
const created = /* @__PURE__ */ new Map();
|
|
56
|
+
host[SINGLETONS] = created;
|
|
57
|
+
return created;
|
|
58
|
+
}, "store");
|
|
59
|
+
var singleton = /* @__PURE__ */ __name((key, create) => {
|
|
60
|
+
const values = store();
|
|
61
|
+
const existing = values.get(key);
|
|
62
|
+
if (existing !== void 0) {
|
|
63
|
+
return existing;
|
|
64
|
+
}
|
|
65
|
+
const created = create();
|
|
66
|
+
values.set(key, created);
|
|
67
|
+
return created;
|
|
68
|
+
}, "singleton");
|
|
69
|
+
|
|
70
|
+
// src/schema/custom-override.ts
|
|
71
|
+
var customOverrideMap = singleton("custom-override-map", () => /* @__PURE__ */ new WeakMap());
|
|
72
|
+
var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
|
|
73
|
+
var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
|
|
74
|
+
const overrideSchema = isWrapper(arg) ? {
|
|
75
|
+
...arg
|
|
76
|
+
} : {
|
|
77
|
+
input: arg,
|
|
78
|
+
output: arg
|
|
79
|
+
};
|
|
80
|
+
const schemaDescription = schema.description;
|
|
81
|
+
if (typeof schemaDescription === "string") {
|
|
82
|
+
overrideSchema.description = schemaDescription;
|
|
83
|
+
}
|
|
84
|
+
customOverrideMap.set(schema, overrideSchema);
|
|
85
|
+
return schema;
|
|
86
|
+
}, "overrideJSONSchema");
|
|
87
|
+
var peekRegistration = /* @__PURE__ */ __name((schema) => resolveThroughClones(schema, (candidate) => customOverrideMap.get(candidate)), "peekRegistration");
|
|
88
|
+
var createCustomOverride = /* @__PURE__ */ __name((io) => {
|
|
89
|
+
return ({ zodSchema, jsonSchema }) => {
|
|
90
|
+
const own = customOverrideMap.get(zodSchema);
|
|
91
|
+
const record = own ?? resolveThroughClones(zodSchema, (candidate) => customOverrideMap.get(candidate));
|
|
92
|
+
if (record === void 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const fragment = record[io];
|
|
96
|
+
if (fragment === void 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const isInherited = own === void 0;
|
|
100
|
+
if (isInherited && jsonSchema.$ref !== void 0) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const ownDescription = isInherited ? jsonSchema.description : void 0;
|
|
104
|
+
for (const key of Object.keys(jsonSchema)) {
|
|
105
|
+
Reflect.deleteProperty(jsonSchema, key);
|
|
106
|
+
}
|
|
107
|
+
Object.assign(jsonSchema, fragment);
|
|
108
|
+
if (fragment.description === void 0) {
|
|
109
|
+
const inherited = ownDescription ?? record.description;
|
|
110
|
+
if (inherited !== void 0) {
|
|
111
|
+
jsonSchema.description = inherited;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, "createCustomOverride");
|
|
116
|
+
|
|
117
|
+
export { __name, createCustomOverride, findIdOwner, findRefTarget, overrideJSONSchema, peekRegistration, singleton };
|
|
118
|
+
//# sourceMappingURL=chunk-MPNAA53V.mjs.map
|
|
119
|
+
//# sourceMappingURL=chunk-MPNAA53V.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/clone-chain.ts","../src/schema/singleton.ts","../src/schema/custom-override.ts"],"names":["sharesDef","child","parent","_zod","def","resolveThroughClones","schema","lookup","current","hit","undefined","readOwnId","metadata","id","get","asZodType","findIdOwner","z","globalRegistry","candidate","owner","findRefTarget","SINGLETONS","Symbol","for","host","globalThis","store","existing","created","Map","singleton","key","create","values","set","customOverrideMap","WeakMap","isWrapper","arg","overrideJSONSchema","overrideSchema","input","output","schemaDescription","description","peekRegistration","createCustomOverride","io","zodSchema","jsonSchema","own","record","fragment","isInherited","$ref","ownDescription","Object","keys","Reflect","deleteProperty","assign","inherited"],"mappings":";;;;AAkBA,IAAMA,SAAAA,2BAAaC,KAAAA,EAAiBC,MAAAA,KAClCD,MAAME,IAAAA,CAAKC,GAAAA,KAAQF,MAAAA,CAAOC,IAAAA,CAAKC,GAAAA,EADf,WAAA,CAAA;AAOX,IAAMC,oBAAAA,mBAAuB,MAAA,CAAA,CAClCC,MAAAA,EACAC,MAAAA,KAAAA;AAEA,EAAA,IAAIC,OAAAA,GAAUF,MAAAA;AACd,EAAA,WAAS;AACP,IAAA,MAAMG,GAAAA,GAAMF,OAAOC,OAAAA,CAAAA;AACnB,IAAA,IAAIC,QAAQC,MAAA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,GAAAA,CAAIK,SAAAA,CAAAA,CAAAA;AAC9E,IAAA,IAAIiC,WAAW1C,MAAAA,EAAW;AACxB,MAAA;AACF,IAAA;AACA,IAAA,MAAM2C,QAAAA,GAAWD,OAAOJ,EAAAA,CAAAA;AACxB,IAAA,IAAIK,aAAa3C,MAAAA,EAAW;AAC1B,MAAA;AACF,IAAA;AACA,IAAA,MAAM4C,cAAcH,GAAAA,KAAQzC,MAAAA;AAI5B,IAAA,IAAI4C,WAAAA,IAAeJ,UAAAA,CAAWK,IAAAA,KAAS7C,MAAAA,EAAW;AAChD,MAAA;AACF,IAAA;AAGA,IAAA,MAAM8C,cAAAA,GAAiBF,WAAAA,GAAcJ,UAAAA,CAAWL,WAAAA,GAAcnC,MAAAA;AAC9D,IAAA,KAAA,MAAWsB,GAAAA,IAAOyB,MAAAA,CAAOC,IAAAA,CAAKR,UAAAA,CAAAA,EAAa;AACzCS,MAAAA,OAAAA,CAAQC,cAAAA,CAAeV,YAAYlB,GAAAA,CAAAA;AACrC,IAAA;AACAyB,IAAAA,MAAAA,CAAOI,MAAAA,CAAOX,YAAYG,QAAAA,CAAAA;AAC1B,IAAA,IAAIA,QAAAA,CAASR,gBAAgBnC,MAAAA,EAAW;AACtC,MAAA,MAAMoD,SAAAA,GAAYN,kBAAkBJ,MAAAA,CAAOP,WAAAA;AAC3C,MAAA,IAAIiB,cAAcpD,MAAAA,EAAW;AAC3BwC,QAAAA,UAAAA,CAAWL,WAAAA,GAAciB,SAAAA;AAC3B,MAAA;AACF,IAAA;AACF,EAAA,CAAA;AACF,CAAA,EAjCoC,sBAAA","file":"chunk-MPNAA53V.mjs","sourcesContent":["import { z } from 'zod';\n\nimport type { $ZodType } from 'zod/v4/core';\n\n/**\n * A schema carrying an `id`, plus the id itself. The owner is the instance the\n * id is registered against — never the clone the lookup started from.\n */\nexport interface IdOwner {\n readonly owner: z.ZodType;\n readonly id: string;\n}\n\ntype ZodMetadataRegistry = typeof z.globalRegistry;\n\n// Metadata-only clones (`.meta()`, `.describe()`, `z.compile()`) reuse the def\n// by reference. `.check()` derivatives (`.min()`, `.refine()`, …) merge a new\n// def and emit a different body, so they must not inherit the ancestor's entry.\nconst sharesDef = (child: $ZodType, parent: $ZodType): boolean =>\n child._zod.def === parent._zod.def;\n\n/**\n * First non-`undefined` `lookup` result walking `schema` and its annotation\n * clones. Stops at the first clone that changed the emitted body.\n */\nexport const resolveThroughClones = <T>(\n schema: $ZodType,\n lookup: (candidate: $ZodType) => T | undefined,\n): T | undefined => {\n let current = schema;\n for (;;) {\n const hit = lookup(current);\n if (hit !== undefined) {\n return hit;\n }\n const parent = current._zod.parent;\n if (parent === undefined || !sharesDef(current, parent)) {\n return undefined;\n }\n current = parent;\n }\n};\n\nconst readOwnId = (schema: $ZodType, metadata: ZodMetadataRegistry): string | undefined => {\n const id = metadata.get(schema)?.id;\n return typeof id === 'string' && id !== '' ? id : undefined;\n};\n\n// Every value reaching this module is a classic `z.ZodType`; the core\n// `$ZodType` the walker is typed on can't express that.\nconst asZodType = (schema: $ZodType): z.ZodType => schema as z.ZodType;\n\n/**\n * Nearest ancestor whose id the schema may legitimately claim as its own name.\n *\n * Stops at the first clone that changed the emitted body, so\n * `createZodDto(Named.min(3))` stays a distinct component instead of\n * collapsing onto `Named` and losing `minLength`.\n */\nexport const findIdOwner = (\n schema: z.ZodType,\n metadata: ZodMetadataRegistry = z.globalRegistry,\n): IdOwner | undefined =>\n resolveThroughClones(schema, (candidate) => {\n const id = readOwnId(candidate, metadata);\n return id === undefined ? undefined : { owner: asZodType(candidate), id };\n });\n\n/**\n * Nearest named ancestor of any kind — the instance Zod's own `toJSONSchema`\n * parent walk emits a `$ref` to. Ungated: `.refine()` and `.min()` clones also\n * emit `$ref` to their ancestor, so the ancestor is a real document dependency\n * and must be registered or the ref dangles.\n */\nexport const findRefTarget = (\n schema: z.ZodType,\n metadata: ZodMetadataRegistry = z.globalRegistry,\n): IdOwner | undefined => {\n let current: $ZodType | undefined = schema;\n while (current !== undefined) {\n const id = readOwnId(current, metadata);\n if (id !== undefined) {\n return { owner: asZodType(current), id };\n }\n current = current._zod.parent;\n }\n return undefined;\n};\n","// Process-wide module state: each entry point is its own bundle, so a\n// module-level WeakMap would exist once per bundle, and once per copy of\n// the package in a consumer's tree.\nconst SINGLETONS = Symbol.for('zod-nest.singletons');\n\ninterface SingletonHost {\n [SINGLETONS]?: Map<string, unknown>;\n}\n\n// `globalThis` has no type for symbol keys and a Map's values are `unknown`.\n// Both assertions live here so every call site stays cast-free.\nconst host = globalThis as SingletonHost;\n\nconst store = (): Map<string, unknown> => {\n const existing = host[SINGLETONS];\n if (existing !== undefined) {\n return existing;\n }\n const created = new Map<string, unknown>();\n host[SINGLETONS] = created;\n return created;\n};\n\n// Callers own the key namespace and are the only writers, so the stored\n// type is theirs by construction. `create` must not return `undefined`.\nexport const singleton = <T>(key: string, create: () => T): T => {\n const values = store();\n const existing = values.get(key);\n if (existing !== undefined) {\n return existing as T;\n }\n const created = create();\n values.set(key, created);\n return created;\n};\n","import type { z } from 'zod';\nimport type { $ZodType } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\n\nimport { resolveThroughClones } from './clone-chain.js';\nimport { singleton } from './singleton.js';\n\n/**\n * Argument shape for {@link overrideJSONSchema}. Two forms:\n *\n * - A raw `SchemaObject` — applied to both input and output emission.\n * - A `{ input?, output? }` wrapper — distinct fragments per emission side,\n * for coercion shapes where input and output diverge (e.g.\n * `z.union([z.array(item), item.transform((v) => [v])])` accepts\n * `T | T[]` on input but always emits `T[]` on output).\n *\n * The wrapper form is detected by the presence of an `input` or `output`\n * key. Neither is a JSON Schema / OpenAPI 3.1 keyword, so the discriminator\n * is unambiguous in practice.\n */\nexport type OverrideJSONSchemaArg = SchemaObject | { input?: SchemaObject; output?: SchemaObject };\n\nexport interface StoredFragments {\n input?: SchemaObject;\n output?: SchemaObject;\n /**\n * Description captured from the Zod schema at `overrideJSONSchema(...)` call\n * time (`.describe(...)` / `.meta({ description })` both write to\n * `z.globalRegistry`). Applied as a fallback at emission time when the\n * per-direction fragment doesn't supply its own `description`. Fragment-\n * supplied descriptions still win.\n */\n description?: string;\n}\n\n/**\n * Per-instance JSON Schema registration store. Keyed by the Zod core type\n * (`$ZodType`) because that's what the override sees on `ctx.zodSchema`;\n * `z.ZodType` widens to `$ZodType` without a cast at the public API boundary.\n * Same WeakMap pattern as `composition.ts`'s `lineageMap`\n * (CLAUDE.md: \"transient, per-instance → WeakMap\").\n *\n * Value holds the per-direction fragments separately so the override factory\n * can pick the right one without surfacing `io` on `OverrideContext`.\n */\nconst customOverrideMap = singleton(\n 'custom-override-map',\n () => new WeakMap<$ZodType, StoredFragments>(),\n);\n\nconst isWrapper = (\n arg: OverrideJSONSchemaArg,\n): arg is { input?: SchemaObject; output?: SchemaObject } => 'input' in arg || 'output' in arg;\n\n/**\n * Register a fixed JSON Schema fragment for a specific Zod schema instance.\n *\n * Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and\n * `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,\n * tripping `ZodNestUnrepresentableError` in strict mode. Also useful for\n * coercion shapes where input and output diverge (`singleOrArray`-style\n * helpers).\n *\n * Two call shapes:\n *\n * ```ts\n * // 1. Single fragment — applied verbatim to both input and output emission.\n * overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });\n *\n * // 2. Divergent fragments — separate fragments per emission side. Omit a\n * // side to leave Zod's default emission untouched on that side.\n * overrideJSONSchema(arrayOrItem, {\n * input: { anyOf: [arrFrag, itemFrag] },\n * output: arrFrag,\n * });\n * ```\n *\n * Idempotent: subsequent calls for the same schema overwrite the prior\n * registration (last-write-wins).\n */\nexport const overrideJSONSchema = <T extends z.ZodType>(\n schema: T,\n arg: OverrideJSONSchemaArg,\n): T => {\n const overrideSchema: StoredFragments = isWrapper(arg) ? { ...arg } : { input: arg, output: arg };\n\n const schemaDescription = schema.description;\n if (typeof schemaDescription === 'string') {\n overrideSchema.description = schemaDescription;\n }\n\n customOverrideMap.set(schema, overrideSchema);\n\n return schema;\n};\n\n/**\n * Read-only lookup into the registration store. Used by the engine to detect\n * when a pipe-typed schema covers its inner descent target with a relevant-io\n * fragment — see `buildToJsonSchemaOptions` in `engine.ts`. Returning a\n * possibly-`undefined` `StoredFragments` keeps the engine ignorant of the\n * underlying WeakMap.\n */\nexport const peekRegistration = (schema: $ZodType): StoredFragments | undefined =>\n resolveThroughClones(schema, (candidate) => customOverrideMap.get(candidate));\n\n/**\n * Internal override factory consulted by the engine. Closes over the current\n * emission direction so the lookup can pick the right registered fragment\n * without surfacing `io` on the `OverrideContext` public contract. Mirrors\n * `createCompositionOverride` at `engine.ts:98`.\n *\n * Mutates `ctx.jsonSchema` in-place (clears existing keys, then assigns the\n * fragment) because Zod's override pipeline doesn't propagate\n * `ctx.jsonSchema = newObj` reassignments — only mutations on the existing\n * object reach the caller (see `composition.ts` for the same constraint).\n *\n * Falls back to the schema's captured `description` (from `.describe(...)` /\n * `.meta({ description })`) when the per-direction fragment doesn't supply\n * one. Captured at `overrideJSONSchema(...)` call time so the inheritance\n * doesn't depend on Zod's emission-time metadata pass. `title` is\n * deliberately not inherited.\n *\n * No-ops if the schema isn't registered, or if the registered record has no\n * fragment for the current `io` direction.\n */\nexport const createCustomOverride = (io: 'input' | 'output'): Override => {\n return ({ zodSchema, jsonSchema }) => {\n const own = customOverrideMap.get(zodSchema);\n const record =\n own ?? resolveThroughClones(zodSchema, (candidate) => customOverrideMap.get(candidate));\n if (record === undefined) {\n return;\n }\n const fragment = record[io];\n if (fragment === undefined) {\n return;\n }\n const isInherited = own === undefined;\n // An inherited record on a `$ref` body would inline a duplicate of the\n // component the ref already points at. A schema's own record still wins:\n // Zod stamps the ancestor's `$ref` onto it before overrides run.\n if (isInherited && jsonSchema.$ref !== undefined) {\n return;\n }\n // Only when inherited: the clone's own `.describe()` outranks the\n // ancestor's. A schema's own record keeps its capture-at-call-time value.\n const ownDescription = isInherited ? jsonSchema.description : undefined;\n for (const key of Object.keys(jsonSchema)) {\n Reflect.deleteProperty(jsonSchema, key);\n }\n Object.assign(jsonSchema, fragment);\n if (fragment.description === undefined) {\n const inherited = ownDescription ?? record.description;\n if (inherited !== undefined) {\n jsonSchema.description = inherited;\n }\n }\n };\n};\n"]}
|