@forklaunch/validator 0.4.11 → 0.5.0

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,126 +1,11 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { SchemaObject } from 'openapi3-ts/oas31';
3
2
  import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
4
- import { TypeCheck } from '@sinclair/typebox/compiler';
5
- import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-BA3PeCI5.js';
6
- export { l as TObjectShape, k as TOuterArray, m as TSchemaTranslate, n as UnboxedTObjectSchema } from '../../schema.types-BA3PeCI5.js';
3
+ import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as TUnionTupleContainer, i as UnionTupleTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-BL6n8u4w.js';
4
+ export { m as TObject, l as TObjectShape, k as TOuterArray, n as TSchemaTranslate, o as UnboxedTObjectSchema } from '../../schema.types-BL6n8u4w.js';
7
5
  import * as _sinclair_typebox from '@sinclair/typebox';
8
- import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema } from '@sinclair/typebox';
9
6
  import '@forklaunch/common';
10
7
  import 'zod';
11
8
 
12
- /**
13
- * Class representing a TypeBox schema definition.
14
- * @implements {SchemaValidator}
15
- */
16
- declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TObject<TProperties>>(schema: T) => TypeCheck<T>), <T extends TIdiomaticSchema>(schema: T) => TResolve<T>, <T extends TIdiomaticSchema>(schema: T) => TOptional<TResolve<T>>, <T extends TIdiomaticSchema>(schema: T) => TArray<TResolve<T>>, <T extends TUnionContainer>(schemas: [...T]) => TUnion<UnionTResolve<T>>, <T extends LiteralSchema>(value: T) => TLiteral<T>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => TUnion<[
17
- {
18
- [K in keyof T]: TLiteral<T[K]>;
19
- }[keyof T]
20
- ]>, (value: unknown) => value is TSchema, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => boolean, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => ParseResult<TResolve<T>>, <T extends TIdiomaticSchema | TCatchall>(schema: T) => SchemaObject> {
21
- _Type: "TypeBox";
22
- _SchemaCatchall: TSchema;
23
- _ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
24
- string: _sinclair_typebox.TString;
25
- uuid: _sinclair_typebox.TString;
26
- uri: _sinclair_typebox.TString;
27
- email: _sinclair_typebox.TString;
28
- number: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TDate, _sinclair_typebox.TBigInt]>, number>;
29
- bigint: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBigInt, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TDate]>, bigint>;
30
- boolean: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBoolean, _sinclair_typebox.TString]>, boolean>;
31
- date: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
32
- symbol: _sinclair_typebox.TSymbol;
33
- nullish: TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
34
- any: _sinclair_typebox.TAny;
35
- unknown: _sinclair_typebox.TUnknown;
36
- never: _sinclair_typebox.TNever;
37
- /**
38
- * Extracts the error type of a schema for error messages.
39
- *
40
- * @param {TCatchall} schema - A schema that contains some type information.
41
- * @returns The type of the schema for error messages.
42
- */
43
- private errorType;
44
- /**
45
- * Compiles schema if this exists, for optimal performance.
46
- *
47
- * @param {TObject<TProperties>} schema - The schema to compile.
48
- * @returns {TypeCheck<T>} - The compiled schema.
49
- */
50
- compile<T extends TObject<TProperties>>(schema: T): TypeCheck<T>;
51
- /**
52
- * Convert a schema to a TypeBox schema.
53
- * @param {TIdiomaticSchema} schema - The schema to convert.
54
- * @returns {TResolve<T>} The resolved schema.
55
- */
56
- schemify<T extends TIdiomaticSchema>(schema: T): TResolve<T>;
57
- /**
58
- * Make a schema optional.
59
- * @param {TIdiomaticSchema} schema - The schema to make optional.
60
- * @returns {TOptional<TResolve<T>>} The optional schema.
61
- */
62
- optional<T extends TIdiomaticSchema>(schema: T): TOptional<TResolve<T>>;
63
- /**
64
- * Create an array schema.
65
- * @param {TIdiomaticSchema} schema - The schema to use for array items.
66
- * @returns {TArray<TResolve<T>>} The array schema.
67
- */
68
- array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
69
- /**
70
- * Create a union schema.
71
- * @param {TUnionContainer} schemas - The schemas to union.
72
- * @returns {TUnion<UnionTResolve<T>>} The union schema.
73
- *
74
- * WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
75
- * This is a limitation of TypeBox. Consider using "optional" instead.
76
- */
77
- union<T extends TUnionContainer>(schemas: [...T]): TUnion<UnionTResolve<T>>;
78
- /**
79
- * Create a literal schema.
80
- * @param {LiteralSchema} value - The literal value.
81
- * @returns {TLiteral<T>} The literal schema.
82
- */
83
- literal<T extends LiteralSchema>(value: T): TLiteral<T>;
84
- /**
85
- * Create an enum schema.
86
- * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
87
- * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
88
- */
89
- enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): TUnion<[
90
- {
91
- [K in keyof T]: TLiteral<T[K]>;
92
- }[keyof T]
93
- ]>;
94
- /**
95
- * Check if a value is a TypeBox object schema.
96
- * @param {unknown} value - The value to check.
97
- * @returns {boolean} True if the value is a TypeBox object schema.
98
- */
99
- isSchema(value: unknown): value is TSchema;
100
- /**
101
- * Validate a value against a schema.
102
- *
103
- * @param {TSchema} schema - The schema to validate against.
104
- * @param {unknown} value - The value to validate.
105
- * @returns {boolean} True if valid, otherwise false.
106
- */
107
- validate<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): boolean;
108
- /**
109
- * Parse a value against a schema.
110
- *
111
- * @param {TSchema} schema - The schema to validate against.
112
- * @param {unknown} value - The value to validate.
113
- * @returns {ParseResult<TResolve<T>>} The parsing result.
114
- */
115
- parse<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): ParseResult<TResolve<T>>;
116
- /**
117
- * Convert a schema to an OpenAPI schema object.
118
- * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
119
- * @returns {SchemaObject} The OpenAPI schema object.
120
- */
121
- openapi<T extends TIdiomaticSchema | TSchema>(schema: T): SchemaObject;
122
- }
123
-
124
9
  /**
125
10
  * Factory function for creating a TypeboxSchemaValidator instance.
126
11
  * @returns {TypeboxSchemaValidator} The TypeboxSchemaValidator instance.
@@ -166,6 +51,18 @@ declare const symbol: _sinclair_typebox.TSymbol;
166
51
  * TypeBox schema definition for undefined, null, void types.
167
52
  */
