@lssm/lib.ui-kit 0.0.0-canary-20251216062412 → 0.0.0-canary-20251217034842

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.
@@ -3,12 +3,19 @@ import { clone, issue, mergeDefs, normalizeParams, shallowClone } from "../core/
3
3
  import { $ZodArray, $ZodBase64, $ZodBase64URL, $ZodCIDRv4, $ZodCIDRv6, $ZodCUID, $ZodCUID2, $ZodCatch, $ZodCustom, $ZodDefault, $ZodE164, $ZodEmail, $ZodEmoji, $ZodGUID, $ZodIPv4, $ZodIPv6, $ZodIntersection, $ZodJWT, $ZodKSUID, $ZodNanoID, $ZodNonOptional, $ZodNullable, $ZodOptional, $ZodPipe, $ZodPrefault, $ZodReadonly, $ZodString, $ZodStringFormat, $ZodTransform, $ZodType, $ZodULID, $ZodURL, $ZodUUID, $ZodUnion, $ZodXID } from "../core/schemas.js";
4
4
  import { globalRegistry } from "../core/registries.js";
5
5
  import { _array, _base64, _base64url, _cidrv4, _cidrv6, _cuid, _cuid2, _e164, _email, _emoji, _endsWith, _guid, _includes, _ipv4, _ipv6, _jwt, _ksuid, _length, _lowercase, _maxLength, _minLength, _nanoid, _normalize, _overwrite, _refine, _regex, _slugify, _startsWith, _string, _superRefine, _toLowerCase, _toUpperCase, _trim, _ulid, _uppercase, _url, _uuid, _uuidv4, _uuidv6, _uuidv7, _xid, describe as describe$1, meta as meta$1 } from "../core/api.js";
6
+ import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../core/to-json-schema.js";
7
+ import { arrayProcessor, catchProcessor, customProcessor, defaultProcessor, intersectionProcessor, nonoptionalProcessor, nullableProcessor, optionalProcessor, pipeProcessor, prefaultProcessor, readonlyProcessor, stringProcessor, transformProcessor, unionProcessor } from "../core/json-schema-processors.js";
6
8
  import { date, datetime, duration, time } from "./iso.js";
7
9
  import { decode, decodeAsync, encode, encodeAsync, parse, parseAsync, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync } from "./parse.js";
8
10
 
9
11
  //#region ../../../node_modules/zod/v4/classic/schemas.js
10
12
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
11
13
  $ZodType.init(inst, def);
14
+ Object.assign(inst["~standard"], { jsonSchema: {
15
+ input: createStandardJSONSchemaMethod(inst, "input"),
16
+ output: createStandardJSONSchemaMethod(inst, "output")
17
+ } });
18
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
12
19
  inst.def = def;
13
20
  inst.type = def.type;
14
21
  Object.defineProperty(inst, "_def", { value: def });
@@ -79,6 +86,7 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
79
86
  const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
80
87
  $ZodString.init(inst, def);
81
88
  ZodType.init(inst, def);
89
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
82
90
  const bag = inst._zod.bag;
83
91
  inst.format = bag.format ?? null;
84
92
  inst.minLength = bag.minimum ?? null;
@@ -216,6 +224,7 @@ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
216
224
  const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
217
225
  $ZodArray.init(inst, def);
218
226
  ZodType.init(inst, def);
227
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
219
228
  inst.element = def.element;
220
229
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
221
230
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -229,6 +238,7 @@ function array(element, params) {
229
238
  const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
230
239
  $ZodUnion.init(inst, def);
231
240
  ZodType.init(inst, def);
241
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
232
242
  inst.options = def.options;
233
243
  });
234
244
  function union(options, params) {
@@ -241,6 +251,7 @@ function union(options, params) {
241
251
  const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
242
252
  $ZodIntersection.init(inst, def);
243
253
  ZodType.init(inst, def);
254
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
244
255
  });
