@sinclair/typebox 0.32.0-dev-26 → 0.32.0-dev-28
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 +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.mjs +2 -6
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/composite/composite.d.mts +1 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/const/const.mjs +6 -6
- package/build/import/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/constructor/constructor.mjs +1 -1
- package/build/import/type/deref/deref.mjs +1 -2
- package/build/import/type/discard/discard.mjs +2 -2
- package/build/import/type/enum/enum.mjs +3 -0
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +5 -5
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +7 -7
- package/build/import/type/exclude/exclude.mjs +0 -1
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +4 -5
- package/build/import/type/extends/extends-from-mapped-result.d.mts +5 -5
- package/build/import/type/extends/extends-from-mapped-result.mjs +7 -7
- package/build/import/type/extends/extends.mjs +0 -1
- package/build/import/type/extract/extract-from-mapped-result.d.mts +5 -5
- package/build/import/type/extract/extract-from-mapped-result.mjs +7 -7
- package/build/import/type/extract/extract.d.mts +1 -2
- package/build/import/type/extract/extract.mjs +4 -2
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/index.d.mts +1 -1
- package/build/import/type/index.mjs +1 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +4 -5
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/import/type/indexed/indexed-property-keys.mjs +3 -5
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +9 -27
- package/build/import/type/intersect/intersect-evaluated.mjs +3 -13
- package/build/import/type/intrinsic/capitalize.d.mts +2 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +1 -1
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -5
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -3
- package/build/import/type/intrinsic/intrinsic.mjs +2 -5
- package/build/import/type/intrinsic/lowercase.d.mts +2 -2
- package/build/import/type/intrinsic/uncapitalize.d.mts +2 -2
- package/build/import/type/intrinsic/uppercase.d.mts +2 -2
- package/build/import/type/iterator/iterator.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -3
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -4
- package/build/import/type/keyof/keyof-property-keys.d.mts +3 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +9 -15
- package/build/import/type/keyof/keyof.mjs +2 -8
- package/build/import/type/mapped/mapped.d.mts +6 -1
- package/build/import/type/mapped/mapped.mjs +21 -14
- package/build/import/type/not/not.mjs +1 -1
- package/build/import/type/object/object.d.mts +1 -1
- package/build/import/type/object/object.mjs +0 -1
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +4 -5
- package/build/import/type/omit/omit-from-mapped-result.d.mts +11 -0
- package/build/import/type/omit/omit-from-mapped-result.mjs +17 -0
- package/build/import/type/omit/omit.d.mts +6 -3
- package/build/import/type/omit/omit.mjs +11 -9
- package/build/import/type/optional/optional-from-mapped-result.d.mts +5 -5
- package/build/import/type/optional/optional-from-mapped-result.mjs +7 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +5 -5
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -4
- package/build/import/type/partial/partial.d.mts +2 -3
- package/build/import/type/partial/partial.mjs +8 -21
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +4 -5
- package/build/import/type/pick/pick-from-mapped-result.d.mts +11 -0
- package/build/import/type/pick/pick-from-mapped-result.mjs +17 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +11 -10
- package/build/import/type/promise/promise.mjs +1 -1
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +5 -5
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -4
- package/build/import/type/record/record.d.mts +5 -3
- package/build/import/type/record/record.mjs +13 -5
- package/build/import/type/ref/ref.mjs +1 -1
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/required/required-from-mapped-result.d.mts +5 -5
- package/build/import/type/required/required-from-mapped-result.mjs +7 -7
- package/build/import/type/required/required.d.mts +2 -3
- package/build/import/type/required/required.mjs +4 -14
- package/build/import/type/rest/rest.d.mts +2 -2
- package/build/import/type/rest/rest.mjs +1 -2
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/sets/index.d.mts +1 -0
- package/build/import/type/sets/index.mjs +1 -0
- package/build/import/type/sets/set.d.mts +24 -0
- package/build/import/type/sets/set.mjs +35 -0
- package/build/import/type/strict/strict.d.mts +1 -1
- package/build/import/type/strict/strict.mjs +1 -1
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/template-literal.d.mts +1 -1
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/type/type/json.d.mts +6 -2
- package/build/import/type/union/union-evaluated.mjs +3 -14
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.js +2 -6
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/composite/composite.d.ts +1 -2
- package/build/require/type/composite/composite.js +5 -6
- package/build/require/type/const/const.js +6 -6
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/constructor/constructor.js +1 -1
- package/build/require/type/deref/deref.js +0 -1
- package/build/require/type/discard/discard.js +2 -2
- package/build/require/type/enum/enum.js +3 -0
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +5 -5
- package/build/require/type/exclude/exclude-from-mapped-result.js +7 -7
- package/build/require/type/exclude/exclude.js +0 -1
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/require/type/extends/extends-from-mapped-key.js +4 -5
- package/build/require/type/extends/extends-from-mapped-result.d.ts +5 -5
- package/build/require/type/extends/extends-from-mapped-result.js +7 -7
- package/build/require/type/extends/extends.js +0 -1
- package/build/require/type/extract/extract-from-mapped-result.d.ts +5 -5
- package/build/require/type/extract/extract-from-mapped-result.js +7 -7
- package/build/require/type/extract/extract.d.ts +1 -2
- package/build/require/type/extract/extract.js +4 -3
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/index.d.ts +1 -1
- package/build/require/type/index.js +1 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-key.js +4 -5
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/require/type/indexed/indexed-property-keys.js +3 -5
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +9 -27
- package/build/require/type/intersect/intersect-evaluated.js +3 -13
- package/build/require/type/intrinsic/capitalize.d.ts +2 -2
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +1 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +4 -5
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -3
- package/build/require/type/intrinsic/intrinsic.js +2 -5
- package/build/require/type/intrinsic/lowercase.d.ts +2 -2
- package/build/require/type/intrinsic/uncapitalize.d.ts +2 -2
- package/build/require/type/intrinsic/uppercase.d.ts +2 -2
- package/build/require/type/iterator/iterator.js +1 -1
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -3
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.d.ts +3 -3
- package/build/require/type/keyof/keyof-property-keys.js +9 -15
- package/build/require/type/keyof/keyof.js +2 -8
- package/build/require/type/mapped/mapped.d.ts +6 -1
- package/build/require/type/mapped/mapped.js +21 -14
- package/build/require/type/not/not.js +1 -1
- package/build/require/type/object/object.d.ts +1 -1
- package/build/require/type/object/object.js +0 -1
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-from-mapped-key.js +4 -5
- package/build/require/type/omit/omit-from-mapped-result.d.ts +11 -0
- package/build/require/type/omit/omit-from-mapped-result.js +22 -0
- package/build/require/type/omit/omit.d.ts +6 -3
- package/build/require/type/omit/omit.js +10 -8
- package/build/require/type/optional/optional-from-mapped-result.d.ts +5 -5
- package/build/require/type/optional/optional-from-mapped-result.js +7 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +5 -5
- package/build/require/type/partial/partial-from-mapped-result.js +4 -4
- package/build/require/type/partial/partial.d.ts +2 -3
- package/build/require/type/partial/partial.js +8 -21
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-from-mapped-key.js +4 -5
- package/build/require/type/pick/pick-from-mapped-result.d.ts +11 -0
- package/build/require/type/pick/pick-from-mapped-result.js +22 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -9
- package/build/require/type/promise/promise.js +1 -1
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +5 -5
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -4
- package/build/require/type/record/record.d.ts +5 -3
- package/build/require/type/record/record.js +12 -4
- package/build/require/type/ref/ref.js +1 -1
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/required/required-from-mapped-result.d.ts +5 -5
- package/build/require/type/required/required-from-mapped-result.js +7 -7
- package/build/require/type/required/required.d.ts +2 -3
- package/build/require/type/required/required.js +4 -14
- package/build/require/type/rest/rest.d.ts +2 -2
- package/build/require/type/rest/rest.js +1 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/sets/index.d.ts +1 -0
- package/build/require/type/{operators → sets}/index.js +1 -1
- package/build/require/type/sets/set.d.ts +24 -0
- package/build/require/type/sets/set.js +47 -0
- package/build/require/type/strict/strict.d.ts +1 -1
- package/build/require/type/strict/strict.js +1 -1
- package/build/require/type/template-literal/parse.js +1 -1
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/template-literal.d.ts +1 -1
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/type/type/json.d.ts +6 -2
- package/build/require/type/union/union-evaluated.js +3 -14
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +68 -67
- package/build/import/type/operators/index.d.mts +0 -1
- package/build/import/type/operators/index.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +0 -24
- package/build/import/type/operators/operators.mjs +0 -77
- package/build/require/type/operators/index.d.ts +0 -1
- package/build/require/type/operators/operators.d.ts +0 -24
- package/build/require/type/operators/operators.js +0 -89
|
@@ -10,6 +10,9 @@ const index_5 = require("../patterns/index");
|
|
|
10
10
|
const index_6 = require("../indexed/index");
|
|
11
11
|
const index_7 = require("../symbols/index");
|
|
12
12
|
const type_1 = require("../clone/type");
|
|
13
|
+
// ------------------------------------------------------------------
|
|
14
|
+
// ValueGuard
|
|
15
|
+
// ------------------------------------------------------------------
|
|
13
16
|
const value_1 = require("../guard/value");
|
|
14
17
|
// ------------------------------------------------------------------
|
|
15
18
|
// TypeGuard
|
|
@@ -50,6 +53,10 @@ function FromLiteralKey(K, T, options) {
|
|
|
50
53
|
return RecordCreateFromKeys([K.toString()], T, options);
|
|
51
54
|
}
|
|
52
55
|
// prettier-ignore
|
|
56
|
+
function FromRegExpKey(K, T, options) {
|
|
57
|
+
return RecordCreateFromPattern(K.source, T, options);
|
|
58
|
+
}
|
|
59
|
+
// prettier-ignore
|
|
53
60
|
function FromStringKey(K, T, options) {
|
|
54
61
|
const pattern = (0, value_1.IsUndefined)(K.pattern) ? index_5.PatternStringExact : K.pattern;
|
|
55
62
|
return RecordCreateFromPattern(pattern, T, options);
|
|
@@ -71,9 +78,10 @@ function Record(K, T, options = {}) {
|
|
|
71
78
|
return ((0, type_2.IsUnion)(K) ? FromUnionKey(K.anyOf, T, options) :
|
|
72
79
|
(0, type_2.IsTemplateLiteral)(K) ? FromTemplateLiteralKey(K, T, options) :
|
|
73
80
|
(0, type_2.IsLiteral)(K) ? FromLiteralKey(K.const, T, options) :
|
|
74
|
-
(0, type_2.
|
|
75
|
-
(0, type_2.
|
|
76
|
-
(0, type_2.
|
|
77
|
-
(0,
|
|
81
|
+
(0, type_2.IsInteger)(K) ? FromIntegerKey(K, T, options) :
|
|
82
|
+
(0, type_2.IsNumber)(K) ? FromNumberKey(K, T, options) :
|
|
83
|
+
(0, type_2.IsRegExp)(K) ? FromRegExpKey(K, T, options) :
|
|
84
|
+
(0, type_2.IsString)(K) ? FromStringKey(K, T, options) :
|
|
85
|
+
(0, index_2.Never)(options));
|
|
78
86
|
}
|
|
79
87
|
exports.Record = Record;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Ref = void 0;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
//
|
|
7
|
+
// ValueGuard
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
const value_1 = require("../guard/value");
|
|
10
10
|
/** `[Json]` Creates a Ref type. */
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { SchemaOptions } from '../schema/index';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { TSchema } from '../schema/index';
|
|
3
|
+
import { Kind } from '../symbols/index';
|
|
4
|
+
export interface TRegExp extends TSchema {
|
|
5
|
+
[Kind]: 'RegExp';
|
|
6
|
+
static: `${string}`;
|
|
7
|
+
type: 'RegExp';
|
|
8
|
+
source: string;
|
|
9
|
+
flags: string;
|
|
10
|
+
}
|
|
11
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
5
12
|
export declare function RegExp(pattern: string, options?: SchemaOptions): TRegExp;
|
|
6
|
-
/** `[JavaScript]` Creates a
|
|
13
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
7
14
|
export declare function RegExp(regex: RegExp, options?: SchemaOptions): TRegExp;
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.RegExp = void 0;
|
|
5
5
|
const value_1 = require("../guard/value");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
|
-
/** `[JavaScript]` Creates a
|
|
7
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
8
8
|
function RegExp(unresolved, options = {}) {
|
|
9
|
-
const
|
|
10
|
-
return { ...options, [index_1.Kind]: '
|
|
9
|
+
const expr = (0, value_1.IsString)(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
|
|
10
|
+
return { ...options, [index_1.Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags };
|
|
11
11
|
}
|
|
12
12
|
exports.RegExp = RegExp;
|
|
@@ -2,10 +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 TFromProperties<
|
|
6
|
-
[K2 in keyof
|
|
5
|
+
type TFromProperties<P extends TProperties> = ({
|
|
6
|
+
[K2 in keyof P]: TRequired<P[K2]>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TRequiredFromMappedResult<
|
|
10
|
-
export declare function RequiredFromMappedResult<
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult> = (TFromProperties<R['properties']>);
|
|
9
|
+
export type TRequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (TMappedResult<P>);
|
|
10
|
+
export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -5,18 +5,18 @@ exports.RequiredFromMappedResult = void 0;
|
|
|
5
5
|
const index_1 = require("../mapped/index");
|
|
6
6
|
const required_1 = require("./required");
|
|
7
7
|
// prettier-ignore
|
|
8
|
-
function FromProperties(
|
|
9
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
10
|
-
return { ...Acc, [K2]: (0, required_1.Required)(
|
|
8
|
+
function FromProperties(P, options) {
|
|
9
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
10
|
+
return { ...Acc, [K2]: (0, required_1.Required)(P[K2], options) };
|
|
11
11
|
}, {});
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
function FromMappedResult(
|
|
15
|
-
return FromProperties(
|
|
14
|
+
function FromMappedResult(R, options) {
|
|
15
|
+
return FromProperties(R.properties, options);
|
|
16
16
|
}
|
|
17
17
|
// prettier-ignore
|
|
18
|
-
function RequiredFromMappedResult(
|
|
19
|
-
const P = FromMappedResult(
|
|
18
|
+
function RequiredFromMappedResult(R, options) {
|
|
19
|
+
const P = FromMappedResult(R, options);
|
|
20
20
|
return (0, index_1.MappedResult)(P);
|
|
21
21
|
}
|
|
22
22
|
exports.RequiredFromMappedResult = RequiredFromMappedResult;
|
|
@@ -9,12 +9,11 @@ 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
|
-
type TFromUnion<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
12
|
+
type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TRequiredResolve<L>]> : Acc);
|
|
14
13
|
type TFromProperties<T extends TProperties> = Evaluate<{
|
|
15
14
|
[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];
|
|
16
15
|
}>;
|
|
17
|
-
type TRequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<TRequiredResolve<S>> : T extends TIntersect<infer S> ? TIntersect<
|
|
16
|
+
type TRequiredResolve<T extends TSchema> = (T extends TRecursive<infer S> ? TRecursive<TRequiredResolve<S>> : T extends TIntersect<infer S> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S> ? TUnion<TFromRest<S>> : T extends TObject<infer S> ? TObject<TFromProperties<S>> : TObject<{}>);
|
|
18
17
|
export type TRequired<T extends TSchema> = TRequiredResolve<T>;
|
|
19
18
|
/** `[Json]` Constructs a type where all properties are required */
|
|
20
19
|
export declare function Required<T extends TMappedResult>(T: T, options?: SchemaOptions): TRequiredFromMappedResult<T>;
|
|
@@ -14,18 +14,8 @@ const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
const type_2 = require("../guard/type");
|
|
16
16
|
// prettier-ignore
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
return (T.length > 0
|
|
20
|
-
? FromIntersect(R, [...Acc, RequiredResolve(L)])
|
|
21
|
-
: Acc);
|
|
22
|
-
}
|
|
23
|
-
// prettier-ignore
|
|
24
|
-
function FromUnion(T, Acc = []) {
|
|
25
|
-
const [L, ...R] = T;
|
|
26
|
-
return (T.length > 0
|
|
27
|
-
? FromUnion(R, [...Acc, RequiredResolve(L)])
|
|
28
|
-
: Acc);
|
|
17
|
+
function FromRest(T) {
|
|
18
|
+
return T.map(L => RequiredResolve(L));
|
|
29
19
|
}
|
|
30
20
|
// prettier-ignore
|
|
31
21
|
function FromProperties(T) {
|
|
@@ -35,8 +25,8 @@ function FromProperties(T) {
|
|
|
35
25
|
}
|
|
36
26
|
// prettier-ignore
|
|
37
27
|
function RequiredResolve(T) {
|
|
38
|
-
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(
|
|
39
|
-
(0, type_2.IsUnion)(T) ? (0, index_2.Union)(
|
|
28
|
+
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromRest(T.allOf)) :
|
|
29
|
+
(0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromRest(T.anyOf)) :
|
|
40
30
|
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties)) :
|
|
41
31
|
(0, index_3.Object)({}));
|
|
42
32
|
}
|
|
@@ -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
|
-
|
|
5
|
+
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): TRestResolve<T>;
|
|
8
7
|
export type TRest<T extends TSchema> = TRestResolve<T>;
|
|
9
8
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
10
9
|
export declare function Rest<T extends TSchema>(T: T): TRest<T>;
|
|
10
|
+
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Rest =
|
|
4
|
+
exports.Rest = void 0;
|
|
5
5
|
const type_1 = require("../clone/type");
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// TypeGuard
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
|
-
// prettier-ignore
|
|
10
9
|
const type_2 = require("../guard/type");
|
|
11
10
|
// prettier-ignore
|
|
12
11
|
function RestResolve(T) {
|
|
@@ -15,7 +14,6 @@ function RestResolve(T) {
|
|
|
15
14
|
(0, type_2.IsTuple)(T) ? [...(T.items ?? [])] :
|
|
16
15
|
[]);
|
|
17
16
|
}
|
|
18
|
-
exports.RestResolve = RestResolve;
|
|
19
17
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
20
18
|
function Rest(T) {
|
|
21
19
|
return (0, type_1.CloneRest)(RestResolve(T));
|
|
@@ -19,6 +19,7 @@ import type { TPromise } from '../promise/index';
|
|
|
19
19
|
import type { TRecord } from '../record/index';
|
|
20
20
|
import type { TThis } from '../recursive/index';
|
|
21
21
|
import type { TRef } from '../ref/index';
|
|
22
|
+
import type { TRegExp } from '../regexp/index';
|
|
22
23
|
import type { TString } from '../string/index';
|
|
23
24
|
import type { TSymbol } from '../symbol/index';
|
|
24
25
|
import type { TTemplateLiteral } from '../template-literal/index';
|
|
@@ -29,4 +30,4 @@ import type { TUnion } from '../union/index';
|
|
|
29
30
|
import type { TUnknown } from '../unknown/index';
|
|
30
31
|
import type { TVoid } from '../void/index';
|
|
31
32
|
import type { TSchema } from './schema';
|
|
32
|
-
export type TAnySchema = TSchema | TAny | TArray | TAsyncIterator | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TIterator | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
33
|
+
export type TAnySchema = TSchema | TAny | TArray | TAsyncIterator | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TIterator | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TRegExp | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './set';
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./set"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TSetIncludes<T extends PropertyKey[], S extends PropertyKey> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? S extends L ? true : TSetIncludes<R, S> : false);
|
|
2
|
+
/** Returns true if element S is in the set of T */
|
|
3
|
+
export declare function SetIncludes<T extends PropertyKey[], S extends PropertyKey>(T: [...T], S: S): TSetIncludes<T, S>;
|
|
4
|
+
export type SetIsSubset<T extends PropertyKey[], S extends PropertyKey[]> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetIncludes<S, L> extends true ? SetIsSubset<R, S> : false : true);
|
|
5
|
+
/** Returns true if T is a subset of S */
|
|
6
|
+
export declare function SetIsSubset<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): SetIsSubset<T, S>;
|
|
7
|
+
export type TSetDistinct<T extends PropertyKey[], Acc extends PropertyKey[] = []> = T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetIncludes<Acc, L> extends false ? TSetDistinct<R, [...Acc, L]> : TSetDistinct<R, [...Acc]> : Acc;
|
|
8
|
+
/** Returns a distinct set of elements */
|
|
9
|
+
export declare function SetDistinct<T extends PropertyKey[]>(T: [...T]): TSetDistinct<T>;
|
|
10
|
+
export type TSetIntersect<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetIncludes<S, L> extends true ? TSetIntersect<R, S, [L, ...Acc]> : TSetIntersect<R, S, [...Acc]> : Acc);
|
|
11
|
+
/** Returns the Intersect of the given sets */
|
|
12
|
+
export declare function SetIntersect<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TSetIntersect<T, S>;
|
|
13
|
+
export type TSetUnion<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = S> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetUnion<R, S, [...Acc, L]> : Acc);
|
|
14
|
+
/** Returns the Union of the given sets */
|
|
15
|
+
export declare function SetUnion<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TSetUnion<T, S>;
|
|
16
|
+
export type TSetComplement<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetIncludes<S, L> extends true ? TSetComplement<R, S, [...Acc]> : TSetComplement<R, S, [...Acc, L]> : Acc);
|
|
17
|
+
/** Returns the Complement by omitting elements in T that are in S */
|
|
18
|
+
export declare function SetComplement<T extends PropertyKey[], S extends PropertyKey[]>(T: [...T], S: [...S]): TSetComplement<T, S>;
|
|
19
|
+
export type TSetIntersectMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? TSetIntersectMany<R, TSetIntersect<Acc, L>> : Acc);
|
|
20
|
+
/** Returns the Intersect of multiple sets */
|
|
21
|
+
export declare function SetIntersectMany<T extends PropertyKey[][]>(T: [...T]): TSetIntersectMany<T>;
|
|
22
|
+
export type TSetUnionMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? TSetUnionMany<R, TSetUnion<Acc, L>> : Acc);
|
|
23
|
+
/** Returns the Union of multiple sets */
|
|
24
|
+
export declare function SetUnionMany<T extends PropertyKey[][]>(T: [...T]): TSetUnionMany<T>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SetUnionMany = exports.SetIntersectMany = exports.SetComplement = exports.SetUnion = exports.SetIntersect = exports.SetDistinct = exports.SetIsSubset = exports.SetIncludes = void 0;
|
|
5
|
+
/** Returns true if element S is in the set of T */
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
function SetIncludes(T, S) {
|
|
8
|
+
return T.includes(S);
|
|
9
|
+
}
|
|
10
|
+
exports.SetIncludes = SetIncludes;
|
|
11
|
+
/** Returns true if T is a subset of S */
|
|
12
|
+
function SetIsSubset(T, S) {
|
|
13
|
+
return T.every((L) => SetIncludes(S, L));
|
|
14
|
+
}
|
|
15
|
+
exports.SetIsSubset = SetIsSubset;
|
|
16
|
+
/** Returns a distinct set of elements */
|
|
17
|
+
function SetDistinct(T) {
|
|
18
|
+
return [...new Set(T)];
|
|
19
|
+
}
|
|
20
|
+
exports.SetDistinct = SetDistinct;
|
|
21
|
+
/** Returns the Intersect of the given sets */
|
|
22
|
+
function SetIntersect(T, S) {
|
|
23
|
+
return T.filter((L) => S.includes(L));
|
|
24
|
+
}
|
|
25
|
+
exports.SetIntersect = SetIntersect;
|
|
26
|
+
/** Returns the Union of the given sets */
|
|
27
|
+
function SetUnion(T, S) {
|
|
28
|
+
return [...T, ...S];
|
|
29
|
+
}
|
|
30
|
+
exports.SetUnion = SetUnion;
|
|
31
|
+
/** Returns the Complement by omitting elements in T that are in S */
|
|
32
|
+
// prettier-ignore
|
|
33
|
+
function SetComplement(T, S) {
|
|
34
|
+
return T.filter(L => !S.includes(L));
|
|
35
|
+
}
|
|
36
|
+
exports.SetComplement = SetComplement;
|
|
37
|
+
/** Returns the Intersect of multiple sets */
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
function SetIntersectMany(T) {
|
|
40
|
+
return (T.length === 1 ? T[0] : T.reduce((Acc, L) => [...SetIntersect(Acc, L)], []));
|
|
41
|
+
}
|
|
42
|
+
exports.SetIntersectMany = SetIntersectMany;
|
|
43
|
+
/** Returns the Union of multiple sets */
|
|
44
|
+
function SetUnionMany(T) {
|
|
45
|
+
return T.reduce((Acc, L) => [...Acc, ...L], []);
|
|
46
|
+
}
|
|
47
|
+
exports.SetUnionMany = SetUnionMany;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Strict = void 0;
|
|
5
|
-
/** `[Json]` Omits compositing symbols from this schema */
|
|
5
|
+
/** `[Json]` Omits compositing symbols from this schema. */
|
|
6
6
|
function Strict(schema) {
|
|
7
7
|
return JSON.parse(JSON.stringify(schema));
|
|
8
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.TemplateLiteralParserError = void 0;
|
|
4
|
-
|
|
5
5
|
const index_1 = require("../error/index");
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// TemplateLiteralParserError
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Assert, Trim } from '../helpers/index';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TTemplateLiteral, TTemplateLiteralKind } from './index';
|
|
3
3
|
import { type TLiteral } from '../literal/index';
|
|
4
4
|
import { type TBoolean } from '../boolean/index';
|
|
5
5
|
import { type TBigInt } from '../bigint/index';
|
|
@@ -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 { TTemplateLiteralSyntax } from './syntax';
|
|
12
|
+
import { type 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> ? {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Transform = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = void 0;
|
|
5
|
-
const type_1 = require("../clone/type");
|
|
6
5
|
const index_1 = require("../symbols/index");
|
|
6
|
+
const type_1 = require("../clone/type");
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
@@ -41,9 +41,9 @@ export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
41
41
|
Parameters<T extends TFunction<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
42
42
|
/** `[JavaScript]` Creates a Promise type */
|
|
43
43
|
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
44
|
-
/** `[JavaScript]` Creates a
|
|
44
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
45
45
|
RegExp(pattern: string, options?: SchemaOptions): TRegExp;
|
|
46
|
-
/** `[JavaScript]` Creates a
|
|
46
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
47
47
|
RegExp(regex: RegExp, options?: SchemaOptions): TRegExp;
|
|
48
48
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
49
49
|
ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
|
|
@@ -66,7 +66,7 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
66
66
|
Promise(item, options = {}) {
|
|
67
67
|
return (0, index_11.Promise)(item, options);
|
|
68
68
|
}
|
|
69
|
-
/** `[JavaScript]` Creates a
|
|
69
|
+
/** `[JavaScript]` Creates a RegExp type */
|
|
70
70
|
RegExp(unresolved, options = {}) {
|
|
71
71
|
return (0, index_12.RegExp)(unresolved, options);
|
|
72
72
|
}
|
|
@@ -21,10 +21,10 @@ import { type TNull } from '../null/index';
|
|
|
21
21
|
import { type TMappedKey } from '../mapped/index';
|
|
22
22
|
import { type TNumber, type NumberOptions } from '../number/index';
|
|
23
23
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index';
|
|
24
|
-
import { type TOmit, type TOmitFromMappedKey } from '../omit/index';
|
|
24
|
+
import { type TOmit, type TOmitFromMappedKey, type TOmitFromMappedResult } from '../omit/index';
|
|
25
25
|
import { type TOptionalWithFlag, type TOptionalFromMappedResult } from '../optional/index';
|
|
26
26
|
import { type TPartial, type TPartialFromMappedResult } from '../partial/index';
|
|
27
|
-
import { type TPick, type TPickFromMappedKey } from '../pick/index';
|
|
27
|
+
import { type TPick, type TPickFromMappedKey, type TPickFromMappedResult } from '../pick/index';
|
|
28
28
|
import { type TReadonlyWithFlag, type TReadonlyFromMappedResult } from '../readonly/index';
|
|
29
29
|
import { type TReadonlyOptional } from '../readonly-optional/index';
|
|
30
30
|
import { type TRecordOrObject } from '../record/index';
|
|
@@ -127,6 +127,8 @@ export declare class JsonTypeBuilder {
|
|
|
127
127
|
/** `[Json]` Creates an Object type */
|
|
128
128
|
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
129
129
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
130
|
+
Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
|
|
131
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
130
132
|
Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K): TOmitFromMappedKey<T, K>;
|
|
131
133
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
132
134
|
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
@@ -137,6 +139,8 @@ export declare class JsonTypeBuilder {
|
|
|
137
139
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
138
140
|
Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
139
141
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
142
|
+
Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K]): TPickFromMappedResult<T, K>;
|
|
143
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
140
144
|
Pick<T extends TSchema, K extends TMappedKey>(T: T, K: K): TPickFromMappedKey<T, K>;
|
|
141
145
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
142
146
|
Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
|
|
@@ -11,25 +11,14 @@ const union_create_1 = require("./union-create");
|
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// TypeGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
|
-
// prettier-ignore
|
|
15
14
|
const type_2 = require("../guard/type");
|
|
16
15
|
// prettier-ignore
|
|
17
16
|
function IsUnionOptional(T) {
|
|
18
|
-
|
|
19
|
-
return (T.length > 0
|
|
20
|
-
? (0, type_2.IsOptional)(L)
|
|
21
|
-
? true
|
|
22
|
-
: IsUnionOptional(R)
|
|
23
|
-
: false);
|
|
17
|
+
return T.some(L => (0, type_2.IsOptional)(L));
|
|
24
18
|
}
|
|
25
19
|
// prettier-ignore
|
|
26
|
-
function RemoveOptionalFromRest(T
|
|
27
|
-
|
|
28
|
-
return (T.length > 0
|
|
29
|
-
? (0, type_2.IsOptional)(L)
|
|
30
|
-
? RemoveOptionalFromRest(R, [...Acc, RemoveOptionalFromType(L)])
|
|
31
|
-
: RemoveOptionalFromRest(R, [...Acc, L])
|
|
32
|
-
: Acc);
|
|
20
|
+
function RemoveOptionalFromRest(T) {
|
|
21
|
+
return T.map(L => (0, type_2.IsOptional)(L) ? RemoveOptionalFromType(L) : L);
|
|
33
22
|
}
|
|
34
23
|
// prettier-ignore
|
|
35
24
|
function RemoveOptionalFromType(T) {
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
import { TypeBoxError } from '../../type/error/index';
|
|
2
2
|
import type { TSchema } from '../../type/schema/index';
|
|
3
3
|
import type { Static } from '../../type/static/index';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class ValueCastError extends TypeBoxError {
|
|
5
5
|
readonly schema: TSchema;
|
|
6
|
-
|
|
7
|
-
constructor(schema: TSchema, value: unknown);
|
|
8
|
-
}
|
|
9
|
-
export declare class ValueCastNeverTypeError extends TypeBoxError {
|
|
10
|
-
readonly schema: TSchema;
|
|
11
|
-
constructor(schema: TSchema);
|
|
12
|
-
}
|
|
13
|
-
export declare class ValueCastRecursiveTypeError extends TypeBoxError {
|
|
14
|
-
readonly schema: TSchema;
|
|
15
|
-
constructor(schema: TSchema);
|
|
16
|
-
}
|
|
17
|
-
export declare class ValueCastUnknownTypeError extends TypeBoxError {
|
|
18
|
-
readonly schema: TSchema;
|
|
19
|
-
constructor(schema: TSchema);
|
|
6
|
+
constructor(schema: TSchema, message: string);
|
|
20
7
|
}
|
|
21
8
|
/** Casts a value into a given type and references. The return value will retain as much information of the original value as possible. */
|
|
22
9
|
export declare function Cast<T extends TSchema>(schema: T, references: TSchema[], value: unknown): Static<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Cast = exports.
|
|
4
|
+
exports.Cast = exports.ValueCastError = void 0;
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../../type/error/index");
|
|
7
7
|
const index_3 = require("../../type/symbols/index");
|
|
@@ -12,35 +12,13 @@ const index_7 = require("../deref/index");
|
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
13
|
// Errors
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
|
-
class
|
|
16
|
-
constructor(schema,
|
|
17
|
-
super(
|
|
15
|
+
class ValueCastError extends index_2.TypeBoxError {
|
|
16
|
+
constructor(schema, message) {
|
|
17
|
+
super(message);
|
|
18
18
|
this.schema = schema;
|
|
19
|
-
this.value = value;
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
exports.
|
|
23
|
-
class ValueCastNeverTypeError extends index_2.TypeBoxError {
|
|
24
|
-
constructor(schema) {
|
|
25
|
-
super('Never types cannot be cast');
|
|
26
|
-
this.schema = schema;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ValueCastNeverTypeError = ValueCastNeverTypeError;
|
|
30
|
-
class ValueCastRecursiveTypeError extends index_2.TypeBoxError {
|
|
31
|
-
constructor(schema) {
|
|
32
|
-
super('Cannot cast recursive schemas');
|
|
33
|
-
this.schema = schema;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ValueCastRecursiveTypeError = ValueCastRecursiveTypeError;
|
|
37
|
-
class ValueCastUnknownTypeError extends index_2.TypeBoxError {
|
|
38
|
-
constructor(schema) {
|
|
39
|
-
super('Unknown type');
|
|
40
|
-
this.schema = schema;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ValueCastUnknownTypeError = ValueCastUnknownTypeError;
|
|
21
|
+
exports.ValueCastError = ValueCastError;
|
|
44
22
|
// ------------------------------------------------------------------
|
|
45
23
|
// The following will score a schema against a value. For objects,
|
|
46
24
|
// the score is the tally of points awarded for each property of
|
|
@@ -109,7 +87,7 @@ function FromArray(schema, references, value) {
|
|
|
109
87
|
return casted;
|
|
110
88
|
const unique = [...new Set(casted)];
|
|
111
89
|
if (!(0, index_5.Check)(schema, references, unique))
|
|
112
|
-
throw new
|
|
90
|
+
throw new ValueCastError(schema, 'Array cast produced invalid data due to uniqueItems constraint');
|
|
113
91
|
return unique;
|
|
114
92
|
}
|
|
115
93
|
function FromConstructor(schema, references, value) {
|
|
@@ -130,7 +108,7 @@ function FromIntersect(schema, references, value) {
|
|
|
130
108
|
return (0, index_5.Check)(schema, references, mapped) ? mapped : (0, index_4.Create)(schema, references);
|
|
131
109
|
}
|
|
132
110
|
function FromNever(schema, references, value) {
|
|
133
|
-
throw new
|
|
111
|
+
throw new ValueCastError(schema, 'Never types cannot be cast');
|
|
134
112
|
}
|
|
135
113
|
function FromObject(schema, references, value) {
|
|
136
114
|
if ((0, index_5.Check)(schema, references, value))
|
|
@@ -14,7 +14,6 @@ const index_9 = require("../../type/never/index");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
// ValueGuard
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
-
// prettier-ignore
|
|
18
17
|
const index_10 = require("../guard/index");
|
|
19
18
|
// ------------------------------------------------------------------
|
|
20
19
|
// TypeGuard
|
|
@@ -290,6 +289,10 @@ function FromRecord(schema, references, value) {
|
|
|
290
289
|
function FromRef(schema, references, value) {
|
|
291
290
|
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
292
291
|
}
|
|
292
|
+
function FromRegExp(schema, references, value) {
|
|
293
|
+
const regex = new RegExp(schema.source, schema.flags);
|
|
294
|
+
return regex.test(value);
|
|
295
|
+
}
|
|
293
296
|
function FromString(schema, references, value) {
|
|
294
297
|
if (!(0, index_10.IsString)(value)) {
|
|
295
298
|
return false;
|
|
@@ -417,6 +420,8 @@ function Visit(schema, references, value) {
|
|
|
417
420
|
return FromRecord(schema_, references_, value);
|
|
418
421
|
case 'Ref':
|
|
419
422
|
return FromRef(schema_, references_, value);
|
|
423
|
+
case 'RegExp':
|
|
424
|
+
return FromRegExp(schema_, references_, value);
|
|
420
425
|
case 'String':
|
|
421
426
|
return FromString(schema_, references_, value);
|
|
422
427
|
case 'Symbol':
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { TypeBoxError } from '../../type/error/index';
|
|
2
1
|
import type { TSchema } from '../../type/schema/index';
|
|
3
|
-
export declare class ValueConvertUnknownTypeError extends TypeBoxError {
|
|
4
|
-
readonly schema: TSchema;
|
|
5
|
-
constructor(schema: TSchema);
|
|
6
|
-
}
|
|
7
2
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
8
3
|
export declare function Convert<T extends TSchema>(schema: T, references: TSchema[], value: unknown): unknown;
|
|
9
4
|
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|