@mastra/schema-compat 1.3.10-alpha.1 → 1.3.11-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,287 @@
1
- import jsonSchemaToZodOriginal, { addJsdocs, its, parseAllOf, parseAnyOf, parseOneOf, parseSchema } from "json-schema-to-zod";
2
- export * from "json-schema-to-zod";
3
- //#region src/json-to-zod.ts
1
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
2
+ const parseAnyOf = (schema, refs) => {
3
+ return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], {
4
+ ...refs,
5
+ path: [
6
+ ...refs.path,
7
+ "anyOf",
8
+ 0
9
+ ]
10
+ }) : `z.union([${schema.anyOf.map((schema, i) => parseSchema(schema, {
11
+ ...refs,
12
+ path: [
13
+ ...refs.path,
14
+ "anyOf",
15
+ i
16
+ ]
17
+ })).join(", ")}])` : `z.any()`;
18
+ };
19
+ //#endregion
20
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseBoolean.js
21
+ const parseBoolean = (_schema) => {
22
+ return "z.boolean()";
23
+ };
24
+ //#endregion
25
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseDefault.js
26
+ const parseDefault = (_schema) => {
27
+ return "z.any()";
28
+ };
29
+ //#endregion
30
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseMultipleType.js
31
+ const parseMultipleType = (schema, refs) => {
32
+ return `z.union([${schema.type.map((type) => parseSchema({
33
+ ...schema,
34
+ type
35
+ }, {
36
+ ...refs,
37
+ withoutDefaults: true
38
+ })).join(", ")}])`;
39
+ };
40
+ //#endregion
41
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseNot.js
42
+ const parseNot = (schema, refs) => {
43
+ return `z.any().refine((value) => !${parseSchema(schema.not, {
44
+ ...refs,
45
+ path: [...refs.path, "not"]
46
+ })}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
47
+ };
48
+ //#endregion
49
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseNull.js
50
+ const parseNull = (_schema) => {
51
+ return "z.null()";
52
+ };
53
+ //#endregion
54
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/utils/half.js
55
+ const half = (arr) => {
56
+ return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
57
+ };
58
+ //#endregion
59
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseAllOf.js
60
+ const originalIndex = Symbol("Original index");
61
+ const ensureOriginalIndex = (arr) => {
62
+ let newArr = [];
63
+ for (let i = 0; i < arr.length; i++) {
64
+ const item = arr[i];
65
+ if (typeof item === "boolean") newArr.push(item ? { [originalIndex]: i } : {
66
+ [originalIndex]: i,
67
+ not: {}
68
+ });
69
+ else if (originalIndex in item) return arr;
70
+ else newArr.push({
71
+ ...item,
72
+ [originalIndex]: i
73
+ });
74
+ }
75
+ return newArr;
76
+ };
77
+ function parseAllOf(schema, refs) {
78
+ if (schema.allOf.length === 0) return "z.never()";
79
+ else if (schema.allOf.length === 1) {
80
+ const item = schema.allOf[0];
81
+ return parseSchema(item, {
82
+ ...refs,
83
+ path: [
84
+ ...refs.path,
85
+ "allOf",
86
+ item[originalIndex]
87
+ ]
88
+ });
89
+ } else {
90
+ const [left, right] = half(ensureOriginalIndex(schema.allOf));
91
+ return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({ allOf: right }, refs)})`;
92
+ }
93
+ }
94
+ //#endregion
95
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/utils/withMessage.js
96
+ function withMessage(schema, key, get) {
97
+ const value = schema[key];
98
+ let r = "";
99
+ if (value !== void 0) {
100
+ const got = get({
101
+ value,
102
+ json: JSON.stringify(value)
103
+ });
104
+ if (got) {
105
+ const opener = got[0];
106
+ const prefix = got.length === 3 ? got[1] : "";
107
+ const closer = got.length === 3 ? got[2] : got[1];
108
+ r += opener;
109
+ if (schema.errorMessage?.[key] !== void 0) r += prefix + JSON.stringify(schema.errorMessage[key]);
110
+ r += closer;
111
+ }
112
+ }
113
+ return r;
114
+ }
115
+ //#endregion
116
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseArray.js
117
+ const parseArray = (schema, refs) => {
118
+ if (Array.isArray(schema.items)) return `z.tuple([${schema.items.map((v, i) => parseSchema(v, {
119
+ ...refs,
120
+ path: [
121
+ ...refs.path,
122
+ "items",
123
+ i
124
+ ]
125
+ }))}])`;
126
+ let r = !schema.items ? "z.array(z.any())" : `z.array(${parseSchema(schema.items, {
127
+ ...refs,
128
+ path: [...refs.path, "items"]
129
+ })})`;
130
+ r += withMessage(schema, "minItems", ({ json }) => [
131
+ `.min(${json}`,
132
+ ", ",
133
+ ")"
134
+ ]);
135
+ r += withMessage(schema, "maxItems", ({ json }) => [
136
+ `.max(${json}`,
137
+ ", ",
138
+ ")"
139
+ ]);
140
+ if (schema.uniqueItems === true) r += withMessage(schema, "uniqueItems", () => [
141
+ ".unique(",
142
+ "",
143
+ ")"
144
+ ]);
145
+ return r;
146
+ };
147
+ //#endregion
148
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseConst.js
149
+ const parseConst = (schema) => {
150
+ return `z.literal(${JSON.stringify(schema.const)})`;
151
+ };
152
+ //#endregion
153
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseEnum.js
154
+ const parseEnum = (schema) => {
155
+ if (schema.enum.length === 0) return "z.never()";
156
+ else if (schema.enum.length === 1) return `z.literal(${JSON.stringify(schema.enum[0])})`;
157
+ else if (schema.enum.every((x) => typeof x === "string")) return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
158
+ else return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
159
+ };
160
+ //#endregion
161
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseIfThenElse.js
162
+ const parseIfThenElse = (schema, refs) => {
163
+ const $if = parseSchema(schema.if, {
164
+ ...refs,
165
+ path: [...refs.path, "if"]
166
+ });
167
+ const $then = parseSchema(schema.then, {
168
+ ...refs,
169
+ path: [...refs.path, "then"]
170
+ });
171
+ const $else = parseSchema(schema.else, {
172
+ ...refs,
173
+ path: [...refs.path, "else"]
174
+ });
175
+ return `z.union([${$then}, ${$else}]).superRefine((value,ctx) => {
176
+ const result = ${$if}.safeParse(value).success
177
+ ? ${$then}.safeParse(value)
178
+ : ${$else}.safeParse(value);
179
+ if (!result.success) {
180
+ result.error.errors.forEach((error) => ctx.addIssue(error))
181
+ }
182
+ })`;
183
+ };
184
+ //#endregion
185
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseNumber.js
186
+ const parseNumber = (schema) => {
187
+ let r = "z.number()";
188
+ if (schema.type === "integer") r += withMessage(schema, "type", () => [".int(", ")"]);
189
+ else r += withMessage(schema, "format", ({ value }) => {
190
+ if (value === "int64") return [".int(", ")"];
191
+ });
192
+ r += withMessage(schema, "multipleOf", ({ value, json }) => {
193
+ if (value === 1) {
194
+ if (r.startsWith("z.number().int(")) return;
195
+ return [".int(", ")"];
196
+ }
197
+ return [
198
+ `.multipleOf(${json}`,
199
+ ", ",
200
+ ")"
201
+ ];
202
+ });
203
+ if (typeof schema.minimum === "number") if (schema.exclusiveMinimum === true) r += withMessage(schema, "minimum", ({ json }) => [
204
+ `.gt(${json}`,
205
+ ", ",
206
+ ")"
207
+ ]);
208
+ else r += withMessage(schema, "minimum", ({ json }) => [
209
+ `.gte(${json}`,
210
+ ", ",
211
+ ")"
212
+ ]);
213
+ else if (typeof schema.exclusiveMinimum === "number") r += withMessage(schema, "exclusiveMinimum", ({ json }) => [
214
+ `.gt(${json}`,
215
+ ", ",
216
+ ")"
217
+ ]);
218
+ if (typeof schema.maximum === "number") if (schema.exclusiveMaximum === true) r += withMessage(schema, "maximum", ({ json }) => [
219
+ `.lt(${json}`,
220
+ ", ",
221
+ ")"
222
+ ]);
223
+ else r += withMessage(schema, "maximum", ({ json }) => [
224
+ `.lte(${json}`,
225
+ ", ",
226
+ ")"
227
+ ]);
228
+ else if (typeof schema.exclusiveMaximum === "number") r += withMessage(schema, "exclusiveMaximum", ({ json }) => [
229
+ `.lt(${json}`,
230
+ ", ",
231
+ ")"
232
+ ]);
233
+ return r;
234
+ };
235
+ //#endregion
236
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseOneOf.js
237
+ const parseOneOf = (schema, refs) => {
238
+ return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
239
+ ...refs,
240
+ path: [
241
+ ...refs.path,
242
+ "oneOf",
243
+ 0
244
+ ]
245
+ }) : `z.any().superRefine((x, ctx) => {
246
+ const schemas = [${schema.oneOf.map((schema, i) => parseSchema(schema, {
247
+ ...refs,
248
+ path: [
249
+ ...refs.path,
250
+ "oneOf",
251
+ i
252
+ ]
253
+ })).join(", ")}];
254
+ const errors = schemas.reduce<z.ZodError[]>(
255
+ (errors, schema) =>
256
+ ((result) =>
257
+ result.error ? [...errors, result.error] : errors)(
258
+ schema.safeParse(x),
259
+ ),
260
+ [],
261
+ );
262
+ if (schemas.length - errors.length !== 1) {
263
+ ctx.addIssue({
264
+ path: ctx.path,
265
+ code: "invalid_union",
266
+ unionErrors: errors,
267
+ message: "Invalid input: Should pass single schema",
268
+ });
269
+ }
270
+ })` : "z.any()";
271
+ };
272
+ //#endregion
273
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/utils/jsdocs.js
274
+ const expandJsdocs = (jsdocs) => {
275
+ const lines = jsdocs.split("\n");
276
+ return `/**${lines.length === 1 ? lines[0] : `\n${lines.map((x) => `* ${x}`).join("\n")}\n`}*/\n`;
277
+ };
278
+ const addJsdocs = (schema, parsed) => {
279
+ const description = schema.description;
280
+ if (!description) return parsed;
281
+ return `\n${expandJsdocs(description)}${parsed}`;
282
+ };
283
+ //#endregion
284
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseObject.js
4
285
  function parseObject(objectSchema, refs) {
5
286
  let properties = void 0;
6
287
  if (objectSchema.properties) if (!Object.keys(objectSchema.properties).length) properties = "z.object({})";
@@ -23,7 +304,7 @@ function parseObject(objectSchema, refs) {
23
304
  }).join(", ");
