@sinclair/typebox 0.32.24 → 0.32.25
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/type/awaited/awaited.mjs +1 -1
- package/build/import/type/clone/value.mjs +8 -3
- package/build/import/type/composite/composite.mjs +14 -10
- package/build/import/type/const/const.mjs +4 -3
- package/build/import/type/deref/deref.d.mts +1 -1
- package/build/import/type/deref/deref.mjs +6 -4
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +4 -3
- package/build/import/type/exclude/exclude.mjs +1 -1
- package/build/import/type/extends/extends-from-mapped-result.mjs +4 -3
- package/build/import/type/extends/extends.mjs +1 -1
- package/build/import/type/extract/extract-from-mapped-result.mjs +4 -3
- package/build/import/type/extract/extract.mjs +1 -1
- package/build/import/type/guard/index.d.mts +1 -0
- package/build/import/type/guard/index.mjs +1 -0
- package/build/import/type/guard/kind.d.mts +136 -0
- package/build/import/type/guard/kind.mjs +217 -0
- package/build/import/type/guard/type.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-result.mjs +5 -3
- package/build/import/type/indexed/indexed-property-keys.mjs +5 -4
- package/build/import/type/indexed/indexed.mjs +1 -1
- package/build/import/type/intersect/intersect-create.mjs +1 -1
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -2
- package/build/import/type/intersect/intersect.mjs +1 -1
- package/build/import/type/intrinsic/intrinsic.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +5 -4
- package/build/import/type/keyof/keyof.mjs +1 -1
- package/build/import/type/mapped/mapped.d.mts +1 -1
- package/build/import/type/mapped/mapped.mjs +14 -12
- package/build/import/type/object/object.mjs +4 -2
- package/build/import/type/omit/omit-from-mapped-result.mjs +4 -3
- package/build/import/type/omit/omit.mjs +2 -4
- package/build/import/type/optional/optional-from-mapped-result.mjs +4 -3
- package/build/import/type/optional/optional.mjs +1 -1
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -3
- package/build/import/type/partial/partial.mjs +5 -4
- package/build/import/type/pick/pick-from-mapped-result.mjs +4 -3
- package/build/import/type/pick/pick.d.mts +1 -1
- package/build/import/type/pick/pick.mjs +6 -4
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -3
- package/build/import/type/readonly/readonly.mjs +1 -1
- package/build/import/type/record/record.mjs +5 -3
- package/build/import/type/required/required-from-mapped-result.mjs +4 -3
- package/build/import/type/required/required.mjs +5 -4
- package/build/import/type/rest/rest.mjs +4 -4
- package/build/import/type/sets/set.mjs +4 -1
- package/build/import/type/template-literal/pattern.mjs +1 -2
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +1 -1
- package/build/import/value/clean/clean.mjs +1 -1
- package/build/import/value/clone/clone.mjs +8 -2
- package/build/import/value/create/create.mjs +11 -7
- package/build/import/value/hash/hash.mjs +1 -1
- package/build/import/value/mutate/mutate.mjs +2 -2
- package/build/import/value/transform/decode.mjs +30 -30
- package/build/import/value/transform/encode.mjs +33 -30
- package/build/require/type/awaited/awaited.js +4 -4
- package/build/require/type/clone/value.js +8 -3
- package/build/require/type/composite/composite.js +15 -11
- package/build/require/type/const/const.js +4 -3
- package/build/require/type/deref/deref.d.ts +1 -1
- package/build/require/type/deref/deref.js +17 -15
- package/build/require/type/exclude/exclude-from-mapped-result.js +4 -3
- package/build/require/type/exclude/exclude.js +4 -4
- package/build/require/type/extends/extends-from-mapped-result.js +4 -3
- package/build/require/type/extends/extends.js +3 -3
- package/build/require/type/extract/extract-from-mapped-result.js +4 -3
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/index.d.ts +1 -0
- package/build/require/type/guard/index.js +2 -1
- package/build/require/type/guard/kind.d.ts +136 -0
- package/build/require/type/guard/kind.js +266 -0
- package/build/require/type/guard/type.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-result.js +5 -3
- package/build/require/type/indexed/indexed-property-keys.js +10 -9
- package/build/require/type/indexed/indexed.js +11 -11
- package/build/require/type/intersect/intersect-create.js +4 -4
- package/build/require/type/intersect/intersect-evaluated.js +4 -5
- package/build/require/type/intersect/intersect.js +2 -2
- package/build/require/type/intrinsic/intrinsic.js +5 -5
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -3
- package/build/require/type/keyof/keyof-property-keys.js +11 -10
- package/build/require/type/keyof/keyof.js +2 -2
- package/build/require/type/mapped/mapped.d.ts +1 -1
- package/build/require/type/mapped/mapped.js +29 -27
- package/build/require/type/object/object.js +6 -4
- package/build/require/type/omit/omit-from-mapped-result.js +4 -3
- package/build/require/type/omit/omit.js +8 -10
- package/build/require/type/optional/optional-from-mapped-result.js +4 -3
- package/build/require/type/optional/optional.js +2 -2
- package/build/require/type/partial/partial-from-mapped-result.js +4 -3
- package/build/require/type/partial/partial.js +9 -8
- package/build/require/type/pick/pick-from-mapped-result.js +4 -3
- package/build/require/type/pick/pick.d.ts +1 -1
- package/build/require/type/pick/pick.js +12 -10
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -3
- package/build/require/type/readonly/readonly.js +2 -2
- package/build/require/type/record/record.js +12 -10
- package/build/require/type/required/required-from-mapped-result.js +4 -3
- package/build/require/type/required/required.js +9 -8
- package/build/require/type/rest/rest.js +4 -4
- package/build/require/type/sets/set.js +4 -1
- package/build/require/type/template-literal/pattern.js +9 -10
- package/build/require/type/transform/transform.js +2 -2
- package/build/require/type/union/union-evaluated.js +3 -3
- package/build/require/value/clean/clean.js +1 -1
- package/build/require/value/clone/clone.js +8 -2
- package/build/require/value/create/create.js +11 -7
- package/build/require/value/hash/hash.js +1 -1
- package/build/require/value/mutate/mutate.js +2 -2
- package/build/require/value/transform/decode.js +30 -30
- package/build/require/value/transform/encode.js +33 -30
- package/package.json +1 -1
- package/readme.md +4 -4
|
@@ -7,8 +7,7 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
import { IsOptional, IsTransform, } from '../guard/type.mjs';
|
|
10
|
+
import { IsOptional, IsTransform } from '../guard/kind.mjs';
|
|
12
11
|
// prettier-ignore
|
|
13
12
|
function IsIntersectOptional(T) {
|
|
14
13
|
return T.every(L => IsOptional(L));
|
|
@@ -4,7 +4,7 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
import { IsTransform } from '../guard/
|
|
7
|
+
import { IsTransform } from '../guard/kind.mjs';
|
|
8
8
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
9
9
|
export function Intersect(T, options = {}) {
|
|
10
10
|
if (T.length === 0)
|
|
@@ -5,7 +5,7 @@ import { Union } from '../union/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// TypeGuard
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/
|
|
8
|
+
import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/kind.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// Apply
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { KeyOf } from './keyof.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(K, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
7
|
+
Acc[K2] = KeyOf(K[K2], options);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, options) {
|
|
@@ -2,12 +2,13 @@ import { SetUnionMany, SetIntersectMany } from '../sets/index.mjs';
|
|
|
2
2
|
// ------------------------------------------------------------------
|
|
3
3
|
// TypeGuard
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/
|
|
5
|
+
import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/kind.mjs';
|
|
6
6
|
// prettier-ignore
|
|
7
7
|
function FromRest(T) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const Acc = [];
|
|
9
|
+
for (const L of T)
|
|
10
|
+
Acc.push(KeyOfPropertyKeys(L));
|
|
11
|
+
return Acc;
|
|
11
12
|
}
|
|
12
13
|
// prettier-ignore
|
|
13
14
|
function FromIntersect(T) {
|
|
@@ -7,7 +7,7 @@ import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
import { IsMappedResult } from '../guard/
|
|
10
|
+
import { IsMappedResult } from '../guard/kind.mjs';
|
|
11
11
|
// prettier-ignore
|
|
12
12
|
export function KeyOfPropertyKeysToRest(T) {
|
|
13
13
|
return T.map(L => L === '[number]' ? Number() : Literal(L));
|
|
@@ -36,7 +36,7 @@ declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K,
|
|
|
36
36
|
export type TMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedFunctionReturnType<R, T, Acc & {
|
|
37
37
|
[_ in L]: FromSchemaType<L, T>;
|
|
38
38
|
}> : Acc);
|
|
39
|
-
export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T
|
|
39
|
+
export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): TMappedFunctionReturnType<K, T>;
|
|
40
40
|
export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
|
|
41
41
|
export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<TMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
|
|
42
42
|
/** `[Json]` Creates a Mapped object type */
|
|
@@ -23,8 +23,7 @@ import { MappedResult } from './mapped-result.mjs';
|
|
|
23
23
|
// ------------------------------------------------------------------
|
|
24
24
|
// TypeGuard
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
import { IsArray, IsAsyncIterator, IsConstructor, IsFunction, IsIntersect, IsIterator, IsReadonly, IsMappedResult, IsMappedKey, IsObject, IsOptional, IsPromise, IsSchema, IsTuple, IsUnion, } from '../guard/type.mjs';
|
|
26
|
+
import { IsArray, IsAsyncIterator, IsConstructor, IsFunction, IsIntersect, IsIterator, IsReadonly, IsMappedResult, IsMappedKey, IsObject, IsOptional, IsPromise, IsSchema, IsTuple, IsUnion } from '../guard/kind.mjs';
|
|
28
27
|
// prettier-ignore
|
|
29
28
|
function FromMappedResult(K, P) {
|
|
30
29
|
return (K in P
|
|
@@ -37,9 +36,10 @@ function MappedKeyToKnownMappedResultProperties(K) {
|
|
|
37
36
|
}
|
|
38
37
|
// prettier-ignore
|
|
39
38
|
function MappedKeyToUnknownMappedResultProperties(P) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const Acc = {};
|
|
40
|
+
for (const L of P)
|
|
41
|
+
Acc[L] = Literal(L);
|
|
42
|
+
return Acc;
|
|
43
43
|
}
|
|
44
44
|
// prettier-ignore
|
|
45
45
|
function MappedKeyToMappedResultProperties(K, P) {
|
|
@@ -58,9 +58,10 @@ function FromRest(K, T) {
|
|
|
58
58
|
}
|
|
59
59
|
// prettier-ignore
|
|
60
60
|
function FromProperties(K, T) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const Acc = {};
|
|
62
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(T))
|
|
63
|
+
Acc[K2] = FromSchemaType(K, T[K2]);
|
|
64
|
+
return Acc;
|
|
64
65
|
}
|
|
65
66
|
// prettier-ignore
|
|
66
67
|
function FromSchemaType(K, T) {
|
|
@@ -85,10 +86,11 @@ function FromSchemaType(K, T) {
|
|
|
85
86
|
T);
|
|
86
87
|
}
|
|
87
88
|
// prettier-ignore
|
|
88
|
-
export function MappedFunctionReturnType(K, T
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
export function MappedFunctionReturnType(K, T) {
|
|
90
|
+
const Acc = {};
|
|
91
|
+
for (const L of K)
|
|
92
|
+
Acc[L] = FromSchemaType(L, T);
|
|
93
|
+
return Acc;
|
|
92
94
|
}
|
|
93
95
|
/** `[Json]` Creates a Mapped object type */
|
|
94
96
|
export function Mapped(key, map, options = {}) {
|
|
@@ -3,14 +3,16 @@ import { Kind } from '../symbols/index.mjs';
|
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
import { IsOptional, IsSchema } from '../guard/
|
|
6
|
+
import { IsOptional, IsSchema } from '../guard/kind.mjs';
|
|
7
7
|
/** `[Json]` Creates an Object type */
|
|
8
8
|
function _Object(properties, options = {}) {
|
|
9
9
|
const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
|
|
10
10
|
const optionalKeys = propertyKeys.filter((key) => IsOptional(properties[key]));
|
|
11
11
|
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
12
12
|
const clonedAdditionalProperties = IsSchema(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
|
|
13
|
-
const clonedProperties =
|
|
13
|
+
const clonedProperties = {};
|
|
14
|
+
for (const key of propertyKeys)
|
|
15
|
+
clonedProperties[key] = CloneType(properties[key]);
|
|
14
16
|
return (requiredKeys.length > 0
|
|
15
17
|
? { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
|
|
16
18
|
: { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Omit } from './omit.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(P, K, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
+
Acc[K2] = Omit(P[K2], K, options);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, K, options) {
|
|
@@ -10,7 +10,7 @@ import { OmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// TypeGuard
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/
|
|
13
|
+
import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, IsMappedResult } from '../guard/kind.mjs';
|
|
14
14
|
// prettier-ignore
|
|
15
15
|
function FromIntersect(T, K) {
|
|
16
16
|
return T.map((T) => OmitResolve(T, K));
|
|
@@ -29,9 +29,7 @@ function FromProperty(T, K) {
|
|
|
29
29
|
}
|
|
30
30
|
// prettier-ignore
|
|
31
31
|
function FromProperties(T, K) {
|
|
32
|
-
return K.reduce((T, K2) =>
|
|
33
|
-
return FromProperty(T, K2);
|
|
34
|
-
}, T);
|
|
32
|
+
return K.reduce((T, K2) => FromProperty(T, K2), T);
|
|
35
33
|
}
|
|
36
34
|
// ------------------------------------------------------------------
|
|
37
35
|
// OmitResolve
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Optional } from './optional.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(P, F) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
+
Acc[K2] = Optional(P[K2], F);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, F) {
|
|
@@ -2,7 +2,7 @@ import { OptionalKind } from '../symbols/index.mjs';
|
|
|
2
2
|
import { CloneType } from '../clone/type.mjs';
|
|
3
3
|
import { Discard } from '../discard/index.mjs';
|
|
4
4
|
import { OptionalFromMappedResult } from './optional-from-mapped-result.mjs';
|
|
5
|
-
import { IsMappedResult } from '../guard/
|
|
5
|
+
import { IsMappedResult } from '../guard/kind.mjs';
|
|
6
6
|
function RemoveOptional(schema) {
|
|
7
7
|
return Discard(CloneType(schema), [OptionalKind]);
|
|
8
8
|
}
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Partial } from './partial.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(K, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
7
|
+
Acc[K2] = Partial(K[K2], options);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, options) {
|
|
@@ -9,16 +9,17 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// TypeGuard
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
|
-
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/
|
|
12
|
+
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
function FromRest(T) {
|
|
15
15
|
return T.map(L => PartialResolve(L));
|
|
16
16
|
}
|
|
17
17
|
// prettier-ignore
|
|
18
18
|
function FromProperties(T) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const Acc = {};
|
|
20
|
+
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
21
|
+
Acc[K] = Optional(T[K]);
|
|
22
|
+
return Acc;
|
|
22
23
|
}
|
|
23
24
|
// ------------------------------------------------------------------
|
|
24
25
|
// PartialResolve
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Pick } from './pick.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(P, K, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
+
Acc[K2] = Pick(P[K2], K, options);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, K, options) {
|
|
@@ -13,7 +13,7 @@ declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T:
|
|
|
13
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, TPick<L, K>]> : Acc;
|
|
14
14
|
declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
|
|
15
15
|
type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
|
|
16
|
-
declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K):
|
|
16
|
+
declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): never;
|
|
17
17
|
export type TPick<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TPick<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
|
|
18
18
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
19
19
|
export declare function Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TPickFromMappedResult<T, K>;
|
|
@@ -10,7 +10,7 @@ import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
// TypeGuard
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
|
-
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/
|
|
13
|
+
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/kind.mjs';
|
|
14
14
|
function FromIntersect(T, K) {
|
|
15
15
|
return T.map((T) => PickResolve(T, K));
|
|
16
16
|
}
|
|
@@ -20,9 +20,11 @@ function FromUnion(T, K) {
|
|
|
20
20
|
}
|
|
21
21
|
// prettier-ignore
|
|
22
22
|
function FromProperties(T, K) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const Acc = {};
|
|
24
|
+
for (const K2 of K)
|
|
25
|
+
if (K2 in T)
|
|
26
|
+
Acc[K2] = T[K2];
|
|
27
|
+
return Acc;
|
|
26
28
|
}
|
|
27
29
|
// ------------------------------------------------------------------
|
|
28
30
|
// PickResolve
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Readonly } from './readonly.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(K, F) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
7
|
+
Acc[K2] = Readonly(K[K2], F);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, F) {
|
|
@@ -2,7 +2,7 @@ import { ReadonlyKind } from '../symbols/index.mjs';
|
|
|
2
2
|
import { CloneType } from '../clone/type.mjs';
|
|
3
3
|
import { Discard } from '../discard/index.mjs';
|
|
4
4
|
import { ReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
|
|
5
|
-
import { IsMappedResult } from '../guard/
|
|
5
|
+
import { IsMappedResult } from '../guard/kind.mjs';
|
|
6
6
|
function RemoveReadonly(schema) {
|
|
7
7
|
return Discard(CloneType(schema), [ReadonlyKind]);
|
|
8
8
|
}
|
|
@@ -13,7 +13,7 @@ import { IsUndefined } from '../guard/value.mjs';
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// TypeGuard
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/
|
|
16
|
+
import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
// RecordCreateFromPattern
|
|
19
19
|
// ------------------------------------------------------------------
|
|
@@ -31,8 +31,10 @@ function RecordCreateFromPattern(pattern, T, options) {
|
|
|
31
31
|
// ------------------------------------------------------------------
|
|
32
32
|
// prettier-ignore
|
|
33
33
|
function RecordCreateFromKeys(K, T, options) {
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const Acc = {};
|
|
35
|
+
for (const K2 of K)
|
|
36
|
+
Acc[K2] = CloneType(T);
|
|
37
|
+
return Object(Acc, { ...options, [Hint]: 'Record' });
|
|
36
38
|
}
|
|
37
39
|
// prettier-ignore
|
|
38
40
|
function FromTemplateLiteralKey(K, T, options) {
|
|
@@ -2,9 +2,10 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Required } from './required.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
4
|
function FromProperties(P, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const Acc = {};
|
|
6
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
+
Acc[K2] = Required(P[K2], options);
|
|
8
|
+
return Acc;
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
10
11
|
function FromMappedResult(R, options) {
|
|
@@ -8,16 +8,17 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// TypeGuard
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
|
-
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/
|
|
11
|
+
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function FromRest(T) {
|
|
14
14
|
return T.map(L => RequiredResolve(L));
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function FromProperties(T) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const Acc = {};
|
|
19
|
+
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
20
|
+
Acc[K] = Discard(T[K], [OptionalKind]);
|
|
21
|
+
return Acc;
|
|
21
22
|
}
|
|
22
23
|
// ------------------------------------------------------------------
|
|
23
24
|
// RequiredResolve
|
|
@@ -2,12 +2,12 @@ import { CloneRest } from '../clone/type.mjs';
|
|
|
2
2
|
// ------------------------------------------------------------------
|
|
3
3
|
// TypeGuard
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
import { IsIntersect, IsUnion, IsTuple } from '../guard/
|
|
5
|
+
import { IsIntersect, IsUnion, IsTuple } from '../guard/kind.mjs';
|
|
6
6
|
// prettier-ignore
|
|
7
7
|
function RestResolve(T) {
|
|
8
|
-
return (IsIntersect(T) ?
|
|
9
|
-
IsUnion(T) ?
|
|
10
|
-
IsTuple(T) ?
|
|
8
|
+
return (IsIntersect(T) ? CloneRest(T.allOf) :
|
|
9
|
+
IsUnion(T) ? CloneRest(T.anyOf) :
|
|
10
|
+
IsTuple(T) ? CloneRest(T.items ?? []) :
|
|
11
11
|
[]);
|
|
12
12
|
}
|
|
13
13
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
@@ -4,8 +4,7 @@ import { TypeBoxError } from '../error/index.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, IsLiteral, IsBoolean } from '../guard/type.mjs';
|
|
7
|
+
import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, IsLiteral, IsBoolean } from '../guard/kind.mjs';
|
|
9
8
|
// ------------------------------------------------------------------
|
|
10
9
|
// TemplateLiteralPatternError
|
|
11
10
|
// ------------------------------------------------------------------
|
|
@@ -3,7 +3,7 @@ import { CloneType } from '../clone/type.mjs';
|
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
import { IsTransform } from '../guard/
|
|
6
|
+
import { IsTransform } from '../guard/kind.mjs';
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TransformBuilders
|
|
9
9
|
// ------------------------------------------------------------------
|
|
@@ -7,7 +7,7 @@ import { UnionCreate } from './union-create.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
import { IsOptional } from '../guard/
|
|
10
|
+
import { IsOptional } from '../guard/kind.mjs';
|
|
11
11
|
// prettier-ignore
|
|
12
12
|
function IsUnionOptional(T) {
|
|
13
13
|
return T.some(L => IsOptional(L));
|
|
@@ -64,7 +64,7 @@ function FromRecord(schema, references, value) {
|
|
|
64
64
|
if (!IsObject(value))
|
|
65
65
|
return value;
|
|
66
66
|
const additionalProperties = schema.additionalProperties;
|
|
67
|
-
const propertyKeys = Object.
|
|
67
|
+
const propertyKeys = Object.getOwnPropertyNames(value);
|
|
68
68
|
const [propertyKey, propertySchema] = Object.entries(schema.patternProperties)[0];
|
|
69
69
|
const propertyKeyTest = new RegExp(propertyKey);
|
|
70
70
|
for (const key of propertyKeys) {
|
|
@@ -6,8 +6,14 @@ import { IsArray, IsDate, IsStandardObject, IsTypedArray, IsValueType } from '..
|
|
|
6
6
|
// Clonable
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
function ObjectType(value) {
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const Acc = {};
|
|
10
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
11
|
+
Acc[key] = Clone(value[key]);
|
|
12
|
+
}
|
|
13
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
14
|
+
Acc[key] = Clone(value[key]);
|
|
15
|
+
}
|
|
16
|
+
return Acc;
|
|
11
17
|
}
|
|
12
18
|
function ArrayType(value) {
|
|
13
19
|
return value.map((element) => Clone(element));
|
|
@@ -207,10 +207,13 @@ function FromObject(schema, references) {
|
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
209
|
const required = new Set(schema.required);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
const Acc = {};
|
|
211
|
+
for (const [key, subschema] of Object.entries(schema.properties)) {
|
|
212
|
+
if (!required.has(key))
|
|
213
|
+
continue;
|
|
214
|
+
Acc[key] = Visit(subschema, references);
|
|
215
|
+
}
|
|
216
|
+
return Acc;
|
|
214
217
|
}
|
|
215
218
|
}
|
|
216
219
|
function FromPromise(schema, references) {
|
|
@@ -228,9 +231,10 @@ function FromRecord(schema, references) {
|
|
|
228
231
|
}
|
|
229
232
|
else if (!(keyPattern === PatternStringExact || keyPattern === PatternNumberExact)) {
|
|
230
233
|
const propertyKeys = keyPattern.slice(1, keyPattern.length - 1).split('|');
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
const Acc = {};
|
|
235
|
+
for (const key of propertyKeys)
|
|
236
|
+
Acc[key] = Visit(valueSchema, references);
|
|
237
|
+
return Acc;
|
|
234
238
|
}
|
|
235
239
|
else {
|
|
236
240
|
return {};
|
|
@@ -81,7 +81,7 @@ function NumberType(value) {
|
|
|
81
81
|
}
|
|
82
82
|
function ObjectType(value) {
|
|
83
83
|
FNV1A64(ByteMarker.Object);
|
|
84
|
-
for (const key of globalThis.Object.
|
|
84
|
+
for (const key of globalThis.Object.getOwnPropertyNames(value).sort()) {
|
|
85
85
|
Visit(key);
|
|
86
86
|
Visit(value[key]);
|
|
87
87
|
}
|
|
@@ -15,8 +15,8 @@ function ObjectType(root, path, current, next) {
|
|
|
15
15
|
ValuePointer.Set(root, path, Clone(next));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
const currentKeys = Object.
|
|
19
|
-
const nextKeys = Object.
|
|
18
|
+
const currentKeys = Object.getOwnPropertyNames(current);
|
|
19
|
+
const nextKeys = Object.getOwnPropertyNames(next);
|
|
20
20
|
for (const currentKey of currentKeys) {
|
|
21
21
|
if (!nextKeys.includes(currentKey)) {
|
|
22
22
|
delete current[currentKey];
|