@sinclair/typebox 0.32.0-dev-21 → 0.32.0-dev-22
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/build/import/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.d.mts +4 -6
- package/build/import/type/awaited/awaited.mjs +3 -3
- package/build/import/type/composite/composite.d.mts +8 -8
- package/build/import/type/const/const.d.mts +4 -7
- package/build/import/type/constructor/constructor.d.mts +4 -4
- package/build/import/type/deref/deref.d.mts +2 -2
- package/build/import/type/deref/deref.mjs +26 -36
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +4 -6
- package/build/import/type/exclude/exclude.d.mts +7 -8
- package/build/import/type/extends/extends-from-mapped-key.d.mts +5 -8
- package/build/import/type/extends/extends-from-mapped-key.mjs +3 -3
- package/build/import/type/extends/extends-from-mapped-result.d.mts +4 -6
- package/build/import/type/extends/extends.d.mts +2 -3
- package/build/import/type/extract/extract-from-mapped-result.d.mts +4 -6
- package/build/import/type/extract/extract.d.mts +8 -8
- package/build/import/type/function/function.d.mts +1 -1
- package/build/import/type/helpers/helpers.d.mts +1 -1
- package/build/import/type/index.d.mts +0 -1
- package/build/import/type/index.mjs +0 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +5 -8
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +3 -6
- package/build/import/type/indexed/indexed-property-keys.d.mts +4 -7
- package/build/import/type/indexed/indexed.d.mts +13 -23
- package/build/import/type/indexed/indexed.mjs +13 -13
- package/build/import/type/intersect/intersect-create.mjs +0 -1
- package/build/import/type/intersect/intersect-evaluated.d.mts +7 -11
- package/build/import/type/intersect/intersect-evaluated.mjs +12 -7
- package/build/import/type/intersect/intersect-type.d.mts +2 -2
- package/build/import/type/intersect/intersect.mjs +1 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +7 -9
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +3 -3
- package/build/import/type/intrinsic/intrinsic.d.mts +6 -8
- package/build/import/type/intrinsic/intrinsic.mjs +5 -3
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +4 -6
- package/build/import/type/keyof/keyof-property-keys.d.mts +9 -13
- package/build/import/type/keyof/keyof-property-keys.mjs +12 -9
- package/build/import/type/keyof/keyof.d.mts +7 -8
- package/build/import/type/keyof/keyof.mjs +8 -6
- package/build/import/type/mapped/mapped.d.mts +9 -13
- package/build/import/type/mapped/mapped.mjs +9 -9
- package/build/import/type/omit/omit-from-mapped-key.d.mts +5 -8
- package/build/import/type/omit/omit-from-mapped-key.mjs +3 -3
- package/build/import/type/omit/omit.d.mts +6 -9
- package/build/import/type/omit/omit.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +16 -16
- package/build/import/type/operators/operators.mjs +21 -25
- package/build/import/type/optional/optional-from-mapped-result.d.mts +4 -6
- package/build/import/type/optional/optional.d.mts +3 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +4 -6
- package/build/import/type/partial/partial.d.mts +4 -7
- package/build/import/type/partial/partial.mjs +6 -7
- package/build/import/type/pick/pick-from-mapped-key.d.mts +5 -8
- package/build/import/type/pick/pick-from-mapped-key.mjs +3 -3
- package/build/import/type/pick/pick.d.mts +4 -4
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +4 -6
- package/build/import/type/readonly/readonly.d.mts +3 -7
- package/build/import/type/record/record.d.mts +13 -19
- package/build/import/type/record/record.mjs +0 -1
- package/build/import/type/ref/ref.mjs +3 -0
- package/build/import/type/required/required-from-mapped-result.d.mts +4 -6
- package/build/import/type/required/required.d.mts +5 -9
- package/build/import/type/required/required.mjs +6 -7
- package/build/import/type/rest/rest.d.mts +3 -3
- package/build/import/type/static/static.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +3 -3
- package/build/import/type/template-literal/generate.d.mts +7 -8
- package/build/import/type/template-literal/syntax.d.mts +2 -2
- package/build/import/type/template-literal/syntax.mjs +2 -2
- package/build/import/type/transform/transform.mjs +0 -1
- package/build/import/type/tuple/tuple.d.mts +1 -2
- package/build/import/type/union/union-evaluated.d.mts +6 -10
- package/build/import/type/union/union-evaluated.mjs +7 -2
- package/build/require/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.d.ts +4 -6
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/composite/composite.d.ts +8 -8
- package/build/require/type/const/const.d.ts +4 -7
- package/build/require/type/constructor/constructor.d.ts +4 -4
- package/build/require/type/deref/deref.d.ts +2 -2
- package/build/require/type/deref/deref.js +25 -35
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +4 -6
- package/build/require/type/exclude/exclude.d.ts +7 -8
- package/build/require/type/extends/extends-from-mapped-key.d.ts +5 -8
- package/build/require/type/extends/extends-from-mapped-key.js +3 -3
- package/build/require/type/extends/extends-from-mapped-result.d.ts +4 -6
- package/build/require/type/extends/extends.d.ts +2 -3
- package/build/require/type/extract/extract-from-mapped-result.d.ts +4 -6
- package/build/require/type/extract/extract.d.ts +8 -8
- package/build/require/type/function/function.d.ts +1 -1
- package/build/require/type/helpers/helpers.d.ts +1 -1
- package/build/require/type/index.d.ts +0 -1
- package/build/require/type/index.js +0 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +5 -8
- package/build/require/type/indexed/indexed-from-mapped-key.js +3 -6
- package/build/require/type/indexed/indexed-property-keys.d.ts +4 -7
- package/build/require/type/indexed/indexed.d.ts +13 -23
- package/build/require/type/indexed/indexed.js +13 -13
- package/build/require/type/intersect/intersect-create.js +0 -1
- package/build/require/type/intersect/intersect-evaluated.d.ts +7 -11
- package/build/require/type/intersect/intersect-evaluated.js +9 -4
- package/build/require/type/intersect/intersect-type.d.ts +2 -2
- package/build/require/type/intersect/intersect.js +0 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +7 -9
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +3 -3
- package/build/require/type/intrinsic/intrinsic.d.ts +6 -8
- package/build/require/type/intrinsic/intrinsic.js +5 -3
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +4 -6
- package/build/require/type/keyof/keyof-property-keys.d.ts +9 -13
- package/build/require/type/keyof/keyof-property-keys.js +12 -9
- package/build/require/type/keyof/keyof.d.ts +7 -8
- package/build/require/type/keyof/keyof.js +8 -6
- package/build/require/type/mapped/mapped.d.ts +9 -13
- package/build/require/type/mapped/mapped.js +9 -9
- package/build/require/type/omit/omit-from-mapped-key.d.ts +5 -8
- package/build/require/type/omit/omit-from-mapped-key.js +3 -3
- package/build/require/type/omit/omit.d.ts +6 -9
- package/build/require/type/omit/omit.js +0 -1
- package/build/require/type/operators/operators.d.ts +16 -16
- package/build/require/type/operators/operators.js +21 -25
- package/build/require/type/optional/optional-from-mapped-result.d.ts +4 -6
- package/build/require/type/optional/optional.d.ts +3 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +4 -6
- package/build/require/type/partial/partial.d.ts +4 -7
- package/build/require/type/partial/partial.js +6 -7
- package/build/require/type/pick/pick-from-mapped-key.d.ts +5 -8
- package/build/require/type/pick/pick-from-mapped-key.js +3 -3
- package/build/require/type/pick/pick.d.ts +4 -4
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +4 -6
- package/build/require/type/readonly/readonly.d.ts +3 -7
- package/build/require/type/record/record.d.ts +13 -19
- package/build/require/type/record/record.js +0 -1
- package/build/require/type/ref/ref.js +3 -0
- package/build/require/type/required/required-from-mapped-result.d.ts +4 -6
- package/build/require/type/required/required.d.ts +5 -9
- package/build/require/type/required/required.js +6 -7
- package/build/require/type/rest/rest.d.ts +3 -3
- package/build/require/type/static/static.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +3 -3
- package/build/require/type/template-literal/generate.d.ts +7 -8
- package/build/require/type/template-literal/syntax.d.ts +2 -2
- package/build/require/type/template-literal/syntax.js +1 -1
- package/build/require/type/transform/transform.js +0 -1
- package/build/require/type/tuple/tuple.d.ts +1 -2
- package/build/require/type/union/union-evaluated.d.ts +6 -10
- package/build/require/type/union/union-evaluated.js +7 -2
- package/package.json +1 -1
- package/build/import/type/modifiers/index.d.mts +0 -1
- package/build/import/type/modifiers/index.mjs +0 -1
- package/build/import/type/modifiers/modifiers.d.mts +0 -18
- package/build/import/type/modifiers/modifiers.mjs +0 -50
- package/build/require/type/modifiers/index.d.ts +0 -1
- package/build/require/type/modifiers/index.js +0 -18
- package/build/require/type/modifiers/modifiers.d.ts +0 -18
- package/build/require/type/modifiers/modifiers.js +0 -56
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type TOperatorIncludes<T extends PropertyKey[], S extends PropertyKey> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? S extends L ? true : TOperatorIncludes<R, S> : false);
|
|
2
2
|
/** Returns true if element S is in the set of T */
|
|
3
|
-
export declare function OperatorIncludes<T extends PropertyKey[], S extends PropertyKey>(T: [...T], S: S):
|
|
4
|
-
export type
|
|
3
|
+
export declare function OperatorIncludes<T extends PropertyKey[], S extends PropertyKey>(T: [...T], S: S): TOperatorIncludes<T, S>;
|
|
4
|
+
export type TOperatorSubset<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? TOperatorSubset<R, S> : false : true);
|
|
5
5
|
/** Returns true if T is a subset of S */
|
|
6
|
-
export declare function OperatorSubset<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]):
|
|
7
|
-
export type
|
|
6
|
+
export declare function OperatorSubset<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TOperatorSubset<T, S>;
|
|
7
|
+
export type TOperatorDistinct<T extends PropertyKey[], Acc extends PropertyKey[] = []> = T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<Acc, L> extends false ? TOperatorDistinct<R, [...Acc, L]> : TOperatorDistinct<R, [...Acc]> : Acc;
|
|
8
8
|
/** Returns a distinct set of elements */
|
|
9
|
-
export declare function OperatorDistinct<T extends PropertyKey[]>(T: [...T], Acc?: PropertyKey[]):
|
|
10
|
-
export type
|
|
9
|
+
export declare function OperatorDistinct<T extends PropertyKey[]>(T: [...T], Acc?: PropertyKey[]): TOperatorDistinct<T>;
|
|
10
|
+
export type TOperatorIntersect<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? TOperatorIntersect<R, S, [L, ...Acc]> : TOperatorIntersect<R, S, [...Acc]> : Acc);
|
|
11
11
|
/** Returns the Intersect of the given sets */
|
|
12
|
-
export declare function OperatorIntersect<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]):
|
|
13
|
-
export type
|
|
12
|
+
export declare function OperatorIntersect<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TOperatorIntersect<T, S>;
|
|
13
|
+
export type TOperatorUnion<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = S> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorUnion<R, S, [...Acc, L]> : Acc);
|
|
14
14
|
/** Returns the Union of the given sets */
|
|
15
|
-
export declare function OperatorUnion<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]):
|
|
16
|
-
export type OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ?
|
|
15
|
+
export declare function OperatorUnion<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S], Acc?: PropertyKey[]): TOperatorUnion<T, S>;
|
|
16
|
+
export type OperatorComplement<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TOperatorIncludes<S, L> extends true ? OperatorComplement<R, S, [...Acc]> : OperatorComplement<R, S, [L, ...Acc]> : Acc);
|
|
17
17
|
/** Returns the Complement by omitting elements in T that are in S */
|
|
18
|
-
export declare function OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): OperatorComplement<T, S>;
|
|
19
|
-
export type OperatorIntersectMany<T extends PropertyKey[][]> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ?
|
|
18
|
+
export declare function OperatorComplement<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S], Acc?: PropertyKey[]): OperatorComplement<T, S>;
|
|
19
|
+
export type OperatorIntersectMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorIntersectMany<R, TOperatorIntersect<Acc, L>> : Acc);
|
|
20
20
|
/** Returns the Intersect of multiple sets */
|
|
21
|
-
export declare function OperatorIntersectMany<T extends PropertyKey[][]>(T: [...T]): OperatorIntersectMany<T>;
|
|
22
|
-
export type OperatorUnionMany<T extends PropertyKey[][]
|
|
21
|
+
export declare function OperatorIntersectMany<T extends PropertyKey[][]>(T: [...T], Acc?: PropertyKey[]): OperatorIntersectMany<T>;
|
|
22
|
+
export type OperatorUnionMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? OperatorUnionMany<R, TOperatorUnion<Acc, L>> : Acc);
|
|
23
23
|
/** Returns the Union of multiple sets */
|
|
24
|
-
export declare function OperatorUnionMany<T extends PropertyKey[][]>(T: [...T]): OperatorUnionMany<T>;
|
|
24
|
+
export declare function OperatorUnionMany<T extends PropertyKey[][]>(T: [...T], Acc?: PropertyKey[]): OperatorUnionMany<T>;
|
|
@@ -9,9 +9,9 @@ export function OperatorIncludes(T, S) {
|
|
|
9
9
|
: false);
|
|
10
10
|
}
|
|
11
11
|
/** Returns true if T is a subset of S */
|
|
12
|
-
// prettier-ignore
|
|
13
12
|
export function OperatorSubset(T, S) {
|
|
14
13
|
const [L, ...R] = T;
|
|
14
|
+
// prettier-ignore
|
|
15
15
|
return (T.length > 0
|
|
16
16
|
? OperatorIncludes(S, L) === true
|
|
17
17
|
? OperatorSubset(R, S)
|
|
@@ -19,19 +19,18 @@ export function OperatorSubset(T, S) {
|
|
|
19
19
|
: true);
|
|
20
20
|
}
|
|
21
21
|
/** Returns a distinct set of elements */
|
|
22
|
-
// prettier-ignore
|
|
23
22
|
export function OperatorDistinct(T, Acc = []) {
|
|
24
23
|
const [L, ...R] = T;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// prettier-ignore
|
|
25
|
+
return (T.length > 0 ?
|
|
26
|
+
(OperatorIncludes(Acc, L) === false
|
|
27
27
|
? OperatorDistinct(R, [...Acc, L])
|
|
28
|
-
: OperatorDistinct(R, [...Acc])
|
|
29
|
-
: Acc);
|
|
28
|
+
: OperatorDistinct(R, [...Acc])) : Acc);
|
|
30
29
|
}
|
|
31
30
|
/** Returns the Intersect of the given sets */
|
|
32
|
-
// prettier-ignore
|
|
33
31
|
export function OperatorIntersect(T, S) {
|
|
34
32
|
const [L, ...R] = T;
|
|
33
|
+
// prettier-ignore
|
|
35
34
|
return (T.length > 0
|
|
36
35
|
? OperatorIncludes(S, L) === true
|
|
37
36
|
? [L, ...OperatorIntersect(R, S)]
|
|
@@ -39,28 +38,26 @@ export function OperatorIntersect(T, S) {
|
|
|
39
38
|
: []);
|
|
40
39
|
}
|
|
41
40
|
/** Returns the Union of the given sets */
|
|
42
|
-
|
|
43
|
-
export function OperatorUnion(T, S) {
|
|
41
|
+
export function OperatorUnion(T, S, Acc = S) {
|
|
44
42
|
const [L, ...R] = T;
|
|
43
|
+
// prettier-ignore
|
|
45
44
|
return (T.length > 0
|
|
46
|
-
?
|
|
47
|
-
|
|
48
|
-
: [L, ...OperatorUnion(R, S)]
|
|
49
|
-
: S);
|
|
45
|
+
? OperatorUnion(R, S, [...Acc, L])
|
|
46
|
+
: Acc);
|
|
50
47
|
}
|
|
51
48
|
/** Returns the Complement by omitting elements in T that are in S */
|
|
52
49
|
// prettier-ignore
|
|
53
|
-
export function OperatorComplement(T, S) {
|
|
50
|
+
export function OperatorComplement(T, S, Acc = []) {
|
|
54
51
|
const [L, ...R] = T;
|
|
55
52
|
return (T.length > 0
|
|
56
53
|
? OperatorIncludes(S, L) === true
|
|
57
|
-
?
|
|
58
|
-
:
|
|
59
|
-
:
|
|
54
|
+
? OperatorComplement(R, S, [...Acc])
|
|
55
|
+
: OperatorComplement(R, S, [L, ...Acc])
|
|
56
|
+
: Acc);
|
|
60
57
|
}
|
|
61
58
|
/** Returns the Intersect of multiple sets */
|
|
62
59
|
// prettier-ignore
|
|
63
|
-
export function OperatorIntersectMany(T) {
|
|
60
|
+
export function OperatorIntersectMany(T, Acc = []) {
|
|
64
61
|
return (T.length === 1
|
|
65
62
|
? T[0]
|
|
66
63
|
: (() => {
|
|
@@ -71,11 +68,10 @@ export function OperatorIntersectMany(T) {
|
|
|
71
68
|
})());
|
|
72
69
|
}
|
|
73
70
|
/** Returns the Union of multiple sets */
|
|
74
|
-
export function OperatorUnionMany(T) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})());
|
|
71
|
+
export function OperatorUnionMany(T, Acc = []) {
|
|
72
|
+
const [L, ...R] = T;
|
|
73
|
+
// prettier-ignore
|
|
74
|
+
return (T.length > 0
|
|
75
|
+
? OperatorUnionMany(R, OperatorUnion(Acc, L))
|
|
76
|
+
: Acc);
|
|
81
77
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { TProperties } from '../object/index.mjs';
|
|
2
2
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
3
3
|
import { type TOptionalWithFlag } from './optional.mjs';
|
|
4
|
-
type
|
|
4
|
+
type TFromProperties<K extends TProperties, F extends boolean> = ({
|
|
5
5
|
[K2 in keyof K]: TOptionalWithFlag<K[K2], F>;
|
|
6
6
|
});
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function
|
|
10
|
-
export type TOptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
|
|
11
|
-
export declare function OptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
7
|
+
type TFromMappedResult<K extends TMappedResult, F extends boolean> = (TFromProperties<K['properties'], F>);
|
|
8
|
+
export type TOptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>> = (TMappedResult<P>);
|
|
9
|
+
export declare function OptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
12
10
|
export {};
|
|
@@ -3,13 +3,9 @@ import type { Ensure } from '../helpers/index.mjs';
|
|
|
3
3
|
import { OptionalKind } from '../symbols/index.mjs';
|
|
4
4
|
import type { TMappedResult } from '../mapped/index.mjs';
|
|
5
5
|
import { type TOptionalFromMappedResult } from './optional-from-mapped-result.mjs';
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function AddOptional<T extends TSchema>(schema: T): T & {
|
|
10
|
-
[OptionalKind]: string;
|
|
11
|
-
};
|
|
12
|
-
export type TOptionalWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveOptional<T> : AddOptional<T>;
|
|
6
|
+
type TRemoveOptional<T extends TSchema> = T extends TOptional<infer S> ? S : T;
|
|
7
|
+
type TAddOptional<T extends TSchema> = T extends TOptional<infer S> ? TOptional<S> : Ensure<TOptional<T>>;
|
|
8
|
+
export type TOptionalWithFlag<T extends TSchema, F extends boolean> = F extends false ? TRemoveOptional<T> : TAddOptional<T>;
|
|
13
9
|
export type TOptional<T extends TSchema> = T & {
|
|
14
10
|
[OptionalKind]: 'Optional';
|
|
15
11
|
};
|
|
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TPartial } from './partial.mjs';
|
|
5
|
-
type
|
|
5
|
+
type TFromProperties<K extends TProperties> = ({
|
|
6
6
|
[K2 in keyof K]: TPartial<K[K2]>;
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
declare function
|
|
11
|
-
export type TPartialFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
|
|
12
|
-
export declare function PartialFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
8
|
+
type TFromMappedResult<K extends TMappedResult> = (TFromProperties<K['properties']>);
|
|
9
|
+
export type TPartialFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function PartialFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
13
11
|
export {};
|
|
@@ -9,15 +9,12 @@ import { type TObject, type TProperties } from '../object/index.mjs';
|
|
|
9
9
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
10
10
|
import { type TUnion } from '../union/index.mjs';
|
|
11
11
|
import { type TPartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
|
|
16
|
-
type FromProperties<T extends TProperties> = Evaluate<{
|
|
12
|
+
type TFromIntersect<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, [...Acc, PartialResolve<L>]> : Acc);
|
|
13
|
+
type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, PartialResolve<L>]> : Acc);
|
|
14
|
+
type TFromProperties<T extends TProperties> = Evaluate<{
|
|
17
15
|
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : T[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : T[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<T[K]>;
|
|
18
16
|
}>;
|
|
19
|
-
|
|
20
|
-
type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S>> : T extends TUnion<infer S> ? TUnion<FromUnion<S>> : T extends TObject<infer S> ? TObject<FromProperties<S>> : TObject<{}>);
|
|
17
|
+
type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
|
|
21
18
|
declare function PartialResolve<T extends TSchema>(T: T): PartialResolve<T>;
|
|
22
19
|
export type TPartial<T extends TSchema> = PartialResolve<T>;
|
|
23
20
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
@@ -9,21 +9,20 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// TypeGuard
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
|
-
// prettier-ignore
|
|
13
12
|
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
|
|
14
13
|
// prettier-ignore
|
|
15
|
-
function FromIntersect(T) {
|
|
14
|
+
function FromIntersect(T, Acc = []) {
|
|
16
15
|
const [L, ...R] = T;
|
|
17
16
|
return (T.length > 0
|
|
18
|
-
?
|
|
19
|
-
:
|
|
17
|
+
? FromIntersect(R, [...Acc, PartialResolve(L)])
|
|
18
|
+
: Acc);
|
|
20
19
|
}
|
|
21
20
|
// prettier-ignore
|
|
22
|
-
function FromUnion(T) {
|
|
21
|
+
function FromUnion(T, Acc = []) {
|
|
23
22
|
const [L, ...R] = T;
|
|
24
23
|
return (T.length > 0
|
|
25
|
-
?
|
|
26
|
-
:
|
|
24
|
+
? FromUnion(R, [...Acc, PartialResolve(L)])
|
|
25
|
+
: Acc);
|
|
27
26
|
}
|
|
28
27
|
// prettier-ignore
|
|
29
28
|
function FromProperties(T) {
|
|
@@ -2,14 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
4
4
|
import { type TPick } from './pick.mjs';
|
|
5
|
-
type
|
|
5
|
+
type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
6
6
|
[_ in K]: TPick<T, [K]>;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare function FromMappedKey<T extends TSchema, K extends TMappedKey>(T: T, K: K, options: SchemaOptions): FromMappedKey<T, K>;
|
|
13
|
-
export type TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>> = (TMappedResult<P>);
|
|
14
|
-
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
|
|
8
|
+
type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
|
|
9
|
+
type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
|
|
10
|
+
export type TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
|
|
11
|
+
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
|
|
15
12
|
export {};
|
|
@@ -7,11 +7,11 @@ function FromPropertyKey(T, K, options) {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromPropertyKeys(T, K, options) {
|
|
10
|
+
function FromPropertyKeys(T, K, options, Acc = {}) {
|
|
11
11
|
const [LK, ...RK] = K;
|
|
12
12
|
return (K.length > 0
|
|
13
|
-
?
|
|
14
|
-
:
|
|
13
|
+
? FromPropertyKeys(T, RK, options, { ...Acc, ...FromPropertyKey(T, LK, options) })
|
|
14
|
+
: Acc);
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function FromMappedKey(T, K, options) {
|
|
@@ -7,10 +7,10 @@ import { type TObject, type TProperties } from '../object/index.mjs';
|
|
|
7
7
|
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
8
8
|
import { TMappedKey } from '../mapped/index.mjs';
|
|
9
9
|
import { type TPickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
10
|
-
type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ?
|
|
11
|
-
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
|
|
12
|
-
type FromUnion<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ?
|
|
13
|
-
declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K>;
|
|
10
|
+
type FromIntersect<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromIntersect<R, K, [...Acc, PickResolve<L, K>]> : Acc;
|
|
11
|
+
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K, []>;
|
|
12
|
+
type FromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromUnion<R, K, [...Acc, PickResolve<L, K>]> : Acc;
|
|
13
|
+
declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
|
|
14
14
|
type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
|
|
15
15
|
declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
|
|
16
16
|
export type PickResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<PickResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { TProperties } from '../object/index.mjs';
|
|
2
2
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
3
3
|
import { type TReadonlyWithFlag } from './readonly.mjs';
|
|
4
|
-
type
|
|
4
|
+
type TFromProperties<K extends TProperties, F extends boolean> = ({
|
|
5
5
|
[K2 in keyof K]: TReadonlyWithFlag<K[K2], F>;
|
|
6
6
|
});
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function
|
|
10
|
-
export type TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
|
|
11
|
-
export declare function ReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
7
|
+
type TFromMappedResult<K extends TMappedResult, F extends boolean> = (TFromProperties<K['properties'], F>);
|
|
8
|
+
export type TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>> = (TMappedResult<P>);
|
|
9
|
+
export declare function ReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
12
10
|
export {};
|
|
@@ -3,13 +3,9 @@ import type { Ensure } from '../helpers/index.mjs';
|
|
|
3
3
|
import { ReadonlyKind } from '../symbols/index.mjs';
|
|
4
4
|
import type { TMappedResult } from '../mapped/index.mjs';
|
|
5
5
|
import { type TReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function AddReadonly<T extends TSchema>(schema: T): T & {
|
|
10
|
-
[ReadonlyKind]: string;
|
|
11
|
-
};
|
|
12
|
-
export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveReadonly<T> : AddReadonly<T>;
|
|
6
|
+
type TRemoveReadonly<T extends TSchema> = T extends TReadonly<infer S> ? S : T;
|
|
7
|
+
type TAddReadonly<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<S> : Ensure<TReadonly<T>>;
|
|
8
|
+
export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? TRemoveReadonly<T> : TAddReadonly<T>;
|
|
13
9
|
export type TReadonly<T extends TSchema> = T & {
|
|
14
10
|
[ReadonlyKind]: 'Readonly';
|
|
15
11
|
};
|
|
@@ -11,34 +11,28 @@ import { type TNumber } from '../number/index.mjs';
|
|
|
11
11
|
import { type TEnum } from '../enum/index.mjs';
|
|
12
12
|
import { TTemplateLiteral, TIsTemplateLiteralFinite } from '../template-literal/index.mjs';
|
|
13
13
|
import { Kind } from '../symbols/index.mjs';
|
|
14
|
-
type
|
|
15
|
-
type
|
|
14
|
+
type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
15
|
+
type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
|
|
16
16
|
[_ in I]: T;
|
|
17
17
|
}>>>);
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
type FromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
|
|
18
|
+
type TFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? TFromTemplateLiteralKeyInfinite<K, T> : TFromTemplateLiteralKeyFinite<K, T>;
|
|
19
|
+
type TFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
|
|
21
20
|
[_ in K[keyof K]]: T;
|
|
22
21
|
}>>;
|
|
23
|
-
type
|
|
22
|
+
type TFromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
|
|
24
23
|
[_ in K['const']]: T;
|
|
25
24
|
};
|
|
26
|
-
type
|
|
25
|
+
type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
|
|
27
26
|
[_ in K['const']]: T;
|
|
28
27
|
};
|
|
29
|
-
type
|
|
30
|
-
type
|
|
31
|
-
|
|
32
|
-
type FromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
|
|
28
|
+
type TFromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? TFromUnionKeyRest<S, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<string> ? TFromUnionKeyLiteralString<L, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<number> ? TFromUnionKeyLiteralNumber<L, T> & TFromUnionKeyRest<R, T> : {}) : {};
|
|
29
|
+
type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<P>>);
|
|
30
|
+
type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
|
|
33
31
|
[_ in Assert<K, PropertyKey>]: T;
|
|
34
32
|
}>>);
|
|
35
|
-
|
|
36
|
-
type
|
|
37
|
-
|
|
38
|
-
type FromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
39
|
-
declare function FromIntegerKey<K extends TInteger, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
|
|
40
|
-
type FromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
41
|
-
declare function FromNumberKey<K extends TNumber, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
|
|
33
|
+
type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
|
|
34
|
+
type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
35
|
+
type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
42
36
|
type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Record<Assert<Static<K>, PropertyKey>, Static<T, P>>);
|
|
43
37
|
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
44
38
|
[Kind]: 'Record';
|
|
@@ -49,7 +43,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
|
|
|
49
43
|
};
|
|
50
44
|
additionalProperties: TAdditionalProperties;
|
|
51
45
|
}
|
|
52
|
-
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ?
|
|
46
|
+
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
|
|
53
47
|
/** `[Json]` Creates a Record type */
|
|
54
48
|
export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
|
|
55
49
|
export {};
|
|
@@ -10,7 +10,6 @@ import { IsUndefined } from '../guard/value.mjs';
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// TypeGuard
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
// prettier-ignore
|
|
14
13
|
import { IsInteger, IsLiteral, IsNumber, IsString, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
|
|
15
14
|
// ------------------------------------------------------------------
|
|
16
15
|
// RecordCreateFromPattern
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
// ------------------------------------------------------------------
|
|
3
|
+
// TypeGuard
|
|
4
|
+
// ------------------------------------------------------------------
|
|
2
5
|
import { IsString, IsUndefined } from '../guard/value.mjs';
|
|
3
6
|
/** `[Json]` Creates a Ref type. */
|
|
4
7
|
export function Ref(unresolved, options = {}) {
|
|
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TRequired } from './required.mjs';
|
|
5
|
-
type
|
|
5
|
+
type TFromProperties<K extends TProperties> = ({
|
|
6
6
|
[K2 in keyof K]: TRequired<K[K2]>;
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
declare function
|
|
11
|
-
export type TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
|
|
12
|
-
export declare function RequiredFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
8
|
+
type TFromMappedResult<K extends TMappedResult> = (TFromProperties<K['properties']>);
|
|
9
|
+
export type TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function RequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
13
11
|
export {};
|
|
@@ -9,17 +9,13 @@ import { type TIntersect } from '../intersect/index.mjs';
|
|
|
9
9
|
import { type TUnion } from '../union/index.mjs';
|
|
10
10
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
11
11
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
|
|
16
|
-
type FromProperties<T extends TProperties> = Evaluate<{
|
|
12
|
+
type TFromIntersect<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
13
|
+
type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
14
|
+
type TFromProperties<T extends TProperties> = Evaluate<{
|
|
17
15
|
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
|
|
18
16
|
}>;
|
|
19
|
-
|
|
20
|
-
type
|
|
21
|
-
declare function RequiredResolve<T extends TSchema>(T: T): RequiredResolve<T>;
|
|
22
|
-
export type TRequired<T extends TSchema> = RequiredResolve<T>;
|
|
17
|
+
type TRequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<TRequiredResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
|
|
18
|
+
export type TRequired<T extends TSchema> = TRequiredResolve<T>;
|
|
23
19
|
/** `[Json]` Constructs a type where all properties are required */
|
|
24
20
|
export declare function Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>;
|
|
25
21
|
/** `[Json]` Constructs a type where all properties are required */
|
|
@@ -8,21 +8,20 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// TypeGuard
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
|
-
// prettier-ignore
|
|
12
11
|
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
|
|
13
12
|
// prettier-ignore
|
|
14
|
-
function FromIntersect(T) {
|
|
13
|
+
function FromIntersect(T, Acc = []) {
|
|
15
14
|
const [L, ...R] = T;
|
|
16
15
|
return (T.length > 0
|
|
17
|
-
?
|
|
18
|
-
:
|
|
16
|
+
? FromIntersect(R, [...Acc, RequiredResolve(L)])
|
|
17
|
+
: Acc);
|
|
19
18
|
}
|
|
20
19
|
// prettier-ignore
|
|
21
|
-
function FromUnion(T) {
|
|
20
|
+
function FromUnion(T, Acc = []) {
|
|
22
21
|
const [L, ...R] = T;
|
|
23
22
|
return (T.length > 0
|
|
24
|
-
?
|
|
25
|
-
:
|
|
23
|
+
? FromUnion(R, [...Acc, RequiredResolve(L)])
|
|
24
|
+
: Acc);
|
|
26
25
|
}
|
|
27
26
|
// prettier-ignore
|
|
28
27
|
function FromProperties(T) {
|
|
@@ -2,9 +2,9 @@ import type { TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
3
3
|
import type { TUnion } from '../union/index.mjs';
|
|
4
4
|
import type { TTuple } from '../tuple/index.mjs';
|
|
5
|
-
export type
|
|
5
|
+
export type TRestResolve<T extends TSchema> = T extends TIntersect<infer S> ? [...S] : T extends TUnion<infer S> ? [...S] : T extends TTuple<infer S> ? [...S] : [
|
|
6
6
|
];
|
|
7
|
-
export declare function RestResolve<T extends TSchema>(T: T):
|
|
8
|
-
export type TRest<T extends TSchema> =
|
|
7
|
+
export declare function RestResolve<T extends TSchema>(T: T): TRestResolve<T>;
|
|
8
|
+
export type TRest<T extends TSchema> = TRestResolve<T>;
|
|
9
9
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
10
10
|
export declare function Rest<T extends TSchema>(T: T): TRest<T>;
|
|
@@ -22,7 +22,7 @@ import type { TTransform } from '../transform/index.mjs';
|
|
|
22
22
|
export type DecodeProperties<T extends TProperties> = {
|
|
23
23
|
[K in keyof T]: DecodeType<T[K]>;
|
|
24
24
|
};
|
|
25
|
-
export type DecodeRest<T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [DecodeType<L
|
|
25
|
+
export type DecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? DecodeRest<R, [...Acc, DecodeType<L>]> : Acc;
|
|
26
26
|
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<DecodeRest<P>, DecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<DecodeRest<P>, DecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<DecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<DecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<DecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<DecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<DecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, DecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<DecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<DecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<DecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<DecodeRest<S>> : T);
|
|
27
27
|
/** Creates an decoded static type from a TypeBox type */
|
|
28
28
|
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeType<T>, P>;
|
|
@@ -9,10 +9,10 @@ import type { TLiteral } from '../literal/index.mjs';
|
|
|
9
9
|
import type { Expression } from './parse.mjs';
|
|
10
10
|
export declare class TemplateLiteralFiniteError extends Error {
|
|
11
11
|
}
|
|
12
|
-
type
|
|
13
|
-
type
|
|
12
|
+
type TFromTemplateLiteralKind<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TString ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TBoolean ? true : T extends TLiteral ? true : false;
|
|
13
|
+
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? TFromTemplateLiteralKind<L> extends false ? false : TFromTemplateLiteralKinds<R> : true;
|
|
14
14
|
export declare function IsTemplateLiteralExpressionFinite(expression: Expression): boolean;
|
|
15
|
-
export type TIsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ?
|
|
15
|
+
export type TIsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? TFromTemplateLiteralKinds<U> : false;
|
|
16
16
|
/** Returns true if this TemplateLiteral resolves to a finite set of values */
|
|
17
17
|
export declare function IsTemplateLiteralFinite<T extends TTemplateLiteral>(schema: T): boolean;
|
|
18
18
|
export {};
|
|
@@ -7,15 +7,14 @@ import type { Expression } from './parse.mjs';
|
|
|
7
7
|
import type { TUnion } from '../union/index.mjs';
|
|
8
8
|
export declare class TemplateLiteralGenerateError extends Error {
|
|
9
9
|
}
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
]) : [];
|
|
10
|
+
type TStringReduceUnary<L extends string, R extends string[], Acc extends string[] = []> = R extends [infer A extends string, ...infer B extends string[]] ? TStringReduceUnary<L, B, [...Acc, `${L}${A}`]> : Acc;
|
|
11
|
+
type TStringReduceBinary<L extends string[], R extends string[], Acc extends string[] = []> = L extends [infer A extends string, ...infer B extends string[]] ? TStringReduceBinary<B, R, [...Acc, ...TStringReduceUnary<A, R>]> : Acc;
|
|
12
|
+
type TStringReduceMany<T extends string[][]> = T extends [infer L extends string[], infer R extends string[], ...infer Rest extends string[][]] ? TStringReduceMany<[TStringReduceBinary<L, R>, ...Rest]> : T;
|
|
13
|
+
type TStringReduce<T extends string[][], O = TStringReduceMany<T>> = 0 extends keyof O ? Assert<O[0], string[]> : [];
|
|
14
|
+
type TFromTemplateLiteralUnionKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [L['const'], ...TFromTemplateLiteralUnionKinds<R>] : [];
|
|
15
|
+
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[], Acc extends TLiteralValue[][] = []> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? (L extends TLiteral<infer S extends TLiteralValue> ? TFromTemplateLiteralKinds<R, [...Acc, [S]]> : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<R, [...Acc, TFromTemplateLiteralUnionKinds<S>]> : L extends TBoolean ? TFromTemplateLiteralKinds<R, [...Acc, ['true', 'false']]> : Acc) : Acc;
|
|
17
16
|
export declare function TemplateLiteralExpressionGenerate(expression: Expression): IterableIterator<string>;
|
|
18
|
-
export type TTemplateLiteralGenerate<T extends TTemplateLiteral, F = TIsTemplateLiteralFinite<T>> = F extends true ? (T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ?
|
|
17
|
+
export type TTemplateLiteralGenerate<T extends TTemplateLiteral, F = TIsTemplateLiteralFinite<T>> = F extends true ? (T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<S> extends infer R extends string[][] ? TStringReduce<R> : [] : []) : [];
|
|
19
18
|
/** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
|
|
20
19
|
export declare function TemplateLiteralGenerate<T extends TTemplateLiteral>(schema: T): TTemplateLiteralGenerate<T>;
|
|
21
20
|
export {};
|
|
@@ -5,12 +5,12 @@ import { type TBoolean } from '../boolean/index.mjs';
|
|
|
5
5
|
import { type TBigInt } from '../bigint/index.mjs';
|
|
6
6
|
import { type TNumber } from '../number/index.mjs';
|
|
7
7
|
import { type TString } from '../string/index.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { type TUnionEvaluated } from '../union/index.mjs';
|
|
9
9
|
declare function FromUnion(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
10
10
|
declare function FromTerminal(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
11
11
|
type FromUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [TLiteral<Trim<L>>, ...FromUnionLiteral<R>] : T extends `${infer L}` ? [TLiteral<Trim<L>>] : [
|
|
12
12
|
];
|
|
13
|
-
type FromUnion<T extends string> =
|
|
13
|
+
type FromUnion<T extends string> = TUnionEvaluated<FromUnionLiteral<T>>;
|
|
14
14
|
type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
|
|
15
15
|
type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$${infer R}` ? [TLiteral<L>, ...FromString<R>] : T extends `${infer L}` ? [TLiteral<L>] : [
|
|
16
16
|
];
|