@nestia/migrate 0.13.17 → 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.
- package/lib/MigrateApplication.d.ts +1 -0
- package/lib/MigrateApplication.js +823 -873
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.js +5 -2
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateControllerAnalyzer.js +14 -88
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +3 -3
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/executable/bundle.js +1 -1
- package/lib/internal/MigrateCommander.js +5 -2
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -9
- package/lib/programmers/MigrateApiFileProgrammer.js +4 -4
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -30
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiNamespaceProgrammer.js +31 -37
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +19 -70
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiSimulatationProgrammer.js +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js +1 -3
- package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.js +4 -4
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestProgrammer.js +27 -23
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.js +22 -22
- package/lib/structures/IMigrateProgram.d.ts +8 -8
- package/lib/structures/IMigrateRoute.d.ts +1 -46
- package/lib/utils/OpenApiTypeChecker.d.ts +1 -1
- package/lib/utils/StringUtil.d.ts +0 -4
- package/lib/utils/StringUtil.js +0 -31
- package/lib/utils/StringUtil.js.map +1 -1
- package/lib/utils/openapi-down-convert/RefVisitor.js +4 -5
- package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
- package/package.json +8 -8
- package/src/MigrateApplication.ts +3 -2
- package/src/analyzers/MigrateAnalyzer.ts +10 -5
- package/src/analyzers/MigrateControllerAnalyzer.ts +17 -122
- package/src/bundles/NEST_TEMPLATE.ts +3 -3
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/internal/MigrateCommander.ts +8 -2
- package/src/programmers/MigrateApiFileProgrammer.ts +10 -14
- package/src/programmers/MigrateApiFunctionProgrammer.ts +43 -41
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +33 -51
- package/src/programmers/MigrateApiProgrammer.ts +26 -95
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +17 -25
- package/src/programmers/MigrateApiStartProgrammer.ts +1 -1
- package/src/programmers/MigrateE2eProgrammer.ts +1 -3
- package/src/programmers/MigrateNestMethodProgrammer.ts +4 -4
- package/src/programmers/MigrateNestProgrammer.ts +10 -4
- package/src/structures/IMigrateProgram.ts +8 -8
- package/src/structures/IMigrateRoute.ts +1 -51
- package/src/utils/StringUtil.ts +0 -42
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +0 -9
- package/lib/analyzers/MigrateMethodAnalyzer.js +0 -304
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +0 -1
- package/src/analyzers/MigrateMethodAnalyzer.ts +0 -387
@@ -1,86 +1,32 @@
|
|
1
|
-
import {
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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(([
|
63
|
-
const
|
64
|
-
routes.map((
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
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 -
|
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": "",
|
@@ -52,7 +52,7 @@ export const NEST_TEMPLATE = [
|
|
52
52
|
{
|
53
53
|
"location": "",
|
54
54
|
"file": "package.json",
|
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.2
|
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}"
|
56
56
|
},
|
57
57
|
{
|
58
58
|
"location": "packages/api",
|
@@ -67,7 +67,7 @@ export const NEST_TEMPLATE = [
|
|
67
67
|
{
|
68
68
|
"location": "packages/api",
|
69
69
|
"file": "package.json",
|
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.2
|
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}"
|
71
71
|
},
|
72
72
|
{
|
73
73
|
"location": "packages/api",
|
@@ -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
|
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
|
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
|
-
|
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.
|
29
|
-
.map((
|
30
|
-
MigrateApiFunctionProgrammer.write(config)(components)(importer)(
|
31
|
-
|
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 [
|
@@ -2,7 +2,6 @@ import { OpenApi } from "@samchon/openapi";
|
|
2
2
|
import ts from "typescript";
|
3
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
4
|
|
5
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
6
5
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
7
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
7
|
import { FilePrinter } from "../utils/FilePrinter";
|
@@ -10,17 +9,11 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
10
9
|
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
11
10
|
|
12
11
|
export namespace MigrateApiFunctionProgrammer {
|
13
|
-
export interface IProps {
|
14
|
-
controller: IMigrateController;
|
15
|
-
route: IMigrateRoute;
|
16
|
-
alias: string;
|
17
|
-
}
|
18
|
-
|
19
12
|
export const write =
|
20
13
|
(config: IMigrateProgram.IConfig) =>
|
21
14
|
(components: OpenApi.IComponents) =>
|
22
15
|
(importer: MigrateImportProgrammer) =>
|
23
|
-
(
|
16
|
+
(route: IMigrateRoute): ts.FunctionDeclaration =>
|
24
17
|
FilePrinter.description(
|
25
18
|
ts.factory.createFunctionDeclaration(
|
26
19
|
[
|
@@ -28,23 +21,25 @@ export namespace MigrateApiFunctionProgrammer {
|
|
28
21
|
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
29
22
|
],
|
30
23
|
undefined,
|
31
|
-
|
24
|
+
route.accessor.at(-1)!,
|
32
25
|
undefined,
|
33
|
-
writeParameterDeclarations(components)(importer)(
|
26
|
+
writeParameterDeclarations(components)(importer)(route),
|
34
27
|
ts.factory.createTypeReferenceNode("Promise", [
|
35
28
|
ts.factory.createTypeReferenceNode(
|
36
|
-
|
29
|
+
route.success === null
|
30
|
+
? "void"
|
31
|
+
: `${route.accessor.at(-1)!}.Output`,
|
37
32
|
),
|
38
33
|
]),
|
39
|
-
ts.factory.createBlock(writeBody(config)(importer)(
|
34
|
+
ts.factory.createBlock(writeBody(config)(importer)(route), true),
|
40
35
|
),
|
41
|
-
writeDescription(
|
36
|
+
writeDescription(route),
|
42
37
|
);
|
43
38
|
|
44
39
|
export const writeParameterDeclarations =
|
45
40
|
(components: OpenApi.IComponents) =>
|
46
41
|
(importer: MigrateImportProgrammer) =>
|
47
|
-
(
|
42
|
+
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
48
43
|
IdentifierFactory.parameter(
|
49
44
|
"connection",
|
50
45
|
ts.factory.createTypeReferenceNode(
|
@@ -53,49 +48,56 @@ export namespace MigrateApiFunctionProgrammer {
|
|
53
48
|
library: "@nestia/fetcher",
|
54
49
|
name: "IConnection",
|
55
50
|
}),
|
56
|
-
|
57
|
-
? [
|
51
|
+
route.headers
|
52
|
+
? [
|
53
|
+
ts.factory.createTypeReferenceNode(
|
54
|
+
`${route.accessor.at(-1)!}.Headers`,
|
55
|
+
),
|
56
|
+
]
|
58
57
|
: undefined,
|
59
58
|
),
|
60
59
|
),
|
61
|
-
...
|
60
|
+
...route.parameters.map((p) =>
|
62
61
|
IdentifierFactory.parameter(
|
63
62
|
p.key,
|
64
63
|
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
65
64
|
),
|
66
65
|
),
|
67
|
-
...(
|
66
|
+
...(route.query
|
68
67
|
? [
|
69
68
|
IdentifierFactory.parameter(
|
70
|
-
|
71
|
-
ts.factory.createTypeReferenceNode(
|
69
|
+
route.query.key,
|
70
|
+
ts.factory.createTypeReferenceNode(
|
71
|
+
`${route.accessor.at(-1)!}.Query`,
|
72
|
+
),
|
72
73
|
),
|
73
74
|
]
|
74
75
|
: []),
|
75
|
-
...(
|
76
|
+
...(route.body
|
76
77
|
? [
|
77
78
|
IdentifierFactory.parameter(
|
78
|
-
|
79
|
-
ts.factory.createTypeReferenceNode(
|
79
|
+
route.body.key,
|
80
|
+
ts.factory.createTypeReferenceNode(
|
81
|
+
`${route.accessor.at(-1)!}.Input`,
|
82
|
+
),
|
80
83
|
),
|
81
84
|
]
|
82
85
|
: []),
|
83
86
|
];
|
84
87
|
|
85
|
-
const writeDescription = (
|
88
|
+
const writeDescription = (route: IMigrateRoute): string =>
|
86
89
|
[
|
87
|
-
|
88
|
-
`@
|
89
|
-
`@path ${props.route.path}`,
|
90
|
+
route.comment(),
|
91
|
+
`@path ${route.emendedPath}`,
|
90
92
|
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
91
93
|
].join("\n");
|
92
94
|
|
93
95
|
const writeBody =
|
94
96
|
(config: IMigrateProgram.IConfig) =>
|
95
97
|
(importer: MigrateImportProgrammer) =>
|
96
|
-
(
|
97
|
-
const encrypted: boolean = !!
|
98
|
-
const contentType: string =
|
98
|
+
(route: IMigrateRoute): ts.Statement[] => {
|
99
|
+
const encrypted: boolean = !!route.success?.["x-nestia-encrypted"];
|
100
|
+
const contentType: string = route.body?.type ?? "application/json";
|
99
101
|
|
100
102
|
const caller = () =>
|
101
103
|
ts.factory.createCallExpression(
|
@@ -141,22 +143,22 @@ export namespace MigrateApiFunctionProgrammer {
|
|
141
143
|
[
|
142
144
|
ts.factory.createSpreadAssignment(
|
143
145
|
IdentifierFactory.access(
|
144
|
-
ts.factory.createIdentifier(
|
146
|
+
ts.factory.createIdentifier(route.accessor.at(-1)!),
|
145
147
|
)("METADATA"),
|
146
148
|
),
|
147
149
|
ts.factory.createPropertyAssignment(
|
148
150
|
"path",
|
149
151
|
ts.factory.createCallExpression(
|
150
152
|
IdentifierFactory.access(
|
151
|
-
ts.factory.createIdentifier(
|
153
|
+
ts.factory.createIdentifier(route.accessor.at(-1)!),
|
152
154
|
)("path"),
|
153
155
|
undefined,
|
154
156
|
[
|
155
|
-
...
|
157
|
+
...route.parameters.map((p) =>
|
156
158
|
ts.factory.createIdentifier(p.key),
|
157
159
|
),
|
158
|
-
...(
|
159
|
-
? [ts.factory.createIdentifier(
|
160
|
+
...(route.query
|
161
|
+
? [ts.factory.createIdentifier(route.query.key)]
|
160
162
|
: []),
|
161
163
|
],
|
162
164
|
),
|
@@ -168,8 +170,8 @@ export namespace MigrateApiFunctionProgrammer {
|
|
168
170
|
],
|
169
171
|
true,
|
170
172
|
),
|
171
|
-
...(
|
172
|
-
? [ts.factory.createIdentifier(
|
173
|
+
...(route.body
|
174
|
+
? [ts.factory.createIdentifier(route.body.key)]
|
173
175
|
: []),
|
174
176
|
],
|
175
177
|
);
|
@@ -181,13 +183,13 @@ export namespace MigrateApiFunctionProgrammer {
|
|
181
183
|
ts.factory.createIdentifier("!!connection.simulate"),
|
182
184
|
undefined,
|
183
185
|
ts.factory.createCallExpression(
|
184
|
-
ts.factory.createIdentifier(`${
|
186
|
+
ts.factory.createIdentifier(`${route.accessor.at(-1)!}.simulate`),
|
185
187
|
[],
|
186
188
|
[
|
187
189
|
"connection",
|
188
|
-
...
|
189
|
-
...(
|
190
|
-
...(
|
190
|
+
...route.parameters.map((p) => p.key),
|
191
|
+
...(route.query ? [route.query.key] : []),
|
192
|
+
...(route.body ? [route.body.key] : []),
|
191
193
|
].map((key) => ts.factory.createIdentifier(key)),
|
192
194
|
),
|
193
195
|
undefined,
|