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
@@ -1,1125 +1,34 @@
1
1
  'use strict';
2
2
 
3
- var zod = require('zod');
4
- var swagger = require('@nestjs/swagger');
5
- var common = require('@nestjs/common');
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
-
10
- // src/helpers/fragments.ts
11
- var binaryFragment = {
12
- type: "string",
13
- format: "binary"
14
- };
15
- var binary = /* @__PURE__ */ __name((opts) => ({
16
- ...binaryFragment,
17
- ...opts
18
- }), "binary");
19
-
20
- // src/schema/custom-override.ts
21
- var customOverrideMap = /* @__PURE__ */ new WeakMap();
22
- var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
23
- var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
24
- const overrideSchema = isWrapper(arg) ? {
25
- ...arg
26
- } : {
27
- input: arg,
28
- output: arg
29
- };
30
- const schemaDescription = schema.description;
31
- if (typeof schemaDescription === "string") {
32
- overrideSchema.description = schemaDescription;
33
- }
34
- customOverrideMap.set(schema, overrideSchema);
35
- return schema;
36
- }, "overrideJSONSchema");
37
- var peekRegistration = /* @__PURE__ */ __name((schema) => customOverrideMap.get(schema), "peekRegistration");
38
- var createCustomOverride = /* @__PURE__ */ __name((io) => {
39
- return ({ zodSchema, jsonSchema }) => {
40
- const record = customOverrideMap.get(zodSchema);
41
- if (record === void 0) {
42
- return;
43
- }
44
- const fragment = record[io];
45
- if (fragment === void 0) {
46
- return;
47
- }
48
- for (const key of Object.keys(jsonSchema)) {
49
- Reflect.deleteProperty(jsonSchema, key);
50
- }
51
- Object.assign(jsonSchema, fragment);
52
- if (fragment.description === void 0 && record.description !== void 0) {
53
- jsonSchema.description = record.description;
54
- }
55
- };
56
- }, "createCustomOverride");
57
-
58
- // src/multipart/file-checks.ts
59
- var normalizeExtension = /* @__PURE__ */ __name((extension) => extension.startsWith(".") ? extension.toLowerCase() : `.${extension.toLowerCase()}`, "normalizeExtension");
60
- var mimeTypeCheck = /* @__PURE__ */ __name((accessors2, options) => {
61
- const allowed = new Set(options.mimeTypes.map((mimeType) => mimeType.toLowerCase()));
62
- return (payload) => {
63
- const mimeType = accessors2.mimeType(payload.value).toLowerCase();
64
- if (allowed.has(mimeType)) {
65
- return;
66
- }
67
- payload.issues.push({
68
- code: "custom",
69
- input: payload.value,
70
- message: `Expected one of ${options.mimeTypes.join(", ")}, received ${mimeType}`
71
- });
72
- };
73
- }, "mimeTypeCheck");
74
- var extensionCheck = /* @__PURE__ */ __name((accessors2, options) => {
75
- const allowed = new Set(options.extensions.map(normalizeExtension));
76
- return (payload) => {
77
- const fileName = accessors2.fileName(payload.value).toLowerCase();
78
- const matched = [
79
- ...allowed
80
- ].some((extension) => fileName.endsWith(extension));
81
- if (matched) {
82
- return;
83
- }
84
- payload.issues.push({
85
- code: "custom",
86
- input: payload.value,
87
- message: `Expected a file ending in ${options.extensions.map(normalizeExtension).join(", ")}, received ${fileName}`
88
- });
89
- };
90
- }, "extensionCheck");
91
- var sizeCheck = /* @__PURE__ */ __name((readSize, options) => {
92
- return (payload) => {
93
- const size = readSize(payload.value);
94
- if (size <= options.maxSize) {
95
- return;
96
- }
97
- payload.issues.push({
98
- code: "custom",
99
- input: payload.value,
100
- message: `Expected at most ${options.maxSize} bytes, received ${size}`
101
- });
102
- };
103
- }, "sizeCheck");
104
-
105
- // src/multipart/file-marker.ts
106
- var fileSchemas = /* @__PURE__ */ new WeakSet();
107
- var isZodType = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && "_zod" in value, "isZodType");
108
- var innerOf = /* @__PURE__ */ __name((def) => {
109
- if ("innerType" in def) {
110
- return def.innerType;
111
- }
112
- if ("element" in def) {
113
- return def.element;
114
- }
115
- return void 0;
116
- }, "innerOf");
117
- var unwrapOnce = /* @__PURE__ */ __name((schema) => {
118
- const inner = innerOf(schema._zod.def);
119
- return isZodType(inner) ? inner : void 0;
120
- }, "unwrapOnce");
121
- var markFileSchema = /* @__PURE__ */ __name((schema) => {
122
- fileSchemas.add(schema);
123
- return schema;
124
- }, "markFileSchema");
125
- var isFileSchema = /* @__PURE__ */ __name((schema) => {
126
- if (fileSchemas.has(schema)) {
127
- return true;
128
- }
129
- const inner = unwrapOnce(schema);
130
- if (inner === void 0) {
131
- return false;
132
- }
133
- return isFileSchema(inner);
134
- }, "isFileSchema");
135
-
136
- // src/multipart/build-file-schema.ts
137
- var resolveFragment = /* @__PURE__ */ __name((options) => {
138
- const contentMediaType = options?.contentMediaType ?? singleMimeType(options?.mimeTypes);
139
- return binary({
140
- ...options?.description !== void 0 ? {
141
- description: options.description
142
- } : {},
143
- ...contentMediaType !== void 0 ? {
144
- contentMediaType
145
- } : {}
146
- });
147
- }, "resolveFragment");
148
- var singleMimeType = /* @__PURE__ */ __name((mimeTypes) => {
149
- if (mimeTypes === void 0 || mimeTypes.length !== 1) {
150
- return void 0;
151
- }
152
- return mimeTypes[0];
153
- }, "singleMimeType");
154
- var collectChecks = /* @__PURE__ */ __name((params) => {
155
- const { accessors: accessors2, options, maxSize } = params;
156
- const checks = [];
157
- if (options?.mimeTypes !== void 0) {
158
- checks.push(mimeTypeCheck(accessors2, {
159
- mimeTypes: options.mimeTypes
160
- }));
161
- }
162
- if (options?.extensions !== void 0) {
163
- checks.push(extensionCheck(accessors2, {
164
- extensions: options.extensions
165
- }));
166
- }
167
- if (maxSize !== void 0 && accessors2.size !== void 0) {
168
- checks.push(sizeCheck(accessors2.size, {
169
- maxSize
170
- }));
171
- }
172
- return checks;
173
- }, "collectChecks");
174
- var withId = /* @__PURE__ */ __name((schema, options, fragment) => {
175
- if (options?.id === void 0) {
176
- return schema;
177
- }
178
- return overrideJSONSchema(schema.meta({
179
- id: options.id
180
- }), fragment);
181
- }, "withId");
182
- var buildFileSchema = /* @__PURE__ */ __name((params) => {
183
- const fragment = resolveFragment(params.options);
184
- const base = overrideJSONSchema(zod.z.custom(params.predicate), fragment);
185
- const checks = collectChecks(params);
186
- const checked = checks.length === 0 ? base : overrideJSONSchema(base.check(...checks), fragment);
187
- return markFileSchema(withId(checked, params.options, fragment));
188
- }, "buildFileSchema");
189
-
190
- // src/multipart/metadata.ts
191
- var MultipartFilesIn = {
192
- Request: "request",
193
- Body: "body"
194
- };
195
- var ZOD_MULTIPART_METADATA_KEY = /* @__PURE__ */ Symbol.for("zod-nest.multipart");
196
- var INNER_TYPE_WRAPPERS = /* @__PURE__ */ new Set([
197
- "optional",
198
- "nullable",
199
- "default",
200
- "prefault",
201
- "catch",
202
- "nonoptional",
203
- "success",
204
- "readonly",
205
- "promise"
206
- ]);
207
- var readId = /* @__PURE__ */ __name((schema) => {
208
- const meta = zod.z.globalRegistry.get(schema);
209
- if (meta === void 0) {
210
- return void 0;
211
- }
212
- const id = meta.id;
213
- return typeof id === "string" ? id : void 0;
214
- }, "readId");
215
- var resolveLazyTarget = /* @__PURE__ */ __name((getter) => {
216
- try {
217
- return [
218
- getter()
219
- ];
220
- } catch (error) {
221
- if (error instanceof ReferenceError) {
222
- return [];
223
- }
224
- throw error;
225
- }
226
- }, "resolveLazyTarget");
227
- var collectChildren = /* @__PURE__ */ __name((schema) => {
228
- const def = schema._zod.def;
229
- if (def.type === "object") {
230
- const out = [];
231
- const shape = def.shape;
232
- if (shape !== void 0) {
233
- for (const value of Object.values(shape)) {
234
- out.push(value);
235
- }
236
- }
237
- if (def.catchall !== void 0) {
238
- out.push(def.catchall);
239
- }
240
- return out;
241
- }
242
- if (def.type === "array") {
243
- return [
244
- def.element
245
- ];
246
- }
247
- if (def.type === "union") {
248
- return def.options.map((opt) => opt);
249
- }
250
- if (def.type === "intersection") {
251
- return [
252
- def.left,
253
- def.right
254
- ];
255
- }
256
- if (def.type === "tuple") {
257
- const out = def.items.map((it) => it);
258
- if (def.rest !== null) {
259
- out.push(def.rest);
260
- }
261
- return out;
262
- }
263
- if (def.type === "record" || def.type === "map") {
264
- return [
265
- def.keyType,
266
- def.valueType
267
- ];
268
- }
269
- if (def.type === "set") {
270
- return [
271
- def.valueType
272
- ];
273
- }
274
- if (def.type === "pipe") {
275
- return [
276
- def.in,
277
- def.out
278
- ];
279
- }
280
- if (def.type === "lazy") {
281
- return resolveLazyTarget(() => def.getter());
282
- }
283
- if (INNER_TYPE_WRAPPERS.has(def.type)) {
284
- return [
285
- def.innerType
286
- ];
287
- }
288
- return [];
289
- }, "collectChildren");
290
- var discoverDependents = /* @__PURE__ */ __name((schema) => {
291
- const visited = /* @__PURE__ */ new WeakSet();
292
- const out = [];
293
- const stack = [
294
- schema
295
- ];
296
- while (stack.length > 0) {
297
- const current = stack.pop();
298
- if (visited.has(current)) {
299
- continue;
300
- }
301
- visited.add(current);
302
- for (const child of collectChildren(current)) {
303
- if (child === void 0 || visited.has(child)) {
304
- continue;
305
- }
306
- const id = readId(child);
307
- if (id !== void 0) {
308
- out.push([
309
- child,
310
- id
311
- ]);
312
- }
313
- stack.push(child);
314
- }
315
- }
316
- return out;
317
- }, "discoverDependents");
318
-
319
- // src/schema/constants.ts
320
- var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
321
- var DEFS_PREFIX = "#/$defs/";
322
- var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
323
- var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
324
- var createRegistry = /* @__PURE__ */ __name(() => {
325
- const seen = /* @__PURE__ */ new Map();
326
- const forceExposed = /* @__PURE__ */ new Set();
327
- const anonymous = /* @__PURE__ */ new Set();
328
- const pendingRoots = [];
329
- const recordOnce = /* @__PURE__ */ __name((schema, id) => {
330
- let set = seen.get(id);
331
- if (set === void 0) {
332
- set = /* @__PURE__ */ new Set();
333
- seen.set(id, set);
334
- }
335
- if (set.has(schema)) {
336
- return false;
337
- }
338
- set.add(schema);
339
- return true;
340
- }, "recordOnce");
341
- const flushPendingDiscovery = /* @__PURE__ */ __name(() => {
342
- for (const root of pendingRoots.splice(0)) {
343
- for (const [child, childId] of discoverDependents(root)) {
344
- recordOnce(child, childId);
345
- }
346
- }
347
- }, "flushPendingDiscovery");
348
- return {
349
- zodRegistry: zod.z.globalRegistry,
350
- register: /* @__PURE__ */ __name((schema, id, flags) => {
351
- if (flags?.expose === true) {
352
- forceExposed.add(id);
353
- }
354
- if (flags?.anonymous === true) {
355
- anonymous.add(id);
356
- }
357
- if (zod.z.globalRegistry.has(schema)) {
358
- const existing = zod.z.globalRegistry.get(schema);
359
- if (existing?.id !== id) {
360
- zod.z.globalRegistry.add(schema, {
361
- ...existing ?? {},
362
- id
363
- });
364
- }
365
- } else {
366
- zod.z.globalRegistry.add(schema, {
367
- id
368
- });
369
- }
370
- if (!recordOnce(schema, id)) {
371
- return;
372
- }
373
- pendingRoots.push(schema);
374
- }, "register"),
375
- hasCollision: /* @__PURE__ */ __name((id) => {
376
- flushPendingDiscovery();
377
- const set = seen.get(id);
378
- return set !== void 0 && set.size > 1;
379
- }, "hasCollision"),
380
- getCollisions: /* @__PURE__ */ __name(() => {
381
- flushPendingDiscovery();
382
- const out = /* @__PURE__ */ new Map();
383
- for (const [id, set] of seen) {
384
- if (set.size <= 1) {
385
- continue;
386
- }
387
- out.set(id, set);
388
- }
389
- return out;
390
- }, "getCollisions"),
391
- ids: /* @__PURE__ */ __name(() => {
392
- flushPendingDiscovery();
393
- return [
394
- ...seen.keys()
395
- ];
396
- }, "ids"),
397
- forceExposedIds: /* @__PURE__ */ __name(() => [
398
- ...forceExposed
399
- ], "forceExposedIds"),
400
- anonymousIds: /* @__PURE__ */ __name(() => [
401
- ...anonymous
402
- ], "anonymousIds")
403
- };
404
- }, "createRegistry");
405
- var defaultRegistry = createRegistry();
406
- var registerSchema = /* @__PURE__ */ __name((schema, registry = defaultRegistry, options) => {
407
- const flags = {
408
- expose: options?.expose,
409
- anonymous: options?.anonymous
410
- };
411
- const explicit = options?.id;
412
- if (typeof explicit === "string" && explicit !== "") {
413
- registry.register(schema, explicit, flags);
414
- return explicit;
415
- }
416
- const meta = registry.zodRegistry.get(schema);
417
- const metaId = meta === void 0 ? void 0 : meta.id;
418
- if (typeof metaId !== "string" || metaId === "") {
419
- return void 0;
420
- }
421
- registry.register(schema, metaId, flags);
422
- return metaId;
423
- }, "registerSchema");
424
-
425
- // src/schema/composition.ts
426
- var lineageMap = /* @__PURE__ */ new WeakMap();
427
- var propsMap = /* @__PURE__ */ new WeakMap();
428
- var DEFAULT_BUILD_REF = /* @__PURE__ */ __name((id) => `${DEFS_PREFIX}${id}`, "DEFAULT_BUILD_REF");
429
- var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
430
- const { buildRef, registry } = opts;
431
- return (ctx) => {
432
- const { jsonSchema, zodSchema } = ctx;
433
- const entry = lineageMap.get(zodSchema);
434
- if (entry === void 0) {
435
- return;
436
- }
437
- const parentCache = propsMap.get(entry.parent);
438
- if (parentCache === void 0) {
439
- return;
440
- }
441
- const parentId = registry.zodRegistry.get(entry.parent)?.id;
442
- if (parentId === void 0) {
443
- return;
444
- }
445
- registerSchema(entry.parent, registry);
446
- const childProps = jsonSchema.properties ?? {};
447
- const childRequired = jsonSchema.required ?? [];
448
- const parentPropSet = new Set(parentCache.properties);
449
- const parentReqSet = new Set(parentCache.required);
450
- const deltaProps = {};
451
- for (const [key, value] of Object.entries(childProps)) {
452
- if (parentPropSet.has(key) && !entry.overriddenKeys.has(key)) {
453
- continue;
454
- }
455
- deltaProps[key] = value;
456
- }
457
- const deltaRequired = childRequired.filter((key) => !parentReqSet.has(key) || entry.overriddenKeys.has(key));
458
- const delta = {
459
- type: "object",
460
- properties: deltaProps
461
- };
462
- if (deltaRequired.length > 0) {
463
- delta.required = deltaRequired;
464
- }
465
- delete jsonSchema.properties;
466
- delete jsonSchema.required;
467
- delete jsonSchema.additionalProperties;
468
- jsonSchema.type = "object";
469
- jsonSchema.allOf = [
470
- {
471
- $ref: buildRef(parentId)
472
- },
473
- delta
474
- ];
475
- jsonSchema.unevaluatedProperties = false;
476
- };
477
- }, "createCompositionOverride");
478
-
479
- // src/schema/errors.ts
480
- var ZodNestError = class extends Error {
481
- static {
482
- __name(this, "ZodNestError");
483
- }
484
- constructor(message) {
485
- super(message);
486
- this.name = "ZodNestError";
487
- }
488
- };
489
- var ZodNestUnrepresentableError = class extends ZodNestError {
490
- static {
491
- __name(this, "ZodNestUnrepresentableError");
492
- }
493
- path;
494
- zodType;
495
- constructor(path, zodType) {
496
- 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.`);
497
- this.name = "ZodNestUnrepresentableError";
498
- this.path = path;
499
- this.zodType = zodType;
500
- }
501
- };
502
- var formatPath = /* @__PURE__ */ __name((path) => {
503
- if (path.length === 0) {
504
- return "<root>";
505
- }
506
- return "/" + path.map(String).join("/");
507
- }, "formatPath");
508
-
509
- // src/schema/override.ts
510
- var primitiveOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
511
- const type = zodSchema._zod.def.type;
512
- if (type === "bigint") {
513
- jsonSchema.type = "integer";
514
- return;
515
- }
516
- if (type === "date") {
517
- jsonSchema.type = "string";
518
- jsonSchema.format = "date-time";
519
- return;
520
- }
521
- }, "primitiveOverride");
522
- var combine = /* @__PURE__ */ __name((...overrides) => {
523
- const list = [];
524
- for (const candidate of overrides) {
525
- if (typeof candidate !== "function") {
526
- continue;
527
- }
528
- list.push(candidate);
529
- }
530
- return (ctx) => {
531
- for (const o of list) {
532
- o(ctx);
533
- }
534
- };
535
- }, "combine");
536
-
537
- // src/schema/post-process.ts
538
- var rewriteRefs = /* @__PURE__ */ __name((node, rootRef) => {
539
- if (Array.isArray(node)) {
540
- for (const item of node) {
541
- rewriteRefs(item, rootRef);
542
- }
543
- return;
544
- }
545
- if (node === null || typeof node !== "object") {
546
- return;
547
- }
548
- const obj = node;
549
- const ref = obj.$ref;
550
- if (typeof ref === "string" && ref.startsWith(DEFS_PREFIX)) {
551
- obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);
552
- } else if (ref === "#" && rootRef !== void 0) {
553
- obj.$ref = rootRef;
554
- }
555
- for (const value of Object.values(obj)) {
556
- rewriteRefs(value, rootRef);
557
- }
558
- }, "rewriteRefs");
559
- var refsIn = /* @__PURE__ */ __name(function* (node) {
560
- if (Array.isArray(node)) {
561
- for (const item of node) {
562
- yield* refsIn(item);
563
- }
564
- return;
565
- }
566
- if (node === null || typeof node !== "object") {
567
- return;
568
- }
569
- const obj = node;
570
- if (typeof obj.$ref === "string") {
571
- yield obj.$ref;
572
- }
573
- for (const value of Object.values(obj)) {
574
- yield* refsIn(value);
575
- }
576
- }, "refsIn");
577
- var rootDefId = /* @__PURE__ */ __name((raw) => {
578
- const ref = raw.$ref;
579
- if (typeof ref !== "string" || !ref.startsWith(DEFS_PREFIX)) {
580
- return void 0;
581
- }
582
- return ref.slice(DEFS_PREFIX.length);
583
- }, "rootDefId");
584
- var isReferenced = /* @__PURE__ */ __name((defs, id) => {
585
- const ownRef = `${DEFS_PREFIX}${id}`;
586
- for (const ref of refsIn(defs)) {
587
- if (ref === "#" || ref === ownRef) {
588
- return true;
589
- }
590
- }
591
- return false;
592
- }, "isReferenced");
593
- var referencesRoot = /* @__PURE__ */ __name((raw) => {
594
- for (const ref of refsIn(raw)) {
595
- if (ref === "#") {
596
- return true;
597
- }
598
- }
599
- return false;
600
- }, "referencesRoot");
601
- var stripEnvelope = /* @__PURE__ */ __name((raw) => {
602
- const root = {
603
- ...raw
604
- };
605
- delete root.$schema;
606
- delete root.$defs;
607
- return root;
608
- }, "stripEnvelope");
609
- var resolveRoot = /* @__PURE__ */ __name((raw, refs, options) => {
610
- const liftedId = rootDefId(raw);
611
- if (liftedId !== void 0) {
612
- const body = refs.get(liftedId);
613
- if (body !== void 0 && !isReferenced(raw.$defs, liftedId)) {
614
- refs.delete(liftedId);
615
- return {
616
- schema: body,
617
- rootRef: void 0
618
- };
619
- }
620
- return {
621
- schema: stripEnvelope(raw),
622
- rootRef: `${COMPONENTS_SCHEMAS_PREFIX}${liftedId}`
623
- };
624
- }
625
- const root = stripEnvelope(raw);
626
- if (!referencesRoot(raw)) {
627
- return {
628
- schema: root,
629
- rootRef: void 0
630
- };
631
- }
632
- const rootId = options?.rootId;
633
- if (rootId === void 0) {
634
- if (options?.strict ?? true) {
635
- 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.');
636
- }
637
- return {
638
- schema: root,
639
- rootRef: void 0
640
- };
641
- }
642
- refs.set(rootId, root);
643
- const rootRef = `${COMPONENTS_SCHEMAS_PREFIX}${rootId}`;
644
- return {
645
- schema: {
646
- $ref: rootRef
647
- },
648
- rootRef
649
- };
650
- }, "resolveRoot");
651
- var postProcess = /* @__PURE__ */ __name((raw, options) => {
652
- const refs = /* @__PURE__ */ new Map();
653
- const rawDefs = raw.$defs;
654
- if (rawDefs !== void 0) {
655
- for (const [id, body] of Object.entries(rawDefs)) {
656
- refs.set(id, body);
657
- }
658
- }
659
- const { schema, rootRef } = resolveRoot(raw, refs, options);
660
- rewriteRefs(schema, rootRef);
661
- for (const body of refs.values()) {
662
- rewriteRefs(body, rootRef);
663
- }
664
- return {
665
- schema,
666
- refs
667
- };
668
- }, "postProcess");
669
-
670
- // src/schema/engine.ts
671
- var STRICT_REQUIRES_OVERRIDE = /* @__PURE__ */ new Set([
672
- "bigint",
673
- "date",
674
- "symbol",
675
- "undefined",
676
- "void",
677
- "map",
678
- "set",
679
- "transform",
680
- "nan",
681
- "custom"
682
- ]);
683
- var ANNOTATION_ONLY_KEYS = /* @__PURE__ */ new Set([
684
- "title",
685
- "description",
686
- "deprecated",
687
- "examples",
688
- "default",
689
- "readOnly",
690
- "writeOnly",
691
- "$id",
692
- "$schema",
693
- "$comment",
694
- "id"
695
- ]);
696
- var isStrictlyUnrepresentable = /* @__PURE__ */ __name((jsonSchema, zodSchema) => {
697
- if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {
698
- return false;
699
- }
700
- return Object.keys(jsonSchema).every((key) => ANNOTATION_ONLY_KEYS.has(key));
701
- }, "isStrictlyUnrepresentable");
702
- var markPipeCoverage = /* @__PURE__ */ __name((schema, io, covered) => {
703
- const def = schema._zod.def;
704
- if (def.type !== "pipe" || def.in === void 0 || def.out === void 0) {
705
- return;
706
- }
707
- const target = io === "output" ? def.out : def.in._zod.traits.has("$ZodTransform") ? def.out : def.in;
708
- if (covered.has(target)) {
709
- return;
710
- }
711
- covered.add(target);
712
- markPipeCoverage(target, io, covered);
713
- }, "markPipeCoverage");
714
- var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
715
- const strict = params.strict ?? true;
716
- const compositionOverride = createCompositionOverride({
717
- buildRef: params.uri ?? DEFAULT_BUILD_REF,
718
- registry: params.registry
719
- });
720
- const customOverride = createCustomOverride(params.io);
721
- const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
722
- const unrepresentableHits = [];
723
- const coveredByPipe = /* @__PURE__ */ new WeakSet();
724
- const wrapped = /* @__PURE__ */ __name((ctx) => {
725
- merged(ctx);
726
- if (ctx.zodSchema._zod.def.type === "pipe") {
727
- const record = peekRegistration(ctx.zodSchema);
728
- if (record !== void 0 && record[params.io] !== void 0) {
729
- markPipeCoverage(ctx.zodSchema, params.io, coveredByPipe);
730
- }
731
- }
732
- if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {
733
- return;
734
- }
735
- unrepresentableHits.push({
736
- path: [
737
- ...ctx.path
738
- ],
739
- zodType: ctx.zodSchema._zod.def.type,
740
- zodSchema: ctx.zodSchema
741
- });
742
- }, "wrapped");
743
- const options = {
744
- target: "draft-2020-12",
745
- io: params.io,
746
- unrepresentable: "any",
747
- metadata: params.registry.zodRegistry,
748
- override: wrapped,
749
- cycles: "ref",
750
- reused: params.reused
751
- };
752
- if (params.uri !== void 0) {
753
- options.uri = params.uri;
754
- }
755
- return {
756
- options,
757
- consumeUnrepresentable: /* @__PURE__ */ __name(() => {
758
- const firstHit = unrepresentableHits.find((hit) => !coveredByPipe.has(hit.zodSchema));
759
- if (firstHit !== void 0) {
760
- throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);
761
- }
762
- }, "consumeUnrepresentable")
763
- };
764
- }, "buildToJsonSchemaOptions");
765
- var resolveRootId = /* @__PURE__ */ __name((schema, registry) => {
766
- const id = registry.zodRegistry.get(schema)?.id;
767
- return typeof id === "string" && id !== "" ? id : void 0;
768
- }, "resolveRootId");
769
- var toOpenApi = /* @__PURE__ */ __name((schema, opts) => {
770
- const built = buildToJsonSchemaOptions({
771
- registry: opts.registry,
772
- io: opts.io,
773
- override: opts.override,
774
- strict: opts.strict,
775
- reused: "inline"
776
- });
777
- const raw = zod.z.toJSONSchema(schema, built.options);
778
- built.consumeUnrepresentable();
779
- const result = postProcess(raw, {
780
- rootId: resolveRootId(schema, opts.registry),
781
- strict: opts.strict
782
- });
783
- for (const [id] of opts.registry.getCollisions()) {
784
- if (!result.refs.has(id)) {
785
- continue;
786
- }
787
- result.refs.set(id, {
788
- description: `ERROR: duplicate zod-nest id <${id}>`,
789
- [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID
790
- });
791
- }
792
- return result;
793
- }, "toOpenApi");
794
-
795
- // src/schema/anon-id.ts
796
- var ANON_BODY_PREFIX = "_AnonBodySchema_";
797
- var anonIdCache = /* @__PURE__ */ new WeakMap();
798
- var counter = 0;
799
- var resolveAnonId = /* @__PURE__ */ __name((schema, prefix) => {
800
- const cached = anonIdCache.get(schema);
801
- if (cached !== void 0) {
802
- return cached;
803
- }
804
- counter += 1;
805
- const id = `${prefix}${counter}`;
806
- anonIdCache.set(schema, id);
807
- return id;
808
- }, "resolveAnonId");
809
-
810
- // src/decorators/internal/zod-schema-ref.ts
811
- function resolveSchemaRef(schema, options) {
812
- const registry = options?.registry ?? defaultRegistry;
813
- const id = registerSchema(schema, registry, {
814
- id: options?.id
815
- });
816
- if (id !== void 0) {
817
- return {
818
- kind: "ref",
819
- ref: {
820
- $ref: `${COMPONENTS_SCHEMAS_PREFIX}${id}`
821
- }
822
- };
823
- }
824
- if (options?.deferAnonInline === true) {
825
- const anonId = resolveAnonId(schema, ANON_BODY_PREFIX);
826
- registerSchema(schema, registry, {
827
- id: anonId,
828
- anonymous: true
829
- });
830
- return {
831
- kind: "ref",
832
- ref: {
833
- $ref: `${COMPONENTS_SCHEMAS_PREFIX}${anonId}`
834
- }
835
- };
836
- }
837
- for (const [child, childId] of discoverDependents(schema)) {
838
- registry.register(child, childId);
839
- }
840
- const { schema: body } = toOpenApi(schema, {
841
- io: "input",
842
- registry
843
- });
844
- return {
845
- kind: "inline",
846
- schema: body
847
- };
848
- }
849
- __name(resolveSchemaRef, "resolveSchemaRef");
850
-
851
- // src/decorators/internal/zod-param-expand.ts
852
- var isZodObject = /* @__PURE__ */ __name((schema) => schema._zod.def.type === "object", "isZodObject");
853
-
854
- // src/decorators/internal/flatten-intersection.ts
855
- var intersectionArms = /* @__PURE__ */ __name((schema) => {
856
- if (schema._zod.def.type !== "intersection") {
857
- return null;
858
- }
859
- const def = schema._zod.def;
860
- return {
861
- left: def.left,
862
- right: def.right
863
- };
864
- }, "intersectionArms");
865
- var unionOptions = /* @__PURE__ */ __name((schema) => {
866
- if (schema._zod.def.type !== "union") {
867
- return null;
868
- }
869
- const def = schema._zod.def;
870
- return def.options;
871
- }, "unionOptions");
872
- var collectObjectShapes = /* @__PURE__ */ __name((schema) => {
873
- if (isZodObject(schema)) {
874
- return {
875
- shapes: [
876
- schema.shape
877
- ],
878
- unionCrossed: false
879
- };
880
- }
881
- const options = unionOptions(schema);
882
- if (options !== null) {
883
- const allShapes = [];
884
- for (const variant of options) {
885
- const variantResult = collectObjectShapes(variant);
886
- if (variantResult === null) {
887
- return null;
888
- }
889
- allShapes.push(...variantResult.shapes);
890
- }
891
- return {
892
- shapes: allShapes,
893
- unionCrossed: true
894
- };
895
- }
896
- const arms = intersectionArms(schema);
897
- if (arms === null) {
898
- return null;
899
- }
900
- const left = collectObjectShapes(arms.left);
901
- if (left === null) {
902
- return null;
903
- }
904
- const right = collectObjectShapes(arms.right);
905
- if (right === null) {
906
- return null;
907
- }
908
- return {
909
- shapes: [
910
- ...left.shapes,
911
- ...right.shapes
912
- ],
913
- unionCrossed: left.unionCrossed || right.unionCrossed
914
- };
915
- }, "collectObjectShapes");
916
- var flattenObjectIntersection = /* @__PURE__ */ __name((schema, registry, decoratorName) => {
917
- const collected = collectObjectShapes(schema);
918
- if (collected === null) {
919
- 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.`);
920
- }
921
- const mergedShape = {};
922
- for (const shape of collected.shapes) {
923
- Object.assign(mergedShape, shape);
924
- }
925
- if (collected.unionCrossed) {
926
- for (const key of Object.keys(mergedShape)) {
927
- const value = mergedShape[key];
928
- if (value !== void 0) {
929
- mergedShape[key] = value.optional();
930
- }
931
- }
932
- }
933
- const merged = zod.z.object(mergedShape);
934
- registerSchema(schema, registry);
935
- for (const [child, childId] of discoverDependents(schema)) {
936
- registry.register(child, childId);
937
- }
938
- const { schema: body } = toOpenApi(merged, {
939
- io: "input",
940
- registry
941
- });
942
- return body;
943
- }, "flattenObjectIntersection");
944
- var isZodSchema = /* @__PURE__ */ __name((value) => value instanceof zod.z.ZodType, "isZodSchema");
945
-
946
- // src/multipart/zod-multipart.decorator.ts
947
- var MULTIPART_CONTENT_TYPE = "multipart/form-data";
948
- var toSchema = /* @__PURE__ */ __name((body) => isZodSchema(body) ? body : zod.z.object({
949
- ...body
950
- }), "toSchema");
951
- var toShape = /* @__PURE__ */ __name((body) => {
952
- if (!isZodSchema(body)) {
953
- return body;
954
- }
955
- return isZodObject(body) ? body.shape : void 0;
956
- }, "toShape");
957
- var partitionKeys = /* @__PURE__ */ __name((shape) => {
958
- const fileKeys = [];
959
- const textKeys = [];
960
- for (const [key, schema] of Object.entries(shape ?? {})) {
961
- if (isFileSchema(schema)) {
962
- fileKeys.push(key);
963
- continue;
964
- }
965
- textKeys.push(key);
966
- }
967
- return {
968
- fileKeys,
969
- textKeys
970
- };
971
- }, "partitionKeys");
972
- var resolveBody = /* @__PURE__ */ __name((schema, options, registry) => {
973
- if (options?.flatten === true) {
974
- return flattenObjectIntersection(schema, registry, "@ZodMultipart");
975
- }
976
- const resolved = resolveSchemaRef(schema, {
977
- ...options?.id !== void 0 ? {
978
- id: options.id
979
- } : {},
980
- registry
981
- });
982
- return resolved.kind === "ref" ? resolved.ref : resolved.schema;
983
- }, "resolveBody");
984
- var createZodMultipart = /* @__PURE__ */ __name((defaultFilesIn) => {
985
- return (body, options) => {
986
- const registry = options?.registry ?? defaultRegistry;
987
- const shape = toShape(body);
988
- const metadata = {
989
- shape,
990
- ...partitionKeys(shape),
991
- filesIn: options?.filesIn ?? defaultFilesIn
992
- };
993
- const schema = resolveBody(toSchema(body), options, registry);
994
- return (target, propertyKey, descriptor) => {
995
- const handler = descriptor.value;
996
- if (typeof handler !== "function") {
997
- throw new TypeError("[zod-nest] @ZodMultipart can only be applied to methods.");
998
- }
999
- Reflect.defineMetadata(ZOD_MULTIPART_METADATA_KEY, metadata, handler);
1000
- const swaggerDescriptor = descriptor;
1001
- swagger.ApiConsumes(MULTIPART_CONTENT_TYPE)(target, propertyKey, swaggerDescriptor);
1002
- swagger.ApiBody({
1003
- schema,
1004
- ...options?.description !== void 0 ? {
1005
- description: options.description
1006
- } : {},
1007
- required: options?.required ?? true
1008
- })(target, propertyKey, swaggerDescriptor);
1009
- };
1010
- };
1011
- }, "createZodMultipart");
1012
- var ZodValidationException = class extends common.BadRequestException {
1013
- static {
1014
- __name(this, "ZodValidationException");
1015
- }
1016
- zodError;
1017
- argMetadata;
1018
- constructor(zodError, argMetadata) {
1019
- super({
1020
- statusCode: common.HttpStatus.BAD_REQUEST,
1021
- message: "Validation failed",
1022
- errors: zod.z.treeifyError(zodError)
1023
- }, {
1024
- cause: zodError
1025
- });
1026
- this.zodError = zodError;
1027
- this.argMetadata = argMetadata;
1028
- }
1029
- };
1030
-
1031
- // src/multipart/param-decorators.ts
1032
- var readMetadata = /* @__PURE__ */ __name((ctx, decorator) => {
1033
- const metadata = Reflect.getMetadata(ZOD_MULTIPART_METADATA_KEY, ctx.getHandler());
1034
- if (!isMultipartMetadata(metadata)) {
1035
- throw new Error(`[zod-nest] ${decorator} requires @ZodMultipart on the same handler \u2014 it reads the declared shape from there.`);
1036
- }
1037
- return metadata;
1038
- }, "readMetadata");
1039
- var isMultipartMetadata = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && "shape" in value && "filesIn" in value, "isMultipartMetadata");
1040
- var requireShape = /* @__PURE__ */ __name((metadata, decorator) => {
1041
- if (metadata.shape !== void 0) {
1042
- return metadata.shape;
1043
- }
1044
- throw new Error(`[zod-nest] ${decorator} needs a flat body shape, but @ZodMultipart was given a composite schema (an intersection or union). Validate it with @Body(new ZodValidationPipe(schema)) instead.`);
1045
- }, "requireShape");
1046
- var schemaFor = /* @__PURE__ */ __name((metadata, name, decorator) => {
1047
- const shape = requireShape(metadata, decorator);
1048
- const schema = shape[name];
1049
- if (schema === void 0) {
1050
- throw new Error(`[zod-nest] ${decorator}('${name}') has no matching property in the @ZodMultipart shape. Declared: ${Object.keys(shape).join(", ")}.`);
1051
- }
1052
- return schema;
1053
- }, "schemaFor");
1054
- var pick = /* @__PURE__ */ __name((shape, keys) => {
1055
- const wanted = new Set(keys);
1056
- const picked = {};
1057
- for (const [key, schema] of Object.entries(shape)) {
1058
- if (wanted.has(key)) {
1059
- picked[key] = schema;
1060
- }
1061
- }
1062
- return zod.z.object(picked);
1063
- }, "pick");
1064
- var validate = /* @__PURE__ */ __name(async (schema, value, argType) => {
1065
- const result = await schema.safeParseAsync(value);
1066
- if (result.success) {
1067
- return result.data;
1068
- }
1069
- throw new ZodValidationException(result.error, {
1070
- type: argType,
1071
- metatype: void 0,
1072
- data: void 0
1073
- });
1074
- }, "validate");
1075
- var assertFilesOnRequest = /* @__PURE__ */ __name((metadata, decorator) => {
1076
- if (metadata.filesIn === MultipartFilesIn.Request) {
1077
- return;
1078
- }
1079
- throw new Error(`[zod-nest] ${decorator} is unavailable under filesIn: 'body' \u2014 the parser puts files in the request body, so read them with @ZodMultipartBody().`);
1080
- }, "assertFilesOnRequest");
1081
- var resolveUploadedFile = /* @__PURE__ */ __name(async (name, ctx) => {
1082
- const metadata = readMetadata(ctx, "@ZodUploadedFile");
1083
- assertFilesOnRequest(metadata, "@ZodUploadedFile");
1084
- const request = ctx.switchToHttp().getRequest();
1085
- return validate(schemaFor(metadata, name, "@ZodUploadedFile"), request.file, "custom");
1086
- }, "resolveUploadedFile");
1087
- var resolveUploadedFiles = /* @__PURE__ */ __name(async (name, ctx) => {
1088
- const metadata = readMetadata(ctx, "@ZodUploadedFiles");
1089
- assertFilesOnRequest(metadata, "@ZodUploadedFiles");
1090
- const request = ctx.switchToHttp().getRequest();
1091
- const schema = name === void 0 ? pick(requireShape(metadata, "@ZodUploadedFiles"), metadata.fileKeys) : schemaFor(metadata, name, "@ZodUploadedFiles");
1092
- return validate(schema, request.files, "custom");
1093
- }, "resolveUploadedFiles");
1094
- var resolveMultipartBody = /* @__PURE__ */ __name(async (_data, ctx) => {
1095
- const metadata = readMetadata(ctx, "@ZodMultipartBody");
1096
- const shape = requireShape(metadata, "@ZodMultipartBody");
1097
- const request = ctx.switchToHttp().getRequest();
1098
- const keys = metadata.filesIn === MultipartFilesIn.Body ? Object.keys(shape) : metadata.textKeys;
1099
- return validate(pick(shape, keys), request.body, "body");
1100
- }, "resolveMultipartBody");
1101
- common.createParamDecorator(resolveUploadedFile);
1102
- common.createParamDecorator(resolveUploadedFiles);
1103
- var ZodMultipartBody = common.createParamDecorator(resolveMultipartBody);
3
+ var chunk26E2XEJU_js = require('../chunk-26E2XEJU.js');
4
+ require('../chunk-FKXVNCDD.js');
5
+ require('../chunk-LXRBMFWD.js');
6
+ var chunk4RXGLSPP_js = require('../chunk-4RXGLSPP.js');
1104
7
 
