zod-nest 0.1.5 → 0.2.0
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.d.mts +70 -1
- package/dist/index.d.ts +70 -1
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,13 @@ declare const COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
|
7
7
|
declare const ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
|
|
8
8
|
/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */
|
|
9
9
|
declare const ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
|
|
10
|
+
/**
|
|
11
|
+
* OpenAPI extension key used by `createZodDto` to mark a class for Phase 2e's
|
|
12
|
+
* doc-merger. The marker carries `{ __zodNestDto: true, dtoId, io }` so the
|
|
13
|
+
* merger can locate every zod-nest DTO in the @nestjs/swagger document and
|
|
14
|
+
* inject the real Zod-derived schema.
|
|
15
|
+
*/
|
|
16
|
+
declare const ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
10
17
|
|
|
11
18
|
type SchemaObject = JSONSchema.BaseSchema;
|
|
12
19
|
|
|
@@ -24,6 +31,13 @@ interface ZodNestRegistry {
|
|
|
24
31
|
getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;
|
|
25
32
|
}
|
|
26
33
|
declare const createRegistry: () => ZodNestRegistry;
|
|
34
|
+
/**
|
|
35
|
+
* Process-wide default registry. `createZodDto` registers schemas here unless
|
|
36
|
+
* the caller passes `options.registry`. Phase 2e's doc merger reads from the
|
|
37
|
+
* same instance for bulk emission. Multi-app WeakMap isolation is deferred
|
|
38
|
+
* to v0.2.
|
|
39
|
+
*/
|
|
40
|
+
declare const defaultRegistry: ZodNestRegistry;
|
|
27
41
|
|
|
28
42
|
interface ToOpenApiOptions {
|
|
29
43
|
io: 'input' | 'output';
|
|
@@ -46,4 +60,59 @@ declare class ZodNestUnrepresentableError extends ZodNestError {
|
|
|
46
60
|
constructor(path: ReadonlyArray<string | number>, zodType: string);
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Runtime detection marker placed on every class returned by `createZodDto`.
|
|
65
|
+
* Used by the validation pipe (Phase 2c), serializer (2d), and doc merger (2e)
|
|
66
|
+
* to discriminate zod-nest DTO classes from regular constructors.
|
|
67
|
+
*/
|
|
68
|
+
declare const ZOD_DTO_SYMBOL: unique symbol;
|
|
69
|
+
|
|
70
|
+
type Io = 'input' | 'output';
|
|
71
|
+
interface CreateZodDtoOptions {
|
|
72
|
+
/** Explicit id override. Highest precedence in id resolution. */
|
|
73
|
+
id?: string;
|
|
74
|
+
/** Registry to register this DTO's schema into. Defaults to `defaultRegistry`. */
|
|
75
|
+
registry?: ZodNestRegistry;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The class type returned by `createZodDto`. Instance type infers to the
|
|
79
|
+
* Zod output type so handler args typed as the DTO get the inferred shape.
|
|
80
|
+
*/
|
|
81
|
+
interface ZodDto<TSchema extends z.ZodType = z.ZodType> {
|
|
82
|
+
new (): z.infer<TSchema>;
|
|
83
|
+
readonly schema: TSchema;
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly io: Io;
|
|
86
|
+
readonly Output: ZodDto<TSchema>;
|
|
87
|
+
parse(input: unknown): z.infer<TSchema>;
|
|
88
|
+
safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>>;
|
|
89
|
+
_OPENAPI_METADATA_FACTORY(): Record<string, unknown>;
|
|
90
|
+
readonly [ZOD_DTO_SYMBOL]: true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare const createZodDto: <TSchema extends z.ZodType>(schema: TSchema, options?: CreateZodDtoOptions) => ZodDto<TSchema>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Payload of the `x-zod-nest-dto` placeholder property that
|
|
97
|
+
* `_OPENAPI_METADATA_FACTORY` returns. Phase 2e's doc merger reads this off
|
|
98
|
+
* each `components.schemas.<DtoName>.properties[x-zod-nest-dto]` entry,
|
|
99
|
+
* uses `dtoId` to look up the schema in the registry, and replaces the
|
|
100
|
+
* synthetic schema body with the real Zod-derived schema.
|
|
101
|
+
*
|
|
102
|
+
* `type` and `required` are benign filler that satisfy @nestjs/swagger's
|
|
103
|
+
* property-type guard (without them, the explorer throws "A circular
|
|
104
|
+
* dependency has been detected"). They have no semantic meaning and are
|
|
105
|
+
* stripped along with the rest of the marker by Phase 2e.
|
|
106
|
+
*/
|
|
107
|
+
interface ZodDtoMarker {
|
|
108
|
+
readonly type: () => typeof Object;
|
|
109
|
+
readonly required: false;
|
|
110
|
+
readonly __zodNestDto: true;
|
|
111
|
+
readonly dtoId: string;
|
|
112
|
+
readonly io: Io;
|
|
113
|
+
}
|
|
114
|
+
declare const makeZodDtoMarker: (dtoId: string, io: Io) => ZodDtoMarker;
|
|
115
|
+
/** Phase 2e (and tests) use this to discriminate a marker from a real schema. */
|
|
116
|
+
declare const isZodDtoMarker: (value: unknown) => value is ZodDtoMarker;
|
|
117
|
+
|
|
118
|
+
export { COMPONENTS_SCHEMAS_PREFIX, type CreateZodDtoOptions, type Io, type Override, type OverrideContext, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, type ZodDto, type ZodDtoMarker, ZodNestError, type ZodNestRegistry, ZodNestUnrepresentableError, createRegistry, createZodDto, defaultRegistry, isZodDtoMarker, makeZodDtoMarker, toOpenApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ declare const COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
|
7
7
|
declare const ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
|
|
8
8
|
/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */
|
|
9
9
|
declare const ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
|
|
10
|
+
/**
|
|
11
|
+
* OpenAPI extension key used by `createZodDto` to mark a class for Phase 2e's
|
|
12
|
+
* doc-merger. The marker carries `{ __zodNestDto: true, dtoId, io }` so the
|
|
13
|
+
* merger can locate every zod-nest DTO in the @nestjs/swagger document and
|
|
14
|
+
* inject the real Zod-derived schema.
|
|
15
|
+
*/
|
|
16
|
+
declare const ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
10
17
|
|
|
11
18
|
type SchemaObject = JSONSchema.BaseSchema;
|
|
12
19
|
|
|
@@ -24,6 +31,13 @@ interface ZodNestRegistry {
|
|
|
24
31
|
getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;
|
|
25
32
|
}
|
|
26
33
|
declare const createRegistry: () => ZodNestRegistry;
|
|
34
|
+
/**
|
|
35
|
+
* Process-wide default registry. `createZodDto` registers schemas here unless
|
|
36
|
+
* the caller passes `options.registry`. Phase 2e's doc merger reads from the
|
|
37
|
+
* same instance for bulk emission. Multi-app WeakMap isolation is deferred
|
|
38
|
+
* to v0.2.
|
|
39
|
+
*/
|
|
40
|
+
declare const defaultRegistry: ZodNestRegistry;
|
|
27
41
|
|
|
28
42
|
interface ToOpenApiOptions {
|
|
29
43
|
io: 'input' | 'output';
|
|
@@ -46,4 +60,59 @@ declare class ZodNestUnrepresentableError extends ZodNestError {
|
|
|
46
60
|
constructor(path: ReadonlyArray<string | number>, zodType: string);
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Runtime detection marker placed on every class returned by `createZodDto`.
|
|
65
|
+
* Used by the validation pipe (Phase 2c), serializer (2d), and doc merger (2e)
|
|
66
|
+
* to discriminate zod-nest DTO classes from regular constructors.
|
|
67
|
+
*/
|
|
68
|
+
declare const ZOD_DTO_SYMBOL: unique symbol;
|
|
69
|
+
|
|
70
|
+
type Io = 'input' | 'output';
|
|
71
|
+
interface CreateZodDtoOptions {
|
|
72
|
+
/** Explicit id override. Highest precedence in id resolution. */
|
|
73
|
+
id?: string;
|
|
74
|
+
/** Registry to register this DTO's schema into. Defaults to `defaultRegistry`. */
|
|
75
|
+
registry?: ZodNestRegistry;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The class type returned by `createZodDto`. Instance type infers to the
|
|
79
|
+
* Zod output type so handler args typed as the DTO get the inferred shape.
|
|
80
|
+
*/
|
|
81
|
+
interface ZodDto<TSchema extends z.ZodType = z.ZodType> {
|
|
82
|
+
new (): z.infer<TSchema>;
|
|
83
|
+
readonly schema: TSchema;
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly io: Io;
|
|
86
|
+
readonly Output: ZodDto<TSchema>;
|
|
87
|
+
parse(input: unknown): z.infer<TSchema>;
|
|
88
|
+
safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>>;
|
|
89
|
+
_OPENAPI_METADATA_FACTORY(): Record<string, unknown>;
|
|
90
|
+
readonly [ZOD_DTO_SYMBOL]: true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare const createZodDto: <TSchema extends z.ZodType>(schema: TSchema, options?: CreateZodDtoOptions) => ZodDto<TSchema>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Payload of the `x-zod-nest-dto` placeholder property that
|
|
97
|
+
* `_OPENAPI_METADATA_FACTORY` returns. Phase 2e's doc merger reads this off
|
|
98
|
+
* each `components.schemas.<DtoName>.properties[x-zod-nest-dto]` entry,
|
|
99
|
+
* uses `dtoId` to look up the schema in the registry, and replaces the
|
|
100
|
+
* synthetic schema body with the real Zod-derived schema.
|
|
101
|
+
*
|
|
102
|
+
* `type` and `required` are benign filler that satisfy @nestjs/swagger's
|
|
103
|
+
* property-type guard (without them, the explorer throws "A circular
|
|
104
|
+
* dependency has been detected"). They have no semantic meaning and are
|
|
105
|
+
* stripped along with the rest of the marker by Phase 2e.
|
|
106
|
+
*/
|
|
107
|
+
interface ZodDtoMarker {
|
|
108
|
+
readonly type: () => typeof Object;
|
|
109
|
+
readonly required: false;
|
|
110
|
+
readonly __zodNestDto: true;
|
|
111
|
+
readonly dtoId: string;
|
|
112
|
+
readonly io: Io;
|
|
113
|
+
}
|
|
114
|
+
declare const makeZodDtoMarker: (dtoId: string, io: Io) => ZodDtoMarker;
|
|
115
|
+
/** Phase 2e (and tests) use this to discriminate a marker from a real schema. */
|
|
116
|
+
declare const isZodDtoMarker: (value: unknown) => value is ZodDtoMarker;
|
|
117
|
+
|
|
118
|
+
export { COMPONENTS_SCHEMAS_PREFIX, type CreateZodDtoOptions, type Io, type Override, type OverrideContext, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, type ZodDto, type ZodDtoMarker, ZodNestError, type ZodNestRegistry, ZodNestUnrepresentableError, createRegistry, createZodDto, defaultRegistry, isZodDtoMarker, makeZodDtoMarker, toOpenApi };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var zod = require('zod');
|
|
|
6
6
|
var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
7
7
|
var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
|
|
8
8
|
var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
|
|
9
|
+
var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
9
10
|
|
|
10
11
|
// src/schema/errors.ts
|
|
11
12
|
var ZodNestError = class extends Error {
|
|
@@ -192,13 +193,132 @@ var createRegistry = () => {
|
|
|
192
193
|
}
|
|
193
194
|
};
|
|
194
195
|
};
|
|
196
|
+
var defaultRegistry = createRegistry();
|
|
197
|
+
|
|
198
|
+
// src/dto/marker.ts
|
|
199
|
+
var makeZodDtoMarker = (dtoId, io) => ({
|
|
200
|
+
type: () => Object,
|
|
201
|
+
required: false,
|
|
202
|
+
__zodNestDto: true,
|
|
203
|
+
dtoId,
|
|
204
|
+
io
|
|
205
|
+
});
|
|
206
|
+
var isZodDtoMarker = (value) => {
|
|
207
|
+
if (value === null || typeof value !== "object") {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return value.__zodNestDto === true;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/dto/symbols.ts
|
|
214
|
+
var ZOD_DTO_SYMBOL = /* @__PURE__ */ Symbol.for("zod-nest.dto");
|
|
215
|
+
|
|
216
|
+
// src/dto/output-dto.ts
|
|
217
|
+
var outputCache = /* @__PURE__ */ new WeakMap();
|
|
218
|
+
var buildSiblingClass = (parent, schema) => {
|
|
219
|
+
const SiblingClass = class {
|
|
220
|
+
static schema = schema;
|
|
221
|
+
static io = "output";
|
|
222
|
+
static [ZOD_DTO_SYMBOL] = true;
|
|
223
|
+
static get id() {
|
|
224
|
+
return parent.id;
|
|
225
|
+
}
|
|
226
|
+
static get Output() {
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
static parse(input) {
|
|
230
|
+
return schema.parse(input);
|
|
231
|
+
}
|
|
232
|
+
static safeParse(input) {
|
|
233
|
+
return schema.safeParse(input);
|
|
234
|
+
}
|
|
235
|
+
static _OPENAPI_METADATA_FACTORY() {
|
|
236
|
+
return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(parent.id, "output") };
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return SiblingClass;
|
|
240
|
+
};
|
|
241
|
+
var resolveOutput = (parent, schema) => {
|
|
242
|
+
const cached = outputCache.get(parent);
|
|
243
|
+
if (cached !== void 0) {
|
|
244
|
+
return cached;
|
|
245
|
+
}
|
|
246
|
+
const sibling = buildSiblingClass(parent, schema);
|
|
247
|
+
outputCache.set(parent, sibling);
|
|
248
|
+
return sibling;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// src/dto/create-zod-dto.ts
|
|
252
|
+
var anonCounter = 0;
|
|
253
|
+
var warnedOnAnonymous = false;
|
|
254
|
+
var resolveId = (registry, schema, providedId, className) => {
|
|
255
|
+
if (providedId !== void 0 && providedId !== "") {
|
|
256
|
+
return providedId;
|
|
257
|
+
}
|
|
258
|
+
const meta = registry.zodRegistry.get(schema);
|
|
259
|
+
if (meta && typeof meta.id === "string" && meta.id !== "") {
|
|
260
|
+
return meta.id;
|
|
261
|
+
}
|
|
262
|
+
if (className !== "" && className.length > 1) {
|
|
263
|
+
return className;
|
|
264
|
+
}
|
|
265
|
+
anonCounter += 1;
|
|
266
|
+
const fallback = `_AnonZodDto_${anonCounter}`;
|
|
267
|
+
if (!warnedOnAnonymous) {
|
|
268
|
+
warnedOnAnonymous = true;
|
|
269
|
+
console.warn(
|
|
270
|
+
`[zod-nest] Could not resolve a DTO id from class name (got "${className}"). Using "${fallback}". Pass \`createZodDto(schema, { id: 'Foo' })\` to set a stable name \u2014 important under minification, where class names become single mangled characters.`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return fallback;
|
|
274
|
+
};
|
|
275
|
+
var createZodDto = (schema, options) => {
|
|
276
|
+
const registry = options?.registry ?? defaultRegistry;
|
|
277
|
+
const io = "input";
|
|
278
|
+
let cachedId;
|
|
279
|
+
const ensureRegistered = (className) => {
|
|
280
|
+
if (cachedId !== void 0) {
|
|
281
|
+
return cachedId;
|
|
282
|
+
}
|
|
283
|
+
cachedId = resolveId(registry, schema, options?.id, className);
|
|
284
|
+
registry.register(schema, cachedId);
|
|
285
|
+
return cachedId;
|
|
286
|
+
};
|
|
287
|
+
const ZodDtoBase = class {
|
|
288
|
+
static schema = schema;
|
|
289
|
+
static io = io;
|
|
290
|
+
static [ZOD_DTO_SYMBOL] = true;
|
|
291
|
+
static get id() {
|
|
292
|
+
return ensureRegistered(this.name);
|
|
293
|
+
}
|
|
294
|
+
static get Output() {
|
|
295
|
+
return resolveOutput(this, schema);
|
|
296
|
+
}
|
|
297
|
+
static parse(input) {
|
|
298
|
+
return schema.parse(input);
|
|
299
|
+
}
|
|
300
|
+
static safeParse(input) {
|
|
301
|
+
return schema.safeParse(input);
|
|
302
|
+
}
|
|
303
|
+
static _OPENAPI_METADATA_FACTORY() {
|
|
304
|
+
return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(ensureRegistered(this.name), io) };
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
return ZodDtoBase;
|
|
308
|
+
};
|
|
195
309
|
|
|
196
310
|
exports.COMPONENTS_SCHEMAS_PREFIX = COMPONENTS_SCHEMAS_PREFIX;
|
|
311
|
+
exports.ZOD_DTO_SYMBOL = ZOD_DTO_SYMBOL;
|
|
312
|
+
exports.ZOD_NEST_DTO_EXTENSION = ZOD_NEST_DTO_EXTENSION;
|
|
197
313
|
exports.ZOD_NEST_ERROR_DUPLICATE_ID = ZOD_NEST_ERROR_DUPLICATE_ID;
|
|
198
314
|
exports.ZOD_NEST_ERROR_EXTENSION = ZOD_NEST_ERROR_EXTENSION;
|
|
199
315
|
exports.ZodNestError = ZodNestError;
|
|
200
316
|
exports.ZodNestUnrepresentableError = ZodNestUnrepresentableError;
|
|
201
317
|
exports.createRegistry = createRegistry;
|
|
318
|
+
exports.createZodDto = createZodDto;
|
|
319
|
+
exports.defaultRegistry = defaultRegistry;
|
|
320
|
+
exports.isZodDtoMarker = isZodDtoMarker;
|
|
321
|
+
exports.makeZodDtoMarker = makeZodDtoMarker;
|
|
202
322
|
exports.toOpenApi = toOpenApi;
|
|
203
323
|
//# sourceMappingURL=index.js.map
|
|
204
324
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema/constants.ts","../src/schema/errors.ts","../src/schema/override.ts","../src/schema/post-process.ts","../src/schema/engine.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AAO,GAAA,KAAQ,MAAA,IAAa,GAAA,CAAI,IAAA,GAAO,CAAA;AAAA,IACzC,CAAA;AAAA,IACA,eAAe,MAAM;AACnB,MAAA,MAAM,GAAA,uBAAU,GAAA,EAA4B;AAC5C,MAAA,KAAA,MAAW,CAAC,EAAA,EAAI,GAAG,CAAA,IAAK,IAAA,EAAM;AAC5B,QAAA,IAAI,GAAA,CAAI,QAAQ,CAAA,EAAG;AACjB,UAAA;AAAA,QACF;AACA,QAAA,GAAA,CAAI,GAAA,CAAI,IAAI,GAAG,CAAA;AAAA,MACjB;AACA,MAAA,OAAO,GAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/** OpenAPI 3.1 `$ref` prefix for entries in `components.schemas`. */\nexport const COMPONENTS_SCHEMAS_PREFIX = '#/components/schemas/';\n\n/** OpenAPI extension key zod-nest uses to surface engine errors inside emitted schemas. */\nexport const ZOD_NEST_ERROR_EXTENSION = 'x-zod-nest-error';\n\n/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */\nexport const ZOD_NEST_ERROR_DUPLICATE_ID = 'duplicate-id';\n","export class ZodNestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ZodNestError';\n }\n}\n\nexport class ZodNestUnrepresentableError extends ZodNestError {\n readonly path: ReadonlyArray<string | number>;\n readonly zodType: string;\n\n constructor(path: ReadonlyArray<string | number>, zodType: string) {\n super(\n `Unrepresentable Zod schema \\`${zodType}\\` at ${formatPath(path)}: no override produced ` +\n `a JSON Schema body. Set strict: false to emit \\`{}\\` instead, or supply an \\`override\\` ` +\n `that handles this Zod type.`,\n );\n this.name = 'ZodNestUnrepresentableError';\n this.path = path;\n this.zodType = zodType;\n }\n}\n\nconst formatPath = (path: ReadonlyArray<string | number>): string => {\n if (path.length === 0) {\n return '<root>';\n }\n return '/' + path.map(String).join('/');\n};\n","import type { $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\n\nexport interface OverrideContext {\n zodSchema: $ZodTypes;\n jsonSchema: SchemaObject;\n path: (string | number)[];\n}\n\nexport type Override = (ctx: OverrideContext) => void;\n\nexport const builtInOverride: Override = ({ zodSchema, jsonSchema }) => {\n const type = zodSchema._zod.def.type;\n if (type === 'bigint') {\n jsonSchema.type = 'integer';\n return;\n }\n if (type === 'date') {\n jsonSchema.type = 'string';\n jsonSchema.format = 'date-time';\n return;\n }\n};\n\nconst STRICT_REQUIRES_OVERRIDE: ReadonlySet<string> = new Set([\n 'bigint',\n 'date',\n 'symbol',\n 'undefined',\n 'void',\n 'map',\n 'set',\n 'transform',\n 'nan',\n 'custom',\n]);\n\nexport const isStrictlyUnrepresentable = (\n jsonSchema: SchemaObject,\n zodSchema: $ZodTypes,\n): boolean => {\n if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {\n return false;\n }\n return Object.keys(jsonSchema).length === 0;\n};\n\nexport const combine = (...overrides: ReadonlyArray<Override | undefined>): Override => {\n const list: Override[] = [];\n for (const candidate of overrides) {\n if (typeof candidate !== 'function') {\n continue;\n }\n list.push(candidate);\n }\n if (list.length === 0) {\n return () => undefined;\n }\n return (ctx) => {\n for (const o of list) {\n o(ctx);\n }\n };\n};\n","import type { SchemaObject } from './openapi.types.js';\n\nimport { COMPONENTS_SCHEMAS_PREFIX } from './constants.js';\n\nexport interface PostProcessResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\nconst DEFS_PREFIX = '#/$defs/';\n\nconst rewriteRefs = (node: unknown, selfRef: string | undefined): void => {\n if (Array.isArray(node)) {\n for (const item of node) {\n rewriteRefs(item, selfRef);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string' && ref.startsWith(DEFS_PREFIX)) {\n obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);\n } else if (ref === '#' && selfRef !== undefined) {\n // Zod emits '#' for cycle refs back to the document root. When we lift a\n // named schema into its own components.schemas entry, '#' should resolve\n // to that entry's own URI.\n obj.$ref = selfRef;\n }\n for (const value of Object.values(obj)) {\n rewriteRefs(value, selfRef);\n }\n};\n\nexport const postProcess = (raw: SchemaObject): PostProcessResult => {\n const refs = new Map<string, SchemaObject>();\n const rawDefs = raw.$defs;\n if (rawDefs !== undefined) {\n for (const [id, body] of Object.entries(rawDefs)) {\n refs.set(id, body);\n }\n }\n\n const root: SchemaObject = { ...raw };\n delete root.$schema;\n delete root.$defs;\n\n // Root has no own self-uri at the 2a level. If the root is a bare `$ref` to a\n // lifted named schema (the common case when input itself has `.meta({ id })`),\n // we'll have already rewritten it to '#/components/schemas/<id>'.\n rewriteRefs(root, undefined);\n\n for (const [id, body] of refs) {\n rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);\n }\n\n return { schema: root, refs };\n};\n","import { z } from 'zod';\n\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './constants.js';\nimport { ZodNestUnrepresentableError } from './errors.js';\nimport { builtInOverride, combine, isStrictlyUnrepresentable } from './override.js';\nimport { postProcess } from './post-process.js';\n\nexport interface ToOpenApiOptions {\n io: 'input' | 'output';\n registry: ZodNestRegistry;\n override?: Override;\n strict?: boolean;\n}\n\nexport interface ToOpenApiResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\ninterface UnrepresentableHit {\n path: (string | number)[];\n zodType: string;\n}\n\nexport const toOpenApi = (schema: z.ZodType, opts: ToOpenApiOptions): ToOpenApiResult => {\n const strict = opts.strict ?? true;\n const merged = combine(builtInOverride, opts.override);\n const unrepresentableHits: UnrepresentableHit[] = [];\n\n const wrapped: Override = (ctx) => {\n merged(ctx);\n if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {\n return;\n }\n unrepresentableHits.push({\n path: [...ctx.path],\n zodType: ctx.zodSchema._zod.def.type,\n });\n };\n\n const raw = z.toJSONSchema(schema, {\n target: 'draft-2020-12',\n io: opts.io,\n unrepresentable: 'any',\n metadata: opts.registry.zodRegistry,\n override: wrapped,\n cycles: 'ref',\n reused: 'inline',\n });\n\n const firstHit = unrepresentableHits[0];\n if (firstHit !== undefined) {\n throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);\n }\n\n const result = postProcess(raw);\n\n for (const [id] of opts.registry.getCollisions()) {\n if (!result.refs.has(id)) {\n continue;\n }\n result.refs.set(id, {\n description: `ERROR: duplicate zod-nest id <${id}>`,\n [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID,\n });\n }\n\n return result;\n};\n","import { z } from 'zod';\n\nexport interface ZodNestRegistry {\n readonly zodRegistry: typeof z.globalRegistry;\n register(schema: z.ZodType, id: string): void;\n hasCollision(id: string): boolean;\n getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;\n}\n\nexport const createRegistry = (): ZodNestRegistry => {\n const seen = new Map<string, Set<z.ZodType>>();\n\n return {\n zodRegistry: z.globalRegistry,\n register: (schema, id) => {\n z.globalRegistry.add(schema, { id });\n let set = seen.get(id);\n if (set === undefined) {\n set = new Set<z.ZodType>();\n seen.set(id, set);\n }\n set.add(schema);\n },\n hasCollision: (id) => {\n const set = seen.get(id);\n return set !== undefined && set.size > 1;\n },\n getCollisions: () => {\n const out = new Map<string, Set<z.ZodType>>();\n for (const [id, set] of seen) {\n if (set.size <= 1) {\n continue;\n }\n out.set(id, set);\n }\n return out;\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/schema/constants.ts","../src/schema/errors.ts","../src/schema/override.ts","../src/schema/post-process.ts","../src/schema/engine.ts","../src/schema/registry.ts","../src/dto/marker.ts","../src/dto/symbols.ts","../src/dto/output-dto.ts","../src/dto/create-zod-dto.ts"],"names":["z"],"mappings":";;;;;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ACjE;AAAA,IAEA,OAAO,MAAM,KAAA,EAAkC;AAC7C,MAAA,OAAO,MAAA,CAAO,MAAM,KAAK,CAAA;AAAA,IAC3B;AAAA,IAEA,OAAO,UAAU,KAAA,EAAwD;AACvE,MAAA,OAAO,MAAA,CAAO,UAAU,KAAK,CAAA;AAAA,IAC/B;AAAA,IAEA,OAAO,yBAAA,GAAqD;AAC1D,MAAA,OAAO,EAAE,CAAC,sBAAsB,GAAG,gBAAA,CAAiB,iBAAiB,IAAA,CAAK,IAAI,CAAA,EAAG,EAAE,CAAA,EAAE;AAAA,IACvF;AAAA,GACF;AAEA,EAAA,OAAO,UAAA;AACT","file":"index.js","sourcesContent":["/** OpenAPI 3.1 `$ref` prefix for entries in `components.schemas`. */\nexport const COMPONENTS_SCHEMAS_PREFIX = '#/components/schemas/';\n\n/** OpenAPI extension key zod-nest uses to surface engine errors inside emitted schemas. */\nexport const ZOD_NEST_ERROR_EXTENSION = 'x-zod-nest-error';\n\n/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */\nexport const ZOD_NEST_ERROR_DUPLICATE_ID = 'duplicate-id';\n\n/**\n * OpenAPI extension key used by `createZodDto` to mark a class for Phase 2e's\n * doc-merger. The marker carries `{ __zodNestDto: true, dtoId, io }` so the\n * merger can locate every zod-nest DTO in the @nestjs/swagger document and\n * inject the real Zod-derived schema.\n */\nexport const ZOD_NEST_DTO_EXTENSION = 'x-zod-nest-dto';\n","export class ZodNestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ZodNestError';\n }\n}\n\nexport class ZodNestUnrepresentableError extends ZodNestError {\n readonly path: ReadonlyArray<string | number>;\n readonly zodType: string;\n\n constructor(path: ReadonlyArray<string | number>, zodType: string) {\n super(\n `Unrepresentable Zod schema \\`${zodType}\\` at ${formatPath(path)}: no override produced ` +\n `a JSON Schema body. Set strict: false to emit \\`{}\\` instead, or supply an \\`override\\` ` +\n `that handles this Zod type.`,\n );\n this.name = 'ZodNestUnrepresentableError';\n this.path = path;\n this.zodType = zodType;\n }\n}\n\nconst formatPath = (path: ReadonlyArray<string | number>): string => {\n if (path.length === 0) {\n return '<root>';\n }\n return '/' + path.map(String).join('/');\n};\n","import type { $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\n\nexport interface OverrideContext {\n zodSchema: $ZodTypes;\n jsonSchema: SchemaObject;\n path: (string | number)[];\n}\n\nexport type Override = (ctx: OverrideContext) => void;\n\nexport const builtInOverride: Override = ({ zodSchema, jsonSchema }) => {\n const type = zodSchema._zod.def.type;\n if (type === 'bigint') {\n jsonSchema.type = 'integer';\n return;\n }\n if (type === 'date') {\n jsonSchema.type = 'string';\n jsonSchema.format = 'date-time';\n return;\n }\n};\n\nconst STRICT_REQUIRES_OVERRIDE: ReadonlySet<string> = new Set([\n 'bigint',\n 'date',\n 'symbol',\n 'undefined',\n 'void',\n 'map',\n 'set',\n 'transform',\n 'nan',\n 'custom',\n]);\n\nexport const isStrictlyUnrepresentable = (\n jsonSchema: SchemaObject,\n zodSchema: $ZodTypes,\n): boolean => {\n if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {\n return false;\n }\n return Object.keys(jsonSchema).length === 0;\n};\n\nexport const combine = (...overrides: ReadonlyArray<Override | undefined>): Override => {\n const list: Override[] = [];\n for (const candidate of overrides) {\n if (typeof candidate !== 'function') {\n continue;\n }\n list.push(candidate);\n }\n if (list.length === 0) {\n return () => undefined;\n }\n return (ctx) => {\n for (const o of list) {\n o(ctx);\n }\n };\n};\n","import type { SchemaObject } from './openapi.types.js';\n\nimport { COMPONENTS_SCHEMAS_PREFIX } from './constants.js';\n\nexport interface PostProcessResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\nconst DEFS_PREFIX = '#/$defs/';\n\nconst rewriteRefs = (node: unknown, selfRef: string | undefined): void => {\n if (Array.isArray(node)) {\n for (const item of node) {\n rewriteRefs(item, selfRef);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string' && ref.startsWith(DEFS_PREFIX)) {\n obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);\n } else if (ref === '#' && selfRef !== undefined) {\n // Zod emits '#' for cycle refs back to the document root. When we lift a\n // named schema into its own components.schemas entry, '#' should resolve\n // to that entry's own URI.\n obj.$ref = selfRef;\n }\n for (const value of Object.values(obj)) {\n rewriteRefs(value, selfRef);\n }\n};\n\nexport const postProcess = (raw: SchemaObject): PostProcessResult => {\n const refs = new Map<string, SchemaObject>();\n const rawDefs = raw.$defs;\n if (rawDefs !== undefined) {\n for (const [id, body] of Object.entries(rawDefs)) {\n refs.set(id, body);\n }\n }\n\n const root: SchemaObject = { ...raw };\n delete root.$schema;\n delete root.$defs;\n\n // Root has no own self-uri at the 2a level. If the root is a bare `$ref` to a\n // lifted named schema (the common case when input itself has `.meta({ id })`),\n // we'll have already rewritten it to '#/components/schemas/<id>'.\n rewriteRefs(root, undefined);\n\n for (const [id, body] of refs) {\n rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);\n }\n\n return { schema: root, refs };\n};\n","import { z } from 'zod';\n\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './constants.js';\nimport { ZodNestUnrepresentableError } from './errors.js';\nimport { builtInOverride, combine, isStrictlyUnrepresentable } from './override.js';\nimport { postProcess } from './post-process.js';\n\nexport interface ToOpenApiOptions {\n io: 'input' | 'output';\n registry: ZodNestRegistry;\n override?: Override;\n strict?: boolean;\n}\n\nexport interface ToOpenApiResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\ninterface UnrepresentableHit {\n path: (string | number)[];\n zodType: string;\n}\n\nexport const toOpenApi = (schema: z.ZodType, opts: ToOpenApiOptions): ToOpenApiResult => {\n const strict = opts.strict ?? true;\n const merged = combine(builtInOverride, opts.override);\n const unrepresentableHits: UnrepresentableHit[] = [];\n\n const wrapped: Override = (ctx) => {\n merged(ctx);\n if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {\n return;\n }\n unrepresentableHits.push({\n path: [...ctx.path],\n zodType: ctx.zodSchema._zod.def.type,\n });\n };\n\n const raw = z.toJSONSchema(schema, {\n target: 'draft-2020-12',\n io: opts.io,\n unrepresentable: 'any',\n metadata: opts.registry.zodRegistry,\n override: wrapped,\n cycles: 'ref',\n reused: 'inline',\n });\n\n const firstHit = unrepresentableHits[0];\n if (firstHit !== undefined) {\n throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);\n }\n\n const result = postProcess(raw);\n\n for (const [id] of opts.registry.getCollisions()) {\n if (!result.refs.has(id)) {\n continue;\n }\n result.refs.set(id, {\n description: `ERROR: duplicate zod-nest id <${id}>`,\n [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID,\n });\n }\n\n return result;\n};\n","import { z } from 'zod';\n\nexport interface ZodNestRegistry {\n readonly zodRegistry: typeof z.globalRegistry;\n register(schema: z.ZodType, id: string): void;\n hasCollision(id: string): boolean;\n getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;\n}\n\nexport const createRegistry = (): ZodNestRegistry => {\n const seen = new Map<string, Set<z.ZodType>>();\n\n return {\n zodRegistry: z.globalRegistry,\n register: (schema, id) => {\n z.globalRegistry.add(schema, { id });\n let set = seen.get(id);\n if (set === undefined) {\n set = new Set<z.ZodType>();\n seen.set(id, set);\n }\n set.add(schema);\n },\n hasCollision: (id) => {\n const set = seen.get(id);\n return set !== undefined && set.size > 1;\n },\n getCollisions: () => {\n const out = new Map<string, Set<z.ZodType>>();\n for (const [id, set] of seen) {\n if (set.size <= 1) {\n continue;\n }\n out.set(id, set);\n }\n return out;\n },\n };\n};\n\n/**\n * Process-wide default registry. `createZodDto` registers schemas here unless\n * the caller passes `options.registry`. Phase 2e's doc merger reads from the\n * same instance for bulk emission. Multi-app WeakMap isolation is deferred\n * to v0.2.\n */\nexport const defaultRegistry: ZodNestRegistry = createRegistry();\n","import type { Io } from './dto.types.js';\n\n/**\n * Payload of the `x-zod-nest-dto` placeholder property that\n * `_OPENAPI_METADATA_FACTORY` returns. Phase 2e's doc merger reads this off\n * each `components.schemas.<DtoName>.properties[x-zod-nest-dto]` entry,\n * uses `dtoId` to look up the schema in the registry, and replaces the\n * synthetic schema body with the real Zod-derived schema.\n *\n * `type` and `required` are benign filler that satisfy @nestjs/swagger's\n * property-type guard (without them, the explorer throws \"A circular\n * dependency has been detected\"). They have no semantic meaning and are\n * stripped along with the rest of the marker by Phase 2e.\n */\nexport interface ZodDtoMarker {\n readonly type: () => typeof Object;\n readonly required: false;\n readonly __zodNestDto: true;\n readonly dtoId: string;\n readonly io: Io;\n}\n\nexport const makeZodDtoMarker = (dtoId: string, io: Io): ZodDtoMarker => ({\n type: () => Object,\n required: false,\n __zodNestDto: true,\n dtoId,\n io,\n});\n\n/** Phase 2e (and tests) use this to discriminate a marker from a real schema. */\nexport const isZodDtoMarker = (value: unknown): value is ZodDtoMarker => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n return (value as { __zodNestDto?: unknown }).__zodNestDto === true;\n};\n","/**\n * Runtime detection marker placed on every class returned by `createZodDto`.\n * Used by the validation pipe (Phase 2c), serializer (2d), and doc merger (2e)\n * to discriminate zod-nest DTO classes from regular constructors.\n */\nexport const ZOD_DTO_SYMBOL: unique symbol = Symbol.for('zod-nest.dto');\n","import type { z } from 'zod';\nimport type { Io, ZodDto } from './dto.types.js';\n\nimport { ZOD_NEST_DTO_EXTENSION } from '../schema/constants.js';\nimport { makeZodDtoMarker } from './marker.js';\nimport { ZOD_DTO_SYMBOL } from './symbols.js';\n\n/**\n * Cache of `parent -> output-sibling` so repeated reads of `Dto.Output` return\n * the same class instance. WeakMap so the sibling can be GC'd if the parent is.\n */\nconst outputCache = new WeakMap<ZodDto<z.ZodType>, ZodDto<z.ZodType>>();\n\n/**\n * `.Output` is always a distinct sibling class — it carries `io: 'output'` so\n * the Phase 2e doc-merger can run the output-side emission and apply the\n * suffix truth table (`Foo` alone vs `Foo` + `FooOutput`) based on actual JSON\n * Schema equality at doc-build time. The earlier \"return self when io-identical\"\n * optimization was dropped because `z.object()` already diverges at the JSON\n * Schema level (input is permissive, output sets `additionalProperties: false`),\n * which would have made the sibling reused only for non-object roots — not\n * worth the implementation complexity.\n */\nconst buildSiblingClass = <TSchema extends z.ZodType>(\n parent: ZodDto<TSchema>,\n schema: TSchema,\n): ZodDto<TSchema> => {\n const SiblingClass = class {\n static readonly schema = schema;\n static readonly io: Io = 'output';\n static readonly [ZOD_DTO_SYMBOL] = true as const;\n\n static get id(): string {\n return parent.id;\n }\n\n static get Output(): ZodDto<TSchema> {\n return this as unknown as ZodDto<TSchema>;\n }\n\n static parse(input: unknown): z.infer<TSchema> {\n return schema.parse(input) as z.infer<TSchema>;\n }\n\n static safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>> {\n return schema.safeParse(input) as z.ZodSafeParseResult<z.infer<TSchema>>;\n }\n\n static _OPENAPI_METADATA_FACTORY(): Record<string, unknown> {\n return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(parent.id, 'output') };\n }\n };\n return SiblingClass as unknown as ZodDto<TSchema>;\n};\n\nexport const resolveOutput = <TSchema extends z.ZodType>(\n parent: ZodDto<TSchema>,\n schema: TSchema,\n): ZodDto<TSchema> => {\n const cached = outputCache.get(parent as ZodDto<z.ZodType>);\n if (cached !== undefined) {\n return cached as ZodDto<TSchema>;\n }\n const sibling = buildSiblingClass(parent, schema);\n outputCache.set(parent as ZodDto<z.ZodType>, sibling as ZodDto<z.ZodType>);\n return sibling;\n};\n","import type { z } from 'zod';\nimport type { ZodNestRegistry } from '../schema/registry.js';\nimport type { CreateZodDtoOptions, Io, ZodDto } from './dto.types.js';\n\nimport { ZOD_NEST_DTO_EXTENSION } from '../schema/constants.js';\nimport { defaultRegistry } from '../schema/registry.js';\nimport { makeZodDtoMarker } from './marker.js';\nimport { resolveOutput } from './output-dto.js';\nimport { ZOD_DTO_SYMBOL } from './symbols.js';\n\nlet anonCounter = 0;\nlet warnedOnAnonymous = false;\n\nconst resolveId = (\n registry: ZodNestRegistry,\n schema: z.ZodType,\n providedId: string | undefined,\n className: string,\n): string => {\n if (providedId !== undefined && providedId !== '') {\n return providedId;\n }\n const meta = registry.zodRegistry.get(schema) as { id?: string } | undefined;\n if (meta && typeof meta.id === 'string' && meta.id !== '') {\n return meta.id;\n }\n if (className !== '' && className.length > 1) {\n return className;\n }\n anonCounter += 1;\n const fallback = `_AnonZodDto_${anonCounter}`;\n if (!warnedOnAnonymous) {\n warnedOnAnonymous = true;\n // eslint-disable-next-line no-console\n console.warn(\n `[zod-nest] Could not resolve a DTO id from class name (got \"${className}\"). ` +\n `Using \"${fallback}\". Pass \\`createZodDto(schema, { id: 'Foo' })\\` to set a stable ` +\n `name — important under minification, where class names become single mangled characters.`,\n );\n }\n return fallback;\n};\n\nexport const createZodDto = <TSchema extends z.ZodType>(\n schema: TSchema,\n options?: CreateZodDtoOptions,\n): ZodDto<TSchema> => {\n const registry: ZodNestRegistry = options?.registry ?? defaultRegistry;\n const io: Io = 'input';\n let cachedId: string | undefined;\n\n const ensureRegistered = (className: string): string => {\n if (cachedId !== undefined) {\n return cachedId;\n }\n cachedId = resolveId(registry, schema, options?.id, className);\n registry.register(schema, cachedId);\n return cachedId;\n };\n\n const ZodDtoBase = class {\n static readonly schema = schema;\n static readonly io: Io = io;\n static readonly [ZOD_DTO_SYMBOL] = true as const;\n\n static get id(): string {\n return ensureRegistered(this.name);\n }\n\n static get Output(): ZodDto<TSchema> {\n return resolveOutput(this as unknown as ZodDto<TSchema>, schema);\n }\n\n static parse(input: unknown): z.infer<TSchema> {\n return schema.parse(input) as z.infer<TSchema>;\n }\n\n static safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>> {\n return schema.safeParse(input) as z.ZodSafeParseResult<z.infer<TSchema>>;\n }\n\n static _OPENAPI_METADATA_FACTORY(): Record<string, unknown> {\n return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(ensureRegistered(this.name), io) };\n }\n };\n\n return ZodDtoBase as unknown as ZodDto<TSchema>;\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
var COMPONENTS_SCHEMAS_PREFIX = "#/components/schemas/";
|
|
5
5
|
var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
|
|
6
6
|
var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
|
|
7
|
+
var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
|
|
7
8
|
|
|
8
9
|
// src/schema/errors.ts
|
|
9
10
|
var ZodNestError = class extends Error {
|
|
@@ -190,7 +191,120 @@ var createRegistry = () => {
|
|
|
190
191
|
}
|
|
191
192
|
};
|
|
192
193
|
};
|
|
194
|
+
var defaultRegistry = createRegistry();
|
|
193
195
|
|
|
194
|
-
|
|
196
|
+
// src/dto/marker.ts
|
|
197
|
+
var makeZodDtoMarker = (dtoId, io) => ({
|
|
198
|
+
type: () => Object,
|
|
199
|
+
required: false,
|
|
200
|
+
__zodNestDto: true,
|
|
201
|
+
dtoId,
|
|
202
|
+
io
|
|
203
|
+
});
|
|
204
|
+
var isZodDtoMarker = (value) => {
|
|
205
|
+
if (value === null || typeof value !== "object") {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return value.__zodNestDto === true;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/dto/symbols.ts
|
|
212
|
+
var ZOD_DTO_SYMBOL = /* @__PURE__ */ Symbol.for("zod-nest.dto");
|
|
213
|
+
|
|
214
|
+
// src/dto/output-dto.ts
|
|
215
|
+
var outputCache = /* @__PURE__ */ new WeakMap();
|
|
216
|
+
var buildSiblingClass = (parent, schema) => {
|
|
217
|
+
const SiblingClass = class {
|
|
218
|
+
static schema = schema;
|
|
219
|
+
static io = "output";
|
|
220
|
+
static [ZOD_DTO_SYMBOL] = true;
|
|
221
|
+
static get id() {
|
|
222
|
+
return parent.id;
|
|
223
|
+
}
|
|
224
|
+
static get Output() {
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
static parse(input) {
|
|
228
|
+
return schema.parse(input);
|
|
229
|
+
}
|
|
230
|
+
static safeParse(input) {
|
|
231
|
+
return schema.safeParse(input);
|
|
232
|
+
}
|
|
233
|
+
static _OPENAPI_METADATA_FACTORY() {
|
|
234
|
+
return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(parent.id, "output") };
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
return SiblingClass;
|
|
238
|
+
};
|
|
239
|
+
var resolveOutput = (parent, schema) => {
|
|
240
|
+
const cached = outputCache.get(parent);
|
|
241
|
+
if (cached !== void 0) {
|
|
242
|
+
return cached;
|
|
243
|
+
}
|
|
244
|
+
const sibling = buildSiblingClass(parent, schema);
|
|
245
|
+
outputCache.set(parent, sibling);
|
|
246
|
+
return sibling;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/dto/create-zod-dto.ts
|
|
250
|
+
var anonCounter = 0;
|
|
251
|
+
var warnedOnAnonymous = false;
|
|
252
|
+
var resolveId = (registry, schema, providedId, className) => {
|
|
253
|
+
if (providedId !== void 0 && providedId !== "") {
|
|
254
|
+
return providedId;
|
|
255
|
+
}
|
|
256
|
+
const meta = registry.zodRegistry.get(schema);
|
|
257
|
+
if (meta && typeof meta.id === "string" && meta.id !== "") {
|
|
258
|
+
return meta.id;
|
|
259
|
+
}
|
|
260
|
+
if (className !== "" && className.length > 1) {
|
|
261
|
+
return className;
|
|
262
|
+
}
|
|
263
|
+
anonCounter += 1;
|
|
264
|
+
const fallback = `_AnonZodDto_${anonCounter}`;
|
|
265
|
+
if (!warnedOnAnonymous) {
|
|
266
|
+
warnedOnAnonymous = true;
|
|
267
|
+
console.warn(
|
|
268
|
+
`[zod-nest] Could not resolve a DTO id from class name (got "${className}"). Using "${fallback}". Pass \`createZodDto(schema, { id: 'Foo' })\` to set a stable name \u2014 important under minification, where class names become single mangled characters.`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return fallback;
|
|
272
|
+
};
|
|
273
|
+
var createZodDto = (schema, options) => {
|
|
274
|
+
const registry = options?.registry ?? defaultRegistry;
|
|
275
|
+
const io = "input";
|
|
276
|
+
let cachedId;
|
|
277
|
+
const ensureRegistered = (className) => {
|
|
278
|
+
if (cachedId !== void 0) {
|
|
279
|
+
return cachedId;
|
|
280
|
+
}
|
|
281
|
+
cachedId = resolveId(registry, schema, options?.id, className);
|
|
282
|
+
registry.register(schema, cachedId);
|
|
283
|
+
return cachedId;
|
|
284
|
+
};
|
|
285
|
+
const ZodDtoBase = class {
|
|
286
|
+
static schema = schema;
|
|
287
|
+
static io = io;
|
|
288
|
+
static [ZOD_DTO_SYMBOL] = true;
|
|
289
|
+
static get id() {
|
|
290
|
+
return ensureRegistered(this.name);
|
|
291
|
+
}
|
|
292
|
+
static get Output() {
|
|
293
|
+
return resolveOutput(this, schema);
|
|
294
|
+
}
|
|
295
|
+
static parse(input) {
|
|
296
|
+
return schema.parse(input);
|
|
297
|
+
}
|
|
298
|
+
static safeParse(input) {
|
|
299
|
+
return schema.safeParse(input);
|
|
300
|
+
}
|
|
301
|
+
static _OPENAPI_METADATA_FACTORY() {
|
|
302
|
+
return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(ensureRegistered(this.name), io) };
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return ZodDtoBase;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export { COMPONENTS_SCHEMAS_PREFIX, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZodNestError, ZodNestUnrepresentableError, createRegistry, createZodDto, defaultRegistry, isZodDtoMarker, makeZodDtoMarker, toOpenApi };
|
|
195
309
|
//# sourceMappingURL=index.mjs.map
|
|
196
310
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema/constants.ts","../src/schema/errors.ts","../src/schema/override.ts","../src/schema/post-process.ts","../src/schema/engine.ts","../src/schema/registry.ts"],"names":["z"],"mappings":";;;AACO,IAAM,yBAAA,GAA4B;AAGlC,IAAM,wBAAA,GAA2B;AAGjC,IAAM,2BAAA,GAA8B;;;ACPpC,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;AACF;AAEO,IAAM,2BAAA,GAAN,cAA0C,YAAA,CAAa;AAAA,EACnD,IAAA;AAAA,EACA,OAAA;AAAA,EAET,WAAA,CAAY,MAAsC,OAAA,EAAiB;AACjE,IAAA,KAAA;AAAA,MACE,CAAA,6BAAA,EAAgC,OAAO,CAAA,MAAA,EAAS,UAAA,CAAW,IAAI,CAAC,CAAA,0IAAA;AAAA,KAGlE;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,6BAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;AAEA,IAAM,UAAA,GAAa,CAAC,IAAA,KAAiD;AACnE,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACrB,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,MAAM,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,CAAE,KAAK,GAAG,CAAA;AACxC,CAAA;;;AC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AA;AACrB,MAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,QAAA,GAAA,uBAAU,GAAA,EAAe;AACzB,QAAA,IAAA,CAAK,GAAA,CAAI,IAAI,GAAG,CAAA;AAAA,MAClB;AACA,MAAA,GAAA,CAAI,IAAI,MAAM,CAAA;AAAA,IAChB,CAAA;AAAA,IACA,YAAA,EAAc,CAAC,EAAA,KAAO;AACpB,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA;AACvB,MAAA,OAAO,GAAA,KAAQ,MAAA,IAAa,GAAA,CAAI,IAAA,GAAO,CAAA;AAAA,IACzC,CAAA;AAAA,IACA,eAAe,MAAM;AACnB,MAAA,MAAM,GAAA,uBAAU,GAAA,EAA4B;AAC5C,MAAA,KAAA,MAAW,CAAC,EAAA,EAAI,GAAG,CAAA,IAAK,IAAA,EAAM;AAC5B,QAAA,IAAI,GAAA,CAAI,QAAQ,CAAA,EAAG;AACjB,UAAA;AAAA,QACF;AACA,QAAA,GAAA,CAAI,GAAA,CAAI,IAAI,GAAG,CAAA;AAAA,MACjB;AACA,MAAA,OAAO,GAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["/** OpenAPI 3.1 `$ref` prefix for entries in `components.schemas`. */\nexport const COMPONENTS_SCHEMAS_PREFIX = '#/components/schemas/';\n\n/** OpenAPI extension key zod-nest uses to surface engine errors inside emitted schemas. */\nexport const ZOD_NEST_ERROR_EXTENSION = 'x-zod-nest-error';\n\n/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */\nexport const ZOD_NEST_ERROR_DUPLICATE_ID = 'duplicate-id';\n","export class ZodNestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ZodNestError';\n }\n}\n\nexport class ZodNestUnrepresentableError extends ZodNestError {\n readonly path: ReadonlyArray<string | number>;\n readonly zodType: string;\n\n constructor(path: ReadonlyArray<string | number>, zodType: string) {\n super(\n `Unrepresentable Zod schema \\`${zodType}\\` at ${formatPath(path)}: no override produced ` +\n `a JSON Schema body. Set strict: false to emit \\`{}\\` instead, or supply an \\`override\\` ` +\n `that handles this Zod type.`,\n );\n this.name = 'ZodNestUnrepresentableError';\n this.path = path;\n this.zodType = zodType;\n }\n}\n\nconst formatPath = (path: ReadonlyArray<string | number>): string => {\n if (path.length === 0) {\n return '<root>';\n }\n return '/' + path.map(String).join('/');\n};\n","import type { $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\n\nexport interface OverrideContext {\n zodSchema: $ZodTypes;\n jsonSchema: SchemaObject;\n path: (string | number)[];\n}\n\nexport type Override = (ctx: OverrideContext) => void;\n\nexport const builtInOverride: Override = ({ zodSchema, jsonSchema }) => {\n const type = zodSchema._zod.def.type;\n if (type === 'bigint') {\n jsonSchema.type = 'integer';\n return;\n }\n if (type === 'date') {\n jsonSchema.type = 'string';\n jsonSchema.format = 'date-time';\n return;\n }\n};\n\nconst STRICT_REQUIRES_OVERRIDE: ReadonlySet<string> = new Set([\n 'bigint',\n 'date',\n 'symbol',\n 'undefined',\n 'void',\n 'map',\n 'set',\n 'transform',\n 'nan',\n 'custom',\n]);\n\nexport const isStrictlyUnrepresentable = (\n jsonSchema: SchemaObject,\n zodSchema: $ZodTypes,\n): boolean => {\n if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {\n return false;\n }\n return Object.keys(jsonSchema).length === 0;\n};\n\nexport const combine = (...overrides: ReadonlyArray<Override | undefined>): Override => {\n const list: Override[] = [];\n for (const candidate of overrides) {\n if (typeof candidate !== 'function') {\n continue;\n }\n list.push(candidate);\n }\n if (list.length === 0) {\n return () => undefined;\n }\n return (ctx) => {\n for (const o of list) {\n o(ctx);\n }\n };\n};\n","import type { SchemaObject } from './openapi.types.js';\n\nimport { COMPONENTS_SCHEMAS_PREFIX } from './constants.js';\n\nexport interface PostProcessResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\nconst DEFS_PREFIX = '#/$defs/';\n\nconst rewriteRefs = (node: unknown, selfRef: string | undefined): void => {\n if (Array.isArray(node)) {\n for (const item of node) {\n rewriteRefs(item, selfRef);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string' && ref.startsWith(DEFS_PREFIX)) {\n obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);\n } else if (ref === '#' && selfRef !== undefined) {\n // Zod emits '#' for cycle refs back to the document root. When we lift a\n // named schema into its own components.schemas entry, '#' should resolve\n // to that entry's own URI.\n obj.$ref = selfRef;\n }\n for (const value of Object.values(obj)) {\n rewriteRefs(value, selfRef);\n }\n};\n\nexport const postProcess = (raw: SchemaObject): PostProcessResult => {\n const refs = new Map<string, SchemaObject>();\n const rawDefs = raw.$defs;\n if (rawDefs !== undefined) {\n for (const [id, body] of Object.entries(rawDefs)) {\n refs.set(id, body);\n }\n }\n\n const root: SchemaObject = { ...raw };\n delete root.$schema;\n delete root.$defs;\n\n // Root has no own self-uri at the 2a level. If the root is a bare `$ref` to a\n // lifted named schema (the common case when input itself has `.meta({ id })`),\n // we'll have already rewritten it to '#/components/schemas/<id>'.\n rewriteRefs(root, undefined);\n\n for (const [id, body] of refs) {\n rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);\n }\n\n return { schema: root, refs };\n};\n","import { z } from 'zod';\n\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './constants.js';\nimport { ZodNestUnrepresentableError } from './errors.js';\nimport { builtInOverride, combine, isStrictlyUnrepresentable } from './override.js';\nimport { postProcess } from './post-process.js';\n\nexport interface ToOpenApiOptions {\n io: 'input' | 'output';\n registry: ZodNestRegistry;\n override?: Override;\n strict?: boolean;\n}\n\nexport interface ToOpenApiResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\ninterface UnrepresentableHit {\n path: (string | number)[];\n zodType: string;\n}\n\nexport const toOpenApi = (schema: z.ZodType, opts: ToOpenApiOptions): ToOpenApiResult => {\n const strict = opts.strict ?? true;\n const merged = combine(builtInOverride, opts.override);\n const unrepresentableHits: UnrepresentableHit[] = [];\n\n const wrapped: Override = (ctx) => {\n merged(ctx);\n if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {\n return;\n }\n unrepresentableHits.push({\n path: [...ctx.path],\n zodType: ctx.zodSchema._zod.def.type,\n });\n };\n\n const raw = z.toJSONSchema(schema, {\n target: 'draft-2020-12',\n io: opts.io,\n unrepresentable: 'any',\n metadata: opts.registry.zodRegistry,\n override: wrapped,\n cycles: 'ref',\n reused: 'inline',\n });\n\n const firstHit = unrepresentableHits[0];\n if (firstHit !== undefined) {\n throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);\n }\n\n const result = postProcess(raw);\n\n for (const [id] of opts.registry.getCollisions()) {\n if (!result.refs.has(id)) {\n continue;\n }\n result.refs.set(id, {\n description: `ERROR: duplicate zod-nest id <${id}>`,\n [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID,\n });\n }\n\n return result;\n};\n","import { z } from 'zod';\n\nexport interface ZodNestRegistry {\n readonly zodRegistry: typeof z.globalRegistry;\n register(schema: z.ZodType, id: string): void;\n hasCollision(id: string): boolean;\n getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;\n}\n\nexport const createRegistry = (): ZodNestRegistry => {\n const seen = new Map<string, Set<z.ZodType>>();\n\n return {\n zodRegistry: z.globalRegistry,\n register: (schema, id) => {\n z.globalRegistry.add(schema, { id });\n let set = seen.get(id);\n if (set === undefined) {\n set = new Set<z.ZodType>();\n seen.set(id, set);\n }\n set.add(schema);\n },\n hasCollision: (id) => {\n const set = seen.get(id);\n return set !== undefined && set.size > 1;\n },\n getCollisions: () => {\n const out = new Map<string, Set<z.ZodType>>();\n for (const [id, set] of seen) {\n if (set.size <= 1) {\n continue;\n }\n out.set(id, set);\n }\n return out;\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/schema/constants.ts","../src/schema/errors.ts","../src/schema/override.ts","../src/schema/post-process.ts","../src/schema/engine.ts","../src/schema/registry.ts","../src/dto/marker.ts","../src/dto/symbols.ts","../src/dto/output-dto.ts","../src/dto/create-zod-dto.ts"],"names":["z"],"mappings":";;;AACO,IAAM,yBAAA,GAA4B;AAGlC,IAAM,wBAAA,GAA2B;AAGjC,IAAM,2BAAA,GAA8B;AAQpC,IAAM,sBAAA,GAAyB;;;ACf/B,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;AACF;AAEO,IAAM,2BAAA,GAAN,cAA0C,YAAA,CAAa;AAAA,EACnD,IAAA;AAAA,EACA,OAAA;AAAA,EAET,WAAA,CAAY,MAAsC,OAAA,EAAiB;AACjE,IAAA,KAAA;AAAA,MACE,CAAA,6BAAA,EAAgC,OAAO,CAAA,MAAA,EAAS,UAAA,CAAW,IAAI,CAAC,CAAA,0IAAA;AAAA,KAGlE;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,6BAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;AAEA,IAAM,UAAA,GAAa,CAAC,IAAA,KAAiD;AACnE,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACrB,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,MAAM,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,CAAE,KAAK,GAAG,CAAA;AACxC,CAAA;;;ACjBO,IAAM,e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AEA,EAAA,MAAM,aAAa,MAAM;AAAA,IACvB,OAAgB,MAAA,GAAS,MAAA;AAAA,IACzB,OAAgB,EAAA,GAAS,EAAA;AAAA,IACzB,QAAiB,cAAc,IAAI,IAAA;AAAA,IAEnC,WAAW,EAAA,GAAa;AACtB,MAAA,OAAO,gBAAA,CAAiB,KAAK,IAAI,CAAA;AAAA,IACnC;AAAA,IAEA,WAAW,MAAA,GAA0B;AACnC,MAAA,OAAO,aAAA,CAAc,MAAoC,MAAM,CAAA;AAAA,IACjE;AAAA,IAEA,OAAO,MAAM,KAAA,EAAkC;AAC7C,MAAA,OAAO,MAAA,CAAO,MAAM,KAAK,CAAA;AAAA,IAC3B;AAAA,IAEA,OAAO,UAAU,KAAA,EAAwD;AACvE,MAAA,OAAO,MAAA,CAAO,UAAU,KAAK,CAAA;AAAA,IAC/B;AAAA,IAEA,OAAO,yBAAA,GAAqD;AAC1D,MAAA,OAAO,EAAE,CAAC,sBAAsB,GAAG,gBAAA,CAAiB,iBAAiB,IAAA,CAAK,IAAI,CAAA,EAAG,EAAE,CAAA,EAAE;AAAA,IACvF;AAAA,GACF;AAEA,EAAA,OAAO,UAAA;AACT","file":"index.mjs","sourcesContent":["/** OpenAPI 3.1 `$ref` prefix for entries in `components.schemas`. */\nexport const COMPONENTS_SCHEMAS_PREFIX = '#/components/schemas/';\n\n/** OpenAPI extension key zod-nest uses to surface engine errors inside emitted schemas. */\nexport const ZOD_NEST_ERROR_EXTENSION = 'x-zod-nest-error';\n\n/** Value of `x-zod-nest-error` when a registry id is claimed by more than one schema. */\nexport const ZOD_NEST_ERROR_DUPLICATE_ID = 'duplicate-id';\n\n/**\n * OpenAPI extension key used by `createZodDto` to mark a class for Phase 2e's\n * doc-merger. The marker carries `{ __zodNestDto: true, dtoId, io }` so the\n * merger can locate every zod-nest DTO in the @nestjs/swagger document and\n * inject the real Zod-derived schema.\n */\nexport const ZOD_NEST_DTO_EXTENSION = 'x-zod-nest-dto';\n","export class ZodNestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ZodNestError';\n }\n}\n\nexport class ZodNestUnrepresentableError extends ZodNestError {\n readonly path: ReadonlyArray<string | number>;\n readonly zodType: string;\n\n constructor(path: ReadonlyArray<string | number>, zodType: string) {\n super(\n `Unrepresentable Zod schema \\`${zodType}\\` at ${formatPath(path)}: no override produced ` +\n `a JSON Schema body. Set strict: false to emit \\`{}\\` instead, or supply an \\`override\\` ` +\n `that handles this Zod type.`,\n );\n this.name = 'ZodNestUnrepresentableError';\n this.path = path;\n this.zodType = zodType;\n }\n}\n\nconst formatPath = (path: ReadonlyArray<string | number>): string => {\n if (path.length === 0) {\n return '<root>';\n }\n return '/' + path.map(String).join('/');\n};\n","import type { $ZodTypes } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\n\nexport interface OverrideContext {\n zodSchema: $ZodTypes;\n jsonSchema: SchemaObject;\n path: (string | number)[];\n}\n\nexport type Override = (ctx: OverrideContext) => void;\n\nexport const builtInOverride: Override = ({ zodSchema, jsonSchema }) => {\n const type = zodSchema._zod.def.type;\n if (type === 'bigint') {\n jsonSchema.type = 'integer';\n return;\n }\n if (type === 'date') {\n jsonSchema.type = 'string';\n jsonSchema.format = 'date-time';\n return;\n }\n};\n\nconst STRICT_REQUIRES_OVERRIDE: ReadonlySet<string> = new Set([\n 'bigint',\n 'date',\n 'symbol',\n 'undefined',\n 'void',\n 'map',\n 'set',\n 'transform',\n 'nan',\n 'custom',\n]);\n\nexport const isStrictlyUnrepresentable = (\n jsonSchema: SchemaObject,\n zodSchema: $ZodTypes,\n): boolean => {\n if (!STRICT_REQUIRES_OVERRIDE.has(zodSchema._zod.def.type)) {\n return false;\n }\n return Object.keys(jsonSchema).length === 0;\n};\n\nexport const combine = (...overrides: ReadonlyArray<Override | undefined>): Override => {\n const list: Override[] = [];\n for (const candidate of overrides) {\n if (typeof candidate !== 'function') {\n continue;\n }\n list.push(candidate);\n }\n if (list.length === 0) {\n return () => undefined;\n }\n return (ctx) => {\n for (const o of list) {\n o(ctx);\n }\n };\n};\n","import type { SchemaObject } from './openapi.types.js';\n\nimport { COMPONENTS_SCHEMAS_PREFIX } from './constants.js';\n\nexport interface PostProcessResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\nconst DEFS_PREFIX = '#/$defs/';\n\nconst rewriteRefs = (node: unknown, selfRef: string | undefined): void => {\n if (Array.isArray(node)) {\n for (const item of node) {\n rewriteRefs(item, selfRef);\n }\n return;\n }\n if (node === null || typeof node !== 'object') {\n return;\n }\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string' && ref.startsWith(DEFS_PREFIX)) {\n obj.$ref = COMPONENTS_SCHEMAS_PREFIX + ref.slice(DEFS_PREFIX.length);\n } else if (ref === '#' && selfRef !== undefined) {\n // Zod emits '#' for cycle refs back to the document root. When we lift a\n // named schema into its own components.schemas entry, '#' should resolve\n // to that entry's own URI.\n obj.$ref = selfRef;\n }\n for (const value of Object.values(obj)) {\n rewriteRefs(value, selfRef);\n }\n};\n\nexport const postProcess = (raw: SchemaObject): PostProcessResult => {\n const refs = new Map<string, SchemaObject>();\n const rawDefs = raw.$defs;\n if (rawDefs !== undefined) {\n for (const [id, body] of Object.entries(rawDefs)) {\n refs.set(id, body);\n }\n }\n\n const root: SchemaObject = { ...raw };\n delete root.$schema;\n delete root.$defs;\n\n // Root has no own self-uri at the 2a level. If the root is a bare `$ref` to a\n // lifted named schema (the common case when input itself has `.meta({ id })`),\n // we'll have already rewritten it to '#/components/schemas/<id>'.\n rewriteRefs(root, undefined);\n\n for (const [id, body] of refs) {\n rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);\n }\n\n return { schema: root, refs };\n};\n","import { z } from 'zod';\n\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\nimport type { ZodNestRegistry } from './registry.js';\n\nimport { ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION } from './constants.js';\nimport { ZodNestUnrepresentableError } from './errors.js';\nimport { builtInOverride, combine, isStrictlyUnrepresentable } from './override.js';\nimport { postProcess } from './post-process.js';\n\nexport interface ToOpenApiOptions {\n io: 'input' | 'output';\n registry: ZodNestRegistry;\n override?: Override;\n strict?: boolean;\n}\n\nexport interface ToOpenApiResult {\n schema: SchemaObject;\n refs: Map<string, SchemaObject>;\n}\n\ninterface UnrepresentableHit {\n path: (string | number)[];\n zodType: string;\n}\n\nexport const toOpenApi = (schema: z.ZodType, opts: ToOpenApiOptions): ToOpenApiResult => {\n const strict = opts.strict ?? true;\n const merged = combine(builtInOverride, opts.override);\n const unrepresentableHits: UnrepresentableHit[] = [];\n\n const wrapped: Override = (ctx) => {\n merged(ctx);\n if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {\n return;\n }\n unrepresentableHits.push({\n path: [...ctx.path],\n zodType: ctx.zodSchema._zod.def.type,\n });\n };\n\n const raw = z.toJSONSchema(schema, {\n target: 'draft-2020-12',\n io: opts.io,\n unrepresentable: 'any',\n metadata: opts.registry.zodRegistry,\n override: wrapped,\n cycles: 'ref',\n reused: 'inline',\n });\n\n const firstHit = unrepresentableHits[0];\n if (firstHit !== undefined) {\n throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);\n }\n\n const result = postProcess(raw);\n\n for (const [id] of opts.registry.getCollisions()) {\n if (!result.refs.has(id)) {\n continue;\n }\n result.refs.set(id, {\n description: `ERROR: duplicate zod-nest id <${id}>`,\n [ZOD_NEST_ERROR_EXTENSION]: ZOD_NEST_ERROR_DUPLICATE_ID,\n });\n }\n\n return result;\n};\n","import { z } from 'zod';\n\nexport interface ZodNestRegistry {\n readonly zodRegistry: typeof z.globalRegistry;\n register(schema: z.ZodType, id: string): void;\n hasCollision(id: string): boolean;\n getCollisions(): ReadonlyMap<string, ReadonlySet<z.ZodType>>;\n}\n\nexport const createRegistry = (): ZodNestRegistry => {\n const seen = new Map<string, Set<z.ZodType>>();\n\n return {\n zodRegistry: z.globalRegistry,\n register: (schema, id) => {\n z.globalRegistry.add(schema, { id });\n let set = seen.get(id);\n if (set === undefined) {\n set = new Set<z.ZodType>();\n seen.set(id, set);\n }\n set.add(schema);\n },\n hasCollision: (id) => {\n const set = seen.get(id);\n return set !== undefined && set.size > 1;\n },\n getCollisions: () => {\n const out = new Map<string, Set<z.ZodType>>();\n for (const [id, set] of seen) {\n if (set.size <= 1) {\n continue;\n }\n out.set(id, set);\n }\n return out;\n },\n };\n};\n\n/**\n * Process-wide default registry. `createZodDto` registers schemas here unless\n * the caller passes `options.registry`. Phase 2e's doc merger reads from the\n * same instance for bulk emission. Multi-app WeakMap isolation is deferred\n * to v0.2.\n */\nexport const defaultRegistry: ZodNestRegistry = createRegistry();\n","import type { Io } from './dto.types.js';\n\n/**\n * Payload of the `x-zod-nest-dto` placeholder property that\n * `_OPENAPI_METADATA_FACTORY` returns. Phase 2e's doc merger reads this off\n * each `components.schemas.<DtoName>.properties[x-zod-nest-dto]` entry,\n * uses `dtoId` to look up the schema in the registry, and replaces the\n * synthetic schema body with the real Zod-derived schema.\n *\n * `type` and `required` are benign filler that satisfy @nestjs/swagger's\n * property-type guard (without them, the explorer throws \"A circular\n * dependency has been detected\"). They have no semantic meaning and are\n * stripped along with the rest of the marker by Phase 2e.\n */\nexport interface ZodDtoMarker {\n readonly type: () => typeof Object;\n readonly required: false;\n readonly __zodNestDto: true;\n readonly dtoId: string;\n readonly io: Io;\n}\n\nexport const makeZodDtoMarker = (dtoId: string, io: Io): ZodDtoMarker => ({\n type: () => Object,\n required: false,\n __zodNestDto: true,\n dtoId,\n io,\n});\n\n/** Phase 2e (and tests) use this to discriminate a marker from a real schema. */\nexport const isZodDtoMarker = (value: unknown): value is ZodDtoMarker => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n return (value as { __zodNestDto?: unknown }).__zodNestDto === true;\n};\n","/**\n * Runtime detection marker placed on every class returned by `createZodDto`.\n * Used by the validation pipe (Phase 2c), serializer (2d), and doc merger (2e)\n * to discriminate zod-nest DTO classes from regular constructors.\n */\nexport const ZOD_DTO_SYMBOL: unique symbol = Symbol.for('zod-nest.dto');\n","import type { z } from 'zod';\nimport type { Io, ZodDto } from './dto.types.js';\n\nimport { ZOD_NEST_DTO_EXTENSION } from '../schema/constants.js';\nimport { makeZodDtoMarker } from './marker.js';\nimport { ZOD_DTO_SYMBOL } from './symbols.js';\n\n/**\n * Cache of `parent -> output-sibling` so repeated reads of `Dto.Output` return\n * the same class instance. WeakMap so the sibling can be GC'd if the parent is.\n */\nconst outputCache = new WeakMap<ZodDto<z.ZodType>, ZodDto<z.ZodType>>();\n\n/**\n * `.Output` is always a distinct sibling class — it carries `io: 'output'` so\n * the Phase 2e doc-merger can run the output-side emission and apply the\n * suffix truth table (`Foo` alone vs `Foo` + `FooOutput`) based on actual JSON\n * Schema equality at doc-build time. The earlier \"return self when io-identical\"\n * optimization was dropped because `z.object()` already diverges at the JSON\n * Schema level (input is permissive, output sets `additionalProperties: false`),\n * which would have made the sibling reused only for non-object roots — not\n * worth the implementation complexity.\n */\nconst buildSiblingClass = <TSchema extends z.ZodType>(\n parent: ZodDto<TSchema>,\n schema: TSchema,\n): ZodDto<TSchema> => {\n const SiblingClass = class {\n static readonly schema = schema;\n static readonly io: Io = 'output';\n static readonly [ZOD_DTO_SYMBOL] = true as const;\n\n static get id(): string {\n return parent.id;\n }\n\n static get Output(): ZodDto<TSchema> {\n return this as unknown as ZodDto<TSchema>;\n }\n\n static parse(input: unknown): z.infer<TSchema> {\n return schema.parse(input) as z.infer<TSchema>;\n }\n\n static safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>> {\n return schema.safeParse(input) as z.ZodSafeParseResult<z.infer<TSchema>>;\n }\n\n static _OPENAPI_METADATA_FACTORY(): Record<string, unknown> {\n return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(parent.id, 'output') };\n }\n };\n return SiblingClass as unknown as ZodDto<TSchema>;\n};\n\nexport const resolveOutput = <TSchema extends z.ZodType>(\n parent: ZodDto<TSchema>,\n schema: TSchema,\n): ZodDto<TSchema> => {\n const cached = outputCache.get(parent as ZodDto<z.ZodType>);\n if (cached !== undefined) {\n return cached as ZodDto<TSchema>;\n }\n const sibling = buildSiblingClass(parent, schema);\n outputCache.set(parent as ZodDto<z.ZodType>, sibling as ZodDto<z.ZodType>);\n return sibling;\n};\n","import type { z } from 'zod';\nimport type { ZodNestRegistry } from '../schema/registry.js';\nimport type { CreateZodDtoOptions, Io, ZodDto } from './dto.types.js';\n\nimport { ZOD_NEST_DTO_EXTENSION } from '../schema/constants.js';\nimport { defaultRegistry } from '../schema/registry.js';\nimport { makeZodDtoMarker } from './marker.js';\nimport { resolveOutput } from './output-dto.js';\nimport { ZOD_DTO_SYMBOL } from './symbols.js';\n\nlet anonCounter = 0;\nlet warnedOnAnonymous = false;\n\nconst resolveId = (\n registry: ZodNestRegistry,\n schema: z.ZodType,\n providedId: string | undefined,\n className: string,\n): string => {\n if (providedId !== undefined && providedId !== '') {\n return providedId;\n }\n const meta = registry.zodRegistry.get(schema) as { id?: string } | undefined;\n if (meta && typeof meta.id === 'string' && meta.id !== '') {\n return meta.id;\n }\n if (className !== '' && className.length > 1) {\n return className;\n }\n anonCounter += 1;\n const fallback = `_AnonZodDto_${anonCounter}`;\n if (!warnedOnAnonymous) {\n warnedOnAnonymous = true;\n // eslint-disable-next-line no-console\n console.warn(\n `[zod-nest] Could not resolve a DTO id from class name (got \"${className}\"). ` +\n `Using \"${fallback}\". Pass \\`createZodDto(schema, { id: 'Foo' })\\` to set a stable ` +\n `name — important under minification, where class names become single mangled characters.`,\n );\n }\n return fallback;\n};\n\nexport const createZodDto = <TSchema extends z.ZodType>(\n schema: TSchema,\n options?: CreateZodDtoOptions,\n): ZodDto<TSchema> => {\n const registry: ZodNestRegistry = options?.registry ?? defaultRegistry;\n const io: Io = 'input';\n let cachedId: string | undefined;\n\n const ensureRegistered = (className: string): string => {\n if (cachedId !== undefined) {\n return cachedId;\n }\n cachedId = resolveId(registry, schema, options?.id, className);\n registry.register(schema, cachedId);\n return cachedId;\n };\n\n const ZodDtoBase = class {\n static readonly schema = schema;\n static readonly io: Io = io;\n static readonly [ZOD_DTO_SYMBOL] = true as const;\n\n static get id(): string {\n return ensureRegistered(this.name);\n }\n\n static get Output(): ZodDto<TSchema> {\n return resolveOutput(this as unknown as ZodDto<TSchema>, schema);\n }\n\n static parse(input: unknown): z.infer<TSchema> {\n return schema.parse(input) as z.infer<TSchema>;\n }\n\n static safeParse(input: unknown): z.ZodSafeParseResult<z.infer<TSchema>> {\n return schema.safeParse(input) as z.ZodSafeParseResult<z.infer<TSchema>>;\n }\n\n static _OPENAPI_METADATA_FACTORY(): Record<string, unknown> {\n return { [ZOD_NEST_DTO_EXTENSION]: makeZodDtoMarker(ensureRegistered(this.name), io) };\n }\n };\n\n return ZodDtoBase as unknown as ZodDto<TSchema>;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-nest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Modern Zod v4-only NestJS + OpenAPI 3.1 integration. Successor to nestjs-zod.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rodrigo Azevedo",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@ianvs/prettier-plugin-sort-imports": "^4.4.0",
|
|
71
71
|
"@nestjs/common": "^11.0.0",
|
|
72
72
|
"@nestjs/core": "^11.0.0",
|
|
73
|
+
"@nestjs/platform-express": "^11.1.21",
|
|
73
74
|
"@nestjs/swagger": "^11.0.0",
|
|
74
75
|
"@semantic-release/changelog": "^6.0.3",
|
|
75
76
|
"@semantic-release/exec": "^7.0.3",
|