@forklaunch/validator 0.1.1 → 0.1.2
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/dist/tests/typebox/equality.test.js.map +1 -1
- package/dist/types/schema.types.d.ts +21 -0
- package/dist/types/typebox.schema.types.d.ts +41 -0
- package/dist/types/zod.schema.types.d.ts +41 -0
- package/package.json +1 -1
- package/dist/tests/equality.test.d.ts +0 -0
- package/dist/tests/equality.test.js +0 -2
- package/dist/tests/equality.test.js.map +0 -1
- package/dist/tests/largeSchema.test.d.ts +0 -0
- package/dist/tests/largeSchema.test.js +0 -2
- package/dist/tests/largeSchema.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equality.test.js","sourceRoot":"","sources":["../../../tests/typebox/equality.test.ts"],"names":[],"mappings":";;;AACA,2CAAsJ;
|
|
1
|
+
{"version":3,"file":"equality.test.js","sourceRoot":"","sources":["../../../tests/typebox/equality.test.ts"],"names":[],"mappings":";;;AACA,2CAAsJ;AAEtJ,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC;IACd,IAAI,EAAE;QACF,CAAC,EAAE,IAAA,eAAK,EAAC,CAAC,gBAAM,EAAE,gBAAM,EAAE,cAAI,EAAE,iBAAO,EAAE,gBAAM,EAAE,eAAK,EAAE,gBAAM,EAAE,eAAK,CAAC,CAAC;QACvE,CAAC,EAAE,IAAA,kBAAQ,EAAC,IAAA,eAAK,EAAC,CAAC,IAAA,eAAK,EAAC;gBACrB,CAAC,EAAE,IAAA,eAAK,EAAC,gBAAM,CAAC;aACnB,CAAC,EAAE,gBAAM,CAAC,CAAC,CAAC;QACb,CAAC,EAAE;YACC,CAAC,EAAE,IAAA,kBAAQ,EAAC,gBAAM,CAAC;YACnB,CAAC,EAAE,gBAAM;YACT,CAAC,EAAE;gBACC,CAAC,EAAE,gBAAM;gBACT,CAAC,EAAE,gBAAM;aACZ;SACJ;KACJ;IACD,GAAG,EAAE;QACD,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,CAAC,EAAE,IAAA,kBAAQ,EAAC;YACR,CAAC,EAAE,IAAA,kBAAQ,EAAC,gBAAM,CAAC;YACnB,CAAC,EAAE,gBAAM;YACT,CAAC,EAAE;gBACC,CAAC,EAAE,gBAAM;gBACT,CAAC,EAAE,gBAAM;aACZ;SACJ,CAAC;KACL,CAAC;IACF,GAAG,EAAE,IAAA,kBAAQ,EAAC;QACV,CAAC,EAAE,gBAAM;KACZ,CAAC;IACF,CAAC,EAAE,IAAA,kBAAQ,EAAC;QACR,CAAC,EAAE,IAAa;KACnB,CAAC;CACL,CAAC,CAAC,CAAC,CAAA;AAEJ,SAAgB,MAAM,KAAqB,CAAC;AAA5C,wBAA4C;AAO5C,MAAM,EAAkC,CAAC;AACzC,MAAM,EAAoC,CAAC;AAC3C,MAAM,EAAoC,CAAC;AAE3C,MAAM,QAAQ,GAAG;IACb,CAAC,EAAE,gBAAM;IACT,GAAG,EAAE,gBAAM;CACd,CAAA;AAED,MAAM,QAAQ,GAAG,IAAA,kBAAQ,EAAC;IACtB,CAAC,EAAE,gBAAM;IACT,GAAG,EAAE,gBAAM;CACd,CAAC,CAAA;AAEF,MAAM,EAAgH,CAAC"}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a schema for an unboxed object where each key can have an idiomatic schema.
|
|
3
|
+
*
|
|
4
|
+
* @template Catchall - The type to use for catch-all cases in the schema.
|
|
5
|
+
*/
|
|
1
6
|
export type UnboxedObjectSchema<Catchall> = {
|
|
2
7
|
[key: KeyTypes]: IdiomaticSchema<Catchall>;
|
|
3
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Represents a schema that can be a literal value.
|
|
11
|
+
*/
|
|
4
12
|
export type LiteralSchema = string | number | boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Represents an idiomatic schema which can be an unboxed object schema, a literal schema, or a catch-all type.
|
|
15
|
+
*
|
|
16
|
+
* @template Catchall - The type to use for catch-all cases in the schema.
|
|
17
|
+
*/
|
|
5
18
|
export type IdiomaticSchema<Catchall> = UnboxedObjectSchema<Catchall> | LiteralSchema | Catchall;
|
|
19
|
+
/**
|
|
20
|
+
* Increments a number type by one, with support up to 50.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The number type to increment.
|
|
23
|
+
*/
|
|
6
24
|
export type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends 2 ? 3 : T extends 3 ? 4 : T extends 4 ? 5 : T extends 5 ? 6 : T extends 6 ? 7 : T extends 7 ? 8 : T extends 8 ? 9 : T extends 9 ? 10 : T extends 10 ? 11 : T extends 11 ? 12 : T extends 12 ? 13 : T extends 13 ? 14 : T extends 14 ? 15 : T extends 15 ? 16 : T extends 16 ? 17 : T extends 17 ? 18 : T extends 18 ? 19 : T extends 19 ? 20 : T extends 20 ? 21 : T extends 21 ? 22 : T extends 22 ? 23 : T extends 23 ? 24 : T extends 24 ? 25 : T extends 25 ? 26 : T extends 26 ? 27 : T extends 27 ? 28 : T extends 28 ? 29 : T extends 29 ? 30 : T extends 30 ? 31 : T extends 31 ? 32 : T extends 32 ? 33 : T extends 33 ? 34 : T extends 34 ? 35 : T extends 35 ? 36 : T extends 36 ? 37 : T extends 37 ? 38 : T extends 38 ? 39 : T extends 39 ? 40 : T extends 40 ? 41 : T extends 41 ? 42 : T extends 42 ? 43 : T extends 43 ? 44 : T extends 44 ? 45 : T extends 45 ? 46 : T extends 46 ? 47 : T extends 47 ? 48 : T extends 48 ? 49 : T extends 49 ? 50 : 50;
|
|
25
|
+
/**
|
|
26
|
+
* Represents key types that can be used in the schema.
|
|
27
|
+
*/
|
|
7
28
|
export type KeyTypes = string | number;
|
|
@@ -1,15 +1,50 @@
|
|
|
1
1
|
import { TSchema, TObject as OriginalTObject, TArray, TLiteral, TNever, Static, TProperties, TKind, TAny } from '@sinclair/typebox';
|
|
2
2
|
import { Increment, KeyTypes, LiteralSchema } from './schema.types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a catch-all schema type.
|
|
5
|
+
*/
|
|
3
6
|
export type TCatchall = TSchema;
|
|
7
|
+
/**
|
|
8
|
+
* Represents an outer array schema type. If the type T is an object shape, it will return an array schema of T. Otherwise, it returns TNever.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to check and possibly convert to an array schema.
|
|
11
|
+
*/
|
|
4
12
|
export type TOuterArray<T> = T extends TObject<TObjectShape> ? TArray<T> : TNever;
|
|
13
|
+
/**
|
|
14
|
+
* Represents the shape of an object schema.
|
|
15
|
+
*/
|
|
5
16
|
export type TObjectShape = TProperties;
|
|
17
|
+
/**
|
|
18
|
+
* Represents an object schema type. If the type T is an object shape, it will return the original TObject type of T. Otherwise, it returns TNever.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The type to check and possibly convert to an object schema.
|
|
21
|
+
*/
|
|
6
22
|
export type TObject<T> = T extends TObjectShape ? OriginalTObject<T> : TNever;
|
|
23
|
+
/**
|
|
24
|
+
* Translates a schema type T to its static type if T extends TCatchall. Otherwise, it returns TNever.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The schema type to translate.
|
|
27
|
+
*/
|
|
7
28
|
export type TSchemaTranslate<T> = T extends TCatchall ? Static<T> : TNever;
|
|
29
|
+
/**
|
|
30
|
+
* Represents an unboxed object schema where each key can have an idiomatic schema.
|
|
31
|
+
*/
|
|
8
32
|
export type UnboxedTObjectSchema = {
|
|
9
33
|
[key: KeyTypes]: TIdiomaticSchema;
|
|
10
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Represents an idiomatic schema which can be an unboxed object schema or a literal schema.
|
|
37
|
+
*/
|
|
11
38
|
export type TIdiomaticSchema = UnboxedTObjectSchema | LiteralSchema;
|
|
39
|
+
/**
|
|
40
|
+
* Represents a container for a union of idiomatic schemas.
|
|
41
|
+
*/
|
|
12
42
|
export type TUnionContainer = [...TIdiomaticSchema[]];
|
|
43
|
+
/**
|
|
44
|
+
* Resolves a union container to a tuple of resolved idiomatic schemas.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The union container to resolve.
|
|
47
|
+
*/
|
|
13
48
|
export type UnionTResolve<T extends TUnionContainer> = T extends [
|
|
14
49
|
...infer A extends TIdiomaticSchema[]
|
|
15
50
|
] ? [
|
|
@@ -17,6 +52,12 @@ export type UnionTResolve<T extends TUnionContainer> = T extends [
|
|
|
17
52
|
[K in keyof A]: TResolve<A[K]>;
|
|
18
53
|
}
|
|
19
54
|
] : [];
|
|
55
|
+
/**
|
|
56
|
+
* Resolves a schema type T to its resolved type. The depth is limited to 40 to prevent infinite recursion.
|
|
57
|
+
*
|
|
58
|
+
* @template T - The schema type to resolve.
|
|
59
|
+
* @template Depth - The current depth of the resolution.
|
|
60
|
+
*/
|
|
20
61
|
export type TResolve<T, Depth extends number = 0> = Depth extends 22 ? TAny : T extends TKind ? T : T extends LiteralSchema ? TLiteral<T> : T extends UnboxedTObjectSchema ? TObject<{
|
|
21
62
|
[K in keyof T]: TResolve<T[K], Increment<Depth>>;
|
|
22
63
|
}> : TNever;
|
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
import { ZodArray, ZodObject as OriginalZodObject, ZodRawShape, ZodType, ZodTypeAny, z, ZodLiteral, ZodNever, ZodAny } from "zod";
|
|
2
2
|
import { IdiomaticSchema, UnboxedObjectSchema, LiteralSchema, Increment } from "./schema.types";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a catch-all Zod schema type.
|
|
5
|
+
*/
|
|
3
6
|
export type ZodCatchall = ZodTypeAny;
|
|
7
|
+
/**
|
|
8
|
+
* Represents an outer array schema type for Zod. If the type T is a Zod object, it will return an array schema of T. Otherwise, it returns ZodNever.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to check and possibly convert to an array schema.
|
|
11
|
+
*/
|
|
4
12
|
export type ZodOuterArray<T> = T extends ZodObject<ZodObjectShape> ? ZodArray<T> : ZodNever;
|
|
13
|
+
/**
|
|
14
|
+
* Represents the shape of a Zod object schema.
|
|
15
|
+
*/
|
|
5
16
|
export type ZodObjectShape = ZodRawShape;
|
|
17
|
+
/**
|
|
18
|
+
* Represents a Zod object schema type. If the type T is a Zod object shape, it will return the original ZodObject type of T. Otherwise, it returns ZodNever.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The type to check and possibly convert to a Zod object schema.
|
|
21
|
+
*/
|
|
6
22
|
export type ZodObject<T> = T extends ZodObjectShape ? OriginalZodObject<T> : ZodNever;
|
|
23
|
+
/**
|
|
24
|
+
* Translates a Zod schema type T to its static type if T extends ZodCatchall. Otherwise, it returns ZodNever.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The Zod schema type to translate.
|
|
27
|
+
*/
|
|
7
28
|
export type ZodSchemaTranslate<T> = T extends ZodCatchall ? z.infer<T> : ZodNever;
|
|
29
|
+
/**
|
|
30
|
+
* Represents an unboxed Zod object schema where each key can have an idiomatic schema.
|
|
31
|
+
*/
|
|
8
32
|
export type ZodObjectSchema = UnboxedObjectSchema<ZodCatchall>;
|
|
33
|
+
/**
|
|
34
|
+
* Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
|
|
35
|
+
*/
|
|
9
36
|
export type ZodIdiomaticSchema = IdiomaticSchema<ZodCatchall>;
|
|
37
|
+
/**
|
|
38
|
+
* Represents a container for a union of Zod idiomatic schemas.
|
|
39
|
+
*/
|
|
10
40
|
export type ZodUnionContainer = readonly [ZodIdiomaticSchema, ZodIdiomaticSchema, ...ZodIdiomaticSchema[]];
|
|
41
|
+
/**
|
|
42
|
+
* Resolves a union container to a tuple of resolved Zod idiomatic schemas.
|
|
43
|
+
*
|
|
44
|
+
* @template T - The union container to resolve.
|
|
45
|
+
*/
|
|
11
46
|
export type UnionZodResolve<T extends ZodUnionContainer> = T extends [
|
|
12
47
|
infer A extends ZodIdiomaticSchema,
|
|
13
48
|
infer B extends ZodIdiomaticSchema,
|
|
@@ -19,6 +54,12 @@ export type UnionZodResolve<T extends ZodUnionContainer> = T extends [
|
|
|
19
54
|
[K in keyof C]: ZodResolve<C[K]>;
|
|
20
55
|
}
|
|
21
56
|
] : [ZodNever, ZodNever];
|
|
57
|
+
/**
|
|
58
|
+
* Resolves a Zod schema type T to its resolved type. The depth is limited to 22 to prevent infinite recursion.
|
|
59
|
+
*
|
|
60
|
+
* @template T - The Zod schema type to resolve.
|
|
61
|
+
* @template Depth - The current depth of the resolution.
|
|
62
|
+
*/
|
|
22
63
|
export type ZodResolve<T, Depth extends number = 0> = Depth extends 22 ? ZodAny : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType | ZodObject<any> ? T : T extends ZodObjectSchema ? ZodObject<{
|
|
23
64
|
[K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
|
|
24
65
|
}> : ZodNever;
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"equality.test.js","sourceRoot":"","sources":["../../tests/equality.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"largeSchema.test.js","sourceRoot":"","sources":["../../tests/largeSchema.test.ts"],"names":[],"mappings":""}
|