@sinclair/typebox 0.34.22 → 0.34.24
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/index.d.ts +0 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/syntax/runtime.d.ts +2 -0
- package/build/cjs/syntax/runtime.js +53 -3
- package/build/cjs/syntax/static.d.ts +22 -1
- package/build/cjs/syntax/syntax.d.ts +18 -20
- package/build/cjs/syntax/syntax.js +14 -9
- package/build/cjs/type/instantiate/instantiate.d.ts +44 -19
- package/build/cjs/type/instantiate/instantiate.js +106 -18
- package/build/cjs/type/type/type.d.ts +0 -1
- package/build/cjs/type/type/type.js +30 -32
- package/build/esm/index.d.mts +0 -1
- package/build/esm/index.mjs +0 -1
- package/build/esm/syntax/runtime.d.mts +2 -0
- package/build/esm/syntax/runtime.mjs +53 -3
- package/build/esm/syntax/static.d.mts +22 -1
- package/build/esm/syntax/syntax.d.mts +18 -20
- package/build/esm/syntax/syntax.mjs +14 -9
- package/build/esm/type/instantiate/instantiate.d.mts +44 -19
- package/build/esm/type/instantiate/instantiate.mjs +105 -18
- package/build/esm/type/type/type.d.mts +0 -1
- package/build/esm/type/type/type.mjs +0 -1
- package/package.json +1 -1
- package/readme.md +84 -67
- package/build/cjs/type/remap/index.d.ts +0 -1
- package/build/cjs/type/remap/index.js +0 -18
- package/build/cjs/type/remap/remap.d.ts +0 -30
- package/build/cjs/type/remap/remap.js +0 -47
- package/build/esm/type/remap/index.d.mts +0 -1
- package/build/esm/type/remap/index.mjs +0 -1
- package/build/esm/type/remap/remap.d.mts +0 -30
- package/build/esm/type/remap/remap.mjs +0 -43
package/build/cjs/index.d.ts
CHANGED
|
@@ -52,7 +52,6 @@ export * from './type/record/index';
|
|
|
52
52
|
export * from './type/recursive/index';
|
|
53
53
|
export * from './type/ref/index';
|
|
54
54
|
export * from './type/regexp/index';
|
|
55
|
-
export * from './type/remap/index';
|
|
56
55
|
export * from './type/required/index';
|
|
57
56
|
export * from './type/rest/index';
|
|
58
57
|
export * from './type/return-type/index';
|
package/build/cjs/index.js
CHANGED
|
@@ -75,7 +75,6 @@ __exportStar(require("./type/record/index"), exports);
|
|
|
75
75
|
__exportStar(require("./type/recursive/index"), exports);
|
|
76
76
|
__exportStar(require("./type/ref/index"), exports);
|
|
77
77
|
__exportStar(require("./type/regexp/index"), exports);
|
|
78
|
-
__exportStar(require("./type/remap/index"), exports);
|
|
79
78
|
__exportStar(require("./type/required/index"), exports);
|
|
80
79
|
__exportStar(require("./type/rest/index"), exports);
|
|
81
80
|
__exportStar(require("./type/return-type/index"), exports);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Runtime } from '../parser/index';
|
|
2
2
|
import * as t from '../type/index';
|
|
3
3
|
export declare const Module: Runtime.Module<{
|
|
4
|
+
GenericArgumentList: Runtime.IUnion<unknown[]>;
|
|
5
|
+
GenericArguments: Runtime.ITuple<{}>;
|
|
4
6
|
Literal: Runtime.IUnion<t.TLiteral<string> | t.TLiteral<number> | t.TLiteral<boolean>>;
|
|
5
7
|
Keyword: Runtime.IUnion<t.TAny | t.TBoolean | t.TBigInt | t.TNever | t.TString | t.TNumber | t.TInteger | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
|
|
6
8
|
KeyOf: Runtime.IUnion<boolean>;
|
|
@@ -40,13 +40,58 @@ const Dereference = (context, key) => {
|
|
|
40
40
|
return key in context ? context[key] : t.Ref(key);
|
|
41
41
|
};
|
|
42
42
|
// ------------------------------------------------------------------
|
|
43
|
+
// GenericArgumentList
|
|
44
|
+
// ------------------------------------------------------------------
|
|
45
|
+
// prettier-ignore
|
|
46
|
+
const GenericArgumentListMapping = (results) => {
|
|
47
|
+
return (results.length === 3 ? [results[0], ...results[2]] :
|
|
48
|
+
results.length === 2 ? [results[0]] :
|
|
49
|
+
results.length === 1 ? [results[0]] :
|
|
50
|
+
[]);
|
|
51
|
+
};
|
|
52
|
+
// prettier-ignore
|
|
53
|
+
const GenericArgumentList = index_1.Runtime.Union([
|
|
54
|
+
index_1.Runtime.Tuple([index_1.Runtime.Ident(), index_1.Runtime.Const(Comma), index_1.Runtime.Ref('GenericArgumentList')]),
|
|
55
|
+
index_1.Runtime.Tuple([index_1.Runtime.Ident(), index_1.Runtime.Const(Comma)]),
|
|
56
|
+
index_1.Runtime.Tuple([index_1.Runtime.Ident()]),
|
|
57
|
+
index_1.Runtime.Tuple([]),
|
|
58
|
+
], (results) => GenericArgumentListMapping(results));
|
|
59
|
+
// ------------------------------------------------------------------
|
|
60
|
+
// GenericArguments
|
|
61
|
+
// ------------------------------------------------------------------
|
|
62
|
+
// prettier-ignore
|
|
63
|
+
const GenericArgumentsContext = (args) => {
|
|
64
|
+
return args.reduce((result, arg, index) => {
|
|
65
|
+
return { ...result, [arg]: t.Argument(index) };
|
|
66
|
+
}, {});
|
|
67
|
+
};
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
const GenericArgumentsMapping = (results) => {
|
|
70
|
+
return results.length === 3
|
|
71
|
+
? GenericArgumentsContext(results[1])
|
|
72
|
+
: {};
|
|
73
|
+
};
|
|
74
|
+
// prettier-ignore
|
|
75
|
+
const GenericArguments = index_1.Runtime.Tuple([
|
|
76
|
+
index_1.Runtime.Const(LAngle),
|
|
77
|
+
index_1.Runtime.Ref('GenericArgumentList'),
|
|
78
|
+
index_1.Runtime.Const(RAngle),
|
|
79
|
+
], results => GenericArgumentsMapping(results));
|
|
80
|
+
// ------------------------------------------------------------------
|
|
43
81
|
// GenericReference
|
|
44
82
|
// ------------------------------------------------------------------
|
|
45
83
|
function GenericReferenceMapping(results, context) {
|
|
46
|
-
const
|
|
47
|
-
|
|
84
|
+
const type = Dereference(context, results[0]);
|
|
85
|
+
const args = results[2];
|
|
86
|
+
return t.Instantiate(type, args);
|
|
48
87
|
}
|
|
49
|
-
|
|
88
|
+
// prettier-ignore
|
|
89
|
+
const GenericReference = index_1.Runtime.Tuple([
|
|
90
|
+
index_1.Runtime.Ident(),
|
|
91
|
+
index_1.Runtime.Const(LAngle),
|
|
92
|
+
index_1.Runtime.Ref('Elements'),
|
|
93
|
+
index_1.Runtime.Const(RAngle)
|
|
94
|
+
], (results, context) => GenericReferenceMapping(results, context));
|
|
50
95
|
// ------------------------------------------------------------------
|
|
51
96
|
// Reference
|
|
52
97
|
// ------------------------------------------------------------------
|
|
@@ -607,6 +652,11 @@ const Uint8Array = index_1.Runtime.Const('Uint8Array', index_1.Runtime.As(t.Uint
|
|
|
607
652
|
// ------------------------------------------------------------------
|
|
608
653
|
// prettier-ignore
|
|
609
654
|
exports.Module = new index_1.Runtime.Module({
|
|
655
|
+
// ----------------------------------------------------------------
|
|
656
|
+
// Generic Arguments
|
|
657
|
+
// ----------------------------------------------------------------
|
|
658
|
+
GenericArgumentList,
|
|
659
|
+
GenericArguments,
|
|
610
660
|
// ----------------------------------------------------------------
|
|
611
661
|
// Type Expressions
|
|
612
662
|
// ----------------------------------------------------------------
|
|
@@ -42,8 +42,29 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
|
|
|
42
42
|
Static.Tuple<[]>
|
|
43
43
|
], DelimitMapping>);
|
|
44
44
|
type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
|
|
45
|
+
interface GenericArgumentListMapping extends Static.IMapping {
|
|
46
|
+
output: (this['input'] extends [infer Ident extends string, Comma, infer Rest extends unknown[]] ? [Ident, ...Rest] : this['input'] extends [infer Ident extends string, Comma] ? [Ident] : this['input'] extends [infer Ident extends string] ? [Ident] : [
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
type GenericArgumentList = Static.Union<[
|
|
50
|
+
Static.Tuple<[Static.Ident, Static.Const<Comma>, GenericArgumentList]>,
|
|
51
|
+
Static.Tuple<[Static.Ident, Static.Const<Comma>]>,
|
|
52
|
+
Static.Tuple<[Static.Ident]>,
|
|
53
|
+
Static.Tuple<[]>
|
|
54
|
+
], GenericArgumentListMapping>;
|
|
55
|
+
type GenericArgumentsContext<Args extends string[], Result extends t.TProperties = {}> = (Args extends [...infer Left extends string[], infer Right extends string] ? GenericArgumentsContext<Left, Result & {
|
|
56
|
+
[_ in Right]: t.TArgument<Left['length']>;
|
|
57
|
+
}> : t.Evaluate<Result>);
|
|
58
|
+
interface GenericArgumentsMapping extends Static.IMapping {
|
|
59
|
+
output: this['input'] extends [LAngle, infer Args extends string[], RAngle] ? GenericArgumentsContext<Args> : never;
|
|
60
|
+
}
|
|
61
|
+
export type GenericArguments = Static.Tuple<[
|
|
62
|
+
Static.Const<LAngle>,
|
|
63
|
+
GenericArgumentList,
|
|
64
|
+
Static.Const<RAngle>
|
|
65
|
+
], GenericArgumentsMapping>;
|
|
45
66
|
interface GenericReferenceMapping extends Static.IMapping {
|
|
46
|
-
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer
|
|
67
|
+
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Args extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, Args> : never : never;
|
|
47
68
|
}
|
|
48
69
|
type GenericReference = Static.Tuple<[
|
|
49
70
|
Static.Ident,
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as t from '../type/index';
|
|
2
2
|
import { Static } from '../parser/index';
|
|
3
|
-
import { Type } from './static';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
import { Type, GenericArguments } from './static';
|
|
4
|
+
type TParseSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (Static.Parse<GenericArguments, Code, {}> extends [infer Args extends t.TProperties, infer Rest extends string] ? Static.Parse<Type, Rest, Context & Args> : Static.Parse<Type, Code, Context>);
|
|
5
|
+
/** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
|
|
6
|
+
export declare function NoInfer<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema;
|
|
7
|
+
/** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
|
|
8
|
+
export declare function NoInfer<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema;
|
|
9
|
+
/** Parses a TypeScript annotation into a TypeBox type */
|
|
10
|
+
export type TSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (TParseSyntax<Context, Code> extends [infer Type extends t.TSchema, string] ? Type : t.TNever);
|
|
11
|
+
/** Parses a TypeScript annotation into a TypeBox type */
|
|
12
|
+
export declare function Syntax<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
|
|
13
|
+
/** Parses a TypeScript annotation into a TypeBox type */
|
|
14
|
+
export declare function Syntax<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
|
|
14
15
|
/**
|
|
15
|
-
* Parses a TSchema type from Syntax.
|
|
16
16
|
* @deprecated Use Syntax() function
|
|
17
17
|
*/
|
|
18
|
-
export declare function Parse<Context extends Record<PropertyKey,
|
|
18
|
+
export declare function Parse<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
|
|
19
19
|
/**
|
|
20
|
-
* Parses a TSchema type from Syntax.
|
|
21
20
|
* @deprecated Use Syntax() function
|
|
22
21
|
*/
|
|
23
|
-
export declare function Parse<
|
|
22
|
+
export declare function Parse<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
|
|
24
23
|
/**
|
|
25
|
-
* Parses a TSchema from TypeScript Syntax
|
|
26
24
|
* @deprecated Use NoInfer() function
|
|
27
25
|
*/
|
|
28
|
-
export declare function ParseOnly<Context extends Record<PropertyKey,
|
|
26
|
+
export declare function ParseOnly<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema | undefined;
|
|
29
27
|
/**
|
|
30
|
-
* Parses a TSchema from TypeScript Syntax
|
|
31
28
|
* @deprecated Use NoInfer() function
|
|
32
29
|
*/
|
|
33
|
-
export declare function ParseOnly<Code extends string>(code: Code, options?:
|
|
30
|
+
export declare function ParseOnly<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema | undefined;
|
|
31
|
+
export {};
|
|
@@ -5,31 +5,36 @@ exports.NoInfer = NoInfer;
|
|
|
5
5
|
exports.Syntax = Syntax;
|
|
6
6
|
exports.Parse = Parse;
|
|
7
7
|
exports.ParseOnly = ParseOnly;
|
|
8
|
-
const
|
|
8
|
+
const t = require("../type/index");
|
|
9
9
|
const runtime_1 = require("./runtime");
|
|
10
|
-
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
function ParseSyntax(context, code) {
|
|
12
|
+
const results = runtime_1.Module.Parse('GenericArguments', code, {}); // [ArgumentContext, Rest]
|
|
13
|
+
return (results.length === 2
|
|
14
|
+
? runtime_1.Module.Parse('Type', results[1], { ...context, ...results[0] })
|
|
15
|
+
: runtime_1.Module.Parse('Type', code, context));
|
|
16
|
+
}
|
|
17
|
+
/** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
|
|
11
18
|
// prettier-ignore
|
|
12
19
|
function NoInfer(...args) {
|
|
13
20
|
const withContext = typeof args[0] === 'string' ? false : true;
|
|
14
21
|
const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}];
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
?
|
|
18
|
-
:
|
|
22
|
+
const result = ParseSyntax(context, code)[0];
|
|
23
|
+
return t.KindGuard.IsSchema(result)
|
|
24
|
+
? t.CloneType(result, options)
|
|
25
|
+
: t.Never(options);
|
|
19
26
|
}
|
|
20
|
-
/** Parses a
|
|
27
|
+
/** Parses a TypeScript annotation into a TypeBox type */
|
|
21
28
|
function Syntax(...args) {
|
|
22
29
|
return NoInfer.apply(null, args);
|
|
23
30
|
}
|
|
24
31
|
/**
|
|
25
|
-
* Parses a TSchema type from Syntax.
|
|
26
32
|
* @deprecated Use Syntax() function
|
|
27
33
|
*/
|
|
28
34
|
function Parse(...args) {
|
|
29
35
|
return NoInfer.apply(null, args);
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
* Parses a TSchema from TypeScript Syntax
|
|
33
38
|
* @deprecated Use NoInfer() function
|
|
34
39
|
*/
|
|
35
40
|
function ParseOnly(...args) {
|
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import { type
|
|
1
|
+
import { type TSchema } from '../schema/index';
|
|
2
|
+
import { type TArgument } from '../argument/index';
|
|
3
|
+
import { type TUnknown } from '../unknown/index';
|
|
4
4
|
import { type TReadonlyOptional } from '../readonly-optional/index';
|
|
5
5
|
import { type TReadonly } from '../readonly/index';
|
|
6
6
|
import { type TOptional } from '../optional/index';
|
|
7
|
-
import { type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
import { type TConstructor } from '../constructor/index';
|
|
8
|
+
import { type TFunction } from '../function/index';
|
|
9
|
+
import { type TIntersect } from '../intersect/index';
|
|
10
|
+
import { type TUnion } from '../union/index';
|
|
11
|
+
import { type TTuple } from '../tuple/index';
|
|
12
|
+
import { type TArray } from '../array/index';
|
|
13
|
+
import { type TAsyncIterator } from '../async-iterator/index';
|
|
14
|
+
import { type TIterator } from '../iterator/index';
|
|
15
|
+
import { type TPromise } from '../promise/index';
|
|
16
|
+
import { type TObject, type TProperties } from '../object/index';
|
|
17
|
+
import { type TRecordOrObject, type TRecord } from '../record/index';
|
|
18
|
+
type TFromConstructor<Args extends TSchema[], Parameters extends TSchema[], InstanceType extends TSchema, Result extends TConstructor = TConstructor<TFromTypes<Args, Parameters>, TFromType<Args, InstanceType>>> = Result;
|
|
19
|
+
type TFromFunction<Args extends TSchema[], Parameters extends TSchema[], ReturnType extends TSchema, Result extends TFunction = TFunction<TFromTypes<Args, Parameters>, TFromType<Args, ReturnType>>> = Result;
|
|
20
|
+
type TFromIntersect<Args extends TSchema[], Types extends TSchema[], Result extends TIntersect = TIntersect<TFromTypes<Args, Types>>> = Result;
|
|
21
|
+
type TFromUnion<Args extends TSchema[], Types extends TSchema[], Result extends TUnion = TUnion<TFromTypes<Args, Types>>> = Result;
|
|
22
|
+
type TFromTuple<Args extends TSchema[], Types extends TSchema[], Result extends TTuple = TTuple<TFromTypes<Args, Types>>> = Result;
|
|
23
|
+
type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TArray = TArray<TFromType<Args, Type>>> = Result;
|
|
24
|
+
type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
|
|
25
|
+
type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
|
|
26
|
+
type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
|
|
27
|
+
type TFromObject<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = TFromProperties<Args, Properties>> = TObject<Result>;
|
|
28
|
+
type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
|
|
29
|
+
type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
|
|
30
|
+
type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
|
|
31
|
+
IsReadonly,
|
|
32
|
+
IsOptional
|
|
33
|
+
] extends [true, true] ? TReadonlyOptional<Mapped> : [
|
|
34
|
+
IsReadonly,
|
|
35
|
+
IsOptional
|
|
36
|
+
] extends [true, false] ? TReadonly<Mapped> : [
|
|
37
|
+
IsReadonly,
|
|
38
|
+
IsOptional
|
|
39
|
+
] extends [false, true] ? TOptional<Mapped> : Mapped)> = Result;
|
|
40
|
+
type TFromProperties<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = {
|
|
41
|
+
[Key in keyof Properties]: TFromProperty<Args, Properties[Key]>;
|
|
42
|
+
}> = Result;
|
|
43
|
+
export type TFromTypes<Args extends TSchema[], Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Args, Right, [...Result, TFromType<Args, Left>]> : Result);
|
|
44
|
+
export declare function FromTypes<Args extends TSchema[], Types extends TSchema[]>(args: [...Args], types: [...Types]): TFromTypes<Args, Types>;
|
|
45
|
+
export type TFromType<Args extends TSchema[], Type extends TSchema> = (Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<Args, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<Args, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Args, Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Args, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Args, Types> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Args, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<Args, Type> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<Args, Type> : Type extends TPromise<infer Type extends TSchema> ? TFromPromise<Args, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Args, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<Args, Key, Value> : Type extends TArgument<infer Index extends number> ? TFromArgument<Args, Index> : Type);
|
|
21
46
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
22
|
-
export type TInstantiate<Type extends TSchema,
|
|
47
|
+
export type TInstantiate<Type extends TSchema, Args extends TSchema[], Result extends TSchema = TFromType<Args, Type>> = Result;
|
|
23
48
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
24
|
-
export declare function Instantiate<Type extends TSchema,
|
|
49
|
+
export declare function Instantiate<Type extends TSchema, Args extends TSchema[]>(type: Type, args: [...Args]): TInstantiate<Type, Args>;
|
|
25
50
|
export {};
|
|
@@ -1,32 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FromTypes = FromTypes;
|
|
4
5
|
exports.Instantiate = Instantiate;
|
|
5
|
-
const
|
|
6
|
+
const type_1 = require("../clone/type");
|
|
7
|
+
const index_1 = require("../unknown/index");
|
|
6
8
|
const index_2 = require("../readonly-optional/index");
|
|
7
9
|
const index_3 = require("../readonly/index");
|
|
8
10
|
const index_4 = require("../optional/index");
|
|
9
|
-
const index_5 = require("../
|
|
11
|
+
const index_5 = require("../object/index");
|
|
12
|
+
const index_6 = require("../record/index");
|
|
13
|
+
const ValueGuard = require("../guard/value");
|
|
10
14
|
const KindGuard = require("../guard/kind");
|
|
11
15
|
// prettier-ignore
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function FromConstructor(args, type) {
|
|
17
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
18
|
+
type.returns = FromType(args, type.returns);
|
|
19
|
+
return type;
|
|
20
|
+
}
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
function FromFunction(args, type) {
|
|
23
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
24
|
+
type.returns = FromType(args, type.returns);
|
|
25
|
+
return type;
|
|
26
|
+
}
|
|
27
|
+
// prettier-ignore
|
|
28
|
+
function FromIntersect(args, type) {
|
|
29
|
+
type.allOf = FromTypes(args, type.allOf);
|
|
30
|
+
return type;
|
|
31
|
+
}
|
|
32
|
+
// prettier-ignore
|
|
33
|
+
function FromUnion(args, type) {
|
|
34
|
+
type.anyOf = FromTypes(args, type.anyOf);
|
|
35
|
+
return type;
|
|
36
|
+
}
|
|
37
|
+
// prettier-ignore
|
|
38
|
+
function FromTuple(args, type) {
|
|
39
|
+
if (ValueGuard.IsUndefined(type.items))
|
|
40
|
+
return type;
|
|
41
|
+
type.items = FromTypes(args, type.items);
|
|
42
|
+
return type;
|
|
43
|
+
}
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
function FromArray(args, type) {
|
|
46
|
+
type.items = FromType(args, type.items);
|
|
47
|
+
return type;
|
|
48
|
+
}
|
|
49
|
+
// prettier-ignore
|
|
50
|
+
function FromAsyncIterator(args, type) {
|
|
51
|
+
type.items = FromType(args, type.items);
|
|
52
|
+
return type;
|
|
53
|
+
}
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
function FromIterator(args, type) {
|
|
56
|
+
type.items = FromType(args, type.items);
|
|
57
|
+
return type;
|
|
58
|
+
}
|
|
59
|
+
// prettier-ignore
|
|
60
|
+
function FromPromise(args, type) {
|
|
61
|
+
type.item = FromType(args, type.item);
|
|
62
|
+
return type;
|
|
63
|
+
}
|
|
64
|
+
// prettier-ignore
|
|
65
|
+
function FromObject(args, type) {
|
|
66
|
+
const properties = FromProperties(args, type.properties);
|
|
67
|
+
return { ...type, ...(0, index_5.Object)(properties) }; // retain options
|
|
68
|
+
}
|
|
69
|
+
// prettier-ignore
|
|
70
|
+
function FromRecord(args, type) {
|
|
71
|
+
const mappedKey = FromType(args, (0, index_6.RecordKey)(type));
|
|
72
|
+
const mappedValue = FromType(args, (0, index_6.RecordValue)(type));
|
|
73
|
+
const result = (0, index_6.Record)(mappedKey, mappedValue);
|
|
74
|
+
return { ...type, ...result }; // retain options
|
|
75
|
+
}
|
|
76
|
+
// prettier-ignore
|
|
77
|
+
function FromArgument(args, argument) {
|
|
78
|
+
return argument.index in args ? args[argument.index] : (0, index_1.Unknown)();
|
|
79
|
+
}
|
|
80
|
+
// prettier-ignore
|
|
81
|
+
function FromProperty(args, type) {
|
|
82
|
+
const isReadonly = KindGuard.IsReadonly(type);
|
|
83
|
+
const isOptional = KindGuard.IsOptional(type);
|
|
84
|
+
const mapped = FromType(args, type);
|
|
85
|
+
return (isReadonly && isOptional ? (0, index_2.ReadonlyOptional)(mapped) :
|
|
86
|
+
isReadonly && !isOptional ? (0, index_3.Readonly)(mapped) :
|
|
87
|
+
!isReadonly && isOptional ? (0, index_4.Optional)(mapped) :
|
|
88
|
+
mapped);
|
|
89
|
+
}
|
|
90
|
+
// prettier-ignore
|
|
91
|
+
function FromProperties(args, properties) {
|
|
92
|
+
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
93
|
+
return { ...result, [key]: FromProperty(args, properties[key]) };
|
|
94
|
+
}, {});
|
|
95
|
+
}
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
function FromTypes(args, types) {
|
|
98
|
+
return types.map(type => FromType(args, type));
|
|
99
|
+
}
|
|
100
|
+
// prettier-ignore
|
|
101
|
+
function FromType(args, type) {
|
|
102
|
+
return (KindGuard.IsConstructor(type) ? FromConstructor(args, type) :
|
|
103
|
+
KindGuard.IsFunction(type) ? FromFunction(args, type) :
|
|
104
|
+
KindGuard.IsIntersect(type) ? FromIntersect(args, type) :
|
|
105
|
+
KindGuard.IsUnion(type) ? FromUnion(args, type) :
|
|
106
|
+
KindGuard.IsTuple(type) ? FromTuple(args, type) :
|
|
107
|
+
KindGuard.IsArray(type) ? FromArray(args, type) :
|
|
108
|
+
KindGuard.IsAsyncIterator(type) ? FromAsyncIterator(args, type) :
|
|
109
|
+
KindGuard.IsIterator(type) ? FromIterator(args, type) :
|
|
110
|
+
KindGuard.IsPromise(type) ? FromPromise(args, type) :
|
|
111
|
+
KindGuard.IsObject(type) ? FromObject(args, type) :
|
|
112
|
+
KindGuard.IsRecord(type) ? FromRecord(args, type) :
|
|
113
|
+
KindGuard.IsArgument(type) ? FromArgument(args, type) :
|
|
114
|
+
type);
|
|
19
115
|
}
|
|
20
116
|
/** `[JavaScript]` Instantiates a type with the given parameters */
|
|
21
117
|
// prettier-ignore
|
|
22
118
|
function Instantiate(type, args) {
|
|
23
|
-
return (0,
|
|
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
|
-
});
|
|
119
|
+
return FromType(args, (0, type_1.CloneType)(type));
|
|
32
120
|
}
|
|
@@ -43,7 +43,6 @@ export { Record } from '../record/index';
|
|
|
43
43
|
export { Recursive } from '../recursive/index';
|
|
44
44
|
export { Ref } from '../ref/index';
|
|
45
45
|
export { RegExp } from '../regexp/index';
|
|
46
|
-
export { Remap } from '../remap/index';
|
|
47
46
|
export { Required } from '../required/index';
|
|
48
47
|
export { Rest } from '../rest/index';
|
|
49
48
|
export { ReturnType } from '../return-type/index';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = exports.String = exports.ReturnType =
|
|
4
|
+
exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Module = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.Instantiate = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Argument = exports.Any = void 0;
|
|
5
|
+
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = exports.String = exports.ReturnType = void 0;
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// Type: Module
|
|
8
8
|
// ------------------------------------------------------------------
|
|
@@ -99,33 +99,31 @@ var index_44 = require("../ref/index");
|
|
|
99
99
|
Object.defineProperty(exports, "Ref", { enumerable: true, get: function () { return index_44.Ref; } });
|
|
100
100
|
var index_45 = require("../regexp/index");
|
|
101
101
|
Object.defineProperty(exports, "RegExp", { enumerable: true, get: function () { return index_45.RegExp; } });
|
|
102
|
-
var index_46 = require("../
|
|
103
|
-
Object.defineProperty(exports, "
|
|
104
|
-
var index_47 = require("../
|
|
105
|
-
Object.defineProperty(exports, "
|
|
106
|
-
var index_48 = require("../
|
|
107
|
-
Object.defineProperty(exports, "
|
|
108
|
-
var index_49 = require("../
|
|
109
|
-
Object.defineProperty(exports, "
|
|
110
|
-
var index_50 = require("../
|
|
111
|
-
Object.defineProperty(exports, "
|
|
112
|
-
var index_51 = require("../
|
|
113
|
-
Object.defineProperty(exports, "
|
|
114
|
-
var index_52 = require("../
|
|
115
|
-
Object.defineProperty(exports, "
|
|
116
|
-
var index_53 = require("../
|
|
117
|
-
Object.defineProperty(exports, "
|
|
118
|
-
var index_54 = require("../
|
|
119
|
-
Object.defineProperty(exports, "
|
|
120
|
-
var index_55 = require("../
|
|
121
|
-
Object.defineProperty(exports, "
|
|
122
|
-
var index_56 = require("../
|
|
123
|
-
Object.defineProperty(exports, "
|
|
124
|
-
var index_57 = require("../
|
|
125
|
-
Object.defineProperty(exports, "
|
|
126
|
-
var index_58 = require("../
|
|
127
|
-
Object.defineProperty(exports, "
|
|
128
|
-
var index_59 = require("../
|
|
129
|
-
Object.defineProperty(exports, "
|
|
130
|
-
var index_60 = require("../void/index");
|
|
131
|
-
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_60.Void; } });
|
|
102
|
+
var index_46 = require("../required/index");
|
|
103
|
+
Object.defineProperty(exports, "Required", { enumerable: true, get: function () { return index_46.Required; } });
|
|
104
|
+
var index_47 = require("../rest/index");
|
|
105
|
+
Object.defineProperty(exports, "Rest", { enumerable: true, get: function () { return index_47.Rest; } });
|
|
106
|
+
var index_48 = require("../return-type/index");
|
|
107
|
+
Object.defineProperty(exports, "ReturnType", { enumerable: true, get: function () { return index_48.ReturnType; } });
|
|
108
|
+
var index_49 = require("../string/index");
|
|
109
|
+
Object.defineProperty(exports, "String", { enumerable: true, get: function () { return index_49.String; } });
|
|
110
|
+
var index_50 = require("../symbol/index");
|
|
111
|
+
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_50.Symbol; } });
|
|
112
|
+
var index_51 = require("../template-literal/index");
|
|
113
|
+
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_51.TemplateLiteral; } });
|
|
114
|
+
var index_52 = require("../transform/index");
|
|
115
|
+
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_52.Transform; } });
|
|
116
|
+
var index_53 = require("../tuple/index");
|
|
117
|
+
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return index_53.Tuple; } });
|
|
118
|
+
var index_54 = require("../uint8array/index");
|
|
119
|
+
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return index_54.Uint8Array; } });
|
|
120
|
+
var index_55 = require("../undefined/index");
|
|
121
|
+
Object.defineProperty(exports, "Undefined", { enumerable: true, get: function () { return index_55.Undefined; } });
|
|
122
|
+
var index_56 = require("../union/index");
|
|
123
|
+
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return index_56.Union; } });
|
|
124
|
+
var index_57 = require("../unknown/index");
|
|
125
|
+
Object.defineProperty(exports, "Unknown", { enumerable: true, get: function () { return index_57.Unknown; } });
|
|
126
|
+
var index_58 = require("../unsafe/index");
|
|
127
|
+
Object.defineProperty(exports, "Unsafe", { enumerable: true, get: function () { return index_58.Unsafe; } });
|
|
128
|
+
var index_59 = require("../void/index");
|
|
129
|
+
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_59.Void; } });
|
package/build/esm/index.d.mts
CHANGED
|
@@ -52,7 +52,6 @@ export * from './type/record/index.mjs';
|
|
|
52
52
|
export * from './type/recursive/index.mjs';
|
|
53
53
|
export * from './type/ref/index.mjs';
|
|
54
54
|
export * from './type/regexp/index.mjs';
|
|
55
|
-
export * from './type/remap/index.mjs';
|
|
56
55
|
export * from './type/required/index.mjs';
|
|
57
56
|
export * from './type/rest/index.mjs';
|
|
58
57
|
export * from './type/return-type/index.mjs';
|
package/build/esm/index.mjs
CHANGED
|
@@ -58,7 +58,6 @@ export * from './type/record/index.mjs';
|
|
|
58
58
|
export * from './type/recursive/index.mjs';
|
|
59
59
|
export * from './type/ref/index.mjs';
|
|
60
60
|
export * from './type/regexp/index.mjs';
|
|
61
|
-
export * from './type/remap/index.mjs';
|
|
62
61
|
export * from './type/required/index.mjs';
|
|
63
62
|
export * from './type/rest/index.mjs';
|
|
64
63
|
export * from './type/return-type/index.mjs';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Runtime } from '../parser/index.mjs';
|
|
2
2
|
import * as t from '../type/index.mjs';
|
|
3
3
|
export declare const Module: Runtime.Module<{
|
|
4
|
+
GenericArgumentList: Runtime.IUnion<unknown[]>;
|
|
5
|
+
GenericArguments: Runtime.ITuple<{}>;
|
|
4
6
|
Literal: Runtime.IUnion<t.TLiteral<string> | t.TLiteral<number> | t.TLiteral<boolean>>;
|
|
5
7
|
Keyword: Runtime.IUnion<t.TAny | t.TBoolean | t.TBigInt | t.TNever | t.TString | t.TNumber | t.TInteger | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
|
|
6
8
|
KeyOf: Runtime.IUnion<boolean>;
|