@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TypeSystemPolicy } from '../../system/policy.mjs';
|
|
2
|
+
import { Immutable } from './immutable.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
4
|
+
/** Creates TypeBox schematics using the configured InstanceMode */
|
|
5
|
+
export function CreateType(schema, options) {
|
|
6
|
+
const result = options !== undefined ? Object.assign(options, schema) : schema;
|
|
7
|
+
switch (TypeSystemPolicy.InstanceMode) {
|
|
8
|
+
case 'freeze':
|
|
9
|
+
return Immutable(result);
|
|
10
|
+
case 'clone':
|
|
11
|
+
return Clone(result);
|
|
12
|
+
default:
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
3
|
/** `[JavaScript]` Creates a Date type */
|
|
3
|
-
export function Date(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Date',
|
|
7
|
-
type: 'Date',
|
|
8
|
-
};
|
|
4
|
+
export function Date(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Date', type: 'Date' }, options);
|
|
9
6
|
}
|
|
@@ -2,6 +2,7 @@ function DiscardKey(value, key) {
|
|
|
2
2
|
const { [key]: _, ...rest } = value;
|
|
3
3
|
return rest;
|
|
4
4
|
}
|
|
5
|
+
/** Discards property keys from the given value. This function returns a shallow Clone. */
|
|
5
6
|
export function Discard(value, keys) {
|
|
6
7
|
return keys.reduce((acc, key) => DiscardKey(acc, key), value);
|
|
7
8
|
}
|
|
@@ -6,7 +6,7 @@ import { Union } from '../union/index.mjs';
|
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
import { IsUndefined } from '../guard/value.mjs';
|
|
8
8
|
/** `[Json]` Creates a Enum type */
|
|
9
|
-
export function Enum(item, options
|
|
9
|
+
export function Enum(item, options) {
|
|
10
10
|
if (IsUndefined(item))
|
|
11
11
|
throw new Error('Enum undefined or empty');
|
|
12
12
|
const values1 = globalThis.Object.getOwnPropertyNames(item)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Union } from '../union/index.mjs';
|
|
2
3
|
import { Never } from '../never/index.mjs';
|
|
3
4
|
import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
|
|
4
|
-
import { CloneType } from '../clone/type.mjs';
|
|
5
5
|
import { ExcludeFromMappedResult } from './exclude-from-mapped-result.mjs';
|
|
6
6
|
import { ExcludeFromTemplateLiteral } from './exclude-from-template-literal.mjs';
|
|
7
7
|
// ------------------------------------------------------------------
|
|
@@ -16,10 +16,10 @@ function ExcludeRest(L, R) {
|
|
|
16
16
|
export function Exclude(L, R, options = {}) {
|
|
17
17
|
// overloads
|
|
18
18
|
if (IsTemplateLiteral(L))
|
|
19
|
-
return
|
|
19
|
+
return CreateType(ExcludeFromTemplateLiteral(L, R), options);
|
|
20
20
|
if (IsMappedResult(L))
|
|
21
|
-
return
|
|
21
|
+
return CreateType(ExcludeFromMappedResult(L, R), options);
|
|
22
22
|
// prettier-ignore
|
|
23
|
-
return
|
|
23
|
+
return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) :
|
|
24
24
|
ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
|
|
25
25
|
}
|
|
@@ -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 {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Literal } from '../literal/index.mjs';
|
|
3
3
|
import { Extends } from './extends.mjs';
|
|
4
|
+
import { Clone } from '../clone/value.mjs';
|
|
4
5
|
// prettier-ignore
|
|
5
6
|
function FromPropertyKey(K, U, L, R, options) {
|
|
6
7
|
return {
|
|
7
|
-
[K]: Extends(Literal(K), U, L, R, options)
|
|
8
|
+
[K]: Extends(Literal(K), U, L, R, Clone(options))
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
// 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 {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Extends } from './extends.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromProperties(P, Right, True, False, options) {
|
|
5
6
|
const Acc = {};
|
|
6
7
|
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
-
Acc[K2] = Extends(P[K2], Right, True, False, options);
|
|
8
|
+
Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
|
|
8
9
|
return Acc;
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Union } from '../union/index.mjs';
|
|
2
3
|
import { ExtendsCheck, ExtendsResult } from './extends-check.mjs';
|
|
3
|
-
import { CloneType } from '../clone/type.mjs';
|
|
4
4
|
import { ExtendsFromMappedKey } from './extends-from-mapped-key.mjs';
|
|
5
5
|
import { ExtendsFromMappedResult } from './extends-from-mapped-result.mjs';
|
|
6
6
|
// ------------------------------------------------------------------
|
|
@@ -15,9 +15,9 @@ function ExtendsResolve(left, right, trueType, falseType) {
|
|
|
15
15
|
falseType);
|
|
16
16
|
}
|
|
17
17
|
/** `[Json]` Creates a Conditional type */
|
|
18
|
-
export function Extends(L, R, T, F, options
|
|
18
|
+
export function Extends(L, R, T, F, options) {
|
|
19
19
|
// prettier-ignore
|
|
20
20
|
return (IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) :
|
|
21
|
-
IsMappedKey(L) ?
|
|
22
|
-
|
|
21
|
+
IsMappedKey(L) ? CreateType(ExtendsFromMappedKey(L, R, T, F, options)) :
|
|
22
|
+
CreateType(ExtendsResolve(L, R, T, F), options));
|
|
23
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Union } from '../union/index.mjs';
|
|
2
3
|
import { Never } from '../never/index.mjs';
|
|
3
4
|
import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
|
|
4
|
-
import { CloneType } from '../clone/type.mjs';
|
|
5
5
|
import { ExtractFromMappedResult } from './extract-from-mapped-result.mjs';
|
|
6
6
|
import { ExtractFromTemplateLiteral } from './extract-from-template-literal.mjs';
|
|
7
7
|
// ------------------------------------------------------------------
|
|
@@ -13,13 +13,13 @@ function ExtractRest(L, R) {
|
|
|
13
13
|
return extracted.length === 1 ? extracted[0] : Union(extracted);
|
|
14
14
|
}
|
|
15
15
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
16
|
-
export function Extract(L, R, options
|
|
16
|
+
export function Extract(L, R, options) {
|
|
17
17
|
// overloads
|
|
18
18
|
if (IsTemplateLiteral(L))
|
|
19
|
-
return
|
|
19
|
+
return CreateType(ExtractFromTemplateLiteral(L, R), options);
|
|
20
20
|
if (IsMappedResult(L))
|
|
21
|
-
return
|
|
21
|
+
return CreateType(ExtractFromMappedResult(L, R), options);
|
|
22
22
|
// prettier-ignore
|
|
23
|
-
return
|
|
23
|
+
return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) :
|
|
24
24
|
ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
|
|
25
25
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates a Function type */
|
|
4
4
|
export function Function(parameters, returns, options) {
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Function',
|
|
8
|
-
type: 'Function',
|
|
9
|
-
parameters: CloneRest(parameters),
|
|
10
|
-
returns: CloneType(returns),
|
|
11
|
-
};
|
|
5
|
+
return CreateType({ [Kind]: 'Function', type: 'Function', parameters, returns }, options);
|
|
12
6
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// --------------------------------------------------------------------------
|
|
2
|
+
// Object Instances
|
|
3
|
+
// --------------------------------------------------------------------------
|
|
1
4
|
/** Returns true if this value is an async iterator */
|
|
2
5
|
export function IsAsyncIterator(value) {
|
|
3
6
|
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 {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Index } from './indexed.mjs';
|
|
2
2
|
import { MappedResult } from '../mapped/index.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function MappedIndexPropertyKey(T, K, options) {
|
|
5
|
-
return { [K]: Index(T, [K], options) };
|
|
6
|
+
return { [K]: Index(T, [K], Clone(options)) };
|
|
6
7
|
}
|
|
7
8
|
// prettier-ignore
|
|
8
9
|
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 {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Never } from '../never/index.mjs';
|
|
2
3
|
import { IntersectEvaluated } from '../intersect/index.mjs';
|
|
3
4
|
import { UnionEvaluated } from '../union/index.mjs';
|
|
4
|
-
import { CloneType } from '../clone/type.mjs';
|
|
5
5
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
6
6
|
import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
7
7
|
import { IndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
@@ -65,10 +65,14 @@ function FromSchema(T, K) {
|
|
|
65
65
|
return (UnionEvaluated(IndexFromPropertyKeys(T, K)));
|
|
66
66
|
}
|
|
67
67
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
68
|
-
export function Index(T, K, options
|
|
68
|
+
export function Index(T, K, options) {
|
|
69
|
+
// mapped-types
|
|
70
|
+
if (IsMappedResult(K))
|
|
71
|
+
return IndexFromMappedResult(T, K, options);
|
|
72
|
+
if (IsMappedKey(K))
|
|
73
|
+
return IndexFromMappedKey(T, K, options);
|
|
69
74
|
// prettier-ignore
|
|
70
|
-
return (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
CloneType(FromSchema(T, K), options));
|
|
75
|
+
return CreateType(IsSchema(K)
|
|
76
|
+
? FromSchema(T, IndexPropertyKeys(K))
|
|
77
|
+
: FromSchema(T, K), options);
|
|
74
78
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
3
|
-
export function InstanceType(schema, options
|
|
4
|
-
return
|
|
3
|
+
export function InstanceType(schema, options) {
|
|
4
|
+
return CreateType(schema.returns, options);
|
|
5
5
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates an Integer type */
|
|
3
|
-
export function Integer(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Integer',
|
|
7
|
-
type: 'integer',
|
|
8
|
-
};
|
|
4
|
+
export function Integer(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Integer', type: 'integer' }, options);
|
|
9
6
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
2
|
import type { TIntersect, IntersectOptions } from './intersect-type.mjs';
|
|
3
|
-
export declare function IntersectCreate<T extends TSchema[]>(T: [...T], options
|
|
3
|
+
export declare function IntersectCreate<T extends TSchema[]>(T: [...T], options?: IntersectOptions): TIntersect<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
-
import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
@@ -8,12 +8,12 @@ import { IsObject, IsSchema } from '../guard/kind.mjs';
|
|
|
8
8
|
// IntersectCreate
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
export function IntersectCreate(T, options) {
|
|
11
|
+
export function IntersectCreate(T, options = {}) {
|
|
12
12
|
const allObjects = T.every((schema) => IsObject(schema));
|
|
13
13
|
const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties)
|
|
14
|
-
? { unevaluatedProperties:
|
|
14
|
+
? { unevaluatedProperties: options.unevaluatedProperties }
|
|
15
15
|
: {};
|
|
16
|
-
return ((options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects
|
|
17
|
-
? { ...
|
|
18
|
-
: { ...
|
|
16
|
+
return CreateType((options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects
|
|
17
|
+
? { ...clonedUnevaluatedProperties, [Kind]: 'Intersect', type: 'object', allOf: T }
|
|
18
|
+
: { ...clonedUnevaluatedProperties, [Kind]: 'Intersect', allOf: T }), options);
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OptionalKind } from '../symbols/index.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { CreateType } from '../create/type.mjs';
|
|
3
3
|
import { Discard } from '../discard/index.mjs';
|
|
4
4
|
import { Never } from '../never/index.mjs';
|
|
5
5
|
import { Optional } from '../optional/index.mjs';
|
|
@@ -31,7 +31,7 @@ export function IntersectEvaluated(T, options = {}) {
|
|
|
31
31
|
if (T.length === 0)
|
|
32
32
|
return Never(options);
|
|
33
33
|
if (T.length === 1)
|
|
34
|
-
return
|
|
34
|
+
return CreateType(T[0], options);
|
|
35
35
|
if (T.some((schema) => IsTransform(schema)))
|
|
36
36
|
throw new Error('Cannot intersect transform types');
|
|
37
37
|
return ResolveIntersect(T, options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Never } from '../never/index.mjs';
|
|
3
3
|
import { IntersectCreate } from './intersect-create.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
@@ -6,11 +6,11 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
import { IsTransform } from '../guard/kind.mjs';
|
|
8
8
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
9
|
-
export function Intersect(T, options
|
|
9
|
+
export function Intersect(T, options) {
|
|
10
10
|
if (T.length === 0)
|
|
11
11
|
return Never(options);
|
|
12
12
|
if (T.length === 1)
|
|
13
|
-
return
|
|
13
|
+
return CreateType(T[0], options);
|
|
14
14
|
if (T.some((schema) => IsTransform(schema)))
|
|
15
15
|
throw new Error('Cannot intersect transform types');
|
|
16
16
|
return IntersectCreate(T, options);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Intrinsic } from './intrinsic.mjs';
|
|
3
3
|
import { Literal } from '../literal/index.mjs';
|
|
4
|
+
import { Clone } from '../clone/value.mjs';
|
|
4
5
|
// prettier-ignore
|
|
5
6
|
function MappedIntrinsicPropertyKey(K, M, options) {
|
|
6
7
|
return {
|
|
7
|
-
[K]: Intrinsic(Literal(K), M, options)
|
|
8
|
+
[K]: Intrinsic(Literal(K), M, Clone(options))
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
11
12
|
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
12
|
-
|
|
13
|
+
const result = K.reduce((Acc, L) => {
|
|
13
14
|
return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
|
|
14
15
|
}, {});
|
|
16
|
+
return result;
|
|
15
17
|
}
|
|
16
18
|
// prettier-ignore
|
|
17
19
|
function MappedIntrinsicProperties(T, M, options) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { TemplateLiteral, TemplateLiteralParseExact, IsTemplateLiteralExpressionFinite, TemplateLiteralExpressionGenerate } from '../template-literal/index.mjs';
|
|
2
3
|
import { IntrinsicFromMappedKey } from './intrinsic-from-mapped-key.mjs';
|
|
3
4
|
import { Literal } from '../literal/index.mjs';
|
|
@@ -58,5 +59,6 @@ export function Intrinsic(schema, mode, options = {}) {
|
|
|
58
59
|
IsTemplateLiteral(schema) ? FromTemplateLiteral(schema, mode, schema) :
|
|
59
60
|
IsUnion(schema) ? Union(FromRest(schema.anyOf, mode), options) :
|
|
60
61
|
IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
|
|
61
|
-
|
|
62
|
+
// Default Type
|
|
63
|
+
CreateType(schema, options));
|
|
62
64
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates an Iterator type */
|
|
4
|
-
export function Iterator(items, options
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Iterator',
|
|
8
|
-
type: 'Iterator',
|
|
9
|
-
items: CloneType(items),
|
|
10
|
-
};
|
|
4
|
+
export function Iterator(items, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Iterator', type: 'Iterator', items }, options);
|
|
11
6
|
}
|
|
@@ -8,5 +8,5 @@ type TFromProperties<K extends TProperties> = ({
|
|
|
8
8
|
});
|
|
9
9
|
type TFromMappedResult<R extends TMappedResult> = (Evaluate<TFromProperties<R['properties']>>);
|
|
10
10
|
export type TKeyOfFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
|
|
11
|
-
export declare function KeyOfFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options
|
|
11
|
+
export declare function KeyOfFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { KeyOf } from './keyof.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromProperties(K, options) {
|
|
5
6
|
const Acc = {};
|
|
6
7
|
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
7
|
-
Acc[K2] = KeyOf(K[K2], options);
|
|
8
|
+
Acc[K2] = KeyOf(K[K2], Clone(options));
|
|
8
9
|
return Acc;
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Literal } from '../literal/index.mjs';
|
|
2
3
|
import { Number } from '../number/index.mjs';
|
|
3
4
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
4
5
|
import { UnionEvaluated } from '../union/index.mjs';
|
|
5
|
-
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
@@ -13,7 +13,7 @@ export function KeyOfPropertyKeysToRest(T) {
|
|
|
13
13
|
return T.map(L => L === '[number]' ? Number() : Literal(L));
|
|
14
14
|
}
|
|
15
15
|
/** `[Json]` Creates a KeyOf type */
|
|
16
|
-
export function KeyOf(T, options
|
|
16
|
+
export function KeyOf(T, options) {
|
|
17
17
|
if (IsMappedResult(T)) {
|
|
18
18
|
return KeyOfFromMappedResult(T, options);
|
|
19
19
|
}
|
|
@@ -21,6 +21,6 @@ export function KeyOf(T, options = {}) {
|
|
|
21
21
|
const K = KeyOfPropertyKeys(T);
|
|
22
22
|
const S = KeyOfPropertyKeysToRest(K);
|
|
23
23
|
const U = UnionEvaluated(S);
|
|
24
|
-
return
|
|
24
|
+
return CreateType(U, options);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a Literal type */
|
|
3
|
-
export function Literal(value, options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
4
|
+
export function Literal(value, options) {
|
|
5
|
+
return CreateType({
|
|
6
6
|
[Kind]: 'Literal',
|
|
7
7
|
const: value,
|
|
8
8
|
type: typeof value,
|
|
9
|
-
};
|
|
9
|
+
}, options);
|
|
10
10
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Kind, OptionalKind, ReadonlyKind } from '../symbols/index.mjs';
|
|
2
|
-
import { CloneType } from '../clone/type.mjs';
|
|
3
2
|
import { Discard } from '../discard/index.mjs';
|
|
4
3
|
// evaluation types
|
|
5
4
|
import { Array } from '../array/index.mjs';
|
|
@@ -93,9 +92,9 @@ export function MappedFunctionReturnType(K, T) {
|
|
|
93
92
|
return Acc;
|
|
94
93
|
}
|
|
95
94
|
/** `[Json]` Creates a Mapped object type */
|
|
96
|
-
export function Mapped(key, map, options
|
|
95
|
+
export function Mapped(key, map, options) {
|
|
97
96
|
const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
98
97
|
const RT = map({ [Kind]: 'MappedKey', keys: K });
|
|
99
98
|
const R = MappedFunctionReturnType(K, RT);
|
|
100
|
-
return
|
|
99
|
+
return Object(R, options);
|
|
101
100
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a Never type */
|
|
3
|
-
export function Never(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Never',
|
|
7
|
-
not: {},
|
|
8
|
-
};
|
|
4
|
+
export function Never(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Never', not: {} }, options);
|
|
9
6
|
}
|
|
@@ -7,4 +7,4 @@ export interface TNot<T extends TSchema = TSchema> extends TSchema {
|
|
|
7
7
|
not: T;
|
|
8
8
|
}
|
|
9
9
|
/** `[Json]` Creates a Not type */
|
|
10
|
-
export declare function Not<T extends TSchema>(
|
|
10
|
+
export declare function Not<T extends TSchema>(not: T, options?: SchemaOptions): TNot<T>;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[Json]` Creates a Not type */
|
|
4
|
-
export function Not(
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Not',
|
|
8
|
-
not: CloneType(schema),
|
|
9
|
-
};
|
|
4
|
+
export function Not(not, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Not', not }, options);
|
|
10
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a Null type */
|
|
3
|
-
export function Null(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Null',
|
|
7
|
-
type: 'null',
|
|
8
|
-
};
|
|
4
|
+
export function Null(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Null', type: 'null' }, options);
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a Number type */
|
|
3
|
-
export function Number(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Number',
|
|
7
|
-
type: 'number',
|
|
8
|
-
};
|
|
4
|
+
export function Number(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Number', type: 'number' }, options);
|
|
9
6
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
import { IsOptional
|
|
6
|
+
import { IsOptional } from '../guard/kind.mjs';
|
|
7
|
+
function RequiredKeys(properties) {
|
|
8
|
+
const keys = [];
|
|
9
|
+
for (let key in properties) {
|
|
10
|
+
if (!IsOptional(properties[key]))
|
|
11
|
+
keys.push(key);
|
|
12
|
+
}
|
|
13
|
+
return keys;
|
|
14
|
+
}
|
|
7
15
|
/** `[Json]` Creates an Object type */
|
|
8
|
-
function _Object(properties, options
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const clonedAdditionalProperties = IsSchema(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
|
|
13
|
-
const clonedProperties = {};
|
|
14
|
-
for (const key of propertyKeys)
|
|
15
|
-
clonedProperties[key] = CloneType(properties[key]);
|
|
16
|
-
return (requiredKeys.length > 0
|
|
17
|
-
? { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
|
|
18
|
-
: { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
16
|
+
function _Object(properties, options) {
|
|
17
|
+
const required = RequiredKeys(properties);
|
|
18
|
+
const schematic = required.length > 0 ? { [Kind]: 'Object', type: 'object', properties, required } : { [Kind]: 'Object', type: 'object', properties };
|
|
19
|
+
return CreateType(schematic, options);
|
|
19
20
|
}
|
|
20
21
|
/** `[Json]` Creates an Object type */
|
|
21
22
|
export const Object = _Object;
|
|
@@ -8,5 +8,5 @@ type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
|
8
8
|
type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
|
|
9
9
|
type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
|
|
10
10
|
export type TOmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
|
|
11
|
-
export declare function OmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options
|
|
11
|
+
export declare function OmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|