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