168
53
  declare const nullish: _sinclair_typebox.TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
54
+ /**
55
+ * TypeBox schema definition for void type.
56
+ */
57
+ declare const void_: _sinclair_typebox.TVoid;
58
+ /**
59
+ * TypeBox schema definition for null type.
60
+ */
61
+ declare const null_: _sinclair_typebox.TNull;
62
+ /**
63
+ * TypeBox schema definition for undefined type.
64
+ */
65
+ declare const undefined_: _sinclair_typebox.TUndefined;
169
66
  /**
170
67
  * TypeBox schema definition for any type.
171
68
  */
@@ -193,7 +90,7 @@ declare const array: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebo
193
90
  /**
194
91
  * Defines a union for a valid schema.
195
92
  */
196
- declare const union: <T extends TUnionContainer>(schemas: [...T]) => _sinclair_typebox.TUnion<UnionTResolve<T>>;
93
+ declare const union: <T extends TUnionTupleContainer>(schemas: [...T]) => _sinclair_typebox.TUnion<UnionTupleTResolve<T>>;
197
94
  /**
198
95
  * Defines a literal for a valid schema.
199
96
  */
@@ -202,6 +99,18 @@ declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.
202
99
  * Defines an enum for a valid schema.
203
100
  */
204
101
  declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => _sinclair_typebox.TUnion<[{ [K in keyof T]: _sinclair_typebox.TLiteral<T[K]>; }[keyof T]]>;
