@forklaunch/implementation-worker-redis 1.0.20 → 1.0.21
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.js +24 -15
- package/lib/consumers/index.mjs +13 -11
- package/lib/domain/schemas/index.js +641 -588
- package/lib/domain/schemas/index.mjs +599 -587
- package/lib/domain/types/index.js +8 -4
- 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/redisWorker.schema.ts
|
|
20
|
-
import { serviceSchemaResolver } from
|
|
26
|
+
import { serviceSchemaResolver } from '@forklaunch/internal';
|
|
21
27
|
|
|
22
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
28
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
|
|
23
29
|
var typebox_exports = {};
|
|
24
30
|
__export(typebox_exports, {
|
|
25
31
|
SchemaValidator: () => SchemaValidator,
|
|
@@ -58,14 +64,14 @@ __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@1.2.
|
|
69
|
+
// ../../../node_modules/.pnpm/@forklaunch+common@1.2.12/node_modules/@forklaunch/common/lib/index.mjs
|
|
64
70
|
function deepCloneWithoutUndefined(obj, seen = /* @__PURE__ */ new WeakMap()) {
|
|
65
71
|
if (obj === null || obj === void 0) {
|
|
66
72
|
return obj;
|
|
67
73
|
}
|
|
68
|
-
if (typeof obj !==
|
|
74
|
+
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
|
69
75
|
return obj;
|
|
70
76
|
}
|
|
71
77
|
if (seen.has(obj)) {
|
|
@@ -107,7 +113,7 @@ function deepCloneWithoutUndefined(obj, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
107
113
|
}
|
|
108
114
|
return clonedArray;
|
|
109
115
|
}
|
|
110
|
-
if (typeof obj ===
|
|
116
|
+
if (typeof obj === 'function') {
|
|
111
117
|
return obj;
|
|
112
118
|
}
|
|
113
119
|
const proto = Object.getPrototypeOf(obj);
|
|
@@ -120,7 +126,7 @@ function deepCloneWithoutUndefined(obj, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
120
126
|
for (const key of allKeys) {
|
|
121
127
|
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
122
128
|
if (!descriptor) continue;
|
|
123
|
-
if (
|
|
129
|
+
if ('value' in descriptor) {
|
|
124
130
|
if (descriptor.value !== void 0) {
|
|
125
131
|
Object.defineProperty(cloned, key, {
|
|
126
132
|
...descriptor,
|
|
@@ -140,263 +146,276 @@ var InMemoryBlob = class extends Blob {
|
|
|
140
146
|
}
|
|
141
147
|
};
|
|
142
148
|
|
|
143
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
149
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
|
|
144
150
|
import {
|
|
145
151
|
FormatRegistry,
|
|
146
152
|
Kind,
|
|
147
153
|
KindGuard,
|
|
148
154
|
Type,
|
|
149
155
|
TypeRegistry
|
|
150
|
-
} from
|
|
151
|
-
import { TypeCheck, TypeCompiler } from
|
|
156
|
+
} from '@sinclair/typebox';
|
|
157
|
+
import { TypeCheck, TypeCompiler } from '@sinclair/typebox/compiler';
|
|
152
158
|
import {
|
|
153
159
|
DefaultErrorFunction,
|
|
154
160
|
SetErrorFunction,
|
|
155
161
|
ValueErrorType
|
|
156
|
-
} from
|
|
157
|
-
import { Value } from
|
|
158
|
-
FormatRegistry.Set(
|
|
159
|
-
TypeRegistry.Set(
|
|
162
|
+
} from '@sinclair/typebox/errors';
|
|
163
|
+
import { Value } from '@sinclair/typebox/value';
|
|
164
|
+
FormatRegistry.Set('binary', (value) => typeof value === 'string');
|
|
165
|
+
TypeRegistry.Set('Blob', (_schema, value) => value instanceof Blob);
|
|
160
166
|
TypeRegistry.Set(
|
|
161
|
-
|
|
167
|
+
'ArrayBuffer',
|
|
162
168
|
(_schema, value) => value instanceof ArrayBuffer
|
|
163
169
|
);
|
|
164
|
-
TypeRegistry.Set(
|
|
170
|
+
TypeRegistry.Set('Buffer', (_schema, value) => value instanceof Buffer);
|
|
165
171
|
SetErrorFunction((params) => {
|
|
166
172
|
switch (params.errorType) {
|
|
167
173
|
case ValueErrorType.Union:
|
|
168
174
|
case ValueErrorType.Array:
|
|
169
175
|
case ValueErrorType.String:
|
|
170
176
|
case ValueErrorType.Number:
|
|
171
|
-
return params.schema.errorType
|
|
177
|
+
return params.schema.errorType
|
|
178
|
+
? `Expected ${params.schema.errorType} value${params.schema.errorSuffix ? 's' : ''}`
|
|
179
|
+
: DefaultErrorFunction(params);
|
|
172
180
|
default:
|
|
173
181
|
return DefaultErrorFunction(params);
|
|
174
182
|
}
|
|
175
183
|
});
|
|
176
184
|
var TypeboxSchemaValidator = class {
|
|
177
|
-
_Type =
|
|
185
|
+
_Type = 'TypeBox';
|
|
178
186
|
_SchemaCatchall;
|
|
179
187
|
_ValidSchemaObject;
|
|
180
188
|
string = Type.String({
|
|
181
|
-
example:
|
|
182
|
-
title:
|
|
189
|
+
example: 'a string',
|
|
190
|
+
title: 'String'
|
|
183
191
|
});
|
|
184
192
|
uuid = Type.String({
|
|
185
|
-
pattern:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
pattern:
|
|
194
|
+
'^[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}$',
|
|
195
|
+
errorType: 'uuid',
|
|
196
|
+
example: 'a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
|
|
197
|
+
title: 'UUID'
|
|
189
198
|
});
|
|
190
199
|
email = Type.String({
|
|
191
|
-
pattern:
|
|
192
|
-
errorType:
|
|
193
|
-
example:
|
|
194
|
-
title:
|
|
200
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
201
|
+
errorType: 'email',
|
|
202
|
+
example: 'a@b.com',
|
|
203
|
+
title: 'Email'
|
|
195
204
|
});
|
|
196
205
|
uri = Type.String({
|
|
197
|
-
pattern:
|
|
198
|
-
errorType:
|
|
199
|
-
example:
|
|
200
|
-
title:
|
|
206
|
+
pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
|
|
207
|
+
errorType: 'uri',
|
|
208
|
+
example: 'https://forklaunch.com',
|
|
209
|
+
title: 'URI'
|
|
201
210
|
});
|
|
202
211
|
number = Type.Transform(
|
|
203
212
|
Type.Union(
|
|
204
213
|
[
|
|
205
214
|
Type.Number(),
|
|
206
|
-
Type.String({ pattern:
|
|
215
|
+
Type.String({ pattern: '^[0-9]+$' }),
|
|
207
216
|
Type.Boolean(),
|
|
208
217
|
Type.Null(),
|
|
209
218
|
Type.BigInt(),
|
|
210
219
|
Type.Date()
|
|
211
220
|
],
|
|
212
221
|
{
|
|
213
|
-
errorType:
|
|
222
|
+
errorType: 'number-like',
|
|
214
223
|
example: 123,
|
|
215
|
-
title:
|
|
224
|
+
title: 'Number'
|
|
216
225
|
}
|
|
217
226
|
)
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
227
|
+
)
|
|
228
|
+
.Decode((value) => {
|
|
229
|
+
if (typeof value !== 'number') {
|
|
230
|
+
const num = Number(value);
|
|
231
|
+
if (isNaN(num)) {
|
|
232
|
+
throw new Error('Invalid number');
|
|
233
|
+
} else {
|
|
234
|
+
return num;
|
|
235
|
+
}
|
|
225
236
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
237
|
+
return value;
|
|
238
|
+
})
|
|
239
|
+
.Encode(Number);
|
|
229
240
|
bigint = Type.Transform(
|
|
230
241
|
Type.Union(
|
|
231
242
|
[
|
|
232
243
|
Type.BigInt(),
|
|
233
244
|
Type.Number(),
|
|
234
|
-
Type.String({ pattern:
|
|
245
|
+
Type.String({ pattern: '^[0-9]+n?$' }),
|
|
235
246
|
Type.Boolean(),
|
|
236
247
|
Type.Date()
|
|
237
248
|
],
|
|
238
249
|
{
|
|
239
|
-
errorType:
|
|
250
|
+
errorType: 'BigInt-like',
|
|
240
251
|
example: 123n,
|
|
241
|
-
title:
|
|
252
|
+
title: 'BigInt'
|
|
242
253
|
}
|
|
243
254
|
)
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
255
|
+
)
|
|
256
|
+
.Decode((value) => {
|
|
257
|
+
if (typeof value !== 'bigint') {
|
|
258
|
+
try {
|
|
259
|
+
if (value instanceof Date) {
|
|
260
|
+
return BigInt(value.getTime());
|
|
261
|
+
}
|
|
262
|
+
return BigInt(value);
|
|
263
|
+
} catch {
|
|
264
|
+
throw new Error('Invalid bigint');
|
|
249
265
|
}
|
|
250
|
-
return BigInt(value);
|
|
251
|
-
} catch {
|
|
252
|
-
throw new Error("Invalid bigint");
|
|
253
266
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
return value;
|
|
268
|
+
})
|
|
269
|
+
.Encode(BigInt);
|
|
257
270
|
boolean = Type.Transform(
|
|
258
271
|
Type.Union(
|
|
259
272
|
[
|
|
260
273
|
Type.Boolean(),
|
|
261
274
|
Type.String({
|
|
262
|
-
pattern:
|
|
275
|
+
pattern: '^(t|T)(r|R)(u|U)(e|E)$|^(f|F)(a|A)(l|L)(s|S)(e|E)$'
|
|
263
276
|
})
|
|
264
277
|
],
|
|
265
278
|
{
|
|
266
|
-
errorType:
|
|
279
|
+
errorType: 'boolean-like',
|
|
267
280
|
example: true,
|
|
268
|
-
title:
|
|
281
|
+
title: 'Boolean'
|
|
269
282
|
}
|
|
270
283
|
)
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
if (value
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
284
|
+
)
|
|
285
|
+
.Decode((value) => {
|
|
286
|
+
if (typeof value === 'string') {
|
|
287
|
+
if (value.toLowerCase() === 'true') return true;
|
|
288
|
+
return false;
|
|
289
|
+
} else {
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
.Encode(Boolean);
|
|
279
294
|
date = Type.Transform(
|
|
280
295
|
Type.Union(
|
|
281
296
|
[
|
|
282
297
|
Type.String({
|
|
283
|
-
pattern:
|
|
298
|
+
pattern:
|
|
299
|
+
'^\\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+$'
|
|
284
300
|
}),
|
|
285
301
|
Type.Number(),
|
|
286
302
|
Type.Date()
|
|
287
303
|
],
|
|
288
304
|
{
|
|
289
|
-
errorType:
|
|
290
|
-
example:
|
|
291
|
-
title:
|
|
305
|
+
errorType: 'date',
|
|
306
|
+
example: '2025-05-16T21:13:04.123Z',
|
|
307
|
+
title: 'Date'
|
|
292
308
|
}
|
|
293
309
|
)
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
)
|
|
311
|
+
.Decode((value) => {
|
|
312
|
+
if (value === null || typeof value === 'boolean') {
|
|
313
|
+
return /* @__PURE__ */ new Date(value ? 1 : 0);
|
|
314
|
+
}
|
|
315
|
+
return new Date(value);
|
|
316
|
+
})
|
|
317
|
+
.Encode((value) => new Date(value).toISOString());
|
|
300
318
|
symbol = Type.Symbol({
|
|
301
|
-
title:
|
|
319
|
+
title: 'Symbol'
|
|
320
|
+
});
|
|
321
|
+
nullish = Type.Union([Type.Void(), Type.Null(), Type.Undefined()], {
|
|
322
|
+
errorType: 'nullish',
|
|
323
|
+
type: 'null',
|
|
324
|
+
example: 'null',
|
|
325
|
+
title: 'Nullish'
|
|
302
326
|
});
|
|
303
|
-
nullish = Type.Union(
|
|
304
|
-
[Type.Void(), Type.Null(), Type.Undefined()],
|
|
305
|
-
{
|
|
306
|
-
errorType: "nullish",
|
|
307
|
-
type: "null",
|
|
308
|
-
example: "null",
|
|
309
|
-
title: "Nullish"
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
327
|
void = Type.Void({
|
|
313
|
-
type:
|
|
314
|
-
example:
|
|
315
|
-
title:
|
|
328
|
+
type: 'null',
|
|
329
|
+
example: 'void',
|
|
330
|
+
title: 'Void'
|
|
316
331
|
});
|
|
317
332
|
null = Type.Null({
|
|
318
|
-
type:
|
|
319
|
-
example:
|
|
320
|
-
title:
|
|
333
|
+
type: 'null',
|
|
334
|
+
example: 'null',
|
|
335
|
+
title: 'Null'
|
|
321
336
|
});
|
|
322
337
|
undefined = Type.Undefined({
|
|
323
|
-
type:
|
|
324
|
-
example:
|
|
325
|
-
title:
|
|
338
|
+
type: 'null',
|
|
339
|
+
example: 'undefined',
|
|
340
|
+
title: 'Undefined'
|
|
326
341
|
});
|
|
327
342
|
any = Type.Any({
|
|
328
|
-
type:
|
|
329
|
-
example:
|
|
330
|
-
title:
|
|
343
|
+
type: 'object',
|
|
344
|
+
example: 'any',
|
|
345
|
+
title: 'Any'
|
|
331
346
|
});
|
|
332
347
|
unknown = Type.Unknown({
|
|
333
|
-
type:
|
|
334
|
-
example:
|
|
335
|
-
title:
|
|
348
|
+
type: 'object',
|
|
349
|
+
example: 'unknown',
|
|
350
|
+
title: 'Unknown'
|
|
336
351
|
});
|
|
337
352
|
never = Type.Never({
|
|
338
|
-
type:
|
|
339
|
-
example:
|
|
340
|
-
title:
|
|
353
|
+
type: 'null',
|
|
354
|
+
example: 'never',
|
|
355
|
+
title: 'Never'
|
|
341
356
|
});
|
|
342
357
|
binary = Type.Transform(
|
|
343
358
|
Type.String({
|
|
344
|
-
errorType:
|
|
345
|
-
format:
|
|
346
|
-
example:
|
|
347
|
-
title:
|
|
359
|
+
errorType: 'binary',
|
|
360
|
+
format: 'binary',
|
|
361
|
+
example: 'a base-64 encodable string',
|
|
362
|
+
title: 'Binary'
|
|
348
363
|
})
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
)
|
|
365
|
+
.Decode((value) => new Uint8Array(Buffer.from(value, 'base64')))
|
|
366
|
+
.Encode((value) => {
|
|
367
|
+
if (value instanceof Buffer) {
|
|
368
|
+
return String.fromCharCode(...new Uint8Array(value));
|
|
369
|
+
}
|
|
370
|
+
return '';
|
|
371
|
+
});
|
|
355
372
|
file = Type.Transform(
|
|
356
373
|
Type.Union([
|
|
357
374
|
Type.Unsafe({
|
|
358
|
-
[Kind]:
|
|
359
|
-
errorType:
|
|
360
|
-
format:
|
|
361
|
-
example:
|
|
362
|
-
title:
|
|
375
|
+
[Kind]: 'Buffer',
|
|
376
|
+
errorType: 'binary',
|
|
377
|
+
format: 'binary',
|
|
378
|
+
example: 'a raw buffer or file stream',
|
|
379
|
+
title: 'File'
|
|
363
380
|
}),
|
|
364
381
|
Type.Unsafe({
|
|
365
|
-
[Kind]:
|
|
366
|
-
errorType:
|
|
367
|
-
format:
|
|
368
|
-
example:
|
|
369
|
-
title:
|
|
382
|
+
[Kind]: 'ArrayBuffer',
|
|
383
|
+
errorType: 'binary',
|
|
384
|
+
format: 'binary',
|
|
385
|
+
example: 'an array buffer',
|
|
386
|
+
title: 'File'
|
|
370
387
|
}),
|
|
371
388
|
Type.Unsafe({
|
|
372
|
-
[Kind]:
|
|
373
|
-
errorType:
|
|
374
|
-
format:
|
|
375
|
-
example:
|
|
376
|
-
title:
|
|
389
|
+
[Kind]: 'Blob',
|
|
390
|
+
errorType: 'binary',
|
|
391
|
+
format: 'binary',
|
|
392
|
+
example: 'a blob object',
|
|
393
|
+
title: 'File'
|
|
377
394
|
}),
|
|
378
395
|
Type.String({
|
|
379
|
-
errorType:
|
|
380
|
-
format:
|
|
381
|
-
example:
|
|
382
|
-
title:
|
|
396
|
+
errorType: 'binary',
|
|
397
|
+
format: 'binary',
|
|
398
|
+
example: 'a string content',
|
|
399
|
+
title: 'File'
|
|
383
400
|
})
|
|
384
401
|
])
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
)
|
|
403
|
+
.Decode((value) => {
|
|
404
|
+
if (value instanceof Buffer) {
|
|
405
|
+
return new InMemoryBlob(value);
|
|
406
|
+
}
|
|
407
|
+
if (value instanceof ArrayBuffer) {
|
|
408
|
+
return new InMemoryBlob(Buffer.from(value));
|
|
409
|
+
}
|
|
410
|
+
if (value instanceof Blob) {
|
|
411
|
+
return value;
|
|
412
|
+
}
|
|
413
|
+
if (typeof value === 'string') {
|
|
414
|
+
return new InMemoryBlob(Buffer.from(value));
|
|
415
|
+
}
|
|
396
416
|
return new InMemoryBlob(Buffer.from(value));
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
}).Encode((value) => value.content);
|
|
417
|
+
})
|
|
418
|
+
.Encode((value) => value.content);
|
|
400
419
|
type = () => this.any;
|
|
401
420
|
/**
|
|
402
421
|
* Extracts the error type of a schema for error messages.
|
|
@@ -405,7 +424,7 @@ var TypeboxSchemaValidator = class {
|
|
|
405
424
|
* @returns The type of the schema for error messages.
|
|
406
425
|
*/
|
|
407
426
|
errorType(schema) {
|
|
408
|
-
if (KindGuard.IsSchema(schema) && Object.hasOwn(schema,
|
|
427
|
+
if (KindGuard.IsSchema(schema) && Object.hasOwn(schema, 'errorType')) {
|
|
409
428
|
return schema.errorType;
|
|
410
429
|
} else if (KindGuard.IsLiteral(schema)) {
|
|
411
430
|
return schema.const;
|
|
@@ -427,7 +446,11 @@ var TypeboxSchemaValidator = class {
|
|
|
427
446
|
* @returns {TResolve<T>} The resolved schema.
|
|
428
447
|
*/
|
|
429
448
|
schemify(schema) {
|
|
430
|
-
if (
|
|
449
|
+
if (
|
|
450
|
+
typeof schema === 'string' ||
|
|
451
|
+
typeof schema === 'number' ||
|
|
452
|
+
typeof schema === 'boolean'
|
|
453
|
+
) {
|
|
431
454
|
return Type.Literal(schema);
|
|
432
455
|
}
|
|
433
456
|
if (KindGuard.IsSchema(schema) || schema instanceof TypeCheck) {
|
|
@@ -435,7 +458,10 @@ var TypeboxSchemaValidator = class {
|
|
|
435
458
|
}
|
|
436
459
|
const newSchema = {};
|
|
437
460
|
Object.getOwnPropertyNames(schema).forEach((key) => {
|
|
438
|
-
if (
|
|
461
|
+
if (
|
|
462
|
+
KindGuard.IsSchema(schema[key]) ||
|
|
463
|
+
KindGuard.IsTransform(schema[key])
|
|
464
|
+
) {
|
|
439
465
|
newSchema[key] = schema[key];
|
|
440
466
|
} else {
|
|
441
467
|
const schemified = this.schemify(schema[key]);
|
|
@@ -477,7 +503,7 @@ var TypeboxSchemaValidator = class {
|
|
|
477
503
|
return this.schemify(schema);
|
|
478
504
|
});
|
|
479
505
|
return Type.Union(unionTypes, {
|
|
480
|
-
errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(
|
|
506
|
+
errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(', ')}`,
|
|
481
507
|
errorSuffix: true
|
|
482
508
|
});
|
|
483
509
|
}
|
|
@@ -548,7 +574,12 @@ var TypeboxSchemaValidator = class {
|
|
|
548
574
|
* @returns {boolean} True if the value is an instance of the schema.
|
|
549
575
|
*/
|
|
550
576
|
isInstanceOf(value, type22) {
|
|
551
|
-
return
|
|
577
|
+
return (
|
|
578
|
+
typeof value === 'object' &&
|
|
579
|
+
value != null &&
|
|
580
|
+
Kind in value &&
|
|
581
|
+
value[Kind] === type22[Kind]
|
|
582
|
+
);
|
|
552
583
|
}
|
|
553
584
|
/**
|
|
554
585
|
* Validate a value against a schema.
|
|
@@ -583,7 +614,7 @@ var TypeboxSchemaValidator = class {
|
|
|
583
614
|
}
|
|
584
615
|
} else {
|
|
585
616
|
const schemified = this.schemify(schema);
|
|
586
|
-
if (schemified[Kind] ===
|
|
617
|
+
if (schemified[Kind] === 'Unsafe') {
|
|
587
618
|
try {
|
|
588
619
|
if (value instanceof Buffer) {
|
|
589
620
|
conversion = new InMemoryBlob(value);
|
|
@@ -592,7 +623,7 @@ var TypeboxSchemaValidator = class {
|
|
|
592
623
|
{
|
|
593
624
|
type: ValueErrorType.String,
|
|
594
625
|
schema: schemified,
|
|
595
|
-
path:
|
|
626
|
+
path: '',
|
|
596
627
|
message: `Invalid file type: expected Buffer or string, got ${typeof value}`,
|
|
597
628
|
value,
|
|
598
629
|
errors: []
|
|
@@ -604,8 +635,8 @@ var TypeboxSchemaValidator = class {
|
|
|
604
635
|
{
|
|
605
636
|
type: ValueErrorType.String,
|
|
606
637
|
schema: schemified,
|
|
607
|
-
path:
|
|
608
|
-
message: err instanceof Error ? err.message :
|
|
638
|
+
path: '',
|
|
639
|
+
message: err instanceof Error ? err.message : 'Invalid file type',
|
|
609
640
|
value,
|
|
610
641
|
errors: []
|
|
611
642
|
}
|
|
@@ -619,33 +650,38 @@ var TypeboxSchemaValidator = class {
|
|
|
619
650
|
}
|
|
620
651
|
}
|
|
621
652
|
}
|
|
622
|
-
return errors != null && errors.length === 0
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
ok: false,
|
|
627
|
-
errors: errors.flatMap((error) => {
|
|
628
|
-
if (error.type === ValueErrorType.Union && error.schema.errorType?.includes("any of")) {
|
|
629
|
-
return error.errors.flatMap(
|
|
630
|
-
(e, idx) => Array.from(e).map((e2) => ({
|
|
631
|
-
path: [
|
|
632
|
-
`Union Schema Variant ${idx}`,
|
|
633
|
-
...error.path.split("/").slice(1),
|
|
634
|
-
...e2.path.split("/").slice(1)
|
|
635
|
-
],
|
|
636
|
-
message: e2.message
|
|
637
|
-
}))
|
|
638
|
-
);
|
|
639
|
-
} else {
|
|
640
|
-
return [
|
|
641
|
-
{
|
|
642
|
-
path: error.path.split("/").slice(1),
|
|
643
|
-
message: error.message
|
|
644
|
-
}
|
|
645
|
-
];
|
|
653
|
+
return errors != null && errors.length === 0
|
|
654
|
+
? {
|
|
655
|
+
ok: true,
|
|
656
|
+
value: conversion
|
|
646
657
|
}
|
|
647
|
-
|
|
648
|
-
|
|
658
|
+
: {
|
|
659
|
+
ok: false,
|
|
660
|
+
errors: errors.flatMap((error) => {
|
|
661
|
+
if (
|
|
662
|
+
error.type === ValueErrorType.Union &&
|
|
663
|
+
error.schema.errorType?.includes('any of')
|
|
664
|
+
) {
|
|
665
|
+
return error.errors.flatMap((e, idx) =>
|
|
666
|
+
Array.from(e).map((e2) => ({
|
|
667
|
+
path: [
|
|
668
|
+
`Union Schema Variant ${idx}`,
|
|
669
|
+
...error.path.split('/').slice(1),
|
|
670
|
+
...e2.path.split('/').slice(1)
|
|
671
|
+
],
|
|
672
|
+
message: e2.message
|
|
673
|
+
}))
|
|
674
|
+
);
|
|
675
|
+
} else {
|
|
676
|
+
return [
|
|
677
|
+
{
|
|
678
|
+
path: error.path.split('/').slice(1),
|
|
679
|
+
message: error.message
|
|
680
|
+
}
|
|
681
|
+
];
|
|
682
|
+
}
|
|
683
|
+
})
|
|
684
|
+
};
|
|
649
685
|
}
|
|
650
686
|
/**
|
|
651
687
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -657,13 +693,13 @@ var TypeboxSchemaValidator = class {
|
|
|
657
693
|
let processedSchema;
|
|
658
694
|
if (KindGuard.IsDate(schemified)) {
|
|
659
695
|
processedSchema = Type.String({
|
|
660
|
-
format:
|
|
696
|
+
format: 'date-time'
|
|
661
697
|
});
|
|
662
698
|
} else {
|
|
663
699
|
processedSchema = deepCloneWithoutUndefined(schemified);
|
|
664
700
|
}
|
|
665
701
|
const newSchema = Object.assign({}, processedSchema);
|
|
666
|
-
if (Object.hasOwn(newSchema,
|
|
702
|
+
if (Object.hasOwn(newSchema, 'properties')) {
|
|
667
703
|
if (newSchema.properties) {
|
|
668
704
|
Object.entries({ ...processedSchema.properties }).forEach(
|
|
669
705
|
([key, value]) => {
|
|
@@ -674,21 +710,17 @@ var TypeboxSchemaValidator = class {
|
|
|
674
710
|
);
|
|
675
711
|
}
|
|
676
712
|
}
|
|
677
|
-
if (Object.hasOwn(newSchema,
|
|
713
|
+
if (Object.hasOwn(newSchema, 'items')) {
|
|
678
714
|
newSchema.items = this.openapi(newSchema.items);
|
|
679
715
|
}
|
|
680
716
|
if (Array.isArray(newSchema.anyOf)) {
|
|
681
|
-
newSchema.anyOf = newSchema.anyOf.map(
|
|
682
|
-
(item) => this.openapi(item)
|
|
683
|
-
);
|
|
717
|
+
newSchema.anyOf = newSchema.anyOf.map((item) => this.openapi(item));
|
|
684
718
|
}
|
|
685
719
|
if (Array.isArray(newSchema.oneOf)) {
|
|
686
|
-
newSchema.oneOf = newSchema.oneOf.map(
|
|
687
|
-
(item) => this.openapi(item)
|
|
688
|
-
);
|
|
720
|
+
newSchema.oneOf = newSchema.oneOf.map((item) => this.openapi(item));
|
|
689
721
|
}
|
|
690
|
-
if (
|
|
691
|
-
delete newSchema[
|
|
722
|
+
if ('errorType' in newSchema) {
|
|
723
|
+
delete newSchema['errorType'];
|
|
692
724
|
}
|
|
693
725
|
return newSchema;
|
|
694
726
|
}
|
|
@@ -735,46 +767,55 @@ var RedisWorkerOptionsSchema = {
|
|
|
735
767
|
interval: number
|
|
736
768
|
};
|
|
737
769
|
|
|
738
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
739
|
-
import {
|
|
740
|
-
z as z2,
|
|
741
|
-
ZodType
|
|
742
|
-
} from "zod/v3";
|
|
770
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
771
|
+
import { z as z2, ZodType } from 'zod/v3';
|
|
743
772
|
|
|
744
773
|
// ../../../node_modules/.pnpm/ts-deepmerge@7.0.3/node_modules/ts-deepmerge/esm/index.js
|
|
745
774
|
var isObject = (obj) => {
|
|
746
|
-
if (typeof obj ===
|
|
747
|
-
if (typeof Object.getPrototypeOf ===
|
|
775
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
776
|
+
if (typeof Object.getPrototypeOf === 'function') {
|
|
748
777
|
const prototype = Object.getPrototypeOf(obj);
|
|
749
778
|
return prototype === Object.prototype || prototype === null;
|
|
750
779
|
}
|
|
751
|
-
return Object.prototype.toString.call(obj) ===
|
|
780
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
752
781
|
}
|
|
753
782
|
return false;
|
|
754
783
|
};
|
|
755
|
-
var merge = (...objects) =>
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (Array.isArray(current)) {
|
|
760
|
-
throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
|
|
761
|
-
}
|
|
762
|
-
Object.keys(current).forEach((key) => {
|
|
763
|
-
if (["__proto__", "constructor", "prototype"].includes(key)) {
|
|
764
|
-
return;
|
|
784
|
+
var merge = (...objects) =>
|
|
785
|
+
objects.reduce((result, current) => {
|
|
786
|
+
if (current === void 0) {
|
|
787
|
+
return result;
|
|
765
788
|
}
|
|
766
|
-
if (Array.isArray(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
771
|
-
result[key] = merge(current[key], void 0);
|
|
772
|
-
} else {
|
|
773
|
-
result[key] = current[key] === void 0 ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
|
|
789
|
+
if (Array.isArray(current)) {
|
|
790
|
+
throw new TypeError(
|
|
791
|
+
'Arguments provided to ts-deepmerge must be objects, not arrays.'
|
|
792
|
+
);
|
|
774
793
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
794
|
+
Object.keys(current).forEach((key) => {
|
|
795
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key)) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
799
|
+
result[key] = merge.options.mergeArrays
|
|
800
|
+
? merge.options.uniqueArrayItems
|
|
801
|
+
? Array.from(new Set(result[key].concat(current[key])))
|
|
802
|
+
: [...result[key], ...current[key]]
|
|
803
|
+
: current[key];
|
|
804
|
+
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
805
|
+
result[key] = merge(result[key], current[key]);
|
|
806
|
+
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
807
|
+
result[key] = merge(current[key], void 0);
|
|
808
|
+
} else {
|
|
809
|
+
result[key] =
|
|
810
|
+
current[key] === void 0
|
|
811
|
+
? merge.options.allowUndefinedOverrides
|
|
812
|
+
? current[key]
|
|
813
|
+
: result[key]
|
|
814
|
+
: current[key];
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
return result;
|
|
818
|
+
}, {});
|
|
778
819
|
var defaultOptions = {
|
|
779
820
|
allowUndefinedOverrides: true,
|
|
780
821
|
mergeArrays: true,
|
|
@@ -788,8 +829,8 @@ merge.withOptions = (options, ...objects) => {
|
|
|
788
829
|
return result;
|
|
789
830
|
};
|
|
790
831
|
|
|
791
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
792
|
-
import { z } from
|
|
832
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
833
|
+
import { z } from 'zod/v3';
|
|
793
834
|
function extendApi(schema, schemaObject = {}) {
|
|
794
835
|
const This = schema.constructor;
|
|
795
836
|
const newSchema = new This(schema._def);
|
|
@@ -806,89 +847,96 @@ function iterateZodObject({
|
|
|
806
847
|
hideDefinitions,
|
|
807
848
|
openApiVersion
|
|
808
849
|
}) {
|
|
809
|
-
const reduced = Object.keys(zodRef.shape)
|
|
810
|
-
(
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
850
|
+
const reduced = Object.keys(zodRef.shape)
|
|
851
|
+
.filter((key) => hideDefinitions?.includes(key) === false)
|
|
852
|
+
.reduce(
|
|
853
|
+
(carry, key) => ({
|
|
854
|
+
...carry,
|
|
855
|
+
[key]: generateSchema(zodRef.shape[key], useOutput, openApiVersion)
|
|
856
|
+
}),
|
|
857
|
+
{}
|
|
858
|
+
);
|
|
816
859
|
return reduced;
|
|
817
860
|
}
|
|
818
861
|
function typeFormat(type22, openApiVersion) {
|
|
819
|
-
return openApiVersion ===
|
|
862
|
+
return openApiVersion === '3.0' ? type22 : [type22];
|
|
820
863
|
}
|
|
821
|
-
function parseTransformation({
|
|
822
|
-
zodRef,
|
|
823
|
-
schemas,
|
|
824
|
-
useOutput,
|
|
825
|
-
openApiVersion
|
|
826
|
-
}) {
|
|
864
|
+
function parseTransformation({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
827
865
|
const input = generateSchema(zodRef._def.schema, useOutput, openApiVersion);
|
|
828
|
-
let output =
|
|
866
|
+
let output = 'undefined';
|
|
829
867
|
if (useOutput && zodRef._def.effect) {
|
|
830
|
-
const effect =
|
|
831
|
-
|
|
868
|
+
const effect =
|
|
869
|
+
zodRef._def.effect.type === 'transform' ? zodRef._def.effect : null;
|
|
870
|
+
if (effect && 'transform' in effect) {
|
|
832
871
|
try {
|
|
833
872
|
const type22 = Array.isArray(input.type) ? input.type[0] : input.type;
|
|
834
873
|
output = typeof effect.transform(
|
|
835
|
-
[
|
|
874
|
+
['integer', 'number'].includes(`${type22}`)
|
|
875
|
+
? 0
|
|
876
|
+
: 'string' === type22
|
|
877
|
+
? ''
|
|
878
|
+
: 'boolean' === type22
|
|
879
|
+
? false
|
|
880
|
+
: 'object' === type22
|
|
881
|
+
? {}
|
|
882
|
+
: 'null' === type22
|
|
883
|
+
? null
|
|
884
|
+
: 'array' === type22
|
|
885
|
+
? []
|
|
886
|
+
: void 0,
|
|
836
887
|
{ addIssue: () => void 0, path: [] }
|
|
837
888
|
// TODO: Discover if context is necessary here
|
|
838
889
|
);
|
|
839
|
-
} catch {
|
|
840
|
-
}
|
|
890
|
+
} catch {}
|
|
841
891
|
}
|
|
842
892
|
}
|
|
843
893
|
const outputType = output;
|
|
844
894
|
return merge(
|
|
845
895
|
{
|
|
846
|
-
...zodRef.description ? { description: zodRef.description } : {},
|
|
896
|
+
...(zodRef.description ? { description: zodRef.description } : {}),
|
|
847
897
|
...input,
|
|
848
|
-
...[
|
|
849
|
-
|
|
850
|
-
|
|
898
|
+
...(['number', 'string', 'boolean', 'null'].includes(output)
|
|
899
|
+
? {
|
|
900
|
+
type: typeFormat(outputType, openApiVersion)
|
|
901
|
+
}
|
|
902
|
+
: {})
|
|
851
903
|
},
|
|
852
904
|
...schemas
|
|
853
905
|
);
|
|
854
906
|
}
|
|
855
|
-
function parseString({
|
|
856
|
-
zodRef,
|
|
857
|
-
schemas,
|
|
858
|
-
openApiVersion
|
|
859
|
-
}) {
|
|
907
|
+
function parseString({ zodRef, schemas, openApiVersion }) {
|
|
860
908
|
const baseSchema = {
|
|
861
|
-
type: typeFormat(
|
|
909
|
+
type: typeFormat('string', openApiVersion)
|
|
862
910
|
};
|
|
863
911
|
const { checks = [] } = zodRef._def;
|
|
864
912
|
checks.forEach((item) => {
|
|
865
913
|
switch (item.kind) {
|
|
866
|
-
case
|
|
867
|
-
baseSchema.format =
|
|
914
|
+
case 'email':
|
|
915
|
+
baseSchema.format = 'email';
|
|
868
916
|
break;
|
|
869
|
-
case
|
|
870
|
-
baseSchema.format =
|
|
917
|
+
case 'uuid':
|
|
918
|
+
baseSchema.format = 'uuid';
|
|
871
919
|
break;
|
|
872
|
-
case
|
|
873
|
-
baseSchema.format =
|
|
920
|
+
case 'cuid':
|
|
921
|
+
baseSchema.format = 'cuid';
|
|
874
922
|
break;
|
|
875
|
-
case
|
|
876
|
-
baseSchema.format =
|
|
923
|
+
case 'url':
|
|
924
|
+
baseSchema.format = 'uri';
|
|
877
925
|
break;
|
|
878
|
-
case
|
|
879
|
-
baseSchema.format =
|
|
926
|
+
case 'datetime':
|
|
927
|
+
baseSchema.format = 'date-time';
|
|
880
928
|
break;
|
|
881
|
-
case
|
|
929
|
+
case 'length':
|
|
882
930
|
baseSchema.minLength = item.value;
|
|
883
931
|
baseSchema.maxLength = item.value;
|
|
884
932
|
break;
|
|
885
|
-
case
|
|
933
|
+
case 'max':
|
|
886
934
|
baseSchema.maxLength = item.value;
|
|
887
935
|
break;
|
|
888
|
-
case
|
|
936
|
+
case 'min':
|
|
889
937
|
baseSchema.minLength = item.value;
|
|
890
938
|
break;
|
|
891
|
-
case
|
|
939
|
+
case 'regex':
|
|
892
940
|
baseSchema.pattern = item.regex.source;
|
|
893
941
|
break;
|
|
894
942
|
}
|
|
@@ -899,45 +947,41 @@ function parseString({
|
|
|
899
947
|
...schemas
|
|
900
948
|
);
|
|
901
949
|
}
|
|
902
|
-
function parseNumber({
|
|
903
|
-
zodRef,
|
|
904
|
-
schemas,
|
|
905
|
-
openApiVersion
|
|
906
|
-
}) {
|
|
950
|
+
function parseNumber({ zodRef, schemas, openApiVersion }) {
|
|
907
951
|
const baseSchema = {
|
|
908
|
-
type: typeFormat(
|
|
952
|
+
type: typeFormat('number', openApiVersion)
|
|
909
953
|
};
|
|
910
954
|
const { checks = [] } = zodRef._def;
|
|
911
955
|
checks.forEach((item) => {
|
|
912
956
|
switch (item.kind) {
|
|
913
|
-
case
|
|
914
|
-
if (item.inclusive || openApiVersion ===
|
|
957
|
+
case 'max':
|
|
958
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
915
959
|
baseSchema.maximum = item.value;
|
|
916
960
|
}
|
|
917
961
|
if (!item.inclusive) {
|
|
918
|
-
if (openApiVersion ===
|
|
962
|
+
if (openApiVersion === '3.0') {
|
|
919
963
|
baseSchema.exclusiveMaximum = true;
|
|
920
964
|
} else {
|
|
921
965
|
baseSchema.exclusiveMaximum = item.value;
|
|
922
966
|
}
|
|
923
967
|
}
|
|
924
968
|
break;
|
|
925
|
-
case
|
|
926
|
-
if (item.inclusive || openApiVersion ===
|
|
969
|
+
case 'min':
|
|
970
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
927
971
|
baseSchema.minimum = item.value;
|
|
928
972
|
}
|
|
929
973
|
if (!item.inclusive) {
|
|
930
|
-
if (openApiVersion ===
|
|
974
|
+
if (openApiVersion === '3.0') {
|
|
931
975
|
baseSchema.exclusiveMinimum = true;
|
|
932
976
|
} else {
|
|
933
977
|
baseSchema.exclusiveMinimum = item.value;
|
|
934
978
|
}
|
|
935
979
|
}
|
|
936
980
|
break;
|
|
937
|
-
case
|
|
938
|
-
baseSchema.type = typeFormat(
|
|
981
|
+
case 'int':
|
|
982
|
+
baseSchema.type = typeFormat('integer', openApiVersion);
|
|
939
983
|
break;
|
|
940
|
-
case
|
|
984
|
+
case 'multipleOf':
|
|
941
985
|
baseSchema.multipleOf = item.value;
|
|
942
986
|
break;
|
|
943
987
|
}
|
|
@@ -965,26 +1009,37 @@ function parseObject({
|
|
|
965
1009
|
openApiVersion
|
|
966
1010
|
}) {
|
|
967
1011
|
let additionalProperties;
|
|
968
|
-
if (
|
|
1012
|
+
if (
|
|
1013
|
+
!(
|
|
1014
|
+
zodRef._def.catchall instanceof z.ZodNever ||
|
|
1015
|
+
zodRef._def.catchall?._def.typeName === 'ZodNever'
|
|
1016
|
+
)
|
|
1017
|
+
)
|
|
969
1018
|
additionalProperties = generateSchema(
|
|
970
1019
|
zodRef._def.catchall,
|
|
971
1020
|
useOutput,
|
|
972
1021
|
openApiVersion
|
|
973
1022
|
);
|
|
974
|
-
else if (zodRef._def.unknownKeys ===
|
|
1023
|
+
else if (zodRef._def.unknownKeys === 'passthrough')
|
|
975
1024
|
additionalProperties = true;
|
|
976
|
-
else if (zodRef._def.unknownKeys ===
|
|
977
|
-
additionalProperties =
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
).filter((key) => {
|
|
1025
|
+
else if (zodRef._def.unknownKeys === 'strict') additionalProperties = false;
|
|
1026
|
+
additionalProperties =
|
|
1027
|
+
additionalProperties != null ? { additionalProperties } : {};
|
|
1028
|
+
const requiredProperties = Object.keys(zodRef.shape).filter((key) => {
|
|
981
1029
|
const item = zodRef.shape[key];
|
|
982
|
-
return
|
|
1030
|
+
return (
|
|
1031
|
+
!(
|
|
1032
|
+
item.isOptional() ||
|
|
1033
|
+
item instanceof z.ZodDefault ||
|
|
1034
|
+
item._def.typeName === 'ZodDefault'
|
|
1035
|
+
) && !(item instanceof z.ZodNever || item._def.typeName === 'ZodDefault')
|
|
1036
|
+
);
|
|
983
1037
|
});
|
|
984
|
-
const required =
|
|
1038
|
+
const required =
|
|
1039
|
+
requiredProperties.length > 0 ? { required: requiredProperties } : {};
|
|
985
1040
|
return merge(
|
|
986
1041
|
{
|
|
987
|
-
type: typeFormat(
|
|
1042
|
+
type: typeFormat('object', openApiVersion),
|
|
988
1043
|
properties: iterateZodObject({
|
|
989
1044
|
zodRef,
|
|
990
1045
|
schemas,
|
|
@@ -996,110 +1051,83 @@ function parseObject({
|
|
|
996
1051
|
...additionalProperties,
|
|
997
1052
|
...hideDefinitions
|
|
998
1053
|
},
|
|
999
|
-
zodRef.description
|
|
1054
|
+
zodRef.description
|
|
1055
|
+
? { description: zodRef.description, hideDefinitions }
|
|
1056
|
+
: {},
|
|
1000
1057
|
...schemas
|
|
1001
1058
|
);
|
|
1002
1059
|
}
|
|
1003
|
-
function parseRecord({
|
|
1004
|
-
zodRef,
|
|
1005
|
-
schemas,
|
|
1006
|
-
useOutput,
|
|
1007
|
-
openApiVersion
|
|
1008
|
-
}) {
|
|
1060
|
+
function parseRecord({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
1009
1061
|
return merge(
|
|
1010
1062
|
{
|
|
1011
|
-
type: typeFormat(
|
|
1012
|
-
additionalProperties:
|
|
1063
|
+
type: typeFormat('object', openApiVersion),
|
|
1064
|
+
additionalProperties:
|
|
1065
|
+
zodRef._def.valueType instanceof z.ZodUnknown
|
|
1066
|
+
? {}
|
|
1067
|
+
: generateSchema(zodRef._def.valueType, useOutput, openApiVersion)
|
|
1013
1068
|
},
|
|
1014
1069
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1015
1070
|
...schemas
|
|
1016
1071
|
);
|
|
1017
1072
|
}
|
|
1018
|
-
function parseBigInt({
|
|
1019
|
-
zodRef,
|
|
1020
|
-
schemas,
|
|
1021
|
-
openApiVersion
|
|
1022
|
-
}) {
|
|
1073
|
+
function parseBigInt({ zodRef, schemas, openApiVersion }) {
|
|
1023
1074
|
return merge(
|
|
1024
1075
|
{
|
|
1025
|
-
type: typeFormat(
|
|
1026
|
-
format:
|
|
1076
|
+
type: typeFormat('integer', openApiVersion),
|
|
1077
|
+
format: 'int64'
|
|
1027
1078
|
},
|
|
1028
1079
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1029
1080
|
...schemas
|
|
1030
1081
|
);
|
|
1031
1082
|
}
|
|
1032
|
-
function parseBoolean({
|
|
1033
|
-
zodRef,
|
|
1034
|
-
schemas,
|
|
1035
|
-
openApiVersion
|
|
1036
|
-
}) {
|
|
1083
|
+
function parseBoolean({ zodRef, schemas, openApiVersion }) {
|
|
1037
1084
|
return merge(
|
|
1038
|
-
{ type: typeFormat(
|
|
1085
|
+
{ type: typeFormat('boolean', openApiVersion) },
|
|
1039
1086
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1040
1087
|
...schemas
|
|
1041
1088
|
);
|
|
1042
1089
|
}
|
|
1043
|
-
function parseDate({
|
|
1044
|
-
zodRef,
|
|
1045
|
-
schemas,
|
|
1046
|
-
openApiVersion
|
|
1047
|
-
}) {
|
|
1090
|
+
function parseDate({ zodRef, schemas, openApiVersion }) {
|
|
1048
1091
|
return merge(
|
|
1049
1092
|
{
|
|
1050
|
-
type: typeFormat(
|
|
1051
|
-
format:
|
|
1093
|
+
type: typeFormat('string', openApiVersion),
|
|
1094
|
+
format: 'date-time'
|
|
1052
1095
|
},
|
|
1053
1096
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1054
1097
|
...schemas
|
|
1055
1098
|
);
|
|
1056
1099
|
}
|
|
1057
|
-
function parseNull({
|
|
1058
|
-
zodRef,
|
|
1059
|
-
schemas,
|
|
1060
|
-
openApiVersion
|
|
1061
|
-
}) {
|
|
1100
|
+
function parseNull({ zodRef, schemas, openApiVersion }) {
|
|
1062
1101
|
return merge(
|
|
1063
|
-
openApiVersion ===
|
|
1064
|
-
type:
|
|
1065
|
-
|
|
1066
|
-
|
|
1102
|
+
openApiVersion === '3.0'
|
|
1103
|
+
? { type: 'null' }
|
|
1104
|
+
: {
|
|
1105
|
+
type: ['string', 'null'],
|
|
1106
|
+
enum: ['null']
|
|
1107
|
+
},
|
|
1067
1108
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1068
1109
|
...schemas
|
|
1069
1110
|
);
|
|
1070
1111
|
}
|
|
1071
|
-
function parseOptional({
|
|
1072
|
-
schemas,
|
|
1073
|
-
zodRef,
|
|
1074
|
-
useOutput,
|
|
1075
|
-
openApiVersion
|
|
1076
|
-
}) {
|
|
1112
|
+
function parseOptional({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1077
1113
|
return merge(
|
|
1078
1114
|
generateSchema(zodRef.unwrap(), useOutput, openApiVersion),
|
|
1079
1115
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1080
1116
|
...schemas
|
|
1081
1117
|
);
|
|
1082
1118
|
}
|
|
1083
|
-
function parseNullable({
|
|
1084
|
-
schemas,
|
|
1085
|
-
zodRef,
|
|
1086
|
-
useOutput,
|
|
1087
|
-
openApiVersion
|
|
1088
|
-
}) {
|
|
1119
|
+
function parseNullable({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1089
1120
|
const schema = generateSchema(zodRef.unwrap(), useOutput, openApiVersion);
|
|
1090
1121
|
return merge(
|
|
1091
1122
|
schema,
|
|
1092
|
-
openApiVersion ===
|
|
1123
|
+
openApiVersion === '3.0'
|
|
1124
|
+
? { nullable: true }
|
|
1125
|
+
: { type: typeFormat('null', openApiVersion) },
|
|
1093
1126
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1094
1127
|
...schemas
|
|
1095
1128
|
);
|
|
1096
1129
|
}
|
|
1097
|
-
function parseDefault({
|
|
1098
|
-
schemas,
|
|
1099
|
-
zodRef,
|
|
1100
|
-
useOutput,
|
|
1101
|
-
openApiVersion
|
|
1102
|
-
}) {
|
|
1130
|
+
function parseDefault({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1103
1131
|
return merge(
|
|
1104
1132
|
{
|
|
1105
1133
|
default: zodRef._def.defaultValue(),
|
|
@@ -1109,12 +1137,7 @@ function parseDefault({
|
|
|
1109
1137
|
...schemas
|
|
1110
1138
|
);
|
|
1111
1139
|
}
|
|
1112
|
-
function parseArray({
|
|
1113
|
-
schemas,
|
|
1114
|
-
zodRef,
|
|
1115
|
-
useOutput,
|
|
1116
|
-
openApiVersion
|
|
1117
|
-
}) {
|
|
1140
|
+
function parseArray({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1118
1141
|
const constraints = {};
|
|
1119
1142
|
if (zodRef._def.exactLength != null) {
|
|
1120
1143
|
constraints.minItems = zodRef._def.exactLength.value;
|
|
@@ -1126,7 +1149,7 @@ function parseArray({
|
|
|
1126
1149
|
constraints.maxItems = zodRef._def.maxLength.value;
|
|
1127
1150
|
return merge(
|
|
1128
1151
|
{
|
|
1129
|
-
type: typeFormat(
|
|
1152
|
+
type: typeFormat('array', openApiVersion),
|
|
1130
1153
|
items: generateSchema(zodRef.element, useOutput, openApiVersion),
|
|
1131
1154
|
...constraints
|
|
1132
1155
|
},
|
|
@@ -1134,11 +1157,7 @@ function parseArray({
|
|
|
1134
1157
|
...schemas
|
|
1135
1158
|
);
|
|
1136
1159
|
}
|
|
1137
|
-
function parseLiteral({
|
|
1138
|
-
schemas,
|
|
1139
|
-
zodRef,
|
|
1140
|
-
openApiVersion
|
|
1141
|
-
}) {
|
|
1160
|
+
function parseLiteral({ schemas, zodRef, openApiVersion }) {
|
|
1142
1161
|
const type22 = typeof zodRef._def.value;
|
|
1143
1162
|
return merge(
|
|
1144
1163
|
{
|
|
@@ -1149,11 +1168,7 @@ function parseLiteral({
|
|
|
1149
1168
|
...schemas
|
|
1150
1169
|
);
|
|
1151
1170
|
}
|
|
1152
|
-
function parseEnum({
|
|
1153
|
-
schemas,
|
|
1154
|
-
zodRef,
|
|
1155
|
-
openApiVersion
|
|
1156
|
-
}) {
|
|
1171
|
+
function parseEnum({ schemas, zodRef, openApiVersion }) {
|
|
1157
1172
|
const type22 = typeof Object.values(zodRef._def.values)[0];
|
|
1158
1173
|
return merge(
|
|
1159
1174
|
{
|
|
@@ -1164,12 +1179,7 @@ function parseEnum({
|
|
|
1164
1179
|
...schemas
|
|
1165
1180
|
);
|
|
1166
1181
|
}
|
|
1167
|
-
function parseIntersection({
|
|
1168
|
-
schemas,
|
|
1169
|
-
zodRef,
|
|
1170
|
-
useOutput,
|
|
1171
|
-
openApiVersion
|
|
1172
|
-
}) {
|
|
1182
|
+
function parseIntersection({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1173
1183
|
return merge(
|
|
1174
1184
|
{
|
|
1175
1185
|
allOf: [
|
|
@@ -1181,20 +1191,20 @@ function parseIntersection({
|
|
|
1181
1191
|
...schemas
|
|
1182
1192
|
);
|
|
1183
1193
|
}
|
|
1184
|
-
function parseUnion({
|
|
1185
|
-
schemas,
|
|
1186
|
-
zodRef,
|
|
1187
|
-
useOutput,
|
|
1188
|
-
openApiVersion
|
|
1189
|
-
}) {
|
|
1194
|
+
function parseUnion({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1190
1195
|
const contents = zodRef._def.options;
|
|
1191
|
-
if (
|
|
1192
|
-
(
|
|
1193
|
-
|
|
1194
|
-
|
|
1196
|
+
if (
|
|
1197
|
+
contents.reduce(
|
|
1198
|
+
(prev, content) => prev && content._def.typeName === 'ZodLiteral',
|
|
1199
|
+
true
|
|
1200
|
+
)
|
|
1201
|
+
) {
|
|
1195
1202
|
const literals = contents;
|
|
1196
1203
|
const type22 = literals.reduce(
|
|
1197
|
-
(prev, content) =>
|
|
1204
|
+
(prev, content) =>
|
|
1205
|
+
!prev || prev === typeof content._def.value
|
|
1206
|
+
? typeof content._def.value
|
|
1207
|
+
: null,
|
|
1198
1208
|
null
|
|
1199
1209
|
);
|
|
1200
1210
|
if (type22) {
|
|
@@ -1208,12 +1218,15 @@ function parseUnion({
|
|
|
1208
1218
|
);
|
|
1209
1219
|
}
|
|
1210
1220
|
}
|
|
1211
|
-
const oneOfContents =
|
|
1221
|
+
const oneOfContents =
|
|
1222
|
+
openApiVersion === '3.0'
|
|
1223
|
+
? contents.filter((content) => content._def.typeName !== 'ZodNull')
|
|
1224
|
+
: contents;
|
|
1212
1225
|
const contentsHasNull = contents.length != oneOfContents.length;
|
|
1213
1226
|
return merge(
|
|
1214
1227
|
{
|
|
1215
|
-
oneOf: oneOfContents.map(
|
|
1216
|
-
|
|
1228
|
+
oneOf: oneOfContents.map((schema) =>
|
|
1229
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1217
1230
|
)
|
|
1218
1231
|
},
|
|
1219
1232
|
contentsHasNull ? { nullable: true } : {},
|
|
@@ -1232,50 +1245,34 @@ function parseDiscriminatedUnion({
|
|
|
1232
1245
|
discriminator: {
|
|
1233
1246
|
propertyName: zodRef._def.discriminator
|
|
1234
1247
|
},
|
|
1235
|
-
oneOf: Array.from(
|
|
1236
|
-
|
|
1237
|
-
)
|
|
1248
|
+
oneOf: Array.from(zodRef._def.options.values()).map((schema) =>
|
|
1249
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1250
|
+
)
|
|
1238
1251
|
},
|
|
1239
1252
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1240
1253
|
...schemas
|
|
1241
1254
|
);
|
|
1242
1255
|
}
|
|
1243
|
-
function parseNever({
|
|
1244
|
-
zodRef,
|
|
1245
|
-
schemas
|
|
1246
|
-
}) {
|
|
1256
|
+
function parseNever({ zodRef, schemas }) {
|
|
1247
1257
|
return merge(
|
|
1248
1258
|
{ readOnly: true },
|
|
1249
1259
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1250
1260
|
...schemas
|
|
1251
1261
|
);
|
|
1252
1262
|
}
|
|
1253
|
-
function parseBranded({
|
|
1254
|
-
schemas,
|
|
1255
|
-
zodRef,
|
|
1256
|
-
useOutput,
|
|
1257
|
-
openApiVersion
|
|
1258
|
-
}) {
|
|
1263
|
+
function parseBranded({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1259
1264
|
return merge(
|
|
1260
1265
|
generateSchema(zodRef._def.type, useOutput, openApiVersion),
|
|
1261
1266
|
...schemas
|
|
1262
1267
|
);
|
|
1263
1268
|
}
|
|
1264
|
-
function catchAllParser({
|
|
1265
|
-
zodRef,
|
|
1266
|
-
schemas
|
|
1267
|
-
}) {
|
|
1269
|
+
function catchAllParser({ zodRef, schemas }) {
|
|
1268
1270
|
return merge(
|
|
1269
1271
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1270
1272
|
...schemas
|
|
1271
1273
|
);
|
|
1272
1274
|
}
|
|
1273
|
-
function parsePipeline({
|
|
1274
|
-
schemas,
|
|
1275
|
-
zodRef,
|
|
1276
|
-
useOutput,
|
|
1277
|
-
openApiVersion
|
|
1278
|
-
}) {
|
|
1275
|
+
function parsePipeline({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1279
1276
|
return merge(
|
|
1280
1277
|
generateSchema(
|
|
1281
1278
|
useOutput ? zodRef._def.out : zodRef._def.in,
|
|
@@ -1285,12 +1282,7 @@ function parsePipeline({
|
|
|
1285
1282
|
...schemas
|
|
1286
1283
|
);
|
|
1287
1284
|
}
|
|
1288
|
-
function parseReadonly({
|
|
1289
|
-
zodRef,
|
|
1290
|
-
useOutput,
|
|
1291
|
-
schemas,
|
|
1292
|
-
openApiVersion
|
|
1293
|
-
}) {
|
|
1285
|
+
function parseReadonly({ zodRef, useOutput, schemas, openApiVersion }) {
|
|
1294
1286
|
return merge(
|
|
1295
1287
|
generateSchema(zodRef._def.innerType, useOutput, openApiVersion),
|
|
1296
1288
|
zodRef.description ? { description: zodRef.description } : {},
|
|
@@ -1334,10 +1326,10 @@ var workerMap = {
|
|
|
1334
1326
|
ZodPipeline: parsePipeline,
|
|
1335
1327
|
ZodReadonly: parseReadonly
|
|
1336
1328
|
};
|
|
1337
|
-
function generateSchema(zodRef, useOutput = false, openApiVersion =
|
|
1329
|
+
function generateSchema(zodRef, useOutput = false, openApiVersion = '3.1') {
|
|
1338
1330
|
const { metaOpenApi = {} } = zodRef;
|
|
1339
1331
|
const schemas = [
|
|
1340
|
-
...Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi]
|
|
1332
|
+
...(Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi])
|
|
1341
1333
|
];
|
|
1342
1334
|
try {
|
|
1343
1335
|
const typeName = zodRef._def.typeName;
|
|
@@ -1356,174 +1348,194 @@ function generateSchema(zodRef, useOutput = false, openApiVersion = "3.1") {
|
|
|
1356
1348
|
}
|
|
1357
1349
|
}
|
|
1358
1350
|
function extendZodWithOpenApi(zod, forceOverride = false) {
|
|
1359
|
-
if (
|
|
1351
|
+
if (
|
|
1352
|
+
!forceOverride &&
|
|
1353
|
+
typeof zod.ZodSchema.prototype.openapi !== 'undefined'
|
|
1354
|
+
) {
|
|
1360
1355
|
return;
|
|
1361
1356
|
}
|
|
1362
|
-
zod.ZodSchema.prototype.openapi = function(metadata) {
|
|
1357
|
+
zod.ZodSchema.prototype.openapi = function (metadata) {
|
|
1363
1358
|
return extendApi(this, metadata);
|
|
1364
1359
|
};
|
|
1365
1360
|
}
|
|
1366
1361
|
extendZodWithOpenApi(z2);
|
|
1367
1362
|
var ZodSchemaValidator = class {
|
|
1368
|
-
_Type =
|
|
1363
|
+
_Type = 'Zod';
|
|
1369
1364
|
_SchemaCatchall;
|
|
1370
1365
|
_ValidSchemaObject;
|
|
1371
1366
|
string = z2.string().openapi({
|
|
1372
|
-
title:
|
|
1373
|
-
example:
|
|
1367
|
+
title: 'String',
|
|
1368
|
+
example: 'a string'
|
|
1374
1369
|
});
|
|
1375
1370
|
uuid = z2.string().uuid().openapi({
|
|
1376
|
-
title:
|
|
1377
|
-
format:
|
|
1378
|
-
pattern:
|
|
1379
|
-
|
|
1371
|
+
title: 'UUID',
|
|
1372
|
+
format: 'uuid',
|
|
1373
|
+
pattern:
|
|
1374
|
+
'^[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}$',
|
|
1375
|
+
example: 'a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6'
|
|
1380
1376
|
});
|
|
1381
1377
|
email = z2.string().email().openapi({
|
|
1382
|
-
title:
|
|
1383
|
-
format:
|
|
1384
|
-
pattern:
|
|
1385
|
-
example:
|
|
1378
|
+
title: 'Email',
|
|
1379
|
+
format: 'email',
|
|
1380
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
1381
|
+
example: 'a@b.com'
|
|
1386
1382
|
});
|
|
1387
1383
|
uri = z2.string().url().openapi({
|
|
1388
|
-
title:
|
|
1389
|
-
format:
|
|
1390
|
-
pattern:
|
|
1391
|
-
example:
|
|
1392
|
-
});
|
|
1393
|
-
number = z2.preprocess((value) => {
|
|
1394
|
-
try {
|
|
1395
|
-
return Number(value);
|
|
1396
|
-
} catch {
|
|
1397
|
-
return value;
|
|
1398
|
-
}
|
|
1399
|
-
}, z2.number()).openapi({
|
|
1400
|
-
title: "Number",
|
|
1401
|
-
example: 123
|
|
1384
|
+
title: 'URI',
|
|
1385
|
+
format: 'uri',
|
|
1386
|
+
pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
|
|
1387
|
+
example: 'https://forklaunch.com'
|
|
1402
1388
|
});
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
return
|
|
1389
|
+
number = z2
|
|
1390
|
+
.preprocess((value) => {
|
|
1391
|
+
try {
|
|
1392
|
+
return Number(value);
|
|
1393
|
+
} catch {
|
|
1394
|
+
return value;
|
|
1407
1395
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1396
|
+
}, z2.number())
|
|
1397
|
+
.openapi({
|
|
1398
|
+
title: 'Number',
|
|
1399
|
+
example: 123
|
|
1400
|
+
});
|
|
1401
|
+
bigint = z2
|
|
1402
|
+
.preprocess((value) => {
|
|
1403
|
+
try {
|
|
1404
|
+
if (value instanceof Date) {
|
|
1405
|
+
return BigInt(value.getTime());
|
|
1406
|
+
}
|
|
1407
|
+
switch (typeof value) {
|
|
1408
|
+
case 'number':
|
|
1409
|
+
case 'string':
|
|
1410
|
+
return BigInt(value);
|
|
1411
|
+
case 'boolean':
|
|
1412
|
+
return BigInt(value ? 1 : 0);
|
|
1413
|
+
default:
|
|
1414
|
+
return value;
|
|
1415
|
+
}
|
|
1416
|
+
} catch {
|
|
1417
|
+
return value;
|
|
1416
1418
|
}
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
if (val.toLowerCase() === "false") return false;
|
|
1430
|
-
}
|
|
1431
|
-
return val;
|
|
1432
|
-
}, z2.boolean()).openapi({
|
|
1433
|
-
title: "Boolean",
|
|
1434
|
-
example: true
|
|
1435
|
-
});
|
|
1436
|
-
date = z2.preprocess((value) => {
|
|
1437
|
-
try {
|
|
1438
|
-
switch (typeof value) {
|
|
1439
|
-
case "string":
|
|
1440
|
-
return new Date(value);
|
|
1441
|
-
case "number":
|
|
1442
|
-
return new Date(value);
|
|
1443
|
-
default:
|
|
1444
|
-
return value;
|
|
1419
|
+
}, z2.bigint())
|
|
1420
|
+
.openapi({
|
|
1421
|
+
title: 'BigInt',
|
|
1422
|
+
type: 'integer',
|
|
1423
|
+
format: 'int64',
|
|
1424
|
+
example: 123n
|
|
1425
|
+
});
|
|
1426
|
+
boolean = z2
|
|
1427
|
+
.preprocess((val) => {
|
|
1428
|
+
if (typeof val === 'string') {
|
|
1429
|
+
if (val.toLowerCase() === 'true') return true;
|
|
1430
|
+
if (val.toLowerCase() === 'false') return false;
|
|
1445
1431
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1432
|
+
return val;
|
|
1433
|
+
}, z2.boolean())
|
|
1434
|
+
.openapi({
|
|
1435
|
+
title: 'Boolean',
|
|
1436
|
+
example: true
|
|
1437
|
+
});
|
|
1438
|
+
date = z2
|
|
1439
|
+
.preprocess((value) => {
|
|
1440
|
+
try {
|
|
1441
|
+
switch (typeof value) {
|
|
1442
|
+
case 'string':
|
|
1443
|
+
return new Date(value);
|
|
1444
|
+
case 'number':
|
|
1445
|
+
return new Date(value);
|
|
1446
|
+
default:
|
|
1447
|
+
return value;
|
|
1448
|
+
}
|
|
1449
|
+
} catch {
|
|
1450
|
+
return value;
|
|
1451
|
+
}
|
|
1452
|
+
}, z2.date())
|
|
1453
|
+
.openapi({
|
|
1454
|
+
title: 'Date',
|
|
1455
|
+
type: 'string',
|
|
1456
|
+
format: 'date-time',
|
|
1457
|
+
example: '2025-05-16T21:13:04.123Z'
|
|
1458
|
+
});
|
|
1455
1459
|
symbol = z2.symbol().openapi({
|
|
1456
|
-
title:
|
|
1457
|
-
example: /* @__PURE__ */ Symbol(
|
|
1460
|
+
title: 'Symbol',
|
|
1461
|
+
example: /* @__PURE__ */ Symbol('symbol')
|
|
1458
1462
|
});
|
|
1459
1463
|
nullish = z2.union([z2.void(), z2.null(), z2.undefined()]).openapi({
|
|
1460
|
-
title:
|
|
1461
|
-
type:
|
|
1464
|
+
title: 'Nullish',
|
|
1465
|
+
type: 'null',
|
|
1462
1466
|
example: null
|
|
1463
1467
|
});
|
|
1464
1468
|
void = z2.void().openapi({
|
|
1465
|
-
title:
|
|
1466
|
-
type:
|
|
1469
|
+
title: 'Void',
|
|
1470
|
+
type: 'null',
|
|
1467
1471
|
example: void 0
|
|
1468
1472
|
});
|
|
1469
1473
|
null = z2.null().openapi({
|
|
1470
|
-
title:
|
|
1471
|
-
type:
|
|
1474
|
+
title: 'Null',
|
|
1475
|
+
type: 'null',
|
|
1472
1476
|
example: null
|
|
1473
1477
|
});
|
|
1474
1478
|
undefined = z2.undefined().openapi({
|
|
1475
|
-
title:
|
|
1476
|
-
type:
|
|
1479
|
+
title: 'Undefined',
|
|
1480
|
+
type: 'null',
|
|
1477
1481
|
example: void 0
|
|
1478
1482
|
});
|
|
1479
1483
|
any = z2.any().openapi({
|
|
1480
|
-
title:
|
|
1481
|
-
type:
|
|
1482
|
-
example:
|
|
1484
|
+
title: 'Any',
|
|
1485
|
+
type: 'object',
|
|
1486
|
+
example: 'any'
|
|
1483
1487
|
});
|
|
1484
1488
|
unknown = z2.unknown().openapi({
|
|
1485
|
-
title:
|
|
1486
|
-
type:
|
|
1487
|
-
example:
|
|
1489
|
+
title: 'Unknown',
|
|
1490
|
+
type: 'object',
|
|
1491
|
+
example: 'unknown'
|
|
1488
1492
|
});
|
|
1489
1493
|
never = z2.never().openapi({
|
|
1490
|
-
title:
|
|
1491
|
-
type:
|
|
1492
|
-
example:
|
|
1493
|
-
});
|
|
1494
|
-
binary = z2.string().transform((val) => new Uint8Array(Buffer.from(val, "base64"))).openapi({
|
|
1495
|
-
title: "Binary",
|
|
1496
|
-
type: "string",
|
|
1497
|
-
format: "binary",
|
|
1498
|
-
example: "a base-64 encodable string"
|
|
1494
|
+
title: 'Never',
|
|
1495
|
+
type: 'null',
|
|
1496
|
+
example: 'never'
|
|
1499
1497
|
});
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1498
|
+
binary = z2
|
|
1499
|
+
.string()
|
|
1500
|
+
.transform((val) => new Uint8Array(Buffer.from(val, 'base64')))
|
|
1501
|
+
.openapi({
|
|
1502
|
+
title: 'Binary',
|
|
1503
|
+
type: 'string',
|
|
1504
|
+
format: 'binary',
|
|
1505
|
+
example: 'a base-64 encodable string'
|
|
1506
|
+
});
|
|
1507
|
+
file = z2
|
|
1508
|
+
.union([
|
|
1509
|
+
z2.instanceof(Buffer),
|
|
1510
|
+
z2.instanceof(ArrayBuffer),
|
|
1511
|
+
z2.instanceof(Blob),
|
|
1512
|
+
z2.string()
|
|
1513
|
+
])
|
|
1514
|
+
.transform((val) => {
|
|
1515
|
+
if (val instanceof Buffer) {
|
|
1516
|
+
return new Blob([val]);
|
|
1517
|
+
}
|
|
1518
|
+
if (val instanceof ArrayBuffer) {
|
|
1519
|
+
return new Blob([val]);
|
|
1520
|
+
}
|
|
1521
|
+
if (val instanceof Blob) {
|
|
1522
|
+
return val;
|
|
1523
|
+
}
|
|
1524
|
+
if (typeof val === 'string') {
|
|
1525
|
+
return new Blob([val]);
|
|
1526
|
+
}
|
|
1516
1527
|
return new Blob([val]);
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1528
|
+
})
|
|
1529
|
+
.refine((val) => val instanceof Blob, {
|
|
1530
|
+
message:
|
|
1531
|
+
'Invalid file type: expected Buffer, ArrayBuffer, Blob, or string'
|
|
1532
|
+
})
|
|
1533
|
+
.openapi({
|
|
1534
|
+
title: 'File',
|
|
1535
|
+
type: 'string',
|
|
1536
|
+
format: 'binary',
|
|
1537
|
+
example: 'a base-64 encodable blob or file'
|
|
1538
|
+
});
|
|
1527
1539
|
type = () => this.any;
|
|
1528
1540
|
/**
|
|
1529
1541
|
* Compiles schema if this exists, for optimal performance.
|
|
@@ -1540,7 +1552,11 @@ var ZodSchemaValidator = class {
|
|
|
1540
1552
|
* @returns {ZodResolve<T>} The resolved schema.
|
|
1541
1553
|
*/
|
|
1542
1554
|
schemify(schema) {
|
|
1543
|
-
if (
|
|
1555
|
+
if (
|
|
1556
|
+
typeof schema === 'string' ||
|
|
1557
|
+
typeof schema === 'number' ||
|
|
1558
|
+
typeof schema === 'boolean'
|
|
1559
|
+
) {
|
|
1544
1560
|
return z2.literal(schema);
|
|
1545
1561
|
}
|
|
1546
1562
|
if (schema instanceof ZodType) {
|
|
@@ -1581,9 +1597,7 @@ var ZodSchemaValidator = class {
|
|
|
1581
1597
|
*/
|
|
1582
1598
|
union(schemas) {
|
|
1583
1599
|
const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
|
|
1584
|
-
return z2.union(
|
|
1585
|
-
resolvedSchemas
|
|
1586
|
-
);
|
|
1600
|
+
return z2.union(resolvedSchemas);
|
|
1587
1601
|
}
|
|
1588
1602
|
/**
|
|
1589
1603
|
* Create a literal schema.
|
|
@@ -1599,9 +1613,7 @@ var ZodSchemaValidator = class {
|
|
|
1599
1613
|
* @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
|
|
1600
1614
|
*/
|
|
1601
1615
|
enum_(schemaEnum) {
|
|
1602
|
-
return this.union(
|
|
1603
|
-
Object.values(schemaEnum)
|
|
1604
|
-
);
|
|
1616
|
+
return this.union(Object.values(schemaEnum));
|
|
1605
1617
|
}
|
|
1606
1618
|
/**
|
|
1607
1619
|
* Create a function schema.
|
|
@@ -1670,31 +1682,33 @@ var ZodSchemaValidator = class {
|
|
|
1670
1682
|
parse(schema, value) {
|
|
1671
1683
|
const resolvedSchema = this.schemify(schema);
|
|
1672
1684
|
const result = resolvedSchema.safeParse(value);
|
|
1673
|
-
return result.success
|
|
1674
|
-
ok:
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1685
|
+
return result.success
|
|
1686
|
+
? { ok: true, value: result.data }
|
|
1687
|
+
: {
|
|
1688
|
+
ok: false,
|
|
1689
|
+
errors: result.error.errors.flatMap((error) => {
|
|
1690
|
+
switch (error.code) {
|
|
1691
|
+
case 'invalid_union':
|
|
1692
|
+
return error.unionErrors.flatMap((unionError, idx) =>
|
|
1693
|
+
unionError.errors.map((e) => ({
|
|
1694
|
+
path: [
|
|
1695
|
+
`Union Schema Variant ${idx}`,
|
|
1696
|
+
...error.path.map((p) => p.toString()),
|
|
1697
|
+
...e.path.map((p) => p.toString())
|
|
1698
|
+
],
|
|
1699
|
+
message: e.message
|
|
1700
|
+
}))
|
|
1701
|
+
);
|
|
1702
|
+
default:
|
|
1703
|
+
return [
|
|
1704
|
+
{
|
|
1705
|
+
path: error.path.map((p) => p.toString()),
|
|
1706
|
+
message: error.message
|
|
1707
|
+
}
|
|
1708
|
+
];
|
|
1709
|
+
}
|
|
1710
|
+
})
|
|
1711
|
+
};
|
|
1698
1712
|
}
|
|
1699
1713
|
/**
|
|
1700
1714
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -1753,6 +1767,4 @@ var RedisWorkerSchemas = serviceSchemaResolver(
|
|
|
1753
1767
|
() => RedisWorkerOptionsSchema,
|
|
1754
1768
|
() => RedisWorkerOptionsSchema2
|
|
1755
1769
|
);
|
|
1756
|
-
export {
|
|
1757
|
-
RedisWorkerSchemas
|
|
1758
|
-
};
|
|
1770
|
+
export { RedisWorkerSchemas };
|