@mastra/schema-compat 1.3.16-alpha.0 → 1.3.17-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.
Files changed (47) hide show
  1. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +274 -889
  2. package/dist/_types/@internal_ai-v6/dist/index.d.ts +1051 -1301
  3. package/dist/{esm-CWlHuVIx.js → esm-BG70JlG8.js} +60 -108
  4. package/dist/{esm-CWlHuVIx.js.map → esm-BG70JlG8.js.map} +1 -1
  5. package/dist/{esm-CkNCkZSB.cjs → esm-BQeGF7AD.cjs} +60 -108
  6. package/dist/{esm-CkNCkZSB.cjs.map → esm-BQeGF7AD.cjs.map} +1 -1
  7. package/dist/index.cjs +162 -185
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.js +162 -185
  10. package/dist/index.js.map +1 -1
  11. package/dist/{json-schema-VSnKq6-P.cjs → json-schema-7oyknwMS.cjs} +241 -247
  12. package/dist/json-schema-7oyknwMS.cjs.map +1 -0
  13. package/dist/{json-schema-R8yfooPa.js → json-schema-BdCwqjfN.js} +241 -247
  14. package/dist/json-schema-BdCwqjfN.js.map +1 -0
  15. package/dist/{json-schema-traverse-B35mHRM8.js → json-schema-traverse-D0CId4oM.js} +5 -7
  16. package/dist/{json-schema-traverse-B35mHRM8.js.map → json-schema-traverse-D0CId4oM.js.map} +1 -1
  17. package/dist/{json-schema-traverse-DbuWNYgg.cjs → json-schema-traverse-evfp8uQX.cjs} +5 -7
  18. package/dist/{json-schema-traverse-DbuWNYgg.cjs.map → json-schema-traverse-evfp8uQX.cjs.map} +1 -1
  19. package/dist/json-to-zod.cjs +153 -142
  20. package/dist/json-to-zod.cjs.map +1 -1
  21. package/dist/json-to-zod.d.ts.map +1 -1
  22. package/dist/json-to-zod.js +153 -142
  23. package/dist/json-to-zod.js.map +1 -1
  24. package/dist/{schema-e0VHpMt0.js → schema-Bf12g7KC.js} +4 -6
  25. package/dist/{schema-e0VHpMt0.js.map → schema-Bf12g7KC.js.map} +1 -1
  26. package/dist/{schema-IhrnbMI3.cjs → schema-D2ab1-Dc.cjs} +5 -7
  27. package/dist/schema-D2ab1-Dc.cjs.map +1 -0
  28. package/dist/schema.cjs +1 -1
  29. package/dist/schema.js +1 -2
  30. package/dist/standard-schema/adapters/ai-sdk.cjs +2 -7
  31. package/dist/standard-schema/adapters/ai-sdk.cjs.map +1 -1
  32. package/dist/standard-schema/adapters/ai-sdk.js +2 -7
  33. package/dist/standard-schema/adapters/ai-sdk.js.map +1 -1
  34. package/dist/standard-schema/adapters/json-schema.cjs +1 -1
  35. package/dist/standard-schema/adapters/json-schema.js +1 -2
  36. package/dist/standard-schema/adapters/zod-v3.cjs +3 -4
  37. package/dist/standard-schema/adapters/zod-v3.cjs.map +1 -1
  38. package/dist/standard-schema/adapters/zod-v3.js +3 -4
  39. package/dist/standard-schema/adapters/zod-v3.js.map +1 -1
  40. package/dist/zod-to-json.cjs +6 -5
  41. package/dist/zod-to-json.cjs.map +1 -1
  42. package/dist/zod-to-json.js +6 -5
  43. package/dist/zod-to-json.js.map +1 -1
  44. package/package.json +24 -25
  45. package/dist/json-schema-R8yfooPa.js.map +0 -1
  46. package/dist/json-schema-VSnKq6-P.cjs.map +0 -1
  47. package/dist/schema-IhrnbMI3.cjs.map +0 -1
