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.
- package/dist/chunk-26E2XEJU.js +294 -0
- package/dist/chunk-26E2XEJU.js.map +1 -0
- package/dist/chunk-4RXGLSPP.js +73 -0
- package/dist/chunk-4RXGLSPP.js.map +1 -0
- package/dist/chunk-FKXVNCDD.js +863 -0
- package/dist/chunk-FKXVNCDD.js.map +1 -0
- package/dist/chunk-LHNXO52A.mjs +838 -0
- package/dist/chunk-LHNXO52A.mjs.map +1 -0
- package/dist/chunk-LXRBMFWD.js +103 -0
- package/dist/chunk-LXRBMFWD.js.map +1 -0
- package/dist/chunk-RAF7JGS6.mjs +286 -0
- package/dist/chunk-RAF7JGS6.mjs.map +1 -0
- package/dist/chunk-WI4JKXT6.mjs +83 -0
- package/dist/chunk-WI4JKXT6.mjs.map +1 -0
- package/dist/chunk-ZZW54ETO.mjs +67 -0
- package/dist/chunk-ZZW54ETO.mjs.map +1 -0
- package/dist/express/index.d.mts +3 -3
- package/dist/express/index.d.ts +3 -3
- package/dist/express/index.js +33 -1118
- package/dist/express/index.js.map +1 -1
- package/dist/express/index.mjs +6 -1102
- package/dist/express/index.mjs.map +1 -1
- package/dist/fastify/index.d.mts +3 -3
- package/dist/fastify/index.d.ts +3 -3
- package/dist/fastify/index.js +18 -1109
- package/dist/fastify/index.js.map +1 -1
- package/dist/fastify/index.mjs +6 -1102
- package/dist/fastify/index.mjs.map +1 -1
- package/dist/helpers/index.js +81 -122
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/index.mjs +4 -101
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +263 -1091
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -895
- package/dist/index.mjs.map +1 -1
- package/dist/{param-decorators-CX1cUqfY.d.ts → param-decorators-23pStLeF.d.ts} +1 -1
- package/dist/{param-decorators-DbgygRVn.d.mts → param-decorators-Dfd2Cy08.d.mts} +1 -1
- package/dist/{registry-C9xStKa6.d.mts → registry-Cs1Y0a-L.d.mts} +1 -1
- package/dist/{registry-C9xStKa6.d.ts → registry-Cs1Y0a-L.d.ts} +1 -1
- package/package.json +26 -33
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { isZodDto, ZodNestError, ZodValidationException, defaultRegistry, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, flattenObjectIntersection, resolveSchemaRef, isZodObject, registerSchema, expandObjectSchema, paramSchemaBody, COMPONENTS_SCHEMAS_PREFIX, isZodSchema, buildToJsonSchemaOptions, resolveAnonId, ANON_RESPONSE_PREFIX, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './chunk-LHNXO52A.mjs';
|
|
2
|
+
export { COMPONENTS_SCHEMAS_PREFIX, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZodNestError, ZodNestUnrepresentableError, ZodValidationException, createRegistry, defaultRegistry, extend, getLineage, isZodDto, isZodSchema, registerSchema, toOpenApi } from './chunk-LHNXO52A.mjs';
|
|
3
|
+
import { singleton, __name } from './chunk-ZZW54ETO.mjs';
|
|
4
|
+
export { overrideJSONSchema } from './chunk-ZZW54ETO.mjs';
|
|
5
|
+
import { InternalServerErrorException, HttpStatus, Injectable, Optional, Inject, Logger, RequestMethod, applyDecorators } from '@nestjs/common';
|
|
1
6
|
import { z } from 'zod';
|
|
2
|
-
import { InternalServerErrorException, HttpStatus, BadRequestException, Injectable, Optional, Inject, Logger, RequestMethod, applyDecorators } from '@nestjs/common';
|
|
3
7
|
import { HTTP_CODE_METADATA, METHOD_METADATA, HEADERS_METADATA } from '@nestjs/common/constants.js';
|
|
4
8
|
import { ApiBody, ApiQuery, ApiResponse, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
|
|
5
9
|
import { Reflector, APP_PIPE, APP_INTERCEPTOR } from '@nestjs/core';
|
|
@@ -7,690 +11,6 @@ import { from } from 'rxjs';
|
|
|
7
11
|
import { mergeMap } from 'rxjs/operators';
|
|
8
12
|
import stringify from 'fast-json-stable-stringify';
|
|
9
13
|
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
|
|
13
|
-
// src/schema/constants.ts
|
|
14
|
-
var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
15
|
-
var DEFS_PREFIX = "#/$defs/";
|
|
16
|
-
var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
|
|
17
|
-
var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
|
|
18
|
-
var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
19
|
-
var INNER_TYPE_WRAPPERS = /* @__PURE__ */ new Set([
|
|
20
|
-
"optional",
|
|
21
|
-
"nullable",
|
|
22
|
-
"default",
|
|
23
|
-
"prefault",
|
|
24
|
-
"catch",
|
|
25
|
-
"nonoptional",
|
|
26
|
-
"success",
|
|
27
|
-
"readonly",
|
|
28
|
-
"promise"
|
|
29
|
-
]);
|
|
30
|
-
var readId = /* @__PURE__ */ __name((schema) => {
|
|
31
|
-
const meta = z.globalRegistry.get(schema);
|
|
32
|
-
if (meta === void 0) {
|
|
33
|
-
return void 0;
|
|
34
|
-
}
|
|
35
|
-
const id = meta.id;
|
|
36
|
-
return typeof id === "string" ? id : void 0;
|
|
37
|
-
}, "readId");
|
|
38
|
-
var resolveLazyTarget = /* @__PURE__ */ __name((getter) => {
|
|
39
|
-
try {
|
|
40
|
-
return [
|
|
41
|
-
getter()
|
|
42
|
-
];
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error instanceof ReferenceError) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
}, "resolveLazyTarget");
|
|
50
|
-
var collectChildren = /* @__PURE__ */ __name((schema) => {
|
|
51
|
-
const def = schema._zod.def;
|
|
52
|
-
if (def.type === "object") {
|
|
53
|
-
const out = [];
|
|
54
|
-
const shape = def.shape;
|
|
55
|
-
if (shape !== void 0) {
|
|
56
|
-
for (const value of Object.values(shape)) {
|
|
57
|
-
out.push(value);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (def.catchall !== void 0) {
|
|
61
|
-
out.push(def.catchall);
|
|
62
|
-
}
|
|
63
|
-
return out;
|
|
64
|
-
}
|
|
65
|
-
if (def.type === "array") {
|
|
66
|
-
return [
|
|
67
|
-
def.element
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
if (def.type === "union") {
|
|
71
|
-
return def.options.map((opt) => opt);
|
|
72
|
-
}
|
|
73
|
-
if (def.type === "intersection") {
|
|
74
|
-
return [
|
|
75
|
-
def.left,
|
|
76
|
-
def.right
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
if (def.type === "tuple") {
|
|
80
|
-
const out = def.items.map((it) => it);
|
|
81
|
-
if (def.rest !== null) {
|
|
82
|
-
out.push(def.rest);
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
if (def.type === "record" || def.type === "map") {
|
|
87
|
-
return [
|
|
88
|
-
def.keyType,
|
|
89
|
-
def.valueType
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
if (def.type === "set") {
|
|
93
|
-
return [
|
|
94
|
-
def.valueType
|
|
95
|
-
];
|
|
96
|
-
}
|
|
97
|
-
if (def.type === "pipe") {
|
|
98
|
-
return [
|
|
99
|
-
def.in,
|
|
100
|
-
def.out
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
if (def.type === "lazy") {
|
|
104
|
-
return resolveLazyTarget(() => def.getter());
|
|
105
|
-
}
|
|
106
|
-
if (INNER_TYPE_WRAPPERS.has(def.type)) {
|
|
107
|
-
return [
|
|
108
|
-
def.innerType
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
return [];
|
|
112
|
-
}, "collectChildren");
|
|
113
|
-
var discoverDependents = /* @__PURE__ */ __name((schema) => {
|
|
114
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
115
|
-
const out = [];
|
|
116
|
-
const stack = [
|
|
117
|
-
schema
|
|
118
|
-
];
|
|
119
|
-
while (stack.length > 0) {
|
|
120
|
-
const current = stack.pop();
|
|
121
|
-
if (visited.has(current)) {
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
visited.add(current);
|
|
125
|
-
for (const child of collectChildren(current)) {
|
|
126
|
-
if (child === void 0 || visited.has(child)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const id = readId(child);
|
|
130
|
-
if (id !== void 0) {
|
|
131
|
-
out.push([
|
|
132
|
-
child,
|
|
133
|
-
id
|
|
134
|
-
]);
|
|
135
|
-
}
|
|
136
|
-
stack.push(child);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return out;
|
|
140
|
-
}, "discoverDependents");
|
|
141
|
-
|
|
142
|
-
// src/schema/registry.ts
|
|
143
|
-
var createRegistry = /* @__PURE__ */ __name(() => {
|
|
144
|
-
const seen = /* @__PURE__ */ new Map();
|
|
145
|
-
const forceExposed = /* @__PURE__ */ new Set();
|
|
146
|
-
const anonymous = /* @__PURE__ */ new Set();
|
|
147
|
-
const pendingRoots = [];
|
|
148
|
-
const recordOnce = /* @__PURE__ */ __name((schema, id) => {
|
|
149
|
-
let set = seen.get(id);
|
|
150
|
-
if (set === void 0) {
|
|
151
|
-
set = /* @__PURE__ */ new Set();
|
|
152
|
-
seen.set(id, set);
|
|
153
|
-
}
|
|
154
|
-
if (set.has(schema)) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
set.add(schema);
|
|
158
|
-
return true;
|
|
159
|
-
}, "recordOnce");
|
|
160
|
-
const flushPendingDiscovery = /* @__PURE__ */ __name(() => {
|
|
161
|
-
for (const root of pendingRoots.splice(0)) {
|
|
162
|
-
for (const [child, childId] of discoverDependents(root)) {
|
|
163
|
-
recordOnce(child, childId);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}, "flushPendingDiscovery");
|
|
167
|
-
return {
|
|
168
|
-
zodRegistry: z.globalRegistry,
|
|
169
|
-
register: /* @__PURE__ */ __name((schema, id, flags) => {
|
|
170
|
-
if (flags?.expose === true) {
|
|
171
|
-
forceExposed.add(id);
|
|
172
|
-
}
|
|
173
|
-
if (flags?.anonymous === true) {
|
|
174
|
-
anonymous.add(id);
|
|
175
|
-
}
|
|
176
|
-
if (z.globalRegistry.has(schema)) {
|
|
177
|
-
const existing = z.globalRegistry.get(schema);
|
|
178
|
-
if (existing?.id !== id) {
|
|
179
|
-
z.globalRegistry.add(schema, {
|
|
180
|
-
...existing ?? {},
|
|
181
|
-
id
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
z.globalRegistry.add(schema, {
|
|
186
|
-
id
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (!recordOnce(schema, id)) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
pendingRoots.push(schema);
|
|
193
|
-
}, "register"),
|
|
194
|
-
hasCollision: /* @__PURE__ */ __name((id) => {
|
|
195
|
-
flushPendingDiscovery();
|
|
196
|
-
const set = seen.get(id);
|
|
197
|
-
return set !== void 0 && set.size > 1;
|
|
198
|
-
}, "hasCollision"),
|
|
199
|
-
getCollisions: /* @__PURE__ */ __name(() => {
|
|
200
|
-
flushPendingDiscovery();
|
|
201
|
-
const out = /* @__PURE__ */ new Map();
|
|
202
|
-
for (const [id, set] of seen) {
|
|
203
|
-
if (set.size <= 1) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
out.set(id, set);
|
|
207
|
-
}
|
|
208
|
-
return out;
|
|
209
|
-
}, "getCollisions"),
|
|
210
|
-
ids: /* @__PURE__ */ __name(() => {
|
|
211
|
-
flushPendingDiscovery();
|
|
212
|
-
return [
|
|
213
|
-
...seen.keys()
|
|
214
|
-
];
|
|
215
|
-
}, "ids"),
|
|
216
|
-
forceExposedIds: /* @__PURE__ */ __name(() => [
|
|
217
|
-
...forceExposed
|
|
218
|
-
], "forceExposedIds"),
|
|
219
|
-
anonymousIds: /* @__PURE__ */ __name(() => [
|
|
220
|
-
...anonymous
|
|
221
|
-
], "anonymousIds")
|
|
222
|
-
};
|
|
223
|
-
}, "createRegistry");
|
|
224
|
-
var defaultRegistry = createRegistry();
|
|
225
|
-
var registerSchema = /* @__PURE__ */ __name((schema, registry = defaultRegistry, options) => {
|
|
226
|
-
const flags = {
|
|
227
|
-
expose: options?.expose,
|
|
228
|
-
anonymous: options?.anonymous
|
|
229
|
-
};
|
|
230
|
-
const explicit = options?.id;
|
|
231
|
-
if (typeof explicit === "string" && explicit !== "") {
|
|
232
|
-
registry.register(schema, explicit, flags);
|
|
233
|
-
return explicit;
|
|
234
|
-
}
|
|
235
|
-
const meta = registry.zodRegistry.get(schema);
|
|
236
|
-
const metaId = meta === void 0 ? void 0 : meta.id;
|
|
237
|
-
if (typeof metaId !== "string" || metaId === "") {
|
|
238
|
-
return void 0;
|
|
239
|
-
}
|
|
240
|
-
registry.register(schema, metaId, flags);
|
|
241
|
-
return metaId;
|
|
242
|
-
}, "registerSchema");
|
|
243
|
-
|
|
244
|
-
// src/schema/composition.ts
|
|
245
|
-
var lineageMap = /* @__PURE__ */ new WeakMap();
|
|
246
|
-
var propsMap = /* @__PURE__ */ new WeakMap();
|
|
247
|
-
var OPTIONAL_WRAPPER_TYPES = /* @__PURE__ */ new Set([
|
|
248
|
-
"optional",
|
|
249
|
-
"default"
|
|
250
|
-
]);
|
|
251
|
-
var isOptionalProp = /* @__PURE__ */ __name((propSchema) => OPTIONAL_WRAPPER_TYPES.has(propSchema._zod.def.type), "isOptionalProp");
|
|
252
|
-
var computeShapeKeys = /* @__PURE__ */ __name((schema) => {
|
|
253
|
-
const { shape } = schema;
|
|
254
|
-
const properties = Object.keys(shape);
|
|
255
|
-
const required = properties.filter((key) => {
|
|
256
|
-
const propSchema = shape[key];
|
|
257
|
-
return propSchema !== void 0 && !isOptionalProp(propSchema);
|
|
258
|
-
});
|
|
259
|
-
return {
|
|
260
|
-
properties,
|
|
261
|
-
required
|
|
262
|
-
};
|
|
263
|
-
}, "computeShapeKeys");
|
|
264
|
-
var computeOverriddenKeys = /* @__PURE__ */ __name((parent, child) => {
|
|
265
|
-
const overriddenKeys = /* @__PURE__ */ new Set();
|
|
266
|
-
for (const key of Object.keys(child.shape)) {
|
|
267
|
-
const parentProp = parent.shape[key];
|
|
268
|
-
if (parentProp !== void 0 && parentProp !== child.shape[key]) {
|
|
269
|
-
overriddenKeys.add(key);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return overriddenKeys;
|
|
273
|
-
}, "computeOverriddenKeys");
|
|
274
|
-
var extend = /* @__PURE__ */ __name((parent, build) => {
|
|
275
|
-
const result = build(parent);
|
|
276
|
-
lineageMap.set(result, {
|
|
277
|
-
op: "extend",
|
|
278
|
-
parent,
|
|
279
|
-
overriddenKeys: computeOverriddenKeys(parent, result)
|
|
280
|
-
});
|
|
281
|
-
if (!propsMap.has(parent)) {
|
|
282
|
-
propsMap.set(parent, computeShapeKeys(parent));
|
|
283
|
-
}
|
|
284
|
-
registerSchema(parent);
|
|
285
|
-
registerSchema(result);
|
|
286
|
-
return result;
|
|
287
|
-
}, "extend");
|
|
288
|
-
var getLineage = /* @__PURE__ */ __name((schema) => lineageMap.get(schema), "getLineage");
|
|
289
|
-
var DEFAULT_BUILD_REF = /* @__PURE__ */ __name((id) => `${DEFS_PREFIX}${id}`, "DEFAULT_BUILD_REF");
|
|
290
|
-
var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
|
|
291
|
-
const { buildRef, registry } = opts;
|
|
292
|
-
return (ctx) => {
|
|
293
|
-
const { jsonSchema, zodSchema } = ctx;
|
|
294
|
-
const entry = lineageMap.get(zodSchema);
|
|
295
|
-
if (entry === void 0) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const parentCache = propsMap.get(entry.parent);
|
|
299
|
-
if (parentCache === void 0) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const parentId = registry.zodRegistry.get(entry.parent)?.id;
|
|
303
|
-
if (parentId === void 0) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
registerSchema(entry.parent, registry);
|
|
307
|
-
const childProps = jsonSchema.properties ?? {};
|
|
308
|
-
const childRequired = jsonSchema.required ?? [];
|
|
309
|
-
const parentPropSet = new Set(parentCache.properties);
|
|
310
|
-
const parentReqSet = new Set(parentCache.required);
|
|
311
|
-
const deltaProps = {};
|
|
312
|
-
for (const [key, value] of Object.entries(childProps)) {
|
|
313
|
-
if (parentPropSet.has(key) && !entry.overriddenKeys.has(key)) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
deltaProps[key] = value;
|
|
317
|
-
}
|
|
318
|
-
const deltaRequired = childRequired.filter((key) => !parentReqSet.has(key) || entry.overriddenKeys.has(key));
|
|
319
|
-
const delta = {
|
|
320
|
-
type: "object",
|
|
321
|
-
properties: deltaProps
|
|
322
|
-
};
|
|
323
|
-
if (deltaRequired.length > 0) {
|
|
324
|
-
delta.required = deltaRequired;
|
|
325
|
-
}
|
|
326
|
-
delete jsonSchema.properties;
|
|
327
|
-
delete jsonSchema.required;
|
|
328
|
-
delete jsonSchema.additionalProperties;
|
|
329
|
-
jsonSchema.type = "object";
|
|
330
|
-
jsonSchema.allOf = [
|
|
331
|
-
{
|
|
332
|
-
$ref: buildRef(parentId)
|
|
333
|
-
},
|
|
334
|
-
delta
|
|
335
|
-
];
|
|
336
|
-
jsonSchema.unevaluatedProperties = false;
|
|
337
|
-
};
|
|
338
|
-
}, "createCompositionOverride");
|
|
339
|
-
|
|
340
|
-
// src/schema/custom-override.ts
|
|
341
|
-
var customOverrideMap = /* @__PURE__ */ new WeakMap();
|
|
342
|
-
var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
|
|
343
|
-
var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
|
|
344
|
-
const overrideSchema = isWrapper(arg) ? {
|
|
345
|
-
...arg
|
|
346
|
-
} : {
|
|
347
|
-
input: arg,
|
|
348
|
-
output: arg
|
|
349
|
-
};
|
|
350
|
-
const schemaDescription = schema.description;
|
|
351
|
-
if (typeof schemaDescription === "string") {
|
|
352
|
-
overrideSchema.description = schemaDescription;
|
|
353
|
-
}
|
|
354
|
-
customOverrideMap.set(schema, overrideSchema);
|
|
355
|
-
return schema;
|
|
356
|
-
}, "overrideJSONSchema");
|
|
357
|
-
var peekRegistration = /* @__PURE__ */ __name((schema) => customOverrideMap.get(schema), "peekRegistration");
|
|
358
|
-
var createCustomOverride = /* @__PURE__ */ __name((io) => {
|
|
359
|
-
return ({ zodSchema, jsonSchema }) => {
|
|
360
|
-
const record = customOverrideMap.get(zodSchema);
|
|
361
|
-
if (record === void 0) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
const fragment = record[io];
|
|
365
|
-
if (fragment === void 0) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
for (const key of Object.keys(jsonSchema)) {
|
|
369
|
-
Reflect.deleteProperty(jsonSchema, key);
|
|
370
|
-
}
|
|
371
|
-
Object.assign(jsonSchema, fragment);
|
|
372
|
-
if (fragment.description === void 0 && record.description !== void 0) {
|
|
373
|
-
jsonSchema.description = record.description;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
}, "createCustomOverride");
|
|
377
|
-
|
|
378
|
-
// src/schema/errors.ts
|
|
379
|
-
var ZodNestError = class extends Error {
|
|
380
|
-
static {
|
|
381
|
-
__name(this, "ZodNestError");
|
|
382
|
-
}
|
|
383
|
-
constructor(message) {
|
|
384
|
-
super(message);
|
|
385
|
-
this.name = "ZodNestError";
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
var ZodNestUnrepresentableError = class extends ZodNestError {
|
|
389
|
-
static {
|
|
390
|
-
__name(this, "ZodNestUnrepresentableError");
|
|
391
|
-
}
|
|
392
|
-
path;
|
|
393
|
-
zodType;
|
|
394
|
-
constructor(path, zodType) {
|
|
395
|
-
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.`);
|
|
396
|
-
this.name = "ZodNestUnrepresentableError";
|
|
397
|
-
this.path = path;
|
|
398
|
-
this.zodType = zodType;
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
var formatPath = /* @__PURE__ */ __name((path) => {
|
|
402
|
-
if (path.length === 0) {
|
|
403
|
-
return "<root>";
|
|
404
|
-
}
|
|
405
|
-
return "/" + path.map(String).join("/");
|
|
406
|
-
}, "formatPath");
|
|
407
|
-
|
|
408
|
-
// src/schema/override.ts
|
|
409
|
-
var primitiveOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
410
|
-
const type = zodSchema._zod.def.type;
|
|
411
|
-
if (type === "bigint") {
|
|
412
|
-
jsonSchema.type = "integer";
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
if (type === "date") {
|
|
416
|
-
jsonSchema.type = "string";
|
|
417
|
-
jsonSchema.format = "date-time";
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
}, "primitiveOverride");
|
|
421
|
-
var combine = /* @__PURE__ */ __name((...overrides) => {
|
|
422
|
-
const list = [];
|
|
423
|
-
for (const candidate of overrides) {
|
|
424
|
-
if (typeof candidate !== "function") {
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
list.push(candidate);
|
|
428
|
-
}
|
|
429
|
-
return (ctx) => {
|
|
430
|
-
for (const o of list) {
|
|
431
|
-
o(ctx);
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
}, "combine");
|
|
435
|
-
|
|
436
|
-
// src/schema/post-process.ts
|
|
437
|
-
var rewriteRefs = /* @__PURE__ */ __name((node, rootRef) => {
|
|
438
|
-
if (Array.isArray(node)) {
|
|
439
|
-
for (const item of node) {
|
|
440
|
-
rewriteRefs(item, rootRef);
|
|
441
|
-
}
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
if (node === null || typeof node !== "object") {
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
const obj = node;
|
|
448
|
-
const ref = obj.$ref;
|
|
449
|
-
if (typeof ref === "string" && ref.startsWith(DEFS_PREFIX)) {
|
|
450
|
-
obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);
|
|
451
|
-
} else if (ref === "#" && rootRef !== void 0) {
|
|
452
|
-
obj.$ref = rootRef;
|
|
453
|
-
}
|
|
454
|
-
for (const value of Object.values(obj)) {
|
|
455
|
-
rewriteRefs(value, rootRef);
|
|
456
|
-
}
|
|
457
|
-
}, "rewriteRefs");
|
|
458
|
-
var refsIn = /* @__PURE__ */ __name(function* (node) {
|
|
459
|
-
if (Array.isArray(node)) {
|
|
460
|
-
for (const item of node) {
|
|
461
|
-
yield* refsIn(item);
|
|
462
|
-
}
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
if (node === null || typeof node !== "object") {
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
const obj = node;
|
|
469
|
-
if (typeof obj.$ref === "string") {
|
|
470
|
-
yield obj.$ref;
|
|
471
|
-
}
|
|
472
|
-
for (const value of Object.values(obj)) {
|
|
473
|
-
yield* refsIn(value);
|
|
474
|
-
}
|
|
475
|
-
}, "refsIn");
|
|
476
|
-
var rootDefId = /* @__PURE__ */ __name((raw) => {
|
|
477
|
-
const ref = raw.$ref;
|
|
478
|
-
if (typeof ref !== "string" || !ref.startsWith(DEFS_PREFIX)) {
|
|
479
|
-
return void 0;
|
|
480
|
-
}
|
|
481
|
-
return ref.slice(DEFS_PREFIX.length);
|
|
482
|
-
}, "rootDefId");
|
|
483
|
-
var isReferenced = /* @__PURE__ */ __name((defs, id) => {
|
|
484
|
-
const ownRef = `${DEFS_PREFIX}${id}`;
|
|
485
|
-
for (const ref of refsIn(defs)) {
|
|
486
|
-
if (ref === "#" || ref === ownRef) {
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return false;
|
|
491
|
-
}, "isReferenced");
|
|
492
|
-
var referencesRoot = /* @__PURE__ */ __name((raw) => {
|
|
493
|
-
for (const ref of refsIn(raw)) {
|
|
494
|
-
if (ref === "#") {
|
|
495
|
-
return true;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return false;
|
|
499
|
-
}, "referencesRoot");
|
|
500
|
-
var stripEnvelope = /* @__PURE__ */ __name((raw) => {
|
|
501
|
-
const root = {
|
|
502
|
-
...raw
|
|
503
|
-
};
|
|
504
|
-
delete root.$schema;
|
|
505
|
-
delete root.$defs;
|
|
506
|
-
return root;
|
|
507
|
-
}, "stripEnvelope");
|
|
508
|
-
var resolveRoot = /* @__PURE__ */ __name((raw, refs, options) => {
|
|
509
|
-
const liftedId = rootDefId(raw);
|
|
510
|
-
if (liftedId !== void 0) {
|
|
511
|
-
const body = refs.get(liftedId);
|
|
512
|
-
if (body !== void 0 && !isReferenced(raw.$defs, liftedId)) {
|
|
513
|
-
refs.delete(liftedId);
|
|
514
|
-
return {
|
|
515
|
-
schema: body,
|
|
516
|
-
rootRef: void 0
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
return {
|
|
520
|
-
schema: stripEnvelope(raw),
|
|
521
|
-
rootRef: `${COMPONENTS_SCHEMAS_PREFIX}${liftedId}`
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
const root = stripEnvelope(raw);
|
|
525
|
-
if (!referencesRoot(raw)) {
|
|
526
|
-
return {
|
|
527
|
-
schema: root,
|
|
528
|
-
rootRef: void 0
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
const rootId = options?.rootId;
|
|
532
|
-
if (rootId === void 0) {
|
|
533
|
-
if (options?.strict ?? true) {
|
|
534
|
-
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.');
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
schema: root,
|
|
538
|
-
rootRef: void 0
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
refs.set(rootId, root);
|
|
542
|
-
const rootRef = `${COMPONENTS_SCHEMAS_PREFIX}${rootId}`;
|
|
543
|
-
return {
|
|
544
|
-
schema: {
|
|
545
|
-
$ref: rootRef
|
|
546
|
-
},
|
|
547
|
-
rootRef
|
|
548
|
-
};
|
|
549
|
-
}, "resolveRoot");
|
|
550
|
-
var postProcess = /* @__PURE__ */ __name((raw, options) => {
|
|
551
|
-
const refs = /* @__PURE__ */ new Map();
|
|
552
|
-
const rawDefs = raw.$defs;
|
|
553
|
-
if (rawDefs !== void 0) {
|
|
554
|
-
for (const [id, body] of Object.entries(rawDefs)) {
|
|
555
|
-
refs.set(id, body);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
const { schema, rootRef } = resolveRoot(raw, refs, options);
|
|
559
|
-
rewriteRefs(schema, rootRef);
|
|
560
|
-
for (const body of refs.values()) {
|
|
561
|
-
rewriteRefs(body, rootRef);
|
|
562
|
-
}
|
|
563
|
-
return {
|
|
564
|
-
schema,
|
|
565
|
-
refs
|
|
566
|
-
};
|
|
567
|
-
}, "postProcess");
|
|
568
|
-
|
|
569
|
-
// src/schema/engine.ts
|
|
570
|
-
var STRICT_REQUIRES_OVERRIDE = /* @__PURE__ */ new Set([
|
|
571
|
-
"bigint",
|
|
572
|
-
"date",
|
|
573
|
-
"symbol",
|
|
574
|
-
"undefined",
|
|
575
|
-
"void",
|
|
576
|
-
"map",
|
|
577
|
-
"set",
|
|
578
|
-
"transform",
|
|
579
|
-
"nan",
|
|
580
|
-
"custom"
|
|
581
|
-
]);
|
|
582
|
-
var ANNOTATION_ONLY_KEYS = /* @__PURE__ */ new Set([
|
|
583
|
-
"title",
|
|
584
|
-
"description",
|
|
585
|
-
"deprecated",
|
|
586
|
-
"examples",
|
|
587
|
-
"default",
|
|
588
|
-
"readOnly",
|
|
589
|
-
"writeOnly",
|
|
590
|
-
"$id",
|
|
591
|
-
"$schema",
|
|
592
|
-
"$comment",
|
|
593
|
-
"id"
|
|
594
|
-
]);
|
|
595
|
-
var isStrictlyUnrepresentable = /* @__PURE__ */ __name((jsonSchema, zodSchema) => {
|
|
596
|
-
if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
return Object.keys(jsonSchema).every((key) => ANNOTATION_ONLY_KEYS.has(key));
|
|
600
|
-
}, "isStrictlyUnrepresentable");
|
|
601
|
-
var markPipeCoverage = /* @__PURE__ */ __name((schema, io, covered) => {
|
|
602
|
-
const def = schema._zod.def;
|
|
603
|
-
if (def.type !== "pipe" || def.in === void 0 || def.out === void 0) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
const target = io === "output" ? def.out : def.in._zod.traits.has("$ZodTransform") ? def.out : def.in;
|
|
607
|
-
if (covered.has(target)) {
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
covered.add(target);
|
|
611
|
-
markPipeCoverage(target, io, covered);
|
|
612
|
-
}, "markPipeCoverage");
|
|
613
|
-
var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
|
|
614
|
-
const strict = params.strict ?? true;
|
|
615
|
-
const compositionOverride = createCompositionOverride({
|
|
616
|
-
buildRef: params.uri ?? DEFAULT_BUILD_REF,
|
|
617
|
-
registry: params.registry
|
|
618
|
-
});
|
|
619
|
-
const customOverride = createCustomOverride(params.io);
|
|
620
|
-
const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
|
|
621
|
-
const unrepresentableHits = [];
|
|
622
|
-
const coveredByPipe = /* @__PURE__ */ new WeakSet();
|
|
623
|
-
const wrapped = /* @__PURE__ */ __name((ctx) => {
|
|
624
|
-
merged(ctx);
|
|
625
|
-
if (ctx.zodSchema._zod.def.type === "pipe") {
|
|
626
|
-
const record = peekRegistration(ctx.zodSchema);
|
|
627
|
-
if (record !== void 0 && record[params.io] !== void 0) {
|
|
628
|
-
markPipeCoverage(ctx.zodSchema, params.io, coveredByPipe);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
unrepresentableHits.push({
|
|
635
|
-
path: [
|
|
636
|
-
...ctx.path
|
|
637
|
-
],
|
|
638
|
-
zodType: ctx.zodSchema._zod.def.type,
|
|
639
|
-
zodSchema: ctx.zodSchema
|
|
640
|
-
});
|
|
641
|
-
}, "wrapped");
|
|
642
|
-
const options = {
|
|
643
|
-
target: "draft-2020-12",
|
|
644
|
-
io: params.io,
|
|
645
|
-
unrepresentable: "any",
|
|
646
|
-
metadata: params.registry.zodRegistry,
|
|
647
|
-
override: wrapped,
|
|
648
|
-
cycles: "ref",
|
|
649
|
-
reused: params.reused
|
|
650
|
-
};
|
|
651
|
-
if (params.uri !== void 0) {
|
|
652
|
-
options.uri = params.uri;
|
|
653
|
-
}
|
|
654
|
-
return {
|
|
655
|
-
options,
|
|
656
|
-
consumeUnrepresentable: /* @__PURE__ */ __name(() => {
|
|
657
|
-
const firstHit = unrepresentableHits.find((hit) => !coveredByPipe.has(hit.zodSchema));
|
|
658
|
-
if (firstHit !== void 0) {
|
|
659
|
-
throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);
|
|
660
|
-
}
|
|
661
|
-
}, "consumeUnrepresentable")
|
|
662
|
-
};
|
|
663
|
-
}, "buildToJsonSchemaOptions");
|
|
664
|
-
var resolveRootId = /* @__PURE__ */ __name((schema, registry) => {
|
|
665
|
-
const id = registry.zodRegistry.get(schema)?.id;
|
|
666
|
-
return typeof id === "string" && id !== "" ? id : void 0;
|
|
667
|
-
}, "resolveRootId");
|
|
668
|
-
var toOpenApi = /* @__PURE__ */ __name((schema, opts) => {
|
|
669
|
-
const built = buildToJsonSchemaOptions({
|
|
670
|
-
registry: opts.registry,
|
|
671
|
-
io: opts.io,
|
|
672
|
-
override: opts.override,
|
|
673
|
-
strict: opts.strict,
|
|
674
|
-
reused: "inline"
|
|
675
|
-
});
|
|
676
|
-
const raw = z.toJSONSchema(schema, built.options);
|
|
677
|
-
built.consumeUnrepresentable();
|
|
678
|
-
const result = postProcess(raw, {
|
|
679
|
-
rootId: resolveRootId(schema, opts.registry),
|
|
680
|
-
strict: opts.strict
|
|
681
|
-
});
|
|
682
|
-
for (const [id] of opts.registry.getCollisions()) {
|
|
683
|
-
if (!result.refs.has(id)) {
|
|
684
|
-
continue;
|
|
685
|
-
}
|
|
686
|
-
result.refs.set(id, {
|
|
687
|
-
description: `ERROR: duplicate zod-nest id <${id}>`,
|
|
688
|
-
[ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
return result;
|
|
692
|
-
}, "toOpenApi");
|
|
693
|
-
|
|
694
14
|
// src/dto/marker.ts
|
|
695
15
|
var makeZodDtoMarker = /* @__PURE__ */ __name((dtoId, io) => ({
|
|
696
16
|
type: /* @__PURE__ */ __name(() => Object, "type"),
|
|
@@ -706,11 +26,8 @@ var isZodDtoMarker = /* @__PURE__ */ __name((value) => {
|
|
|
706
26
|
return value.__zodNestDto === true;
|
|
707
27
|
}, "isZodDtoMarker");
|
|
708
28
|
|
|
709
|
-
// src/dto/symbols.ts
|
|
710
|
-
var ZOD_DTO_SYMBOL = /* @__PURE__ */ Symbol.for("zod-nest.dto");
|
|
711
|
-
|
|
712
29
|
// src/dto/output-dto.ts
|
|
713
|
-
var outputCache = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
var outputCache = singleton("output-dto-cache", () => /* @__PURE__ */ new WeakMap());
|
|
714
31
|
var buildSiblingClass = /* @__PURE__ */ __name((parent, schema) => {
|
|
715
32
|
const SiblingClass = class {
|
|
716
33
|
static {
|
|
@@ -754,16 +71,18 @@ var resolveOutput = /* @__PURE__ */ __name((parent, schema) => {
|
|
|
754
71
|
}, "resolveOutput");
|
|
755
72
|
|
|
756
73
|
// src/dto/create-zod-dto.ts
|
|
757
|
-
var
|
|
758
|
-
|
|
74
|
+
var anonState = singleton("anon-dto-state", () => ({
|
|
75
|
+
counter: 0,
|
|
76
|
+
warned: false
|
|
77
|
+
}));
|
|
759
78
|
var resolveFallbackId = /* @__PURE__ */ __name((className) => {
|
|
760
79
|
if (className !== "" && className.length > 1) {
|
|
761
80
|
return className;
|
|
762
81
|
}
|
|
763
|
-
|
|
764
|
-
const fallback = `_AnonZodDto_${
|
|
765
|
-
if (!
|
|
766
|
-
|
|
82
|
+
anonState.counter += 1;
|
|
83
|
+
const fallback = `_AnonZodDto_${anonState.counter}`;
|
|
84
|
+
if (!anonState.warned) {
|
|
85
|
+
anonState.warned = true;
|
|
767
86
|
console.warn(`[zod-nest] Could not resolve a DTO id from class name (got "${className}"). Using "${fallback}". Set an explicit id via \`schema.meta({ id: 'Foo' })\` (preferred) or \`createZodDto(schema, { id: 'Foo' })\` \u2014 important under minification, where class names become single mangled characters.`);
|
|
768
87
|
}
|
|
769
88
|
return fallback;
|
|
@@ -817,8 +136,6 @@ var createZodDto = /* @__PURE__ */ __name((schema, options) => {
|
|
|
817
136
|
};
|
|
818
137
|
return ZodDtoBase;
|
|
819
138
|
}, "createZodDto");
|
|
820
|
-
var isZodDto = /* @__PURE__ */ __name((value) => typeof value === "function" && value[ZOD_DTO_SYMBOL] === true, "isZodDto");
|
|
821
|
-
var isZodSchema = /* @__PURE__ */ __name((value) => value instanceof z.ZodType, "isZodSchema");
|
|
822
139
|
var ZodSerializationException = class extends InternalServerErrorException {
|
|
823
140
|
static {
|
|
824
141
|
__name(this, "ZodSerializationException");
|
|
@@ -836,24 +153,6 @@ var ZodSerializationException = class extends InternalServerErrorException {
|
|
|
836
153
|
this.executionContext = executionContext;
|
|
837
154
|
}
|
|
838
155
|
};
|
|
839
|
-
var ZodValidationException = class extends BadRequestException {
|
|
840
|
-
static {
|
|
841
|
-
__name(this, "ZodValidationException");
|
|
842
|
-
}
|
|
843
|
-
zodError;
|
|
844
|
-
argMetadata;
|
|
845
|
-
constructor(zodError, argMetadata) {
|
|
846
|
-
super({
|
|
847
|
-
statusCode: HttpStatus.BAD_REQUEST,
|
|
848
|
-
message: "Validation failed",
|
|
849
|
-
errors: z.treeifyError(zodError)
|
|
850
|
-
}, {
|
|
851
|
-
cause: zodError
|
|
852
|
-
});
|
|
853
|
-
this.zodError = zodError;
|
|
854
|
-
this.argMetadata = argMetadata;
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
156
|
var DEFAULT_LOGGER_CONTEXT = "ZodValidation";
|
|
858
157
|
var REDACTED = "[REDACTED]";
|
|
859
158
|
var PREVIEW_RESERVE_BYTES = 100;
|
|
@@ -1250,24 +549,8 @@ var appendResponseVariant = /* @__PURE__ */ __name((handler, variant) => {
|
|
|
1250
549
|
], handler);
|
|
1251
550
|
}, "appendResponseVariant");
|
|
1252
551
|
|
|
1253
|
-
// src/schema/anon-id.ts
|
|
1254
|
-
var ANON_RESPONSE_PREFIX = "_AnonResponseSchema_";
|
|
1255
|
-
var ANON_BODY_PREFIX = "_AnonBodySchema_";
|
|
1256
|
-
var anonIdCache = /* @__PURE__ */ new WeakMap();
|
|
1257
|
-
var counter = 0;
|
|
1258
|
-
var resolveAnonId = /* @__PURE__ */ __name((schema, prefix) => {
|
|
1259
|
-
const cached = anonIdCache.get(schema);
|
|
1260
|
-
if (cached !== void 0) {
|
|
1261
|
-
return cached;
|
|
1262
|
-
}
|
|
1263
|
-
counter += 1;
|
|
1264
|
-
const id = `${prefix}${counter}`;
|
|
1265
|
-
anonIdCache.set(schema, id);
|
|
1266
|
-
return id;
|
|
1267
|
-
}, "resolveAnonId");
|
|
1268
|
-
|
|
1269
552
|
// src/response/normalize-type.ts
|
|
1270
|
-
var responseDtoCache = /* @__PURE__ */ new WeakMap();
|
|
553
|
+
var responseDtoCache = singleton("response-dto-cache", () => /* @__PURE__ */ new WeakMap());
|
|
1271
554
|
var schemaToOutputDto = /* @__PURE__ */ __name((schema) => {
|
|
1272
555
|
const cached = responseDtoCache.get(schema);
|
|
1273
556
|
if (cached !== void 0) {
|
|
@@ -1475,166 +758,6 @@ var ZodResponse = /* @__PURE__ */ __name((opts) => {
|
|
|
1475
758
|
});
|
|
1476
759
|
};
|
|
1477
760
|
}, "ZodResponse");
|
|
1478
|
-
|
|
1479
|
-
// src/decorators/internal/zod-schema-ref.ts
|
|
1480
|
-
function resolveSchemaRef(schema, options) {
|
|
1481
|
-
const registry = options?.registry ?? defaultRegistry;
|
|
1482
|
-
const id = registerSchema(schema, registry, {
|
|
1483
|
-
id: options?.id
|
|
1484
|
-
});
|
|
1485
|
-
if (id !== void 0) {
|
|
1486
|
-
return {
|
|
1487
|
-
kind: "ref",
|
|
1488
|
-
ref: {
|
|
1489
|
-
$ref: `${COMPONENTS_SCHEMAS_PREFIX}${id}`
|
|
1490
|
-
}
|
|
1491
|
-
};
|
|
1492
|
-
}
|
|
1493
|
-
if (options?.deferAnonInline === true) {
|
|
1494
|
-
const anonId = resolveAnonId(schema, ANON_BODY_PREFIX);
|
|
1495
|
-
registerSchema(schema, registry, {
|
|
1496
|
-
id: anonId,
|
|
1497
|
-
anonymous: true
|
|
1498
|
-
});
|
|
1499
|
-
return {
|
|
1500
|
-
kind: "ref",
|
|
1501
|
-
ref: {
|
|
1502
|
-
$ref: `${COMPONENTS_SCHEMAS_PREFIX}${anonId}`
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
for (const [child, childId] of discoverDependents(schema)) {
|
|
1507
|
-
registry.register(child, childId);
|
|
1508
|
-
}
|
|
1509
|
-
const { schema: body } = toOpenApi(schema, {
|
|
1510
|
-
io: "input",
|
|
1511
|
-
registry
|
|
1512
|
-
});
|
|
1513
|
-
return {
|
|
1514
|
-
kind: "inline",
|
|
1515
|
-
schema: body
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
__name(resolveSchemaRef, "resolveSchemaRef");
|
|
1519
|
-
|
|
1520
|
-
// src/decorators/internal/zod-param-expand.ts
|
|
1521
|
-
var isZodObject = /* @__PURE__ */ __name((schema) => schema._zod.def.type === "object", "isZodObject");
|
|
1522
|
-
var expandObjectSchema = /* @__PURE__ */ __name((schema, options) => {
|
|
1523
|
-
if (!isZodObject(schema)) {
|
|
1524
|
-
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.`);
|
|
1525
|
-
}
|
|
1526
|
-
const registry = options.registry ?? defaultRegistry;
|
|
1527
|
-
registerSchema(schema, registry, {
|
|
1528
|
-
id: options.id
|
|
1529
|
-
});
|
|
1530
|
-
const result = [];
|
|
1531
|
-
for (const [name, propSchema] of Object.entries(schema.shape)) {
|
|
1532
|
-
const resolution = resolveSchemaRef(propSchema, {
|
|
1533
|
-
registry
|
|
1534
|
-
});
|
|
1535
|
-
const required = options.forceRequired === true || !isOptionalProp(propSchema);
|
|
1536
|
-
result.push({
|
|
1537
|
-
name,
|
|
1538
|
-
required,
|
|
1539
|
-
resolution
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1542
|
-
return result;
|
|
1543
|
-
}, "expandObjectSchema");
|
|
1544
|
-
var paramSchemaBody = /* @__PURE__ */ __name((resolution) => resolution.kind === "ref" ? resolution.ref : resolution.schema, "paramSchemaBody");
|
|
1545
|
-
|
|
1546
|
-
// src/decorators/internal/flatten-intersection.ts
|
|
1547
|
-
var intersectionArms = /* @__PURE__ */ __name((schema) => {
|
|
1548
|
-
if (schema._zod.def.type !== "intersection") {
|
|
1549
|
-
return null;
|
|
1550
|
-
}
|
|
1551
|
-
const def = schema._zod.def;
|
|
1552
|
-
return {
|
|
1553
|
-
left: def.left,
|
|
1554
|
-
right: def.right
|
|
1555
|
-
};
|
|
1556
|
-
}, "intersectionArms");
|
|
1557
|
-
var unionOptions = /* @__PURE__ */ __name((schema) => {
|
|
1558
|
-
if (schema._zod.def.type !== "union") {
|
|
1559
|
-
return null;
|
|
1560
|
-
}
|
|
1561
|
-
const def = schema._zod.def;
|
|
1562
|
-
return def.options;
|
|
1563
|
-
}, "unionOptions");
|
|
1564
|
-
var collectObjectShapes = /* @__PURE__ */ __name((schema) => {
|
|
1565
|
-
if (isZodObject(schema)) {
|
|
1566
|
-
return {
|
|
1567
|
-
shapes: [
|
|
1568
|
-
schema.shape
|
|
1569
|
-
],
|
|
1570
|
-
unionCrossed: false
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
const options = unionOptions(schema);
|
|
1574
|
-
if (options !== null) {
|
|
1575
|
-
const allShapes = [];
|
|
1576
|
-
for (const variant of options) {
|
|
1577
|
-
const variantResult = collectObjectShapes(variant);
|
|
1578
|
-
if (variantResult === null) {
|
|
1579
|
-
return null;
|
|
1580
|
-
}
|
|
1581
|
-
allShapes.push(...variantResult.shapes);
|
|
1582
|
-
}
|
|
1583
|
-
return {
|
|
1584
|
-
shapes: allShapes,
|
|
1585
|
-
unionCrossed: true
|
|
1586
|
-
};
|
|
1587
|
-
}
|
|
1588
|
-
const arms = intersectionArms(schema);
|
|
1589
|
-
if (arms === null) {
|
|
1590
|
-
return null;
|
|
1591
|
-
}
|
|
1592
|
-
const left = collectObjectShapes(arms.left);
|
|
1593
|
-
if (left === null) {
|
|
1594
|
-
return null;
|
|
1595
|
-
}
|
|
1596
|
-
const right = collectObjectShapes(arms.right);
|
|
1597
|
-
if (right === null) {
|
|
1598
|
-
return null;
|
|
1599
|
-
}
|
|
1600
|
-
return {
|
|
1601
|
-
shapes: [
|
|
1602
|
-
...left.shapes,
|
|
1603
|
-
...right.shapes
|
|
1604
|
-
],
|
|
1605
|
-
unionCrossed: left.unionCrossed || right.unionCrossed
|
|
1606
|
-
};
|
|
1607
|
-
}, "collectObjectShapes");
|
|
1608
|
-
var flattenObjectIntersection = /* @__PURE__ */ __name((schema, registry, decoratorName) => {
|
|
1609
|
-
const collected = collectObjectShapes(schema);
|
|
1610
|
-
if (collected === null) {
|
|
1611
|
-
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.`);
|
|
1612
|
-
}
|
|
1613
|
-
const mergedShape = {};
|
|
1614
|
-
for (const shape of collected.shapes) {
|
|
1615
|
-
Object.assign(mergedShape, shape);
|
|
1616
|
-
}
|
|
1617
|
-
if (collected.unionCrossed) {
|
|
1618
|
-
for (const key of Object.keys(mergedShape)) {
|
|
1619
|
-
const value = mergedShape[key];
|
|
1620
|
-
if (value !== void 0) {
|
|
1621
|
-
mergedShape[key] = value.optional();
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
const merged = z.object(mergedShape);
|
|
1626
|
-
registerSchema(schema, registry);
|
|
1627
|
-
for (const [child, childId] of discoverDependents(schema)) {
|
|
1628
|
-
registry.register(child, childId);
|
|
1629
|
-
}
|
|
1630
|
-
const { schema: body } = toOpenApi(merged, {
|
|
1631
|
-
io: "input",
|
|
1632
|
-
registry
|
|
1633
|
-
});
|
|
1634
|
-
return body;
|
|
1635
|
-
}, "flattenObjectIntersection");
|
|
1636
|
-
|
|
1637
|
-
// src/decorators/zod-body.decorator.ts
|
|
1638
761
|
var ZodBody = /* @__PURE__ */ __name((schema, options) => {
|
|
1639
762
|
const apiBodySchema = resolveBodySchema(schema, options);
|
|
1640
763
|
return ApiBody({
|
|
@@ -2618,7 +1741,7 @@ var addRefTitles = /* @__PURE__ */ __name((node, titleById) => {
|
|
|
2618
1741
|
}, "addRefTitles");
|
|
2619
1742
|
|
|
2620
1743
|
// src/document/rewrite-refs.ts
|
|
2621
|
-
var
|
|
1744
|
+
var rewriteRefs = /* @__PURE__ */ __name((params) => {
|
|
2622
1745
|
const { doc, renames, divergentOutputIds } = params;
|
|
2623
1746
|
if (renames.size > 0) {
|
|
2624
1747
|
walkRefs(doc, (ref) => {
|
|
@@ -2752,7 +1875,7 @@ var applyZodNest = /* @__PURE__ */ __name((doc, opts = {}) => {
|
|
|
2752
1875
|
outputSchemas,
|
|
2753
1876
|
queryParamStyle: opts.queryParamStyle
|
|
2754
1877
|
});
|
|
2755
|
-
|
|
1878
|
+
rewriteRefs({
|
|
2756
1879
|
doc,
|
|
2757
1880
|
renames,
|
|
2758
1881
|
divergentOutputIds
|
|
@@ -2773,6 +1896,6 @@ var applyZodNest = /* @__PURE__ */ __name((doc, opts = {}) => {
|
|
|
2773
1896
|
return doc;
|
|
2774
1897
|
}, "applyZodNest");
|
|
2775
1898
|
|
|
2776
|
-
export {
|
|
1899
|
+
export { DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, DEFAULT_STREAM_CONTENT_TYPES, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, ZodBody, ZodCookies, ZodHeaders, ZodNestDocumentError, ZodNestModule, ZodQuery, ZodResponse, ZodSerializationException, ZodSerializerInterceptor, ZodValidationPipe, applyZodNest, createZodDto, defaultStatusFor, isZodDtoMarker, makeZodDtoMarker, resolveEffectiveStatus };
|
|
2777
1900
|
//# sourceMappingURL=index.mjs.map
|
|
2778
1901
|
//# sourceMappingURL=index.mjs.map
|