102
+ /**
103
+ * Defines a function for a valid schema.
104
+ */
105
+ declare const function_: <Args extends TUnionTupleContainer, ReturnType extends TIdiomaticSchema>(args: [...Args], returnType: ReturnType) => _sinclair_typebox.TFunction<UnionTupleTResolve<Args>, TResolve<ReturnType>>;
106
+ /**
107
+ * Defines a record for a valid schema.
108
+ */
109
+ declare const record: <Key extends TIdiomaticSchema, Value extends TIdiomaticSchema>(key: Key, value: Value) => _sinclair_typebox.TRecord<TResolve<Key>, TResolve<Value>>;
110
+ /**
111
+ * Defines a promise for a valid schema.
112
+ */
113
+ declare const promise: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebox.TPromise<TResolve<T>>;
205
114
  /**
206
115
  * Checks if a value is a TypeBox schema.
207
116
  */
@@ -209,14 +118,14 @@ declare const isSchema: (value: unknown) => value is _sinclair_typebox.TSchema;
209
118
  /**
210
119
  * Validates a value against a valid schema.
211
120
  */
212
- declare const validate: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => boolean;
121
+ declare const validate: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => boolean;
213
122
  /**
214
123
  * Parses a value against a valid schema.
215
124
  */
216
- declare const parse: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T>>;
125
+ declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T>>;
217
126
  /**
218
127
  * Generates an OpenAPI schema object from a valid schema.
219
128
  */
220
- declare const openapi: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
129
+ declare const openapi: <T extends TIdiomaticSchema | TCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
221
130
 
222
- export { SchemaValidator, TCatchall, TIdiomaticSchema, TObject, TResolve, TUnionContainer, TypeboxSchemaValidator, UnionTResolve, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
131
+ export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve, TUnionTupleContainer, TypeboxSchemaValidator, UnionTupleTResolve, any, array, bigint, boolean, date, email, enum_, function_, isSchema, literal, never, null_, nullish, number, openapi, optional, parse, promise, record, schemify, string, symbol, undefined_, union, unknown, uri, uuid, validate, void_ };
@@ -28,22 +28,28 @@ __export(typebox_exports, {
28
28
  date: () => date,
29
29
  email: () => email,
30
30
  enum_: () => enum_,
31
+ function_: () => function_,
31
32
  isSchema: () => isSchema,
32
33
  literal: () => literal,
33
34
  never: () => never,
35
+ null_: () => null_,
34
36
  nullish: () => nullish,
35
37
  number: () => number,
36
38
  openapi: () => openapi,
37
39
  optional: () => optional,
38
40
  parse: () => parse,
41
+ promise: () => promise,
42
+ record: () => record,
39
43
  schemify: () => schemify,
40
44
  string: () => string,
41
45
  symbol: () => symbol,
46
+ undefined_: () => undefined_,
42
47
  union: () => union,
43
48
  unknown: () => unknown,
44
49
  uri: () => uri,
45
50
  uuid: () => uuid,
46
- validate: () => validate
51
+ validate: () => validate,
52
+ void_: () => void_
47
53
  });
48
54
  module.exports = __toCommonJS(typebox_exports);
49
55
 
