typia 3.8.4 → 3.8.5
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/factories/MetadataTagFactory.js +5 -5
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +17 -15
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +1 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -1
- package/lib/programmers/IsProgrammer.js +5 -2
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +1 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/disable_function_importer_declare.d.ts +2 -0
- package/lib/programmers/helpers/disable_function_importer_declare.js +15 -0
- package/lib/programmers/helpers/disable_function_importer_declare.js.map +1 -0
- package/package.json +1 -1
- package/src/Primitive.ts +123 -123
- package/src/factories/MetadataFactory.ts +62 -62
- package/src/factories/MetadataTagFactory.ts +5 -7
- package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
- package/src/metadata/IMetadata.ts +26 -26
- package/src/metadata/Metadata.ts +539 -539
- package/src/programmers/AssertProgrammer.ts +1 -1
- package/src/programmers/CheckerProgrammer.ts +901 -901
- package/src/programmers/IsProgrammer.ts +6 -2
- package/src/programmers/ValidateProgrammer.ts +1 -1
- package/src/programmers/helpers/disable_function_importer_declare.ts +21 -0
- package/src/programmers/internal/application_object.ts +155 -155
- package/src/programmers/internal/application_tuple.ts +31 -31
- package/src/schemas/IJsonSchema.ts +130 -130
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../metadata/Metadata";
|
|
4
|
-
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
-
|
|
6
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
7
|
-
|
|
8
|
-
export namespace MetadataFactory {
|
|
9
|
-
export interface IOptions {
|
|
10
|
-
resolve: boolean;
|
|
11
|
-
constant: boolean;
|
|
12
|
-
validate?: (meta: Metadata) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const analyze =
|
|
16
|
-
(checker: ts.TypeChecker) =>
|
|
17
|
-
(options: IOptions) =>
|
|
18
|
-
(collection: MetadataCollection) =>
|
|
19
|
-
(type: ts.Type | null): Metadata => {
|
|
20
|
-
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
21
|
-
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
22
|
-
collection,
|
|
23
|
-
)(type, false);
|
|
24
|
-
|
|
25
|
-
// FIND RECURSIVE OBJECTS
|
|
26
|
-
for (const object of collection.objects())
|
|
27
|
-
object.recursive = object.properties.some((prop) =>
|
|
28
|
-
isRecursive(object.name)(prop.value),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// RETURNS
|
|
32
|
-
return metadata;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const isRecursive =
|
|
36
|
-
(name: string) =>
|
|
37
|
-
(meta: Metadata): boolean => {
|
|
38
|
-
const similar = (str: string) =>
|
|
39
|
-
name === str ||
|
|
40
|
-
name.indexOf(`<${str},`) !== -1 ||
|
|
41
|
-
name.indexOf(`, ${str}>`) !== -1 ||
|
|
42
|
-
name.indexOf(`, ${str},`) !== -1;
|
|
43
|
-
return (
|
|
44
|
-
meta.objects.some((obj) => similar(obj.name)) ||
|
|
45
|
-
meta.arrays.some((arr) => isRecursive(name)(arr)) ||
|
|
46
|
-
meta.tuples.some((tuple) =>
|
|
47
|
-
tuple.some((m) => isRecursive(name)(m.rest ?? m)),
|
|
48
|
-
) ||
|
|
49
|
-
meta.maps.some((map) => isRecursive(name)(map.value))
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @deprecated Use `analyze` function instead
|
|
55
|
-
*/
|
|
56
|
-
export const generate = (
|
|
57
|
-
checker: ts.TypeChecker,
|
|
58
|
-
collection: MetadataCollection,
|
|
59
|
-
type: ts.Type,
|
|
60
|
-
options: IOptions,
|
|
61
|
-
) => analyze(checker)(options)(collection)(type);
|
|
62
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
+
|
|
6
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
7
|
+
|
|
8
|
+
export namespace MetadataFactory {
|
|
9
|
+
export interface IOptions {
|
|
10
|
+
resolve: boolean;
|
|
11
|
+
constant: boolean;
|
|
12
|
+
validate?: (meta: Metadata) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const analyze =
|
|
16
|
+
(checker: ts.TypeChecker) =>
|
|
17
|
+
(options: IOptions) =>
|
|
18
|
+
(collection: MetadataCollection) =>
|
|
19
|
+
(type: ts.Type | null): Metadata => {
|
|
20
|
+
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
21
|
+
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
22
|
+
collection,
|
|
23
|
+
)(type, false);
|
|
24
|
+
|
|
25
|
+
// FIND RECURSIVE OBJECTS
|
|
26
|
+
for (const object of collection.objects())
|
|
27
|
+
object.recursive = object.properties.some((prop) =>
|
|
28
|
+
isRecursive(object.name)(prop.value),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// RETURNS
|
|
32
|
+
return metadata;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const isRecursive =
|
|
36
|
+
(name: string) =>
|
|
37
|
+
(meta: Metadata): boolean => {
|
|
38
|
+
const similar = (str: string) =>
|
|
39
|
+
name === str ||
|
|
40
|
+
name.indexOf(`<${str},`) !== -1 ||
|
|
41
|
+
name.indexOf(`, ${str}>`) !== -1 ||
|
|
42
|
+
name.indexOf(`, ${str},`) !== -1;
|
|
43
|
+
return (
|
|
44
|
+
meta.objects.some((obj) => similar(obj.name)) ||
|
|
45
|
+
meta.arrays.some((arr) => isRecursive(name)(arr)) ||
|
|
46
|
+
meta.tuples.some((tuple) =>
|
|
47
|
+
tuple.some((m) => isRecursive(name)(m.rest ?? m)),
|
|
48
|
+
) ||
|
|
49
|
+
meta.maps.some((map) => isRecursive(name)(map.value))
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use `analyze` function instead
|
|
55
|
+
*/
|
|
56
|
+
export const generate = (
|
|
57
|
+
checker: ts.TypeChecker,
|
|
58
|
+
collection: MetadataCollection,
|
|
59
|
+
type: ts.Type,
|
|
60
|
+
options: IOptions,
|
|
61
|
+
) => analyze(checker)(options)(collection)(type);
|
|
62
|
+
}
|
|
@@ -83,13 +83,11 @@ export namespace MetadataTagFactory {
|
|
|
83
83
|
/* -----------------------------------------------------------
|
|
84
84
|
NUMBER
|
|
85
85
|
----------------------------------------------------------- */
|
|
86
|
-
type: (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
return { kind: "type", value: text };
|
|
86
|
+
type: (_identifier, metadata, text, _output) => {
|
|
87
|
+
return has_atomic(metadata)("number") &&
|
|
88
|
+
(text === "int" || text === "uint")
|
|
89
|
+
? { kind: "type", value: text }
|
|
90
|
+
: null;
|
|
93
91
|
},
|
|
94
92
|
minimum: (identifier, metadata, text, output) => {
|
|
95
93
|
validate(identifier, metadata, output, "minimum", "number", [
|
|
@@ -1,143 +1,143 @@
|
|
|
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) || isProperty(node))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
: (node) => isProperty(node);
|
|
42
|
-
|
|
43
|
-
const insert =
|
|
44
|
-
(key: Metadata) =>
|
|
45
|
-
(value: Metadata) =>
|
|
46
|
-
(identifier: () => string) =>
|
|
47
|
-
(
|
|
48
|
-
symbol: ts.Symbol | undefined,
|
|
49
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
50
|
-
): MetadataProperty => {
|
|
51
|
-
// COMMENTS AND TAGS
|
|
52
|
-
const description: string | undefined =
|
|
53
|
-
CommentFactory.string(
|
|
54
|
-
symbol?.getDocumentationComment(checker)
|
|
55
|
-
)
|
|
56
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
-
symbol?.getJsDocTags()
|
|
58
|
-
).filter(filter
|
|
59
|
-
|
|
60
|
-
// THE PROPERTY
|
|
61
|
-
const property = MetadataProperty.create({
|
|
62
|
-
key,
|
|
63
|
-
value,
|
|
64
|
-
description,
|
|
65
|
-
jsDocTags,
|
|
66
|
-
tags: MetadataTagFactory.generate(value)(jsDocTags)(() =>
|
|
67
|
-
identifier(),
|
|
68
|
-
),
|
|
69
|
-
});
|
|
70
|
-
obj.properties.push(property);
|
|
71
|
-
return property;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//----
|
|
75
|
-
// REGULAR PROPERTIES
|
|
76
|
-
//----
|
|
77
|
-
for (const prop of parent.getApparentProperties()) {
|
|
78
|
-
// CHECK INTERNAL TAG
|
|
79
|
-
if (
|
|
80
|
-
(prop.getJsDocTags(checker)
|
|
81
|
-
(tag) => tag.name === "internal",
|
|
82
|
-
) !== undefined
|
|
83
|
-
)
|
|
84
|
-
continue;
|
|
85
|
-
|
|
86
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
87
|
-
const [node, type] = (() => {
|
|
88
|
-
const node = (prop.getDeclarations()
|
|
89
|
-
| ts.PropertyDeclaration
|
|
90
|
-
| undefined;
|
|
91
|
-
const type: ts.Type | undefined = node
|
|
92
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
93
|
-
: "getTypeOfPropertyOfType" in checker
|
|
94
|
-
? (checker as any).getTypeOfPropertyOfType(
|
|
95
|
-
parent,
|
|
96
|
-
prop.name,
|
|
97
|
-
)
|
|
98
|
-
: undefined;
|
|
99
|
-
return [node, type];
|
|
100
|
-
})();
|
|
101
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
102
|
-
|
|
103
|
-
// GET EXACT TYPE
|
|
104
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
105
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
106
|
-
collection,
|
|
107
|
-
)(type, false);
|
|
108
|
-
|
|
109
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
110
|
-
if (node?.questionToken) {
|
|
111
|
-
Writable(value).required = false;
|
|
112
|
-
Writable(value).optional = true;
|
|
113
|
-
}
|
|
114
|
-
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//----
|
|
118
|
-
// DYNAMIC PROPERTIES
|
|
119
|
-
//----
|
|
120
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
121
|
-
// GET EXACT TYPE
|
|
122
|
-
const analyzer = (type: ts.Type) =>
|
|
123
|
-
explore_metadata(checker)(options)(collection)(type, false);
|
|
124
|
-
const key: Metadata = analyzer(index.keyType);
|
|
125
|
-
const value: Metadata = analyzer(index.type);
|
|
126
|
-
|
|
127
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
128
|
-
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
129
|
-
index.declaration?.parent
|
|
130
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
131
|
-
: undefined,
|
|
132
|
-
(doc) => doc.name !== "default",
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return obj;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const isProperty = (node: ts.Declaration) =>
|
|
140
|
-
ts.isPropertyDeclaration(node) ||
|
|
141
|
-
ts.isPropertyAssignment(node) ||
|
|
142
|
-
ts.isPropertySignature(node) ||
|
|
143
|
-
ts.isTypeLiteralNode(node);
|
|
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) || isProperty(node))
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
: (node) => isProperty(node);
|
|
42
|
+
|
|
43
|
+
const insert =
|
|
44
|
+
(key: Metadata) =>
|
|
45
|
+
(value: Metadata) =>
|
|
46
|
+
(identifier: () => string) =>
|
|
47
|
+
(
|
|
48
|
+
symbol: ts.Symbol | undefined,
|
|
49
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
50
|
+
): MetadataProperty => {
|
|
51
|
+
// COMMENTS AND TAGS
|
|
52
|
+
const description: string | undefined =
|
|
53
|
+
CommentFactory.string(
|
|
54
|
+
symbol?.getDocumentationComment(checker) ?? [],
|
|
55
|
+
) ?? undefined;
|
|
56
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
+
symbol?.getJsDocTags() ?? []
|
|
58
|
+
).filter(filter ?? (() => true));
|
|
59
|
+
|
|
60
|
+
// THE PROPERTY
|
|
61
|
+
const property = MetadataProperty.create({
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
description,
|
|
65
|
+
jsDocTags,
|
|
66
|
+
tags: MetadataTagFactory.generate(value)(jsDocTags)(() =>
|
|
67
|
+
identifier(),
|
|
68
|
+
),
|
|
69
|
+
});
|
|
70
|
+
obj.properties.push(property);
|
|
71
|
+
return property;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//----
|
|
75
|
+
// REGULAR PROPERTIES
|
|
76
|
+
//----
|
|
77
|
+
for (const prop of parent.getApparentProperties()) {
|
|
78
|
+
// CHECK INTERNAL TAG
|
|
79
|
+
if (
|
|
80
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
81
|
+
(tag) => tag.name === "internal",
|
|
82
|
+
) !== undefined
|
|
83
|
+
)
|
|
84
|
+
continue;
|
|
85
|
+
|
|
86
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
87
|
+
const [node, type] = (() => {
|
|
88
|
+
const node = (prop.getDeclarations() ?? [])[0] as
|
|
89
|
+
| ts.PropertyDeclaration
|
|
90
|
+
| undefined;
|
|
91
|
+
const type: ts.Type | undefined = node
|
|
92
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
93
|
+
: "getTypeOfPropertyOfType" in checker
|
|
94
|
+
? (checker as any).getTypeOfPropertyOfType(
|
|
95
|
+
parent,
|
|
96
|
+
prop.name,
|
|
97
|
+
)
|
|
98
|
+
: undefined;
|
|
99
|
+
return [node, type];
|
|
100
|
+
})();
|
|
101
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
102
|
+
|
|
103
|
+
// GET EXACT TYPE
|
|
104
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
105
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
106
|
+
collection,
|
|
107
|
+
)(type, false);
|
|
108
|
+
|
|
109
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
110
|
+
if (node?.questionToken) {
|
|
111
|
+
Writable(value).required = false;
|
|
112
|
+
Writable(value).optional = true;
|
|
113
|
+
}
|
|
114
|
+
insert(key)(value)(() => `${obj.name}.${prop.name}`)(prop);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//----
|
|
118
|
+
// DYNAMIC PROPERTIES
|
|
119
|
+
//----
|
|
120
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
121
|
+
// GET EXACT TYPE
|
|
122
|
+
const analyzer = (type: ts.Type) =>
|
|
123
|
+
explore_metadata(checker)(options)(collection)(type, false);
|
|
124
|
+
const key: Metadata = analyzer(index.keyType);
|
|
125
|
+
const value: Metadata = analyzer(index.type);
|
|
126
|
+
|
|
127
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
128
|
+
insert(key)(value)(() => `${obj.name}[${key.getName()}]`)(
|
|
129
|
+
index.declaration?.parent
|
|
130
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
131
|
+
: undefined,
|
|
132
|
+
(doc) => doc.name !== "default",
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return obj;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const isProperty = (node: ts.Declaration) =>
|
|
140
|
+
ts.isPropertyDeclaration(node) ||
|
|
141
|
+
ts.isPropertyAssignment(node) ||
|
|
142
|
+
ts.isPropertySignature(node) ||
|
|
143
|
+
ts.isTypeLiteralNode(node);
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { Writable } from "../../../typings/Writable";
|
|
6
|
-
|
|
7
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
8
|
-
|
|
9
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
10
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
11
|
-
import { explore_metadata } from "./explore_metadata";
|
|
12
|
-
|
|
13
|
-
export const iterate_metadata_tuple =
|
|
14
|
-
(checker: ts.TypeChecker) =>
|
|
15
|
-
(options: MetadataFactory.IOptions) =>
|
|
16
|
-
(collection: MetadataCollection) =>
|
|
17
|
-
(meta: Metadata, type: ts.TupleType): boolean => {
|
|
18
|
-
if (!(checker as any).isTupleType(type)) return false;
|
|
19
|
-
|
|
20
|
-
const elementFlags: readonly ts.ElementFlags[] =
|
|
21
|
-
type.elementFlags ??
|
|
22
|
-
(type.target as ts.TupleType)?.elementFlags ??
|
|
23
|
-
[];
|
|
24
|
-
|
|
25
|
-
const children: Metadata[] = checker
|
|
26
|
-
.getTypeArguments(type as ts.TypeReference)
|
|
27
|
-
.map((elem, i) => {
|
|
28
|
-
const child: Metadata = explore_metadata(checker)(options)(
|
|
29
|
-
collection,
|
|
30
|
-
)(elem, false);
|
|
31
|
-
|
|
32
|
-
// CHECK OPTIONAL
|
|
33
|
-
const flag: ts.ElementFlags | undefined = elementFlags[i];
|
|
34
|
-
if (flag === ts.ElementFlags.Optional)
|
|
35
|
-
Writable(child).optional = true;
|
|
36
|
-
|
|
37
|
-
// REST TYPE
|
|
38
|
-
if (flag !== ts.ElementFlags.Rest) return child;
|
|
39
|
-
const wrapper: Metadata = Metadata.initialize();
|
|
40
|
-
Writable(wrapper).rest = child;
|
|
41
|
-
return wrapper;
|
|
42
|
-
});
|
|
43
|
-
ArrayUtil.set(meta.tuples, children, join_tuple_names);
|
|
44
|
-
return true;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const join_tuple_names = (metas: Metadata[]): string =>
|
|
48
|
-
`[${metas.map((m) => m.getName).join(", ")}]`;
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { Writable } from "../../../typings/Writable";
|
|
6
|
+
|
|
7
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
8
|
+
|
|
9
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
10
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
11
|
+
import { explore_metadata } from "./explore_metadata";
|
|
12
|
+
|
|
13
|
+
export const iterate_metadata_tuple =
|
|
14
|
+
(checker: ts.TypeChecker) =>
|
|
15
|
+
(options: MetadataFactory.IOptions) =>
|
|
16
|
+
(collection: MetadataCollection) =>
|
|
17
|
+
(meta: Metadata, type: ts.TupleType): boolean => {
|
|
18
|
+
if (!(checker as any).isTupleType(type)) return false;
|
|
19
|
+
|
|
20
|
+
const elementFlags: readonly ts.ElementFlags[] =
|
|
21
|
+
type.elementFlags ??
|
|
22
|
+
(type.target as ts.TupleType)?.elementFlags ??
|
|
23
|
+
[];
|
|
24
|
+
|
|
25
|
+
const children: Metadata[] = checker
|
|
26
|
+
.getTypeArguments(type as ts.TypeReference)
|
|
27
|
+
.map((elem, i) => {
|
|
28
|
+
const child: Metadata = explore_metadata(checker)(options)(
|
|
29
|
+
collection,
|
|
30
|
+
)(elem, false);
|
|
31
|
+
|
|
32
|
+
// CHECK OPTIONAL
|
|
33
|
+
const flag: ts.ElementFlags | undefined = elementFlags[i];
|
|
34
|
+
if (flag === ts.ElementFlags.Optional)
|
|
35
|
+
Writable(child).optional = true;
|
|
36
|
+
|
|
37
|
+
// REST TYPE
|
|
38
|
+
if (flag !== ts.ElementFlags.Rest) return child;
|
|
39
|
+
const wrapper: Metadata = Metadata.initialize();
|
|
40
|
+
Writable(wrapper).rest = child;
|
|
41
|
+
return wrapper;
|
|
42
|
+
});
|
|
43
|
+
ArrayUtil.set(meta.tuples, children, join_tuple_names);
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const join_tuple_names = (metas: Metadata[]): string =>
|
|
48
|
+
`[${metas.map((m) => m.getName).join(", ")}]`;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Atomic } from "../typings/Atomic";
|
|
2
|
-
|
|
3
|
-
import { IMetadataConstant } from "./IMetadataConstant";
|
|
4
|
-
import { IMetadataEntry } from "./IMetadataEntry";
|
|
5
|
-
|
|
6
|
-
export interface IMetadata {
|
|
7
|
-
any: boolean;
|
|
8
|
-
required: boolean;
|
|
9
|
-
optional: boolean;
|
|
10
|
-
nullable: boolean;
|
|
11
|
-
functional: boolean;
|
|
12
|
-
|
|
13
|
-
atomics: Atomic.Literal[];
|
|
14
|
-
constants: IMetadataConstant[];
|
|
15
|
-
templates: IMetadata[][];
|
|
16
|
-
resolved: IMetadata | null;
|
|
17
|
-
|
|
18
|
-
rest: IMetadata | null;
|
|
19
|
-
arrays: IMetadata[];
|
|
20
|
-
tuples: IMetadata[][];
|
|
21
|
-
objects: string[];
|
|
22
|
-
|
|
23
|
-
natives: string[];
|
|
24
|
-
sets: IMetadata[];
|
|
25
|
-
maps: IMetadataEntry[];
|
|
26
|
-
}
|
|
1
|
+
import { Atomic } from "../typings/Atomic";
|
|
2
|
+
|
|
3
|
+
import { IMetadataConstant } from "./IMetadataConstant";
|
|
4
|
+
import { IMetadataEntry } from "./IMetadataEntry";
|
|
5
|
+
|
|
6
|
+
export interface IMetadata {
|
|
7
|
+
any: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
nullable: boolean;
|
|
11
|
+
functional: boolean;
|
|
12
|
+
|
|
13
|
+
atomics: Atomic.Literal[];
|
|
14
|
+
constants: IMetadataConstant[];
|
|
15
|
+
templates: IMetadata[][];
|
|
16
|
+
resolved: IMetadata | null;
|
|
17
|
+
|
|
18
|
+
rest: IMetadata | null;
|
|
19
|
+
arrays: IMetadata[];
|
|
20
|
+
tuples: IMetadata[][];
|
|
21
|
+
objects: string[];
|
|
22
|
+
|
|
23
|
+
natives: string[];
|
|
24
|
+
sets: IMetadata[];
|
|
25
|
+
maps: IMetadataEntry[];
|
|
26
|
+
}
|