@nestia/migrate 0.7.0-dev.20240201 → 0.7.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/package.json +68 -68
- package/src/MigrateApplication.ts +35 -35
- package/src/archivers/FileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +2 -7
- package/src/bundles/SDK_TEMPLATE.ts +1 -6
- package/src/executable/bundle.ts +102 -102
- package/src/executable/migrate.ts +7 -7
- package/src/module.ts +4 -4
- package/src/programmers/DtoProgrammer.ts +74 -74
- package/src/programmers/ImportProgrammer.ts +114 -114
- package/src/programmers/NestControllerProgrammer.ts +48 -48
- package/src/programmers/NestProgrammer.ts +74 -74
- package/src/structures/IMigrateProgram.ts +9 -9
- package/src/structures/IMigrateRoute.ts +44 -44
- package/src/utils/JsonTypeChecker.ts +67 -67
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
package/package.json
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
{
|
2
|
-
"name": "@nestia/migrate",
|
3
|
-
"version": "0.7.0
|
4
|
-
"description": "Migration program from swagger to NestJS",
|
5
|
-
"main": "lib/index.js",
|
6
|
-
"typings": "lib/index.d.ts",
|
7
|
-
"bin": {
|
8
|
-
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
-
},
|
10
|
-
"scripts": {
|
11
|
-
"build": "rimraf lib && tsc",
|
12
|
-
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
-
"dev": "npm run build -- --watch",
|
14
|
-
"prepare": "ts-patch install && typia patch && npm run bundle",
|
15
|
-
"test": "node lib/test"
|
16
|
-
},
|
17
|
-
"repository": {
|
18
|
-
"type": "git",
|
19
|
-
"url": "https://github.com/samchon/nestia"
|
20
|
-
},
|
21
|
-
"keywords": [
|
22
|
-
"migration",
|
23
|
-
"swagger",
|
24
|
-
"NestJS",
|
25
|
-
"nestia"
|
26
|
-
],
|
27
|
-
"author": "Jeongho Nam",
|
28
|
-
"license": "MIT",
|
29
|
-
"bugs": {
|
30
|
-
"url": "https://github.com/samchon/nestia/issues"
|
31
|
-
},
|
32
|
-
"homepage": "https://github.com/samchon/nestia#readme",
|
33
|
-
"devDependencies": {
|
34
|
-
"@nestia/core": "2.5.0
|
35
|
-
"@nestia/fetcher": "2.5.0
|
36
|
-
"@nestjs/common": "^10.3.1",
|
37
|
-
"@nestjs/core": "^10.3.1",
|
38
|
-
"@nestjs/platform-express": "^10.3.1",
|
39
|
-
"@nestjs/platform-fastify": "^10.3.1",
|
40
|
-
"@types/express": "^4.17.21",
|
41
|
-
"@types/inquirer": "^9.0.7",
|
42
|
-
"@types/node": "^20.3.3",
|
43
|
-
"dotenv": "^16.3.1",
|
44
|
-
"dotenv-expand": "^10.0.0",
|
45
|
-
"rimraf": "^5.0.1",
|
46
|
-
"serialize-error": "^4.1.0",
|
47
|
-
"source-map-support": "^0.5.21",
|
48
|
-
"ts-node": "^10.9.1",
|
49
|
-
"ts-patch": "^3.1.0",
|
50
|
-
"tstl": "^2.5.13",
|
51
|
-
"typescript-transform-paths": "^3.4.6"
|
52
|
-
},
|
53
|
-
"dependencies": {
|
54
|
-
"commander": "10.0.0",
|
55
|
-
"inquirer": "8.2.5",
|
56
|
-
"typescript": "^5.3.3",
|
57
|
-
"typia": "^5.4.1"
|
58
|
-
},
|
59
|
-
"files": [
|
60
|
-
"lib",
|
61
|
-
"src",
|
62
|
-
"!lib/test",
|
63
|
-
"!src/test",
|
64
|
-
"package.json",
|
65
|
-
"README.md",
|
66
|
-
"LICENSE"
|
67
|
-
]
|
68
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@nestia/migrate",
|
3
|
+
"version": "0.7.0",
|
4
|
+
"description": "Migration program from swagger to NestJS",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"typings": "lib/index.d.ts",
|
7
|
+
"bin": {
|
8
|
+
"@nestia/migrate": "lib/executable/migrate.js"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"build": "rimraf lib && tsc",
|
12
|
+
"bundle": "ts-node src/executable/bundle.ts",
|
13
|
+
"dev": "npm run build -- --watch",
|
14
|
+
"prepare": "ts-patch install && typia patch && npm run bundle",
|
15
|
+
"test": "node lib/test"
|
16
|
+
},
|
17
|
+
"repository": {
|
18
|
+
"type": "git",
|
19
|
+
"url": "https://github.com/samchon/nestia"
|
20
|
+
},
|
21
|
+
"keywords": [
|
22
|
+
"migration",
|
23
|
+
"swagger",
|
24
|
+
"NestJS",
|
25
|
+
"nestia"
|
26
|
+
],
|
27
|
+
"author": "Jeongho Nam",
|
28
|
+
"license": "MIT",
|
29
|
+
"bugs": {
|
30
|
+
"url": "https://github.com/samchon/nestia/issues"
|
31
|
+
},
|
32
|
+
"homepage": "https://github.com/samchon/nestia#readme",
|
33
|
+
"devDependencies": {
|
34
|
+
"@nestia/core": "2.5.0",
|
35
|
+
"@nestia/fetcher": "2.5.0",
|
36
|
+
"@nestjs/common": "^10.3.1",
|
37
|
+
"@nestjs/core": "^10.3.1",
|
38
|
+
"@nestjs/platform-express": "^10.3.1",
|
39
|
+
"@nestjs/platform-fastify": "^10.3.1",
|
40
|
+
"@types/express": "^4.17.21",
|
41
|
+
"@types/inquirer": "^9.0.7",
|
42
|
+
"@types/node": "^20.3.3",
|
43
|
+
"dotenv": "^16.3.1",
|
44
|
+
"dotenv-expand": "^10.0.0",
|
45
|
+
"rimraf": "^5.0.1",
|
46
|
+
"serialize-error": "^4.1.0",
|
47
|
+
"source-map-support": "^0.5.21",
|
48
|
+
"ts-node": "^10.9.1",
|
49
|
+
"ts-patch": "^3.1.0",
|
50
|
+
"tstl": "^2.5.13",
|
51
|
+
"typescript-transform-paths": "^3.4.6"
|
52
|
+
},
|
53
|
+
"dependencies": {
|
54
|
+
"commander": "10.0.0",
|
55
|
+
"inquirer": "8.2.5",
|
56
|
+
"typescript": "^5.3.3",
|
57
|
+
"typia": "^5.4.1"
|
58
|
+
},
|
59
|
+
"files": [
|
60
|
+
"lib",
|
61
|
+
"src",
|
62
|
+
"!lib/test",
|
63
|
+
"!src/test",
|
64
|
+
"package.json",
|
65
|
+
"README.md",
|
66
|
+
"LICENSE"
|
67
|
+
]
|
68
|
+
}
|
@@ -1,35 +1,35 @@
|
|
1
|
-
import typia from "typia";
|
2
|
-
|
3
|
-
import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
|
4
|
-
import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
|
5
|
-
import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
|
6
|
-
import { ApiProgrammer } from "./programmers/ApiProgrammer";
|
7
|
-
import { NestProgrammer } from "./programmers/NestProgrammer";
|
8
|
-
import { IMigrateFile } from "./structures/IMigrateFile";
|
9
|
-
import { ISwagger } from "./structures/ISwagger";
|
10
|
-
|
11
|
-
export class MigrateApplication {
|
12
|
-
public constructor(public readonly swagger: ISwagger) {
|
13
|
-
typia.assert(swagger);
|
14
|
-
}
|
15
|
-
|
16
|
-
public nest(simulate: boolean): IMigrateFile[] {
|
17
|
-
const program = MigrateAnalyzer.analyze({
|
18
|
-
mode: "nest",
|
19
|
-
simulate,
|
20
|
-
})(this.swagger);
|
21
|
-
return [
|
22
|
-
...NEST_TEMPLATE,
|
23
|
-
...NestProgrammer.write(program),
|
24
|
-
...ApiProgrammer.write(program),
|
25
|
-
];
|
26
|
-
}
|
27
|
-
|
28
|
-
public sdk(simulate: boolean): IMigrateFile[] {
|
29
|
-
const program = MigrateAnalyzer.analyze({
|
30
|
-
mode: "sdk",
|
31
|
-
simulate,
|
32
|
-
})(this.swagger);
|
33
|
-
return [...SDK_TEMPLATE, ...ApiProgrammer.write(program)];
|
34
|
-
}
|
35
|
-
}
|
1
|
+
import typia from "typia";
|
2
|
+
|
3
|
+
import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
|
4
|
+
import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
|
5
|
+
import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
|
6
|
+
import { ApiProgrammer } from "./programmers/ApiProgrammer";
|
7
|
+
import { NestProgrammer } from "./programmers/NestProgrammer";
|
8
|
+
import { IMigrateFile } from "./structures/IMigrateFile";
|
9
|
+
import { ISwagger } from "./structures/ISwagger";
|
10
|
+
|
11
|
+
export class MigrateApplication {
|
12
|
+
public constructor(public readonly swagger: ISwagger) {
|
13
|
+
typia.assert(swagger);
|
14
|
+
}
|
15
|
+
|
16
|
+
public nest(simulate: boolean): IMigrateFile[] {
|
17
|
+
const program = MigrateAnalyzer.analyze({
|
18
|
+
mode: "nest",
|
19
|
+
simulate,
|
20
|
+
})(this.swagger);
|
21
|
+
return [
|
22
|
+
...NEST_TEMPLATE,
|
23
|
+
...NestProgrammer.write(program),
|
24
|
+
...ApiProgrammer.write(program),
|
25
|
+
];
|
26
|
+
}
|
27
|
+
|
28
|
+
public sdk(simulate: boolean): IMigrateFile[] {
|
29
|
+
const program = MigrateAnalyzer.analyze({
|
30
|
+
mode: "sdk",
|
31
|
+
simulate,
|
32
|
+
})(this.swagger);
|
33
|
+
return [...SDK_TEMPLATE, ...ApiProgrammer.write(program)];
|
34
|
+
}
|
35
|
+
}
|
@@ -1,38 +1,38 @@
|
|
1
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
-
|
3
|
-
export namespace FileArchiver {
|
4
|
-
export interface IOperator {
|
5
|
-
mkdir(path: string): Promise<void>;
|
6
|
-
writeFile(path: string, content: string): Promise<void>;
|
7
|
-
}
|
8
|
-
|
9
|
-
export const archive =
|
10
|
-
(operator: IOperator) =>
|
11
|
-
(output: string) =>
|
12
|
-
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
-
const visited: Set<string> = new Set();
|
14
|
-
for (const f of files) {
|
15
|
-
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
-
await operator.writeFile(
|
17
|
-
[output, f.location, f.file].join("/"),
|
18
|
-
f.content,
|
19
|
-
);
|
20
|
-
}
|
21
|
-
};
|
22
|
-
|
23
|
-
const mkdir =
|
24
|
-
(creator: (path: string) => void) =>
|
25
|
-
(output: string) =>
|
26
|
-
(visited: Set<string>) =>
|
27
|
-
async (path: string): Promise<void> => {
|
28
|
-
const sequence: string[] = path
|
29
|
-
.split("/")
|
30
|
-
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
-
for (const s of sequence)
|
32
|
-
if (visited.has(s) === false)
|
33
|
-
try {
|
34
|
-
await creator([output, s].join("/"));
|
35
|
-
visited.add(s);
|
36
|
-
} catch {}
|
37
|
-
};
|
38
|
-
}
|
1
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
+
|
3
|
+
export namespace FileArchiver {
|
4
|
+
export interface IOperator {
|
5
|
+
mkdir(path: string): Promise<void>;
|
6
|
+
writeFile(path: string, content: string): Promise<void>;
|
7
|
+
}
|
8
|
+
|
9
|
+
export const archive =
|
10
|
+
(operator: IOperator) =>
|
11
|
+
(output: string) =>
|
12
|
+
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
+
const visited: Set<string> = new Set();
|
14
|
+
for (const f of files) {
|
15
|
+
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
+
await operator.writeFile(
|
17
|
+
[output, f.location, f.file].join("/"),
|
18
|
+
f.content,
|
19
|
+
);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
const mkdir =
|
24
|
+
(creator: (path: string) => void) =>
|
25
|
+
(output: string) =>
|
26
|
+
(visited: Set<string>) =>
|
27
|
+
async (path: string): Promise<void> => {
|
28
|
+
const sequence: string[] = path
|
29
|
+
.split("/")
|
30
|
+
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
+
for (const s of sequence)
|
32
|
+
if (visited.has(s) === false)
|
33
|
+
try {
|
34
|
+
await creator([output, s].join("/"));
|
35
|
+
visited.add(s);
|
36
|
+
} catch {}
|
37
|
+
};
|
38
|
+
}
|
@@ -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 \"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.1\",\r\n \"@nestia/sdk\": \"^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 \"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.1\",\r\n \"@nestia/sdk\": \"^2.5.0\",\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.2.1\",\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\": \"^2.5.0\",\r\n \"@nestia/fetcher\": \"^2.5.0\",\r\n \"@nestjs/common\": \"^10.3.0\",\r\n \"@nestjs/core\": \"^10.3.0\",\r\n \"@nestjs/platform-fastify\": \"^10.3.0\",\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 \"tstl\": \"^2.5.13\",\r\n \"typia\": \"^5.4.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 \"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\": \"^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 \"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\": \"^2.5.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
|
71
71
|
},
|
72
72
|
{
|
73
73
|
"location": "packages/api",
|
@@ -129,11 +129,6 @@ export const NEST_TEMPLATE = [
|
|
129
129
|
"file": "IPage.ts",
|
130
130
|
"content": "import { tags } from \"typia\";\r\n\r\n/**\r\n * A page.\r\n *\r\n * Collection of records with pagination indformation.\r\n *\r\n * @author Samchon\r\n */\r\nexport interface IPage<T extends object> {\r\n /**\r\n * Page information.\r\n */\r\n pagination: IPage.IPagination;\r\n\r\n /**\r\n * List of records.\r\n */\r\n data: T[];\r\n}\r\nexport namespace IPage {\r\n /**\r\n * Page information.\r\n */\r\n export interface IPagination {\r\n /**\r\n * Current page number.\r\n */\r\n current: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Limitation of records per a page.\r\n *\r\n * @default 100\r\n */\r\n limit: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Count of total records in database.\r\n */\r\n records: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Number of total pages.\r\n *\r\n * Equal to {@link records} / {@link limit} with ceiling.\r\n */\r\n pages: number & tags.Type<\"uint32\">;\r\n }\r\n\r\n /**\r\n * Page request data\r\n */\r\n export interface IRequest {\r\n /**\r\n * Page number.\r\n */\r\n page?: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Limitation of records per a page.\r\n */\r\n limit?: number & tags.Type<\"uint32\">;\r\n }\r\n\r\n /**\r\n * Sorting column specialization.\r\n *\r\n * The plus means ascending order and the minus means descending order.\r\n */\r\n export type Sort<Literal extends string> = Array<\r\n `-${Literal}` | `+${Literal}`\r\n >;\r\n}\r\n"
|
131
131
|
},
|
132
|
-
{
|
133
|
-
"location": "src/api/utils",
|
134
|
-
"file": "NestiaSimulator.ts",
|
135
|
-
"content": "import { HttpError } from \"@nestia/fetcher\";\r\n\r\nimport typia from \"typia\";\r\n\r\nexport namespace NestiaSimulator {\r\n export interface IProps {\r\n host: string;\r\n path: string;\r\n method: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\r\n contentType: string;\r\n }\r\n\r\n export const assert = (props: IProps) => {\r\n return {\r\n param: param(props),\r\n query: query(props),\r\n body: body(props),\r\n };\r\n };\r\n const param =\r\n (props: IProps) =>\r\n (name: string) =>\r\n <T>(task: () => T): void => {\r\n validate(\r\n (exp) => `URL parameter \"${name}\" is not ${exp.expected} type.`,\r\n )(props)(task);\r\n };\r\n\r\n const query =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(\r\n () =>\r\n \"Request query parameters are not following the promised type.\",\r\n )(props)(task);\r\n\r\n const body =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(() => \"Request body is not following the promised type.\")(\r\n props,\r\n )(task);\r\n\r\n const validate =\r\n (message: (exp: typia.TypeGuardError) => string, path?: string) =>\r\n (props: IProps) =>\r\n <T>(task: () => T): void => {\r\n try {\r\n task();\r\n } catch (exp) {\r\n if (typia.is<typia.TypeGuardError>(exp))\r\n throw new HttpError(\r\n props.method,\r\n props.host + props.path,\r\n 400,\r\n {\r\n \"Content-Type\": props.contentType,\r\n },\r\n JSON.stringify({\r\n method: exp.method,\r\n path: path ?? exp.path,\r\n expected: exp.expected,\r\n value: exp.value,\r\n message: message(exp),\r\n }),\r\n );\r\n throw exp;\r\n }\r\n };\r\n}\r\n"
|
136
|
-
},
|
137
132
|
{
|
138
133
|
"location": "src/executable",
|
139
134
|
"file": "server.ts",
|
@@ -12,7 +12,7 @@ export const SDK_TEMPLATE = [
|
|
12
12
|
{
|
13
13
|
"location": "",
|
14
14
|
"file": "package.json",
|
15
|
-
"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\": \"rimraf lib && tsc\",\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\": \"^2.
|
15
|
+
"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\": \"rimraf lib && tsc\",\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\": \"^2.5.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"location": "",
|
@@ -44,11 +44,6 @@ export const SDK_TEMPLATE = [
|
|
44
44
|
"file": "Primitive.ts",
|
45
45
|
"content": "export type { Primitive } from \"@nestia/fetcher\";\r\n"
|
46
46
|
},
|
47
|
-
{
|
48
|
-
"location": "src/utils",
|
49
|
-
"file": "NestiaSimulator.ts",
|
50
|
-
"content": "import { HttpError } from \"@nestia/fetcher\";\r\n\r\nimport typia from \"typia\";\r\n\r\nexport namespace NestiaSimulator {\r\n export interface IProps {\r\n host: string;\r\n path: string;\r\n method: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\r\n contentType: string;\r\n }\r\n\r\n export const assert = (props: IProps) => {\r\n return {\r\n param: param(props),\r\n query: query(props),\r\n body: body(props),\r\n };\r\n };\r\n const param =\r\n (props: IProps) =>\r\n (name: string) =>\r\n <T>(task: () => T): void => {\r\n validate(\r\n (exp) => `URL parameter \"${name}\" is not ${exp.expected} type.`,\r\n )(props)(task);\r\n };\r\n\r\n const query =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(\r\n () =>\r\n \"Request query parameters are not following the promised type.\",\r\n )(props)(task);\r\n\r\n const body =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(() => \"Request body is not following the promised type.\")(\r\n props,\r\n )(task);\r\n\r\n const validate =\r\n (message: (exp: typia.TypeGuardError) => string, path?: string) =>\r\n (props: IProps) =>\r\n <T>(task: () => T): void => {\r\n try {\r\n task();\r\n } catch (exp) {\r\n if (typia.is<typia.TypeGuardError>(exp))\r\n throw new HttpError(\r\n props.method,\r\n props.host + props.path,\r\n 400,\r\n {\r\n \"Content-Type\": props.contentType,\r\n },\r\n JSON.stringify({\r\n method: exp.method,\r\n path: path ?? exp.path,\r\n expected: exp.expected,\r\n value: exp.value,\r\n message: message(exp),\r\n }),\r\n );\r\n throw exp;\r\n }\r\n };\r\n}\r\n"
|
51
|
-
},
|
52
47
|
{
|
53
48
|
"location": "",
|
54
49
|
"file": "tsconfig.json",
|
package/src/executable/bundle.ts
CHANGED
@@ -1,102 +1,102 @@
|
|
1
|
-
import cp from "child_process";
|
2
|
-
import fs from "fs";
|
3
|
-
|
4
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
-
|
6
|
-
const ROOT: string = `${__dirname}/../..`;
|
7
|
-
const ASSETS: string = `${ROOT}/assets`;
|
8
|
-
|
9
|
-
const bundle = async (props: {
|
10
|
-
mode: "nest" | "sdk";
|
11
|
-
repository: string;
|
12
|
-
exceptions?: string[];
|
13
|
-
}): Promise<void> => {
|
14
|
-
const root: string = `${__dirname}/../..`;
|
15
|
-
const assets: string = `${root}/assets`;
|
16
|
-
const template: string = `${assets}/${props.mode}`;
|
17
|
-
|
18
|
-
const clone = async () => {
|
19
|
-
// CLONE REPOSITORY
|
20
|
-
if (fs.existsSync(template))
|
21
|
-
await fs.promises.rm(template, { recursive: true });
|
22
|
-
else
|
23
|
-
try {
|
24
|
-
await fs.promises.mkdir(ASSETS);
|
25
|
-
} catch {}
|
26
|
-
|
27
|
-
cp.execSync(
|
28
|
-
`git clone https://github.com/samchon/${props.repository} ${props.mode}`,
|
29
|
-
{
|
30
|
-
cwd: ASSETS,
|
31
|
-
},
|
32
|
-
);
|
33
|
-
|
34
|
-
// REMOVE VUNLERABLE FILES
|
35
|
-
for (const location of props.exceptions ?? [])
|
36
|
-
await fs.promises.rm(`${template}/${location}`, { recursive: true });
|
37
|
-
};
|
38
|
-
|
39
|
-
const iterate = (collection: IMigrateFile[]) => async (location: string) => {
|
40
|
-
const directory: string[] = await fs.promises.readdir(location);
|
41
|
-
for (const file of directory) {
|
42
|
-
const absolute: string = location + "/" + file;
|
43
|
-
const stats: fs.Stats = await fs.promises.stat(absolute);
|
44
|
-
if (stats.isDirectory()) await iterate(collection)(absolute);
|
45
|
-
else {
|
46
|
-
const content: string = await fs.promises.readFile(absolute, "utf-8");
|
47
|
-
collection.push({
|
48
|
-
location: (() => {
|
49
|
-
const str: string = location.replace(template, "");
|
50
|
-
return str[0] === "/" ? str.substring(1) : str;
|
51
|
-
})(),
|
52
|
-
file,
|
53
|
-
content,
|
54
|
-
});
|
55
|
-
}
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
const archive = async (collection: IMigrateFile[]): Promise<void> => {
|
60
|
-
const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
|
61
|
-
const body: string = JSON.stringify(collection, null, 2);
|
62
|
-
const content: string = `export const ${name} = ${body}`;
|
63
|
-
|
64
|
-
try {
|
65
|
-
await fs.promises.mkdir(`${ROOT}/src/bundles`);
|
66
|
-
} catch {}
|
67
|
-
await fs.promises.writeFile(
|
68
|
-
`${ROOT}/src/bundles/${name}.ts`,
|
69
|
-
content,
|
70
|
-
"utf8",
|
71
|
-
);
|
72
|
-
};
|
73
|
-
|
74
|
-
const collection: IMigrateFile[] = [];
|
75
|
-
await clone();
|
76
|
-
await iterate(collection)(template);
|
77
|
-
await archive(collection);
|
78
|
-
};
|
79
|
-
|
80
|
-
const main = async (): Promise<void> => {
|
81
|
-
await bundle({
|
82
|
-
mode: "nest",
|
83
|
-
repository: "nestia-start",
|
84
|
-
exceptions: [
|
85
|
-
".git",
|
86
|
-
"src/api/functional",
|
87
|
-
"src/controllers",
|
88
|
-
"src/MyModule.ts",
|
89
|
-
"src/providers",
|
90
|
-
"test/features",
|
91
|
-
],
|
92
|
-
});
|
93
|
-
await bundle({
|
94
|
-
mode: "sdk",
|
95
|
-
repository: "nestia-sdk-template",
|
96
|
-
exceptions: [".git", "src/functional", "src/structures"],
|
97
|
-
});
|
98
|
-
};
|
99
|
-
main().catch((exp) => {
|
100
|
-
console.error(exp);
|
101
|
-
process.exit(-1);
|
102
|
-
});
|
1
|
+
import cp from "child_process";
|
2
|
+
import fs from "fs";
|
3
|
+
|
4
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
+
|
6
|
+
const ROOT: string = `${__dirname}/../..`;
|
7
|
+
const ASSETS: string = `${ROOT}/assets`;
|
8
|
+
|
9
|
+
const bundle = async (props: {
|
10
|
+
mode: "nest" | "sdk";
|
11
|
+
repository: string;
|
12
|
+
exceptions?: string[];
|
13
|
+
}): Promise<void> => {
|
14
|
+
const root: string = `${__dirname}/../..`;
|
15
|
+
const assets: string = `${root}/assets`;
|
16
|
+
const template: string = `${assets}/${props.mode}`;
|
17
|
+
|
18
|
+
const clone = async () => {
|
19
|
+
// CLONE REPOSITORY
|
20
|
+
if (fs.existsSync(template))
|
21
|
+
await fs.promises.rm(template, { recursive: true });
|
22
|
+
else
|
23
|
+
try {
|
24
|
+
await fs.promises.mkdir(ASSETS);
|
25
|
+
} catch {}
|
26
|
+
|
27
|
+
cp.execSync(
|
28
|
+
`git clone https://github.com/samchon/${props.repository} ${props.mode}`,
|
29
|
+
{
|
30
|
+
cwd: ASSETS,
|
31
|
+
},
|
32
|
+
);
|
33
|
+
|
34
|
+
// REMOVE VUNLERABLE FILES
|
35
|
+
for (const location of props.exceptions ?? [])
|
36
|
+
await fs.promises.rm(`${template}/${location}`, { recursive: true });
|
37
|
+
};
|
38
|
+
|
39
|
+
const iterate = (collection: IMigrateFile[]) => async (location: string) => {
|
40
|
+
const directory: string[] = await fs.promises.readdir(location);
|
41
|
+
for (const file of directory) {
|
42
|
+
const absolute: string = location + "/" + file;
|
43
|
+
const stats: fs.Stats = await fs.promises.stat(absolute);
|
44
|
+
if (stats.isDirectory()) await iterate(collection)(absolute);
|
45
|
+
else {
|
46
|
+
const content: string = await fs.promises.readFile(absolute, "utf-8");
|
47
|
+
collection.push({
|
48
|
+
location: (() => {
|
49
|
+
const str: string = location.replace(template, "");
|
50
|
+
return str[0] === "/" ? str.substring(1) : str;
|
51
|
+
})(),
|
52
|
+
file,
|
53
|
+
content,
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
const archive = async (collection: IMigrateFile[]): Promise<void> => {
|
60
|
+
const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
|
61
|
+
const body: string = JSON.stringify(collection, null, 2);
|
62
|
+
const content: string = `export const ${name} = ${body}`;
|
63
|
+
|
64
|
+
try {
|
65
|
+
await fs.promises.mkdir(`${ROOT}/src/bundles`);
|
66
|
+
} catch {}
|
67
|
+
await fs.promises.writeFile(
|
68
|
+
`${ROOT}/src/bundles/${name}.ts`,
|
69
|
+
content,
|
70
|
+
"utf8",
|
71
|
+
);
|
72
|
+
};
|
73
|
+
|
74
|
+
const collection: IMigrateFile[] = [];
|
75
|
+
await clone();
|
76
|
+
await iterate(collection)(template);
|
77
|
+
await archive(collection);
|
78
|
+
};
|
79
|
+
|
80
|
+
const main = async (): Promise<void> => {
|
81
|
+
await bundle({
|
82
|
+
mode: "nest",
|
83
|
+
repository: "nestia-start",
|
84
|
+
exceptions: [
|
85
|
+
".git",
|
86
|
+
"src/api/functional",
|
87
|
+
"src/controllers",
|
88
|
+
"src/MyModule.ts",
|
89
|
+
"src/providers",
|
90
|
+
"test/features",
|
91
|
+
],
|
92
|
+
});
|
93
|
+
await bundle({
|
94
|
+
mode: "sdk",
|
95
|
+
repository: "nestia-sdk-template",
|
96
|
+
exceptions: [".git", "src/functional", "src/structures"],
|
97
|
+
});
|
98
|
+
};
|
99
|
+
main().catch((exp) => {
|
100
|
+
console.error(exp);
|
101
|
+
process.exit(-1);
|
102
|
+
});
|
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import { MigrateCommander } from "../internal/MigrateCommander";
|
3
|
-
|
4
|
-
MigrateCommander.main().catch((exp) => {
|
5
|
-
console.error(exp);
|
6
|
-
process.exit(-1);
|
7
|
-
});
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { MigrateCommander } from "../internal/MigrateCommander";
|
3
|
+
|
4
|
+
MigrateCommander.main().catch((exp) => {
|
5
|
+
console.error(exp);
|
6
|
+
process.exit(-1);
|
7
|
+
});
|
package/src/module.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from "./MigrateApplication";
|
2
|
-
|
3
|
-
export * from "./structures/ISwagger";
|
4
|
-
export * from "./structures/IMigrateProgram";
|
1
|
+
export * from "./MigrateApplication";
|
2
|
+
|
3
|
+
export * from "./structures/ISwagger";
|
4
|
+
export * from "./structures/IMigrateProgram";
|