@sinclair/typebox 0.32.5 → 0.32.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/import/index.d.mts +7 -7
- package/build/import/index.mjs +4 -4
- package/build/import/type/awaited/awaited.d.mts +3 -4
- package/build/import/type/awaited/awaited.mjs +7 -4
- package/build/import/type/composite/composite.d.mts +2 -3
- package/build/import/type/composite/composite.mjs +3 -7
- package/build/import/type/deref/deref.d.mts +3 -5
- package/build/import/type/deref/deref.mjs +4 -1
- package/build/import/type/exclude/exclude.d.mts +5 -8
- package/build/import/type/exclude/exclude.mjs +10 -18
- package/build/import/type/extract/extract.d.mts +7 -9
- package/build/import/type/extract/extract.mjs +10 -18
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed.d.mts +6 -4
- package/build/import/type/indexed/indexed.mjs +5 -5
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -2
- package/build/import/type/keyof/keyof.d.mts +3 -3
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.d.mts +3 -3
- package/build/import/type/mapped/mapped.mjs +2 -2
- package/build/import/type/omit/omit-from-mapped-result.d.mts +3 -2
- package/build/import/type/omit/omit.d.mts +3 -5
- package/build/import/type/omit/omit.mjs +4 -1
- package/build/import/type/partial/partial-from-mapped-result.d.mts +3 -2
- package/build/import/type/pick/pick-from-mapped-result.d.mts +3 -2
- package/build/import/type/pick/pick.d.mts +3 -5
- package/build/import/type/pick/pick.mjs +4 -1
- package/build/import/type/required/required-from-mapped-result.d.mts +3 -2
- package/build/import/type/static/static.d.mts +5 -5
- package/build/require/index.d.ts +7 -7
- package/build/require/index.js +12 -6
- package/build/require/type/awaited/awaited.d.ts +3 -4
- package/build/require/type/awaited/awaited.js +7 -4
- package/build/require/type/composite/composite.d.ts +2 -3
- package/build/require/type/composite/composite.js +3 -7
- package/build/require/type/deref/deref.d.ts +3 -5
- package/build/require/type/deref/deref.js +4 -2
- package/build/require/type/exclude/exclude.d.ts +5 -8
- package/build/require/type/exclude/exclude.js +10 -18
- package/build/require/type/extract/extract.d.ts +7 -9
- package/build/require/type/extract/extract.js +10 -18
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed.d.ts +6 -4
- package/build/require/type/indexed/indexed.js +8 -6
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -2
- package/build/require/type/keyof/keyof.d.ts +3 -3
- package/build/require/type/keyof/keyof.js +4 -3
- package/build/require/type/mapped/mapped.d.ts +3 -3
- package/build/require/type/mapped/mapped.js +4 -3
- package/build/require/type/omit/omit-from-mapped-result.d.ts +3 -2
- package/build/require/type/omit/omit.d.ts +3 -5
- package/build/require/type/omit/omit.js +4 -2
- package/build/require/type/partial/partial-from-mapped-result.d.ts +3 -2
- package/build/require/type/pick/pick-from-mapped-result.d.ts +3 -2
- package/build/require/type/pick/pick.d.ts +3 -5
- package/build/require/type/pick/pick.js +4 -2
- package/build/require/type/required/required-from-mapped-result.d.ts +3 -2
- package/build/require/type/static/static.d.ts +5 -5
- package/package.json +1 -1
- package/readme.md +11 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.KeyOf = void 0;
|
|
4
|
+
exports.KeyOf = exports.KeyOfPropertyKeysToRest = void 0;
|
|
5
5
|
const index_1 = require("../literal/index");
|
|
6
6
|
const index_2 = require("../number/index");
|
|
7
7
|
const keyof_property_keys_1 = require("./keyof-property-keys");
|
|
@@ -13,9 +13,10 @@ const keyof_from_mapped_result_1 = require("./keyof-from-mapped-result");
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const type_2 = require("../guard/type");
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function
|
|
16
|
+
function KeyOfPropertyKeysToRest(T) {
|
|
17
17
|
return T.map(L => L === '[number]' ? (0, index_2.Number)() : (0, index_1.Literal)(L));
|
|
18
18
|
}
|
|
19
|
+
exports.KeyOfPropertyKeysToRest = KeyOfPropertyKeysToRest;
|
|
19
20
|
/** `[Json]` Creates a KeyOf type */
|
|
20
21
|
function KeyOf(T, options = {}) {
|
|
21
22
|
if ((0, type_2.IsMappedResult)(T)) {
|
|
@@ -23,7 +24,7 @@ function KeyOf(T, options = {}) {
|
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
26
|
const K = (0, keyof_property_keys_1.KeyOfPropertyKeys)(T);
|
|
26
|
-
const S =
|
|
27
|
+
const S = KeyOfPropertyKeysToRest(K);
|
|
27
28
|
const U = (0, index_3.UnionEvaluated)(S);
|
|
28
29
|
return (0, type_1.CloneType)(U, options);
|
|
29
30
|
}
|
|
@@ -33,12 +33,12 @@ type FromProperties<K extends PropertyKey, T extends TProperties, R extends TPro
|
|
|
33
33
|
declare function FromProperties<K extends PropertyKey, T extends TProperties>(K: K, T: T): FromProperties<K, T>;
|
|
34
34
|
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);
|
|
35
35
|
declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K, T: T): FromSchemaType<K, T>;
|
|
36
|
-
type
|
|
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
|
-
declare function
|
|
39
|
+
export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T, Acc?: TProperties): TMappedFunctionReturnType<K, T>;
|
|
40
40
|
export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
|
|
41
|
-
export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<
|
|
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 */
|
|
43
43
|
export declare function Mapped<K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>, F extends TMappedFunction<I> = TMappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
44
44
|
/** `[Json]` Creates a Mapped object type */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Mapped = void 0;
|
|
4
|
+
exports.Mapped = exports.MappedFunctionReturnType = void 0;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
6
|
const type_1 = require("../clone/type");
|
|
7
7
|
const index_2 = require("../discard/index");
|
|
@@ -89,16 +89,17 @@ function FromSchemaType(K, T) {
|
|
|
89
89
|
T);
|
|
90
90
|
}
|
|
91
91
|
// prettier-ignore
|
|
92
|
-
function
|
|
92
|
+
function MappedFunctionReturnType(K, T, Acc = {}) {
|
|
93
93
|
return K.reduce((Acc, L) => {
|
|
94
94
|
return { ...Acc, [L]: FromSchemaType(L, T) };
|
|
95
95
|
}, {});
|
|
96
96
|
}
|
|
97
|
+
exports.MappedFunctionReturnType = MappedFunctionReturnType;
|
|
97
98
|
/** `[Json]` Creates a Mapped object type */
|
|
98
99
|
function Mapped(key, map, options = {}) {
|
|
99
100
|
const K = (0, type_2.IsSchema)(key) ? (0, index_7.IndexPropertyKeys)(key) : key;
|
|
100
101
|
const RT = map({ [index_1.Kind]: 'MappedKey', keys: K });
|
|
101
|
-
const R =
|
|
102
|
+
const R = MappedFunctionReturnType(K, RT);
|
|
102
103
|
return (0, type_1.CloneType)((0, index_11.Object)(R), options);
|
|
103
104
|
}
|
|
104
105
|
exports.Mapped = Mapped;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index';
|
|
2
3
|
import type { TProperties } from '../object/index';
|
|
3
4
|
import { type TMappedResult } from '../mapped/index';
|
|
4
5
|
import { type TOmit } from './omit';
|
|
5
6
|
type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
6
7
|
[K2 in keyof P]: TOmit<P[K2], K>;
|
|
7
8
|
});
|
|
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
|
|
9
|
+
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (Evaluate<TFromProperties<R['properties'], K>>);
|
|
10
|
+
export type TOmitFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (Ensure<TMappedResult<P>>);
|
|
10
11
|
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
12
|
export {};
|
|
@@ -8,12 +8,10 @@ import { type TObject, type TProperties } from '../object/index';
|
|
|
8
8
|
import { type TIndexPropertyKeys } from '../indexed/index';
|
|
9
9
|
import { type TOmitFromMappedKey } from './omit-from-mapped-key';
|
|
10
10
|
import { type TOmitFromMappedResult } from './omit-from-mapped-result';
|
|
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,
|
|
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,
|
|
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, TOmit<L, K>]> : Acc);
|
|
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, TOmit<L, K>]> : Acc);
|
|
13
13
|
type TFromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Omit<T, I>>;
|
|
14
|
-
export type
|
|
15
|
-
export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TOmitResolve<T, K>;
|
|
16
|
-
export type TOmit<T extends TSchema, K extends PropertyKey[]> = TOmitResolve<T, K>;
|
|
14
|
+
export type TOmit<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TOmit<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<{}>;
|
|
17
15
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
18
16
|
export declare function Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
|
|
19
17
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Omit =
|
|
4
|
+
exports.Omit = void 0;
|
|
5
5
|
const index_1 = require("../intersect/index");
|
|
6
6
|
const index_2 = require("../union/index");
|
|
7
7
|
const index_3 = require("../object/index");
|
|
@@ -37,6 +37,9 @@ function FromProperties(T, K) {
|
|
|
37
37
|
return FromProperty(T, K2);
|
|
38
38
|
}, T);
|
|
39
39
|
}
|
|
40
|
+
// ------------------------------------------------------------------
|
|
41
|
+
// OmitResolve
|
|
42
|
+
// ------------------------------------------------------------------
|
|
40
43
|
// prettier-ignore
|
|
41
44
|
function OmitResolve(T, K) {
|
|
42
45
|
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
@@ -44,7 +47,6 @@ function OmitResolve(T, K) {
|
|
|
44
47
|
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
45
48
|
(0, index_3.Object)({}));
|
|
46
49
|
}
|
|
47
|
-
exports.OmitResolve = OmitResolve;
|
|
48
50
|
function Omit(T, K, options = {}) {
|
|
49
51
|
// mapped
|
|
50
52
|
if ((0, type_2.IsMappedKey)(K))
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index';
|
|
2
3
|
import type { TProperties } from '../object/index';
|
|
3
4
|
import { type TMappedResult } from '../mapped/index';
|
|
4
5
|
import { type TPartial } from './partial';
|
|
5
6
|
type TFromProperties<P extends TProperties> = ({
|
|
6
7
|
[K2 in keyof P]: TPartial<P[K2]>;
|
|
7
8
|
});
|
|
8
|
-
type TFromMappedResult<R extends TMappedResult> = (TFromProperties<R['properties']
|
|
9
|
-
export type TPartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (TMappedResult<P
|
|
9
|
+
type TFromMappedResult<R extends TMappedResult> = (Evaluate<TFromProperties<R['properties']>>);
|
|
10
|
+
export type TPartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
|
|
10
11
|
export declare function PartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
|
|
11
12
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index';
|
|
2
3
|
import type { TProperties } from '../object/index';
|
|
3
4
|
import { type TMappedResult } from '../mapped/index';
|
|
4
5
|
import { type TPick } from './pick';
|
|
5
6
|
type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
6
7
|
[K2 in keyof P]: TPick<P[K2], K>;
|
|
7
8
|
});
|
|
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
|
|
9
|
+
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (Evaluate<TFromProperties<R['properties'], K>>);
|
|
10
|
+
export type TPickFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (Ensure<TMappedResult<P>>);
|
|
10
11
|
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
12
|
export {};
|
|
@@ -8,15 +8,13 @@ import type { TMappedKey, TMappedResult } from '../mapped/index';
|
|
|
8
8
|
import { type TIndexPropertyKeys } from '../indexed/index';
|
|
9
9
|
import { type TPickFromMappedKey } from './pick-from-mapped-key';
|
|
10
10
|
import { type TPickFromMappedResult } from './pick-from-mapped-result';
|
|
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,
|
|
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, TPick<L, K>]> : Acc;
|
|
12
12
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K, []>;
|
|
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,
|
|
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
16
|
declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
|
|
17
|
-
export type
|
|
18
|
-
export declare function PickResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): PickResolve<T, K>;
|
|
19
|
-
export type TPick<T extends TSchema, K extends PropertyKey[]> = PickResolve<T, K>;
|
|
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<{}>;
|
|
20
18
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
21
19
|
export declare function Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TPickFromMappedResult<T, K>;
|
|
22
20
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Pick =
|
|
4
|
+
exports.Pick = void 0;
|
|
5
5
|
const index_1 = require("../intersect/index");
|
|
6
6
|
const index_2 = require("../union/index");
|
|
7
7
|
const index_3 = require("../object/index");
|
|
@@ -28,6 +28,9 @@ function FromProperties(T, K) {
|
|
|
28
28
|
return K in T ? { ...Acc, [K]: T[K] } : Acc;
|
|
29
29
|
}, {});
|
|
30
30
|
}
|
|
31
|
+
// ------------------------------------------------------------------
|
|
32
|
+
// PickResolve
|
|
33
|
+
// ------------------------------------------------------------------
|
|
31
34
|
// prettier-ignore
|
|
32
35
|
function PickResolve(T, K) {
|
|
33
36
|
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
@@ -35,7 +38,6 @@ function PickResolve(T, K) {
|
|
|
35
38
|
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
36
39
|
(0, index_3.Object)({}));
|
|
37
40
|
}
|
|
38
|
-
exports.PickResolve = PickResolve;
|
|
39
41
|
function Pick(T, K, options = {}) {
|
|
40
42
|
// mapped
|
|
41
43
|
if ((0, type_2.IsMappedKey)(K))
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index';
|
|
2
3
|
import type { TProperties } from '../object/index';
|
|
3
4
|
import { type TMappedResult } from '../mapped/index';
|
|
4
5
|
import { type TRequired } from './required';
|
|
5
6
|
type TFromProperties<P extends TProperties> = ({
|
|
6
7
|
[K2 in keyof P]: TRequired<P[K2]>;
|
|
7
8
|
});
|
|
8
|
-
type TFromMappedResult<R extends TMappedResult> = (TFromProperties<R['properties']
|
|
9
|
-
export type TRequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (TMappedResult<P
|
|
9
|
+
type TFromMappedResult<R extends TMappedResult> = (Evaluate<TFromProperties<R['properties']>>);
|
|
10
|
+
export type TRequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
|
|
10
11
|
export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
|
|
11
12
|
export {};
|
|
@@ -19,13 +19,13 @@ import type { TUnion } from '../union/index';
|
|
|
19
19
|
import type { TUnsafe } from '../unsafe/index';
|
|
20
20
|
import type { TSchema } from '../schema/index';
|
|
21
21
|
import type { TTransform } from '../transform/index';
|
|
22
|
-
export type
|
|
23
|
-
[K in keyof T]:
|
|
22
|
+
export type TDecodeProperties<T extends TProperties> = {
|
|
23
|
+
[K in keyof T]: TDecodeType<T[K]>;
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
26
|
-
export type
|
|
25
|
+
export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc;
|
|
26
|
+
export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<TDecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
|
|
27
27
|
/** Creates an decoded static type from a TypeBox type */
|
|
28
|
-
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<
|
|
28
|
+
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<TDecodeType<T>, P>;
|
|
29
29
|
/** Creates an encoded static type from a TypeBox type */
|
|
30
30
|
export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
|
|
31
31
|
/** Creates a static type from a TypeBox type */
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -53,7 +53,7 @@ type T = Static<typeof T> // type T = {
|
|
|
53
53
|
|
|
54
54
|
TypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.
|
|
55
55
|
|
|
56
|
-
This library is
|
|
56
|
+
This library is designed to be a runtime type system providing similar capabilities to TypeScript's programmable type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
|
|
57
57
|
|
|
58
58
|
License MIT
|
|
59
59
|
|
|
@@ -648,7 +648,7 @@ TypeBox provides an extended type set that can be used to create schematics for
|
|
|
648
648
|
|
|
649
649
|
### Import
|
|
650
650
|
|
|
651
|
-
Import the Type namespace to bring in
|
|
651
|
+
Import the Type namespace to bring in the full TypeBox type system. This is recommended for most users.
|
|
652
652
|
|
|
653
653
|
```typescript
|
|
654
654
|
import { Type, type Static } from '@sinclair/typebox'
|
|
@@ -870,7 +870,7 @@ function test(node: Node) {
|
|
|
870
870
|
|
|
871
871
|
### Template Literal Types
|
|
872
872
|
|
|
873
|
-
TypeBox supports template literal types with TemplateLiteral. This type can be created using a syntax similar to the TypeScript template literal syntax or composed from exterior types. TypeBox encodes template literals as regular expressions which enables the template to be checked by Json Schema validators. This type also supports regular expression parsing that enables template patterns to be used for generative types. The following shows both TypeScript and TypeBox usage.
|
|
873
|
+
TypeBox supports template literal types with the TemplateLiteral function. This type can be created using a syntax similar to the TypeScript template literal syntax or composed from exterior types. TypeBox encodes template literals as regular expressions which enables the template to be checked by Json Schema validators. This type also supports regular expression parsing that enables template patterns to be used for generative types. The following shows both TypeScript and TypeBox usage.
|
|
874
874
|
|
|
875
875
|
```typescript
|
|
876
876
|
// TypeScript
|
|
@@ -905,7 +905,7 @@ const R = Type.Record(K, Type.String()) // const R: TObject<{
|
|
|
905
905
|
|
|
906
906
|
### Indexed Access Types
|
|
907
907
|
|
|
908
|
-
TypeBox supports indexed access types with Index. This
|
|
908
|
+
TypeBox supports indexed access types with the Index function. This function enables uniform access to interior property and element types without having to extract them from the underlying schema representation. Index types are supported for Object, Array, Tuple, Union and Intersect types.
|
|
909
909
|
|
|
910
910
|
```typescript
|
|
911
911
|
const T = Type.Object({ // type T = {
|
|
@@ -944,7 +944,7 @@ const C = Type.Index(T, Type.KeyOf(T)) // type C = T[keyof T]
|
|
|
944
944
|
|
|
945
945
|
### Mapped Types
|
|
946
946
|
|
|
947
|
-
TypeBox supports mapped
|
|
947
|
+
TypeBox supports mapped types with the Mapped function. This function accepts two arguments, the first is a union type typically derived from KeyOf, the second is a mapping function that receives a mapping key `K` that can be used to index properties of a type. The following implements a mapped type that remaps each property to be `T | null`
|
|
948
948
|
|
|
949
949
|
```typescript
|
|
950
950
|
const T = Type.Object({ // type T = {
|
|
@@ -953,14 +953,14 @@ const T = Type.Object({ // type T = {
|
|
|
953
953
|
z: Type.Boolean() // z: boolean
|
|
954
954
|
}) // }
|
|
955
955
|
|
|
956
|
-
const M = Type.Mapped(Type.KeyOf(T), K => { // type M = { [K in keyof T]
|
|
957
|
-
return Type.
|
|
956
|
+
const M = Type.Mapped(Type.KeyOf(T), K => { // type M = { [K in keyof T]: T[K] | null }
|
|
957
|
+
return Type.Union([Type.Index(T, K), Type.Null()]) //
|
|
958
958
|
}) // ... evaluated as
|
|
959
959
|
//
|
|
960
960
|
// const M: TObject<{
|
|
961
|
-
// x:
|
|
962
|
-
// y:
|
|
963
|
-
// z:
|
|
961
|
+
// x: TUnion<[TNumber, TNull]>,
|
|
962
|
+
// y: TUnion<[TString, TNull]>,
|
|
963
|
+
// z: TUnion<[TBoolean, TNull]>
|
|
964
964
|
// }>
|
|
965
965
|
```
|
|
966
966
|
|
|
@@ -968,7 +968,7 @@ const M = Type.Mapped(Type.KeyOf(T), K => { // type M = { [K in keyof T
|
|
|
968
968
|
|
|
969
969
|
### Conditional Types
|
|
970
970
|
|
|
971
|
-
TypeBox supports runtime conditional types with Extends. This
|
|
971
|
+
TypeBox supports runtime conditional types with the Extends function. This function performs a structural assignability check against the first (`left`) and second (`right`) arguments and will return either the third (`true`) or fourth (`false`) argument based on the result. The conditional types Exclude and Extract are also supported. The following shows both TypeScript and TypeBox examples of conditional types.
|
|
972
972
|
|
|
973
973
|
```typescript
|
|
974
974
|
// Extends
|