@mastra/schema-compat 1.3.17-alpha.0 → 1.3.17
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/index.cjs +48 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -49
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/anthropic.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility-v4.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +2 -1
- package/dist/zod-to-json.cjs.map +1 -1
- package/dist/zod-to-json.d.ts.map +1 -1
- package/dist/zod-to-json.js +2 -1
- package/dist/zod-to-json.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -3432,16 +3432,14 @@ function isZodType(value) {
|
|
|
3432
3432
|
*/
|
|
3433
3433
|
function convertSchemaToZod(schema) {
|
|
3434
3434
|
if (isZodType(schema)) return schema;
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
throw new Error(errorMessage + (e instanceof Error ? `\n${e.stack}` : "\nUnknown error object"));
|
|
3444
|
-
}
|
|
3435
|
+
const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
|
|
3436
|
+
try {
|
|
3437
|
+
if ("toJSONSchema" in z$1) return convertJsonSchemaToZod(jsonSchemaToConvert);
|
|
3438
|
+
return convertJsonSchemaToZod$1(jsonSchemaToConvert);
|
|
3439
|
+
} catch (e) {
|
|
3440
|
+
const errorMessage = `[Schema Builder] Failed to convert schema parameters to Zod. Original schema: ${JSON.stringify(jsonSchemaToConvert)}`;
|
|
3441
|
+
console.error(errorMessage, e);
|
|
3442
|
+
throw new Error(errorMessage + (e instanceof Error ? `\n${e.stack}` : "\nUnknown error object"));
|
|
3445
3443
|
}
|
|
3446
3444
|
}
|
|
3447
3445
|
/**
|
|
@@ -3487,16 +3485,15 @@ function applyCompatLayer({ schema, compatLayers, mode }) {
|
|
|
3487
3485
|
return standardSchemaToJSONSchema(compatSchema);
|
|
3488
3486
|
}
|
|
3489
3487
|
return standardSchemaToJSONSchema(standardSchema);
|
|
3490
|
-
} else {
|
|
3491
|
-
let zodSchema;
|
|
3492
|
-
if (isZodType(schema)) zodSchema = schema;
|
|
3493
|
-
else {
|
|
3494
|
-
if (isStandardSchemaWithJSON(schema)) throw new Error("StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode");
|
|
3495
|
-
zodSchema = convertSchemaToZod(schema);
|
|
3496
|
-
}
|
|
3497
|
-
for (const compat of compatLayers) if (compat.shouldApply()) return compat.processToAISDKSchema(zodSchema);
|
|
3498
|
-
return convertZodSchemaToAISDKSchema(zodSchema);
|
|
3499
3488
|
}
|
|
3489
|
+
let zodSchema;
|
|
3490
|
+
if (isZodType(schema)) zodSchema = schema;
|
|
3491
|
+
else {
|
|
3492
|
+
if (isStandardSchemaWithJSON(schema)) throw new Error("StandardSchemaWithJSON is not supported for applyCompatLayer and aiSdkSchema mode");
|
|
3493
|
+
zodSchema = convertSchemaToZod(schema);
|
|
3494
|
+
}
|
|
3495
|
+
for (const compat of compatLayers) if (compat.shouldApply()) return compat.processToAISDKSchema(zodSchema);
|
|
3496
|
+
return convertZodSchemaToAISDKSchema(zodSchema);
|
|
3500
3497
|
}
|
|
3501
3498
|
// src/schema-compatibility-v3.ts
|
|
3502
3499
|
/**
|
|
@@ -3753,7 +3750,7 @@ var SchemaCompatLayer$1 = class {
|
|
|
3753
3750
|
*/
|
|
3754
3751
|
mergeParameterDescription(description, constraints) {
|
|
3755
3752
|
if (constraints.length > 0) return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
|
|
3756
|
-
|
|
3753
|
+
return description;
|
|
3757
3754
|
}
|
|
3758
3755
|
/**
|
|
3759
3756
|
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
@@ -3918,7 +3915,7 @@ var SchemaCompatLayer$1 = class {
|
|
|
3918
3915
|
*/
|
|
3919
3916
|
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
|
|
3920
3917
|
if (handleTypes.includes(value._def.innerType._def.typeName)) return this.processZodType(value._def.innerType).optional();
|
|
3921
|
-
|
|
3918
|
+
return value;
|
|
3922
3919
|
}
|
|
3923
3920
|
/**
|
|
3924
3921
|
* Default handler for Zod nullable types. Processes the inner type and maintains nullability.
|
|
@@ -3929,7 +3926,7 @@ var SchemaCompatLayer$1 = class {
|
|
|
3929
3926
|
*/
|
|
3930
3927
|
defaultZodNullableHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
|
|
3931
3928
|
if (handleTypes.includes(value._def.innerType._def.typeName)) return this.processZodType(value._def.innerType).nullable();
|
|
3932
|
-
|
|
3929
|
+
return value;
|
|
3933
3930
|
}
|
|
3934
3931
|
/**
|
|
3935
3932
|
* Recursively collects leaf types from a ZodIntersection tree.
|
|
@@ -4230,7 +4227,7 @@ var SchemaCompatLayer$2 = class {
|
|
|
4230
4227
|
*/
|
|
4231
4228
|
mergeParameterDescription(description, constraints) {
|
|
4232
4229
|
if (constraints.length > 0) return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
|
|
4233
|
-
|
|
4230
|
+
return description;
|
|
4234
4231
|
}
|
|
4235
4232
|
/**
|
|
4236
4233
|
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
@@ -4404,7 +4401,7 @@ var SchemaCompatLayer$2 = class {
|
|
|
4404
4401
|
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES$2) {
|
|
4405
4402
|
const innerType = value._zod?.def?.innerType;
|
|
4406
4403
|
if (innerType && handleTypes.includes(zodV4TypeName(innerType))) return this.processZodType(innerType).optional();
|
|
4407
|
-
|
|
4404
|
+
return value;
|
|
4408
4405
|
}
|
|
4409
4406
|
/**
|
|
4410
4407
|
* Default handler for Zod nullable types. Processes the inner type and maintains nullability.
|
|
@@ -4416,7 +4413,7 @@ var SchemaCompatLayer$2 = class {
|
|
|
4416
4413
|
defaultZodNullableHandler(value, handleTypes = SUPPORTED_ZOD_TYPES$2) {
|
|
4417
4414
|
const innerType = value._zod?.def?.innerType;
|
|
4418
4415
|
if (innerType && handleTypes.includes(zodV4TypeName(innerType))) return this.processZodType(innerType).nullable();
|
|
4419
|
-
|
|
4416
|
+
return value;
|
|
4420
4417
|
}
|
|
4421
4418
|
/**
|
|
4422
4419
|
* Recursively collects leaf types from a ZodIntersection tree.
|
|
@@ -4558,82 +4555,82 @@ var SchemaCompatLayer = class {
|
|
|
4558
4555
|
}
|
|
4559
4556
|
getUnsupportedZodTypes(value) {
|
|
4560
4557
|
if ("_zod" in value) return this.v4Layer.getUnsupportedZodTypes();
|
|
4561
|
-
|
|
4558
|
+
return this.v3Layer.getUnsupportedZodTypes();
|
|
4562
4559
|
}
|
|
4563
4560
|
isOptional(v) {
|
|
4564
4561
|
if ("_zod" in v) return this.v4Layer.isOptional(v);
|
|
4565
|
-
|
|
4562
|
+
return this.v3Layer.isOptional(v);
|
|
4566
4563
|
}
|
|
4567
4564
|
isObj(v) {
|
|
4568
4565
|
if ("_zod" in v) return this.v4Layer.isObj(v);
|
|
4569
|
-
|
|
4566
|
+
return this.v3Layer.isObj(v);
|
|
4570
4567
|
}
|
|
4571
4568
|
isNull(v) {
|
|
4572
4569
|
if ("_zod" in v) return this.v4Layer.isNull(v);
|
|
4573
|
-
|
|
4570
|
+
return this.v3Layer.isNull(v);
|
|
4574
4571
|
}
|
|
4575
4572
|
isNullable(v) {
|
|
4576
4573
|
if ("_zod" in v) return this.v4Layer.isNullable(v);
|
|
4577
|
-
|
|
4574
|
+
return this.v3Layer.isNullable(v);
|
|
4578
4575
|
}
|
|
4579
4576
|
isArr(v) {
|
|
4580
4577
|
if ("_zod" in v) return this.v4Layer.isArr(v);
|
|
4581
|
-
|
|
4578
|
+
return this.v3Layer.isArr(v);
|
|
4582
4579
|
}
|
|
4583
4580
|
isUnion(v) {
|
|
4584
4581
|
if ("_zod" in v) return this.v4Layer.isUnion(v);
|
|
4585
|
-
|
|
4582
|
+
return this.v3Layer.isUnion(v);
|
|
4586
4583
|
}
|
|
4587
4584
|
isString(v) {
|
|
4588
4585
|
if ("_zod" in v) return this.v4Layer.isString(v);
|
|
4589
|
-
|
|
4586
|
+
return this.v3Layer.isString(v);
|
|
4590
4587
|
}
|
|
4591
4588
|
isNumber(v) {
|
|
4592
4589
|
if ("_zod" in v) return this.v4Layer.isNumber(v);
|
|
4593
|
-
|
|
4590
|
+
return this.v3Layer.isNumber(v);
|
|
4594
4591
|
}
|
|
4595
4592
|
isDate(v) {
|
|
4596
4593
|
if ("_zod" in v) return this.v4Layer.isDate(v);
|
|
4597
|
-
|
|
4594
|
+
return this.v3Layer.isDate(v);
|
|
4598
4595
|
}
|
|
4599
4596
|
isDefault(v) {
|
|
4600
4597
|
if ("_zod" in v) return this.v4Layer.isDefault(v);
|
|
4601
|
-
|
|
4598
|
+
return this.v3Layer.isDefault(v);
|
|
4602
4599
|
}
|
|
4603
4600
|
isIntersection(v) {
|
|
4604
4601
|
if ("_zod" in v) return this.v4Layer.isIntersection(v);
|
|
4605
|
-
|
|
4602
|
+
return this.v3Layer.isIntersection(v);
|
|
4606
4603
|
}
|
|
4607
4604
|
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
4608
4605
|
if ("_zod" in value) return this.v4Layer.defaultZodObjectHandler(value, options);
|
|
4609
|
-
|
|
4606
|
+
return this.v3Layer.defaultZodObjectHandler(value, options);
|
|
4610
4607
|
}
|
|
4611
4608
|
mergeParameterDescription(description, constraints) {
|
|
4612
4609
|
return this.v3Layer.mergeParameterDescription(description, constraints);
|
|
4613
4610
|
}
|
|
4614
4611
|
defaultUnsupportedZodTypeHandler(value, throwOnTypes) {
|
|
4615
4612
|
if ("_zod" in value) return this.v4Layer.defaultUnsupportedZodTypeHandler(value, throwOnTypes ?? UNSUPPORTED_ZOD_TYPES$2);
|
|
4616
|
-
|
|
4613
|
+
return this.v3Layer.defaultUnsupportedZodTypeHandler(value, throwOnTypes ?? UNSUPPORTED_ZOD_TYPES);
|
|
4617
4614
|
}
|
|
4618
4615
|
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
4619
4616
|
if ("_zod" in value) return this.v4Layer.defaultZodArrayHandler(value, handleChecks);
|
|
4620
|
-
|
|
4617
|
+
return this.v3Layer.defaultZodArrayHandler(value, handleChecks);
|
|
4621
4618
|
}
|
|
4622
4619
|
defaultZodUnionHandler(value) {
|
|
4623
4620
|
if ("_zod" in value) return this.v4Layer.defaultZodUnionHandler(value);
|
|
4624
|
-
|
|
4621
|
+
return this.v3Layer.defaultZodUnionHandler(value);
|
|
4625
4622
|
}
|
|
4626
4623
|
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
4627
4624
|
if ("_zod" in value) return this.v4Layer.defaultZodStringHandler(value);
|
|
4628
|
-
|
|
4625
|
+
return this.v3Layer.defaultZodStringHandler(value, handleChecks);
|
|
4629
4626
|
}
|
|
4630
4627
|
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
4631
4628
|
if ("_zod" in value) return this.v4Layer.defaultZodNumberHandler(value);
|
|
4632
|
-
|
|
4629
|
+
return this.v3Layer.defaultZodNumberHandler(value, handleChecks);
|
|
4633
4630
|
}
|
|
4634
4631
|
defaultZodDateHandler(value) {
|
|
4635
4632
|
if ("_zod" in value) return this.v4Layer.defaultZodDateHandler(value);
|
|
4636
|
-
|
|
4633
|
+
return this.v3Layer.defaultZodDateHandler(value);
|
|
4637
4634
|
}
|
|
4638
4635
|
defaultZodOptionalHandler(value, handleTypes) {
|
|
4639
4636
|
if (!handleTypes) handleTypes = [
|
|
@@ -4654,16 +4651,18 @@ var SchemaCompatLayer = class {
|
|
|
4654
4651
|
const innerType = value._zod?.def?.innerType;
|
|
4655
4652
|
if (!innerType) return value;
|
|
4656
4653
|
return this.processZodType(innerType).optional();
|
|
4657
|
-
}
|
|
4658
|
-
|
|
4654
|
+
}
|
|
4655
|
+
return this.processZodType(value._def.innerType).optional();
|
|
4656
|
+
}
|
|
4657
|
+
return value;
|
|
4659
4658
|
}
|
|
4660
4659
|
defaultZodNullableHandler(value, handleTypes) {
|
|
4661
4660
|
if ("_zod" in value) return this.v4Layer.defaultZodNullableHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES$2);
|
|
4662
|
-
|
|
4661
|
+
return this.v3Layer.defaultZodNullableHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES);
|
|
4663
4662
|
}
|
|
4664
4663
|
defaultZodIntersectionHandler(value) {
|
|
4665
4664
|
if ("_zod" in value) return this.v4Layer.defaultZodIntersectionHandler(value);
|
|
4666
|
-
|
|
4665
|
+
return this.v3Layer.defaultZodIntersectionHandler(value);
|
|
4667
4666
|
}
|
|
4668
4667
|
/**
|
|
4669
4668
|
* @deprecated please use processToCompatSchema to usse StandardSchemaWithJSON
|
|
@@ -5628,7 +5627,7 @@ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
|
|
|
5628
5627
|
else if (this.isUnion(value)) return this.defaultZodUnionHandler(value);
|
|
5629
5628
|
else if (this.isString(value)) {
|
|
5630
5629
|
if (this.getModel().modelId.includes("claude-3.5-haiku")) return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
5631
|
-
|
|
5630
|
+
return value;
|
|
5632
5631
|
} else if (isNull(z$1)(value)) return z$1.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
5633
5632
|
else if (isIntersection(z$1)(value)) return this.defaultZodIntersectionHandler(value);
|
|
5634
5633
|
return this.defaultUnsupportedZodTypeHandler(value);
|