zod-nest 3.2.0 → 3.2.1

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