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.
Files changed (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. 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
- private readonly options?: Partial<MetadataCollection.IOptions>,
19
- ) {
20
- this.dict_ = new Map();
21
- this.names_ = new Map();
22
- this.unions_ = new Map();
23
- this.index_ = 0;
24
- }
25
-
26
- public objects(): MetadataObject[] {
27
- return [...this.dict_.values()];
28
- }
29
- public unions(): MetadataObject[][] {
30
- return [...this.unions_.values()];
31
- }
32
-
33
- public emplace(
34
- checker: ts.TypeChecker,
35
- type: ts.Type,
36
- ): [MetadataObject, boolean] {
37
- const oldbie = this.dict_.get(type);
38
- if (oldbie !== undefined) return [oldbie, false];
39
-
40
- const $id: string = this.get_name(checker, type);
41
- const obj: MetadataObject = MetadataObject.create({
42
- name: $id,
43
- properties: [],
44
- description:
45
- (type.symbol &&
46
- CommentFactory.generate(
47
- type.symbol.getDocumentationComment(checker),
48
- )) ||
49
- undefined,
50
- jsDocTags: type.symbol?.getJsDocTags() || [],
51
- validated: false,
52
- index: this.index_++,
53
- recursive: false,
54
- nullables: [],
55
- });
56
- this.dict_.set(type, obj);
57
- return [obj, true];
58
- }
59
-
60
- /**
61
- * @internal
62
- */
63
- public getUnionIndex(meta: Metadata): number {
64
- const key: string = meta.objects.map((obj) => obj.name).join(" | ");
65
- MapUtil.take(this.unions_, key, () => meta.objects);
66
- return [...this.unions_.keys()].indexOf(key);
67
- }
68
-
69
- private get_name(checker: ts.TypeChecker, type: ts.Type): string {
70
- const name: string = (() => {
71
- const str: string = TypeFactory.getFullName(checker, type);
72
- return this.options?.replace ? this.options.replace(str) : str;
73
- })();
74
-
75
- const duplicates: Map<ts.Type, string> = MapUtil.take(
76
- this.names_,
77
- name,
78
- () => new Map(),
79
- );
80
- const oldbie: string | undefined = duplicates.get(type);
81
- if (oldbie !== undefined) return oldbie;
82
-
83
- const addicted: string = duplicates.size
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
+ }