1105
8
  // src/fastify/index.ts
1106
- var isFastifyMultipartFile = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && "type" in value && value.type === "file" && "mimetype" in value && "filename" in value && "toBuffer" in value && typeof value.toBuffer === "function", "isFastifyMultipartFile");
9
+ var isFastifyMultipartFile = /* @__PURE__ */ chunk4RXGLSPP_js.__name((value) => value !== null && typeof value === "object" && "type" in value && value.type === "file" && "mimetype" in value && "filename" in value && "toBuffer" in value && typeof value.toBuffer === "function", "isFastifyMultipartFile");
1107
10
  var accessors = {
1108
- mimeType: /* @__PURE__ */ __name((file) => file.mimetype, "mimeType"),
1109
- fileName: /* @__PURE__ */ __name((file) => file.filename, "fileName")
11
+ mimeType: /* @__PURE__ */ chunk4RXGLSPP_js.__name((file) => file.mimetype, "mimeType"),
12
+ fileName: /* @__PURE__ */ chunk4RXGLSPP_js.__name((file) => file.filename, "fileName")
1110
13
  };
1111
- var fastifyMultipartFile = /* @__PURE__ */ __name((options) => buildFileSchema({
14
+ var fastifyMultipartFile = /* @__PURE__ */ chunk4RXGLSPP_js.__name((options) => chunk26E2XEJU_js.buildFileSchema({
1112
15
  predicate: isFastifyMultipartFile,
1113
16
  accessors,
1114
17
  options
1115
18
  }), "fastifyMultipartFile");
1116
19
  var FastifyMultipartFileSchema = fastifyMultipartFile();
1117
- var ZodMultipart = createZodMultipart(MultipartFilesIn.Body);
1118
-
20
+ var ZodMultipart = chunk26E2XEJU_js.createZodMultipart(chunk26E2XEJU_js.MultipartFilesIn.Body);
21
+
22
+ Object.defineProperty(exports, "MULTIPART_CONTENT_TYPE", {
23
+ enumerable: true,
24
+ get: function () { return chunk26E2XEJU_js.MULTIPART_CONTENT_TYPE; }
25
+ });
26
+ Object.defineProperty(exports, "ZodMultipartBody", {
27
+ enumerable: true,
28
+ get: function () { return chunk26E2XEJU_js.ZodMultipartBody; }
29
+ });
1119
30
  exports.FastifyMultipartFileSchema = FastifyMultipartFileSchema;
1120
- exports.MULTIPART_CONTENT_TYPE = MULTIPART_CONTENT_TYPE;
1121
31
  exports.ZodMultipart = ZodMultipart;
1122
- exports.ZodMultipartBody = ZodMultipartBody;
1123
32
  exports.fastifyMultipartFile = fastifyMultipartFile;
1124
33
  //# sourceMappingURL=index.js.map
1125
34
  //# sourceMappingURL=index.js.map