@forklaunch/implementation-worker-kafka 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 +27 -15
- package/lib/consumers/index.mjs +16 -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 +13 -8
- package/lib/producers/index.mjs +2 -4
- 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/kafka.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
|
}
|
|
@@ -738,46 +770,55 @@ var KafkaWorkerOptionsSchema = {
|
|
|
738
770
|
peekCount: number
|
|
739
771
|
};
|
|
740
772
|
|
|
741
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
742
|
-
import {
|
|
743
|
-
z as z2,
|
|
744
|
-
ZodType
|
|
745
|
-
} from "zod/v3";
|
|
773
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
774
|
+
import { z as z2, ZodType } from 'zod/v3';
|
|
746
775
|
|
|
747
776
|
// ../../../node_modules/.pnpm/ts-deepmerge@7.0.3/node_modules/ts-deepmerge/esm/index.js
|
|
748
777
|
var isObject = (obj) => {
|
|
749
|
-
if (typeof obj ===
|
|
750
|
-
if (typeof Object.getPrototypeOf ===
|
|
778
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
779
|
+
if (typeof Object.getPrototypeOf === 'function') {
|
|
751
780
|
const prototype = Object.getPrototypeOf(obj);
|
|
752
781
|
return prototype === Object.prototype || prototype === null;
|
|
753
782
|
}
|
|
754
|
-
return Object.prototype.toString.call(obj) ===
|
|
783
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
755
784
|
}
|
|
756
785
|
return false;
|
|
757
786
|
};
|
|
758
|
-
var merge = (...objects) =>
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
if (Array.isArray(current)) {
|
|
763
|
-
throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
|
|
764
|
-
}
|
|
765
|
-
Object.keys(current).forEach((key) => {
|
|
766
|
-
if (["__proto__", "constructor", "prototype"].includes(key)) {
|
|
767
|
-
return;
|
|
787
|
+
var merge = (...objects) =>
|
|
788
|
+
objects.reduce((result, current) => {
|
|
789
|
+
if (current === void 0) {
|
|
790
|
+
return result;
|
|
768
791
|
}
|
|
769
|
-
if (Array.isArray(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
774
|
-
result[key] = merge(current[key], void 0);
|
|
775
|
-
} else {
|
|
776
|
-
result[key] = current[key] === void 0 ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
|
|
792
|
+
if (Array.isArray(current)) {
|
|
793
|
+
throw new TypeError(
|
|
794
|
+
'Arguments provided to ts-deepmerge must be objects, not arrays.'
|
|
795
|
+
);
|
|
777
796
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
797
|
+
Object.keys(current).forEach((key) => {
|
|
798
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key)) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
|
|
802
|
+
result[key] = merge.options.mergeArrays
|
|
803
|
+
? merge.options.uniqueArrayItems
|
|
804
|
+
? Array.from(new Set(result[key].concat(current[key])))
|
|
805
|
+
: [...result[key], ...current[key]]
|
|
806
|
+
: current[key];
|
|
807
|
+
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
808
|
+
result[key] = merge(result[key], current[key]);
|
|
809
|
+
} else if (!isObject(result[key]) && isObject(current[key])) {
|
|
810
|
+
result[key] = merge(current[key], void 0);
|
|
811
|
+
} else {
|
|
812
|
+
result[key] =
|
|
813
|
+
current[key] === void 0
|
|
814
|
+
? merge.options.allowUndefinedOverrides
|
|
815
|
+
? current[key]
|
|
816
|
+
: result[key]
|
|
817
|
+
: current[key];
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
return result;
|
|
821
|
+
}, {});
|
|
781
822
|
var defaultOptions = {
|
|
782
823
|
allowUndefinedOverrides: true,
|
|
783
824
|
mergeArrays: true,
|
|
@@ -791,8 +832,8 @@ merge.withOptions = (options, ...objects) => {
|
|
|
791
832
|
return result;
|
|
792
833
|
};
|
|
793
834
|
|
|
794
|
-
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.
|
|
795
|
-
import { z } from
|
|
835
|
+
// ../../../node_modules/.pnpm/@forklaunch+validator@1.2.12/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
|
|
836
|
+
import { z } from 'zod/v3';
|
|
796
837
|
function extendApi(schema, schemaObject = {}) {
|
|
797
838
|
const This = schema.constructor;
|
|
798
839
|
const newSchema = new This(schema._def);
|
|
@@ -809,89 +850,96 @@ function iterateZodObject({
|
|
|
809
850
|
hideDefinitions,
|
|
810
851
|
openApiVersion
|
|
811
852
|
}) {
|
|
812
|
-
const reduced = Object.keys(zodRef.shape)
|
|
813
|
-
(
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
853
|
+
const reduced = Object.keys(zodRef.shape)
|
|
854
|
+
.filter((key) => hideDefinitions?.includes(key) === false)
|
|
855
|
+
.reduce(
|
|
856
|
+
(carry, key) => ({
|
|
857
|
+
...carry,
|
|
858
|
+
[key]: generateSchema(zodRef.shape[key], useOutput, openApiVersion)
|
|
859
|
+
}),
|
|
860
|
+
{}
|
|
861
|
+
);
|
|
819
862
|
return reduced;
|
|
820
863
|
}
|
|
821
864
|
function typeFormat(type22, openApiVersion) {
|
|
822
|
-
return openApiVersion ===
|
|
865
|
+
return openApiVersion === '3.0' ? type22 : [type22];
|
|
823
866
|
}
|
|
824
|
-
function parseTransformation({
|
|
825
|
-
zodRef,
|
|
826
|
-
schemas,
|
|
827
|
-
useOutput,
|
|
828
|
-
openApiVersion
|
|
829
|
-
}) {
|
|
867
|
+
function parseTransformation({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
830
868
|
const input = generateSchema(zodRef._def.schema, useOutput, openApiVersion);
|
|
831
|
-
let output =
|
|
869
|
+
let output = 'undefined';
|
|
832
870
|
if (useOutput && zodRef._def.effect) {
|
|
833
|
-
const effect =
|
|
834
|
-
|
|
871
|
+
const effect =
|
|
872
|
+
zodRef._def.effect.type === 'transform' ? zodRef._def.effect : null;
|
|
873
|
+
if (effect && 'transform' in effect) {
|
|
835
874
|
try {
|
|
836
875
|
const type22 = Array.isArray(input.type) ? input.type[0] : input.type;
|
|
837
876
|
output = typeof effect.transform(
|
|
838
|
-
[
|
|
877
|
+
['integer', 'number'].includes(`${type22}`)
|
|
878
|
+
? 0
|
|
879
|
+
: 'string' === type22
|
|
880
|
+
? ''
|
|
881
|
+
: 'boolean' === type22
|
|
882
|
+
? false
|
|
883
|
+
: 'object' === type22
|
|
884
|
+
? {}
|
|
885
|
+
: 'null' === type22
|
|
886
|
+
? null
|
|
887
|
+
: 'array' === type22
|
|
888
|
+
? []
|
|
889
|
+
: void 0,
|
|
839
890
|
{ addIssue: () => void 0, path: [] }
|
|
840
891
|
// TODO: Discover if context is necessary here
|
|
841
892
|
);
|
|
842
|
-
} catch {
|
|
843
|
-
}
|
|
893
|
+
} catch {}
|
|
844
894
|
}
|
|
845
895
|
}
|
|
846
896
|
const outputType = output;
|
|
847
897
|
return merge(
|
|
848
898
|
{
|
|
849
|
-
...zodRef.description ? { description: zodRef.description } : {},
|
|
899
|
+
...(zodRef.description ? { description: zodRef.description } : {}),
|
|
850
900
|
...input,
|
|
851
|
-
...[
|
|
852
|
-
|
|
853
|
-
|
|
901
|
+
...(['number', 'string', 'boolean', 'null'].includes(output)
|
|
902
|
+
? {
|
|
903
|
+
type: typeFormat(outputType, openApiVersion)
|
|
904
|
+
}
|
|
905
|
+
: {})
|
|
854
906
|
},
|
|
855
907
|
...schemas
|
|
856
908
|
);
|
|
857
909
|
}
|
|
858
|
-
function parseString({
|
|
859
|
-
zodRef,
|
|
860
|
-
schemas,
|
|
861
|
-
openApiVersion
|
|
862
|
-
}) {
|
|
910
|
+
function parseString({ zodRef, schemas, openApiVersion }) {
|
|
863
911
|
const baseSchema = {
|
|
864
|
-
type: typeFormat(
|
|
912
|
+
type: typeFormat('string', openApiVersion)
|
|
865
913
|
};
|
|
866
914
|
const { checks = [] } = zodRef._def;
|
|
867
915
|
checks.forEach((item) => {
|
|
868
916
|
switch (item.kind) {
|
|
869
|
-
case
|
|
870
|
-
baseSchema.format =
|
|
917
|
+
case 'email':
|
|
918
|
+
baseSchema.format = 'email';
|
|
871
919
|
break;
|
|
872
|
-
case
|
|
873
|
-
baseSchema.format =
|
|
920
|
+
case 'uuid':
|
|
921
|
+
baseSchema.format = 'uuid';
|
|
874
922
|
break;
|
|
875
|
-
case
|
|
876
|
-
baseSchema.format =
|
|
923
|
+
case 'cuid':
|
|
924
|
+
baseSchema.format = 'cuid';
|
|
877
925
|
break;
|
|
878
|
-
case
|
|
879
|
-
baseSchema.format =
|
|
926
|
+
case 'url':
|
|
927
|
+
baseSchema.format = 'uri';
|
|
880
928
|
break;
|
|
881
|
-
case
|
|
882
|
-
baseSchema.format =
|
|
929
|
+
case 'datetime':
|
|
930
|
+
baseSchema.format = 'date-time';
|
|
883
931
|
break;
|
|
884
|
-
case
|
|
932
|
+
case 'length':
|
|
885
933
|
baseSchema.minLength = item.value;
|
|
886
934
|
baseSchema.maxLength = item.value;
|
|
887
935
|
break;
|
|
888
|
-
case
|
|
936
|
+
case 'max':
|
|
889
937
|
baseSchema.maxLength = item.value;
|
|
890
938
|
break;
|
|
891
|
-
case
|
|
939
|
+
case 'min':
|
|
892
940
|
baseSchema.minLength = item.value;
|
|
893
941
|
break;
|
|
894
|
-
case
|
|
942
|
+
case 'regex':
|
|
895
943
|
baseSchema.pattern = item.regex.source;
|
|
896
944
|
break;
|
|
897
945
|
}
|
|
@@ -902,45 +950,41 @@ function parseString({
|
|
|
902
950
|
...schemas
|
|
903
951
|
);
|
|
904
952
|
}
|
|
905
|
-
function parseNumber({
|
|
906
|
-
zodRef,
|
|
907
|
-
schemas,
|
|
908
|
-
openApiVersion
|
|
909
|
-
}) {
|
|
953
|
+
function parseNumber({ zodRef, schemas, openApiVersion }) {
|
|
910
954
|
const baseSchema = {
|
|
911
|
-
type: typeFormat(
|
|
955
|
+
type: typeFormat('number', openApiVersion)
|
|
912
956
|
};
|
|
913
957
|
const { checks = [] } = zodRef._def;
|
|
914
958
|
checks.forEach((item) => {
|
|
915
959
|
switch (item.kind) {
|
|
916
|
-
case
|
|
917
|
-
if (item.inclusive || openApiVersion ===
|
|
960
|
+
case 'max':
|
|
961
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
918
962
|
baseSchema.maximum = item.value;
|
|
919
963
|
}
|
|
920
964
|
if (!item.inclusive) {
|
|
921
|
-
if (openApiVersion ===
|
|
965
|
+
if (openApiVersion === '3.0') {
|
|
922
966
|
baseSchema.exclusiveMaximum = true;
|
|
923
967
|
} else {
|
|
924
968
|
baseSchema.exclusiveMaximum = item.value;
|
|
925
969
|
}
|
|
926
970
|
}
|
|
927
971
|
break;
|
|
928
|
-
case
|
|
929
|
-
if (item.inclusive || openApiVersion ===
|
|
972
|
+
case 'min':
|
|
973
|
+
if (item.inclusive || openApiVersion === '3.0') {
|
|
930
974
|
baseSchema.minimum = item.value;
|
|
931
975
|
}
|
|
932
976
|
if (!item.inclusive) {
|
|
933
|
-
if (openApiVersion ===
|
|
977
|
+
if (openApiVersion === '3.0') {
|
|
934
978
|
baseSchema.exclusiveMinimum = true;
|
|
935
979
|
} else {
|
|
936
980
|
baseSchema.exclusiveMinimum = item.value;
|
|
937
981
|
}
|
|
938
982
|
}
|
|
939
983
|
break;
|
|
940
|
-
case
|
|
941
|
-
baseSchema.type = typeFormat(
|
|
984
|
+
case 'int':
|
|
985
|
+
baseSchema.type = typeFormat('integer', openApiVersion);
|
|
942
986
|
break;
|
|
943
|
-
case
|
|
987
|
+
case 'multipleOf':
|
|
944
988
|
baseSchema.multipleOf = item.value;
|
|
945
989
|
break;
|
|
946
990
|
}
|
|
@@ -968,26 +1012,37 @@ function parseObject({
|
|
|
968
1012
|
openApiVersion
|
|
969
1013
|
}) {
|
|
970
1014
|
let additionalProperties;
|
|
971
|
-
if (
|
|
1015
|
+
if (
|
|
1016
|
+
!(
|
|
1017
|
+
zodRef._def.catchall instanceof z.ZodNever ||
|
|
1018
|
+
zodRef._def.catchall?._def.typeName === 'ZodNever'
|
|
1019
|
+
)
|
|
1020
|
+
)
|
|
972
1021
|
additionalProperties = generateSchema(
|
|
973
1022
|
zodRef._def.catchall,
|
|
974
1023
|
useOutput,
|
|
975
1024
|
openApiVersion
|
|
976
1025
|
);
|
|
977
|
-
else if (zodRef._def.unknownKeys ===
|
|
1026
|
+
else if (zodRef._def.unknownKeys === 'passthrough')
|
|
978
1027
|
additionalProperties = true;
|
|
979
|
-
else if (zodRef._def.unknownKeys ===
|
|
980
|
-
additionalProperties =
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
).filter((key) => {
|
|
1028
|
+
else if (zodRef._def.unknownKeys === 'strict') additionalProperties = false;
|
|
1029
|
+
additionalProperties =
|
|
1030
|
+
additionalProperties != null ? { additionalProperties } : {};
|
|
1031
|
+
const requiredProperties = Object.keys(zodRef.shape).filter((key) => {
|
|
984
1032
|
const item = zodRef.shape[key];
|
|
985
|
-
return
|
|
1033
|
+
return (
|
|
1034
|
+
!(
|
|
1035
|
+
item.isOptional() ||
|
|
1036
|
+
item instanceof z.ZodDefault ||
|
|
1037
|
+
item._def.typeName === 'ZodDefault'
|
|
1038
|
+
) && !(item instanceof z.ZodNever || item._def.typeName === 'ZodDefault')
|
|
1039
|
+
);
|
|
986
1040
|
});
|
|
987
|
-
const required =
|
|
1041
|
+
const required =
|
|
1042
|
+
requiredProperties.length > 0 ? { required: requiredProperties } : {};
|
|
988
1043
|
return merge(
|
|
989
1044
|
{
|
|
990
|
-
type: typeFormat(
|
|
1045
|
+
type: typeFormat('object', openApiVersion),
|
|
991
1046
|
properties: iterateZodObject({
|
|
992
1047
|
zodRef,
|
|
993
1048
|
schemas,
|
|
@@ -999,110 +1054,83 @@ function parseObject({
|
|
|
999
1054
|
...additionalProperties,
|
|
1000
1055
|
...hideDefinitions
|
|
1001
1056
|
},
|
|
1002
|
-
zodRef.description
|
|
1057
|
+
zodRef.description
|
|
1058
|
+
? { description: zodRef.description, hideDefinitions }
|
|
1059
|
+
: {},
|
|
1003
1060
|
...schemas
|
|
1004
1061
|
);
|
|
1005
1062
|
}
|
|
1006
|
-
function parseRecord({
|
|
1007
|
-
zodRef,
|
|
1008
|
-
schemas,
|
|
1009
|
-
useOutput,
|
|
1010
|
-
openApiVersion
|
|
1011
|
-
}) {
|
|
1063
|
+
function parseRecord({ zodRef, schemas, useOutput, openApiVersion }) {
|
|
1012
1064
|
return merge(
|
|
1013
1065
|
{
|
|
1014
|
-
type: typeFormat(
|
|
1015
|
-
additionalProperties:
|
|
1066
|
+
type: typeFormat('object', openApiVersion),
|
|
1067
|
+
additionalProperties:
|
|
1068
|
+
zodRef._def.valueType instanceof z.ZodUnknown
|
|
1069
|
+
? {}
|
|
1070
|
+
: generateSchema(zodRef._def.valueType, useOutput, openApiVersion)
|
|
1016
1071
|
},
|
|
1017
1072
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1018
1073
|
...schemas
|
|
1019
1074
|
);
|
|
1020
1075
|
}
|
|
1021
|
-
function parseBigInt({
|
|
1022
|
-
zodRef,
|
|
1023
|
-
schemas,
|
|
1024
|
-
openApiVersion
|
|
1025
|
-
}) {
|
|
1076
|
+
function parseBigInt({ zodRef, schemas, openApiVersion }) {
|
|
1026
1077
|
return merge(
|
|
1027
1078
|
{
|
|
1028
|
-
type: typeFormat(
|
|
1029
|
-
format:
|
|
1079
|
+
type: typeFormat('integer', openApiVersion),
|
|
1080
|
+
format: 'int64'
|
|
1030
1081
|
},
|
|
1031
1082
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1032
1083
|
...schemas
|
|
1033
1084
|
);
|
|
1034
1085
|
}
|
|
1035
|
-
function parseBoolean({
|
|
1036
|
-
zodRef,
|
|
1037
|
-
schemas,
|
|
1038
|
-
openApiVersion
|
|
1039
|
-
}) {
|
|
1086
|
+
function parseBoolean({ zodRef, schemas, openApiVersion }) {
|
|
1040
1087
|
return merge(
|
|
1041
|
-
{ type: typeFormat(
|
|
1088
|
+
{ type: typeFormat('boolean', openApiVersion) },
|
|
1042
1089
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1043
1090
|
...schemas
|
|
1044
1091
|
);
|
|
1045
1092
|
}
|
|
1046
|
-
function parseDate({
|
|
1047
|
-
zodRef,
|
|
1048
|
-
schemas,
|
|
1049
|
-
openApiVersion
|
|
1050
|
-
}) {
|
|
1093
|
+
function parseDate({ zodRef, schemas, openApiVersion }) {
|
|
1051
1094
|
return merge(
|
|
1052
1095
|
{
|
|
1053
|
-
type: typeFormat(
|
|
1054
|
-
format:
|
|
1096
|
+
type: typeFormat('string', openApiVersion),
|
|
1097
|
+
format: 'date-time'
|
|
1055
1098
|
},
|
|
1056
1099
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1057
1100
|
...schemas
|
|
1058
1101
|
);
|
|
1059
1102
|
}
|
|
1060
|
-
function parseNull({
|
|
1061
|
-
zodRef,
|
|
1062
|
-
schemas,
|
|
1063
|
-
openApiVersion
|
|
1064
|
-
}) {
|
|
1103
|
+
function parseNull({ zodRef, schemas, openApiVersion }) {
|
|
1065
1104
|
return merge(
|
|
1066
|
-
openApiVersion ===
|
|
1067
|
-
type:
|
|
1068
|
-
|
|
1069
|
-
|
|
1105
|
+
openApiVersion === '3.0'
|
|
1106
|
+
? { type: 'null' }
|
|
1107
|
+
: {
|
|
1108
|
+
type: ['string', 'null'],
|
|
1109
|
+
enum: ['null']
|
|
1110
|
+
},
|
|
1070
1111
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1071
1112
|
...schemas
|
|
1072
1113
|
);
|
|
1073
1114
|
}
|
|
1074
|
-
function parseOptional({
|
|
1075
|
-
schemas,
|
|
1076
|
-
zodRef,
|
|
1077
|
-
useOutput,
|
|
1078
|
-
openApiVersion
|
|
1079
|
-
}) {
|
|
1115
|
+
function parseOptional({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1080
1116
|
return merge(
|
|
1081
1117
|
generateSchema(zodRef.unwrap(), useOutput, openApiVersion),
|
|
1082
1118
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1083
1119
|
...schemas
|
|
1084
1120
|
);
|
|
1085
1121
|
}
|
|
1086
|
-
function parseNullable({
|
|
1087
|
-
schemas,
|
|
1088
|
-
zodRef,
|
|
1089
|
-
useOutput,
|
|
1090
|
-
openApiVersion
|
|
1091
|
-
}) {
|
|
1122
|
+
function parseNullable({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1092
1123
|
const schema = generateSchema(zodRef.unwrap(), useOutput, openApiVersion);
|
|
1093
1124
|
return merge(
|
|
1094
1125
|
schema,
|
|
1095
|
-
openApiVersion ===
|
|
1126
|
+
openApiVersion === '3.0'
|
|
1127
|
+
? { nullable: true }
|
|
1128
|
+
: { type: typeFormat('null', openApiVersion) },
|
|
1096
1129
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1097
1130
|
...schemas
|
|
1098
1131
|
);
|
|
1099
1132
|
}
|
|
1100
|
-
function parseDefault({
|
|
1101
|
-
schemas,
|
|
1102
|
-
zodRef,
|
|
1103
|
-
useOutput,
|
|
1104
|
-
openApiVersion
|
|
1105
|
-
}) {
|
|
1133
|
+
function parseDefault({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1106
1134
|
return merge(
|
|
1107
1135
|
{
|
|
1108
1136
|
default: zodRef._def.defaultValue(),
|
|
@@ -1112,12 +1140,7 @@ function parseDefault({
|
|
|
1112
1140
|
...schemas
|
|
1113
1141
|
);
|
|
1114
1142
|
}
|
|
1115
|
-
function parseArray({
|
|
1116
|
-
schemas,
|
|
1117
|
-
zodRef,
|
|
1118
|
-
useOutput,
|
|
1119
|
-
openApiVersion
|
|
1120
|
-
}) {
|
|
1143
|
+
function parseArray({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1121
1144
|
const constraints = {};
|
|
1122
1145
|
if (zodRef._def.exactLength != null) {
|
|
1123
1146
|
constraints.minItems = zodRef._def.exactLength.value;
|
|
@@ -1129,7 +1152,7 @@ function parseArray({
|
|
|
1129
1152
|
constraints.maxItems = zodRef._def.maxLength.value;
|
|
1130
1153
|
return merge(
|
|
1131
1154
|
{
|
|
1132
|
-
type: typeFormat(
|
|
1155
|
+
type: typeFormat('array', openApiVersion),
|
|
1133
1156
|
items: generateSchema(zodRef.element, useOutput, openApiVersion),
|
|
1134
1157
|
...constraints
|
|
1135
1158
|
},
|
|
@@ -1137,11 +1160,7 @@ function parseArray({
|
|
|
1137
1160
|
...schemas
|
|
1138
1161
|
);
|
|
1139
1162
|
}
|
|
1140
|
-
function parseLiteral({
|
|
1141
|
-
schemas,
|
|
1142
|
-
zodRef,
|
|
1143
|
-
openApiVersion
|
|
1144
|
-
}) {
|
|
1163
|
+
function parseLiteral({ schemas, zodRef, openApiVersion }) {
|
|
1145
1164
|
const type22 = typeof zodRef._def.value;
|
|
1146
1165
|
return merge(
|
|
1147
1166
|
{
|
|
@@ -1152,11 +1171,7 @@ function parseLiteral({
|
|
|
1152
1171
|
...schemas
|
|
1153
1172
|
);
|
|
1154
1173
|
}
|
|
1155
|
-
function parseEnum({
|
|
1156
|
-
schemas,
|
|
1157
|
-
zodRef,
|
|
1158
|
-
openApiVersion
|
|
1159
|
-
}) {
|
|
1174
|
+
function parseEnum({ schemas, zodRef, openApiVersion }) {
|
|
1160
1175
|
const type22 = typeof Object.values(zodRef._def.values)[0];
|
|
1161
1176
|
return merge(
|
|
1162
1177
|
{
|
|
@@ -1167,12 +1182,7 @@ function parseEnum({
|
|
|
1167
1182
|
...schemas
|
|
1168
1183
|
);
|
|
1169
1184
|
}
|
|
1170
|
-
function parseIntersection({
|
|
1171
|
-
schemas,
|
|
1172
|
-
zodRef,
|
|
1173
|
-
useOutput,
|
|
1174
|
-
openApiVersion
|
|
1175
|
-
}) {
|
|
1185
|
+
function parseIntersection({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1176
1186
|
return merge(
|
|
1177
1187
|
{
|
|
1178
1188
|
allOf: [
|
|
@@ -1184,20 +1194,20 @@ function parseIntersection({
|
|
|
1184
1194
|
...schemas
|
|
1185
1195
|
);
|
|
1186
1196
|
}
|
|
1187
|
-
function parseUnion({
|
|
1188
|
-
schemas,
|
|
1189
|
-
zodRef,
|
|
1190
|
-
useOutput,
|
|
1191
|
-
openApiVersion
|
|
1192
|
-
}) {
|
|
1197
|
+
function parseUnion({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1193
1198
|
const contents = zodRef._def.options;
|
|
1194
|
-
if (
|
|
1195
|
-
(
|
|
1196
|
-
|
|
1197
|
-
|
|
1199
|
+
if (
|
|
1200
|
+
contents.reduce(
|
|
1201
|
+
(prev, content) => prev && content._def.typeName === 'ZodLiteral',
|
|
1202
|
+
true
|
|
1203
|
+
)
|
|
1204
|
+
) {
|
|
1198
1205
|
const literals = contents;
|
|
1199
1206
|
const type22 = literals.reduce(
|
|
1200
|
-
(prev, content) =>
|
|
1207
|
+
(prev, content) =>
|
|
1208
|
+
!prev || prev === typeof content._def.value
|
|
1209
|
+
? typeof content._def.value
|
|
1210
|
+
: null,
|
|
1201
1211
|
null
|
|
1202
1212
|
);
|
|
1203
1213
|
if (type22) {
|
|
@@ -1211,12 +1221,15 @@ function parseUnion({
|
|
|
1211
1221
|
);
|
|
1212
1222
|
}
|
|
1213
1223
|
}
|
|
1214
|
-
const oneOfContents =
|
|
1224
|
+
const oneOfContents =
|
|
1225
|
+
openApiVersion === '3.0'
|
|
1226
|
+
? contents.filter((content) => content._def.typeName !== 'ZodNull')
|
|
1227
|
+
: contents;
|
|
1215
1228
|
const contentsHasNull = contents.length != oneOfContents.length;
|
|
1216
1229
|
return merge(
|
|
1217
1230
|
{
|
|
1218
|
-
oneOf: oneOfContents.map(
|
|
1219
|
-
|
|
1231
|
+
oneOf: oneOfContents.map((schema) =>
|
|
1232
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1220
1233
|
)
|
|
1221
1234
|
},
|
|
1222
1235
|
contentsHasNull ? { nullable: true } : {},
|
|
@@ -1235,50 +1248,34 @@ function parseDiscriminatedUnion({
|
|
|
1235
1248
|
discriminator: {
|
|
1236
1249
|
propertyName: zodRef._def.discriminator
|
|
1237
1250
|
},
|
|
1238
|
-
oneOf: Array.from(
|
|
1239
|
-
|
|
1240
|
-
)
|
|
1251
|
+
oneOf: Array.from(zodRef._def.options.values()).map((schema) =>
|
|
1252
|
+
generateSchema(schema, useOutput, openApiVersion)
|
|
1253
|
+
)
|
|
1241
1254
|
},
|
|
1242
1255
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1243
1256
|
...schemas
|
|
1244
1257
|
);
|
|
1245
1258
|
}
|
|
1246
|
-
function parseNever({
|
|
1247
|
-
zodRef,
|
|
1248
|
-
schemas
|
|
1249
|
-
}) {
|
|
1259
|
+
function parseNever({ zodRef, schemas }) {
|
|
1250
1260
|
return merge(
|
|
1251
1261
|
{ readOnly: true },
|
|
1252
1262
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1253
1263
|
...schemas
|
|
1254
1264
|
);
|
|
1255
1265
|
}
|
|
1256
|
-
function parseBranded({
|
|
1257
|
-
schemas,
|
|
1258
|
-
zodRef,
|
|
1259
|
-
useOutput,
|
|
1260
|
-
openApiVersion
|
|
1261
|
-
}) {
|
|
1266
|
+
function parseBranded({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1262
1267
|
return merge(
|
|
1263
1268
|
generateSchema(zodRef._def.type, useOutput, openApiVersion),
|
|
1264
1269
|
...schemas
|
|
1265
1270
|
);
|
|
1266
1271
|
}
|
|
1267
|
-
function catchAllParser({
|
|
1268
|
-
zodRef,
|
|
1269
|
-
schemas
|
|
1270
|
-
}) {
|
|
1272
|
+
function catchAllParser({ zodRef, schemas }) {
|
|
1271
1273
|
return merge(
|
|
1272
1274
|
zodRef.description ? { description: zodRef.description } : {},
|
|
1273
1275
|
...schemas
|
|
1274
1276
|
);
|
|
1275
1277
|
}
|
|
1276
|
-
function parsePipeline({
|
|
1277
|
-
schemas,
|
|
1278
|
-
zodRef,
|
|
1279
|
-
useOutput,
|
|
1280
|
-
openApiVersion
|
|
1281
|
-
}) {
|
|
1278
|
+
function parsePipeline({ schemas, zodRef, useOutput, openApiVersion }) {
|
|
1282
1279
|
return merge(
|
|
1283
1280
|
generateSchema(
|
|
1284
1281
|
useOutput ? zodRef._def.out : zodRef._def.in,
|
|
@@ -1288,12 +1285,7 @@ function parsePipeline({
|
|
|
1288
1285
|
...schemas
|
|
1289
1286
|
);
|
|
1290
1287
|
}
|
|
1291
|
-
function parseReadonly({
|
|
1292
|
-
zodRef,
|
|
1293
|
-
useOutput,
|
|
1294
|
-
schemas,
|
|
1295
|
-
openApiVersion
|
|
1296
|
-
}) {
|
|
1288
|
+
function parseReadonly({ zodRef, useOutput, schemas, openApiVersion }) {
|
|
1297
1289
|
return merge(
|
|
1298
1290
|
generateSchema(zodRef._def.innerType, useOutput, openApiVersion),
|
|
1299
1291
|
zodRef.description ? { description: zodRef.description } : {},
|
|
@@ -1337,10 +1329,10 @@ var workerMap = {
|
|
|
1337
1329
|
ZodPipeline: parsePipeline,
|
|
1338
1330
|
ZodReadonly: parseReadonly
|
|
1339
1331
|
};
|
|
1340
|
-
function generateSchema(zodRef, useOutput = false, openApiVersion =
|
|
1332
|
+
function generateSchema(zodRef, useOutput = false, openApiVersion = '3.1') {
|
|
1341
1333
|
const { metaOpenApi = {} } = zodRef;
|
|
1342
1334
|
const schemas = [
|
|
1343
|
-
...Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi]
|
|
1335
|
+
...(Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi])
|
|
1344
1336
|
];
|
|
1345
1337
|
try {
|
|
1346
1338
|
const typeName = zodRef._def.typeName;
|
|
@@ -1359,174 +1351,194 @@ function generateSchema(zodRef, useOutput = false, openApiVersion = "3.1") {
|
|
|
1359
1351
|
}
|
|
1360
1352
|
}
|
|
1361
1353
|
function extendZodWithOpenApi(zod, forceOverride = false) {
|
|
1362
|
-
if (
|
|
1354
|
+
if (
|
|
1355
|
+
!forceOverride &&
|
|
1356
|
+
typeof zod.ZodSchema.prototype.openapi !== 'undefined'
|
|
1357
|
+
) {
|
|
1363
1358
|
return;
|
|
1364
1359
|
}
|
|
1365
|
-
zod.ZodSchema.prototype.openapi = function(metadata) {
|
|
1360
|
+
zod.ZodSchema.prototype.openapi = function (metadata) {
|
|
1366
1361
|
return extendApi(this, metadata);
|
|
1367
1362
|
};
|
|
1368
1363
|
}
|
|
1369
1364
|
extendZodWithOpenApi(z2);
|
|
1370
1365
|
var ZodSchemaValidator = class {
|
|
1371
|
-
_Type =
|
|
1366
|
+
_Type = 'Zod';
|
|
1372
1367
|
_SchemaCatchall;
|
|
1373
1368
|
_ValidSchemaObject;
|
|
1374
1369
|
string = z2.string().openapi({
|
|
1375
|
-
title:
|
|
1376
|
-
example:
|
|
1370
|
+
title: 'String',
|
|
1371
|
+
example: 'a string'
|
|
1377
1372
|
});
|
|
1378
1373
|
uuid = z2.string().uuid().openapi({
|
|
1379
|
-
title:
|
|
1380
|
-
format:
|
|
1381
|
-
pattern:
|
|
1382
|
-
|
|
1374
|
+
title: 'UUID',
|
|
1375
|
+
format: 'uuid',
|
|
1376
|
+
pattern:
|
|
1377
|
+
'^[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}$',
|
|
1378
|
+
example: 'a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6'
|
|
1383
1379
|
});
|
|
1384
1380
|
email = z2.string().email().openapi({
|
|
1385
|
-
title:
|
|
1386
|
-
format:
|
|
1387
|
-
pattern:
|
|
1388
|
-
example:
|
|
1381
|
+
title: 'Email',
|
|
1382
|
+
format: 'email',
|
|
1383
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
1384
|
+
example: 'a@b.com'
|
|
1389
1385
|
});
|
|
1390
1386
|
uri = z2.string().url().openapi({
|
|
1391
|
-
title:
|
|
1392
|
-
format:
|
|
1393
|
-
pattern:
|
|
1394
|
-
example:
|
|
1395
|
-
});
|
|
1396
|
-
number = z2.preprocess((value) => {
|
|
1397
|
-
try {
|
|
1398
|
-
return Number(value);
|
|
1399
|
-
} catch {
|
|
1400
|
-
return value;
|
|
1401
|
-
}
|
|
1402
|
-
}, z2.number()).openapi({
|
|
1403
|
-
title: "Number",
|
|
1404
|
-
example: 123
|
|
1387
|
+
title: 'URI',
|
|
1388
|
+
format: 'uri',
|
|
1389
|
+
pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
|
|
1390
|
+
example: 'https://forklaunch.com'
|
|
1405
1391
|
});
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
return
|
|
1392
|
+
number = z2
|
|
1393
|
+
.preprocess((value) => {
|
|
1394
|
+
try {
|
|
1395
|
+
return Number(value);
|
|
1396
|
+
} catch {
|
|
1397
|
+
return value;
|
|
1410
1398
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1399
|
+
}, z2.number())
|
|
1400
|
+
.openapi({
|
|
1401
|
+
title: 'Number',
|
|
1402
|
+
example: 123
|
|
1403
|
+
});
|
|
1404
|
+
bigint = z2
|
|
1405
|
+
.preprocess((value) => {
|
|
1406
|
+
try {
|
|
1407
|
+
if (value instanceof Date) {
|
|
1408
|
+
return BigInt(value.getTime());
|
|
1409
|
+
}
|
|
1410
|
+
switch (typeof value) {
|
|
1411
|
+
case 'number':
|
|
1412
|
+
case 'string':
|
|
1413
|
+
return BigInt(value);
|
|
1414
|
+
case 'boolean':
|
|
1415
|
+
return BigInt(value ? 1 : 0);
|
|
1416
|
+
default:
|
|
1417
|
+
return value;
|
|
1418
|
+
}
|
|
1419
|
+
} catch {
|
|
1420
|
+
return value;
|
|
1419
1421
|
}
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
if (val.toLowerCase() === "false") return false;
|
|
1433
|
-
}
|
|
1434
|
-
return val;
|
|
1435
|
-
}, z2.boolean()).openapi({
|
|
1436
|
-
title: "Boolean",
|
|
1437
|
-
example: true
|
|
1438
|
-
});
|
|
1439
|
-
date = z2.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;
|
|
1422
|
+
}, z2.bigint())
|
|
1423
|
+
.openapi({
|
|
1424
|
+
title: 'BigInt',
|
|
1425
|
+
type: 'integer',
|
|
1426
|
+
format: 'int64',
|
|
1427
|
+
example: 123n
|
|
1428
|
+
});
|
|
1429
|
+
boolean = z2
|
|
1430
|
+
.preprocess((val) => {
|
|
1431
|
+
if (typeof val === 'string') {
|
|
1432
|
+
if (val.toLowerCase() === 'true') return true;
|
|
1433
|
+
if (val.toLowerCase() === 'false') return false;
|
|
1448
1434
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1435
|
+
return val;
|
|
1436
|
+
}, z2.boolean())
|
|
1437
|
+
.openapi({
|
|
1438
|
+
title: 'Boolean',
|
|
1439
|
+
example: true
|
|
1440
|
+
});
|
|
1441
|
+
date = z2
|
|
1442
|
+
.preprocess((value) => {
|
|
1443
|
+
try {
|
|
1444
|
+
switch (typeof value) {
|
|
1445
|
+
case 'string':
|
|
1446
|
+
return new Date(value);
|
|
1447
|
+
case 'number':
|
|
1448
|
+
return new Date(value);
|
|
1449
|
+
default:
|
|
1450
|
+
return value;
|
|
1451
|
+
}
|
|
1452
|
+
} catch {
|
|
1453
|
+
return value;
|
|
1454
|
+
}
|
|
1455
|
+
}, z2.date())
|
|
1456
|
+
.openapi({
|
|
1457
|
+
title: 'Date',
|
|
1458
|
+
type: 'string',
|
|
1459
|
+
format: 'date-time',
|
|
1460
|
+
example: '2025-05-16T21:13:04.123Z'
|
|
1461
|
+
});
|
|
1458
1462
|
symbol = z2.symbol().openapi({
|
|
1459
|
-
title:
|
|
1460
|
-
example: /* @__PURE__ */ Symbol(
|
|
1463
|
+
title: 'Symbol',
|
|
1464
|
+
example: /* @__PURE__ */ Symbol('symbol')
|
|
1461
1465
|
});
|
|
1462
1466
|
nullish = z2.union([z2.void(), z2.null(), z2.undefined()]).openapi({
|
|
1463
|
-
title:
|
|
1464
|
-
type:
|
|
1467
|
+
title: 'Nullish',
|
|
1468
|
+
type: 'null',
|
|
1465
1469
|
example: null
|
|
1466
1470
|
});
|
|
1467
1471
|
void = z2.void().openapi({
|
|
1468
|
-
title:
|
|
1469
|
-
type:
|
|
1472
|
+
title: 'Void',
|
|
1473
|
+
type: 'null',
|
|
1470
1474
|
example: void 0
|
|
1471
1475
|
});
|
|
1472
1476
|
null = z2.null().openapi({
|
|
1473
|
-
title:
|
|
1474
|
-
type:
|
|
1477
|
+
title: 'Null',
|
|
1478
|
+
type: 'null',
|
|
1475
1479
|
example: null
|
|
1476
1480
|
});
|
|
1477
1481
|
undefined = z2.undefined().openapi({
|
|
1478
|
-
title:
|
|
1479
|
-
type:
|
|
1482
|
+
title: 'Undefined',
|
|
1483
|
+
type: 'null',
|
|
1480
1484
|
example: void 0
|
|
1481
1485
|
});
|
|
1482
1486
|
any = z2.any().openapi({
|
|
1483
|
-
title:
|
|
1484
|
-
type:
|
|
1485
|
-
example:
|
|
1487
|
+
title: 'Any',
|
|
1488
|
+
type: 'object',
|
|
1489
|
+
example: 'any'
|
|
1486
1490
|
});
|
|
1487
1491
|
unknown = z2.unknown().openapi({
|
|
1488
|
-
title:
|
|
1489
|
-
type:
|
|
1490
|
-
example:
|
|
1492
|
+
title: 'Unknown',
|
|
1493
|
+
type: 'object',
|
|
1494
|
+
example: 'unknown'
|
|
1491
1495
|
});
|
|
1492
1496
|
never = z2.never().openapi({
|
|
1493
|
-
title:
|
|
1494
|
-
type:
|
|
1495
|
-
example:
|
|
1496
|
-
});
|
|
1497
|
-
binary = z2.string().transform((val) => new Uint8Array(Buffer.from(val, "base64"))).openapi({
|
|
1498
|
-
title: "Binary",
|
|
1499
|
-
type: "string",
|
|
1500
|
-
format: "binary",
|
|
1501
|
-
example: "a base-64 encodable string"
|
|
1497
|
+
title: 'Never',
|
|
1498
|
+
type: 'null',
|
|
1499
|
+
example: 'never'
|
|
1502
1500
|
});
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1501
|
+
binary = z2
|
|
1502
|
+
.string()
|
|
1503
|
+
.transform((val) => new Uint8Array(Buffer.from(val, 'base64')))
|
|
1504
|
+
.openapi({
|
|
1505
|
+
title: 'Binary',
|
|
1506
|
+
type: 'string',
|
|
1507
|
+
format: 'binary',
|
|
1508
|
+
example: 'a base-64 encodable string'
|
|
1509
|
+
});
|
|
1510
|
+
file = z2
|
|
1511
|
+
.union([
|
|
1512
|
+
z2.instanceof(Buffer),
|
|
1513
|
+
z2.instanceof(ArrayBuffer),
|
|
1514
|
+
z2.instanceof(Blob),
|
|
1515
|
+
z2.string()
|
|
1516
|
+
])
|
|
1517
|
+
.transform((val) => {
|
|
1518
|
+
if (val instanceof Buffer) {
|
|
1519
|
+
return new Blob([val]);
|
|
1520
|
+
}
|
|
1521
|
+
if (val instanceof ArrayBuffer) {
|
|
1522
|
+
return new Blob([val]);
|
|
1523
|
+
}
|
|
1524
|
+
if (val instanceof Blob) {
|
|
1525
|
+
return val;
|
|
1526
|
+
}
|
|
1527
|
+
if (typeof val === 'string') {
|
|
1528
|
+
return new Blob([val]);
|
|
1529
|
+
}
|
|
1519
1530
|
return new Blob([val]);
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1531
|
+
})
|
|
1532
|
+
.refine((val) => val instanceof Blob, {
|
|
1533
|
+
message:
|
|
1534
|
+
'Invalid file type: expected Buffer, ArrayBuffer, Blob, or string'
|
|
1535
|
+
})
|
|
1536
|
+
.openapi({
|
|
1537
|
+
title: 'File',
|
|
1538
|
+
type: 'string',
|
|
1539
|
+
format: 'binary',
|
|
1540
|
+
example: 'a base-64 encodable blob or file'
|
|
1541
|
+
});
|
|
1530
1542
|
type = () => this.any;
|
|
1531
1543
|
/**
|
|
1532
1544
|
* Compiles schema if this exists, for optimal performance.
|
|
@@ -1543,7 +1555,11 @@ var ZodSchemaValidator = class {
|
|
|
1543
1555
|
* @returns {ZodResolve<T>} The resolved schema.
|
|
1544
1556
|
*/
|
|
1545
1557
|
schemify(schema) {
|
|
1546
|
-
if (
|
|
1558
|
+
if (
|
|
1559
|
+
typeof schema === 'string' ||
|
|
1560
|
+
typeof schema === 'number' ||
|
|
1561
|
+
typeof schema === 'boolean'
|
|
1562
|
+
) {
|
|
1547
1563
|
return z2.literal(schema);
|
|
1548
1564
|
}
|
|
1549
1565
|
if (schema instanceof ZodType) {
|
|
@@ -1584,9 +1600,7 @@ var ZodSchemaValidator = class {
|
|
|
1584
1600
|
*/
|
|
1585
1601
|
union(schemas) {
|
|
1586
1602
|
const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
|
|
1587
|
-
return z2.union(
|
|
1588
|
-
resolvedSchemas
|
|
1589
|
-
);
|
|
1603
|
+
return z2.union(resolvedSchemas);
|
|
1590
1604
|
}
|
|
1591
1605
|
/**
|
|
1592
1606
|
* Create a literal schema.
|
|
@@ -1602,9 +1616,7 @@ var ZodSchemaValidator = class {
|
|
|
1602
1616
|
* @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
|
|
1603
1617
|
*/
|
|
1604
1618
|
enum_(schemaEnum) {
|
|
1605
|
-
return this.union(
|
|
1606
|
-
Object.values(schemaEnum)
|
|
1607
|
-
);
|
|
1619
|
+
return this.union(Object.values(schemaEnum));
|
|
1608
1620
|
}
|
|
1609
1621
|
/**
|
|
1610
1622
|
* Create a function schema.
|
|
@@ -1673,31 +1685,33 @@ var ZodSchemaValidator = class {
|
|
|
1673
1685
|
parse(schema, value) {
|
|
1674
1686
|
const resolvedSchema = this.schemify(schema);
|
|
1675
1687
|
const result = resolvedSchema.safeParse(value);
|
|
1676
|
-
return result.success
|
|
1677
|
-
ok:
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1688
|
+
return result.success
|
|
1689
|
+
? { ok: true, value: result.data }
|
|
1690
|
+
: {
|
|
1691
|
+
ok: false,
|
|
1692
|
+
errors: result.error.errors.flatMap((error) => {
|
|
1693
|
+
switch (error.code) {
|
|
1694
|
+
case 'invalid_union':
|
|
1695
|
+
return error.unionErrors.flatMap((unionError, idx) =>
|
|
1696
|
+
unionError.errors.map((e) => ({
|
|
1697
|
+
path: [
|
|
1698
|
+
`Union Schema Variant ${idx}`,
|
|
1699
|
+
...error.path.map((p) => p.toString()),
|
|
1700
|
+
...e.path.map((p) => p.toString())
|
|
1701
|
+
],
|
|
1702
|
+
message: e.message
|
|
1703
|
+
}))
|
|
1704
|
+
);
|
|
1705
|
+
default:
|
|
1706
|
+
return [
|
|
1707
|
+
{
|
|
1708
|
+
path: error.path.map((p) => p.toString()),
|
|
1709
|
+
message: error.message
|
|
1710
|
+
}
|
|
1711
|
+
];
|
|
1712
|
+
}
|
|
1713
|
+
})
|
|
1714
|
+
};
|
|
1701
1715
|
}
|
|
1702
1716
|
/**
|
|
1703
1717
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -1759,6 +1773,4 @@ var KafkaWorkerSchemas = serviceSchemaResolver(
|
|
|
1759
1773
|
() => KafkaWorkerOptionsSchema,
|
|
1760
1774
|
() => KafkaWorkerOptionsSchema2
|
|
1761
1775
|
);
|
|
1762
|
-
export {
|
|
1763
|
-
KafkaWorkerSchemas
|
|
1764
|
-
};
|
|
1776
|
+
export { KafkaWorkerSchemas };
|