@mastra/schema-compat 1.3.6-alpha.2 → 1.3.6-alpha.3
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/CHANGELOG.md +6 -0
- package/dist/esm-WUB3nKhz.js +1095 -0
- package/dist/esm-WUB3nKhz.js.map +1 -0
- package/dist/esm-pT0d13Vi.cjs +1106 -0
- package/dist/esm-pT0d13Vi.cjs.map +1 -0
- package/dist/index.cjs +132 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -1
- package/dist/index.js.map +1 -1
- 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 +2 -2
- package/dist/standard-schema/adapters/zod-v3.js.map +1 -1
- package/dist/zod-to-json.cjs +2 -4
- package/dist/zod-to-json.cjs.map +1 -1
- package/dist/zod-to-json.js +2 -2
- package/dist/zod-to-json.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -4,8 +4,138 @@ import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as is
|
|
|
4
4
|
import { ZodArray, ZodDate, ZodDefault, ZodFirstPartyTypeKind, ZodIntersection, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodString, ZodUnion, z } from "zod/v3";
|
|
5
5
|
import { z as z$1 } from "zod";
|
|
6
6
|
import { convertJsonSchemaToZod } from "zod-from-json-schema";
|
|
7
|
-
import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from "zod-from-json-schema-v3";
|
|
8
7
|
import { ZodArray as ZodArray$1, ZodDate as ZodDate$1, ZodDefault as ZodDefault$1, ZodIntersection as ZodIntersection$1, ZodNull as ZodNull$1, ZodNullable as ZodNullable$1, ZodNumber as ZodNumber$1, ZodObject as ZodObject$1, ZodOptional as ZodOptional$1, ZodString as ZodString$1, ZodUnion as ZodUnion$1, z as z$2 } from "zod/v4";
|
|
8
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod-from-json-schema/0.0.5/8e273a13436172e49bb0898e3f9caf0fd3966851d12111764522ea958a085aeb/node_modules/zod-from-json-schema/dist/index.mjs
|
|
9
|
+
function convertJsonSchemaToZod$1(schema) {
|
|
10
|
+
function addMetadata(zodSchema, jsonSchema) {
|
|
11
|
+
if (jsonSchema.description) zodSchema = zodSchema.describe(jsonSchema.description);
|
|
12
|
+
return zodSchema;
|
|
13
|
+
}
|
|
14
|
+
if (schema.const !== void 0) {
|
|
15
|
+
if (typeof schema.const === "string") return addMetadata(z$1.literal(schema.const), schema);
|
|
16
|
+
else if (typeof schema.const === "number") return addMetadata(z$1.literal(schema.const), schema);
|
|
17
|
+
else if (typeof schema.const === "boolean") return addMetadata(z$1.literal(schema.const), schema);
|
|
18
|
+
else if (schema.const === null) return addMetadata(z$1.null(), schema);
|
|
19
|
+
return addMetadata(z$1.literal(schema.const), schema);
|
|
20
|
+
}
|
|
21
|
+
if (schema.type) switch (schema.type) {
|
|
22
|
+
case "string": {
|
|
23
|
+
if (schema.enum) {
|
|
24
|
+
if (schema.enum.length === 0) return addMetadata(z$1.string(), schema);
|
|
25
|
+
return addMetadata(z$1.enum(schema.enum), schema);
|
|
26
|
+
}
|
|
27
|
+
let stringSchema = z$1.string();
|
|
28
|
+
if (schema.minLength !== void 0) stringSchema = stringSchema.min(schema.minLength);
|
|
29
|
+
if (schema.maxLength !== void 0) stringSchema = stringSchema.max(schema.maxLength);
|
|
30
|
+
if (schema.pattern !== void 0) {
|
|
31
|
+
const regex = new RegExp(schema.pattern);
|
|
32
|
+
stringSchema = stringSchema.regex(regex);
|
|
33
|
+
}
|
|
34
|
+
return addMetadata(stringSchema, schema);
|
|
35
|
+
}
|
|
36
|
+
case "number":
|
|
37
|
+
case "integer": {
|
|
38
|
+
if (schema.enum) {
|
|
39
|
+
if (schema.enum.length === 0) return addMetadata(z$1.number(), schema);
|
|
40
|
+
const options = schema.enum.map((val) => z$1.literal(val));
|
|
41
|
+
if (options.length === 1) return addMetadata(options[0], schema);
|
|
42
|
+
if (options.length >= 2) return addMetadata(z$1.union([
|
|
43
|
+
options[0],
|
|
44
|
+
options[1],
|
|
45
|
+
...options.slice(2)
|
|
46
|
+
]), schema);
|
|
47
|
+
}
|
|
48
|
+
let numberSchema = schema.type === "integer" ? z$1.number().int() : z$1.number();
|
|
49
|
+
if (schema.minimum !== void 0) numberSchema = numberSchema.min(schema.minimum);
|
|
50
|
+
if (schema.maximum !== void 0) numberSchema = numberSchema.max(schema.maximum);
|
|
51
|
+
if (schema.exclusiveMinimum !== void 0) numberSchema = numberSchema.gt(schema.exclusiveMinimum);
|
|
52
|
+
if (schema.exclusiveMaximum !== void 0) numberSchema = numberSchema.lt(schema.exclusiveMaximum);
|
|
53
|
+
if (schema.multipleOf !== void 0) numberSchema = numberSchema.multipleOf(schema.multipleOf);
|
|
54
|
+
return addMetadata(numberSchema, schema);
|
|
55
|
+
}
|
|
56
|
+
case "boolean":
|
|
57
|
+
if (schema.enum) {
|
|
58
|
+
if (schema.enum.length === 0) return addMetadata(z$1.boolean(), schema);
|
|
59
|
+
const options = schema.enum.map((val) => z$1.literal(val));
|
|
60
|
+
if (options.length === 1) return addMetadata(options[0], schema);
|
|
61
|
+
if (options.length >= 2) return addMetadata(z$1.union([
|
|
62
|
+
options[0],
|
|
63
|
+
options[1],
|
|
64
|
+
...options.slice(2)
|
|
65
|
+
]), schema);
|
|
66
|
+
}
|
|
67
|
+
return addMetadata(z$1.boolean(), schema);
|
|
68
|
+
case "null": return addMetadata(z$1.null(), schema);
|
|
69
|
+
case "object":
|
|
70
|
+
if (schema.properties) {
|
|
71
|
+
const shape = {};
|
|
72
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) shape[key] = convertJsonSchemaToZod$1(propSchema);
|
|
73
|
+
if (schema.required && Array.isArray(schema.required)) {
|
|
74
|
+
const required = new Set(schema.required);
|
|
75
|
+
for (const key of Object.keys(shape)) if (!required.has(key)) shape[key] = shape[key].optional();
|
|
76
|
+
} else for (const key of Object.keys(shape)) shape[key] = shape[key].optional();
|
|
77
|
+
let zodSchema;
|
|
78
|
+
if (schema.additionalProperties !== false) zodSchema = z$1.object(shape).passthrough();
|
|
79
|
+
else zodSchema = z$1.object(shape);
|
|
80
|
+
return addMetadata(zodSchema, schema);
|
|
81
|
+
}
|
|
82
|
+
return addMetadata(z$1.object({}), schema);
|
|
83
|
+
case "array": {
|
|
84
|
+
let arraySchema;
|
|
85
|
+
if (schema.items) arraySchema = z$1.array(convertJsonSchemaToZod$1(schema.items));
|
|
86
|
+
else arraySchema = z$1.array(z$1.any());
|
|
87
|
+
if (schema.minItems !== void 0) arraySchema = arraySchema.min(schema.minItems);
|
|
88
|
+
if (schema.maxItems !== void 0) arraySchema = arraySchema.max(schema.maxItems);
|
|
89
|
+
if (schema.uniqueItems === true) arraySchema = arraySchema.refine((items) => {
|
|
90
|
+
const seen = /* @__PURE__ */ new Set();
|
|
91
|
+
return items.every((item) => {
|
|
92
|
+
if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
|
|
93
|
+
if (seen.has(item)) return false;
|
|
94
|
+
seen.add(item);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
const serialized = JSON.stringify(item);
|
|
98
|
+
if (seen.has(serialized)) return false;
|
|
99
|
+
seen.add(serialized);
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
}, { message: "Array items must be unique" });
|
|
103
|
+
return addMetadata(arraySchema, schema);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (schema.enum) {
|
|
107
|
+
if (schema.enum.length === 0) return addMetadata(z$1.never(), schema);
|
|
108
|
+
if (schema.enum.every((val) => typeof val === "string")) return addMetadata(z$1.enum(schema.enum), schema);
|
|
109
|
+
else {
|
|
110
|
+
const options = schema.enum.map((val) => z$1.literal(val));
|
|
111
|
+
if (options.length === 1) return addMetadata(options[0], schema);
|
|
112
|
+
if (options.length >= 2) return addMetadata(z$1.union([
|
|
113
|
+
options[0],
|
|
114
|
+
options[1],
|
|
115
|
+
...options.slice(2)
|
|
116
|
+
]), schema);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (schema.anyOf && schema.anyOf.length >= 2) {
|
|
120
|
+
const schemas = schema.anyOf.map(convertJsonSchemaToZod$1);
|
|
121
|
+
return addMetadata(z$1.union([
|
|
122
|
+
schemas[0],
|
|
123
|
+
schemas[1],
|
|
124
|
+
...schemas.slice(2)
|
|
125
|
+
]), schema);
|
|
126
|
+
}
|
|
127
|
+
if (schema.allOf) return addMetadata(schema.allOf.reduce((acc, s) => z$1.intersection(acc, convertJsonSchemaToZod$1(s)), z$1.object({})), schema);
|
|
128
|
+
if (schema.oneOf && schema.oneOf.length >= 2) {
|
|
129
|
+
const schemas = schema.oneOf.map(convertJsonSchemaToZod$1);
|
|
130
|
+
return addMetadata(z$1.union([
|
|
131
|
+
schemas[0],
|
|
132
|
+
schemas[1],
|
|
133
|
+
...schemas.slice(2)
|
|
134
|
+
]), schema);
|
|
135
|
+
}
|
|
136
|
+
return addMetadata(z$1.any(), schema);
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
9
139
|
//#region ../_vendored/ai_v4/dist/dist-Cm5DZgxA.js
|
|
10
140
|
var marker$1 = "vercel.ai.error";
|
|
11
141
|
var symbol$1 = Symbol.for(marker$1);
|