@@ -68,7 +74,6 @@ var TypeboxSchemaValidator = class {
68
74
  _SchemaCatchall;
69
75
  _ValidSchemaObject;
70
76
  string = import_typebox.Type.String();
71
- // uuid = Type.String({ format: 'uuid' });
72
77
  uuid = import_typebox.Type.String({
73
78
  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}$",
74
79
  errorType: "uuid"
@@ -181,6 +186,9 @@ var TypeboxSchemaValidator = class {
181
186
  nullish = import_typebox.Type.Union([import_typebox.Type.Void(), import_typebox.Type.Null(), import_typebox.Type.Undefined()], {
182
187
  errorType: "nullish"
183
188
  });
189
+ void = import_typebox.Type.Void();
190
+ null = import_typebox.Type.Null();
191
+ undefined = import_typebox.Type.Undefined();
184
192
  any = import_typebox.Type.Any();
185
193
  unknown = import_typebox.Type.Unknown();
186
194
  never = import_typebox.Type.Never();
@@ -191,7 +199,7 @@ var TypeboxSchemaValidator = class {
191
199
  * @returns The type of the schema for error messages.
192
200
  */
193
201
  errorType(schema) {
194
- if (Object.hasOwn(schema, "errorType")) {
202
+ if (import_typebox.KindGuard.IsSchema(schema) && Object.hasOwn(schema, "errorType")) {
195
203
  return schema.errorType;
196
204
  } else if (import_typebox.KindGuard.IsLiteral(schema)) {
197
205
  return schema.const;
@@ -236,7 +244,7 @@ var TypeboxSchemaValidator = class {
236
244
  * @returns {TOptional<TResolve<T>>} The optional schema.
237
245
  */
238
246
  optional(schema) {
239
- const schemified = import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
247
+ const schemified = this.schemify(schema);
240
248
  return import_typebox.Type.Optional(schemified);
241
249
  }
242
250
  /**
@@ -245,22 +253,22 @@ var TypeboxSchemaValidator = class {
245
253
  * @returns {TArray<TResolve<T>>} The array schema.
246
254
  */
247
255
  array(schema) {
248
- const schemified = import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
256
+ const schemified = this.schemify(schema);
249
257
  return import_typebox.Type.Array(schemified, {
250
258
  errorType: `array of ${this.errorType(schemified)}`
251
259
  });
252
260
  }
253
261
  /**
254
262
  * Create a union schema.
255
- * @param {TUnionContainer} schemas - The schemas to union.
256
- * @returns {TUnion<UnionTResolve<T>>} The union schema.
263
+ * @param {TUnionTupleContainer} schemas - The schemas to union.
264
+ * @returns {TUnion<UnionTupleTResolve<T>>} The union schema.
257
265
  *
258
266
  * WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
259
267
  * This is a limitation of TypeBox. Consider using "optional" instead.
260
268
  */
261
269
  union(schemas) {
262
270
  const unionTypes = schemas.map((schema) => {
263
- return import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
271
+ return this.schemify(schema);
264
272
  });
265
273
  return import_typebox.Type.Union(unionTypes, {
266
274
  errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(", ")}`,
@@ -280,13 +288,45 @@ var TypeboxSchemaValidator = class {
280
288
  /**
281
289
  * Create an enum schema.
282
290
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
283
- * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
291
+ * @returns {TUnion<UnionTupleTResolve<T[]>>} The enum schema.
284
292
  */
285
293
  enum_(schemaEnum) {
286
294
  return this.union(
287
295
  Object.values(schemaEnum).map((value) => this.literal(value))
288
296
  );
289
297
  }
298
+ /**
299
+ * Create a function schema.
300
+ * @param {TSchema[]} args - The arguments of the function.
301
+ * @param {TAny} returnType - The return type of the function.
302
+ * @returns {TFunction<Args, ReturnType>} The function schema.
303
+ */
304
+ function_(args, returnType) {
305
+ const schemaArgs = args.map((schema) => {
306
+ return this.schemify(schema);
307
+ });
308
+ const schemaReturnType = this.schemify(returnType);
309
+ return import_typebox.Type.Function(schemaArgs, schemaReturnType);
310
+ }
311
+ /**
312
+ * Create a record schema.
313
+ * @param {TIdiomaticSchema} key - The key schema.
314
+ * @param {TIdiomaticSchema} value - The value schema.
315
+ * @returns {TRecord<TResolve<Key>, TResolve<Value>>} The record schema.
316
+ */
317
+ record(key, value) {
318
+ const keySchema = this.schemify(key);
319
+ const valueSchema = this.schemify(value);
320
+ return import_typebox.Type.Record(keySchema, valueSchema);
321
+ }
322
+ /**
323
+ * Create a promise schema.
324
+ * @param {TIdiomaticSchema} schema - The schema to use for the promise.
325
+ * @returns {TPromise<TResolve<T>>} The promise schema.
326
+ */
327
+ promise(schema) {
328
+ return import_typebox.Type.Promise(this.schemify(schema));
329
+ }
290
330
  /**
291
331
  * Check if a value is a TypeBox object schema.
292
332
  * @param {unknown} value - The value to check.
@@ -306,7 +346,7 @@ var TypeboxSchemaValidator = class {
306
346
  if (schema instanceof import_compiler.TypeCheck) {
307
347
  return schema.Check(value);
308
348
  } else {
309
- const schemified = import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
349
+ const schemified = this.schemify(schema);
310
350
  return import_value.Value.Check(schemified, value);
311
351
  }
312
352
  }
@@ -327,7 +367,7 @@ var TypeboxSchemaValidator = class {
327
367
  errors = Array.from(schema.Errors(value));
328
368
  }
329
369
  } else {
330
- const schemified = import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
370
+ const schemified = this.schemify(schema);
331
371
  if (import_value.Value.Check(schemified, value)) {
332
372
  conversion = import_value.Value.Decode(schemified, value);
333
373
  } else {
@@ -374,11 +414,11 @@ var TypeboxSchemaValidator = class {
374
414
  }
375
415
  /**
376
416
  * Convert a schema to an OpenAPI schema object.
377
- * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
417
+ * @param {TIdiomaticSchema | TCatchall} schema - The schema to convert.
378
418
  * @returns {SchemaObject} The OpenAPI schema object.
379
419
  */
380
420
  openapi(schema) {
381
- const schemified = import_typebox.KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
421
+ const schemified = this.schemify(schema);
382
422
  if (Object.hasOwn(schemified, "openapiType") || import_typebox.KindGuard.IsLiteral(schemified)) {
383
423
  return schemified.openapiType;
384
424
  }
@@ -410,6 +450,9 @@ var boolean = StaticSchemaValidator.boolean;
410
450
  var date = StaticSchemaValidator.date;
411
451
  var symbol = StaticSchemaValidator.symbol;
412
452
  var nullish = StaticSchemaValidator.nullish;
453
+ var void_ = StaticSchemaValidator.void;
454
+ var null_ = StaticSchemaValidator.null;
455
+ var undefined_ = StaticSchemaValidator.undefined;
413
456
  var any = StaticSchemaValidator.any;
414
457
  var unknown = StaticSchemaValidator.unknown;
415
458
  var never = StaticSchemaValidator.never;
@@ -425,6 +468,13 @@ var literal = StaticSchemaValidator.literal.bind(
425
468
  StaticSchemaValidator
426
469
  );
427
470
  var enum_ = StaticSchemaValidator.enum_.bind(StaticSchemaValidator);
471
+ var function_ = StaticSchemaValidator.function_.bind(
472
+ StaticSchemaValidator
473
+ );
474
+ var record = StaticSchemaValidator.record.bind(StaticSchemaValidator);
475
+ var promise = StaticSchemaValidator.promise.bind(
476
+ StaticSchemaValidator
477
+ );
428
478
  var isSchema = StaticSchemaValidator.isSchema.bind(
429
479
  StaticSchemaValidator
430
480
  );
@@ -445,20 +495,26 @@ var openapi = StaticSchemaValidator.openapi.bind(
445
495
  date,
446
496
  email,
447
497
  enum_,
498
+ function_,
448
499
  isSchema,
449
500
  literal,
450
501
  never,
502
+ null_,
451
503
  nullish,
452
504
  number,
453
505
  openapi,
454
506
  optional,
455
507
  parse,
508
+ promise,
509
+ record,
456
510
  schemify,
457
511
  string,
458
512
  symbol,
513
+ undefined_,
459
514
  union,
460
515
  unknown,
461
516
  uri,
462
517
  uuid,
463
- validate
518
+ validate,
519
+ void_
464
520
  });
@@ -27,7 +27,6 @@ var TypeboxSchemaValidator = class {
27
27
  _SchemaCatchall;
28
28
  _ValidSchemaObject;
29
29
  string = Type.String();
30
- // uuid = Type.String({ format: 'uuid' });
31
30
  uuid = Type.String({
32
31
  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}$",
33
32
  errorType: "uuid"
@@ -140,6 +139,9 @@ var TypeboxSchemaValidator = class {
140
139
  nullish = Type.Union([Type.Void(), Type.Null(), Type.Undefined()], {
141
140
  errorType: "nullish"
142
141
  });
142
+ void = Type.Void();
143
+ null = Type.Null();
144
+ undefined = Type.Undefined();
143
145
  any = Type.Any();
144
146
  unknown = Type.Unknown();
145
147
  never = Type.Never();
@@ -150,7 +152,7 @@ var TypeboxSchemaValidator = class {
150
152
  * @returns The type of the schema for error messages.
151
153
  */
152
154
  errorType(schema) {
153
- if (Object.hasOwn(schema, "errorType")) {
155
+ if (KindGuard.IsSchema(schema) && Object.hasOwn(schema, "errorType")) {
154
156
  return schema.errorType;
155
157
  } else if (KindGuard.IsLiteral(schema)) {
156
158
  return schema.const;
@@ -195,7 +197,7 @@ var TypeboxSchemaValidator = class {
195
197
  * @returns {TOptional<TResolve<T>>} The optional schema.
196
198
  */
197
199
  optional(schema) {
198
- const schemified = KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
200
+ const schemified = this.schemify(schema);
199
201
  return Type.Optional(schemified);
200
202
  }
201
203
  /**
@@ -204,22 +206,22 @@ var TypeboxSchemaValidator = class {
204
206
  * @returns {TArray<TResolve<T>>} The array schema.
205
207
  */
206
208
  array(schema) {
207
- const schemified = KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
209
+ const schemified = this.schemify(schema);
208
210
  return Type.Array(schemified, {
209
211
  errorType: `array of ${this.errorType(schemified)}`
210
212
  });
211
213
  }
212
214
  /**
213
215
  * Create a union schema.
214
- * @param {TUnionContainer} schemas - The schemas to union.
215
- * @returns {TUnion<UnionTResolve<T>>} The union schema.
216
+ * @param {TUnionTupleContainer} schemas - The schemas to union.
217
+ * @returns {TUnion<UnionTupleTResolve<T>>} The union schema.
216
218
  *
217
219
  * WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
218
220
  * This is a limitation of TypeBox. Consider using "optional" instead.
219
221
  */
220
222
  union(schemas) {
221
223
  const unionTypes = schemas.map((schema) => {
222
- return KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
224
+ return this.schemify(schema);
223
225
  });
224
226
  return Type.Union(unionTypes, {
225
227
  errorType: `any of ${unionTypes.map((s) => this.errorType(s)).join(", ")}`,
@@ -239,13 +241,45 @@ var TypeboxSchemaValidator = class {
239
241
  /**
240
242
  * Create an enum schema.
241
243
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
242
- * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
244
+ * @returns {TUnion<UnionTupleTResolve<T[]>>} The enum schema.
243
245
  */
244
246
  enum_(schemaEnum) {
245
247
  return this.union(
246
248
  Object.values(schemaEnum).map((value) => this.literal(value))
247
249
  );
248
250
  }
251
+ /**
252
+ * Create a function schema.
253
+ * @param {TSchema[]} args - The arguments of the function.
254
+ * @param {TAny} returnType - The return type of the function.
255
+ * @returns {TFunction<Args, ReturnType>} The function schema.
256
+ */
257
+ function_(args, returnType) {
258
+ const schemaArgs = args.map((schema) => {
259
+ return this.schemify(schema);
260
+ });
261
+ const schemaReturnType = this.schemify(returnType);
262
+ return Type.Function(schemaArgs, schemaReturnType);
263
+ }
264
+ /**
265
+ * Create a record schema.
266
+ * @param {TIdiomaticSchema} key - The key schema.
267
+ * @param {TIdiomaticSchema} value - The value schema.
268
+ * @returns {TRecord<TResolve<Key>, TResolve<Value>>} The record schema.
269
+ */
270
+ record(key, value) {
271
+ const keySchema = this.schemify(key);
272
+ const valueSchema = this.schemify(value);
273
+ return Type.Record(keySchema, valueSchema);
274
+ }
275
+ /**
276
+ * Create a promise schema.
277
+ * @param {TIdiomaticSchema} schema - The schema to use for the promise.
278
+ * @returns {TPromise<TResolve<T>>} The promise schema.
279
+ */
280
+ promise(schema) {
281
+ return Type.Promise(this.schemify(schema));
282
+ }
249
283
  /**
250
284
  * Check if a value is a TypeBox object schema.
251
285
  * @param {unknown} value - The value to check.
@@ -265,7 +299,7 @@ var TypeboxSchemaValidator = class {
265
299
  if (schema instanceof TypeCheck) {
266
300
  return schema.Check(value);
267
301
  } else {
268
- const schemified = KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
302
+ const schemified = this.schemify(schema);
269
303
  return Value.Check(schemified, value);
270
304
  }
271
305
  }
@@ -286,7 +320,7 @@ var TypeboxSchemaValidator = class {
286
320
  errors = Array.from(schema.Errors(value));
287
321
  }
288
322
  } else {
289
- const schemified = KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
323
+ const schemified = this.schemify(schema);
290
324
  if (Value.Check(schemified, value)) {
291
325
  conversion = Value.Decode(schemified, value);
292
326
  } else {
@@ -333,11 +367,11 @@ var TypeboxSchemaValidator = class {
333
367
  }
334
368
  /**
335
369
  * Convert a schema to an OpenAPI schema object.
336
- * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
370
+ * @param {TIdiomaticSchema | TCatchall} schema - The schema to convert.
337
371
  * @returns {SchemaObject} The OpenAPI schema object.
338
372
  */
339
373
  openapi(schema) {
340
- const schemified = KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
374
+ const schemified = this.schemify(schema);
341
375
  if (Object.hasOwn(schemified, "openapiType") || KindGuard.IsLiteral(schemified)) {
342
376
  return schemified.openapiType;
343
377
  }
@@ -369,6 +403,9 @@ var boolean = StaticSchemaValidator.boolean;
369
403
  var date = StaticSchemaValidator.date;
370
404
  var symbol = StaticSchemaValidator.symbol;
371
405
  var nullish = StaticSchemaValidator.nullish;
406
+ var void_ = StaticSchemaValidator.void;
407
+ var null_ = StaticSchemaValidator.null;
408
+ var undefined_ = StaticSchemaValidator.undefined;
372
409
  var any = StaticSchemaValidator.any;
373
410
  var unknown = StaticSchemaValidator.unknown;
374
411
  var never = StaticSchemaValidator.never;
@@ -384,6 +421,13 @@ var literal = StaticSchemaValidator.literal.bind(
384
421
  StaticSchemaValidator
385
422
  );
386
423
  var enum_ = StaticSchemaValidator.enum_.bind(StaticSchemaValidator);
424
+ var function_ = StaticSchemaValidator.function_.bind(
425
+ StaticSchemaValidator
426
+ );
427
+ var record = StaticSchemaValidator.record.bind(StaticSchemaValidator);
428
+ var promise = StaticSchemaValidator.promise.bind(
429
+ StaticSchemaValidator
430
+ );
387
431
  var isSchema = StaticSchemaValidator.isSchema.bind(
388
432
  StaticSchemaValidator
389
433
  );
@@ -403,20 +447,26 @@ export {
403
447
  date,
404
448
  email,
405
449
  enum_,
450
+ function_,
406
451
  isSchema,
407
452
  literal,
408
453
  never,
454
+ null_,
409
455
  nullish,
410
456
  number,
411
457
  openapi,
412
458
  optional,
413
459
  parse,
460
+ promise,
461
+ record,
414
462
  schemify,
415
463
  string,
416
464
  symbol,
465
+ undefined_,
417
466
  union,
418
467
  unknown,
419
468
  uri,
420
469
  uuid,
421
- validate
470
+ validate,
471
+ void_
422
472
  };
@@ -1,6 +1,6 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { Z as ZodSchemaValidator, o as ZodIdiomaticSchema, p as ZodResolve, q as ZodUnionContainer, r as UnionZodResolve, L as LiteralSchema, s as ZodCatchall, a as ParseResult } from '../../schema.types-BA3PeCI5.mjs';
3
- export { x as UnboxedZodObjectSchema, v as ZodObject, u as ZodObjectShape, t as ZodOuterArray, w as ZodSchemaTranslate } from '../../schema.types-BA3PeCI5.mjs';
2
+ import { Z as ZodSchemaValidator, p as ZodIdiomaticSchema, q as ZodResolve, r as ZodUnionContainer, s as UnionZodResolve, L as LiteralSchema, t as ZodTupleContainer, u as TupleZodResolve, v as ZodRecordKey, w as ZodCatchall, a as ParseResult } from '../../schema.types-BL6n8u4w.mjs';
3
+ export { C as UnboxedZodObjectSchema, z as ZodObject, y as ZodObjectShape, x as ZodOuterArray, B as ZodSchemaTranslate } from '../../schema.types-BL6n8u4w.mjs';
4
4
  import * as zod from 'zod';
5
5
  import '@forklaunch/common';
6
6
  import '@sinclair/typebox';
@@ -51,6 +51,18 @@ declare const symbol: zod.ZodSymbol;
51
51
  * Zod schema definition for undefined, null, void types.
52
52
  */
53
53
  declare const nullish: zod.ZodUnion<[zod.ZodVoid, zod.ZodNull, zod.ZodUndefined]>;
54
+ /**
55
+ * Zod schema definition for void type.
56
+ */
57
+ declare const void_: zod.ZodVoid;
58
+ /**
59
+ * Zod schema definition for null type.
60
+ */
61
+ declare const null_: zod.ZodNull;
62
+ /**
63
+ * Zod schema definition for undefined type.
64
+ */
65
+ declare const undefined_: zod.ZodUndefined;
54
66
  /**
55
67
  * Zod schema definition for any type.
56
68
  */
@@ -82,11 +94,23 @@ declare const union: <T extends ZodUnionContainer>(schemas: T) => zod.ZodUnion<U
82
94
  /**
83
95
  * Defines a literal for a valid schema.
84
96
  */
85
- declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<ZodResolve<T>>;
97
+ declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<T>;
86
98
  /**
87
99
  * Defines an enum for a valid schema.
88
100
  */
89
101
  declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => zod.ZodUnion<[{ [K in keyof T]: zod.ZodLiteral<T[K]>; }[keyof T]]>;
102
+ /**
103
+ * Defines a function for a valid schema.
104
+ */
105
+ declare const function_: <Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType) => zod.ZodFunction<zod.ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>;
106
+ /**
107
+ * Defines a record for a valid schema.
108
+ */
109
+ declare const record: <Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value) => zod.ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>;
110
+ /**
111
+ * Defines a promise for a valid schema.
112
+ */
113
+ declare const promise: <T extends ZodIdiomaticSchema>(schema: T) => zod.ZodPromise<ZodResolve<T>>;
90
114
  /**
91
115
  * Checks if a value is a Zod schema.
92
116
  */
@@ -104,4 +128,4 @@ declare const parse: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, val
104
128
  */
105
129
  declare const openapi: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
106
130
 
107
- export { SchemaValidator, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodResolve, ZodSchemaValidator, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
131
+ export { SchemaValidator, TupleZodResolve, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodRecordKey, ZodResolve, ZodSchemaValidator, ZodTupleContainer, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, function_, isSchema, literal, never, null_, nullish, number, openapi, optional, parse, promise, record, schemify, string, symbol, undefined_, union, unknown, uri, uuid, validate, void_ };