zod-nest 0.10.0 → 0.10.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/index.js +406 -257
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +407 -258
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -2,25 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
var common = require('@nestjs/common');
|
|
5
|
+
var core = require('@nestjs/core');
|
|
5
6
|
var rxjs = require('rxjs');
|
|
6
7
|
var operators = require('rxjs/operators');
|
|
7
8
|
var constants_js = require('@nestjs/common/constants.js');
|
|
8
|
-
var core = require('@nestjs/core');
|
|
9
9
|
var stringify = require('fast-json-stable-stringify');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
13
|
var stringify__default = /*#__PURE__*/_interopDefault(stringify);
|
|
14
14
|
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
18
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
19
|
-
if (decorator = decorators[i])
|
|
20
|
-
result = (decorator(result)) || result;
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
24
17
|
|
|
25
18
|
// src/schema/constants.ts
|
|
26
19
|
var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
@@ -32,28 +25,37 @@ var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
|
32
25
|
// src/schema/composition.ts
|
|
33
26
|
var lineageMap = /* @__PURE__ */ new WeakMap();
|
|
34
27
|
var propsMap = /* @__PURE__ */ new WeakMap();
|
|
35
|
-
var OPTIONAL_WRAPPER_TYPES = /* @__PURE__ */ new Set([
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
var OPTIONAL_WRAPPER_TYPES = /* @__PURE__ */ new Set([
|
|
29
|
+
"optional",
|
|
30
|
+
"default"
|
|
31
|
+
]);
|
|
32
|
+
var isOptionalProp = /* @__PURE__ */ __name((propSchema) => OPTIONAL_WRAPPER_TYPES.has(propSchema._zod.def.type), "isOptionalProp");
|
|
33
|
+
var computeShapeKeys = /* @__PURE__ */ __name((schema) => {
|
|
38
34
|
const { shape } = schema;
|
|
39
35
|
const properties = Object.keys(shape);
|
|
40
36
|
const required = properties.filter((key) => {
|
|
41
37
|
const propSchema = shape[key];
|
|
42
38
|
return propSchema !== void 0 && !isOptionalProp(propSchema);
|
|
43
39
|
});
|
|
44
|
-
return {
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
return {
|
|
41
|
+
properties,
|
|
42
|
+
required
|
|
43
|
+
};
|
|
44
|
+
}, "computeShapeKeys");
|
|
45
|
+
var extend = /* @__PURE__ */ __name((parent, build) => {
|
|
47
46
|
const result = build(parent);
|
|
48
|
-
lineageMap.set(result, {
|
|
47
|
+
lineageMap.set(result, {
|
|
48
|
+
op: "extend",
|
|
49
|
+
parent
|
|
50
|
+
});
|
|
49
51
|
if (!propsMap.has(parent)) {
|
|
50
52
|
propsMap.set(parent, computeShapeKeys(parent));
|
|
51
53
|
}
|
|
52
54
|
return result;
|
|
53
|
-
};
|
|
54
|
-
var getLineage = (schema) => lineageMap.get(schema);
|
|
55
|
-
var DEFAULT_BUILD_REF = (id) => `${DEFS_PREFIX}${id}
|
|
56
|
-
var createCompositionOverride = (opts) => {
|
|
55
|
+
}, "extend");
|
|
56
|
+
var getLineage = /* @__PURE__ */ __name((schema) => lineageMap.get(schema), "getLineage");
|
|
57
|
+
var DEFAULT_BUILD_REF = /* @__PURE__ */ __name((id) => `${DEFS_PREFIX}${id}`, "DEFAULT_BUILD_REF");
|
|
58
|
+
var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
|
|
57
59
|
const { buildRef, registry } = opts;
|
|
58
60
|
return (ctx) => {
|
|
59
61
|
const { jsonSchema, zodSchema } = ctx;
|
|
@@ -81,7 +83,10 @@ var createCompositionOverride = (opts) => {
|
|
|
81
83
|
deltaProps[key] = value;
|
|
82
84
|
}
|
|
83
85
|
const deltaRequired = childRequired.filter((key) => !parentReqSet.has(key));
|
|
84
|
-
const delta = {
|
|
86
|
+
const delta = {
|
|
87
|
+
type: "object",
|
|
88
|
+
properties: deltaProps
|
|
89
|
+
};
|
|
85
90
|
if (deltaRequired.length > 0) {
|
|
86
91
|
delta.required = deltaRequired;
|
|
87
92
|
}
|
|
@@ -89,39 +94,48 @@ var createCompositionOverride = (opts) => {
|
|
|
89
94
|
delete jsonSchema.properties;
|
|
90
95
|
delete jsonSchema.required;
|
|
91
96
|
delete jsonSchema.additionalProperties;
|
|
92
|
-
jsonSchema.allOf = [
|
|
97
|
+
jsonSchema.allOf = [
|
|
98
|
+
{
|
|
99
|
+
$ref: buildRef(parentId)
|
|
100
|
+
},
|
|
101
|
+
delta
|
|
102
|
+
];
|
|
93
103
|
jsonSchema.unevaluatedProperties = false;
|
|
94
104
|
};
|
|
95
|
-
};
|
|
105
|
+
}, "createCompositionOverride");
|
|
96
106
|
|
|
97
107
|
// src/schema/errors.ts
|
|
98
108
|
var ZodNestError = class extends Error {
|
|
109
|
+
static {
|
|
110
|
+
__name(this, "ZodNestError");
|
|
111
|
+
}
|
|
99
112
|
constructor(message) {
|
|
100
113
|
super(message);
|
|
101
114
|
this.name = "ZodNestError";
|
|
102
115
|
}
|
|
103
116
|
};
|
|
104
117
|
var ZodNestUnrepresentableError = class extends ZodNestError {
|
|
118
|
+
static {
|
|
119
|
+
__name(this, "ZodNestUnrepresentableError");
|
|
120
|
+
}
|
|
105
121
|
path;
|
|
106
122
|
zodType;
|
|
107
123
|
constructor(path, zodType) {
|
|
108
|
-
super(
|
|
109
|
-
`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.`
|
|
110
|
-
);
|
|
124
|
+
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.`);
|
|
111
125
|
this.name = "ZodNestUnrepresentableError";
|
|
112
126
|
this.path = path;
|
|
113
127
|
this.zodType = zodType;
|
|
114
128
|
}
|
|
115
129
|
};
|
|
116
|
-
var formatPath = (path) => {
|
|
130
|
+
var formatPath = /* @__PURE__ */ __name((path) => {
|
|
117
131
|
if (path.length === 0) {
|
|
118
132
|
return "<root>";
|
|
119
133
|
}
|
|
120
134
|
return "/" + path.map(String).join("/");
|
|
121
|
-
};
|
|
135
|
+
}, "formatPath");
|
|
122
136
|
|
|
123
137
|
// src/schema/override.ts
|
|
124
|
-
var primitiveOverride = ({ zodSchema, jsonSchema }) => {
|
|
138
|
+
var primitiveOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
125
139
|
const type = zodSchema._zod.def.type;
|
|
126
140
|
if (type === "bigint") {
|
|
127
141
|
jsonSchema.type = "integer";
|
|
@@ -132,8 +146,8 @@ var primitiveOverride = ({ zodSchema, jsonSchema }) => {
|
|
|
132
146
|
jsonSchema.format = "date-time";
|
|
133
147
|
return;
|
|
134
148
|
}
|
|
135
|
-
};
|
|
136
|
-
var combine = (...overrides) => {
|
|
149
|
+
}, "primitiveOverride");
|
|
150
|
+
var combine = /* @__PURE__ */ __name((...overrides) => {
|
|
137
151
|
const list = [];
|
|
138
152
|
for (const candidate of overrides) {
|
|
139
153
|
if (typeof candidate !== "function") {
|
|
@@ -146,10 +160,10 @@ var combine = (...overrides) => {
|
|
|
146
160
|
o(ctx);
|
|
147
161
|
}
|
|
148
162
|
};
|
|
149
|
-
};
|
|
163
|
+
}, "combine");
|
|
150
164
|
|
|
151
165
|
// src/schema/post-process.ts
|
|
152
|
-
var rewriteRefs = (node, selfRef) => {
|
|
166
|
+
var rewriteRefs = /* @__PURE__ */ __name((node, selfRef) => {
|
|
153
167
|
if (Array.isArray(node)) {
|
|
154
168
|
for (const item of node) {
|
|
155
169
|
rewriteRefs(item, selfRef);
|
|
@@ -169,8 +183,8 @@ var rewriteRefs = (node, selfRef) => {
|
|
|
169
183
|
for (const value of Object.values(obj)) {
|
|
170
184
|
rewriteRefs(value, selfRef);
|
|
171
185
|
}
|
|
172
|
-
};
|
|
173
|
-
var postProcess = (raw) => {
|
|
186
|
+
}, "rewriteRefs");
|
|
187
|
+
var postProcess = /* @__PURE__ */ __name((raw) => {
|
|
174
188
|
const refs = /* @__PURE__ */ new Map();
|
|
175
189
|
const rawDefs = raw.$defs;
|
|
176
190
|
if (rawDefs !== void 0) {
|
|
@@ -178,15 +192,20 @@ var postProcess = (raw) => {
|
|
|
178
192
|
refs.set(id, body);
|
|
179
193
|
}
|
|
180
194
|
}
|
|
181
|
-
const root = {
|
|
195
|
+
const root = {
|
|
196
|
+
...raw
|
|
197
|
+
};
|
|
182
198
|
delete root.$schema;
|
|
183
199
|
delete root.$defs;
|
|
184
200
|
rewriteRefs(root, void 0);
|
|
185
201
|
for (const [id, body] of refs) {
|
|
186
202
|
rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);
|
|
187
203
|
}
|
|
188
|
-
return {
|
|
189
|
-
|
|
204
|
+
return {
|
|
205
|
+
schema: root,
|
|
206
|
+
refs
|
|
207
|
+
};
|
|
208
|
+
}, "postProcess");
|
|
190
209
|
|
|
191
210
|
// src/schema/engine.ts
|
|
192
211
|
var STRICT_REQUIRES_OVERRIDE = /* @__PURE__ */ new Set([
|
|
@@ -201,13 +220,13 @@ var STRICT_REQUIRES_OVERRIDE = /* @__PURE__ */ new Set([
|
|
|
201
220
|
"nan",
|
|
202
221
|
"custom"
|
|
203
222
|
]);
|
|
204
|
-
var isStrictlyUnrepresentable = (jsonSchema, zodSchema) => {
|
|
223
|
+
var isStrictlyUnrepresentable = /* @__PURE__ */ __name((jsonSchema, zodSchema) => {
|
|
205
224
|
if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {
|
|
206
225
|
return false;
|
|
207
226
|
}
|
|
208
227
|
return Object.keys(jsonSchema).length === 0;
|
|
209
|
-
};
|
|
210
|
-
var buildToJsonSchemaOptions = (params) => {
|
|
228
|
+
}, "isStrictlyUnrepresentable");
|
|
229
|
+
var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
|
|
211
230
|
const strict = params.strict ?? true;
|
|
212
231
|
const compositionOverride = createCompositionOverride({
|
|
213
232
|
buildRef: params.uri ?? DEFAULT_BUILD_REF,
|
|
@@ -215,16 +234,18 @@ var buildToJsonSchemaOptions = (params) => {
|
|
|
215
234
|
});
|
|
216
235
|
const merged = combine(primitiveOverride, compositionOverride, params.override);
|
|
217
236
|
const unrepresentableHits = [];
|
|
218
|
-
const wrapped = (ctx) => {
|
|
237
|
+
const wrapped = /* @__PURE__ */ __name((ctx) => {
|
|
219
238
|
merged(ctx);
|
|
220
239
|
if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {
|
|
221
240
|
return;
|
|
222
241
|
}
|
|
223
242
|
unrepresentableHits.push({
|
|
224
|
-
path: [
|
|
243
|
+
path: [
|
|
244
|
+
...ctx.path
|
|
245
|
+
],
|
|
225
246
|
zodType: ctx.zodSchema._zod.def.type
|
|
226
247
|
});
|
|
227
|
-
};
|
|
248
|
+
}, "wrapped");
|
|
228
249
|
const options = {
|
|
229
250
|
target: "draft-2020-12",
|
|
230
251
|
io: params.io,
|
|
@@ -239,15 +260,15 @@ var buildToJsonSchemaOptions = (params) => {
|
|
|
239
260
|
}
|
|
240
261
|
return {
|
|
241
262
|
options,
|
|
242
|
-
consumeUnrepresentable: () => {
|
|
263
|
+
consumeUnrepresentable: /* @__PURE__ */ __name(() => {
|
|
243
264
|
const firstHit = unrepresentableHits[0];
|
|
244
265
|
if (firstHit !== void 0) {
|
|
245
266
|
throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);
|
|
246
267
|
}
|
|
247
|
-
}
|
|
268
|
+
}, "consumeUnrepresentable")
|
|
248
269
|
};
|
|
249
|
-
};
|
|
250
|
-
var toOpenApi = (schema, opts) => {
|
|
270
|
+
}, "buildToJsonSchemaOptions");
|
|
271
|
+
var toOpenApi = /* @__PURE__ */ __name((schema, opts) => {
|
|
251
272
|
const built = buildToJsonSchemaOptions({
|
|
252
273
|
registry: opts.registry,
|
|
253
274
|
io: opts.io,
|
|
@@ -268,25 +289,27 @@ var toOpenApi = (schema, opts) => {
|
|
|
268
289
|
});
|
|
269
290
|
}
|
|
270
291
|
return result;
|
|
271
|
-
};
|
|
272
|
-
var createRegistry = () => {
|
|
292
|
+
}, "toOpenApi");
|
|
293
|
+
var createRegistry = /* @__PURE__ */ __name(() => {
|
|
273
294
|
const seen = /* @__PURE__ */ new Map();
|
|
274
295
|
return {
|
|
275
296
|
zodRegistry: zod.z.globalRegistry,
|
|
276
|
-
register: (schema, id) => {
|
|
277
|
-
zod.z.globalRegistry.add(schema, {
|
|
297
|
+
register: /* @__PURE__ */ __name((schema, id) => {
|
|
298
|
+
zod.z.globalRegistry.add(schema, {
|
|
299
|
+
id
|
|
300
|
+
});
|
|
278
301
|
let set = seen.get(id);
|
|
279
302
|
if (set === void 0) {
|
|
280
303
|
set = /* @__PURE__ */ new Set();
|
|
281
304
|
seen.set(id, set);
|
|
282
305
|
}
|
|
283
306
|
set.add(schema);
|
|
284
|
-
},
|
|
285
|
-
hasCollision: (id) => {
|
|
307
|
+
}, "register"),
|
|
308
|
+
hasCollision: /* @__PURE__ */ __name((id) => {
|
|
286
309
|
const set = seen.get(id);
|
|
287
310
|
return set !== void 0 && set.size > 1;
|
|
288
|
-
},
|
|
289
|
-
getCollisions: () => {
|
|
311
|
+
}, "hasCollision"),
|
|
312
|
+
getCollisions: /* @__PURE__ */ __name(() => {
|
|
290
313
|
const out = /* @__PURE__ */ new Map();
|
|
291
314
|
for (const [id, set] of seen) {
|
|
292
315
|
if (set.size <= 1) {
|
|
@@ -295,34 +318,39 @@ var createRegistry = () => {
|
|
|
295
318
|
out.set(id, set);
|
|
296
319
|
}
|
|
297
320
|
return out;
|
|
298
|
-
},
|
|
299
|
-
ids: () => [
|
|
321
|
+
}, "getCollisions"),
|
|
322
|
+
ids: /* @__PURE__ */ __name(() => [
|
|
323
|
+
...seen.keys()
|
|
324
|
+
], "ids")
|
|
300
325
|
};
|
|
301
|
-
};
|
|
326
|
+
}, "createRegistry");
|
|
302
327
|
var defaultRegistry = createRegistry();
|
|
303
328
|
|
|
304
329
|
// src/dto/marker.ts
|
|
305
|
-
var makeZodDtoMarker = (dtoId, io) => ({
|
|
306
|
-
type: () => Object,
|
|
330
|
+
var makeZodDtoMarker = /* @__PURE__ */ __name((dtoId, io) => ({
|
|
331
|
+
type: /* @__PURE__ */ __name(() => Object, "type"),
|
|
307
332
|
required: false,
|
|
308
333
|
__zodNestDto: true,
|
|
309
334
|
dtoId,
|
|
310
335
|
io
|
|
311
|
-
});
|
|
312
|
-
var isZodDtoMarker = (value) => {
|
|
336
|
+
}), "makeZodDtoMarker");
|
|
337
|
+
var isZodDtoMarker = /* @__PURE__ */ __name((value) => {
|
|
313
338
|
if (value === null || typeof value !== "object") {
|
|
314
339
|
return false;
|
|
315
340
|
}
|
|
316
341
|
return value.__zodNestDto === true;
|
|
317
|
-
};
|
|
342
|
+
}, "isZodDtoMarker");
|
|
318
343
|
|
|
319
344
|
// src/dto/symbols.ts
|
|
320
345
|
var ZOD_DTO_SYMBOL = /* @__PURE__ */ Symbol.for("zod-nest.dto");
|
|
321
346
|
|
|
322
347
|
// src/dto/output-dto.ts
|
|
323
348
|
var outputCache = /* @__PURE__ */ new WeakMap();
|
|
324
|
-
var buildSiblingClass = (parent, schema) => {
|
|
349
|
+
var buildSiblingClass = /* @__PURE__ */ __name((parent, schema) => {
|
|
325
350
|
const SiblingClass = class {
|
|
351
|
+
static {
|
|
352
|
+
__name(this, "SiblingClass");
|
|
353
|
+
}
|
|
326
354
|
static schema = schema;
|
|
327
355
|
static io = "output";
|
|
328
356
|
static [ZOD_DTO_SYMBOL] = true;
|
|
@@ -339,12 +367,14 @@ var buildSiblingClass = (parent, schema) => {
|
|
|
339
367
|
return schema.safeParse(input);
|
|
340
368
|
}
|
|
341
369
|
static _OPENAPI_METADATA_FACTORY() {
|
|
342
|
-
return {
|
|
370
|
+
return {
|
|
371
|
+
[ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(parent.id, "output")
|
|
372
|
+
};
|
|
343
373
|
}
|
|
344
374
|
};
|
|
345
375
|
return SiblingClass;
|
|
346
|
-
};
|
|
347
|
-
var resolveOutput = (parent, schema) => {
|
|
376
|
+
}, "buildSiblingClass");
|
|
377
|
+
var resolveOutput = /* @__PURE__ */ __name((parent, schema) => {
|
|
348
378
|
const cached = outputCache.get(parent);
|
|
349
379
|
if (cached !== void 0) {
|
|
350
380
|
return cached;
|
|
@@ -352,12 +382,12 @@ var resolveOutput = (parent, schema) => {
|
|
|
352
382
|
const sibling = buildSiblingClass(parent, schema);
|
|
353
383
|
outputCache.set(parent, sibling);
|
|
354
384
|
return sibling;
|
|
355
|
-
};
|
|
385
|
+
}, "resolveOutput");
|
|
356
386
|
|
|
357
387
|
// src/dto/create-zod-dto.ts
|
|
358
388
|
var anonCounter = 0;
|
|
359
389
|
var warnedOnAnonymous = false;
|
|
360
|
-
var resolveId = (registry, schema, providedId, className) => {
|
|
390
|
+
var resolveId = /* @__PURE__ */ __name((registry, schema, providedId, className) => {
|
|
361
391
|
if (providedId !== void 0 && providedId !== "") {
|
|
362
392
|
return providedId;
|
|
363
393
|
}
|
|
@@ -372,25 +402,26 @@ var resolveId = (registry, schema, providedId, className) => {
|
|
|
372
402
|
const fallback = `_AnonZodDto_${anonCounter}`;
|
|
373
403
|
if (!warnedOnAnonymous) {
|
|
374
404
|
warnedOnAnonymous = true;
|
|
375
|
-
console.warn(
|
|
376
|
-
`[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.`
|
|
377
|
-
);
|
|
405
|
+
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.`);
|
|
378
406
|
}
|
|
379
407
|
return fallback;
|
|
380
|
-
};
|
|
381
|
-
var createZodDto = (schema, options) => {
|
|
408
|
+
}, "resolveId");
|
|
409
|
+
var createZodDto = /* @__PURE__ */ __name((schema, options) => {
|
|
382
410
|
const registry = options?.registry ?? defaultRegistry;
|
|
383
411
|
const io = "input";
|
|
384
412
|
let cachedId;
|
|
385
|
-
const ensureRegistered = (className) => {
|
|
413
|
+
const ensureRegistered = /* @__PURE__ */ __name((className) => {
|
|
386
414
|
if (cachedId !== void 0) {
|
|
387
415
|
return cachedId;
|
|
388
416
|
}
|
|
389
417
|
cachedId = resolveId(registry, schema, options?.id, className);
|
|
390
418
|
registry.register(schema, cachedId);
|
|
391
419
|
return cachedId;
|
|
392
|
-
};
|
|
420
|
+
}, "ensureRegistered");
|
|
393
421
|
const ZodDtoBase = class {
|
|
422
|
+
static {
|
|
423
|
+
__name(this, "ZodDtoBase");
|
|
424
|
+
}
|
|
394
425
|
static schema = schema;
|
|
395
426
|
static io = io;
|
|
396
427
|
static [ZOD_DTO_SYMBOL] = true;
|
|
@@ -407,41 +438,47 @@ var createZodDto = (schema, options) => {
|
|
|
407
438
|
return schema.safeParse(input);
|
|
408
439
|
}
|
|
409
440
|
static _OPENAPI_METADATA_FACTORY() {
|
|
410
|
-
return {
|
|
441
|
+
return {
|
|
442
|
+
[ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(ensureRegistered(this.name), io)
|
|
443
|
+
};
|
|
411
444
|
}
|
|
412
445
|
};
|
|
413
446
|
return ZodDtoBase;
|
|
414
|
-
};
|
|
447
|
+
}, "createZodDto");
|
|
415
448
|
|
|
416
449
|
// src/dto/predicates.ts
|
|
417
|
-
var isZodDto = (value) => typeof value === "function" && value[ZOD_DTO_SYMBOL] === true;
|
|
450
|
+
var isZodDto = /* @__PURE__ */ __name((value) => typeof value === "function" && value[ZOD_DTO_SYMBOL] === true, "isZodDto");
|
|
418
451
|
var ZodSerializationException = class extends common.InternalServerErrorException {
|
|
452
|
+
static {
|
|
453
|
+
__name(this, "ZodSerializationException");
|
|
454
|
+
}
|
|
419
455
|
zodError;
|
|
420
456
|
executionContext;
|
|
421
457
|
constructor(zodError, executionContext) {
|
|
422
|
-
super(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
);
|
|
458
|
+
super({
|
|
459
|
+
statusCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
460
|
+
message: "Response validation failed"
|
|
461
|
+
}, {
|
|
462
|
+
cause: zodError
|
|
463
|
+
});
|
|
429
464
|
this.zodError = zodError;
|
|
430
465
|
this.executionContext = executionContext;
|
|
431
466
|
}
|
|
432
467
|
};
|
|
433
468
|
var ZodValidationException = class extends common.BadRequestException {
|
|
469
|
+
static {
|
|
470
|
+
__name(this, "ZodValidationException");
|
|
471
|
+
}
|
|
434
472
|
zodError;
|
|
435
473
|
argMetadata;
|
|
436
474
|
constructor(zodError, argMetadata) {
|
|
437
|
-
super(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
);
|
|
475
|
+
super({
|
|
476
|
+
statusCode: common.HttpStatus.BAD_REQUEST,
|
|
477
|
+
message: "Validation failed",
|
|
478
|
+
errors: zod.z.treeifyError(zodError)
|
|
479
|
+
}, {
|
|
480
|
+
cause: zodError
|
|
481
|
+
});
|
|
445
482
|
this.zodError = zodError;
|
|
446
483
|
this.argMetadata = argMetadata;
|
|
447
484
|
}
|
|
@@ -449,11 +486,11 @@ var ZodValidationException = class extends common.BadRequestException {
|
|
|
449
486
|
var DEFAULT_LOGGER_CONTEXT = "ZodValidation";
|
|
450
487
|
var REDACTED = "[REDACTED]";
|
|
451
488
|
var PREVIEW_RESERVE_BYTES = 100;
|
|
452
|
-
var noopLogValidationFailure = () => {
|
|
453
|
-
};
|
|
454
|
-
var isPlainRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
489
|
+
var noopLogValidationFailure = /* @__PURE__ */ __name(() => {
|
|
490
|
+
}, "noopLogValidationFailure");
|
|
491
|
+
var isPlainRecord = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isPlainRecord");
|
|
455
492
|
var CIRCULAR = "[CIRCULAR]";
|
|
456
|
-
var redactValue = (value, redactSet, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
493
|
+
var redactValue = /* @__PURE__ */ __name((value, redactSet, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
457
494
|
if (Array.isArray(value)) {
|
|
458
495
|
if (seen.has(value)) {
|
|
459
496
|
return CIRCULAR;
|
|
@@ -477,13 +514,17 @@ var redactValue = (value, redactSet, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
477
514
|
out[key] = redactValue(value[key], redactSet, seen);
|
|
478
515
|
}
|
|
479
516
|
return out;
|
|
480
|
-
};
|
|
481
|
-
var capLoggedValue = (value, maxBytes) => {
|
|
517
|
+
}, "redactValue");
|
|
518
|
+
var capLoggedValue = /* @__PURE__ */ __name((value, maxBytes) => {
|
|
482
519
|
let serialized;
|
|
483
520
|
try {
|
|
484
521
|
serialized = JSON.stringify(value);
|
|
485
522
|
} catch {
|
|
486
|
-
return {
|
|
523
|
+
return {
|
|
524
|
+
_truncated: true,
|
|
525
|
+
_originalBytes: -1,
|
|
526
|
+
_reason: "unserializable"
|
|
527
|
+
};
|
|
487
528
|
}
|
|
488
529
|
if (serialized === void 0) {
|
|
489
530
|
return value;
|
|
@@ -498,10 +539,10 @@ var capLoggedValue = (value, maxBytes) => {
|
|
|
498
539
|
_originalBytes: byteSize,
|
|
499
540
|
_preview: serialized.slice(0, previewBudget)
|
|
500
541
|
};
|
|
501
|
-
};
|
|
502
|
-
var loggerContextFor = (side) => side === "output" ? "ZodSerializerInterceptor" : "ZodValidationPipe";
|
|
503
|
-
var messageFor = (side) => side === "output" ? "Response validation failed" : "Request validation failed";
|
|
504
|
-
var createValidationLogger = (opts) => {
|
|
542
|
+
}, "capLoggedValue");
|
|
543
|
+
var loggerContextFor = /* @__PURE__ */ __name((side) => side === "output" ? "ZodSerializerInterceptor" : "ZodValidationPipe", "loggerContextFor");
|
|
544
|
+
var messageFor = /* @__PURE__ */ __name((side) => side === "output" ? "Response validation failed" : "Request validation failed", "messageFor");
|
|
545
|
+
var createValidationLogger = /* @__PURE__ */ __name((opts) => {
|
|
505
546
|
const redactSet = new Set(opts.redactKeys.map((key) => key.toLowerCase()));
|
|
506
547
|
const { logger } = opts;
|
|
507
548
|
return (err, value, ctx) => {
|
|
@@ -530,7 +571,7 @@ var createValidationLogger = (opts) => {
|
|
|
530
571
|
}
|
|
531
572
|
logger.warn(payload, loggerContext);
|
|
532
573
|
};
|
|
533
|
-
};
|
|
574
|
+
}, "createValidationLogger");
|
|
534
575
|
var DEFAULT_REDACT_KEYS = [
|
|
535
576
|
// Credentials
|
|
536
577
|
"password",
|
|
@@ -549,40 +590,67 @@ var DEFAULT_REDACT_KEYS = [
|
|
|
549
590
|
];
|
|
550
591
|
var DEFAULT_MAX_LOGGED_VALUE_BYTES = 4096;
|
|
551
592
|
var ZOD_NEST_OPTIONS = /* @__PURE__ */ Symbol("zod-nest.options");
|
|
552
|
-
var resolveLogFlags = (validationLogs) => {
|
|
593
|
+
var resolveLogFlags = /* @__PURE__ */ __name((validationLogs) => {
|
|
553
594
|
if (typeof validationLogs === "boolean") {
|
|
554
|
-
return {
|
|
595
|
+
return {
|
|
596
|
+
input: validationLogs,
|
|
597
|
+
output: validationLogs
|
|
598
|
+
};
|
|
555
599
|
}
|
|
556
600
|
return {
|
|
557
601
|
input: validationLogs?.input ?? false,
|
|
558
602
|
output: validationLogs?.output ?? false
|
|
559
603
|
};
|
|
560
|
-
};
|
|
561
|
-
var normalizeZodNestOptions = (opts) => {
|
|
604
|
+
}, "resolveLogFlags");
|
|
605
|
+
var normalizeZodNestOptions = /* @__PURE__ */ __name((opts) => {
|
|
562
606
|
const flags = resolveLogFlags(opts?.validationLogs);
|
|
563
607
|
const redactKeys = opts?.redactKeys ?? DEFAULT_REDACT_KEYS;
|
|
564
608
|
const maxLoggedValueBytes = opts?.maxLoggedValueBytes ?? DEFAULT_MAX_LOGGED_VALUE_BYTES;
|
|
565
609
|
const logger = opts?.logger ?? new common.Logger(DEFAULT_LOGGER_CONTEXT);
|
|
566
|
-
const loggerOpts = {
|
|
610
|
+
const loggerOpts = {
|
|
611
|
+
logger,
|
|
612
|
+
redactKeys,
|
|
613
|
+
maxLoggedValueBytes
|
|
614
|
+
};
|
|
567
615
|
return {
|
|
568
616
|
createValidationException: opts?.createValidationException,
|
|
569
617
|
createSerializationException: opts?.createSerializationException,
|
|
570
618
|
logInputFailure: flags.input ? createValidationLogger(loggerOpts) : noopLogValidationFailure,
|
|
571
619
|
logOutputFailure: flags.output ? createValidationLogger(loggerOpts) : noopLogValidationFailure
|
|
572
620
|
};
|
|
573
|
-
};
|
|
621
|
+
}, "normalizeZodNestOptions");
|
|
574
622
|
|
|
575
623
|
// src/pipes/validation.pipe.ts
|
|
576
|
-
|
|
577
|
-
var
|
|
578
|
-
|
|
579
|
-
|
|
624
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
625
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
626
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
627
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
628
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
629
|
+
}
|
|
630
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
631
|
+
function _ts_metadata(k, v) {
|
|
632
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
633
|
+
}
|
|
634
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
635
|
+
function _ts_param(paramIndex, decorator) {
|
|
636
|
+
return function(target, key) {
|
|
637
|
+
decorator(target, key, paramIndex);
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
__name(_ts_param, "_ts_param");
|
|
641
|
+
var isZodSchema = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && "_zod" in value, "isZodSchema");
|
|
642
|
+
var isOptionsObject = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !isZodSchema(value), "isOptionsObject");
|
|
643
|
+
var defaultExceptionFactory = /* @__PURE__ */ __name((zodError, argMetadata) => new ZodValidationException(zodError, argMetadata), "defaultExceptionFactory");
|
|
644
|
+
exports.ZodValidationPipe = class _ZodValidationPipe {
|
|
645
|
+
static {
|
|
646
|
+
__name(this, "ZodValidationPipe");
|
|
647
|
+
}
|
|
580
648
|
explicitSchema;
|
|
581
649
|
explicitDtoName;
|
|
582
650
|
createValidationException;
|
|
583
651
|
logInputFailure;
|
|
584
652
|
constructor(arg, moduleOptions) {
|
|
585
|
-
const parsed =
|
|
653
|
+
const parsed = _ZodValidationPipe.parseArg(arg);
|
|
586
654
|
this.explicitSchema = parsed.schema;
|
|
587
655
|
this.explicitDtoName = parsed.dtoName;
|
|
588
656
|
this.createValidationException = parsed.factory ?? moduleOptions?.createValidationException ?? defaultExceptionFactory;
|
|
@@ -627,16 +695,32 @@ exports.ZodValidationPipe = class ZodValidationPipe {
|
|
|
627
695
|
}
|
|
628
696
|
static parseArg(arg) {
|
|
629
697
|
if (arg === void 0) {
|
|
630
|
-
return {
|
|
698
|
+
return {
|
|
699
|
+
schema: void 0,
|
|
700
|
+
factory: void 0,
|
|
701
|
+
dtoName: void 0
|
|
702
|
+
};
|
|
631
703
|
}
|
|
632
704
|
if (isZodDto(arg)) {
|
|
633
|
-
return {
|
|
705
|
+
return {
|
|
706
|
+
schema: arg.schema,
|
|
707
|
+
factory: void 0,
|
|
708
|
+
dtoName: arg.name
|
|
709
|
+
};
|
|
634
710
|
}
|
|
635
711
|
if (isZodSchema(arg)) {
|
|
636
|
-
return {
|
|
712
|
+
return {
|
|
713
|
+
schema: arg,
|
|
714
|
+
factory: void 0,
|
|
715
|
+
dtoName: void 0
|
|
716
|
+
};
|
|
637
717
|
}
|
|
638
718
|
if (!isOptionsObject(arg)) {
|
|
639
|
-
return {
|
|
719
|
+
return {
|
|
720
|
+
schema: void 0,
|
|
721
|
+
factory: void 0,
|
|
722
|
+
dtoName: void 0
|
|
723
|
+
};
|
|
640
724
|
}
|
|
641
725
|
const optionSchema = arg.schema;
|
|
642
726
|
const dtoName = isZodDto(optionSchema) ? optionSchema.name : void 0;
|
|
@@ -648,57 +732,76 @@ exports.ZodValidationPipe = class ZodValidationPipe {
|
|
|
648
732
|
};
|
|
649
733
|
}
|
|
650
734
|
};
|
|
651
|
-
exports.ZodValidationPipe =
|
|
735
|
+
exports.ZodValidationPipe = _ts_decorate([
|
|
652
736
|
common.Injectable(),
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
737
|
+
_ts_param(0, common.Optional()),
|
|
738
|
+
_ts_param(1, common.Optional()),
|
|
739
|
+
_ts_param(1, common.Inject(ZOD_NEST_OPTIONS)),
|
|
740
|
+
_ts_metadata("design:type", Function),
|
|
741
|
+
_ts_metadata("design:paramtypes", [
|
|
742
|
+
typeof ZodValidationPipeArg === "undefined" ? Object : ZodValidationPipeArg,
|
|
743
|
+
typeof NormalizedZodNestOptions === "undefined" ? Object : NormalizedZodNestOptions
|
|
744
|
+
])
|
|
656
745
|
], exports.ZodValidationPipe);
|
|
657
746
|
|
|
658
747
|
// src/response/metadata.ts
|
|
659
748
|
var ZOD_RESPONSES_METADATA_KEY = /* @__PURE__ */ Symbol.for("zod-nest.responses");
|
|
660
|
-
var getResponseVariants = (handler) => {
|
|
749
|
+
var getResponseVariants = /* @__PURE__ */ __name((handler) => {
|
|
661
750
|
const meta = Reflect.getMetadata(ZOD_RESPONSES_METADATA_KEY, handler);
|
|
662
751
|
return meta;
|
|
663
|
-
};
|
|
664
|
-
var appendResponseVariant = (handler, variant) => {
|
|
752
|
+
}, "getResponseVariants");
|
|
753
|
+
var appendResponseVariant = /* @__PURE__ */ __name((handler, variant) => {
|
|
665
754
|
const existing = Reflect.getMetadata(ZOD_RESPONSES_METADATA_KEY, handler) ?? [];
|
|
666
|
-
Reflect.defineMetadata(ZOD_RESPONSES_METADATA_KEY, [
|
|
667
|
-
|
|
755
|
+
Reflect.defineMetadata(ZOD_RESPONSES_METADATA_KEY, [
|
|
756
|
+
variant,
|
|
757
|
+
...existing
|
|
758
|
+
], handler);
|
|
759
|
+
}, "appendResponseVariant");
|
|
668
760
|
|
|
669
761
|
// src/decorators/zod-response.decorator.ts
|
|
670
|
-
var buildArrayKind = (dtos) => {
|
|
762
|
+
var buildArrayKind = /* @__PURE__ */ __name((dtos) => {
|
|
671
763
|
for (const [index, element] of dtos.entries()) {
|
|
672
764
|
if (!isZodDto(element)) {
|
|
673
|
-
throw new TypeError(
|
|
674
|
-
`[zod-nest] @ZodResponse({ type }) element [${index}] is not a zod-nest DTO (class returned by createZodDto). Wrap raw schemas with createZodDto first.`
|
|
675
|
-
);
|
|
765
|
+
throw new TypeError(`[zod-nest] @ZodResponse({ type }) element [${index}] is not a zod-nest DTO (class returned by createZodDto). Wrap raw schemas with createZodDto first.`);
|
|
676
766
|
}
|
|
677
767
|
}
|
|
678
768
|
const [head, ...rest] = dtos;
|
|
679
769
|
if (rest.length === 0) {
|
|
680
|
-
return {
|
|
770
|
+
return {
|
|
771
|
+
kind: "array",
|
|
772
|
+
dto: [
|
|
773
|
+
head
|
|
774
|
+
],
|
|
775
|
+
validationSchema: zod.z.array(head.schema)
|
|
776
|
+
};
|
|
681
777
|
}
|
|
682
|
-
const tupleSchemas = [
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
778
|
+
const tupleSchemas = [
|
|
779
|
+
head.schema,
|
|
780
|
+
...rest.map((d) => d.schema)
|
|
781
|
+
];
|
|
782
|
+
return {
|
|
783
|
+
kind: "tuple",
|
|
784
|
+
dto: dtos,
|
|
785
|
+
validationSchema: zod.z.tuple(tupleSchemas)
|
|
786
|
+
};
|
|
787
|
+
}, "buildArrayKind");
|
|
788
|
+
var buildKind = /* @__PURE__ */ __name((type) => {
|
|
686
789
|
if (Array.isArray(type)) {
|
|
687
790
|
if (type.length === 0) {
|
|
688
|
-
throw new TypeError(
|
|
689
|
-
"[zod-nest] @ZodResponse({ type: [] }) is invalid \u2014 provide at least one DTO."
|
|
690
|
-
);
|
|
791
|
+
throw new TypeError("[zod-nest] @ZodResponse({ type: [] }) is invalid \u2014 provide at least one DTO.");
|
|
691
792
|
}
|
|
692
793
|
return buildArrayKind(type);
|
|
693
794
|
}
|
|
694
795
|
if (!isZodDto(type)) {
|
|
695
|
-
throw new TypeError(
|
|
696
|
-
"[zod-nest] @ZodResponse({ type }) must be a zod-nest DTO class (from createZodDto) or an array of such classes."
|
|
697
|
-
);
|
|
796
|
+
throw new TypeError("[zod-nest] @ZodResponse({ type }) must be a zod-nest DTO class (from createZodDto) or an array of such classes.");
|
|
698
797
|
}
|
|
699
|
-
return {
|
|
700
|
-
|
|
701
|
-
|
|
798
|
+
return {
|
|
799
|
+
kind: "single",
|
|
800
|
+
dto: type,
|
|
801
|
+
validationSchema: type.schema
|
|
802
|
+
};
|
|
803
|
+
}, "buildKind");
|
|
804
|
+
var ZodResponse = /* @__PURE__ */ __name((opts) => {
|
|
702
805
|
const built = buildKind(opts.type);
|
|
703
806
|
return (_target, _propertyKey, descriptor) => {
|
|
704
807
|
const handler = descriptor.value;
|
|
@@ -715,10 +818,10 @@ var ZodResponse = (opts) => {
|
|
|
715
818
|
};
|
|
716
819
|
appendResponseVariant(handler, variant);
|
|
717
820
|
};
|
|
718
|
-
};
|
|
821
|
+
}, "ZodResponse");
|
|
719
822
|
var POST_DEFAULT_STATUS = 201;
|
|
720
823
|
var GENERIC_DEFAULT_STATUS = 200;
|
|
721
|
-
var defaultStatusFor = (handler) => {
|
|
824
|
+
var defaultStatusFor = /* @__PURE__ */ __name((handler) => {
|
|
722
825
|
const httpCode = Reflect.getMetadata(constants_js.HTTP_CODE_METADATA, handler);
|
|
723
826
|
if (typeof httpCode === "number") {
|
|
724
827
|
return httpCode;
|
|
@@ -728,42 +831,59 @@ var defaultStatusFor = (handler) => {
|
|
|
728
831
|
return POST_DEFAULT_STATUS;
|
|
729
832
|
}
|
|
730
833
|
return GENERIC_DEFAULT_STATUS;
|
|
731
|
-
};
|
|
732
|
-
var resolveEffectiveStatus = (variant, handler) => {
|
|
834
|
+
}, "defaultStatusFor");
|
|
835
|
+
var resolveEffectiveStatus = /* @__PURE__ */ __name((variant, handler) => {
|
|
733
836
|
if (variant.status !== void 0) {
|
|
734
837
|
return variant.status;
|
|
735
838
|
}
|
|
736
839
|
return defaultStatusFor(handler);
|
|
737
|
-
};
|
|
840
|
+
}, "resolveEffectiveStatus");
|
|
738
841
|
|
|
739
842
|
// src/interceptors/serializer.interceptor.ts
|
|
740
|
-
|
|
741
|
-
var
|
|
843
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
844
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
845
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
846
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
847
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
848
|
+
}
|
|
849
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
850
|
+
function _ts_metadata2(k, v) {
|
|
851
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
852
|
+
}
|
|
853
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
854
|
+
function _ts_param2(paramIndex, decorator) {
|
|
855
|
+
return function(target, key) {
|
|
856
|
+
decorator(target, key, paramIndex);
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
__name(_ts_param2, "_ts_param");
|
|
860
|
+
var defaultSerializationFactory = /* @__PURE__ */ __name((err, ctx) => new ZodSerializationException(err, ctx), "defaultSerializationFactory");
|
|
861
|
+
var formatDtoLabel = /* @__PURE__ */ __name((variant) => {
|
|
742
862
|
if (variant.kind === "single") {
|
|
743
863
|
return variant.dto.name;
|
|
744
864
|
}
|
|
745
865
|
const dtos = variant.dto;
|
|
746
866
|
return `[${dtos.map((d) => d.name).join(", ")}]`;
|
|
747
|
-
};
|
|
748
|
-
var formatHandlerLabel = (context) => `${context.getClass().name}.${context.getHandler().name}
|
|
867
|
+
}, "formatDtoLabel");
|
|
868
|
+
var formatHandlerLabel = /* @__PURE__ */ __name((context) => `${context.getClass().name}.${context.getHandler().name}`, "formatHandlerLabel");
|
|
749
869
|
exports.ZodSerializerInterceptor = class ZodSerializerInterceptor {
|
|
870
|
+
static {
|
|
871
|
+
__name(this, "ZodSerializerInterceptor");
|
|
872
|
+
}
|
|
873
|
+
reflector;
|
|
874
|
+
logOutputFailure;
|
|
875
|
+
createSerializationException;
|
|
750
876
|
constructor(reflector, options) {
|
|
751
877
|
this.reflector = reflector;
|
|
752
878
|
this.logOutputFailure = options?.logOutputFailure ?? noopLogValidationFailure;
|
|
753
879
|
this.createSerializationException = options?.createSerializationException ?? defaultSerializationFactory;
|
|
754
880
|
}
|
|
755
|
-
reflector;
|
|
756
|
-
logOutputFailure;
|
|
757
|
-
createSerializationException;
|
|
758
881
|
intercept(context, next) {
|
|
759
882
|
if (context.getType() !== "http") {
|
|
760
883
|
return next.handle();
|
|
761
884
|
}
|
|
762
885
|
const handler = context.getHandler();
|
|
763
|
-
const variants = this.reflector.get(
|
|
764
|
-
ZOD_RESPONSES_METADATA_KEY,
|
|
765
|
-
handler
|
|
766
|
-
);
|
|
886
|
+
const variants = this.reflector.get(ZOD_RESPONSES_METADATA_KEY, handler);
|
|
767
887
|
if (variants === void 0 || variants.length === 0) {
|
|
768
888
|
return next.handle();
|
|
769
889
|
}
|
|
@@ -797,35 +917,54 @@ exports.ZodSerializerInterceptor = class ZodSerializerInterceptor {
|
|
|
797
917
|
throw this.createSerializationException(result.error, context);
|
|
798
918
|
}
|
|
799
919
|
};
|
|
800
|
-
exports.ZodSerializerInterceptor =
|
|
920
|
+
exports.ZodSerializerInterceptor = _ts_decorate2([
|
|
801
921
|
common.Injectable(),
|
|
802
|
-
|
|
803
|
-
|
|
922
|
+
_ts_param2(1, common.Optional()),
|
|
923
|
+
_ts_param2(1, common.Inject(ZOD_NEST_OPTIONS)),
|
|
924
|
+
_ts_metadata2("design:type", Function),
|
|
925
|
+
_ts_metadata2("design:paramtypes", [
|
|
926
|
+
typeof core.Reflector === "undefined" ? Object : core.Reflector,
|
|
927
|
+
typeof NormalizedZodNestOptions === "undefined" ? Object : NormalizedZodNestOptions
|
|
928
|
+
])
|
|
804
929
|
], exports.ZodSerializerInterceptor);
|
|
805
930
|
var ZodNestModule = class _ZodNestModule {
|
|
931
|
+
static {
|
|
932
|
+
__name(this, "ZodNestModule");
|
|
933
|
+
}
|
|
806
934
|
static forRoot(options) {
|
|
807
935
|
const normalized = normalizeZodNestOptions(options);
|
|
808
936
|
return {
|
|
809
937
|
module: _ZodNestModule,
|
|
810
938
|
global: true,
|
|
811
939
|
providers: [
|
|
812
|
-
{
|
|
813
|
-
|
|
814
|
-
|
|
940
|
+
{
|
|
941
|
+
provide: ZOD_NEST_OPTIONS,
|
|
942
|
+
useValue: normalized
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
provide: core.APP_PIPE,
|
|
946
|
+
useClass: exports.ZodValidationPipe
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
provide: core.APP_INTERCEPTOR,
|
|
950
|
+
useClass: exports.ZodSerializerInterceptor
|
|
951
|
+
}
|
|
815
952
|
],
|
|
816
|
-
exports: [
|
|
953
|
+
exports: [
|
|
954
|
+
ZOD_NEST_OPTIONS
|
|
955
|
+
]
|
|
817
956
|
};
|
|
818
957
|
}
|
|
819
958
|
};
|
|
820
|
-
var URI = (id) => `#/components/schemas/${id}
|
|
821
|
-
var bulkEmit = (opts) => {
|
|
959
|
+
var URI = /* @__PURE__ */ __name((id) => `#/components/schemas/${id}`, "URI");
|
|
960
|
+
var bulkEmit = /* @__PURE__ */ __name((opts) => {
|
|
822
961
|
const knownIds = new Set(opts.registry.ids());
|
|
823
962
|
return {
|
|
824
963
|
inputSchemas: runPass(opts, "input", knownIds),
|
|
825
964
|
outputSchemas: runPass(opts, "output", knownIds)
|
|
826
965
|
};
|
|
827
|
-
};
|
|
828
|
-
var runPass = (opts, io, knownIds) => {
|
|
966
|
+
}, "bulkEmit");
|
|
967
|
+
var runPass = /* @__PURE__ */ __name((opts, io, knownIds) => {
|
|
829
968
|
const built = buildToJsonSchemaOptions({
|
|
830
969
|
registry: opts.registry,
|
|
831
970
|
io,
|
|
@@ -843,7 +982,7 @@ var runPass = (opts, io, knownIds) => {
|
|
|
843
982
|
}
|
|
844
983
|
}
|
|
845
984
|
return filtered;
|
|
846
|
-
};
|
|
985
|
+
}, "runPass");
|
|
847
986
|
|
|
848
987
|
// src/document/http-methods.ts
|
|
849
988
|
var HTTP_METHODS = [
|
|
@@ -858,14 +997,18 @@ var HTTP_METHODS = [
|
|
|
858
997
|
];
|
|
859
998
|
|
|
860
999
|
// src/document/collect-usage.ts
|
|
861
|
-
var isPlainRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
862
|
-
var collectUsage = (doc, app) => {
|
|
1000
|
+
var isPlainRecord2 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isPlainRecord");
|
|
1001
|
+
var collectUsage = /* @__PURE__ */ __name((doc, app) => {
|
|
863
1002
|
const classToDtoId = buildClassToDtoIdMap(doc);
|
|
864
1003
|
const inputExposedIds = collectInputExposedIds(doc, classToDtoId);
|
|
865
1004
|
const outputExposedIds = collectOutputExposedIds(app);
|
|
866
|
-
return {
|
|
867
|
-
|
|
868
|
-
|
|
1005
|
+
return {
|
|
1006
|
+
inputExposedIds,
|
|
1007
|
+
outputExposedIds,
|
|
1008
|
+
classToDtoId
|
|
1009
|
+
};
|
|
1010
|
+
}, "collectUsage");
|
|
1011
|
+
var buildClassToDtoIdMap = /* @__PURE__ */ __name((doc) => {
|
|
869
1012
|
const map = /* @__PURE__ */ new Map();
|
|
870
1013
|
const schemas = doc.components?.schemas ?? {};
|
|
871
1014
|
for (const [className, schema] of Object.entries(schemas)) {
|
|
@@ -876,8 +1019,8 @@ var buildClassToDtoIdMap = (doc) => {
|
|
|
876
1019
|
map.set(className, marker.dtoId);
|
|
877
1020
|
}
|
|
878
1021
|
return map;
|
|
879
|
-
};
|
|
880
|
-
var readMarker = (schema) => {
|
|
1022
|
+
}, "buildClassToDtoIdMap");
|
|
1023
|
+
var readMarker = /* @__PURE__ */ __name((schema) => {
|
|
881
1024
|
if (!isPlainRecord2(schema)) {
|
|
882
1025
|
return void 0;
|
|
883
1026
|
}
|
|
@@ -888,9 +1031,11 @@ var readMarker = (schema) => {
|
|
|
888
1031
|
if (!isZodDtoMarker(marker)) {
|
|
889
1032
|
return void 0;
|
|
890
1033
|
}
|
|
891
|
-
return {
|
|
892
|
-
|
|
893
|
-
|
|
1034
|
+
return {
|
|
1035
|
+
dtoId: marker.dtoId
|
|
1036
|
+
};
|
|
1037
|
+
}, "readMarker");
|
|
1038
|
+
var collectInputExposedIds = /* @__PURE__ */ __name((doc, classToDtoId) => {
|
|
894
1039
|
const ids = /* @__PURE__ */ new Set();
|
|
895
1040
|
const paths = doc.paths ?? {};
|
|
896
1041
|
for (const pathItem of Object.values(paths)) {
|
|
@@ -902,8 +1047,8 @@ var collectInputExposedIds = (doc, classToDtoId) => {
|
|
|
902
1047
|
}
|
|
903
1048
|
}
|
|
904
1049
|
return ids;
|
|
905
|
-
};
|
|
906
|
-
var operationsOf = (pathItem) => {
|
|
1050
|
+
}, "collectInputExposedIds");
|
|
1051
|
+
var operationsOf = /* @__PURE__ */ __name((pathItem) => {
|
|
907
1052
|
const out = [];
|
|
908
1053
|
for (const method of HTTP_METHODS) {
|
|
909
1054
|
const op = pathItem[method];
|
|
@@ -912,8 +1057,8 @@ var operationsOf = (pathItem) => {
|
|
|
912
1057
|
}
|
|
913
1058
|
}
|
|
914
1059
|
return out;
|
|
915
|
-
};
|
|
916
|
-
var collectRefsFromOperation = (operation, classToDtoId, ids) => {
|
|
1060
|
+
}, "operationsOf");
|
|
1061
|
+
var collectRefsFromOperation = /* @__PURE__ */ __name((operation, classToDtoId, ids) => {
|
|
917
1062
|
if (isPlainRecord2(operation.requestBody)) {
|
|
918
1063
|
collectRefsFromContent(operation.requestBody.content, classToDtoId, ids);
|
|
919
1064
|
}
|
|
@@ -926,8 +1071,8 @@ var collectRefsFromOperation = (operation, classToDtoId, ids) => {
|
|
|
926
1071
|
collectRefFromSchema(param.schema, classToDtoId, ids);
|
|
927
1072
|
}
|
|
928
1073
|
}
|
|
929
|
-
};
|
|
930
|
-
var collectRefsFromContent = (content, classToDtoId, ids) => {
|
|
1074
|
+
}, "collectRefsFromOperation");
|
|
1075
|
+
var collectRefsFromContent = /* @__PURE__ */ __name((content, classToDtoId, ids) => {
|
|
931
1076
|
if (!isPlainRecord2(content)) {
|
|
932
1077
|
return;
|
|
933
1078
|
}
|
|
@@ -937,8 +1082,8 @@ var collectRefsFromContent = (content, classToDtoId, ids) => {
|
|
|
937
1082
|
}
|
|
938
1083
|
collectRefFromSchema(mediaType.schema, classToDtoId, ids);
|
|
939
1084
|
}
|
|
940
|
-
};
|
|
941
|
-
var collectRefFromSchema = (schema, classToDtoId, ids) => {
|
|
1085
|
+
}, "collectRefsFromContent");
|
|
1086
|
+
var collectRefFromSchema = /* @__PURE__ */ __name((schema, classToDtoId, ids) => {
|
|
942
1087
|
if (!isPlainRecord2(schema)) {
|
|
943
1088
|
return;
|
|
944
1089
|
}
|
|
@@ -951,8 +1096,8 @@ var collectRefFromSchema = (schema, classToDtoId, ids) => {
|
|
|
951
1096
|
if (dtoId !== void 0) {
|
|
952
1097
|
ids.add(dtoId);
|
|
953
1098
|
}
|
|
954
|
-
};
|
|
955
|
-
var collectOutputExposedIds = (app) => {
|
|
1099
|
+
}, "collectRefFromSchema");
|
|
1100
|
+
var collectOutputExposedIds = /* @__PURE__ */ __name((app) => {
|
|
956
1101
|
const ids = /* @__PURE__ */ new Set();
|
|
957
1102
|
const discovery = app.get(core.DiscoveryService);
|
|
958
1103
|
for (const wrapper of discovery.getControllers()) {
|
|
@@ -979,8 +1124,8 @@ var collectOutputExposedIds = (app) => {
|
|
|
979
1124
|
}
|
|
980
1125
|
}
|
|
981
1126
|
return ids;
|
|
982
|
-
};
|
|
983
|
-
var addVariantDtoIds = (variant, ids) => {
|
|
1127
|
+
}, "collectOutputExposedIds");
|
|
1128
|
+
var addVariantDtoIds = /* @__PURE__ */ __name((variant, ids) => {
|
|
984
1129
|
if (variant.kind === "single") {
|
|
985
1130
|
if (isZodDto(variant.dto)) {
|
|
986
1131
|
ids.add(variant.dto.id);
|
|
@@ -995,10 +1140,13 @@ var addVariantDtoIds = (variant, ids) => {
|
|
|
995
1140
|
ids.add(dto.id);
|
|
996
1141
|
}
|
|
997
1142
|
}
|
|
998
|
-
};
|
|
1143
|
+
}, "addVariantDtoIds");
|
|
999
1144
|
|
|
1000
1145
|
// src/document/errors.ts
|
|
1001
1146
|
var ZodNestDocumentError = class extends ZodNestError {
|
|
1147
|
+
static {
|
|
1148
|
+
__name(this, "ZodNestDocumentError");
|
|
1149
|
+
}
|
|
1002
1150
|
code;
|
|
1003
1151
|
details;
|
|
1004
1152
|
constructor(code, message, details = {}) {
|
|
@@ -1010,7 +1158,7 @@ var ZodNestDocumentError = class extends ZodNestError {
|
|
|
1010
1158
|
};
|
|
1011
1159
|
|
|
1012
1160
|
// src/document/walk-refs.ts
|
|
1013
|
-
var walkRefs = (node, visit) => {
|
|
1161
|
+
var walkRefs = /* @__PURE__ */ __name((node, visit) => {
|
|
1014
1162
|
if (node === null || typeof node !== "object") {
|
|
1015
1163
|
return;
|
|
1016
1164
|
}
|
|
@@ -1032,10 +1180,10 @@ var walkRefs = (node, visit) => {
|
|
|
1032
1180
|
}
|
|
1033
1181
|
walkRefs(value, visit);
|
|
1034
1182
|
}
|
|
1035
|
-
};
|
|
1183
|
+
}, "walkRefs");
|
|
1036
1184
|
|
|
1037
1185
|
// src/document/dangling-refs.ts
|
|
1038
|
-
var assertNoDanglingRefs = (params) => {
|
|
1186
|
+
var assertNoDanglingRefs = /* @__PURE__ */ __name((params) => {
|
|
1039
1187
|
const { doc, collected } = params;
|
|
1040
1188
|
const schemas = doc.components?.schemas ?? {};
|
|
1041
1189
|
const dangling = [];
|
|
@@ -1053,14 +1201,12 @@ var assertNoDanglingRefs = (params) => {
|
|
|
1053
1201
|
return;
|
|
1054
1202
|
}
|
|
1055
1203
|
const lines = dangling.map((ref) => ` - ${ref} \u2014 ${hintFor(ref, collected)}`);
|
|
1056
|
-
throw new ZodNestDocumentError(
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
};
|
|
1063
|
-
var hintFor = (ref, collected) => {
|
|
1204
|
+
throw new ZodNestDocumentError("DANGLING_REF", `Found ${dangling.length} \`$ref\` target(s) that don't resolve to a schema in \`components.schemas\`. The most common cause is a \`meta.id\` typo on a DTO, a DTO used without \`createZodDto\`, or a \`$ref\` left behind by a pre-pass that mutated the doc before \`applyZodNest\`.
|
|
1205
|
+
${lines.join("\n")}`, {
|
|
1206
|
+
dangling
|
|
1207
|
+
});
|
|
1208
|
+
}, "assertNoDanglingRefs");
|
|
1209
|
+
var hintFor = /* @__PURE__ */ __name((ref, collected) => {
|
|
1064
1210
|
const id = ref.slice(COMPONENTS_SCHEMAS_PREFIX.length);
|
|
1065
1211
|
const usedInput = collected.inputExposedIds.has(id);
|
|
1066
1212
|
const usedOutput = collected.outputExposedIds.has(id);
|
|
@@ -1074,28 +1220,23 @@ var hintFor = (ref, collected) => {
|
|
|
1074
1220
|
return "used as output but body missing \u2014 DTO is registered under a different id";
|
|
1075
1221
|
}
|
|
1076
1222
|
return "no DTO with this id was registered \u2014 check for a meta.id typo or a DTO used without createZodDto";
|
|
1077
|
-
};
|
|
1223
|
+
}, "hintFor");
|
|
1078
1224
|
|
|
1079
1225
|
// src/document/constants.ts
|
|
1080
1226
|
var OUTPUT_SUFFIX = "Output";
|
|
1081
1227
|
|
|
1082
1228
|
// src/document/merge-schemas.ts
|
|
1083
|
-
var mergeSchemas = (params) => {
|
|
1229
|
+
var mergeSchemas = /* @__PURE__ */ __name((params) => {
|
|
1084
1230
|
const { doc, inputSchemas, outputSchemas, collected, collisions } = params;
|
|
1085
1231
|
const schemas = ensureComponentsSchemas(doc);
|
|
1086
1232
|
const renames = /* @__PURE__ */ new Map();
|
|
1087
1233
|
const divergentOutputIds = /* @__PURE__ */ new Set();
|
|
1088
|
-
const exposedIds = /* @__PURE__ */ new Set([
|
|
1234
|
+
const exposedIds = /* @__PURE__ */ new Set([
|
|
1235
|
+
...collected.inputExposedIds,
|
|
1236
|
+
...collected.outputExposedIds
|
|
1237
|
+
]);
|
|
1089
1238
|
for (const id of exposedIds) {
|
|
1090
|
-
applyTruthTable(
|
|
1091
|
-
schemas,
|
|
1092
|
-
id,
|
|
1093
|
-
collected.inputExposedIds.has(id),
|
|
1094
|
-
collected.outputExposedIds.has(id),
|
|
1095
|
-
inputSchemas.get(id),
|
|
1096
|
-
outputSchemas.get(id),
|
|
1097
|
-
divergentOutputIds
|
|
1098
|
-
);
|
|
1239
|
+
applyTruthTable(schemas, id, collected.inputExposedIds.has(id), collected.outputExposedIds.has(id), inputSchemas.get(id), outputSchemas.get(id), divergentOutputIds);
|
|
1099
1240
|
}
|
|
1100
1241
|
for (const [className, dtoId] of collected.classToDtoId) {
|
|
1101
1242
|
if (className === dtoId) {
|
|
@@ -1105,16 +1246,19 @@ var mergeSchemas = (params) => {
|
|
|
1105
1246
|
delete schemas[className];
|
|
1106
1247
|
}
|
|
1107
1248
|
applyCollisionDecoration(schemas, collisions, divergentOutputIds);
|
|
1108
|
-
return {
|
|
1109
|
-
|
|
1110
|
-
|
|
1249
|
+
return {
|
|
1250
|
+
divergentOutputIds,
|
|
1251
|
+
renames
|
|
1252
|
+
};
|
|
1253
|
+
}, "mergeSchemas");
|
|
1254
|
+
var ensureComponentsSchemas = /* @__PURE__ */ __name((doc) => {
|
|
1111
1255
|
const components = doc.components ?? {};
|
|
1112
1256
|
doc.components = components;
|
|
1113
1257
|
const schemas = components.schemas ?? {};
|
|
1114
1258
|
components.schemas = schemas;
|
|
1115
1259
|
return schemas;
|
|
1116
|
-
};
|
|
1117
|
-
var applyTruthTable = (schemas, id, inputExposed, outputExposed, inputBody, outputBody, divergentOutputIds) => {
|
|
1260
|
+
}, "ensureComponentsSchemas");
|
|
1261
|
+
var applyTruthTable = /* @__PURE__ */ __name((schemas, id, inputExposed, outputExposed, inputBody, outputBody, divergentOutputIds) => {
|
|
1118
1262
|
if (inputExposed && !outputExposed) {
|
|
1119
1263
|
writeOrThrowAmbiguous(schemas, id, inputBody);
|
|
1120
1264
|
return;
|
|
@@ -1130,8 +1274,8 @@ var applyTruthTable = (schemas, id, inputExposed, outputExposed, inputBody, outp
|
|
|
1130
1274
|
writeOrThrowAmbiguous(schemas, id, inputBody);
|
|
1131
1275
|
writeOrThrowAmbiguous(schemas, `${id}${OUTPUT_SUFFIX}`, outputBody);
|
|
1132
1276
|
divergentOutputIds.add(id);
|
|
1133
|
-
};
|
|
1134
|
-
var writeOrThrowAmbiguous = (schemas, key, body) => {
|
|
1277
|
+
}, "applyTruthTable");
|
|
1278
|
+
var writeOrThrowAmbiguous = /* @__PURE__ */ __name((schemas, key, body) => {
|
|
1135
1279
|
if (body === void 0) {
|
|
1136
1280
|
return;
|
|
1137
1281
|
}
|
|
@@ -1140,13 +1284,11 @@ var writeOrThrowAmbiguous = (schemas, key, body) => {
|
|
|
1140
1284
|
schemas[key] = body;
|
|
1141
1285
|
return;
|
|
1142
1286
|
}
|
|
1143
|
-
throw new ZodNestDocumentError(
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
};
|
|
1149
|
-
var isMarkerPlaceholder = (value) => {
|
|
1287
|
+
throw new ZodNestDocumentError("AMBIGUOUS_RENAME", `Two distinct schemas target \`components.schemas[${key}]\` with differing bodies \u2014 multiple createZodDto classes likely share the same dtoId. Set distinct \`options.id\` values, or align the class names so renames are unambiguous.`, {
|
|
1288
|
+
key
|
|
1289
|
+
});
|
|
1290
|
+
}, "writeOrThrowAmbiguous");
|
|
1291
|
+
var isMarkerPlaceholder = /* @__PURE__ */ __name((value) => {
|
|
1150
1292
|
if (value === null || typeof value !== "object") {
|
|
1151
1293
|
return false;
|
|
1152
1294
|
}
|
|
@@ -1156,8 +1298,8 @@ var isMarkerPlaceholder = (value) => {
|
|
|
1156
1298
|
}
|
|
1157
1299
|
const marker = properties[ZOD_NEST_DTO_EXTENSION];
|
|
1158
1300
|
return isZodDtoMarker(marker);
|
|
1159
|
-
};
|
|
1160
|
-
var canonicalEqual = (a, b) => {
|
|
1301
|
+
}, "isMarkerPlaceholder");
|
|
1302
|
+
var canonicalEqual = /* @__PURE__ */ __name((a, b) => {
|
|
1161
1303
|
if (a === b) {
|
|
1162
1304
|
return true;
|
|
1163
1305
|
}
|
|
@@ -1165,16 +1307,16 @@ var canonicalEqual = (a, b) => {
|
|
|
1165
1307
|
return false;
|
|
1166
1308
|
}
|
|
1167
1309
|
return stringify__default.default(a) === stringify__default.default(b);
|
|
1168
|
-
};
|
|
1169
|
-
var applyCollisionDecoration = (schemas, collisions, divergentOutputIds) => {
|
|
1310
|
+
}, "canonicalEqual");
|
|
1311
|
+
var applyCollisionDecoration = /* @__PURE__ */ __name((schemas, collisions, divergentOutputIds) => {
|
|
1170
1312
|
for (const [id] of collisions) {
|
|
1171
1313
|
decorateIfPresent(schemas, id);
|
|
1172
1314
|
if (divergentOutputIds.has(id)) {
|
|
1173
1315
|
decorateIfPresent(schemas, `${id}${OUTPUT_SUFFIX}`);
|
|
1174
1316
|
}
|
|
1175
1317
|
}
|
|
1176
|
-
};
|
|
1177
|
-
var decorateIfPresent = (schemas, key) => {
|
|
1318
|
+
}, "applyCollisionDecoration");
|
|
1319
|
+
var decorateIfPresent = /* @__PURE__ */ __name((schemas, key) => {
|
|
1178
1320
|
if (!(key in schemas)) {
|
|
1179
1321
|
return;
|
|
1180
1322
|
}
|
|
@@ -1182,10 +1324,10 @@ var decorateIfPresent = (schemas, key) => {
|
|
|
1182
1324
|
description: `ERROR: duplicate zod-nest id <${key.replace(/Output$/, "")}>`,
|
|
1183
1325
|
[ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID
|
|
1184
1326
|
};
|
|
1185
|
-
};
|
|
1327
|
+
}, "decorateIfPresent");
|
|
1186
1328
|
|
|
1187
1329
|
// src/document/rewrite-refs.ts
|
|
1188
|
-
var rewriteRefs2 = (params) => {
|
|
1330
|
+
var rewriteRefs2 = /* @__PURE__ */ __name((params) => {
|
|
1189
1331
|
const { doc, renames, divergentOutputIds } = params;
|
|
1190
1332
|
if (renames.size > 0) {
|
|
1191
1333
|
walkRefs(doc, (ref) => {
|
|
@@ -1210,8 +1352,8 @@ var rewriteRefs2 = (params) => {
|
|
|
1210
1352
|
}
|
|
1211
1353
|
rewriteResponseSubtree(pathItem, divergentOutputIds);
|
|
1212
1354
|
}
|
|
1213
|
-
};
|
|
1214
|
-
var rewriteResponseSubtree = (pathItem, divergentOutputIds) => {
|
|
1355
|
+
}, "rewriteRefs");
|
|
1356
|
+
var rewriteResponseSubtree = /* @__PURE__ */ __name((pathItem, divergentOutputIds) => {
|
|
1215
1357
|
for (const method of HTTP_METHODS) {
|
|
1216
1358
|
const op = pathItem[method];
|
|
1217
1359
|
if (op === null || typeof op !== "object") {
|
|
@@ -1232,10 +1374,10 @@ var rewriteResponseSubtree = (pathItem, divergentOutputIds) => {
|
|
|
1232
1374
|
return `${COMPONENTS_SCHEMAS_PREFIX}${target}${OUTPUT_SUFFIX}`;
|
|
1233
1375
|
});
|
|
1234
1376
|
}
|
|
1235
|
-
};
|
|
1377
|
+
}, "rewriteResponseSubtree");
|
|
1236
1378
|
|
|
1237
1379
|
// src/document/strip-markers.ts
|
|
1238
|
-
var stripMarkers = (doc) => {
|
|
1380
|
+
var stripMarkers = /* @__PURE__ */ __name((doc) => {
|
|
1239
1381
|
const schemas = doc.components?.schemas;
|
|
1240
1382
|
if (schemas === void 0) {
|
|
1241
1383
|
return;
|
|
@@ -1243,8 +1385,8 @@ var stripMarkers = (doc) => {
|
|
|
1243
1385
|
for (const schema of Object.values(schemas)) {
|
|
1244
1386
|
stripMarkerFromSchema(schema);
|
|
1245
1387
|
}
|
|
1246
|
-
};
|
|
1247
|
-
var stripMarkerFromSchema = (schema) => {
|
|
1388
|
+
}, "stripMarkers");
|
|
1389
|
+
var stripMarkerFromSchema = /* @__PURE__ */ __name((schema) => {
|
|
1248
1390
|
if (schema === null || typeof schema !== "object") {
|
|
1249
1391
|
return;
|
|
1250
1392
|
}
|
|
@@ -1260,10 +1402,10 @@ var stripMarkerFromSchema = (schema) => {
|
|
|
1260
1402
|
if (Object.keys(props).length === 0) {
|
|
1261
1403
|
delete schema.properties;
|
|
1262
1404
|
}
|
|
1263
|
-
};
|
|
1405
|
+
}, "stripMarkerFromSchema");
|
|
1264
1406
|
|
|
1265
1407
|
// src/document/apply-zod-nest.ts
|
|
1266
|
-
var applyZodNest = (doc, opts) => {
|
|
1408
|
+
var applyZodNest = /* @__PURE__ */ __name((doc, opts) => {
|
|
1267
1409
|
const registry = opts.registry ?? defaultRegistry;
|
|
1268
1410
|
const collected = collectUsage(doc, opts.app);
|
|
1269
1411
|
const { inputSchemas, outputSchemas } = bulkEmit({
|
|
@@ -1278,11 +1420,18 @@ var applyZodNest = (doc, opts) => {
|
|
|
1278
1420
|
collected,
|
|
1279
1421
|
collisions: registry.getCollisions()
|
|
1280
1422
|
});
|
|
1281
|
-
rewriteRefs2({
|
|
1423
|
+
rewriteRefs2({
|
|
1424
|
+
doc,
|
|
1425
|
+
renames,
|
|
1426
|
+
divergentOutputIds
|
|
1427
|
+
});
|
|
1282
1428
|
stripMarkers(doc);
|
|
1283
|
-
assertNoDanglingRefs({
|
|
1429
|
+
assertNoDanglingRefs({
|
|
1430
|
+
doc,
|
|
1431
|
+
collected
|
|
1432
|
+
});
|
|
1284
1433
|
return doc;
|
|
1285
|
-
};
|
|
1434
|
+
}, "applyZodNest");
|
|
1286
1435
|
|
|
1287
1436
|
exports.COMPONENTS_SCHEMAS_PREFIX = COMPONENTS_SCHEMAS_PREFIX;
|
|
1288
1437
|
exports.DEFAULT_MAX_LOGGED_VALUE_BYTES = DEFAULT_MAX_LOGGED_VALUE_BYTES;
|