zod-nest 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-4RXGLSPP.js +73 -0
- package/dist/chunk-4RXGLSPP.js.map +1 -0
- package/dist/chunk-BAG3BDRM.mjs +847 -0
- package/dist/chunk-BAG3BDRM.mjs.map +1 -0
- package/dist/chunk-KSDHVGMB.js +294 -0
- package/dist/chunk-KSDHVGMB.js.map +1 -0
- package/dist/chunk-LXRBMFWD.js +103 -0
- package/dist/chunk-LXRBMFWD.js.map +1 -0
- package/dist/chunk-RTWHQFNA.mjs +286 -0
- package/dist/chunk-RTWHQFNA.mjs.map +1 -0
- package/dist/chunk-T4KTFCJW.js +872 -0
- package/dist/chunk-T4KTFCJW.js.map +1 -0
- package/dist/chunk-WI4JKXT6.mjs +83 -0
- package/dist/chunk-WI4JKXT6.mjs.map +1 -0
- package/dist/chunk-ZZW54ETO.mjs +67 -0
- package/dist/chunk-ZZW54ETO.mjs.map +1 -0
- package/dist/express/index.d.mts +3 -3
- package/dist/express/index.d.ts +3 -3
- package/dist/express/index.js +33 -1118
- package/dist/express/index.js.map +1 -1
- package/dist/express/index.mjs +6 -1102
- package/dist/express/index.mjs.map +1 -1
- package/dist/fastify/index.d.mts +3 -3
- package/dist/fastify/index.d.ts +3 -3
- package/dist/fastify/index.js +18 -1109
- package/dist/fastify/index.js.map +1 -1
- package/dist/fastify/index.mjs +6 -1102
- package/dist/fastify/index.mjs.map +1 -1
- package/dist/helpers/index.js +81 -122
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/index.mjs +4 -101
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +263 -1091
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -895
- package/dist/index.mjs.map +1 -1
- package/dist/{param-decorators-CX1cUqfY.d.ts → param-decorators-23pStLeF.d.ts} +1 -1
- package/dist/{param-decorators-DbgygRVn.d.mts → param-decorators-Dfd2Cy08.d.mts} +1 -1
- package/dist/{registry-C9xStKa6.d.mts → registry-Cs1Y0a-L.d.mts} +1 -1
- package/dist/{registry-C9xStKa6.d.ts → registry-Cs1Y0a-L.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/schema/singleton.ts
|
|
7
|
+
var SINGLETONS = /* @__PURE__ */ Symbol.for("zod-nest.singletons");
|
|
8
|
+
var host = globalThis;
|
|
9
|
+
var store = /* @__PURE__ */ __name(() => {
|
|
10
|
+
const existing = host[SINGLETONS];
|
|
11
|
+
if (existing !== void 0) {
|
|
12
|
+
return existing;
|
|
13
|
+
}
|
|
14
|
+
const created = /* @__PURE__ */ new Map();
|
|
15
|
+
host[SINGLETONS] = created;
|
|
16
|
+
return created;
|
|
17
|
+
}, "store");
|
|
18
|
+
var singleton = /* @__PURE__ */ __name((key, create) => {
|
|
19
|
+
const values = store();
|
|
20
|
+
const existing = values.get(key);
|
|
21
|
+
if (existing !== void 0) {
|
|
22
|
+
return existing;
|
|
23
|
+
}
|
|
24
|
+
const created = create();
|
|
25
|
+
values.set(key, created);
|
|
26
|
+
return created;
|
|
27
|
+
}, "singleton");
|
|
28
|
+
|
|
29
|
+
// src/schema/custom-override.ts
|
|
30
|
+
var customOverrideMap = singleton("custom-override-map", () => /* @__PURE__ */ new WeakMap());
|
|
31
|
+
var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
|
|
32
|
+
var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
|
|
33
|
+
const overrideSchema = isWrapper(arg) ? {
|
|
34
|
+
...arg
|
|
35
|
+
} : {
|
|
36
|
+
input: arg,
|
|
37
|
+
output: arg
|
|
38
|
+
};
|
|
39
|
+
const schemaDescription = schema.description;
|
|
40
|
+
if (typeof schemaDescription === "string") {
|
|
41
|
+
overrideSchema.description = schemaDescription;
|
|
42
|
+
}
|
|
43
|
+
customOverrideMap.set(schema, overrideSchema);
|
|
44
|
+
return schema;
|
|
45
|
+
}, "overrideJSONSchema");
|
|
46
|
+
var peekRegistration = /* @__PURE__ */ __name((schema) => customOverrideMap.get(schema), "peekRegistration");
|
|
47
|
+
var createCustomOverride = /* @__PURE__ */ __name((io) => {
|
|
48
|
+
return ({ zodSchema, jsonSchema }) => {
|
|
49
|
+
const record = customOverrideMap.get(zodSchema);
|
|
50
|
+
if (record === void 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const fragment = record[io];
|
|
54
|
+
if (fragment === void 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (const key of Object.keys(jsonSchema)) {
|
|
58
|
+
Reflect.deleteProperty(jsonSchema, key);
|
|
59
|
+
}
|
|
60
|
+
Object.assign(jsonSchema, fragment);
|
|
61
|
+
if (fragment.description === void 0 && record.description !== void 0) {
|
|
62
|
+
jsonSchema.description = record.description;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}, "createCustomOverride");
|
|
66
|
+
|
|
67
|
+
exports.__name = __name;
|
|
68
|
+
exports.createCustomOverride = createCustomOverride;
|
|
69
|
+
exports.overrideJSONSchema = overrideJSONSchema;
|
|
70
|
+
exports.peekRegistration = peekRegistration;
|
|
71
|
+
exports.singleton = singleton;
|
|
72
|
+
//# sourceMappingURL=chunk-4RXGLSPP.js.map
|
|
73
|
+
//# sourceMappingURL=chunk-4RXGLSPP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/singleton.ts","../src/schema/custom-override.ts"],"names":["SINGLETONS","Symbol","for","host","globalThis","store","existing","undefined","created","Map","singleton","key","create","values","get","set","customOverrideMap","WeakMap","isWrapper","arg","overrideJSONSchema","schema","overrideSchema","input","output","schemaDescription","description","peekRegistration","createCustomOverride","io","zodSchema","jsonSchema","record","fragment","Object","keys","Reflect","deleteProperty","assign"],"mappings":";;;;;;AAGA,IAAMA,UAAAA,mBAAaC,MAAAA,CAAOC,GAAAA,CAAI,qBAAA,CAAA;AAQ9B,IAAMC,IAAAA,GAAOC,UAAAA;AAEb,IAAMC,wBAAQ,MAAA,CAAA,MAAA;AACZ,EAAA,MAAMC,QAAAA,GAAWH,KAAKH,UAAAA,CAAAA;AACtB,EAAA,IAAIM,aAAaC,MAAAA,EAAW;AAC1B,IAAA,OAAOD,QAAAA;AACT,EAAA;AACA,EAAA,MAAME,OAAAA,uBAAcC,GAAAA,EAAAA;AACpBN,EAAAA,IAAAA,CAAKH,UAAAA,CAAAA,GAAcQ,OAAAA;AACnB,EAAA,OAAOA,OAAAA;AACT,CAAA,EARc,OAAA,CAAA;AAYP,IAAME,SAAAA,mBAAY,MAAA,CAAA,CAAIC,GAAAA,EAAaC,MAAAA,KAAAA;AACxC,EAAA,MAAMC,SAASR,KAAAA,EAAAA;AACf,EAAA,MAAMC,QAAAA,GAAWO,MAAAA,CAAOC,GAAAA,CAAIH,GAAAA,CAAAA;AAC5B,EAAA,IAAIL,aAAaC,MAAAA,EAAW;AAC1B,IAAA,OAAOD,QAAAA;AACT,EAAA;AACA,EAAA,MAAME,UAAUI,MAAAA,EAAAA;AAChBC,EAAAA,MAAAA,CAAOE,GAAAA,CAAIJ,KAAKH,OAAAA,CAAAA;AAChB,EAAA,OAAOA,OAAAA;AACT,CAAA,EATyB,WAAA;;;ACoBzB,IAAMQ,oBAAoBN,SAAAA,CACxB,qBAAA,EACA,sBAAM,IAAIO,SAAAA,CAAAA;AAGZ,IAAMC,4BAAY,MAAA,CAAA,CAChBC,GAAAA,KAC2D,OAAA,IAAWA,GAAAA,IAAO,YAAYA,GAAAA,EAFzE,WAAA,CAAA;AA8BX,IAAMC,kBAAAA,mBAAqB,MAAA,CAAA,CAChCC,MAAA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AA,KAAgBnB,MAAAA,IAAayB,MAAAA,CAAON,gBAAgBnB,MAAAA,EAAW;AAC1EwB,MAAAA,UAAAA,CAAWL,cAAcM,MAAAA,CAAON,WAAAA;AAClC,IAAA;AACF,EAAA,CAAA;AACF,CAAA,EAlBoC,sBAAA","file":"chunk-4RXGLSPP.js","sourcesContent":["// Process-wide module state: each entry point is its own bundle, so a\n// module-level WeakMap would exist once per bundle, and once per copy of\n// the package in a consumer's tree.\nconst SINGLETONS = Symbol.for('zod-nest.singletons');\n\ninterface SingletonHost {\n [SINGLETONS]?: Map<string, unknown>;\n}\n\n// `globalThis` has no type for symbol keys and a Map's values are `unknown`.\n// Both assertions live here so every call site stays cast-free.\nconst host = globalThis as SingletonHost;\n\nconst store = (): Map<string, unknown> => {\n const existing = host[SINGLETONS];\n if (existing !== undefined) {\n return existing;\n }\n const created = new Map<string, unknown>();\n host[SINGLETONS] = created;\n return created;\n};\n\n// Callers own the key namespace and are the only writers, so the stored\n// type is theirs by construction. `create` must not return `undefined`.\nexport const singleton = <T>(key: string, create: () => T): T => {\n const values = store();\n const existing = values.get(key);\n if (existing !== undefined) {\n return existing as T;\n }\n const created = create();\n values.set(key, created);\n return created;\n};\n","import type { z } from 'zod';\nimport type { $ZodType } from 'zod/v4/core';\nimport type { SchemaObject } from './openapi.types.js';\nimport type { Override } from './override.js';\n\nimport { singleton } from './singleton.js';\n\n/**\n * Argument shape for {@link overrideJSONSchema}. Two forms:\n *\n * - A raw `SchemaObject` — applied to both input and output emission.\n * - A `{ input?, output? }` wrapper — distinct fragments per emission side,\n * for coercion shapes where input and output diverge (e.g.\n * `z.union([z.array(item), item.transform((v) => [v])])` accepts\n * `T | T[]` on input but always emits `T[]` on output).\n *\n * The wrapper form is detected by the presence of an `input` or `output`\n * key. Neither is a JSON Schema / OpenAPI 3.1 keyword, so the discriminator\n * is unambiguous in practice.\n */\nexport type OverrideJSONSchemaArg = SchemaObject | { input?: SchemaObject; output?: SchemaObject };\n\nexport interface StoredFragments {\n input?: SchemaObject;\n output?: SchemaObject;\n /**\n * Description captured from the Zod schema at `overrideJSONSchema(...)` call\n * time (`.describe(...)` / `.meta({ description })` both write to\n * `z.globalRegistry`). Applied as a fallback at emission time when the\n * per-direction fragment doesn't supply its own `description`. Fragment-\n * supplied descriptions still win.\n */\n description?: string;\n}\n\n/**\n * Per-instance JSON Schema registration store. Keyed by the Zod core type\n * (`$ZodType`) because that's what the override sees on `ctx.zodSchema`;\n * `z.ZodType` widens to `$ZodType` without a cast at the public API boundary.\n * Same WeakMap pattern as `composition.ts`'s `lineageMap`\n * (CLAUDE.md: \"transient, per-instance → WeakMap\").\n *\n * Value holds the per-direction fragments separately so the override factory\n * can pick the right one without surfacing `io` on `OverrideContext`.\n */\nconst customOverrideMap = singleton(\n 'custom-override-map',\n () => new WeakMap<$ZodType, StoredFragments>(),\n);\n\nconst isWrapper = (\n arg: OverrideJSONSchemaArg,\n): arg is { input?: SchemaObject; output?: SchemaObject } => 'input' in arg || 'output' in arg;\n\n/**\n * Register a fixed JSON Schema fragment for a specific Zod schema instance.\n *\n * Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and\n * `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,\n * tripping `ZodNestUnrepresentableError` in strict mode. Also useful for\n * coercion shapes where input and output diverge (`singleOrArray`-style\n * helpers).\n *\n * Two call shapes:\n *\n * ```ts\n * // 1. Single fragment — applied verbatim to both input and output emission.\n * overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });\n *\n * // 2. Divergent fragments — separate fragments per emission side. Omit a\n * // side to leave Zod's default emission untouched on that side.\n * overrideJSONSchema(arrayOrItem, {\n * input: { anyOf: [arrFrag, itemFrag] },\n * output: arrFrag,\n * });\n * ```\n *\n * Idempotent: subsequent calls for the same schema overwrite the prior\n * registration (last-write-wins).\n */\nexport const overrideJSONSchema = <T extends z.ZodType>(\n schema: T,\n arg: OverrideJSONSchemaArg,\n): T => {\n const overrideSchema: StoredFragments = isWrapper(arg) ? { ...arg } : { input: arg, output: arg };\n\n const schemaDescription = schema.description;\n if (typeof schemaDescription === 'string') {\n overrideSchema.description = schemaDescription;\n }\n\n customOverrideMap.set(schema, overrideSchema);\n\n return schema;\n};\n\n/**\n * Read-only lookup into the registration store. Used by the engine to detect\n * when a pipe-typed schema covers its inner descent target with a relevant-io\n * fragment — see `buildToJsonSchemaOptions` in `engine.ts`. Returning a\n * possibly-`undefined` `StoredFragments` keeps the engine ignorant of the\n * underlying WeakMap.\n */\nexport const peekRegistration = (schema: $ZodType): StoredFragments | undefined =>\n customOverrideMap.get(schema);\n\n/**\n * Internal override factory consulted by the engine. Closes over the current\n * emission direction so the lookup can pick the right registered fragment\n * without surfacing `io` on the `OverrideContext` public contract. Mirrors\n * `createCompositionOverride` at `engine.ts:98`.\n *\n * Mutates `ctx.jsonSchema` in-place (clears existing keys, then assigns the\n * fragment) because Zod's override pipeline doesn't propagate\n * `ctx.jsonSchema = newObj` reassignments — only mutations on the existing\n * object reach the caller (see `composition.ts` for the same constraint).\n *\n * Falls back to the schema's captured `description` (from `.describe(...)` /\n * `.meta({ description })`) when the per-direction fragment doesn't supply\n * one. Captured at `overrideJSONSchema(...)` call time so the inheritance\n * doesn't depend on Zod's emission-time metadata pass. `title` is\n * deliberately not inherited.\n *\n * No-ops if the schema isn't registered, or if the registered record has no\n * fragment for the current `io` direction.\n */\nexport const createCustomOverride = (io: 'input' | 'output'): Override => {\n return ({ zodSchema, jsonSchema }) => {\n const record = customOverrideMap.get(zodSchema);\n if (record === undefined) {\n return;\n }\n const fragment = record[io];\n if (fragment === undefined) {\n return;\n }\n for (const key of Object.keys(jsonSchema)) {\n Reflect.deleteProperty(jsonSchema, key);\n }\n Object.assign(jsonSchema, fragment);\n if (fragment.description === undefined && record.description !== undefined) {\n jsonSchema.description = record.description;\n }\n };\n};\n"]}
|