typia 3.4.6 → 3.4.7
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/lib/executable/typia.js +0 -0
- 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 +1 -1
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- 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,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
|
+
}
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
-
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
6
|
-
|
|
7
|
-
import { Writable } from "../../typings/Writable";
|
|
8
|
-
|
|
9
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
10
|
-
|
|
11
|
-
import { CommentFactory } from "../CommentFactory";
|
|
12
|
-
import { MetadataCollection } from "../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../MetadataFactory";
|
|
14
|
-
import { MetadataTagFactory } from "../MetadataTagFactory";
|
|
15
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
16
|
-
import { explore_metadata } from "./explore_metadata";
|
|
17
|
-
|
|
18
|
-
export const emplace_metadata_object =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: MetadataFactory.IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
23
|
-
// EMPLACE OBJECT
|
|
24
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
25
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
26
|
-
if (newbie === false) return obj;
|
|
27
|
-
|
|
28
|
-
// PREPARE ASSETS
|
|
29
|
-
const isClass: boolean = parent.isClass();
|
|
30
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
31
|
-
? (node) => {
|
|
32
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
33
|
-
.getChildren()[0]
|
|
34
|
-
?.getChildren()[0]?.kind;
|
|
35
|
-
return (
|
|
36
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
37
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
38
|
-
(ts.isParameter(node) || ts.isPropertyDeclaration(node))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
: (node) =>
|
|
42
|
-
ts.isPropertyDeclaration(node) ||
|
|
43
|
-
ts.isPropertyAssignment(node) ||
|
|
44
|
-
ts.isPropertySignature(node) ||
|
|
45
|
-
ts.isTypeLiteralNode(node);
|
|
46
|
-
|
|
47
|
-
const insert =
|
|
48
|
-
(key: Metadata) =>
|
|
49
|
-
(value: Metadata) =>
|
|
50
|
-
(identifier: () => string) =>
|
|
51
|
-
(
|
|
52
|
-
symbol: ts.Symbol | undefined,
|
|
53
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
54
|
-
): MetadataProperty => {
|
|
55
|
-
// COMMENTS AND TAGS
|
|
56
|
-
const description: string | undefined =
|
|
57
|
-
CommentFactory.generate(
|
|
58
|
-
symbol?.getDocumentationComment(checker) || [],
|
|
59
|
-
) || undefined;
|
|
60
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
61
|
-
symbol?.getJsDocTags() || []
|
|
62
|
-
).filter(filter || (() => true));
|
|
63
|
-
|
|
64
|
-
// THE PROPERTY
|
|
65
|
-
const property = MetadataProperty.create({
|
|
66
|
-
key,
|
|
67
|
-
value,
|
|
68
|
-
description,
|
|
69
|
-
jsDocTags,
|
|
70
|
-
tags: MetadataTagFactory.generate(
|
|
71
|
-
() => identifier(),
|
|
72
|
-
value,
|
|
73
|
-
jsDocTags,
|
|
74
|
-
),
|
|
75
|
-
});
|
|
76
|
-
obj.properties.push(property);
|
|
77
|
-
return property;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
//----
|
|
81
|
-
// REGULAR PROPERTIES
|
|
82
|
-
//----
|
|
83
|
-
for (const prop of parent.getApparentProperties()) {
|
|
84
|
-
// CHECK INTERNAL TAG
|
|
85
|
-
if (
|
|
86
|
-
(prop.getJsDocTags(checker) || []).find(
|
|
87
|
-
(tag) => tag.name === "internal",
|
|
88
|
-
) !== undefined
|
|
89
|
-
)
|
|
90
|
-
continue;
|
|
91
|
-
|
|
92
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
93
|
-
const [node, type] = (() => {
|
|
94
|
-
const node = (prop.getDeclarations() || [])[0] as
|
|
95
|
-
| ts.PropertyDeclaration
|
|
96
|
-
| undefined;
|
|
97
|
-
const type: ts.Type | undefined = node
|
|
98
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
99
|
-
: "getTypeOfPropertyOfType" in checker
|
|
100
|
-
? (checker as any).getTypeOfPropertyOfType(
|
|
101
|
-
parent,
|
|
102
|
-
prop.name,
|
|
103
|
-
)
|
|
104
|
-
: undefined;
|
|
105
|
-
return [node, type];
|
|
106
|
-
})();
|
|
107
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
108
|
-
|
|
109
|
-
// GET EXACT TYPE
|
|
110
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
111
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
112
|
-
collection,
|
|
113
|
-
)(type, false);
|
|
114
|
-
|
|
115
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
116
|
-
if (node?.questionToken) Writable(value).required = false;
|
|
117
|
-
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//----
|
|
121
|
-
// DYNAMIC PROPERTIES
|
|
122
|
-
//----
|
|
123
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
124
|
-
// GET EXACT TYPE
|
|
125
|
-
const analyzer = (type: ts.Type) =>
|
|
126
|
-
explore_metadata(checker)(options)(collection)(type, false);
|
|
127
|
-
const key: Metadata = analyzer(index.keyType);
|
|
128
|
-
const value: Metadata = analyzer(index.type);
|
|
129
|
-
|
|
130
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
131
|
-
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
132
|
-
index.declaration?.parent
|
|
133
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
134
|
-
: undefined,
|
|
135
|
-
(doc) => doc.name !== "default",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return obj;
|
|
140
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
+
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
6
|
+
|
|
7
|
+
import { Writable } from "../../typings/Writable";
|
|
8
|
+
|
|
9
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
10
|
+
|
|
11
|
+
import { CommentFactory } from "../CommentFactory";
|
|
12
|
+
import { MetadataCollection } from "../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../MetadataFactory";
|
|
14
|
+
import { MetadataTagFactory } from "../MetadataTagFactory";
|
|
15
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
16
|
+
import { explore_metadata } from "./explore_metadata";
|
|
17
|
+
|
|
18
|
+
export const emplace_metadata_object =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: MetadataFactory.IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
23
|
+
// EMPLACE OBJECT
|
|
24
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
25
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
26
|
+
if (newbie === false) return obj;
|
|
27
|
+
|
|
28
|
+
// PREPARE ASSETS
|
|
29
|
+
const isClass: boolean = parent.isClass();
|
|
30
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
31
|
+
? (node) => {
|
|
32
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
33
|
+
.getChildren()[0]
|
|
34
|
+
?.getChildren()[0]?.kind;
|
|
35
|
+
return (
|
|
36
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
37
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
38
|
+
(ts.isParameter(node) || ts.isPropertyDeclaration(node))
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
: (node) =>
|
|
42
|
+
ts.isPropertyDeclaration(node) ||
|
|
43
|
+
ts.isPropertyAssignment(node) ||
|
|
44
|
+
ts.isPropertySignature(node) ||
|
|
45
|
+
ts.isTypeLiteralNode(node);
|
|
46
|
+
|
|
47
|
+
const insert =
|
|
48
|
+
(key: Metadata) =>
|
|
49
|
+
(value: Metadata) =>
|
|
50
|
+
(identifier: () => string) =>
|
|
51
|
+
(
|
|
52
|
+
symbol: ts.Symbol | undefined,
|
|
53
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
54
|
+
): MetadataProperty => {
|
|
55
|
+
// COMMENTS AND TAGS
|
|
56
|
+
const description: string | undefined =
|
|
57
|
+
CommentFactory.generate(
|
|
58
|
+
symbol?.getDocumentationComment(checker) || [],
|
|
59
|
+
) || undefined;
|
|
60
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
61
|
+
symbol?.getJsDocTags() || []
|
|
62
|
+
).filter(filter || (() => true));
|
|
63
|
+
|
|
64
|
+
// THE PROPERTY
|
|
65
|
+
const property = MetadataProperty.create({
|
|
66
|
+
key,
|
|
67
|
+
value,
|
|
68
|
+
description,
|
|
69
|
+
jsDocTags,
|
|
70
|
+
tags: MetadataTagFactory.generate(
|
|
71
|
+
() => identifier(),
|
|
72
|
+
value,
|
|
73
|
+
jsDocTags,
|
|
74
|
+
),
|
|
75
|
+
});
|
|
76
|
+
obj.properties.push(property);
|
|
77
|
+
return property;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//----
|
|
81
|
+
// REGULAR PROPERTIES
|
|
82
|
+
//----
|
|
83
|
+
for (const prop of parent.getApparentProperties()) {
|
|
84
|
+
// CHECK INTERNAL TAG
|
|
85
|
+
if (
|
|
86
|
+
(prop.getJsDocTags(checker) || []).find(
|
|
87
|
+
(tag) => tag.name === "internal",
|
|
88
|
+
) !== undefined
|
|
89
|
+
)
|
|
90
|
+
continue;
|
|
91
|
+
|
|
92
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
93
|
+
const [node, type] = (() => {
|
|
94
|
+
const node = (prop.getDeclarations() || [])[0] as
|
|
95
|
+
| ts.PropertyDeclaration
|
|
96
|
+
| undefined;
|
|
97
|
+
const type: ts.Type | undefined = node
|
|
98
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
99
|
+
: "getTypeOfPropertyOfType" in checker
|
|
100
|
+
? (checker as any).getTypeOfPropertyOfType(
|
|
101
|
+
parent,
|
|
102
|
+
prop.name,
|
|
103
|
+
)
|
|
104
|
+
: undefined;
|
|
105
|
+
return [node, type];
|
|
106
|
+
})();
|
|
107
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
108
|
+
|
|
109
|
+
// GET EXACT TYPE
|
|
110
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
111
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
112
|
+
collection,
|
|
113
|
+
)(type, false);
|
|
114
|
+
|
|
115
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
116
|
+
if (node?.questionToken) Writable(value).required = false;
|
|
117
|
+
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//----
|
|
121
|
+
// DYNAMIC PROPERTIES
|
|
122
|
+
//----
|
|
123
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
124
|
+
// GET EXACT TYPE
|
|
125
|
+
const analyzer = (type: ts.Type) =>
|
|
126
|
+
explore_metadata(checker)(options)(collection)(type, false);
|
|
127
|
+
const key: Metadata = analyzer(index.keyType);
|
|
128
|
+
const value: Metadata = analyzer(index.type);
|
|
129
|
+
|
|
130
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
131
|
+
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
132
|
+
index.declaration?.parent
|
|
133
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
134
|
+
: undefined,
|
|
135
|
+
(doc) => doc.name !== "default",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return obj;
|
|
140
|
+
};
|