@forklaunch/validator 0.4.12 → 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.
- package/lib/__test__/utils/mockSchemaValidator.d.mts +111 -3
- package/lib/__test__/utils/mockSchemaValidator.d.ts +111 -3
- package/lib/__test__/utils/mockSchemaValidator.js +105 -0
- package/lib/__test__/utils/mockSchemaValidator.mjs +102 -0
- package/lib/index.d.mts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/{schema.types-LkSEBFTv.d.mts → schema.types-BL6n8u4w.d.mts} +113 -20
- package/lib/{schema.types-LkSEBFTv.d.ts → schema.types-BL6n8u4w.d.ts} +113 -20
- package/lib/src/typebox/index.d.mts +28 -4
- package/lib/src/typebox/index.d.ts +28 -4
- package/lib/src/typebox/index.js +68 -11
- package/lib/src/typebox/index.mjs +61 -10
- package/lib/src/zod/index.d.mts +28 -4
- package/lib/src/zod/index.d.ts +28 -4
- package/lib/src/zod/index.js +65 -23
- package/lib/src/zod/index.mjs +60 -24
- package/package.json +2 -2
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Prettify } from '@forklaunch/common';
|
|
2
2
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
3
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
4
|
-
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TUnknown, TKind, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
|
|
4
|
+
import { TProperties, TOptional, TArray, TUnion, TLiteral, TFunction, TRecord, TPromise, TSchema, TUnknown, TKind, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
|
|
5
5
|
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
6
|
-
import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
|
|
6
|
+
import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodFunction, ZodTuple, ZodRecord, ZodPromise, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Class representing a TypeBox schema definition.
|
|
10
10
|
* @implements {SchemaValidator}
|
|
11
11
|
*/
|
|
12
|
-
declare class TypeboxSchemaValidator implements SchemaValidator<(<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
|
|
12
|
+
declare class TypeboxSchemaValidator implements SchemaValidator<(<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 TUnionTupleContainer>(schemas: [...T]) => TUnion<UnionTupleTResolve<T>>, <T extends LiteralSchema>(value: T) => TLiteral<T>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => TUnion<[
|
|
13
13
|
{
|
|
14
14
|
[K in keyof T]: TLiteral<T[K]>;
|
|
15
15
|
}[keyof T]
|
|
16
|
-
]>, (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> {
|
|
16
|
+
]>, <Args extends TUnionTupleContainer, ReturnType extends TIdiomaticSchema>(args: [...Args], returnType: ReturnType) => TFunction<UnionTupleTResolve<Args>, TResolve<ReturnType>>, <Key extends TIdiomaticSchema, Value extends TIdiomaticSchema>(key: Key, value: Value) => TRecord<TResolve<Key>, TResolve<Value>>, <T extends TIdiomaticSchema>(schema: T) => TPromise<TResolve<T>>, (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> {
|
|
17
17
|
_Type: "TypeBox";
|
|
18
18
|
_SchemaCatchall: TCatchall;
|
|
19
19
|
_ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
|
|
@@ -27,6 +27,9 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
27
27
|
date: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
28
28
|
symbol: _sinclair_typebox.TSymbol;
|
|
29
29
|
nullish: TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
30
|
+
void: _sinclair_typebox.TVoid;
|
|
31
|
+
null: _sinclair_typebox.TNull;
|
|
32
|
+
undefined: _sinclair_typebox.TUndefined;
|
|
30
33
|
any: _sinclair_typebox.TAny;
|
|
31
34
|
unknown: _sinclair_typebox.TUnknown;
|
|
32
35
|
never: _sinclair_typebox.TNever;
|
|
@@ -64,13 +67,13 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
64
67
|
array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
|
|
65
68
|
/**
|
|
66
69
|
* Create a union schema.
|
|
67
|
-
* @param {
|
|
68
|
-
* @returns {TUnion<
|
|
70
|
+
* @param {TUnionTupleContainer} schemas - The schemas to union.
|
|
71
|
+
* @returns {TUnion<UnionTupleTResolve<T>>} The union schema.
|
|
69
72
|
*
|
|
70
73
|
* WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
|
|
71
74
|
* This is a limitation of TypeBox. Consider using "optional" instead.
|
|
72
75
|
*/
|
|
73
|
-
union<T extends
|
|
76
|
+
union<T extends TUnionTupleContainer>(schemas: [...T]): TUnion<UnionTupleTResolve<T>>;
|
|
74
77
|
/**
|
|
75
78
|
* Create a literal schema.
|
|
76
79
|
* @param {LiteralSchema} value - The literal value.
|
|
@@ -80,13 +83,33 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
80
83
|
/**
|
|
81
84
|
* Create an enum schema.
|
|
82
85
|
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
83
|
-
* @returns {TUnion<
|
|
86
|
+
* @returns {TUnion<UnionTupleTResolve<T[]>>} The enum schema.
|
|
84
87
|
*/
|
|
85
88
|
enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): TUnion<[
|
|
86
89
|
{
|
|
87
90
|
[K in keyof T]: TLiteral<T[K]>;
|
|
88
91
|
}[keyof T]
|
|
89
92
|
]>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a function schema.
|
|
95
|
+
* @param {TSchema[]} args - The arguments of the function.
|
|
96
|
+
* @param {TAny} returnType - The return type of the function.
|
|
97
|
+
* @returns {TFunction<Args, ReturnType>} The function schema.
|
|
98
|
+
*/
|
|
99
|
+
function_<Args extends TUnionTupleContainer, ReturnType extends TIdiomaticSchema>(args: [...Args], returnType: ReturnType): TFunction<UnionTupleTResolve<Args>, TResolve<ReturnType>>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a record schema.
|
|
102
|
+
* @param {TIdiomaticSchema} key - The key schema.
|
|
103
|
+
* @param {TIdiomaticSchema} value - The value schema.
|
|
104
|
+
* @returns {TRecord<TResolve<Key>, TResolve<Value>>} The record schema.
|
|
105
|
+
*/
|
|
106
|
+
record<Key extends TIdiomaticSchema, Value extends TIdiomaticSchema>(key: Key, value: Value): TRecord<TResolve<Key>, TResolve<Value>>;
|
|
107
|
+
/**
|
|
108
|
+
* Create a promise schema.
|
|
109
|
+
* @param {TIdiomaticSchema} schema - The schema to use for the promise.
|
|
110
|
+
* @returns {TPromise<TResolve<T>>} The promise schema.
|
|
111
|
+
*/
|
|
112
|
+
promise<T extends TIdiomaticSchema>(schema: T): TPromise<TResolve<T>>;
|
|
90
113
|
/**
|
|
91
114
|
* Check if a value is a TypeBox object schema.
|
|
92
115
|
* @param {unknown} value - The value to check.
|
|
@@ -156,16 +179,16 @@ type TIdiomaticSchema = IdiomaticSchema<TypeboxSchemaValidator>;
|
|
|
156
179
|
/**
|
|
157
180
|
* Represents a container for a union of idiomatic schemas.
|
|
158
181
|
*/
|
|
159
|
-
type
|
|
182
|
+
type TUnionTupleContainer = [...TIdiomaticSchema[]];
|
|
160
183
|
/**
|
|
161
184
|
* Resolves a union container to a tuple of resolved idiomatic schemas.
|
|
162
185
|
*
|
|
163
186
|
* @template T - The union container to resolve.
|
|
164
187
|
*/
|
|
165
|
-
type
|
|
188
|
+
type UnionTupleTResolve<T extends TUnionTupleContainer, Acc extends TIdiomaticSchema[] = []> = T extends [
|
|
166
189
|
infer Head extends TIdiomaticSchema,
|
|
167
|
-
...infer Tail extends
|
|
168
|
-
] ?
|
|
190
|
+
...infer Tail extends TUnionTupleContainer
|
|
191
|
+
] ? UnionTupleTResolve<Tail, [...Acc, TResolve<Head>]> : T extends [] ? Acc : TNever[];
|
|
169
192
|
/**
|
|
170
193
|
* Resolves a schema type T to its resolved type. The depth is limited to 12 to prevent infinite recursion, due to StaticDecode limitations.
|
|
171
194
|
*
|
|
@@ -187,11 +210,11 @@ type TResolve<T, Depth extends number = 0> = Depth extends 12 ? TUnknown : T ext
|
|
|
187
210
|
* Class representing a Zod schema definition.
|
|
188
211
|
* @implements {StaticSchemaValidator}
|
|
189
212
|
*/
|
|
190
|
-
declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<
|
|
213
|
+
declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<T>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => ZodUnion<[
|
|
191
214
|
{
|
|
192
215
|
[K in keyof T]: ZodLiteral<T[K]>;
|
|
193
216
|
}[keyof T]
|
|
194
|
-
]>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
|
|
217
|
+
]>, <Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType) => ZodFunction<ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>, <Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value) => ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodPromise<ZodResolve<T>>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
|
|
195
218
|
_Type: "Zod";
|
|
196
219
|
_SchemaCatchall: ZodType;
|
|
197
220
|
_ValidSchemaObject: ZodObject$1<ZodRawShape> | ZodArray<ZodObject$1<ZodRawShape>>;
|
|
@@ -204,7 +227,10 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
204
227
|
boolean: z.ZodEffects<z.ZodBoolean, boolean, unknown>;
|
|
205
228
|
date: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodDate>;
|
|
206
229
|
symbol: z.ZodSymbol;
|
|
207
|
-
nullish: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
230
|
+
nullish: z.ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
231
|
+
void: z.ZodVoid;
|
|
232
|
+
null: z.ZodNull;
|
|
233
|
+
undefined: z.ZodUndefined;
|
|
208
234
|
any: z.ZodAny;
|
|
209
235
|
unknown: z.ZodUnknown;
|
|
210
236
|
never: z.ZodNever;
|
|
@@ -244,7 +270,7 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
244
270
|
* @param {LiteralSchema} value - The literal value.
|
|
245
271
|
* @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
|
|
246
272
|
*/
|
|
247
|
-
literal<T extends LiteralSchema>(value: T): ZodLiteral<
|
|
273
|
+
literal<T extends LiteralSchema>(value: T): ZodLiteral<T>;
|
|
248
274
|
/**
|
|
249
275
|
* Create an enum schema.
|
|
250
276
|
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
@@ -255,6 +281,26 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
255
281
|
[K in keyof T]: ZodLiteral<T[K]>;
|
|
256
282
|
}[keyof T]
|
|
257
283
|
]>;
|
|
284
|
+
/**
|
|
285
|
+
* Create a function schema.
|
|
286
|
+
* @param {ZodTuple} args - The arguments of the function.
|
|
287
|
+
* @param {ZodAny} returnType - The return type of the function.
|
|
288
|
+
* @returns {ZodFunction<Args, ReturnType>} The function schema.
|
|
289
|
+
*/
|
|
290
|
+
function_<Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType): ZodFunction<ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>;
|
|
291
|
+
/**
|
|
292
|
+
* Create a record schema.
|
|
293
|
+
* @param {ZodIdiomaticSchema} key - The key schema.
|
|
294
|
+
* @param {ZodIdiomaticSchema} value - The value schema.
|
|
295
|
+
* @returns {ZodRecord<ZodResolve<Key>, ZodResolve<Value>>} The record schema.
|
|
296
|
+
*/
|
|
297
|
+
record<Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value): ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>;
|
|
298
|
+
/**
|
|
299
|
+
* Create a promise schema.
|
|
300
|
+
* @param {ZodIdiomaticSchema} schema - The schema to use for the promise.
|
|
301
|
+
* @returns {ZodPromise<ZodResolve<T>>} The promise schema.
|
|
302
|
+
*/
|
|
303
|
+
promise<T extends ZodIdiomaticSchema>(schema: T): ZodPromise<ZodResolve<T>>;
|
|
258
304
|
/**
|
|
259
305
|
* Checks if a value is a Zod schema.
|
|
260
306
|
* @param {unknown} value - The value to check.
|
|
@@ -318,6 +364,24 @@ type UnboxedZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
|
|
|
318
364
|
* Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
|
|
319
365
|
*/
|
|
320
366
|
type ZodIdiomaticSchema = IdiomaticSchema<ZodSchemaValidator>;
|
|
367
|
+
/**
|
|
368
|
+
* Represents a container for a union of Zod idiomatic schemas.
|
|
369
|
+
*/
|
|
370
|
+
type ZodTupleContainer = readonly [] | readonly [ZodIdiomaticSchema, ...ZodIdiomaticSchema[]];
|
|
371
|
+
/**
|
|
372
|
+
* Resolves a union container to a tuple of resolved Zod idiomatic schemas.
|
|
373
|
+
*
|
|
374
|
+
* @template T - The union container to resolve.
|
|
375
|
+
*/
|
|
376
|
+
type TupleZodResolve<T extends ZodTupleContainer> = T extends [
|
|
377
|
+
infer A extends ZodIdiomaticSchema,
|
|
378
|
+
...infer B extends ZodIdiomaticSchema[]
|
|
379
|
+
] ? [
|
|
380
|
+
ZodResolve<A>,
|
|
381
|
+
...{
|
|
382
|
+
[K in keyof B]: ZodResolve<B[K]>;
|
|
383
|
+
}
|
|
384
|
+
] : [];
|
|
321
385
|
/**
|
|
322
386
|
* Represents a container for a union of Zod idiomatic schemas.
|
|
323
387
|
*/
|
|
@@ -351,6 +415,12 @@ type UnionZodResolve<T extends ZodUnionContainer> = T extends [
|
|
|
351
415
|
type ZodResolve<T, Depth extends number = 0> = Depth extends 29 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends UnboxedZodObjectSchema ? ZodObject<{
|
|
352
416
|
[K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
|
|
353
417
|
}> extends infer R ? R : ZodNever : ZodNever;
|
|
418
|
+
/**
|
|
419
|
+
* Represents the key type of a Zod record schema.
|
|
420
|
+
*
|
|
421
|
+
* @template T - The Zod idiomatic schema to get the key type from.
|
|
422
|
+
*/
|
|
423
|
+
type ZodRecordKey<T extends ZodIdiomaticSchema> = ZodResolve<T> extends infer R ? R extends boolean ? never : unknown extends R ? never : R : never;
|
|
354
424
|
|
|
355
425
|
/**
|
|
356
426
|
* Represents an error with a path and message.
|
|
@@ -382,7 +452,7 @@ type ParseResult<T> = {
|
|
|
382
452
|
* @template ParseFunction - The function type for parsing a value against a schema.
|
|
383
453
|
* @template OpenAPIFunction - The function type for converting a schema into an OpenAPI schema object.
|
|
384
454
|
*/
|
|
385
|
-
interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, SchematicFunction = <T>(schema: T) => unknown, OptionalFunction = <T>(schema: T) => unknown, ArrayFunction = <T>(schema: T) => unknown, UnionFunction = <T>(schemas: T[]) => unknown, LiteralFunction = <T extends LiteralSchema>(schema: T) => unknown, EnumFunction = <T extends LiteralSchema>(schemaEnum: Record<string, T>) => unknown, SchemaGuardFunction = <T>(value: unknown) => value is T, ValidationFunction = <T>(schema: T, value: unknown) => boolean, ParseFunction = <T>(schema: T, value: unknown) => ParseResult<SchemaResolve<T>>, OpenAPIFunction = <T>(schema: T) => SchemaObject> {
|
|
455
|
+
interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, SchematicFunction = <T>(schema: T) => unknown, OptionalFunction = <T>(schema: T) => unknown, ArrayFunction = <T>(schema: T) => unknown, UnionFunction = <T>(schemas: T[]) => unknown, LiteralFunction = <T extends LiteralSchema>(schema: T) => unknown, EnumFunction = <T extends LiteralSchema>(schemaEnum: Record<string, T>) => unknown, FunctionFunction = <Args, ReturnType>(args: Args, returnType: ReturnType) => unknown, RecordFunction = <Key, Value>(key: Key, value: Value) => unknown, PromiseFunction = <T>(schema: T) => unknown, SchemaGuardFunction = <T>(value: unknown) => value is T, ValidationFunction = <T>(schema: T, value: unknown) => boolean, ParseFunction = <T>(schema: T, value: unknown) => ParseResult<SchemaResolve<T>>, OpenAPIFunction = <T>(schema: T) => SchemaObject> {
|
|
386
456
|
/**
|
|
387
457
|
* The type of the schema validator.
|
|
388
458
|
*/
|
|
@@ -496,6 +566,29 @@ interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, Schem
|
|
|
496
566
|
* @returns {unknown} - The enum schema.
|
|
497
567
|
*/
|
|
498
568
|
enum_: EnumFunction;
|
|
569
|
+
/**
|
|
570
|
+
* Creates a function schema from a tuple of arguments and a return type.
|
|
571
|
+
*
|
|
572
|
+
* @param {Args} args - The arguments of the function.
|
|
573
|
+
* @param {ReturnType} returnType - The return type of the function.
|
|
574
|
+
* @returns {unknown} - The function schema.
|
|
575
|
+
*/
|
|
576
|
+
function_: FunctionFunction;
|
|
577
|
+
/**
|
|
578
|
+
* Creates a promise schema from a schema.
|
|
579
|
+
*
|
|
580
|
+
* @param {T} schema - The schema to use for the promise.
|
|
581
|
+
* @returns {unknown} - The promise schema.
|
|
582
|
+
*/
|
|
583
|
+
promise: PromiseFunction;
|
|
584
|
+
/**
|
|
585
|
+
* Creates a record schema from a key and value schema.
|
|
586
|
+
*
|
|
587
|
+
* @param {Key} key - The key schema.
|
|
588
|
+
* @param {Value} value - The value schema.
|
|
589
|
+
* @returns {unknown} - The record schema.
|
|
590
|
+
*/
|
|
591
|
+
record: RecordFunction;
|
|
499
592
|
/**
|
|
500
593
|
* Checks if a value is a schema.
|
|
501
594
|
*
|
|
@@ -530,7 +623,7 @@ interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, Schem
|
|
|
530
623
|
/**
|
|
531
624
|
* Type representing any schema validator.
|
|
532
625
|
*/
|
|
533
|
-
type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> & {
|
|
626
|
+
type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> & {
|
|
534
627
|
/**
|
|
535
628
|
* The type of the schema resolver.
|
|
536
629
|
*/
|
|
@@ -579,7 +672,7 @@ type SchemaPrettify<T, SV extends AnySchemaValidator> = Prettify<SchemaTranslate
|
|
|
579
672
|
* @template T - The type of the schema.
|
|
580
673
|
* @template SV - The type of the schema validator.
|
|
581
674
|
*/
|
|
582
|
-
type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends AnySchemaValidator> = SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV
|
|
675
|
+
type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends AnySchemaValidator> = SchemaTranslate<SchemaResolve<T>[SV['_Type']]>[SV['_Type']] extends infer Schema ? Schema extends (...args: infer Args) => infer Return ? (...args: Args) => Return : SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV> : never;
|
|
583
676
|
/**
|
|
584
677
|
* Represents a schema for an unboxed object where each key can have an idiomatic schema.
|
|
585
678
|
*
|
|
@@ -609,4 +702,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
|
|
|
609
702
|
*/
|
|
610
703
|
type KeyTypes = string | number;
|
|
611
704
|
|
|
612
|
-
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, TypeboxSchemaValidator as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type
|
|
705
|
+
export { type AnySchemaValidator as A, type ZodSchemaTranslate as B, type UnboxedZodObjectSchema as C, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, TypeboxSchemaValidator as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionTupleContainer as h, type UnionTupleTResolve as i, type TCatchall as j, type TOuterArray as k, type TObjectShape as l, type TObject as m, type TSchemaTranslate as n, type UnboxedTObjectSchema as o, type ZodIdiomaticSchema as p, type ZodResolve as q, type ZodUnionContainer as r, type UnionZodResolve as s, type ZodTupleContainer as t, type TupleZodResolve as u, type ZodRecordKey as v, type ZodCatchall as w, type ZodOuterArray as x, type ZodObjectShape as y, type ZodObject as z };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Prettify } from '@forklaunch/common';
|
|
2
2
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
3
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
4
|
-
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TUnknown, TKind, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
|
|
4
|
+
import { TProperties, TOptional, TArray, TUnion, TLiteral, TFunction, TRecord, TPromise, TSchema, TUnknown, TKind, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
|
|
5
5
|
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
6
|
-
import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
|
|
6
|
+
import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodFunction, ZodTuple, ZodRecord, ZodPromise, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Class representing a TypeBox schema definition.
|
|
10
10
|
* @implements {SchemaValidator}
|
|
11
11
|
*/
|
|
12
|
-
declare class TypeboxSchemaValidator implements SchemaValidator<(<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
|
|
12
|
+
declare class TypeboxSchemaValidator implements SchemaValidator<(<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 TUnionTupleContainer>(schemas: [...T]) => TUnion<UnionTupleTResolve<T>>, <T extends LiteralSchema>(value: T) => TLiteral<T>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => TUnion<[
|
|
13
13
|
{
|
|
14
14
|
[K in keyof T]: TLiteral<T[K]>;
|
|
15
15
|
}[keyof T]
|
|
16
|
-
]>, (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> {
|
|
16
|
+
]>, <Args extends TUnionTupleContainer, ReturnType extends TIdiomaticSchema>(args: [...Args], returnType: ReturnType) => TFunction<UnionTupleTResolve<Args>, TResolve<ReturnType>>, <Key extends TIdiomaticSchema, Value extends TIdiomaticSchema>(key: Key, value: Value) => TRecord<TResolve<Key>, TResolve<Value>>, <T extends TIdiomaticSchema>(schema: T) => TPromise<TResolve<T>>, (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> {
|
|
17
17
|
_Type: "TypeBox";
|
|
18
18
|
_SchemaCatchall: TCatchall;
|
|
19
19
|
_ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
|
|
@@ -27,6 +27,9 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
27
27
|
date: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
28
28
|
symbol: _sinclair_typebox.TSymbol;
|
|
29
29
|
nullish: TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
30
|
+
void: _sinclair_typebox.TVoid;
|
|
31
|
+
null: _sinclair_typebox.TNull;
|
|
32
|
+
undefined: _sinclair_typebox.TUndefined;
|
|
30
33
|
any: _sinclair_typebox.TAny;
|
|
31
34
|
unknown: _sinclair_typebox.TUnknown;
|
|
32
35
|
never: _sinclair_typebox.TNever;
|
|
@@ -64,13 +67,13 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
64
67
|
array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
|
|
65
68
|
/**
|
|
66
69
|
* Create a union schema.
|
|
67
|
-
* @param {
|
|
68
|
-
* @returns {TUnion<
|
|
70
|
+
* @param {TUnionTupleContainer} schemas - The schemas to union.
|
|
71
|
+
* @returns {TUnion<UnionTupleTResolve<T>>} The union schema.
|
|
69
72
|
*
|
|
70
73
|
* WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
|
|
71
74
|
* This is a limitation of TypeBox. Consider using "optional" instead.
|
|
72
75
|
*/
|
|
73
|
-
union<T extends
|
|
76
|
+
union<T extends TUnionTupleContainer>(schemas: [...T]): TUnion<UnionTupleTResolve<T>>;
|
|
74
77
|
/**
|
|
75
78
|
* Create a literal schema.
|
|
76
79
|
* @param {LiteralSchema} value - The literal value.
|
|
@@ -80,13 +83,33 @@ declare class TypeboxSchemaValidator implements SchemaValidator<(<T extends TObj
|
|
|
80
83
|
/**
|
|
81
84
|
* Create an enum schema.
|
|
82
85
|
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
83
|
-
* @returns {TUnion<
|
|
86
|
+
* @returns {TUnion<UnionTupleTResolve<T[]>>} The enum schema.
|
|
84
87
|
*/
|
|
85
88
|
enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): TUnion<[
|
|
86
89
|
{
|
|
87
90
|
[K in keyof T]: TLiteral<T[K]>;
|
|
88
91
|
}[keyof T]
|
|
89
92
|
]>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a function schema.
|
|
95
|
+
* @param {TSchema[]} args - The arguments of the function.
|
|
96
|
+
* @param {TAny} returnType - The return type of the function.
|
|
97
|
+
* @returns {TFunction<Args, ReturnType>} The function schema.
|
|
98
|
+
*/
|
|
99
|
+
function_<Args extends TUnionTupleContainer, ReturnType extends TIdiomaticSchema>(args: [...Args], returnType: ReturnType): TFunction<UnionTupleTResolve<Args>, TResolve<ReturnType>>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a record schema.
|
|
102
|
+
* @param {TIdiomaticSchema} key - The key schema.
|
|
103
|
+
* @param {TIdiomaticSchema} value - The value schema.
|
|
104
|
+
* @returns {TRecord<TResolve<Key>, TResolve<Value>>} The record schema.
|
|
105
|
+
*/
|
|
106
|
+
record<Key extends TIdiomaticSchema, Value extends TIdiomaticSchema>(key: Key, value: Value): TRecord<TResolve<Key>, TResolve<Value>>;
|
|
107
|
+
/**
|
|
108
|
+
* Create a promise schema.
|
|
109
|
+
* @param {TIdiomaticSchema} schema - The schema to use for the promise.
|
|
110
|
+
* @returns {TPromise<TResolve<T>>} The promise schema.
|
|
111
|
+
*/
|
|
112
|
+
promise<T extends TIdiomaticSchema>(schema: T): TPromise<TResolve<T>>;
|
|
90
113
|
/**
|
|
91
114
|
* Check if a value is a TypeBox object schema.
|
|
92
115
|
* @param {unknown} value - The value to check.
|
|
@@ -156,16 +179,16 @@ type TIdiomaticSchema = IdiomaticSchema<TypeboxSchemaValidator>;
|
|
|
156
179
|
/**
|
|
157
180
|
* Represents a container for a union of idiomatic schemas.
|
|
158
181
|
*/
|
|
159
|
-
type
|
|
182
|
+
type TUnionTupleContainer = [...TIdiomaticSchema[]];
|
|
160
183
|
/**
|
|
161
184
|
* Resolves a union container to a tuple of resolved idiomatic schemas.
|
|
162
185
|
*
|
|
163
186
|
* @template T - The union container to resolve.
|
|
164
187
|
*/
|
|
165
|
-
type
|
|
188
|
+
type UnionTupleTResolve<T extends TUnionTupleContainer, Acc extends TIdiomaticSchema[] = []> = T extends [
|
|
166
189
|
infer Head extends TIdiomaticSchema,
|
|
167
|
-
...infer Tail extends
|
|
168
|
-
] ?
|
|
190
|
+
...infer Tail extends TUnionTupleContainer
|
|
191
|
+
] ? UnionTupleTResolve<Tail, [...Acc, TResolve<Head>]> : T extends [] ? Acc : TNever[];
|
|
169
192
|
/**
|
|
170
193
|
* Resolves a schema type T to its resolved type. The depth is limited to 12 to prevent infinite recursion, due to StaticDecode limitations.
|
|
171
194
|
*
|
|
@@ -187,11 +210,11 @@ type TResolve<T, Depth extends number = 0> = Depth extends 12 ? TUnknown : T ext
|
|
|
187
210
|
* Class representing a Zod schema definition.
|
|
188
211
|
* @implements {StaticSchemaValidator}
|
|
189
212
|
*/
|
|
190
|
-
declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<
|
|
213
|
+
declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<T>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => ZodUnion<[
|
|
191
214
|
{
|
|
192
215
|
[K in keyof T]: ZodLiteral<T[K]>;
|
|
193
216
|
}[keyof T]
|
|
194
|
-
]>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
|
|
217
|
+
]>, <Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType) => ZodFunction<ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>, <Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value) => ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodPromise<ZodResolve<T>>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
|
|
195
218
|
_Type: "Zod";
|
|
196
219
|
_SchemaCatchall: ZodType;
|
|
197
220
|
_ValidSchemaObject: ZodObject$1<ZodRawShape> | ZodArray<ZodObject$1<ZodRawShape>>;
|
|
@@ -204,7 +227,10 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
204
227
|
boolean: z.ZodEffects<z.ZodBoolean, boolean, unknown>;
|
|
205
228
|
date: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodDate>;
|
|
206
229
|
symbol: z.ZodSymbol;
|
|
207
|
-
nullish: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
230
|
+
nullish: z.ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
231
|
+
void: z.ZodVoid;
|
|
232
|
+
null: z.ZodNull;
|
|
233
|
+
undefined: z.ZodUndefined;
|
|
208
234
|
any: z.ZodAny;
|
|
209
235
|
unknown: z.ZodUnknown;
|
|
210
236
|
never: z.ZodNever;
|
|
@@ -244,7 +270,7 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
244
270
|
* @param {LiteralSchema} value - The literal value.
|
|
245
271
|
* @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
|
|
246
272
|
*/
|
|
247
|
-
literal<T extends LiteralSchema>(value: T): ZodLiteral<
|
|
273
|
+
literal<T extends LiteralSchema>(value: T): ZodLiteral<T>;
|
|
248
274
|
/**
|
|
249
275
|
* Create an enum schema.
|
|
250
276
|
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
@@ -255,6 +281,26 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
255
281
|
[K in keyof T]: ZodLiteral<T[K]>;
|
|
256
282
|
}[keyof T]
|
|
257
283
|
]>;
|
|
284
|
+
/**
|
|
285
|
+
* Create a function schema.
|
|
286
|
+
* @param {ZodTuple} args - The arguments of the function.
|
|
287
|
+
* @param {ZodAny} returnType - The return type of the function.
|
|
288
|
+
* @returns {ZodFunction<Args, ReturnType>} The function schema.
|
|
289
|
+
*/
|
|
290
|
+
function_<Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType): ZodFunction<ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>;
|
|
291
|
+
/**
|
|
292
|
+
* Create a record schema.
|
|
293
|
+
* @param {ZodIdiomaticSchema} key - The key schema.
|
|
294
|
+
* @param {ZodIdiomaticSchema} value - The value schema.
|
|
295
|
+
* @returns {ZodRecord<ZodResolve<Key>, ZodResolve<Value>>} The record schema.
|
|
296
|
+
*/
|
|
297
|
+
record<Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value): ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>;
|
|
298
|
+
/**
|
|
299
|
+
* Create a promise schema.
|
|
300
|
+
* @param {ZodIdiomaticSchema} schema - The schema to use for the promise.
|
|
301
|
+
* @returns {ZodPromise<ZodResolve<T>>} The promise schema.
|
|
302
|
+
*/
|
|
303
|
+
promise<T extends ZodIdiomaticSchema>(schema: T): ZodPromise<ZodResolve<T>>;
|
|
258
304
|
/**
|
|
259
305
|
* Checks if a value is a Zod schema.
|
|
260
306
|
* @param {unknown} value - The value to check.
|
|
@@ -318,6 +364,24 @@ type UnboxedZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
|
|
|
318
364
|
* Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
|
|
319
365
|
*/
|
|
320
366
|
type ZodIdiomaticSchema = IdiomaticSchema<ZodSchemaValidator>;
|
|
367
|
+
/**
|
|
368
|
+
* Represents a container for a union of Zod idiomatic schemas.
|
|
369
|
+
*/
|
|
370
|
+
type ZodTupleContainer = readonly [] | readonly [ZodIdiomaticSchema, ...ZodIdiomaticSchema[]];
|
|
371
|
+
/**
|
|
372
|
+
* Resolves a union container to a tuple of resolved Zod idiomatic schemas.
|
|
373
|
+
*
|
|
374
|
+
* @template T - The union container to resolve.
|
|
375
|
+
*/
|
|
376
|
+
type TupleZodResolve<T extends ZodTupleContainer> = T extends [
|
|
377
|
+
infer A extends ZodIdiomaticSchema,
|
|
378
|
+
...infer B extends ZodIdiomaticSchema[]
|
|
379
|
+
] ? [
|
|
380
|
+
ZodResolve<A>,
|
|
381
|
+
...{
|
|
382
|
+
[K in keyof B]: ZodResolve<B[K]>;
|
|
383
|
+
}
|
|
384
|
+
] : [];
|
|
321
385
|
/**
|
|
322
386
|
* Represents a container for a union of Zod idiomatic schemas.
|
|
323
387
|
*/
|
|
@@ -351,6 +415,12 @@ type UnionZodResolve<T extends ZodUnionContainer> = T extends [
|
|
|
351
415
|
type ZodResolve<T, Depth extends number = 0> = Depth extends 29 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends UnboxedZodObjectSchema ? ZodObject<{
|
|
352
416
|
[K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
|
|
353
417
|
}> extends infer R ? R : ZodNever : ZodNever;
|
|
418
|
+
/**
|
|
419
|
+
* Represents the key type of a Zod record schema.
|
|
420
|
+
*
|
|
421
|
+
* @template T - The Zod idiomatic schema to get the key type from.
|
|
422
|
+
*/
|
|
423
|
+
type ZodRecordKey<T extends ZodIdiomaticSchema> = ZodResolve<T> extends infer R ? R extends boolean ? never : unknown extends R ? never : R : never;
|
|
354
424
|
|
|
355
425
|
/**
|
|
356
426
|
* Represents an error with a path and message.
|
|
@@ -382,7 +452,7 @@ type ParseResult<T> = {
|
|
|
382
452
|
* @template ParseFunction - The function type for parsing a value against a schema.
|
|
383
453
|
* @template OpenAPIFunction - The function type for converting a schema into an OpenAPI schema object.
|
|
384
454
|
*/
|
|
385
|
-
interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, SchematicFunction = <T>(schema: T) => unknown, OptionalFunction = <T>(schema: T) => unknown, ArrayFunction = <T>(schema: T) => unknown, UnionFunction = <T>(schemas: T[]) => unknown, LiteralFunction = <T extends LiteralSchema>(schema: T) => unknown, EnumFunction = <T extends LiteralSchema>(schemaEnum: Record<string, T>) => unknown, SchemaGuardFunction = <T>(value: unknown) => value is T, ValidationFunction = <T>(schema: T, value: unknown) => boolean, ParseFunction = <T>(schema: T, value: unknown) => ParseResult<SchemaResolve<T>>, OpenAPIFunction = <T>(schema: T) => SchemaObject> {
|
|
455
|
+
interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, SchematicFunction = <T>(schema: T) => unknown, OptionalFunction = <T>(schema: T) => unknown, ArrayFunction = <T>(schema: T) => unknown, UnionFunction = <T>(schemas: T[]) => unknown, LiteralFunction = <T extends LiteralSchema>(schema: T) => unknown, EnumFunction = <T extends LiteralSchema>(schemaEnum: Record<string, T>) => unknown, FunctionFunction = <Args, ReturnType>(args: Args, returnType: ReturnType) => unknown, RecordFunction = <Key, Value>(key: Key, value: Value) => unknown, PromiseFunction = <T>(schema: T) => unknown, SchemaGuardFunction = <T>(value: unknown) => value is T, ValidationFunction = <T>(schema: T, value: unknown) => boolean, ParseFunction = <T>(schema: T, value: unknown) => ParseResult<SchemaResolve<T>>, OpenAPIFunction = <T>(schema: T) => SchemaObject> {
|
|
386
456
|
/**
|
|
387
457
|
* The type of the schema validator.
|
|
388
458
|
*/
|
|
@@ -496,6 +566,29 @@ interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, Schem
|
|
|
496
566
|
* @returns {unknown} - The enum schema.
|
|
497
567
|
*/
|
|
498
568
|
enum_: EnumFunction;
|
|
569
|
+
/**
|
|
570
|
+
* Creates a function schema from a tuple of arguments and a return type.
|
|
571
|
+
*
|
|
572
|
+
* @param {Args} args - The arguments of the function.
|
|
573
|
+
* @param {ReturnType} returnType - The return type of the function.
|
|
574
|
+
* @returns {unknown} - The function schema.
|
|
575
|
+
*/
|
|
576
|
+
function_: FunctionFunction;
|
|
577
|
+
/**
|
|
578
|
+
* Creates a promise schema from a schema.
|
|
579
|
+
*
|
|
580
|
+
* @param {T} schema - The schema to use for the promise.
|
|
581
|
+
* @returns {unknown} - The promise schema.
|
|
582
|
+
*/
|
|
583
|
+
promise: PromiseFunction;
|
|
584
|
+
/**
|
|
585
|
+
* Creates a record schema from a key and value schema.
|
|
586
|
+
*
|
|
587
|
+
* @param {Key} key - The key schema.
|
|
588
|
+
* @param {Value} value - The value schema.
|
|
589
|
+
* @returns {unknown} - The record schema.
|
|
590
|
+
*/
|
|
591
|
+
record: RecordFunction;
|
|
499
592
|
/**
|
|
500
593
|
* Checks if a value is a schema.
|
|
501
594
|
*
|
|
@@ -530,7 +623,7 @@ interface SchemaValidator<CompilationFunction = <T>(schema: T) => unknown, Schem
|
|
|
530
623
|
/**
|
|
531
624
|
* Type representing any schema validator.
|
|
532
625
|
*/
|
|
533
|
-
type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> & {
|
|
626
|
+
type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> & {
|
|
534
627
|
/**
|
|
535
628
|
* The type of the schema resolver.
|
|
536
629
|
*/
|
|
@@ -579,7 +672,7 @@ type SchemaPrettify<T, SV extends AnySchemaValidator> = Prettify<SchemaTranslate
|
|
|
579
672
|
* @template T - The type of the schema.
|
|
580
673
|
* @template SV - The type of the schema validator.
|
|
581
674
|
*/
|
|
582
|
-
type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends AnySchemaValidator> = SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV
|
|
675
|
+
type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends AnySchemaValidator> = SchemaTranslate<SchemaResolve<T>[SV['_Type']]>[SV['_Type']] extends infer Schema ? Schema extends (...args: infer Args) => infer Return ? (...args: Args) => Return : SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV> : never;
|
|
583
676
|
/**
|
|
584
677
|
* Represents a schema for an unboxed object where each key can have an idiomatic schema.
|
|
585
678
|
*
|
|
@@ -609,4 +702,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
|
|
|
609
702
|
*/
|
|
610
703
|
type KeyTypes = string | number;
|
|
611
704
|
|
|
612
|
-
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, TypeboxSchemaValidator as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type
|
|
705
|
+
export { type AnySchemaValidator as A, type ZodSchemaTranslate as B, type UnboxedZodObjectSchema as C, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, TypeboxSchemaValidator as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionTupleContainer as h, type UnionTupleTResolve as i, type TCatchall as j, type TOuterArray as k, type TObjectShape as l, type TObject as m, type TSchemaTranslate as n, type UnboxedTObjectSchema as o, type ZodIdiomaticSchema as p, type ZodResolve as q, type ZodUnionContainer as r, type UnionZodResolve as s, type ZodTupleContainer as t, type TupleZodResolve as u, type ZodRecordKey as v, type ZodCatchall as w, type ZodOuterArray as x, type ZodObjectShape as y, type ZodObject as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
2
|
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
3
|
-
import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as
|
|
4
|
-
export { m as TObject, l as TObjectShape, k as TOuterArray, n as TSchemaTranslate, o as UnboxedTObjectSchema } from '../../schema.types-
|
|
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.mjs';
|
|
4
|
+
export { m as TObject, l as TObjectShape, k as TOuterArray, n as TSchemaTranslate, o as UnboxedTObjectSchema } from '../../schema.types-BL6n8u4w.mjs';
|
|
5
5
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
6
6
|
import '@forklaunch/common';
|
|
7
7
|
import 'zod';
|
|
@@ -51,6 +51,18 @@ declare const symbol: _sinclair_typebox.TSymbol;
|
|
|
51
51
|
* TypeBox schema definition for undefined, null, void types.
|
|
52
52
|
*/
|
|
53
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;
|
|
54
66
|
/**
|
|
55
67
|
* TypeBox schema definition for any type.
|
|
56
68
|
*/
|
|
@@ -78,7 +90,7 @@ declare const array: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebo
|
|
|
78
90
|
/**
|
|
79
91
|
* Defines a union for a valid schema.
|
|
80
92
|
*/
|
|
81
|
-
declare const union: <T extends
|
|
93
|
+
declare const union: <T extends TUnionTupleContainer>(schemas: [...T]) => _sinclair_typebox.TUnion<UnionTupleTResolve<T>>;
|
|
82
94
|
/**
|
|
83
95
|
* Defines a literal for a valid schema.
|
|
84
96
|
*/
|
|
@@ -87,6 +99,18 @@ declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.
|
|
|
87
99
|
* Defines an enum for a valid schema.
|
|
88
100
|
*/
|
|
89
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>>;
|
|
90
114
|
/**
|
|
91
115
|
* Checks if a value is a TypeBox schema.
|
|
92
116
|
*/
|
|
@@ -104,4 +128,4 @@ declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sincl
|
|
|
104
128
|
*/
|
|
105
129
|
declare const openapi: <T extends TIdiomaticSchema | TCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
|
|
106
130
|
|
|
107
|
-
export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve,
|
|
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_ };
|