zod-nest 3.2.0 → 3.2.2

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.
Files changed (43) hide show
  1. package/dist/chunk-26E2XEJU.js +294 -0
  2. package/dist/chunk-26E2XEJU.js.map +1 -0
  3. package/dist/chunk-4RXGLSPP.js +73 -0
  4. package/dist/chunk-4RXGLSPP.js.map +1 -0
  5. package/dist/chunk-FKXVNCDD.js +863 -0
  6. package/dist/chunk-FKXVNCDD.js.map +1 -0
  7. package/dist/chunk-LHNXO52A.mjs +838 -0
  8. package/dist/chunk-LHNXO52A.mjs.map +1 -0
  9. package/dist/chunk-LXRBMFWD.js +103 -0
  10. package/dist/chunk-LXRBMFWD.js.map +1 -0
  11. package/dist/chunk-RAF7JGS6.mjs +286 -0
  12. package/dist/chunk-RAF7JGS6.mjs.map +1 -0
  13. package/dist/chunk-WI4JKXT6.mjs +83 -0
  14. package/dist/chunk-WI4JKXT6.mjs.map +1 -0
  15. package/dist/chunk-ZZW54ETO.mjs +67 -0
  16. package/dist/chunk-ZZW54ETO.mjs.map +1 -0
  17. package/dist/express/index.d.mts +3 -3
  18. package/dist/express/index.d.ts +3 -3
  19. package/dist/express/index.js +33 -1118
  20. package/dist/express/index.js.map +1 -1
  21. package/dist/express/index.mjs +6 -1102
  22. package/dist/express/index.mjs.map +1 -1
  23. package/dist/fastify/index.d.mts +3 -3
  24. package/dist/fastify/index.d.ts +3 -3
  25. package/dist/fastify/index.js +18 -1109
  26. package/dist/fastify/index.js.map +1 -1
  27. package/dist/fastify/index.mjs +6 -1102
  28. package/dist/fastify/index.mjs.map +1 -1
  29. package/dist/helpers/index.js +81 -122
  30. package/dist/helpers/index.js.map +1 -1
  31. package/dist/helpers/index.mjs +4 -101
  32. package/dist/helpers/index.mjs.map +1 -1
  33. package/dist/index.d.mts +2 -2
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.js +263 -1091
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +18 -895
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/{param-decorators-CX1cUqfY.d.ts → param-decorators-23pStLeF.d.ts} +1 -1
  40. package/dist/{param-decorators-DbgygRVn.d.mts → param-decorators-Dfd2Cy08.d.mts} +1 -1
  41. package/dist/{registry-C9xStKa6.d.mts → registry-Cs1Y0a-L.d.mts} +1 -1
  42. package/dist/{registry-C9xStKa6.d.ts → registry-Cs1Y0a-L.d.ts} +1 -1
  43. package/package.json +26 -33
