@nestia/migrate 0.13.16 → 0.14.0

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 (69) hide show
  1. package/lib/MigrateApplication.d.ts +1 -0
  2. package/lib/MigrateApplication.js +843 -893
  3. package/lib/MigrateApplication.js.map +1 -1
  4. package/lib/analyzers/MigrateAnalyzer.js +5 -2
  5. package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
  6. package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
  7. package/lib/analyzers/MigrateControllerAnalyzer.js +14 -88
  8. package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/bundles/NEST_TEMPLATE.js +21 -6
  10. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  11. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  12. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  13. package/lib/executable/bundle.js +1 -1
  14. package/lib/internal/MigrateCommander.js +5 -2
  15. package/lib/internal/MigrateCommander.js.map +1 -1
  16. package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -9
  17. package/lib/programmers/MigrateApiFileProgrammer.js +4 -4
  18. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
  19. package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -8
  20. package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -30
  21. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  22. package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -8
  23. package/lib/programmers/MigrateApiNamespaceProgrammer.js +31 -37
  24. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  25. package/lib/programmers/MigrateApiProgrammer.js +19 -70
  26. package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
  27. package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +2 -8
  28. package/lib/programmers/MigrateApiSimulatationProgrammer.js +16 -16
  29. package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
  30. package/lib/programmers/MigrateApiStartProgrammer.js +1 -1
  31. package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
  32. package/lib/programmers/MigrateE2eProgrammer.js +1 -3
  33. package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
  34. package/lib/programmers/MigrateNestMethodProgrammer.js +4 -4
  35. package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
  36. package/lib/programmers/MigrateNestProgrammer.js +27 -23
  37. package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
  38. package/lib/programmers/MigrateSchemaProgrammer.js +22 -22
  39. package/lib/structures/IMigrateProgram.d.ts +8 -8
  40. package/lib/structures/IMigrateRoute.d.ts +1 -46
  41. package/lib/utils/OpenApiTypeChecker.d.ts +1 -1
  42. package/lib/utils/StringUtil.d.ts +0 -4
  43. package/lib/utils/StringUtil.js +0 -31
  44. package/lib/utils/StringUtil.js.map +1 -1
  45. package/lib/utils/openapi-down-convert/RefVisitor.js +4 -5
  46. package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
  47. package/package.json +11 -8
  48. package/src/MigrateApplication.ts +3 -2
  49. package/src/analyzers/MigrateAnalyzer.ts +10 -5
  50. package/src/analyzers/MigrateControllerAnalyzer.ts +17 -122
  51. package/src/bundles/NEST_TEMPLATE.ts +21 -6
  52. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  53. package/src/internal/MigrateCommander.ts +8 -2
  54. package/src/programmers/MigrateApiFileProgrammer.ts +10 -14
  55. package/src/programmers/MigrateApiFunctionProgrammer.ts +43 -41
  56. package/src/programmers/MigrateApiNamespaceProgrammer.ts +33 -51
  57. package/src/programmers/MigrateApiProgrammer.ts +26 -95
  58. package/src/programmers/MigrateApiSimulatationProgrammer.ts +17 -25
  59. package/src/programmers/MigrateApiStartProgrammer.ts +1 -1
  60. package/src/programmers/MigrateE2eProgrammer.ts +1 -3
  61. package/src/programmers/MigrateNestMethodProgrammer.ts +4 -4
  62. package/src/programmers/MigrateNestProgrammer.ts +10 -4
  63. package/src/structures/IMigrateProgram.ts +8 -8
  64. package/src/structures/IMigrateRoute.ts +1 -51
  65. package/src/utils/StringUtil.ts +0 -42
  66. package/lib/analyzers/MigrateMethodAnalyzer.d.ts +0 -9
  67. package/lib/analyzers/MigrateMethodAnalyzer.js +0 -304
  68. package/lib/analyzers/MigrateMethodAnalyzer.js.map +0 -1
  69. package/src/analyzers/MigrateMethodAnalyzer.ts +0 -387
@@ -34,7 +34,6 @@ export class MigrateApplication {
34
34
  const program: IMigrateProgram = MigrateAnalyzer.analyze({
35
35
  mode: "nest",
36
36
  document: this.document,
37
- dictionary: new Map(),
38
37
  simulate: config.simulate,
39
38
  e2e: config.e2e,
40
39
  });
@@ -46,6 +45,7 @@ export class MigrateApplication {
46
45
  ...MigrateApiProgrammer.write(program),
47
46
  ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
48
47
  ],
48
+ errors: program.errors,
49
49
  };
50
50
  }
51
51
 
@@ -53,7 +53,6 @@ export class MigrateApplication {
53
53
  const program: IMigrateProgram = MigrateAnalyzer.analyze({
54
54
  mode: "sdk",
55
55
  document: this.document,
56
- dictionary: new Map(),
57
56
  simulate: config.simulate,
58
57
  e2e: config.e2e,
59
58
  });
@@ -70,6 +69,7 @@ export class MigrateApplication {
70
69
  content: JSON.stringify(this.document, null, 2),
71
70
  },
72
71
  ],
72
+ errors: program.errors,
73
73
  };
74
74
  }
75
75
  }
