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