@@ -1,4 +1,4 @@
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
1
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
2
2
  const parseAnyOf = (schema, refs) => {
3
3
  return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], {
4
4
  ...refs,
@@ -16,18 +16,15 @@ const parseAnyOf = (schema, refs) => {
16
16
  ]
17
17
  })).join(", ")}])` : `z.any()`;
18
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
19
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseBoolean.js
21
20
  const parseBoolean = (_schema) => {
22
21
  return "z.boolean()";
23
22
  };
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
23
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseDefault.js
26
24
  const parseDefault = (_schema) => {
27
25
  return "z.any()";
28
26
  };
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
27
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseMultipleType.js
31
28
  const parseMultipleType = (schema, refs) => {
32
29
  return `z.union([${schema.type.map((type) => parseSchema({
33
30
  ...schema,
@@ -37,26 +34,22 @@ const parseMultipleType = (schema, refs) => {
37
34
  withoutDefaults: true
38
35
  })).join(", ")}])`;
39
36
  };
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
37
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseNot.js
42
38
  const parseNot = (schema, refs) => {
43
39
  return `z.any().refine((value) => !${parseSchema(schema.not, {
44
40
  ...refs,
45
41
  path: [...refs.path, "not"]
46
42
  })}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
47
43
  };
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
44
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseNull.js
50
45
  const parseNull = (_schema) => {
51
46
  return "z.null()";
52
47
  };
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
48
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/utils/half.js
55
49
  const half = (arr) => {
56
50
  return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
57
51
  };
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
52
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseAllOf.js
60
53
  const originalIndex = Symbol("Original index");
61
54
  const ensureOriginalIndex = (arr) => {
62
55
  let newArr = [];
@@ -91,9 +84,8 @@ function parseAllOf(schema, refs) {
91
84
  return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({ allOf: right }, refs)})`;
92
85
  }
93
86
  }
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) {
87
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/utils/withMessage.js
88
+ function withMessage(schema, key, get, fallbackMessage) {
97
89
  const value = schema[key];
98
90
  let r = "";
99
91
  if (value !== void 0) {
@@ -106,14 +98,14 @@ function withMessage(schema, key, get) {
106
98
  const prefix = got.length === 3 ? got[1] : "";
107
99
  const closer = got.length === 3 ? got[2] : got[1];
108
100
  r += opener;
109
- if (schema.errorMessage?.[key] !== void 0) r += prefix + JSON.stringify(schema.errorMessage[key]);
101
+ const message = schema.errorMessage?.[key] ?? fallbackMessage;
102
+ if (message !== void 0) r += prefix + JSON.stringify(message);
110
103
  r += closer;
111
104
  }
112
105
  }
113
106
  return r;
114
107
  }
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
108
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseArray.js
117
109
  const parseArray = (schema, refs) => {
118
110
  if (Array.isArray(schema.items)) return `z.tuple([${schema.items.map((v, i) => parseSchema(v, {
119
111
  ...refs,
@@ -138,27 +130,24 @@ const parseArray = (schema, refs) => {
138
130
  ")"
139
131
  ]);
140
132
  if (schema.uniqueItems === true) r += withMessage(schema, "uniqueItems", () => [
141
- ".unique(",
142
- "",
133
+ ".refine((arr) => arr.every((item, i) => arr.indexOf(item) == i)",
134
+ ", ",
143
135
  ")"
144
- ]);
136
+ ], "All items must be unique!");
145
137
  return r;
146
138
  };
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
139
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseConst.js
149
140
  const parseConst = (schema) => {
150
141
  return `z.literal(${JSON.stringify(schema.const)})`;
151
142
  };
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
143
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseEnum.js
154
144
  const parseEnum = (schema) => {
155
145
  if (schema.enum.length === 0) return "z.never()";
156
146
  else if (schema.enum.length === 1) return `z.literal(${JSON.stringify(schema.enum[0])})`;
157
147
  else if (schema.enum.every((x) => typeof x === "string")) return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
158
148
  else return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
159
149
  };
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
150
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseIfThenElse.js
162
151
  const parseIfThenElse = (schema, refs) => {
163
152
  const $if = parseSchema(schema.if, {
164
153
  ...refs,
@@ -181,8 +170,7 @@ const parseIfThenElse = (schema, refs) => {
181
170
  }
182
171
  })`;
183
172
  };
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
173
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseNumber.js
186
174
  const parseNumber = (schema) => {
187
175
  let r = "z.number()";
188
176
  if (schema.type === "integer") r += withMessage(schema, "type", () => [".int(", ")"]);
@@ -200,41 +188,43 @@ const parseNumber = (schema) => {
200
188
  ")"
201
189
  ];
202
190
  });
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 }) => [
191
+ if (typeof schema.minimum === "number") {
192
+ if (schema.exclusiveMinimum === true) r += withMessage(schema, "minimum", ({ json }) => [
193
+ `.gt(${json}`,
194
+ ", ",
195
+ ")"
196
+ ]);
197
+ else r += withMessage(schema, "minimum", ({ json }) => [
198
+ `.gte(${json}`,
199
+ ", ",
200
+ ")"
201
+ ]);
202
+ } else if (typeof schema.exclusiveMinimum === "number") r += withMessage(schema, "exclusiveMinimum", ({ json }) => [
214
203
  `.gt(${json}`,
215
204
  ", ",
216
205
  ")"
217
206
  ]);
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 }) => [
207
+ if (typeof schema.maximum === "number") {
208
+ if (schema.exclusiveMaximum === true) r += withMessage(schema, "maximum", ({ json }) => [
209
+ `.lt(${json}`,
210
+ ", ",
211
+ ")"
212
+ ]);
213
+ else r += withMessage(schema, "maximum", ({ json }) => [
214
+ `.lte(${json}`,
215
+ ", ",
216
+ ")"
217
+ ]);
218
+ } else if (typeof schema.exclusiveMaximum === "number") r += withMessage(schema, "exclusiveMaximum", ({ json }) => [
229
219
  `.lt(${json}`,
230
220
  ", ",
231
221
  ")"
232
222
  ]);
233
223
  return r;
234
224
  };
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
225
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseOneOf.js
237
226
  const parseOneOf = (schema, refs) => {
227
+ let is3 = refs.zodVersion === 3;
238
228
  return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
239
229
  ...refs,
240
230
  path: [
@@ -251,26 +241,38 @@ const parseOneOf = (schema, refs) => {
251
241
  i
252
242
  ]
253
243
  })).join(", ")}];
254
- const errors = schemas.reduce<z.ZodError[]>(
255
- (errors, schema) =>
244
+ const { errors, failed } = schemas.reduce<{
245
+ errors: z.${is3 ? "ZodError" : "core.$ZodIssue"}[];
246
+ failed: number;
247
+ }>(
248
+ ({ errors, failed }, schema) =>
256
249
  ((result) =>
257
- result.error ? [...errors, result.error] : errors)(
250
+ result.error
251
+ ? {
252
+ errors: [...errors, ${is3 ? "result.error" : "...result.error.issues"}],
253
+ failed: failed + 1,
254
+ }
255
+ : { errors, failed })(
258
256
  schema.safeParse(x),
259
257
  ),
260
- [],
258
+ { errors: [], failed: 0 },
261
259
  );
262
- if (schemas.length - errors.length !== 1) {
263
- ctx.addIssue({
264
- path: ctx.path,
260
+ const passed = schemas.length - failed;
261
+ if (passed !== 1) {
262
+ ctx.addIssue(errors.length ? {
263
+ path: ${is3 ? "ctx.path" : "[]"},
265
264
  code: "invalid_union",
266
- unionErrors: errors,
267
- message: "Invalid input: Should pass single schema",
265
+ ${is3 ? "unionErrors: errors" : "errors: [errors]"},
266
+ message: "Invalid input: Should pass single schema. Passed " + passed,
267
+ } : {
268
+ path: ${is3 ? "ctx.path" : "[]"},
269
+ code: "custom",${is3 ? "" : "\n errors: [errors],"}
270
+ message: "Invalid input: Should pass single schema. Passed " + passed,
268
271
  });
269
272
  }
270
273
  })` : "z.any()";
271
274
  };
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
275
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/utils/jsdocs.js
274
276
  const expandJsdocs = (jsdocs) => {
275
277
  const lines = jsdocs.split("\n");
276
278
  return `/**${lines.length === 1 ? lines[0] : `\n${lines.map((x) => `* ${x}`).join("\n")}\n`}*/\n`;
@@ -280,29 +282,38 @@ const addJsdocs = (schema, parsed) => {
280
282
  if (!description) return parsed;
281
283
  return `\n${expandJsdocs(description)}${parsed}`;
282
284
  };
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
285
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseObject.js
286
+ function emitRecord(valueSchema, refs) {
287
+ if (refs.zodVersion === 3) return `z.record(${valueSchema})`;
288
+ return `z.record(z.string(), ${valueSchema})`;
289
+ }
290
+ function emitErrorPath(refs) {
291
+ if (refs.zodVersion === 3) return `path: [...ctx.path, key]`;
292
+ return `path: [key]`;
293
+ }
285
294
  function parseObject(objectSchema, refs) {
286
295
  let properties = void 0;
287
- if (objectSchema.properties) if (!Object.keys(objectSchema.properties).length) properties = "z.object({})";
288
- else {
289
- properties = "z.object({ ";
290
- properties += Object.keys(objectSchema.properties).map((key) => {
291
- const propSchema = objectSchema.properties[key];
292
- let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
293
- ...refs,
294
- path: [
295
- ...refs.path,
296
- "properties",
297
- key
298
- ]
299
- })}`;
300
- if (refs.withJsdocs && typeof propSchema === "object") result = addJsdocs(propSchema, result);
301
- const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
302
- const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
303
- return !hasDefault && !required ? `${result}.optional()` : result;
304
- }).join(", ");
305
- properties += " })";
296
+ if (objectSchema.properties) {
297
+ if (!Object.keys(objectSchema.properties).length) properties = "z.object({})";
298
+ else {
299
+ properties = "z.object({ ";
300
+ properties += Object.keys(objectSchema.properties).map((key) => {
301
+ const propSchema = objectSchema.properties[key];
302
+ let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
303
+ ...refs,
304
+ path: [
305
+ ...refs.path,
306
+ "properties",
307
+ key
308
+ ]
309
+ })}`;
310
+ if (refs.withJsdocs && typeof propSchema === "object") result = addJsdocs(propSchema, result);
311
+ const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
312
+ const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
313
+ return !hasDefault && !required ? `${result}.optional()` : result;
314
+ }).join(", ");
315
+ properties += " })";
316
+ }
306
317
  }
307
318
  const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
308
319
  ...refs,
@@ -321,23 +332,26 @@ function parseObject(objectSchema, refs) {
321
332
  })];
322
333
  }, {}));
323
334
  patternProperties = "";
324
- if (properties) if (additionalProperties) patternProperties += `.catchall(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
325
- else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
326
- else patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
327
- else if (additionalProperties) patternProperties += `z.record(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
328
- else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
329
- else patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
335
+ if (properties) {
336
+ if (additionalProperties) patternProperties += `.catchall(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
337
+ else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
338
+ else patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
339
+ } else if (additionalProperties) patternProperties += emitRecord(`z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}])`, refs);
340
+ else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += emitRecord(`z.union([${Object.values(parsedPatternProperties).join(", ")}])`, refs);
341
+ else patternProperties += emitRecord(`${Object.values(parsedPatternProperties)}`, refs);
330
342
  patternProperties += ".superRefine((value, ctx) => {\n";
331
343
  patternProperties += "for (const key in value) {\n";
332
- if (additionalProperties) if (objectSchema.properties) patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)\n`;
333
- else patternProperties += `let evaluated = false\n`;
344
+ if (additionalProperties) {
345
+ if (objectSchema.properties) patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)\n`;
346
+ else patternProperties += `let evaluated = false\n`;
347
+ }
334
348
  for (const key in objectSchema.patternProperties) {
335
349
  patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
336
350
  if (additionalProperties) patternProperties += "evaluated = true\n";
337
351
  patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
338
352
  patternProperties += "if (!result.success) {\n";
339
353
  patternProperties += `ctx.addIssue({
340
- path: [...ctx.path, key],
354
+ ${emitErrorPath(refs)},
341
355
  code: 'custom',
342
356
  message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
343
357
  params: {
@@ -352,7 +366,7 @@ function parseObject(objectSchema, refs) {
352
366
  patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
353
367
  patternProperties += "if (!result.success) {\n";
354
368
  patternProperties += `ctx.addIssue({
355
- path: [...ctx.path, key],
369
+ ${emitErrorPath(refs)},
356
370
  code: 'custom',
357
371
  message: \`Invalid input: must match catchall schema\`,
358
372
  params: {
@@ -365,7 +379,7 @@ function parseObject(objectSchema, refs) {
365
379
  patternProperties += "}\n";
366
380
  patternProperties += "})";
367
381
  }
368
- let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? `z.record(${additionalProperties})` : "z.record(z.any())";
382
+ let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? emitRecord(additionalProperties, refs) : emitRecord("z.any()", refs);
369
383
  if (its.an.anyOf(objectSchema)) output += `.and(${parseAnyOf({
370
384
  ...objectSchema,
371
385
  anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? {
@@ -389,8 +403,7 @@ function parseObject(objectSchema, refs) {
389
403
  }, refs)})`;
390
404
  return output;
391
405
  }
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
406
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseString.js
394
407
  const parseString = (schema) => {
395
408
  let r = "z.string()";
396
409
  r += withMessage(schema, "format", ({ value }) => {
@@ -457,8 +470,7 @@ const parseString = (schema) => {
457
470
  }
458
471
  return r;
459
472
  };
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
473
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseSimpleDiscriminatedOneOf.js
462
474
  const parseSimpleDiscriminatedOneOf = (schema, refs) => {
463
475
  return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
464
476
  ...refs,
@@ -476,22 +488,19 @@ const parseSimpleDiscriminatedOneOf = (schema, refs) => {
476
488
  ]
477
489
  })).join(", ")}])` : "z.any()";
478
490
  };
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
491
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/utils/omit.js
481
492
  const omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
482
493
  if (!keys.includes(key)) acc[key] = obj[key];
483
494
  return acc;
484
495
  }, {});
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
496
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseNullable.js
487
497
  /**
488
498
  * For compatibility with open api 3.0 nullable
489
499
  */
490
500
  const parseNullable = (schema, refs) => {
491
501
  return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
492
502
  };
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
503
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/parsers/parseSchema.js
495
504
  const parseSchema = (schema, refs = {
496
505
  seen: /* @__PURE__ */ new Map(),
497
506
  path: []
@@ -580,15 +589,15 @@ const its = {
580
589
  oneOf: (x) => x.oneOf !== void 0
581
590
  }
582
591
  };
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 } = {}) => {
592
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/jsonSchemaToZod.js
593
+ const jsonSchemaToZod$1 = (schema, { module, name, type, noImport, zodVersion = 4, ...rest } = {}) => {
586
594
  if (type && (!name || module !== "esm")) throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
587
595
  let result = parseSchema(schema, {
588
596
  module,
589
597
  name,
590
598
  path: [],
591
599
  seen: /* @__PURE__ */ new Map(),
600
+ zodVersion,
592
601
  ...rest
593
602
  });
594
603
  const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
@@ -612,32 +621,32 @@ ${result}`;
612
621
  }
613
622
  return result;
614
623
  };
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
624
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/json-schema-to-zod/2.8.1/c100d4d307044bc24116b6230c3615807364a7e5d169923ae0cf63fb170f8f2b/node_modules/json-schema-to-zod/dist/esm/index.js
617
625
  var esm_default = jsonSchemaToZod$1;
618
- //#endregion
619
- //#region src/json-to-zod.ts
626
+ // src/json-to-zod.ts
620
627
  function parseObject$1(objectSchema, refs) {
621
628
  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 += " })";
629
+ if (objectSchema.properties) {
630
+ if (!Object.keys(objectSchema.properties).length) properties = "z.object({})";
631
+ else {
632
+ properties = "z.object({ ";
633
+ properties += Object.keys(objectSchema.properties).map((key) => {
634
+ const propSchema = objectSchema.properties[key];
635
+ let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
636
+ ...refs,
637
+ path: [
638
+ ...refs.path,
639
+ "properties",
640
+ key
641
+ ]
642
+ })}`;
643
+ if (refs.withJsdocs && typeof propSchema === "object") result = addJsdocs(propSchema, result);
644
+ const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
645
+ const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
646
+ return !hasDefault && !required ? `${result}.optional()` : result;
647
+ }).join(", ");
648
+ properties += " })";
649
+ }
641
650
  }
642
651
  const additionalProperties = objectSchema.additionalProperties !== void 0 && objectSchema.additionalProperties !== false ? parseSchema(objectSchema.additionalProperties, {
643
652
  ...refs,
@@ -656,16 +665,19 @@ function parseObject$1(objectSchema, refs) {
656
665
  })];
657
666
  }, {}));
658
667
  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(", ")}]))`;
668
+ if (properties) {
669
+ if (additionalProperties) patternProperties += `.catchall(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
670
+ else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
671
+ else patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
672
+ } else if (additionalProperties) patternProperties += `z.record(z.string(), z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
663
673
  else if (Object.keys(parsedPatternProperties).length > 1) patternProperties += `z.record(z.string(), z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
664
674
  else patternProperties += `z.record(z.string(), ${Object.values(parsedPatternProperties)})`;
665
675
  patternProperties += ".superRefine((value, ctx) => {\n";
666
676
  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`;
677
+ if (additionalProperties) {
678
+ if (objectSchema.properties) patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)\n`;
679
+ else patternProperties += `let evaluated = false\n`;
680
+ }
669
681
  for (const key in objectSchema.patternProperties) {
670
682
  patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
671
683
  if (additionalProperties) patternProperties += "evaluated = true\n";
@@ -808,7 +820,6 @@ function jsonSchemaToZod(schema, options = {}) {
808
820
  parserOverride
809
821
  }).replace(/\.reduce<[^>]+>/g, ".reduce");
810
822
  }
811
- //#endregion
812
823
  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 };
813
824
 
814
825
  //# sourceMappingURL=json-to-zod.js.map