@alint-js/plugin-simplicity 0.0.28 → 0.0.30

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.
@@ -0,0 +1,788 @@
1
+ //#region ../../node_modules/.pnpm/zod@4.4.3/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
+ "captureStackTrace" in Error && Error.captureStackTrace;
7
+ Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
8
+ //#endregion
9
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
10
+ var _a;
11
+ var $ZodRegistry = class {
12
+ constructor() {
13
+ this._map = /* @__PURE__ */ new WeakMap();
14
+ this._idmap = /* @__PURE__ */ new Map();
15
+ }
16
+ add(schema, ..._meta) {
17
+ const meta = _meta[0];
18
+ this._map.set(schema, meta);
19
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
20
+ return this;
21
+ }
22
+ clear() {
23
+ this._map = /* @__PURE__ */ new WeakMap();
24
+ this._idmap = /* @__PURE__ */ new Map();
25
+ return this;
26
+ }
27
+ remove(schema) {
28
+ const meta = this._map.get(schema);
29
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
30
+ this._map.delete(schema);
31
+ return this;
32
+ }
33
+ get(schema) {
34
+ const p = schema._zod.parent;
35
+ if (p) {
36
+ const pm = { ...this.get(p) ?? {} };
37
+ delete pm.id;
38
+ const f = {
39
+ ...pm,
40
+ ...this._map.get(schema)
41
+ };
42
+ return Object.keys(f).length ? f : void 0;
43
+ }
44
+ return this._map.get(schema);
45
+ }
46
+ has(schema) {
47
+ return this._map.has(schema);
48
+ }
49
+ };
50
+ function registry() {
51
+ return new $ZodRegistry();
52
+ }
53
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
54
+ const globalRegistry = globalThis.__zod_globalRegistry;
55
+ //#endregion
56
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
57
+ function initializeContext(params) {
58
+ let target = params?.target ?? "draft-2020-12";
59
+ if (target === "draft-4") target = "draft-04";
60
+ if (target === "draft-7") target = "draft-07";
61
+ return {
62
+ processors: params.processors ?? {},
63
+ metadataRegistry: params?.metadata ?? globalRegistry,
64
+ target,
65
+ unrepresentable: params?.unrepresentable ?? "throw",
66
+ override: params?.override ?? (() => {}),
67
+ io: params?.io ?? "output",
68
+ counter: 0,
69
+ seen: /* @__PURE__ */ new Map(),
70
+ cycles: params?.cycles ?? "ref",
71
+ reused: params?.reused ?? "inline",
72
+ external: params?.external ?? void 0
73
+ };
74
+ }
75
+ function process(schema, ctx, _params = {
76
+ path: [],
77
+ schemaPath: []
78
+ }) {
79
+ var _a;
80
+ const def = schema._zod.def;
81
+ const seen = ctx.seen.get(schema);
82
+ if (seen) {
83
+ seen.count++;
84
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
85
+ return seen.schema;
86
+ }
87
+ const result = {
88
+ schema: {},
89
+ count: 1,
90
+ cycle: void 0,
91
+ path: _params.path
92
+ };
93
+ ctx.seen.set(schema, result);
94
+ const overrideSchema = schema._zod.toJSONSchema?.();
95
+ if (overrideSchema) result.schema = overrideSchema;
96
+ else {
97
+ const params = {
98
+ ..._params,
99
+ schemaPath: [..._params.schemaPath, schema],
100
+ path: _params.path
101
+ };
102
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
103
+ else {
104
+ const _json = result.schema;
105
+ const processor = ctx.processors[def.type];
106
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
107
+ processor(schema, ctx, _json, params);
108
+ }
109
+ const parent = schema._zod.parent;
110
+ if (parent) {
111
+ if (!result.ref) result.ref = parent;
112
+ process(parent, ctx, params);
113
+ ctx.seen.get(parent).isParent = true;
114
+ }
115
+ }
116
+ const meta = ctx.metadataRegistry.get(schema);
117
+ if (meta) Object.assign(result.schema, meta);
118
+ if (ctx.io === "input" && isTransforming(schema)) {
119
+ delete result.schema.examples;
120
+ delete result.schema.default;
121
+ }
122
+ if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
123
+ delete result.schema._prefault;
124
+ return ctx.seen.get(schema).schema;
125
+ }
126
+ function extractDefs(ctx, schema) {
127
+ const root = ctx.seen.get(schema);
128
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
129
+ const idToSchema = /* @__PURE__ */ new Map();
130
+ for (const entry of ctx.seen.entries()) {
131
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
132
+ if (id) {
133
+ const existing = idToSchema.get(id);
134
+ 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.`);
135
+ idToSchema.set(id, entry[0]);
136
+ }
137
+ }
138
+ const makeURI = (entry) => {
139
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
140
+ if (ctx.external) {
141
+ const externalId = ctx.external.registry.get(entry[0])?.id;
142
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
143
+ if (externalId) return { ref: uriGenerator(externalId) };
144
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
145
+ entry[1].defId = id;
146
+ return {
147
+ defId: id,
148
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
149
+ };
150
+ }
151
+ if (entry[1] === root) return { ref: "#" };
152
+ const defUriPrefix = `#/${defsSegment}/`;
153
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
154
+ return {
155
+ defId,
156
+ ref: defUriPrefix + defId
157
+ };
158
+ };
159
+ const extractToDef = (entry) => {
160
+ if (entry[1].schema.$ref) return;
161
+ const seen = entry[1];
162
+ const { ref, defId } = makeURI(entry);
163
+ seen.def = { ...seen.schema };
164
+ if (defId) seen.defId = defId;
165
+ const schema = seen.schema;
166
+ for (const key in schema) delete schema[key];
167
+ schema.$ref = ref;
168
+ };
169
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
170
+ const seen = entry[1];
171
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
172
+
173
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
174
+ }
175
+ for (const entry of ctx.seen.entries()) {
176
+ const seen = entry[1];
177
+ if (schema === entry[0]) {
178
+ extractToDef(entry);
179
+ continue;
180
+ }
181
+ if (ctx.external) {
182
+ const ext = ctx.external.registry.get(entry[0])?.id;
183
+ if (schema !== entry[0] && ext) {
184
+ extractToDef(entry);
185
+ continue;
186
+ }
187
+ }
188
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
189
+ extractToDef(entry);
190
+ continue;
191
+ }
192
+ if (seen.cycle) {
193
+ extractToDef(entry);
194
+ continue;
195
+ }
196
+ if (seen.count > 1) {
197
+ if (ctx.reused === "ref") {
198
+ extractToDef(entry);
199
+ continue;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ function finalize(ctx, schema) {
205
+ const root = ctx.seen.get(schema);
206
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
207
+ const flattenRef = (zodSchema) => {
208
+ const seen = ctx.seen.get(zodSchema);
209
+ if (seen.ref === null) return;
210
+ const schema = seen.def ?? seen.schema;
211
+ const _cached = { ...schema };
212
+ const ref = seen.ref;
213
+ seen.ref = null;
214
+ if (ref) {
215
+ flattenRef(ref);
216
+ const refSeen = ctx.seen.get(ref);
217
+ const refSchema = refSeen.schema;
218
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
219
+ schema.allOf = schema.allOf ?? [];
220
+ schema.allOf.push(refSchema);
221
+ } else Object.assign(schema, refSchema);
222
+ Object.assign(schema, _cached);
223
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
224
+ if (key === "$ref" || key === "allOf") continue;
225
+ if (!(key in _cached)) delete schema[key];
226
+ }
227
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
228
+ if (key === "$ref" || key === "allOf") continue;
229
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
230
+ }
231
+ }
232
+ const parent = zodSchema._zod.parent;
233
+ if (parent && parent !== ref) {
234
+ flattenRef(parent);
235
+ const parentSeen = ctx.seen.get(parent);
236
+ if (parentSeen?.schema.$ref) {
237
+ schema.$ref = parentSeen.schema.$ref;
238
+ if (parentSeen.def) for (const key in schema) {
239
+ if (key === "$ref" || key === "allOf") continue;
240
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
241
+ }
242
+ }
243
+ }
244
+ ctx.override({
245
+ zodSchema,
246
+ jsonSchema: schema,
247
+ path: seen.path ?? []
248
+ });
249
+ };
250
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
251
+ const result = {};
252
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
253
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
254
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
255
+ else if (ctx.target === "openapi-3.0") {}
256
+ if (ctx.external?.uri) {
257
+ const id = ctx.external.registry.get(schema)?.id;
258
+ if (!id) throw new Error("Schema is missing an `id` property");
259
+ result.$id = ctx.external.uri(id);
260
+ }
261
+ Object.assign(result, root.def ?? root.schema);
262
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
263
+ if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
264
+ const defs = ctx.external?.defs ?? {};
265
+ for (const entry of ctx.seen.entries()) {
266
+ const seen = entry[1];
267
+ if (seen.def && seen.defId) {
268
+ if (seen.def.id === seen.defId) delete seen.def.id;
269
+ defs[seen.defId] = seen.def;
270
+ }
271
+ }
272
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
273
+ else result.definitions = defs;
274
+ try {
275
+ const finalized = JSON.parse(JSON.stringify(result));
276
+ Object.defineProperty(finalized, "~standard", {
277
+ value: {
278
+ ...schema["~standard"],
279
+ jsonSchema: {
280
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
281
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
282
+ }
283
+ },
284
+ enumerable: false,
285
+ writable: false
286
+ });
287
+ return finalized;
288
+ } catch (_err) {
289
+ throw new Error("Error converting schema to JSON.");
290
+ }
291
+ }
292
+ function isTransforming(_schema, _ctx) {
293
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
294
+ if (ctx.seen.has(_schema)) return false;
295
+ ctx.seen.add(_schema);
296
+ const def = _schema._zod.def;
297
+ if (def.type === "transform") return true;
298
+ if (def.type === "array") return isTransforming(def.element, ctx);
299
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
300
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
301
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
302
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
303
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
304
+ if (def.type === "pipe") {
305
+ if (_schema._zod.traits.has("$ZodCodec")) return true;
306
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
307
+ }
308
+ if (def.type === "object") {
309
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
310
+ return false;
311
+ }
312
+ if (def.type === "union") {
313
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
314
+ return false;
315
+ }
316
+ if (def.type === "tuple") {
317
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
318
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
319
+ return false;
320
+ }
321
+ return false;
322
+ }
323
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
324
+ const { libraryOptions, target } = params ?? {};
325
+ const ctx = initializeContext({
326
+ ...libraryOptions ?? {},
327
+ target,
328
+ io,
329
+ processors
330
+ });
331
+ process(schema, ctx);
332
+ extractDefs(ctx, schema);
333
+ return finalize(ctx, schema);
334
+ };
335
+ //#endregion
336
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
337
+ const formatMap = {
338
+ guid: "uuid",
339
+ url: "uri",
340
+ datetime: "date-time",
341
+ json_string: "json-string",
342
+ regex: ""
343
+ };
344
+ const stringProcessor = (schema, ctx, _json, _params) => {
345
+ const json = _json;
346
+ json.type = "string";
347
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
348
+ if (typeof minimum === "number") json.minLength = minimum;
349
+ if (typeof maximum === "number") json.maxLength = maximum;
350
+ if (format) {
351
+ json.format = formatMap[format] ?? format;
352
+ if (json.format === "") delete json.format;
353
+ if (format === "time") delete json.format;
354
+ }
355
+ if (contentEncoding) json.contentEncoding = contentEncoding;
356
+ if (patterns && patterns.size > 0) {
357
+ const regexes = [...patterns];
358
+ if (regexes.length === 1) json.pattern = regexes[0].source;
359
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
360
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
361
+ pattern: regex.source
362
+ }))];
363
+ }
364
+ };
365
+ const numberProcessor = (schema, ctx, _json, _params) => {
366
+ const json = _json;
367
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
368
+ if (typeof format === "string" && format.includes("int")) json.type = "integer";
369
+ else json.type = "number";
370
+ const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
371
+ const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
372
+ const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
373
+ if (exMin) if (legacy) {
374
+ json.minimum = exclusiveMinimum;
375
+ json.exclusiveMinimum = true;
376
+ } else json.exclusiveMinimum = exclusiveMinimum;
377
+ else if (typeof minimum === "number") json.minimum = minimum;
378
+ if (exMax) if (legacy) {
379
+ json.maximum = exclusiveMaximum;
380
+ json.exclusiveMaximum = true;
381
+ } else json.exclusiveMaximum = exclusiveMaximum;
382
+ else if (typeof maximum === "number") json.maximum = maximum;
383
+ if (typeof multipleOf === "number") json.multipleOf = multipleOf;
384
+ };
385
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
386
+ json.type = "boolean";
387
+ };
388
+ const bigintProcessor = (_schema, ctx, _json, _params) => {
389
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
390
+ };
391
+ const symbolProcessor = (_schema, ctx, _json, _params) => {
392
+ if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
393
+ };
394
+ const nullProcessor = (_schema, ctx, json, _params) => {
395
+ if (ctx.target === "openapi-3.0") {
396
+ json.type = "string";
397
+ json.nullable = true;
398
+ json.enum = [null];
399
+ } else json.type = "null";
400
+ };
401
+ const undefinedProcessor = (_schema, ctx, _json, _params) => {
402
+ if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
403
+ };
404
+ const voidProcessor = (_schema, ctx, _json, _params) => {
405
+ if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
406
+ };
407
+ const neverProcessor = (_schema, _ctx, json, _params) => {
408
+ json.not = {};
409
+ };
410
+ const anyProcessor = (_schema, _ctx, _json, _params) => {};
411
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {};
412
+ const dateProcessor = (_schema, ctx, _json, _params) => {
413
+ if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
414
+ };
415
+ const enumProcessor = (schema, _ctx, json, _params) => {
416
+ const def = schema._zod.def;
417
+ const values = getEnumValues(def.entries);
418
+ if (values.every((v) => typeof v === "number")) json.type = "number";
419
+ if (values.every((v) => typeof v === "string")) json.type = "string";
420
+ json.enum = values;
421
+ };
422
+ const literalProcessor = (schema, ctx, json, _params) => {
423
+ const def = schema._zod.def;
424
+ const vals = [];
425
+ for (const val of def.values) if (val === void 0) {
426
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
427
+ } else if (typeof val === "bigint") if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
428
+ else vals.push(Number(val));
429
+ else vals.push(val);
430
+ if (vals.length === 0) {} else if (vals.length === 1) {
431
+ const val = vals[0];
432
+ json.type = val === null ? "null" : typeof val;
433
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
434
+ else json.const = val;
435
+ } else {
436
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
437
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
438
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
439
+ if (vals.every((v) => v === null)) json.type = "null";
440
+ json.enum = vals;
441
+ }
442
+ };
443
+ const nanProcessor = (_schema, ctx, _json, _params) => {
444
+ if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
445
+ };
446
+ const templateLiteralProcessor = (schema, _ctx, json, _params) => {
447
+ const _json = json;
448
+ const pattern = schema._zod.pattern;
449
+ if (!pattern) throw new Error("Pattern not found in template literal");
450
+ _json.type = "string";
451
+ _json.pattern = pattern.source;
452
+ };
453
+ const fileProcessor = (schema, _ctx, json, _params) => {
454
+ const _json = json;
455
+ const file = {
456
+ type: "string",
457
+ format: "binary",
458
+ contentEncoding: "binary"
459
+ };
460
+ const { minimum, maximum, mime } = schema._zod.bag;
461
+ if (minimum !== void 0) file.minLength = minimum;
462
+ if (maximum !== void 0) file.maxLength = maximum;
463
+ if (mime) if (mime.length === 1) {
464
+ file.contentMediaType = mime[0];
465
+ Object.assign(_json, file);
466
+ } else {
467
+ Object.assign(_json, file);
468
+ _json.anyOf = mime.map((m) => ({ contentMediaType: m }));
469
+ }
470
+ else Object.assign(_json, file);
471
+ };
472
+ const successProcessor = (_schema, _ctx, json, _params) => {
473
+ json.type = "boolean";
474
+ };
475
+ const customProcessor = (_schema, ctx, _json, _params) => {
476
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
477
+ };
478
+ const functionProcessor = (_schema, ctx, _json, _params) => {
479
+ if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
480
+ };
481
+ const transformProcessor = (_schema, ctx, _json, _params) => {
482
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
483
+ };
484
+ const mapProcessor = (_schema, ctx, _json, _params) => {
485
+ if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
486
+ };
487
+ const setProcessor = (_schema, ctx, _json, _params) => {
488
+ if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
489
+ };
490
+ const arrayProcessor = (schema, ctx, _json, params) => {
491
+ const json = _json;
492
+ const def = schema._zod.def;
493
+ const { minimum, maximum } = schema._zod.bag;
494
+ if (typeof minimum === "number") json.minItems = minimum;
495
+ if (typeof maximum === "number") json.maxItems = maximum;
496
+ json.type = "array";
497
+ json.items = process(def.element, ctx, {
498
+ ...params,
499
+ path: [...params.path, "items"]
500
+ });
501
+ };
502
+ const objectProcessor = (schema, ctx, _json, params) => {
503
+ const json = _json;
504
+ const def = schema._zod.def;
505
+ json.type = "object";
506
+ json.properties = {};
507
+ const shape = def.shape;
508
+ for (const key in shape) json.properties[key] = process(shape[key], ctx, {
509
+ ...params,
510
+ path: [
511
+ ...params.path,
512
+ "properties",
513
+ key
514
+ ]
515
+ });
516
+ const allKeys = new Set(Object.keys(shape));
517
+ const requiredKeys = new Set([...allKeys].filter((key) => {
518
+ const v = def.shape[key]._zod;
519
+ if (ctx.io === "input") return v.optin === void 0;
520
+ else return v.optout === void 0;
521
+ }));
522
+ if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
523
+ if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
524
+ else if (!def.catchall) {
525
+ if (ctx.io === "output") json.additionalProperties = false;
526
+ } else if (def.catchall) json.additionalProperties = process(def.catchall, ctx, {
527
+ ...params,
528
+ path: [...params.path, "additionalProperties"]
529
+ });
530
+ };
531
+ const unionProcessor = (schema, ctx, json, params) => {
532
+ const def = schema._zod.def;
533
+ const isExclusive = def.inclusive === false;
534
+ const options = def.options.map((x, i) => process(x, ctx, {
535
+ ...params,
536
+ path: [
537
+ ...params.path,
538
+ isExclusive ? "oneOf" : "anyOf",
539
+ i
540
+ ]
541
+ }));
542
+ if (isExclusive) json.oneOf = options;
543
+ else json.anyOf = options;
544
+ };
545
+ const intersectionProcessor = (schema, ctx, json, params) => {
546
+ const def = schema._zod.def;
547
+ const a = process(def.left, ctx, {
548
+ ...params,
549
+ path: [
550
+ ...params.path,
551
+ "allOf",
552
+ 0
553
+ ]
554
+ });
555
+ const b = process(def.right, ctx, {
556
+ ...params,
557
+ path: [
558
+ ...params.path,
559
+ "allOf",
560
+ 1
561
+ ]
562
+ });
563
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
564
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
565
+ };
566
+ const tupleProcessor = (schema, ctx, _json, params) => {
567
+ const json = _json;
568
+ const def = schema._zod.def;
569
+ json.type = "array";
570
+ const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
571
+ const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
572
+ const prefixItems = def.items.map((x, i) => process(x, ctx, {
573
+ ...params,
574
+ path: [
575
+ ...params.path,
576
+ prefixPath,
577
+ i
578
+ ]
579
+ }));
580
+ const rest = def.rest ? process(def.rest, ctx, {
581
+ ...params,
582
+ path: [
583
+ ...params.path,
584
+ restPath,
585
+ ...ctx.target === "openapi-3.0" ? [def.items.length] : []
586
+ ]
587
+ }) : null;
588
+ if (ctx.target === "draft-2020-12") {
589
+ json.prefixItems = prefixItems;
590
+ if (rest) json.items = rest;
591
+ } else if (ctx.target === "openapi-3.0") {
592
+ json.items = { anyOf: prefixItems };
593
+ if (rest) json.items.anyOf.push(rest);
594
+ json.minItems = prefixItems.length;
595
+ if (!rest) json.maxItems = prefixItems.length;
596
+ } else {
597
+ json.items = prefixItems;
598
+ if (rest) json.additionalItems = rest;
599
+ }
600
+ const { minimum, maximum } = schema._zod.bag;
601
+ if (typeof minimum === "number") json.minItems = minimum;
602
+ if (typeof maximum === "number") json.maxItems = maximum;
603
+ };
604
+ const recordProcessor = (schema, ctx, _json, params) => {
605
+ const json = _json;
606
+ const def = schema._zod.def;
607
+ json.type = "object";
608
+ const keyType = def.keyType;
609
+ const patterns = keyType._zod.bag?.patterns;
610
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
611
+ const valueSchema = process(def.valueType, ctx, {
612
+ ...params,
613
+ path: [
614
+ ...params.path,
615
+ "patternProperties",
616
+ "*"
617
+ ]
618
+ });
619
+ json.patternProperties = {};
620
+ for (const pattern of patterns) json.patternProperties[pattern.source] = valueSchema;
621
+ } else {
622
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process(def.keyType, ctx, {
623
+ ...params,
624
+ path: [...params.path, "propertyNames"]
625
+ });
626
+ json.additionalProperties = process(def.valueType, ctx, {
627
+ ...params,
628
+ path: [...params.path, "additionalProperties"]
629
+ });
630
+ }
631
+ const keyValues = keyType._zod.values;
632
+ if (keyValues) {
633
+ const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
634
+ if (validKeyValues.length > 0) json.required = validKeyValues;
635
+ }
636
+ };
637
+ const nullableProcessor = (schema, ctx, json, params) => {
638
+ const def = schema._zod.def;
639
+ const inner = process(def.innerType, ctx, params);
640
+ const seen = ctx.seen.get(schema);
641
+ if (ctx.target === "openapi-3.0") {
642
+ seen.ref = def.innerType;
643
+ json.nullable = true;
644
+ } else json.anyOf = [inner, { type: "null" }];
645
+ };
646
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
647
+ const def = schema._zod.def;
648
+ process(def.innerType, ctx, params);
649
+ const seen = ctx.seen.get(schema);
650
+ seen.ref = def.innerType;
651
+ };
652
+ const defaultProcessor = (schema, ctx, json, params) => {
653
+ const def = schema._zod.def;
654
+ process(def.innerType, ctx, params);
655
+ const seen = ctx.seen.get(schema);
656
+ seen.ref = def.innerType;
657
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
658
+ };
659
+ const prefaultProcessor = (schema, ctx, json, params) => {
660
+ const def = schema._zod.def;
661
+ process(def.innerType, ctx, params);
662
+ const seen = ctx.seen.get(schema);
663
+ seen.ref = def.innerType;
664
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
665
+ };
666
+ const catchProcessor = (schema, ctx, json, params) => {
667
+ const def = schema._zod.def;
668
+ process(def.innerType, ctx, params);
669
+ const seen = ctx.seen.get(schema);
670
+ seen.ref = def.innerType;
671
+ let catchValue;
672
+ try {
673
+ catchValue = def.catchValue(void 0);
674
+ } catch {
675
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
676
+ }
677
+ json.default = catchValue;
678
+ };
679
+ const pipeProcessor = (schema, ctx, _json, params) => {
680
+ const def = schema._zod.def;
681
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
682
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
683
+ process(innerType, ctx, params);
684
+ const seen = ctx.seen.get(schema);
685
+ seen.ref = innerType;
686
+ };
687
+ const readonlyProcessor = (schema, ctx, json, params) => {
688
+ const def = schema._zod.def;
689
+ process(def.innerType, ctx, params);
690
+ const seen = ctx.seen.get(schema);
691
+ seen.ref = def.innerType;
692
+ json.readOnly = true;
693
+ };
694
+ const promiseProcessor = (schema, ctx, _json, params) => {
695
+ const def = schema._zod.def;
696
+ process(def.innerType, ctx, params);
697
+ const seen = ctx.seen.get(schema);
698
+ seen.ref = def.innerType;
699
+ };
700
+ const optionalProcessor = (schema, ctx, _json, params) => {
701
+ const def = schema._zod.def;
702
+ process(def.innerType, ctx, params);
703
+ const seen = ctx.seen.get(schema);
704
+ seen.ref = def.innerType;
705
+ };
706
+ const lazyProcessor = (schema, ctx, _json, params) => {
707
+ const innerType = schema._zod.innerType;
708
+ process(innerType, ctx, params);
709
+ const seen = ctx.seen.get(schema);
710
+ seen.ref = innerType;
711
+ };
712
+ const allProcessors = {
713
+ string: stringProcessor,
714
+ number: numberProcessor,
715
+ boolean: booleanProcessor,
716
+ bigint: bigintProcessor,
717
+ symbol: symbolProcessor,
718
+ null: nullProcessor,
719
+ undefined: undefinedProcessor,
720
+ void: voidProcessor,
721
+ never: neverProcessor,
722
+ any: anyProcessor,
723
+ unknown: unknownProcessor,
724
+ date: dateProcessor,
725
+ enum: enumProcessor,
726
+ literal: literalProcessor,
727
+ nan: nanProcessor,
728
+ template_literal: templateLiteralProcessor,
729
+ file: fileProcessor,
730
+ success: successProcessor,
731
+ custom: customProcessor,
732
+ function: functionProcessor,
733
+ transform: transformProcessor,
734
+ map: mapProcessor,
735
+ set: setProcessor,
736
+ array: arrayProcessor,
737
+ object: objectProcessor,
738
+ union: unionProcessor,
739
+ intersection: intersectionProcessor,
740
+ tuple: tupleProcessor,
741
+ record: recordProcessor,
742
+ nullable: nullableProcessor,
743
+ nonoptional: nonoptionalProcessor,
744
+ default: defaultProcessor,
745
+ prefault: prefaultProcessor,
746
+ catch: catchProcessor,
747
+ pipe: pipeProcessor,
748
+ readonly: readonlyProcessor,
749
+ promise: promiseProcessor,
750
+ optional: optionalProcessor,
751
+ lazy: lazyProcessor
752
+ };
753
+ function toJSONSchema(input, params) {
754
+ if ("_idmap" in input) {
755
+ const registry = input;
756
+ const ctx = initializeContext({
757
+ ...params,
758
+ processors: allProcessors
759
+ });
760
+ const defs = {};
761
+ for (const entry of registry._idmap.entries()) {
762
+ const [_, schema] = entry;
763
+ process(schema, ctx);
764
+ }
765
+ const schemas = {};
766
+ ctx.external = {
767
+ registry,
768
+ uri: params?.uri,
769
+ defs
770
+ };
771
+ for (const entry of registry._idmap.entries()) {
772
+ const [key, schema] = entry;
773
+ extractDefs(ctx, schema);
774
+ schemas[key] = finalize(ctx, schema);
775
+ }
776
+ if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
777
+ return { schemas };
778
+ }
779
+ const ctx = initializeContext({
780
+ ...params,
781
+ processors: allProcessors
782
+ });
783
+ process(input, ctx);
784
+ extractDefs(ctx, input);
785
+ return finalize(ctx, input);
786
+ }
787
+ //#endregion
788
+ export { toJSONSchema };