@sinclair/typebox 0.32.0-dev-20 → 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/compiler/compiler.mjs +62 -62
- package/build/import/errors/errors.mjs +62 -62
- package/build/import/index.d.mts +6 -6
- package/build/import/index.mjs +1 -1
- 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 +5 -8
- package/build/import/type/indexed/indexed-property-keys.mjs +6 -11
- 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 +8 -6
- 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 +14 -20
- package/build/import/type/record/record.mjs +2 -4
- 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/schema/schema.d.mts +1 -1
- package/build/import/type/static/static.d.mts +1 -1
- package/build/import/type/symbol/symbol.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +7 -5
- package/build/import/type/template-literal/finite.mjs +14 -5
- package/build/import/type/template-literal/generate.d.mts +14 -9
- package/build/import/type/template-literal/generate.mjs +19 -9
- package/build/import/type/template-literal/index.d.mts +1 -1
- package/build/import/type/template-literal/index.mjs +1 -1
- package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
- package/build/import/type/template-literal/syntax.d.mts +3 -3
- package/build/import/type/template-literal/syntax.mjs +2 -3
- package/build/import/type/template-literal/template-literal.d.mts +2 -2
- package/build/import/type/template-literal/template-literal.mjs +1 -1
- package/build/import/type/template-literal/union.d.mts +2 -2
- package/build/import/type/template-literal/union.mjs +5 -10
- package/build/import/type/transform/transform.mjs +0 -1
- package/build/import/type/tuple/tuple.d.mts +1 -2
- package/build/import/type/type/json.d.mts +2 -2
- package/build/import/type/union/union-evaluated.d.mts +6 -10
- package/build/import/type/union/union-evaluated.mjs +7 -2
- package/build/import/value/cast/cast.mjs +20 -20
- package/build/import/value/check/check.mjs +62 -62
- package/build/import/value/clean/clean.mjs +16 -16
- package/build/import/value/convert/convert.mjs +36 -36
- package/build/import/value/create/create.mjs +66 -67
- package/build/import/value/default/default.mjs +16 -16
- package/build/import/value/transform/decode.mjs +18 -18
- package/build/import/value/transform/encode.mjs +18 -18
- package/build/import/value/transform/has.mjs +28 -28
- package/build/require/compiler/compiler.js +62 -62
- package/build/require/errors/errors.js +62 -62
- package/build/require/index.d.ts +6 -6
- package/build/require/index.js +4 -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 +5 -8
- package/build/require/type/indexed/indexed-property-keys.js +4 -9
- 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 +7 -5
- 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 +14 -20
- package/build/require/type/record/record.js +1 -3
- 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/schema/schema.d.ts +1 -1
- package/build/require/type/static/static.d.ts +1 -1
- package/build/require/type/symbol/symbol.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +7 -5
- package/build/require/type/template-literal/finite.js +16 -6
- package/build/require/type/template-literal/generate.d.ts +14 -9
- package/build/require/type/template-literal/generate.js +22 -11
- package/build/require/type/template-literal/index.d.ts +1 -1
- package/build/require/type/template-literal/index.js +1 -1
- package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
- package/build/require/type/template-literal/syntax.d.ts +3 -3
- package/build/require/type/template-literal/syntax.js +1 -2
- package/build/require/type/template-literal/template-literal.d.ts +2 -2
- package/build/require/type/template-literal/template-literal.js +1 -1
- package/build/require/type/template-literal/union.d.ts +2 -2
- package/build/require/type/template-literal/union.js +5 -10
- package/build/require/type/transform/transform.js +0 -1
- package/build/require/type/tuple/tuple.d.ts +1 -2
- package/build/require/type/type/json.d.ts +2 -2
- package/build/require/type/union/union-evaluated.d.ts +6 -10
- package/build/require/type/union/union-evaluated.js +7 -2
- package/build/require/value/cast/cast.js +20 -20
- package/build/require/value/check/check.js +62 -62
- package/build/require/value/clean/clean.js +16 -16
- package/build/require/value/convert/convert.js +36 -36
- package/build/require/value/create/create.js +65 -66
- package/build/require/value/default/default.js +16 -16
- package/build/require/value/transform/decode.js +18 -18
- package/build/require/value/transform/encode.js +18 -18
- package/build/require/value/transform/has.js +28 -28
- package/package.json +1 -1
- package/readme.md +47 -47
- 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
- /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
- /package/build/require/type/template-literal/{parser.d.ts → parse.d.ts} +0 -0
|
@@ -8,32 +8,22 @@ import { type TMappedKey } from '../mapped/index.mjs';
|
|
|
8
8
|
import { type TUnion } from '../union/index.mjs';
|
|
9
9
|
import { type TTuple } from '../tuple/index.mjs';
|
|
10
10
|
import { type TArray } from '../array/index.mjs';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { type TIntersectEvaluated } from '../intersect/index.mjs';
|
|
12
|
+
import { type TUnionEvaluated } from '../union/index.mjs';
|
|
13
13
|
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
14
14
|
import { type TIndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
declare function FromUnionRest<T extends TSchema[]>(T: [...T], S?: [...T]): FromUnionRest<T>;
|
|
23
|
-
type FromUnion<T extends TSchema[], K extends PropertyKey> = (UnionEvaluated<FromUnionRest<FromRest<T, K>>>);
|
|
24
|
-
declare function FromUnion<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromUnion<T, K>;
|
|
25
|
-
type FromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? UnionEvaluated<T> : TNever);
|
|
26
|
-
declare function FromTuple<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromTuple<T, K>;
|
|
27
|
-
type FromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
28
|
-
declare function FromArray<T extends TSchema, K extends PropertyKey>(T: T, K: K): FromArray<T, K>;
|
|
15
|
+
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TFromKey<L, K>, TSchema>]> : Acc);
|
|
16
|
+
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
17
|
+
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
18
|
+
type TFromUnionRest<T extends TSchema[], Acc extends TSchema[] = T> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [] : TFromUnionRest<R, Acc> : Acc);
|
|
19
|
+
type TFromUnion<T extends TSchema[], K extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<T, K>>>);
|
|
20
|
+
type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? TUnionEvaluated<T> : TNever);
|
|
21
|
+
type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
29
22
|
type AssertPropertyKey<T> = Assert<T, string | number>;
|
|
30
|
-
type
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
type FromKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? [FromKey<T, L>, ...FromKeys<T, R>] : []);
|
|
35
|
-
declare function FromKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromKeys<T, K>;
|
|
36
|
-
type FromSchema<T extends TSchema, K extends PropertyKey[]> = (UnionEvaluated<FromKeys<T, K>>);
|
|
23
|
+
type TFromProperty<T extends TProperties, K extends PropertyKey> = (K extends keyof T ? T[K] : `${AssertPropertyKey<K>}` extends `${AssertPropertyKey<keyof T>}` ? T[AssertPropertyKey<K>] : TNever);
|
|
24
|
+
type TFromKey<T extends TSchema, K extends PropertyKey> = (T extends TRecursive<infer S> ? TFromKey<S, K> : T extends TIntersect<infer S> ? TFromIntersect<S, K> : T extends TUnion<infer S> ? TFromUnion<S, K> : T extends TTuple<infer S> ? TFromTuple<S, K> : T extends TArray<infer S> ? TFromArray<S, K> : T extends TObject<infer S> ? TFromProperty<S, K> : TNever);
|
|
25
|
+
type TFromKeys<T extends TSchema, K extends PropertyKey[], Acc extends TSchema[] = []> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TFromKeys<T, R, [...Acc, Assert<TFromKey<T, L>, TSchema>]> : Acc);
|
|
26
|
+
type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<TFromKeys<T, K>>);
|
|
37
27
|
declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
|
|
38
28
|
export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
|
|
39
29
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
@@ -10,33 +10,33 @@ import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
|
10
10
|
// prettier-ignore
|
|
11
11
|
import { IsArray, IsIntersect, IsObject, IsMappedKey, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
|
-
function FromRest(T, K) {
|
|
13
|
+
function FromRest(T, K, Acc = []) {
|
|
14
14
|
const [L, ...R] = T;
|
|
15
15
|
return (T.length > 0
|
|
16
|
-
?
|
|
17
|
-
:
|
|
16
|
+
? FromRest(R, K, [...Acc, FromKey(L, K)])
|
|
17
|
+
: Acc);
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
|
-
function FromIntersectRest(T) {
|
|
20
|
+
function FromIntersectRest(T, Acc = []) {
|
|
21
21
|
const [L, ...R] = T;
|
|
22
22
|
return (T.length > 0
|
|
23
23
|
? IsNever(L)
|
|
24
|
-
?
|
|
25
|
-
: [
|
|
26
|
-
:
|
|
24
|
+
? FromIntersectRest(R, [...Acc])
|
|
25
|
+
: FromIntersectRest(R, [...Acc, L])
|
|
26
|
+
: Acc);
|
|
27
27
|
}
|
|
28
28
|
// prettier-ignore
|
|
29
29
|
function FromIntersect(T, K) {
|
|
30
30
|
return (IntersectEvaluated(FromIntersectRest(FromRest(T, K))));
|
|
31
31
|
}
|
|
32
32
|
// prettier-ignore
|
|
33
|
-
function FromUnionRest(T,
|
|
33
|
+
function FromUnionRest(T, Acc = T) {
|
|
34
34
|
const [L, ...R] = T;
|
|
35
35
|
return (T.length > 0
|
|
36
36
|
? IsNever(L)
|
|
37
37
|
? []
|
|
38
|
-
: FromUnionRest(R,
|
|
39
|
-
:
|
|
38
|
+
: FromUnionRest(R, Acc)
|
|
39
|
+
: Acc);
|
|
40
40
|
}
|
|
41
41
|
// prettier-ignore
|
|
42
42
|
function FromUnion(T, K) {
|
|
@@ -70,11 +70,11 @@ function FromKey(T, K) {
|
|
|
70
70
|
Never());
|
|
71
71
|
}
|
|
72
72
|
// prettier-ignore
|
|
73
|
-
function FromKeys(T, K) {
|
|
73
|
+
function FromKeys(T, K, Acc = []) {
|
|
74
74
|
const [L, ...R] = K;
|
|
75
75
|
return (K.length > 0
|
|
76
|
-
?
|
|
77
|
-
:
|
|
76
|
+
? FromKeys(T, R, [...Acc, FromKey(T, L)])
|
|
77
|
+
: Acc);
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
80
|
function FromSchema(T, K) {
|
|
@@ -3,7 +3,6 @@ import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
// prettier-ignore
|
|
7
6
|
import { IsObject, IsSchema } from '../guard/type.mjs';
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
// IntersectCreate
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
2
|
import { type TNever } from '../never/index.mjs';
|
|
3
3
|
import { type TOptional } from '../optional/index.mjs';
|
|
4
4
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
5
|
import { TIntersect, IntersectOptions } from './intersect-type.mjs';
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
declare function RemoveOptionalFromType<T extends TSchema>(T: T): RemoveOptionalFromType<T>;
|
|
12
|
-
type ResolveIntersect<T extends TSchema[]> = (IsIntersectOptional<T> extends true ? TOptional<TIntersect<RemoveOptionalFromRest<T>>> : TIntersect<RemoveOptionalFromRest<T>>);
|
|
13
|
-
declare function ResolveIntersect<T extends TSchema[]>(T: [...T], options: SchemaOptions): ResolveIntersect<T>;
|
|
14
|
-
export type IntersectEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : ResolveIntersect<T>);
|
|
6
|
+
type TIsIntersectOptional<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<TSchema> ? TIsIntersectOptional<R> : false : true);
|
|
7
|
+
type TRemoveOptionalFromType<T extends TSchema> = (T extends TReadonly<infer S extends TSchema> ? TReadonly<TRemoveOptionalFromType<S>> : T extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromType<S> : T);
|
|
8
|
+
type TRemoveOptionalFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<R, [...Acc, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<R, [...Acc, L]> : Acc);
|
|
9
|
+
type TResolveIntersect<T extends TSchema[]> = (TIsIntersectOptional<T> extends true ? TOptional<TIntersect<TRemoveOptionalFromRest<T>>> : TIntersect<TRemoveOptionalFromRest<T>>);
|
|
10
|
+
export type TIntersectEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TResolveIntersect<T>);
|
|
15
11
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
16
|
-
export declare function IntersectEvaluated<T extends TSchema[], R =
|
|
12
|
+
export declare function IntersectEvaluated<T extends TSchema[], R = TIntersectEvaluated<T>>(T: [...T], options?: IntersectOptions): R;
|
|
17
13
|
export {};
|
|
@@ -8,25 +8,30 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
import { IsOptional
|
|
11
|
+
import { IsOptional, IsTransform, } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function IsIntersectOptional(T) {
|
|
14
14
|
const [L, ...R] = T;
|
|
15
15
|
return (T.length > 0
|
|
16
|
-
?
|
|
16
|
+
? IsOptional(L)
|
|
17
17
|
? IsIntersectOptional(R)
|
|
18
18
|
: false
|
|
19
19
|
: true);
|
|
20
20
|
}
|
|
21
21
|
// prettier-ignore
|
|
22
|
-
function RemoveOptionalFromRest(T) {
|
|
23
|
-
return (T.map(T => RemoveOptionalFromType(T)));
|
|
24
|
-
}
|
|
25
|
-
// prettier-ignore
|
|
26
22
|
function RemoveOptionalFromType(T) {
|
|
27
23
|
return (Discard(T, [OptionalKind]));
|
|
28
24
|
}
|
|
29
25
|
// prettier-ignore
|
|
26
|
+
function RemoveOptionalFromRest(T, Acc = []) {
|
|
27
|
+
const [L, ...R] = T;
|
|
28
|
+
return (T.length > 0
|
|
29
|
+
? IsOptional(L)
|
|
30
|
+
? RemoveOptionalFromRest(R, [...Acc, RemoveOptionalFromType(L)])
|
|
31
|
+
: RemoveOptionalFromRest(R, [...Acc, L])
|
|
32
|
+
: Acc);
|
|
33
|
+
}
|
|
34
|
+
// prettier-ignore
|
|
30
35
|
function ResolveIntersect(T, options) {
|
|
31
36
|
return (IsIntersectOptional(T)
|
|
32
37
|
? Optional(IntersectCreate(RemoveOptionalFromRest(T), options))
|
|
@@ -38,7 +43,7 @@ export function IntersectEvaluated(T, options = {}) {
|
|
|
38
43
|
return Never(options);
|
|
39
44
|
if (T.length === 1)
|
|
40
45
|
return CloneType(T[0], options);
|
|
41
|
-
if (T.some((schema) =>
|
|
46
|
+
if (T.some((schema) => IsTransform(schema)))
|
|
42
47
|
throw new Error('Cannot intersect transform types');
|
|
43
48
|
return ResolveIntersect(T, options);
|
|
44
49
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import { Kind } from '../symbols/index.mjs';
|
|
4
|
-
type
|
|
4
|
+
type TIntersectStatic<T extends TSchema[], P extends unknown[], Acc extends unknown = unknown> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TIntersectStatic<R, P, Acc & Static<L, P>> : Acc;
|
|
5
5
|
export type TUnevaluatedProperties = undefined | TSchema | boolean;
|
|
6
6
|
export interface IntersectOptions extends SchemaOptions {
|
|
7
7
|
unevaluatedProperties?: TUnevaluatedProperties;
|
|
8
8
|
}
|
|
9
9
|
export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
|
|
10
10
|
[Kind]: 'Intersect';
|
|
11
|
-
static:
|
|
11
|
+
static: TIntersectStatic<T, this['params']>;
|
|
12
12
|
type?: 'object';
|
|
13
13
|
allOf: [...T];
|
|
14
14
|
}
|
|
@@ -4,8 +4,7 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
import { IsTransform, } from '../guard/type.mjs';
|
|
7
|
+
import { IsTransform } from '../guard/type.mjs';
|
|
9
8
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
10
9
|
export function Intersect(T, options = {}) {
|
|
11
10
|
if (T.length === 0)
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { Assert } from '../helpers/index.mjs';
|
|
3
4
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
4
5
|
import { type TIntrinsic, type IntrinsicMode } from './intrinsic.mjs';
|
|
5
6
|
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
6
|
-
type
|
|
7
|
-
[_ in K]: TIntrinsic<TLiteral<
|
|
7
|
+
type TMappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode> = {
|
|
8
|
+
[_ in K]: TIntrinsic<TLiteral<Assert<K, TLiteralValue>>, M>;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode>(T: K, M: M, options: SchemaOptions): MappedIntrinsicProperties<K, M>;
|
|
14
|
-
export type TIntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>> = (TMappedResult<P>);
|
|
15
|
-
export declare function IntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>>(T: K, M: M, options: SchemaOptions): TMappedResult<P>;
|
|
10
|
+
type TMappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedIntrinsicPropertyKeys<R, M, Acc & TMappedIntrinsicPropertyKey<L, M>> : Acc);
|
|
11
|
+
type TMappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode> = (TMappedIntrinsicPropertyKeys<K['keys'], M>);
|
|
12
|
+
export type TIntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = TMappedIntrinsicProperties<K, M>> = (TMappedResult<P>);
|
|
13
|
+
export declare function IntrinsicFromMappedKey<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = TMappedIntrinsicProperties<K, M>>(T: K, M: M, options: SchemaOptions): TMappedResult<P>;
|
|
16
14
|
export {};
|
|
@@ -8,11 +8,11 @@ function MappedIntrinsicPropertyKey(K, M, options) {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
11
|
+
function MappedIntrinsicPropertyKeys(K, M, options, Acc = {}) {
|
|
12
12
|
const [L, ...R] = K;
|
|
13
13
|
return (K.length > 0
|
|
14
|
-
?
|
|
15
|
-
:
|
|
14
|
+
? MappedIntrinsicPropertyKeys(R, M, options, { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) })
|
|
15
|
+
: Acc);
|
|
16
16
|
}
|
|
17
17
|
// prettier-ignore
|
|
18
18
|
function MappedIntrinsicProperties(T, M, options) {
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import { type TTemplateLiteral, type TTemplateLiteralKind } from '../template-literal/index.mjs';
|
|
3
3
|
import { type TIntrinsicFromMappedKey } from './intrinsic-from-mapped-key.mjs';
|
|
4
|
-
import { type TLiteral
|
|
4
|
+
import { type TLiteral } from '../literal/index.mjs';
|
|
5
5
|
import { type TUnion } from '../union/index.mjs';
|
|
6
6
|
import { type TMappedKey } from '../mapped/index.mjs';
|
|
7
7
|
export type IntrinsicMode = 'Uppercase' | 'Lowercase' | 'Capitalize' | 'Uncapitalize';
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
declare function
|
|
12
|
-
type
|
|
13
|
-
declare function FromRest<T extends TSchema[], M extends IntrinsicMode>(T: [...T], mode: M): FromRest<T, M>;
|
|
14
|
-
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicFromMappedKey<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<FromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<FromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<FromLiteralValue<S, M>> : T;
|
|
8
|
+
type TFromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode> = M extends IntrinsicMode ? T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? [TIntrinsic<L, M>, ...TFromTemplateLiteral<R, M>] : T : T;
|
|
9
|
+
type TFromLiteralValue<T, M extends IntrinsicMode> = (T extends string ? M extends 'Uncapitalize' ? Uncapitalize<T> : M extends 'Capitalize' ? Capitalize<T> : M extends 'Uppercase' ? Uppercase<T> : M extends 'Lowercase' ? Lowercase<T> : string : T);
|
|
10
|
+
type FromRest<T extends TSchema[], M extends IntrinsicMode, Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromRest<R, M, [...Acc, TIntrinsic<L, M>]> : Acc;
|
|
11
|
+
declare function FromRest<T extends TSchema[], M extends IntrinsicMode>(T: [...T], M: M, Acc?: TSchema[]): FromRest<T, M>;
|
|
12
|
+
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicFromMappedKey<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<TFromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<FromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<TFromLiteralValue<S, M>> : T;
|
|
15
13
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
16
14
|
export declare function Intrinsic<T extends TMappedKey, M extends IntrinsicMode>(schema: T, mode: M, options?: SchemaOptions): TIntrinsicFromMappedKey<T, M>;
|
|
17
15
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { TemplateLiteral, TemplateLiteralParseExact,
|
|
1
|
+
import { TemplateLiteral, TemplateLiteralParseExact, IsTemplateLiteralExpressionFinite, TemplateLiteralExpressionGenerate } from '../template-literal/index.mjs';
|
|
2
2
|
import { IntrinsicFromMappedKey } from './intrinsic-from-mapped-key.mjs';
|
|
3
3
|
import { Literal } from '../literal/index.mjs';
|
|
4
4
|
import { Union } from '../union/index.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// TypeGuard
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
// prettier-ignore
|
|
9
8
|
import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/type.mjs';
|
|
10
9
|
// ------------------------------------------------------------------
|
|
11
10
|
// Apply
|
|
@@ -28,10 +27,10 @@ function FromTemplateLiteral(schema, mode, options) {
|
|
|
28
27
|
// note: template literals require special runtime handling as they are encoded in string patterns.
|
|
29
28
|
// This diverges from the mapped type which would otherwise map on the template literal kind.
|
|
30
29
|
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
31
|
-
const finite =
|
|
30
|
+
const finite = IsTemplateLiteralExpressionFinite(expression);
|
|
32
31
|
if (!finite)
|
|
33
32
|
return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
|
|
34
|
-
const strings = [...
|
|
33
|
+
const strings = [...TemplateLiteralExpressionGenerate(expression)];
|
|
35
34
|
const literals = strings.map((value) => Literal(value));
|
|
36
35
|
const mapped = FromRest(literals, mode);
|
|
37
36
|
const union = Union(mapped);
|
|
@@ -45,9 +44,12 @@ function FromLiteralValue(value, mode) {
|
|
|
45
44
|
mode === 'Lowercase' ? ApplyLowercase(value) :
|
|
46
45
|
value) : value.toString());
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
// prettier-ignore
|
|
48
|
+
function FromRest(T, M, Acc = []) {
|
|
49
49
|
const [L, ...R] = T;
|
|
50
|
-
return (T.length > 0
|
|
50
|
+
return (T.length > 0
|
|
51
|
+
? FromRest(R, M, [...Acc, Intrinsic(L, M)])
|
|
52
|
+
: Acc);
|
|
51
53
|
}
|
|
52
54
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
53
55
|
export function Intrinsic(schema, mode, 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 TKeyOf } from './keyof.mjs';
|
|
5
|
-
type
|
|
5
|
+
type TFromProperties<K extends TProperties> = ({
|
|
6
6
|
[K2 in keyof K]: TKeyOf<K[K2]>;
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
declare function
|
|
11
|
-
export type TKeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
|
|
12
|
-
export declare function KeyOfFromMappedResult<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 TKeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function KeyOfFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
13
11
|
export {};
|
|
@@ -7,24 +7,20 @@ import type { TTuple } from '../tuple/index.mjs';
|
|
|
7
7
|
import type { TArray } from '../array/index.mjs';
|
|
8
8
|
import type { TObject, TProperties } from '../object/index.mjs';
|
|
9
9
|
import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs';
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type FromUnion<T extends TSchema[], C extends PropertyKey[][] = FromRest<T>> = (OperatorIntersectMany<C>);
|
|
10
|
+
type TFromRest<T extends TSchema[], Acc extends PropertyKey[][] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TKeyOfPropertyKeys<L>]> : Acc);
|
|
11
|
+
type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = OperatorUnionMany<C>> = R;
|
|
12
|
+
declare function FromIntersect<T extends TSchema[]>(T: [...T]): FromIntersect<T>;
|
|
13
|
+
type FromUnion<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = OperatorIntersectMany<C>> = R;
|
|
15
14
|
declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
type FromArray<_ extends TSchema> = ([
|
|
15
|
+
type TFromTuple<T extends TSchema[], I extends string = ZeroString, Acc extends PropertyKey[] = []> = T extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? TFromTuple<R, Increment<I>, [...Acc, I]> : Acc;
|
|
16
|
+
type TFromArray<_ extends TSchema> = ([
|
|
19
17
|
'[number]'
|
|
20
18
|
]);
|
|
21
|
-
|
|
22
|
-
type
|
|
23
|
-
declare function FromProperties<T extends TProperties>(T: T): FromProperties<T>;
|
|
24
|
-
export type KeyOfPropertyKeys<T extends TSchema> = (T extends TRecursive<infer S> ? KeyOfPropertyKeys<S> : T extends TIntersect<infer S> ? FromIntersect<S> : T extends TUnion<infer S> ? FromUnion<S> : T extends TTuple<infer S> ? FromTuple<S> : T extends TArray<infer S> ? FromArray<S> : T extends TObject<infer S> ? FromProperties<S> : [
|
|
19
|
+
type TFromProperties<T extends TProperties> = (UnionToTuple<keyof T>);
|
|
20
|
+
export type TKeyOfPropertyKeys<T extends TSchema> = (T extends TRecursive<infer S> ? TKeyOfPropertyKeys<S> : T extends TIntersect<infer S> ? FromIntersect<S> : T extends TUnion<infer S> ? FromUnion<S> : T extends TTuple<infer S> ? TFromTuple<S> : T extends TArray<infer S> ? TFromArray<S> : T extends TObject<infer S> ? TFromProperties<S> : [
|
|
25
21
|
]);
|
|
26
22
|
/** Returns a tuple of PropertyKeys derived from the given TSchema. */
|
|
27
|
-
export declare function KeyOfPropertyKeys<T extends TSchema>(T: T):
|
|
23
|
+
export declare function KeyOfPropertyKeys<T extends TSchema>(T: T): TKeyOfPropertyKeys<T>;
|
|
28
24
|
/** Returns a regular expression pattern derived from the given TSchema */
|
|
29
25
|
export declare function KeyOfPattern(schema: TSchema): string;
|
|
30
26
|
export {};
|
|
@@ -6,27 +6,30 @@ import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs
|
|
|
6
6
|
// prettier-ignore
|
|
7
7
|
import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/type.mjs';
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function FromRest(T) {
|
|
9
|
+
function FromRest(T, Acc = []) {
|
|
10
10
|
const [L, ...R] = T;
|
|
11
11
|
return (T.length > 0
|
|
12
|
-
?
|
|
13
|
-
:
|
|
12
|
+
? FromRest(R, [...Acc, KeyOfPropertyKeys(L)])
|
|
13
|
+
: Acc);
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function FromIntersect(T
|
|
17
|
-
|
|
16
|
+
function FromIntersect(T) {
|
|
17
|
+
const C = FromRest(T);
|
|
18
|
+
const R = OperatorUnionMany(C);
|
|
19
|
+
return R;
|
|
18
20
|
}
|
|
19
21
|
// prettier-ignore
|
|
20
22
|
function FromUnion(T) {
|
|
21
23
|
const C = FromRest(T);
|
|
22
|
-
|
|
24
|
+
const R = OperatorIntersectMany(C);
|
|
25
|
+
return R;
|
|
23
26
|
}
|
|
24
27
|
// prettier-ignore
|
|
25
|
-
function FromTuple(T, I = '0') {
|
|
28
|
+
function FromTuple(T, I = '0', Acc = []) {
|
|
26
29
|
const [_, ...R] = T;
|
|
27
30
|
return (T.length > 0
|
|
28
|
-
?
|
|
29
|
-
:
|
|
31
|
+
? FromTuple(R, Increment(I), [...Acc, I])
|
|
32
|
+
: Acc);
|
|
30
33
|
}
|
|
31
34
|
// prettier-ignore
|
|
32
35
|
function FromArray(_) {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { Ensure } from '../helpers/index.mjs';
|
|
2
|
+
import type { Assert, Ensure } from '../helpers/index.mjs';
|
|
3
3
|
import type { TMappedResult } from '../mapped/index.mjs';
|
|
4
|
-
import
|
|
4
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
5
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
5
6
|
import { type TNumber } from '../number/index.mjs';
|
|
6
|
-
import { type
|
|
7
|
-
import {
|
|
8
|
-
import { UnionEvaluated } from '../union/index.mjs';
|
|
7
|
+
import { type TKeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
8
|
+
import { type TUnionEvaluated } from '../union/index.mjs';
|
|
9
9
|
import { type TKeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
export type TKeyOf<T extends TSchema> = (Ensure<UnionEvaluated<FromLiterals<KeyOfPropertyKeys<T>>>>);
|
|
10
|
+
type TFromPropertyKeys<T extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? L extends '[number]' ? TFromPropertyKeys<R, [...Acc, TNumber]> : TFromPropertyKeys<R, [...Acc, TLiteral<Assert<L, TLiteralValue>>]> : Acc);
|
|
11
|
+
export type TKeyOf<T extends TSchema, K extends PropertyKey[] = TKeyOfPropertyKeys<T>, S extends TSchema[] = TFromPropertyKeys<K>, U = TUnionEvaluated<S>> = (Ensure<U>);
|
|
13
12
|
/** `[Json]` Creates a KeyOf type */
|
|
14
13
|
export declare function KeyOf<T extends TMappedResult>(T: T, options?: SchemaOptions): TKeyOfFromMappedResult<T>;
|
|
15
14
|
/** `[Json]` Creates a KeyOf type */
|
|
@@ -10,13 +10,13 @@ import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
|
10
10
|
// prettier-ignore
|
|
11
11
|
import { IsMappedResult } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
|
-
function
|
|
13
|
+
function FromPropertyKeys(T, Acc = []) {
|
|
14
14
|
const [L, ...R] = T;
|
|
15
15
|
return (T.length > 0
|
|
16
16
|
? L === '[number]'
|
|
17
|
-
?
|
|
18
|
-
:
|
|
19
|
-
:
|
|
17
|
+
? FromPropertyKeys(R, [...Acc, Number()])
|
|
18
|
+
: FromPropertyKeys(R, [...Acc, Literal(L)])
|
|
19
|
+
: Acc);
|
|
20
20
|
}
|
|
21
21
|
/** `[Json]` Creates a KeyOf type */
|
|
22
22
|
export function KeyOf(T, options = {}) {
|
|
@@ -24,7 +24,9 @@ export function KeyOf(T, options = {}) {
|
|
|
24
24
|
return KeyOfFromMappedResult(T, options);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
const K =
|
|
28
|
-
|
|
27
|
+
const K = KeyOfPropertyKeys(T);
|
|
28
|
+
const S = FromPropertyKeys(K);
|
|
29
|
+
const U = UnionEvaluated(S);
|
|
30
|
+
return CloneType(U, options);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
@@ -16,26 +16,22 @@ import { type TTuple } from '../tuple/index.mjs';
|
|
|
16
16
|
import { type TUnion } from '../union/index.mjs';
|
|
17
17
|
import { type TMappedResult } from './mapped-result.mjs';
|
|
18
18
|
import type { TMappedKey } from './mapped-key.mjs';
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
type MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
|
|
19
|
+
type TFromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
|
|
20
|
+
type TMappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[], Acc extends TProperties = {}> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedKeyToMappedResultProperties<K, R, Acc & {
|
|
22
21
|
[_ in L]: TLiteral<Assert<L, TLiteralValue>>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type
|
|
26
|
-
declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): FromMappedResult<K, MappedKeyToMappedResultProperties<K, P>>;
|
|
27
|
-
type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
|
|
28
|
-
declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
|
|
22
|
+
}> : Acc);
|
|
23
|
+
type TFromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = TMappedKeyToMappedResultProperties<K, P>> = (TFromMappedResult<K, R>);
|
|
24
|
+
type TFromRest<K extends PropertyKey, T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<K, R, [...Acc, FromSchemaType<K, L>]> : Acc);
|
|
29
25
|
type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
|
|
30
26
|
[K2 in keyof T]: FromSchemaType<K, T[K2]>;
|
|
31
27
|
}>> = R;
|
|
32
28
|
declare function FromProperties<K extends PropertyKey, T extends TProperties>(K: K, T: T): FromProperties<K, T>;
|
|
33
|
-
type FromSchemaType<K extends PropertyKey, T extends TSchema> = (T extends TReadonly<infer S> ? TReadonly<FromSchemaType<K, S>> : T extends TOptional<infer S> ? TOptional<FromSchemaType<K, S>> : T extends TMappedResult<infer P> ?
|
|
29
|
+
type FromSchemaType<K extends PropertyKey, T extends TSchema> = (T extends TReadonly<infer S> ? TReadonly<FromSchemaType<K, S>> : T extends TOptional<infer S> ? TOptional<FromSchemaType<K, S>> : T extends TMappedResult<infer P> ? TFromMappedResult<K, P> : T extends TMappedKey<infer P> ? TFromMappedKey<K, P> : T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<TFromRest<K, S>, FromSchemaType<K, R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<TFromRest<K, S>, FromSchemaType<K, R>> : T extends TAsyncIterator<infer S> ? TAsyncIterator<FromSchemaType<K, S>> : T extends TIterator<infer S> ? TIterator<FromSchemaType<K, S>> : T extends TIntersect<infer S> ? TIntersect<TFromRest<K, S>> : T extends TUnion<infer S> ? TUnion<TFromRest<K, S>> : T extends TTuple<infer S> ? TTuple<TFromRest<K, S>> : T extends TObject<infer S> ? TObject<FromProperties<K, S>> : T extends TArray<infer S> ? TArray<FromSchemaType<K, S>> : T extends TPromise<infer S> ? TPromise<FromSchemaType<K, S>> : T);
|
|
34
30
|
declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K, T: T): FromSchemaType<K, T>;
|
|
35
|
-
type FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
|
|
31
|
+
type FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? FromMappedFunctionReturnType<R, T, Acc & {
|
|
36
32
|
[_ in L]: FromSchemaType<L, T>;
|
|
37
|
-
}
|
|
38
|
-
declare function FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): FromMappedFunctionReturnType<K, T>;
|
|
33
|
+
}> : Acc);
|
|
34
|
+
declare function FromMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T, Acc?: TProperties): FromMappedFunctionReturnType<K, T>;
|
|
39
35
|
export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
|
|
40
36
|
export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<FromMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
|
|
41
37
|
/** `[Json]` Creates a Mapped object type */
|
|
@@ -30,11 +30,11 @@ function FromMappedResult(K, P) {
|
|
|
30
30
|
: MappedResult(P));
|
|
31
31
|
}
|
|
32
32
|
// prettier-ignore
|
|
33
|
-
function MappedKeyToMappedResultProperties(K, P) {
|
|
33
|
+
function MappedKeyToMappedResultProperties(K, P, Acc = {}) {
|
|
34
34
|
const [L, ...R] = P;
|
|
35
35
|
return (P.length > 0
|
|
36
|
-
? { [L]: Literal(L)
|
|
37
|
-
:
|
|
36
|
+
? MappedKeyToMappedResultProperties(K, R, { ...Acc, [L]: Literal(L) })
|
|
37
|
+
: Acc);
|
|
38
38
|
}
|
|
39
39
|
// prettier-ignore
|
|
40
40
|
function FromMappedKey(K, P) {
|
|
@@ -42,11 +42,11 @@ function FromMappedKey(K, P) {
|
|
|
42
42
|
return FromMappedResult(K, R);
|
|
43
43
|
}
|
|
44
44
|
// prettier-ignore
|
|
45
|
-
function FromRest(K, T) {
|
|
45
|
+
function FromRest(K, T, Acc = []) {
|
|
46
46
|
const [L, ...R] = T;
|
|
47
47
|
return (T.length > 0
|
|
48
|
-
?
|
|
49
|
-
:
|
|
48
|
+
? FromRest(K, R, [...Acc, FromSchemaType(K, L)])
|
|
49
|
+
: Acc);
|
|
50
50
|
}
|
|
51
51
|
// prettier-ignore
|
|
52
52
|
function FromProperties(K, T) {
|
|
@@ -77,11 +77,11 @@ function FromSchemaType(K, T) {
|
|
|
77
77
|
T);
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
|
-
function FromMappedFunctionReturnType(K, T) {
|
|
80
|
+
function FromMappedFunctionReturnType(K, T, Acc = {}) {
|
|
81
81
|
const [L, ...R] = K;
|
|
82
82
|
return (K.length > 0
|
|
83
|
-
? { [L]: FromSchemaType(L, T)
|
|
84
|
-
:
|
|
83
|
+
? FromMappedFunctionReturnType(R, T, { ...Acc, [L]: FromSchemaType(L, T) })
|
|
84
|
+
: Acc);
|
|
85
85
|
}
|
|
86
86
|
/** `[Json]` Creates a Mapped object type */
|
|
87
87
|
export function Mapped(key, map, options = {}) {
|