@mastra/schema-compat 0.0.0-add-save-score-validation-on-stores-20250911031242
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 +177 -0
- package/LICENSE.md +15 -0
- package/README.md +144 -0
- package/dist/chunk-7YUR5KZ5.cjs +34 -0
- package/dist/chunk-7YUR5KZ5.cjs.map +1 -0
- package/dist/chunk-GWTUXMDD.js +28 -0
- package/dist/chunk-GWTUXMDD.js.map +1 -0
- package/dist/index.cjs +1424 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1399 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-compats/anthropic.d.ts +13 -0
- package/dist/provider-compats/anthropic.d.ts.map +1 -0
- package/dist/provider-compats/deepseek.d.ts +13 -0
- package/dist/provider-compats/deepseek.d.ts.map +1 -0
- package/dist/provider-compats/google.d.ts +13 -0
- package/dist/provider-compats/google.d.ts.map +1 -0
- package/dist/provider-compats/meta.d.ts +13 -0
- package/dist/provider-compats/meta.d.ts.map +1 -0
- package/dist/provider-compats/openai-reasoning.d.ts +14 -0
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
- package/dist/provider-compats/openai.d.ts +13 -0
- package/dist/provider-compats/openai.d.ts.map +1 -0
- 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 +228 -0
- package/dist/schema-compatibility.d.ts.map +1 -0
- 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 +96 -0
- package/dist/utils.d.ts.map +1 -0
- 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 +80 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# @mastra/schema-compat
|
|
2
|
+
|
|
3
|
+
## 0.0.0-add-save-score-validation-on-stores-20250911031242
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Change SchemaCompat zodToJsonSchema ref strategy from none to relative, leading to less schema warnings and smaller converted schema sizes ([#7697](https://github.com/mastra-ai/mastra/pull/7697))
|
|
8
|
+
|
|
9
|
+
## 0.11.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ab48c97: dependencies updates:
|
|
14
|
+
- Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
|
|
15
|
+
- 637f323: Fix issue with some compilers and calling zod v4's toJSONSchema function
|
|
16
|
+
- de3cbc6: Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
17
|
+
- 45e4d39: Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
|
|
18
|
+
|
|
19
|
+
## 0.11.2-alpha.3
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#7350](https://github.com/mastra-ai/mastra/pull/7350) [`45e4d39`](https://github.com/mastra-ai/mastra/commit/45e4d391a2a09fc70c48e4d60f505586ada1ba0e) Thanks [@LekoArts](https://github.com/LekoArts)! - Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
|
|
24
|
+
|
|
25
|
+
## 0.11.2-alpha.2
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
30
|
+
|
|
31
|
+
## 0.11.2-alpha.1
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- [#5816](https://github.com/mastra-ai/mastra/pull/5816) [`ab48c97`](https://github.com/mastra-ai/mastra/commit/ab48c979098ea571faf998a55d3a00e7acd7a715) Thanks [@dane-ai-mastra](https://github.com/apps/dane-ai-mastra)! - dependencies updates:
|
|
36
|
+
- Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
|
|
37
|
+
|
|
38
|
+
## 0.11.2-alpha.0
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- [#7121](https://github.com/mastra-ai/mastra/pull/7121) [`637f323`](https://github.com/mastra-ai/mastra/commit/637f32371d79a8f78c52c0d53411af0915fcec67) Thanks [@DanielSLew](https://github.com/DanielSLew)! - Fix issue with some compilers and calling zod v4's toJSONSchema function
|
|
43
|
+
|
|
44
|
+
## 0.11.1
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- [`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix peerdpes for @mastra/core
|
|
49
|
+
|
|
50
|
+
## 0.11.0
|
|
51
|
+
|
|
52
|
+
### Minor Changes
|
|
53
|
+
|
|
54
|
+
- [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
|
|
59
|
+
|
|
60
|
+
- [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
|
|
61
|
+
|
|
62
|
+
- [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
|
|
63
|
+
|
|
64
|
+
## 0.11.0-alpha.2
|
|
65
|
+
|
|
66
|
+
### Minor Changes
|
|
67
|
+
|
|
68
|
+
- [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
|
|
69
|
+
|
|
70
|
+
## 0.10.6-alpha.1
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
|
|
75
|
+
|
|
76
|
+
## 0.10.6-alpha.0
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
|
|
81
|
+
|
|
82
|
+
- [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
|
|
83
|
+
|
|
84
|
+
## 0.10.7
|
|
85
|
+
|
|
86
|
+
### Patch Changes
|
|
87
|
+
|
|
88
|
+
- dd94a26: Dont rely on the full language model for schema compat
|
|
89
|
+
- 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
|
|
90
|
+
- ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
|
|
91
|
+
|
|
92
|
+
## 0.10.7-alpha.1
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
|
|
97
|
+
|
|
98
|
+
## 0.10.7-alpha.0
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- dd94a26: Dont rely on the full language model for schema compat
|
|
103
|
+
- 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
|
|
104
|
+
|
|
105
|
+
## 0.10.6
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
|
|
110
|
+
|
|
111
|
+
## 0.10.6-alpha.0
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
|
|
116
|
+
|
|
117
|
+
## 0.10.5
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- 4da943f: Fix Cannot read properties of undefined (reading 'typeName') in schema compat check
|
|
122
|
+
|
|
123
|
+
## 0.10.5-alpha.0
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- 4da943f: Fix Cannot read properties of undefined (reading 'typeName') in schema compat check
|
|
128
|
+
|
|
129
|
+
## 0.10.4
|
|
130
|
+
|
|
131
|
+
### Patch Changes
|
|
132
|
+
|
|
133
|
+
- 0c85311: Fix Google models ZodNull tool schema handling
|
|
134
|
+
|
|
135
|
+
## 0.10.4-alpha.0
|
|
136
|
+
|
|
137
|
+
### Patch Changes
|
|
138
|
+
|
|
139
|
+
- 0c85311: Fix Google models ZodNull tool schema handling
|
|
140
|
+
|
|
141
|
+
## 0.10.3
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
146
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
147
|
+
|
|
148
|
+
## 0.10.3-alpha.1
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
|
|
153
|
+
|
|
154
|
+
## 0.10.3-alpha.0
|
|
155
|
+
|
|
156
|
+
### Patch Changes
|
|
157
|
+
|
|
158
|
+
- 98bbe5a: Claude cannot handle tuple schemas now.
|
|
159
|
+
|
|
160
|
+
## 0.10.2
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
|
|
165
|
+
- f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra
|
|
166
|
+
|
|
167
|
+
## 0.10.2-alpha.3
|
|
168
|
+
|
|
169
|
+
### Patch Changes
|
|
170
|
+
|
|
171
|
+
- f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
|
|
172
|
+
|
|
173
|
+
## 0.10.2-alpha.2
|
|
174
|
+
|
|
175
|
+
### Patch Changes
|
|
176
|
+
|
|
177
|
+
- f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @mastra/schema-compat
|
|
2
|
+
|
|
3
|
+
Schema compatibility layer for Mastra.ai that provides compatibility fixes for different AI model providers when using Zod schemas with tools.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @mastra/schema-compat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
The package provides a base `SchemaCompatLayer` class that you can extend to create custom compatibility layers for different AI model providers:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { SchemaCompatLayer } from '@mastra/schema-compat';
|
|
19
|
+
import type { LanguageModelV1 } from 'ai';
|
|
20
|
+
|
|
21
|
+
class MyCustomCompat extends SchemaCompatLayer {
|
|
22
|
+
constructor(model: LanguageModelV1) {
|
|
23
|
+
super(model);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
shouldApply(): boolean {
|
|
27
|
+
return this.getModel().provider === 'my-provider';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getSchemaTarget() {
|
|
31
|
+
return 'jsonSchema7';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
|
|
35
|
+
// Your custom processing logic here
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Schema Processing
|
|
42
|
+
|
|
43
|
+
The package includes pre-built compatibility layers for popular AI providers:
|
|
44
|
+
|
|
45
|
+
Use the `applyCompatLayer` function to automatically apply the right compatibility layer:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { applyCompatLayer, OpenAISchemaCompatLayer, AnthropicSchemaCompatLayer } from '@mastra/schema-compat';
|
|
49
|
+
import { yourCustomCompatibilityLayer } from './customCompatibilityLayer';
|
|
50
|
+
import { z } from 'zod';
|
|
51
|
+
|
|
52
|
+
const schema = z.object({
|
|
53
|
+
name: z.string().email(),
|
|
54
|
+
preferences: z.array(z.string()).min(1),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const compatLayers = [
|
|
58
|
+
new OpenAISchemaCompatLayer(model),
|
|
59
|
+
new AnthropicSchemaCompatLayer(model),
|
|
60
|
+
new yourCustomCompatibilityLayer(model),
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
// Automatically applies the first matching compatibility
|
|
64
|
+
const result = applyCompatLayer({
|
|
65
|
+
schema,
|
|
66
|
+
compatLayers,
|
|
67
|
+
mode: 'aiSdkSchema', // or 'jsonSchema'
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Schema Building Utilities
|
|
72
|
+
|
|
73
|
+
The package also provides utility functions for schema conversion:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { convertZodSchemaToAISDKSchema, convertSchemaToZod } from '@mastra/schema-compat';
|
|
77
|
+
import { z } from 'zod';
|
|
78
|
+
import { jsonSchema } from 'ai';
|
|
79
|
+
|
|
80
|
+
const zodSchema = z.object({
|
|
81
|
+
name: z.string(),
|
|
82
|
+
age: z.number(),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Convert Zod to AI SDK Schema
|
|
86
|
+
const aiSchema = convertZodSchemaToAISDKSchema(zodSchema);
|
|
87
|
+
|
|
88
|
+
// Convert AI SDK Schema back to Zod
|
|
89
|
+
const aiSdkSchema = jsonSchema({
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
name: { type: 'string' },
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
const backToZod = convertSchemaToZod(aiSdkSchema);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### Classes
|
|
101
|
+
|
|
102
|
+
- `SchemaCompatLayer` - Base abstract class for creating compatibility layers
|
|
103
|
+
- `AnthropicSchemaCompatLayer` - Compatibility for Anthropic Claude models
|
|
104
|
+
- `OpenAISchemaCompatLayer` - Compatibility for OpenAI models (without structured outputs)
|
|
105
|
+
- `OpenAIReasoningSchemaCompatLayer` - Compatibility for OpenAI reasoning models (o1 series)
|
|
106
|
+
- `GoogleSchemaCompatLayer` - Compatibility for Google Gemini models
|
|
107
|
+
- `DeepSeekSchemaCompatLayer` - Compatibility for DeepSeek models
|
|
108
|
+
- `MetaSchemaCompatLayer` - Compatibility for Meta Llama models
|
|
109
|
+
|
|
110
|
+
### Functions
|
|
111
|
+
|
|
112
|
+
- `applyCompatLayer(options)` - Process schema with automatic compatibility detection
|
|
113
|
+
- `convertZodSchemaToAISDKSchema(zodSchema, target?)` - Convert Zod schema to AI SDK Schema
|
|
114
|
+
- `convertSchemaToZod(schema)` - Convert AI SDK Schema to Zod schema
|
|
115
|
+
|
|
116
|
+
### Types and Constants
|
|
117
|
+
|
|
118
|
+
- `StringCheckType`, `NumberCheckType`, `ArrayCheckType` - Check types for validation
|
|
119
|
+
- `UnsupportedZodType`, `SupportedZodType`, `AllZodType` - Zod type classifications
|
|
120
|
+
- `ZodShape`, `ShapeKey`, `ShapeValue` - Utility types for Zod schemas
|
|
121
|
+
- `ALL_STRING_CHECKS`, `ALL_NUMBER_CHECKS`, `ALL_ARRAY_CHECKS` - Validation constraint arrays
|
|
122
|
+
- `SUPPORTED_ZOD_TYPES`, `UNSUPPORTED_ZOD_TYPES` - Type classification arrays
|
|
123
|
+
|
|
124
|
+
## Provider-Specific Behavior
|
|
125
|
+
|
|
126
|
+
Different AI providers have varying levels of support for JSON Schema features. This package handles these differences automatically:
|
|
127
|
+
|
|
128
|
+
- **OpenAI**: Removes certain string validations for models without structured outputs
|
|
129
|
+
- **Anthropic**: Handles complex nested schemas with proper constraint descriptions
|
|
130
|
+
- **Google**: Uses OpenAPI 3.0 schema format for better compatibility
|
|
131
|
+
- **DeepSeek**: Converts advanced string patterns to descriptions
|
|
132
|
+
- **Meta**: Optimizes array and union type handling
|
|
133
|
+
|
|
134
|
+
## Testing
|
|
135
|
+
|
|
136
|
+
The package includes comprehensive tests covering all functionality:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Run tests
|
|
140
|
+
pnpm test
|
|
141
|
+
|
|
142
|
+
# Run tests in watch mode
|
|
143
|
+
pnpm test --watch
|
|
144
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var zodToJsonSchemaOriginal = require('zod-to-json-schema');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
|
|
9
|
+
|
|
10
|
+
// src/zod-to-json.ts
|
|
11
|
+
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
|
|
12
|
+
const fn = "toJSONSchema";
|
|
13
|
+
if (fn in zod.z) {
|
|
14
|
+
return zod.z[fn](zodSchema, {
|
|
15
|
+
unrepresentable: "any",
|
|
16
|
+
override: (ctx) => {
|
|
17
|
+
const def = ctx.zodSchema?._zod?.def;
|
|
18
|
+
if (def && def.type === "date") {
|
|
19
|
+
ctx.jsonSchema.type = "string";
|
|
20
|
+
ctx.jsonSchema.format = "date-time";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
return zodToJsonSchemaOriginal__default.default(zodSchema, {
|
|
26
|
+
$refStrategy: strategy,
|
|
27
|
+
target
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.zodToJsonSchema = zodToJsonSchema;
|
|
33
|
+
//# sourceMappingURL=chunk-7YUR5KZ5.cjs.map
|
|
34
|
+
//# sourceMappingURL=chunk-7YUR5KZ5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["z","zodToJsonSchemaOriginal"],"mappings":";;;;;;;;;;AAOO,SAAS,eAAA,CACd,SAAA,EACA,MAAA,GAAkB,aAAA,EAClB,WAAkD,UAAA,EAClD;AACA,EAAA,MAAM,EAAA,GAAK,cAAA;AAEX,EAAA,IAAI,MAAMA,KAAA,EAAG;AAEX,IAAA,OAAQA,KAAA,CAAU,EAAE,CAAA,CAAE,SAAA,EAAW;AAAA,MAC/B,eAAA,EAAiB,KAAA;AAAA,MACjB,QAAA,EAAU,CAAC,GAAA,KAAa;AAEtB,QAAA,MAAM,GAAA,GAAM,GAAA,CAAI,SAAA,EAAW,IAAA,EAAM,GAAA;AACjC,QAAA,IAAI,GAAA,IAAO,GAAA,CAAI,IAAA,KAAS,MAAA,EAAQ;AAC9B,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH,CAAA,MAAO;AACL,IAAA,OAAOC,yCAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-7YUR5KZ5.cjs","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport type { ZodType as ZodSchemaV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\nexport function zodToJsonSchema(\n zodSchema: ZodSchemaV3 | ZodSchemaV4,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n) {\n const fn = 'toJSONSchema';\n\n if (fn in z) {\n // Use dynamic property access to avoid import errors in Zod v3\n return (z as any)[fn](zodSchema, {\n unrepresentable: 'any',\n override: (ctx: any) => {\n // Safe access to handle cases where _zod might be undefined\n const def = ctx.zodSchema?._zod?.def;\n if (def && def.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n },\n }) as JSONSchema7;\n } else {\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\n }) as JSONSchema7;\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import zodToJsonSchemaOriginal from 'zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
// src/zod-to-json.ts
|
|
5
|
+
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
|
|
6
|
+
const fn = "toJSONSchema";
|
|
7
|
+
if (fn in z) {
|
|
8
|
+
return z[fn](zodSchema, {
|
|
9
|
+
unrepresentable: "any",
|
|
10
|
+
override: (ctx) => {
|
|
11
|
+
const def = ctx.zodSchema?._zod?.def;
|
|
12
|
+
if (def && def.type === "date") {
|
|
13
|
+
ctx.jsonSchema.type = "string";
|
|
14
|
+
ctx.jsonSchema.format = "date-time";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
return zodToJsonSchemaOriginal(zodSchema, {
|
|
20
|
+
$refStrategy: strategy,
|
|
21
|
+
target
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { zodToJsonSchema };
|
|
27
|
+
//# sourceMappingURL=chunk-GWTUXMDD.js.map
|
|
28
|
+
//# sourceMappingURL=chunk-GWTUXMDD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/zod-to-json.ts"],"names":[],"mappings":";;;;AAOO,SAAS,eAAA,CACd,SAAA,EACA,MAAA,GAAkB,aAAA,EAClB,WAAkD,UAAA,EAClD;AACA,EAAA,MAAM,EAAA,GAAK,cAAA;AAEX,EAAA,IAAI,MAAM,CAAA,EAAG;AAEX,IAAA,OAAQ,CAAA,CAAU,EAAE,CAAA,CAAE,SAAA,EAAW;AAAA,MAC/B,eAAA,EAAiB,KAAA;AAAA,MACjB,QAAA,EAAU,CAAC,GAAA,KAAa;AAEtB,QAAA,MAAM,GAAA,GAAM,GAAA,CAAI,SAAA,EAAW,IAAA,EAAM,GAAA;AACjC,QAAA,IAAI,GAAA,IAAO,GAAA,CAAI,IAAA,KAAS,MAAA,EAAQ;AAC9B,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH,CAAA,MAAO;AACL,IAAA,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-GWTUXMDD.js","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport type { ZodType as ZodSchemaV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\nexport function zodToJsonSchema(\n zodSchema: ZodSchemaV3 | ZodSchemaV4,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n) {\n const fn = 'toJSONSchema';\n\n if (fn in z) {\n // Use dynamic property access to avoid import errors in Zod v3\n return (z as any)[fn](zodSchema, {\n unrepresentable: 'any',\n override: (ctx: any) => {\n // Safe access to handle cases where _zod might be undefined\n const def = ctx.zodSchema?._zod?.def;\n if (def && def.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n },\n }) as JSONSchema7;\n } else {\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\n }) as JSONSchema7;\n }\n}\n"]}
|