@mastra/schema-compat 0.11.5 → 0.11.6
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 +24 -0
- package/dist/chunk-5WM4A32G.cjs +83 -0
- package/dist/chunk-5WM4A32G.cjs.map +1 -0
- package/dist/chunk-U2HXWNAF.js +77 -0
- package/dist/chunk-U2HXWNAF.js.map +1 -0
- package/dist/index.cjs +51 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -80
- package/dist/index.js.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +2 -33
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility-v4.d.ts +2 -33
- package/dist/schema-compatibility-v4.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +2 -33
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/zod-to-json-test-suite.d.ts +6 -0
- package/dist/zod-to-json-test-suite.d.ts.map +1 -0
- package/dist/zod-to-json.cjs +2 -2
- package/dist/zod-to-json.d.ts.map +1 -1
- package/dist/zod-to-json.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-7YUR5KZ5.cjs +0 -34
- package/dist/chunk-7YUR5KZ5.cjs.map +0 -1
- package/dist/chunk-GWTUXMDD.js +0 -28
- package/dist/chunk-GWTUXMDD.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zodToJsonSchema } from './chunk-
|
|
1
|
+
import { zodToJsonSchema } from './chunk-U2HXWNAF.js';
|
|
2
2
|
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodDate, ZodDefault } from 'zod';
|
|
3
3
|
import { jsonSchema } from 'ai';
|
|
4
4
|
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
@@ -229,8 +229,8 @@ var SchemaCompatLayer = class {
|
|
|
229
229
|
* @returns The updated description with constraints, or undefined if no constraints
|
|
230
230
|
*/
|
|
231
231
|
mergeParameterDescription(description, constraints) {
|
|
232
|
-
if (
|
|
233
|
-
return (description ? description + "\n" : "") +
|
|
232
|
+
if (constraints.length > 0) {
|
|
233
|
+
return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
|
|
234
234
|
} else {
|
|
235
235
|
return description;
|
|
236
236
|
}
|
|
@@ -260,24 +260,24 @@ var SchemaCompatLayer = class {
|
|
|
260
260
|
const zodArrayDef = value._def;
|
|
261
261
|
const processedType = this.processZodType(zodArrayDef.type);
|
|
262
262
|
let result = z.array(processedType);
|
|
263
|
-
const constraints =
|
|
263
|
+
const constraints = [];
|
|
264
264
|
if (zodArrayDef.minLength?.value !== void 0) {
|
|
265
265
|
if (handleChecks.includes("min")) {
|
|
266
|
-
constraints.
|
|
266
|
+
constraints.push(`minimum length ${zodArrayDef.minLength.value}`);
|
|
267
267
|
} else {
|
|
268
268
|
result = result.min(zodArrayDef.minLength.value);
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
if (zodArrayDef.maxLength?.value !== void 0) {
|
|
272
272
|
if (handleChecks.includes("max")) {
|
|
273
|
-
constraints.
|
|
273
|
+
constraints.push(`maximum length ${zodArrayDef.maxLength.value}`);
|
|
274
274
|
} else {
|
|
275
275
|
result = result.max(zodArrayDef.maxLength.value);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
if (zodArrayDef.exactLength?.value !== void 0) {
|
|
279
279
|
if (handleChecks.includes("length")) {
|
|
280
|
-
constraints.
|
|
280
|
+
constraints.push(`exact length ${zodArrayDef.exactLength.value}`);
|
|
281
281
|
} else {
|
|
282
282
|
result = result.length(zodArrayDef.exactLength.value);
|
|
283
283
|
}
|
|
@@ -312,7 +312,7 @@ var SchemaCompatLayer = class {
|
|
|
312
312
|
* @returns The processed Zod string
|
|
313
313
|
*/
|
|
314
314
|
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
315
|
-
const constraints =
|
|
315
|
+
const constraints = [];
|
|
316
316
|
const checks = value._def.checks || [];
|
|
317
317
|
const newChecks = [];
|
|
318
318
|
for (const check of checks) {
|
|
@@ -320,38 +320,20 @@ var SchemaCompatLayer = class {
|
|
|
320
320
|
if (handleChecks.includes(check.kind)) {
|
|
321
321
|
switch (check.kind) {
|
|
322
322
|
case "regex": {
|
|
323
|
-
constraints.regex
|
|
324
|
-
pattern: check.regex.source,
|
|
325
|
-
flags: check.regex.flags
|
|
326
|
-
};
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
case "emoji": {
|
|
330
|
-
constraints.emoji = true;
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
case "email": {
|
|
334
|
-
constraints.email = true;
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
case "url": {
|
|
338
|
-
constraints.url = true;
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case "uuid": {
|
|
342
|
-
constraints.uuid = true;
|
|
323
|
+
constraints.push(`input must match this regex ${check.regex.source}`);
|
|
343
324
|
break;
|
|
344
325
|
}
|
|
326
|
+
case "emoji":
|
|
327
|
+
case "email":
|
|
328
|
+
case "url":
|
|
329
|
+
case "uuid":
|
|
345
330
|
case "cuid": {
|
|
346
|
-
constraints.
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
case "min": {
|
|
350
|
-
constraints.minLength = check.value;
|
|
331
|
+
constraints.push(`a valid ${check.kind}`);
|
|
351
332
|
break;
|
|
352
333
|
}
|
|
334
|
+
case "min":
|
|
353
335
|
case "max": {
|
|
354
|
-
constraints.
|
|
336
|
+
constraints.push(`${check.kind}imum length ${check.value}`);
|
|
355
337
|
break;
|
|
356
338
|
}
|
|
357
339
|
}
|
|
@@ -378,7 +360,7 @@ var SchemaCompatLayer = class {
|
|
|
378
360
|
* @returns The processed Zod number
|
|
379
361
|
*/
|
|
380
362
|
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
381
|
-
const constraints =
|
|
363
|
+
const constraints = [];
|
|
382
364
|
const checks = value._def.checks || [];
|
|
383
365
|
const newChecks = [];
|
|
384
366
|
for (const check of checks) {
|
|
@@ -387,20 +369,20 @@ var SchemaCompatLayer = class {
|
|
|
387
369
|
switch (check.kind) {
|
|
388
370
|
case "min":
|
|
389
371
|
if (check.inclusive) {
|
|
390
|
-
constraints.
|
|
372
|
+
constraints.push(`greater than or equal to ${check.value}`);
|
|
391
373
|
} else {
|
|
392
|
-
constraints.
|
|
374
|
+
constraints.push(`greater than ${check.value}`);
|
|
393
375
|
}
|
|
394
376
|
break;
|
|
395
377
|
case "max":
|
|
396
378
|
if (check.inclusive) {
|
|
397
|
-
constraints.
|
|
379
|
+
constraints.push(`lower than or equal to ${check.value}`);
|
|
398
380
|
} else {
|
|
399
|
-
constraints.
|
|
381
|
+
constraints.push(`lower than ${check.value}`);
|
|
400
382
|
}
|
|
401
383
|
break;
|
|
402
384
|
case "multipleOf": {
|
|
403
|
-
constraints.
|
|
385
|
+
constraints.push(`multiple of ${check.value}`);
|
|
404
386
|
break;
|
|
405
387
|
}
|
|
406
388
|
}
|
|
@@ -435,7 +417,7 @@ var SchemaCompatLayer = class {
|
|
|
435
417
|
* @returns A Zod string schema representing the date in ISO format
|
|
436
418
|
*/
|
|
437
419
|
defaultZodDateHandler(value) {
|
|
438
|
-
const constraints =
|
|
420
|
+
const constraints = [];
|
|
439
421
|
const checks = value._def.checks || [];
|
|
440
422
|
for (const check of checks) {
|
|
441
423
|
if ("kind" in check) {
|
|
@@ -443,19 +425,19 @@ var SchemaCompatLayer = class {
|
|
|
443
425
|
case "min":
|
|
444
426
|
const minDate = new Date(check.value);
|
|
445
427
|
if (!isNaN(minDate.getTime())) {
|
|
446
|
-
constraints.
|
|
428
|
+
constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
|
|
447
429
|
}
|
|
448
430
|
break;
|
|
449
431
|
case "max":
|
|
450
432
|
const maxDate = new Date(check.value);
|
|
451
433
|
if (!isNaN(maxDate.getTime())) {
|
|
452
|
-
constraints.
|
|
434
|
+
constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
|
|
453
435
|
}
|
|
454
436
|
break;
|
|
455
437
|
}
|
|
456
438
|
}
|
|
457
439
|
}
|
|
458
|
-
constraints.
|
|
440
|
+
constraints.push(`Date format is date-time`);
|
|
459
441
|
let result = z.string().describe("date-time");
|
|
460
442
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
461
443
|
if (description) {
|
|
@@ -663,8 +645,8 @@ var SchemaCompatLayer2 = class {
|
|
|
663
645
|
* @returns The updated description with constraints, or undefined if no constraints
|
|
664
646
|
*/
|
|
665
647
|
mergeParameterDescription(description, constraints) {
|
|
666
|
-
if (
|
|
667
|
-
return (description ? description + "\n" : "") +
|
|
648
|
+
if (constraints.length > 0) {
|
|
649
|
+
return (description ? description + "\n" : "") + `constraints: ${constraints.join(`, `)}`;
|
|
668
650
|
} else {
|
|
669
651
|
return description;
|
|
670
652
|
}
|
|
@@ -694,26 +676,26 @@ var SchemaCompatLayer2 = class {
|
|
|
694
676
|
const zodArrayDef = value._zod.def;
|
|
695
677
|
const processedType = this.processZodType(zodArrayDef.element);
|
|
696
678
|
let result = z$1.array(processedType);
|
|
697
|
-
const constraints =
|
|
679
|
+
const constraints = [];
|
|
698
680
|
if (zodArrayDef.checks) {
|
|
699
681
|
for (const check of zodArrayDef.checks) {
|
|
700
682
|
if (check._zod.def.check === "min_length") {
|
|
701
683
|
if (handleChecks.includes("min")) {
|
|
702
|
-
constraints.
|
|
684
|
+
constraints.push(`minimum length ${check._zod.def.minimum}`);
|
|
703
685
|
} else {
|
|
704
686
|
result = result.min(check._zod.def.minimum);
|
|
705
687
|
}
|
|
706
688
|
}
|
|
707
689
|
if (check._zod.def.check === "max_length") {
|
|
708
690
|
if (handleChecks.includes("max")) {
|
|
709
|
-
constraints.
|
|
691
|
+
constraints.push(`maximum length ${check._zod.def.maximum}`);
|
|
710
692
|
} else {
|
|
711
693
|
result = result.max(check._zod.def.maximum);
|
|
712
694
|
}
|
|
713
695
|
}
|
|
714
696
|
if (check._zod.def.check === "length_equals") {
|
|
715
697
|
if (handleChecks.includes("length")) {
|
|
716
|
-
constraints.
|
|
698
|
+
constraints.push(`exact length ${check._zod.def.length}`);
|
|
717
699
|
} else {
|
|
718
700
|
result = result.length(check._zod.def.length);
|
|
719
701
|
}
|
|
@@ -752,7 +734,7 @@ var SchemaCompatLayer2 = class {
|
|
|
752
734
|
* @returns The processed Zod string
|
|
753
735
|
*/
|
|
754
736
|
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS2) {
|
|
755
|
-
const constraints =
|
|
737
|
+
const constraints = [];
|
|
756
738
|
const checks = value._zod.def.checks || [];
|
|
757
739
|
const newChecks = [];
|
|
758
740
|
if (checks) {
|
|
@@ -760,36 +742,23 @@ var SchemaCompatLayer2 = class {
|
|
|
760
742
|
if (handleChecks.includes(check._zod.def.check)) {
|
|
761
743
|
switch (check._zod.def.check) {
|
|
762
744
|
case "min_length":
|
|
763
|
-
constraints.
|
|
745
|
+
constraints.push(`minimum length ${check._zod.def.minimum}`);
|
|
764
746
|
break;
|
|
765
747
|
case "max_length":
|
|
766
|
-
constraints.
|
|
748
|
+
constraints.push(`maximum length ${check._zod.def.maximum}`);
|
|
767
749
|
break;
|
|
768
750
|
case "string_format":
|
|
769
751
|
{
|
|
770
752
|
switch (check._zod.def.format) {
|
|
771
753
|
case "email":
|
|
772
|
-
constraints.email = true;
|
|
773
|
-
break;
|
|
774
754
|
case "url":
|
|
775
|
-
constraints.url = true;
|
|
776
|
-
break;
|
|
777
755
|
case "emoji":
|
|
778
|
-
constraints.emoji = true;
|
|
779
|
-
break;
|
|
780
756
|
case "uuid":
|
|
781
|
-
constraints.uuid = true;
|
|
782
|
-
break;
|
|
783
757
|
case "cuid":
|
|
784
|
-
constraints.
|
|
758
|
+
constraints.push(`a valid ${check._zod.def.format}`);
|
|
785
759
|
break;
|
|
786
760
|
case "regex":
|
|
787
|
-
constraints.regex
|
|
788
|
-
// @ts-expect-error - fix later
|
|
789
|
-
pattern: check._zod.def.pattern,
|
|
790
|
-
// @ts-expect-error - fix later
|
|
791
|
-
flags: check._zod.def.flags
|
|
792
|
-
};
|
|
761
|
+
constraints.push(`input must match this regex ${check._zod.def.pattern}`);
|
|
793
762
|
break;
|
|
794
763
|
}
|
|
795
764
|
}
|
|
@@ -820,7 +789,7 @@ var SchemaCompatLayer2 = class {
|
|
|
820
789
|
* @returns The processed Zod number
|
|
821
790
|
*/
|
|
822
791
|
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS2) {
|
|
823
|
-
const constraints =
|
|
792
|
+
const constraints = [];
|
|
824
793
|
const checks = value._zod.def.checks || [];
|
|
825
794
|
const newChecks = [];
|
|
826
795
|
if (checks) {
|
|
@@ -829,20 +798,20 @@ var SchemaCompatLayer2 = class {
|
|
|
829
798
|
switch (check._zod.def.check) {
|
|
830
799
|
case "greater_than":
|
|
831
800
|
if (check._zod.def.inclusive) {
|
|
832
|
-
constraints.
|
|
801
|
+
constraints.push(`greater than or equal to ${check._zod.def.value}`);
|
|
833
802
|
} else {
|
|
834
|
-
constraints.
|
|
803
|
+
constraints.push(`greater than ${check._zod.def.value}`);
|
|
835
804
|
}
|
|
836
805
|
break;
|
|
837
806
|
case "less_than":
|
|
838
807
|
if (check._zod.def.inclusive) {
|
|
839
|
-
constraints.
|
|
808
|
+
constraints.push(`lower than or equal to ${check._zod.def.value}`);
|
|
840
809
|
} else {
|
|
841
|
-
constraints.
|
|
810
|
+
constraints.push(`lower than ${check._zod.def.value}`);
|
|
842
811
|
}
|
|
843
812
|
break;
|
|
844
813
|
case "multiple_of": {
|
|
845
|
-
constraints.
|
|
814
|
+
constraints.push(`multiple of ${check._zod.def.value}`);
|
|
846
815
|
break;
|
|
847
816
|
}
|
|
848
817
|
}
|
|
@@ -879,7 +848,7 @@ var SchemaCompatLayer2 = class {
|
|
|
879
848
|
* @returns A Zod string schema representing the date in ISO format
|
|
880
849
|
*/
|
|
881
850
|
defaultZodDateHandler(value) {
|
|
882
|
-
const constraints =
|
|
851
|
+
const constraints = [];
|
|
883
852
|
const checks = value._zod.def.checks || [];
|
|
884
853
|
if (checks) {
|
|
885
854
|
for (const check of checks) {
|
|
@@ -887,19 +856,19 @@ var SchemaCompatLayer2 = class {
|
|
|
887
856
|
case "less_than":
|
|
888
857
|
const minDate = new Date(check._zod.def.value);
|
|
889
858
|
if (!isNaN(minDate.getTime())) {
|
|
890
|
-
constraints.
|
|
859
|
+
constraints.push(`Date must be newer than ${minDate.toISOString()} (ISO)`);
|
|
891
860
|
}
|
|
892
861
|
break;
|
|
893
862
|
case "greater_than":
|
|
894
863
|
const maxDate = new Date(check._zod.def.value);
|
|
895
864
|
if (!isNaN(maxDate.getTime())) {
|
|
896
|
-
constraints.
|
|
865
|
+
constraints.push(`Date must be older than ${maxDate.toISOString()} (ISO)`);
|
|
897
866
|
}
|
|
898
867
|
break;
|
|
899
868
|
}
|
|
900
869
|
}
|
|
901
870
|
}
|
|
902
|
-
constraints.
|
|
871
|
+
constraints.push(`Date format is date-time`);
|
|
903
872
|
let result = z$1.string().describe("date-time");
|
|
904
873
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
905
874
|
if (description) {
|
|
@@ -1368,9 +1337,9 @@ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
1368
1337
|
const defaultDef = value._def;
|
|
1369
1338
|
const innerType = defaultDef.innerType;
|
|
1370
1339
|
const defaultValue = typeof defaultDef.defaultValue === "function" ? defaultDef.defaultValue() : defaultDef.defaultValue;
|
|
1371
|
-
const constraints =
|
|
1340
|
+
const constraints = [];
|
|
1372
1341
|
if (defaultValue !== void 0) {
|
|
1373
|
-
constraints.
|
|
1342
|
+
constraints.push(`the default value is ${defaultValue}`);
|
|
1374
1343
|
}
|
|
1375
1344
|
const description = this.mergeParameterDescription(value.description, constraints);
|
|
1376
1345
|
let result = this.processZodType(innerType);
|