@@ -77,6 +77,7 @@ export namespace MigrateApplication {
77
77
  export interface IOutput {
78
78
  program: IMigrateProgram;
79
79
  files: IMigrateFile[];
80
+ errors: IMigrateProgram.IError[];
80
81
  }
81
82
  export interface IConfig {
82
83
  simulate: boolean;
@@ -1,9 +1,14 @@
1
+ import { OpenApi } from "@samchon/openapi";
2
+
1
3
  import { IMigrateProgram } from "../structures/IMigrateProgram";
2
- import { MigrateControllerAnalyzer } from "./MigrateControllerAnalyzer";
3
4
 
4
5
  export namespace MigrateAnalyzer {
5
- export const analyze = (props: IMigrateProgram.IProps): IMigrateProgram => ({
6
- ...props,
7
- controllers: MigrateControllerAnalyzer.analyze(props),
8
- });
6
+ export const analyze = (props: IMigrateProgram.IProps): IMigrateProgram => {
7
+ const result = OpenApi.migrate(props.document);
8
+ return {
9
+ ...props,
10
+ routes: result.routes,
11
+ errors: result.errors,
12
+ };
13
+ };
9
14
  }
@@ -1,86 +1,32 @@
1
- import { OpenApi } from "@samchon/openapi";
2
- import { Escaper } from "typia/lib/utils/Escaper";
1
+ import { IMigrateRoute } from "@samchon/openapi";
3
2
 
4
3
  import { IMigrateController } from "../structures/IMigrateController";
5
- import { IMigrateProgram } from "../structures/IMigrateProgram";
6
- import { IMigrateRoute } from "../structures/IMigrateRoute";
7
4
  import { MapUtil } from "../utils/MapUtil";
8
5
  import { StringUtil } from "../utils/StringUtil";
9
- import { MigrateMethodAnalzyer } from "./MigrateMethodAnalyzer";
10
6
 
11
7
  export namespace MigrateControllerAnalyzer {
12
- export const analyze = (
13
- props: IMigrateProgram.IProps,
14
- ): IMigrateController[] => {
15
- interface IEntry {
16
- endpoint: OpenApi.IOperation;
17
- route: IMigrateRoute;
18
- }
19
- const endpoints: Map<string, IEntry[]> = new Map();
20
-
21
- // GATHER ROUTES
22
- for (const [path, collection] of [
23
- ...Object.entries(props.document.paths ?? {}),
24
- ...Object.entries(props.document.webhooks ?? {}),
25
- ]) {
26
- if (collection === undefined) continue;
27
-
28
- // PREPARE DIRECTORIES
29
- const location: string = StringUtil.splitWithNormalization(path)
30
- .filter((str) => str[0] !== "{" && str[0] !== ":")
8
+ export const analyze = (routes: IMigrateRoute[]): IMigrateController[] => {
9
+ const endpoints: Map<string, IMigrateRoute[]> = new Map();
10
+ for (const r of routes) {
11
+ const location: string = r.emendedPath
12
+ .split("/")
13
+ .filter((s) => s[0] !== ":")
31
14
  .join("/");
32
- for (const s of sequence(location)) MapUtil.take(endpoints)(s)(() => []);
33
-
34
- // INSERT ROUTES TO THE LAST DIRECTORY
35
- const routes: IEntry[] = MapUtil.take(endpoints)(location)(() => []);
36
- for (const [method, value] of Object.entries(collection)) {
37
- if (
38
- value === undefined ||
39
- ["get", "post", "patch", "put", "delete"].includes(method) === false
40
- )
41
- continue;
42
- const r: IMigrateRoute | null = MigrateMethodAnalzyer.analyze(props)({
43
- path,
44
- method,
45
- })(value as OpenApi.IOperation);
46
- if (
47
- r !== null &&
48
- routes.find(
49
- (x) => x.route.method === r.method && x.route.path === r.path,
50
- ) === undefined
51
- )
52
- routes.push({
53
- endpoint: value as OpenApi.IOperation,
54
- route: r,
55
- });
56
- }
15
+ MapUtil.take(endpoints)(location)(() => []).push(r);
57
16
  }
58
-
59
- // GENERATE CONTROLLERS
60
17
  const total: IMigrateController[] = [...endpoints.entries()]
61
18
  .filter(([_l, routes]) => !!routes.length)
62
- .map(([location, routes]) => {
63
- const prefix: string = StringUtil.commonPrefix(
64
- routes.map((e) => e.route.path),
65
- );
66
- for (const e of routes)
67
- e.route.path = StringUtil.reJoinWithDecimalParameters(
68
- e.route.path.replace(prefix, ""),
69
- );
70
- const controller: IMigrateController = {
71
- name: StringUtil.pascal(location) + "Controller",
72
- path: StringUtil.reJoinWithDecimalParameters(prefix),
19
+ .map(([path, routes]) => {
20
+ const name: string =
21
+ routes[0].accessor.slice(0, -1).map(StringUtil.capitalize).join("") +
22
+ "Controller";
23
+ const location: string = routes[0].accessor.slice(0, -2).join("/");
24
+ return {
25
+ name,
26
+ path,
73
27
  location: "src/controllers/" + location,
74
- routes: routes.map((e) => e.route),
28
+ routes,
75
29
  };
76
- emend(controller);
77
-
78
- for (const e of routes)
79
- props.dictionary.set(e.endpoint, {
80
- controller,
81
- route: e.route,
82
- });
83
- return controller;
84
30
  });
85
31
  for (const c of total)
86
32
  if (c.name === "Controller")
@@ -89,55 +35,4 @@ export namespace MigrateControllerAnalyzer {
89
35
  );
90
36
  return total;
91
37
  };
92
-
93
- const sequence = (location: string): string[] =>
94
- StringUtil.splitWithNormalization(location)
95
- .map((_str, i, entire) => entire.slice(0, i + 1).join("/"))
96
- .slice(0, -1)
97
- .reverse();
98
-
99
- const emend = (controller: IMigrateController): void => {
100
- interface IRouteCapsule {
101
- variables: string[];
102
- route: IMigrateRoute;
103
- }
104
- const dict: Map<string, IRouteCapsule[]> = new Map();
105
- for (const route of controller.routes) {
106
- const additional: string[] = StringUtil.splitWithNormalization(
107
- route.path,
108
- );
109
- const statics: string[] = additional.filter((str) => str[0] !== ":");
110
- if (statics.length) route.name = StringUtil.camel(statics.join("/"));
111
- else
112
- MapUtil.take(dict)(route.method)(() => []).push({
113
- variables: additional
114
- .filter((str) => str[0] === ":")
115
- .map((str) => str.substring(1)),
116
- route,
117
- });
118
- }
119
- for (const [method, capsules] of dict) {
120
- const emended: string = method === "delete" ? "erase" : method;
121
- for (const c of capsules) {
122
- const empty: boolean = c.variables.length === 0;
123
- c.route.name = empty
124
- ? emended
125
- : StringUtil.camel(`${emended}By/${c.variables.join("/and/")}`);
126
- }
127
- }
128
- for (const method of controller.routes) {
129
- if (Escaper.variable(method.name) === false)
130
- method.name = "_" + method.name;
131
- for (const spec of [method.headers, method.query, method.body])
132
- if (spec)
133
- spec.key = StringUtil.escapeDuplicate(
134
- method.parameters.map((p) => p.key),
135
- )(spec.key);
136
- }
137
- controller.routes.forEach((r, i) => {
138
- r.name = StringUtil.escapeDuplicate(
139
- controller.routes.filter((_r, j) => i !== j).map((x) => x.name),
140
- )(r.name);
141
- });
142
- };
143
38
  }
@@ -12,7 +12,7 @@ export const NEST_TEMPLATE = [
12
12
  {
13
13
  "location": ".github/workflows",
14
14
  "file": "build.yml",
15
- "content": "name: build\r\non: \r\n push:\r\n paths:\r\n - package.json\r\n - 'src/**'\r\n - 'test/**'\r\n pull_request:\r\n paths:\r\n - package.json\r\n - 'src/**'\r\n - 'test/**'\r\n\r\njobs:\r\n Ubuntu:\r\n runs-on: ubuntu-latest\r\n steps:\r\n - uses: actions/checkout@v4\r\n - uses: actions/setup-node@v4\r\n with:\r\n node-version: 20.x\r\n - uses: pnpm/action-setup@v2\r\n with:\r\n version: 8\r\n \r\n - name: Install Backend-Server\r\n run: pnpm install\r\n\r\n - name: Build Swagger\r\n run: npm run build:swagger\r\n\r\n - name: Build SDK\r\n run: npm run build:sdk\r\n\r\n - name: Compile Backend-Server\r\n run: npm run build\r\n\r\n - name: Run Test Program\r\n run: npm run test\r\n\r\n - name: Test Webpack\r\n run: npm run webpack && npm run test:webpack\r\n\r\n - name: EsLint\r\n run: npm run eslint\r\n"
15
+ "content": "name: build\r\non: \r\n push:\r\n paths:\r\n - 'src/**'\r\n - 'test/**'\r\n - 'package.json'\r\n pull_request:\r\n paths:\r\n - 'src/**'\r\n - 'test/**'\r\n - 'package.json'\r\njobs:\r\n Ubuntu:\r\n runs-on: ubuntu-latest\r\n steps:\r\n - uses: actions/checkout@v4\r\n - uses: actions/setup-node@v4\r\n with:\r\n node-version: 20.x\r\n - uses: pnpm/action-setup@v2\r\n with:\r\n version: 8\r\n \r\n - name: Install Backend-Server\r\n run: pnpm install\r\n\r\n - name: Build Swagger\r\n run: npm run build:swagger\r\n\r\n - name: Build SDK\r\n run: npm run build:sdk\r\n\r\n - name: Compile Backend-Server\r\n run: npm run build\r\n\r\n - name: Run Test Program\r\n run: npm run test\r\n\r\n - name: Test Webpack\r\n run: npm run webpack && npm run test:webpack\r\n\r\n - name: EsLint\r\n run: npm run eslint\r\n"
16
16
  },
17
17
  {
18
18
  "location": "",
@@ -34,6 +34,11 @@ export const NEST_TEMPLATE = [
34
34
  "file": "settings.json",
35
35
  "content": "{\r\n \"editor.tabSize\": 2,\r\n \"editor.formatOnSave\": true,\r\n \"[javascript][typescript]\": {\r\n \"editor.defaultFormatter\": \"esbenp.prettier-vscode\",\r\n \"editor.codeActionsOnSave\": {\r\n \"source.fixAll.eslint\": \"explicit\"\r\n },\r\n }\r\n}"
36
36
  },
37
+ {
38
+ "location": "docs/benchmarks",
39
+ "file": "AMD Ryzen 9 7940HS w Radeon 780M Graphics.md",
40
+ "content": "# Benchmark Report\r\n> Generated by [`@nestia/e2e`](https://github.com/samchon/nestia)\r\n\r\n - Specifications\r\n - CPU: AMD Ryzen 9 7940HS w/ Radeon 780M Graphics \r\n - RAM: 31 GB\r\n - NodeJS Version: v20.10.0\r\n - Backend Server: 1 core / 1 thread\r\n - Arguments\r\n - Count: 1,024\r\n - Threads: 4\r\n - Simultaneous: 32\r\n - Time\r\n - Start: 2024-06-21T13:24:13.810Z\r\n - Complete: 2024-06-21T13:24:16.611Z\r\n - Elapsed: 2,801 ms\r\n\r\nType | Count | Success | Mean. | Stdev. | Minimum | Maximum\r\n----|----|----|----|----|----|----\r\nTotal | 3,955 | 3,955 | 20.34 | 24.96 | 2 | 152\r\n\r\n> Unit: milliseconds\r\n\r\n## Endpoints\r\nType | Count | Success | Mean. | Stdev. | Minimum | Maximum\r\n----|----|----|----|----|----|----\r\nPATCH /bbs/articles/:section | 656 | 656 | 50.46 | 40.03 | 2 | 152\r\nGET /bbs/articles/:section/:id | 43 | 43 | 18.39 | 5.2 | 9 | 31\r\nPUT /bbs/articles/:section/:id | 22 | 22 | 16.77 | 3.46 | 12 | 28\r\nPOST /bbs/articles/:section | 3,234 | 3,234 | 14.28 | 14.68 | 6 | 132\r\n\r\n> Unit: milliseconds\r\n\r\n## Failures\r\nMethod | Path | Count | Failures\r\n-------|------|-------|----------"
41
+ },
37
42
  {
38
43
  "location": "",
39
44
  "file": "LICENSE",
@@ -47,7 +52,7 @@ export const NEST_TEMPLATE = [
47
52
  {
48
53
  "location": "",
49
54
  "file": "package.json",
50
- "content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.3\",\r\n \"@nestia/sdk\": \"^3.2.1\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.3.0\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.0.2\",\r\n \"typescript\": \"^5.3.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^3.2.1\",\r\n \"@nestia/fetcher\": \"^3.2.1\",\r\n \"@nestjs/common\": \"^10.3.9\",\r\n \"@nestjs/core\": \"^10.3.9\",\r\n \"@nestjs/platform-express\": \"^10.3.9\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tgrid\": \"^1.0.0\",\r\n \"tstl\": \"^3.0.0\",\r\n \"typia\": \"^6.1.0\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
55
+ "content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"benchmark\": \"node bin/test/benchmark\",\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.6.0\",\r\n \"@nestia/sdk\": \"^3.3.2\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/cli-progress\": \"^3.11.5\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"cli-progress\": \"^3.12.0\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.3.0\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.2.1\",\r\n \"typescript\": \"^5.5.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^3.3.2\",\r\n \"@nestia/fetcher\": \"^3.3.2\",\r\n \"@nestjs/common\": \"^10.3.9\",\r\n \"@nestjs/core\": \"^10.3.9\",\r\n \"@nestjs/platform-express\": \"^10.3.9\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tgrid\": \"^1.0.2\",\r\n \"tstl\": \"^3.0.0\",\r\n \"typia\": \"^6.3.1\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
51
56
  },
52
57
  {
53
58
  "location": "packages/api",
@@ -62,7 +67,7 @@ export const NEST_TEMPLATE = [
62
67
  {
63
68
  "location": "packages/api",
64
69
  "file": "package.json",
65
- "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.2.1\",\r\n \"tgrid\": \"^1.0.0\",\r\n \"typia\": \"^6.1.0\"\r\n }\r\n}"
70
+ "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.3.2\",\r\n \"tgrid\": \"^1.0.2\",\r\n \"typia\": \"^6.3.1\"\r\n }\r\n}"
66
71
  },
67
72
  {
68
73
  "location": "packages/api",
@@ -82,7 +87,7 @@ export const NEST_TEMPLATE = [
82
87
  {
83
88
  "location": "",
84
89
  "file": "README.md",
85
- "content": "# Nestia Template\r\n## Outline\r\n[![Build Status](https://github.com/samchon/nestia-start/workflows/build/badge.svg)](https://github.com/samchon/nestia-start/actions?query=workflow%3Abuild)\r\n\r\nA template repository for backend projects using [nestia](https://github.com/samchon/nestia).\r\n\r\nYou can create a new project from this boilerplate by running below command:\r\n\r\n```bash\r\nnpx nestia start <directory>\r\n```\r\n\r\nFor reference, this is a minimal boilerplate project concentrating only on [nestia](https://github.com/samchon/nestia) SDK generation. \r\n\r\nIf you wanna much detailed boilerplate project, visit [`@samchon/backend`](https://github.com/samchon/backend).\r\n\r\n\r\n\r\n\r\n## Directories and Files\r\nThis template project has categorized directories like below.\r\n\r\nAs you can see from the below, all of the Backend source files are placed into the [src](src/) directory. When you build the TypeScript source files, compiled files would be placed into the `lib` directory following the [tsconfig.json](tsconfig.json) configuration. Otherwise you build client [SDK](#32-sdk) library for npm publishing and their compiled files would be placed into the [packages](packages) directory.\r\n\r\n - [packages/api/](packages/api): SDK module built by `npm run build:api`\r\n - [src/](src): Backend source directory\r\n - [src/api/](src/api/): Client SDK that would be published to the `@ORGANIZATION/PROJECT-api`\r\n - [**src/api/functional/**](src/api/functional/): API functions generated by the [`nestia`](https://github.com/samchon/nestia)\r\n - [**src/api/structures/**](src/api/structures/): DTO structures\r\n - [src/controllers/](src/controllers/): Controller classes of the Main Program\r\n - [**test/**](test): Test Automation Program\r\n - [nestia.config.ts](nestia.config.ts): Configuration file of [`nestia`](https://github.com/samchon/nestia)\r\n - [package.json](package.json): NPM configuration\r\n - [tsconfig.json](tsconfig.json): TypeScript configuration for the main program\r\n - [tsconfig.api.json](tsconfig.api.json): TypeScript configuration for the SDK generation\r\n\r\n\r\n\r\n\r\n## NPM Run Commands\r\nList of the run commands defined in the [package.json](package.json) are like below:\r\n\r\n - `build`: Build everything\r\n - `build:api`: Build client SDK libray for the client developers\r\n - `build:main`: Build main program (`src` directory)\r\n - `build:sdk`: Build SDK into main program only\r\n - `build:swagger`: Build Swagger Documents\r\n - `build:test` Build test automation program (`test` directory)\r\n - `dev`: Incremental build for development (test program)\r\n - `eslint` & `eslint:fix` & `prettier`: Prettier and ESLint execution\r\n - `start`: Start local NestJS server\r\n - `test`: Run test automation program\r\n\r\n\r\n\r\n\r\n## Specialization\r\nTransform this template project to be yours.\r\n\r\nWhen you've created a new backend project through this template project, you can specialize it to be suitable for you by changing some words. Replace below words through IDE specific function like `Edit > Replace in Files` (*Ctrl + Shift + H*), who've been supported by the VSCode.\r\n\r\n| Before | After\r\n|-----------------|----------------------------------------\r\n| ORGANIZATION | Your account or corporation name\r\n| PROJECT | Your own project name\r\n| AUTHOR | Author name\r\n| https://github.com/samchon/nestia-start | Your repository URL\r\n\r\n\r\n\r\n\r\n## Test Driven Development\r\nWith [nestia](https://github.com/samchon/nestia) helps to accomplish TDD (Test Driven Development). \r\n\r\nJust define DTOs and API controllers' methods (only declarations) first. After the definitions, and build SDK (Software Development Kit) through [nestia](https://github.com/samchon/nestia) (`npm run build:sdk`). After buildling those SDK, develop test automation program using the SDK, following use-case scenarios in the framework of client side.\r\n\r\nDuring the test automation program development, you can find that which API is mis-designed or which requirement analysis is not exact. Development of the main program must be the last step after such validation process during TDD.\r\n\r\n> Visit the [samchon/backend](https://github.com/samchon/backend), then you may find much detailed story about this TDD.\r\n>\r\n> 1. Definitions\r\n> 2. SDK\r\n> 3. Test Automation Program\r\n> 4. Main Program\r\n\r\n```typescript\r\nimport typia from \"typia\";\r\n\r\nimport api from \"@ORGANIZATION/PROJECT-api/lib/index\";\r\nimport { IBbsArticle } from \"@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle\";\r\n\r\nimport { ArrayUtil } from \"../../../../utils/ArrayUtil\";\r\nimport { GaffComparator } from \"../../../internal/GaffComparator\";\r\nimport { RandomGenerator } from \"../../../internal/RandomGenerator\";\r\nimport { validate_index_sort } from \"../../../internal/validate_index_sort\";\r\n\r\nexport async function test_api_bbs_article_index_sort(\r\n connection: api.IConnection,\r\n): Promise<void> {\r\n // GENERATE 100 ARTICLES\r\n const section: string = \"general\";\r\n const articles: IBbsArticle[] = await ArrayUtil.asyncRepeat(100, () =>\r\n api.functional.bbs.articles.store(connection, section, {\r\n writer: RandomGenerator.name(),\r\n title: RandomGenerator.paragraph(),\r\n body: RandomGenerator.content(),\r\n format: \"txt\",\r\n files: [],\r\n password: RandomGenerator.alphabets(8),\r\n }),\r\n );\r\n typia.assertEquals(articles);\r\n\r\n // PREPARE VALIDATOR\r\n const validator = validate_index_sort(\"BbsArticleProvider.index()\")(\r\n (input: IBbsArticle.IRequest) =>\r\n api.functional.bbs.articles.index(connection, section, input),\r\n );\r\n\r\n // DO VALIDATE\r\n const components = [\r\n validator(\"created_at\")(GaffComparator.dates((x) => x.created_at)),\r\n validator(\"updated_at\")(GaffComparator.dates((x) => x.updated_at)),\r\n validator(\"title\")(GaffComparator.strings((x) => x.title)),\r\n validator(\"writer\")(GaffComparator.strings((x) => x.writer)),\r\n validator(\r\n \"writer\",\r\n \"title\",\r\n )(GaffComparator.strings((x) => [x.writer, x.title])),\r\n ];\r\n for (const comp of components) {\r\n await comp(\"+\");\r\n await comp(\"-\");\r\n }\r\n}\r\n```"
90
+ "content": "# Nestia Template\r\n## Outline\r\n[![Build Status](https://github.com/samchon/nestia-start/workflows/build/badge.svg)](https://github.com/samchon/nestia-start/actions?query=workflow%3Abuild)\r\n\r\nA template repository for backend projects using [nestia](https://github.com/samchon/nestia).\r\n\r\nYou can create a new project from this boilerplate by running below command:\r\n\r\n```bash\r\nnpx nestia start <directory>\r\n```\r\n\r\nFor reference, this is a minimal boilerplate project concentrating only on [nestia](https://github.com/samchon/nestia) SDK generation. \r\n\r\nIf you wanna much detailed boilerplate project, visit [`@samchon/backend`](https://github.com/samchon/backend).\r\n\r\n\r\n\r\n\r\n## Directories and Files\r\nThis template project has categorized directories like below.\r\n\r\nAs you can see from the below, all of the Backend source files are placed into the [src](src/) directory. When you build the TypeScript source files, compiled files would be placed into the `lib` directory following the [tsconfig.json](tsconfig.json) configuration. Otherwise you build client [SDK](#32-sdk) library for npm publishing and their compiled files would be placed into the [packages](packages) directory.\r\n\r\n - [packages/api/](packages/api): SDK module built by `npm run build:api`\r\n - [src/](src): Backend source directory\r\n - [src/api/](src/api/): Client SDK that would be published to the `@ORGANIZATION/PROJECT-api`\r\n - [**src/api/functional/**](src/api/functional/): API functions generated by the [`nestia`](https://github.com/samchon/nestia)\r\n - [**src/api/structures/**](src/api/structures/): DTO structures\r\n - [src/controllers/](src/controllers/): Controller classes of the Main Program\r\n - [**test/**](test): Test Automation Program\r\n - [nestia.config.ts](nestia.config.ts): Configuration file of [`nestia`](https://github.com/samchon/nestia)\r\n - [package.json](package.json): NPM configuration\r\n - [tsconfig.json](tsconfig.json): TypeScript configuration for the main program\r\n - [tsconfig.api.json](tsconfig.api.json): TypeScript configuration for the SDK generation\r\n\r\n\r\n\r\n\r\n## NPM Run Commands\r\nList of the run commands defined in the [package.json](package.json) are like below:\r\n\r\n - `build`: Build everything\r\n - `build:api`: Build client SDK libray for the client developers\r\n - `build:main`: Build main program (`src` directory)\r\n - `build:sdk`: Build SDK into main program only\r\n - `build:swagger`: Build Swagger Documents\r\n - `build:test` Build test automation program (`test` directory)\r\n - `dev`: Incremental build for development (test program)\r\n - `eslint` & `eslint:fix` & `prettier`: Prettier and ESLint execution\r\n - `start`: Start local NestJS server\r\n - `test`: Run test automation program\r\n - `benchmark`: Run performance benchmark program\r\n\r\n\r\n\r\n\r\n## Specialization\r\nTransform this template project to be yours.\r\n\r\nWhen you've created a new backend project through this template project, you can specialize it to be suitable for you by changing some words. Replace below words through IDE specific function like `Edit > Replace in Files` (*Ctrl + Shift + H*), who've been supported by the VSCode.\r\n\r\n| Before | After\r\n|-----------------|----------------------------------------\r\n| ORGANIZATION | Your account or corporation name\r\n| PROJECT | Your own project name\r\n| AUTHOR | Author name\r\n| https://github.com/samchon/nestia-start | Your repository URL\r\n\r\n\r\n\r\n\r\n## Test Driven Development\r\nWith [nestia](https://github.com/samchon/nestia) helps to accomplish TDD (Test Driven Development). \r\n\r\nJust define DTOs and API controllers' methods (only declarations) first. After the definitions, and build SDK (Software Development Kit) through [nestia](https://github.com/samchon/nestia) (`npm run build:sdk`). After buildling those SDK, develop test automation program using the SDK, following use-case scenarios in the framework of client side.\r\n\r\nDuring the test automation program development, you can find that which API is mis-designed or which requirement analysis is not exact. Development of the main program must be the last step after such validation process during TDD.\r\n\r\n> Visit the [samchon/backend](https://github.com/samchon/backend), then you may find much detailed story about this TDD.\r\n>\r\n> 1. Definitions\r\n> 2. SDK\r\n> 3. Test Automation Program\r\n> 4. Main Program\r\n\r\n```typescript\r\nimport {\r\n ArrayUtil,\r\n GaffComparator,\r\n RandomGenerator,\r\n TestValidator,\r\n} from \"@nestia/e2e\";\r\n\r\nimport api from \"@ORGANIZATION/PROJECT-api/lib/index\";\r\nimport { IBbsArticle } from \"@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle\";\r\nimport { IPage } from \"@ORGANIZATION/PROJECT-api/lib/structures/common/IPage\";\r\n\r\nexport async function test_api_bbs_article_index_sort(\r\n connection: api.IConnection,\r\n): Promise<void> {\r\n // GENERATE 100 ARTICLES\r\n const section: string = \"general\";\r\n await ArrayUtil.asyncRepeat(100)(() =>\r\n api.functional.bbs.articles.create(connection, section, {\r\n writer: RandomGenerator.name(),\r\n title: RandomGenerator.paragraph(5)(),\r\n body: RandomGenerator.content(8)()(),\r\n format: \"txt\",\r\n files: [],\r\n password: RandomGenerator.alphabets(8),\r\n }),\r\n );\r\n\r\n // PREPARE VALIDATOR\r\n const validator = TestValidator.sort(\"BbsArticleProvider.index()\")(async (\r\n sort: IPage.Sort<IBbsArticle.IRequest.SortableColumns>,\r\n ) => {\r\n const page: IPage<IBbsArticle.ISummary> =\r\n await api.functional.bbs.articles.index(connection, section, {\r\n limit: 100,\r\n sort,\r\n });\r\n return page.data;\r\n });\r\n\r\n // DO VALIDATE\r\n const components = [\r\n validator(\"created_at\")(GaffComparator.dates((x) => x.created_at)),\r\n validator(\"updated_at\")(GaffComparator.dates((x) => x.updated_at)),\r\n validator(\"title\")(GaffComparator.strings((x) => x.title)),\r\n validator(\"writer\")(GaffComparator.strings((x) => x.writer)),\r\n validator(\r\n \"writer\",\r\n \"title\",\r\n )(GaffComparator.strings((x) => [x.writer, x.title])),\r\n ];\r\n for (const comp of components) {\r\n await comp(\"+\", false);\r\n await comp(\"-\", false);\r\n }\r\n}\r\n```\r\n\r\nFor reference, if you run `npm run benchmark` command, your test functions defined in the [test/features/api](test/features/api) directory would be utilized for performance benchmarking. If you want to see the performance bench result earlier, visit below link please:\r\n\r\n - [docs/benchmarks/AMD Ryzen 9 7940HS w Radeon 780M Graphics.md](https://github.com/samchon/nestia-start/blob/master/docs/benchmarks/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics.md)"
86
91
  },
87
92
  {
88
93
  "location": "src/api",
@@ -159,15 +164,25 @@ export const NEST_TEMPLATE = [
159
164
  "file": "MapUtil.ts",
160
165
  "content": "export namespace MapUtil {\r\n export function take<Key, T>(\r\n dict: Map<Key, T>,\r\n key: Key,\r\n generator: () => T,\r\n ): T {\r\n const oldbie: T | undefined = dict.get(key);\r\n if (oldbie) return oldbie;\r\n\r\n const value: T = generator();\r\n dict.set(key, value);\r\n return value;\r\n }\r\n}\r\n"
161
166
  },
167
+ {
168
+ "location": "test/benchmark",
169
+ "file": "index.ts",
170
+ "content": "import { DynamicBenchmarker } from \"@nestia/e2e\";\r\nimport cliProgress from \"cli-progress\";\r\nimport fs from \"fs\";\r\nimport os from \"os\";\r\nimport { IPointer } from \"tstl\";\r\n\r\nimport { MyBackend } from \"../../src/MyBackend\";\r\nimport { MyConfiguration } from \"../../src/MyConfiguration\";\r\nimport { MyGlobal } from \"../../src/MyGlobal\";\r\nimport { ArgumentParser } from \"../helpers/ArgumentParser\";\r\n\r\ninterface IOptions {\r\n include?: string[];\r\n exclude?: string[];\r\n count: number;\r\n threads: number;\r\n simultaneous: number;\r\n}\r\n\r\nconst getOptions = () =>\r\n ArgumentParser.parse<IOptions>(async (command, prompt, action) => {\r\n // command.option(\"--mode <string>\", \"target mode\");\r\n // command.option(\"--reset <true|false>\", \"reset local DB or not\");\r\n command.option(\"--include <string...>\", \"include feature files\");\r\n command.option(\"--exclude <string...>\", \"exclude feature files\");\r\n command.option(\"--count <number>\", \"number of requests to make\");\r\n command.option(\"--threads <number>\", \"number of threads to use\");\r\n command.option(\r\n \"--simultaneous <number>\",\r\n \"number of simultaneous requests to make\",\r\n );\r\n return action(async (options) => {\r\n // if (typeof options.reset === \"string\")\r\n // options.reset = options.reset === \"true\";\r\n // options.mode ??= await prompt.select(\"mode\")(\"Select mode\")([\r\n // \"LOCAL\",\r\n // \"DEV\",\r\n // \"REAL\",\r\n // ]);\r\n // options.reset ??= await prompt.boolean(\"reset\")(\"Reset local DB\");\r\n options.count = Number(\r\n options.count ??\r\n (await prompt.number(\"count\")(\"Number of requests to make\")),\r\n );\r\n options.threads = Number(\r\n options.threads ??\r\n (await prompt.number(\"threads\")(\"Number of threads to use\")),\r\n );\r\n options.simultaneous = Number(\r\n options.simultaneous ??\r\n (await prompt.number(\"simultaneous\")(\r\n \"Number of simultaneous requests to make\",\r\n )),\r\n );\r\n return options as IOptions;\r\n });\r\n });\r\n\r\nconst main = async (): Promise<void> => {\r\n // CONFIGURATIONS\r\n const options: IOptions = await getOptions();\r\n MyGlobal.testing = true;\r\n\r\n // BACKEND SERVER\r\n const backend: MyBackend = new MyBackend();\r\n await backend.open();\r\n\r\n // DO BENCHMARK\r\n const prev: IPointer<number> = { value: 0 };\r\n const bar: cliProgress.SingleBar = new cliProgress.SingleBar(\r\n {},\r\n cliProgress.Presets.shades_classic,\r\n );\r\n bar.start(options.count, 0);\r\n\r\n const report: DynamicBenchmarker.IReport = await DynamicBenchmarker.master({\r\n servant: `${__dirname}/servant.js`,\r\n count: options.count,\r\n threads: options.threads,\r\n simultaneous: options.simultaneous,\r\n filter: (func) =>\r\n (!options.include?.length ||\r\n (options.include ?? []).some((str) => func.includes(str))) &&\r\n (!options.exclude?.length ||\r\n (options.exclude ?? []).every((str) => !func.includes(str))),\r\n progress: (value: number) => {\r\n if (value >= 100 + prev.value) {\r\n bar.update(value);\r\n prev.value = value;\r\n }\r\n },\r\n stdio: \"ignore\",\r\n });\r\n bar.stop();\r\n\r\n // DOCUMENTATION\r\n try {\r\n await fs.promises.mkdir(`${MyConfiguration.ROOT}/docs/benchmarks`, {\r\n recursive: true,\r\n });\r\n } catch {}\r\n await fs.promises.writeFile(\r\n `${MyConfiguration.ROOT}/docs/benchmarks/${os\r\n .cpus()[0]\r\n .model.trim()\r\n .split(\"\\\\\")\r\n .join(\"\")\r\n .split(\"/\")\r\n .join(\"\")}.md`,\r\n DynamicBenchmarker.markdown(report),\r\n \"utf8\",\r\n );\r\n\r\n // CLOSE\r\n await backend.close();\r\n};\r\nmain().catch((exp) => {\r\n console.error(exp);\r\n process.exit(-1);\r\n});\r\n"
171
+ },
172
+ {
173
+ "location": "test/benchmark",
174
+ "file": "servant.ts",
175
+ "content": "import { DynamicBenchmarker } from \"@nestia/e2e\";\r\n\r\nimport { MyConfiguration } from \"../../src/MyConfiguration\";\r\n\r\nDynamicBenchmarker.servant({\r\n connection: {\r\n host: `http://127.0.0.1:${MyConfiguration.API_PORT()}`,\r\n },\r\n location: `${__dirname}/../features`,\r\n parameters: (connection) => [connection],\r\n prefix: \"test_api_\",\r\n}).catch((exp) => {\r\n console.error(exp);\r\n process.exit(-1);\r\n});\r\n"
176
+ },
162
177
  {
163
178
  "location": "test/helpers",
164
179
  "file": "ArgumentParser.ts",
165
- "content": "import commander from \"commander\";\r\nimport * as inquirer from \"inquirer\";\r\n\r\nexport namespace ArgumentParser {\r\n export type Inquiry<T> = (\r\n command: commander.Command,\r\n prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,\r\n action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,\r\n ) => Promise<T>;\r\n\r\n export interface Prompt {\r\n select: (\r\n name: string,\r\n ) => (\r\n message: string,\r\n ) => <Choice extends string>(choices: Choice[]) => Promise<Choice>;\r\n boolean: (name: string) => (message: string) => Promise<boolean>;\r\n }\r\n\r\n export const parse = async <T>(\r\n inquiry: (\r\n command: commander.Command,\r\n prompt: Prompt,\r\n action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,\r\n ) => Promise<T>,\r\n ): Promise<T> => {\r\n // TAKE OPTIONS\r\n const action = (closure: (options: Partial<T>) => Promise<T>) =>\r\n new Promise<T>((resolve, reject) => {\r\n commander.program.action(async (options) => {\r\n try {\r\n resolve(await closure(options));\r\n } catch (exp) {\r\n reject(exp);\r\n }\r\n });\r\n commander.program.parseAsync().catch(reject);\r\n });\r\n\r\n const select =\r\n (name: string) =>\r\n (message: string) =>\r\n async <Choice extends string>(choices: Choice[]): Promise<Choice> =>\r\n (\r\n await inquirer.createPromptModule()({\r\n type: \"list\",\r\n name,\r\n message,\r\n choices,\r\n })\r\n )[name];\r\n const boolean = (name: string) => async (message: string) =>\r\n (\r\n await inquirer.createPromptModule()({\r\n type: \"confirm\",\r\n name,\r\n message,\r\n })\r\n )[name] as boolean;\r\n\r\n const output: T | Error = await (async () => {\r\n try {\r\n return await inquiry(commander.program, { select, boolean }, action);\r\n } catch (error) {\r\n return error as Error;\r\n }\r\n })();\r\n\r\n // RETURNS\r\n if (output instanceof Error) throw output;\r\n return output;\r\n };\r\n}\r\n"
180
+ "content": "import commander from \"commander\";\r\nimport * as inquirer from \"inquirer\";\r\n\r\nexport namespace ArgumentParser {\r\n export type Inquiry<T> = (\r\n command: commander.Command,\r\n prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,\r\n action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,\r\n ) => Promise<T>;\r\n\r\n export interface Prompt {\r\n select: (\r\n name: string,\r\n ) => (\r\n message: string,\r\n ) => <Choice extends string>(choices: Choice[]) => Promise<Choice>;\r\n boolean: (name: string) => (message: string) => Promise<boolean>;\r\n number: (name: string) => (message: string) => Promise<number>;\r\n }\r\n\r\n export const parse = async <T>(\r\n inquiry: (\r\n command: commander.Command,\r\n prompt: Prompt,\r\n action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,\r\n ) => Promise<T>,\r\n ): Promise<T> => {\r\n // TAKE OPTIONS\r\n const action = (closure: (options: Partial<T>) => Promise<T>) =>\r\n new Promise<T>((resolve, reject) => {\r\n commander.program.action(async (options) => {\r\n try {\r\n resolve(await closure(options));\r\n } catch (exp) {\r\n reject(exp);\r\n }\r\n });\r\n commander.program.parseAsync().catch(reject);\r\n });\r\n\r\n const select =\r\n (name: string) =>\r\n (message: string) =>\r\n async <Choice extends string>(choices: Choice[]): Promise<Choice> =>\r\n (\r\n await inquirer.createPromptModule()({\r\n type: \"list\",\r\n name,\r\n message,\r\n choices,\r\n })\r\n )[name];\r\n const boolean = (name: string) => async (message: string) =>\r\n (\r\n await inquirer.createPromptModule()({\r\n type: \"confirm\",\r\n name,\r\n message,\r\n })\r\n )[name] as boolean;\r\n const number = (name: string) => async (message: string) =>\r\n Number(\r\n (\r\n await inquirer.createPromptModule()({\r\n type: \"number\",\r\n name,\r\n message,\r\n })\r\n )[name],\r\n );\r\n\r\n const output: T | Error = await (async () => {\r\n try {\r\n return await inquiry(\r\n commander.program,\r\n { select, boolean, number },\r\n action,\r\n );\r\n } catch (error) {\r\n return error as Error;\r\n }\r\n })();\r\n\r\n // RETURNS\r\n if (output instanceof Error) throw output;\r\n return output;\r\n };\r\n}\r\n"
166
181
  },
167
182
  {
168
183
  "location": "test",
169
184
  "file": "index.ts",
170
- "content": "import { DynamicExecutor } from \"@nestia/e2e\";\r\n\r\nimport api from \"@ORGANIZATION/PROJECT-api\";\r\n\r\nimport { MyBackend } from \"../src/MyBackend\";\r\nimport { MyConfiguration } from \"../src/MyConfiguration\";\r\nimport { MyGlobal } from \"../src/MyGlobal\";\r\nimport { ArgumentParser } from \"./helpers/ArgumentParser\";\r\n\r\ninterface IOptions {\r\n include?: string[];\r\n exclude?: string[];\r\n}\r\n\r\nconst getOptions = () =>\r\n ArgumentParser.parse<IOptions>(async (command, prompt, action) => {\r\n // command.option(\"--mode <string>\", \"target mode\");\r\n // command.option(\"--reset <true|false>\", \"reset local DB or not\");\r\n command.option(\"--include <string...>\", \"include feature files\");\r\n command.option(\"--exclude <string...>\", \"exclude feature files\");\r\n\r\n prompt;\r\n\r\n return action(async (options) => {\r\n // if (typeof options.reset === \"string\")\r\n // options.reset = options.reset === \"true\";\r\n // options.mode ??= await prompt.select(\"mode\")(\"Select mode\")([\r\n // \"LOCAL\",\r\n // \"DEV\",\r\n // \"REAL\",\r\n // ]);\r\n // options.reset ??= await prompt.boolean(\"reset\")(\"Reset local DB\");\r\n return options as IOptions;\r\n });\r\n });\r\n\r\nasync function main(): Promise<void> {\r\n const options: IOptions = await getOptions();\r\n MyGlobal.testing = true;\r\n\r\n // BACKEND SERVER\r\n const backend: MyBackend = new MyBackend();\r\n await backend.open();\r\n\r\n //----\r\n // CLINET CONNECTOR\r\n //----\r\n // DO TEST\r\n const connection: api.IConnection = {\r\n host: `http://127.0.0.1:${MyConfiguration.API_PORT()}`,\r\n };\r\n const report: DynamicExecutor.IReport = await DynamicExecutor.validate({\r\n prefix: \"test\",\r\n parameters: () => [\r\n {\r\n host: connection.host,\r\n encryption: connection.encryption,\r\n },\r\n ],\r\n filter: (func) =>\r\n (!options.include?.length ||\r\n (options.include ?? []).some((str) => func.includes(str))) &&\r\n (!options.exclude?.length ||\r\n (options.exclude ?? []).every((str) => !func.includes(str))),\r\n })(__dirname + \"/features\");\r\n\r\n await backend.close();\r\n\r\n const failures: DynamicExecutor.IReport.IExecution[] =\r\n report.executions.filter((exec) => exec.error !== null);\r\n if (failures.length === 0) {\r\n console.log(\"Success\");\r\n console.log(\"Elapsed time\", report.time.toLocaleString(), `ms`);\r\n } else {\r\n for (const f of failures) console.log(f.error);\r\n process.exit(-1);\r\n }\r\n\r\n console.log(\r\n [\r\n `All: #${report.executions.length}`,\r\n `Success: #${report.executions.length - failures.length}`,\r\n `Failed: #${failures.length}`,\r\n ].join(\"\\n\"),\r\n );\r\n}\r\nmain().catch((exp) => {\r\n console.log(exp);\r\n process.exit(-1);\r\n});\r\n"
185
+ "content": "import { DynamicExecutor } from \"@nestia/e2e\";\r\n\r\nimport api from \"@ORGANIZATION/PROJECT-api\";\r\n\r\nimport { MyBackend } from \"../src/MyBackend\";\r\nimport { MyConfiguration } from \"../src/MyConfiguration\";\r\nimport { MyGlobal } from \"../src/MyGlobal\";\r\nimport { ArgumentParser } from \"./helpers/ArgumentParser\";\r\n\r\ninterface IOptions {\r\n include?: string[];\r\n exclude?: string[];\r\n}\r\n\r\nconst getOptions = () =>\r\n ArgumentParser.parse<IOptions>(async (command, _prompt, action) => {\r\n // command.option(\"--mode <string>\", \"target mode\");\r\n // command.option(\"--reset <true|false>\", \"reset local DB or not\");\r\n command.option(\"--include <string...>\", \"include feature files\");\r\n command.option(\"--exclude <string...>\", \"exclude feature files\");\r\n\r\n return action(async (options) => {\r\n // if (typeof options.reset === \"string\")\r\n // options.reset = options.reset === \"true\";\r\n // options.mode ??= await prompt.select(\"mode\")(\"Select mode\")([\r\n // \"LOCAL\",\r\n // \"DEV\",\r\n // \"REAL\",\r\n // ]);\r\n // options.reset ??= await prompt.boolean(\"reset\")(\"Reset local DB\");\r\n return options as IOptions;\r\n });\r\n });\r\n\r\nasync function main(): Promise<void> {\r\n // CONFIGURATIONS\r\n const options: IOptions = await getOptions();\r\n MyGlobal.testing = true;\r\n\r\n // BACKEND SERVER\r\n const backend: MyBackend = new MyBackend();\r\n await backend.open();\r\n\r\n //----\r\n // CLINET CONNECTOR\r\n //----\r\n // DO TEST\r\n const connection: api.IConnection = {\r\n host: `http://127.0.0.1:${MyConfiguration.API_PORT()}`,\r\n };\r\n const report: DynamicExecutor.IReport = await DynamicExecutor.validate({\r\n prefix: \"test\",\r\n parameters: () => [\r\n {\r\n host: connection.host,\r\n encryption: connection.encryption,\r\n },\r\n ],\r\n filter: (func) =>\r\n (!options.include?.length ||\r\n (options.include ?? []).some((str) => func.includes(str))) &&\r\n (!options.exclude?.length ||\r\n (options.exclude ?? []).every((str) => !func.includes(str))),\r\n })(__dirname + \"/features\");\r\n\r\n await backend.close();\r\n\r\n const failures: DynamicExecutor.IReport.IExecution[] =\r\n report.executions.filter((exec) => exec.error !== null);\r\n if (failures.length === 0) {\r\n console.log(\"Success\");\r\n console.log(\"Elapsed time\", report.time.toLocaleString(), `ms`);\r\n } else {\r\n for (const f of failures) console.log(f.error);\r\n process.exit(-1);\r\n }\r\n\r\n console.log(\r\n [\r\n `All: #${report.executions.length}`,\r\n `Success: #${report.executions.length - failures.length}`,\r\n `Failed: #${failures.length}`,\r\n ].join(\"\\n\"),\r\n );\r\n}\r\nmain().catch((exp) => {\r\n console.log(exp);\r\n process.exit(-1);\r\n});\r\n"
171
186
  },
172
187
  {
173
188
  "location": "test",
@@ -27,7 +27,7 @@ export const SDK_TEMPLATE = [
27
27
  {
28
28
  "location": "",
29
29
  "file": "package.json",
30
- "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"exports\": {\r\n \".\": {\r\n \"types\": \"./lib/index.d.ts\",\r\n \"require\": \"./lib/index.js\",\r\n \"import\": \"./lib/index.mjs\"\r\n }\r\n },\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc && rollup -c\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"hello\": \"node hello\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"ts-node test/start.ts\",\r\n \"swagger\": \"ts-node test/swagger.ts\",\r\n \"test\": \"ts-node test/index.ts\",\r\n \"test:simulate\": \"ts-node test/index.ts --simulate true\",\r\n \"test:manual\": \"ts-node test/manual.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.2.1\",\r\n \"typia\": \"^6.1.0\"\r\n },\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.3\",\r\n \"@rollup/plugin-terser\": \"^0.4.4\",\r\n \"@rollup/plugin-typescript\": \"^11.1.6\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"8.2.5\",\r\n \"@types/swagger-ui-express\": \"^4.1.6\",\r\n \"commander\": \"^10.0.0\",\r\n \"express\": \"^4.19.2\",\r\n \"inquirer\": \"8.2.5\",\r\n \"prettier\": \"^3.2.5\",\r\n \"rimraf\": \"^5.0.5\",\r\n \"rollup\": \"^4.13.2\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\",\r\n \"typescript-transform-paths\": \"^3.4.6\"\r\n }\r\n}"
30
+ "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"exports\": {\r\n \".\": {\r\n \"types\": \"./lib/index.d.ts\",\r\n \"require\": \"./lib/index.js\",\r\n \"import\": \"./lib/index.mjs\"\r\n }\r\n },\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc && rollup -c\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"hello\": \"node hello\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"ts-node test/start.ts\",\r\n \"swagger\": \"ts-node test/swagger.ts\",\r\n \"test\": \"ts-node test/index.ts\",\r\n \"test:simulate\": \"ts-node test/index.ts --simulate true\",\r\n \"test:manual\": \"ts-node test/manual.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.3.2\",\r\n \"tgrid\": \"^1.0.2\",\r\n \"typia\": \"^6.3.1\"\r\n },\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.6.0\",\r\n \"@rollup/plugin-terser\": \"^0.4.4\",\r\n \"@rollup/plugin-typescript\": \"^11.1.6\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"8.2.5\",\r\n \"@types/swagger-ui-express\": \"^4.1.6\",\r\n \"commander\": \"^10.0.0\",\r\n \"express\": \"^4.19.2\",\r\n \"inquirer\": \"8.2.5\",\r\n \"prettier\": \"^3.2.5\",\r\n \"rimraf\": \"^5.0.5\",\r\n \"rollup\": \"^4.13.2\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.2.1\",\r\n \"typescript\": \"^5.5.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\"\r\n }\r\n}"
31
31
  },
32
32
  {
33
33
  "location": "",
@@ -50,13 +50,19 @@ export namespace MigrateCommander {
50
50
  }
51
51
 
52
52
  const app: MigrateApplication = result.data;
53
- const { files } =
53
+ const program =
54
54
  options.mode === "nest" ? app.nest(options) : app.sdk(options);
55
+ if (program.errors)
56
+ for (const error of program.errors)
57
+ console.error(
58
+ `Failed to migrate ${error.method} ${error.path}`,
59
+ ...error.messages.map((msg) => ` - ${msg}`),
60
+ );
55
61
  await MigrateFileArchiver.archive({
56
62
  mkdir: fs.promises.mkdir,
57
63
  writeFile: async (file, content) =>
58
64
  fs.promises.writeFile(file, await beautify(content), "utf-8"),
59
- })(options.output)(files);
65
+ })(options.output)(program.files);
60
66
  };
61
67
 
62
68
  const beautify = async (script: string): Promise<string> => {
@@ -1,9 +1,7 @@
1
- import { OpenApi } from "@samchon/openapi";
1
+ import { IMigrateRoute, OpenApi } from "@samchon/openapi";
2
2
  import ts from "typescript";
3
3
 
4
- import { IMigrateController } from "../structures/IMigrateController";
5
4
  import { IMigrateProgram } from "../structures/IMigrateProgram";
6
- import { IMigrateRoute } from "../structures/IMigrateRoute";
7
5
  import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
8
6
  import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
9
7
  import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
@@ -11,24 +9,22 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
11
9
  export namespace MigrateApiFileProgrammer {
12
10
  export interface IProps {
13
11
  namespace: string[];
14
- entries: IEntry[];
12
+ routes: IMigrateRoute[];
15
13
  children: Set<string>;
16
14
  }
17
- export interface IEntry {
18
- controller: IMigrateController;
19
- route: IMigrateRoute;
20
- alias: string;
21
- }
22
-
23
15
  export const write =
24
16
  (config: IMigrateProgram.IConfig) =>
25
17
  (components: OpenApi.IComponents) =>
26
18
  (props: IProps): ts.Statement[] => {
27
19
  const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
28
- const statements: ts.Statement[] = props.entries
29
- .map((p) => [
30
- MigrateApiFunctionProgrammer.write(config)(components)(importer)(p),
31
- MigrateApiNamespaceProgrammer.write(config)(components)(importer)(p),
20
+ const statements: ts.Statement[] = props.routes
21
+ .map((route) => [
22
+ MigrateApiFunctionProgrammer.write(config)(components)(importer)(
23
+ route,
24
+ ),
25
+ MigrateApiNamespaceProgrammer.write(config)(components)(importer)(
26
+ route,
27
+ ),
32
28
  ])
33
29
  .flat();
34
30
  return [