@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
|
@@ -2,9 +2,9 @@ import type { TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
3
3
|
import type { TUnion } from '../union/index.mjs';
|
|
4
4
|
import type { TTuple } from '../tuple/index.mjs';
|
|
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.mjs';
|
|
|
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.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
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.mjs';
|
|
|
6
6
|
import type { TInteger } from '../integer/index.mjs';
|
|
7
7
|
import type { TBigInt } from '../bigint/index.mjs';
|
|
8
8
|
import type { TLiteral } from '../literal/index.mjs';
|
|
9
|
-
import type { Expression } from './
|
|
9
|
+
import type { Expression } from './parse.mjs';
|
|
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,3 +1,4 @@
|
|
|
1
|
+
import { TemplateLiteralParseExact } from './parse.mjs';
|
|
1
2
|
// ------------------------------------------------------------------
|
|
2
3
|
// TemplateLiteralFiniteError
|
|
3
4
|
// ------------------------------------------------------------------
|
|
@@ -28,12 +29,20 @@ function IsBooleanExpression(expression) {
|
|
|
28
29
|
function IsStringExpression(expression) {
|
|
29
30
|
return expression.type === 'const' && expression.const === '.*';
|
|
30
31
|
}
|
|
32
|
+
// ------------------------------------------------------------------
|
|
33
|
+
// IsTemplateLiteralExpressionFinite
|
|
34
|
+
// ------------------------------------------------------------------
|
|
31
35
|
// prettier-ignore
|
|
32
|
-
export function
|
|
33
|
-
return (
|
|
34
|
-
|
|
35
|
-
(expression.type === 'and') ? expression.expr.every((expr) =>
|
|
36
|
-
(expression.type === 'or') ? expression.expr.every((expr) =>
|
|
36
|
+
export function IsTemplateLiteralExpressionFinite(expression) {
|
|
37
|
+
return (IsNumberExpression(expression) || IsStringExpression(expression) ? false :
|
|
38
|
+
IsBooleanExpression(expression) ? true :
|
|
39
|
+
(expression.type === 'and') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
40
|
+
(expression.type === 'or') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
|
|
37
41
|
(expression.type === 'const') ? true :
|
|
38
42
|
(() => { throw new TemplateLiteralFiniteError(`Unknown expression type`); })());
|
|
39
43
|
}
|
|
44
|
+
/** Returns true if this TemplateLiteral resolves to a finite set of values */
|
|
45
|
+
export function IsTemplateLiteralFinite(schema) {
|
|
46
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
47
|
+
return IsTemplateLiteralExpressionFinite(expression);
|
|
48
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { TIsTemplateLiteralFinite } from './finite.mjs';
|
|
2
|
+
import type { Assert } from '../helpers/index.mjs';
|
|
3
|
+
import type { TBoolean } from '../boolean/index.mjs';
|
|
1
4
|
import type { TTemplateLiteral, TTemplateLiteralKind } from './index.mjs';
|
|
2
5
|
import type { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
3
|
-
import type { Expression } from './
|
|
6
|
+
import type { Expression } from './parse.mjs';
|
|
4
7
|
import type { TUnion } from '../union/index.mjs';
|
|
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,5 +1,12 @@
|
|
|
1
|
+
import { IsTemplateLiteralExpressionFinite } from './finite.mjs';
|
|
2
|
+
import { TemplateLiteralParseExact } from './parse.mjs';
|
|
1
3
|
// ------------------------------------------------------------------
|
|
2
|
-
//
|
|
4
|
+
// TemplateLiteralGenerateError
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
export class TemplateLiteralGenerateError extends Error {
|
|
7
|
+
}
|
|
8
|
+
// ------------------------------------------------------------------
|
|
9
|
+
// TemplateLiteralExpressionGenerate
|
|
3
10
|
// ------------------------------------------------------------------
|
|
4
11
|
// prettier-ignore
|
|
5
12
|
function* GenerateReduce(buffer) {
|
|
@@ -13,23 +20,18 @@ function* GenerateReduce(buffer) {
|
|
|
13
20
|
}
|
|
14
21
|
// prettier-ignore
|
|
15
22
|
function* GenerateAnd(expression) {
|
|
16
|
-
return yield* GenerateReduce(expression.expr.map((expr) => [...
|
|
23
|
+
return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
|
|
17
24
|
}
|
|
18
25
|
// prettier-ignore
|
|
19
26
|
function* GenerateOr(expression) {
|
|
20
27
|
for (const expr of expression.expr)
|
|
21
|
-
yield*
|
|
28
|
+
yield* TemplateLiteralExpressionGenerate(expr);
|
|
22
29
|
}
|
|
23
30
|
// prettier-ignore
|
|
24
31
|
function* GenerateConst(expression) {
|
|
25
32
|
return yield expression.const;
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
// TemplateLiteralGenerateError
|
|
29
|
-
// ------------------------------------------------------------------
|
|
30
|
-
export class TemplateLiteralGenerateError extends Error {
|
|
31
|
-
}
|
|
32
|
-
export function* TemplateLiteralGenerate(expression) {
|
|
34
|
+
export function* TemplateLiteralExpressionGenerate(expression) {
|
|
33
35
|
return expression.type === 'and'
|
|
34
36
|
? yield* GenerateAnd(expression)
|
|
35
37
|
: expression.type === 'or'
|
|
@@ -40,3 +42,11 @@ export function* TemplateLiteralGenerate(expression) {
|
|
|
40
42
|
throw new TemplateLiteralGenerateError('Unknown expression');
|
|
41
43
|
})();
|
|
42
44
|
}
|
|
45
|
+
/** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
|
|
46
|
+
export function TemplateLiteralGenerate(schema) {
|
|
47
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
48
|
+
// prettier-ignore
|
|
49
|
+
return (IsTemplateLiteralExpressionFinite(expression)
|
|
50
|
+
? [...TemplateLiteralExpressionGenerate(expression)]
|
|
51
|
+
: []);
|
|
52
|
+
}
|
|
@@ -127,16 +127,21 @@ function And(pattern) {
|
|
|
127
127
|
(expressions.length === 1) ? expressions[0] :
|
|
128
128
|
{ type: 'and', expr: expressions });
|
|
129
129
|
}
|
|
130
|
+
// ------------------------------------------------------------------
|
|
131
|
+
// TemplateLiteralParse
|
|
132
|
+
// ------------------------------------------------------------------
|
|
130
133
|
/** Parses a pattern and returns an expression tree */
|
|
131
|
-
// prettier-ignore
|
|
132
134
|
export function TemplateLiteralParse(pattern) {
|
|
135
|
+
// prettier-ignore
|
|
133
136
|
return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
|
|
134
137
|
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
135
138
|
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
136
139
|
{ type: 'const', const: pattern });
|
|
137
140
|
}
|
|
141
|
+
// ------------------------------------------------------------------
|
|
142
|
+
// TemplateLiteralParseExact
|
|
143
|
+
// ------------------------------------------------------------------
|
|
138
144
|
/** Parses a pattern and strips forward and trailing ^ and $ */
|
|
139
|
-
// prettier-ignore
|
|
140
145
|
export function TemplateLiteralParseExact(pattern) {
|
|
141
146
|
return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
|
|
142
147
|
}
|
|
@@ -5,16 +5,16 @@ import { type TBoolean } from '../boolean/index.mjs';
|
|
|
5
5
|
import { type TBigInt } from '../bigint/index.mjs';
|
|
6
6
|
import { type TNumber } from '../number/index.mjs';
|
|
7
7
|
import { type TString } from '../string/index.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { type TUnionEvaluated } from '../union/index.mjs';
|
|
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 {};
|
|
@@ -3,7 +3,7 @@ import { Boolean } from '../boolean/index.mjs';
|
|
|
3
3
|
import { BigInt } from '../bigint/index.mjs';
|
|
4
4
|
import { Number } from '../number/index.mjs';
|
|
5
5
|
import { String } from '../string/index.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
7
7
|
import { Never } from '../never/index.mjs';
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// SyntaxParsers
|
|
@@ -19,7 +19,7 @@ function* FromUnion(syntax) {
|
|
|
19
19
|
const literals = trim.split('|').map((literal) => Literal(literal.trim()));
|
|
20
20
|
return (literals.length === 0 ? Never() :
|
|
21
21
|
literals.length === 1 ? literals[0] :
|
|
22
|
-
|
|
22
|
+
UnionEvaluated(literals));
|
|
23
23
|
})());
|
|
24
24
|
}
|
|
25
25
|
// prettier-ignore
|
|
@@ -49,7 +49,6 @@ function* FromSyntax(syntax) {
|
|
|
49
49
|
}
|
|
50
50
|
yield Literal(syntax);
|
|
51
51
|
}
|
|
52
|
-
// prettier-ignore
|
|
53
52
|
/** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
|
|
54
53
|
export function TemplateLiteralSyntax(syntax) {
|
|
55
54
|
return [...FromSyntax(syntax)];
|
|
@@ -9,7 +9,7 @@ import type { TString } from '../string/index.mjs';
|
|
|
9
9
|
import type { TBoolean } from '../boolean/index.mjs';
|
|
10
10
|
import type { TNever } from '../never/index.mjs';
|
|
11
11
|
import type { Static } from '../static/index.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import { TTemplateLiteralSyntax } from './syntax.mjs';
|
|
13
13
|
import { EmptyString } from '../helpers/index.mjs';
|
|
14
14
|
import { Kind } from '../symbols/index.mjs';
|
|
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 {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TemplateLiteralPattern } from './pattern.mjs';
|
|
2
1
|
import { TemplateLiteralSyntax } from './syntax.mjs';
|
|
2
|
+
import { TemplateLiteralPattern } from './pattern.mjs';
|
|
3
3
|
import { IsString } from '../guard/value.mjs';
|
|
4
4
|
import { Kind } from '../symbols/index.mjs';
|
|
5
5
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
@@ -3,5 +3,5 @@ import { type TUnion } from '../union/index.mjs';
|
|
|
3
3
|
import { type TLiteral } from '../literal/index.mjs';
|
|
4
4
|
import { type TString } from '../string/index.mjs';
|
|
5
5
|
import { type TNever } from '../never/index.mjs';
|
|
6
|
-
/**
|
|
7
|
-
export declare function TemplateLiteralToUnion(
|
|
6
|
+
/** Returns a Union from the given TemplateLiteral */
|
|
7
|
+
export declare function TemplateLiteralToUnion(schema: TTemplateLiteral): TNever | TString | TUnion<TLiteral[]>;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Union } from '../union/index.mjs';
|
|
2
2
|
import { Literal } from '../literal/index.mjs';
|
|
3
|
-
import { String } from '../string/index.mjs';
|
|
4
3
|
import { TemplateLiteralGenerate } from './generate.mjs';
|
|
5
|
-
import { TemplateLiteralParseExact } from './parser.mjs';
|
|
6
|
-
import { IsTemplateLiteralFinite } from './finite.mjs';
|
|
7
4
|
// ------------------------------------------------------------------
|
|
8
5
|
// TemplateLiteralToUnion
|
|
9
6
|
// ------------------------------------------------------------------
|
|
10
|
-
/**
|
|
11
|
-
export function TemplateLiteralToUnion(
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const literals = [...TemplateLiteralGenerate(expression)].map((value) => Literal(value));
|
|
16
|
-
return Union(literals);
|
|
7
|
+
/** Returns a Union from the given TemplateLiteral */
|
|
8
|
+
export function TemplateLiteralToUnion(schema) {
|
|
9
|
+
const R = TemplateLiteralGenerate(schema);
|
|
10
|
+
const L = R.map((S) => Literal(S));
|
|
11
|
+
return Union(L);
|
|
17
12
|
}
|
|
@@ -3,7 +3,6 @@ import { TransformKind } from '../symbols/index.mjs';
|
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
// prettier-ignore
|
|
7
6
|
import { IsTransform } from '../guard/type.mjs';
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
// TransformBuilders
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import { Kind } from '../symbols/index.mjs';
|
|
4
|
-
type
|
|
5
|
-
type TupleStatic<T extends TSchema[], P extends unknown[], R extends unknown[] = TupleStaticRest<T, P>> = R;
|
|
4
|
+
type TupleStatic<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TupleStatic<R, P, [...Acc, Static<L, P>]> : Acc;
|
|
6
5
|
export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
7
6
|
[Kind]: 'Tuple';
|
|
8
7
|
static: TupleStatic<T, this['params']>;
|
|
@@ -34,7 +34,7 @@ import { type TRequired, type TRequiredFromMappedResult } from '../required/inde
|
|
|
34
34
|
import { type TRest } from '../rest/index.mjs';
|
|
35
35
|
import { type TSchema, type SchemaOptions } from '../schema/index.mjs';
|
|
36
36
|
import { type TString, type StringOptions } from '../string/index.mjs';
|
|
37
|
-
import { type TTemplateLiteral, type TTemplateLiteralKind, type
|
|
37
|
+
import { type TTemplateLiteral, type TTemplateLiteralKind, type TTemplateLiteralSyntax } from '../template-literal/index.mjs';
|
|
38
38
|
import { TransformDecodeBuilder } from '../transform/index.mjs';
|
|
39
39
|
import { type TTuple } from '../tuple/index.mjs';
|
|
40
40
|
import { Union } from '../union/index.mjs';
|
|
@@ -157,7 +157,7 @@ export declare class JsonTypeBuilder {
|
|
|
157
157
|
/** `[Json]` Creates a String type */
|
|
158
158
|
String(options?: StringOptions): TString;
|
|
159
159
|
/** `[Json]` Creates a TemplateLiteral type from template dsl string */
|
|
160
|
-
TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions):
|
|
160
|
+
TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TTemplateLiteralSyntax<T>;
|
|
161
161
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
162
162
|
TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
|
|
163
163
|
/** `[Json]` Creates a Transform type */
|
|
@@ -3,15 +3,11 @@ import { type TNever } from '../never/index.mjs';
|
|
|
3
3
|
import { type TOptional } from '../optional/index.mjs';
|
|
4
4
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
5
|
import type { TUnion } from './union-type.mjs';
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
declare function RemoveOptionalFromType<T extends TSchema>(T: T): RemoveOptionalFromType<T>;
|
|
12
|
-
type ResolveUnion<T extends TSchema[], R extends TSchema[] = RemoveOptionalFromRest<T>> = (IsUnionOptional<T> extends true ? TOptional<TUnion<R>> : TUnion<R>);
|
|
13
|
-
declare function ResolveUnion<T extends TSchema[]>(T: T, options: SchemaOptions): ResolveUnion<T>;
|
|
14
|
-
export type UnionEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : ResolveUnion<T>);
|
|
6
|
+
type TIsUnionOptional<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<TSchema> ? true : TIsUnionOptional<R> : false);
|
|
7
|
+
type TRemoveOptionalFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<R, [...Acc, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<R, [...Acc, L]> : Acc);
|
|
8
|
+
type TRemoveOptionalFromType<T extends TSchema> = (T extends TReadonly<infer S extends TSchema> ? TReadonly<TRemoveOptionalFromType<S>> : T extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromType<S> : T);
|
|
9
|
+
type TResolveUnion<T extends TSchema[], R extends TSchema[] = TRemoveOptionalFromRest<T>> = (TIsUnionOptional<T> extends true ? TOptional<TUnion<R>> : TUnion<R>);
|
|
10
|
+
export type TUnionEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TResolveUnion<T>);
|
|
15
11
|
/** `[Json]` Creates an evaluated Union type */
|
|
16
|
-
export declare function UnionEvaluated<T extends TSchema[], R =
|
|
12
|
+
export declare function UnionEvaluated<T extends TSchema[], R = TUnionEvaluated<T>>(T: [...T], options?: SchemaOptions): R;
|
|
17
13
|
export {};
|
|
@@ -19,8 +19,13 @@ function IsUnionOptional(T) {
|
|
|
19
19
|
: false);
|
|
20
20
|
}
|
|
21
21
|
// prettier-ignore
|
|
22
|
-
function RemoveOptionalFromRest(T) {
|
|
23
|
-
|
|
22
|
+
function RemoveOptionalFromRest(T, Acc = []) {
|
|
23
|
+
const [L, ...R] = T;
|
|
24
|
+
return (T.length > 0
|
|
25
|
+
? IsOptional(L)
|
|
26
|
+
? RemoveOptionalFromRest(R, [...Acc, RemoveOptionalFromType(L)])
|
|
27
|
+
: RemoveOptionalFromRest(R, [...Acc, L])
|
|
28
|
+
: Acc);
|
|
24
29
|
}
|
|
25
30
|
// prettier-ignore
|
|
26
31
|
function RemoveOptionalFromType(T) {
|
|
@@ -94,7 +94,7 @@ function Default(schema, references, value) {
|
|
|
94
94
|
// ------------------------------------------------------------------
|
|
95
95
|
// Cast
|
|
96
96
|
// ------------------------------------------------------------------
|
|
97
|
-
function
|
|
97
|
+
function FromArray(schema, references, value) {
|
|
98
98
|
if (Check(schema, references, value))
|
|
99
99
|
return Clone(value);
|
|
100
100
|
const created = IsArray(value) ? Clone(value) : Create(schema, references);
|
|
@@ -108,7 +108,7 @@ function TArray(schema, references, value) {
|
|
|
108
108
|
throw new ValueCastArrayUniqueItemsTypeError(schema, unique);
|
|
109
109
|
return unique;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function FromConstructor(schema, references, value) {
|
|
112
112
|
if (Check(schema, references, value))
|
|
113
113
|
return Create(schema, references);
|
|
114
114
|
const required = new Set(schema.returns.required || []);
|
|
@@ -120,15 +120,15 @@ function TConstructor(schema, references, value) {
|
|
|
120
120
|
}
|
|
121
121
|
return result;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function FromIntersect(schema, references, value) {
|
|
124
124
|
const created = Create(schema, references);
|
|
125
125
|
const mapped = IsPlainObject(created) && IsPlainObject(value) ? { ...created, ...value } : value;
|
|
126
126
|
return Check(schema, references, mapped) ? mapped : Create(schema, references);
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function FromNever(schema, references, value) {
|
|
129
129
|
throw new ValueCastNeverTypeError(schema);
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function FromObject(schema, references, value) {
|
|
132
132
|
if (Check(schema, references, value))
|
|
133
133
|
return value;
|
|
134
134
|
if (value === null || typeof value !== 'object')
|
|
@@ -151,7 +151,7 @@ function TObject(schema, references, value) {
|
|
|
151
151
|
}
|
|
152
152
|
return result;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function FromRecord(schema, references, value) {
|
|
155
155
|
if (Check(schema, references, value))
|
|
156
156
|
return Clone(value);
|
|
157
157
|
if (value === null || typeof value !== 'object' || Array.isArray(value) || value instanceof Date)
|
|
@@ -164,13 +164,13 @@ function TRecord(schema, references, value) {
|
|
|
164
164
|
}
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function FromRef(schema, references, value) {
|
|
168
168
|
return Visit(Deref(schema, references), references, value);
|
|
169
169
|
}
|
|
170
|
-
function
|
|
170
|
+
function FromThis(schema, references, value) {
|
|
171
171
|
return Visit(Deref(schema, references), references, value);
|
|
172
172
|
}
|
|
173
|
-
function
|
|
173
|
+
function FromTuple(schema, references, value) {
|
|
174
174
|
if (Check(schema, references, value))
|
|
175
175
|
return Clone(value);
|
|
176
176
|
if (!IsArray(value))
|
|
@@ -179,7 +179,7 @@ function TTuple(schema, references, value) {
|
|
|
179
179
|
return [];
|
|
180
180
|
return schema.items.map((schema, index) => Visit(schema, references, value[index]));
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function FromUnion(schema, references, value) {
|
|
183
183
|
return Check(schema, references, value) ? Clone(value) : CastUnion(schema, references, value);
|
|
184
184
|
}
|
|
185
185
|
function Visit(schema, references, value) {
|
|
@@ -190,25 +190,25 @@ function Visit(schema, references, value) {
|
|
|
190
190
|
// Structural
|
|
191
191
|
// --------------------------------------------------------------
|
|
192
192
|
case 'Array':
|
|
193
|
-
return
|
|
193
|
+
return FromArray(schema_, references_, value);
|
|
194
194
|
case 'Constructor':
|
|
195
|
-
return
|
|
195
|
+
return FromConstructor(schema_, references_, value);
|
|
196
196
|
case 'Intersect':
|
|
197
|
-
return
|
|
197
|
+
return FromIntersect(schema_, references_, value);
|
|
198
198
|
case 'Never':
|
|
199
|
-
return
|
|
199
|
+
return FromNever(schema_, references_, value);
|
|
200
200
|
case 'Object':
|
|
201
|
-
return
|
|
201
|
+
return FromObject(schema_, references_, value);
|
|
202
202
|
case 'Record':
|
|
203
|
-
return
|
|
203
|
+
return FromRecord(schema_, references_, value);
|
|
204
204
|
case 'Ref':
|
|
205
|
-
return
|
|
205
|
+
return FromRef(schema_, references_, value);
|
|
206
206
|
case 'This':
|
|
207
|
-
return
|
|
207
|
+
return FromThis(schema_, references_, value);
|
|
208
208
|
case 'Tuple':
|
|
209
|
-
return
|
|
209
|
+
return FromTuple(schema_, references_, value);
|
|
210
210
|
case 'Union':
|
|
211
|
-
return
|
|
211
|
+
return FromUnion(schema_, references_, value);
|
|
212
212
|
// --------------------------------------------------------------
|
|
213
213
|
// DefaultClone
|
|
214
214
|
// --------------------------------------------------------------
|