@sinclair/typebox 0.32.0-dev-20 → 0.32.0-dev-22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/import/compiler/compiler.mjs +62 -62
- package/build/import/errors/errors.mjs +62 -62
- package/build/import/index.d.mts +6 -6
- package/build/import/index.mjs +1 -1
- package/build/import/type/awaited/awaited.d.mts +4 -6
- package/build/import/type/awaited/awaited.mjs +3 -3
- package/build/import/type/composite/composite.d.mts +8 -8
- package/build/import/type/const/const.d.mts +4 -7
- package/build/import/type/constructor/constructor.d.mts +4 -4
- package/build/import/type/deref/deref.d.mts +2 -2
- package/build/import/type/deref/deref.mjs +26 -36
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +4 -6
- package/build/import/type/exclude/exclude.d.mts +7 -8
- package/build/import/type/extends/extends-from-mapped-key.d.mts +5 -8
- package/build/import/type/extends/extends-from-mapped-key.mjs +3 -3
- package/build/import/type/extends/extends-from-mapped-result.d.mts +4 -6
- package/build/import/type/extends/extends.d.mts +2 -3
- package/build/import/type/extract/extract-from-mapped-result.d.mts +4 -6
- package/build/import/type/extract/extract.d.mts +8 -8
- package/build/import/type/function/function.d.mts +1 -1
- package/build/import/type/helpers/helpers.d.mts +1 -1
- package/build/import/type/index.d.mts +0 -1
- package/build/import/type/index.mjs +0 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +5 -8
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +3 -6
- package/build/import/type/indexed/indexed-property-keys.d.mts +5 -8
- package/build/import/type/indexed/indexed-property-keys.mjs +6 -11
- package/build/import/type/indexed/indexed.d.mts +13 -23
- package/build/import/type/indexed/indexed.mjs +13 -13
- package/build/import/type/intersect/intersect-create.mjs +0 -1
- package/build/import/type/intersect/intersect-evaluated.d.mts +7 -11
- package/build/import/type/intersect/intersect-evaluated.mjs +12 -7
- package/build/import/type/intersect/intersect-type.d.mts +2 -2
- package/build/import/type/intersect/intersect.mjs +1 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +7 -9
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +3 -3
- package/build/import/type/intrinsic/intrinsic.d.mts +6 -8
- package/build/import/type/intrinsic/intrinsic.mjs +8 -6
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +4 -6
- package/build/import/type/keyof/keyof-property-keys.d.mts +9 -13
- package/build/import/type/keyof/keyof-property-keys.mjs +12 -9
- package/build/import/type/keyof/keyof.d.mts +7 -8
- package/build/import/type/keyof/keyof.mjs +8 -6
- package/build/import/type/mapped/mapped.d.mts +9 -13
- package/build/import/type/mapped/mapped.mjs +9 -9
- package/build/import/type/omit/omit-from-mapped-key.d.mts +5 -8
- package/build/import/type/omit/omit-from-mapped-key.mjs +3 -3
- package/build/import/type/omit/omit.d.mts +6 -9
- package/build/import/type/omit/omit.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +16 -16
- package/build/import/type/operators/operators.mjs +21 -25
- package/build/import/type/optional/optional-from-mapped-result.d.mts +4 -6
- package/build/import/type/optional/optional.d.mts +3 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +4 -6
- package/build/import/type/partial/partial.d.mts +4 -7
- package/build/import/type/partial/partial.mjs +6 -7
- package/build/import/type/pick/pick-from-mapped-key.d.mts +5 -8
- package/build/import/type/pick/pick-from-mapped-key.mjs +3 -3
- package/build/import/type/pick/pick.d.mts +4 -4
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +4 -6
- package/build/import/type/readonly/readonly.d.mts +3 -7
- package/build/import/type/record/record.d.mts +14 -20
- package/build/import/type/record/record.mjs +2 -4
- package/build/import/type/ref/ref.mjs +3 -0
- package/build/import/type/required/required-from-mapped-result.d.mts +4 -6
- package/build/import/type/required/required.d.mts +5 -9
- package/build/import/type/required/required.mjs +6 -7
- package/build/import/type/rest/rest.d.mts +3 -3
- package/build/import/type/schema/schema.d.mts +1 -1
- package/build/import/type/static/static.d.mts +1 -1
- package/build/import/type/symbol/symbol.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +7 -5
- package/build/import/type/template-literal/finite.mjs +14 -5
- package/build/import/type/template-literal/generate.d.mts +14 -9
- package/build/import/type/template-literal/generate.mjs +19 -9
- package/build/import/type/template-literal/index.d.mts +1 -1
- package/build/import/type/template-literal/index.mjs +1 -1
- package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
- package/build/import/type/template-literal/syntax.d.mts +3 -3
- package/build/import/type/template-literal/syntax.mjs +2 -3
- package/build/import/type/template-literal/template-literal.d.mts +2 -2
- package/build/import/type/template-literal/template-literal.mjs +1 -1
- package/build/import/type/template-literal/union.d.mts +2 -2
- package/build/import/type/template-literal/union.mjs +5 -10
- package/build/import/type/transform/transform.mjs +0 -1
- package/build/import/type/tuple/tuple.d.mts +1 -2
- package/build/import/type/type/json.d.mts +2 -2
- package/build/import/type/union/union-evaluated.d.mts +6 -10
- package/build/import/type/union/union-evaluated.mjs +7 -2
- package/build/import/value/cast/cast.mjs +20 -20
- package/build/import/value/check/check.mjs +62 -62
- package/build/import/value/clean/clean.mjs +16 -16
- package/build/import/value/convert/convert.mjs +36 -36
- package/build/import/value/create/create.mjs +66 -67
- package/build/import/value/default/default.mjs +16 -16
- package/build/import/value/transform/decode.mjs +18 -18
- package/build/import/value/transform/encode.mjs +18 -18
- package/build/import/value/transform/has.mjs +28 -28
- package/build/require/compiler/compiler.js +62 -62
- package/build/require/errors/errors.js +62 -62
- package/build/require/index.d.ts +6 -6
- package/build/require/index.js +4 -2
- package/build/require/type/awaited/awaited.d.ts +4 -6
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/composite/composite.d.ts +8 -8
- package/build/require/type/const/const.d.ts +4 -7
- package/build/require/type/constructor/constructor.d.ts +4 -4
- package/build/require/type/deref/deref.d.ts +2 -2
- package/build/require/type/deref/deref.js +25 -35
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +4 -6
- package/build/require/type/exclude/exclude.d.ts +7 -8
- package/build/require/type/extends/extends-from-mapped-key.d.ts +5 -8
- package/build/require/type/extends/extends-from-mapped-key.js +3 -3
- package/build/require/type/extends/extends-from-mapped-result.d.ts +4 -6
- package/build/require/type/extends/extends.d.ts +2 -3
- package/build/require/type/extract/extract-from-mapped-result.d.ts +4 -6
- package/build/require/type/extract/extract.d.ts +8 -8
- package/build/require/type/function/function.d.ts +1 -1
- package/build/require/type/helpers/helpers.d.ts +1 -1
- package/build/require/type/index.d.ts +0 -1
- package/build/require/type/index.js +0 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +5 -8
- package/build/require/type/indexed/indexed-from-mapped-key.js +3 -6
- package/build/require/type/indexed/indexed-property-keys.d.ts +5 -8
- package/build/require/type/indexed/indexed-property-keys.js +4 -9
- package/build/require/type/indexed/indexed.d.ts +13 -23
- package/build/require/type/indexed/indexed.js +13 -13
- package/build/require/type/intersect/intersect-create.js +0 -1
- package/build/require/type/intersect/intersect-evaluated.d.ts +7 -11
- package/build/require/type/intersect/intersect-evaluated.js +9 -4
- package/build/require/type/intersect/intersect-type.d.ts +2 -2
- package/build/require/type/intersect/intersect.js +0 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +7 -9
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +3 -3
- package/build/require/type/intrinsic/intrinsic.d.ts +6 -8
- package/build/require/type/intrinsic/intrinsic.js +7 -5
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +4 -6
- package/build/require/type/keyof/keyof-property-keys.d.ts +9 -13
- package/build/require/type/keyof/keyof-property-keys.js +12 -9
- package/build/require/type/keyof/keyof.d.ts +7 -8
- package/build/require/type/keyof/keyof.js +8 -6
- package/build/require/type/mapped/mapped.d.ts +9 -13
- package/build/require/type/mapped/mapped.js +9 -9
- package/build/require/type/omit/omit-from-mapped-key.d.ts +5 -8
- package/build/require/type/omit/omit-from-mapped-key.js +3 -3
- package/build/require/type/omit/omit.d.ts +6 -9
- package/build/require/type/omit/omit.js +0 -1
- package/build/require/type/operators/operators.d.ts +16 -16
- package/build/require/type/operators/operators.js +21 -25
- package/build/require/type/optional/optional-from-mapped-result.d.ts +4 -6
- package/build/require/type/optional/optional.d.ts +3 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +4 -6
- package/build/require/type/partial/partial.d.ts +4 -7
- package/build/require/type/partial/partial.js +6 -7
- package/build/require/type/pick/pick-from-mapped-key.d.ts +5 -8
- package/build/require/type/pick/pick-from-mapped-key.js +3 -3
- package/build/require/type/pick/pick.d.ts +4 -4
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +4 -6
- package/build/require/type/readonly/readonly.d.ts +3 -7
- package/build/require/type/record/record.d.ts +14 -20
- package/build/require/type/record/record.js +1 -3
- package/build/require/type/ref/ref.js +3 -0
- package/build/require/type/required/required-from-mapped-result.d.ts +4 -6
- package/build/require/type/required/required.d.ts +5 -9
- package/build/require/type/required/required.js +6 -7
- package/build/require/type/rest/rest.d.ts +3 -3
- package/build/require/type/schema/schema.d.ts +1 -1
- package/build/require/type/static/static.d.ts +1 -1
- package/build/require/type/symbol/symbol.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +7 -5
- package/build/require/type/template-literal/finite.js +16 -6
- package/build/require/type/template-literal/generate.d.ts +14 -9
- package/build/require/type/template-literal/generate.js +22 -11
- package/build/require/type/template-literal/index.d.ts +1 -1
- package/build/require/type/template-literal/index.js +1 -1
- package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
- package/build/require/type/template-literal/syntax.d.ts +3 -3
- package/build/require/type/template-literal/syntax.js +1 -2
- package/build/require/type/template-literal/template-literal.d.ts +2 -2
- package/build/require/type/template-literal/template-literal.js +1 -1
- package/build/require/type/template-literal/union.d.ts +2 -2
- package/build/require/type/template-literal/union.js +5 -10
- package/build/require/type/transform/transform.js +0 -1
- package/build/require/type/tuple/tuple.d.ts +1 -2
- package/build/require/type/type/json.d.ts +2 -2
- package/build/require/type/union/union-evaluated.d.ts +6 -10
- package/build/require/type/union/union-evaluated.js +7 -2
- package/build/require/value/cast/cast.js +20 -20
- package/build/require/value/check/check.js +62 -62
- package/build/require/value/clean/clean.js +16 -16
- package/build/require/value/convert/convert.js +36 -36
- package/build/require/value/create/create.js +65 -66
- package/build/require/value/default/default.js +16 -16
- package/build/require/value/transform/decode.js +18 -18
- package/build/require/value/transform/encode.js +18 -18
- package/build/require/value/transform/has.js +28 -28
- package/package.json +1 -1
- package/readme.md +47 -47
- package/build/import/type/modifiers/index.d.mts +0 -1
- package/build/import/type/modifiers/index.mjs +0 -1
- package/build/import/type/modifiers/modifiers.d.mts +0 -18
- package/build/import/type/modifiers/modifiers.mjs +0 -50
- package/build/require/type/modifiers/index.d.ts +0 -1
- package/build/require/type/modifiers/index.js +0 -18
- package/build/require/type/modifiers/modifiers.d.ts +0 -18
- package/build/require/type/modifiers/modifiers.js +0 -56
- /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
- /package/build/require/type/template-literal/{parser.d.ts → parse.d.ts} +0 -0
|
@@ -13,21 +13,20 @@ const partial_from_mapped_result_1 = require("./partial-from-mapped-result");
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// TypeGuard
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
// prettier-ignore
|
|
17
16
|
const type_2 = require("../guard/type");
|
|
18
17
|
// prettier-ignore
|
|
19
|
-
function FromIntersect(T) {
|
|
18
|
+
function FromIntersect(T, Acc = []) {
|
|
20
19
|
const [L, ...R] = T;
|
|
21
20
|
return (T.length > 0
|
|
22
|
-
?
|
|
23
|
-
:
|
|
21
|
+
? FromIntersect(R, [...Acc, PartialResolve(L)])
|
|
22
|
+
: Acc);
|
|
24
23
|
}
|
|
25
24
|
// prettier-ignore
|
|
26
|
-
function FromUnion(T) {
|
|
25
|
+
function FromUnion(T, Acc = []) {
|
|
27
26
|
const [L, ...R] = T;
|
|
28
27
|
return (T.length > 0
|
|
29
|
-
?
|
|
30
|
-
:
|
|
28
|
+
? FromUnion(R, [...Acc, PartialResolve(L)])
|
|
29
|
+
: Acc);
|
|
31
30
|
}
|
|
32
31
|
// prettier-ignore
|
|
33
32
|
function FromProperties(T) {
|
|
@@ -2,14 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import type { TProperties } from '../object/index';
|
|
3
3
|
import { type TMappedResult, type TMappedKey } from '../mapped/index';
|
|
4
4
|
import { type TPick } from './pick';
|
|
5
|
-
type
|
|
5
|
+
type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
6
6
|
[_ in K]: TPick<T, [K]>;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare function FromMappedKey<T extends TSchema, K extends TMappedKey>(T: T, K: K, options: SchemaOptions): FromMappedKey<T, K>;
|
|
13
|
-
export type TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>> = (TMappedResult<P>);
|
|
14
|
-
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = FromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
|
|
8
|
+
type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
|
|
9
|
+
type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
|
|
10
|
+
export type TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
|
|
11
|
+
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
|
|
15
12
|
export {};
|
|
@@ -11,11 +11,11 @@ function FromPropertyKey(T, K, options) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
function FromPropertyKeys(T, K, options) {
|
|
14
|
+
function FromPropertyKeys(T, K, options, Acc = {}) {
|
|
15
15
|
const [LK, ...RK] = K;
|
|
16
16
|
return (K.length > 0
|
|
17
|
-
?
|
|
18
|
-
:
|
|
17
|
+
? FromPropertyKeys(T, RK, options, { ...Acc, ...FromPropertyKey(T, LK, options) })
|
|
18
|
+
: Acc);
|
|
19
19
|
}
|
|
20
20
|
// prettier-ignore
|
|
21
21
|
function FromMappedKey(T, K, options) {
|
|
@@ -7,10 +7,10 @@ import { type TObject, type TProperties } from '../object/index';
|
|
|
7
7
|
import { type TIndexPropertyKeys } from '../indexed/index';
|
|
8
8
|
import { TMappedKey } from '../mapped/index';
|
|
9
9
|
import { type TPickFromMappedKey } from './pick-from-mapped-key';
|
|
10
|
-
type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ?
|
|
11
|
-
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
|
|
12
|
-
type FromUnion<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ?
|
|
13
|
-
declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K>;
|
|
10
|
+
type FromIntersect<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromIntersect<R, K, [...Acc, PickResolve<L, K>]> : Acc;
|
|
11
|
+
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K, []>;
|
|
12
|
+
type FromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromUnion<R, K, [...Acc, PickResolve<L, K>]> : Acc;
|
|
13
|
+
declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
|
|
14
14
|
type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
|
|
15
15
|
declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
|
|
16
16
|
export type PickResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<PickResolve<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<{}>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { TProperties } from '../object/index';
|
|
2
2
|
import { type TMappedResult } from '../mapped/index';
|
|
3
3
|
import { type TReadonlyWithFlag } from './readonly';
|
|
4
|
-
type
|
|
4
|
+
type TFromProperties<K extends TProperties, F extends boolean> = ({
|
|
5
5
|
[K2 in keyof K]: TReadonlyWithFlag<K[K2], F>;
|
|
6
6
|
});
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function
|
|
10
|
-
export type TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
|
|
11
|
-
export declare function ReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
7
|
+
type TFromMappedResult<K extends TMappedResult, F extends boolean> = (TFromProperties<K['properties'], F>);
|
|
8
|
+
export type TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>> = (TMappedResult<P>);
|
|
9
|
+
export declare function ReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = TFromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
|
|
12
10
|
export {};
|
|
@@ -3,13 +3,9 @@ import type { Ensure } from '../helpers/index';
|
|
|
3
3
|
import { ReadonlyKind } from '../symbols/index';
|
|
4
4
|
import type { TMappedResult } from '../mapped/index';
|
|
5
5
|
import { type TReadonlyFromMappedResult } from './readonly-from-mapped-result';
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
declare function AddReadonly<T extends TSchema>(schema: T): T & {
|
|
10
|
-
[ReadonlyKind]: string;
|
|
11
|
-
};
|
|
12
|
-
export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveReadonly<T> : AddReadonly<T>;
|
|
6
|
+
type TRemoveReadonly<T extends TSchema> = T extends TReadonly<infer S> ? S : T;
|
|
7
|
+
type TAddReadonly<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<S> : Ensure<TReadonly<T>>;
|
|
8
|
+
export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? TRemoveReadonly<T> : TAddReadonly<T>;
|
|
13
9
|
export type TReadonly<T extends TSchema> = T & {
|
|
14
10
|
[ReadonlyKind]: 'Readonly';
|
|
15
11
|
};
|
|
@@ -9,36 +9,30 @@ import { type TString } from '../string/index';
|
|
|
9
9
|
import { type TInteger } from '../integer/index';
|
|
10
10
|
import { type TNumber } from '../number/index';
|
|
11
11
|
import { type TEnum } from '../enum/index';
|
|
12
|
-
import { TTemplateLiteral,
|
|
12
|
+
import { TTemplateLiteral, TIsTemplateLiteralFinite } from '../template-literal/index';
|
|
13
13
|
import { Kind } from '../symbols/index';
|
|
14
|
-
type
|
|
15
|
-
type
|
|
14
|
+
type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
15
|
+
type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
|
|
16
16
|
[_ in I]: T;
|
|
17
17
|
}>>>);
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
type FromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
|
|
18
|
+
type TFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? TFromTemplateLiteralKeyInfinite<K, T> : TFromTemplateLiteralKeyFinite<K, T>;
|
|
19
|
+
type TFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
|
|
21
20
|
[_ in K[keyof K]]: T;
|
|
22
21
|
}>>;
|
|
23
|
-
type
|
|
22
|
+
type TFromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
|
|
24
23
|
[_ in K['const']]: T;
|
|
25
24
|
};
|
|
26
|
-
type
|
|
25
|
+
type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
|
|
27
26
|
[_ in K['const']]: T;
|
|
28
27
|
};
|
|
29
|
-
type
|
|
30
|
-
type
|
|
31
|
-
|
|
32
|
-
type FromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
|
|
28
|
+
type TFromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? TFromUnionKeyRest<S, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<string> ? TFromUnionKeyLiteralString<L, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<number> ? TFromUnionKeyLiteralNumber<L, T> & TFromUnionKeyRest<R, T> : {}) : {};
|
|
29
|
+
type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<P>>);
|
|
30
|
+
type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
|
|
33
31
|
[_ in Assert<K, PropertyKey>]: T;
|
|
34
32
|
}>>);
|
|
35
|
-
|
|
36
|
-
type
|
|
37
|
-
|
|
38
|
-
type FromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
39
|
-
declare function FromIntegerKey<K extends TInteger, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
|
|
40
|
-
type FromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
41
|
-
declare function FromNumberKey<K extends TNumber, T extends TSchema>(_: K, T: T, options: ObjectOptions): FromIntegerKey<K, T>;
|
|
33
|
+
type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
|
|
34
|
+
type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
35
|
+
type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
42
36
|
type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Record<Assert<Static<K>, PropertyKey>, Static<T, P>>);
|
|
43
37
|
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
44
38
|
[Kind]: 'Record';
|
|
@@ -49,7 +43,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
|
|
|
49
43
|
};
|
|
50
44
|
additionalProperties: TAdditionalProperties;
|
|
51
45
|
}
|
|
52
|
-
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ?
|
|
46
|
+
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
|
|
53
47
|
/** `[Json]` Creates a Record type */
|
|
54
48
|
export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
|
|
55
49
|
export {};
|
|
@@ -14,7 +14,6 @@ const value_1 = require("../guard/value");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
// TypeGuard
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
-
// prettier-ignore
|
|
18
17
|
const type_2 = require("../guard/type");
|
|
19
18
|
// ------------------------------------------------------------------
|
|
20
19
|
// RecordCreateFromPattern
|
|
@@ -38,8 +37,7 @@ function RecordCreateFromKeys(K, T, options) {
|
|
|
38
37
|
}
|
|
39
38
|
// prettier-ignore
|
|
40
39
|
function FromTemplateLiteralKey(K, T, options) {
|
|
41
|
-
|
|
42
|
-
return ((0, index_4.IsTemplateLiteralFinite)(expression)
|
|
40
|
+
return ((0, index_4.IsTemplateLiteralFinite)(K)
|
|
43
41
|
? RecordCreateFromKeys((0, index_6.IndexPropertyKeys)(K), T, options)
|
|
44
42
|
: RecordCreateFromPattern(K.pattern, T, options));
|
|
45
43
|
}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Ref = void 0;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
|
+
// ------------------------------------------------------------------
|
|
7
|
+
// TypeGuard
|
|
8
|
+
// ------------------------------------------------------------------
|
|
6
9
|
const value_1 = require("../guard/value");
|
|
7
10
|
/** `[Json]` Creates a Ref type. */
|
|
8
11
|
function Ref(unresolved, options = {}) {
|
|
@@ -2,12 +2,10 @@ import type { SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import type { TProperties } from '../object/index';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index';
|
|
4
4
|
import { type TRequired } from './required';
|
|
5
|
-
type
|
|
5
|
+
type TFromProperties<K extends TProperties> = ({
|
|
6
6
|
[K2 in keyof K]: TRequired<K[K2]>;
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
declare function
|
|
11
|
-
export type TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>> = (TMappedResult<P>);
|
|
12
|
-
export declare function RequiredFromMappedResult<T extends TMappedResult, P extends TProperties = FromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
8
|
+
type TFromMappedResult<K extends TMappedResult> = (TFromProperties<K['properties']>);
|
|
9
|
+
export type TRequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function RequiredFromMappedResult<T extends TMappedResult, P extends TProperties = TFromMappedResult<T>>(T: T, options: SchemaOptions): TMappedResult<P>;
|
|
13
11
|
export {};
|
|
@@ -9,17 +9,13 @@ import { type TIntersect } from '../intersect/index';
|
|
|
9
9
|
import { type TUnion } from '../union/index';
|
|
10
10
|
import { type TObject, type TProperties } from '../object/index';
|
|
11
11
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result';
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
|
|
16
|
-
type FromProperties<T extends TProperties> = Evaluate<{
|
|
12
|
+
type TFromIntersect<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
13
|
+
type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
14
|
+
type TFromProperties<T extends TProperties> = Evaluate<{
|
|
17
15
|
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
|
|
18
16
|
}>;
|
|
19
|
-
|
|
20
|
-
type
|
|
21
|
-
declare function RequiredResolve<T extends TSchema>(T: T): RequiredResolve<T>;
|
|
22
|
-
export type TRequired<T extends TSchema> = RequiredResolve<T>;
|
|
17
|
+
type TRequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<TRequiredResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromIntersect<S>> : T extends TUnion<infer S> ? TUnion<TFromUnion<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
|
|
18
|
+
export type TRequired<T extends TSchema> = TRequiredResolve<T>;
|
|
23
19
|
/** `[Json]` Constructs a type where all properties are required */
|
|
24
20
|
export declare function Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>;
|
|
25
21
|
/** `[Json]` Constructs a type where all properties are required */
|
|
@@ -12,21 +12,20 @@ const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
13
|
// TypeGuard
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
|
-
// prettier-ignore
|
|
16
15
|
const type_2 = require("../guard/type");
|
|
17
16
|
// prettier-ignore
|
|
18
|
-
function FromIntersect(T) {
|
|
17
|
+
function FromIntersect(T, Acc = []) {
|
|
19
18
|
const [L, ...R] = T;
|
|
20
19
|
return (T.length > 0
|
|
21
|
-
?
|
|
22
|
-
:
|
|
20
|
+
? FromIntersect(R, [...Acc, RequiredResolve(L)])
|
|
21
|
+
: Acc);
|
|
23
22
|
}
|
|
24
23
|
// prettier-ignore
|
|
25
|
-
function FromUnion(T) {
|
|
24
|
+
function FromUnion(T, Acc = []) {
|
|
26
25
|
const [L, ...R] = T;
|
|
27
26
|
return (T.length > 0
|
|
28
|
-
?
|
|
29
|
-
:
|
|
27
|
+
? FromUnion(R, [...Acc, RequiredResolve(L)])
|
|
28
|
+
: Acc);
|
|
30
29
|
}
|
|
31
30
|
// prettier-ignore
|
|
32
31
|
function FromProperties(T) {
|
|
@@ -2,9 +2,9 @@ import type { TSchema } from '../schema/index';
|
|
|
2
2
|
import type { TIntersect } from '../intersect/index';
|
|
3
3
|
import type { TUnion } from '../union/index';
|
|
4
4
|
import type { TTuple } from '../tuple/index';
|
|
5
|
-
export type
|
|
5
|
+
export type TRestResolve<T extends TSchema> = T extends TIntersect<infer S> ? [...S] : T extends TUnion<infer S> ? [...S] : T extends TTuple<infer S> ? [...S] : [
|
|
6
6
|
];
|
|
7
|
-
export declare function RestResolve<T extends TSchema>(T: T):
|
|
8
|
-
export type TRest<T extends TSchema> =
|
|
7
|
+
export declare function RestResolve<T extends TSchema>(T: T): TRestResolve<T>;
|
|
8
|
+
export type TRest<T extends TSchema> = TRestResolve<T>;
|
|
9
9
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
10
10
|
export declare function Rest<T extends TSchema>(T: T): TRest<T>;
|
|
@@ -20,7 +20,7 @@ export interface SchemaOptions {
|
|
|
20
20
|
export interface TKind {
|
|
21
21
|
[Kind]: string;
|
|
22
22
|
}
|
|
23
|
-
export interface TSchema extends
|
|
23
|
+
export interface TSchema extends TKind, SchemaOptions {
|
|
24
24
|
[ReadonlyKind]?: string;
|
|
25
25
|
[OptionalKind]?: string;
|
|
26
26
|
[Hint]?: string;
|
|
@@ -22,7 +22,7 @@ import type { TTransform } from '../transform/index';
|
|
|
22
22
|
export type DecodeProperties<T extends TProperties> = {
|
|
23
23
|
[K in keyof T]: DecodeType<T[K]>;
|
|
24
24
|
};
|
|
25
|
-
export type DecodeRest<T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [DecodeType<L
|
|
25
|
+
export type DecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? DecodeRest<R, [...Acc, DecodeType<L>]> : Acc;
|
|
26
26
|
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<DecodeRest<P>, DecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<DecodeRest<P>, DecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<DecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<DecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<DecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<DecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<DecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, DecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<DecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<DecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<DecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<DecodeRest<S>> : T);
|
|
27
27
|
/** Creates an decoded static type from a TypeBox type */
|
|
28
28
|
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeType<T>, P>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import { Kind } from '../symbols/index';
|
|
3
|
-
export type
|
|
3
|
+
export type TSymbolValue = string | number | undefined;
|
|
4
4
|
export interface TSymbol extends TSchema, SchemaOptions {
|
|
5
5
|
[Kind]: 'Symbol';
|
|
6
6
|
static: symbol;
|
|
@@ -6,11 +6,13 @@ import type { TNumber } from '../number/index';
|
|
|
6
6
|
import type { TInteger } from '../integer/index';
|
|
7
7
|
import type { TBigInt } from '../bigint/index';
|
|
8
8
|
import type { TLiteral } from '../literal/index';
|
|
9
|
-
import type { Expression } from './
|
|
9
|
+
import type { Expression } from './parse';
|
|
10
10
|
export declare class TemplateLiteralFiniteError extends Error {
|
|
11
11
|
}
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
export
|
|
15
|
-
export
|
|
12
|
+
type TFromTemplateLiteralKind<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TString ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TBoolean ? true : T extends TLiteral ? true : false;
|
|
13
|
+
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? TFromTemplateLiteralKind<L> extends false ? false : TFromTemplateLiteralKinds<R> : true;
|
|
14
|
+
export declare function IsTemplateLiteralExpressionFinite(expression: Expression): boolean;
|
|
15
|
+
export type TIsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? TFromTemplateLiteralKinds<U> : false;
|
|
16
|
+
/** Returns true if this TemplateLiteral resolves to a finite set of values */
|
|
17
|
+
export declare function IsTemplateLiteralFinite<T extends TTemplateLiteral>(schema: T): boolean;
|
|
16
18
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.IsTemplateLiteralFinite = exports.TemplateLiteralFiniteError = void 0;
|
|
4
|
+
exports.IsTemplateLiteralFinite = exports.IsTemplateLiteralExpressionFinite = exports.TemplateLiteralFiniteError = void 0;
|
|
5
|
+
const parse_1 = require("./parse");
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// TemplateLiteralFiniteError
|
|
7
8
|
// ------------------------------------------------------------------
|
|
@@ -33,13 +34,22 @@ function IsBooleanExpression(expression) {
|
|
|
33
34
|
function IsStringExpression(expression) {
|
|
34
35
|
return expression.type === 'const' && expression.const === '.*';
|
|
35
36
|
}
|
|
37
|
+
// ------------------------------------------------------------------
|
|
38
|
+
// IsTemplateLiteralExpressionFinite
|
|
39
|
+
// ------------------------------------------------------------------
|
|
36
40
|
// prettier-ignore
|
|
37
|
-
function
|
|
38
|
-
return (
|
|
39
|
-
|
|
40
|
-
(expression.type === 'and') ? expression.expr.every((expr) =>
|
|
41
|
-
(expression.type === 'or') ? expression.expr.every((expr) =>
|
|
41
|
+
function IsTemplateLiteralExpressionFinite(expression) {
|
|
42
|
+
return (IsNumberExpression(expression) || IsStringExpression(expression) ? false :
|
|
43
|
+
IsBooleanExpression(expression) ? true :
|
|
44
|
+
(expression.type === 'and') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
45
|
+
(expression.type === 'or') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
42
46
|
(expression.type === 'const') ? true :
|
|
43
47
|
(() => { throw new TemplateLiteralFiniteError(`Unknown expression type`); })());
|
|
44
48
|
}
|
|
49
|
+
exports.IsTemplateLiteralExpressionFinite = IsTemplateLiteralExpressionFinite;
|
|
50
|
+
/** Returns true if this TemplateLiteral resolves to a finite set of values */
|
|
51
|
+
function IsTemplateLiteralFinite(schema) {
|
|
52
|
+
const expression = (0, parse_1.TemplateLiteralParseExact)(schema.pattern);
|
|
53
|
+
return IsTemplateLiteralExpressionFinite(expression);
|
|
54
|
+
}
|
|
45
55
|
exports.IsTemplateLiteralFinite = IsTemplateLiteralFinite;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { TIsTemplateLiteralFinite } from './finite';
|
|
2
|
+
import type { Assert } from '../helpers/index';
|
|
3
|
+
import type { TBoolean } from '../boolean/index';
|
|
1
4
|
import type { TTemplateLiteral, TTemplateLiteralKind } from './index';
|
|
2
5
|
import type { TLiteral, TLiteralValue } from '../literal/index';
|
|
3
|
-
import type { Expression } from './
|
|
6
|
+
import type { Expression } from './parse';
|
|
4
7
|
import type { TUnion } from '../union/index';
|
|
5
|
-
type StringReduceUnary<L extends string, R extends string[]> = R extends [infer A extends string, ...infer B extends string[]] ? [`${L}${A}`, ...StringReduceUnary<L, B>] : [];
|
|
6
|
-
type StringReduceBinary<L extends string[], R extends string[]> = L extends [infer A extends string, ...infer B extends string[]] ? [...StringReduceUnary<A, R>, ...StringReduceBinary<B, R>] : [];
|
|
7
|
-
type StringReduceMany<T extends string[][]> = T extends [infer L extends string[], infer R extends string[], ...infer Rest extends string[][]] ? StringReduceMany<[StringReduceBinary<L, R>, ...Rest]> : T;
|
|
8
|
-
type StringReduce<T extends string[][], O = StringReduceMany<T>> = 0 extends keyof O ? O[0] : [];
|
|
9
|
-
type TemplateLiteralReduceUnion<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [L['const'], ...TemplateLiteralReduceUnion<R>] : [];
|
|
10
|
-
type TemplateLiteralReduce<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? L extends TLiteral<infer S extends TLiteralValue> ? [[S], ...TemplateLiteralReduce<R>] : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? [TemplateLiteralReduceUnion<S>, ...TemplateLiteralReduce<R>] : [] : [];
|
|
11
8
|
export declare class TemplateLiteralGenerateError extends Error {
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
type TStringReduceUnary<L extends string, R extends string[], Acc extends string[] = []> = R extends [infer A extends string, ...infer B extends string[]] ? TStringReduceUnary<L, B, [...Acc, `${L}${A}`]> : Acc;
|
|
11
|
+
type TStringReduceBinary<L extends string[], R extends string[], Acc extends string[] = []> = L extends [infer A extends string, ...infer B extends string[]] ? TStringReduceBinary<B, R, [...Acc, ...TStringReduceUnary<A, R>]> : Acc;
|
|
12
|
+
type TStringReduceMany<T extends string[][]> = T extends [infer L extends string[], infer R extends string[], ...infer Rest extends string[][]] ? TStringReduceMany<[TStringReduceBinary<L, R>, ...Rest]> : T;
|
|
13
|
+
type TStringReduce<T extends string[][], O = TStringReduceMany<T>> = 0 extends keyof O ? Assert<O[0], string[]> : [];
|
|
14
|
+
type TFromTemplateLiteralUnionKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [L['const'], ...TFromTemplateLiteralUnionKinds<R>] : [];
|
|
15
|
+
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[], Acc extends TLiteralValue[][] = []> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? (L extends TLiteral<infer S extends TLiteralValue> ? TFromTemplateLiteralKinds<R, [...Acc, [S]]> : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<R, [...Acc, TFromTemplateLiteralUnionKinds<S>]> : L extends TBoolean ? TFromTemplateLiteralKinds<R, [...Acc, ['true', 'false']]> : Acc) : Acc;
|
|
16
|
+
export declare function TemplateLiteralExpressionGenerate(expression: Expression): IterableIterator<string>;
|
|
17
|
+
export type TTemplateLiteralGenerate<T extends TTemplateLiteral, F = TIsTemplateLiteralFinite<T>> = F extends true ? (T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<S> extends infer R extends string[][] ? TStringReduce<R> : [] : []) : [];
|
|
18
|
+
/** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
|
|
19
|
+
export declare function TemplateLiteralGenerate<T extends TTemplateLiteral>(schema: T): TTemplateLiteralGenerate<T>;
|
|
15
20
|
export {};
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TemplateLiteralGenerate = exports.TemplateLiteralGenerateError = void 0;
|
|
4
|
+
exports.TemplateLiteralGenerate = exports.TemplateLiteralExpressionGenerate = exports.TemplateLiteralGenerateError = void 0;
|
|
5
|
+
const finite_1 = require("./finite");
|
|
6
|
+
const parse_1 = require("./parse");
|
|
5
7
|
// ------------------------------------------------------------------
|
|
6
|
-
//
|
|
8
|
+
// TemplateLiteralGenerateError
|
|
9
|
+
// ------------------------------------------------------------------
|
|
10
|
+
class TemplateLiteralGenerateError extends Error {
|
|
11
|
+
}
|
|
12
|
+
exports.TemplateLiteralGenerateError = TemplateLiteralGenerateError;
|
|
13
|
+
// ------------------------------------------------------------------
|
|
14
|
+
// TemplateLiteralExpressionGenerate
|
|
7
15
|
// ------------------------------------------------------------------
|
|
8
16
|
// prettier-ignore
|
|
9
17
|
function* GenerateReduce(buffer) {
|
|
@@ -17,24 +25,18 @@ function* GenerateReduce(buffer) {
|
|
|
17
25
|
}
|
|
18
26
|
// prettier-ignore
|
|
19
27
|
function* GenerateAnd(expression) {
|
|
20
|
-
return yield* GenerateReduce(expression.expr.map((expr) => [...
|
|
28
|
+
return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
|
|
21
29
|
}
|
|
22
30
|
// prettier-ignore
|
|
23
31
|
function* GenerateOr(expression) {
|
|
24
32
|
for (const expr of expression.expr)
|
|
25
|
-
yield*
|
|
33
|
+
yield* TemplateLiteralExpressionGenerate(expr);
|
|
26
34
|
}
|
|
27
35
|
// prettier-ignore
|
|
28
36
|
function* GenerateConst(expression) {
|
|
29
37
|
return yield expression.const;
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
// TemplateLiteralGenerateError
|
|
33
|
-
// ------------------------------------------------------------------
|
|
34
|
-
class TemplateLiteralGenerateError extends Error {
|
|
35
|
-
}
|
|
36
|
-
exports.TemplateLiteralGenerateError = TemplateLiteralGenerateError;
|
|
37
|
-
function* TemplateLiteralGenerate(expression) {
|
|
39
|
+
function* TemplateLiteralExpressionGenerate(expression) {
|
|
38
40
|
return expression.type === 'and'
|
|
39
41
|
? yield* GenerateAnd(expression)
|
|
40
42
|
: expression.type === 'or'
|
|
@@ -45,4 +47,13 @@ function* TemplateLiteralGenerate(expression) {
|
|
|
45
47
|
throw new TemplateLiteralGenerateError('Unknown expression');
|
|
46
48
|
})();
|
|
47
49
|
}
|
|
50
|
+
exports.TemplateLiteralExpressionGenerate = TemplateLiteralExpressionGenerate;
|
|
51
|
+
/** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
|
|
52
|
+
function TemplateLiteralGenerate(schema) {
|
|
53
|
+
const expression = (0, parse_1.TemplateLiteralParseExact)(schema.pattern);
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
return ((0, finite_1.IsTemplateLiteralExpressionFinite)(expression)
|
|
56
|
+
? [...TemplateLiteralExpressionGenerate(expression)]
|
|
57
|
+
: []);
|
|
58
|
+
}
|
|
48
59
|
exports.TemplateLiteralGenerate = TemplateLiteralGenerate;
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
__exportStar(require("./finite"), exports);
|
|
19
19
|
__exportStar(require("./generate"), exports);
|
|
20
20
|
__exportStar(require("./syntax"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./parse"), exports);
|
|
22
22
|
__exportStar(require("./pattern"), exports);
|
|
23
23
|
__exportStar(require("./union"), exports);
|
|
24
24
|
__exportStar(require("./template-literal"), exports);
|
|
@@ -132,17 +132,22 @@ function And(pattern) {
|
|
|
132
132
|
(expressions.length === 1) ? expressions[0] :
|
|
133
133
|
{ type: 'and', expr: expressions });
|
|
134
134
|
}
|
|
135
|
+
// ------------------------------------------------------------------
|
|
136
|
+
// TemplateLiteralParse
|
|
137
|
+
// ------------------------------------------------------------------
|
|
135
138
|
/** Parses a pattern and returns an expression tree */
|
|
136
|
-
// prettier-ignore
|
|
137
139
|
function TemplateLiteralParse(pattern) {
|
|
140
|
+
// prettier-ignore
|
|
138
141
|
return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
|
|
139
142
|
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
140
143
|
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
141
144
|
{ type: 'const', const: pattern });
|
|
142
145
|
}
|
|
143
146
|
exports.TemplateLiteralParse = TemplateLiteralParse;
|
|
147
|
+
// ------------------------------------------------------------------
|
|
148
|
+
// TemplateLiteralParseExact
|
|
149
|
+
// ------------------------------------------------------------------
|
|
144
150
|
/** Parses a pattern and strips forward and trailing ^ and $ */
|
|
145
|
-
// prettier-ignore
|
|
146
151
|
function TemplateLiteralParseExact(pattern) {
|
|
147
152
|
return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
|
|
148
153
|
}
|
|
@@ -5,16 +5,16 @@ import { type TBoolean } from '../boolean/index';
|
|
|
5
5
|
import { type TBigInt } from '../bigint/index';
|
|
6
6
|
import { type TNumber } from '../number/index';
|
|
7
7
|
import { type TString } from '../string/index';
|
|
8
|
-
import {
|
|
8
|
+
import { type TUnionEvaluated } from '../union/index';
|
|
9
9
|
declare function FromUnion(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
10
10
|
declare function FromTerminal(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
11
11
|
type FromUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [TLiteral<Trim<L>>, ...FromUnionLiteral<R>] : T extends `${infer L}` ? [TLiteral<Trim<L>>] : [
|
|
12
12
|
];
|
|
13
|
-
type FromUnion<T extends string> =
|
|
13
|
+
type FromUnion<T extends string> = TUnionEvaluated<FromUnionLiteral<T>>;
|
|
14
14
|
type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
|
|
15
15
|
type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$${infer R}` ? [TLiteral<L>, ...FromString<R>] : T extends `${infer L}` ? [TLiteral<L>] : [
|
|
16
16
|
];
|
|
17
|
-
export type
|
|
17
|
+
export type TTemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
|
|
18
18
|
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
|
|
19
19
|
export declare function TemplateLiteralSyntax(syntax: string): TTemplateLiteralKind[];
|
|
20
20
|
export {};
|
|
@@ -23,7 +23,7 @@ function* FromUnion(syntax) {
|
|
|
23
23
|
const literals = trim.split('|').map((literal) => (0, index_1.Literal)(literal.trim()));
|
|
24
24
|
return (literals.length === 0 ? (0, index_7.Never)() :
|
|
25
25
|
literals.length === 1 ? literals[0] :
|
|
26
|
-
(0, index_6.
|
|
26
|
+
(0, index_6.UnionEvaluated)(literals));
|
|
27
27
|
})());
|
|
28
28
|
}
|
|
29
29
|
// prettier-ignore
|
|
@@ -53,7 +53,6 @@ function* FromSyntax(syntax) {
|
|
|
53
53
|
}
|
|
54
54
|
yield (0, index_1.Literal)(syntax);
|
|
55
55
|
}
|
|
56
|
-
// prettier-ignore
|
|
57
56
|
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
|
|
58
57
|
function TemplateLiteralSyntax(syntax) {
|
|
59
58
|
return [...FromSyntax(syntax)];
|
|
@@ -9,7 +9,7 @@ import type { TString } from '../string/index';
|
|
|
9
9
|
import type { TBoolean } from '../boolean/index';
|
|
10
10
|
import type { TNever } from '../never/index';
|
|
11
11
|
import type { Static } from '../static/index';
|
|
12
|
-
import {
|
|
12
|
+
import { TTemplateLiteralSyntax } from './syntax';
|
|
13
13
|
import { EmptyString } from '../helpers/index';
|
|
14
14
|
import { Kind } from '../symbols/index';
|
|
15
15
|
type TemplateLiteralStaticKind<T, Acc extends string> = T extends TUnion<infer U> ? {
|
|
@@ -24,7 +24,7 @@ export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLi
|
|
|
24
24
|
pattern: string;
|
|
25
25
|
}
|
|
26
26
|
/** `[Json]` Creates a TemplateLiteral type from template dsl string */
|
|
27
|
-
export declare function TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions):
|
|
27
|
+
export declare function TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TTemplateLiteralSyntax<T>;
|
|
28
28
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
29
29
|
export declare function TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
|
|
30
30
|
export {};
|