@mastra/deployer 1.68.0-alpha.0 → 1.68.0-alpha.11

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.
Files changed (121) hide show
  1. package/dist/_types/@hono_node-server/package.json +1 -0
  2. package/dist/_types/@mastra_hono/package.json +1 -0
  3. package/dist/{analyze-hp4aHpms.cjs → analyze-ClD1cvPT.cjs} +150 -99
  4. package/dist/analyze-ClD1cvPT.cjs.map +1 -0
  5. package/dist/{analyze-B5HY26Tt.js → analyze-DEk6PGTI.js} +148 -96
  6. package/dist/analyze-DEk6PGTI.js.map +1 -0
  7. package/dist/{arktype-aI7TBD0R-S0daSmHG.js → arktype-aI7TBD0R-BGjyzmsj.js} +2 -2
  8. package/dist/{arktype-aI7TBD0R-S0daSmHG.js.map → arktype-aI7TBD0R-BGjyzmsj.js.map} +1 -1
  9. package/dist/{arktype-aI7TBD0R-BuTX_Phx.cjs → arktype-aI7TBD0R-DCxjN6oF.cjs} +2 -2
  10. package/dist/{arktype-aI7TBD0R-BuTX_Phx.cjs.map → arktype-aI7TBD0R-DCxjN6oF.cjs.map} +1 -1
  11. package/dist/build/analyze/analyzeEntry.d.ts +8 -1
  12. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  13. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  14. package/dist/build/analyze.cjs +1 -1
  15. package/dist/build/analyze.d.ts +2 -1
  16. package/dist/build/analyze.d.ts.map +1 -1
  17. package/dist/build/analyze.js +1 -1
  18. package/dist/build/bundler.cjs +2 -1
  19. package/dist/build/bundler.d.ts +10 -0
  20. package/dist/build/bundler.d.ts.map +1 -1
  21. package/dist/build/bundler.js +2 -2
  22. package/dist/build/index.cjs +6 -6
  23. package/dist/build/index.js +6 -6
  24. package/dist/build/package-info.d.ts +4 -0
  25. package/dist/build/package-info.d.ts.map +1 -1
  26. package/dist/build/plugins/subpath-externals-resolver.d.ts +2 -1
  27. package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -1
  28. package/dist/build/plugins/tsconfig-paths.d.ts +2 -1
  29. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  30. package/dist/build/watcher.d.ts.map +1 -1
  31. package/dist/{build-Dit9VFE2.cjs → build-DJMEiMA1.cjs} +8 -7
  32. package/dist/build-DJMEiMA1.cjs.map +1 -0
  33. package/dist/{build-Boe3fe3L.js → build-JNlRQOvG.js} +8 -7
  34. package/dist/build-JNlRQOvG.js.map +1 -0
  35. package/dist/bundler/index.cjs +29 -62
  36. package/dist/bundler/index.cjs.map +1 -1
  37. package/dist/bundler/index.d.ts +1 -11
  38. package/dist/bundler/index.d.ts.map +1 -1
  39. package/dist/bundler/index.js +30 -63
  40. package/dist/bundler/index.js.map +1 -1
  41. package/dist/bundler/workspaceDependencies.d.ts +1 -1
  42. package/dist/bundler/workspaceDependencies.d.ts.map +1 -1
  43. package/dist/{bundler-CzQiVHzN.js → bundler-CC0klr1q.js} +63 -13
  44. package/dist/bundler-CC0klr1q.js.map +1 -0
  45. package/dist/{bundler-BKf2S2r_.cjs → bundler-CjoP35xh.cjs} +74 -11
  46. package/dist/bundler-CjoP35xh.cjs.map +1 -0
  47. package/dist/{bundlerOptions-I2E5y2Wp.cjs → bundlerOptions-09fXosF4.cjs} +2 -2
  48. package/dist/{bundlerOptions-I2E5y2Wp.cjs.map → bundlerOptions-09fXosF4.cjs.map} +1 -1
  49. package/dist/{bundlerOptions-BSySFLb3.js → bundlerOptions-BaAR_H3U.js} +2 -2
  50. package/dist/{bundlerOptions-BSySFLb3.js.map → bundlerOptions-BaAR_H3U.js.map} +1 -1
  51. package/dist/core-D3wM1JKp.js +1159 -0
  52. package/dist/core-D3wM1JKp.js.map +1 -0
  53. package/dist/core-QL_X0T4Y.cjs +1159 -0
  54. package/dist/core-QL_X0T4Y.cjs.map +1 -0
  55. package/dist/docs/SKILL.md +1 -1
  56. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  57. package/dist/docs/references/docs-deployment-monorepo.md +2 -2
  58. package/dist/{effect-QlVUlMFu-tf02PTZR.cjs → effect-QlVUlMFu-B2nZ842E.cjs} +3 -3
  59. package/dist/{effect-QlVUlMFu-tf02PTZR.cjs.map → effect-QlVUlMFu-B2nZ842E.cjs.map} +1 -1
  60. package/dist/{effect-QlVUlMFu-BN-VJnMF.js → effect-QlVUlMFu-DbWuPaWV.js} +3 -3
  61. package/dist/{effect-QlVUlMFu-BN-VJnMF.js.map → effect-QlVUlMFu-DbWuPaWV.js.map} +1 -1
  62. package/dist/{esm-DZ1Siz1C.cjs → esm-Ai6osZ1a.cjs} +61 -50
  63. package/dist/esm-Ai6osZ1a.cjs.map +1 -0
  64. package/dist/{esm-B51vJPGv.js → esm-D-wYOO-S.js} +61 -50
  65. package/dist/esm-D-wYOO-S.js.map +1 -0
  66. package/dist/{index-CLddUTqr-eO-ae7Sx.js → index-CLddUTqr-BXqo9et4.js} +8 -8
  67. package/dist/{index-CLddUTqr-eO-ae7Sx.js.map → index-CLddUTqr-BXqo9et4.js.map} +1 -1
  68. package/dist/{index-CLddUTqr-DS5tJ3WV.cjs → index-CLddUTqr-DsGkVS-W.cjs} +8 -8
  69. package/dist/{index-CLddUTqr-DS5tJ3WV.cjs.map → index-CLddUTqr-DsGkVS-W.cjs.map} +1 -1
  70. package/dist/index.cjs +3 -3
  71. package/dist/index.js +3 -3
  72. package/dist/server/index.cjs +21 -19
  73. package/dist/server/index.cjs.map +1 -1
  74. package/dist/server/index.d.ts +2 -2
  75. package/dist/server/index.js +22 -20
  76. package/dist/server/index.js.map +1 -1
  77. package/dist/services/deps.d.ts +1 -1
  78. package/dist/services/deps.d.ts.map +1 -1
  79. package/dist/services/index.cjs +1 -1
  80. package/dist/services/index.js +1 -1
  81. package/dist/{services-BLvNG7v7.cjs → services-Beob47UW.cjs} +42 -23
  82. package/dist/services-Beob47UW.cjs.map +1 -0
  83. package/dist/{services-B9KRKBT-.js → services-Lm6PRS4D.js} +42 -23
  84. package/dist/services-Lm6PRS4D.js.map +1 -0
  85. package/dist/{sury-CWZTCd75-YUPbTtKO.cjs → sury-CWZTCd75-ChXu4j-p.cjs} +3 -3
  86. package/dist/{sury-CWZTCd75-YUPbTtKO.cjs.map → sury-CWZTCd75-ChXu4j-p.cjs.map} +1 -1
  87. package/dist/{sury-CWZTCd75-ClSNrMWF.js → sury-CWZTCd75-OKz7uWLi.js} +3 -3
  88. package/dist/{sury-CWZTCd75-ClSNrMWF.js.map → sury-CWZTCd75-OKz7uWLi.js.map} +1 -1
  89. package/dist/{typebox-Dei93FPO-CVSJ3SAf.js → typebox-Dei93FPO-C5ACKU09.js} +2 -2
  90. package/dist/{typebox-Dei93FPO-CVSJ3SAf.js.map → typebox-Dei93FPO-C5ACKU09.js.map} +1 -1
  91. package/dist/{typebox-Dei93FPO-BTBshlGz.cjs → typebox-Dei93FPO-KTtPU745.cjs} +2 -2
  92. package/dist/{typebox-Dei93FPO-BTBshlGz.cjs.map → typebox-Dei93FPO-KTtPU745.cjs.map} +1 -1
  93. package/dist/{utils-DYi43Kp4.js → utils-Bl3Lm7SI.js} +1 -2
  94. package/dist/{utils-DYi43Kp4.js.map → utils-Bl3Lm7SI.js.map} +1 -1
  95. package/dist/{utils-7WDNT3Ca.cjs → utils-Bsr_sEcH.cjs} +2 -2
  96. package/dist/{utils-7WDNT3Ca.cjs.map → utils-Bsr_sEcH.cjs.map} +1 -1
  97. package/dist/{valibot--1zFm7rT-Dn5WqdyK.cjs → valibot--1zFm7rT-BeX3W1HK.cjs} +3 -3
  98. package/dist/{valibot--1zFm7rT-Dn5WqdyK.cjs.map → valibot--1zFm7rT-BeX3W1HK.cjs.map} +1 -1
  99. package/dist/{valibot--1zFm7rT-BxcEC3Pu.js → valibot--1zFm7rT-BuVb-6oJ.js} +3 -3
  100. package/dist/{valibot--1zFm7rT-BxcEC3Pu.js.map → valibot--1zFm7rT-BuVb-6oJ.js.map} +1 -1
  101. package/dist/validator/custom-resolver.cjs +1 -1
  102. package/dist/validator/custom-resolver.js +1 -1
  103. package/dist/{zod-Bwrt9trS-Bd40XYOT.js → zod-Bwrt9trS-D5b1oyiT.js} +5 -5
  104. package/dist/{zod-Bwrt9trS-Bd40XYOT.js.map → zod-Bwrt9trS-D5b1oyiT.js.map} +1 -1
  105. package/dist/{zod-Bwrt9trS-Bi11nE9Q.cjs → zod-Bwrt9trS-DGQs9DWc.cjs} +5 -5
  106. package/dist/{zod-Bwrt9trS-Bi11nE9Q.cjs.map → zod-Bwrt9trS-DGQs9DWc.cjs.map} +1 -1
  107. package/package.json +15 -14
  108. package/dist/analyze-B5HY26Tt.js.map +0 -1
  109. package/dist/analyze-hp4aHpms.cjs.map +0 -1
  110. package/dist/build-Boe3fe3L.js.map +0 -1
  111. package/dist/build-Dit9VFE2.cjs.map +0 -1
  112. package/dist/bundler-BKf2S2r_.cjs.map +0 -1
  113. package/dist/bundler-CzQiVHzN.js.map +0 -1
  114. package/dist/core-D0wEgdn3.cjs +0 -790
  115. package/dist/core-D0wEgdn3.cjs.map +0 -1
  116. package/dist/core-DF65PJXc.js +0 -790
  117. package/dist/core-DF65PJXc.js.map +0 -1
  118. package/dist/esm-B51vJPGv.js.map +0 -1
  119. package/dist/esm-DZ1Siz1C.cjs.map +0 -1
  120. package/dist/services-B9KRKBT-.js.map +0 -1
  121. package/dist/services-BLvNG7v7.cjs.map +0 -1
