@forklaunch/implementation-worker-database 0.6.3 → 0.6.4
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/lib/consumers/index.d.mts +26 -12
- package/lib/consumers/index.d.ts +26 -12
- package/lib/consumers/index.js +13 -8
- package/lib/consumers/index.mjs +2 -4
- package/lib/domain/schemas/index.d.mts +38 -6
- package/lib/domain/schemas/index.d.ts +38 -6
- package/lib/domain/schemas/index.js +579 -537
- package/lib/domain/schemas/index.mjs +543 -541
- package/lib/domain/types/index.d.mts +2 -2
- package/lib/domain/types/index.d.ts +2 -2
- package/lib/domain/types/index.js +8 -4
- package/lib/producers/index.d.mts +9 -6
- package/lib/producers/index.d.ts +9 -6
- package/lib/producers/index.js +12 -7
- package/lib/producers/index.mjs +1 -3
- package/package.json +6 -6
|
@@ -7,19 +7,25 @@ var __export = (target, all) => {
|
|
|
7
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
8
|
};
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from ===
|
|
10
|
+
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
11
11
|
for (let key of __getOwnPropNames(from))
|
|
12
12
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
return to;
|
|
16
19
|
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (
|
|
21
|
+
__copyProps(target, mod, 'default'),
|
|
22
|
+
secondTarget && __copyProps(secondTarget, mod, 'default')
|
|
23
|
+
);
|
|
18
24
|
|
|
19
25
|
// domain/schemas/databaseWorker.schema.ts
|
|
20
|
-
import { serviceSchemaResolver } from
|
|
26
|
+
import { serviceSchemaResolver } from '@forklaunch/internal';
|
|
21
27
|
|
|
22
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.
|
|
28
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.7/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
|
|
23
29
|
var typebox_exports = {};
|
|
24
30
|
__export(typebox_exports, {
|
|
25
31
|
SchemaValidator: () => SchemaValidator,
|
|
@@ -58,9 +64,9 @@ __export(typebox_exports, {
|
|
|
58
64
|
void_: () => void_
|
|
59
65
|
});
|
|
60
66
|
__reExport(typebox_exports, typebox_star);
|
|
61
|
-
import * as typebox_star from
|
|
67
|
+
import * as typebox_star from '@sinclair/typebox';
|
|
62
68
|
|
|
63
|
-
// ../../../node_modules/.pnpm/@forklaunch+common@0.6.
|
|
69
|
+
// ../../../node_modules/.pnpm/@forklaunch+common@0.6.7/node_modules/@forklaunch/common/lib/index.mjs
|
|
64
70
|
var InMemoryBlob = class extends Blob {
|
|
65
71
|
constructor(content) {
|
|
66
72
|
super([content]);
|
|
@@ -68,221 +74,229 @@ var InMemoryBlob = class extends Blob {
|
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
76
|
|
|
71
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.
|
|
72
|
-
import {
|
|
73
|
-
|
|
74
|
-
Kind,
|
|
75
|
-
KindGuard,
|
|
76
|
-
Type
|
|
77
|
-
} from "@sinclair/typebox";
|
|
78
|
-
import { TypeCheck, TypeCompiler } from "@sinclair/typebox/compiler";
|
|
77
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.7/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
|
|
78
|
+
import { FormatRegistry, Kind, KindGuard, Type } from '@sinclair/typebox';
|
|
79
|
+
import { TypeCheck, TypeCompiler } from '@sinclair/typebox/compiler';
|
|
79
80
|
import {
|
|
80
81
|
DefaultErrorFunction,
|
|
81
82
|
SetErrorFunction,
|
|
82
83
|
ValueErrorType
|
|
83
|
-
} from
|
|
84
|
-
import { Value } from
|
|
85
|
-
FormatRegistry.Set(
|
|
84
|
+
} from '@sinclair/typebox/errors';
|
|
85
|
+
import { Value } from '@sinclair/typebox/value';
|
|
86
|
+
FormatRegistry.Set('binary', (value) => typeof value === 'string');
|
|
86
87
|
SetErrorFunction((params) => {
|
|
87
88
|
switch (params.errorType) {
|
|
88
89
|
case ValueErrorType.Union:
|
|
89
90
|
case ValueErrorType.Array:
|
|
90
91
|
case ValueErrorType.String:
|
|
91
92
|
case ValueErrorType.Number:
|
|
92
|
-
return params.schema.errorType
|
|
93
|
+
return params.schema.errorType
|
|
94
|
+
? `Expected ${params.schema.errorType} value${params.schema.errorSuffix ? 's' : ''}`
|
|
95
|
+
: DefaultErrorFunction(params);
|
|
93
96
|
default:
|
|
94
97
|
return DefaultErrorFunction(params);
|
|
95
98
|
}
|
|
96
99
|
});
|
|
97
100
|
var TypeboxSchemaValidator = class {
|
|
98
|
-
_Type =
|
|
101
|
+
_Type = 'TypeBox';
|
|
99
102
|
_SchemaCatchall;
|
|
100
103
|
_ValidSchemaObject;
|
|
101
104
|
string = Type.String({
|
|
102
|
-
example:
|
|
103
|
-
title:
|
|
105
|
+
example: 'a string',
|
|
106
|
+
title: 'String'
|
|
104
107
|
});
|
|
105
108
|
uuid = Type.String({
|
|
106
|
-
pattern:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
pattern:
|
|
110
|
+
'^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$',
|
|
111
|
+
errorType: 'uuid',
|
|
112
|
+
example: 'a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
|
|
113
|
+
title: 'UUID'
|
|
110
114
|
});
|
|
111
115
|
email = Type.String({
|
|
112
|
-
pattern:
|
|
113
|
-
errorType:
|
|
114
|
-
example:
|
|
115
|
-
title:
|
|
116
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
117
|
+
errorType: 'email',
|
|
118
|
+
example: 'a@b.com',
|
|
119
|
+
title: 'Email'
|
|
116
120
|
});
|
|
117
121
|
uri = Type.String({
|
|
118
|
-
pattern:
|
|
119
|
-
errorType:
|
|
120
|
-
example:
|
|
121
|
-
title:
|
|
122
|
+
pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
|
|
123
|
+
errorType: 'uri',
|
|
124
|
+
example: 'https://forklaunch.com',
|
|
125
|
+
title: 'URI'
|
|
122
126
|
});
|
|
123
127
|
number = Type.Transform(
|
|
124
128
|
Type.Union(
|
|
125
129
|
[
|
|
126
130
|
Type.Number(),
|
|
127
|
-
Type.String({ pattern:
|
|
131
|
+
Type.String({ pattern: '^[0-9]+$' }),
|
|
128
132
|
Type.Boolean(),
|
|
129
133
|
Type.Null(),
|
|
130
134
|
Type.BigInt(),
|
|
131
135
|
Type.Date()
|
|
132
136
|
],
|
|
133
137
|
{
|
|
134
|
-
errorType:
|
|
138
|
+
errorType: 'number-like',
|
|
135
139
|
example: 123,
|
|
136
|
-
title:
|
|
140
|
+
title: 'Number'
|
|
137
141
|
}
|
|
138
142
|
)
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
)
|
|
144
|
+
.Decode((value) => {
|
|
145
|
+
if (typeof value !== 'number') {
|
|
146
|
+
const num = Number(value);
|
|
147
|
+
if (isNaN(num)) {
|
|
148
|
+
throw new Error('Invalid number');
|
|
149
|
+
} else {
|
|
150
|
+
return num;
|
|
151
|
+
}
|
|
146
152
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
return value;
|
|
154
|
+
})
|
|
155
|
+
.Encode(Number);
|
|
150
156
|
bigint = Type.Transform(
|
|
151
157
|
Type.Union(
|
|
152
158
|
[
|
|
153
159
|
Type.BigInt(),
|
|
154
160
|
Type.Number(),
|
|
155
|
-
Type.String({ pattern:
|
|
161
|
+
Type.String({ pattern: '^[0-9]+n?$' }),
|
|
156
162
|
Type.Boolean(),
|
|
157
163
|
Type.Date()
|
|
158
164
|
],
|
|
159
165
|
{
|
|
160
|
-
errorType:
|
|
166
|
+
errorType: 'BigInt-like',
|
|
161
167
|
example: 123n,
|
|
162
|
-
title:
|
|
168
|
+
title: 'BigInt'
|
|
163
169
|
}
|
|
164
170
|
)
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
)
|
|
172
|
+
.Decode((value) => {
|
|
173
|
+
if (typeof value !== 'bigint') {
|
|
174
|
+
try {
|
|
175
|
+
if (value instanceof Date) {
|
|
176
|
+
return BigInt(value.getTime());
|
|
177
|
+
}
|
|
178
|
+
return BigInt(value);
|
|
179
|
+
} catch {
|
|
180
|
+
throw new Error('Invalid bigint');
|
|
170
181
|
}
|
|
171
|
-
return BigInt(value);
|
|
172
|
-
} catch {
|
|
173
|
-
throw new Error("Invalid bigint");
|
|
174
182
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
return value;
|
|
184
|
+
})
|
|
185
|
+
.Encode(BigInt);
|
|
178
186
|
boolean = Type.Transform(
|
|
179
187
|
Type.Union(
|
|
180
188
|
[
|
|
181
189
|
Type.Boolean(),
|
|
182
190
|
Type.String({
|
|
183
|
-
pattern:
|
|
191
|
+
pattern: '^(t|T)(r|R)(u|U)(e|E)$|^(f|F)(a|A)(l|L)(s|S)(e|E)$'
|
|
184
192
|
})
|
|
185
193
|
],
|
|
186
194
|
{
|
|
187
|
-
errorType:
|
|
195
|
+
errorType: 'boolean-like',
|
|
188
196
|
example: true,
|
|
189
|
-
title:
|
|
197
|
+
title: 'Boolean'
|
|
190
198
|
}
|
|
191
199
|
)
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
if (value
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
)
|
|
201
|
+
.Decode((value) => {
|
|
202
|
+
if (typeof value === 'string') {
|
|
203
|
+
if (value.toLowerCase() === 'true') return true;
|
|
204
|
+
return false;
|
|
205
|
+
} else {
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
.Encode(Boolean);
|
|
200
210
|
date = Type.Transform(
|
|
201
211
|
Type.Union(
|
|
202
212
|
[
|
|
203
213
|
Type.String({
|
|
204
|
-
pattern:
|
|
214
|
+
pattern:
|
|
215
|
+
'^\\d{4}(-\\d{2}){0,2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|([+-]\\d{2}:\\d{2}))?)?$|^\\d{1,2}\\/\\d{1,2}\\/\\d{4}$|^\\d{4}\\/\\d{1,2}\\/\\d{1,2}$|^\\d+$'
|
|
205
216
|
}),
|
|
206
217
|
Type.Number(),
|
|
207
218
|
Type.Date()
|
|
208
219
|
],
|
|
209
220
|
{
|
|
210
|
-
errorType:
|
|
211
|
-
example:
|
|
212
|
-
title:
|
|
221
|
+
errorType: 'date',
|
|
222
|
+
example: '2025-05-16T21:13:04.123Z',
|
|
223
|
+
title: 'Date'
|
|
213
224
|
}
|
|
214
225
|
)
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
)
|
|
227
|
+
.Decode((value) => {
|
|
228
|
+
if (value === null || typeof value === 'boolean') {
|
|
229
|
+
return /* @__PURE__ */ new Date(value ? 1 : 0);
|
|
230
|
+
}
|
|
231
|
+
return new Date(value);
|
|
232
|
+
})
|
|
233
|
+
.Encode((value) => new Date(value).toISOString());
|
|
221
234
|
symbol = Type.Symbol({
|
|
222
|
-
title:
|
|
235
|
+
title: 'Symbol'
|
|
236
|
+
});
|
|
237
|
+
nullish = Type.Union([Type.Void(), Type.Null(), Type.Undefined()], {
|
|
238
|
+
errorType: 'nullish',
|
|
239
|
+
type: 'null',
|
|
240
|
+
example: 'null',
|
|
241
|
+
title: 'Nullish'
|
|
223
242
|
});
|
|
224
|
-
nullish = Type.Union(
|
|
225
|
-
[Type.Void(), Type.Null(), Type.Undefined()],
|
|
226
|
-
{
|
|
227
|
-
errorType: "nullish",
|
|
228
|
-
type: "null",
|
|
229
|
-
example: "null",
|
|
230
|
-
title: "Nullish"
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
243
|
void = Type.Void({
|
|
234
|
-
type:
|
|
235
|
-
example:
|
|
236
|
-
title:
|
|
244
|
+
type: 'null',
|
|
245
|
+
example: 'void',
|
|
246
|
+
title: 'Void'
|
|
237
247
|
});
|
|
238
248
|
null = Type.Null({
|
|
239
|
-
type:
|
|
240
|
-
example:
|
|
241
|
-
title:
|
|
249
|
+
type: 'null',
|
|
250
|
+
example: 'null',
|
|
251
|
+
title: 'Null'
|
|
242
252
|
});
|
|
243
253
|
undefined = Type.Undefined({
|
|
244
|
-
type:
|
|
245
|
-
example:
|
|
246
|
-
title:
|
|
254
|
+
type: 'null',
|
|
255
|
+
example: 'undefined',
|
|
256
|
+
title: 'Undefined'
|
|
247
257
|
});
|
|
248
258
|
any = Type.Any({
|
|
249
|
-
type:
|
|
250
|
-
example:
|
|
251
|
-
title:
|
|
259
|
+
type: 'object',
|
|
260
|
+
example: 'any',
|
|
261
|
+
title: 'Any'
|
|
252
262
|
});
|
|
253
263
|
unknown = Type.Unknown({
|
|
254
|
-
type:
|
|
255
|
-
example:
|
|
256
|
-
title:
|
|
264
|
+
type: 'object',
|
|
265
|
+
example: 'unknown',
|
|
266
|
+
title: 'Unknown'
|
|
257
267
|
});
|
|
258
268
|
never = Type.Never({
|
|
259
|
-
type:
|
|
260
|
-
example:
|
|
261
|
-
title:
|
|
269
|
+
type: 'null',
|
|
270
|
+
example: 'never',
|
|
271
|
+
title: 'Never'
|
|
262
272
|
});
|
|
263
273
|
binary = Type.Transform(
|
|
264
274
|
Type.String({
|
|
265
|
-
errorType:
|
|
266
|
-
format:
|
|
267
|
-
example:
|
|
268
|
-
title:
|
|
275
|
+
errorType: 'binary',
|
|
276
|
+
format: 'binary',
|
|
277
|
+
example: 'a base-64 encodable string',
|
|
278
|
+
title: 'Binary'
|
|
269
279
|
})
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
280
|
+
)
|
|
281
|
+
.Decode((value) => new Uint8Array(Buffer.from(value, 'base64')))
|
|
282
|
+
.Encode((value) => {
|
|
283
|
+
if (value instanceof Buffer) {
|
|
284
|
+
return String.fromCharCode(...new Uint8Array(value));
|
|
285
|
+
}
|
|
286
|
+
return '';
|
|
287
|
+
});
|
|
276
288
|
file = Type.Transform(
|
|
277
289
|
Type.Unsafe({
|
|
278
|
-
errorType:
|
|
279
|
-
format:
|
|
280
|
-
example:
|
|
281
|
-
title:
|
|
290
|
+
errorType: 'binary',
|
|
291
|
+
format: 'binary',
|
|
292
|
+
example: 'a raw buffer or file stream',
|
|
293
|
+
title: 'File'
|
|
282
294
|
})
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
|
|
295
|
+
)
|
|
296
|
+
.Decode((value) => {
|
|
297
|
+
return new InMemoryBlob(value);
|
|
298
|
+
})
|
|
299
|
+
.Encode((value) => value.content);
|
|
286
300
|
type = () => this.any;
|
|
287
301
|
/**
|
|
288
302
|
* Extracts the error type of a schema for error messages.
|
|
@@ -291,7 +305,7 @@ var TypeboxSchemaValidator = class {
|
|
|
291
305
|
* @returns The type of the schema for error messages.
|
|
292
306
|
*/
|
|
293
307
|
errorType(schema) {
|
|
294
|
-
if (KindGuard.IsSchema(schema) && Object.hasOwn(schema,
|
|
308
|
+
if (KindGuard.IsSchema(schema) && Object.hasOwn(schema, 'errorType')) {
|
|
295
309
|
return schema.errorType;
|
|
296
310
|
} else if (KindGuard.IsLiteral(schema)) {
|
|
297
311
|
return schema.const;
|
|
@@ -313,7 +327,11 @@ var TypeboxSchemaValidator = class {
|
|
|
313
327
|
* @returns {TResolve<T>} The resolved schema.
|
|
314
328
|
*/
|
|
315
329
|
schemify(schema) {
|
|
316
|
-
if (
|
|
330
|
+
if (
|
|
331
|
+
typeof schema === 'string' ||
|
|
332
|
+
typeof schema === 'number' ||
|
|
333
|
+
typeof schema === 'boolean'
|
|
334
|
+
) {
|
|
317
335
|
return Type.Literal(schema);
|
|
318
336
|
}
|
|
319
337
|
if (KindGuard.IsSchema(schema) || schema instanceof TypeCheck) {
|
|
@@ -363,7 +381,7 @@ var TypeboxSchemaValidator = class {
|
|
|
363
381
|
return this.schemify(schema);
|
|
364
382
|
});
|
|
365
383
|
return Type.Union(unionTypes, {
|
|
366
|
-
errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(
|
|
384
|
+
errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(', ')}`,
|
|
367
385
|
errorSuffix: true
|
|
368
386
|
});
|
|
369
387
|
}
|
|
@@ -434,7 +452,12 @@ var TypeboxSchemaValidator = class {
|
|
|
434
452
|
* @returns {boolean} True if the value is an instance of the schema.
|
|
435
453
|
*/
|
|
436
454
|
isInstanceOf(value, type22) {
|
|
437
|
-
return
|
|
455
|
+
return (
|
|
456
|
+
typeof value === 'object' &&
|
|
457
|
+
value != null &&
|
|
458
|
+
Kind in value &&
|
|
459
|
+
value[Kind] === type22[Kind]
|
|
460
|
+
);
|
|
438
461
|
}
|
|
439
462
|
/**
|
|
440
463
|
* Validate a value against a schema.
|
|
@@ -469,7 +492,7 @@ var TypeboxSchemaValidator = class {
|
|
|
469
492
|
}
|
|
470
493
|
} else {
|
|
471
494
|
const schemified = this.schemify(schema);
|
|
472
|
-
if (schemified[Kind] ===
|
|
495
|
+
if (schemified[Kind] === 'Unsafe') {
|
|
473
496
|
try {
|
|
474
497
|
if (value instanceof Buffer) {
|
|
475
498
|
conversion = new InMemoryBlob(value);
|
|
@@ -478,7 +501,7 @@ var TypeboxSchemaValidator = class {
|
|
|
478
501
|
{
|
|
479
502
|
type: ValueErrorType.String,
|
|
480
503
|
schema: schemified,
|
|
481
|
-
path:
|
|
504
|
+
path: '',
|
|
482
505
|
message: `Invalid file type: expected Buffer or string, got ${typeof value}`,
|
|
483
506
|
value,
|
|
484
507
|
errors: []
|
|
@@ -490,8 +513,8 @@ var TypeboxSchemaValidator = class {
|
|
|
490
513
|
{
|
|
491
514
|
type: ValueErrorType.String,
|
|
492
515
|
schema: schemified,
|
|
493
|
-
path:
|
|
494
|
-
message: err instanceof Error ? err.message :
|
|
516
|
+
path: '',
|
|
517
|
+
message: err instanceof Error ? err.message : 'Invalid file type',
|
|
495
518
|
value,
|
|
496
519
|
errors: []
|
|
497
520
|
}
|
|
@@ -505,33 +528,38 @@ var TypeboxSchemaValidator = class {
|
|
|
505
528
|
}
|
|
506
529
|
}
|
|
507
530
|
}
|
|
508
|
-
return errors != null && errors.length === 0
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
ok: false,
|
|
513
|
-
errors: errors.flatMap((error) => {
|
|
514
|
-
if (error.type === ValueErrorType.Union && error.schema.errorType.includes("any of")) {
|
|
515
|
-
return error.errors.flatMap(
|
|
516
|
-
(e, idx) => Array.from(e).map((e2) => ({
|
|
517
|
-
path: [
|
|
518
|
-
`Union Schema Variant ${idx}`,
|
|
519
|
-
...error.path.split("/").slice(1),
|
|
520
|
-
...e2.path.split("/").slice(1)
|
|
521
|
-
],
|
|
522
|
-
message: e2.message
|
|
523
|
-
}))
|
|
524
|
-
);
|
|
525
|
-
} else {
|
|
526
|
-
return [
|
|
527
|
-
{
|
|
528
|
-
path: error.path.split("/").slice(1),
|
|
529
|
-
message: error.message
|
|
530
|
-
}
|
|
531
|
-
];
|
|
531
|
+
return errors != null && errors.length === 0
|
|
532
|
+
? {
|
|
533
|
+
ok: true,
|
|
534
|
+
value: conversion
|
|
532
535
|
}
|
|
533
|
-
|
|
534
|
-
|
|
536
|
+
: {
|
|
537
|
+
ok: false,
|
|
538
|
+
errors: errors.flatMap((error) => {
|
|
539
|
+
if (
|
|
540
|
+
error.type === ValueErrorType.Union &&
|
|
541
|
+
error.schema.errorType.includes('any of')
|
|
542
|
+
) {
|
|
543
|
+
return error.errors.flatMap((e, idx) =>
|
|
544
|
+
Array.from(e).map((e2) => ({
|
|
545
|
+
path: [
|
|
546
|
+
`Union Schema Variant ${idx}`,
|
|
547
|
+
...error.path.split('/').slice(1),
|
|
548
|
+
...e2.path.split('/').slice(1)
|
|
549
|
+
],
|
|
550
|
+
message: e2.message
|
|
551
|
+
}))
|
|
552
|
+
);
|
|
553
|
+
} else {
|
|
554
|
+
return [
|
|
555
|
+
{
|
|
556
|
+
path: error.path.split('/').slice(1),
|
|
557
|
+
message: error.message
|
|
558
|
+
}
|
|
559
|
+
];
|
|
560
|
+
}
|
|
561
|
+
})
|
|
562
|
+
};
|
|
535
563
|
}
|
|
536
564
|
/**
|
|
537
565
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -542,11 +570,11 @@ var TypeboxSchemaValidator = class {
|
|
|
542
570
|
let schemified = this.schemify(schema);
|
|
543
571
|
if (KindGuard.IsDate(schemified)) {
|
|
544
572
|
schemified = Type.String({
|
|
545
|
-
format:
|
|
573
|
+
format: 'date-time'
|
|
546
574
|
});
|
|
547
575
|
}
|
|
548
576
|
const newSchema = Object.assign({}, schemified);
|
|
549
|
-
if (Object.hasOwn(newSchema,
|
|
577
|
+
if (Object.hasOwn(newSchema, 'properties')) {
|
|
550
578
|
if (newSchema.properties) {
|
|
551
579
|
Object.entries({ ...schemified.properties }).forEach(([key, value]) => {
|
|
552
580
|
if (KindGuard.IsSchema(value) && newSchema.properties) {
|
|
@@ -555,21 +583,17 @@ var TypeboxSchemaValidator = class {
|
|
|
555
583
|
});
|
|
556
584
|
}
|
|
557
585
|
}
|
|
558
|
-
if (Object.hasOwn(newSchema,
|
|
586
|
+
if (Object.hasOwn(newSchema, 'items')) {
|
|
559
587
|
newSchema.items = this.openapi(newSchema.items);
|
|
560
588
|
}
|
|
561
589
|
if (Array.isArray(newSchema.anyOf)) {
|
|
562
|
-
newSchema.anyOf = newSchema.anyOf.map(
|
|
563
|
-
(item) => this.openapi(item)
|
|
564
|
-
);
|
|
590
|
+
newSchema.anyOf = newSchema.anyOf.map((item) => this.openapi(item));
|
|
565
591
|
}
|
|
566
592
|
if (Array.isArray(newSchema.oneOf)) {
|
|
567
|
-
newSchema.oneOf = newSchema.oneOf.map(
|
|
568
|
-
(item) => this.openapi(item)
|
|
569
|
-
);
|
|
593
|
+
newSchema.oneOf = newSchema.oneOf.map((item) => this.openapi(item));
|
|
570
594
|
}
|
|
571
|
-
if (
|
|
572
|
-
delete newSchema[
|
|
595
|
+
if ('errorType' in newSchema) {
|
|
596
|
+
delete newSchema['errorType'];
|
|
573
597
|
}
|
|
574
598
|
return newSchema;
|
|
575
599
|
}
|
|
@@ -615,46 +639,55 @@ var DatabaseWorkerOptionsSchema = {
|
|
|
615
639
|
interval: number
|
|
616
640
|
};
|
|
617
641
|
|
|
618
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.
|
|
619
|
-
import {
|
|
620
|
-
z as z2,
|
|
621
|
-
ZodType
|
|
622
|
-
} from "zod/v3";
|
|
642
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.7/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
643
|
+
import { z as z2, ZodType } from 'zod/v3';
|
|
623
644
|
|
|
624
645
|
// ../../../node_modules/.pnpm/ts-deepmerge@7.0.3/node_modules/ts-deepmerge/esm/index.js
|
|
625
646
|
var isObject = (obj) => {
|
|
626
|
-
if (typeof obj ===
|
|
627
|
-
if (typeof Object.getPrototypeOf ===
|
|
647
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
648
|
+
if (typeof Object.getPrototypeOf === 'function') {
|
|
628
649
|
const prototype = Object.getPrototypeOf(obj);
|
|
629
650
|
return prototype === Object.prototype || prototype === null;
|
|
630
651
|
}
|
|
631
|
-
return Object.prototype.toString.call(obj) ===
|
|
652
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
632
653
|
}
|
|
633
654
|
return false;
|
|
634
655
|
};
|
|
635
|
-
var merge = (...objects) =>
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (Array.isArray(current)) {
|
|
640
|
-
throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
|
|
641
|
-
}
|
|
642
|
-
Object.keys(current).forEach((key) => {
|
|
643
|
-
if (["__proto__", "constructor", "prototype"].includes(key)) {
|
|
644
|
-
return;
|
|
656
|
+
var merge = (...objects) =>
|
|
657
|
+
objects.reduce((result, current) => {
|
|
658
|
+
if (current === void 0) {
|
|
659
|
+
return result;
|
|
645
660
|
}
|
|
646
|
-
if (Array.isArray(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
651
|
-
result[key] = merge(current[key], void 0);
|
|
652
|
-
} else {
|
|
653
|
-
result[key] = current[key] === void 0 ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
|
|
661
|
+
if (Array.isArray(current)) {
|
|
662
|
+
throw new TypeError(
|
|
663
|
+
'Arguments provided to ts-deepmerge must be objects, not arrays.'
|
|
664
|
+
);
|
|
654
665
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
666
|
+
Object.keys(current).forEach((key) => {
|
|
667
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key)) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
671
|
+
result[key] = merge.options.mergeArrays
|
|
672
|
+
? merge.options.uniqueArrayItems
|
|
673
|
+
? Array.from(new Set(result[key].concat(current[key])))
|
|
674
|
+
: [...result[key], ...current[key]]
|
|
675
|
+
: current[key];
|
|
676
|
+
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
677
|
+
result[key] = merge(result[key], current[key]);
|
|
678
|
+
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
679
|
+
result[key] = merge(current[key], void 0);
|
|
680
|
+
} else {
|
|
681
|
+
result[key] =
|
|
682
|
+
current[key] === void 0
|
|
683
|
+
? merge.options.allowUndefinedOverrides
|
|
684
|
+
? current[key]
|
|
685
|
+
: result[key]
|
|
686
|
+
: current[key];
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
return result;
|
|
690
|
+
}, {});
|
|
658
691
|
var defaultOptions = {
|
|
659
692
|
allowUndefinedOverrides: true,
|
|
660
693
|
mergeArrays: true,
|
|
@@ -668,8 +701,8 @@ merge.withOptions = (options, ...objects) => {
|
|
|
668
701
|
return result;
|
|
669
702
|
};
|
|
670
703
|
|
|
671
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.
|
|
672
|
-
import { z } from
|
|
704
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@0.10.7/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
705
|
+
import { z } from 'zod/v3';
|
|
673
706
|
function extendApi(schema, schemaObject = {}) {
|
|
674
707
|
const This = schema.constructor;
|
|
675
708
|
const newSchema = new This(schema._def);
|
|
@@ -686,89 +719,96 @@ function iterateZodObject({
|
|
|
686
719
|
hideDefinitions,
|
|
687
720
|
openApiVersion
|
|
688
721
|
}) {
|
|
689
|
-
const reduced = Object.keys(zodRef.shape)
|
|
690
|
-
(
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
722
|
+
const reduced = Object.keys(zodRef.shape)
|
|
723
|
+
.filter((key) => hideDefinitions?.includes(key) === false)
|
|
724
|
+
.reduce(
|
|
725
|
+
(carry, key) => ({
|
|
726
|
+
...carry,
|
|
727
|
+
[key]: generateSchema(zodRef.shape[key], useOutput, openApiVersion)
|
|
728
|
+
}),
|
|
729
|
+
{}
|
|
730
|
+
);
|
|
696
731
|
return reduced;
|
|
697
732
|
}
|
|
698
733
|
function typeFormat(type22, openApiVersion) {
|
|
699
|
-
return openApiVersion ===
|
|
734
|
+
return openApiVersion === '3.0' ? type22 : [type22];
|
|
700
735
|
}
|
|
701
|
-
function parseTransformation({
|
|
702
|
-
zodRef,
|
|
703
|
-
schemas,
|
|
704
|
-
useOutput,
|
|
705
|
-
openApiVersion
|
|
706
|
-
}) {
|
|
736
|
+
function parseTransformation({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
707
737
|
const input = generateSchema(zodRef._def.schema, useOutput, openApiVersion);
|
|
708
|
-
let output =
|
|
738
|
+
let output = 'undefined';
|
|
709
739
|
if (useOutput && zodRef._def.effect) {
|
|
710
|
-
const effect =
|
|
711
|
-
|
|
740
|
+
const effect =
|
|
741
|
+
zodRef._def.effect.type === 'transform' ? zodRef._def.effect : null;
|
|
742
|
+
if (effect && 'transform' in effect) {
|
|
712
743
|
try {
|
|
713
744
|
const type22 = Array.isArray(input.type) ? input.type[0] : input.type;
|
|
714
745
|
output = typeof effect.transform(
|
|
715
|
-
[
|
|
746
|
+
['integer', 'number'].includes(`${type22}`)
|
|
747
|
+
? 0
|
|
748
|
+
: 'string' === type22
|
|
749
|
+
? ''
|
|
750
|
+
: 'boolean' === type22
|
|
751
|
+
? false
|
|
752
|
+
: 'object' === type22
|
|
753
|
+
? {}
|
|
754
|
+
: 'null' === type22
|
|
755
|
+
? null
|
|
756
|
+
: 'array' === type22
|
|
757
|
+
? []
|
|
758
|
+
: void 0,
|
|
716
759
|
{ addIssue: () => void 0, path: [] }
|
|
717
760
|
// TODO: Discover if context is necessary here
|
|
718
761
|
);
|
|
719
|
-
} catch {
|
|
720
|
-
}
|
|
762
|
+
} catch {}
|
|
721
763
|
}
|
|
722
764
|
}
|
|
723
765
|
const outputType = output;
|
|
724
766
|
return merge(
|
|
725
767
|
{
|
|
726
|
-
...zodRef.description ? { description: zodRef.description } : {},
|
|
768
|
+
...(zodRef.description ? { description: zodRef.description } : {}),
|
|
727
769
|
...input,
|
|
728
|
-
...[
|
|
729
|
-
|
|
730
|
-
|
|
770
|
+
...(['number', 'string', 'boolean', 'null'].includes(output)
|
|
771
|
+
? {
|
|
772
|
+
type: typeFormat(outputType, openApiVersion)
|
|
773
|
+
}
|
|
774
|
+
: {})
|
|
731
775
|
},
|
|
732
776
|
...schemas
|
|
733
777
|
);
|
|
734
778
|
}
|
|
735
|
-
function parseString({
|
|
736
|
-
zodRef,
|
|
737
|
-
schemas,
|
|
738
|
-
openApiVersion
|
|
739
|
-
}) {
|
|
779
|
+
function parseString({ zodRef, schemas, openApiVersion }) {
|
|
740
780
|
const baseSchema = {
|
|
741
|
-
type: typeFormat(
|
|
781
|
+
type: typeFormat('string', openApiVersion)
|
|
742
782
|
};
|
|
743
783
|
const { checks = [] } = zodRef._def;
|
|
744
784
|
checks.forEach((item) => {
|
|
745
785
|
switch (item.kind) {
|
|
746
|
-
case
|
|
747
|
-
baseSchema.format =
|
|
786
|
+
case 'email':
|
|
787
|
+
baseSchema.format = 'email';
|
|
748
788
|
break;
|
|
749
|
-
case
|
|
750
|
-
baseSchema.format =
|
|
789
|
+
case 'uuid':
|
|
790
|
+
baseSchema.format = 'uuid';
|
|
751
791
|
break;
|
|
752
|
-
case
|
|
753
|
-
baseSchema.format =
|
|
792
|
+
case 'cuid':
|
|
793
|
+
baseSchema.format = 'cuid';
|
|
754
794
|
break;
|
|
755
|
-
case
|
|
756
|
-
baseSchema.format =
|
|
795
|
+
case 'url':
|
|
796
|
+
baseSchema.format = 'uri';
|
|
757
797
|
break;
|
|
758
|
-
case
|
|
759
|
-
baseSchema.format =
|
|
798
|
+
case 'datetime':
|
|
799
|
+
baseSchema.format = 'date-time';
|
|
760
800
|
break;
|
|
761
|
-
case
|
|
801
|
+
case 'length':
|
|
762
802
|
baseSchema.minLength = item.value;
|
|
763
803
|
baseSchema.maxLength = item.value;
|
|
764
804
|
break;
|
|
765
|
-
case
|
|
805
|
+
case 'max':
|
|
766
806
|
baseSchema.maxLength = item.value;
|
|
767
807
|
break;
|
|
768
|
-
case
|
|
808
|
+
case 'min':
|
|
769
809
|
baseSchema.minLength = item.value;
|
|
770
810
|
break;
|
|
771
|
-
case
|
|
811
|
+
case 'regex':
|
|
772
812
|
baseSchema.pattern = item.regex.source;
|
|
773
813
|
break;
|
|
774
814
|
}
|
|
@@ -779,45 +819,41 @@ function parseString({
|
|
|
779
819
|
...schemas
|
|
780
820
|
);
|
|
781
821
|
}
|
|
782
|
-
function parseNumber({
|
|
783
|
-
zodRef,
|
|
784
|
-
schemas,
|
|
785
|
-
openApiVersion
|
|
786
|
-
}) {
|
|
822
|
+
function parseNumber({ zodRef, schemas, openApiVersion }) {
|
|
787
823
|
const baseSchema = {
|
|
788
|
-
type: typeFormat(
|
|
824
|
+
type: typeFormat('number', openApiVersion)
|
|
789
825
|
};
|
|
790
826
|
const { checks = [] } = zodRef._def;
|
|
791
827
|
checks.forEach((item) => {
|
|
792
828
|
switch (item.kind) {
|
|
793
|
-
case
|
|
794
|
-
if (item.inclusive || openApiVersion ===
|
|
829
|
+
case 'max':
|
|
830
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
795
831
|
baseSchema.maximum = item.value;
|
|
796
832
|
}
|
|
797
833
|
if (!item.inclusive) {
|
|
798
|
-
if (openApiVersion ===
|
|
834
|
+
if (openApiVersion === '3.0') {
|
|
799
835
|
baseSchema.exclusiveMaximum = true;
|
|
800
836
|
} else {
|
|
801
837
|
baseSchema.exclusiveMaximum = item.value;
|
|
802
838
|
}
|
|
803
839
|
}
|
|
804
840
|
break;
|
|
805
|
-
case
|
|
806
|
-
if (item.inclusive || openApiVersion ===
|
|
841
|
+
case 'min':
|
|
842
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
807
843
|
baseSchema.minimum = item.value;
|
|
808
844
|
}
|
|
809
845
|
if (!item.inclusive) {
|
|
810
|
-
if (openApiVersion ===
|
|
846
|
+
if (openApiVersion === '3.0') {
|
|
811
847
|
baseSchema.exclusiveMinimum = true;
|
|
812
848
|
} else {
|
|
813
849
|
baseSchema.exclusiveMinimum = item.value;
|
|
814
850
|
}
|
|
815
851
|
}
|
|
816
852
|
break;
|
|
817
|
-
case
|
|
818
|
-
baseSchema.type = typeFormat(
|
|
853
|
+
case 'int':
|
|
854
|
+
baseSchema.type = typeFormat('integer', openApiVersion);
|
|
819
855
|
break;
|
|
820
|
-
case
|
|
856
|
+
case 'multipleOf':
|
|
821
857
|
baseSchema.multipleOf = item.value;
|
|
822
858
|
break;
|
|
823
859
|
}
|
|
@@ -845,26 +881,37 @@ function parseObject({
|
|
|
845
881
|
openApiVersion
|
|
846
882
|
}) {
|
|
847
883
|
let additionalProperties;
|
|
848
|
-
if (
|
|
884
|
+
if (
|
|
885
|
+
!(
|
|
886
|
+
zodRef._def.catchall instanceof z.ZodNever ||
|
|
887
|
+
zodRef._def.catchall?._def.typeName === 'ZodNever'
|
|
888
|
+
)
|
|
889
|
+
)
|
|
849
890
|
additionalProperties = generateSchema(
|
|
850
891
|
zodRef._def.catchall,
|
|
851
892
|
useOutput,
|
|
852
893
|
openApiVersion
|
|
853
894
|
);
|
|
854
|
-
else if (zodRef._def.unknownKeys ===
|
|
895
|
+
else if (zodRef._def.unknownKeys === 'passthrough')
|
|
855
896
|
additionalProperties = true;
|
|
856
|
-
else if (zodRef._def.unknownKeys ===
|
|
857
|
-
additionalProperties =
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
).filter((key) => {
|
|
897
|
+
else if (zodRef._def.unknownKeys === 'strict') additionalProperties = false;
|
|
898
|
+
additionalProperties =
|
|
899
|
+
additionalProperties != null ? { additionalProperties } : {};
|
|
900
|
+
const requiredProperties = Object.keys(zodRef.shape).filter((key) => {
|
|
861
901
|
const item = zodRef.shape[key];
|
|
862
|
-
return
|
|
902
|
+
return (
|
|
903
|
+
!(
|
|
904
|
+
item.isOptional() ||
|
|
905
|
+
item instanceof z.ZodDefault ||
|
|
906
|
+
item._def.typeName === 'ZodDefault'
|
|
907
|
+
) && !(item instanceof z.ZodNever || item._def.typeName === 'ZodDefault')
|
|
908
|
+
);
|
|
863
909
|
});
|
|
864
|
-
const required =
|
|
910
|
+
const required =
|
|
911
|
+
requiredProperties.length > 0 ? { required: requiredProperties } : {};
|
|
865
912
|
return merge(
|
|
866
913
|
{
|
|
867
|
-
type: typeFormat(
|
|
914
|
+
type: typeFormat('object', openApiVersion),
|
|
868
915
|
properties: iterateZodObject({
|
|
869
916
|
zodRef,
|
|
870
917
|
schemas,
|
|
@@ -876,110 +923,83 @@ function parseObject({
|
|
|
876
923
|
...additionalProperties,
|
|
877
924
|
...hideDefinitions
|
|
878
925
|
},
|
|
879
|
-
zodRef.description
|
|
926
|
+
zodRef.description
|
|
927
|
+
? { description: zodRef.description, hideDefinitions }
|
|
928
|
+
: {},
|
|
880
929
|
...schemas
|
|
881
930
|
);
|
|
882
931
|
}
|
|
883
|
-
function parseRecord({
|
|
884
|
-
zodRef,
|
|
885
|
-
schemas,
|
|
886
|
-
useOutput,
|
|
887
|
-
openApiVersion
|
|
888
|
-
}) {
|
|
932
|
+
function parseRecord({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
889
933
|
return merge(
|
|
890
934
|
{
|
|
891
|
-
type: typeFormat(
|
|
892
|
-
additionalProperties:
|
|
935
|
+
type: typeFormat('object', openApiVersion),
|
|
936
|
+
additionalProperties:
|
|
937
|
+
zodRef._def.valueType instanceof z.ZodUnknown
|
|
938
|
+
? {}
|
|
939
|
+
: generateSchema(zodRef._def.valueType, useOutput, openApiVersion)
|
|
893
940
|
},
|
|
894
941
|
zodRef.description ? { description: zodRef.description } : {},
|
|
895
942
|
...schemas
|
|
896
943
|
);
|
|
897
944
|
}
|
|
898
|
-
function parseBigInt({
|
|
899
|
-
zodRef,
|
|
900
|
-
schemas,
|
|
901
|
-
openApiVersion
|
|
902
|
-
}) {
|
|
945
|
+
function parseBigInt({ zodRef, schemas, openApiVersion }) {
|
|
903
946
|
return merge(
|
|
904
947
|
{
|
|
905
|
-
type: typeFormat(
|
|
906
|
-
format:
|
|
948
|
+
type: typeFormat('integer', openApiVersion),
|
|
949
|
+
format: 'int64'
|
|
907
950
|
},
|
|
908
951
|
zodRef.description ? { description: zodRef.description } : {},
|
|
909
952
|
...schemas
|
|
910
953
|
);
|
|
911
954
|
}
|
|
912
|
-
function parseBoolean({
|
|
913
|
-
zodRef,
|
|
914
|
-
schemas,
|
|
915
|
-
openApiVersion
|
|
916
|
-
}) {
|
|
955
|
+
function parseBoolean({ zodRef, schemas, openApiVersion }) {
|
|
917
956
|
return merge(
|
|
918
|
-
{ type: typeFormat(
|
|
957
|
+
{ type: typeFormat('boolean', openApiVersion) },
|
|
919
958
|
zodRef.description ? { description: zodRef.description } : {},
|
|
920
959
|
...schemas
|
|
921
960
|
);
|
|
922
961
|
}
|
|
923
|
-
function parseDate({
|
|
924
|
-
zodRef,
|
|
925
|
-
schemas,
|
|
926
|
-
openApiVersion
|
|
927
|
-
}) {
|
|
962
|
+
function parseDate({ zodRef, schemas, openApiVersion }) {
|
|
928
963
|
return merge(
|
|
929
964
|
{
|
|
930
|
-
type: typeFormat(
|
|
931
|
-
format:
|
|
965
|
+
type: typeFormat('string', openApiVersion),
|
|
966
|
+
format: 'date-time'
|
|
932
967
|
},
|
|
933
968
|
zodRef.description ? { description: zodRef.description } : {},
|
|
934
969
|
...schemas
|
|
935
970
|
);
|
|
936
971
|
}
|
|
937
|
-
function parseNull({
|
|
938
|
-
zodRef,
|
|
939
|
-
schemas,
|
|
940
|
-
openApiVersion
|
|
941
|
-
}) {
|
|
972
|
+
function parseNull({ zodRef, schemas, openApiVersion }) {
|
|
942
973
|
return merge(
|
|
943
|
-
openApiVersion ===
|
|
944
|
-
type:
|
|
945
|
-
|
|
946
|
-
|
|
974
|
+
openApiVersion === '3.0'
|
|
975
|
+
? { type: 'null' }
|
|
976
|
+
: {
|
|
977
|
+
type: ['string', 'null'],
|
|
978
|
+
enum: ['null']
|
|
979
|
+
},
|
|
947
980
|
zodRef.description ? { description: zodRef.description } : {},
|
|
948
981
|
...schemas
|
|
949
982
|
);
|
|
950
983
|
}
|
|
951
|
-
function parseOptional({
|
|
952
|
-
schemas,
|
|
953
|
-
zodRef,
|
|
954
|
-
useOutput,
|
|
955
|
-
openApiVersion
|
|
956
|
-
}) {
|
|
984
|
+
function parseOptional({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
957
985
|
return merge(
|
|
958
986
|
generateSchema(zodRef.unwrap(), useOutput, openApiVersion),
|
|
959
987
|
zodRef.description ? { description: zodRef.description } : {},
|
|
960
988
|
...schemas
|
|
961
989
|
);
|
|
962
990
|
}
|
|
963
|
-
function parseNullable({
|
|
964
|
-
schemas,
|
|
965
|
-
zodRef,
|
|
966
|
-
useOutput,
|
|
967
|
-
openApiVersion
|
|
968
|
-
}) {
|
|
991
|
+
function parseNullable({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
969
992
|
const schema = generateSchema(zodRef.unwrap(), useOutput, openApiVersion);
|
|
970
993
|
return merge(
|
|
971
994
|
schema,
|
|
972
|
-
openApiVersion ===
|
|
995
|
+
openApiVersion === '3.0'
|
|
996
|
+
? { nullable: true }
|
|
997
|
+
: { type: typeFormat('null', openApiVersion) },
|
|
973
998
|
zodRef.description ? { description: zodRef.description } : {},
|
|
974
999
|
...schemas
|
|
975
1000
|
);
|
|
976
1001
|
}
|
|
977
|
-
function parseDefault({
|
|
978
|
-
schemas,
|
|
979
|
-
zodRef,
|
|
980
|
-
useOutput,
|
|
981
|
-
openApiVersion
|
|
982
|
-
}) {
|
|
1002
|
+
function parseDefault({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
983
1003
|
return merge(
|
|
984
1004
|
{
|
|
985
1005
|
default: zodRef._def.defaultValue(),
|
|
@@ -989,12 +1009,7 @@ function parseDefault({
|
|
|
989
1009
|
...schemas
|
|
990
1010
|
);
|
|
991
1011
|
}
|
|
992
|
-
function parseArray({
|
|
993
|
-
schemas,
|
|
994
|
-
zodRef,
|
|
995
|
-
useOutput,
|
|
996
|
-
openApiVersion
|
|
997
|
-
}) {
|
|
1012
|
+
function parseArray({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
998
1013
|
const constraints = {};
|
|
999
1014
|
if (zodRef._def.exactLength != null) {
|
|
1000
1015
|
constraints.minItems = zodRef._def.exactLength.value;
|
|
@@ -1006,7 +1021,7 @@ function parseArray({
|
|
|
1006
1021
|
constraints.maxItems = zodRef._def.maxLength.value;
|
|
1007
1022
|
return merge(
|
|
1008
1023
|
{
|
|
1009
|
-
type: typeFormat(
|
|
1024
|
+
type: typeFormat('array', openApiVersion),
|
|
1010
1025
|
items: generateSchema(zodRef.element, useOutput, openApiVersion),
|
|
1011
1026
|
...constraints
|
|
1012
1027
|
},
|
|
@@ -1014,11 +1029,7 @@ function parseArray({
|
|
|
1014
1029
|
...schemas
|
|
1015
1030
|
);
|
|
1016
1031
|
}
|
|
1017
|
-
function parseLiteral({
|
|
1018
|
-
schemas,
|
|
1019
|
-
zodRef,
|
|
1020
|
-
openApiVersion
|
|
1021
|
-
}) {
|
|
1032
|
+
function parseLiteral({ schemas, zodRef, openApiVersion }) {
|
|
1022
1033
|
const type22 = typeof zodRef._def.value;
|
|
1023
1034
|
return merge(
|
|
1024
1035
|
{
|
|
@@ -1029,11 +1040,7 @@ function parseLiteral({
|
|
|
1029
1040
|
...schemas
|
|
1030
1041
|
);
|
|
1031
1042
|
}
|
|
1032
|
-
function parseEnum({
|
|
1033
|
-
schemas,
|
|
1034
|
-
zodRef,
|
|
1035
|
-
openApiVersion
|
|
1036
|
-
}) {
|
|
1043
|
+
function parseEnum({ schemas, zodRef, openApiVersion }) {
|
|
1037
1044
|
const type22 = typeof Object.values(zodRef._def.values)[0];
|
|
1038
1045
|
return merge(
|
|
1039
1046
|
{
|
|
@@ -1044,12 +1051,7 @@ function parseEnum({
|
|
|
1044
1051
|
...schemas
|
|
1045
1052
|
);
|
|
1046
1053
|
}
|
|
1047
|
-
function parseIntersection({
|
|
1048
|
-
schemas,
|
|
1049
|
-
zodRef,
|
|
1050
|
-
useOutput,
|
|
1051
|
-
openApiVersion
|
|
1052
|
-
}) {
|
|
1054
|
+
function parseIntersection({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1053
1055
|
return merge(
|
|
1054
1056
|
{
|
|
1055
1057
|
allOf: [
|
|
@@ -1061,20 +1063,20 @@ function parseIntersection({
|
|
|
1061
1063
|
...schemas
|
|
1062
1064
|
);
|
|
1063
1065
|
}
|
|
1064
|
-
function parseUnion({
|
|
1065
|
-
schemas,
|
|
1066
|
-
zodRef,
|
|
1067
|
-
useOutput,
|
|
1068
|
-
openApiVersion
|
|
1069
|
-
}) {
|
|
1066
|
+
function parseUnion({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1070
1067
|
const contents = zodRef._def.options;
|
|
1071
|
-
if (
|
|
1072
|
-
(
|
|
1073
|
-
|
|
1074
|
-
|
|
1068
|
+
if (
|
|
1069
|
+
contents.reduce(
|
|
1070
|
+
(prev, content) => prev && content._def.typeName === 'ZodLiteral',
|
|
1071
|
+
true
|
|
1072
|
+
)
|
|
1073
|
+
) {
|
|
1075
1074
|
const literals = contents;
|
|
1076
1075
|
const type22 = literals.reduce(
|
|
1077
|
-
(prev, content) =>
|
|
1076
|
+
(prev, content) =>
|
|
1077
|
+
!prev || prev === typeof content._def.value
|
|
1078
|
+
? typeof content._def.value
|
|
1079
|
+
: null,
|
|
1078
1080
|
null
|
|
1079
1081
|
);
|
|
1080
1082
|
if (type22) {
|
|
@@ -1088,12 +1090,15 @@ function parseUnion({
|
|
|
1088
1090
|
);
|
|
1089
1091
|
}
|
|
1090
1092
|
}
|
|
1091
|
-
const oneOfContents =
|
|
1093
|
+
const oneOfContents =
|
|
1094
|
+
openApiVersion === '3.0'
|
|
1095
|
+
? contents.filter((content) => content._def.typeName !== 'ZodNull')
|
|
1096
|
+
: contents;
|
|
1092
1097
|
const contentsHasNull = contents.length != oneOfContents.length;
|
|
1093
1098
|
return merge(
|
|
1094
1099
|
{
|
|
1095
|
-
oneOf: oneOfContents.map(
|
|
1096
|
-
|
|
1100
|
+
oneOf: oneOfContents.map((schema) =>
|
|
1101
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1097
1102
|
)
|
|
1098
1103
|
},
|
|
1099
1104
|
contentsHasNull ? { nullable: true } : {},
|
|
@@ -1112,50 +1117,34 @@ function parseDiscriminatedUnion({
|
|
|
1112
1117
|
discriminator: {
|
|
1113
1118
|
propertyName: zodRef._def.discriminator
|
|
1114
1119
|
},
|
|
1115
|
-
oneOf: Array.from(
|
|
1116
|
-
|
|
1117
|
-
)
|
|
1120
|
+
oneOf: Array.from(zodRef._def.options.values()).map((schema) =>
|
|
1121
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1122
|
+
)
|
|
1118
1123
|
},
|
|
1119
1124
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1120
1125
|
...schemas
|
|
1121
1126
|
);
|
|
1122
1127
|
}
|
|
1123
|
-
function parseNever({
|
|
1124
|
-
zodRef,
|
|
1125
|
-
schemas
|
|
1126
|
-
}) {
|
|
1128
|
+
function parseNever({ zodRef, schemas }) {
|
|
1127
1129
|
return merge(
|
|
1128
1130
|
{ readOnly: true },
|
|
1129
1131
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1130
1132
|
...schemas
|
|
1131
1133
|
);
|
|
1132
1134
|
}
|
|
1133
|
-
function parseBranded({
|
|
1134
|
-
schemas,
|
|
1135
|
-
zodRef,
|
|
1136
|
-
useOutput,
|
|
1137
|
-
openApiVersion
|
|
1138
|
-
}) {
|
|
1135
|
+
function parseBranded({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1139
1136
|
return merge(
|
|
1140
1137
|
generateSchema(zodRef._def.type, useOutput, openApiVersion),
|
|
1141
1138
|
...schemas
|
|
1142
1139
|
);
|
|
1143
1140
|
}
|
|
1144
|
-
function catchAllParser({
|
|
1145
|
-
zodRef,
|
|
1146
|
-
schemas
|
|
1147
|
-
}) {
|
|
1141
|
+
function catchAllParser({ zodRef, schemas }) {
|
|
1148
1142
|
return merge(
|
|
1149
1143
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1150
1144
|
...schemas
|
|
1151
1145
|
);
|
|
1152
1146
|
}
|
|
1153
|
-
function parsePipeline({
|
|
1154
|
-
schemas,
|
|
1155
|
-
zodRef,
|
|
1156
|
-
useOutput,
|
|
1157
|
-
openApiVersion
|
|
1158
|
-
}) {
|
|
1147
|
+
function parsePipeline({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1159
1148
|
return merge(
|
|
1160
1149
|
generateSchema(
|
|
1161
1150
|
useOutput ? zodRef._def.out : zodRef._def.in,
|
|
@@ -1165,12 +1154,7 @@ function parsePipeline({
|
|
|
1165
1154
|
...schemas
|
|
1166
1155
|
);
|
|
1167
1156
|
}
|
|
1168
|
-
function parseReadonly({
|
|
1169
|
-
zodRef,
|
|
1170
|
-
useOutput,
|
|
1171
|
-
schemas,
|
|
1172
|
-
openApiVersion
|
|
1173
|
-
}) {
|
|
1157
|
+
function parseReadonly({ zodRef, useOutput, schemas, openApiVersion }) {
|
|
1174
1158
|
return merge(
|
|
1175
1159
|
generateSchema(zodRef._def.innerType, useOutput, openApiVersion),
|
|
1176
1160
|
zodRef.description ? { description: zodRef.description } : {},
|
|
@@ -1214,10 +1198,10 @@ var workerMap = {
|
|
|
1214
1198
|
ZodPipeline: parsePipeline,
|
|
1215
1199
|
ZodReadonly: parseReadonly
|
|
1216
1200
|
};
|
|
1217
|
-
function generateSchema(zodRef, useOutput = false, openApiVersion =
|
|
1201
|
+
function generateSchema(zodRef, useOutput = false, openApiVersion = '3.1') {
|
|
1218
1202
|
const { metaOpenApi = {} } = zodRef;
|
|
1219
1203
|
const schemas = [
|
|
1220
|
-
...Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi]
|
|
1204
|
+
...(Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi])
|
|
1221
1205
|
];
|
|
1222
1206
|
try {
|
|
1223
1207
|
const typeName = zodRef._def.typeName;
|
|
@@ -1236,155 +1220,173 @@ function generateSchema(zodRef, useOutput = false, openApiVersion = "3.1") {
|
|
|
1236
1220
|
}
|
|
1237
1221
|
}
|
|
1238
1222
|
function extendZodWithOpenApi(zod, forceOverride = false) {
|
|
1239
|
-
if (
|
|
1223
|
+
if (
|
|
1224
|
+
!forceOverride &&
|
|
1225
|
+
typeof zod.ZodSchema.prototype.openapi !== 'undefined'
|
|
1226
|
+
) {
|
|
1240
1227
|
return;
|
|
1241
1228
|
}
|
|
1242
|
-
zod.ZodSchema.prototype.openapi = function(metadata) {
|
|
1229
|
+
zod.ZodSchema.prototype.openapi = function (metadata) {
|
|
1243
1230
|
return extendApi(this, metadata);
|
|
1244
1231
|
};
|
|
1245
1232
|
}
|
|
1246
1233
|
extendZodWithOpenApi(z2);
|
|
1247
1234
|
var ZodSchemaValidator = class {
|
|
1248
|
-
_Type =
|
|
1235
|
+
_Type = 'Zod';
|
|
1249
1236
|
_SchemaCatchall;
|
|
1250
1237
|
_ValidSchemaObject;
|
|
1251
1238
|
string = z2.string().openapi({
|
|
1252
|
-
title:
|
|
1253
|
-
example:
|
|
1239
|
+
title: 'String',
|
|
1240
|
+
example: 'a string'
|
|
1254
1241
|
});
|
|
1255
1242
|
uuid = z2.string().uuid().openapi({
|
|
1256
|
-
title:
|
|
1257
|
-
format:
|
|
1258
|
-
pattern:
|
|
1259
|
-
|
|
1243
|
+
title: 'UUID',
|
|
1244
|
+
format: 'uuid',
|
|
1245
|
+
pattern:
|
|
1246
|
+
'^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$',
|
|
1247
|
+
example: 'a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6'
|
|
1260
1248
|
});
|
|
1261
1249
|
email = z2.string().email().openapi({
|
|
1262
|
-
title:
|
|
1263
|
-
format:
|
|
1264
|
-
pattern:
|
|
1265
|
-
example:
|
|
1250
|
+
title: 'Email',
|
|
1251
|
+
format: 'email',
|
|
1252
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
1253
|
+
example: 'a@b.com'
|
|
1266
1254
|
});
|
|
1267
1255
|
uri = z2.string().url().openapi({
|
|
1268
|
-
title:
|
|
1269
|
-
format:
|
|
1270
|
-
pattern:
|
|
1271
|
-
example:
|
|
1256
|
+
title: 'URI',
|
|
1257
|
+
format: 'uri',
|
|
1258
|
+
pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
|
|
1259
|
+
example: 'https://forklaunch.com'
|
|
1272
1260
|
});
|
|
1273
|
-
number = z2
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}, z2.number()).openapi({
|
|
1280
|
-
title: "Number",
|
|
1281
|
-
example: 123
|
|
1282
|
-
});
|
|
1283
|
-
bigint = z2.preprocess((value) => {
|
|
1284
|
-
try {
|
|
1285
|
-
if (value instanceof Date) {
|
|
1286
|
-
return BigInt(value.getTime());
|
|
1261
|
+
number = z2
|
|
1262
|
+
.preprocess((value) => {
|
|
1263
|
+
try {
|
|
1264
|
+
return Number(value);
|
|
1265
|
+
} catch {
|
|
1266
|
+
return value;
|
|
1287
1267
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1268
|
+
}, z2.number())
|
|
1269
|
+
.openapi({
|
|
1270
|
+
title: 'Number',
|
|
1271
|
+
example: 123
|
|
1272
|
+
});
|
|
1273
|
+
bigint = z2
|
|
1274
|
+
.preprocess((value) => {
|
|
1275
|
+
try {
|
|
1276
|
+
if (value instanceof Date) {
|
|
1277
|
+
return BigInt(value.getTime());
|
|
1278
|
+
}
|
|
1279
|
+
switch (typeof value) {
|
|
1280
|
+
case 'number':
|
|
1281
|
+
case 'string':
|
|
1282
|
+
return BigInt(value);
|
|
1283
|
+
case 'boolean':
|
|
1284
|
+
return BigInt(value ? 1 : 0);
|
|
1285
|
+
default:
|
|
1286
|
+
return value;
|
|
1287
|
+
}
|
|
1288
|
+
} catch {
|
|
1289
|
+
return value;
|
|
1296
1290
|
}
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
if (val.toLowerCase() === "false") return false;
|
|
1310
|
-
}
|
|
1311
|
-
return val;
|
|
1312
|
-
}, z2.boolean()).openapi({
|
|
1313
|
-
title: "Boolean",
|
|
1314
|
-
example: true
|
|
1315
|
-
});
|
|
1316
|
-
date = z2.preprocess((value) => {
|
|
1317
|
-
try {
|
|
1318
|
-
switch (typeof value) {
|
|
1319
|
-
case "string":
|
|
1320
|
-
return new Date(value);
|
|
1321
|
-
case "number":
|
|
1322
|
-
return new Date(value);
|
|
1323
|
-
default:
|
|
1324
|
-
return value;
|
|
1291
|
+
}, z2.bigint())
|
|
1292
|
+
.openapi({
|
|
1293
|
+
title: 'BigInt',
|
|
1294
|
+
type: 'integer',
|
|
1295
|
+
format: 'int64',
|
|
1296
|
+
example: 123n
|
|
1297
|
+
});
|
|
1298
|
+
boolean = z2
|
|
1299
|
+
.preprocess((val) => {
|
|
1300
|
+
if (typeof val === 'string') {
|
|
1301
|
+
if (val.toLowerCase() === 'true') return true;
|
|
1302
|
+
if (val.toLowerCase() === 'false') return false;
|
|
1325
1303
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1304
|
+
return val;
|
|
1305
|
+
}, z2.boolean())
|
|
1306
|
+
.openapi({
|
|
1307
|
+
title: 'Boolean',
|
|
1308
|
+
example: true
|
|
1309
|
+
});
|
|
1310
|
+
date = z2
|
|
1311
|
+
.preprocess((value) => {
|
|
1312
|
+
try {
|
|
1313
|
+
switch (typeof value) {
|
|
1314
|
+
case 'string':
|
|
1315
|
+
return new Date(value);
|
|
1316
|
+
case 'number':
|
|
1317
|
+
return new Date(value);
|
|
1318
|
+
default:
|
|
1319
|
+
return value;
|
|
1320
|
+
}
|
|
1321
|
+
} catch {
|
|
1322
|
+
return value;
|
|
1323
|
+
}
|
|
1324
|
+
}, z2.date())
|
|
1325
|
+
.openapi({
|
|
1326
|
+
title: 'Date',
|
|
1327
|
+
type: 'string',
|
|
1328
|
+
format: 'date-time',
|
|
1329
|
+
example: '2025-05-16T21:13:04.123Z'
|
|
1330
|
+
});
|
|
1335
1331
|
symbol = z2.symbol().openapi({
|
|
1336
|
-
title:
|
|
1337
|
-
example: Symbol(
|
|
1332
|
+
title: 'Symbol',
|
|
1333
|
+
example: Symbol('symbol')
|
|
1338
1334
|
});
|
|
1339
1335
|
nullish = z2.union([z2.void(), z2.null(), z2.undefined()]).openapi({
|
|
1340
|
-
title:
|
|
1341
|
-
type:
|
|
1336
|
+
title: 'Nullish',
|
|
1337
|
+
type: 'null',
|
|
1342
1338
|
example: null
|
|
1343
1339
|
});
|
|
1344
1340
|
void = z2.void().openapi({
|
|
1345
|
-
title:
|
|
1346
|
-
type:
|
|
1341
|
+
title: 'Void',
|
|
1342
|
+
type: 'null',
|
|
1347
1343
|
example: void 0
|
|
1348
1344
|
});
|
|
1349
1345
|
null = z2.null().openapi({
|
|
1350
|
-
title:
|
|
1351
|
-
type:
|
|
1346
|
+
title: 'Null',
|
|
1347
|
+
type: 'null',
|
|
1352
1348
|
example: null
|
|
1353
1349
|
});
|
|
1354
1350
|
undefined = z2.undefined().openapi({
|
|
1355
|
-
title:
|
|
1356
|
-
type:
|
|
1351
|
+
title: 'Undefined',
|
|
1352
|
+
type: 'null',
|
|
1357
1353
|
example: void 0
|
|
1358
1354
|
});
|
|
1359
1355
|
any = z2.any().openapi({
|
|
1360
|
-
title:
|
|
1361
|
-
type:
|
|
1362
|
-
example:
|
|
1356
|
+
title: 'Any',
|
|
1357
|
+
type: 'object',
|
|
1358
|
+
example: 'any'
|
|
1363
1359
|
});
|
|
1364
1360
|
unknown = z2.unknown().openapi({
|
|
1365
|
-
title:
|
|
1366
|
-
type:
|
|
1367
|
-
example:
|
|
1361
|
+
title: 'Unknown',
|
|
1362
|
+
type: 'object',
|
|
1363
|
+
example: 'unknown'
|
|
1368
1364
|
});
|
|
1369
1365
|
never = z2.never().openapi({
|
|
1370
|
-
title:
|
|
1371
|
-
type:
|
|
1372
|
-
example:
|
|
1373
|
-
});
|
|
1374
|
-
binary = z2.string().transform((val) => new Uint8Array(Buffer.from(val, "base64"))).openapi({
|
|
1375
|
-
title: "Binary",
|
|
1376
|
-
type: "string",
|
|
1377
|
-
format: "binary",
|
|
1378
|
-
example: "a base-64 encodable string"
|
|
1379
|
-
});
|
|
1380
|
-
file = z2.instanceof(Buffer).transform((val) => {
|
|
1381
|
-
return new Blob([val]);
|
|
1382
|
-
}).openapi({
|
|
1383
|
-
title: "File",
|
|
1384
|
-
type: "string",
|
|
1385
|
-
format: "binary",
|
|
1386
|
-
example: "a base-64 encodable blob or file"
|
|
1366
|
+
title: 'Never',
|
|
1367
|
+
type: 'null',
|
|
1368
|
+
example: 'never'
|
|
1387
1369
|
});
|
|
1370
|
+
binary = z2
|
|
1371
|
+
.string()
|
|
1372
|
+
.transform((val) => new Uint8Array(Buffer.from(val, 'base64')))
|
|
1373
|
+
.openapi({
|
|
1374
|
+
title: 'Binary',
|
|
1375
|
+
type: 'string',
|
|
1376
|
+
format: 'binary',
|
|
1377
|
+
example: 'a base-64 encodable string'
|
|
1378
|
+
});
|
|
1379
|
+
file = z2
|
|
1380
|
+
.instanceof(Buffer)
|
|
1381
|
+
.transform((val) => {
|
|
1382
|
+
return new Blob([val]);
|
|
1383
|
+
})
|
|
1384
|
+
.openapi({
|
|
1385
|
+
title: 'File',
|
|
1386
|
+
type: 'string',
|
|
1387
|
+
format: 'binary',
|
|
1388
|
+
example: 'a base-64 encodable blob or file'
|
|
1389
|
+
});
|
|
1388
1390
|
type = () => this.any;
|
|
1389
1391
|
/**
|
|
1390
1392
|
* Compiles schema if this exists, for optimal performance.
|
|
@@ -1401,7 +1403,11 @@ var ZodSchemaValidator = class {
|
|
|
1401
1403
|
* @returns {ZodResolve<T>} The resolved schema.
|
|
1402
1404
|
*/
|
|
1403
1405
|
schemify(schema) {
|
|
1404
|
-
if (
|
|
1406
|
+
if (
|
|
1407
|
+
typeof schema === 'string' ||
|
|
1408
|
+
typeof schema === 'number' ||
|
|
1409
|
+
typeof schema === 'boolean'
|
|
1410
|
+
) {
|
|
1405
1411
|
return z2.literal(schema);
|
|
1406
1412
|
}
|
|
1407
1413
|
if (schema instanceof ZodType) {
|
|
@@ -1442,9 +1448,7 @@ var ZodSchemaValidator = class {
|
|
|
1442
1448
|
*/
|
|
1443
1449
|
union(schemas) {
|
|
1444
1450
|
const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
|
|
1445
|
-
return z2.union(
|
|
1446
|
-
resolvedSchemas
|
|
1447
|
-
);
|
|
1451
|
+
return z2.union(resolvedSchemas);
|
|
1448
1452
|
}
|
|
1449
1453
|
/**
|
|
1450
1454
|
* Create a literal schema.
|
|
@@ -1460,9 +1464,7 @@ var ZodSchemaValidator = class {
|
|
|
1460
1464
|
* @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
|
|
1461
1465
|
*/
|
|
1462
1466
|
enum_(schemaEnum) {
|
|
1463
|
-
return this.union(
|
|
1464
|
-
Object.values(schemaEnum)
|
|
1465
|
-
);
|
|
1467
|
+
return this.union(Object.values(schemaEnum));
|
|
1466
1468
|
}
|
|
1467
1469
|
/**
|
|
1468
1470
|
* Create a function schema.
|
|
@@ -1531,31 +1533,33 @@ var ZodSchemaValidator = class {
|
|
|
1531
1533
|
parse(schema, value) {
|
|
1532
1534
|
const resolvedSchema = this.schemify(schema);
|
|
1533
1535
|
const result = resolvedSchema.safeParse(value);
|
|
1534
|
-
return result.success
|
|
1535
|
-
ok:
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1536
|
+
return result.success
|
|
1537
|
+
? { ok: true, value: result.data }
|
|
1538
|
+
: {
|
|
1539
|
+
ok: false,
|
|
1540
|
+
errors: result.error.errors.flatMap((error) => {
|
|
1541
|
+
switch (error.code) {
|
|
1542
|
+
case 'invalid_union':
|
|
1543
|
+
return error.unionErrors.flatMap((unionError, idx) =>
|
|
1544
|
+
unionError.errors.map((e) => ({
|
|
1545
|
+
path: [
|
|
1546
|
+
`Union Schema Variant ${idx}`,
|
|
1547
|
+
...error.path.map((p) => p.toString()),
|
|
1548
|
+
...e.path.map((p) => p.toString())
|
|
1549
|
+
],
|
|
1550
|
+
message: e.message
|
|
1551
|
+
}))
|
|
1552
|
+
);
|
|
1553
|
+
default:
|
|
1554
|
+
return [
|
|
1555
|
+
{
|
|
1556
|
+
path: error.path.map((p) => p.toString()),
|
|
1557
|
+
message: error.message
|
|
1558
|
+
}
|
|
1559
|
+
];
|
|
1560
|
+
}
|
|
1561
|
+
})
|
|
1562
|
+
};
|
|
1559
1563
|
}
|
|
1560
1564
|
/**
|
|
1561
1565
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -1612,6 +1616,4 @@ var DatabaseWorkerSchemas = serviceSchemaResolver(
|
|
|
1612
1616
|
() => DatabaseWorkerOptionsSchema,
|
|
1613
1617
|
() => DatabaseWorkerOptionsSchema2
|
|
1614
1618
|
);
|
|
1615
|
-
export {
|
|
1616
|
-
DatabaseWorkerSchemas
|
|
1617
|
-
};
|
|
1619
|
+
export { DatabaseWorkerSchemas };
|