@forklaunch/implementation-worker-database 1.0.35 → 1.0.36

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.
@@ -1,1758 +1,15 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
-
19
1
  // domain/schemas/databaseWorker.schema.ts
20
2
  import { serviceSchemaResolver } from "@forklaunch/internal";
21
3
 
22
- // ../../../node_modules/.pnpm/@forklaunch+validator@1.2.27/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
23
- var typebox_exports = {};
24
- __export(typebox_exports, {
25
- SchemaValidator: () => SchemaValidator,
26
- TypeboxSchemaValidator: () => TypeboxSchemaValidator,
27
- any: () => any,
28
- array: () => array,
29
- bigint: () => bigint,
30
- binary: () => binary,
31
- boolean: () => boolean,
32
- date: () => date,
33
- email: () => email,
34
- enum_: () => enum_,
35
- file: () => file,
36
- function_: () => function_,
37
- isSchema: () => isSchema,
38
- literal: () => literal,
39
- never: () => never,
40
- null_: () => null_,
41
- nullish: () => nullish,
42
- number: () => number,
43
- openapi: () => openapi,
44
- optional: () => optional,
45
- parse: () => parse,
46
- promise: () => promise,
47
- record: () => record,
48
- schemify: () => schemify,
49
- string: () => string,
50
- symbol: () => symbol,
51
- type: () => type,
52
- undefined_: () => undefined_,
53
- union: () => union,
54
- unknown: () => unknown,
55
- uri: () => uri,
56
- uuid: () => uuid,
57
- validate: () => validate,
58
- void_: () => void_
59
- });
60
- __reExport(typebox_exports, typebox_star);
61
- import * as typebox_star from "@sinclair/typebox";
62
-
63
- // ../../../node_modules/.pnpm/@forklaunch+common@1.2.26/node_modules/@forklaunch/common/lib/index.mjs
64
- function deepCloneWithoutUndefined(obj, seen = /* @__PURE__ */ new WeakMap()) {
65
- if (obj === null || obj === void 0) {
66
- return obj;
67
- }
68
- if (typeof obj !== "object" && typeof obj !== "function") {
69
- return obj;
70
- }
71
- if (seen.has(obj)) {
72
- return seen.get(obj);
73
- }
74
- if (obj instanceof Date) {
75
- return new Date(obj.getTime());
76
- }
77
- if (obj instanceof RegExp) {
78
- return new RegExp(obj.source, obj.flags);
79
- }
80
- if (obj instanceof Map) {
81
- const clonedMap = /* @__PURE__ */ new Map();
82
- seen.set(obj, clonedMap);
83
- obj.forEach((value, key) => {
84
- if (value !== void 0) {
85
- clonedMap.set(key, deepCloneWithoutUndefined(value, seen));
86
- }
87
- });
88
- return clonedMap;
89
- }
90
- if (obj instanceof Set) {
91
- const clonedSet = /* @__PURE__ */ new Set();
92
- seen.set(obj, clonedSet);
93
- obj.forEach((value) => {
94
- if (value !== void 0) {
95
- clonedSet.add(deepCloneWithoutUndefined(value, seen));
96
- }
97
- });
98
- return clonedSet;
99
- }
100
- if (Array.isArray(obj)) {
101
- const clonedArray = [];
102
- seen.set(obj, clonedArray);
103
- for (const item of obj) {
104
- if (item !== void 0) {
105
- clonedArray.push(deepCloneWithoutUndefined(item, seen));
106
- }
107
- }
108
- return clonedArray;
109
- }
110
- if (typeof obj === "function") {
111
- return obj;
112
- }
113
- const proto = Object.getPrototypeOf(obj);
114
- const cloned = Object.create(proto);
115
- seen.set(obj, cloned);
116
- const allKeys = [
117
- ...Object.getOwnPropertyNames(obj),
118
- ...Object.getOwnPropertySymbols(obj)
119
- ];
120
- for (const key of allKeys) {
121
- const descriptor = Object.getOwnPropertyDescriptor(obj, key);
122
- if (!descriptor) continue;
123
- if ("value" in descriptor) {
124
- if (descriptor.value !== void 0) {
125
- Object.defineProperty(cloned, key, {
126
- ...descriptor,
127
- value: deepCloneWithoutUndefined(descriptor.value, seen)
128
- });
129
- }
130
- } else {
131
- Object.defineProperty(cloned, key, descriptor);
132
- }
133
- }
134
- return cloned;
135
- }
136
- var InMemoryBlob = class extends Blob {
137
- constructor(content) {
138
- super([content]);
139
- this.content = content;
140
- }
141
- content;
142
- };
143
-
144
- // ../../../node_modules/.pnpm/@forklaunch+validator@1.2.27/node_modules/@forklaunch/validator/lib/src/typebox/index.mjs
145
- import {
146
- FormatRegistry,
147
- Kind,
148
- KindGuard,
149
- Type,
150
- TypeRegistry
151
- } from "@sinclair/typebox";
152
- import { TypeCheck, TypeCompiler } from "@sinclair/typebox/compiler";
153
- import {
154
- DefaultErrorFunction,
155
- SetErrorFunction,
156
- ValueErrorType
157
- } from "@sinclair/typebox/errors";
158
- import { Value } from "@sinclair/typebox/value";
159
- FormatRegistry.Set("binary", (value) => typeof value === "string");
160
- TypeRegistry.Set("Blob", (_schema, value) => value instanceof Blob);
161
- TypeRegistry.Set(
162
- "ArrayBuffer",
163
- (_schema, value) => value instanceof ArrayBuffer
164
- );
165
- TypeRegistry.Set("Buffer", (_schema, value) => value instanceof Buffer);
166
- SetErrorFunction((params) => {
167
- switch (params.errorType) {
168
- case ValueErrorType.Union:
169
- case ValueErrorType.Array:
170
- case ValueErrorType.String:
171
- case ValueErrorType.Number:
172
- return params.schema.errorType ? `Expected ${params.schema.errorType} value${params.schema.errorSuffix ? "s" : ""}` : DefaultErrorFunction(params);
173
- default:
174
- return DefaultErrorFunction(params);
175
- }
176
- });
177
- var TypeboxSchemaValidator = class {
178
- _Type = "TypeBox";
179
- _SchemaCatchall;
180
- _ValidSchemaObject;
181
- string = Type.String({
182
- example: "a string",
183
- title: "String"
184
- });
185
- uuid = Type.String({
186
- 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}$",
187
- errorType: "uuid",
188
- example: "a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
189
- title: "UUID"
190
- });
191
- email = Type.String({
192
- pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
193
- errorType: "email",
194
- example: "a@b.com",
195
- title: "Email"
196
- });
197
- uri = Type.String({
198
- pattern: "^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$",
199
- errorType: "uri",
200
- example: "https://forklaunch.com",
201
- title: "URI"
202
- });
203
- number = Type.Transform(
204
- Type.Union(
205
- [
206
- Type.Number(),
207
- Type.String({ pattern: "^[0-9]+$" }),
208
- Type.Boolean(),
209
- Type.Null(),
210
- Type.BigInt(),
211
- Type.Date()
212
- ],
213
- {
214
- errorType: "number-like",
215
- example: 123,
216
- title: "Number"
217
- }
218
- )
219
- ).Decode((value) => {
220
- if (typeof value !== "number") {
221
- const num = Number(value);
222
- if (isNaN(num)) {
223
- throw new Error("Invalid number");
224
- } else {
225
- return num;
226
- }
227
- }
228
- return value;
229
- }).Encode(Number);
230
- bigint = Type.Transform(
231
- Type.Union(
232
- [
233
- Type.BigInt(),
234
- Type.Number(),
235
- Type.String({ pattern: "^[0-9]+n?$" }),
236
- Type.Boolean(),
237
- Type.Date()
238
- ],
239
- {
240
- errorType: "BigInt-like",
241
- example: 123n,
242
- title: "BigInt"
243
- }
244
- )
245
- ).Decode((value) => {
246
- if (typeof value !== "bigint") {
247
- try {
248
- if (value instanceof Date) {
249
- return BigInt(value.getTime());
250
- }
251
- return BigInt(value);
252
- } catch {
253
- throw new Error("Invalid bigint");
254
- }
255
- }
256
- return value;
257
- }).Encode(BigInt);
258
- boolean = Type.Transform(
259
- Type.Union(
260
- [
261
- Type.Boolean(),
262
- Type.String({
263
- pattern: "^(t|T)(r|R)(u|U)(e|E)$|^(f|F)(a|A)(l|L)(s|S)(e|E)$"
264
- })
265
- ],
266
- {
267
- errorType: "boolean-like",
268
- example: true,
269
- title: "Boolean"
270
- }
271
- )
272
- ).Decode((value) => {
273
- if (typeof value === "string") {
274
- if (value.toLowerCase() === "true") return true;
275
- return false;
276
- } else {
277
- return value;
278
- }
279
- }).Encode(Boolean);
280
- date = Type.Transform(
281
- Type.Union(
282
- [
283
- Type.String({
284
- 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+$"
285
- }),
286
- Type.Number(),
287
- Type.Date()
288
- ],
289
- {
290
- errorType: "date",
291
- example: "2025-05-16T21:13:04.123Z",
292
- title: "Date"
293
- }
294
- )
295
- ).Decode((value) => {
296
- if (value === null || typeof value === "boolean") {
297
- return /* @__PURE__ */ new Date(value ? 1 : 0);
298
- }
299
- return new Date(value);
300
- }).Encode((value) => new Date(value).toISOString());
301
- symbol = Type.Symbol({
302
- title: "Symbol"
303
- });
304
- nullish = Type.Union(
305
- [Type.Void(), Type.Null(), Type.Undefined()],
306
- {
307
- errorType: "nullish",
308
- type: "null",
309
- example: "null",
310
- title: "Nullish"
311
- }
312
- );
313
- void = Type.Void({
314
- type: "null",
315
- example: "void",
316
- title: "Void"
317
- });
318
- null = Type.Null({
319
- type: "null",
320
- example: "null",
321
- title: "Null"
322
- });
323
- undefined = Type.Undefined({
324
- type: "null",
325
- example: "undefined",
326
- title: "Undefined"
327
- });
328
- any = Type.Any({
329
- type: "object",
330
- example: "any",
331
- title: "Any"
332
- });
333
- unknown = Type.Unknown({
334
- type: "object",
335
- example: "unknown",
336
- title: "Unknown"
337
- });
338
- never = Type.Never({
339
- type: "null",
340
- example: "never",
341
- title: "Never"
342
- });
343
- binary = Type.Transform(
344
- Type.String({
345
- errorType: "binary",
346
- format: "binary",
347
- example: "a base-64 encodable string",
348
- title: "Binary"
349
- })
350
- ).Decode((value) => new Uint8Array(Buffer.from(value, "base64"))).Encode((value) => {
351
- if (value instanceof Buffer) {
352
- return String.fromCharCode(...new Uint8Array(value));
353
- }
354
- return "";
355
- });
356
- file = Type.Transform(
357
- Type.Union([
358
- Type.Unsafe({
359
- [Kind]: "Buffer",
360
- errorType: "binary",
361
- format: "binary",
362
- example: "a raw buffer or file stream",
363
- title: "File"
364
- }),
365
- Type.Unsafe({
366
- [Kind]: "ArrayBuffer",
367
- errorType: "binary",
368
- format: "binary",
369
- example: "an array buffer",
370
- title: "File"
371
- }),
372
- Type.Unsafe({
373
- [Kind]: "Blob",
374
- errorType: "binary",
375
- format: "binary",
376
- example: "a blob object",
377
- title: "File"
378
- }),
379
- Type.String({
380
- errorType: "binary",
381
- format: "binary",
382
- example: "a string content",
383
- title: "File"
384
- })
385
- ])
386
- ).Decode((value) => {
387
- if (value instanceof Buffer) {
388
- return new InMemoryBlob(value);
389
- }
390
- if (value instanceof ArrayBuffer) {
391
- return new InMemoryBlob(Buffer.from(value));
392
- }
393
- if (value instanceof Blob) {
394
- return value;
395
- }
396
- if (typeof value === "string") {
397
- return new InMemoryBlob(Buffer.from(value));
398
- }
399
- return new InMemoryBlob(Buffer.from(value));
400
- }).Encode((value) => value.content);
401
- type = () => this.any;
402
- /**
403
- * Extracts the error type of a schema for error messages.
404
- *
405
- * @param {TCatchall} schema - A schema that contains some type information.
406
- * @returns The type of the schema for error messages.
407
- */
408
- errorType(schema) {
409
- if (KindGuard.IsSchema(schema) && Object.hasOwn(schema, "errorType")) {
410
- return schema.errorType;
411
- } else if (KindGuard.IsLiteral(schema)) {
412
- return schema.const;
413
- }
414
- return schema[Kind].toLowerCase();
415
- }
416
- /**
417
- * Compiles schema if this exists, for optimal performance.
418
- *
419
- * @param {TObject<TProperties>} schema - The schema to compile.
420
- * @returns {TypeCheck<T>} - The compiled schema.
421
- */
422
- compile(schema) {
423
- return TypeCompiler.Compile(schema);
424
- }
425
- /**
426
- * Convert a schema to a TypeBox schema.
427
- * @param {TIdiomaticSchema} schema - The schema to convert.
428
- * @returns {TResolve<T>} The resolved schema.
429
- */
430
- schemify(schema) {
431
- if (typeof schema === "string" || typeof schema === "number" || typeof schema === "boolean") {
432
- return Type.Literal(schema);
433
- }
434
- if (KindGuard.IsSchema(schema) || schema instanceof TypeCheck) {
435
- return schema;
436
- }
437
- const newSchema = {};
438
- Object.getOwnPropertyNames(schema).forEach((key) => {
439
- if (KindGuard.IsSchema(schema[key]) || KindGuard.IsTransform(schema[key])) {
440
- newSchema[key] = schema[key];
441
- } else {
442
- const schemified = this.schemify(schema[key]);
443
- newSchema[key] = schemified;
444
- }
445
- });
446
- return Type.Object(newSchema);
447
- }
448
- /**
449
- * Make a schema optional.
450
- * @param {TIdiomaticSchema} schema - The schema to make optional.
451
- * @returns {TOptional<TResolve<T>>} The optional schema.
452
- */
453
- optional(schema) {
454
- const schemified = this.schemify(schema);
455
- return Type.Optional(schemified);
456
- }
457
- /**
458
- * Create an array schema.
459
- * @param {TIdiomaticSchema} schema - The schema to use for array items.
460
- * @returns {TArray<TResolve<T>>} The array schema.
461
- */
462
- array(schema) {
463
- const schemified = this.schemify(schema);
464
- return Type.Array(schemified, {
465
- errorType: `array of ${this.errorType(schemified)}`
466
- });
467
- }
468
- /**
469
- * Create a union schema.
470
- * @param {TUnionTupleContainer} schemas - The schemas to union.
471
- * @returns {TUnion<UnionTupleTResolve<T>>} The union schema.
472
- *
473
- * WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
474
- * This is a limitation of TypeBox. Consider using "optional" instead.
475
- */
476
- union(schemas) {
477
- const unionTypes = schemas.map((schema) => {
478
- return this.schemify(schema);
479
- });
480
- return Type.Union(unionTypes, {
481
- errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(", ")}`,
482
- errorSuffix: true
483
- });
484
- }
485
- /**
486
- * Create a literal schema.
487
- * @param {LiteralSchema} value - The literal value.
488
- * @returns {TLiteral<T>} The literal schema.
489
- */
490
- literal(value) {
491
- return Type.Literal(value, {
492
- errorType: value
493
- });
494
- }
495
- /**
496
- * Create an enum schema.
497
- * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
498
- * @returns {TUnion<UnionTupleTResolve<T[]>>} The enum schema.
499
- */
500
- enum_(schemaEnum) {
501
- return this.union(
502
- Object.values(schemaEnum).map((value) => this.literal(value))
503
- );
504
- }
505
- /**
506
- * Create a function schema.
507
- * @param {TSchema[]} args - The arguments of the function.
508
- * @param {TAny} returnType - The return type of the function.
509
- * @returns {TFunction<Args, ReturnType>} The function schema.
510
- */
511
- function_(args, returnType) {
512
- const schemaArgs = args.map((schema) => {
513
- return this.schemify(schema);
514
- });
515
- const schemaReturnType = this.schemify(returnType);
516
- return Type.Function(schemaArgs, schemaReturnType);
517
- }
518
- /**
519
- * Create a record schema.
520
- * @param {TIdiomaticSchema} key - The key schema.
521
- * @param {TIdiomaticSchema} value - The value schema.
522
- * @returns {TRecord<TResolve<Key>, TResolve<Value>>} The record schema.
523
- */
524
- record(key, value) {
525
- const keySchema = this.schemify(key);
526
- const valueSchema = this.schemify(value);
527
- return Type.Record(keySchema, valueSchema);
528
- }
529
- /**
530
- * Create a promise schema.
531
- * @param {TIdiomaticSchema} schema - The schema to use for the promise.
532
- * @returns {TPromise<TResolve<T>>} The promise schema.
533
- */
534
- promise(schema) {
535
- return Type.Promise(this.schemify(schema));
536
- }
537
- /**
538
- * Check if a value is a TypeBox object schema.
539
- * @param {unknown} value - The value to check.
540
- * @returns {boolean} True if the value is a TypeBox object schema.
541
- */
542
- isSchema(value) {
543
- return KindGuard.IsSchema(value);
544
- }
545
- /**
546
- * Check if a value is an instance of a TypeBox schema.
547
- * @param {object} value - The value to check.
548
- * @param {TCatchall} type - The schema to check against.
549
- * @returns {boolean} True if the value is an instance of the schema.
550
- */
551
- isInstanceOf(value, type22) {
552
- return typeof value === "object" && value != null && Kind in value && value[Kind] === type22[Kind];
553
- }
554
- /**
555
- * Validate a value against a schema.
556
- *
557
- * @param {TSchema} schema - The schema to validate against.
558
- * @param {unknown} value - The value to validate.
559
- * @returns {boolean} True if valid, otherwise false.
560
- */
561
- validate(schema, value) {
562
- if (schema instanceof TypeCheck) {
563
- return schema.Check(value);
564
- } else {
565
- const schemified = this.schemify(schema);
566
- return Value.Check(schemified, value);
567
- }
568
- }
569
- /**
570
- * Parse a value against a schema.
571
- *
572
- * @param {TSchema} schema - The schema to validate against.
573
- * @param {unknown} value - The value to validate.
574
- * @returns {ParseResult<TResolve<T>>} The parsing result.
575
- */
576
- parse(schema, value) {
577
- let errors = [];
578
- let conversion;
579
- if (schema instanceof TypeCheck) {
580
- if (schema.Check(value)) {
581
- conversion = schema.Decode(value);
582
- } else {
583
- errors = Array.from(schema.Errors(value));
584
- }
585
- } else {
586
- const schemified = this.schemify(schema);
587
- if (schemified[Kind] === "Unsafe") {
588
- try {
589
- if (value instanceof Buffer) {
590
- conversion = new InMemoryBlob(value);
591
- } else {
592
- errors = [
593
- {
594
- type: ValueErrorType.String,
595
- schema: schemified,
596
- path: "",
597
- message: `Invalid file type: expected Buffer or string, got ${typeof value}`,
598
- value,
599
- errors: []
600
- }
601
- ];
602
- }
603
- } catch (err) {
604
- errors = [
605
- {
606
- type: ValueErrorType.String,
607
- schema: schemified,
608
- path: "",
609
- message: err instanceof Error ? err.message : "Invalid file type",
610
- value,
611
- errors: []
612
- }
613
- ];
614
- }
615
- } else {
616
- if (Value.Check(schemified, value)) {
617
- conversion = Value.Decode(schemified, value);
618
- } else {
619
- errors = Array.from(Value.Errors(schemified, value));
620
- }
621
- }
622
- }
623
- return errors != null && errors.length === 0 ? {
624
- ok: true,
625
- value: conversion
626
- } : {
627
- ok: false,
628
- errors: errors.flatMap((error) => {
629
- if (error.type === ValueErrorType.Union && error.schema.errorType?.includes("any of")) {
630
- return error.errors.flatMap(
631
- (e, idx) => Array.from(e).map((e2) => ({
632
- path: [
633
- `Union Schema Variant ${idx}`,
634
- ...error.path.split("/").slice(1),
635
- ...e2.path.split("/").slice(1)
636
- ],
637
- message: e2.message
638
- }))
639
- );
640
- } else {
641
- return [
642
- {
643
- path: error.path.split("/").slice(1),
644
- message: error.message
645
- }
646
- ];
647
- }
648
- })
649
- };
650
- }
651
- /**
652
- * Convert a schema to an OpenAPI schema object.
653
- * @param {TIdiomaticSchema | TCatchall} schema - The schema to convert.
654
- * @returns {SchemaObject} The OpenAPI schema object.
655
- */
656
- openapi(schema) {
657
- const schemified = this.schemify(schema);
658
- let processedSchema;
659
- if (KindGuard.IsDate(schemified)) {
660
- processedSchema = Type.String({
661
- format: "date-time"
662
- });
663
- } else {
664
- processedSchema = deepCloneWithoutUndefined(schemified);
665
- }
666
- const newSchema = Object.assign({}, processedSchema);
667
- if (Object.hasOwn(newSchema, "properties")) {
668
- if (newSchema.properties) {
669
- Object.entries({ ...processedSchema.properties }).forEach(
670
- ([key, value]) => {
671
- if (KindGuard.IsSchema(value) && newSchema.properties) {
672
- newSchema.properties[key] = this.openapi(value);
673
- }
674
- }
675
- );
676
- }
677
- }
678
- if (Object.hasOwn(newSchema, "items")) {
679
- newSchema.items = this.openapi(newSchema.items);
680
- }
681
- if (Array.isArray(newSchema.anyOf)) {
682
- newSchema.anyOf = newSchema.anyOf.map(
683
- (item) => this.openapi(item)
684
- );
685
- }
686
- if (Array.isArray(newSchema.oneOf)) {
687
- newSchema.oneOf = newSchema.oneOf.map(
688
- (item) => this.openapi(item)
689
- );
690
- }
691
- if ("errorType" in newSchema) {
692
- delete newSchema["errorType"];
693
- }
694
- return newSchema;
695
- }
696
- };
697
- var SchemaValidator = () => new TypeboxSchemaValidator();
698
- var StaticSchemaValidator = SchemaValidator();
699
- var string = StaticSchemaValidator.string;
700
- var uuid = StaticSchemaValidator.uuid;
701
- var uri = StaticSchemaValidator.uri;
702
- var email = StaticSchemaValidator.email;
703
- var number = StaticSchemaValidator.number;
704
- var bigint = StaticSchemaValidator.bigint;
705
- var boolean = StaticSchemaValidator.boolean;
706
- var date = StaticSchemaValidator.date;
707
- var symbol = StaticSchemaValidator.symbol;
708
- var nullish = StaticSchemaValidator.nullish;
709
- var void_ = StaticSchemaValidator.void;
710
- var null_ = StaticSchemaValidator.null;
711
- var undefined_ = StaticSchemaValidator.undefined;
712
- var any = StaticSchemaValidator.any;
713
- var unknown = StaticSchemaValidator.unknown;
714
- var never = StaticSchemaValidator.never;
715
- var binary = StaticSchemaValidator.binary;
716
- var file = StaticSchemaValidator.file;
717
- var type = StaticSchemaValidator.type;
718
- var schemify = StaticSchemaValidator.schemify.bind(StaticSchemaValidator);
719
- var optional = StaticSchemaValidator.optional.bind(StaticSchemaValidator);
720
- var array = StaticSchemaValidator.array.bind(StaticSchemaValidator);
721
- var union = StaticSchemaValidator.union.bind(StaticSchemaValidator);
722
- var literal = StaticSchemaValidator.literal.bind(StaticSchemaValidator);
723
- var enum_ = StaticSchemaValidator.enum_.bind(StaticSchemaValidator);
724
- var function_ = StaticSchemaValidator.function_.bind(StaticSchemaValidator);
725
- var record = StaticSchemaValidator.record.bind(StaticSchemaValidator);
726
- var promise = StaticSchemaValidator.promise.bind(StaticSchemaValidator);
727
- var isSchema = StaticSchemaValidator.isSchema.bind(StaticSchemaValidator);
728
- var validate = StaticSchemaValidator.validate.bind(StaticSchemaValidator);
729
- var parse = StaticSchemaValidator.parse.bind(StaticSchemaValidator);
730
- var openapi = StaticSchemaValidator.openapi.bind(StaticSchemaValidator);
731
-
732
4
  // domain/schemas/typebox/databaseWorker.schema.ts
5
+ import { number } from "@forklaunch/validator/typebox";
733
6
  var DatabaseWorkerOptionsSchema = {
734
7
  retries: number,
735
8
  interval: number
736
9
  };
737
10
 
738
- // ../../../node_modules/.pnpm/@forklaunch+validator@1.2.27/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
739
- import {
740
- z as z2,
741
- ZodType
742
- } from "zod/v3";
743
-
744
- // ../../../node_modules/.pnpm/ts-deepmerge@8.0.0/node_modules/ts-deepmerge/esm/index.js
745
- var isObject = (obj) => {
746
- if (typeof obj === "object" && obj !== null) {
747
- if (typeof Object.getPrototypeOf === "function") {
748
- const prototype = Object.getPrototypeOf(obj);
749
- return prototype === Object.prototype || prototype === null;
750
- }
751
- return Object.prototype.toString.call(obj) === "[object Object]";
752
- }
753
- return false;
754
- };
755
- var UNSAFE_KEYS = /* @__PURE__ */ new Set([
756
- "__proto__",
757
- "constructor",
758
- "prototype",
759
- "toString",
760
- "valueOf",
761
- "hasOwnProperty",
762
- "isPrototypeOf",
763
- "propertyIsEnumerable",
764
- "toLocaleString"
765
- ]);
766
- var merge = (...objects) => objects.reduce((result, current) => {
767
- if (current === void 0) {
768
- return result;
769
- }
770
- if (Array.isArray(current)) {
771
- throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
772
- }
773
- Object.keys(current).forEach((key) => {
774
- if (UNSAFE_KEYS.has(key)) {
775
- return;
776
- }
777
- if (Array.isArray(result[key]) && Array.isArray(current[key])) {
778
- result[key] = merge.options.mergeArrays ? merge.options.uniqueArrayItems ? Array.from(new Set(result[key].concat(current[key]))) : [...result[key], ...current[key]] : current[key];
779
- } else if (isObject(result[key]) && isObject(current[key])) {
780
- result[key] = merge(result[key], current[key]);
781
- } else if (!isObject(result[key]) && isObject(current[key])) {
782
- result[key] = merge(current[key], void 0);
783
- } else {
784
- result[key] = current[key] === void 0 ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
785
- }
786
- });
787
- return result;
788
- }, {});
789
- var defaultOptions = {
790
- allowUndefinedOverrides: true,
791
- mergeArrays: true,
792
- uniqueArrayItems: true
793
- };
794
- merge.options = defaultOptions;
795
- merge.withOptions = (options, ...objects) => {
796
- merge.options = Object.assign(Object.assign({}, defaultOptions), options);
797
- const result = merge(...objects);
798
- merge.options = defaultOptions;
799
- return result;
800
- };
801
-
802
- // ../../../node_modules/.pnpm/@forklaunch+validator@1.2.27/node_modules/@forklaunch/validator/lib/src/zod/index.mjs
803
- import { z } from "zod/v3";
804
- function extendApi(schema, schemaObject = {}) {
805
- const This = schema.constructor;
806
- const newSchema = new This(schema._def);
807
- newSchema.metaOpenApi = Object.assign(
808
- {},
809
- schema.metaOpenApi || {},
810
- schemaObject
811
- );
812
- return newSchema;
813
- }
814
- function iterateZodObject({
815
- zodRef,
816
- useOutput,
817
- hideDefinitions,
818
- openApiVersion
819
- }) {
820
- const reduced = Object.keys(zodRef.shape).filter((key) => hideDefinitions?.includes(key) === false).reduce(
821
- (carry, key) => ({
822
- ...carry,
823
- [key]: generateSchema(zodRef.shape[key], useOutput, openApiVersion)
824
- }),
825
- {}
826
- );
827
- return reduced;
828
- }
829
- function typeFormat(type22, openApiVersion) {
830
- return openApiVersion === "3.0" ? type22 : [type22];
831
- }
832
- function parseTransformation({
833
- zodRef,
834
- schemas,
835
- useOutput,
836
- openApiVersion
837
- }) {
838
- const input = generateSchema(zodRef._def.schema, useOutput, openApiVersion);
839
- let output = "undefined";
840
- if (useOutput && zodRef._def.effect) {
841
- const effect = zodRef._def.effect.type === "transform" ? zodRef._def.effect : null;
842
- if (effect && "transform" in effect) {
843
- try {
844
- const type22 = Array.isArray(input.type) ? input.type[0] : input.type;
845
- output = typeof effect.transform(
846
- ["integer", "number"].includes(`${type22}`) ? 0 : "string" === type22 ? "" : "boolean" === type22 ? false : "object" === type22 ? {} : "null" === type22 ? null : "array" === type22 ? [] : void 0,
847
- { addIssue: () => void 0, path: [] }
848
- // TODO: Discover if context is necessary here
849
- );
850
- } catch {
851
- }
852
- }
853
- }
854
- const outputType = output;
855
- return merge(
856
- {
857
- ...zodRef.description ? { description: zodRef.description } : {},
858
- ...input,
859
- ...["number", "string", "boolean", "null"].includes(output) ? {
860
- type: typeFormat(outputType, openApiVersion)
861
- } : {}
862
- },
863
- ...schemas
864
- );
865
- }
866
- function parseString({
867
- zodRef,
868
- schemas,
869
- openApiVersion
870
- }) {
871
- const baseSchema = {
872
- type: typeFormat("string", openApiVersion)
873
- };
874
- const { checks = [] } = zodRef._def;
875
- checks.forEach((item) => {
876
- switch (item.kind) {
877
- case "email":
878
- baseSchema.format = "email";
879
- break;
880
- case "uuid":
881
- baseSchema.format = "uuid";
882
- break;
883
- case "cuid":
884
- baseSchema.format = "cuid";
885
- break;
886
- case "url":
887
- baseSchema.format = "uri";
888
- break;
889
- case "datetime":
890
- baseSchema.format = "date-time";
891
- break;
892
- case "length":
893
- baseSchema.minLength = item.value;
894
- baseSchema.maxLength = item.value;
895
- break;
896
- case "max":
897
- baseSchema.maxLength = item.value;
898
- break;
899
- case "min":
900
- baseSchema.minLength = item.value;
901
- break;
902
- case "regex":
903
- baseSchema.pattern = item.regex.source;
904
- break;
905
- }
906
- });
907
- return merge(
908
- baseSchema,
909
- zodRef.description ? { description: zodRef.description } : {},
910
- ...schemas
911
- );
912
- }
913
- function parseNumber({
914
- zodRef,
915
- schemas,
916
- openApiVersion
917
- }) {
918
- const baseSchema = {
919
- type: typeFormat("number", openApiVersion)
920
- };
921
- const { checks = [] } = zodRef._def;
922
- checks.forEach((item) => {
923
- switch (item.kind) {
924
- case "max":
925
- if (item.inclusive || openApiVersion === "3.0") {
926
- baseSchema.maximum = item.value;
927
- }
928
- if (!item.inclusive) {
929
- if (openApiVersion === "3.0") {
930
- baseSchema.exclusiveMaximum = true;
931
- } else {
932
- baseSchema.exclusiveMaximum = item.value;
933
- }
934
- }
935
- break;
936
- case "min":
937
- if (item.inclusive || openApiVersion === "3.0") {
938
- baseSchema.minimum = item.value;
939
- }
940
- if (!item.inclusive) {
941
- if (openApiVersion === "3.0") {
942
- baseSchema.exclusiveMinimum = true;
943
- } else {
944
- baseSchema.exclusiveMinimum = item.value;
945
- }
946
- }
947
- break;
948
- case "int":
949
- baseSchema.type = typeFormat("integer", openApiVersion);
950
- break;
951
- case "multipleOf":
952
- baseSchema.multipleOf = item.value;
953
- break;
954
- }
955
- });
956
- return merge(
957
- baseSchema,
958
- zodRef.description ? { description: zodRef.description } : {},
959
- ...schemas
960
- );
961
- }
962
- function getExcludedDefinitionsFromSchema(schemas) {
963
- const excludedDefinitions = [];
964
- for (const schema of schemas) {
965
- if (Array.isArray(schema.hideDefinitions)) {
966
- excludedDefinitions.push(...schema.hideDefinitions);
967
- }
968
- }
969
- return excludedDefinitions;
970
- }
971
- function parseObject({
972
- zodRef,
973
- schemas,
974
- useOutput,
975
- hideDefinitions,
976
- openApiVersion
977
- }) {
978
- let additionalProperties;
979
- if (!(zodRef._def.catchall instanceof z.ZodNever || zodRef._def.catchall?._def.typeName === "ZodNever"))
980
- additionalProperties = generateSchema(
981
- zodRef._def.catchall,
982
- useOutput,
983
- openApiVersion
984
- );
985
- else if (zodRef._def.unknownKeys === "passthrough")
986
- additionalProperties = true;
987
- else if (zodRef._def.unknownKeys === "strict") additionalProperties = false;
988
- additionalProperties = additionalProperties != null ? { additionalProperties } : {};
989
- const requiredProperties = Object.keys(
990
- zodRef.shape
991
- ).filter((key) => {
992
- const item = zodRef.shape[key];
993
- return !(item.isOptional() || item instanceof z.ZodDefault || item._def.typeName === "ZodDefault") && !(item instanceof z.ZodNever || item._def.typeName === "ZodDefault");
994
- });
995
- const required = requiredProperties.length > 0 ? { required: requiredProperties } : {};
996
- return merge(
997
- {
998
- type: typeFormat("object", openApiVersion),
999
- properties: iterateZodObject({
1000
- zodRef,
1001
- schemas,
1002
- useOutput,
1003
- hideDefinitions: getExcludedDefinitionsFromSchema(schemas),
1004
- openApiVersion
1005
- }),
1006
- ...required,
1007
- ...additionalProperties,
1008
- ...hideDefinitions
1009
- },
1010
- zodRef.description ? { description: zodRef.description, hideDefinitions } : {},
1011
- ...schemas
1012
- );
1013
- }
1014
- function parseRecord({
1015
- zodRef,
1016
- schemas,
1017
- useOutput,
1018
- openApiVersion
1019
- }) {
1020
- return merge(
1021
- {
1022
- type: typeFormat("object", openApiVersion),
1023
- additionalProperties: zodRef._def.valueType instanceof z.ZodUnknown ? {} : generateSchema(zodRef._def.valueType, useOutput, openApiVersion)
1024
- },
1025
- zodRef.description ? { description: zodRef.description } : {},
1026
- ...schemas
1027
- );
1028
- }
1029
- function parseBigInt({
1030
- zodRef,
1031
- schemas,
1032
- openApiVersion
1033
- }) {
1034
- return merge(
1035
- {
1036
- type: typeFormat("integer", openApiVersion),
1037
- format: "int64"
1038
- },
1039
- zodRef.description ? { description: zodRef.description } : {},
1040
- ...schemas
1041
- );
1042
- }
1043
- function parseBoolean({
1044
- zodRef,
1045
- schemas,
1046
- openApiVersion
1047
- }) {
1048
- return merge(
1049
- { type: typeFormat("boolean", openApiVersion) },
1050
- zodRef.description ? { description: zodRef.description } : {},
1051
- ...schemas
1052
- );
1053
- }
1054
- function parseDate({
1055
- zodRef,
1056
- schemas,
1057
- openApiVersion
1058
- }) {
1059
- return merge(
1060
- {
1061
- type: typeFormat("string", openApiVersion),
1062
- format: "date-time"
1063
- },
1064
- zodRef.description ? { description: zodRef.description } : {},
1065
- ...schemas
1066
- );
1067
- }
1068
- function parseNull({
1069
- zodRef,
1070
- schemas,
1071
- openApiVersion
1072
- }) {
1073
- return merge(
1074
- openApiVersion === "3.0" ? { type: "null" } : {
1075
- type: ["string", "null"],
1076
- enum: ["null"]
1077
- },
1078
- zodRef.description ? { description: zodRef.description } : {},
1079
- ...schemas
1080
- );
1081
- }
1082
- function parseOptional({
1083
- schemas,
1084
- zodRef,
1085
- useOutput,
1086
- openApiVersion
1087
- }) {
1088
- return merge(
1089
- generateSchema(zodRef.unwrap(), useOutput, openApiVersion),
1090
- zodRef.description ? { description: zodRef.description } : {},
1091
- ...schemas
1092
- );
1093
- }
1094
- function parseNullable({
1095
- schemas,
1096
- zodRef,
1097
- useOutput,
1098
- openApiVersion
1099
- }) {
1100
- const schema = generateSchema(zodRef.unwrap(), useOutput, openApiVersion);
1101
- return merge(
1102
- schema,
1103
- openApiVersion === "3.0" ? { nullable: true } : { type: typeFormat("null", openApiVersion) },
1104
- zodRef.description ? { description: zodRef.description } : {},
1105
- ...schemas
1106
- );
1107
- }
1108
- function parseDefault({
1109
- schemas,
1110
- zodRef,
1111
- useOutput,
1112
- openApiVersion
1113
- }) {
1114
- return merge(
1115
- {
1116
- default: zodRef._def.defaultValue(),
1117
- ...generateSchema(zodRef._def.innerType, useOutput, openApiVersion)
1118
- },
1119
- zodRef.description ? { description: zodRef.description } : {},
1120
- ...schemas
1121
- );
1122
- }
1123
- function parseArray({
1124
- schemas,
1125
- zodRef,
1126
- useOutput,
1127
- openApiVersion
1128
- }) {
1129
- const constraints = {};
1130
- if (zodRef._def.exactLength != null) {
1131
- constraints.minItems = zodRef._def.exactLength.value;
1132
- constraints.maxItems = zodRef._def.exactLength.value;
1133
- }
1134
- if (zodRef._def.minLength != null)
1135
- constraints.minItems = zodRef._def.minLength.value;
1136
- if (zodRef._def.maxLength != null)
1137
- constraints.maxItems = zodRef._def.maxLength.value;
1138
- return merge(
1139
- {
1140
- type: typeFormat("array", openApiVersion),
1141
- items: generateSchema(zodRef.element, useOutput, openApiVersion),
1142
- ...constraints
1143
- },
1144
- zodRef.description ? { description: zodRef.description } : {},
1145
- ...schemas
1146
- );
1147
- }
1148
- function parseLiteral({
1149
- schemas,
1150
- zodRef,
1151
- openApiVersion
1152
- }) {
1153
- const type22 = typeof zodRef._def.value;
1154
- return merge(
1155
- {
1156
- type: typeFormat(type22, openApiVersion),
1157
- enum: [zodRef._def.value]
1158
- },
1159
- zodRef.description ? { description: zodRef.description } : {},
1160
- ...schemas
1161
- );
1162
- }
1163
- function parseEnum({
1164
- schemas,
1165
- zodRef,
1166
- openApiVersion
1167
- }) {
1168
- const type22 = typeof Object.values(zodRef._def.values)[0];
1169
- return merge(
1170
- {
1171
- type: typeFormat(type22, openApiVersion),
1172
- enum: Object.values(zodRef._def.values)
1173
- },
1174
- zodRef.description ? { description: zodRef.description } : {},
1175
- ...schemas
1176
- );
1177
- }
1178
- function parseIntersection({
1179
- schemas,
1180
- zodRef,
1181
- useOutput,
1182
- openApiVersion
1183
- }) {
1184
- return merge(
1185
- {
1186
- allOf: [
1187
- generateSchema(zodRef._def.left, useOutput, openApiVersion),
1188
- generateSchema(zodRef._def.right, useOutput, openApiVersion)
1189
- ]
1190
- },
1191
- zodRef.description ? { description: zodRef.description } : {},
1192
- ...schemas
1193
- );
1194
- }
1195
- function parseUnion({
1196
- schemas,
1197
- zodRef,
1198
- useOutput,
1199
- openApiVersion
1200
- }) {
1201
- const contents = zodRef._def.options;
1202
- if (contents.reduce(
1203
- (prev, content) => prev && content._def.typeName === "ZodLiteral",
1204
- true
1205
- )) {
1206
- const literals = contents;
1207
- const type22 = literals.reduce(
1208
- (prev, content) => !prev || prev === typeof content._def.value ? typeof content._def.value : null,
1209
- null
1210
- );
1211
- if (type22) {
1212
- return merge(
1213
- {
1214
- type: typeFormat(type22, openApiVersion),
1215
- enum: literals.map((literal22) => literal22._def.value)
1216
- },
1217
- zodRef.description ? { description: zodRef.description } : {},
1218
- ...schemas
1219
- );
1220
- }
1221
- }
1222
- const oneOfContents = openApiVersion === "3.0" ? contents.filter((content) => content._def.typeName !== "ZodNull") : contents;
1223
- const contentsHasNull = contents.length != oneOfContents.length;
1224
- return merge(
1225
- {
1226
- oneOf: oneOfContents.map(
1227
- (schema) => generateSchema(schema, useOutput, openApiVersion)
1228
- )
1229
- },
1230
- contentsHasNull ? { nullable: true } : {},
1231
- zodRef.description ? { description: zodRef.description } : {},
1232
- ...schemas
1233
- );
1234
- }
1235
- function parseDiscriminatedUnion({
1236
- schemas,
1237
- zodRef,
1238
- useOutput,
1239
- openApiVersion
1240
- }) {
1241
- return merge(
1242
- {
1243
- discriminator: {
1244
- propertyName: zodRef._def.discriminator
1245
- },
1246
- oneOf: Array.from(
1247
- zodRef._def.options.values()
1248
- ).map((schema) => generateSchema(schema, useOutput, openApiVersion))
1249
- },
1250
- zodRef.description ? { description: zodRef.description } : {},
1251
- ...schemas
1252
- );
1253
- }
1254
- function parseNever({
1255
- zodRef,
1256
- schemas
1257
- }) {
1258
- return merge(
1259
- { readOnly: true },
1260
- zodRef.description ? { description: zodRef.description } : {},
1261
- ...schemas
1262
- );
1263
- }
1264
- function parseBranded({
1265
- schemas,
1266
- zodRef,
1267
- useOutput,
1268
- openApiVersion
1269
- }) {
1270
- return merge(
1271
- generateSchema(zodRef._def.type, useOutput, openApiVersion),
1272
- ...schemas
1273
- );
1274
- }
1275
- function catchAllParser({
1276
- zodRef,
1277
- schemas
1278
- }) {
1279
- return merge(
1280
- zodRef.description ? { description: zodRef.description } : {},
1281
- ...schemas
1282
- );
1283
- }
1284
- function parsePipeline({
1285
- schemas,
1286
- zodRef,
1287
- useOutput,
1288
- openApiVersion
1289
- }) {
1290
- return merge(
1291
- generateSchema(
1292
- useOutput ? zodRef._def.out : zodRef._def.in,
1293
- useOutput,
1294
- openApiVersion
1295
- ),
1296
- ...schemas
1297
- );
1298
- }
1299
- function parseReadonly({
1300
- zodRef,
1301
- useOutput,
1302
- schemas,
1303
- openApiVersion
1304
- }) {
1305
- return merge(
1306
- generateSchema(zodRef._def.innerType, useOutput, openApiVersion),
1307
- zodRef.description ? { description: zodRef.description } : {},
1308
- ...schemas
1309
- );
1310
- }
1311
- var workerMap = {
1312
- ZodObject: parseObject,
1313
- ZodRecord: parseRecord,
1314
- ZodString: parseString,
1315
- ZodNumber: parseNumber,
1316
- ZodBigInt: parseBigInt,
1317
- ZodBoolean: parseBoolean,
1318
- ZodDate: parseDate,
1319
- ZodNull: parseNull,
1320
- ZodOptional: parseOptional,
1321
- ZodNullable: parseNullable,
1322
- ZodDefault: parseDefault,
1323
- ZodArray: parseArray,
1324
- ZodLiteral: parseLiteral,
1325
- ZodEnum: parseEnum,
1326
- ZodNativeEnum: parseEnum,
1327
- ZodTransformer: parseTransformation,
1328
- ZodEffects: parseTransformation,
1329
- ZodIntersection: parseIntersection,
1330
- ZodUnion: parseUnion,
1331
- ZodDiscriminatedUnion: parseDiscriminatedUnion,
1332
- ZodNever: parseNever,
1333
- ZodBranded: parseBranded,
1334
- // TODO Transform the rest to schemas
1335
- ZodUndefined: catchAllParser,
1336
- // TODO: `prefixItems` is allowed in OpenAPI 3.1 which can be used to create tuples
1337
- ZodTuple: catchAllParser,
1338
- ZodMap: catchAllParser,
1339
- ZodFunction: catchAllParser,
1340
- ZodLazy: catchAllParser,
1341
- ZodPromise: catchAllParser,
1342
- ZodAny: catchAllParser,
1343
- ZodUnknown: catchAllParser,
1344
- ZodVoid: catchAllParser,
1345
- ZodPipeline: parsePipeline,
1346
- ZodReadonly: parseReadonly
1347
- };
1348
- function generateSchema(zodRef, useOutput = false, openApiVersion = "3.1") {
1349
- const { metaOpenApi = {} } = zodRef;
1350
- const schemas = [
1351
- ...Array.isArray(metaOpenApi) ? metaOpenApi : [metaOpenApi]
1352
- ];
1353
- try {
1354
- const typeName = zodRef._def.typeName;
1355
- if (typeName in workerMap) {
1356
- return workerMap[typeName]({
1357
- zodRef,
1358
- schemas,
1359
- useOutput,
1360
- openApiVersion
1361
- });
1362
- }
1363
- return catchAllParser({ zodRef, schemas, openApiVersion });
1364
- } catch (err) {
1365
- console.error(err);
1366
- return catchAllParser({ zodRef, schemas, openApiVersion });
1367
- }
1368
- }
1369
- function extendZodWithOpenApi(zod, forceOverride = false) {
1370
- if (!forceOverride && typeof zod.ZodSchema.prototype.openapi !== "undefined") {
1371
- return;
1372
- }
1373
- zod.ZodSchema.prototype.openapi = function(metadata) {
1374
- return extendApi(this, metadata);
1375
- };
1376
- }
1377
- extendZodWithOpenApi(z2);
1378
- var ZodSchemaValidator = class {
1379
- _Type = "Zod";
1380
- _SchemaCatchall;
1381
- _ValidSchemaObject;
1382
- string = z2.string().openapi({
1383
- title: "String",
1384
- example: "a string"
1385
- });
1386
- uuid = z2.string().uuid().openapi({
1387
- title: "UUID",
1388
- format: "uuid",
1389
- 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}$",
1390
- example: "a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6"
1391
- });
1392
- email = z2.string().email().openapi({
1393
- title: "Email",
1394
- format: "email",
1395
- pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
1396
- example: "a@b.com"
1397
- });
1398
- uri = z2.string().url().openapi({
1399
- title: "URI",
1400
- format: "uri",
1401
- pattern: "^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$",
1402
- example: "https://forklaunch.com"
1403
- });
1404
- number = z2.preprocess((value) => {
1405
- try {
1406
- return Number(value);
1407
- } catch {
1408
- return value;
1409
- }
1410
- }, z2.number()).openapi({
1411
- title: "Number",
1412
- example: 123
1413
- });
1414
- bigint = z2.preprocess((value) => {
1415
- try {
1416
- if (value instanceof Date) {
1417
- return BigInt(value.getTime());
1418
- }
1419
- switch (typeof value) {
1420
- case "number":
1421
- case "string":
1422
- return BigInt(value);
1423
- case "boolean":
1424
- return BigInt(value ? 1 : 0);
1425
- default:
1426
- return value;
1427
- }
1428
- } catch {
1429
- return value;
1430
- }
1431
- }, z2.bigint()).openapi({
1432
- title: "BigInt",
1433
- type: "integer",
1434
- format: "int64",
1435
- example: 123n
1436
- });
1437
- boolean = z2.preprocess((val) => {
1438
- if (typeof val === "string") {
1439
- if (val.toLowerCase() === "true") return true;
1440
- if (val.toLowerCase() === "false") return false;
1441
- }
1442
- return val;
1443
- }, z2.boolean()).openapi({
1444
- title: "Boolean",
1445
- example: true
1446
- });
1447
- date = z2.preprocess((value) => {
1448
- try {
1449
- switch (typeof value) {
1450
- case "string":
1451
- return new Date(value);
1452
- case "number":
1453
- return new Date(value);
1454
- default:
1455
- return value;
1456
- }
1457
- } catch {
1458
- return value;
1459
- }
1460
- }, z2.date()).openapi({
1461
- title: "Date",
1462
- type: "string",
1463
- format: "date-time",
1464
- example: "2025-05-16T21:13:04.123Z"
1465
- });
1466
- symbol = z2.symbol().openapi({
1467
- title: "Symbol",
1468
- example: /* @__PURE__ */ Symbol("symbol")
1469
- });
1470
- nullish = z2.union([z2.void(), z2.null(), z2.undefined()]).openapi({
1471
- title: "Nullish",
1472
- type: "null",
1473
- example: null
1474
- });
1475
- void = z2.void().openapi({
1476
- title: "Void",
1477
- type: "null",
1478
- example: void 0
1479
- });
1480
- null = z2.null().openapi({
1481
- title: "Null",
1482
- type: "null",
1483
- example: null
1484
- });
1485
- undefined = z2.undefined().openapi({
1486
- title: "Undefined",
1487
- type: "null",
1488
- example: void 0
1489
- });
1490
- any = z2.any().openapi({
1491
- title: "Any",
1492
- type: "object",
1493
- example: "any"
1494
- });
1495
- unknown = z2.unknown().openapi({
1496
- title: "Unknown",
1497
- type: "object",
1498
- example: "unknown"
1499
- });
1500
- never = z2.never().openapi({
1501
- title: "Never",
1502
- type: "null",
1503
- example: "never"
1504
- });
1505
- binary = z2.string().transform((val) => new Uint8Array(Buffer.from(val, "base64"))).openapi({
1506
- title: "Binary",
1507
- type: "string",
1508
- format: "binary",
1509
- example: "a base-64 encodable string"
1510
- });
1511
- file = z2.union([
1512
- z2.instanceof(Buffer),
1513
- z2.instanceof(ArrayBuffer),
1514
- z2.instanceof(Blob),
1515
- z2.string()
1516
- ]).transform((val) => {
1517
- if (val instanceof Buffer) {
1518
- return new Blob([val]);
1519
- }
1520
- if (val instanceof ArrayBuffer) {
1521
- return new Blob([val]);
1522
- }
1523
- if (val instanceof Blob) {
1524
- return val;
1525
- }
1526
- if (typeof val === "string") {
1527
- return new Blob([val]);
1528
- }
1529
- return new Blob([val]);
1530
- }).refine((val) => val instanceof Blob, {
1531
- message: "Invalid file type: expected Buffer, ArrayBuffer, Blob, or string"
1532
- }).openapi({
1533
- title: "File",
1534
- type: "string",
1535
- format: "binary",
1536
- example: "a base-64 encodable blob or file"
1537
- });
1538
- type = () => this.any;
1539
- /**
1540
- * Compiles schema if this exists, for optimal performance.
1541
- *
1542
- * @param {ZodObject<ZodRawShape>} schema - The schema to compile.
1543
- * @returns {ZodResolve<T>} - The compiled schema.
1544
- */
1545
- compile(schema) {
1546
- return schema;
1547
- }
1548
- /**
1549
- * Convert a schema to a Zod schema.
1550
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
1551
- * @returns {ZodResolve<T>} The resolved schema.
1552
- */
1553
- schemify(schema) {
1554
- if (typeof schema === "string" || typeof schema === "number" || typeof schema === "boolean") {
1555
- return z2.literal(schema);
1556
- }
1557
- if (schema instanceof ZodType) {
1558
- return schema;
1559
- }
1560
- const newSchema = {};
1561
- Object.getOwnPropertyNames(schema).forEach((key) => {
1562
- if (schema[key] instanceof ZodType) {
1563
- newSchema[key] = schema[key];
1564
- } else {
1565
- newSchema[key] = this.schemify(schema[key]);
1566
- }
1567
- });
1568
- return z2.object(newSchema);
1569
- }
1570
- /**
1571
- * Make a schema optional.
1572
- * @param {ZodIdiomaticSchema} schema - The schema to make optional.
1573
- * @returns {ZodOptional<ZodResolve<T>>} The optional schema.
1574
- */
1575
- optional(schema) {
1576
- const resolvedSchema = this.schemify(schema);
1577
- return resolvedSchema.optional();
1578
- }
1579
- /**
1580
- * Create an array schema.
1581
- * @param {ZodIdiomaticSchema} schema - The schema to use for array items.
1582
- * @returns {ZodArray<ZodResolve<T>>} The array schema.
1583
- */
1584
- array(schema) {
1585
- const resolvedSchema = this.schemify(schema);
1586
- return resolvedSchema.array();
1587
- }
1588
- /**
1589
- * Create a union schema.
1590
- * @param {ZodUnionContainer} schemas - The schemas to union.
1591
- * @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
1592
- */
1593
- union(schemas) {
1594
- const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
1595
- return z2.union(
1596
- resolvedSchemas
1597
- );
1598
- }
1599
- /**
1600
- * Create a literal schema.
1601
- * @param {LiteralSchema} value - The literal value.
1602
- * @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
1603
- */
1604
- literal(value) {
1605
- return z2.literal(value);
1606
- }
1607
- /**
1608
- * Create an enum schema.
1609
- * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
1610
- * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
1611
- */
1612
- enum_(schemaEnum) {
1613
- return this.union(
1614
- Object.values(schemaEnum)
1615
- );
1616
- }
1617
- /**
1618
- * Create a function schema.
1619
- * @param {ZodTuple} args - The arguments of the function.
1620
- * @param {ZodAny} returnType - The return type of the function.
1621
- * @returns {ZodFunction<Args, ReturnType>} The function schema.
1622
- */
1623
- function_(args, returnType) {
1624
- const schemaArgs = args.map((schema) => this.schemify(schema));
1625
- const schemaReturnType = this.schemify(returnType);
1626
- return z2.function(z2.tuple(schemaArgs), schemaReturnType);
1627
- }
1628
- /**
1629
- * Create a record schema.
1630
- * @param {ZodIdiomaticSchema} key - The key schema.
1631
- * @param {ZodIdiomaticSchema} value - The value schema.
1632
- * @returns {ZodRecord<ZodResolve<Key>, ZodResolve<Value>>} The record schema.
1633
- */
1634
- record(key, value) {
1635
- const keySchema = this.schemify(key);
1636
- const valueSchema = this.schemify(value);
1637
- return z2.record(keySchema, valueSchema);
1638
- }
1639
- /**
1640
- * Create a promise schema.
1641
- * @param {ZodIdiomaticSchema} schema - The schema to use for the promise.
1642
- * @returns {ZodPromise<ZodResolve<T>>} The promise schema.
1643
- */
1644
- promise(schema) {
1645
- return z2.promise(this.schemify(schema));
1646
- }
1647
- /**
1648
- * Checks if a value is a Zod schema.
1649
- * @param {unknown} value - The value to check.
1650
- * @returns {boolean} True if the value is a Zod schema.
1651
- */
1652
- isSchema(value) {
1653
- return value instanceof ZodType;
1654
- }
1655
- /**
1656
- * Checks if a value is an instance of a Zod schema.
1657
- * @param {object} value - The value to check.
1658
- * @param {ZodType} type - The schema to check against.
1659
- * @returns {boolean} True if the value is an instance of the schema.
1660
- */
1661
- isInstanceOf(value, type22) {
1662
- return this.isSchema(value) && type22._def.typeName === value._def.typeName;
1663
- }
1664
- /**
1665
- * Validate a value against a schema.
1666
- * @param {ZodCatchall} schema - The schema to validate against.
1667
- * @param {unknown} value - The value to validate.
1668
- * @returns {boolean} True if valid, otherwise false.
1669
- */
1670
- validate(schema, value) {
1671
- const resolvedSchema = this.schemify(schema);
1672
- return resolvedSchema.safeParse(value).success;
1673
- }
1674
- /**
1675
- * Parses a value to a schema validation.
1676
- *
1677
- * @param {ZodCatchall} schema - The schema to validate against.
1678
- * @param {unknown} value - The value to validate.
1679
- * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
1680
- */
1681
- parse(schema, value) {
1682
- const resolvedSchema = this.schemify(schema);
1683
- const result = resolvedSchema.safeParse(value);
1684
- return result.success ? { ok: true, value: result.data } : {
1685
- ok: false,
1686
- errors: result.error.errors.flatMap((error) => {
1687
- switch (error.code) {
1688
- case "invalid_union":
1689
- return error.unionErrors.flatMap(
1690
- (unionError, idx) => unionError.errors.map((e) => ({
1691
- path: [
1692
- `Union Schema Variant ${idx}`,
1693
- ...error.path.map((p) => p.toString()),
1694
- ...e.path.map((p) => p.toString())
1695
- ],
1696
- message: e.message
1697
- }))
1698
- );
1699
- default:
1700
- return [
1701
- {
1702
- path: error.path.map((p) => p.toString()),
1703
- message: error.message
1704
- }
1705
- ];
1706
- }
1707
- })
1708
- };
1709
- }
1710
- /**
1711
- * Convert a schema to an OpenAPI schema object.
1712
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
1713
- * @returns {SchemaObject} The OpenAPI schema object.
1714
- */
1715
- openapi(schema) {
1716
- const schemified = this.schemify(schema);
1717
- return generateSchema(deepCloneWithoutUndefined(schemified));
1718
- }
1719
- };
1720
- var SchemaValidator2 = () => new ZodSchemaValidator();
1721
- var StaticSchemaValidator2 = SchemaValidator2();
1722
- var string2 = StaticSchemaValidator2.string;
1723
- var uuid2 = StaticSchemaValidator2.uuid;
1724
- var email2 = StaticSchemaValidator2.email;
1725
- var uri2 = StaticSchemaValidator2.uri;
1726
- var number2 = StaticSchemaValidator2.number;
1727
- var bigint2 = StaticSchemaValidator2.bigint;
1728
- var boolean2 = StaticSchemaValidator2.boolean;
1729
- var date2 = StaticSchemaValidator2.date;
1730
- var symbol2 = StaticSchemaValidator2.symbol;
1731
- var nullish2 = StaticSchemaValidator2.nullish;
1732
- var void_2 = StaticSchemaValidator2.void;
1733
- var null_2 = StaticSchemaValidator2.null;
1734
- var undefined_2 = StaticSchemaValidator2.undefined;
1735
- var any2 = StaticSchemaValidator2.any;
1736
- var unknown2 = StaticSchemaValidator2.unknown;
1737
- var never2 = StaticSchemaValidator2.never;
1738
- var binary2 = StaticSchemaValidator2.binary;
1739
- var file2 = StaticSchemaValidator2.file;
1740
- var type2 = StaticSchemaValidator2.type;
1741
- var schemify2 = StaticSchemaValidator2.schemify.bind(StaticSchemaValidator2);
1742
- var optional2 = StaticSchemaValidator2.optional.bind(StaticSchemaValidator2);
1743
- var array2 = StaticSchemaValidator2.array.bind(StaticSchemaValidator2);
1744
- var union2 = StaticSchemaValidator2.union.bind(StaticSchemaValidator2);
1745
- var literal2 = StaticSchemaValidator2.literal.bind(StaticSchemaValidator2);
1746
- var enum_2 = StaticSchemaValidator2.enum_.bind(StaticSchemaValidator2);
1747
- var function_2 = StaticSchemaValidator2.function_.bind(StaticSchemaValidator2);
1748
- var record2 = StaticSchemaValidator2.record.bind(StaticSchemaValidator2);
1749
- var promise2 = StaticSchemaValidator2.promise.bind(StaticSchemaValidator2);
1750
- var isSchema2 = StaticSchemaValidator2.isSchema.bind(StaticSchemaValidator2);
1751
- var validate2 = StaticSchemaValidator2.validate.bind(StaticSchemaValidator2);
1752
- var parse2 = StaticSchemaValidator2.parse.bind(StaticSchemaValidator2);
1753
- var openapi2 = StaticSchemaValidator2.openapi.bind(StaticSchemaValidator2);
1754
-
1755
11
  // domain/schemas/zod/databaseWorker.schema.ts
12
+ import { number as number2 } from "@forklaunch/validator/zod";
1756
13
  var DatabaseWorkerOptionsSchema2 = {
1757
14
  retries: number2,
1758
15
  interval: number2