@sinclair/typebox 0.32.34 → 0.33.0
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/cjs/errors/function.js +1 -1
- package/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/system/policy.d.ts +9 -1
- package/build/cjs/system/policy.js +13 -2
- package/build/cjs/type/any/any.js +4 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/array/array.js +3 -8
- package/build/cjs/type/async-iterator/async-iterator.js +3 -8
- package/build/cjs/type/awaited/awaited.js +3 -3
- package/build/cjs/type/bigint/bigint.js +3 -6
- package/build/cjs/type/boolean/boolean.js +3 -6
- package/build/cjs/type/clone/type.d.ts +1 -1
- package/build/cjs/type/clone/type.js +2 -2
- package/build/cjs/type/composite/composite.js +1 -1
- package/build/cjs/type/const/const.js +3 -3
- package/build/cjs/type/constructor/constructor.js +2 -8
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +2 -3
- package/build/cjs/type/create/immutable.d.ts +2 -0
- package/build/cjs/type/create/immutable.js +41 -0
- package/build/cjs/type/create/index.d.ts +1 -0
- package/build/cjs/type/create/index.js +18 -0
- package/build/cjs/type/create/type.d.ts +3 -0
- package/build/cjs/type/create/type.js +19 -0
- package/build/cjs/type/date/date.js +3 -6
- package/build/cjs/type/discard/discard.d.ts +1 -0
- package/build/cjs/type/discard/discard.js +1 -0
- package/build/cjs/type/enum/enum.js +1 -1
- package/build/cjs/type/exclude/exclude.js +4 -4
- package/build/cjs/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-key.js +2 -1
- package/build/cjs/type/extends/extends-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-result.js +2 -1
- package/build/cjs/type/extends/extends.js +4 -4
- package/build/cjs/type/extract/extract.js +5 -5
- package/build/cjs/type/function/function.js +2 -8
- package/build/cjs/type/guard/value.js +3 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +2 -1
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/indexed/indexed.js +10 -6
- package/build/cjs/type/instance-type/instance-type.js +3 -3
- package/build/cjs/type/integer/integer.js +3 -6
- package/build/cjs/type/intersect/intersect-create.d.ts +1 -1
- package/build/cjs/type/intersect/intersect-create.js +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +2 -2
- package/build/cjs/type/intersect/intersect.js +3 -3
- package/build/cjs/type/intrinsic/intrinsic-from-mapped-key.js +4 -2
- package/build/cjs/type/intrinsic/intrinsic.js +3 -1
- package/build/cjs/type/iterator/iterator.js +3 -8
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +2 -1
- package/build/cjs/type/keyof/keyof.js +3 -3
- package/build/cjs/type/literal/literal.js +4 -4
- package/build/cjs/type/mapped/mapped-key.js +3 -2
- package/build/cjs/type/mapped/mapped-result.js +3 -2
- package/build/cjs/type/mapped/mapped.js +2 -3
- package/build/cjs/type/never/never.js +3 -6
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +3 -7
- package/build/cjs/type/null/null.js +3 -6
- package/build/cjs/type/number/number.js +3 -6
- package/build/cjs/type/object/object.js +13 -12
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-key.js +2 -1
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-result.js +2 -1
- package/build/cjs/type/omit/omit.js +4 -4
- package/build/cjs/type/optional/optional.js +3 -3
- package/build/cjs/type/parameters/parameters.js +2 -3
- package/build/cjs/type/partial/partial-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/partial/partial-from-mapped-result.js +2 -1
- package/build/cjs/type/partial/partial.js +4 -4
- package/build/cjs/type/patterns/patterns.d.ts +2 -0
- package/build/cjs/type/patterns/patterns.js +3 -1
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-key.js +2 -1
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-result.js +2 -1
- package/build/cjs/type/pick/pick.js +4 -4
- package/build/cjs/type/promise/promise.js +3 -8
- package/build/cjs/type/readonly/readonly.js +3 -3
- package/build/cjs/type/record/record.d.ts +4 -1
- package/build/cjs/type/record/record.js +16 -7
- package/build/cjs/type/recursive/recursive.js +3 -2
- package/build/cjs/type/ref/ref.js +4 -7
- package/build/cjs/type/regexp/regexp.js +3 -2
- package/build/cjs/type/required/required-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/required/required.js +4 -4
- package/build/cjs/type/rest/rest.d.ts +1 -1
- package/build/cjs/type/rest/rest.js +4 -5
- package/build/cjs/type/return-type/return-type.js +3 -3
- package/build/cjs/type/string/string.js +3 -2
- package/build/cjs/type/symbol/symbol.js +2 -1
- package/build/cjs/type/template-literal/template-literal.js +3 -2
- package/build/cjs/type/transform/transform.js +1 -3
- package/build/cjs/type/tuple/tuple.js +5 -7
- package/build/cjs/type/type/javascript.js +13 -13
- package/build/cjs/type/type/json.js +35 -35
- package/build/cjs/type/uint8array/uint8array.js +3 -2
- package/build/cjs/type/undefined/undefined.js +3 -2
- package/build/cjs/type/union/union-create.d.ts +1 -1
- package/build/cjs/type/union/union-create.js +2 -2
- package/build/cjs/type/union/union-evaluated.js +3 -3
- package/build/cjs/type/union/union.js +3 -3
- package/build/cjs/type/unknown/unknown.js +3 -5
- package/build/cjs/type/unsafe/unsafe.js +2 -4
- package/build/cjs/type/void/void.js +3 -6
- package/build/cjs/value/convert/convert.js +3 -0
- package/build/esm/errors/function.mjs +1 -1
- package/build/esm/index.d.mts +1 -0
- package/build/esm/index.mjs +1 -0
- package/build/esm/system/policy.d.mts +9 -1
- package/build/esm/system/policy.mjs +13 -2
- package/build/esm/type/any/any.mjs +3 -2
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/array/array.mjs +3 -8
- package/build/esm/type/async-iterator/async-iterator.mjs +3 -8
- package/build/esm/type/awaited/awaited.mjs +3 -3
- package/build/esm/type/bigint/bigint.mjs +3 -6
- package/build/esm/type/boolean/boolean.mjs +3 -6
- package/build/esm/type/clone/type.d.mts +1 -1
- package/build/esm/type/clone/type.mjs +2 -2
- package/build/esm/type/composite/composite.mjs +1 -1
- package/build/esm/type/const/const.mjs +3 -3
- package/build/esm/type/constructor/constructor.mjs +2 -8
- package/build/esm/type/constructor-parameters/constructor-parameters.mjs +2 -3
- package/build/esm/type/create/immutable.d.mts +2 -0
- package/build/esm/type/create/immutable.mjs +37 -0
- package/build/esm/type/create/index.d.mts +1 -0
- package/build/esm/type/create/index.mjs +1 -0
- package/build/esm/type/create/type.d.mts +3 -0
- package/build/esm/type/create/type.mjs +15 -0
- package/build/esm/type/date/date.mjs +3 -6
- package/build/esm/type/discard/discard.d.mts +1 -0
- package/build/esm/type/discard/discard.mjs +1 -0
- package/build/esm/type/enum/enum.mjs +1 -1
- package/build/esm/type/exclude/exclude.mjs +4 -4
- package/build/esm/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-key.mjs +2 -1
- package/build/esm/type/extends/extends-from-mapped-result.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-result.mjs +2 -1
- package/build/esm/type/extends/extends.mjs +4 -4
- package/build/esm/type/extract/extract.mjs +5 -5
- package/build/esm/type/function/function.mjs +2 -8
- package/build/esm/type/guard/value.mjs +3 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +1 -1
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +2 -1
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/esm/type/indexed/indexed.mjs +10 -6
- package/build/esm/type/instance-type/instance-type.mjs +3 -3
- package/build/esm/type/integer/integer.mjs +3 -6
- package/build/esm/type/intersect/intersect-create.d.mts +1 -1
- package/build/esm/type/intersect/intersect-create.mjs +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +2 -2
- package/build/esm/type/intersect/intersect.mjs +3 -3
- package/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -2
- package/build/esm/type/intrinsic/intrinsic.mjs +3 -1
- package/build/esm/type/iterator/iterator.mjs +3 -8
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +1 -1
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +2 -1
- package/build/esm/type/keyof/keyof.mjs +3 -3
- package/build/esm/type/literal/literal.mjs +4 -4
- package/build/esm/type/mapped/mapped-key.mjs +3 -2
- package/build/esm/type/mapped/mapped-result.mjs +3 -2
- package/build/esm/type/mapped/mapped.mjs +2 -3
- package/build/esm/type/never/never.mjs +3 -6
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +3 -7
- package/build/esm/type/null/null.mjs +3 -6
- package/build/esm/type/number/number.mjs +3 -6
- package/build/esm/type/object/object.mjs +14 -13
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-key.mjs +2 -1
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-result.mjs +2 -1
- package/build/esm/type/omit/omit.mjs +4 -4
- package/build/esm/type/optional/optional.mjs +3 -3
- package/build/esm/type/parameters/parameters.mjs +2 -3
- package/build/esm/type/partial/partial-from-mapped-result.d.mts +1 -1
- package/build/esm/type/partial/partial-from-mapped-result.mjs +2 -1
- package/build/esm/type/partial/partial.mjs +4 -4
- package/build/esm/type/patterns/patterns.d.mts +2 -0
- package/build/esm/type/patterns/patterns.mjs +2 -0
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-key.mjs +2 -1
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-result.mjs +2 -1
- package/build/esm/type/pick/pick.mjs +4 -4
- package/build/esm/type/promise/promise.mjs +3 -8
- package/build/esm/type/readonly/readonly.mjs +3 -3
- package/build/esm/type/record/record.d.mts +4 -1
- package/build/esm/type/record/record.mjs +18 -9
- package/build/esm/type/recursive/recursive.mjs +3 -2
- package/build/esm/type/ref/ref.mjs +4 -7
- package/build/esm/type/regexp/regexp.mjs +3 -2
- package/build/esm/type/required/required-from-mapped-result.d.mts +1 -1
- package/build/esm/type/required/required.mjs +4 -4
- package/build/esm/type/rest/rest.d.mts +1 -1
- package/build/esm/type/rest/rest.mjs +4 -5
- package/build/esm/type/return-type/return-type.mjs +3 -3
- package/build/esm/type/string/string.mjs +3 -2
- package/build/esm/type/symbol/symbol.mjs +2 -1
- package/build/esm/type/template-literal/template-literal.mjs +3 -2
- package/build/esm/type/transform/transform.mjs +1 -3
- package/build/esm/type/tuple/tuple.mjs +5 -7
- package/build/esm/type/type/javascript.mjs +13 -13
- package/build/esm/type/type/json.mjs +35 -35
- package/build/esm/type/uint8array/uint8array.mjs +3 -2
- package/build/esm/type/undefined/undefined.mjs +3 -2
- package/build/esm/type/union/union-create.d.mts +1 -1
- package/build/esm/type/union/union-create.mjs +2 -2
- package/build/esm/type/union/union-evaluated.mjs +3 -3
- package/build/esm/type/union/union.mjs +3 -3
- package/build/esm/type/unknown/unknown.mjs +3 -5
- package/build/esm/type/unsafe/unsafe.mjs +2 -4
- package/build/esm/type/void/void.mjs +3 -6
- package/build/esm/value/convert/convert.mjs +3 -0
- package/package.json +1 -1
|
@@ -100,7 +100,7 @@ function DefaultErrorFunction(error) {
|
|
|
100
100
|
case errors_1.ValueErrorType.ObjectMinProperties:
|
|
101
101
|
return `Expected object to have at least ${error.schema.minProperties} properties`;
|
|
102
102
|
case errors_1.ValueErrorType.ObjectRequiredProperty:
|
|
103
|
-
return '
|
|
103
|
+
return 'Expected required property';
|
|
104
104
|
case errors_1.ValueErrorType.Promise:
|
|
105
105
|
return 'Expected Promise';
|
|
106
106
|
case errors_1.ValueErrorType.RegExp:
|
package/build/cjs/index.d.ts
CHANGED
package/build/cjs/index.js
CHANGED
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
// Infrastructure
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
21
|
__exportStar(require("./type/clone/index"), exports);
|
|
22
|
+
__exportStar(require("./type/create/index"), exports);
|
|
22
23
|
__exportStar(require("./type/error/index"), exports);
|
|
23
24
|
__exportStar(require("./type/guard/index"), exports);
|
|
24
25
|
__exportStar(require("./type/helpers/index"), exports);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare namespace TypeSystemPolicy {
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
|
|
4
|
+
* references for embedded types, which may cause side effects if type properties are explicitly updated
|
|
5
|
+
* outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
|
|
6
|
+
* preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
|
|
7
|
+
* it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
|
|
8
|
+
* fastest way to instantiate types. The default setting is `default`.
|
|
9
|
+
*/
|
|
10
|
+
let InstanceMode: 'default' | 'clone' | 'freeze';
|
|
3
11
|
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
4
12
|
let ExactOptionalPropertyTypes: boolean;
|
|
5
13
|
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
@@ -6,9 +6,20 @@ const index_1 = require("../value/guard/index");
|
|
|
6
6
|
var TypeSystemPolicy;
|
|
7
7
|
(function (TypeSystemPolicy) {
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
|
-
// TypeSystemPolicy
|
|
9
|
+
// TypeSystemPolicy: Instancing
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
|
|
13
|
+
* references for embedded types, which may cause side effects if type properties are explicitly updated
|
|
14
|
+
* outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
|
|
15
|
+
* preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
|
|
16
|
+
* it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
|
|
17
|
+
* fastest way to instantiate types. The default setting is `default`.
|
|
18
|
+
*/
|
|
19
|
+
TypeSystemPolicy.InstanceMode = 'default';
|
|
20
|
+
// ------------------------------------------------------------------
|
|
21
|
+
// TypeSystemPolicy: Checking
|
|
10
22
|
// ------------------------------------------------------------------
|
|
11
|
-
/** Shared assertion routines used by the value and errors modules */
|
|
12
23
|
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
13
24
|
TypeSystemPolicy.ExactOptionalPropertyTypes = false;
|
|
14
25
|
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Any = Any;
|
|
5
|
-
const index_1 = require("../
|
|
5
|
+
const index_1 = require("../create/index");
|
|
6
|
+
const index_2 = require("../symbols/index");
|
|
6
7
|
/** `[Json]` Creates an Any type */
|
|
7
|
-
function Any(options
|
|
8
|
-
return
|
|
8
|
+
function Any(options) {
|
|
9
|
+
return (0, index_1.CreateType)({ [index_2.Kind]: 'Any' }, options);
|
|
9
10
|
}
|
|
@@ -24,5 +24,5 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
24
24
|
items: T;
|
|
25
25
|
}
|
|
26
26
|
/** `[Json]` Creates an Array type */
|
|
27
|
-
export declare function Array<T extends TSchema>(
|
|
27
|
+
export declare function Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
28
28
|
export {};
|
|
@@ -2,14 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Array = Array;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[Json]` Creates an Array type */
|
|
8
|
-
function Array(
|
|
9
|
-
return {
|
|
10
|
-
...options,
|
|
11
|
-
[index_1.Kind]: 'Array',
|
|
12
|
-
type: 'array',
|
|
13
|
-
items: (0, type_1.CloneType)(schema),
|
|
14
|
-
};
|
|
8
|
+
function Array(items, options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Array', type: 'array', items }, options);
|
|
15
10
|
}
|
|
@@ -3,13 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.AsyncIterator = AsyncIterator;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
|
-
const type_1 = require("../
|
|
6
|
+
const type_1 = require("../create/type");
|
|
7
7
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
8
|
-
function AsyncIterator(items, options
|
|
9
|
-
return {
|
|
10
|
-
...options,
|
|
11
|
-
[index_1.Kind]: 'AsyncIterator',
|
|
12
|
-
type: 'AsyncIterator',
|
|
13
|
-
items: (0, type_1.CloneType)(items),
|
|
14
|
-
};
|
|
8
|
+
function AsyncIterator(items, options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'AsyncIterator', type: 'AsyncIterator', items }, options);
|
|
15
10
|
}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Awaited = Awaited;
|
|
5
5
|
const index_1 = require("../intersect/index");
|
|
6
6
|
const index_2 = require("../union/index");
|
|
7
|
-
const type_1 = require("../
|
|
7
|
+
const type_1 = require("../create/type");
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// TypeGuard
|
|
10
10
|
// ------------------------------------------------------------------
|
|
@@ -36,6 +36,6 @@ function AwaitedResolve(T) {
|
|
|
36
36
|
T);
|
|
37
37
|
}
|
|
38
38
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
39
|
-
function Awaited(T, options
|
|
40
|
-
return (0, type_1.
|
|
39
|
+
function Awaited(T, options) {
|
|
40
|
+
return (0, type_1.CreateType)(AwaitedResolve(T), options);
|
|
41
41
|
}
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.BigInt = BigInt;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
|
+
const index_2 = require("../create/index");
|
|
6
7
|
/** `[JavaScript]` Creates a BigInt type */
|
|
7
|
-
function BigInt(options
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: 'BigInt',
|
|
11
|
-
type: 'bigint',
|
|
12
|
-
};
|
|
8
|
+
function BigInt(options) {
|
|
9
|
+
return (0, index_2.CreateType)({ [index_1.Kind]: 'BigInt', type: 'bigint' }, options);
|
|
13
10
|
}
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Boolean = Boolean;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
|
+
const index_2 = require("../create/index");
|
|
6
7
|
/** `[Json]` Creates a Boolean type */
|
|
7
|
-
function Boolean(options
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: 'Boolean',
|
|
11
|
-
type: 'boolean',
|
|
12
|
-
};
|
|
8
|
+
function Boolean(options) {
|
|
9
|
+
return (0, index_2.CreateType)({ [index_1.Kind]: 'Boolean', type: 'boolean' }, options);
|
|
13
10
|
}
|
|
@@ -9,6 +9,6 @@ function CloneRest(schemas) {
|
|
|
9
9
|
return schemas.map((schema) => CloneType(schema));
|
|
10
10
|
}
|
|
11
11
|
/** Clones a Type */
|
|
12
|
-
function CloneType(schema, options
|
|
13
|
-
return
|
|
12
|
+
function CloneType(schema, options) {
|
|
13
|
+
return options === undefined ? (0, value_1.Clone)(schema) : (0, value_1.Clone)({ ...options, ...schema });
|
|
14
14
|
}
|
|
@@ -38,7 +38,7 @@ function CompositeProperties(T, K) {
|
|
|
38
38
|
return Acc;
|
|
39
39
|
}
|
|
40
40
|
// prettier-ignore
|
|
41
|
-
function Composite(T, options
|
|
41
|
+
function Composite(T, options) {
|
|
42
42
|
const K = CompositeKeys(T);
|
|
43
43
|
const P = CompositeProperties(T, K);
|
|
44
44
|
const R = (0, index_4.Object)(P, options);
|
|
@@ -15,7 +15,7 @@ const index_10 = require("../readonly/index");
|
|
|
15
15
|
const index_11 = require("../undefined/index");
|
|
16
16
|
const index_12 = require("../uint8array/index");
|
|
17
17
|
const index_13 = require("../unknown/index");
|
|
18
|
-
const index_14 = require("../
|
|
18
|
+
const index_14 = require("../create/index");
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
// ValueGuard
|
|
21
21
|
// ------------------------------------------------------------------
|
|
@@ -53,6 +53,6 @@ function FromValue(value, root) {
|
|
|
53
53
|
(0, index_7.Object)({}));
|
|
54
54
|
}
|
|
55
55
|
/** `[JavaScript]` Creates a readonly const type from the given value. */
|
|
56
|
-
function Const(T, options
|
|
57
|
-
return (0, index_14.
|
|
56
|
+
function Const(T, options) {
|
|
57
|
+
return (0, index_14.CreateType)(FromValue(T, true), options);
|
|
58
58
|
}
|
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Constructor = Constructor;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[JavaScript]` Creates a Constructor type */
|
|
8
8
|
function Constructor(parameters, returns, options) {
|
|
9
|
-
return {
|
|
10
|
-
...options,
|
|
11
|
-
[index_1.Kind]: 'Constructor',
|
|
12
|
-
type: 'Constructor',
|
|
13
|
-
parameters: (0, type_1.CloneRest)(parameters),
|
|
14
|
-
returns: (0, type_1.CloneType)(returns),
|
|
15
|
-
};
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Constructor', type: 'Constructor', parameters, returns }, options);
|
|
16
10
|
}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConstructorParameters = ConstructorParameters;
|
|
5
5
|
const index_1 = require("../tuple/index");
|
|
6
|
-
const type_1 = require("../clone/type");
|
|
7
6
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
8
|
-
function ConstructorParameters(schema, options
|
|
9
|
-
return (0, index_1.Tuple)(
|
|
7
|
+
function ConstructorParameters(schema, options) {
|
|
8
|
+
return (0, index_1.Tuple)(schema.parameters, options);
|
|
10
9
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Immutable = Immutable;
|
|
5
|
+
const ValueGuard = require("../guard/value");
|
|
6
|
+
function ImmutableArray(value) {
|
|
7
|
+
return globalThis.Object.freeze(value).map((value) => Immutable(value));
|
|
8
|
+
}
|
|
9
|
+
function ImmutableDate(value) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function ImmutableUint8Array(value) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function ImmutableRegExp(value) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function ImmutableObject(value) {
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
21
|
+
result[key] = Immutable(value[key]);
|
|
22
|
+
}
|
|
23
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
24
|
+
result[key] = Immutable(value[key]);
|
|
25
|
+
}
|
|
26
|
+
return globalThis.Object.freeze(result);
|
|
27
|
+
}
|
|
28
|
+
/** Specialized deep immutable value. Applies freeze recursively to the given value */
|
|
29
|
+
function Immutable(value) {
|
|
30
|
+
return ValueGuard.IsArray(value)
|
|
31
|
+
? ImmutableArray(value)
|
|
32
|
+
: ValueGuard.IsDate(value)
|
|
33
|
+
? ImmutableDate(value)
|
|
34
|
+
: ValueGuard.IsUint8Array(value)
|
|
35
|
+
? ImmutableUint8Array(value)
|
|
36
|
+
: ValueGuard.IsRegExp(value)
|
|
37
|
+
? ImmutableRegExp(value)
|
|
38
|
+
: ValueGuard.IsObject(value)
|
|
39
|
+
? ImmutableObject(value)
|
|
40
|
+
: value;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./type"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CreateType = CreateType;
|
|
5
|
+
const policy_1 = require("../../system/policy");
|
|
6
|
+
const immutable_1 = require("./immutable");
|
|
7
|
+
const value_1 = require("../clone/value");
|
|
8
|
+
/** Creates TypeBox schematics using the configured InstanceMode */
|
|
9
|
+
function CreateType(schema, options) {
|
|
10
|
+
const result = options !== undefined ? Object.assign(options, schema) : schema;
|
|
11
|
+
switch (policy_1.TypeSystemPolicy.InstanceMode) {
|
|
12
|
+
case 'freeze':
|
|
13
|
+
return (0, immutable_1.Immutable)(result);
|
|
14
|
+
case 'clone':
|
|
15
|
+
return (0, value_1.Clone)(result);
|
|
16
|
+
default:
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Date = Date;
|
|
5
5
|
const index_1 = require("../symbols/index");
|
|
6
|
+
const type_1 = require("../create/type");
|
|
6
7
|
/** `[JavaScript]` Creates a Date type */
|
|
7
|
-
function Date(options
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: 'Date',
|
|
11
|
-
type: 'Date',
|
|
12
|
-
};
|
|
8
|
+
function Date(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Date', type: 'Date' }, options);
|
|
13
10
|
}
|
|
@@ -6,6 +6,7 @@ function DiscardKey(value, key) {
|
|
|
6
6
|
const { [key]: _, ...rest } = value;
|
|
7
7
|
return rest;
|
|
8
8
|
}
|
|
9
|
+
/** Discards property keys from the given value. This function returns a shallow Clone. */
|
|
9
10
|
function Discard(value, keys) {
|
|
10
11
|
return keys.reduce((acc, key) => DiscardKey(acc, key), value);
|
|
11
12
|
}
|
|
@@ -10,7 +10,7 @@ const index_3 = require("../union/index");
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
const value_1 = require("../guard/value");
|
|
12
12
|
/** `[Json]` Creates a Enum type */
|
|
13
|
-
function Enum(item, options
|
|
13
|
+
function Enum(item, options) {
|
|
14
14
|
if ((0, value_1.IsUndefined)(item))
|
|
15
15
|
throw new Error('Enum undefined or empty');
|
|
16
16
|
const values1 = globalThis.Object.getOwnPropertyNames(item)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Exclude = Exclude;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../union/index");
|
|
6
7
|
const index_2 = require("../never/index");
|
|
7
8
|
const index_3 = require("../extends/index");
|
|
8
|
-
const type_1 = require("../clone/type");
|
|
9
9
|
const exclude_from_mapped_result_1 = require("./exclude-from-mapped-result");
|
|
10
10
|
const exclude_from_template_literal_1 = require("./exclude-from-template-literal");
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -20,10 +20,10 @@ function ExcludeRest(L, R) {
|
|
|
20
20
|
function Exclude(L, R, options = {}) {
|
|
21
21
|
// overloads
|
|
22
22
|
if ((0, kind_1.IsTemplateLiteral)(L))
|
|
23
|
-
return (0, type_1.
|
|
23
|
+
return (0, type_1.CreateType)((0, exclude_from_template_literal_1.ExcludeFromTemplateLiteral)(L, R), options);
|
|
24
24
|
if ((0, kind_1.IsMappedResult)(L))
|
|
25
|
-
return (0, type_1.
|
|
25
|
+
return (0, type_1.CreateType)((0, exclude_from_mapped_result_1.ExcludeFromMappedResult)(L, R), options);
|
|
26
26
|
// prettier-ignore
|
|
27
|
-
return (0, type_1.
|
|
27
|
+
return (0, type_1.CreateType)((0, kind_1.IsUnion)(L) ? ExcludeRest(L.anyOf, R) :
|
|
28
28
|
(0, index_3.ExtendsCheck)(L, R) !== index_3.ExtendsResult.False ? (0, index_2.Never)() : L, options);
|
|
29
29
|
}
|
|
@@ -10,5 +10,5 @@ type TFromPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchem
|
|
|
10
10
|
type TFromPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema, Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<RK, U, L, R, Acc & TFromPropertyKey<LK, U, L, R>> : Acc);
|
|
11
11
|
type TFromMappedKey<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema> = (TFromPropertyKeys<K['keys'], U, L, R>);
|
|
12
12
|
export type TExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>> = (TMappedResult<P>);
|
|
13
|
-
export declare function ExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>>(T: T, U: U, L: L, R: R, options
|
|
13
|
+
export declare function ExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>>(T: T, U: U, L: L, R: R, options?: SchemaOptions): TMappedResult<P>;
|
|
14
14
|
export {};
|
|
@@ -5,10 +5,11 @@ exports.ExtendsFromMappedKey = ExtendsFromMappedKey;
|
|
|
5
5
|
const index_1 = require("../mapped/index");
|
|
6
6
|
const index_2 = require("../literal/index");
|
|
7
7
|
const extends_1 = require("./extends");
|
|
8
|
+
const value_1 = require("../clone/value");
|
|
8
9
|
// prettier-ignore
|
|
9
10
|
function FromPropertyKey(K, U, L, R, options) {
|
|
10
11
|
return {
|
|
11
|
-
[K]: (0, extends_1.Extends)((0, index_2.Literal)(K), U, L, R, options)
|
|
12
|
+
[K]: (0, extends_1.Extends)((0, index_2.Literal)(K), U, L, R, (0, value_1.Clone)(options))
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
// prettier-ignore
|
|
@@ -7,5 +7,5 @@ type TFromProperties<P extends TProperties, Right extends TSchema, False extends
|
|
|
7
7
|
});
|
|
8
8
|
type TFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema> = (TFromProperties<Left['properties'], Right, True, False>);
|
|
9
9
|
export type TExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>> = (TMappedResult<P>);
|
|
10
|
-
export declare function ExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>>(Left: Left, Right: Right, True: True, False: False, options
|
|
10
|
+
export declare function ExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>>(Left: Left, Right: Right, True: True, False: False, options?: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.ExtendsFromMappedResult = ExtendsFromMappedResult;
|
|
5
5
|
const index_1 = require("../mapped/index");
|
|
6
6
|
const extends_1 = require("./extends");
|
|
7
|
+
const value_1 = require("../clone/value");
|
|
7
8
|
// prettier-ignore
|
|
8
9
|
function FromProperties(P, Right, True, False, options) {
|
|
9
10
|
const Acc = {};
|
|
10
11
|
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
11
|
-
Acc[K2] = (0, extends_1.Extends)(P[K2], Right, True, False, options);
|
|
12
|
+
Acc[K2] = (0, extends_1.Extends)(P[K2], Right, True, False, (0, value_1.Clone)(options));
|
|
12
13
|
return Acc;
|
|
13
14
|
}
|
|
14
15
|
// prettier-ignore
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Extends = Extends;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../union/index");
|
|
6
7
|
const extends_check_1 = require("./extends-check");
|
|
7
|
-
const type_1 = require("../clone/type");
|
|
8
8
|
const extends_from_mapped_key_1 = require("./extends-from-mapped-key");
|
|
9
9
|
const extends_from_mapped_result_1 = require("./extends-from-mapped-result");
|
|
10
10
|
// ------------------------------------------------------------------
|
|
@@ -19,9 +19,9 @@ function ExtendsResolve(left, right, trueType, falseType) {
|
|
|
19
19
|
falseType);
|
|
20
20
|
}
|
|
21
21
|
/** `[Json]` Creates a Conditional type */
|
|
22
|
-
function Extends(L, R, T, F, options
|
|
22
|
+
function Extends(L, R, T, F, options) {
|
|
23
23
|
// prettier-ignore
|
|
24
24
|
return ((0, kind_1.IsMappedResult)(L) ? (0, extends_from_mapped_result_1.ExtendsFromMappedResult)(L, R, T, F, options) :
|
|
25
|
-
(0, kind_1.IsMappedKey)(L) ? (0, type_1.
|
|
26
|
-
(0, type_1.
|
|
25
|
+
(0, kind_1.IsMappedKey)(L) ? (0, type_1.CreateType)((0, extends_from_mapped_key_1.ExtendsFromMappedKey)(L, R, T, F, options)) :
|
|
26
|
+
(0, type_1.CreateType)(ExtendsResolve(L, R, T, F), options));
|
|
27
27
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Extract = Extract;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../union/index");
|
|
6
7
|
const index_2 = require("../never/index");
|
|
7
8
|
const index_3 = require("../extends/index");
|
|
8
|
-
const type_1 = require("../clone/type");
|
|
9
9
|
const extract_from_mapped_result_1 = require("./extract-from-mapped-result");
|
|
10
10
|
const extract_from_template_literal_1 = require("./extract-from-template-literal");
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -17,13 +17,13 @@ function ExtractRest(L, R) {
|
|
|
17
17
|
return extracted.length === 1 ? extracted[0] : (0, index_1.Union)(extracted);
|
|
18
18
|
}
|
|
19
19
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
20
|
-
function Extract(L, R, options
|
|
20
|
+
function Extract(L, R, options) {
|
|
21
21
|
// overloads
|
|
22
22
|
if ((0, kind_1.IsTemplateLiteral)(L))
|
|
23
|
-
return (0, type_1.
|
|
23
|
+
return (0, type_1.CreateType)((0, extract_from_template_literal_1.ExtractFromTemplateLiteral)(L, R), options);
|
|
24
24
|
if ((0, kind_1.IsMappedResult)(L))
|
|
25
|
-
return (0, type_1.
|
|
25
|
+
return (0, type_1.CreateType)((0, extract_from_mapped_result_1.ExtractFromMappedResult)(L, R), options);
|
|
26
26
|
// prettier-ignore
|
|
27
|
-
return (0, type_1.
|
|
27
|
+
return (0, type_1.CreateType)((0, kind_1.IsUnion)(L) ? ExtractRest(L.anyOf, R) :
|
|
28
28
|
(0, index_3.ExtendsCheck)(L, R) !== index_3.ExtendsResult.False ? L : (0, index_2.Never)(), options);
|
|
29
29
|
}
|
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Function = Function;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[JavaScript]` Creates a Function type */
|
|
8
8
|
function Function(parameters, returns, options) {
|
|
9
|
-
return {
|
|
10
|
-
...options,
|
|
11
|
-
[index_1.Kind]: 'Function',
|
|
12
|
-
type: 'Function',
|
|
13
|
-
parameters: (0, type_1.CloneRest)(parameters),
|
|
14
|
-
returns: (0, type_1.CloneType)(returns),
|
|
15
|
-
};
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Function', type: 'Function', parameters, returns }, options);
|
|
16
10
|
}
|
|
@@ -16,6 +16,9 @@ exports.IsString = IsString;
|
|
|
16
16
|
exports.IsSymbol = IsSymbol;
|
|
17
17
|
exports.IsUint8Array = IsUint8Array;
|
|
18
18
|
exports.IsUndefined = IsUndefined;
|
|
19
|
+
// --------------------------------------------------------------------------
|
|
20
|
+
// Object Instances
|
|
21
|
+
// --------------------------------------------------------------------------
|
|
19
22
|
/** Returns true if this value is an async iterator */
|
|
20
23
|
function IsAsyncIterator(value) {
|
|
21
24
|
return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
|
|
@@ -9,5 +9,5 @@ type TMappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
|
9
9
|
type TMappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedIndexPropertyKeys<T, R, Acc & TMappedIndexPropertyKey<T, L>> : Acc);
|
|
10
10
|
type TMappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<T, K['keys']>>;
|
|
11
11
|
export type TIndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>> = (Ensure<TMappedResult<P>>);
|
|
12
|
-
export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options
|
|
12
|
+
export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
|
|
13
13
|
export {};
|
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.IndexFromMappedKey = IndexFromMappedKey;
|
|
5
5
|
const indexed_1 = require("./indexed");
|
|
6
6
|
const index_1 = require("../mapped/index");
|
|
7
|
+
const value_1 = require("../clone/value");
|
|
7
8
|
// prettier-ignore
|
|
8
9
|
function MappedIndexPropertyKey(T, K, options) {
|
|
9
|
-
return { [K]: (0, indexed_1.Index)(T, [K], options) };
|
|
10
|
+
return { [K]: (0, indexed_1.Index)(T, [K], (0, value_1.Clone)(options)) };
|
|
10
11
|
}
|
|
11
12
|
// prettier-ignore
|
|
12
13
|
function MappedIndexPropertyKeys(T, K, options) {
|
|
@@ -8,5 +8,5 @@ type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
|
8
8
|
});
|
|
9
9
|
type TFromMappedResult<T extends TSchema, R extends TMappedResult> = (TFromProperties<T, R['properties']>);
|
|
10
10
|
export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
|
|
11
|
-
export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options
|
|
11
|
+
export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.IndexFromPropertyKey = IndexFromPropertyKey;
|
|
5
5
|
exports.IndexFromPropertyKeys = IndexFromPropertyKeys;
|
|
6
6
|
exports.Index = Index;
|
|
7
|
+
const type_1 = require("../create/type");
|
|
7
8
|
const index_1 = require("../never/index");
|
|
8
9
|
const index_2 = require("../intersect/index");
|
|
9
10
|
const index_3 = require("../union/index");
|
|
10
|
-
const type_1 = require("../clone/type");
|
|
11
11
|
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
12
12
|
const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
|
|
13
13
|
const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
|
|
@@ -71,10 +71,14 @@ function FromSchema(T, K) {
|
|
|
71
71
|
return ((0, index_3.UnionEvaluated)(IndexFromPropertyKeys(T, K)));
|
|
72
72
|
}
|
|
73
73
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
74
|
-
function Index(T, K, options
|
|
74
|
+
function Index(T, K, options) {
|
|
75
|
+
// mapped-types
|
|
76
|
+
if ((0, kind_1.IsMappedResult)(K))
|
|
77
|
+
return (0, indexed_from_mapped_result_1.IndexFromMappedResult)(T, K, options);
|
|
78
|
+
if ((0, kind_1.IsMappedKey)(K))
|
|
79
|
+
return (0, indexed_from_mapped_key_1.IndexFromMappedKey)(T, K, options);
|
|
75
80
|
// prettier-ignore
|
|
76
|
-
return (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0, type_1.CloneType)(FromSchema(T, K), options));
|
|
81
|
+
return (0, type_1.CreateType)((0, kind_1.IsSchema)(K)
|
|
82
|
+
? FromSchema(T, (0, indexed_property_keys_1.IndexPropertyKeys)(K))
|
|
83
|
+
: FromSchema(T, K), options);
|
|
80
84
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.InstanceType = InstanceType;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
7
|
-
function InstanceType(schema, options
|
|
8
|
-
return (0, type_1.
|
|
7
|
+
function InstanceType(schema, options) {
|
|
8
|
+
return (0, type_1.CreateType)(schema.returns, options);
|
|
9
9
|
}
|