@sinclair/typebox 0.34.0 → 0.34.1
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/syntax/runtime.d.ts +4 -1
- package/build/cjs/syntax/runtime.js +3 -1
- package/build/cjs/syntax/static.d.ts +3 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/computed/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -4
- package/build/cjs/type/guard/kind.js +10 -0
- package/build/cjs/type/guard/type.d.ts +6 -3
- package/build/cjs/type/guard/type.js +6 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +8 -52
- package/build/cjs/type/module/module.js +14 -11
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +41 -51
- package/build/cjs/type/type/json.js +40 -40
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/check/check.js +3 -3
- package/build/cjs/value/transform/decode.js +7 -7
- package/build/cjs/value/transform/encode.js +7 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/syntax/runtime.d.mts +4 -1
- package/build/esm/syntax/runtime.mjs +3 -1
- package/build/esm/syntax/static.d.mts +3 -3
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +9 -4
- package/build/esm/type/guard/kind.mjs +8 -0
- package/build/esm/type/guard/type.d.mts +6 -3
- package/build/esm/type/guard/type.mjs +5 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +8 -52
- package/build/esm/type/module/module.mjs +14 -11
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +41 -51
- package/build/esm/type/type/json.mjs +40 -40
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/check/check.mjs +2 -2
- package/build/esm/value/transform/decode.mjs +2 -2
- package/build/esm/value/transform/encode.mjs +2 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +30 -19
|
@@ -3,50 +3,62 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Required = Required;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
-
const index_1 = require("../
|
|
7
|
-
const index_2 = require("../
|
|
8
|
-
const index_3 = require("../
|
|
9
|
-
const index_4 = require("../
|
|
10
|
-
const index_5 = require("../
|
|
6
|
+
const index_1 = require("../computed/index");
|
|
7
|
+
const index_2 = require("../object/index");
|
|
8
|
+
const index_3 = require("../intersect/index");
|
|
9
|
+
const index_4 = require("../union/index");
|
|
10
|
+
const index_5 = require("../ref/index");
|
|
11
|
+
const index_6 = require("../symbols/index");
|
|
12
|
+
const index_7 = require("../discard/index");
|
|
11
13
|
const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
12
14
|
// ------------------------------------------------------------------
|
|
13
15
|
// TypeGuard
|
|
14
16
|
// ------------------------------------------------------------------
|
|
15
17
|
const kind_1 = require("../guard/kind");
|
|
16
18
|
// prettier-ignore
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
+
function FromComputed(target, parameters) {
|
|
20
|
+
return (0, index_1.Computed)('Required', [(0, index_1.Computed)(target, parameters)]);
|
|
19
21
|
}
|
|
20
22
|
// prettier-ignore
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
24
|
-
Acc[K] = (0, index_5.Discard)(T[K], [index_4.OptionalKind]);
|
|
25
|
-
return Acc;
|
|
23
|
+
function FromRef($ref) {
|
|
24
|
+
return (0, index_1.Computed)('Required', [(0, index_5.Ref)($ref)]);
|
|
26
25
|
}
|
|
27
26
|
// prettier-ignore
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
27
|
+
function FromProperties(properties) {
|
|
28
|
+
const requiredProperties = {};
|
|
29
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
30
|
+
requiredProperties[K] = (0, index_7.Discard)(properties[K], [index_6.OptionalKind]);
|
|
31
|
+
return requiredProperties;
|
|
32
|
+
}
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
function FromObject(type) {
|
|
35
|
+
const options = (0, index_7.Discard)(type, [index_6.TransformKind, '$id', 'required', 'properties']);
|
|
36
|
+
const properties = FromProperties(type['properties']);
|
|
37
|
+
return (0, index_2.Object)(properties, options);
|
|
38
|
+
}
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
function FromRest(types) {
|
|
41
|
+
return types.map(type => RequiredResolve(type));
|
|
32
42
|
}
|
|
33
43
|
// ------------------------------------------------------------------
|
|
34
44
|
// RequiredResolve
|
|
35
45
|
// ------------------------------------------------------------------
|
|
36
46
|
// prettier-ignore
|
|
37
|
-
function RequiredResolve(
|
|
38
|
-
return ((0, kind_1.
|
|
39
|
-
(0, kind_1.
|
|
40
|
-
(0, kind_1.
|
|
41
|
-
(0,
|
|
47
|
+
function RequiredResolve(type) {
|
|
48
|
+
return ((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) :
|
|
49
|
+
(0, kind_1.IsRef)(type) ? FromRef(type.$ref) :
|
|
50
|
+
(0, kind_1.IsIntersect)(type) ? (0, index_3.Intersect)(FromRest(type.allOf)) :
|
|
51
|
+
(0, kind_1.IsUnion)(type) ? (0, index_4.Union)(FromRest(type.anyOf)) :
|
|
52
|
+
(0, kind_1.IsObject)(type) ? FromObject(type) :
|
|
53
|
+
(0, index_2.Object)({}));
|
|
42
54
|
}
|
|
43
55
|
/** `[Json]` Constructs a type where all properties are required */
|
|
44
|
-
function Required(
|
|
45
|
-
if ((0, kind_1.IsMappedResult)(
|
|
46
|
-
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(
|
|
56
|
+
function Required(type, options) {
|
|
57
|
+
if ((0, kind_1.IsMappedResult)(type)) {
|
|
58
|
+
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(type, options);
|
|
47
59
|
}
|
|
48
60
|
else {
|
|
49
61
|
// special: mapping types require overridable options
|
|
50
|
-
return (0, type_1.CreateType)({ ...RequiredResolve(
|
|
62
|
+
return (0, type_1.CreateType)({ ...RequiredResolve(type), ...options });
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -12,5 +12,5 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
12
12
|
maxItems: number;
|
|
13
13
|
}
|
|
14
14
|
/** `[Json]` Creates a Tuple type */
|
|
15
|
-
export declare function Tuple<
|
|
15
|
+
export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
|
16
16
|
export {};
|
|
@@ -5,9 +5,9 @@ exports.Tuple = Tuple;
|
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[Json]` Creates a Tuple type */
|
|
8
|
-
function Tuple(
|
|
8
|
+
function Tuple(types, options) {
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
return (0, type_1.CreateType)(
|
|
11
|
-
{ [index_1.Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems:
|
|
12
|
-
{ [index_1.Kind]: 'Tuple', type: 'array', minItems:
|
|
10
|
+
return (0, type_1.CreateType)(types.length > 0 ?
|
|
11
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', items: types, additionalItems: false, minItems: types.length, maxItems: types.length } :
|
|
12
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', minItems: types.length, maxItems: types.length }, options);
|
|
13
13
|
}
|
|
@@ -20,33 +20,33 @@ import { type TVoid } from '../void/index';
|
|
|
20
20
|
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
21
21
|
export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
22
22
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
23
|
-
AsyncIterator<
|
|
23
|
+
AsyncIterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TAsyncIterator<Type>;
|
|
24
24
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
25
|
-
Awaited<
|
|
25
|
+
Awaited<Type extends TSchema>(schema: Type, options?: SchemaOptions): TAwaited<Type>;
|
|
26
26
|
/** `[JavaScript]` Creates a BigInt type */
|
|
27
27
|
BigInt(options?: BigIntOptions): TBigInt;
|
|
28
28
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
29
|
-
ConstructorParameters<
|
|
29
|
+
ConstructorParameters<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
|
|
30
30
|
/** `[JavaScript]` Creates a Constructor type */
|
|
31
|
-
Constructor<
|
|
31
|
+
Constructor<Parameters extends TSchema[], InstanceType extends TSchema>(parameters: [...Parameters], instanceType: InstanceType, options?: SchemaOptions): TConstructor<Parameters, InstanceType>;
|
|
32
32
|
/** `[JavaScript]` Creates a Date type */
|
|
33
33
|
Date(options?: DateOptions): TDate;
|
|
34
34
|
/** `[JavaScript]` Creates a Function type */
|
|
35
|
-
Function<
|
|
35
|
+
Function<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: SchemaOptions): TFunction<Parameters, ReturnType>;
|
|
36
36
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
37
|
-
InstanceType<
|
|
37
|
+
InstanceType<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
|
|
38
38
|
/** `[JavaScript]` Creates an Iterator type */
|
|
39
|
-
Iterator<
|
|
39
|
+
Iterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TIterator<Type>;
|
|
40
40
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
41
|
-
Parameters<
|
|
41
|
+
Parameters<Type extends TFunction>(schema: Type, options?: SchemaOptions): TParameters<Type>;
|
|
42
42
|
/** `[JavaScript]` Creates a Promise type */
|
|
43
|
-
Promise<
|
|
43
|
+
Promise<Type extends TSchema>(item: Type, options?: SchemaOptions): TPromise<Type>;
|
|
44
44
|
/** `[JavaScript]` Creates a RegExp type */
|
|
45
45
|
RegExp(pattern: string, options?: RegExpOptions): TRegExp;
|
|
46
46
|
/** `[JavaScript]` Creates a RegExp type */
|
|
47
47
|
RegExp(regex: RegExp, options?: RegExpOptions): TRegExp;
|
|
48
48
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
49
|
-
ReturnType<
|
|
49
|
+
ReturnType<Type extends TFunction>(type: Type, options?: SchemaOptions): TReturnType<Type>;
|
|
50
50
|
/** `[JavaScript]` Creates a Symbol type */
|
|
51
51
|
Symbol(options?: SchemaOptions): TSymbol;
|
|
52
52
|
/** `[JavaScript]` Creates a Undefined type */
|
|
@@ -39,16 +39,16 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
39
39
|
return (0, index_5.ConstructorParameters)(schema, options);
|
|
40
40
|
}
|
|
41
41
|
/** `[JavaScript]` Creates a Constructor type */
|
|
42
|
-
Constructor(parameters,
|
|
43
|
-
return (0, index_4.Constructor)(parameters,
|
|
42
|
+
Constructor(parameters, instanceType, options) {
|
|
43
|
+
return (0, index_4.Constructor)(parameters, instanceType, options);
|
|
44
44
|
}
|
|
45
45
|
/** `[JavaScript]` Creates a Date type */
|
|
46
46
|
Date(options = {}) {
|
|
47
47
|
return (0, index_6.Date)(options);
|
|
48
48
|
}
|
|
49
49
|
/** `[JavaScript]` Creates a Function type */
|
|
50
|
-
Function(parameters,
|
|
51
|
-
return (0, index_7.Function)(parameters,
|
|
50
|
+
Function(parameters, returnType, options) {
|
|
51
|
+
return (0, index_7.Function)(parameters, returnType, options);
|
|
52
52
|
}
|
|
53
53
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
54
54
|
InstanceType(schema, options) {
|
|
@@ -71,8 +71,8 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
71
71
|
return (0, index_12.RegExp)(unresolved, options);
|
|
72
72
|
}
|
|
73
73
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
74
|
-
ReturnType(
|
|
75
|
-
return (0, index_13.ReturnType)(
|
|
74
|
+
ReturnType(type, options) {
|
|
75
|
+
return (0, index_13.ReturnType)(type, options);
|
|
76
76
|
}
|
|
77
77
|
/** `[JavaScript]` Creates a Symbol type */
|
|
78
78
|
Symbol(options) {
|
|
@@ -7,11 +7,11 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index';
|
|
|
7
7
|
import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index';
|
|
8
8
|
import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index';
|
|
9
9
|
import { type TExtract, type TExtractFromMappedResult, type TExtractFromTemplateLiteral } from '../extract/index';
|
|
10
|
-
import { TIndex, type TIndexPropertyKeys
|
|
10
|
+
import { TIndex, type TIndexPropertyKeys } from '../indexed/index';
|
|
11
11
|
import { type IntegerOptions, type TInteger } from '../integer/index';
|
|
12
12
|
import { Intersect, type IntersectOptions } from '../intersect/index';
|
|
13
13
|
import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index';
|
|
14
|
-
import { type TKeyOf
|
|
14
|
+
import { type TKeyOf } from '../keyof/index';
|
|
15
15
|
import { type TLiteral, type TLiteralValue } from '../literal/index';
|
|
16
16
|
import { type TMappedFunction, type TMapped, type TMappedResult } from '../mapped/index';
|
|
17
17
|
import { type TNever } from '../never/index';
|
|
@@ -21,10 +21,10 @@ import { type TMappedKey } from '../mapped/index';
|
|
|
21
21
|
import { TModule } from '../module/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
|
|
24
|
+
import { type TOmit } 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
|
|
27
|
+
import { type TPick } 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';
|
|
@@ -43,27 +43,27 @@ import { type TUnsafe, type UnsafeOptions } from '../unsafe/index';
|
|
|
43
43
|
/** Json Type Builder with Static Resolution for TypeScript */
|
|
44
44
|
export declare class JsonTypeBuilder {
|
|
45
45
|
/** `[Json]` Creates a Readonly and Optional property */
|
|
46
|
-
ReadonlyOptional<
|
|
46
|
+
ReadonlyOptional<Type extends TSchema>(type: Type): TReadonlyOptional<Type>;
|
|
47
47
|
/** `[Json]` Creates a Readonly property */
|
|
48
|
-
Readonly<
|
|
48
|
+
Readonly<Type extends TMappedResult, Flag extends boolean>(type: Type, enable: Flag): TReadonlyFromMappedResult<Type, Flag>;
|
|
49
49
|
/** `[Json]` Creates a Readonly property */
|
|
50
|
-
Readonly<
|
|
50
|
+
Readonly<Type extends TSchema, Flag extends boolean>(type: Type, enable: Flag): TReadonlyWithFlag<Type, Flag>;
|
|
51
51
|
/** `[Json]` Creates a Optional property */
|
|
52
|
-
Readonly<
|
|
52
|
+
Readonly<Type extends TMappedResult>(type: Type): TReadonlyFromMappedResult<Type, true>;
|
|
53
53
|
/** `[Json]` Creates a Readonly property */
|
|
54
|
-
Readonly<
|
|
54
|
+
Readonly<Type extends TSchema>(type: Type): TReadonlyWithFlag<Type, true>;
|
|
55
55
|
/** `[Json]` Creates a Optional property */
|
|
56
|
-
Optional<
|
|
56
|
+
Optional<Type extends TMappedResult, Flag extends boolean>(type: Type, enable: Flag): TOptionalFromMappedResult<Type, Flag>;
|
|
57
57
|
/** `[Json]` Creates a Optional property */
|
|
58
|
-
Optional<
|
|
58
|
+
Optional<Type extends TSchema, Flag extends boolean>(type: Type, enable: Flag): TOptionalWithFlag<Type, Flag>;
|
|
59
59
|
/** `[Json]` Creates a Optional property */
|
|
60
|
-
Optional<
|
|
60
|
+
Optional<Type extends TMappedResult>(type: Type): TOptionalFromMappedResult<Type, true>;
|
|
61
61
|
/** `[Json]` Creates a Optional property */
|
|
62
|
-
Optional<
|
|
62
|
+
Optional<Type extends TSchema>(type: Type): TOptionalWithFlag<Type, true>;
|
|
63
63
|
/** `[Json]` Creates an Any type */
|
|
64
64
|
Any(options?: SchemaOptions): TAny;
|
|
65
65
|
/** `[Json]` Creates an Array type */
|
|
66
|
-
Array<
|
|
66
|
+
Array<Type extends TSchema>(items: Type, options?: ArrayOptions): TArray<Type>;
|
|
67
67
|
/** `[Json]` Creates a Boolean type */
|
|
68
68
|
Boolean(options?: SchemaOptions): TBoolean;
|
|
69
69
|
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
@@ -93,25 +93,23 @@ export declare class JsonTypeBuilder {
|
|
|
93
93
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
94
94
|
Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
95
95
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
|
-
Index<
|
|
96
|
+
Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, key: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
|
|
97
97
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
98
|
-
Index<
|
|
98
|
+
Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
99
99
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
100
|
-
Index<
|
|
100
|
+
Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
101
101
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
102
|
-
Index<
|
|
102
|
+
Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
103
103
|
/** `[Json]` Creates an Integer type */
|
|
104
104
|
Integer(options?: IntegerOptions): TInteger;
|
|
105
105
|
/** `[Json]` Creates an Intersect type */
|
|
106
|
-
Intersect<
|
|
106
|
+
Intersect<Types extends TSchema[]>(types: [...Types], options?: IntersectOptions): Intersect<Types>;
|
|
107
107
|
/** `[Json]` Creates a KeyOf type */
|
|
108
|
-
KeyOf<
|
|
109
|
-
/** `[Json]` Creates a KeyOf type */
|
|
110
|
-
KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): TKeyOf<T>;
|
|
108
|
+
KeyOf<Type extends TSchema>(type: Type, options?: SchemaOptions): TKeyOf<Type>;
|
|
111
109
|
/** `[Json]` Creates a Literal type */
|
|
112
|
-
Literal<
|
|
110
|
+
Literal<LiteralValue extends TLiteralValue>(literalValue: LiteralValue, options?: SchemaOptions): TLiteral<LiteralValue>;
|
|
113
111
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
114
|
-
Lowercase<
|
|
112
|
+
Lowercase<Type extends TSchema>(type: Type, options?: SchemaOptions): TLowercase<Type>;
|
|
115
113
|
/** `[Json]` Creates a Mapped object type */
|
|
116
114
|
Mapped<K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>, F extends TMappedFunction<I> = TMappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
117
115
|
/** `[Json]` Creates a Mapped object type */
|
|
@@ -121,59 +119,51 @@ export declare class JsonTypeBuilder {
|
|
|
121
119
|
/** `[Json]` Creates a Never type */
|
|
122
120
|
Never(options?: SchemaOptions): TNever;
|
|
123
121
|
/** `[Json]` Creates a Not type */
|
|
124
|
-
Not<T extends TSchema>(
|
|
122
|
+
Not<T extends TSchema>(type: T, options?: SchemaOptions): TNot<T>;
|
|
125
123
|
/** `[Json]` Creates a Null type */
|
|
126
124
|
Null(options?: SchemaOptions): TNull;
|
|
127
125
|
/** `[Json]` Creates a Number type */
|
|
128
126
|
Number(options?: NumberOptions): TNumber;
|
|
129
127
|
/** `[Json]` Creates an Object type */
|
|
130
128
|
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
131
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
132
|
-
Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
|
|
133
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
134
|
-
Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TOmitFromMappedKey<T, K>;
|
|
135
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
136
|
-
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
137
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
138
|
-
Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
139
|
-
/** `[Json]` Constructs a type where all properties are optional */
|
|
140
|
-
Partial<T extends TMappedResult>(T: T, options?: SchemaOptions): TPartialFromMappedResult<T>;
|
|
141
|
-
/** `[Json]` Constructs a type where all properties are optional */
|
|
142
|
-
Partial<T extends TSchema>(schema: T, options?: SchemaOptions): TPartial<T>;
|
|
143
129
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
144
|
-
|
|
130
|
+
Omit<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TOmit<Type, Key>;
|
|
145
131
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
146
|
-
|
|
132
|
+
Omit<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
|
133
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
134
|
+
Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
135
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
136
|
+
Partial<Type extends TSchema>(type: Type, options?: SchemaOptions): TPartial<Type>;
|
|
147
137
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
148
|
-
Pick<
|
|
138
|
+
Pick<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
|
149
139
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
150
|
-
Pick<
|
|
140
|
+
Pick<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TPick<Type, Key>;
|
|
151
141
|
/** `[Json]` Creates a Record type */
|
|
152
|
-
Record<
|
|
142
|
+
Record<Key extends TSchema, Value extends TSchema>(key: Key, value: Value, options?: ObjectOptions): TRecordOrObject<Key, Value>;
|
|
153
143
|
/** `[Json]` Creates a Recursive type */
|
|
154
144
|
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
155
145
|
/** `[Json]` Creates a Ref type. */
|
|
156
146
|
Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
157
147
|
/** `[Json]` Constructs a type where all properties are required */
|
|
158
|
-
Required<
|
|
148
|
+
Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
159
149
|
/** `[Json]` Constructs a type where all properties are required */
|
|
160
|
-
Required<
|
|
150
|
+
Required<Type extends TSchema>(type: Type, options?: SchemaOptions): TRequired<Type>;
|
|
161
151
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
162
|
-
Rest<
|
|
152
|
+
Rest<Type extends TSchema>(type: Type): TRest<Type>;
|
|
163
153
|
/** `[Json]` Creates a String type */
|
|
164
154
|
String(options?: StringOptions): TString;
|
|
165
155
|
/** `[Json]` Creates a TemplateLiteral type from template dsl string */
|
|
166
|
-
TemplateLiteral<
|
|
156
|
+
TemplateLiteral<Syntax extends string>(syntax: Syntax, options?: SchemaOptions): TTemplateLiteralSyntax<Syntax>;
|
|
167
157
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
168
|
-
TemplateLiteral<
|
|
158
|
+
TemplateLiteral<Kinds extends TTemplateLiteralKind[]>(kinds: [...Kinds], options?: SchemaOptions): TTemplateLiteral<Kinds>;
|
|
169
159
|
/** `[Json]` Creates a Transform type */
|
|
170
|
-
Transform<
|
|
160
|
+
Transform<Type extends TSchema>(type: Type): TransformDecodeBuilder<Type>;
|
|
171
161
|
/** `[Json]` Creates a Tuple type */
|
|
172
|
-
Tuple<
|
|
162
|
+
Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
|
173
163
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
174
|
-
Uncapitalize<
|
|
164
|
+
Uncapitalize<Type extends TSchema>(type: Type, options?: SchemaOptions): TUncapitalize<Type>;
|
|
175
165
|
/** `[Json]` Creates a Union type */
|
|
176
|
-
Union<
|
|
166
|
+
Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
177
167
|
/** `[Json]` Creates an Unknown type */
|
|
178
168
|
Unknown(options?: SchemaOptions): TUnknown;
|
|
179
169
|
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
@@ -48,16 +48,16 @@ class JsonTypeBuilder {
|
|
|
48
48
|
// Modifiers
|
|
49
49
|
// ------------------------------------------------------------------------
|
|
50
50
|
/** `[Json]` Creates a Readonly and Optional property */
|
|
51
|
-
ReadonlyOptional(
|
|
52
|
-
return (0, index_28.ReadonlyOptional)(
|
|
51
|
+
ReadonlyOptional(type) {
|
|
52
|
+
return (0, index_28.ReadonlyOptional)(type);
|
|
53
53
|
}
|
|
54
54
|
/** `[Json]` Creates a Readonly property */
|
|
55
|
-
Readonly(
|
|
56
|
-
return (0, index_27.Readonly)(
|
|
55
|
+
Readonly(type, enable) {
|
|
56
|
+
return (0, index_27.Readonly)(type, enable ?? true);
|
|
57
57
|
}
|
|
58
58
|
/** `[Json]` Creates a Optional property */
|
|
59
|
-
Optional(
|
|
60
|
-
return (0, index_24.Optional)(
|
|
59
|
+
Optional(type, enable) {
|
|
60
|
+
return (0, index_24.Optional)(type, enable ?? true);
|
|
61
61
|
}
|
|
62
62
|
// ------------------------------------------------------------------------
|
|
63
63
|
// Types
|
|
@@ -67,8 +67,8 @@ class JsonTypeBuilder {
|
|
|
67
67
|
return (0, index_1.Any)(options);
|
|
68
68
|
}
|
|
69
69
|
/** `[Json]` Creates an Array type */
|
|
70
|
-
Array(
|
|
71
|
-
return (0, index_2.Array)(
|
|
70
|
+
Array(items, options) {
|
|
71
|
+
return (0, index_2.Array)(items, options);
|
|
72
72
|
}
|
|
73
73
|
/** `[Json]` Creates a Boolean type */
|
|
74
74
|
Boolean(options) {
|
|
@@ -103,28 +103,28 @@ class JsonTypeBuilder {
|
|
|
103
103
|
return (0, index_9.Extract)(type, union, options);
|
|
104
104
|
}
|
|
105
105
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
106
|
-
Index(
|
|
107
|
-
return (0, index_10.Index)(
|
|
106
|
+
Index(type, key, options) {
|
|
107
|
+
return (0, index_10.Index)(type, key, options);
|
|
108
108
|
}
|
|
109
109
|
/** `[Json]` Creates an Integer type */
|
|
110
110
|
Integer(options) {
|
|
111
111
|
return (0, index_11.Integer)(options);
|
|
112
112
|
}
|
|
113
113
|
/** `[Json]` Creates an Intersect type */
|
|
114
|
-
Intersect(
|
|
115
|
-
return (0, index_12.Intersect)(
|
|
114
|
+
Intersect(types, options) {
|
|
115
|
+
return (0, index_12.Intersect)(types, options);
|
|
116
116
|
}
|
|
117
117
|
/** `[Json]` Creates a KeyOf type */
|
|
118
|
-
KeyOf(
|
|
119
|
-
return (0, index_14.KeyOf)(
|
|
118
|
+
KeyOf(type, options) {
|
|
119
|
+
return (0, index_14.KeyOf)(type, options);
|
|
120
120
|
}
|
|
121
121
|
/** `[Json]` Creates a Literal type */
|
|
122
|
-
Literal(
|
|
123
|
-
return (0, index_15.Literal)(
|
|
122
|
+
Literal(literalValue, options) {
|
|
123
|
+
return (0, index_15.Literal)(literalValue, options);
|
|
124
124
|
}
|
|
125
125
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
126
|
-
Lowercase(
|
|
127
|
-
return (0, index_13.Lowercase)(
|
|
126
|
+
Lowercase(type, options) {
|
|
127
|
+
return (0, index_13.Lowercase)(type, options);
|
|
128
128
|
}
|
|
129
129
|
/** `[Json]` Creates a Mapped object type */
|
|
130
130
|
Mapped(key, map, options) {
|
|
@@ -139,8 +139,8 @@ class JsonTypeBuilder {
|
|
|
139
139
|
return (0, index_17.Never)(options);
|
|
140
140
|
}
|
|
141
141
|
/** `[Json]` Creates a Not type */
|
|
142
|
-
Not(
|
|
143
|
-
return (0, index_18.Not)(
|
|
142
|
+
Not(type, options) {
|
|
143
|
+
return (0, index_18.Not)(type, options);
|
|
144
144
|
}
|
|
145
145
|
/** `[Json]` Creates a Null type */
|
|
146
146
|
Null(options) {
|
|
@@ -155,20 +155,20 @@ class JsonTypeBuilder {
|
|
|
155
155
|
return (0, index_22.Object)(properties, options);
|
|
156
156
|
}
|
|
157
157
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
158
|
-
Omit(schema,
|
|
159
|
-
return (0, index_23.Omit)(schema,
|
|
158
|
+
Omit(schema, selector, options) {
|
|
159
|
+
return (0, index_23.Omit)(schema, selector, options);
|
|
160
160
|
}
|
|
161
161
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
162
|
-
Partial(
|
|
163
|
-
return (0, index_25.Partial)(
|
|
162
|
+
Partial(type, options) {
|
|
163
|
+
return (0, index_25.Partial)(type, options);
|
|
164
164
|
}
|
|
165
165
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
166
|
-
Pick(
|
|
167
|
-
return (0, index_26.Pick)(
|
|
166
|
+
Pick(type, key, options) {
|
|
167
|
+
return (0, index_26.Pick)(type, key, options);
|
|
168
168
|
}
|
|
169
169
|
/** `[Json]` Creates a Record type */
|
|
170
|
-
Record(key,
|
|
171
|
-
return (0, index_29.Record)(key,
|
|
170
|
+
Record(key, value, options) {
|
|
171
|
+
return (0, index_29.Record)(key, value, options);
|
|
172
172
|
}
|
|
173
173
|
/** `[Json]` Creates a Recursive type */
|
|
174
174
|
Recursive(callback, options) {
|
|
@@ -179,12 +179,12 @@ class JsonTypeBuilder {
|
|
|
179
179
|
return (0, index_31.Ref)($ref, options);
|
|
180
180
|
}
|
|
181
181
|
/** `[Json]` Constructs a type where all properties are required */
|
|
182
|
-
Required(
|
|
183
|
-
return (0, index_32.Required)(
|
|
182
|
+
Required(type, options) {
|
|
183
|
+
return (0, index_32.Required)(type, options);
|
|
184
184
|
}
|
|
185
185
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
186
|
-
Rest(
|
|
187
|
-
return (0, index_33.Rest)(
|
|
186
|
+
Rest(type) {
|
|
187
|
+
return (0, index_33.Rest)(type);
|
|
188
188
|
}
|
|
189
189
|
/** `[Json]` Creates a String type */
|
|
190
190
|
String(options) {
|
|
@@ -195,20 +195,20 @@ class JsonTypeBuilder {
|
|
|
195
195
|
return (0, index_35.TemplateLiteral)(unresolved, options);
|
|
196
196
|
}
|
|
197
197
|
/** `[Json]` Creates a Transform type */
|
|
198
|
-
Transform(
|
|
199
|
-
return (0, index_36.Transform)(
|
|
198
|
+
Transform(type) {
|
|
199
|
+
return (0, index_36.Transform)(type);
|
|
200
200
|
}
|
|
201
201
|
/** `[Json]` Creates a Tuple type */
|
|
202
|
-
Tuple(
|
|
203
|
-
return (0, index_37.Tuple)(
|
|
202
|
+
Tuple(types, options) {
|
|
203
|
+
return (0, index_37.Tuple)(types, options);
|
|
204
204
|
}
|
|
205
205
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
206
|
-
Uncapitalize(
|
|
207
|
-
return (0, index_13.Uncapitalize)(
|
|
206
|
+
Uncapitalize(type, options) {
|
|
207
|
+
return (0, index_13.Uncapitalize)(type, options);
|
|
208
208
|
}
|
|
209
209
|
/** `[Json]` Creates a Union type */
|
|
210
|
-
Union(
|
|
211
|
-
return (0, index_38.Union)(
|
|
210
|
+
Union(types, options) {
|
|
211
|
+
return (0, index_38.Union)(types, options);
|
|
212
212
|
}
|
|
213
213
|
/** `[Json]` Creates an Unknown type */
|
|
214
214
|
Unknown(options) {
|
|
@@ -3,11 +3,11 @@ import { type TNever } from '../never/index';
|
|
|
3
3
|
import { type TOptional } from '../optional/index';
|
|
4
4
|
import type { TReadonly } from '../readonly/index';
|
|
5
5
|
import type { TUnion } from './union-type';
|
|
6
|
-
type TIsUnionOptional<
|
|
7
|
-
type TRemoveOptionalFromRest<
|
|
8
|
-
type TRemoveOptionalFromType<
|
|
9
|
-
type TResolveUnion<
|
|
10
|
-
export type TUnionEvaluated<
|
|
6
|
+
type TIsUnionOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? true : TIsUnionOptional<Right> : false);
|
|
7
|
+
type TRemoveOptionalFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<Right, [...Result, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<Right, [...Result, Left]> : Result);
|
|
8
|
+
type TRemoveOptionalFromType<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType<Type> : Type);
|
|
9
|
+
type TResolveUnion<Types extends TSchema[], Result extends TSchema[] = TRemoveOptionalFromRest<Types>, IsOptional extends boolean = TIsUnionOptional<Types>> = (IsOptional extends true ? TOptional<TUnion<Result>> : TUnion<Result>);
|
|
10
|
+
export type TUnionEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveUnion<Types>);
|
|
11
11
|
/** `[Json]` Creates an evaluated Union type */
|
|
12
|
-
export declare function UnionEvaluated<
|
|
12
|
+
export declare function UnionEvaluated<Types extends TSchema[], Result = TUnionEvaluated<Types>>(T: [...Types], options?: SchemaOptions): Result;
|
|
13
13
|
export {};
|
|
@@ -13,27 +13,28 @@ const union_create_1 = require("./union-create");
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const kind_1 = require("../guard/kind");
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function IsUnionOptional(
|
|
17
|
-
return
|
|
16
|
+
function IsUnionOptional(types) {
|
|
17
|
+
return types.some(type => (0, kind_1.IsOptional)(type));
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
|
-
function RemoveOptionalFromRest(
|
|
21
|
-
return
|
|
20
|
+
function RemoveOptionalFromRest(types) {
|
|
21
|
+
return types.map(left => (0, kind_1.IsOptional)(left) ? RemoveOptionalFromType(left) : left);
|
|
22
22
|
}
|
|
23
23
|
// prettier-ignore
|
|
24
24
|
function RemoveOptionalFromType(T) {
|
|
25
25
|
return ((0, index_2.Discard)(T, [index_1.OptionalKind]));
|
|
26
26
|
}
|
|
27
27
|
// prettier-ignore
|
|
28
|
-
function ResolveUnion(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function ResolveUnion(types, options) {
|
|
29
|
+
const isOptional = IsUnionOptional(types);
|
|
30
|
+
return (isOptional
|
|
31
|
+
? (0, index_4.Optional)((0, union_create_1.UnionCreate)(RemoveOptionalFromRest(types), options))
|
|
32
|
+
: (0, union_create_1.UnionCreate)(RemoveOptionalFromRest(types), options));
|
|
32
33
|
}
|
|
33
34
|
/** `[Json]` Creates an evaluated Union type */
|
|
34
35
|
function UnionEvaluated(T, options) {
|
|
35
36
|
// prettier-ignore
|
|
36
|
-
return (T.length ===
|
|
37
|
-
T.length ===
|
|
37
|
+
return (T.length === 1 ? (0, type_1.CreateType)(T[0], options) :
|
|
38
|
+
T.length === 0 ? (0, index_3.Never)(options) :
|
|
38
39
|
ResolveUnion(T, options));
|
|
39
40
|
}
|
|
@@ -3,4 +3,4 @@ import { type TNever } from '../never/index';
|
|
|
3
3
|
import type { TUnion } from './union-type';
|
|
4
4
|
export type Union<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TUnion<T>);
|
|
5
5
|
/** `[Json]` Creates a Union type */
|
|
6
|
-
export declare function Union<
|
|
6
|
+
export declare function Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
@@ -6,9 +6,9 @@ const index_1 = require("../never/index");
|
|
|
6
6
|
const type_1 = require("../create/type");
|
|
7
7
|
const union_create_1 = require("./union-create");
|
|
8
8
|
/** `[Json]` Creates a Union type */
|
|
9
|
-
function Union(
|
|
9
|
+
function Union(types, options) {
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
return (
|
|
12
|
-
|
|
13
|
-
(0, union_create_1.UnionCreate)(
|
|
11
|
+
return (types.length === 0 ? (0, index_1.Never)(options) :
|
|
12
|
+
types.length === 1 ? (0, type_1.CreateType)(types[0], options) :
|
|
13
|
+
(0, union_create_1.UnionCreate)(types, options));
|
|
14
14
|
}
|