@sinclair/typebox 0.32.4 → 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/import/value/clean/clean.d.mts +2 -2
- package/build/import/value/convert/convert.d.mts +2 -2
- package/build/import/value/default/default.d.mts +2 -2
- package/build/import/value/value/value.d.mts +6 -6
- 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/build/require/value/clean/clean.d.ts +2 -2
- package/build/require/value/convert/convert.d.ts +2 -2
- package/build/require/value/default/default.d.ts +2 -2
- package/build/require/value/value/value.d.ts +6 -6
- package/license +1 -1
- package/package.json +1 -1
- package/readme.md +11 -11
|
@@ -8,15 +8,13 @@ import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
|
8
8
|
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
9
9
|
import { type TPickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
10
10
|
import { type TPickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
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 */
|
|
@@ -24,8 +24,11 @@ function FromProperties(T, K) {
|
|
|
24
24
|
return K in T ? { ...Acc, [K]: T[K] } : Acc;
|
|
25
25
|
}, {});
|
|
26
26
|
}
|
|
27
|
+
// ------------------------------------------------------------------
|
|
28
|
+
// PickResolve
|
|
29
|
+
// ------------------------------------------------------------------
|
|
27
30
|
// prettier-ignore
|
|
28
|
-
|
|
31
|
+
function PickResolve(T, K) {
|
|
29
32
|
return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf, K)) :
|
|
30
33
|
IsUnion(T) ? Union(FromUnion(T.anyOf, K)) :
|
|
31
34
|
IsObject(T) ? Object(FromProperties(T.properties, K)) :
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
2
3
|
import type { TProperties } from '../object/index.mjs';
|
|
3
4
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
5
|
import { type TRequired } from './required.mjs';
|
|
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.mjs';
|
|
|
19
19
|
import type { TUnsafe } from '../unsafe/index.mjs';
|
|
20
20
|
import type { TSchema } from '../schema/index.mjs';
|
|
21
21
|
import type { TTransform } from '../transform/index.mjs';
|
|
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 */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from '../../type/schema/index.mjs';
|
|
2
2
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
3
|
-
export declare function Clean
|
|
3
|
+
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
4
4
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
5
|
-
export declare function Clean
|
|
5
|
+
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from '../../type/schema/index.mjs';
|
|
2
2
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
3
|
-
export declare function Convert
|
|
3
|
+
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
4
4
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
5
|
-
export declare function Convert
|
|
5
|
+
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from '../../type/schema/index.mjs';
|
|
2
2
|
/** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
|
|
3
|
-
export declare function Default
|
|
3
|
+
export declare function Default(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
4
4
|
/** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
|
|
5
|
-
export declare function Default
|
|
5
|
+
export declare function Default(schema: TSchema, value: unknown): unknown;
|
|
@@ -16,13 +16,13 @@ export declare function Check<T extends TSchema>(schema: T, references: TSchema[
|
|
|
16
16
|
/** Returns true if the value matches the given type */
|
|
17
17
|
export declare function Check<T extends TSchema>(schema: T, value: unknown): value is Static<T>;
|
|
18
18
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
19
|
-
export declare function Clean
|
|
19
|
+
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
20
20
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
21
|
-
export declare function Clean
|
|
21
|
+
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
22
22
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
23
|
-
export declare function Convert
|
|
23
|
+
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
24
24
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possibl. */
|
|
25
|
-
export declare function Convert
|
|
25
|
+
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
26
26
|
/** Returns a structural clone of the given value */
|
|
27
27
|
export declare function Clone<T>(value: T): T;
|
|
28
28
|
/** Decodes a value or throws if error */
|
|
@@ -30,9 +30,9 @@ export declare function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T
|
|
|
30
30
|
/** Decodes a value or throws if error */
|
|
31
31
|
export declare function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R;
|
|
32
32
|
/** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
|
|
33
|
-
export declare function Default
|
|
33
|
+
export declare function Default(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
34
34
|
/** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
|
|
35
|
-
export declare function Default
|
|
35
|
+
export declare function Default(schema: TSchema, value: unknown): unknown;
|
|
36
36
|
/** Encodes a value or throws if error */
|
|
37
37
|
export declare function Encode<T extends TSchema, R = StaticEncode<T>>(schema: T, references: TSchema[], value: unknown): R;
|
|
38
38
|
/** Encodes a value or throws if error */
|
package/build/require/index.d.ts
CHANGED
|
@@ -18,19 +18,19 @@ export { Date, type TDate, type DateOptions } from './type/date/index';
|
|
|
18
18
|
export { Deref, type TDeref } from './type/deref/index';
|
|
19
19
|
export { Enum, type TEnum } from './type/enum/index';
|
|
20
20
|
export { Exclude, type TExclude, type TExcludeFromMappedResult } from './type/exclude/index';
|
|
21
|
-
export { Extends, type TExtends, type ExtendsFromMappedResult, type ExtendsFromMappedKey
|
|
21
|
+
export { Extends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCheck, type TExtends, type ExtendsFromMappedResult, type ExtendsFromMappedKey } from './type/extends/index';
|
|
22
22
|
export { Extract, type TExtract, type TExtractFromMappedResult } from './type/extract/index';
|
|
23
23
|
export { Function, type TFunction } from './type/function/index';
|
|
24
24
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index';
|
|
25
|
-
export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from './type/indexed/index';
|
|
25
|
+
export { Index, IndexPropertyKeys, IndexFromPropertyKeys, IndexFromPropertyKey, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromPropertyKeys, type TIndexFromPropertyKey, type TIndexFromMappedKey, type TIndexFromMappedResult, } from './type/indexed/index';
|
|
26
26
|
export { InstanceType, type TInstanceType } from './type/instance-type/index';
|
|
27
27
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index';
|
|
28
28
|
export { Intersect, IntersectEvaluated, type TIntersect, type TIntersectEvaluated, type IntersectOptions } from './type/intersect/index';
|
|
29
29
|
export { Iterator, type TIterator } from './type/iterator/index';
|
|
30
30
|
export { Intrinsic, IntrinsicFromMappedKey, type TIntrinsic, Capitalize, type TCapitalize, Lowercase, type TLowercase, Uncapitalize, type TUncapitalize, Uppercase, type TUppercase } from './type/intrinsic/index';
|
|
31
|
-
export { KeyOf, type TKeyOf, type
|
|
31
|
+
export { KeyOf, KeyOfPropertyKeys, KeyOfPropertyKeysToRest, KeyOfFromMappedResult, KeyOfPattern, type TKeyOf, type TKeyOfPropertyKeys, type TKeyOfPropertyKeysToRest, type TKeyOfFromMappedResult } from './type/keyof/index';
|
|
32
32
|
export { Literal, type TLiteral, type TLiteralValue } from './type/literal/index';
|
|
33
|
-
export { Mapped, MappedKey, MappedResult, type TMapped, type TMappedKey, type TMappedResult, type TMappedFunction } from './type/mapped/index';
|
|
33
|
+
export { Mapped, MappedKey, MappedResult, MappedFunctionReturnType, type TMapped, type TMappedKey, type TMappedResult, type TMappedFunction, type TMappedFunctionReturnType } from './type/mapped/index';
|
|
34
34
|
export { Never, type TNever } from './type/never/index';
|
|
35
35
|
export { Not, type TNot } from './type/not/index';
|
|
36
36
|
export { Null, type TNull } from './type/null/index';
|
|
@@ -44,7 +44,7 @@ export { Pick, type TPick, type TPickFromMappedKey, type TPickFromMappedResult }
|
|
|
44
44
|
export { Promise, type TPromise } from './type/promise/index';
|
|
45
45
|
export { Readonly, ReadonlyFromMappedResult, type TReadonly, type TReadonlyWithFlag, type TReadonlyFromMappedResult } from './type/readonly/index';
|
|
46
46
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index';
|
|
47
|
-
export { Record, type TRecord } from './type/record/index';
|
|
47
|
+
export { Record, type TRecord, type TRecordOrObject } from './type/record/index';
|
|
48
48
|
export { Recursive, type TRecursive, type TThis } from './type/recursive/index';
|
|
49
49
|
export { Ref, type TRef } from './type/ref/index';
|
|
50
50
|
export { RegExp, type TRegExp } from './type/regexp/index';
|
|
@@ -52,11 +52,11 @@ export { Required, type TRequired, type TRequiredFromMappedResult } from './type
|
|
|
52
52
|
export { Rest, type TRest } from './type/rest/index';
|
|
53
53
|
export { ReturnType, type TReturnType } from './type/return-type/index';
|
|
54
54
|
export { type TSchema, type TKind, type SchemaOptions, type TAnySchema } from './type/schema/index';
|
|
55
|
-
export { type Static, type StaticDecode, type StaticEncode } from './type/static/index';
|
|
55
|
+
export { type Static, type StaticDecode, type StaticEncode, type TDecodeType, type TDecodeRest, type TDecodeProperties } from './type/static/index';
|
|
56
56
|
export { Strict } from './type/strict/index';
|
|
57
57
|
export { String, type TString, type StringOptions, type StringFormatOption, type StringContentEncodingOption } from './type/string/index';
|
|
58
58
|
export { Symbol, type TSymbol, type TSymbolValue as SymbolValue } from './type/symbol/index';
|
|
59
|
-
export { TemplateLiteral,
|
|
59
|
+
export { TemplateLiteral, TemplateLiteralSyntax, TemplateLiteralGenerate, TemplateLiteralParse, TemplateLiteralParseExact, IsTemplateLiteralFinite, TemplateLiteralExpressionGenerate, IsTemplateLiteralExpressionFinite, type TTemplateLiteral, type TTemplateLiteralSyntax, type TTemplateLiteralGenerate, type TTemplateLiteralKind, type TIsTemplateLiteralFinite, } from './type/template-literal/index';
|
|
60
60
|
export { Transform, TransformDecodeBuilder, TransformEncodeBuilder, type TTransform, type TransformOptions, type TransformFunction } from './type/transform/index';
|
|
61
61
|
export { Tuple, type TTuple } from './type/tuple/index';
|
|
62
62
|
export { Uint8Array, type TUint8Array, type Uint8ArrayOptions } from './type/uint8array/index';
|
package/build/require/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.UnionEvaluated = exports.Union = void 0;
|
|
4
|
+
exports.Iterator = exports.IntersectEvaluated = exports.Intersect = exports.Integer = exports.InstanceType = exports.IndexFromMappedResult = exports.IndexFromMappedKey = exports.IndexFromPropertyKey = exports.IndexFromPropertyKeys = exports.IndexPropertyKeys = exports.Index = exports.Increment = exports.Function = exports.Extract = exports.ExtendsUndefinedCheck = exports.ExtendsResult = exports.ExtendsCheck = exports.Extends = exports.Exclude = exports.Enum = exports.Deref = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = exports.TypeBoxError = exports.CloneRest = exports.CloneType = exports.ValueGuard = exports.TypeGuard = exports.FormatRegistry = exports.TypeRegistry = exports.PatternStringExact = exports.PatternString = exports.PatternNumberExact = exports.PatternNumber = exports.PatternBooleanExact = exports.PatternBoolean = exports.TransformKind = exports.OptionalKind = exports.ReadonlyKind = exports.Hint = exports.Kind = void 0;
|
|
5
|
+
exports.IsTemplateLiteralExpressionFinite = exports.TemplateLiteralExpressionGenerate = exports.IsTemplateLiteralFinite = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.TemplateLiteralGenerate = exports.TemplateLiteralSyntax = exports.TemplateLiteral = exports.Symbol = exports.String = exports.Strict = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.ReadonlyFromMappedResult = exports.Readonly = exports.Promise = exports.Pick = exports.PartialFromMappedResult = exports.Partial = exports.Parameters = exports.OptionalFromMappedResult = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.MappedFunctionReturnType = exports.MappedResult = exports.MappedKey = exports.Mapped = exports.Literal = exports.KeyOfPattern = exports.KeyOfFromMappedResult = exports.KeyOfPropertyKeysToRest = exports.KeyOfPropertyKeys = exports.KeyOf = exports.Uppercase = exports.Uncapitalize = exports.Lowercase = exports.Capitalize = exports.IntrinsicFromMappedKey = exports.Intrinsic = void 0;
|
|
6
|
+
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.UnionEvaluated = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = void 0;
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// Infrastructure
|
|
9
9
|
// ------------------------------------------------------------------
|
|
@@ -76,6 +76,8 @@ Object.defineProperty(exports, "Increment", { enumerable: true, get: function ()
|
|
|
76
76
|
var index_24 = require("./type/indexed/index");
|
|
77
77
|
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_24.Index; } });
|
|
78
78
|
Object.defineProperty(exports, "IndexPropertyKeys", { enumerable: true, get: function () { return index_24.IndexPropertyKeys; } });
|
|
79
|
+
Object.defineProperty(exports, "IndexFromPropertyKeys", { enumerable: true, get: function () { return index_24.IndexFromPropertyKeys; } });
|
|
80
|
+
Object.defineProperty(exports, "IndexFromPropertyKey", { enumerable: true, get: function () { return index_24.IndexFromPropertyKey; } });
|
|
79
81
|
Object.defineProperty(exports, "IndexFromMappedKey", { enumerable: true, get: function () { return index_24.IndexFromMappedKey; } });
|
|
80
82
|
Object.defineProperty(exports, "IndexFromMappedResult", { enumerable: true, get: function () { return index_24.IndexFromMappedResult; } });
|
|
81
83
|
var index_25 = require("./type/instance-type/index");
|
|
@@ -97,6 +99,8 @@ Object.defineProperty(exports, "Uppercase", { enumerable: true, get: function ()
|
|
|
97
99
|
var index_30 = require("./type/keyof/index");
|
|
98
100
|
Object.defineProperty(exports, "KeyOf", { enumerable: true, get: function () { return index_30.KeyOf; } });
|
|
99
101
|
Object.defineProperty(exports, "KeyOfPropertyKeys", { enumerable: true, get: function () { return index_30.KeyOfPropertyKeys; } });
|
|
102
|
+
Object.defineProperty(exports, "KeyOfPropertyKeysToRest", { enumerable: true, get: function () { return index_30.KeyOfPropertyKeysToRest; } });
|
|
103
|
+
Object.defineProperty(exports, "KeyOfFromMappedResult", { enumerable: true, get: function () { return index_30.KeyOfFromMappedResult; } });
|
|
100
104
|
Object.defineProperty(exports, "KeyOfPattern", { enumerable: true, get: function () { return index_30.KeyOfPattern; } });
|
|
101
105
|
var index_31 = require("./type/literal/index");
|
|
102
106
|
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return index_31.Literal; } });
|
|
@@ -104,6 +108,7 @@ var index_32 = require("./type/mapped/index");
|
|
|
104
108
|
Object.defineProperty(exports, "Mapped", { enumerable: true, get: function () { return index_32.Mapped; } });
|
|
105
109
|
Object.defineProperty(exports, "MappedKey", { enumerable: true, get: function () { return index_32.MappedKey; } });
|
|
106
110
|
Object.defineProperty(exports, "MappedResult", { enumerable: true, get: function () { return index_32.MappedResult; } });
|
|
111
|
+
Object.defineProperty(exports, "MappedFunctionReturnType", { enumerable: true, get: function () { return index_32.MappedFunctionReturnType; } });
|
|
107
112
|
var index_33 = require("./type/never/index");
|
|
108
113
|
Object.defineProperty(exports, "Never", { enumerable: true, get: function () { return index_33.Never; } });
|
|
109
114
|
var index_34 = require("./type/not/index");
|
|
@@ -155,12 +160,13 @@ var index_55 = require("./type/symbol/index");
|
|
|
155
160
|
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_55.Symbol; } });
|
|
156
161
|
var index_56 = require("./type/template-literal/index");
|
|
157
162
|
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_56.TemplateLiteral; } });
|
|
158
|
-
Object.defineProperty(exports, "
|
|
159
|
-
Object.defineProperty(exports, "
|
|
163
|
+
Object.defineProperty(exports, "TemplateLiteralSyntax", { enumerable: true, get: function () { return index_56.TemplateLiteralSyntax; } });
|
|
164
|
+
Object.defineProperty(exports, "TemplateLiteralGenerate", { enumerable: true, get: function () { return index_56.TemplateLiteralGenerate; } });
|
|
160
165
|
Object.defineProperty(exports, "TemplateLiteralParse", { enumerable: true, get: function () { return index_56.TemplateLiteralParse; } });
|
|
161
166
|
Object.defineProperty(exports, "TemplateLiteralParseExact", { enumerable: true, get: function () { return index_56.TemplateLiteralParseExact; } });
|
|
162
|
-
Object.defineProperty(exports, "
|
|
167
|
+
Object.defineProperty(exports, "IsTemplateLiteralFinite", { enumerable: true, get: function () { return index_56.IsTemplateLiteralFinite; } });
|
|
163
168
|
Object.defineProperty(exports, "TemplateLiteralExpressionGenerate", { enumerable: true, get: function () { return index_56.TemplateLiteralExpressionGenerate; } });
|
|
169
|
+
Object.defineProperty(exports, "IsTemplateLiteralExpressionFinite", { enumerable: true, get: function () { return index_56.IsTemplateLiteralExpressionFinite; } });
|
|
164
170
|
var index_57 = require("./type/transform/index");
|
|
165
171
|
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_57.Transform; } });
|
|
166
172
|
Object.defineProperty(exports, "TransformDecodeBuilder", { enumerable: true, get: function () { return index_57.TransformDecodeBuilder; } });
|
|
@@ -2,9 +2,8 @@ import type { TSchema, SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import { type TIntersect } from '../intersect/index';
|
|
3
3
|
import { type TUnion } from '../union/index';
|
|
4
4
|
import { type TPromise } from '../promise/index';
|
|
5
|
-
type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc,
|
|
6
|
-
type
|
|
7
|
-
export type TAwaited<T extends TSchema> = (TFromSchema<T>);
|
|
5
|
+
type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TAwaited<L>]> : Acc;
|
|
6
|
+
export type TAwaited<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S> ? TUnion<TFromRest<S>> : T extends TPromise<infer S> ? TAwaited<S> : T;
|
|
8
7
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
9
|
-
export declare function Awaited<T extends TSchema>(T: T, options?: SchemaOptions):
|
|
8
|
+
export declare function Awaited<T extends TSchema>(T: T, options?: SchemaOptions): TAwaited<T>;
|
|
10
9
|
export {};
|
|
@@ -11,7 +11,7 @@ const type_1 = require("../clone/type");
|
|
|
11
11
|
const type_2 = require("../guard/type");
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function FromRest(T) {
|
|
14
|
-
return T.map(L =>
|
|
14
|
+
return T.map(L => AwaitedResolve(L));
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function FromIntersect(T) {
|
|
@@ -23,10 +23,13 @@ function FromUnion(T) {
|
|
|
23
23
|
}
|
|
24
24
|
// prettier-ignore
|
|
25
25
|
function FromPromise(T) {
|
|
26
|
-
return
|
|
26
|
+
return AwaitedResolve(T);
|
|
27
27
|
}
|
|
28
|
+
// ----------------------------------------------------------------
|
|
29
|
+
// AwaitedResolve
|
|
30
|
+
// ----------------------------------------------------------------
|
|
28
31
|
// prettier-ignore
|
|
29
|
-
function
|
|
32
|
+
function AwaitedResolve(T) {
|
|
30
33
|
return ((0, type_2.IsIntersect)(T) ? FromIntersect(T.allOf) :
|
|
31
34
|
(0, type_2.IsUnion)(T) ? FromUnion(T.anyOf) :
|
|
32
35
|
(0, type_2.IsPromise)(T) ? FromPromise(T.item) :
|
|
@@ -34,6 +37,6 @@ function FromSchema(T) {
|
|
|
34
37
|
}
|
|
35
38
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
36
39
|
function Awaited(T, options = {}) {
|
|
37
|
-
return (0, type_1.CloneType)(
|
|
40
|
+
return (0, type_1.CloneType)(AwaitedResolve(T), options);
|
|
38
41
|
}
|
|
39
42
|
exports.Awaited = Awaited;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UnionToTuple, Assert, Evaluate } from '../helpers/index';
|
|
1
|
+
import type { UnionToTuple, Assert, Ensure, Evaluate } from '../helpers/index';
|
|
2
2
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index';
|
|
3
3
|
import { type TIntersect } from '../intersect/index';
|
|
4
4
|
import { type TIndex } from '../indexed/index';
|
|
@@ -7,8 +7,7 @@ type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[], Acc ex
|
|
|
7
7
|
[_ in L]: TIndex<T, [L]>;
|
|
8
8
|
}> : Acc;
|
|
9
9
|
type TCompositeReduce<T extends TObject[]> = UnionToTuple<TCompositeKeys<T>> extends infer K ? Evaluate<TCompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
10
|
-
type
|
|
11
|
-
export type TComposite<T extends TObject[]> = TCompositeResolve<T>;
|
|
10
|
+
export type TComposite<T extends TObject[]> = TIntersect<T> extends TIntersect ? Ensure<TObject<TCompositeReduce<T>>> : Ensure<TObject<{}>>;
|
|
12
11
|
/** `[Json]` Creates a Composite object type */
|
|
13
12
|
export declare function Composite<T extends TObject[]>(T: [...T], options?: ObjectOptions): TComposite<T>;
|
|
14
13
|
export {};
|
|
@@ -6,15 +6,11 @@ const index_1 = require("../object/index");
|
|
|
6
6
|
const index_2 = require("../intersect/index");
|
|
7
7
|
const index_3 = require("../indexed/index");
|
|
8
8
|
const index_4 = require("../keyof/index");
|
|
9
|
-
|
|
10
|
-
function
|
|
9
|
+
/** `[Json]` Creates a Composite object type */
|
|
10
|
+
function Composite(T, options) {
|
|
11
11
|
const intersect = (0, index_2.Intersect)(T, {});
|
|
12
12
|
const keys = (0, index_4.KeyOfPropertyKeys)(intersect);
|
|
13
13
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: (0, index_3.Index)(intersect, [key]) }), {});
|
|
14
|
-
return (0, index_1.Object)(properties);
|
|
15
|
-
}
|
|
16
|
-
/** `[Json]` Creates a Composite object type */
|
|
17
|
-
function Composite(T, options) {
|
|
18
|
-
return (0, type_1.CloneType)(CompositeResolve(T), options);
|
|
14
|
+
return (0, index_1.Object)(properties, options);
|
|
19
15
|
}
|
|
20
16
|
exports.Composite = Composite;
|
|
@@ -11,14 +11,12 @@ import type { TConstructor } from '../constructor/index';
|
|
|
11
11
|
import type { TFunction } from '../function/index';
|
|
12
12
|
import type { TRef } from '../ref/index';
|
|
13
13
|
import type { TObject, TProperties } from '../object/index';
|
|
14
|
-
export type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc,
|
|
14
|
+
export type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TDeref<L>]> : Acc);
|
|
15
15
|
type FromProperties<T extends TProperties> = Evaluate<{
|
|
16
|
-
[K in keyof T]:
|
|
16
|
+
[K in keyof T]: TDeref<T[K]>;
|
|
17
17
|
}>;
|
|
18
18
|
declare function FromProperties(properties: TProperties, references: TSchema[]): TProperties;
|
|
19
|
-
export type
|
|
20
|
-
export declare function DerefResolve<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>;
|
|
21
|
-
export type TDeref<T extends TSchema> = DerefResolve<T>;
|
|
19
|
+
export type TDeref<T extends TSchema> = T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<TFromRest<S>, TDeref<R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<TFromRest<S>, TDeref<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TFromRest<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TFromRest<S>> : T extends TObject<infer S extends TProperties> ? TObject<FromProperties<S>> : T extends TArray<infer S extends TSchema> ? TArray<TDeref<S>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDeref<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDeref<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDeref<S>> : T extends TRef<infer S extends TSchema> ? TDeref<S> : T;
|
|
22
20
|
/** `[Json]` Creates a dereferenced type */
|
|
23
21
|
export declare function Deref<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>;
|
|
24
22
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Deref =
|
|
4
|
+
exports.Deref = void 0;
|
|
5
5
|
const type_1 = require("../clone/type");
|
|
6
6
|
const index_1 = require("../discard/index");
|
|
7
7
|
const value_1 = require("../guard/value");
|
|
@@ -95,7 +95,9 @@ function DerefResolve(schema, references) {
|
|
|
95
95
|
(0, type_2.IsRef)(schema) ? FromRef(schema, references) :
|
|
96
96
|
schema);
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
// ------------------------------------------------------------------
|
|
99
|
+
// TDeref
|
|
100
|
+
// ------------------------------------------------------------------
|
|
99
101
|
/** `[Json]` Creates a dereferenced type */
|
|
100
102
|
function Deref(schema, references) {
|
|
101
103
|
return DerefResolve((0, type_1.CloneType)(schema), (0, type_1.CloneRest)(references));
|
|
@@ -11,14 +11,11 @@ import { type TExcludeFromMappedResult } from './exclude-from-mapped-result';
|
|
|
11
11
|
type TExcludeTemplateLiteralResult<T extends string> = TUnionEvaluated<AssertRest<UnionToTuple<{
|
|
12
12
|
[K in T]: TLiteral<K>;
|
|
13
13
|
}[T]>>>;
|
|
14
|
-
type TExcludeTemplateLiteral<
|
|
15
|
-
type
|
|
16
|
-
[K in keyof
|
|
14
|
+
type TExcludeTemplateLiteral<L extends TTemplateLiteral, R extends TSchema> = (Exclude<Static<L>, Static<R>> extends infer S ? TExcludeTemplateLiteralResult<Assert<S, string>> : never);
|
|
15
|
+
type TExcludeRest<L extends TSchema[], R extends TSchema> = AssertRest<UnionToTuple<{
|
|
16
|
+
[K in keyof L]: Static<AssertType<L[K]>> extends Static<R> ? never : L[K];
|
|
17
17
|
}[number]>> extends infer R extends TSchema[] ? TUnionEvaluated<R> : never;
|
|
18
|
-
type
|
|
19
|
-
export type TExclude<T extends TSchema, U extends TSchema> = TExcludeResolve<T, U>;
|
|
18
|
+
export type TExclude<L extends TSchema, R extends TSchema> = (L extends TMappedResult<L> ? TExcludeFromMappedResult<L, R> : L extends TTemplateLiteral ? TExcludeTemplateLiteral<L, R> : L extends TUnion<infer S> ? TExcludeRest<S, R> : L extends R ? TNever : L);
|
|
20
19
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
21
|
-
export declare function Exclude<L extends
|
|
22
|
-
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
23
|
-
export declare function Exclude<L extends TSchema, R extends TSchema>(unionType: L, excludedMembers: R, options?: SchemaOptions): TExclude<L, R>;
|
|
20
|
+
export declare function Exclude<L extends TSchema, R extends TSchema>(L: L, R: R, options?: SchemaOptions): TExclude<L, R>;
|
|
24
21
|
export {};
|
|
@@ -12,25 +12,17 @@ const exclude_from_mapped_result_1 = require("./exclude-from-mapped-result");
|
|
|
12
12
|
// TypeGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const type_2 = require("../guard/type");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
(0, type_2.IsTemplateLiteral)(R) ? ExcludeResolve(L, (0, index_1.TemplateLiteralToUnion)(R)) :
|
|
19
|
-
(0, type_2.IsUnion)(L) ? (() => {
|
|
20
|
-
const narrowed = L.anyOf.filter((inner) => (0, index_4.ExtendsCheck)(inner, R) === index_4.ExtendsResult.False);
|
|
21
|
-
return (narrowed.length === 1 ? narrowed[0] : (0, index_2.Union)(narrowed));
|
|
22
|
-
})() :
|
|
23
|
-
(0, index_4.ExtendsCheck)(L, R) !== index_4.ExtendsResult.False ? (0, index_3.Never)() :
|
|
24
|
-
L);
|
|
15
|
+
function ExcludeRest(L, R) {
|
|
16
|
+
const excluded = L.filter((inner) => (0, index_4.ExtendsCheck)(inner, R) === index_4.ExtendsResult.False);
|
|
17
|
+
return excluded.length === 1 ? excluded[0] : (0, index_2.Union)(excluded);
|
|
25
18
|
}
|
|
26
19
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
27
|
-
function Exclude(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
20
|
+
function Exclude(L, R, options = {}) {
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
return (0, type_1.CloneType)(((0, type_2.IsMappedResult)(L) ? (0, exclude_from_mapped_result_1.ExcludeFromMappedResult)(L, R, options) :
|
|
23
|
+
(0, type_2.IsTemplateLiteral)(L) ? Exclude((0, index_1.TemplateLiteralToUnion)(L), R) :
|
|
24
|
+
(0, type_2.IsTemplateLiteral)(R) ? Exclude(L, (0, index_1.TemplateLiteralToUnion)(R)) :
|
|
25
|
+
(0, type_2.IsUnion)(L) ? ExcludeRest(L.anyOf, R) :
|
|
26
|
+
(0, index_4.ExtendsCheck)(L, R) !== index_4.ExtendsResult.False ? (0, index_3.Never)() : L), options);
|
|
35
27
|
}
|
|
36
28
|
exports.Exclude = Exclude;
|
|
@@ -5,19 +5,17 @@ import { type TTemplateLiteral } from '../template-literal/index';
|
|
|
5
5
|
import { type TLiteral } from '../literal/index';
|
|
6
6
|
import { type TUnion } from '../union/index';
|
|
7
7
|
import { type Static } from '../static/index';
|
|
8
|
+
import { type TNever } from '../never/index';
|
|
8
9
|
import { type TUnionEvaluated } from '../union/index';
|
|
9
10
|
import { type TExtractFromMappedResult } from './extract-from-mapped-result';
|
|
10
|
-
type
|
|
11
|
+
type TExtractTemplateLiteralResult<T extends string> = TUnionEvaluated<AssertRest<UnionToTuple<{
|
|
11
12
|
[K in T]: TLiteral<K>;
|
|
12
13
|
}[T]>>>;
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
[K in keyof
|
|
14
|
+
type TExtractTemplateLiteral<L extends TTemplateLiteral, R extends TSchema> = Extract<Static<L>, Static<R>> extends infer S ? TExtractTemplateLiteralResult<Assert<S, string>> : never;
|
|
15
|
+
type TExtractRest<L extends TSchema[], R extends TSchema> = AssertRest<UnionToTuple<{
|
|
16
|
+
[K in keyof L]: Static<AssertType<L[K]>> extends Static<R> ? L[K] : never;
|
|
16
17
|
}[number]>> extends infer R extends TSchema[] ? TUnionEvaluated<R> : never;
|
|
17
|
-
type
|
|
18
|
-
export type TExtract<T extends TSchema, U extends TSchema> = TExtractResolve<T, U>;
|
|
18
|
+
export type TExtract<L extends TSchema, U extends TSchema> = (L extends TMappedResult ? TExtractFromMappedResult<L, U> : L extends TTemplateLiteral ? TExtractTemplateLiteral<L, U> : L extends TUnion<infer S> ? TExtractRest<S, U> : L extends U ? L : TNever);
|
|
19
19
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
20
|
-
export declare function Extract<L extends
|
|
21
|
-
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
22
|
-
export declare function Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
20
|
+
export declare function Extract<L extends TSchema, R extends TSchema>(L: L, R: R, options?: SchemaOptions): TExtract<L, R>;
|
|
23
21
|
export {};
|
|
@@ -12,25 +12,17 @@ const extract_from_mapped_result_1 = require("./extract-from-mapped-result");
|
|
|
12
12
|
// TypeGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const type_2 = require("../guard/type");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
(0, type_2.IsTemplateLiteral)(R) ? ExtractResolve(L, (0, index_1.TemplateLiteralToUnion)(R)) :
|
|
19
|
-
(0, type_2.IsUnion)(L) ? (() => {
|
|
20
|
-
const narrowed = L.anyOf.filter((inner) => (0, index_4.ExtendsCheck)(inner, R) !== index_4.ExtendsResult.False);
|
|
21
|
-
return (narrowed.length === 1 ? narrowed[0] : (0, index_2.Union)(narrowed));
|
|
22
|
-
})() :
|
|
23
|
-
(0, index_4.ExtendsCheck)(L, R) !== index_4.ExtendsResult.False ? L :
|
|
24
|
-
(0, index_3.Never)());
|
|
15
|
+
function ExtractRest(L, R) {
|
|
16
|
+
const extracted = L.filter((inner) => (0, index_4.ExtendsCheck)(inner, R) !== index_4.ExtendsResult.False);
|
|
17
|
+
return extracted.length === 1 ? extracted[0] : (0, index_2.Union)(extracted);
|
|
25
18
|
}
|
|
26
19
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
27
|
-
function Extract(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
20
|
+
function Extract(L, R, options = {}) {
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
return (0, type_1.CloneType)(((0, type_2.IsMappedResult)(L) ? (0, extract_from_mapped_result_1.ExtractFromMappedResult)(L, R, options) :
|
|
23
|
+
(0, type_2.IsTemplateLiteral)(L) ? Extract((0, index_1.TemplateLiteralToUnion)(L), R) :
|
|
24
|
+
(0, type_2.IsTemplateLiteral)(R) ? Extract(L, (0, index_1.TemplateLiteralToUnion)(R)) :
|
|
25
|
+
(0, type_2.IsUnion)(L) ? ExtractRest(L.anyOf, R) :
|
|
26
|
+
(0, index_4.ExtendsCheck)(L, R) !== index_4.ExtendsResult.False ? L : (0, index_3.Never)()), options);
|
|
35
27
|
}
|
|
36
28
|
exports.Extract = Extract;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
-
import type { Evaluate } from '../helpers/index';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index';
|
|
3
3
|
import type { TProperties } from '../object/index';
|
|
4
4
|
import { type TIndex } from './indexed';
|
|
5
5
|
import { type TMappedResult, type TMappedKey } from '../mapped/index';
|
|
@@ -8,6 +8,6 @@ type TMappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
|
8
8
|
};
|
|
9
9
|
type TMappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedIndexPropertyKeys<T, R, Acc & TMappedIndexPropertyKey<T, L>> : Acc);
|
|
10
10
|
type TMappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<T, K['keys']>>;
|
|
11
|
-
export type TIndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>> = (TMappedResult<P
|
|
11
|
+
export type TIndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>> = (Ensure<TMappedResult<P>>);
|
|
12
12
|
export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
|
|
13
13
|
export {};
|
|
@@ -13,7 +13,7 @@ import { type TUnionEvaluated } from '../union/index';
|
|
|
13
13
|
import { type TIndexPropertyKeys } from './indexed-property-keys';
|
|
14
14
|
import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
|
|
15
15
|
import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
|
|
16
|
-
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<
|
|
16
|
+
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Acc);
|
|
17
17
|
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
18
18
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
19
19
|
type TFromUnionRest<T extends TSchema[]> = T;
|
|
@@ -22,9 +22,11 @@ type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T
|
|
|
22
22
|
type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
23
23
|
type AssertPropertyKey<T> = Assert<T, string | number>;
|
|
24
24
|
type TFromProperty<T extends TProperties, K extends PropertyKey> = (K extends keyof T ? T[K] : `${AssertPropertyKey<K>}` extends `${AssertPropertyKey<keyof T>}` ? T[AssertPropertyKey<K>] : TNever);
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
type
|
|
25
|
+
export type TIndexFromPropertyKey<T extends TSchema, K extends PropertyKey> = (T extends TRecursive<infer S> ? TIndexFromPropertyKey<S, K> : T extends TIntersect<infer S> ? TFromIntersect<S, K> : T extends TUnion<infer S> ? TFromUnion<S, K> : T extends TTuple<infer S> ? TFromTuple<S, K> : T extends TArray<infer S> ? TFromArray<S, K> : T extends TObject<infer S> ? TFromProperty<S, K> : TNever);
|
|
26
|
+
export declare function IndexFromPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): TIndexFromPropertyKey<T, K>;
|
|
27
|
+
export type TIndexFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TSchema[] = []> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TIndexFromPropertyKeys<T, R, [...Acc, Assert<TIndexFromPropertyKey<T, L>, TSchema>]> : Acc);
|
|
28
|
+
export declare function IndexFromPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TIndexFromPropertyKeys<T, K>;
|
|
29
|
+
type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<TIndexFromPropertyKeys<T, K>>);
|
|
28
30
|
declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
|
|
29
31
|
export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
|
|
30
32
|
/** `[Json]` Returns an Indexed property type for the given keys */
|