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