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