@sinclair/typebox 0.32.0-dev-26 → 0.32.0-dev-28
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 +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.mjs +2 -6
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/composite/composite.d.mts +1 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/const/const.mjs +6 -6
- package/build/import/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/constructor/constructor.mjs +1 -1
- package/build/import/type/deref/deref.mjs +1 -2
- package/build/import/type/discard/discard.mjs +2 -2
- package/build/import/type/enum/enum.mjs +3 -0
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +5 -5
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +7 -7
- package/build/import/type/exclude/exclude.mjs +0 -1
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +4 -5
- package/build/import/type/extends/extends-from-mapped-result.d.mts +5 -5
- package/build/import/type/extends/extends-from-mapped-result.mjs +7 -7
- package/build/import/type/extends/extends.mjs +0 -1
- package/build/import/type/extract/extract-from-mapped-result.d.mts +5 -5
- package/build/import/type/extract/extract-from-mapped-result.mjs +7 -7
- package/build/import/type/extract/extract.d.mts +1 -2
- package/build/import/type/extract/extract.mjs +4 -2
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/index.d.mts +1 -1
- package/build/import/type/index.mjs +1 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +4 -5
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/import/type/indexed/indexed-property-keys.mjs +3 -5
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +9 -27
- package/build/import/type/intersect/intersect-evaluated.mjs +3 -13
- package/build/import/type/intrinsic/capitalize.d.mts +2 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +1 -1
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -5
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -3
- package/build/import/type/intrinsic/intrinsic.mjs +2 -5
- package/build/import/type/intrinsic/lowercase.d.mts +2 -2
- package/build/import/type/intrinsic/uncapitalize.d.mts +2 -2
- package/build/import/type/intrinsic/uppercase.d.mts +2 -2
- package/build/import/type/iterator/iterator.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -3
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -4
- package/build/import/type/keyof/keyof-property-keys.d.mts +3 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +9 -15
- package/build/import/type/keyof/keyof.mjs +2 -8
- package/build/import/type/mapped/mapped.d.mts +6 -1
- package/build/import/type/mapped/mapped.mjs +21 -14
- package/build/import/type/not/not.mjs +1 -1
- package/build/import/type/object/object.d.mts +1 -1
- package/build/import/type/object/object.mjs +0 -1
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +4 -5
- package/build/import/type/omit/omit-from-mapped-result.d.mts +11 -0
- package/build/import/type/omit/omit-from-mapped-result.mjs +17 -0
- package/build/import/type/omit/omit.d.mts +6 -3
- package/build/import/type/omit/omit.mjs +11 -9
- package/build/import/type/optional/optional-from-mapped-result.d.mts +5 -5
- package/build/import/type/optional/optional-from-mapped-result.mjs +7 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +5 -5
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -4
- package/build/import/type/partial/partial.d.mts +2 -3
- package/build/import/type/partial/partial.mjs +8 -21
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +4 -5
- package/build/import/type/pick/pick-from-mapped-result.d.mts +11 -0
- package/build/import/type/pick/pick-from-mapped-result.mjs +17 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +11 -10
- package/build/import/type/promise/promise.mjs +1 -1
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +5 -5
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -4
- package/build/import/type/record/record.d.mts +5 -3
- package/build/import/type/record/record.mjs +13 -5
- package/build/import/type/ref/ref.mjs +1 -1
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/required/required-from-mapped-result.d.mts +5 -5
- package/build/import/type/required/required-from-mapped-result.mjs +7 -7
- package/build/import/type/required/required.d.mts +2 -3
- package/build/import/type/required/required.mjs +4 -14
- package/build/import/type/rest/rest.d.mts +2 -2
- package/build/import/type/rest/rest.mjs +1 -2
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/sets/index.d.mts +1 -0
- package/build/import/type/sets/index.mjs +1 -0
- package/build/import/type/sets/set.d.mts +24 -0
- package/build/import/type/sets/set.mjs +35 -0
- package/build/import/type/strict/strict.d.mts +1 -1
- package/build/import/type/strict/strict.mjs +1 -1
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/template-literal.d.mts +1 -1
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/type/type/json.d.mts +6 -2
- package/build/import/type/union/union-evaluated.mjs +3 -14
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.js +2 -6
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/composite/composite.d.ts +1 -2
- package/build/require/type/composite/composite.js +5 -6
- package/build/require/type/const/const.js +6 -6
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/constructor/constructor.js +1 -1
- package/build/require/type/deref/deref.js +0 -1
- package/build/require/type/discard/discard.js +2 -2
- package/build/require/type/enum/enum.js +3 -0
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +5 -5
- package/build/require/type/exclude/exclude-from-mapped-result.js +7 -7
- package/build/require/type/exclude/exclude.js +0 -1
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/require/type/extends/extends-from-mapped-key.js +4 -5
- package/build/require/type/extends/extends-from-mapped-result.d.ts +5 -5
- package/build/require/type/extends/extends-from-mapped-result.js +7 -7
- package/build/require/type/extends/extends.js +0 -1
- package/build/require/type/extract/extract-from-mapped-result.d.ts +5 -5
- package/build/require/type/extract/extract-from-mapped-result.js +7 -7
- package/build/require/type/extract/extract.d.ts +1 -2
- package/build/require/type/extract/extract.js +4 -3
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/index.d.ts +1 -1
- package/build/require/type/index.js +1 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-key.js +4 -5
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/require/type/indexed/indexed-property-keys.js +3 -5
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +9 -27
- package/build/require/type/intersect/intersect-evaluated.js +3 -13
- package/build/require/type/intrinsic/capitalize.d.ts +2 -2
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +1 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +4 -5
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -3
- package/build/require/type/intrinsic/intrinsic.js +2 -5
- package/build/require/type/intrinsic/lowercase.d.ts +2 -2
- package/build/require/type/intrinsic/uncapitalize.d.ts +2 -2
- package/build/require/type/intrinsic/uppercase.d.ts +2 -2
- package/build/require/type/iterator/iterator.js +1 -1
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -3
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.d.ts +3 -3
- package/build/require/type/keyof/keyof-property-keys.js +9 -15
- package/build/require/type/keyof/keyof.js +2 -8
- package/build/require/type/mapped/mapped.d.ts +6 -1
- package/build/require/type/mapped/mapped.js +21 -14
- package/build/require/type/not/not.js +1 -1
- package/build/require/type/object/object.d.ts +1 -1
- package/build/require/type/object/object.js +0 -1
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-from-mapped-key.js +4 -5
- package/build/require/type/omit/omit-from-mapped-result.d.ts +11 -0
- package/build/require/type/omit/omit-from-mapped-result.js +22 -0
- package/build/require/type/omit/omit.d.ts +6 -3
- package/build/require/type/omit/omit.js +10 -8
- package/build/require/type/optional/optional-from-mapped-result.d.ts +5 -5
- package/build/require/type/optional/optional-from-mapped-result.js +7 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +5 -5
- package/build/require/type/partial/partial-from-mapped-result.js +4 -4
- package/build/require/type/partial/partial.d.ts +2 -3
- package/build/require/type/partial/partial.js +8 -21
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-from-mapped-key.js +4 -5
- package/build/require/type/pick/pick-from-mapped-result.d.ts +11 -0
- package/build/require/type/pick/pick-from-mapped-result.js +22 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -9
- package/build/require/type/promise/promise.js +1 -1
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +5 -5
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -4
- package/build/require/type/record/record.d.ts +5 -3
- package/build/require/type/record/record.js +12 -4
- package/build/require/type/ref/ref.js +1 -1
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/required/required-from-mapped-result.d.ts +5 -5
- package/build/require/type/required/required-from-mapped-result.js +7 -7
- package/build/require/type/required/required.d.ts +2 -3
- package/build/require/type/required/required.js +4 -14
- package/build/require/type/rest/rest.d.ts +2 -2
- package/build/require/type/rest/rest.js +1 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/sets/index.d.ts +1 -0
- package/build/require/type/{operators → sets}/index.js +1 -1
- package/build/require/type/sets/set.d.ts +24 -0
- package/build/require/type/sets/set.js +47 -0
- package/build/require/type/strict/strict.d.ts +1 -1
- package/build/require/type/strict/strict.js +1 -1
- package/build/require/type/template-literal/parse.js +1 -1
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/template-literal.d.ts +1 -1
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/type/type/json.d.ts +6 -2
- package/build/require/type/union/union-evaluated.js +3 -14
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +68 -67
- package/build/import/type/operators/index.d.mts +0 -1
- package/build/import/type/operators/index.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +0 -24
- package/build/import/type/operators/operators.mjs +0 -77
- package/build/require/type/operators/index.d.ts +0 -1
- package/build/require/type/operators/operators.d.ts +0 -24
- package/build/require/type/operators/operators.js +0 -89
|
@@ -16,6 +16,8 @@ import { Promise } from '../promise/index.mjs';
|
|
|
16
16
|
import { Readonly } from '../readonly/index.mjs';
|
|
17
17
|
import { Tuple } from '../tuple/index.mjs';
|
|
18
18
|
import { Union } from '../union/index.mjs';
|
|
19
|
+
// operator
|
|
20
|
+
import { SetIncludes } from '../sets/index.mjs';
|
|
19
21
|
// mapping types
|
|
20
22
|
import { MappedResult } from './mapped-result.mjs';
|
|
21
23
|
// ------------------------------------------------------------------
|
|
@@ -30,11 +32,20 @@ function FromMappedResult(K, P) {
|
|
|
30
32
|
: MappedResult(P));
|
|
31
33
|
}
|
|
32
34
|
// prettier-ignore
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
function MappedKeyToKnownMappedResultProperties(K) {
|
|
36
|
+
return { [K]: Literal(K) };
|
|
37
|
+
}
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
function MappedKeyToUnknownMappedResultProperties(P) {
|
|
40
|
+
return P.reduce((Acc, L) => {
|
|
41
|
+
return { ...Acc, [L]: Literal(L) };
|
|
42
|
+
}, {});
|
|
43
|
+
}
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
function MappedKeyToMappedResultProperties(K, P) {
|
|
46
|
+
return (SetIncludes(P, K)
|
|
47
|
+
? MappedKeyToKnownMappedResultProperties(K)
|
|
48
|
+
: MappedKeyToUnknownMappedResultProperties(P));
|
|
38
49
|
}
|
|
39
50
|
// prettier-ignore
|
|
40
51
|
function FromMappedKey(K, P) {
|
|
@@ -42,11 +53,8 @@ function FromMappedKey(K, P) {
|
|
|
42
53
|
return FromMappedResult(K, R);
|
|
43
54
|
}
|
|
44
55
|
// prettier-ignore
|
|
45
|
-
function FromRest(K, T
|
|
46
|
-
|
|
47
|
-
return (T.length > 0
|
|
48
|
-
? FromRest(K, R, [...Acc, FromSchemaType(K, L)])
|
|
49
|
-
: Acc);
|
|
56
|
+
function FromRest(K, T) {
|
|
57
|
+
return T.map(L => FromSchemaType(K, L));
|
|
50
58
|
}
|
|
51
59
|
// prettier-ignore
|
|
52
60
|
function FromProperties(K, T) {
|
|
@@ -78,10 +86,9 @@ function FromSchemaType(K, T) {
|
|
|
78
86
|
}
|
|
79
87
|
// prettier-ignore
|
|
80
88
|
function FromMappedFunctionReturnType(K, T, Acc = {}) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
: Acc);
|
|
89
|
+
return K.reduce((Acc, L) => {
|
|
90
|
+
return { ...Acc, [L]: FromSchemaType(L, T) };
|
|
91
|
+
}, {});
|
|
85
92
|
}
|
|
86
93
|
/** `[Json]` Creates a Mapped object type */
|
|
87
94
|
export function Mapped(key, map, options = {}) {
|
|
@@ -15,7 +15,7 @@ type OptionalPropertyKeys<T extends TProperties> = {
|
|
|
15
15
|
}[keyof T];
|
|
16
16
|
type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
17
17
|
type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
18
|
-
|
|
18
|
+
type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
|
|
19
19
|
[K in keyof T]: Static<T[K], P>;
|
|
20
20
|
}>;
|
|
21
21
|
export type TPropertyKey = string | number;
|
|
@@ -3,7 +3,6 @@ import { Kind } from '../symbols/index.mjs';
|
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
// prettier-ignore
|
|
7
6
|
import { IsOptional, IsSchema } from '../guard/type.mjs';
|
|
8
7
|
/** `[Json]` Creates an Object type */
|
|
9
8
|
export function _Object(properties, options = {}) {
|
|
@@ -7,11 +7,10 @@ function FromPropertyKey(T, K, options) {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromPropertyKeys(T, K, options
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
: Acc);
|
|
10
|
+
function FromPropertyKeys(T, K, options) {
|
|
11
|
+
return K.reduce((Acc, LK) => {
|
|
12
|
+
return { ...Acc, ...FromPropertyKey(T, LK, options) };
|
|
13
|
+
}, {});
|
|
15
14
|
}
|
|
16
15
|
// prettier-ignore
|
|
17
16
|
function FromMappedKey(T, K, options) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TOmit } from './omit.mjs';
|
|
5
|
+
type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
6
|
+
[K2 in keyof P]: TOmit<P[K2], K>;
|
|
7
|
+
});
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (TFromProperties<R['properties'], K>);
|
|
9
|
+
export type TOmitFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (TMappedResult<P>);
|
|
10
|
+
export declare function OmitFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options: SchemaOptions): TMappedResult<P>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Omit } from './omit.mjs';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
function FromProperties(P, K, options) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Omit(P[K2], K, options) };
|
|
7
|
+
}, {});
|
|
8
|
+
}
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
function FromMappedResult(R, K, options) {
|
|
11
|
+
return FromProperties(R.properties, K, options);
|
|
12
|
+
}
|
|
13
|
+
// prettier-ignore
|
|
14
|
+
export function OmitFromMappedResult(R, K, options) {
|
|
15
|
+
const P = FromMappedResult(R, K, options);
|
|
16
|
+
return MappedResult(P);
|
|
17
|
+
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { TupleToUnion, Evaluate } from '../helpers/index.mjs';
|
|
3
3
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
4
|
+
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
4
5
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
5
6
|
import { type TUnion } from '../union/index.mjs';
|
|
6
7
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
7
8
|
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
8
|
-
import { TMappedKey } from '../mapped/index.mjs';
|
|
9
9
|
import { type TOmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
10
|
+
import { type TOmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
10
11
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, K, [...Acc, TOmitResolve<L, K>]> : Acc);
|
|
11
12
|
type TFromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Acc, TOmitResolve<L, K>]> : Acc);
|
|
12
13
|
type TFromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Omit<T, I>>;
|
|
13
14
|
export type TOmitResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TOmitResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S, K>> : T extends TObject<infer S> ? TObject<TFromProperties<S, K>> : TObject<{}>;
|
|
14
15
|
export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TOmitResolve<T, K>;
|
|
15
16
|
export type TOmit<T extends TSchema, K extends PropertyKey[]> = TOmitResolve<T, K>;
|
|
16
|
-
/** `[Json]` Constructs a type whose keys are
|
|
17
|
-
export declare function Omit<T extends
|
|
17
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
18
|
+
export declare function Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
|
|
19
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
20
|
+
export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TOmitFromMappedKey<T, K>;
|
|
18
21
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
19
22
|
export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
20
23
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
@@ -6,10 +6,11 @@ import { Discard } from '../discard/index.mjs';
|
|
|
6
6
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
7
|
import { CloneType } from '../clone/type.mjs';
|
|
8
8
|
import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
9
|
+
import { OmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
9
10
|
// ------------------------------------------------------------------
|
|
10
11
|
// TypeGuard
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
|
-
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/type.mjs';
|
|
13
|
+
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/type.mjs';
|
|
13
14
|
// prettier-ignore
|
|
14
15
|
function FromIntersect(T, K) {
|
|
15
16
|
return T.map((T) => OmitResolve(T, K));
|
|
@@ -40,13 +41,14 @@ export function OmitResolve(T, K) {
|
|
|
40
41
|
Object({}));
|
|
41
42
|
}
|
|
42
43
|
export function Omit(T, K, options = {}) {
|
|
43
|
-
|
|
44
|
+
// mapped
|
|
45
|
+
if (IsMappedKey(K))
|
|
44
46
|
return OmitFromMappedKey(T, K, options);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
if (IsMappedResult(T))
|
|
48
|
+
return OmitFromMappedResult(T, K, options);
|
|
49
|
+
// non-mapped
|
|
50
|
+
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
51
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
52
|
+
const R = CloneType(OmitResolve(T, I), options);
|
|
53
|
+
return { ...D, ...R };
|
|
52
54
|
}
|
|
@@ -1,10 +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 TFromProperties<
|
|
5
|
-
[K2 in keyof
|
|
4
|
+
type TFromProperties<P extends TProperties, F extends boolean> = ({
|
|
5
|
+
[K2 in keyof P]: TOptionalWithFlag<P[K2], F>;
|
|
6
6
|
});
|
|
7
|
-
type TFromMappedResult<
|
|
8
|
-
export type TOptionalFromMappedResult<
|
|
9
|
-
export declare function OptionalFromMappedResult<
|
|
7
|
+
type TFromMappedResult<R extends TMappedResult, F extends boolean> = (TFromProperties<R['properties'], F>);
|
|
8
|
+
export type TOptionalFromMappedResult<R extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<R, F>> = (TMappedResult<P>);
|
|
9
|
+
export declare function OptionalFromMappedResult<R extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<R, F>>(R: R, F: F): TMappedResult<P>;
|
|
10
10
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Optional } from './optional.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
|
-
function FromProperties(
|
|
5
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
6
|
-
return { ...Acc, [K2]: Optional(
|
|
4
|
+
function FromProperties(P, F) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Optional(P[K2], F) };
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, F) {
|
|
11
|
+
return FromProperties(R.properties, F);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function OptionalFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function OptionalFromMappedResult(R, F) {
|
|
15
|
+
const P = FromMappedResult(R, F);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -2,10 +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 TFromProperties<
|
|
6
|
-
[K2 in keyof
|
|
5
|
+
type TFromProperties<P extends TProperties> = ({
|
|
6
|
+
[K2 in keyof P]: TPartial<P[K2]>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TPartialFromMappedResult<
|
|
10
|
-
export declare function PartialFromMappedResult<
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult> = (TFromProperties<R['properties']>);
|
|
9
|
+
export type TPartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (TMappedResult<P>);
|
|
10
|
+
export declare function PartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -7,11 +7,11 @@ function FromProperties(K, options) {
|
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, options) {
|
|
11
|
+
return FromProperties(R.properties, options);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function PartialFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function PartialFromMappedResult(R, options) {
|
|
15
|
+
const P = FromMappedResult(R, options);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -9,12 +9,11 @@ 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
|
-
type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, PartialResolve<L>]> : Acc);
|
|
12
|
+
type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, PartialResolve<L>]> : Acc);
|
|
14
13
|
type TFromProperties<T extends TProperties> = Evaluate<{
|
|
15
14
|
[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]>;
|
|
16
15
|
}>;
|
|
17
|
-
type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<
|
|
16
|
+
type PartialResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<PartialResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S> ? TUnion<TFromRest<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
|
|
18
17
|
declare function PartialResolve<T extends TSchema>(T: T): PartialResolve<T>;
|
|
19
18
|
export type TPartial<T extends TSchema> = PartialResolve<T>;
|
|
20
19
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
@@ -11,18 +11,8 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
return (T.length > 0
|
|
17
|
-
? FromIntersect(R, [...Acc, PartialResolve(L)])
|
|
18
|
-
: Acc);
|
|
19
|
-
}
|
|
20
|
-
// prettier-ignore
|
|
21
|
-
function FromUnion(T, Acc = []) {
|
|
22
|
-
const [L, ...R] = T;
|
|
23
|
-
return (T.length > 0
|
|
24
|
-
? FromUnion(R, [...Acc, PartialResolve(L)])
|
|
25
|
-
: Acc);
|
|
14
|
+
function FromRest(T) {
|
|
15
|
+
return T.map(L => PartialResolve(L));
|
|
26
16
|
}
|
|
27
17
|
// prettier-ignore
|
|
28
18
|
function FromProperties(T) {
|
|
@@ -32,19 +22,16 @@ function FromProperties(T) {
|
|
|
32
22
|
}
|
|
33
23
|
// prettier-ignore
|
|
34
24
|
function PartialResolve(T) {
|
|
35
|
-
return (IsIntersect(T) ? Intersect(
|
|
36
|
-
IsUnion(T) ? Union(
|
|
25
|
+
return (IsIntersect(T) ? Intersect(FromRest(T.allOf)) :
|
|
26
|
+
IsUnion(T) ? Union(FromRest(T.anyOf)) :
|
|
37
27
|
IsObject(T) ? Object(FromProperties(T.properties)) :
|
|
38
28
|
Object({}));
|
|
39
29
|
}
|
|
40
30
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
41
31
|
export function Partial(T, options = {}) {
|
|
42
|
-
if (IsMappedResult(T))
|
|
32
|
+
if (IsMappedResult(T))
|
|
43
33
|
return PartialFromMappedResult(T, options);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const R = CloneType(PartialResolve(T), options);
|
|
48
|
-
return { ...D, ...R };
|
|
49
|
-
}
|
|
34
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
35
|
+
const R = CloneType(PartialResolve(T), options);
|
|
36
|
+
return { ...D, ...R };
|
|
50
37
|
}
|
|
@@ -7,11 +7,10 @@ function FromPropertyKey(T, K, options) {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromPropertyKeys(T, K, options
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
: Acc);
|
|
10
|
+
function FromPropertyKeys(T, K, options) {
|
|
11
|
+
return K.reduce((Acc, LK) => {
|
|
12
|
+
return { ...Acc, ...FromPropertyKey(T, LK, options) };
|
|
13
|
+
}, {});
|
|
15
14
|
}
|
|
16
15
|
// prettier-ignore
|
|
17
16
|
function FromMappedKey(T, K, options) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TPick } from './pick.mjs';
|
|
5
|
+
type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
6
|
+
[K2 in keyof P]: TPick<P[K2], K>;
|
|
7
|
+
});
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (TFromProperties<R['properties'], K>);
|
|
9
|
+
export type TPickFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (TMappedResult<P>);
|
|
10
|
+
export declare function PickFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options: SchemaOptions): TMappedResult<P>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Pick } from './pick.mjs';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
function FromProperties(P, K, options) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Pick(P[K2], K, options) };
|
|
7
|
+
}, {});
|
|
8
|
+
}
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
function FromMappedResult(R, K, options) {
|
|
11
|
+
return FromProperties(R.properties, K, options);
|
|
12
|
+
}
|
|
13
|
+
// prettier-ignore
|
|
14
|
+
export function PickFromMappedResult(R, K, options) {
|
|
15
|
+
const P = FromMappedResult(R, K, options);
|
|
16
|
+
return MappedResult(P);
|
|
17
|
+
}
|
|
@@ -4,9 +4,10 @@ import { type TRecursive } from '../recursive/index.mjs';
|
|
|
4
4
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
5
5
|
import { type TUnion } from '../union/index.mjs';
|
|
6
6
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
7
|
+
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
7
8
|
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
8
|
-
import { TMappedKey } from '../mapped/index.mjs';
|
|
9
9
|
import { type TPickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
10
|
+
import { type TPickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
10
11
|
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
12
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K, []>;
|
|
12
13
|
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;
|
|
@@ -17,7 +18,9 @@ export type PickResolve<T extends TProperties, K extends PropertyKey[]> = T exte
|
|
|
17
18
|
export declare function PickResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): PickResolve<T, K>;
|
|
18
19
|
export type TPick<T extends TSchema, K extends PropertyKey[]> = PickResolve<T, K>;
|
|
19
20
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
20
|
-
export declare function Pick<T extends
|
|
21
|
+
export declare function Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TPickFromMappedResult<T, K>;
|
|
22
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
23
|
+
export declare function Pick<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TPickFromMappedKey<T, K>;
|
|
21
24
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
22
25
|
export declare function Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
|
|
23
26
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
@@ -6,11 +6,11 @@ import { Discard } from '../discard/index.mjs';
|
|
|
6
6
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
7
|
import { CloneType } from '../clone/type.mjs';
|
|
8
8
|
import { PickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
9
|
+
import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
9
10
|
// ------------------------------------------------------------------
|
|
10
11
|
// TypeGuard
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, } from '../guard/type.mjs';
|
|
13
|
+
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/type.mjs';
|
|
14
14
|
function FromIntersect(T, K) {
|
|
15
15
|
return T.map((T) => PickResolve(T, K));
|
|
16
16
|
}
|
|
@@ -32,13 +32,14 @@ export function PickResolve(T, K) {
|
|
|
32
32
|
Object({}));
|
|
33
33
|
}
|
|
34
34
|
export function Pick(T, K, options = {}) {
|
|
35
|
-
|
|
35
|
+
// mapped
|
|
36
|
+
if (IsMappedKey(K))
|
|
36
37
|
return PickFromMappedKey(T, K, options);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
38
|
+
if (IsMappedResult(T))
|
|
39
|
+
return PickFromMappedResult(T, K, options);
|
|
40
|
+
// non-mapped
|
|
41
|
+
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
42
|
+
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
43
|
+
const R = CloneType(PickResolve(T, I), options);
|
|
44
|
+
return { ...D, ...R };
|
|
44
45
|
}
|
|
@@ -1,10 +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 TFromProperties<
|
|
5
|
-
[K2 in keyof
|
|
4
|
+
type TFromProperties<P extends TProperties, F extends boolean> = ({
|
|
5
|
+
[K2 in keyof P]: TReadonlyWithFlag<P[K2], F>;
|
|
6
6
|
});
|
|
7
|
-
type TFromMappedResult<
|
|
8
|
-
export type TReadonlyFromMappedResult<
|
|
9
|
-
export declare function ReadonlyFromMappedResult<
|
|
7
|
+
type TFromMappedResult<R extends TMappedResult, F extends boolean> = (TFromProperties<R['properties'], F>);
|
|
8
|
+
export type TReadonlyFromMappedResult<R extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<R, F>> = (TMappedResult<P>);
|
|
9
|
+
export declare function ReadonlyFromMappedResult<R extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<R, F>>(R: R, F: F): TMappedResult<P>;
|
|
10
10
|
export {};
|
|
@@ -7,11 +7,11 @@ function FromProperties(K, F) {
|
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, F) {
|
|
11
|
+
return FromProperties(R.properties, F);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function ReadonlyFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function ReadonlyFromMappedResult(R, F) {
|
|
15
|
+
const P = FromMappedResult(R, F);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -2,14 +2,15 @@ import type { TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import type { Evaluate, Ensure, Assert } from '../helpers/index.mjs';
|
|
4
4
|
import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
|
|
5
|
-
import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
5
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
6
6
|
import { type TNever } from '../never/index.mjs';
|
|
7
7
|
import { type TUnion } from '../union/index.mjs';
|
|
8
|
+
import { type TRegExp } from '../regexp/index.mjs';
|
|
8
9
|
import { type TString } from '../string/index.mjs';
|
|
9
10
|
import { type TInteger } from '../integer/index.mjs';
|
|
10
11
|
import { type TNumber } from '../number/index.mjs';
|
|
11
12
|
import { type TEnum } from '../enum/index.mjs';
|
|
12
|
-
import {
|
|
13
|
+
import { TIsTemplateLiteralFinite, type TTemplateLiteral } from '../template-literal/index.mjs';
|
|
13
14
|
import { Kind } from '../symbols/index.mjs';
|
|
14
15
|
type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
15
16
|
type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
|
|
@@ -30,6 +31,7 @@ type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties
|
|
|
30
31
|
type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
|
|
31
32
|
[_ in Assert<K, PropertyKey>]: T;
|
|
32
33
|
}>>);
|
|
34
|
+
type TFromRegExpKey<_ extends TRegExp, T extends TSchema> = (Ensure<TRecord<TRegExp, T>>);
|
|
33
35
|
type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
|
|
34
36
|
type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
35
37
|
type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
@@ -43,7 +45,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
|
|
|
43
45
|
};
|
|
44
46
|
additionalProperties: TAdditionalProperties;
|
|
45
47
|
}
|
|
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;
|
|
48
|
+
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 TRegExp ? TFromRegExpKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
|
|
47
49
|
/** `[Json]` Creates a Record type */
|
|
48
50
|
export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
|
|
49
51
|
export {};
|
|
@@ -6,11 +6,14 @@ import { PatternStringExact, PatternNumberExact } from '../patterns/index.mjs';
|
|
|
6
6
|
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
7
7
|
import { Kind, Hint } from '../symbols/index.mjs';
|
|
8
8
|
import { CloneType } from '../clone/type.mjs';
|
|
9
|
+
// ------------------------------------------------------------------
|
|
10
|
+
// ValueGuard
|
|
11
|
+
// ------------------------------------------------------------------
|
|
9
12
|
import { IsUndefined } from '../guard/value.mjs';
|
|
10
13
|
// ------------------------------------------------------------------
|
|
11
14
|
// TypeGuard
|
|
12
15
|
// ------------------------------------------------------------------
|
|
13
|
-
import { IsInteger, IsLiteral, IsNumber, IsString, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
|
|
16
|
+
import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
|
|
14
17
|
// ------------------------------------------------------------------
|
|
15
18
|
// RecordCreateFromPattern
|
|
16
19
|
// ------------------------------------------------------------------
|
|
@@ -46,6 +49,10 @@ function FromLiteralKey(K, T, options) {
|
|
|
46
49
|
return RecordCreateFromKeys([K.toString()], T, options);
|
|
47
50
|
}
|
|
48
51
|
// prettier-ignore
|
|
52
|
+
function FromRegExpKey(K, T, options) {
|
|
53
|
+
return RecordCreateFromPattern(K.source, T, options);
|
|
54
|
+
}
|
|
55
|
+
// prettier-ignore
|
|
49
56
|
function FromStringKey(K, T, options) {
|
|
50
57
|
const pattern = IsUndefined(K.pattern) ? PatternStringExact : K.pattern;
|
|
51
58
|
return RecordCreateFromPattern(pattern, T, options);
|
|
@@ -67,8 +74,9 @@ export function Record(K, T, options = {}) {
|
|
|
67
74
|
return (IsUnion(K) ? FromUnionKey(K.anyOf, T, options) :
|
|
68
75
|
IsTemplateLiteral(K) ? FromTemplateLiteralKey(K, T, options) :
|
|
69
76
|
IsLiteral(K) ? FromLiteralKey(K.const, T, options) :
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
IsInteger(K) ? FromIntegerKey(K, T, options) :
|
|
78
|
+
IsNumber(K) ? FromNumberKey(K, T, options) :
|
|
79
|
+
IsRegExp(K) ? FromRegExpKey(K, T, options) :
|
|
80
|
+
IsString(K) ? FromStringKey(K, T, options) :
|
|
81
|
+
Never(options));
|
|
74
82
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
2
|
// ------------------------------------------------------------------
|
|
3
|
-
//
|
|
3
|
+
// ValueGuard
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
import { IsString, IsUndefined } from '../guard/value.mjs';
|
|
6
6
|
/** `[Json]` Creates a Ref type. */
|