typia 3.4.15 → 3.5.0-dev.20221222
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 +48 -7
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +119 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +11 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +134 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +2 -3
- package/src/executable/internal/TypiaSetupWizard.ts +173 -173
- package/src/factories/MetadataCollection.ts +83 -122
- package/src/factories/MetadataFactory.ts +47 -47
- package/src/factories/MetadataTagFactory.ts +351 -351
- package/src/factories/ProtocolFactory.ts +92 -0
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
- package/src/functional/$number.ts +12 -12
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +11 -0
- package/src/metadata/IMetadataTag.ts +137 -122
- package/src/metadata/Metadata.ts +479 -477
- package/src/module.ts +1547 -1535
- package/src/programmers/AssertParseProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +445 -445
- package/src/programmers/AssertStringifyProgrammer.ts +65 -65
- package/src/programmers/CheckerProgrammer.ts +810 -810
- package/src/programmers/IsParseProgrammer.ts +61 -61
- package/src/programmers/IsProgrammer.ts +175 -175
- package/src/programmers/IsStringifyProgrammer.ts +69 -69
- package/src/programmers/MessageProgrammer.ts +116 -0
- package/src/programmers/StringifyProgrammer.ts +762 -762
- package/src/programmers/ValidateParseProgrammer.ts +59 -59
- package/src/programmers/ValidateProgrammer.ts +237 -237
- package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +231 -228
- package/src/programmers/internal/check_bigint.ts +85 -85
- package/src/programmers/internal/check_number.ts +175 -175
- package/src/schemas/IJsonSchema.ts +90 -90
- package/src/transformers/CallExpressionTransformer.ts +131 -124
- package/src/transformers/ITransformOptions.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
import type Comment from "comment-json";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
export namespace TypiaSetupWizard {
|
|
6
|
-
export async function ttypescript(manager: string): Promise<void> {
|
|
7
|
-
// INSTALL
|
|
8
|
-
const pack: any = await prepare(manager);
|
|
9
|
-
add(manager)(pack)("ttypescript", true);
|
|
10
|
-
add(manager)(pack)("ts-node", true);
|
|
11
|
-
|
|
12
|
-
// TSCONFIG.JSON
|
|
13
|
-
await configure(manager)(pack);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function tsPatch(manager: string): Promise<void> {
|
|
17
|
-
// INSTALL
|
|
18
|
-
add(manager)(await prepare(manager))("ts-patch", true);
|
|
19
|
-
execute("npx ts-patch install");
|
|
20
|
-
|
|
21
|
-
// PACKAGE.JSON
|
|
22
|
-
const pack: any = JSON.parse(
|
|
23
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
24
|
-
);
|
|
25
|
-
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
26
|
-
pack.scripts = {};
|
|
27
|
-
if (typeof pack.scripts.prepare === "string") {
|
|
28
|
-
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
29
|
-
pack.scripts.prepare =
|
|
30
|
-
"ts-patch install && " + pack.scripts.prepare;
|
|
31
|
-
} else pack.scripts.prepare = "ts-patch install";
|
|
32
|
-
|
|
33
|
-
await fs.promises.writeFile(
|
|
34
|
-
"package.json",
|
|
35
|
-
JSON.stringify(pack, null, 2),
|
|
36
|
-
"utf8",
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// TSCONFIG.JSON
|
|
40
|
-
await configure(manager)(pack);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function prepare(manager: string): Promise<any> {
|
|
44
|
-
if (fs.existsSync("package.json") === false)
|
|
45
|
-
halt(() => {})("make package.json file or move to it.");
|
|
46
|
-
|
|
47
|
-
const pack: any = JSON.parse(
|
|
48
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
49
|
-
);
|
|
50
|
-
const wizard = add(manager)(pack);
|
|
51
|
-
wizard("typia", false);
|
|
52
|
-
wizard("typescript", true);
|
|
53
|
-
return pack;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const configure =
|
|
57
|
-
(manager: string) =>
|
|
58
|
-
async (pack: any): Promise<void> => {
|
|
59
|
-
// VALIDATE PRERATATION
|
|
60
|
-
if (fs.existsSync("tsconfig.json") === false) {
|
|
61
|
-
execute("npx tsc --init");
|
|
62
|
-
if (fs.existsSync("tsconfig.json") === false)
|
|
63
|
-
halt(() => {})("tsconfig.json file does not exist.");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const temporary: boolean = !fs.existsSync(
|
|
67
|
-
"node_modules/comment-json",
|
|
68
|
-
);
|
|
69
|
-
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
70
|
-
|
|
71
|
-
const halter: (msg: string) => never = halt(() => {
|
|
72
|
-
if (temporary === true) remove(manager)("comment-json", true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// READ TSCONFIG FILE
|
|
76
|
-
const Comment: typeof import("comment-json") = await import(
|
|
77
|
-
process.cwd() + "/node_modules/comment-json"
|
|
78
|
-
);
|
|
79
|
-
const config: Comment.CommentObject = Comment.parse(
|
|
80
|
-
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
81
|
-
) as Comment.CommentObject;
|
|
82
|
-
const options = config.compilerOptions as
|
|
83
|
-
| Comment.CommentObject
|
|
84
|
-
| undefined;
|
|
85
|
-
if (options === undefined)
|
|
86
|
-
halter(
|
|
87
|
-
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
91
|
-
(() => {
|
|
92
|
-
const plugins = options.plugins as
|
|
93
|
-
| Comment.CommentArray<Comment.CommentObject>
|
|
94
|
-
| undefined;
|
|
95
|
-
if (plugins === undefined)
|
|
96
|
-
return (options.plugins = [] as any);
|
|
97
|
-
else if (!Array.isArray(plugins))
|
|
98
|
-
halter(
|
|
99
|
-
`"plugins" property of tsconfig.json must be array type.`,
|
|
100
|
-
);
|
|
101
|
-
return plugins;
|
|
102
|
-
})();
|
|
103
|
-
|
|
104
|
-
// CHECK WHETHER CONFIGURED
|
|
105
|
-
const strict: boolean = options.strict === true;
|
|
106
|
-
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
107
|
-
(p) =>
|
|
108
|
-
typeof p === "object" &&
|
|
109
|
-
p !== null &&
|
|
110
|
-
p.transform === "typia/lib/transform",
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
if (strict === true && oldbie !== undefined) {
|
|
114
|
-
console.log(
|
|
115
|
-
"you've been already configured the tsconfig.json file.",
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
// DO CONFIGURE
|
|
119
|
-
options.strict = true;
|
|
120
|
-
if (oldbie === undefined)
|
|
121
|
-
plugins.push(
|
|
122
|
-
Comment.parse(`
|
|
123
|
-
{
|
|
124
|
-
"transform": "typia/lib/transform"
|
|
125
|
-
}`) as Comment.CommentObject,
|
|
126
|
-
);
|
|
127
|
-
await fs.promises.writeFile(
|
|
128
|
-
"tsconfig.json",
|
|
129
|
-
Comment.stringify(config, null, 2),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
if (temporary === true) remove(manager)("comment-json", false);
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const add =
|
|
137
|
-
(manager: string) =>
|
|
138
|
-
(pack: any) =>
|
|
139
|
-
(modulo: string, devOnly: boolean): void => {
|
|
140
|
-
const exists: boolean =
|
|
141
|
-
(devOnly === false
|
|
142
|
-
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
143
|
-
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
144
|
-
fs.existsSync("node_modules/" + modulo);
|
|
145
|
-
const middle: string =
|
|
146
|
-
manager === "yarn"
|
|
147
|
-
? `add${devOnly ? " -D" : ""}`
|
|
148
|
-
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
149
|
-
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const remove =
|
|
153
|
-
(manager: string) =>
|
|
154
|
-
(modulo: string, devOnly: boolean): void => {
|
|
155
|
-
const middle: string =
|
|
156
|
-
manager === "yarn"
|
|
157
|
-
? `remove${devOnly ? " -D" : ""}`
|
|
158
|
-
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
159
|
-
execute(`${manager} ${middle} ${modulo}`);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const halt =
|
|
163
|
-
(closer: () => any) =>
|
|
164
|
-
(desc: string): never => {
|
|
165
|
-
closer();
|
|
166
|
-
console.error(desc);
|
|
167
|
-
process.exit(-1);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
function execute(command: string): void {
|
|
171
|
-
console.log(command);
|
|
172
|
-
cp.execSync(command, { stdio: "inherit" });
|
|
173
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
import type Comment from "comment-json";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
export namespace TypiaSetupWizard {
|
|
6
|
+
export async function ttypescript(manager: string): Promise<void> {
|
|
7
|
+
// INSTALL
|
|
8
|
+
const pack: any = await prepare(manager);
|
|
9
|
+
add(manager)(pack)("ttypescript", true);
|
|
10
|
+
add(manager)(pack)("ts-node", true);
|
|
11
|
+
|
|
12
|
+
// TSCONFIG.JSON
|
|
13
|
+
await configure(manager)(pack);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function tsPatch(manager: string): Promise<void> {
|
|
17
|
+
// INSTALL
|
|
18
|
+
add(manager)(await prepare(manager))("ts-patch", true);
|
|
19
|
+
execute("npx ts-patch install");
|
|
20
|
+
|
|
21
|
+
// PACKAGE.JSON
|
|
22
|
+
const pack: any = JSON.parse(
|
|
23
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
24
|
+
);
|
|
25
|
+
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
26
|
+
pack.scripts = {};
|
|
27
|
+
if (typeof pack.scripts.prepare === "string") {
|
|
28
|
+
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
29
|
+
pack.scripts.prepare =
|
|
30
|
+
"ts-patch install && " + pack.scripts.prepare;
|
|
31
|
+
} else pack.scripts.prepare = "ts-patch install";
|
|
32
|
+
|
|
33
|
+
await fs.promises.writeFile(
|
|
34
|
+
"package.json",
|
|
35
|
+
JSON.stringify(pack, null, 2),
|
|
36
|
+
"utf8",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// TSCONFIG.JSON
|
|
40
|
+
await configure(manager)(pack);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function prepare(manager: string): Promise<any> {
|
|
44
|
+
if (fs.existsSync("package.json") === false)
|
|
45
|
+
halt(() => {})("make package.json file or move to it.");
|
|
46
|
+
|
|
47
|
+
const pack: any = JSON.parse(
|
|
48
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
49
|
+
);
|
|
50
|
+
const wizard = add(manager)(pack);
|
|
51
|
+
wizard("typia", false);
|
|
52
|
+
wizard("typescript", true);
|
|
53
|
+
return pack;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const configure =
|
|
57
|
+
(manager: string) =>
|
|
58
|
+
async (pack: any): Promise<void> => {
|
|
59
|
+
// VALIDATE PRERATATION
|
|
60
|
+
if (fs.existsSync("tsconfig.json") === false) {
|
|
61
|
+
execute("npx tsc --init");
|
|
62
|
+
if (fs.existsSync("tsconfig.json") === false)
|
|
63
|
+
halt(() => {})("tsconfig.json file does not exist.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const temporary: boolean = !fs.existsSync(
|
|
67
|
+
"node_modules/comment-json",
|
|
68
|
+
);
|
|
69
|
+
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
70
|
+
|
|
71
|
+
const halter: (msg: string) => never = halt(() => {
|
|
72
|
+
if (temporary === true) remove(manager)("comment-json", true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// READ TSCONFIG FILE
|
|
76
|
+
const Comment: typeof import("comment-json") = await import(
|
|
77
|
+
process.cwd() + "/node_modules/comment-json"
|
|
78
|
+
);
|
|
79
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
80
|
+
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
81
|
+
) as Comment.CommentObject;
|
|
82
|
+
const options = config.compilerOptions as
|
|
83
|
+
| Comment.CommentObject
|
|
84
|
+
| undefined;
|
|
85
|
+
if (options === undefined)
|
|
86
|
+
halter(
|
|
87
|
+
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
91
|
+
(() => {
|
|
92
|
+
const plugins = options.plugins as
|
|
93
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
94
|
+
| undefined;
|
|
95
|
+
if (plugins === undefined)
|
|
96
|
+
return (options.plugins = [] as any);
|
|
97
|
+
else if (!Array.isArray(plugins))
|
|
98
|
+
halter(
|
|
99
|
+
`"plugins" property of tsconfig.json must be array type.`,
|
|
100
|
+
);
|
|
101
|
+
return plugins;
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
// CHECK WHETHER CONFIGURED
|
|
105
|
+
const strict: boolean = options.strict === true;
|
|
106
|
+
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
107
|
+
(p) =>
|
|
108
|
+
typeof p === "object" &&
|
|
109
|
+
p !== null &&
|
|
110
|
+
p.transform === "typia/lib/transform",
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (strict === true && oldbie !== undefined) {
|
|
114
|
+
console.log(
|
|
115
|
+
"you've been already configured the tsconfig.json file.",
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
// DO CONFIGURE
|
|
119
|
+
options.strict = true;
|
|
120
|
+
if (oldbie === undefined)
|
|
121
|
+
plugins.push(
|
|
122
|
+
Comment.parse(`
|
|
123
|
+
{
|
|
124
|
+
"transform": "typia/lib/transform"
|
|
125
|
+
}`) as Comment.CommentObject,
|
|
126
|
+
);
|
|
127
|
+
await fs.promises.writeFile(
|
|
128
|
+
"tsconfig.json",
|
|
129
|
+
Comment.stringify(config, null, 2),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (temporary === true) remove(manager)("comment-json", false);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const add =
|
|
137
|
+
(manager: string) =>
|
|
138
|
+
(pack: any) =>
|
|
139
|
+
(modulo: string, devOnly: boolean): void => {
|
|
140
|
+
const exists: boolean =
|
|
141
|
+
(devOnly === false
|
|
142
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
143
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
144
|
+
fs.existsSync("node_modules/" + modulo);
|
|
145
|
+
const middle: string =
|
|
146
|
+
manager === "yarn"
|
|
147
|
+
? `add${devOnly ? " -D" : ""}`
|
|
148
|
+
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
149
|
+
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const remove =
|
|
153
|
+
(manager: string) =>
|
|
154
|
+
(modulo: string, devOnly: boolean): void => {
|
|
155
|
+
const middle: string =
|
|
156
|
+
manager === "yarn"
|
|
157
|
+
? `remove${devOnly ? " -D" : ""}`
|
|
158
|
+
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
159
|
+
execute(`${manager} ${middle} ${modulo}`);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const halt =
|
|
163
|
+
(closer: () => any) =>
|
|
164
|
+
(desc: string): never => {
|
|
165
|
+
closer();
|
|
166
|
+
console.error(desc);
|
|
167
|
+
process.exit(-1);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
function execute(command: string): void {
|
|
171
|
+
console.log(command);
|
|
172
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
173
|
+
}
|
|
@@ -1,122 +1,83 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../metadata/MetadataObject";
|
|
5
|
-
|
|
6
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
7
|
-
|
|
8
|
-
import { CommentFactory } from "./CommentFactory";
|
|
9
|
-
import { TypeFactory } from "./TypeFactory";
|
|
10
|
-
|
|
11
|
-
export class MetadataCollection {
|
|
12
|
-
private readonly dict_: Map<ts.Type, MetadataObject>;
|
|
13
|
-
private readonly names_: Map<string, Map<ts.Type, string>>;
|
|
14
|
-
private readonly unions_: Map<string, MetadataObject[]>;
|
|
15
|
-
private index_: number;
|
|
16
|
-
|
|
17
|
-
public constructor(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
? `${name}.o${duplicates.size}`
|
|
85
|
-
: name;
|
|
86
|
-
duplicates.set(type, addicted);
|
|
87
|
-
return addicted;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export namespace MetadataCollection {
|
|
91
|
-
export interface IOptions {
|
|
92
|
-
replace?(str: string): string;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function replace(str: string): string {
|
|
96
|
-
for (const [before, after] of REPLACERS)
|
|
97
|
-
str = str.split(before).join(after);
|
|
98
|
-
return str;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function escape(str: string): string {
|
|
102
|
-
for (const [before, after] of REPLACERS)
|
|
103
|
-
if (after !== "") str = str.split(after).join(before);
|
|
104
|
-
return str;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const REPLACERS: [string, string][] = [
|
|
108
|
-
["$", "_dollar_"],
|
|
109
|
-
["&", "_and_"],
|
|
110
|
-
["|", "_or_"],
|
|
111
|
-
["{", "_blt_"],
|
|
112
|
-
["}", "_bgt_"],
|
|
113
|
-
["<", "_lt_"],
|
|
114
|
-
[">", "_gt_"],
|
|
115
|
-
["[", "_alt_"],
|
|
116
|
-
["]", "_agt_"],
|
|
117
|
-
[",", "_comma_"],
|
|
118
|
-
["`", "_backquote_"],
|
|
119
|
-
["'", "_singlequote_"],
|
|
120
|
-
['"', "_doublequote_"],
|
|
121
|
-
[" ", "_space_"],
|
|
122
|
-
];
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../metadata/MetadataObject";
|
|
5
|
+
|
|
6
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
7
|
+
|
|
8
|
+
import { CommentFactory } from "./CommentFactory";
|
|
9
|
+
import { TypeFactory } from "./TypeFactory";
|
|
10
|
+
|
|
11
|
+
export class MetadataCollection {
|
|
12
|
+
private readonly dict_: Map<ts.Type, MetadataObject>;
|
|
13
|
+
private readonly names_: Map<string, Map<ts.Type, string>>;
|
|
14
|
+
private readonly unions_: Map<string, MetadataObject[]>;
|
|
15
|
+
private index_: number;
|
|
16
|
+
|
|
17
|
+
public constructor() {
|
|
18
|
+
this.dict_ = new Map();
|
|
19
|
+
this.names_ = new Map();
|
|
20
|
+
this.unions_ = new Map();
|
|
21
|
+
this.index_ = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public objects(): MetadataObject[] {
|
|
25
|
+
return [...this.dict_.values()];
|
|
26
|
+
}
|
|
27
|
+
public unions(): MetadataObject[][] {
|
|
28
|
+
return [...this.unions_.values()];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public emplace(
|
|
32
|
+
checker: ts.TypeChecker,
|
|
33
|
+
type: ts.Type,
|
|
34
|
+
): [MetadataObject, boolean] {
|
|
35
|
+
const oldbie = this.dict_.get(type);
|
|
36
|
+
if (oldbie !== undefined) return [oldbie, false];
|
|
37
|
+
|
|
38
|
+
const $id: string = this.get_name(checker, type);
|
|
39
|
+
const obj: MetadataObject = MetadataObject.create({
|
|
40
|
+
name: $id,
|
|
41
|
+
properties: [],
|
|
42
|
+
description:
|
|
43
|
+
(type.symbol &&
|
|
44
|
+
CommentFactory.generate(
|
|
45
|
+
type.symbol.getDocumentationComment(checker),
|
|
46
|
+
)) ||
|
|
47
|
+
undefined,
|
|
48
|
+
jsDocTags: type.symbol?.getJsDocTags() || [],
|
|
49
|
+
validated: false,
|
|
50
|
+
index: this.index_++,
|
|
51
|
+
recursive: false,
|
|
52
|
+
nullables: [],
|
|
53
|
+
});
|
|
54
|
+
this.dict_.set(type, obj);
|
|
55
|
+
return [obj, true];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
public getUnionIndex(meta: Metadata): number {
|
|
62
|
+
const key: string = meta.objects.map((obj) => obj.name).join(" | ");
|
|
63
|
+
MapUtil.take(this.unions_, key, () => meta.objects);
|
|
64
|
+
return [...this.unions_.keys()].indexOf(key);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private get_name(checker: ts.TypeChecker, type: ts.Type): string {
|
|
68
|
+
const name: string = TypeFactory.getFullName(checker, type);
|
|
69
|
+
const duplicates: Map<ts.Type, string> = MapUtil.take(
|
|
70
|
+
this.names_,
|
|
71
|
+
name,
|
|
72
|
+
() => new Map(),
|
|
73
|
+
);
|
|
74
|
+
const oldbie: string | undefined = duplicates.get(type);
|
|
75
|
+
if (oldbie !== undefined) return oldbie;
|
|
76
|
+
|
|
77
|
+
const addicted: string = duplicates.size
|
|
78
|
+
? `${name}.o${duplicates.size}`
|
|
79
|
+
: name;
|
|
80
|
+
duplicates.set(type, addicted);
|
|
81
|
+
return addicted;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../metadata/Metadata";
|
|
4
|
-
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
-
|
|
6
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
7
|
-
|
|
8
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
9
|
-
|
|
10
|
-
export namespace MetadataFactory {
|
|
11
|
-
export interface IOptions {
|
|
12
|
-
resolve: boolean;
|
|
13
|
-
constant: boolean;
|
|
14
|
-
validate?: (meta: Metadata) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function generate(
|
|
18
|
-
checker: ts.TypeChecker,
|
|
19
|
-
collection: MetadataCollection,
|
|
20
|
-
type: ts.Type | null,
|
|
21
|
-
options: IOptions,
|
|
22
|
-
): Metadata {
|
|
23
|
-
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
24
|
-
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
25
|
-
collection,
|
|
26
|
-
)(type, false);
|
|
27
|
-
|
|
28
|
-
// FIND RECURSIVE OBJECTS
|
|
29
|
-
for (const object of collection.objects())
|
|
30
|
-
object.recursive = object.properties.some(
|
|
31
|
-
(prop) =>
|
|
32
|
-
ArrayUtil.has(
|
|
33
|
-
prop.value.objects,
|
|
34
|
-
(elem) => elem.name === object.name,
|
|
35
|
-
) ||
|
|
36
|
-
prop.value.arrays.some((meta) =>
|
|
37
|
-
ArrayUtil.has(
|
|
38
|
-
meta.objects,
|
|
39
|
-
(elem) => elem.name === object.name,
|
|
40
|
-
),
|
|
41
|
-
),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// RETURNS
|
|
45
|
-
return metadata;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
7
|
+
|
|
8
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
9
|
+
|
|
10
|
+
export namespace MetadataFactory {
|
|
11
|
+
export interface IOptions {
|
|
12
|
+
resolve: boolean;
|
|
13
|
+
constant: boolean;
|
|
14
|
+
validate?: (meta: Metadata) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function generate(
|
|
18
|
+
checker: ts.TypeChecker,
|
|
19
|
+
collection: MetadataCollection,
|
|
20
|
+
type: ts.Type | null,
|
|
21
|
+
options: IOptions,
|
|
22
|
+
): Metadata {
|
|
23
|
+
// CONSTRUCT SCHEMA WITH OBJECTS
|
|
24
|
+
const metadata: Metadata = explore_metadata(checker)(options)(
|
|
25
|
+
collection,
|
|
26
|
+
)(type, false);
|
|
27
|
+
|
|
28
|
+
// FIND RECURSIVE OBJECTS
|
|
29
|
+
for (const object of collection.objects())
|
|
30
|
+
object.recursive = object.properties.some(
|
|
31
|
+
(prop) =>
|
|
32
|
+
ArrayUtil.has(
|
|
33
|
+
prop.value.objects,
|
|
34
|
+
(elem) => elem.name === object.name,
|
|
35
|
+
) ||
|
|
36
|
+
prop.value.arrays.some((meta) =>
|
|
37
|
+
ArrayUtil.has(
|
|
38
|
+
meta.objects,
|
|
39
|
+
(elem) => elem.name === object.name,
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// RETURNS
|
|
45
|
+
return metadata;
|
|
46
|
+
}
|
|
47
|
+
}
|