@nestia/sdk 2.4.5 → 2.4.6

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 (66) hide show
  1. package/lib/analyses/ConfigAnalyzer.js +1 -1
  2. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.js.map +1 -1
  5. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  6. package/lib/executable/sdk.js +11 -11
  7. package/lib/generates/SwaggerGenerator.js.map +1 -1
  8. package/lib/generates/internal/SdkFunctionProgrammer.js +7 -7
  9. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  10. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  11. package/package.json +3 -3
  12. package/src/INestiaConfig.ts +248 -248
  13. package/src/NestiaSdkApplication.ts +253 -253
  14. package/src/analyses/AccessorAnalyzer.ts +60 -60
  15. package/src/analyses/ConfigAnalyzer.ts +3 -3
  16. package/src/analyses/ControllerAnalyzer.ts +2 -2
  17. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  18. package/src/analyses/GenericAnalyzer.ts +51 -51
  19. package/src/analyses/ImportAnalyzer.ts +138 -138
  20. package/src/analyses/PathAnalyzer.ts +14 -14
  21. package/src/analyses/ReflectAnalyzer.ts +9 -9
  22. package/src/analyses/SecurityAnalyzer.ts +20 -20
  23. package/src/executable/internal/CommandParser.ts +15 -15
  24. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  25. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  26. package/src/executable/sdk.ts +73 -73
  27. package/src/generates/E2eGenerator.ts +64 -64
  28. package/src/generates/SdkGenerator.ts +96 -96
  29. package/src/generates/SwaggerGenerator.ts +5 -5
  30. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  31. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  32. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  33. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +518 -518
  35. package/src/generates/internal/SdkImportWizard.ts +55 -55
  36. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  37. package/src/generates/internal/SdkSimulationProgrammer.ts +4 -4
  38. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  39. package/src/generates/internal/SwaggerSchemaGenerator.ts +16 -16
  40. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  41. package/src/index.ts +4 -4
  42. package/src/module.ts +2 -2
  43. package/src/structures/IController.ts +91 -91
  44. package/src/structures/IErrorReport.ts +6 -6
  45. package/src/structures/INestiaProject.ts +13 -13
  46. package/src/structures/INormalizedInput.ts +20 -20
  47. package/src/structures/IRoute.ts +52 -52
  48. package/src/structures/ISwagger.ts +91 -91
  49. package/src/structures/ISwaggerComponents.ts +29 -29
  50. package/src/structures/ISwaggerError.ts +8 -8
  51. package/src/structures/ISwaggerInfo.ts +80 -80
  52. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  53. package/src/structures/ISwaggerLazySchema.ts +7 -7
  54. package/src/structures/ISwaggerRoute.ts +51 -51
  55. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  56. package/src/structures/ITypeTuple.ts +6 -6
  57. package/src/structures/MethodType.ts +5 -5
  58. package/src/structures/ParamCategory.ts +1 -1
  59. package/src/structures/TypeEntry.ts +22 -22
  60. package/src/utils/ArrayUtil.ts +26 -26
  61. package/src/utils/FileRetriever.ts +22 -22
  62. package/src/utils/ImportDictionary.ts +125 -125
  63. package/src/utils/MapUtil.ts +14 -14
  64. package/src/utils/PathUtil.ts +10 -10
  65. package/src/utils/SourceFinder.ts +66 -66
  66. package/src/utils/StripEnums.ts +5 -5