245
256
  function intersection(left, right) {
246
257
  return new ZodIntersection({
@@ -252,6 +263,7 @@ function intersection(left, right) {
252
263
  const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
253
264
  $ZodTransform.init(inst, def);
254
265
  ZodType.init(inst, def);
266
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
255
267
  inst._zod.parse = (payload, _ctx) => {
256
268
  if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
257
269
  payload.addIssue = (issue$1) => {
@@ -283,6 +295,7 @@ function transform(fn) {
283
295
  const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
284
296
  $ZodOptional.init(inst, def);
285
297
  ZodType.init(inst, def);
298
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
286
299
  inst.unwrap = () => inst._zod.def.innerType;
287
300
  });
288
301
  function optional(innerType) {
@@ -294,6 +307,7 @@ function optional(innerType) {
294
307
  const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
295
308
  $ZodNullable.init(inst, def);
296
309
  ZodType.init(inst, def);
310
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
297
311
  inst.unwrap = () => inst._zod.def.innerType;
298
312
  });
299
313
  function nullable(innerType) {
@@ -305,6 +319,7 @@ function nullable(innerType) {
305
319
  const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
306
320
  $ZodDefault.init(inst, def);
307
321
  ZodType.init(inst, def);
322
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
308
323
  inst.unwrap = () => inst._zod.def.innerType;
309
324
  inst.removeDefault = inst.unwrap;
310
325
  });
@@ -320,6 +335,7 @@ function _default(innerType, defaultValue) {
320
335
  const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
321
336
  $ZodPrefault.init(inst, def);
322
337
  ZodType.init(inst, def);
338
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
323
339
  inst.unwrap = () => inst._zod.def.innerType;
324
340
  });
325
341
  function prefault(innerType, defaultValue) {
@@ -334,6 +350,7 @@ function prefault(innerType, defaultValue) {
334
350
  const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
335
351
  $ZodNonOptional.init(inst, def);
336
352
  ZodType.init(inst, def);
353
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
337
354
  inst.unwrap = () => inst._zod.def.innerType;
338
355
  });
339
356
  function nonoptional(innerType, params) {
@@ -346,6 +363,7 @@ function nonoptional(innerType, params) {
346
363
  const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
347
364
  $ZodCatch.init(inst, def);
348
365
  ZodType.init(inst, def);
366
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
349
367
  inst.unwrap = () => inst._zod.def.innerType;
350
368
  inst.removeCatch = inst.unwrap;
351
369
  });
@@ -359,6 +377,7 @@ function _catch(innerType, catchValue) {
359
377
  const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
360
378
  $ZodPipe.init(inst, def);
361
379
  ZodType.init(inst, def);
380
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
362
381
  inst.in = def.in;
363
382
  inst.out = def.out;
364
383
  });
@@ -372,6 +391,7 @@ function pipe(in_, out) {
372
391
  const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
373
392
  $ZodReadonly.init(inst, def);
374
393
  ZodType.init(inst, def);
394
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
375
395
  inst.unwrap = () => inst._zod.def.innerType;
376
396
  });
377
397
  function readonly(innerType) {
@@ -383,6 +403,7 @@ function readonly(innerType) {
383
403
  const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
384
404
  $ZodCustom.init(inst, def);
385
405
  ZodType.init(inst, def);
406
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
386
407
  });
387
408
  function refine(fn, _params = {}) {
388
409
  return _refine(ZodCustom, fn, _params);
@@ -0,0 +1,148 @@
1
+ import { process } from "./to-json-schema.js";
2
+
3
+ //#region ../../../node_modules/zod/v4/core/json-schema-processors.js
4
+ const formatMap = {
5
+ guid: "uuid",
6
+ url: "uri",
7
+ datetime: "date-time",
8
+ json_string: "json-string",
9
+ regex: ""
10
+ };
11
+ const stringProcessor = (schema, ctx, _json, _params) => {
12
+ const json = _json;
13
+ json.type = "string";
14
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
15
+ if (typeof minimum === "number") json.minLength = minimum;
16
+ if (typeof maximum === "number") json.maxLength = maximum;
17
+ if (format) {
18
+ json.format = formatMap[format] ?? format;
19
+ if (json.format === "") delete json.format;
20
+ }
21
+ if (contentEncoding) json.contentEncoding = contentEncoding;
22
+ if (patterns && patterns.size > 0) {
23
+ const regexes = [...patterns];
24
+ if (regexes.length === 1) json.pattern = regexes[0].source;
25
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
26
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
27
+ pattern: regex.source
28
+ }))];
29
+ }
30
+ };
31
+ const customProcessor = (_schema, ctx, _json, _params) => {
32
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
33
+ };
34
+ const transformProcessor = (_schema, ctx, _json, _params) => {
35
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
36
+ };
37
+ const arrayProcessor = (schema, ctx, _json, params) => {
38
+ const json = _json;
39
+ const def = schema._zod.def;
40
+ const { minimum, maximum } = schema._zod.bag;
41
+ if (typeof minimum === "number") json.minItems = minimum;
42
+ if (typeof maximum === "number") json.maxItems = maximum;
43
+ json.type = "array";
44
+ json.items = process(def.element, ctx, {
45
+ ...params,
46
+ path: [...params.path, "items"]
47
+ });
48
+ };
49
+ const unionProcessor = (schema, ctx, json, params) => {
50
+ const def = schema._zod.def;
51
+ const isExclusive = def.inclusive === false;
52
+ const options = def.options.map((x, i) => process(x, ctx, {
53
+ ...params,
54
+ path: [
55
+ ...params.path,
56
+ isExclusive ? "oneOf" : "anyOf",
57
+ i
58
+ ]
59
+ }));
60
+ if (isExclusive) json.oneOf = options;
61
+ else json.anyOf = options;
62
+ };
63
+ const intersectionProcessor = (schema, ctx, json, params) => {
64
+ const def = schema._zod.def;
65
+ const a = process(def.left, ctx, {
66
+ ...params,
67
+ path: [
68
+ ...params.path,
69
+ "allOf",
70
+ 0
71
+ ]
72
+ });
73
+ const b = process(def.right, ctx, {
74
+ ...params,
75
+ path: [
76
+ ...params.path,
77
+ "allOf",
78
+ 1
79
+ ]
80
+ });
81
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
82
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
83
+ };
84
+ const nullableProcessor = (schema, ctx, json, params) => {
85
+ const def = schema._zod.def;
86
+ const inner = process(def.innerType, ctx, params);
87
+ const seen = ctx.seen.get(schema);
88
+ if (ctx.target === "openapi-3.0") {
89
+ seen.ref = def.innerType;
90
+ json.nullable = true;
91
+ } else json.anyOf = [inner, { type: "null" }];
92
+ };
93
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
94
+ const def = schema._zod.def;
95
+ process(def.innerType, ctx, params);
96
+ const seen = ctx.seen.get(schema);
97
+ seen.ref = def.innerType;
98
+ };
99
+ const defaultProcessor = (schema, ctx, json, params) => {
100
+ const def = schema._zod.def;
101
+ process(def.innerType, ctx, params);
102
+ const seen = ctx.seen.get(schema);
103
+ seen.ref = def.innerType;
104
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
105
+ };
106
+ const prefaultProcessor = (schema, ctx, json, params) => {
107
+ const def = schema._zod.def;
108
+ process(def.innerType, ctx, params);
109
+ const seen = ctx.seen.get(schema);
110
+ seen.ref = def.innerType;
111
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
112
+ };
113
+ const catchProcessor = (schema, ctx, json, params) => {
114
+ const def = schema._zod.def;
115
+ process(def.innerType, ctx, params);
116
+ const seen = ctx.seen.get(schema);
117
+ seen.ref = def.innerType;
118
+ let catchValue;
119
+ try {
120
+ catchValue = def.catchValue(void 0);
121
+ } catch {
122
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
123
+ }
124
+ json.default = catchValue;
125
+ };
126
+ const pipeProcessor = (schema, ctx, _json, params) => {
127
+ const def = schema._zod.def;
128
+ const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
129
+ process(innerType, ctx, params);
130
+ const seen = ctx.seen.get(schema);
131
+ seen.ref = innerType;
132
+ };
133
+ const readonlyProcessor = (schema, ctx, json, params) => {
134
+ const def = schema._zod.def;
135
+ process(def.innerType, ctx, params);
136
+ const seen = ctx.seen.get(schema);
137
+ seen.ref = def.innerType;
138
+ json.readOnly = true;
139
+ };
140
+ const optionalProcessor = (schema, ctx, _json, params) => {
141
+ const def = schema._zod.def;
142
+ process(def.innerType, ctx, params);
143
+ const seen = ctx.seen.get(schema);
144
+ seen.ref = def.innerType;
145
+ };
146
+
147
+ //#endregion
148
+ export { arrayProcessor, catchProcessor, customProcessor, defaultProcessor, intersectionProcessor, nonoptionalProcessor, nullableProcessor, optionalProcessor, pipeProcessor, prefaultProcessor, readonlyProcessor, stringProcessor, transformProcessor, unionProcessor };
@@ -0,0 +1,260 @@
1
+ import { globalRegistry } from "./registries.js";
2
+
3
+ //#region ../../../node_modules/zod/v4/core/to-json-schema.js
4
+ function initializeContext(params) {
5
+ let target = params?.target ?? "draft-2020-12";
6
+ if (target === "draft-4") target = "draft-04";
7
+ if (target === "draft-7") target = "draft-07";
8
+ return {
9
+ processors: params.processors ?? {},
10
+ metadataRegistry: params?.metadata ?? globalRegistry,
11
+ target,
12
+ unrepresentable: params?.unrepresentable ?? "throw",
13
+ override: params?.override ?? (() => {}),
14
+ io: params?.io ?? "output",
15
+ counter: 0,
16
+ seen: /* @__PURE__ */ new Map(),
17
+ cycles: params?.cycles ?? "ref",
18
+ reused: params?.reused ?? "inline",
19
+ external: params?.external ?? void 0
20
+ };
21
+ }
22
+ function process(schema, ctx, _params = {
23
+ path: [],
24
+ schemaPath: []
25
+ }) {
26
+ var _a;
27
+ const def = schema._zod.def;
28
+ const seen = ctx.seen.get(schema);
29
+ if (seen) {
30
+ seen.count++;
31
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
32
+ return seen.schema;
33
+ }
34
+ const result = {
35
+ schema: {},
36
+ count: 1,
37
+ cycle: void 0,
38
+ path: _params.path
39
+ };
40
+ ctx.seen.set(schema, result);
41
+ const overrideSchema = schema._zod.toJSONSchema?.();
42
+ if (overrideSchema) result.schema = overrideSchema;
43
+ else {
44
+ const params = {
45
+ ..._params,
46
+ schemaPath: [..._params.schemaPath, schema],
47
+ path: _params.path
48
+ };
49
+ const parent = schema._zod.parent;
50
+ if (parent) {
51
+ result.ref = parent;
52
+ process(parent, ctx, params);
53
+ ctx.seen.get(parent).isParent = true;
54
+ } else if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
55
+ else {
56
+ const _json = result.schema;
57
+ const processor = ctx.processors[def.type];
58
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
59
+ processor(schema, ctx, _json, params);
60
+ }
61
+ }
62
+ const meta = ctx.metadataRegistry.get(schema);
63
+ if (meta) Object.assign(result.schema, meta);
64
+ if (ctx.io === "input" && isTransforming(schema)) {
65
+ delete result.schema.examples;
66
+ delete result.schema.default;
67
+ }
68
+ if (ctx.io === "input" && result.schema._prefault) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
69
+ delete result.schema._prefault;
70
+ return ctx.seen.get(schema).schema;
71
+ }
72
+ function extractDefs(ctx, schema) {
73
+ const root = ctx.seen.get(schema);
74
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
75
+ const makeURI = (entry) => {
76
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
77
+ if (ctx.external) {
78
+ const externalId = ctx.external.registry.get(entry[0])?.id;
79
+ const uriGenerator = ctx.external.uri ?? ((id$1) => id$1);
80
+ if (externalId) return { ref: uriGenerator(externalId) };
81
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
82
+ entry[1].defId = id;
83
+ return {
84
+ defId: id,
85
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
86
+ };
87
+ }
88
+ if (entry[1] === root) return { ref: "#" };
89
+ const defUriPrefix = `#/${defsSegment}/`;
90
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
91
+ return {
92
+ defId,
93
+ ref: defUriPrefix + defId
94
+ };
95
+ };
96
+ const extractToDef = (entry) => {
97
+ if (entry[1].schema.$ref) return;
98
+ const seen = entry[1];
99
+ const { ref, defId } = makeURI(entry);
100
+ seen.def = { ...seen.schema };
101
+ if (defId) seen.defId = defId;
102
+ const schema$1 = seen.schema;
103
+ for (const key in schema$1) delete schema$1[key];
104
+ schema$1.$ref = ref;
105
+ };
106
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
107
+ const seen = entry[1];
108
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
109
+
110
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
111
+ }
112
+ for (const entry of ctx.seen.entries()) {
113
+ const seen = entry[1];
114
+ if (schema === entry[0]) {
115
+ extractToDef(entry);
116
+ continue;
117
+ }
118
+ if (ctx.external) {
119
+ const ext = ctx.external.registry.get(entry[0])?.id;
120
+ if (schema !== entry[0] && ext) {
121
+ extractToDef(entry);
122
+ continue;
123
+ }
124
+ }
125
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
126
+ extractToDef(entry);
127
+ continue;
128
+ }
129
+ if (seen.cycle) {
130
+ extractToDef(entry);
131
+ continue;
132
+ }
133
+ if (seen.count > 1) {
134
+ if (ctx.reused === "ref") {
135
+ extractToDef(entry);
136
+ continue;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ function finalize(ctx, schema) {
142
+ const root = ctx.seen.get(schema);
143
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
144
+ const flattenRef = (zodSchema) => {
145
+ const seen = ctx.seen.get(zodSchema);
146
+ const schema$1 = seen.def ?? seen.schema;
147
+ const _cached = { ...schema$1 };
148
+ if (seen.ref === null) return;
149
+ const ref = seen.ref;
150
+ seen.ref = null;
151
+ if (ref) {
152
+ flattenRef(ref);
153
+ const refSchema = ctx.seen.get(ref).schema;
154
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
155
+ schema$1.allOf = schema$1.allOf ?? [];
156
+ schema$1.allOf.push(refSchema);
157
+ } else {
158
+ Object.assign(schema$1, refSchema);
159
+ Object.assign(schema$1, _cached);
160
+ }
161
+ }
162
+ if (!seen.isParent) ctx.override({
163
+ zodSchema,
164
+ jsonSchema: schema$1,
165
+ path: seen.path ?? []
166
+ });
167
+ };
168
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
169
+ const result = {};
170
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
171
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
172
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
173
+ else if (ctx.target === "openapi-3.0") {}
174
+ if (ctx.external?.uri) {
175
+ const id = ctx.external.registry.get(schema)?.id;
176
+ if (!id) throw new Error("Schema is missing an `id` property");
177
+ result.$id = ctx.external.uri(id);
178
+ }
179
+ Object.assign(result, root.def ?? root.schema);
180
+ const defs = ctx.external?.defs ?? {};
181
+ for (const entry of ctx.seen.entries()) {
182
+ const seen = entry[1];
183
+ if (seen.def && seen.defId) defs[seen.defId] = seen.def;
184
+ }
185
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
186
+ else result.definitions = defs;
187
+ try {
188
+ const finalized = JSON.parse(JSON.stringify(result));
189
+ Object.defineProperty(finalized, "~standard", {
190
+ value: {
191
+ ...schema["~standard"],
192
+ jsonSchema: {
193
+ input: createStandardJSONSchemaMethod(schema, "input"),
194
+ output: createStandardJSONSchemaMethod(schema, "output")
195
+ }
196
+ },
197
+ enumerable: false,
198
+ writable: false
199
+ });
200
+ return finalized;
201
+ } catch (_err) {
202
+ throw new Error("Error converting schema to JSON.");
203
+ }
204
+ }
205
+ function isTransforming(_schema, _ctx) {
206
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
207
+ if (ctx.seen.has(_schema)) return false;
208
+ ctx.seen.add(_schema);
209
+ const def = _schema._zod.def;
210
+ if (def.type === "transform") return true;
211
+ if (def.type === "array") return isTransforming(def.element, ctx);
212
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
213
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
214
+ 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);
215
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
216
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
217
+ if (def.type === "pipe") return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
218
+ if (def.type === "object") {
219
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
220
+ return false;
221
+ }
222
+ if (def.type === "union") {
223
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
224
+ return false;
225
+ }
226
+ if (def.type === "tuple") {
227
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
228
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
229
+ return false;
230
+ }
231
+ return false;
232
+ }
233
+ /**
234
+ * Creates a toJSONSchema method for a schema instance.
235
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
236
+ */
237
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
238
+ const ctx = initializeContext({
239
+ ...params,
240
+ processors
241
+ });
242
+ process(schema, ctx);
243
+ extractDefs(ctx, schema);
244
+ return finalize(ctx, schema);
245
+ };
246
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
247
+ const { libraryOptions, target } = params ?? {};
248
+ const ctx = initializeContext({
249
+ ...libraryOptions ?? {},
250
+ target,
251
+ io,
252
+ processors: {}
253
+ });
254
+ process(schema, ctx);
255
+ extractDefs(ctx, schema);
256
+ return finalize(ctx, schema);
257
+ };
258
+
259
+ //#endregion
260
+ export { createStandardJSONSchemaMethod, createToJSONSchemaMethod, process };
@@ -1,8 +1,8 @@
1
1
  //#region ../../../node_modules/zod/v4/core/versions.js
2
2
  const version = {
3
3
  major: 4,
4
- minor: 1,
5
- patch: 13
4
+ minor: 2,
5
+ patch: 1
6
6
  };
7
7
 
8
8
  //#endregion