24
305
  properties += " })";
25
306
  }
26
- const additionalProperties = objectSchema.additionalProperties !== void 0 && objectSchema.additionalProperties !== false ? parseSchema(objectSchema.additionalProperties, {
307
+ const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
27
308
  ...refs,
28
309
  path: [...refs.path, "additionalProperties"]
29
310
  }) : void 0;
@@ -108,6 +389,341 @@ function parseObject(objectSchema, refs) {
108
389
  }, refs)})`;
109
390
  return output;
110
391
  }
392
+ //#endregion
393
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseString.js
394
+ const parseString = (schema) => {
395
+ let r = "z.string()";
396
+ r += withMessage(schema, "format", ({ value }) => {
397
+ switch (value) {
398
+ case "email": return [".email(", ")"];
399
+ case "ip": return [".ip(", ")"];
400
+ case "ipv4": return [
401
+ ".ip({ version: \"v4\"",
402
+ ", message: ",
403
+ " })"
404
+ ];
405
+ case "ipv6": return [
406
+ ".ip({ version: \"v6\"",
407
+ ", message: ",
408
+ " })"
409
+ ];
410
+ case "uri": return [".url(", ")"];
411
+ case "uuid": return [".uuid(", ")"];
412
+ case "date-time": return [
413
+ ".datetime({ offset: true",
414
+ ", message: ",
415
+ " })"
416
+ ];
417
+ case "time": return [".time(", ")"];
418
+ case "date": return [".date(", ")"];
419
+ case "binary": return [".base64(", ")"];
420
+ case "duration": return [".duration(", ")"];
421
+ }
422
+ });
423
+ r += withMessage(schema, "pattern", ({ json }) => [
424
+ `.regex(new RegExp(${json})`,
425
+ ", ",
426
+ ")"
427
+ ]);
428
+ r += withMessage(schema, "minLength", ({ json }) => [
429
+ `.min(${json}`,
430
+ ", ",
431
+ ")"
432
+ ]);
433
+ r += withMessage(schema, "maxLength", ({ json }) => [
434
+ `.max(${json}`,
435
+ ", ",
436
+ ")"
437
+ ]);
438
+ r += withMessage(schema, "contentEncoding", ({ value }) => {
439
+ if (value === "base64") return [".base64(", ")"];
440
+ });
441
+ const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
442
+ if (value === "application/json") return [
443
+ ".transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: \"custom\", message: \"Invalid JSON\" }); }}",
444
+ ", ",
445
+ ")"
446
+ ];
447
+ });
448
+ if (contentMediaType != "") {
449
+ r += contentMediaType;
450
+ r += withMessage(schema, "contentSchema", ({ value }) => {
451
+ if (value && value instanceof Object) return [
452
+ `.pipe(${parseSchema(value)}`,
453
+ ", ",
454
+ ")"
455
+ ];
456
+ });
457
+ }
458
+ return r;
459
+ };
460
+ //#endregion
461
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseSimpleDiscriminatedOneOf.js
462
+ const parseSimpleDiscriminatedOneOf = (schema, refs) => {
463
+ return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
464
+ ...refs,
465
+ path: [
466
+ ...refs.path,
467
+ "oneOf",
468
+ 0
469
+ ]
470
+ }) : `z.discriminatedUnion("${schema.discriminator.propertyName}", [${schema.oneOf.map((schema, i) => parseSchema(schema, {
471
+ ...refs,
472
+ path: [
473
+ ...refs.path,
474
+ "oneOf",
475
+ i
476
+ ]
477
+ })).join(", ")}])` : "z.any()";
478
+ };
479
+ //#endregion
480
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/utils/omit.js
481
+ const omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
482
+ if (!keys.includes(key)) acc[key] = obj[key];
483
+ return acc;
484
+ }, {});
485
+ //#endregion
486
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseNullable.js
487
+ /**
488
+ * For compatibility with open api 3.0 nullable
489
+ */
490
+ const parseNullable = (schema, refs) => {
491
+ return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
492
+ };
493
+ //#endregion
494
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/parsers/parseSchema.js
495
+ const parseSchema = (schema, refs = {
496
+ seen: /* @__PURE__ */ new Map(),
497
+ path: []
498
+ }, blockMeta) => {
499
+ if (typeof schema !== "object") return schema ? "z.any()" : "z.never()";
500
+ if (refs.parserOverride) {
501
+ const custom = refs.parserOverride(schema, refs);
502
+ if (typeof custom === "string") return custom;
503
+ }
504
+ let seen = refs.seen.get(schema);
505
+ if (seen) {
506
+ if (seen.r !== void 0) return seen.r;
507
+ if (refs.depth === void 0 || seen.n >= refs.depth) return "z.any()";
508
+ seen.n += 1;
509
+ } else {
510
+ seen = {
511
+ r: void 0,
512
+ n: 0
513
+ };
514
+ refs.seen.set(schema, seen);
515
+ }
516
+ let parsed = selectParser(schema, refs);
517
+ if (!blockMeta) {
518
+ if (!refs.withoutDescribes) parsed = addDescribes$1(schema, parsed);
519
+ if (!refs.withoutDefaults) parsed = addDefaults$1(schema, parsed);
520
+ parsed = addAnnotations$1(schema, parsed);
521
+ }
522
+ seen.r = parsed;
523
+ return parsed;
524
+ };
525
+ const addDescribes$1 = (schema, parsed) => {
526
+ if (schema.description) parsed += `.describe(${JSON.stringify(schema.description)})`;
527
+ return parsed;
528
+ };
529
+ const addDefaults$1 = (schema, parsed) => {
530
+ if (schema.default !== void 0) parsed += `.default(${JSON.stringify(schema.default)})`;
531
+ return parsed;
532
+ };
533
+ const addAnnotations$1 = (schema, parsed) => {
534
+ if (schema.readOnly) parsed += ".readonly()";
535
+ return parsed;
536
+ };
537
+ const selectParser = (schema, refs) => {
538
+ if (its.a.nullable(schema)) return parseNullable(schema, refs);
539
+ else if (its.an.object(schema)) return parseObject(schema, refs);
540
+ else if (its.an.array(schema)) return parseArray(schema, refs);
541
+ else if (its.an.anyOf(schema)) return parseAnyOf(schema, refs);
542
+ else if (its.an.allOf(schema)) return parseAllOf(schema, refs);
543
+ else if (its.a.simpleDiscriminatedOneOf(schema)) return parseSimpleDiscriminatedOneOf(schema, refs);
544
+ else if (its.a.oneOf(schema)) return parseOneOf(schema, refs);
545
+ else if (its.a.not(schema)) return parseNot(schema, refs);
546
+ else if (its.an.enum(schema)) return parseEnum(schema);
547
+ else if (its.a.const(schema)) return parseConst(schema);
548
+ else if (its.a.multipleType(schema)) return parseMultipleType(schema, refs);
549
+ else if (its.a.primitive(schema, "string")) return parseString(schema);
550
+ else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) return parseNumber(schema);
551
+ else if (its.a.primitive(schema, "boolean")) return parseBoolean(schema);
552
+ else if (its.a.primitive(schema, "null")) return parseNull(schema);
553
+ else if (its.a.conditional(schema)) return parseIfThenElse(schema, refs);
554
+ else return parseDefault(schema);
555
+ };
556
+ const its = {
557
+ an: {
558
+ object: (x) => x.type === "object",
559
+ array: (x) => x.type === "array",
560
+ anyOf: (x) => x.anyOf !== void 0,
561
+ allOf: (x) => x.allOf !== void 0,
562
+ enum: (x) => x.enum !== void 0
563
+ },
564
+ a: {
565
+ nullable: (x) => x.nullable === true,
566
+ multipleType: (x) => Array.isArray(x.type),
567
+ not: (x) => x.not !== void 0,
568
+ const: (x) => x.const !== void 0,
569
+ primitive: (x, p) => x.type === p,
570
+ conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
571
+ simpleDiscriminatedOneOf: (x) => {
572
+ if (!x.oneOf || !Array.isArray(x.oneOf) || x.oneOf.length === 0 || !x.discriminator || typeof x.discriminator !== "object" || !("propertyName" in x.discriminator) || typeof x.discriminator.propertyName !== "string") return false;
573
+ const discriminatorProp = x.discriminator.propertyName;
574
+ return x.oneOf.every((schema) => {
575
+ if (!schema || typeof schema !== "object" || schema.type !== "object" || !schema.properties || typeof schema.properties !== "object" || !(discriminatorProp in schema.properties)) return false;
576
+ const property = schema.properties[discriminatorProp];
577
+ return property && typeof property === "object" && property.type === "string" && (property.const !== void 0 || property.enum && Array.isArray(property.enum) && property.enum.length === 1) && Array.isArray(schema.required) && schema.required.includes(discriminatorProp);
578
+ });
579
+ },
580
+ oneOf: (x) => x.oneOf !== void 0
581
+ }
582
+ };
583
+ //#endregion
584
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/jsonSchemaToZod.js
585
+ const jsonSchemaToZod$1 = (schema, { module, name, type, noImport, ...rest } = {}) => {
586
+ if (type && (!name || module !== "esm")) throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
587
+ let result = parseSchema(schema, {
588
+ module,
589
+ name,
590
+ path: [],
591
+ seen: /* @__PURE__ */ new Map(),
592
+ ...rest
593
+ });
594
+ const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
595
+ if (module === "cjs") {
596
+ result = `${jsdocs}module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
597
+ `;
598
+ if (!noImport) result = `${jsdocs}const { z } = require("zod")
599
+
600
+ ${result}`;
601
+ } else if (module === "esm") {
602
+ result = `${jsdocs}export ${name ? `const ${name} =` : `default`} ${result}
603
+ `;
604
+ if (!noImport) result = `import { z } from "zod"
605
+
606
+ ${result}`;
607
+ } else if (name) result = `${jsdocs}const ${name} = ${result}`;
608
+ if (type && name) {
609
+ let typeName = typeof type === "string" ? type : `${name[0].toUpperCase()}${name.substring(1)}`;
610
+ result += `export type ${typeName} = z.infer<typeof ${name}>
611
+ `;
612
+ }
613
+ return result;
614
+ };
615
+ //#endregion
616
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.7.0/a13e04d716ba0ad807c80424b9ecc2fa744903d957ce250899a6422d8d845e4a/node_modules/json-schema-to-zod/dist/esm/index.js
617
+ var esm_default = jsonSchemaToZod$1;
618
+ //#endregion
619
+ //#region src/json-to-zod.ts
620
+ function parseObject$1(objectSchema, refs) {
621
+ let properties = void 0;
622
+ if (objectSchema.properties) if (!Object.keys(objectSchema.properties).length) properties = "z.object({})";
623
+ else {
624
+ properties = "z.object({ ";
625
+ properties += Object.keys(objectSchema.properties).map((key) => {
626
+ const propSchema = objectSchema.properties[key];
627
+ let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
628
+ ...refs,
629
+ path: [
630
+ ...refs.path,
631
+ "properties",
632
+ key
633
+ ]
634
+ })}`;
635
+ if (refs.withJsdocs && typeof propSchema === "object") result = addJsdocs(propSchema, result);
636
+ const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
637
+ const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
638
+ return !hasDefault && !required ? `${result}.optional()` : result;
639
+ }).join(", ");
640
+ properties += " })";
641
+ }
642
+ const additionalProperties = objectSchema.additionalProperties !== void 0 && objectSchema.additionalProperties !== false ? parseSchema(objectSchema.additionalProperties, {
643
+ ...refs,
644
+ path: [...refs.path, "additionalProperties"]
645
+ }) : void 0;
646
+ let patternProperties = void 0;
647
+ if (objectSchema.patternProperties) {
648
+ const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
649
+ return [key, parseSchema(value, {
650
+ ...refs,
651
+ path: [
652
+ ...refs.path,
653
+ "patternProperties",
654
+ key
655
+ ]
656
+ })];
657
+ }, {}));
658
+ patternProperties = "";
659
+ if (properties) if (additionalProperties) patternProperties += `.catchall(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
660
+ else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
661
+ else patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
662
+ else if (additionalProperties) patternProperties += `z.record(z.string(), z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
663
+ else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `z.record(z.string(), z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
664
+ else patternProperties += `z.record(z.string(), ${Object.values(parsedPatternProperties)})`;
665
+ patternProperties += ".superRefine((value, ctx) => {\n";
666
+ patternProperties += "for (const key in value) {\n";
667
+ if (additionalProperties) if (objectSchema.properties) patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)\n`;
668
+ else patternProperties += `let evaluated = false\n`;
669
+ for (const key in objectSchema.patternProperties) {
670
+ patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
671
+ if (additionalProperties) patternProperties += "evaluated = true\n";
672
+ patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
673
+ patternProperties += "if (!result.success) {\n";
674
+ patternProperties += `ctx.addIssue({
675
+ path: [...ctx.path, key],
676
+ code: 'custom',
677
+ message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
678
+ params: {
679
+ issues: result.error.issues
680
+ }
681
+ })\n`;
682
+ patternProperties += "}\n";
683
+ patternProperties += "}\n";
684
+ }
685
+ if (additionalProperties) {
686
+ patternProperties += "if (!evaluated) {\n";
687
+ patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
688
+ patternProperties += "if (!result.success) {\n";
689
+ patternProperties += `ctx.addIssue({
690
+ path: [...ctx.path, key],
691
+ code: 'custom',
692
+ message: \`Invalid input: must match catchall schema\`,
693
+ params: {
694
+ issues: result.error.issues
695
+ }
696
+ })\n`;
697
+ patternProperties += "}\n";
698
+ patternProperties += "}\n";
699
+ }
700
+ patternProperties += "}\n";
701
+ patternProperties += "})";
702
+ }
703
+ let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? `z.record(z.string(), ${additionalProperties})` : "z.record(z.string(), z.any())";
704
+ if (its.an.anyOf(objectSchema)) output += `.and(${parseAnyOf({
705
+ ...objectSchema,
706
+ anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? {
707
+ ...x,
708
+ type: "object"
709
+ } : x)
710
+ }, refs)})`;
711
+ if (its.a.oneOf(objectSchema)) output += `.and(${parseOneOf({
712
+ ...objectSchema,
713
+ oneOf: objectSchema.oneOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? {
714
+ ...x,
715
+ type: "object"
716
+ } : x)
717
+ }, refs)})`;
718
+ if (its.an.allOf(objectSchema)) output += `.and(${parseAllOf({
719
+ ...objectSchema,
720
+ allOf: objectSchema.allOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? {
721
+ ...x,
722
+ type: "object"
723
+ } : x)
724
+ }, refs)})`;
725
+ return output;
726
+ }
111
727
  const parserOverride = (schema, refs) => {
112
728
  let parsed = "";
113
729
  let seen = refs.seen.get(schema);
@@ -164,7 +780,7 @@ const parserOverride = (schema, refs) => {
164
780
  };
165
781
  refs.seen.set(schema, seen);
166
782
  }
167
- parsed = parseObject(schema, refs);
783
+ parsed = parseObject$1(schema, refs);
168
784
  }
169
785
  if (parsed) {
170
786
  if (!refs.withoutDescribes) parsed = addDescribes(schema, parsed);
@@ -187,12 +803,12 @@ const addAnnotations = (schema, parsed) => {
187
803
  return parsed;
188
804
  };
189
805
  function jsonSchemaToZod(schema, options = {}) {
190
- return jsonSchemaToZodOriginal(schema, {
806
+ return esm_default(schema, {
191
807
  ...options,
192
808
  parserOverride
193
809
  }).replace(/\.reduce<[^>]+>/g, ".reduce");
194
810
  }
195
811
  //#endregion
196
- export { jsonSchemaToZod };
812
+ export { addJsdocs, expandJsdocs, half, its, jsonSchemaToZod, omit, parseAllOf, parseAnyOf, parseArray, parseBoolean, parseConst, parseDefault, parseEnum, parseIfThenElse, parseMultipleType, parseNot, parseNull, parseNullable, parseNumber, parseObject, parseOneOf, parseSchema, parseSimpleDiscriminatedOneOf, parseString, withMessage };
197
813
 
198
814
  //# sourceMappingURL=json-to-zod.js.map