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