@ai-sdk/provider-utils 5.0.9 → 5.0.10
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 +6 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/schema.ts +23 -4
package/package.json
CHANGED
package/src/schema.ts
CHANGED
|
@@ -69,7 +69,13 @@ export type ZodSchema<SCHEMA = any> =
|
|
|
69
69
|
| z3.Schema<SCHEMA, z3.ZodTypeDef, any>
|
|
70
70
|
| z4.core.$ZodType<SCHEMA, any>;
|
|
71
71
|
|
|
72
|
-
export type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> &
|
|
72
|
+
export type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & {
|
|
73
|
+
readonly '~standard': StandardSchemaV1.Props<unknown, SCHEMA> & {
|
|
74
|
+
readonly jsonSchema?: StandardJSONSchemaV1.Converter;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type StandardSchemaWithJsonSchema<SCHEMA = any> = StandardSchema<SCHEMA> &
|
|
73
79
|
StandardJSONSchemaV1<unknown, SCHEMA>;
|
|
74
80
|
|
|
75
81
|
export type FlexibleSchema<SCHEMA = any> =
|
|
@@ -154,12 +160,19 @@ function standardSchema<OBJECT>(
|
|
|
154
160
|
standardSchema: StandardSchema<OBJECT>,
|
|
155
161
|
): Schema<OBJECT> {
|
|
156
162
|
return jsonSchema(
|
|
157
|
-
() =>
|
|
158
|
-
|
|
163
|
+
() => {
|
|
164
|
+
if (!hasStandardJsonSchema(standardSchema)) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Standard schema vendor '${standardSchema['~standard'].vendor}' does not support JSON Schema conversion.`,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return addAdditionalPropertiesToJsonSchema(
|
|
159
171
|
standardSchema['~standard'].jsonSchema.input({
|
|
160
172
|
target: 'draft-07',
|
|
161
173
|
}) as JSONSchema7,
|
|
162
|
-
)
|
|
174
|
+
);
|
|
175
|
+
},
|
|
163
176
|
{
|
|
164
177
|
validate: async value => {
|
|
165
178
|
const result = await standardSchema['~standard'].validate(value);
|
|
@@ -177,6 +190,12 @@ function standardSchema<OBJECT>(
|
|
|
177
190
|
);
|
|
178
191
|
}
|
|
179
192
|
|
|
193
|
+
function hasStandardJsonSchema<OBJECT>(
|
|
194
|
+
schema: StandardSchema<OBJECT>,
|
|
195
|
+
): schema is StandardSchemaWithJsonSchema<OBJECT> {
|
|
196
|
+
return schema['~standard'].jsonSchema != null;
|
|
197
|
+
}
|
|
198
|
+
|
|
180
199
|
export function zod3Schema<OBJECT>(
|
|
181
200
|
zodSchema: z3.Schema<OBJECT, z3.ZodTypeDef, any>,
|
|
182
201
|
options?: {
|