typia 3.4.6 → 3.4.8
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/README.md +12 -2
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/TypiaSetupWizard.d.ts +2 -2
- package/lib/executable/internal/TypiaSetupWizard.js +57 -35
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/typia.js +22 -21
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/internal/iterate_metadata.js +1 -1
- package/lib/factories/internal/iterate_metadata.js.map +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
- package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/TypiaSetupWizard.ts +108 -87
- package/src/executable/typia.ts +25 -14
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +52 -52
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +1 -2
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_object.ts +45 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +798 -798
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +169 -169
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +18 -18
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_schema.ts +221 -221
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_number.ts +181 -181
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
8
|
-
import { explore_metadata } from "./internal/explore_metadata";
|
|
9
|
-
|
|
10
|
-
export namespace MetadataFactory {
|
|
11
|
-
export interface IOptions {
|
|
12
|
-
resolve: boolean;
|
|
13
|
-
constant: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function generate(
|
|
17
|
-
checker: ts.TypeChecker,
|
|
18
|
-
collection: MetadataCollection,
|
|
19
|
-
type: ts.Type | null,
|
|
20
|
-
options: IOptions,
|
|
21
|
-
): Metadata {
|
|
22
|
-
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
23
|
-
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
24
|
-
collection,
|
|
25
|
-
)(type, false);
|
|
26
|
-
|
|
27
|
-
// FIND RECURSIVE OBJECTS
|
|
28
|
-
for (const object of collection.objects())
|
|
29
|
-
object.recursive = object.properties.some(
|
|
30
|
-
(prop) =>
|
|
31
|
-
ArrayUtil.has(
|
|
32
|
-
prop.value.objects,
|
|
33
|
-
(elem) => elem.name === object.name,
|
|
34
|
-
) ||
|
|
35
|
-
prop.value.arrays.some((meta) =>
|
|
36
|
-
ArrayUtil.has(
|
|
37
|
-
meta.objects,
|
|
38
|
-
(elem) => elem.name === object.name,
|
|
39
|
-
),
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// RETURNS
|
|
44
|
-
return metadata;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
8
|
+
import { explore_metadata } from "./internal/explore_metadata";
|
|
9
|
+
|
|
10
|
+
export namespace MetadataFactory {
|
|
11
|
+
export interface IOptions {
|
|
12
|
+
resolve: boolean;
|
|
13
|
+
constant: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function generate(
|
|
17
|
+
checker: ts.TypeChecker,
|
|
18
|
+
collection: MetadataCollection,
|
|
19
|
+
type: ts.Type | null,
|
|
20
|
+
options: IOptions,
|
|
21
|
+
): Metadata {
|
|
22
|
+
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
23
|
+
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
24
|
+
collection,
|
|
25
|
+
)(type, false);
|
|
26
|
+
|
|
27
|
+
// FIND RECURSIVE OBJECTS
|
|
28
|
+
for (const object of collection.objects())
|
|
29
|
+
object.recursive = object.properties.some(
|
|
30
|
+
(prop) =>
|
|
31
|
+
ArrayUtil.has(
|
|
32
|
+
prop.value.objects,
|
|
33
|
+
(elem) => elem.name === object.name,
|
|
34
|
+
) ||
|
|
35
|
+
prop.value.arrays.some((meta) =>
|
|
36
|
+
ArrayUtil.has(
|
|
37
|
+
meta.objects,
|
|
38
|
+
(elem) => elem.name === object.name,
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// RETURNS
|
|
44
|
+
return metadata;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace StatementFactory {
|
|
4
|
-
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
-
return ts.factory.createVariableStatement(
|
|
6
|
-
undefined,
|
|
7
|
-
ts.factory.createVariableDeclarationList(
|
|
8
|
-
[
|
|
9
|
-
ts.factory.createVariableDeclaration(
|
|
10
|
-
name,
|
|
11
|
-
undefined,
|
|
12
|
-
undefined,
|
|
13
|
-
initializer,
|
|
14
|
-
),
|
|
15
|
-
],
|
|
16
|
-
ts.NodeFlags.Const,
|
|
17
|
-
),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function transpile(script: string) {
|
|
22
|
-
return ts.factory.createExpressionStatement(
|
|
23
|
-
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// export function require(variable: string, location: string) {
|
|
28
|
-
// return ts.factory.createImportDeclaration(
|
|
29
|
-
// undefined,
|
|
30
|
-
// undefined,
|
|
31
|
-
// ts.factory.createImportClause(
|
|
32
|
-
// false,
|
|
33
|
-
// undefined,
|
|
34
|
-
// ts.factory.createNamespaceImport(
|
|
35
|
-
// ts.factory.createIdentifier(variable),
|
|
36
|
-
// ),
|
|
37
|
-
// ),
|
|
38
|
-
// ts.factory.createStringLiteral(location),
|
|
39
|
-
// );
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// export function importModulo(variable: string, location: string) {
|
|
43
|
-
// return ts.factory.createImportDeclaration(
|
|
44
|
-
// undefined,
|
|
45
|
-
// undefined,
|
|
46
|
-
// ts.factory.createImportClause(
|
|
47
|
-
// false,
|
|
48
|
-
// undefined,
|
|
49
|
-
// ts.factory.createNamedImports([
|
|
50
|
-
// ts.factory.createImportSpecifier(
|
|
51
|
-
// false,
|
|
52
|
-
// undefined,
|
|
53
|
-
// ts.factory.createIdentifier(variable),
|
|
54
|
-
// ),
|
|
55
|
-
// ]),
|
|
56
|
-
// ),
|
|
57
|
-
// ts.factory.createStringLiteral(location),
|
|
58
|
-
// );
|
|
59
|
-
// }
|
|
60
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace StatementFactory {
|
|
4
|
+
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
+
return ts.factory.createVariableStatement(
|
|
6
|
+
undefined,
|
|
7
|
+
ts.factory.createVariableDeclarationList(
|
|
8
|
+
[
|
|
9
|
+
ts.factory.createVariableDeclaration(
|
|
10
|
+
name,
|
|
11
|
+
undefined,
|
|
12
|
+
undefined,
|
|
13
|
+
initializer,
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
ts.NodeFlags.Const,
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function transpile(script: string) {
|
|
22
|
+
return ts.factory.createExpressionStatement(
|
|
23
|
+
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// export function require(variable: string, location: string) {
|
|
28
|
+
// return ts.factory.createImportDeclaration(
|
|
29
|
+
// undefined,
|
|
30
|
+
// undefined,
|
|
31
|
+
// ts.factory.createImportClause(
|
|
32
|
+
// false,
|
|
33
|
+
// undefined,
|
|
34
|
+
// ts.factory.createNamespaceImport(
|
|
35
|
+
// ts.factory.createIdentifier(variable),
|
|
36
|
+
// ),
|
|
37
|
+
// ),
|
|
38
|
+
// ts.factory.createStringLiteral(location),
|
|
39
|
+
// );
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// export function importModulo(variable: string, location: string) {
|
|
43
|
+
// return ts.factory.createImportDeclaration(
|
|
44
|
+
// undefined,
|
|
45
|
+
// undefined,
|
|
46
|
+
// ts.factory.createImportClause(
|
|
47
|
+
// false,
|
|
48
|
+
// undefined,
|
|
49
|
+
// ts.factory.createNamedImports([
|
|
50
|
+
// ts.factory.createImportSpecifier(
|
|
51
|
+
// false,
|
|
52
|
+
// undefined,
|
|
53
|
+
// ts.factory.createIdentifier(variable),
|
|
54
|
+
// ),
|
|
55
|
+
// ]),
|
|
56
|
+
// ),
|
|
57
|
+
// ts.factory.createStringLiteral(location),
|
|
58
|
+
// );
|
|
59
|
+
// }
|
|
60
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace TemplateFactory {
|
|
4
|
-
export function generate(expressions: ts.Expression[]): ts.Expression {
|
|
5
|
-
if (expressions.every((exp) => ts.isStringLiteral(exp)))
|
|
6
|
-
return ts.factory.createStringLiteral(
|
|
7
|
-
(expressions as ts.StringLiteral[])
|
|
8
|
-
.map((str) => str.text)
|
|
9
|
-
.join(""),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const it: IIerator = {
|
|
13
|
-
value: "",
|
|
14
|
-
index: 0,
|
|
15
|
-
};
|
|
16
|
-
gather(expressions, it);
|
|
17
|
-
|
|
18
|
-
const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
|
|
19
|
-
const spans: ts.TemplateSpan[] = [];
|
|
20
|
-
|
|
21
|
-
while (true) {
|
|
22
|
-
const elem: ts.Expression = expressions[it.index++]!;
|
|
23
|
-
gather(expressions, it);
|
|
24
|
-
|
|
25
|
-
const broken: boolean = it.index === expressions.length;
|
|
26
|
-
spans.push(
|
|
27
|
-
ts.factory.createTemplateSpan(
|
|
28
|
-
elem,
|
|
29
|
-
broken
|
|
30
|
-
? ts.factory.createTemplateTail(it.value)
|
|
31
|
-
: ts.factory.createTemplateMiddle(it.value),
|
|
32
|
-
),
|
|
33
|
-
);
|
|
34
|
-
if (broken === true) break;
|
|
35
|
-
}
|
|
36
|
-
return ts.factory.createTemplateExpression(head, spans);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function gather(expressions: ts.Expression[], it: IIerator): void {
|
|
40
|
-
const found: number = expressions.findIndex(
|
|
41
|
-
(elem, index) => index >= it.index && !ts.isStringLiteral(elem),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const last: number = found !== -1 ? found : expressions.length;
|
|
45
|
-
it.value = expressions
|
|
46
|
-
.slice(it.index, last)
|
|
47
|
-
.map((elem) => (elem as ts.StringLiteral).text)
|
|
48
|
-
.reduce((x, y) => x + y, "");
|
|
49
|
-
it.index = last;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface IIerator {
|
|
53
|
-
value: string;
|
|
54
|
-
index: number;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace TemplateFactory {
|
|
4
|
+
export function generate(expressions: ts.Expression[]): ts.Expression {
|
|
5
|
+
if (expressions.every((exp) => ts.isStringLiteral(exp)))
|
|
6
|
+
return ts.factory.createStringLiteral(
|
|
7
|
+
(expressions as ts.StringLiteral[])
|
|
8
|
+
.map((str) => str.text)
|
|
9
|
+
.join(""),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const it: IIerator = {
|
|
13
|
+
value: "",
|
|
14
|
+
index: 0,
|
|
15
|
+
};
|
|
16
|
+
gather(expressions, it);
|
|
17
|
+
|
|
18
|
+
const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
|
|
19
|
+
const spans: ts.TemplateSpan[] = [];
|
|
20
|
+
|
|
21
|
+
while (true) {
|
|
22
|
+
const elem: ts.Expression = expressions[it.index++]!;
|
|
23
|
+
gather(expressions, it);
|
|
24
|
+
|
|
25
|
+
const broken: boolean = it.index === expressions.length;
|
|
26
|
+
spans.push(
|
|
27
|
+
ts.factory.createTemplateSpan(
|
|
28
|
+
elem,
|
|
29
|
+
broken
|
|
30
|
+
? ts.factory.createTemplateTail(it.value)
|
|
31
|
+
: ts.factory.createTemplateMiddle(it.value),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
if (broken === true) break;
|
|
35
|
+
}
|
|
36
|
+
return ts.factory.createTemplateExpression(head, spans);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function gather(expressions: ts.Expression[], it: IIerator): void {
|
|
40
|
+
const found: number = expressions.findIndex(
|
|
41
|
+
(elem, index) => index >= it.index && !ts.isStringLiteral(elem),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const last: number = found !== -1 ? found : expressions.length;
|
|
45
|
+
it.value = expressions
|
|
46
|
+
.slice(it.index, last)
|
|
47
|
+
.map((elem) => (elem as ts.StringLiteral).text)
|
|
48
|
+
.reduce((x, y) => x + y, "");
|
|
49
|
+
it.index = last;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface IIerator {
|
|
53
|
+
value: string;
|
|
54
|
+
index: number;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace TypeFactory {
|
|
4
|
-
export function resolve(
|
|
5
|
-
checker: ts.TypeChecker,
|
|
6
|
-
type: ts.Type,
|
|
7
|
-
): ts.Type | null {
|
|
8
|
-
return getReturnType(checker, type, "toJSON");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isFunction(type: ts.Type): boolean {
|
|
12
|
-
return getFunction(type) !== null;
|
|
13
|
-
}
|
|
14
|
-
function getFunction(type: ts.Type) {
|
|
15
|
-
const node = type.symbol?.declarations?.[0];
|
|
16
|
-
if (node === undefined) return null;
|
|
17
|
-
|
|
18
|
-
return ts.isFunctionLike(node)
|
|
19
|
-
? node
|
|
20
|
-
: ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
|
|
21
|
-
? ts.isFunctionLike(node.initializer)
|
|
22
|
-
? node.initializer
|
|
23
|
-
: null
|
|
24
|
-
: null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getReturnType(
|
|
28
|
-
checker: ts.TypeChecker,
|
|
29
|
-
type: ts.Type,
|
|
30
|
-
name: string,
|
|
31
|
-
): ts.Type | null {
|
|
32
|
-
// FIND TO-JSON METHOD
|
|
33
|
-
const symbol: ts.Symbol | undefined = type.getProperty(name);
|
|
34
|
-
if (!symbol) return null;
|
|
35
|
-
else if (!symbol.valueDeclaration) return null;
|
|
36
|
-
|
|
37
|
-
// GET FUNCTION DECLARATION
|
|
38
|
-
const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
|
|
39
|
-
symbol,
|
|
40
|
-
symbol.valueDeclaration,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// RETURNS THE RETURN-TYPE
|
|
44
|
-
const signature: ts.Signature | undefined = checker.getSignaturesOfType(
|
|
45
|
-
functor,
|
|
46
|
-
ts.SignatureKind.Call,
|
|
47
|
-
)[0];
|
|
48
|
-
return signature ? signature.getReturnType() : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getFullName(
|
|
52
|
-
checker: ts.TypeChecker,
|
|
53
|
-
type: ts.Type,
|
|
54
|
-
symbol?: ts.Symbol,
|
|
55
|
-
): string {
|
|
56
|
-
// PRIMITIVE
|
|
57
|
-
symbol ||= type.aliasSymbol || type.getSymbol();
|
|
58
|
-
if (symbol === undefined) return checker.typeToString(type);
|
|
59
|
-
|
|
60
|
-
// UNION OR INTERSECT
|
|
61
|
-
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
62
|
-
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
63
|
-
return type.types
|
|
64
|
-
.map((child) => getFullName(checker, child))
|
|
65
|
-
.join(joiner);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//----
|
|
69
|
-
// SPECIALIZATION
|
|
70
|
-
//----
|
|
71
|
-
const name: string = get_name(symbol);
|
|
72
|
-
|
|
73
|
-
// CHECK GENERIC
|
|
74
|
-
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
75
|
-
? type.aliasTypeArguments || []
|
|
76
|
-
: checker.getTypeArguments(type as ts.TypeReference);
|
|
77
|
-
return generic.length
|
|
78
|
-
? name === "Promise"
|
|
79
|
-
? getFullName(checker, generic[0]!)
|
|
80
|
-
: `${name}<${generic
|
|
81
|
-
.map((child) => getFullName(checker, child))
|
|
82
|
-
.join(", ")}>`
|
|
83
|
-
: name;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function explore_name(name: string, decl: ts.Node): string {
|
|
87
|
-
return ts.isModuleBlock(decl)
|
|
88
|
-
? explore_name(
|
|
89
|
-
`${decl.parent.name.getText()}.${name}`,
|
|
90
|
-
decl.parent.parent,
|
|
91
|
-
)
|
|
92
|
-
: name;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function get_name(symbol: ts.Symbol): string {
|
|
96
|
-
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
97
|
-
return parent
|
|
98
|
-
? explore_name(symbol.escapedName.toString(), parent)
|
|
99
|
-
: "__type";
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace TypeFactory {
|
|
4
|
+
export function resolve(
|
|
5
|
+
checker: ts.TypeChecker,
|
|
6
|
+
type: ts.Type,
|
|
7
|
+
): ts.Type | null {
|
|
8
|
+
return getReturnType(checker, type, "toJSON");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isFunction(type: ts.Type): boolean {
|
|
12
|
+
return getFunction(type) !== null;
|
|
13
|
+
}
|
|
14
|
+
function getFunction(type: ts.Type) {
|
|
15
|
+
const node = type.symbol?.declarations?.[0];
|
|
16
|
+
if (node === undefined) return null;
|
|
17
|
+
|
|
18
|
+
return ts.isFunctionLike(node)
|
|
19
|
+
? node
|
|
20
|
+
: ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
|
|
21
|
+
? ts.isFunctionLike(node.initializer)
|
|
22
|
+
? node.initializer
|
|
23
|
+
: null
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getReturnType(
|
|
28
|
+
checker: ts.TypeChecker,
|
|
29
|
+
type: ts.Type,
|
|
30
|
+
name: string,
|
|
31
|
+
): ts.Type | null {
|
|
32
|
+
// FIND TO-JSON METHOD
|
|
33
|
+
const symbol: ts.Symbol | undefined = type.getProperty(name);
|
|
34
|
+
if (!symbol) return null;
|
|
35
|
+
else if (!symbol.valueDeclaration) return null;
|
|
36
|
+
|
|
37
|
+
// GET FUNCTION DECLARATION
|
|
38
|
+
const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
|
|
39
|
+
symbol,
|
|
40
|
+
symbol.valueDeclaration,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// RETURNS THE RETURN-TYPE
|
|
44
|
+
const signature: ts.Signature | undefined = checker.getSignaturesOfType(
|
|
45
|
+
functor,
|
|
46
|
+
ts.SignatureKind.Call,
|
|
47
|
+
)[0];
|
|
48
|
+
return signature ? signature.getReturnType() : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getFullName(
|
|
52
|
+
checker: ts.TypeChecker,
|
|
53
|
+
type: ts.Type,
|
|
54
|
+
symbol?: ts.Symbol,
|
|
55
|
+
): string {
|
|
56
|
+
// PRIMITIVE
|
|
57
|
+
symbol ||= type.aliasSymbol || type.getSymbol();
|
|
58
|
+
if (symbol === undefined) return checker.typeToString(type);
|
|
59
|
+
|
|
60
|
+
// UNION OR INTERSECT
|
|
61
|
+
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
62
|
+
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
63
|
+
return type.types
|
|
64
|
+
.map((child) => getFullName(checker, child))
|
|
65
|
+
.join(joiner);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//----
|
|
69
|
+
// SPECIALIZATION
|
|
70
|
+
//----
|
|
71
|
+
const name: string = get_name(symbol);
|
|
72
|
+
|
|
73
|
+
// CHECK GENERIC
|
|
74
|
+
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
75
|
+
? type.aliasTypeArguments || []
|
|
76
|
+
: checker.getTypeArguments(type as ts.TypeReference);
|
|
77
|
+
return generic.length
|
|
78
|
+
? name === "Promise"
|
|
79
|
+
? getFullName(checker, generic[0]!)
|
|
80
|
+
: `${name}<${generic
|
|
81
|
+
.map((child) => getFullName(checker, child))
|
|
82
|
+
.join(", ")}>`
|
|
83
|
+
: name;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function explore_name(name: string, decl: ts.Node): string {
|
|
87
|
+
return ts.isModuleBlock(decl)
|
|
88
|
+
? explore_name(
|
|
89
|
+
`${decl.parent.name.getText()}.${name}`,
|
|
90
|
+
decl.parent.parent,
|
|
91
|
+
)
|
|
92
|
+
: name;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function get_name(symbol: ts.Symbol): string {
|
|
96
|
+
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
97
|
+
return parent
|
|
98
|
+
? explore_name(symbol.escapedName.toString(), parent)
|
|
99
|
+
: "__type";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ValueFactory {
|
|
4
|
-
export const NULL = () => ts.factory.createNull();
|
|
5
|
-
export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
|
|
6
|
-
export const BOOLEAN = (value: boolean) =>
|
|
7
|
-
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
8
|
-
export const INPUT = (str: string = "input") =>
|
|
9
|
-
ts.factory.createIdentifier(str);
|
|
10
|
-
export const TYPEOF = (input: ts.Expression) =>
|
|
11
|
-
ts.factory.createTypeOfExpression(input);
|
|
12
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ValueFactory {
|
|
4
|
+
export const NULL = () => ts.factory.createNull();
|
|
5
|
+
export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
|
|
6
|
+
export const BOOLEAN = (value: boolean) =>
|
|
7
|
+
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
8
|
+
export const INPUT = (str: string = "input") =>
|
|
9
|
+
ts.factory.createIdentifier(str);
|
|
10
|
+
export const TYPEOF = (input: ts.Expression) =>
|
|
11
|
+
ts.factory.createTypeOfExpression(input);
|
|
12
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
export namespace MetadataHelper {
|
|
4
|
-
export function literal_to_metadata(key: string): Metadata {
|
|
5
|
-
const metadata: Metadata = Metadata.initialize();
|
|
6
|
-
metadata.constants.push({
|
|
7
|
-
type: "string",
|
|
8
|
-
values: [key],
|
|
9
|
-
});
|
|
10
|
-
return metadata;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace MetadataHelper {
|
|
4
|
+
export function literal_to_metadata(key: string): Metadata {
|
|
5
|
+
const metadata: Metadata = Metadata.initialize();
|
|
6
|
+
metadata.constants.push({
|
|
7
|
+
type: "string",
|
|
8
|
+
values: [key],
|
|
9
|
+
});
|
|
10
|
+
return metadata;
|
|
11
|
+
}
|
|
12
|
+
}
|