@ai-sdk/provider-utils 4.0.8 → 4.0.9
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 +8 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -2
- package/src/__snapshots__/schema.test.ts.snap +0 -346
- package/src/add-additional-properties-to-json-schema.test.ts +0 -289
- package/src/convert-async-iterator-to-readable-stream.test.ts +0 -78
- package/src/convert-image-model-file-to-data-uri.test.ts +0 -85
- package/src/convert-to-form-data.test.ts +0 -167
- package/src/create-tool-name-mapping.test.ts +0 -163
- package/src/delay.test.ts +0 -212
- package/src/delayed-promise.test.ts +0 -132
- package/src/download-blob.test.ts +0 -145
- package/src/generate-id.test.ts +0 -31
- package/src/get-from-api.test.ts +0 -199
- package/src/get-runtime-environment-user-agent.test.ts +0 -47
- package/src/inject-json-instruction.test.ts +0 -404
- package/src/is-url-supported.test.ts +0 -282
- package/src/media-type-to-extension.test.ts +0 -26
- package/src/normalize-headers.test.ts +0 -64
- package/src/parse-json.test.ts +0 -191
- package/src/remove-undefined-entries.test.ts +0 -57
- package/src/resolve.test.ts +0 -125
- package/src/response-handler.test.ts +0 -89
- package/src/schema.test-d.ts +0 -11
- package/src/schema.test.ts +0 -502
- package/src/secure-json-parse.test.ts +0 -59
- package/src/to-json-schema/zod3-to-json-schema/parse-def.test.ts +0 -224
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.test.ts +0 -98
- package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.test.ts +0 -51
- package/src/to-json-schema/zod3-to-json-schema/parsers/branded.test.ts +0 -16
- package/src/to-json-schema/zod3-to-json-schema/parsers/catch.test.ts +0 -15
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.test.ts +0 -97
- package/src/to-json-schema/zod3-to-json-schema/parsers/default.test.ts +0 -54
- package/src/to-json-schema/zod3-to-json-schema/parsers/effects.test.ts +0 -41
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.test.ts +0 -92
- package/src/to-json-schema/zod3-to-json-schema/parsers/map.test.ts +0 -48
- package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.test.ts +0 -102
- package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.test.ts +0 -67
- package/src/to-json-schema/zod3-to-json-schema/parsers/number.test.ts +0 -65
- package/src/to-json-schema/zod3-to-json-schema/parsers/object.test.ts +0 -149
- package/src/to-json-schema/zod3-to-json-schema/parsers/optional.test.ts +0 -147
- package/src/to-json-schema/zod3-to-json-schema/parsers/pipe.test.ts +0 -35
- package/src/to-json-schema/zod3-to-json-schema/parsers/promise.test.ts +0 -15
- package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.test.ts +0 -20
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.test.ts +0 -108
- package/src/to-json-schema/zod3-to-json-schema/parsers/set.test.ts +0 -20
- package/src/to-json-schema/zod3-to-json-schema/parsers/string.test.ts +0 -438
- package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.test.ts +0 -33
- package/src/to-json-schema/zod3-to-json-schema/parsers/union.test.ts +0 -226
- package/src/to-json-schema/zod3-to-json-schema/refs.test.ts +0 -919
- package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.test.ts +0 -862
- package/src/types/tool.test-d.ts +0 -228
- package/src/validate-types.test.ts +0 -105
- package/src/with-user-agent-suffix.test.ts +0 -84
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { z } from 'zod/v3';
|
|
3
|
-
import { parseUnionDef } from './union';
|
|
4
|
-
import { getRefs } from '../refs';
|
|
5
|
-
import { JSONSchema7 } from '@ai-sdk/provider';
|
|
6
|
-
|
|
7
|
-
describe('union', () => {
|
|
8
|
-
it('Should be possible to get a simple type array from a union of only unvalidated primitives', () => {
|
|
9
|
-
const parsedSchema = parseUnionDef(
|
|
10
|
-
z.union([z.string(), z.number(), z.boolean(), z.null()])._def,
|
|
11
|
-
getRefs(),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
expect(parsedSchema).toStrictEqual({
|
|
15
|
-
type: ['string', 'number', 'boolean', 'null'],
|
|
16
|
-
} satisfies JSONSchema7);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('Should be possible to get a simple type array with enum values from a union of literals', () => {
|
|
20
|
-
const parsedSchema = parseUnionDef(
|
|
21
|
-
z.union([
|
|
22
|
-
z.literal('string'),
|
|
23
|
-
z.literal(123),
|
|
24
|
-
z.literal(true),
|
|
25
|
-
z.literal(null),
|
|
26
|
-
z.literal(BigInt(50)),
|
|
27
|
-
])._def,
|
|
28
|
-
getRefs(),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(parsedSchema).toStrictEqual({
|
|
32
|
-
type: ['string', 'number', 'boolean', 'null', 'integer'],
|
|
33
|
-
enum: ['string', 123, true, null, BigInt(50) as unknown as number],
|
|
34
|
-
} satisfies JSONSchema7);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Should be possible to get an anyOf array with enum values from a union of literals', () => {
|
|
38
|
-
const parsedSchema = parseUnionDef(
|
|
39
|
-
z.union([
|
|
40
|
-
z.literal(undefined),
|
|
41
|
-
z.literal(Symbol('abc')),
|
|
42
|
-
// @ts-expect-error Ok
|
|
43
|
-
z.literal(function () {}),
|
|
44
|
-
])._def,
|
|
45
|
-
getRefs(),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(parsedSchema).toStrictEqual({
|
|
49
|
-
anyOf: [
|
|
50
|
-
{
|
|
51
|
-
type: 'object',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
type: 'object',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'object',
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
} satisfies JSONSchema7);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('Should be possible to create a union with objects, arrays and validated primitives as an anyOf', () => {
|
|
64
|
-
const parsedSchema = parseUnionDef(
|
|
65
|
-
z.union([
|
|
66
|
-
z.object({ herp: z.string(), derp: z.boolean() }),
|
|
67
|
-
z.array(z.number()),
|
|
68
|
-
z.string().min(3),
|
|
69
|
-
z.number(),
|
|
70
|
-
])._def,
|
|
71
|
-
getRefs(),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
expect(parsedSchema).toStrictEqual({
|
|
75
|
-
anyOf: [
|
|
76
|
-
{
|
|
77
|
-
type: 'object',
|
|
78
|
-
properties: {
|
|
79
|
-
herp: {
|
|
80
|
-
type: 'string',
|
|
81
|
-
},
|
|
82
|
-
derp: {
|
|
83
|
-
type: 'boolean',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
required: ['herp', 'derp'],
|
|
87
|
-
additionalProperties: false,
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
type: 'array',
|
|
91
|
-
items: {
|
|
92
|
-
type: 'number',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
type: 'string',
|
|
97
|
-
minLength: 3,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
type: 'number',
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
} satisfies JSONSchema7);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should be possible to deref union schemas', () => {
|
|
107
|
-
const recurring = z.object({ foo: z.boolean() });
|
|
108
|
-
|
|
109
|
-
const union = z.union([recurring, recurring, recurring]);
|
|
110
|
-
|
|
111
|
-
const jsonSchema = parseUnionDef(union._def, getRefs());
|
|
112
|
-
|
|
113
|
-
expect(jsonSchema).toStrictEqual({
|
|
114
|
-
anyOf: [
|
|
115
|
-
{
|
|
116
|
-
type: 'object',
|
|
117
|
-
properties: {
|
|
118
|
-
foo: {
|
|
119
|
-
type: 'boolean',
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
required: ['foo'],
|
|
123
|
-
additionalProperties: false,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
$ref: '#/anyOf/0',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
$ref: '#/anyOf/0',
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
} satisfies JSONSchema7);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('nullable primitives should come out fine', () => {
|
|
136
|
-
const union = z.union([z.string(), z.null()]);
|
|
137
|
-
|
|
138
|
-
const jsonSchema = parseUnionDef(union._def, getRefs());
|
|
139
|
-
|
|
140
|
-
expect(jsonSchema).toStrictEqual({
|
|
141
|
-
type: ['string', 'null'],
|
|
142
|
-
} satisfies JSONSchema7);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should join a union of Zod enums into a single enum', () => {
|
|
146
|
-
const union = z.union([z.enum(['a', 'b', 'c']), z.enum(['c', 'd', 'e'])]);
|
|
147
|
-
|
|
148
|
-
const jsonSchema = parseUnionDef(union._def, getRefs());
|
|
149
|
-
|
|
150
|
-
expect(jsonSchema).toStrictEqual({
|
|
151
|
-
type: 'string',
|
|
152
|
-
enum: ['a', 'b', 'c', 'd', 'e'],
|
|
153
|
-
} satisfies JSONSchema7);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should work with discriminated union type', () => {
|
|
157
|
-
const discUnion = z.discriminatedUnion('kek', [
|
|
158
|
-
z.object({ kek: z.literal('A'), lel: z.boolean() }),
|
|
159
|
-
z.object({ kek: z.literal('B'), lel: z.number() }),
|
|
160
|
-
]);
|
|
161
|
-
|
|
162
|
-
const jsonSchema = parseUnionDef(discUnion._def, getRefs());
|
|
163
|
-
|
|
164
|
-
expect(jsonSchema).toStrictEqual({
|
|
165
|
-
anyOf: [
|
|
166
|
-
{
|
|
167
|
-
type: 'object',
|
|
168
|
-
properties: {
|
|
169
|
-
kek: {
|
|
170
|
-
type: 'string',
|
|
171
|
-
const: 'A',
|
|
172
|
-
},
|
|
173
|
-
lel: {
|
|
174
|
-
type: 'boolean',
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
required: ['kek', 'lel'],
|
|
178
|
-
additionalProperties: false,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
type: 'object',
|
|
182
|
-
properties: {
|
|
183
|
-
kek: {
|
|
184
|
-
type: 'string',
|
|
185
|
-
const: 'B',
|
|
186
|
-
},
|
|
187
|
-
lel: {
|
|
188
|
-
type: 'number',
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
required: ['kek', 'lel'],
|
|
192
|
-
additionalProperties: false,
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
} satisfies JSONSchema7);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should not ignore descriptions in literal unions', () => {
|
|
199
|
-
expect(
|
|
200
|
-
parseUnionDef(
|
|
201
|
-
z.union([z.literal(true), z.literal('herp'), z.literal(3)])._def,
|
|
202
|
-
getRefs(),
|
|
203
|
-
),
|
|
204
|
-
).toStrictEqual({
|
|
205
|
-
type: ['boolean', 'string', 'number'],
|
|
206
|
-
enum: [true, 'herp', 3],
|
|
207
|
-
} satisfies JSONSchema7);
|
|
208
|
-
|
|
209
|
-
expect(
|
|
210
|
-
parseUnionDef(
|
|
211
|
-
z.union([
|
|
212
|
-
z.literal(true),
|
|
213
|
-
z.literal('herp').describe('derp'),
|
|
214
|
-
z.literal(3),
|
|
215
|
-
])._def,
|
|
216
|
-
getRefs(),
|
|
217
|
-
),
|
|
218
|
-
).toStrictEqual({
|
|
219
|
-
anyOf: [
|
|
220
|
-
{ type: 'boolean', const: true },
|
|
221
|
-
{ type: 'string', const: 'herp', description: 'derp' },
|
|
222
|
-
{ type: 'number', const: 3 },
|
|
223
|
-
],
|
|
224
|
-
} satisfies JSONSchema7);
|
|
225
|
-
});
|
|
226
|
-
});
|