@@ -0,0 +1,1159 @@
1
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/util.js
2
+ function getEnumValues(entries) {
3
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
4
+ return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
5
+ }
6
+ function assignProp(target, prop, value) {
7
+ Object.defineProperty(target, prop, {
8
+ value,
9
+ writable: true,
10
+ enumerable: true,
11
+ configurable: true
12
+ });
13
+ }
14
+ "captureStackTrace" in Error && Error.captureStackTrace;
15
+ const NUMBER_FORMAT_RANGES = /*@__PURE__*/ (() => ({
16
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
17
+ int32: [-2147483648, 2147483647],
18
+ uint32: [0, 4294967295],
19
+ float32: [-34028234663852886e22, 34028234663852886e22],
20
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
21
+ }))();
22
+ const BIGINT_FORMAT_RANGES = {
23
+ int64: [/* @__PURE__*/ BigInt("-9223372036854775808"), /* @__PURE__*/ BigInt("9223372036854775807")],
24
+ uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")]
25
+ };
26
+ //#endregion
27
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/regexes.js
28
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
29
+ const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
30
+ const integer = /^-?\d+$/;
31
+ const number = /^-?\d+(?:\.\d+)?$/;
32
+ //#endregion
33
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/schemas.js
34
+ const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
35
+ const base64urlCharset = /^[A-Za-z0-9_-]*$/;
36
+ //#endregion
37
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/registries.js
38
+ var _a;
39
+ var $ZodRegistry = class {
40
+ constructor() {
41
+ this._map = /* @__PURE__ */ new WeakMap();
42
+ this._idmap = /* @__PURE__ */ new Map();
43
+ }
44
+ add(schema, ..._meta) {
45
+ const meta = _meta[0];
46
+ this._map.set(schema, meta);
47
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
48
+ return this;
49
+ }
50
+ clear() {
51
+ this._map = /* @__PURE__ */ new WeakMap();
52
+ this._idmap = /* @__PURE__ */ new Map();
53
+ return this;
54
+ }
55
+ remove(schema) {
56
+ const meta = this._map.get(schema);
57
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
58
+ this._map.delete(schema);
59
+ return this;
60
+ }
61
+ get(schema) {
62
+ const p = schema._zod.parent;
63
+ if (p) {
64
+ const pm = { ...this.get(p) ?? {} };
65
+ delete pm.id;
66
+ const f = {
67
+ ...pm,
68
+ ...this._map.get(schema)
69
+ };
70
+ return Object.keys(f).length ? f : void 0;
71
+ }
72
+ return this._map.get(schema);
73
+ }
74
+ has(schema) {
75
+ return this._map.has(schema);
76
+ }
77
+ };
78
+ function registry() {
79
+ return new $ZodRegistry();
80
+ }
81
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
82
+ const globalRegistry = globalThis.__zod_globalRegistry;
83
+ //#endregion
84
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/to-json-schema.js
85
+ function assignProps(target, ...sources) {
86
+ for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
87
+ return target;
88
+ }
89
+ function initializeContext(params) {
90
+ let target = params?.target ?? "draft-2020-12";
91
+ if (target === "draft-4") target = "draft-04";
92
+ if (target === "draft-7") target = "draft-07";
93
+ return {
94
+ processors: params.processors ?? {},
95
+ metadataRegistry: params?.metadata ?? globalRegistry,
96
+ target,
97
+ unrepresentable: params?.unrepresentable ?? "throw",
98
+ override: params?.override ?? (() => {}),
99
+ io: params?.io ?? "output",
100
+ counter: 0,
101
+ seen: /* @__PURE__ */ new Map(),
102
+ sharedDefsExtractedFor: void 0,
103
+ sharedEmitDoneFor: void 0,
104
+ cycles: params?.cycles ?? "ref",
105
+ reused: params?.reused ?? "inline",
106
+ intersections: [],
107
+ deferred: [],
108
+ external: params?.external ?? void 0
109
+ };
110
+ }
111
+ /**
112
+ * Applies the `unrepresentable` setting at a site that has no JSON Schema equivalent. Throws
113
+ * `message` unless the setting (or the handler's return value) says otherwise. Returns `true` if a
114
+ * custom JSON Schema was written into `json`, in which case the caller must not write its own.
115
+ */
116
+ function handleUnrepresentable(schema, ctx, json, params, message) {
117
+ const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({
118
+ zodSchema: schema,
119
+ path: params.path,
120
+ message
121
+ }) : ctx.unrepresentable;
122
+ if (result === "any") return false;
123
+ if (result === void 0 || result === "throw") throw new Error(message);
124
+ Object.assign(json, result);
125
+ return true;
126
+ }
127
+ function processSchema(schema, ctx, _params = {
128
+ path: [],
129
+ schemaPath: []
130
+ }) {
131
+ var _a;
132
+ const def = schema._zod.def;
133
+ const seen = ctx.seen.get(schema);
134
+ if (seen) {
135
+ seen.count++;
136
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
137
+ return seen.schema;
138
+ }
139
+ const result = {
140
+ schema: {},
141
+ count: 1,
142
+ cycle: void 0,
143
+ path: _params.path
144
+ };
145
+ ctx.seen.set(schema, result);
146
+ ctx.sharedDefsExtractedFor = void 0;
147
+ ctx.sharedEmitDoneFor = void 0;
148
+ const overrideSchema = schema._zod.toJSONSchema?.();
149
+ if (overrideSchema) result.schema = overrideSchema;
150
+ else {
151
+ const params = {
152
+ ..._params,
153
+ schemaPath: [..._params.schemaPath, schema],
154
+ path: _params.path
155
+ };
156
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
157
+ else {
158
+ const _json = result.schema;
159
+ const processor = ctx.processors[def.type];
160
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
161
+ processor(schema, ctx, _json, params);
162
+ }
163
+ const parent = schema._zod.parent;
164
+ if (parent) {
165
+ if (!result.ref) result.ref = parent;
166
+ processSchema(parent, ctx, params);
167
+ ctx.seen.get(parent).isParent = true;
168
+ }
169
+ }
170
+ const meta = ctx.metadataRegistry.get(schema);
171
+ if (meta) assignProps(result.schema, meta);
172
+ if (ctx.io === "input" && isTransforming(schema)) {
173
+ delete result.schema.examples;
174
+ delete result.schema.default;
175
+ }
176
+ if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
177
+ delete result.schema._prefault;
178
+ return ctx.seen.get(schema).schema;
179
+ }
180
+ function encodeJSONPointerSegment(segment) {
181
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
182
+ }
183
+ function extractDefs(ctx, schema) {
184
+ const root = ctx.seen.get(schema);
185
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
186
+ if (ctx.external && ctx.sharedDefsExtractedFor === ctx.external) return;
187
+ const idToSchema = /* @__PURE__ */ new Map();
188
+ for (const entry of ctx.seen.entries()) {
189
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
190
+ if (id) {
191
+ const existing = idToSchema.get(id);
192
+ if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
193
+ idToSchema.set(id, entry[0]);
194
+ }
195
+ }
196
+ const makeURI = (entry) => {
197
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
198
+ if (ctx.external) {
199
+ const externalId = ctx.external.registry.get(entry[0])?.id;
200
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
201
+ if (externalId) return { ref: uriGenerator(externalId) };
202
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
203
+ entry[1].defId = id;
204
+ return {
205
+ defId: id,
206
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`
207
+ };
208
+ }
209
+ const uriPrefix = `#`;
210
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
211
+ if (entry[1] === root && !entry[1].schema.id) return { ref: uriPrefix };
212
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
213
+ return {
214
+ defId,
215
+ ref: defUriPrefix + encodeJSONPointerSegment(defId)
216
+ };
217
+ };
218
+ const extractToDef = (entry) => {
219
+ if (entry[1].schema.$ref) return;
220
+ const seen = entry[1];
221
+ const { ref, defId } = makeURI(entry);
222
+ seen.def = { ...seen.schema };
223
+ if (defId) seen.defId = defId;
224
+ const schema = seen.schema;
225
+ for (const key in schema) delete schema[key];
226
+ schema.$ref = ref;
227
+ };
228
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
229
+ const seen = entry[1];
230
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
231
+
232
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
233
+ }
234
+ for (const entry of ctx.seen.entries()) {
235
+ const seen = entry[1];
236
+ if (schema === entry[0]) {
237
+ extractToDef(entry);
238
+ continue;
239
+ }
240
+ if (ctx.external) {
241
+ const ext = ctx.external.registry.get(entry[0])?.id;
242
+ if (schema !== entry[0] && ext) {
243
+ extractToDef(entry);
244
+ continue;
245
+ }
246
+ }
247
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
248
+ extractToDef(entry);
249
+ continue;
250
+ }
251
+ if (seen.cycle) {
252
+ extractToDef(entry);
253
+ continue;
254
+ }
255
+ if (seen.count > 1) {
256
+ if (ctx.reused === "ref") extractToDef(entry);
257
+ }
258
+ }
259
+ if (ctx.external) ctx.sharedDefsExtractedFor = ctx.external;
260
+ }
261
+ /** Rewrites `anyOf: [{type: "a"}, {type: "b"}]` to `type: ["a", "b"]`, which every JSON Schema draft treats as equivalent and most consumers render far better for the nullable case. Only branches that are a bare type assertion qualify — anything carrying a constraint, `$ref`, `const` or metadata is left alone. Runs after `flattenRef`, so a branch an override decorated or `$defs` extraction turned into a `$ref` is no longer bare and correctly stays in `anyOf`. `oneOf` is excluded: `integer` and `number` overlap, so "exactly one" and "at least one" are not the same there. OpenAPI 3.0 is excluded: its `type` must be a single string. */
262
+ function compactTypeUnion(schema) {
263
+ const options = schema.anyOf;
264
+ if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0) return;
265
+ const types = [];
266
+ for (const option of options) {
267
+ if (!option || typeof option !== "object") return;
268
+ compactTypeUnion(option);
269
+ const keys = Object.keys(option);
270
+ if (keys.length !== 1 || keys[0] !== "type") return;
271
+ const type = option.type;
272
+ for (const member of Array.isArray(type) ? type : [type]) {
273
+ if (typeof member !== "string") return;
274
+ if (!types.includes(member)) types.push(member);
275
+ }
276
+ }
277
+ delete schema.anyOf;
278
+ schema.type = types.length === 1 ? types[0] : types;
279
+ }
280
+ /** Keywords `foldIntersection` knows how to combine. Anything else — `$ref`, `patternProperties`,
281
+ * an annotation like `description` — makes a member unfoldable, so a constraint this does not
282
+ * understand leaves the `allOf` alone instead of being silently dropped or misattributed. */
283
+ const FOLDABLE_KEYS = /* @__PURE__ */ new Set([
284
+ "type",
285
+ "properties",
286
+ "required",
287
+ "additionalProperties"
288
+ ]);
289
+ const UNION_KEYS = ["oneOf", "anyOf"];
290
+ /** A member's constraint on a key it does not declare itself. A `catchall` states one; `false`, an absent `additionalProperties`, and the empty schema a loose object emits state nothing. */
291
+ function undeclaredConstraint(member) {
292
+ const extra = member.additionalProperties;
293
+ if (extra === void 0 || extra === false || typeof extra !== "object" || extra === null) return null;
294
+ return Object.keys(extra).length ? extra : null;
295
+ }
296
+ /** Combines object members into the single object they describe together, or returns `null` if any of them carries a keyword outside {@link FOLDABLE_KEYS}. */
297
+ function foldObjects(members) {
298
+ const objects = [];
299
+ for (const member of members) {
300
+ if (typeof member !== "object" || member.type !== "object") return null;
301
+ for (const key in member) if (!FOLDABLE_KEYS.has(key)) return null;
302
+ objects.push(member);
303
+ }
304
+ const properties = {};
305
+ const required = /* @__PURE__ */ new Set();
306
+ for (const object of objects) {
307
+ for (const key in object.properties) {
308
+ if (Object.prototype.hasOwnProperty.call(properties, key)) continue;
309
+ const parts = [];
310
+ for (const other of objects) {
311
+ const part = other.properties?.[key] ?? undeclaredConstraint(other);
312
+ if (part === null || part === void 0) continue;
313
+ if (!parts.some((seen) => JSON.stringify(seen) === JSON.stringify(part))) parts.push(part);
314
+ }
315
+ assignProp(properties, key, parts.length === 1 ? parts[0] : foldObjects(parts) ?? { allOf: parts });
316
+ }
317
+ for (const key of object.required ?? []) required.add(key);
318
+ }
319
+ const folded = {
320
+ type: "object",
321
+ properties
322
+ };
323
+ if (required.size) folded.required = [...required];
324
+ if (objects.every((object) => object.additionalProperties === false)) folded.additionalProperties = false;
325
+ else {
326
+ const constraints = [];
327
+ for (const object of objects) {
328
+ const constraint = undeclaredConstraint(object);
329
+ if (constraint && !constraints.some((seen) => JSON.stringify(seen) === JSON.stringify(constraint))) constraints.push(constraint);
330
+ }
331
+ if (constraints.length === 1) folded.additionalProperties = constraints[0];
332
+ else if (constraints.length > 1) folded.additionalProperties = { allOf: constraints };
333
+ }
334
+ return folded;
335
+ }
336
+ /** `additionalProperties` in an `allOf` member sees only that member's own `properties`, so two
337
+ * closed object members reject each other's keys and the schema validates nothing. Zod's parser
338
+ * pools the key sets instead — `handleIntersectionResults` reports a key as unrecognized only when
339
+ * *every* side rejects it — so the emitted schema has to pool them too, and folding the members
340
+ * into one object is the encoding that says so on every target.
341
+ *
342
+ * This runs from `finalize`, after `extractDefs`, which is what keeps it clear of the `$ref`
343
+ * machinery: a member extracted into `$defs` is already a `$ref` by now and declines to fold, so it
344
+ * keeps its reference and its own closedness rather than being inlined as a stale copy. */
345
+ function foldIntersection(json) {
346
+ const allOf = json.allOf;
347
+ if (!Array.isArray(allOf) || allOf.length < 2) return;
348
+ for (const key of FOLDABLE_KEYS) if (key in json) return;
349
+ const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
350
+ let folded = null;
351
+ if (!unions.length) folded = foldObjects(allOf);
352
+ else {
353
+ const union = unions[0];
354
+ const keyword = UNION_KEYS.find((k) => Array.isArray(union[k]));
355
+ if (Object.keys(union).length !== 1) return;
356
+ const rest = allOf.filter((m) => m !== union);
357
+ const branches = union[keyword].map((branch) => foldObjects([...rest, branch]));
358
+ if (branches.some((b) => !b)) return;
359
+ folded = { [keyword]: branches };
360
+ }
361
+ if (!folded) return;
362
+ delete json.allOf;
363
+ assignProps(json, folded);
364
+ }
365
+ function finalize(ctx, schema) {
366
+ const root = ctx.seen.get(schema);
367
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
368
+ const flattenRef = (zodSchema) => {
369
+ const seen = ctx.seen.get(zodSchema);
370
+ if (seen.ref === null) return;
371
+ const schema = seen.def ?? seen.schema;
372
+ const _cached = { ...schema };
373
+ const ref = seen.ref;
374
+ seen.ref = null;
375
+ if (ref) {
376
+ flattenRef(ref);
377
+ const refSeen = ctx.seen.get(ref);
378
+ const refSchema = refSeen.schema;
379
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
380
+ schema.allOf = schema.allOf ?? [];
381
+ schema.allOf.push(refSchema);
382
+ } else assignProps(schema, refSchema);
383
+ assignProps(schema, _cached);
384
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
385
+ if (key === "$ref" || key === "allOf") continue;
386
+ if (!(key in _cached)) delete schema[key];
387
+ }
388
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
389
+ if (key === "$ref" || key === "allOf") continue;
390
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
391
+ }
392
+ }
393
+ const parent = zodSchema._zod.parent;
394
+ if (parent && parent !== ref) {
395
+ flattenRef(parent);
396
+ const parentSeen = ctx.seen.get(parent);
397
+ if (parentSeen?.schema.$ref) {
398
+ schema.$ref = parentSeen.schema.$ref;
399
+ if (parentSeen.def) for (const key in schema) {
400
+ if (key === "$ref" || key === "allOf") continue;
401
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
402
+ }
403
+ }
404
+ }
405
+ ctx.override({
406
+ zodSchema,
407
+ jsonSchema: schema,
408
+ path: seen.path ?? []
409
+ });
410
+ };
411
+ if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) {
412
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
413
+ if (ctx.target !== "openapi-3.0") for (const entry of ctx.seen.entries()) compactTypeUnion(entry[1].def ?? entry[1].schema);
414
+ for (const rewrite of ctx.deferred) rewrite();
415
+ if (ctx.intersections.length) {
416
+ const carriers = /* @__PURE__ */ new Map();
417
+ for (const seen of ctx.seen.values()) for (const json of [seen.schema, seen.def]) {
418
+ const allOf = json?.allOf;
419
+ if (!Array.isArray(allOf)) continue;
420
+ const existing = carriers.get(allOf);
421
+ if (existing) existing.push(json);
422
+ else carriers.set(allOf, [json]);
423
+ }
424
+ for (const allOf of ctx.intersections) for (const json of carriers.get(allOf) ?? []) foldIntersection(json);
425
+ }
426
+ }
427
+ const result = {};
428
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
429
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
430
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
431
+ else if (ctx.target === "openapi-3.0") {}
432
+ if (ctx.external?.uri) {
433
+ const id = ctx.external.registry.get(schema)?.id;
434
+ if (!id) throw new Error("Schema is missing an `id` property");
435
+ result.$id = ctx.external.uri(id);
436
+ }
437
+ assignProps(result, root.defId ? root.schema : root.def ?? root.schema);
438
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
439
+ if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
440
+ const defs = ctx.external?.defs ?? {};
441
+ if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) for (const entry of ctx.seen.entries()) {
442
+ const seen = entry[1];
443
+ if (seen.def && seen.defId) {
444
+ if (seen.def.id === seen.defId) delete seen.def.id;
445
+ assignProp(defs, seen.defId, seen.def);
446
+ }
447
+ }
448
+ if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
449
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
450
+ else result.definitions = defs;
451
+ try {
452
+ const finalized = JSON.parse(JSON.stringify(result));
453
+ Object.defineProperty(finalized, "~standard", {
454
+ value: {
455
+ ...schema["~standard"],
456
+ jsonSchema: {
457
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
458
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
459
+ }
460
+ },
461
+ enumerable: false,
462
+ writable: false
463
+ });
464
+ return finalized;
465
+ } catch (_err) {
466
+ throw new Error("Error converting schema to JSON.");
467
+ }
468
+ }
469
+ function isTransforming(_schema, _ctx) {
470
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
471
+ if (ctx.seen.has(_schema)) return false;
472
+ ctx.seen.add(_schema);
473
+ const def = _schema._zod.def;
474
+ if (def.type === "transform") return true;
475
+ if (def.type === "array") return isTransforming(def.element, ctx);
476
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
477
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
478
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault" || def.type === "catch") return isTransforming(def.innerType, ctx);
479
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
480
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
481
+ if (def.type === "pipe") {
482
+ if (_schema._zod.traits.has("$ZodCodec")) return true;
483
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
484
+ }
485
+ if (def.type === "object") {
486
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
487
+ return false;
488
+ }
489
+ if (def.type === "union") {
490
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
491
+ return false;
492
+ }
493
+ if (def.type === "tuple") {
494
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
495
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
496
+ return false;
497
+ }
498
+ return false;
499
+ }
500
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
501
+ const { libraryOptions, target } = params ?? {};
502
+ const ctx = initializeContext({
503
+ ...libraryOptions ?? {},
504
+ target,
505
+ io,
506
+ processors
507
+ });
508
+ processSchema(schema, ctx);
509
+ extractDefs(ctx, schema);
510
+ return finalize(ctx, schema);
511
+ };
512
+ //#endregion
513
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/json-schema-processors.js
514
+ const narrowMin = (agg, key, value) => {
515
+ if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
516
+ };
517
+ const narrowMax = (agg, key, value) => {
518
+ if (agg[key] === void 0 || value < agg[key]) agg[key] = value;
519
+ };
520
+ const narrowBoth = (agg, value) => {
521
+ narrowMin(agg, "minimum", value);
522
+ narrowMax(agg, "maximum", value);
523
+ };
524
+ const addDivisor = (agg, value) => {
525
+ agg.multipleOf ?? (agg.multipleOf = []);
526
+ if (!agg.multipleOf.includes(value)) agg.multipleOf.push(value);
527
+ };
528
+ const addPattern = (agg, pattern) => {
529
+ agg.patterns ?? (agg.patterns = /* @__PURE__ */ new Set());
530
+ agg.patterns.add(pattern);
531
+ };
532
+ const intersectMime = (agg, mime) => {
533
+ agg.mime = agg.mime ? agg.mime.filter((m) => mime.includes(m)) : [...mime];
534
+ };
535
+ const setFormat = (agg, format) => {
536
+ agg.format = format;
537
+ if (format.includes("int")) agg.isInt = true;
538
+ };
539
+ const minContributor = (agg, def) => narrowMin(agg, "minimum", def.minimum);
540
+ const maxContributor = (agg, def) => narrowMax(agg, "maximum", def.maximum);
541
+ const formatContributor = (ranges) => (agg, def) => {
542
+ setFormat(agg, def.format);
543
+ const [minimum, maximum] = ranges[def.format];
544
+ narrowMin(agg, "minimum", minimum);
545
+ narrowMax(agg, "maximum", maximum);
546
+ };
547
+ const contributors = {
548
+ greater_than: (agg, def) => narrowMin(agg, def.inclusive ? "minimum" : "exclusiveMinimum", def.value),
549
+ less_than: (agg, def) => narrowMax(agg, def.inclusive ? "maximum" : "exclusiveMaximum", def.value),
550
+ multiple_of: (agg, def) => addDivisor(agg, def.value),
551
+ number_format: formatContributor(NUMBER_FORMAT_RANGES),
552
+ bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
553
+ min_length: minContributor,
554
+ max_length: maxContributor,
555
+ length_equals: (agg, def) => narrowBoth(agg, def.length),
556
+ min_size: minContributor,
557
+ max_size: maxContributor,
558
+ size_equals: (agg, def) => narrowBoth(agg, def.size),
559
+ string_format: (agg, def) => {
560
+ setFormat(agg, def.format);
561
+ if (def.pattern) addPattern(agg, def.pattern);
562
+ if (def.format === "base64" || def.format === "base64url") agg.contentEncoding = def.format;
563
+ if (def.local || def.precision === -1) agg.laxFormat = true;
564
+ },
565
+ mime_type: (agg, def) => intersectMime(agg, def.mime)
566
+ };
567
+ function aggregateChecks(schema) {
568
+ const agg = {};
569
+ const def = schema._zod.def;
570
+ const list = schema._zod.traits.has("$ZodCheck") ? [schema, ...def.checks ?? []] : def.checks ?? [];
571
+ for (const ch of list) contributors[ch._zod.def.check]?.(agg, ch._zod.def);
572
+ const bag = schema._zod.bag;
573
+ if (bag.minimum !== void 0) narrowMin(agg, "minimum", bag.minimum);
574
+ if (bag.exclusiveMinimum !== void 0) narrowMin(agg, "exclusiveMinimum", bag.exclusiveMinimum);
575
+ if (bag.maximum !== void 0) narrowMax(agg, "maximum", bag.maximum);
576
+ if (bag.exclusiveMaximum !== void 0) narrowMax(agg, "exclusiveMaximum", bag.exclusiveMaximum);
577
+ if (bag.multipleOf !== void 0) addDivisor(agg, bag.multipleOf);
578
+ if (bag.format !== void 0) {
579
+ agg.format ?? (agg.format = bag.format);
580
+ if (bag.format.includes("int")) agg.isInt = true;
581
+ }
582
+ if (bag.mime) intersectMime(agg, bag.mime);
583
+ for (const pattern of bag.patterns ?? []) addPattern(agg, pattern);
584
+ return agg;
585
+ }
586
+ const formatMap = {
587
+ guid: "uuid",
588
+ url: "uri",
589
+ datetime: "date-time",
590
+ json_string: "json-string",
591
+ regex: ""
592
+ };
593
+ const exactPatterns = /* @__PURE__ */ new Map([[base64Charset, base64], [base64urlCharset, base64url]]);
594
+ const exactPattern = (p) => exactPatterns.get(p) ?? p;
595
+ const stringProcessor = (schema, ctx, _json, _params) => {
596
+ const json = _json;
597
+ json.type = "string";
598
+ const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
599
+ if (typeof minimum === "number") json.minLength = minimum;
600
+ if (typeof maximum === "number") json.maxLength = maximum;
601
+ if (format) {
602
+ json.format = formatMap[format] ?? format;
603
+ if (json.format === "") delete json.format;
604
+ if (format === "time" || laxFormat) delete json.format;
605
+ }
606
+ if (contentEncoding) json.contentEncoding = contentEncoding;
607
+ if (patterns && patterns.size > 0) {
608
+ const patternList = [...patterns].map(exactPattern);
609
+ if (patternList.length === 1) json.pattern = patternList[0].source;
610
+ else if (patternList.length > 1) json.allOf = [...patternList.map((regex) => ({
611
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
612
+ pattern: regex.source
613
+ }))];
614
+ }
615
+ };
616
+ const numberProcessor = (schema, ctx, _json, params) => {
617
+ const json = _json;
618
+ const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } = aggregateChecks(schema);
619
+ json.type = isInt ? "integer" : "number";
620
+ const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
621
+ const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
622
+ const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
623
+ if (exMin) if (legacy) {
624
+ json.minimum = exclusiveMinimum;
625
+ json.exclusiveMinimum = true;
626
+ } else json.exclusiveMinimum = exclusiveMinimum;
627
+ else if (typeof minimum === "number") json.minimum = minimum;
628
+ if (exMax) if (legacy) {
629
+ json.maximum = exclusiveMaximum;
630
+ json.exclusiveMaximum = true;
631
+ } else json.exclusiveMaximum = exclusiveMaximum;
632
+ else if (typeof maximum === "number") json.maximum = maximum;
633
+ if (multipleOf) {
634
+ const divisors = /* @__PURE__ */ new Set();
635
+ for (const divisor of multipleOf) if (Number.isFinite(divisor) && divisor !== 0) divisors.add(Math.abs(divisor));
636
+ else handleUnrepresentable(schema, ctx, json, params, `A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`);
637
+ const [first, ...rest] = divisors;
638
+ if (first !== void 0) json.multipleOf = first;
639
+ if (rest.length) json.allOf = [...json.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
640
+ }
641
+ };
642
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
643
+ json.type = "boolean";
644
+ };
645
+ const bigintProcessor = (schema, ctx, json, params) => {
646
+ handleUnrepresentable(schema, ctx, json, params, "BigInt cannot be represented in JSON Schema");
647
+ };
648
+ const symbolProcessor = (schema, ctx, json, params) => {
649
+ handleUnrepresentable(schema, ctx, json, params, "Symbols cannot be represented in JSON Schema");
650
+ };
651
+ const nullProcessor = (_schema, ctx, json, _params) => {
652
+ if (ctx.target === "openapi-3.0") {
653
+ json.type = "string";
654
+ json.nullable = true;
655
+ json.enum = [null];
656
+ } else json.type = "null";
657
+ };
658
+ const undefinedProcessor = (schema, ctx, json, params) => {
659
+ handleUnrepresentable(schema, ctx, json, params, "Undefined cannot be represented in JSON Schema");
660
+ };
661
+ const voidProcessor = (schema, ctx, json, params) => {
662
+ handleUnrepresentable(schema, ctx, json, params, "Void cannot be represented in JSON Schema");
663
+ };
664
+ const neverProcessor = (_schema, _ctx, json, _params) => {
665
+ json.not = {};
666
+ };
667
+ const anyProcessor = (_schema, _ctx, _json, _params) => {};
668
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {};
669
+ const dateProcessor = (schema, ctx, json, params) => {
670
+ handleUnrepresentable(schema, ctx, json, params, "Date cannot be represented in JSON Schema");
671
+ };
672
+ const enumProcessor = (schema, _ctx, json, _params) => {
673
+ const def = schema._zod.def;
674
+ const values = getEnumValues(def.entries);
675
+ if (values.length === 0) {
676
+ json.not = {};
677
+ return;
678
+ }
679
+ if (values.every((v) => typeof v === "number")) json.type = "number";
680
+ if (values.every((v) => typeof v === "string")) json.type = "string";
681
+ json.enum = values;
682
+ };
683
+ const literalProcessor = (schema, ctx, json, params) => {
684
+ const def = schema._zod.def;
685
+ if (def.values.length === 0) {
686
+ json.not = {};
687
+ return;
688
+ }
689
+ const vals = [];
690
+ for (const val of def.values) if (val === void 0) {
691
+ if (handleUnrepresentable(schema, ctx, json, params, "Literal `undefined` cannot be represented in JSON Schema")) return;
692
+ } else if (typeof val === "bigint") {
693
+ if (handleUnrepresentable(schema, ctx, json, params, "BigInt literals cannot be represented in JSON Schema")) return;
694
+ vals.push(Number(val));
695
+ } else vals.push(val);
696
+ if (vals.length === 0) {} else if (vals.length === 1) {
697
+ const val = vals[0];
698
+ json.type = val === null ? "null" : typeof val;
699
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
700
+ else json.const = val;
701
+ } else {
702
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
703
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
704
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
705
+ if (vals.every((v) => v === null)) json.type = "null";
706
+ json.enum = vals;
707
+ }
708
+ };
709
+ const nanProcessor = (schema, ctx, json, params) => {
710
+ handleUnrepresentable(schema, ctx, json, params, "NaN cannot be represented in JSON Schema");
711
+ };
712
+ const templateLiteralProcessor = (schema, _ctx, json, _params) => {
713
+ const _json = json;
714
+ const pattern = schema._zod.pattern;
715
+ if (!pattern) throw new Error("Pattern not found in template literal");
716
+ _json.type = "string";
717
+ _json.pattern = pattern.source;
718
+ };
719
+ const fileProcessor = (schema, _ctx, json, _params) => {
720
+ const _json = json;
721
+ _json.type = "string";
722
+ _json.format = "binary";
723
+ _json.contentEncoding = "binary";
724
+ const { minimum, maximum, mime } = aggregateChecks(schema);
725
+ if (minimum !== void 0) _json.minLength = minimum;
726
+ if (maximum !== void 0) _json.maxLength = maximum;
727
+ if (!mime) return;
728
+ if (mime.length === 0) _json.not = {};
729
+ else if (mime.length === 1) _json.contentMediaType = mime[0];
730
+ else _json.anyOf = mime.map((m) => ({ contentMediaType: m }));
731
+ };
732
+ const successProcessor = (_schema, _ctx, json, _params) => {
733
+ json.type = "boolean";
734
+ };
735
+ const customProcessor = (schema, ctx, json, params) => {
736
+ handleUnrepresentable(schema, ctx, json, params, "Custom types cannot be represented in JSON Schema");
737
+ };
738
+ const functionProcessor = (schema, ctx, json, params) => {
739
+ handleUnrepresentable(schema, ctx, json, params, "Function types cannot be represented in JSON Schema");
740
+ };
741
+ const transformProcessor = (schema, ctx, json, params) => {
742
+ handleUnrepresentable(schema, ctx, json, params, "Transforms cannot be represented in JSON Schema");
743
+ };
744
+ const mapProcessor = (schema, ctx, json, params) => {
745
+ handleUnrepresentable(schema, ctx, json, params, "Map cannot be represented in JSON Schema");
746
+ };
747
+ const setProcessor = (schema, ctx, json, params) => {
748
+ handleUnrepresentable(schema, ctx, json, params, "Set cannot be represented in JSON Schema");
749
+ };
750
+ const arrayProcessor = (schema, ctx, _json, params) => {
751
+ const json = _json;
752
+ const def = schema._zod.def;
753
+ const { minimum, maximum } = aggregateChecks(schema);
754
+ if (typeof minimum === "number") json.minItems = minimum;
755
+ if (typeof maximum === "number") json.maxItems = maximum;
756
+ json.type = "array";
757
+ json.items = processSchema(def.element, ctx, {
758
+ ...params,
759
+ path: [...params.path, "items"]
760
+ });
761
+ };
762
+ function inputOptin(schema) {
763
+ const def = schema._zod.def;
764
+ if (def.type === "pipe" && def.in._zod.traits.has("$ZodTransform")) return inputOptin(def.out);
765
+ if (def.type === "catch") return inputOptin(def.innerType);
766
+ return schema._zod.optin;
767
+ }
768
+ const objectProcessor = (schema, ctx, _json, params) => {
769
+ const json = _json;
770
+ const def = schema._zod.def;
771
+ const shape = def.shape;
772
+ if (Object.getOwnPropertySymbols(shape).length && handleUnrepresentable(schema, ctx, json, params, "Symbol keys cannot be represented in JSON Schema")) return;
773
+ json.type = "object";
774
+ json.properties = {};
775
+ for (const key in shape) assignProp(json.properties, key, processSchema(shape[key], ctx, {
776
+ ...params,
777
+ path: [
778
+ ...params.path,
779
+ "properties",
780
+ key
781
+ ]
782
+ }));
783
+ const requiredKeys = [];
784
+ for (const key of Object.keys(shape)) {
785
+ const field = def.shape[key];
786
+ if (ctx.io === "input" ? inputOptin(field) === void 0 : field._zod.optout === void 0) requiredKeys.push(key);
787
+ }
788
+ if (requiredKeys.length > 0) json.required = requiredKeys;
789
+ if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
790
+ else if (!def.catchall) {
791
+ if (ctx.io === "output") json.additionalProperties = false;
792
+ } else if (def.catchall) json.additionalProperties = processSchema(def.catchall, ctx, {
793
+ ...params,
794
+ path: [...params.path, "additionalProperties"]
795
+ });
796
+ };
797
+ const unionProcessor = (schema, ctx, json, params) => {
798
+ const def = schema._zod.def;
799
+ const isExclusive = def.inclusive === false;
800
+ const options = def.options.map((x, i) => processSchema(x, ctx, {
801
+ ...params,
802
+ path: [
803
+ ...params.path,
804
+ isExclusive ? "oneOf" : "anyOf",
805
+ i
806
+ ]
807
+ }));
808
+ if (isExclusive) json.oneOf = options;
809
+ else json.anyOf = options;
810
+ };
811
+ const intersectionProcessor = (schema, ctx, json, params) => {
812
+ const def = schema._zod.def;
813
+ const a = processSchema(def.left, ctx, {
814
+ ...params,
815
+ path: [
816
+ ...params.path,
817
+ "allOf",
818
+ 0
819
+ ]
820
+ });
821
+ const b = processSchema(def.right, ctx, {
822
+ ...params,
823
+ path: [
824
+ ...params.path,
825
+ "allOf",
826
+ 1
827
+ ]
828
+ });
829
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
830
+ const allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
831
+ json.allOf = allOf;
832
+ ctx.intersections.push(allOf);
833
+ };
834
+ const tupleProcessor = (schema, ctx, _json, params) => {
835
+ const json = _json;
836
+ const def = schema._zod.def;
837
+ json.type = "array";
838
+ const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
839
+ const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
840
+ const prefixItems = def.items.map((x, i) => processSchema(x, ctx, {
841
+ ...params,
842
+ path: [
843
+ ...params.path,
844
+ prefixPath,
845
+ i
846
+ ]
847
+ }));
848
+ const rest = def.rest ? processSchema(def.rest, ctx, {
849
+ ...params,
850
+ path: [
851
+ ...params.path,
852
+ restPath,
853
+ ...ctx.target === "openapi-3.0" ? [def.items.length] : []
854
+ ]
855
+ }) : null;
856
+ let minItems = def.items.length;
857
+ while (minItems > 0) {
858
+ const item = def.items[minItems - 1];
859
+ if (!(ctx.io === "input" ? inputOptin(item) !== void 0 : item._zod.optout === "optional")) break;
860
+ minItems--;
861
+ }
862
+ const maxItems = def.items.length;
863
+ const isClosed = !def.rest;
864
+ if (ctx.target === "draft-2020-12") {
865
+ json.prefixItems = prefixItems;
866
+ if (isClosed) json.items = false;
867
+ else if (rest) json.items = rest;
868
+ if (minItems > 0) json.minItems = minItems;
869
+ if (isClosed) json.maxItems = maxItems;
870
+ } else if (ctx.target === "openapi-3.0") {
871
+ json.items = { anyOf: prefixItems };
872
+ if (rest) json.items.anyOf.push(rest);
873
+ if (minItems > 0) json.minItems = minItems;
874
+ if (isClosed) json.maxItems = maxItems;
875
+ } else {
876
+ json.items = prefixItems;
877
+ if (isClosed) json.additionalItems = false;
878
+ else if (rest) json.additionalItems = rest;
879
+ if (minItems > 0) json.minItems = minItems;
880
+ if (isClosed) json.maxItems = maxItems;
881
+ }
882
+ const { minimum, maximum } = aggregateChecks(schema);
883
+ if (typeof minimum === "number") json.minItems = minimum;
884
+ if (typeof maximum === "number") json.maxItems = maximum;
885
+ };
886
+ /** JSON object keys are always strings, so a numeric record key schema is re-expressed over the
887
+ * numeric-string form the record parser matches. Deferred to `finalize`, after the flatten: a key
888
+ * behind a wrapper only carries its own `type` before then, and a union key only has its branches.
889
+ *
890
+ * A numeric bound cannot apply to a property name, so `minimum` and its siblings are dropped rather
891
+ * than carried over: keeping them beside `type: "string"` reproduces the match-nothing schema this
892
+ * exists to fix. A key that carries one therefore emits wider than the record parses — `z.record(z.number().min(5), V)`
893
+ * accepts `"3"` — which is the deliberate trade, since throwing on it would reject an ordinary schema
894
+ * outright. */
895
+ function stringifyKeyNames(bySchema, json, visited) {
896
+ if (json.$ref) {
897
+ if (visited.has(json)) return json;
898
+ visited.add(json);
899
+ const def = bySchema.get(json)?.def;
900
+ if (!def) return json;
901
+ const inlined = stringifyKeyNames(bySchema, def, visited);
902
+ return inlined === def ? json : inlined;
903
+ }
904
+ for (const keyword of ["anyOf", "oneOf"]) {
905
+ const branches = json[keyword];
906
+ if (!Array.isArray(branches)) continue;
907
+ const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
908
+ if (mapped.some((branch, i) => branch !== branches[i])) json = {
909
+ ...json,
910
+ [keyword]: mapped
911
+ };
912
+ }
913
+ const types = Array.isArray(json.type) ? json.type : [json.type];
914
+ const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
915
+ const values = json.enum ?? (json.const !== void 0 ? [json.const] : void 0);
916
+ if (!numericType && !values?.some((v) => typeof v === "number")) return json;
917
+ const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json;
918
+ if (rest.enum) rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
919
+ else if (typeof rest.const === "number") rest.const = String(rest.const);
920
+ if (!numericType) return rest;
921
+ rest.type = "string";
922
+ if (!values) rest.pattern = (types.includes("number") ? number : integer).source;
923
+ return rest;
924
+ }
925
+ /** Every record of one conversion, so the carriers are found in a single pass rather than once per record. */
926
+ const pendingRecords = /* @__PURE__ */ new WeakMap();
927
+ function rewriteKeyNames(ctx) {
928
+ const bySchema = /* @__PURE__ */ new Map();
929
+ for (const entry of ctx.seen.values()) if (entry.def && !bySchema.has(entry.schema)) bySchema.set(entry.schema, entry);
930
+ const rewrites = /* @__PURE__ */ new Map();
931
+ for (const record of pendingRecords.get(ctx) ?? []) {
932
+ const seen = ctx.seen.get(record);
933
+ const names = (seen?.def ?? seen?.schema)?.propertyNames;
934
+ if (!names || names === true || rewrites.has(names)) continue;
935
+ const rewritten = stringifyKeyNames(bySchema, names, /* @__PURE__ */ new Set());
936
+ if (rewritten !== names) rewrites.set(names, rewritten);
937
+ }
938
+ if (!rewrites.size) return;
939
+ for (const entry of ctx.seen.values()) for (const carrier of [entry.schema, entry.def]) {
940
+ const rewritten = carrier && rewrites.get(carrier.propertyNames);
941
+ if (rewritten) carrier.propertyNames = rewritten;
942
+ }
943
+ }
944
+ const recordProcessor = (schema, ctx, _json, params) => {
945
+ const json = _json;
946
+ const def = schema._zod.def;
947
+ json.type = "object";
948
+ const keyType = def.keyType;
949
+ const patterns = aggregateChecks(keyType).patterns;
950
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
951
+ const valueSchema = processSchema(def.valueType, ctx, {
952
+ ...params,
953
+ path: [
954
+ ...params.path,
955
+ "patternProperties",
956
+ "*"
957
+ ]
958
+ });
959
+ json.patternProperties = {};
960
+ for (const pattern of patterns) assignProp(json.patternProperties, exactPattern(pattern).source, valueSchema);
961
+ } else {
962
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
963
+ json.propertyNames = processSchema(def.keyType, ctx, {
964
+ ...params,
965
+ path: [...params.path, "propertyNames"]
966
+ });
967
+ let pending = pendingRecords.get(ctx);
968
+ if (!pending) {
969
+ pending = [];
970
+ pendingRecords.set(ctx, pending);
971
+ ctx.deferred.push(() => rewriteKeyNames(ctx));
972
+ }
973
+ pending.push(schema);
974
+ }
975
+ json.additionalProperties = processSchema(def.valueType, ctx, {
976
+ ...params,
977
+ path: [...params.path, "additionalProperties"]
978
+ });
979
+ }
980
+ const keyValues = keyType._zod.values;
981
+ const omittableOnInput = ctx.io === "input" && inputOptin(def.valueType) !== void 0;
982
+ if (keyValues && !def.partial && !omittableOnInput) {
983
+ const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
984
+ if (validKeyValues.length > 0) json.required = validKeyValues.map(String);
985
+ }
986
+ };
987
+ const nullableProcessor = (schema, ctx, json, params) => {
988
+ const def = schema._zod.def;
989
+ const inner = processSchema(def.innerType, ctx, params);
990
+ const seen = ctx.seen.get(schema);
991
+ if (ctx.target === "openapi-3.0") {
992
+ seen.ref = def.innerType;
993
+ json.nullable = true;
994
+ } else json.anyOf = [inner, { type: "null" }];
995
+ };
996
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
997
+ const def = schema._zod.def;
998
+ processSchema(def.innerType, ctx, params);
999
+ const seen = ctx.seen.get(schema);
1000
+ seen.ref = def.innerType;
1001
+ };
1002
+ /** Round-trips a default value through JSON so the emitted schema is guaranteed to be valid JSON.
1003
+ * A BigInt has no reliable encoding, so it goes through `unrepresentable` like any other
1004
+ * unrepresentable value. Returns a sentinel when the caller must not write a default of its own. */
1005
+ const UNREPRESENTABLE_DEFAULT = Symbol();
1006
+ function serializeDefaultValue(value, schema, ctx, json, params) {
1007
+ let unrepresentable = false;
1008
+ const serialized = JSON.stringify(value, (_, val) => {
1009
+ if (typeof val !== "bigint") return val;
1010
+ unrepresentable = true;
1011
+ return null;
1012
+ });
1013
+ if (!unrepresentable) return JSON.parse(serialized);
1014
+ handleUnrepresentable(schema, ctx, json, params, "BigInt defaults cannot be represented in JSON Schema");
1015
+ return UNREPRESENTABLE_DEFAULT;
1016
+ }
1017
+ const defaultProcessor = (schema, ctx, json, params) => {
1018
+ const def = schema._zod.def;
1019
+ processSchema(def.innerType, ctx, params);
1020
+ const seen = ctx.seen.get(schema);
1021
+ seen.ref = def.innerType;
1022
+ const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
1023
+ if (value !== UNREPRESENTABLE_DEFAULT) json.default = value;
1024
+ };
1025
+ const prefaultProcessor = (schema, ctx, json, params) => {
1026
+ const def = schema._zod.def;
1027
+ processSchema(def.innerType, ctx, params);
1028
+ const seen = ctx.seen.get(schema);
1029
+ seen.ref = def.innerType;
1030
+ if (ctx.io !== "input") return;
1031
+ const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
1032
+ if (value !== UNREPRESENTABLE_DEFAULT) json._prefault = value;
1033
+ };
1034
+ const catchProcessor = (schema, ctx, json, params) => {
1035
+ const def = schema._zod.def;
1036
+ processSchema(def.innerType, ctx, params);
1037
+ const seen = ctx.seen.get(schema);
1038
+ seen.ref = def.innerType;
1039
+ let catchValue;
1040
+ try {
1041
+ catchValue = def.catchValue(void 0);
1042
+ } catch {
1043
+ handleUnrepresentable(schema, ctx, json, params, "Dynamic catch values are not supported in JSON Schema");
1044
+ return;
1045
+ }
1046
+ json.default = catchValue;
1047
+ };
1048
+ const pipeProcessor = (schema, ctx, _json, params) => {
1049
+ const def = schema._zod.def;
1050
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
1051
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
1052
+ processSchema(innerType, ctx, params);
1053
+ const seen = ctx.seen.get(schema);
1054
+ seen.ref = innerType;
1055
+ };
1056
+ const readonlyProcessor = (schema, ctx, json, params) => {
1057
+ const def = schema._zod.def;
1058
+ processSchema(def.innerType, ctx, params);
1059
+ const seen = ctx.seen.get(schema);
1060
+ seen.ref = def.innerType;
1061
+ json.readOnly = true;
1062
+ };
1063
+ const promiseProcessor = (schema, ctx, _json, params) => {
1064
+ const def = schema._zod.def;
1065
+ processSchema(def.innerType, ctx, params);
1066
+ const seen = ctx.seen.get(schema);
1067
+ seen.ref = def.innerType;
1068
+ };
1069
+ const optionalProcessor = (schema, ctx, _json, params) => {
1070
+ const def = schema._zod.def;
1071
+ processSchema(def.innerType, ctx, params);
1072
+ const seen = ctx.seen.get(schema);
1073
+ seen.ref = def.innerType;
1074
+ };
1075
+ const lazyProcessor = (schema, ctx, _json, params) => {
1076
+ const innerType = schema._zod.innerType;
1077
+ processSchema(innerType, ctx, params);
1078
+ const seen = ctx.seen.get(schema);
1079
+ seen.ref = innerType;
1080
+ };
1081
+ const allProcessors = {
1082
+ string: stringProcessor,
1083
+ number: numberProcessor,
1084
+ boolean: booleanProcessor,
1085
+ bigint: bigintProcessor,
1086
+ symbol: symbolProcessor,
1087
+ null: nullProcessor,
1088
+ undefined: undefinedProcessor,
1089
+ void: voidProcessor,
1090
+ never: neverProcessor,
1091
+ any: anyProcessor,
1092
+ unknown: unknownProcessor,
1093
+ date: dateProcessor,
1094
+ enum: enumProcessor,
1095
+ literal: literalProcessor,
1096
+ nan: nanProcessor,
1097
+ template_literal: templateLiteralProcessor,
1098
+ file: fileProcessor,
1099
+ success: successProcessor,
1100
+ custom: customProcessor,
1101
+ function: functionProcessor,
1102
+ transform: transformProcessor,
1103
+ map: mapProcessor,
1104
+ set: setProcessor,
1105
+ array: arrayProcessor,
1106
+ object: objectProcessor,
1107
+ union: unionProcessor,
1108
+ intersection: intersectionProcessor,
1109
+ tuple: tupleProcessor,
1110
+ record: recordProcessor,
1111
+ nullable: nullableProcessor,
1112
+ nonoptional: nonoptionalProcessor,
1113
+ default: defaultProcessor,
1114
+ prefault: prefaultProcessor,
1115
+ catch: catchProcessor,
1116
+ pipe: pipeProcessor,
1117
+ readonly: readonlyProcessor,
1118
+ promise: promiseProcessor,
1119
+ optional: optionalProcessor,
1120
+ lazy: lazyProcessor
1121
+ };
1122
+ function toJSONSchema(input, params) {
1123
+ if ("_idmap" in input) {
1124
+ const registry = input;
1125
+ const ctx = initializeContext({
1126
+ ...params,
1127
+ processors: allProcessors
1128
+ });
1129
+ const defs = {};
1130
+ for (const entry of registry._idmap.entries()) {
1131
+ const [_, schema] = entry;
1132
+ processSchema(schema, ctx);
1133
+ }
1134
+ const schemas = {};
1135
+ ctx.external = {
1136
+ registry,
1137
+ uri: params?.uri,
1138
+ defs
1139
+ };
1140
+ for (const entry of registry._idmap.entries()) {
1141
+ const [key, schema] = entry;
1142
+ extractDefs(ctx, schema);
1143
+ assignProp(schemas, key, finalize(ctx, schema));
1144
+ }
1145
+ if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
1146
+ return { schemas };
1147
+ }
1148
+ const ctx = initializeContext({
1149
+ ...params,
1150
+ processors: allProcessors
1151
+ });
1152
+ processSchema(input, ctx);
1153
+ extractDefs(ctx, input);
1154
+ return finalize(ctx, input);
1155
+ }
1156
+ //#endregion
1157
+ exports.toJSONSchema = toJSONSchema;
1158
+
1159
+ //# sourceMappingURL=core-QL_X0T4Y.cjs.map