@@ -1,253 +1,253 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import ts from "typescript";
4
-
5
- import { INestiaConfig } from "./INestiaConfig";
6
- import { AccessorAnalyzer } from "./analyses/AccessorAnalyzer";
7
- import { ConfigAnalyzer } from "./analyses/ConfigAnalyzer";
8
- import { ControllerAnalyzer } from "./analyses/ControllerAnalyzer";
9
- import { ReflectAnalyzer } from "./analyses/ReflectAnalyzer";
10
- import { E2eGenerator } from "./generates/E2eGenerator";
11
- import { SdkGenerator } from "./generates/SdkGenerator";
12
- import { SwaggerGenerator } from "./generates/SwaggerGenerator";
13
- import { IController } from "./structures/IController";
14
- import { IErrorReport } from "./structures/IErrorReport";
15
- import { INestiaProject } from "./structures/INestiaProject";
16
- import { IRoute } from "./structures/IRoute";
17
- import { MapUtil } from "./utils/MapUtil";
18
-
19
- export class NestiaSdkApplication {
20
- public constructor(
21
- private readonly config: INestiaConfig,
22
- private readonly compilerOptions: ts.CompilerOptions,
23
- ) {}
24
-
25
- public async e2e(): Promise<void> {
26
- if (!this.config.output)
27
- throw new Error(
28
- "Error on NestiaApplication.e2e(): output path of SDK is not specified.",
29
- );
30
- else if (!this.config.e2e)
31
- throw new Error(
32
- "Error on NestiaApplication.e2e(): output path of e2e test files is not specified.",
33
- );
34
-
35
- const validate =
36
- (title: string) =>
37
- async (location: string): Promise<void> => {
38
- const parent: string = path.resolve(location + "/..");
39
- const stats: fs.Stats = await fs.promises.lstat(parent);
40
- if (stats.isDirectory() === false)
41
- throw new Error(
42
- `Error on NestiaApplication.e2e(): output directory of ${title} does not exists.`,
43
- );
44
- };
45
- await validate("sdk")(this.config.output);
46
- await validate("e2e")(this.config.e2e);
47
-
48
- print_title("Nestia E2E Generator");
49
- await this.generate(
50
- "e2e",
51
- (config) => config,
52
- (checker) => (config) => async (routes) => {
53
- await SdkGenerator.generate(checker)(config)(routes);
54
- await E2eGenerator.generate(config)(routes);
55
- },
56
- );
57
- }
58
-
59
- public async sdk(): Promise<void> {
60
- if (!this.config.output)
61
- throw new Error(
62
- "Error on NestiaApplication.sdk(): output path is not specified.",
63
- );
64
-
65
- const parent: string = path.resolve(this.config.output + "/..");
66
- const stats: fs.Stats = await fs.promises.lstat(parent);
67
- if (stats.isDirectory() === false)
68
- throw new Error(
69
- "Error on NestiaApplication.sdk(): output directory does not exists.",
70
- );
71
-
72
- print_title("Nestia SDK Generator");
73
- await this.generate("sdk", (config) => config, SdkGenerator.generate);
74
- }
75
-
76
- public async swagger(): Promise<void> {
77
- if (!this.config.swagger?.output)
78
- throw new Error(
79
- `Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`,
80
- );
81
-
82
- const parsed: path.ParsedPath = path.parse(this.config.swagger.output);
83
- const directory: string = !!parsed.ext
84
- ? path.resolve(parsed.dir)
85
- : this.config.swagger.output;
86
- const stats: fs.Stats = await fs.promises.lstat(directory);
87
- if (stats.isDirectory() === false)
88
- throw new Error(
89
- "Error on NestiaApplication.swagger(): output directory does not exists.",
90
- );
91
-
92
- print_title("Nestia Swagger Generator");
93
- await this.generate(
94
- "swagger",
95
- (config) => config.swagger!,
96
- SwaggerGenerator.generate,
97
- );
98
- }
99
-
100
- private async generate<Config>(
101
- method: string,
102
- config: (entire: INestiaConfig) => Config,
103
- archiver: (
104
- checker: ts.TypeChecker,
105
- ) => (config: Config) => (routes: IRoute[]) => Promise<void>,
106
- ): Promise<void> {
107
- //----
108
- // ANALYZE REFLECTS
109
- //----
110
- const unique: WeakSet<any> = new WeakSet();
111
- const controllers: IController[] = [];
112
- const project: INestiaProject = {
113
- config: this.config,
114
- input: await ConfigAnalyzer.input(this.config),
115
- checker: null!,
116
- errors: [],
117
- warnings: [],
118
- };
119
-
120
- console.log("Analyzing reflections");
121
- for (const include of (await ConfigAnalyzer.input(this.config)).include)
122
- controllers.push(
123
- ...(await ReflectAnalyzer.analyze(project)(
124
- unique,
125
- include.file,
126
- include.paths,
127
- include.controller,
128
- )),
129
- );
130
-
131
- const agg: number = (() => {
132
- const set: Set<string> = new Set();
133
- for (const c of controllers)
134
- for (const cPath of c.paths)
135
- for (const f of c.functions)
136
- for (const fPath of f.paths)
137
- set.add(`${f.method}::${cPath}/${fPath}`);
138
- return set.size;
139
- })();
140
-
141
- console.log(` - controllers: #${controllers.length}`);
142
- console.log(` - paths: #${agg}`);
143
- console.log(
144
- ` - routes: #${controllers
145
- .map(
146
- (c) =>
147
- c.paths.length *
148
- c.functions.map((f) => f.paths.length).reduce((a, b) => a + b, 0),
149
- )
150
- .reduce((a, b) => a + b, 0)}`,
151
- );
152
-
153
- //----
154
- // ANALYZE TYPESCRIPT CODE
155
- //----
156
- console.log("Analyzing source codes");
157
-
158
- const program: ts.Program = ts.createProgram(
159
- controllers.map((c) => c.file),
160
- this.compilerOptions,
161
- );
162
- project.checker = program.getTypeChecker();
163
-
164
- const routeList: IRoute[] = [];
165
- for (const c of controllers) {
166
- const file: ts.SourceFile | undefined = program.getSourceFile(c.file);
167
- if (file === undefined) continue;
168
- routeList.push(...(await ControllerAnalyzer.analyze(project)(file, c)));
169
- }
170
-
171
- // REPORT ERRORS
172
- if (project.errors.length) {
173
- report_errors("error")(project.errors);
174
- process.exit(-1);
175
- }
176
- if (project.warnings.length) report_errors("warning")(project.warnings);
177
-
178
- // FIND IMPLICIT TYPES
179
- const implicit: IRoute[] = routeList.filter(is_implicit_return_typed);
180
- if (implicit.length > 0)
181
- throw new Error(
182
- `NestiaApplication.${method}(): implicit return type is not allowed.\n` +
183
- "\n" +
184
- "List of implicit return typed routes:\n" +
185
- implicit
186
- .map(
187
- (it) =>
188
- ` - ${it.symbol.class}.${it.symbol.function} at "${it.location}"`,
189
- )
190
- .join("\n"),
191
- );
192
-
193
- // DO GENERATE
194
- AccessorAnalyzer.analyze(routeList);
195
- await archiver(project.checker)(config(this.config))(routeList);
196
- }
197
- }
198
-
199
- const print_title = (str: string): void => {
200
- console.log("-----------------------------------------------------------");
201
- console.log(` ${str}`);
202
- console.log("-----------------------------------------------------------");
203
- };
204
-
205
- const is_implicit_return_typed = (route: IRoute): boolean => {
206
- const name: string = route.output.typeName;
207
- if (name === "void") return false;
208
- else if (name.indexOf("readonly [") !== -1) return true;
209
-
210
- const pos: number = name.indexOf("__object");
211
- if (pos === -1) return false;
212
-
213
- const before: number = pos - 1;
214
- const after: number = pos + "__object".length;
215
- for (const i of [before, after])
216
- if (name[i] === undefined) continue;
217
- else if (VARIABLE.test(name[i])) return false;
218
- return true;
219
- };
220
-
221
- const report_errors =
222
- (type: "error" | "warning") =>
223
- (errors: IErrorReport[]): void => {
224
- // key: file
225
- // key: controller
226
- // key: function
227
- // value: message
228
- const map: Map<string, Map<string, Map<string, Set<string>>>> = new Map();
229
- for (const e of errors) {
230
- const file = MapUtil.take(map, e.file, () => new Map());
231
- const controller = MapUtil.take(file, e.controller, () => new Map());
232
- const func = MapUtil.take(controller, e.function, () => new Set());
233
- func.add(e.message);
234
- }
235
-
236
- console.log("");
237
- print_title(`Nestia ${type[0].toUpperCase()}${type.slice(1)} Report`);
238
- for (const [file, cMap] of map) {
239
- for (const [controller, fMap] of cMap)
240
- for (const [func, messages] of fMap) {
241
- const location: string = path.relative(process.cwd(), file);
242
- console.log(
243
- `${location} - ${
244
- func !== null ? `${controller}.${func}()` : controller
245
- }`,
246
- );
247
- for (const msg of messages) console.log(` - ${msg}`);
248
- console.log("");
249
- }
250
- }
251
- };
252
-
253
- const VARIABLE = /[a-zA-Z_$0-9]/;
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import ts from "typescript";
4
+
5
+ import { INestiaConfig } from "./INestiaConfig";
6
+ import { AccessorAnalyzer } from "./analyses/AccessorAnalyzer";
7
+ import { ConfigAnalyzer } from "./analyses/ConfigAnalyzer";
8
+ import { ControllerAnalyzer } from "./analyses/ControllerAnalyzer";
9
+ import { ReflectAnalyzer } from "./analyses/ReflectAnalyzer";
10
+ import { E2eGenerator } from "./generates/E2eGenerator";
11
+ import { SdkGenerator } from "./generates/SdkGenerator";
12
+ import { SwaggerGenerator } from "./generates/SwaggerGenerator";
13
+ import { IController } from "./structures/IController";
14
+ import { IErrorReport } from "./structures/IErrorReport";
15
+ import { INestiaProject } from "./structures/INestiaProject";
16
+ import { IRoute } from "./structures/IRoute";
17
+ import { MapUtil } from "./utils/MapUtil";
18
+
19
+ export class NestiaSdkApplication {
20
+ public constructor(
21
+ private readonly config: INestiaConfig,
22
+ private readonly compilerOptions: ts.CompilerOptions,
23
+ ) {}
24
+
25
+ public async e2e(): Promise<void> {
26
+ if (!this.config.output)
27
+ throw new Error(
28
+ "Error on NestiaApplication.e2e(): output path of SDK is not specified.",
29
+ );
30
+ else if (!this.config.e2e)
31
+ throw new Error(
32
+ "Error on NestiaApplication.e2e(): output path of e2e test files is not specified.",
33
+ );
34
+
35
+ const validate =
36
+ (title: string) =>
37
+ async (location: string): Promise<void> => {
38
+ const parent: string = path.resolve(location + "/..");
39
+ const stats: fs.Stats = await fs.promises.lstat(parent);
40
+ if (stats.isDirectory() === false)
41
+ throw new Error(
42
+ `Error on NestiaApplication.e2e(): output directory of ${title} does not exists.`,
43
+ );
44
+ };
45
+ await validate("sdk")(this.config.output);
46
+ await validate("e2e")(this.config.e2e);
47
+
48
+ print_title("Nestia E2E Generator");
49
+ await this.generate(
50
+ "e2e",
51
+ (config) => config,
52
+ (checker) => (config) => async (routes) => {
53
+ await SdkGenerator.generate(checker)(config)(routes);
54
+ await E2eGenerator.generate(config)(routes);
55
+ },
56
+ );
57
+ }
58
+
59
+ public async sdk(): Promise<void> {
60
+ if (!this.config.output)
61
+ throw new Error(
62
+ "Error on NestiaApplication.sdk(): output path is not specified.",
63
+ );
64
+
65
+ const parent: string = path.resolve(this.config.output + "/..");
66
+ const stats: fs.Stats = await fs.promises.lstat(parent);
67
+ if (stats.isDirectory() === false)
68
+ throw new Error(
69
+ "Error on NestiaApplication.sdk(): output directory does not exists.",
70
+ );
71
+
72
+ print_title("Nestia SDK Generator");
73
+ await this.generate("sdk", (config) => config, SdkGenerator.generate);
74
+ }
75
+
76
+ public async swagger(): Promise<void> {
77
+ if (!this.config.swagger?.output)
78
+ throw new Error(
79
+ `Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`,
80
+ );
81
+
82
+ const parsed: path.ParsedPath = path.parse(this.config.swagger.output);
83
+ const directory: string = !!parsed.ext
84
+ ? path.resolve(parsed.dir)
85
+ : this.config.swagger.output;
86
+ const stats: fs.Stats = await fs.promises.lstat(directory);
87
+ if (stats.isDirectory() === false)
88
+ throw new Error(
89
+ "Error on NestiaApplication.swagger(): output directory does not exists.",
90
+ );
91
+
92
+ print_title("Nestia Swagger Generator");
93
+ await this.generate(
94
+ "swagger",
95
+ (config) => config.swagger!,
96
+ SwaggerGenerator.generate,
97
+ );
98
+ }
99
+
100
+ private async generate<Config>(
101
+ method: string,
102
+ config: (entire: INestiaConfig) => Config,
103
+ archiver: (
104
+ checker: ts.TypeChecker,
105
+ ) => (config: Config) => (routes: IRoute[]) => Promise<void>,
106
+ ): Promise<void> {
107
+ //----
108
+ // ANALYZE REFLECTS
109
+ //----
110
+ const unique: WeakSet<any> = new WeakSet();
111
+ const controllers: IController[] = [];
112
+ const project: INestiaProject = {
113
+ config: this.config,
114
+ input: await ConfigAnalyzer.input(this.config),
115
+ checker: null!,
116
+ errors: [],
117
+ warnings: [],
118
+ };
119
+
120
+ console.log("Analyzing reflections");
121
+ for (const include of (await ConfigAnalyzer.input(this.config)).include)
122
+ controllers.push(
123
+ ...(await ReflectAnalyzer.analyze(project)(
124
+ unique,
125
+ include.file,
126
+ include.paths,
127
+ include.controller,
128
+ )),
129
+ );
130
+
131
+ const agg: number = (() => {
132
+ const set: Set<string> = new Set();
133
+ for (const c of controllers)
134
+ for (const cPath of c.paths)
135
+ for (const f of c.functions)
136
+ for (const fPath of f.paths)
137
+ set.add(`${f.method}::${cPath}/${fPath}`);
138
+ return set.size;
139
+ })();
140
+
141
+ console.log(` - controllers: #${controllers.length}`);
142
+ console.log(` - paths: #${agg}`);
143
+ console.log(
144
+ ` - routes: #${controllers
145
+ .map(
146
+ (c) =>
147
+ c.paths.length *
148
+ c.functions.map((f) => f.paths.length).reduce((a, b) => a + b, 0),
149
+ )
150
+ .reduce((a, b) => a + b, 0)}`,
151
+ );
152
+
153
+ //----
154
+ // ANALYZE TYPESCRIPT CODE
155
+ //----
156
+ console.log("Analyzing source codes");
157
+
158
+ const program: ts.Program = ts.createProgram(
159
+ controllers.map((c) => c.file),
160
+ this.compilerOptions,
161
+ );
162
+ project.checker = program.getTypeChecker();
163
+
164
+ const routeList: IRoute[] = [];
165
+ for (const c of controllers) {
166
+ const file: ts.SourceFile | undefined = program.getSourceFile(c.file);
167
+ if (file === undefined) continue;
168
+ routeList.push(...(await ControllerAnalyzer.analyze(project)(file, c)));
169
+ }
170
+
171
+ // REPORT ERRORS
172
+ if (project.errors.length) {
173
+ report_errors("error")(project.errors);
174
+ process.exit(-1);
175
+ }
176
+ if (project.warnings.length) report_errors("warning")(project.warnings);
177
+
178
+ // FIND IMPLICIT TYPES
179
+ const implicit: IRoute[] = routeList.filter(is_implicit_return_typed);
180
+ if (implicit.length > 0)
181
+ throw new Error(
182
+ `NestiaApplication.${method}(): implicit return type is not allowed.\n` +
183
+ "\n" +
184
+ "List of implicit return typed routes:\n" +
185
+ implicit
186
+ .map(
187
+ (it) =>
188
+ ` - ${it.symbol.class}.${it.symbol.function} at "${it.location}"`,
189
+ )
190
+ .join("\n"),
191
+ );
192
+
193
+ // DO GENERATE
194
+ AccessorAnalyzer.analyze(routeList);
195
+ await archiver(project.checker)(config(this.config))(routeList);
196
+ }
197
+ }
198
+
199
+ const print_title = (str: string): void => {
200
+ console.log("-----------------------------------------------------------");
201
+ console.log(` ${str}`);
202
+ console.log("-----------------------------------------------------------");
203
+ };
204
+
205
+ const is_implicit_return_typed = (route: IRoute): boolean => {
206
+ const name: string = route.output.typeName;
207
+ if (name === "void") return false;
208
+ else if (name.indexOf("readonly [") !== -1) return true;
209
+
210
+ const pos: number = name.indexOf("__object");
211
+ if (pos === -1) return false;
212
+
213
+ const before: number = pos - 1;
214
+ const after: number = pos + "__object".length;
215
+ for (const i of [before, after])
216
+ if (name[i] === undefined) continue;
217
+ else if (VARIABLE.test(name[i])) return false;
218
+ return true;
219
+ };
220
+
221
+ const report_errors =
222
+ (type: "error" | "warning") =>
223
+ (errors: IErrorReport[]): void => {
224
+ // key: file
225
+ // key: controller
226
+ // key: function
227
+ // value: message
228
+ const map: Map<string, Map<string, Map<string, Set<string>>>> = new Map();
229
+ for (const e of errors) {
230
+ const file = MapUtil.take(map, e.file, () => new Map());
231
+ const controller = MapUtil.take(file, e.controller, () => new Map());
232
+ const func = MapUtil.take(controller, e.function, () => new Set());
233
+ func.add(e.message);
234
+ }
235
+
236
+ console.log("");
237
+ print_title(`Nestia ${type[0].toUpperCase()}${type.slice(1)} Report`);
238
+ for (const [file, cMap] of map) {
239
+ for (const [controller, fMap] of cMap)
240
+ for (const [func, messages] of fMap) {
241
+ const location: string = path.relative(process.cwd(), file);
242
+ console.log(
243
+ `${location} - ${
244
+ func !== null ? `${controller}.${func}()` : controller
245
+ }`,
246
+ );
247
+ for (const msg of messages) console.log(` - ${msg}`);
248
+ console.log("");
249
+ }
250
+ }
251
+ };
252
+
253
+ const VARIABLE = /[a-zA-Z_$0-9]/;
@@ -1,60 +1,60 @@
1
- import { Escaper } from "typia/lib/utils/Escaper";
2
-
3
- import { IRoute } from "../structures/IRoute";
4
-
5
- export namespace AccessorAnalyzer {
6
- export const analyze = (routes: IRoute[]) => {
7
- shrink(routes);
8
- variable(routes);
9
- shrink(routes);
10
- for (const r of routes) r.name = r.accessors.at(-1) ?? r.name;
11
- };
12
-
13
- const prepare = (routeList: IRoute[]): Map<string, number> => {
14
- const dict: Map<string, number> = new Map();
15
- for (const route of routeList)
16
- route.accessors.forEach((_a, i) => {
17
- const key: string = route.accessors.slice(0, i + 1).join(".");
18
- dict.set(key, (dict.get(key) ?? 0) + 1);
19
- });
20
- return dict;
21
- };
22
-
23
- const variable = (routeList: IRoute[]) => {
24
- const dict: Map<string, number> = prepare(routeList);
25
- for (const route of routeList) {
26
- const emended: string[] = route.accessors.slice();
27
- route.accessors.forEach((accessor, i) => {
28
- if (Escaper.variable(accessor)) return;
29
- while (true) {
30
- accessor = "$" + accessor;
31
- const partial: string = [
32
- ...route.accessors.slice(0, i),
33
- accessor,
34
- ].join(".");
35
- if (dict.has(partial) === false) {
36
- emended[i] = accessor;
37
- break;
38
- }
39
- }
40
- });
41
- route.accessors.splice(0, route.accessors.length, ...emended);
42
- }
43
- };
44
-
45
- const shrink = (routeList: IRoute[]) => {
46
- const dict: Map<string, number> = prepare(routeList);
47
- for (const route of routeList) {
48
- if (
49
- route.accessors.length < 2 ||
50
- route.accessors.at(-1) !== route.accessors.at(-2)
51
- )
52
- continue;
53
-
54
- const cut: string[] = route.accessors.slice(0, -1);
55
- if ((dict.get(cut.join(".")) ?? 0) > 1) continue;
56
-
57
- route.accessors = cut;
58
- }
59
- };
60
- }
1
+ import { Escaper } from "typia/lib/utils/Escaper";
2
+
3
+ import { IRoute } from "../structures/IRoute";
4
+
5
+ export namespace AccessorAnalyzer {
6
+ export const analyze = (routes: IRoute[]) => {
7
+ shrink(routes);
8
+ variable(routes);
9
+ shrink(routes);
10
+ for (const r of routes) r.name = r.accessors.at(-1) ?? r.name;
11
+ };
12
+
13
+ const prepare = (routeList: IRoute[]): Map<string, number> => {
14
+ const dict: Map<string, number> = new Map();
15
+ for (const route of routeList)
16
+ route.accessors.forEach((_a, i) => {
17
+ const key: string = route.accessors.slice(0, i + 1).join(".");
18
+ dict.set(key, (dict.get(key) ?? 0) + 1);
19
+ });
20
+ return dict;
21
+ };
22
+
23
+ const variable = (routeList: IRoute[]) => {
24
+ const dict: Map<string, number> = prepare(routeList);
25
+ for (const route of routeList) {
26
+ const emended: string[] = route.accessors.slice();
27
+ route.accessors.forEach((accessor, i) => {
28
+ if (Escaper.variable(accessor)) return;
29
+ while (true) {
30
+ accessor = "$" + accessor;
31
+ const partial: string = [
32
+ ...route.accessors.slice(0, i),
33
+ accessor,
34
+ ].join(".");
35
+ if (dict.has(partial) === false) {
36
+ emended[i] = accessor;
37
+ break;
38
+ }
39
+ }
40
+ });
41
+ route.accessors.splice(0, route.accessors.length, ...emended);
42
+ }
43
+ };
44
+
45
+ const shrink = (routeList: IRoute[]) => {
46
+ const dict: Map<string, number> = prepare(routeList);
47
+ for (const route of routeList) {
48
+ if (
49
+ route.accessors.length < 2 ||
50
+ route.accessors.at(-1) !== route.accessors.at(-2)
51
+ )
52
+ continue;
53
+
54
+ const cut: string[] = route.accessors.slice(0, -1);
55
+ if ((dict.get(cut.join(".")) ?? 0) > 1) continue;
56
+
57
+ route.accessors = cut;
58
+ }
59
+ };
60
+ }
@@ -65,7 +65,7 @@ export namespace ConfigAnalyzer {
65
65
  return {
66
66
  include: files.toJSON().map((pair) => ({
67
67
  controller: pair.first.first,
68
- file: pair.first.second,
68
+ file: decodeURIComponent(pair.first.second),
69
69
  paths: [...pair.second.values()],
70
70
  })),
71
71
  globalPrefix:
@@ -95,8 +95,8 @@ export namespace ConfigAnalyzer {
95
95
  ? 7
96
96
  : 8
97
97
  : str.startsWith("file://")
98
- ? 7
99
- : 0,
98
+ ? 7
99
+ : 0,
100
100
  );
101
101
 
102
102
  const transform_input =
@@ -265,8 +265,8 @@ export namespace ControllerAnalyzer {
265
265
  v === null
266
266
  ? null
267
267
  : project.input.versioning?.prefix?.length
268
- ? `${project.input.versioning.prefix}${v}`
269
- : v,
268
+ ? `${project.input.versioning.prefix}${v}`
269
+ : v,
270
270
  ),
271
271
  )({
272
272
  method: func.method,