@sinclair/typebox 0.34.15 → 0.34.17
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/compiler/compiler.js +5 -0
- package/build/cjs/errors/errors.js +3 -0
- package/build/cjs/index.d.ts +3 -0
- package/build/cjs/index.js +3 -0
- package/build/cjs/syntax/index.d.ts +1 -1
- package/build/cjs/syntax/index.js +1 -1
- package/build/cjs/syntax/runtime.d.ts +40 -54
- package/build/cjs/syntax/runtime.js +91 -203
- package/build/cjs/syntax/static.d.ts +80 -146
- package/build/cjs/syntax/syntax.d.ts +33 -0
- package/build/cjs/syntax/syntax.js +37 -0
- package/build/cjs/type/argument/argument.d.ts +9 -0
- package/build/cjs/type/argument/argument.js +10 -0
- package/build/cjs/type/argument/index.d.ts +1 -0
- package/build/cjs/type/argument/index.js +18 -0
- package/build/cjs/type/constructor-parameters/constructor-parameters.d.ts +3 -3
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +3 -1
- package/build/cjs/type/guard/kind.d.ts +9 -6
- package/build/cjs/type/guard/kind.js +6 -0
- package/build/cjs/type/guard/type.d.ts +9 -6
- package/build/cjs/type/guard/type.js +9 -0
- package/build/cjs/type/index.d.ts +2 -0
- package/build/cjs/type/index.js +2 -0
- package/build/cjs/type/instance-type/instance-type.d.ts +5 -4
- package/build/cjs/type/instance-type/instance-type.js +3 -1
- package/build/cjs/type/instantiate/index.d.ts +1 -0
- package/build/cjs/type/instantiate/index.js +18 -0
- package/build/cjs/type/instantiate/instantiate.d.ts +25 -0
- package/build/cjs/type/instantiate/instantiate.js +32 -0
- package/build/cjs/type/parameters/parameters.d.ts +3 -3
- package/build/cjs/type/parameters/parameters.js +3 -1
- package/build/cjs/type/record/record.d.ts +16 -1
- package/build/cjs/type/record/record.js +53 -23
- package/build/cjs/type/remap/index.d.ts +1 -0
- package/build/cjs/type/remap/index.js +18 -0
- package/build/cjs/type/remap/remap.d.ts +19 -0
- package/build/cjs/type/remap/remap.js +35 -0
- package/build/cjs/type/return-type/return-type.d.ts +5 -4
- package/build/cjs/type/return-type/return-type.js +3 -1
- package/build/cjs/type/type/javascript.d.ts +10 -4
- package/build/cjs/type/type/javascript.js +44 -34
- package/build/cjs/type/type/type.d.ts +3 -0
- package/build/cjs/type/type/type.js +123 -117
- package/build/cjs/value/check/check.js +5 -0
- package/build/cjs/value/create/create.js +5 -0
- package/build/esm/compiler/compiler.mjs +5 -0
- package/build/esm/errors/errors.mjs +3 -0
- package/build/esm/index.d.mts +3 -0
- package/build/esm/index.mjs +3 -0
- package/build/esm/syntax/index.d.mts +1 -1
- package/build/esm/syntax/index.mjs +1 -1
- package/build/esm/syntax/runtime.d.mts +40 -54
- package/build/esm/syntax/runtime.mjs +91 -203
- package/build/esm/syntax/static.d.mts +80 -146
- package/build/esm/syntax/syntax.d.mts +33 -0
- package/build/esm/syntax/syntax.mjs +30 -0
- package/build/esm/type/argument/argument.d.mts +9 -0
- package/build/esm/type/argument/argument.mjs +6 -0
- package/build/esm/type/argument/index.d.mts +1 -0
- package/build/esm/type/argument/index.mjs +1 -0
- package/build/esm/type/constructor-parameters/constructor-parameters.d.mts +3 -3
- package/build/esm/type/constructor-parameters/constructor-parameters.mjs +3 -1
- package/build/esm/type/guard/kind.d.mts +9 -6
- package/build/esm/type/guard/kind.mjs +5 -0
- package/build/esm/type/guard/type.d.mts +9 -6
- package/build/esm/type/guard/type.mjs +8 -0
- package/build/esm/type/index.d.mts +2 -0
- package/build/esm/type/index.mjs +2 -0
- package/build/esm/type/instance-type/instance-type.d.mts +5 -4
- package/build/esm/type/instance-type/instance-type.mjs +3 -1
- package/build/esm/type/instantiate/index.d.mts +1 -0
- package/build/esm/type/instantiate/index.mjs +1 -0
- package/build/esm/type/instantiate/instantiate.d.mts +25 -0
- package/build/esm/type/instantiate/instantiate.mjs +28 -0
- package/build/esm/type/parameters/parameters.d.mts +3 -3
- package/build/esm/type/parameters/parameters.mjs +3 -1
- package/build/esm/type/record/record.d.mts +16 -1
- package/build/esm/type/record/record.mjs +35 -8
- package/build/esm/type/remap/index.d.mts +1 -0
- package/build/esm/type/remap/index.mjs +1 -0
- package/build/esm/type/remap/remap.d.mts +19 -0
- package/build/esm/type/remap/remap.mjs +31 -0
- package/build/esm/type/return-type/return-type.d.mts +5 -4
- package/build/esm/type/return-type/return-type.mjs +3 -1
- package/build/esm/type/type/javascript.d.mts +10 -4
- package/build/esm/type/type/javascript.mjs +10 -0
- package/build/esm/type/type/type.d.mts +3 -0
- package/build/esm/type/type/type.mjs +3 -0
- package/build/esm/value/check/check.mjs +5 -0
- package/build/esm/value/create/create.mjs +5 -0
- package/package.json +11 -1
- package/parser/package.json +4 -0
- package/readme.md +107 -184
- package/build/cjs/syntax/parse.d.ts +0 -15
- package/build/cjs/syntax/parse.js +0 -19
- package/build/esm/syntax/parse.d.mts +0 -15
- package/build/esm/syntax/parse.mjs +0 -14
- /package/build/cjs/{syntax/parsebox → parser}/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/module.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/module.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/token.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/token.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/types.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/types.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/parse.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/parse.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/token.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/token.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/types.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/types.js +0 -0
- /package/build/esm/{syntax/parsebox → parser}/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/guard.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/guard.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/module.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/module.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/parse.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/parse.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/token.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/token.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/types.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/types.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/parse.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/parse.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/token.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/token.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/types.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/types.mjs +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
-
import type { Ensure } from '../helpers/index';
|
|
3
2
|
import type { TConstructor } from '../constructor/index';
|
|
4
3
|
import { type TTuple } from '../tuple/index';
|
|
5
|
-
|
|
4
|
+
import { type TNever } from '../never/index';
|
|
5
|
+
export type TConstructorParameters<Type extends TSchema> = (Type extends TConstructor<infer Parameters extends TSchema[], infer _InstanceType extends TSchema> ? TTuple<Parameters> : TNever);
|
|
6
6
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
7
|
-
export declare function ConstructorParameters<
|
|
7
|
+
export declare function ConstructorParameters<Type extends TSchema>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConstructorParameters = ConstructorParameters;
|
|
5
5
|
const index_1 = require("../tuple/index");
|
|
6
|
+
const index_2 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
7
9
|
function ConstructorParameters(schema, options) {
|
|
8
|
-
return (0, index_1.Tuple)(schema.parameters, options);
|
|
10
|
+
return (KindGuard.IsConstructor(schema) ? (0, index_1.Tuple)(schema.parameters, options) : (0, index_2.Never)(options));
|
|
9
11
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index';
|
|
2
2
|
import { TransformOptions } from '../transform/index';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TAny } from '../any/index';
|
|
4
|
+
import type { TArgument } from '../argument/index';
|
|
4
5
|
import type { TArray } from '../array/index';
|
|
6
|
+
import type { TAsyncIterator } from '../async-iterator/index';
|
|
5
7
|
import type { TBoolean } from '../boolean/index';
|
|
6
8
|
import type { TComputed } from '../computed/index';
|
|
7
|
-
import type { TRecord } from '../record/index';
|
|
8
|
-
import type { TString } from '../string/index';
|
|
9
|
-
import type { TUnion } from '../union/index';
|
|
10
|
-
import type { TAny } from '../any/index';
|
|
11
|
-
import type { TAsyncIterator } from '../async-iterator/index';
|
|
12
9
|
import type { TBigInt } from '../bigint/index';
|
|
13
10
|
import type { TConstructor } from '../constructor/index';
|
|
14
11
|
import type { TFunction } from '../function/index';
|
|
@@ -26,14 +23,18 @@ import type { TObject, TProperties } from '../object/index';
|
|
|
26
23
|
import type { TOptional } from '../optional/index';
|
|
27
24
|
import type { TPromise } from '../promise/index';
|
|
28
25
|
import type { TReadonly } from '../readonly/index';
|
|
26
|
+
import type { TRecord } from '../record/index';
|
|
29
27
|
import type { TRef } from '../ref/index';
|
|
30
28
|
import type { TRegExp } from '../regexp/index';
|
|
31
29
|
import type { TSchema } from '../schema/index';
|
|
30
|
+
import type { TString } from '../string/index';
|
|
32
31
|
import type { TSymbol } from '../symbol/index';
|
|
32
|
+
import type { TTemplateLiteral } from '../template-literal/index';
|
|
33
33
|
import type { TTuple } from '../tuple/index';
|
|
34
34
|
import type { TUint8Array } from '../uint8array/index';
|
|
35
35
|
import type { TUndefined } from '../undefined/index';
|
|
36
36
|
import type { TUnknown } from '../unknown/index';
|
|
37
|
+
import type { TUnion } from '../union/index';
|
|
37
38
|
import type { TUnsafe } from '../unsafe/index';
|
|
38
39
|
import type { TVoid } from '../void/index';
|
|
39
40
|
import type { TDate } from '../date/index';
|
|
@@ -44,6 +45,8 @@ export declare function IsReadonly<T extends TSchema>(value: T): value is TReado
|
|
|
44
45
|
export declare function IsOptional<T extends TSchema>(value: T): value is TOptional<T>;
|
|
45
46
|
/** `[Kind-Only]` Returns true if the given value is TAny */
|
|
46
47
|
export declare function IsAny(value: unknown): value is TAny;
|
|
48
|
+
/** `[Kind-Only]` Returns true if the given value is TArgument */
|
|
49
|
+
export declare function IsArgument(value: unknown): value is TArgument;
|
|
47
50
|
/** `[Kind-Only]` Returns true if the given value is TArray */
|
|
48
51
|
export declare function IsArray(value: unknown): value is TArray;
|
|
49
52
|
/** `[Kind-Only]` Returns true if the given value is TAsyncIterator */
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.IsReadonly = IsReadonly;
|
|
5
5
|
exports.IsOptional = IsOptional;
|
|
6
6
|
exports.IsAny = IsAny;
|
|
7
|
+
exports.IsArgument = IsArgument;
|
|
7
8
|
exports.IsArray = IsArray;
|
|
8
9
|
exports.IsAsyncIterator = IsAsyncIterator;
|
|
9
10
|
exports.IsBigInt = IsBigInt;
|
|
@@ -63,6 +64,10 @@ function IsOptional(value) {
|
|
|
63
64
|
function IsAny(value) {
|
|
64
65
|
return IsKindOf(value, 'Any');
|
|
65
66
|
}
|
|
67
|
+
/** `[Kind-Only]` Returns true if the given value is TArgument */
|
|
68
|
+
function IsArgument(value) {
|
|
69
|
+
return IsKindOf(value, 'Argument');
|
|
70
|
+
}
|
|
66
71
|
/** `[Kind-Only]` Returns true if the given value is TArray */
|
|
67
72
|
function IsArray(value) {
|
|
68
73
|
return IsKindOf(value, 'Array');
|
|
@@ -243,6 +248,7 @@ function IsKind(value) {
|
|
|
243
248
|
function IsSchema(value) {
|
|
244
249
|
// prettier-ignore
|
|
245
250
|
return (IsAny(value) ||
|
|
251
|
+
IsArgument(value) ||
|
|
246
252
|
IsArray(value) ||
|
|
247
253
|
IsBoolean(value) ||
|
|
248
254
|
IsBigInt(value) ||
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index';
|
|
2
2
|
import { TypeBoxError } from '../error/index';
|
|
3
3
|
import { TransformOptions } from '../transform/index';
|
|
4
|
-
import type {
|
|
4
|
+
import type { TAny } from '../any/index';
|
|
5
|
+
import type { TArgument } from '../argument/index';
|
|
5
6
|
import type { TArray } from '../array/index';
|
|
7
|
+
import type { TAsyncIterator } from '../async-iterator/index';
|
|
6
8
|
import type { TBoolean } from '../boolean/index';
|
|
7
9
|
import type { TComputed } from '../computed/index';
|
|
8
|
-
import type { TRecord } from '../record/index';
|
|
9
|
-
import type { TString } from '../string/index';
|
|
10
|
-
import type { TUnion } from '../union/index';
|
|
11
|
-
import type { TAny } from '../any/index';
|
|
12
|
-
import type { TAsyncIterator } from '../async-iterator/index';
|
|
13
10
|
import type { TBigInt } from '../bigint/index';
|
|
14
11
|
import type { TConstructor } from '../constructor/index';
|
|
15
12
|
import type { TFunction } from '../function/index';
|
|
@@ -27,13 +24,17 @@ import type { TObject, TProperties } from '../object/index';
|
|
|
27
24
|
import type { TOptional } from '../optional/index';
|
|
28
25
|
import type { TPromise } from '../promise/index';
|
|
29
26
|
import type { TReadonly } from '../readonly/index';
|
|
27
|
+
import type { TRecord } from '../record/index';
|
|
30
28
|
import type { TRef } from '../ref/index';
|
|
31
29
|
import type { TRegExp } from '../regexp/index';
|
|
32
30
|
import type { TSchema } from '../schema/index';
|
|
31
|
+
import type { TString } from '../string/index';
|
|
33
32
|
import type { TSymbol } from '../symbol/index';
|
|
33
|
+
import type { TTemplateLiteral } from '../template-literal/index';
|
|
34
34
|
import type { TTuple } from '../tuple/index';
|
|
35
35
|
import type { TUint8Array } from '../uint8array/index';
|
|
36
36
|
import type { TUndefined } from '../undefined/index';
|
|
37
|
+
import type { TUnion } from '../union/index';
|
|
37
38
|
import type { TUnknown } from '../unknown/index';
|
|
38
39
|
import type { TUnsafe } from '../unsafe/index';
|
|
39
40
|
import type { TVoid } from '../void/index';
|
|
@@ -47,6 +48,8 @@ export declare function IsReadonly<T extends TSchema>(value: T): value is TReado
|
|
|
47
48
|
export declare function IsOptional<T extends TSchema>(value: T): value is TOptional<T>;
|
|
48
49
|
/** Returns true if the given value is TAny */
|
|
49
50
|
export declare function IsAny(value: unknown): value is TAny;
|
|
51
|
+
/** Returns true if the given value is TArgument */
|
|
52
|
+
export declare function IsArgument(value: unknown): value is TArgument;
|
|
50
53
|
/** Returns true if the given value is TArray */
|
|
51
54
|
export declare function IsArray(value: unknown): value is TArray;
|
|
52
55
|
/** Returns true if the given value is TAsyncIterator */
|
|
@@ -5,6 +5,7 @@ exports.TypeGuardUnknownTypeError = void 0;
|
|
|
5
5
|
exports.IsReadonly = IsReadonly;
|
|
6
6
|
exports.IsOptional = IsOptional;
|
|
7
7
|
exports.IsAny = IsAny;
|
|
8
|
+
exports.IsArgument = IsArgument;
|
|
8
9
|
exports.IsArray = IsArray;
|
|
9
10
|
exports.IsAsyncIterator = IsAsyncIterator;
|
|
10
11
|
exports.IsBigInt = IsBigInt;
|
|
@@ -58,6 +59,7 @@ class TypeGuardUnknownTypeError extends index_2.TypeBoxError {
|
|
|
58
59
|
}
|
|
59
60
|
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
60
61
|
const KnownTypes = [
|
|
62
|
+
'Argument',
|
|
61
63
|
'Any',
|
|
62
64
|
'Array',
|
|
63
65
|
'AsyncIterator',
|
|
@@ -157,6 +159,12 @@ function IsAny(value) {
|
|
|
157
159
|
return (IsKindOf(value, 'Any') &&
|
|
158
160
|
IsOptionalString(value.$id));
|
|
159
161
|
}
|
|
162
|
+
/** Returns true if the given value is TArgument */
|
|
163
|
+
function IsArgument(value) {
|
|
164
|
+
// prettier-ignore
|
|
165
|
+
return (IsKindOf(value, 'Argument') &&
|
|
166
|
+
ValueGuard.IsNumber(value.index));
|
|
167
|
+
}
|
|
160
168
|
/** Returns true if the given value is TArray */
|
|
161
169
|
function IsArray(value) {
|
|
162
170
|
return (IsKindOf(value, 'Array') &&
|
|
@@ -517,6 +525,7 @@ function IsKind(value) {
|
|
|
517
525
|
function IsSchema(value) {
|
|
518
526
|
// prettier-ignore
|
|
519
527
|
return (ValueGuard.IsObject(value)) && (IsAny(value) ||
|
|
528
|
+
IsArgument(value) ||
|
|
520
529
|
IsArray(value) ||
|
|
521
530
|
IsBoolean(value) ||
|
|
522
531
|
IsBigInt(value) ||
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './any/index';
|
|
2
|
+
export * from './argument/index';
|
|
2
3
|
export * from './array/index';
|
|
3
4
|
export * from './async-iterator/index';
|
|
4
5
|
export * from './awaited/index';
|
|
@@ -21,6 +22,7 @@ export * from './guard/index';
|
|
|
21
22
|
export * from './helpers/index';
|
|
22
23
|
export * from './indexed/index';
|
|
23
24
|
export * from './instance-type/index';
|
|
25
|
+
export * from './instantiate/index';
|
|
24
26
|
export * from './integer/index';
|
|
25
27
|
export * from './intersect/index';
|
|
26
28
|
export * from './intrinsic/index';
|
package/build/cjs/type/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./any/index"), exports);
|
|
19
|
+
__exportStar(require("./argument/index"), exports);
|
|
19
20
|
__exportStar(require("./array/index"), exports);
|
|
20
21
|
__exportStar(require("./async-iterator/index"), exports);
|
|
21
22
|
__exportStar(require("./awaited/index"), exports);
|
|
@@ -38,6 +39,7 @@ __exportStar(require("./guard/index"), exports);
|
|
|
38
39
|
__exportStar(require("./helpers/index"), exports);
|
|
39
40
|
__exportStar(require("./indexed/index"), exports);
|
|
40
41
|
__exportStar(require("./instance-type/index"), exports);
|
|
42
|
+
__exportStar(require("./instantiate/index"), exports);
|
|
41
43
|
__exportStar(require("./integer/index"), exports);
|
|
42
44
|
__exportStar(require("./intersect/index"), exports);
|
|
43
45
|
__exportStar(require("./intrinsic/index"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
|
|
1
|
+
import { type TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
+
import { type TConstructor } from '../constructor/index';
|
|
3
|
+
import { type TNever } from '../never/index';
|
|
4
|
+
export type TInstanceType<Type extends TSchema, Result extends TSchema = Type extends TConstructor<infer _Parameters extends TSchema[], infer InstanceType extends TSchema> ? InstanceType : TNever> = Result;
|
|
4
5
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
5
|
-
export declare function InstanceType<
|
|
6
|
+
export declare function InstanceType<Type extends TSchema>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.InstanceType = InstanceType;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
+
const index_1 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
7
9
|
function InstanceType(schema, options) {
|
|
8
|
-
return (0, type_1.CreateType)(schema.returns, options);
|
|
10
|
+
return (KindGuard.IsConstructor(schema) ? (0, type_1.CreateType)(schema.returns, options) : (0, index_1.Never)(options));
|
|
9
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instantiate';
|
|
@@ -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("./instantiate"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index';
|
|
2
|
+
import type { TArgument } from '../argument/index';
|
|
3
|
+
import { type TNever } from '../never/index';
|
|
4
|
+
import { type TReadonlyOptional } from '../readonly-optional/index';
|
|
5
|
+
import { type TReadonly } from '../readonly/index';
|
|
6
|
+
import { type TOptional } from '../optional/index';
|
|
7
|
+
import { type TRemap, type TMapping as TRemapMapping } from '../remap/index';
|
|
8
|
+
type TInstantiateArgument<Argument extends TArgument, Type extends TSchema, IsArgumentReadonly extends number = Argument extends TReadonly<TSchema> ? 1 : 0, IsArgumentOptional extends number = Argument extends TOptional<TSchema> ? 1 : 0, Result extends TSchema = ([
|
|
9
|
+
IsArgumentReadonly,
|
|
10
|
+
IsArgumentOptional
|
|
11
|
+
] extends [1, 1] ? TReadonlyOptional<Type> : [
|
|
12
|
+
IsArgumentReadonly,
|
|
13
|
+
IsArgumentOptional
|
|
14
|
+
] extends [0, 1] ? TOptional<Type> : [
|
|
15
|
+
IsArgumentReadonly,
|
|
16
|
+
IsArgumentOptional
|
|
17
|
+
] extends [1, 0] ? TReadonly<Type> : Type)> = Result;
|
|
18
|
+
interface TInstantiateArguments<Arguments extends TSchema[]> extends TRemapMapping {
|
|
19
|
+
output: (this['input'] extends TArgument<infer Index extends number> ? Index extends keyof Arguments ? Arguments[Index] extends TSchema ? TInstantiateArgument<this['input'], Arguments[Index]> : TNever : TNever : this['input']);
|
|
20
|
+
}
|
|
21
|
+
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
22
|
+
export type TInstantiate<Type extends TSchema, Arguments extends TSchema[]> = (TRemap<Type, TInstantiateArguments<Arguments>>);
|
|
23
|
+
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
24
|
+
export declare function Instantiate<Type extends TSchema, Arguments extends TSchema[]>(type: Type, args: [...Arguments]): TInstantiate<Type, Arguments>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Instantiate = Instantiate;
|
|
5
|
+
const index_1 = require("../never/index");
|
|
6
|
+
const index_2 = require("../readonly-optional/index");
|
|
7
|
+
const index_3 = require("../readonly/index");
|
|
8
|
+
const index_4 = require("../optional/index");
|
|
9
|
+
const index_5 = require("../remap/index");
|
|
10
|
+
const KindGuard = require("../guard/kind");
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
function InstantiateArgument(argument, type) {
|
|
13
|
+
const isReadonly = KindGuard.IsReadonly(argument);
|
|
14
|
+
const isOptional = KindGuard.IsOptional(argument);
|
|
15
|
+
return (isReadonly && isOptional ? (0, index_2.ReadonlyOptional)(type) :
|
|
16
|
+
isReadonly && !isOptional ? (0, index_3.Readonly)(type) :
|
|
17
|
+
!isReadonly && isOptional ? (0, index_4.Optional)(type) :
|
|
18
|
+
type);
|
|
19
|
+
}
|
|
20
|
+
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
function Instantiate(type, args) {
|
|
23
|
+
return (0, index_5.Remap)(type, (type) => {
|
|
24
|
+
return KindGuard.IsArgument(type)
|
|
25
|
+
? type.index in args
|
|
26
|
+
? KindGuard.IsSchema(args[type.index])
|
|
27
|
+
? InstantiateArgument(type, args[type.index])
|
|
28
|
+
: (0, index_1.Never)()
|
|
29
|
+
: (0, index_1.Never)()
|
|
30
|
+
: type;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import type { TFunction } from '../function/index';
|
|
3
|
-
import type { Ensure } from '../helpers/index';
|
|
4
3
|
import { type TTuple } from '../tuple/index';
|
|
5
|
-
|
|
4
|
+
import { type TNever } from '../never/index';
|
|
5
|
+
export type TParameters<Type extends TSchema> = (Type extends TFunction<infer Parameters extends TSchema[], infer _ReturnType extends TSchema> ? TTuple<Parameters> : TNever);
|
|
6
6
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
7
|
-
export declare function Parameters<
|
|
7
|
+
export declare function Parameters<Type extends TSchema>(schema: Type, options?: SchemaOptions): TParameters<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Parameters = Parameters;
|
|
5
5
|
const index_1 = require("../tuple/index");
|
|
6
|
+
const index_2 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
7
9
|
function Parameters(schema, options) {
|
|
8
|
-
return (0, index_1.Tuple)(schema.parameters, options);
|
|
10
|
+
return (KindGuard.IsFunction(schema) ? (0, index_1.Tuple)(schema.parameters, options) : (0, index_2.Never)());
|
|
9
11
|
}
|
|
@@ -3,6 +3,7 @@ import type { TSchema } from '../schema/index';
|
|
|
3
3
|
import type { Static } from '../static/index';
|
|
4
4
|
import type { Evaluate, Ensure, Assert } from '../helpers/index';
|
|
5
5
|
import { type TAny } from '../any/index';
|
|
6
|
+
import { type TBoolean } from '../boolean/index';
|
|
6
7
|
import { type TComputed } from '../computed/index';
|
|
7
8
|
import { type TEnumRecord, type TEnum } from '../enum/index';
|
|
8
9
|
import { type TInteger } from '../integer/index';
|
|
@@ -38,6 +39,10 @@ type TFromRegExpKey<_Key extends TRegExp, Type extends TSchema> = (Ensure<TRecor
|
|
|
38
39
|
type TFromStringKey<_Key extends TString, Type extends TSchema> = (Ensure<TRecord<TString, Type>>);
|
|
39
40
|
type TFromAnyKey<_Key extends TAny, Type extends TSchema> = (Ensure<TRecord<TAny, Type>>);
|
|
40
41
|
type TFromNeverKey<_Key extends TNever, Type extends TSchema> = (Ensure<TRecord<TNever, Type>>);
|
|
42
|
+
type TFromBooleanKey<_Key extends TBoolean, Type extends TSchema> = (Ensure<TObject<{
|
|
43
|
+
true: Type;
|
|
44
|
+
false: Type;
|
|
45
|
+
}>>);
|
|
41
46
|
type TFromIntegerKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
|
|
42
47
|
type TFromNumberKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
|
|
43
48
|
type RecordStatic<Key extends TSchema, Type extends TSchema, P extends unknown[]> = (Evaluate<{
|
|
@@ -52,7 +57,17 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
|
|
|
52
57
|
};
|
|
53
58
|
additionalProperties: TAdditionalProperties;
|
|
54
59
|
}
|
|
55
|
-
export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
|
|
60
|
+
export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TBoolean ? TFromBooleanKey<Key, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
|
|
56
61
|
/** `[Json]` Creates a Record type */
|
|
57
62
|
export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
|
|
63
|
+
/** Gets the Records Pattern */
|
|
64
|
+
export declare function RecordPattern(record: TRecord): string;
|
|
65
|
+
/** Gets the Records Key Type */
|
|
66
|
+
export type TRecordKey<Type extends TRecord> = (Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString);
|
|
67
|
+
/** Gets the Records Key Type */
|
|
68
|
+
export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
|
|
69
|
+
/** Gets a Record Value Type */
|
|
70
|
+
export type TRecordValue<Type extends TRecord> = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever);
|
|
71
|
+
/** Gets a Record Value Type */
|
|
72
|
+
export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
|
|
58
73
|
export {};
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Record = Record;
|
|
5
|
+
exports.RecordPattern = RecordPattern;
|
|
6
|
+
exports.RecordKey = RecordKey;
|
|
7
|
+
exports.RecordValue = RecordValue;
|
|
5
8
|
const type_1 = require("../create/type");
|
|
6
9
|
const index_1 = require("../symbols/index");
|
|
7
10
|
const index_2 = require("../computed/index");
|
|
8
11
|
const index_3 = require("../never/index");
|
|
9
|
-
const index_4 = require("../
|
|
10
|
-
const index_5 = require("../
|
|
11
|
-
const index_6 = require("../
|
|
12
|
-
const index_7 = require("../
|
|
13
|
-
const index_8 = require("../
|
|
14
|
-
const index_9 = require("../
|
|
12
|
+
const index_4 = require("../number/index");
|
|
13
|
+
const index_5 = require("../object/index");
|
|
14
|
+
const index_6 = require("../ref/index");
|
|
15
|
+
const index_7 = require("../string/index");
|
|
16
|
+
const index_8 = require("../union/index");
|
|
17
|
+
const index_9 = require("../template-literal/index");
|
|
18
|
+
const index_10 = require("../patterns/index");
|
|
19
|
+
const index_11 = require("../indexed/index");
|
|
15
20
|
// ------------------------------------------------------------------
|
|
16
21
|
// ValueGuard
|
|
17
22
|
// ------------------------------------------------------------------
|
|
@@ -35,17 +40,17 @@ function RecordCreateFromKeys(K, T, options) {
|
|
|
35
40
|
const result = {};
|
|
36
41
|
for (const K2 of K)
|
|
37
42
|
result[K2] = T;
|
|
38
|
-
return (0,
|
|
43
|
+
return (0, index_5.Object)(result, { ...options, [index_1.Hint]: 'Record' });
|
|
39
44
|
}
|
|
40
45
|
// prettier-ignore
|
|
41
46
|
function FromTemplateLiteralKey(K, T, options) {
|
|
42
|
-
return ((0,
|
|
43
|
-
? RecordCreateFromKeys((0,
|
|
47
|
+
return ((0, index_9.IsTemplateLiteralFinite)(K)
|
|
48
|
+
? RecordCreateFromKeys((0, index_11.IndexPropertyKeys)(K), T, options)
|
|
44
49
|
: RecordCreateFromPattern(K.pattern, T, options));
|
|
45
50
|
}
|
|
46
51
|
// prettier-ignore
|
|
47
52
|
function FromUnionKey(key, type, options) {
|
|
48
|
-
return RecordCreateFromKeys((0,
|
|
53
|
+
return RecordCreateFromKeys((0, index_11.IndexPropertyKeys)((0, index_8.Union)(key)), type, options);
|
|
49
54
|
}
|
|
50
55
|
// prettier-ignore
|
|
51
56
|
function FromLiteralKey(key, type, options) {
|
|
@@ -57,24 +62,28 @@ function FromRegExpKey(key, type, options) {
|
|
|
57
62
|
}
|
|
58
63
|
// prettier-ignore
|
|
59
64
|
function FromStringKey(key, type, options) {
|
|
60
|
-
const pattern = (0, value_1.IsUndefined)(key.pattern) ?
|
|
65
|
+
const pattern = (0, value_1.IsUndefined)(key.pattern) ? index_10.PatternStringExact : key.pattern;
|
|
61
66
|
return RecordCreateFromPattern(pattern, type, options);
|
|
62
67
|
}
|
|
63
68
|
// prettier-ignore
|
|
64
69
|
function FromAnyKey(_, type, options) {
|
|
65
|
-
return RecordCreateFromPattern(
|
|
70
|
+
return RecordCreateFromPattern(index_10.PatternStringExact, type, options);
|
|
66
71
|
}
|
|
67
72
|
// prettier-ignore
|
|
68
73
|
function FromNeverKey(_key, type, options) {
|
|
69
|
-
return RecordCreateFromPattern(
|
|
74
|
+
return RecordCreateFromPattern(index_10.PatternNeverExact, type, options);
|
|
75
|
+
}
|
|
76
|
+
// prettier-ignore
|
|
77
|
+
function FromBooleanKey(_key, type, options) {
|
|
78
|
+
return (0, index_5.Object)({ true: type, false: type }, options);
|
|
70
79
|
}
|
|
71
80
|
// prettier-ignore
|
|
72
81
|
function FromIntegerKey(_key, type, options) {
|
|
73
|
-
return RecordCreateFromPattern(
|
|
82
|
+
return RecordCreateFromPattern(index_10.PatternNumberExact, type, options);
|
|
74
83
|
}
|
|
75
84
|
// prettier-ignore
|
|
76
85
|
function FromNumberKey(_, type, options) {
|
|
77
|
-
return RecordCreateFromPattern(
|
|
86
|
+
return RecordCreateFromPattern(index_10.PatternNumberExact, type, options);
|
|
78
87
|
}
|
|
79
88
|
// ------------------------------------------------------------------
|
|
80
89
|
// TRecordOrObject
|
|
@@ -84,15 +93,36 @@ function Record(key, type, options = {}) {
|
|
|
84
93
|
// prettier-ignore
|
|
85
94
|
return ((0, kind_1.IsComputed)(type) ? (0, index_2.Computed)('Record', [key, (0, index_2.Computed)(type.target, type.parameters)], options) :
|
|
86
95
|
(0, kind_1.IsComputed)(key) ? (0, index_2.Computed)('Record', [(0, index_2.Computed)(type.target, type.parameters), type], options) :
|
|
87
|
-
(0, kind_1.IsRef)(key) ? (0, index_2.Computed)('Record', [(0,
|
|
96
|
+
(0, kind_1.IsRef)(key) ? (0, index_2.Computed)('Record', [(0, index_6.Ref)(key.$ref), type]) :
|
|
88
97
|
(0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
|
|
89
98
|
(0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
|
|
90
99
|
(0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
|
|
91
|
-
(0, kind_1.
|
|
92
|
-
(0, kind_1.
|
|
93
|
-
(0, kind_1.
|
|
94
|
-
(0, kind_1.
|
|
95
|
-
(0, kind_1.
|
|
96
|
-
(0, kind_1.
|
|
97
|
-
(0,
|
|
100
|
+
(0, kind_1.IsBoolean)(key) ? FromBooleanKey(key, type, options) :
|
|
101
|
+
(0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
|
|
102
|
+
(0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
|
|
103
|
+
(0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
|
|
104
|
+
(0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
|
|
105
|
+
(0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
|
|
106
|
+
(0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
|
|
107
|
+
(0, index_3.Never)(options));
|
|
108
|
+
}
|
|
109
|
+
// ------------------------------------------------------------------
|
|
110
|
+
// Record Utilities
|
|
111
|
+
// ------------------------------------------------------------------
|
|
112
|
+
/** Gets the Records Pattern */
|
|
113
|
+
function RecordPattern(record) {
|
|
114
|
+
return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
|
|
115
|
+
}
|
|
116
|
+
/** Gets the Records Key Type */
|
|
117
|
+
// prettier-ignore
|
|
118
|
+
function RecordKey(type) {
|
|
119
|
+
const pattern = RecordPattern(type);
|
|
120
|
+
return (pattern === index_10.PatternStringExact ? (0, index_7.String)() :
|
|
121
|
+
pattern === index_10.PatternNumberExact ? (0, index_4.Number)() :
|
|
122
|
+
(0, index_7.String)({ pattern }));
|
|
123
|
+
}
|
|
124
|
+
/** Gets a Record Value Type */
|
|
125
|
+
// prettier-ignore
|
|
126
|
+
function RecordValue(type) {
|
|
127
|
+
return type.patternProperties[RecordPattern(type)];
|
|
98
128
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './remap';
|
|
@@ -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("./remap"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as t from '@sinclair/typebox';
|
|
2
|
+
export type TCallback = (schema: t.TSchema) => t.TSchema;
|
|
3
|
+
export interface TMapping {
|
|
4
|
+
input: unknown;
|
|
5
|
+
output: unknown;
|
|
6
|
+
}
|
|
7
|
+
type TApply<Type extends t.TSchema, Mapping extends TMapping, Mapped = (Mapping & {
|
|
8
|
+
input: Type;
|
|
9
|
+
})['output'], Result = Mapped extends t.TSchema ? Mapped : never> = Result;
|
|
10
|
+
type TFromProperties<Properties extends t.TProperties, Mapping extends TMapping, Result extends t.TProperties = {
|
|
11
|
+
[Key in keyof Properties]: TRemap<Properties[Key], Mapping>;
|
|
12
|
+
}> = Result;
|
|
13
|
+
type TFromTypes<Types extends t.TSchema[], Mapping extends TMapping, Result extends t.TSchema[] = []> = (Types extends [infer Left extends t.TSchema, ...infer Right extends t.TSchema[]] ? TFromTypes<Right, Mapping, [...Result, TRemap<Left, Mapping>]> : Result);
|
|
14
|
+
type TFromType<Type extends t.TSchema, Mapping extends TMapping, Result extends t.TSchema = (TApply<Type, Mapping>)> = Result;
|
|
15
|
+
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
16
|
+
export type TRemap<Type extends t.TSchema, Mapping extends TMapping, Mapped extends t.TSchema = TFromType<Type, Mapping>, Result extends t.TSchema = (Mapped extends t.TConstructor<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TConstructor<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TFunction<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TFunction<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TIntersect<infer Types extends t.TSchema[]> ? t.TIntersect<TFromTypes<Types, Mapping>> : Mapped extends t.TUnion<infer Types extends t.TSchema[]> ? t.TUnion<TFromTypes<Types, Mapping>> : Mapped extends t.TTuple<infer Types extends t.TSchema[]> ? t.TTuple<TFromTypes<Types, Mapping>> : Mapped extends t.TArray<infer Type extends t.TSchema> ? t.TArray<TFromType<Type, Mapping>> : Mapped extends t.TAsyncIterator<infer Type extends t.TSchema> ? t.TAsyncIterator<TFromType<Type, Mapping>> : Mapped extends t.TIterator<infer Type extends t.TSchema> ? t.TIterator<TFromType<Type, Mapping>> : Mapped extends t.TPromise<infer Type extends t.TSchema> ? t.TPromise<TFromType<Type, Mapping>> : Mapped extends t.TObject<infer Properties extends t.TProperties> ? t.TObject<TFromProperties<Properties, Mapping>> : Mapped extends t.TRecord<infer Key extends t.TSchema, infer Value extends t.TSchema> ? t.TRecordOrObject<TFromType<Key, Mapping>, TFromType<Value, Mapping>> : Mapped)> = Result;
|
|
17
|
+
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
18
|
+
export declare function Remap(type: t.TSchema, callback: TCallback): t.TSchema;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Remap = Remap;
|
|
5
|
+
const t = require("@sinclair/typebox");
|
|
6
|
+
function FromProperties(properties, func) {
|
|
7
|
+
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
8
|
+
return { ...result, [key]: Remap(properties[key], func) };
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
function FromTypes(types, callback) {
|
|
12
|
+
return types.map((type) => Remap(type, callback));
|
|
13
|
+
}
|
|
14
|
+
function FromType(type, callback) {
|
|
15
|
+
return callback(type);
|
|
16
|
+
}
|
|
17
|
+
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
function Remap(type, callback) {
|
|
20
|
+
// Map incoming type
|
|
21
|
+
const mapped = t.CloneType(FromType(type, callback));
|
|
22
|
+
// Return remapped interior
|
|
23
|
+
return (t.KindGuard.IsConstructor(type) ? t.Constructor(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
24
|
+
t.KindGuard.IsFunction(type) ? t.Function(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
25
|
+
t.KindGuard.IsIntersect(type) ? t.Intersect(FromTypes(type.allOf, callback), mapped) :
|
|
26
|
+
t.KindGuard.IsUnion(type) ? t.Union(FromTypes(type.anyOf, callback), mapped) :
|
|
27
|
+
t.KindGuard.IsTuple(type) ? t.Tuple(FromTypes(type.items || [], callback), mapped) :
|
|
28
|
+
t.KindGuard.IsArray(type) ? t.Array(FromType(type.items, callback), mapped) :
|
|
29
|
+
t.KindGuard.IsAsyncIterator(type) ? t.AsyncIterator(FromType(type.items, callback), mapped) :
|
|
30
|
+
t.KindGuard.IsIterator(type) ? t.Iterator(FromType(type.items, callback), mapped) :
|
|
31
|
+
t.KindGuard.IsPromise(type) ? t.Promise(FromType(type.items, callback), mapped) :
|
|
32
|
+
t.KindGuard.IsObject(type) ? t.Object(FromProperties(type.properties, callback), mapped) :
|
|
33
|
+
t.KindGuard.IsRecord(type) ? t.Record(FromType(t.RecordKey(type), callback), FromType(t.RecordValue(type), callback), mapped) :
|
|
34
|
+
t.CloneType(mapped));
|
|
35
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
|
|
1
|
+
import { type TSchema, type SchemaOptions } from '../schema/index';
|
|
2
|
+
import { type TFunction } from '../function/index';
|
|
3
|
+
import { type TNever } from '../never/index';
|
|
4
|
+
export type TReturnType<Type extends TSchema, Result extends TSchema = Type extends TFunction<infer _Parameters extends TSchema[], infer ReturnType extends TSchema> ? ReturnType : TNever> = Result;
|
|
4
5
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
5
|
-
export declare function ReturnType<
|
|
6
|
+
export declare function ReturnType<Type extends TSchema>(schema: Type, options?: SchemaOptions): TReturnType<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ReturnType = ReturnType;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
+
const index_1 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
7
9
|
function ReturnType(schema, options) {
|
|
8
|
-
return (0, type_1.CreateType)(schema.returns, options);
|
|
10
|
+
return (KindGuard.IsFunction(schema) ? (0, type_1.CreateType)(schema.returns, options) : (0, index_1.Never)(options));
|
|
9
11
|
}
|