@@ -0,0 +1,838 @@
1
+ import { singleton, __name, createCustomOverride, peekRegistration } from './chunk-ZZW54ETO.mjs';
2
+ import { z } from 'zod';
3
+ import { BadRequestException, HttpStatus } from '@nestjs/common';
4
+
5
+ // src/schema/constants.ts
6
+ var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
7
+ var DEFS_PREFIX = "#/$defs/";
8
+ var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
9
+ var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
10
+ var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
11
+ var INNER_TYPE_WRAPPERS = /* @__PURE__ */ new Set([
12
+ "optional",
13
+ "nullable",
14
+ "default",
15
+ "prefault",
16
+ "catch",
17
+ "nonoptional",
18
+ "success",
19
+ "readonly",
20
+ "promise"
21
+ ]);
22
+ var readId = /* @__PURE__ */ __name((schema) => {
23
+ const meta = z.globalRegistry.get(schema);
24
+ if (meta === void 0) {
25
+ return void 0;
26
+ }
27
+ const id = meta.id;
28
+ return typeof id === "string" ? id : void 0;
29
+ }, "readId");
30
+ var resolveLazyTarget = /* @__PURE__ */ __name((getter) => {
31
+ try {
32
+ return [
33
+ getter()
34
+ ];
35
+ } catch (error) {
36
+ if (error instanceof ReferenceError) {
37
+ return [];
38
+ }
39
+ throw error;
40
+ }
41
+ }, "resolveLazyTarget");
42
+ var collectChildren = /* @__PURE__ */ __name((schema) => {
43
+ const def = schema._zod.def;
44
+ if (def.type === "object") {
45
+ const shape = def.shape;
46
+ const out = [
47
+ ...Object.values(shape)
48
+ ];
49
+ if (def.catchall !== void 0) {
50
+ out.push(def.catchall);
51
+ }
52
+ return out;
53
+ }
54
+ if (def.type === "array") {
55
+ return [
56
+ def.element
57
+ ];
58
+ }
59
+ if (def.type === "union") {
60
+ return def.options.map((opt) => opt);
61
+ }
62
+ if (def.type === "intersection") {
63
+ return [
64
+ def.left,
65
+ def.right
66
+ ];
67
+ }
68
+ if (def.type === "tuple") {
69
+ const out = def.items.map((it) => it);
70
+ if (def.rest !== null) {
71
+ out.push(def.rest);
72
+ }
73
+ return out;
74
+ }
75
+ if (def.type === "record" || def.type === "map") {
76
+ return [
77
+ def.keyType,
78
+ def.valueType
79
+ ];
80
+ }
81
+ if (def.type === "set") {
82
+ return [
83
+ def.valueType
84
+ ];
85
+ }
86
+ if (def.type === "pipe") {
87
+ return [
88
+ def.in,
89
+ def.out
90
+ ];
91
+ }
92
+ if (def.type === "lazy") {
93
+ return resolveLazyTarget(() => def.getter());
94
+ }
95
+ if (INNER_TYPE_WRAPPERS.has(def.type)) {
96
+ return [
97
+ def.innerType
98
+ ];
99
+ }
100
+ return [];
101
+ }, "collectChildren");
102
+ var discoverDependents = /* @__PURE__ */ __name((schema) => {
103
+ const visited = /* @__PURE__ */ new WeakSet();
104
+ const out = [];
105
+ const stack = [
106
+ schema
107
+ ];
108
+ while (stack.length > 0) {
109
+ const current = stack.pop();
110
+ if (visited.has(current)) {
111
+ continue;
112
+ }
113
+ visited.add(current);
114
+ for (const child of collectChildren(current)) {
115
+ if (child === void 0 || visited.has(child)) {
116
+ continue;
117
+ }
118
+ const id = readId(child);
119
+ if (id !== void 0) {
120
+ out.push([
121
+ child,
122
+ id
123
+ ]);
124
+ }
125
+ stack.push(child);
126
+ }
127
+ }
128
+ return out;
129
+ }, "discoverDependents");
130
+
131
+ // src/schema/registry.ts
132
+ var createRegistry = /* @__PURE__ */ __name(() => {
133
+ const seen = /* @__PURE__ */ new Map();
134
+ const forceExposed = /* @__PURE__ */ new Set();
135
+ const anonymous = /* @__PURE__ */ new Set();
136
+ const pendingRoots = [];
137
+ const recordOnce = /* @__PURE__ */ __name((schema, id) => {
138
+ let set = seen.get(id);
139
+ if (set === void 0) {
140
+ set = /* @__PURE__ */ new Set();
141
+ seen.set(id, set);
142
+ }
143
+ if (set.has(schema)) {
144
+ return false;
145
+ }
146
+ set.add(schema);
147
+ return true;
148
+ }, "recordOnce");
149
+ const flushPendingDiscovery = /* @__PURE__ */ __name(() => {
150
+ for (const root of pendingRoots.splice(0)) {
151
+ for (const [child, childId] of discoverDependents(root)) {
152
+ recordOnce(child, childId);
153
+ }
154
+ }
155
+ }, "flushPendingDiscovery");
156
+ return {
157
+ zodRegistry: z.globalRegistry,
158
+ register: /* @__PURE__ */ __name((schema, id, flags) => {
159
+ if (flags?.expose === true) {
160
+ forceExposed.add(id);
161
+ }
162
+ if (flags?.anonymous === true) {
163
+ anonymous.add(id);
164
+ }
165
+ if (z.globalRegistry.has(schema)) {
166
+ const existing = z.globalRegistry.get(schema) ?? {};
167
+ if (existing.id !== id) {
168
+ z.globalRegistry.add(schema, {
169
+ ...existing,
170
+ id
171
+ });
172
+ }
173
+ } else {
174
+ z.globalRegistry.add(schema, {
175
+ id
176
+ });
177
+ }
178
+ if (!recordOnce(schema, id)) {
179
+ return;
180
+ }
181
+ pendingRoots.push(schema);
182
+ }, "register"),
183
+ hasCollision: /* @__PURE__ */ __name((id) => {
184
+ flushPendingDiscovery();
185
+ const set = seen.get(id);
186
+ return set !== void 0 && set.size > 1;
187
+ }, "hasCollision"),
188
+ getCollisions: /* @__PURE__ */ __name(() => {
189
+ flushPendingDiscovery();
190
+ const out = /* @__PURE__ */ new Map();
191
+ for (const [id, set] of seen) {
192
+ if (set.size <= 1) {
193
+ continue;
194
+ }
195
+ out.set(id, set);
196
+ }
197
+ return out;
198
+ }, "getCollisions"),
199
+ ids: /* @__PURE__ */ __name(() => {
200
+ flushPendingDiscovery();
201
+ return [
202
+ ...seen.keys()
203
+ ];
204
+ }, "ids"),
205
+ forceExposedIds: /* @__PURE__ */ __name(() => [
206
+ ...forceExposed
207
+ ], "forceExposedIds"),
208
+ anonymousIds: /* @__PURE__ */ __name(() => [
209
+ ...anonymous
210
+ ], "anonymousIds")
211
+ };
212
+ }, "createRegistry");
213
+ var defaultRegistry = singleton("default-registry", createRegistry);
214
+ var registerSchema = /* @__PURE__ */ __name((schema, registry = defaultRegistry, options) => {
215
+ const flags = {
216
+ expose: options?.expose,
217
+ anonymous: options?.anonymous
218
+ };
219
+ const explicit = options?.id;
220
+ if (typeof explicit === "string" && explicit !== "") {
221
+ registry.register(schema, explicit, flags);
222
+ return explicit;
223
+ }
224
+ const meta = registry.zodRegistry.get(schema);
225
+ const metaId = meta === void 0 ? void 0 : meta.id;
226
+ if (typeof metaId !== "string" || metaId === "") {
227
+ return void 0;
228
+ }
229
+ registry.register(schema, metaId, flags);
230
+ return metaId;
231
+ }, "registerSchema");
232
+
233
+ // src/schema/composition.ts
234
+ var lineageMap = singleton("lineage-map", () => /* @__PURE__ */ new WeakMap());
235
+ var OPTIONAL_WRAPPER_TYPES = /* @__PURE__ */ new Set([
236
+ "optional",
237
+ "default"
238
+ ]);
239
+ var isOptionalProp = /* @__PURE__ */ __name((propSchema) => OPTIONAL_WRAPPER_TYPES.has(propSchema._zod.def.type), "isOptionalProp");
240
+ var computeShapeKeys = /* @__PURE__ */ __name((schema) => {
241
+ const entries = Object.entries(schema.shape);
242
+ return {
243
+ properties: entries.map(([key]) => key),
244
+ required: entries.filter(([, propSchema]) => !isOptionalProp(propSchema)).map(([key]) => key)
245
+ };
246
+ }, "computeShapeKeys");
247
+ var computeOverriddenKeys = /* @__PURE__ */ __name((parent, child) => {
248
+ const overriddenKeys = /* @__PURE__ */ new Set();
249
+ for (const key of Object.keys(child.shape)) {
250
+ const parentProp = parent.shape[key];
251
+ if (parentProp !== void 0 && parentProp !== child.shape[key]) {
252
+ overriddenKeys.add(key);
253
+ }
254
+ }
255
+ return overriddenKeys;
256
+ }, "computeOverriddenKeys");
257
+ var extend = /* @__PURE__ */ __name((parent, build) => {
258
+ const result = build(parent);
259
+ lineageMap.set(result, {
260
+ op: "extend",
261
+ parent,
262
+ overriddenKeys: computeOverriddenKeys(parent, result)
263
+ });
264
+ registerSchema(parent);
265
+ registerSchema(result);
266
+ return result;
267
+ }, "extend");
268
+ var getLineage = /* @__PURE__ */ __name((schema) => lineageMap.get(schema), "getLineage");
269
+ var DEFAULT_BUILD_REF = /* @__PURE__ */ __name((id) => `${DEFS_PREFIX}${id}`, "DEFAULT_BUILD_REF");
270
+ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
271
+ const { buildRef, registry } = opts;
272
+ return (ctx) => {
273
+ const { jsonSchema, zodSchema } = ctx;
274
+ const entry = lineageMap.get(zodSchema);
275
+ if (entry === void 0) {
276
+ return;
277
+ }
278
+ const parentCache = computeShapeKeys(entry.parent);
279
+ const parentId = registry.zodRegistry.get(entry.parent)?.id;
280
+ if (parentId === void 0) {
281
+ return;
282
+ }
283
+ registerSchema(entry.parent, registry);
284
+ const childProps = jsonSchema.properties ?? {};
285
+ const childRequired = jsonSchema.required ?? [];
286
+ const parentPropSet = new Set(parentCache.properties);
287
+ const parentReqSet = new Set(parentCache.required);
288
+ const deltaProps = {};
289
+ for (const [key, value] of Object.entries(childProps)) {
290
+ if (parentPropSet.has(key) && !entry.overriddenKeys.has(key)) {
291
+ continue;
292
+ }
293
+ deltaProps[key] = value;
294
+ }
295
+ const deltaRequired = childRequired.filter((key) => !parentReqSet.has(key) || entry.overriddenKeys.has(key));
296
+ const delta = {
297
+ type: "object",
298
+ properties: deltaProps
299
+ };
300
+ if (deltaRequired.length > 0) {
301
+ delta.required = deltaRequired;
302
+ }
303
+ delete jsonSchema.properties;
304
+ delete jsonSchema.required;
305
+ delete jsonSchema.additionalProperties;
306
+ jsonSchema.type = "object";
307
+ jsonSchema.allOf = [
308
+ {
309
+ $ref: buildRef(parentId)
310
+ },
311
+ delta
312
+ ];
313
+ jsonSchema.unevaluatedProperties = false;
314
+ };
315
+ }, "createCompositionOverride");
316
+
317
+ // src/schema/errors.ts
318
+ var ZodNestError = class extends Error {
319
+ static {
320
+ __name(this, "ZodNestError");
321
+ }
322
+ constructor(message) {
323
+ super(message);
324
+ this.name = "ZodNestError";
325
+ }
326
+ };
327
+ var ZodNestUnrepresentableError = class extends ZodNestError {
328
+ static {
329
+ __name(this, "ZodNestUnrepresentableError");
330
+ }
331
+ path;
332
+ zodType;
333
+ constructor(path, zodType) {
334
+ super(`Unrepresentable Zod schema \`${zodType}\` at ${formatPath(path)}: no override produced a JSON Schema body. Set strict: false to emit \`{}\` instead, or supply an \`override\` that handles this Zod type.`);
335
+ this.name = "ZodNestUnrepresentableError";
336
+ this.path = path;
337
+ this.zodType = zodType;
338
+ }
339
+ };
340
+ var formatPath = /* @__PURE__ */ __name((path) => {
341
+ if (path.length === 0) {
342
+ return "<root>";
343
+ }
344
+ return "/" + path.map(String).join("/");
345
+ }, "formatPath");
346
+
347
+ // src/schema/override.ts
348
+ var primitiveOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
349
+ const type = zodSchema._zod.def.type;
350
+ if (type === "bigint") {
351
+ jsonSchema.type = "integer";
352
+ return;
353
+ }
354
+ if (type === "date") {
355
+ jsonSchema.type = "string";
356
+ jsonSchema.format = "date-time";
357
+ return;
358
+ }
359
+ }, "primitiveOverride");
360
+ var combine = /* @__PURE__ */ __name((...overrides) => {
361
+ const list = [];
362
+ for (const candidate of overrides) {
363
+ if (typeof candidate !== "function") {
364
+ continue;
365
+ }
366
+ list.push(candidate);
367
+ }
368
+ return (ctx) => {
369
+ for (const o of list) {
370
+ o(ctx);
371
+ }
372
+ };
373
+ }, "combine");
374
+
375
+ // src/schema/post-process.ts
376
+ var rewriteRefs = /* @__PURE__ */ __name((node, rootRef) => {
377
+ if (Array.isArray(node)) {
378
+ for (const item of node) {
379
+ rewriteRefs(item, rootRef);
380
+ }
381
+ return;
382
+ }
383
+ if (node === null || typeof node !== "object") {
384
+ return;
385
+ }
386
+ const obj = node;
387
+ const ref = obj.$ref;
388
+ if (typeof ref === "string" && ref.startsWith(DEFS_PREFIX)) {
389
+ obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);
390
+ } else if (ref === "#" && rootRef !== void 0) {
391
+ obj.$ref = rootRef;
392
+ }
393
+ for (const value of Object.values(obj)) {
394
+ rewriteRefs(value, rootRef);
395
+ }
396
+ }, "rewriteRefs");
397
+ var refsIn = /* @__PURE__ */ __name(function* (node) {
398
+ if (Array.isArray(node)) {
399
+ for (const item of node) {
400
+ yield* refsIn(item);
401
+ }
402
+ return;
403
+ }
404
+ if (node === null || typeof node !== "object") {
405
+ return;
406
+ }
407
+ const obj = node;
408
+ if (typeof obj.$ref === "string") {
409
+ yield obj.$ref;
410
+ }
411
+ for (const value of Object.values(obj)) {
412
+ yield* refsIn(value);
413
+ }
414
+ }, "refsIn");
415
+ var rootDefId = /* @__PURE__ */ __name((raw) => {
416
+ const ref = raw.$ref;
417
+ if (typeof ref !== "string" || !ref.startsWith(DEFS_PREFIX)) {
418
+ return void 0;
419
+ }
420
+ return ref.slice(DEFS_PREFIX.length);
421
+ }, "rootDefId");
422
+ var isReferenced = /* @__PURE__ */ __name((defs, id) => {
423
+ const ownRef = `${DEFS_PREFIX}${id}`;
424
+ for (const ref of refsIn(defs)) {
425
+ if (ref === "#" || ref === ownRef) {
426
+ return true;
427
+ }
428
+ }
429
+ return false;
430
+ }, "isReferenced");
431
+ var referencesRoot = /* @__PURE__ */ __name((raw) => {
432
+ for (const ref of refsIn(raw)) {
433
+ if (ref === "#") {
434
+ return true;
435
+ }
436
+ }
437
+ return false;
438
+ }, "referencesRoot");
439
+ var stripEnvelope = /* @__PURE__ */ __name((raw) => {
440
+ const root = {
441
+ ...raw
442
+ };
443
+ delete root.$schema;
444
+ delete root.$defs;
445
+ return root;
446
+ }, "stripEnvelope");
447
+ var resolveRoot = /* @__PURE__ */ __name((raw, refs, options) => {
448
+ const liftedId = rootDefId(raw);
449
+ if (liftedId !== void 0) {
450
+ const body = refs.get(liftedId);
451
+ if (body !== void 0 && !isReferenced(raw.$defs, liftedId)) {
452
+ refs.delete(liftedId);
453
+ return {
454
+ schema: body,
455
+ rootRef: void 0
456
+ };
457
+ }
458
+ return {
459
+ schema: stripEnvelope(raw),
460
+ rootRef: `${COMPONENTS_SCHEMAS_PREFIX}${liftedId}`
461
+ };
462
+ }
463
+ const root = stripEnvelope(raw);
464
+ if (!referencesRoot(raw)) {
465
+ return {
466
+ schema: root,
467
+ rootRef: void 0
468
+ };
469
+ }
470
+ const rootId = options?.rootId;
471
+ if (rootId === void 0) {
472
+ if (options?.strict ?? true) {
473
+ throw new ZodNestError('A schema referenced from inside its own emission has no id, so the reference cannot be resolved. Add `.meta({ id: "\u2026" })` to the root schema, or set strict: false to leave the reference unresolved.');
474
+ }
475
+ return {
476
+ schema: root,
477
+ rootRef: void 0
478
+ };
479
+ }
480
+ refs.set(rootId, root);
481
+ const rootRef = `${COMPONENTS_SCHEMAS_PREFIX}${rootId}`;
482
+ return {
483
+ schema: {
484
+ $ref: rootRef
485
+ },
486
+ rootRef
487
+ };
488
+ }, "resolveRoot");
489
+ var postProcess = /* @__PURE__ */ __name((raw, options) => {
490
+ const refs = /* @__PURE__ */ new Map();
491
+ const rawDefs = raw.$defs;
492
+ if (rawDefs !== void 0) {
493
+ for (const [id, body] of Object.entries(rawDefs)) {
494
+ refs.set(id, body);
495
+ }
496
+ }
497
+ const { schema, rootRef } = resolveRoot(raw, refs, options);
498
+ rewriteRefs(schema, rootRef);
499
+ for (const body of refs.values()) {
500
+ rewriteRefs(body, rootRef);
501
+ }
502
+ return {
503
+ schema,
504
+ refs
505
+ };
506
+ }, "postProcess");
507
+
508
+ // src/schema/engine.ts
509
+ var STRICT_REQUIRES_OVERRIDE = /* @__PURE__ */ new Set([
510
+ "bigint",
511
+ "date",
512
+ "symbol",
513
+ "undefined",
514
+ "void",
515
+ "map",
516
+ "set",
517
+ "transform",
518
+ "nan",
519
+ "custom"
520
+ ]);
521
+ var ANNOTATION_ONLY_KEYS = /* @__PURE__ */ new Set([
522
+ "title",
523
+ "description",
524
+ "deprecated",
525
+ "examples",
526
+ "default",
527
+ "readOnly",
528
+ "writeOnly",
529
+ "$id",
530
+ "$schema",
531
+ "$comment",
532
+ "id"
533
+ ]);
534
+ var isStrictlyUnrepresentable = /* @__PURE__ */ __name((jsonSchema, zodSchema) => {
535
+ if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {
536
+ return false;
537
+ }
538
+ return Object.keys(jsonSchema).every((key) => ANNOTATION_ONLY_KEYS.has(key));
539
+ }, "isStrictlyUnrepresentable");
540
+ var descentTarget = /* @__PURE__ */ __name(($in, out, io) => {
541
+ if (io === "output") {
542
+ return out;
543
+ }
544
+ if ($in._zod.traits.has("$ZodTransform")) {
545
+ return out;
546
+ }
547
+ return $in;
548
+ }, "descentTarget");
549
+ var markPipeCoverage = /* @__PURE__ */ __name((schema, io, covered) => {
550
+ const def = schema._zod.def;
551
+ if (def.type !== "pipe" || def.in === void 0 || def.out === void 0) {
552
+ return;
553
+ }
554
+ const target = descentTarget(def.in, def.out, io);
555
+ if (covered.has(target)) {
556
+ return;
557
+ }
558
+ covered.add(target);
559
+ markPipeCoverage(target, io, covered);
560
+ }, "markPipeCoverage");
561
+ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
562
+ const strict = params.strict ?? true;
563
+ const compositionOverride = createCompositionOverride({
564
+ buildRef: params.uri ?? DEFAULT_BUILD_REF,
565
+ registry: params.registry
566
+ });
567
+ const customOverride = createCustomOverride(params.io);
568
+ const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
569
+ const unrepresentableHits = [];
570
+ const coveredByPipe = /* @__PURE__ */ new WeakSet();
571
+ const wrapped = /* @__PURE__ */ __name((ctx) => {
572
+ merged(ctx);
573
+ if (ctx.zodSchema._zod.def.type === "pipe") {
574
+ const record = peekRegistration(ctx.zodSchema);
575
+ if (record !== void 0 && record[params.io] !== void 0) {
576
+ markPipeCoverage(ctx.zodSchema, params.io, coveredByPipe);
577
+ }
578
+ }
579
+ if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {
580
+ return;
581
+ }
582
+ unrepresentableHits.push({
583
+ path: [
584
+ ...ctx.path
585
+ ],
586
+ zodType: ctx.zodSchema._zod.def.type,
587
+ zodSchema: ctx.zodSchema
588
+ });
589
+ }, "wrapped");
590
+ const options = {
591
+ target: "draft-2020-12",
592
+ io: params.io,
593
+ unrepresentable: "any",
594
+ metadata: params.registry.zodRegistry,
595
+ override: wrapped,
596
+ cycles: "ref",
597
+ reused: params.reused
598
+ };
599
+ if (params.uri !== void 0) {
600
+ options.uri = params.uri;
601
+ }
602
+ return {
603
+ options,
604
+ consumeUnrepresentable: /* @__PURE__ */ __name(() => {
605
+ const firstHit = unrepresentableHits.find((hit) => !coveredByPipe.has(hit.zodSchema));
606
+ if (firstHit !== void 0) {
607
+ throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);
608
+ }
609
+ }, "consumeUnrepresentable")
610
+ };
611
+ }, "buildToJsonSchemaOptions");
612
+ var resolveRootId = /* @__PURE__ */ __name((schema, registry) => {
613
+ const id = registry.zodRegistry.get(schema)?.id;
614
+ return typeof id === "string" && id !== "" ? id : void 0;
615
+ }, "resolveRootId");
616
+ var toOpenApi = /* @__PURE__ */ __name((schema, opts) => {
617
+ const built = buildToJsonSchemaOptions({
618
+ registry: opts.registry,
619
+ io: opts.io,
620
+ override: opts.override,
621
+ strict: opts.strict,
622
+ reused: "inline"
623
+ });
624
+ const raw = z.toJSONSchema(schema, built.options);
625
+ built.consumeUnrepresentable();
626
+ const result = postProcess(raw, {
627
+ rootId: resolveRootId(schema, opts.registry),
628
+ strict: opts.strict
629
+ });
630
+ for (const [id] of opts.registry.getCollisions()) {
631
+ if (!result.refs.has(id)) {
632
+ continue;
633
+ }
634
+ result.refs.set(id, {
635
+ description: `ERROR: duplicate zod-nest id <${id}>`,
636
+ [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID
637
+ });
638
+ }
639
+ return result;
640
+ }, "toOpenApi");
641
+
642
+ // src/dto/symbols.ts
643
+ var ZOD_DTO_SYMBOL = /* @__PURE__ */ Symbol.for("zod-nest.dto");
644
+ var isZodDto = /* @__PURE__ */ __name((value) => typeof value === "function" && value[ZOD_DTO_SYMBOL] === true, "isZodDto");
645
+ var isZodSchema = /* @__PURE__ */ __name((value) => value instanceof z.ZodType, "isZodSchema");
646
+ var ZodValidationException = class extends BadRequestException {
647
+ static {
648
+ __name(this, "ZodValidationException");
649
+ }
650
+ zodError;
651
+ argMetadata;
652
+ constructor(zodError, argMetadata) {
653
+ super({
654
+ statusCode: HttpStatus.BAD_REQUEST,
655
+ message: "Validation failed",
656
+ errors: z.treeifyError(zodError)
657
+ }, {
658
+ cause: zodError
659
+ });
660
+ this.zodError = zodError;
661
+ this.argMetadata = argMetadata;
662
+ }
663
+ };
664
+
665
+ // src/schema/anon-id.ts
666
+ var ANON_RESPONSE_PREFIX = "_AnonResponseSchema_";
667
+ var ANON_BODY_PREFIX = "_AnonBodySchema_";
668
+ var anonIdCache = singleton("anon-id-cache", () => /* @__PURE__ */ new WeakMap());
669
+ var counterRef = singleton("anon-id-counter", () => ({
670
+ value: 0
671
+ }));
672
+ var resolveAnonId = /* @__PURE__ */ __name((schema, prefix) => {
673
+ const cached = anonIdCache.get(schema);
674
+ if (cached !== void 0) {
675
+ return cached;
676
+ }
677
+ counterRef.value += 1;
678
+ const id = `${prefix}${counterRef.value}`;
679
+ anonIdCache.set(schema, id);
680
+ return id;
681
+ }, "resolveAnonId");
682
+
683
+ // src/decorators/internal/zod-schema-ref.ts
684
+ function resolveSchemaRef(schema, options) {
685
+ const registry = options?.registry ?? defaultRegistry;
686
+ const id = registerSchema(schema, registry, {
687
+ id: options?.id
688
+ });
689
+ if (id !== void 0) {
690
+ return {
691
+ kind: "ref",
692
+ ref: {
693
+ $ref: `${COMPONENTS_SCHEMAS_PREFIX}${id}`
694
+ }
695
+ };
696
+ }
697
+ if (options?.deferAnonInline === true) {
698
+ const anonId = resolveAnonId(schema, ANON_BODY_PREFIX);
699
+ registerSchema(schema, registry, {
700
+ id: anonId,
701
+ anonymous: true
702
+ });
703
+ return {
704
+ kind: "ref",
705
+ ref: {
706
+ $ref: `${COMPONENTS_SCHEMAS_PREFIX}${anonId}`
707
+ }
708
+ };
709
+ }
710
+ for (const [child, childId] of discoverDependents(schema)) {
711
+ registry.register(child, childId);
712
+ }
713
+ const { schema: body } = toOpenApi(schema, {
714
+ io: "input",
715
+ registry
716
+ });
717
+ return {
718
+ kind: "inline",
719
+ schema: body
720
+ };
721
+ }
722
+ __name(resolveSchemaRef, "resolveSchemaRef");
723
+
724
+ // src/decorators/internal/zod-param-expand.ts
725
+ var isZodObject = /* @__PURE__ */ __name((schema) => schema._zod.def.type === "object", "isZodObject");
726
+ var expandObjectSchema = /* @__PURE__ */ __name((schema, options) => {
727
+ if (!isZodObject(schema)) {
728
+ throw new ZodNestError(`${options.decoratorName} requires a \`z.object({...})\` schema (got \`${schema._zod.def.type}\`). Each property of the object becomes one OpenAPI parameter. For non-object body shapes (intersections, unions, primitives), use \`@ZodBody\` instead.`);
729
+ }
730
+ const registry = options.registry ?? defaultRegistry;
731
+ registerSchema(schema, registry, {
732
+ id: options.id
733
+ });
734
+ const result = [];
735
+ for (const [name, propSchema] of Object.entries(schema.shape)) {
736
+ const resolution = resolveSchemaRef(propSchema, {
737
+ registry
738
+ });
739
+ const required = options.forceRequired === true || !isOptionalProp(propSchema);
740
+ result.push({
741
+ name,
742
+ required,
743
+ resolution
744
+ });
745
+ }
746
+ return result;
747
+ }, "expandObjectSchema");
748
+ var paramSchemaBody = /* @__PURE__ */ __name((resolution) => resolution.kind === "ref" ? resolution.ref : resolution.schema, "paramSchemaBody");
749
+ var intersectionArms = /* @__PURE__ */ __name((schema) => {
750
+ if (schema._zod.def.type !== "intersection") {
751
+ return null;
752
+ }
753
+ const def = schema._zod.def;
754
+ return {
755
+ left: def.left,
756
+ right: def.right
757
+ };
758
+ }, "intersectionArms");
759
+ var unionOptions = /* @__PURE__ */ __name((schema) => {
760
+ if (schema._zod.def.type !== "union") {
761
+ return null;
762
+ }
763
+ const def = schema._zod.def;
764
+ return def.options;
765
+ }, "unionOptions");
766
+ var collectObjectShapes = /* @__PURE__ */ __name((schema) => {
767
+ if (isZodObject(schema)) {
768
+ return {
769
+ shapes: [
770
+ schema.shape
771
+ ],
772
+ unionCrossed: false
773
+ };
774
+ }
775
+ const options = unionOptions(schema);
776
+ if (options !== null) {
777
+ const allShapes = [];
778
+ for (const variant of options) {
779
+ const variantResult = collectObjectShapes(variant);
780
+ if (variantResult === null) {
781
+ return null;
782
+ }
783
+ allShapes.push(...variantResult.shapes);
784
+ }
785
+ return {
786
+ shapes: allShapes,
787
+ unionCrossed: true
788
+ };
789
+ }
790
+ const arms = intersectionArms(schema);
791
+ if (arms === null) {
792
+ return null;
793
+ }
794
+ const left = collectObjectShapes(arms.left);
795
+ if (left === null) {
796
+ return null;
797
+ }
798
+ const right = collectObjectShapes(arms.right);
799
+ if (right === null) {
800
+ return null;
801
+ }
802
+ return {
803
+ shapes: [
804
+ ...left.shapes,
805
+ ...right.shapes
806
+ ],
807
+ unionCrossed: left.unionCrossed || right.unionCrossed
808
+ };
809
+ }, "collectObjectShapes");
810
+ var flattenObjectIntersection = /* @__PURE__ */ __name((schema, registry, decoratorName) => {
811
+ const collected = collectObjectShapes(schema);
812
+ if (collected === null) {
813
+ throw new ZodNestError(`${decoratorName} \`flatten: true\` requires every leaf of the schema to be a \`z.object({...})\` \u2014 intersections and unions of objects are supported, but primitives, tuples, transforms, and other non-object leaves are not. Drop \`flatten: true\` to emit the original schema with its composition intact.`);
814
+ }
815
+ const mergedShape = {};
816
+ for (const shape of collected.shapes) {
817
+ Object.assign(mergedShape, shape);
818
+ }
819
+ if (collected.unionCrossed) {
820
+ for (const [key, value] of Object.entries(mergedShape)) {
821
+ mergedShape[key] = value.optional();
822
+ }
823
+ }
824
+ const merged = z.object(mergedShape);
825
+ registerSchema(schema, registry);
826
+ for (const [child, childId] of discoverDependents(schema)) {
827
+ registry.register(child, childId);
828
+ }
829
+ const { schema: body } = toOpenApi(merged, {
830
+ io: "input",
831
+ registry
832
+ });
833
+ return body;
834
+ }, "flattenObjectIntersection");
835
+
836
+ export { ANON_RESPONSE_PREFIX, COMPONENTS_SCHEMAS_PREFIX, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZodNestError, ZodNestUnrepresentableError, ZodValidationException, buildToJsonSchemaOptions, createRegistry, defaultRegistry, expandObjectSchema, extend, flattenObjectIntersection, getLineage, isZodDto, isZodObject, isZodSchema, paramSchemaBody, registerSchema, resolveAnonId, resolveSchemaRef, toOpenApi };
837
+ //# sourceMappingURL=chunk-LHNXO52A.mjs.map
838
+ //# sourceMappingURL=chunk-LHNXO52A.mjs.map