@mastra/schema-compat 0.10.7 → 0.11.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +34 -0
- package/README.md +0 -4
- package/dist/chunk-FTKGHMGD.js +27 -0
- package/dist/chunk-FTKGHMGD.js.map +1 -0
- package/dist/chunk-LNR4XKDU.cjs +33 -0
- package/dist/chunk-LNR4XKDU.cjs.map +1 -0
- package/dist/index.cjs +846 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +845 -85
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/anthropic.d.ts +6 -4
- package/dist/provider-compats/anthropic.d.ts.map +1 -1
- package/dist/provider-compats/deepseek.d.ts +6 -4
- package/dist/provider-compats/deepseek.d.ts.map +1 -1
- package/dist/provider-compats/google.d.ts +6 -4
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/meta.d.ts +6 -4
- package/dist/provider-compats/meta.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts +6 -4
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts +6 -4
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +319 -0
- package/dist/schema-compatibility-v3.d.ts.map +1 -0
- package/dist/schema-compatibility-v4.d.ts +310 -0
- package/dist/schema-compatibility-v4.d.ts.map +1 -0
- package/dist/schema-compatibility.d.ts +80 -134
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils-test-suite.d.ts +2 -0
- package/dist/utils-test-suite.d.ts.map +1 -0
- package/dist/utils.d.ts +17 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +12 -0
- package/dist/zod-to-json.cjs.map +1 -0
- package/dist/zod-to-json.d.ts +6 -0
- package/dist/zod-to-json.d.ts.map +1 -0
- package/dist/zod-to-json.js +3 -0
- package/dist/zod-to-json.js.map +1 -0
- package/dist/zodTypes.d.ts +21 -0
- package/dist/zodTypes.d.ts.map +1 -0
- package/package.json +16 -6
- package/src/index.ts +4 -3
- package/src/provider-compats/anthropic.ts +29 -11
- package/src/provider-compats/deepseek.ts +14 -9
- package/src/provider-compats/google.ts +18 -32
- package/src/provider-compats/meta.ts +15 -10
- package/src/provider-compats/openai-reasoning.ts +18 -24
- package/src/provider-compats/openai.ts +22 -12
- package/src/schema-compatibility-v3.ts +664 -0
- package/src/schema-compatibility-v4.test.ts +476 -0
- package/src/schema-compatibility-v4.ts +706 -0
- package/src/schema-compatibility.test.ts +12 -28
- package/src/schema-compatibility.ts +263 -383
- package/src/types.ts +5 -0
- package/src/utils-test-suite.ts +467 -0
- package/src/utils-v3.test.ts +9 -0
- package/src/utils-v4.test.ts +9 -0
- package/src/utils.ts +30 -24
- package/src/zod-to-json.ts +27 -0
- package/src/zodTypes.ts +56 -0
- package/tsup.config.ts +8 -3
- package/src/utils.test.ts +0 -460
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MockLanguageModelV1 } from 'ai/test';
|
|
2
2
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import { z } from 'zod/v3';
|
|
4
|
+
import { SchemaCompatLayer } from './schema-compatibility';
|
|
5
|
+
import type { ModelInformation } from './types';
|
|
6
6
|
|
|
7
7
|
class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
8
8
|
constructor(model: ModelInformation) {
|
|
@@ -18,16 +18,16 @@ class MockSchemaCompatibility extends SchemaCompatLayer {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
processZodType(value: z.ZodTypeAny): z.ZodTypeAny {
|
|
21
|
-
if (isObj(value)) {
|
|
21
|
+
if (this.isObj(value)) {
|
|
22
22
|
return this.defaultZodObjectHandler(value);
|
|
23
|
-
} else if (isArr(value)) {
|
|
23
|
+
} else if (this.isArr(value)) {
|
|
24
24
|
// For these tests, we will handle all checks by converting them to descriptions.
|
|
25
25
|
return this.defaultZodArrayHandler(value, ['min', 'max', 'length']);
|
|
26
|
-
} else if (isOptional(value)) {
|
|
26
|
+
} else if (this.isOptional(value)) {
|
|
27
27
|
return this.defaultZodOptionalHandler(value);
|
|
28
|
-
} else if (isUnion(value)) {
|
|
28
|
+
} else if (this.isUnion(value)) {
|
|
29
29
|
return this.defaultZodUnionHandler(value);
|
|
30
|
-
} else if (isString(value)) {
|
|
30
|
+
} else if (this.isString(value)) {
|
|
31
31
|
// Add a marker to confirm it was processed
|
|
32
32
|
return z.string().describe(`${value.description || 'string'}:processed`);
|
|
33
33
|
} else {
|
|
@@ -45,20 +45,12 @@ describe('SchemaCompatLayer', () => {
|
|
|
45
45
|
let compatibility: MockSchemaCompatibility;
|
|
46
46
|
|
|
47
47
|
beforeEach(() => {
|
|
48
|
-
compatibility = new MockSchemaCompatibility(
|
|
49
|
-
modelId: mockModel.modelId,
|
|
50
|
-
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
51
|
-
provider: mockModel.provider,
|
|
52
|
-
});
|
|
48
|
+
compatibility = new MockSchemaCompatibility(mockModel);
|
|
53
49
|
});
|
|
54
50
|
|
|
55
51
|
describe('constructor and getModel', () => {
|
|
56
52
|
it('should store and return the model', () => {
|
|
57
|
-
expect(compatibility.getModel()).
|
|
58
|
-
modelId: mockModel.modelId,
|
|
59
|
-
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
60
|
-
provider: mockModel.provider,
|
|
61
|
-
});
|
|
53
|
+
expect(compatibility.getModel()).toBe(mockModel);
|
|
62
54
|
});
|
|
63
55
|
});
|
|
64
56
|
|
|
@@ -359,11 +351,7 @@ describe('SchemaCompatLayer', () => {
|
|
|
359
351
|
}
|
|
360
352
|
}
|
|
361
353
|
|
|
362
|
-
const testCompat = new TestCompatibility(
|
|
363
|
-
modelId: mockModel.modelId,
|
|
364
|
-
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
365
|
-
provider: mockModel.provider,
|
|
366
|
-
});
|
|
354
|
+
const testCompat = new TestCompatibility(mockModel);
|
|
367
355
|
const result = testCompat.defaultZodOptionalHandler(optionalSchema);
|
|
368
356
|
|
|
369
357
|
expect(result._def.typeName).toBe('ZodOptional');
|
|
@@ -412,11 +400,7 @@ describe('SchemaCompatLayer', () => {
|
|
|
412
400
|
return super.processZodType(value);
|
|
413
401
|
}
|
|
414
402
|
}
|
|
415
|
-
const preservingCompat = new PreservingMock(
|
|
416
|
-
modelId: mockModel.modelId,
|
|
417
|
-
supportsStructuredOutputs: mockModel.supportsStructuredOutputs ?? false,
|
|
418
|
-
provider: mockModel.provider,
|
|
419
|
-
});
|
|
403
|
+
const preservingCompat = new PreservingMock(mockModel);
|
|
420
404
|
const preservingResult = preservingCompat.processToAISDKSchema(arraySchema);
|
|
421
405
|
expect(preservingResult.jsonSchema.description).toBeUndefined();
|
|
422
406
|
expect(
|