@nestia/migrate 0.6.2 → 0.6.3
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/IMigrateConfig.d.ts +3 -0
- package/lib/IMigrateConfig.js +3 -0
- package/lib/IMigrateConfig.js.map +1 -0
- package/lib/MigrateApplication.d.ts +3 -1
- package/lib/MigrateApplication.js +5 -4
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.d.ts +2 -1
- package/lib/analyzers/MigrateAnalyzer.js +2 -1
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/executable/migrate.js +6 -3
- package/lib/executable/migrate.js.map +1 -1
- package/lib/internal/MigrateArguments.d.ts +8 -0
- package/lib/internal/MigrateArguments.js +67 -0
- package/lib/internal/MigrateArguments.js.map +1 -0
- package/lib/programmers/ApiFileProgrammer.d.ts +2 -1
- package/lib/programmers/ApiFileProgrammer.js +3 -3
- package/lib/programmers/ApiFileProgrammer.js.map +1 -1
- package/lib/programmers/ApiFunctionProgrammer.d.ts +3 -1
- package/lib/programmers/ApiFunctionProgrammer.js +34 -23
- package/lib/programmers/ApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/ApiNamespaceProgrammer.d.ts +3 -1
- package/lib/programmers/ApiNamespaceProgrammer.js +15 -2
- package/lib/programmers/ApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/ApiProgrammer.js +1 -1
- package/lib/programmers/ApiProgrammer.js.map +1 -1
- package/lib/programmers/ApiSimulatationProgrammer.d.ts +14 -0
- package/lib/programmers/ApiSimulatationProgrammer.js +127 -0
- package/lib/programmers/ApiSimulatationProgrammer.js.map +1 -0
- package/lib/structures/IMigrateProgram.d.ts +2 -0
- package/package.json +67 -64
- package/src/IMigrateConfig.ts +3 -0
- package/src/MigrateApplication.ts +8 -4
- package/src/analyzers/MigrateAnalyzer.ts +8 -4
- package/src/executable/migrate.ts +9 -3
- package/src/internal/MigrateArguments.ts +74 -0
- package/src/programmers/ApiFileProgrammer.ts +4 -2
- package/src/programmers/ApiFunctionProgrammer.ts +47 -20
- package/src/programmers/ApiNamespaceProgrammer.ts +24 -1
- package/src/programmers/ApiProgrammer.ts +3 -1
- package/src/programmers/ApiSimulatationProgrammer.ts +328 -0
- package/src/structures/IMigrateProgram.ts +2 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.ApiSimulatationProgrammer = void 0;
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
8
|
+
const IdentifierFactory_1 = require("typia/lib/factories/IdentifierFactory");
|
9
|
+
const StatementFactory_1 = require("typia/lib/factories/StatementFactory");
|
10
|
+
const TypeFactory_1 = require("typia/lib/factories/TypeFactory");
|
11
|
+
const ApiFunctionProgrammer_1 = require("./ApiFunctionProgrammer");
|
12
|
+
const ApiNamespaceProgrammer_1 = require("./ApiNamespaceProgrammer");
|
13
|
+
const SchemaProgrammer_1 = require("./SchemaProgrammer");
|
14
|
+
var ApiSimulatationProgrammer;
|
15
|
+
(function (ApiSimulatationProgrammer) {
|
16
|
+
ApiSimulatationProgrammer.random = (components) => (importer) => (props) => constant("random")(typescript_1.default.factory.createArrowFunction(undefined, undefined, [
|
17
|
+
typescript_1.default.factory.createParameterDeclaration(undefined, undefined, "g", typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier("Partial"), [
|
18
|
+
typescript_1.default.factory.createTypeReferenceNode(`${importer.external({
|
19
|
+
type: "default",
|
20
|
+
library: "typia",
|
21
|
+
name: "typia",
|
22
|
+
})}.IRandomGenerator`),
|
23
|
+
])),
|
24
|
+
], undefined, undefined, typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier(importer.external({
|
25
|
+
type: "default",
|
26
|
+
library: "typia",
|
27
|
+
name: "typia",
|
28
|
+
})))("random"), [
|
29
|
+
props.route.success
|
30
|
+
? SchemaProgrammer_1.SchemaProgrammer.write(components)(importer)(props.route.success.schema)
|
31
|
+
: TypeFactory_1.TypeFactory.keyword("void"),
|
32
|
+
], [typescript_1.default.factory.createIdentifier("g")])));
|
33
|
+
ApiSimulatationProgrammer.simulate = (components) => (importer) => (props) => {
|
34
|
+
const caller = () => typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("random"), undefined, [
|
35
|
+
typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createLogicalAnd(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createStringLiteral("object"), typescript_1.default.factory.createTypeOfExpression(typescript_1.default.factory.createIdentifier("connection.simulate"))), typescript_1.default.factory.createStrictInequality(typescript_1.default.factory.createNull(), typescript_1.default.factory.createIdentifier("connection.simulate"))), undefined, typescript_1.default.factory.createIdentifier("connection.simulate"), undefined, typescript_1.default.factory.createIdentifier("undefined")),
|
36
|
+
]);
|
37
|
+
assert;
|
38
|
+
return constant("simulate")(typescript_1.default.factory.createArrowFunction(undefined, undefined, ApiFunctionProgrammer_1.ApiFunctionProgrammer.writeParameterDeclarations(components)(importer)(props), typescript_1.default.factory.createTypeReferenceNode(props.route.success ? "Output" : "void"), undefined, typescript_1.default.factory.createBlock([
|
39
|
+
...assert(components)(importer)(props),
|
40
|
+
typescript_1.default.factory.createReturnStatement(caller()),
|
41
|
+
], true)));
|
42
|
+
};
|
43
|
+
const assert = (components) => (importer) => (props) => {
|
44
|
+
var _a, _b;
|
45
|
+
const parameters = [
|
46
|
+
...props.route.parameters.map((p) => ({
|
47
|
+
category: "param",
|
48
|
+
name: p.key,
|
49
|
+
schema: SchemaProgrammer_1.SchemaProgrammer.write(components)(importer)(p.schema),
|
50
|
+
})),
|
51
|
+
...(props.route.query
|
52
|
+
? [
|
53
|
+
{
|
54
|
+
category: "query",
|
55
|
+
name: props.route.query.key,
|
56
|
+
schema: SchemaProgrammer_1.SchemaProgrammer.write(components)(importer)(props.route.query.schema),
|
57
|
+
},
|
58
|
+
]
|
59
|
+
: []),
|
60
|
+
...(props.route.body
|
61
|
+
? [
|
62
|
+
{
|
63
|
+
category: "body",
|
64
|
+
name: props.route.body.key,
|
65
|
+
schema: SchemaProgrammer_1.SchemaProgrammer.write(components)(importer)(props.route.body.schema),
|
66
|
+
},
|
67
|
+
]
|
68
|
+
: []),
|
69
|
+
];
|
70
|
+
if (parameters.length === 0)
|
71
|
+
return [];
|
72
|
+
const validator = StatementFactory_1.StatementFactory.constant("assert", typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier(importer.external({
|
73
|
+
type: "instance",
|
74
|
+
library: `@nestia/fetcher/lib/NestiaSimulator`,
|
75
|
+
name: "NestiaSimulator",
|
76
|
+
})))("assert"), undefined, [
|
77
|
+
typescript_1.default.factory.createObjectLiteralExpression([
|
78
|
+
typescript_1.default.factory.createPropertyAssignment("method", typescript_1.default.factory.createIdentifier("METADATA.method")),
|
79
|
+
typescript_1.default.factory.createPropertyAssignment("host", typescript_1.default.factory.createIdentifier("connection.host")),
|
80
|
+
typescript_1.default.factory.createPropertyAssignment("path", ApiNamespaceProgrammer_1.ApiNamespaceProgrammer.writePathCallExpression(props)),
|
81
|
+
typescript_1.default.factory.createPropertyAssignment("contentType", typescript_1.default.factory.createStringLiteral((_b = (_a = props.route.success) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : "application/json")),
|
82
|
+
], true),
|
83
|
+
]));
|
84
|
+
const individual = parameters
|
85
|
+
.map((p) => typescript_1.default.factory.createCallExpression((() => {
|
86
|
+
const base = IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier("assert"))(p.category);
|
87
|
+
if (p.category !== "param")
|
88
|
+
return base;
|
89
|
+
return typescript_1.default.factory.createCallExpression(base, undefined, [
|
90
|
+
typescript_1.default.factory.createStringLiteral(p.name),
|
91
|
+
]);
|
92
|
+
})(), undefined, [
|
93
|
+
typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier(importer.external({
|
94
|
+
type: "default",
|
95
|
+
library: "typia",
|
96
|
+
name: "typia",
|
97
|
+
})))("assert"), undefined, [
|
98
|
+
typescript_1.default.factory.createIdentifier(p.category === "headers" ? "connection.headers" : p.name),
|
99
|
+
])),
|
100
|
+
]))
|
101
|
+
.map(typescript_1.default.factory.createExpressionStatement);
|
102
|
+
return [validator, tryAndCatch(importer)(individual)];
|
103
|
+
};
|
104
|
+
const tryAndCatch = (importer) => (individual) => typescript_1.default.factory.createTryStatement(typescript_1.default.factory.createBlock(individual, true), typescript_1.default.factory.createCatchClause("exp", typescript_1.default.factory.createBlock([
|
105
|
+
typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createLogicalNot(typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier(importer.external({
|
106
|
+
type: "default",
|
107
|
+
library: "typia",
|
108
|
+
name: "typia",
|
109
|
+
})))("is"), [
|
110
|
+
typescript_1.default.factory.createTypeReferenceNode(importer.external({
|
111
|
+
type: "instance",
|
112
|
+
library: "@nestia/Fetcher",
|
113
|
+
name: "HttpError",
|
114
|
+
})),
|
115
|
+
], [typescript_1.default.factory.createIdentifier("exp")])), typescript_1.default.factory.createThrowStatement(typescript_1.default.factory.createIdentifier("exp"))),
|
116
|
+
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createObjectLiteralExpression([
|
117
|
+
typescript_1.default.factory.createPropertyAssignment("success", typescript_1.default.factory.createFalse()),
|
118
|
+
typescript_1.default.factory.createPropertyAssignment("status", typescript_1.default.factory.createIdentifier("exp.status")),
|
119
|
+
typescript_1.default.factory.createPropertyAssignment("headers", typescript_1.default.factory.createIdentifier("exp.headers")),
|
120
|
+
typescript_1.default.factory.createPropertyAssignment("data", typescript_1.default.factory.createIdentifier("exp.toJSON().message")),
|
121
|
+
], true), TypeFactory_1.TypeFactory.keyword("any"))),
|
122
|
+
], true)), undefined);
|
123
|
+
})(ApiSimulatationProgrammer || (exports.ApiSimulatationProgrammer = ApiSimulatationProgrammer = {}));
|
124
|
+
const constant = (name) => (expression) => typescript_1.default.factory.createVariableStatement([typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.default.factory.createVariableDeclarationList([
|
125
|
+
typescript_1.default.factory.createVariableDeclaration(typescript_1.default.factory.createIdentifier(name), undefined, undefined, expression),
|
126
|
+
], typescript_1.default.NodeFlags.Const));
|
127
|
+
//# sourceMappingURL=ApiSimulatationProgrammer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ApiSimulatationProgrammer.js","sourceRoot":"","sources":["../../src/programmers/ApiSimulatationProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAC5B,6EAA0E;AAC1E,2EAAwE;AACxE,iEAA8D;AAK9D,mEAAgE;AAChE,qEAAkE;AAElE,yDAAsD;AAEtD,IAAiB,yBAAyB,CA0SzC;AA1SD,WAAiB,yBAAyB;IAM3B,gCAAM,GACjB,CAAC,UAA8B,EAAE,EAAE,CACnC,CAAC,QAA0B,EAAE,EAAE,CAC/B,CAAC,KAAa,EAAE,EAAE,CAChB,QAAQ,CAAC,QAAQ,CAAC,CAChB,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAC5B,SAAS,EACT,SAAS,EACT;QACE,oBAAE,CAAC,OAAO,CAAC,0BAA0B,CACnC,SAAS,EACT,SAAS,EACT,GAAG,EACH,oBAAE,CAAC,OAAO,CAAC,WAAW,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EACnD,oBAAE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,yBAAyB,QA0SzC;AAED,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,UAAyB,EAAE,EAAE,CAC/D,oBAAE,CAAC,OAAO,CAAC,uBAAuB,CAChC,CAAC,oBAAE,CAAC,OAAO,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,EACxD,oBAAE,CAAC,OAAO,CAAC,6BAA6B,CACtC;IACE,oBAAE,CAAC,OAAO,CAAC,yBAAyB,CAClC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EACjC,SAAS,EACT,SAAS,EACT,UAAU,CACX;CACF,EACD,oBAAE,CAAC,SAAS,CAAC,KAAK,CACnB,CACF,CAAC"}
|
@@ -1,6 +1,8 @@
|
|
1
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
1
2
|
import { IMigrateController } from "./IMigrateController";
|
2
3
|
import { ISwagger } from "./ISwagger";
|
3
4
|
export interface IMigrateProgram {
|
5
|
+
config: IMigrateConfig;
|
4
6
|
controllers: IMigrateController[];
|
5
7
|
swagger: ISwagger;
|
6
8
|
}
|
package/package.json
CHANGED
@@ -1,64 +1,67 @@
|
|
1
|
-
{
|
2
|
-
"name": "@nestia/migrate",
|
3
|
-
"version": "0.6.
|
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
|
-
"dev": "npm run build -- --watch",
|
13
|
-
"prepare": "ts-patch install && typia patch && ts-node src/executable/bundle.ts",
|
14
|
-
"test": "node lib/test"
|
15
|
-
},
|
16
|
-
"repository": {
|
17
|
-
"type": "git",
|
18
|
-
"url": "https://github.com/samchon/nestia"
|
19
|
-
},
|
20
|
-
"keywords": [
|
21
|
-
"migration",
|
22
|
-
"swagger",
|
23
|
-
"NestJS",
|
24
|
-
"nestia"
|
25
|
-
],
|
26
|
-
"author": "Jeongho Nam",
|
27
|
-
"license": "MIT",
|
28
|
-
"bugs": {
|
29
|
-
"url": "https://github.com/samchon/nestia/issues"
|
30
|
-
},
|
31
|
-
"homepage": "https://github.com/samchon/nestia#readme",
|
32
|
-
"devDependencies": {
|
33
|
-
"@nestia/core": "
|
34
|
-
"@nestia/fetcher": "
|
35
|
-
"@nestjs/common": "^10.3.1",
|
36
|
-
"@nestjs/core": "^10.3.1",
|
37
|
-
"@nestjs/platform-express": "^10.3.1",
|
38
|
-
"@nestjs/platform-fastify": "^10.3.1",
|
39
|
-
"@types/express": "^4.17.21",
|
40
|
-
"@types/
|
41
|
-
"
|
42
|
-
"dotenv
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"ts-
|
48
|
-
"
|
49
|
-
"
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
"
|
54
|
-
|
55
|
-
|
56
|
-
"
|
57
|
-
|
58
|
-
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
|
64
|
-
|
1
|
+
{
|
2
|
+
"name": "@nestia/migrate",
|
3
|
+
"version": "0.6.3",
|
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
|
+
"dev": "npm run build -- --watch",
|
13
|
+
"prepare": "ts-patch install && typia patch && ts-node src/executable/bundle.ts",
|
14
|
+
"test": "node lib/test"
|
15
|
+
},
|
16
|
+
"repository": {
|
17
|
+
"type": "git",
|
18
|
+
"url": "https://github.com/samchon/nestia"
|
19
|
+
},
|
20
|
+
"keywords": [
|
21
|
+
"migration",
|
22
|
+
"swagger",
|
23
|
+
"NestJS",
|
24
|
+
"nestia"
|
25
|
+
],
|
26
|
+
"author": "Jeongho Nam",
|
27
|
+
"license": "MIT",
|
28
|
+
"bugs": {
|
29
|
+
"url": "https://github.com/samchon/nestia/issues"
|
30
|
+
},
|
31
|
+
"homepage": "https://github.com/samchon/nestia#readme",
|
32
|
+
"devDependencies": {
|
33
|
+
"@nestia/core": "2.5.0-dev.20240201",
|
34
|
+
"@nestia/fetcher": "2.5.0-dev.20240201",
|
35
|
+
"@nestjs/common": "^10.3.1",
|
36
|
+
"@nestjs/core": "^10.3.1",
|
37
|
+
"@nestjs/platform-express": "^10.3.1",
|
38
|
+
"@nestjs/platform-fastify": "^10.3.1",
|
39
|
+
"@types/express": "^4.17.21",
|
40
|
+
"@types/inquirer": "^9.0.7",
|
41
|
+
"@types/node": "^20.3.3",
|
42
|
+
"dotenv": "^16.3.1",
|
43
|
+
"dotenv-expand": "^10.0.0",
|
44
|
+
"rimraf": "^5.0.1",
|
45
|
+
"serialize-error": "^4.1.0",
|
46
|
+
"source-map-support": "^0.5.21",
|
47
|
+
"ts-node": "^10.9.1",
|
48
|
+
"ts-patch": "^3.1.0",
|
49
|
+
"tstl": "^2.5.13",
|
50
|
+
"typescript-transform-paths": "^3.4.6"
|
51
|
+
},
|
52
|
+
"dependencies": {
|
53
|
+
"commander": "10.0.0",
|
54
|
+
"inquirer": "8.2.5",
|
55
|
+
"typescript": "^5.3.3",
|
56
|
+
"typia": "^5.4.1"
|
57
|
+
},
|
58
|
+
"files": [
|
59
|
+
"lib",
|
60
|
+
"src",
|
61
|
+
"!lib/test",
|
62
|
+
"!src/test",
|
63
|
+
"package.json",
|
64
|
+
"README.md",
|
65
|
+
"LICENSE"
|
66
|
+
]
|
67
|
+
}
|
@@ -2,6 +2,7 @@ import cp from "child_process";
|
|
2
2
|
import fs from "fs";
|
3
3
|
import typia from "typia";
|
4
4
|
|
5
|
+
import { IMigrateConfig } from "./IMigrateConfig";
|
5
6
|
import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
|
6
7
|
import { FileArchiver } from "./archivers/FileArchiver";
|
7
8
|
import { TEMPLATE } from "./bundles/TEMPLATE";
|
@@ -16,7 +17,10 @@ export class MigrateApplication {
|
|
16
17
|
private program: IMigrateProgram | null;
|
17
18
|
private files: IMigrateFile[] | null;
|
18
19
|
|
19
|
-
public constructor(
|
20
|
+
public constructor(
|
21
|
+
public readonly config: IMigrateConfig,
|
22
|
+
swagger: ISwagger,
|
23
|
+
) {
|
20
24
|
this.swagger = typia.assert(swagger);
|
21
25
|
this.program = null;
|
22
26
|
this.files = null;
|
@@ -24,7 +28,7 @@ export class MigrateApplication {
|
|
24
28
|
|
25
29
|
public analyze(): IMigrateProgram {
|
26
30
|
if (this.program === null)
|
27
|
-
this.program = MigrateAnalyzer.analyze(this.swagger);
|
31
|
+
this.program = MigrateAnalyzer.analyze(this.config)(this.swagger);
|
28
32
|
return this.program;
|
29
33
|
}
|
30
34
|
|
@@ -32,8 +36,8 @@ export class MigrateApplication {
|
|
32
36
|
if (this.files === null) {
|
33
37
|
this.program ??= this.analyze();
|
34
38
|
this.files = [
|
35
|
-
...NestProgrammer.write(this.program),
|
36
39
|
...ApiProgrammer.write(this.program),
|
40
|
+
...NestProgrammer.write(this.program),
|
37
41
|
];
|
38
42
|
}
|
39
43
|
return this.files;
|
@@ -64,7 +68,7 @@ export class MigrateApplication {
|
|
64
68
|
force: true,
|
65
69
|
});
|
66
70
|
} catch {}
|
67
|
-
} catch {
|
71
|
+
} catch (exp) {
|
68
72
|
await archiver(TEMPLATE);
|
69
73
|
}
|
70
74
|
await archiver(files);
|
@@ -1,9 +1,13 @@
|
|
1
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
1
2
|
import { IMigrateProgram, ISwagger } from "../module";
|
2
3
|
import { ControllerAnalyzer } from "./ControllerAnalyzer";
|
3
4
|
|
4
5
|
export namespace MigrateAnalyzer {
|
5
|
-
export const analyze =
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
export const analyze =
|
7
|
+
(config: IMigrateConfig) =>
|
8
|
+
(swagger: ISwagger): IMigrateProgram => ({
|
9
|
+
config,
|
10
|
+
swagger,
|
11
|
+
controllers: ControllerAnalyzer.analyze(swagger),
|
12
|
+
});
|
9
13
|
}
|
@@ -8,9 +8,10 @@ import { SetupWizard } from "../utils/SetupWizard";
|
|
8
8
|
|
9
9
|
const USAGE = `Wrong command has been detected. Use like below:
|
10
10
|
|
11
|
-
npx @nestia/migrate
|
11
|
+
npx @nestia/migrate <nest|sdk> --input <swagger.json> --output <directory>
|
12
12
|
|
13
|
-
ex) npx @nestia/migrate swagger.json my-
|
13
|
+
ex) npx @nestia/migrate nest --input swagger.json --output my-nest-project
|
14
|
+
ex) npx @nestia/migrate sdk --input swagger.json --output my-sdk-library
|
14
15
|
`;
|
15
16
|
|
16
17
|
function halt(desc: string): never {
|
@@ -47,7 +48,12 @@ const main = async (argv: string[]): Promise<void> => {
|
|
47
48
|
})();
|
48
49
|
|
49
50
|
// DO GENERATE
|
50
|
-
const app: MigrateApplication = new MigrateApplication(
|
51
|
+
const app: MigrateApplication = new MigrateApplication(
|
52
|
+
{
|
53
|
+
simulate: false,
|
54
|
+
},
|
55
|
+
swagger,
|
56
|
+
);
|
51
57
|
await app.generate(output);
|
52
58
|
|
53
59
|
// RUN SCRIPTS
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import commander from "commander";
|
2
|
+
import inquirer from "inquirer";
|
3
|
+
|
4
|
+
export namespace MigrateArguments {
|
5
|
+
export interface IOutput {
|
6
|
+
mode: "nest" | "sdk";
|
7
|
+
input: string;
|
8
|
+
output: string;
|
9
|
+
}
|
10
|
+
|
11
|
+
export const parse = async (): Promise<IOutput> => {
|
12
|
+
// PREPARE ASSETS
|
13
|
+
commander.program.option("--node [nest/sdk]", "migration mode");
|
14
|
+
commander.program.option(
|
15
|
+
"--input [swagger.json]",
|
16
|
+
"location of target swagger.json file",
|
17
|
+
);
|
18
|
+
commander.program.option("--output [directory]", "output directory path");
|
19
|
+
|
20
|
+
// INTERNAL PROCEDURES
|
21
|
+
const questioned = { value: false };
|
22
|
+
const action = (
|
23
|
+
closure: (options: Partial<IOutput>) => Promise<IOutput>,
|
24
|
+
) => {
|
25
|
+
return new Promise<IOutput>((resolve, reject) => {
|
26
|
+
commander.program.action(async (options) => {
|
27
|
+
try {
|
28
|
+
resolve(await closure(options));
|
29
|
+
} catch (exp) {
|
30
|
+
reject(exp);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
commander.program.parseAsync().catch(reject);
|
34
|
+
});
|
35
|
+
};
|
36
|
+
const select =
|
37
|
+
(name: string) =>
|
38
|
+
(message: string) =>
|
39
|
+
async <Choice extends string>(
|
40
|
+
choices: Choice[],
|
41
|
+
filter?: (value: string) => Choice,
|
42
|
+
): Promise<Choice> => {
|
43
|
+
questioned.value = true;
|
44
|
+
return (
|
45
|
+
await inquirer.createPromptModule()({
|
46
|
+
type: "list",
|
47
|
+
name: name,
|
48
|
+
message: message,
|
49
|
+
choices: choices,
|
50
|
+
filter,
|
51
|
+
})
|
52
|
+
)[name];
|
53
|
+
};
|
54
|
+
const input = (name: string) => async (message: string) =>
|
55
|
+
(
|
56
|
+
await inquirer.createPromptModule()({
|
57
|
+
type: "input",
|
58
|
+
name,
|
59
|
+
message,
|
60
|
+
})
|
61
|
+
)[name];
|
62
|
+
|
63
|
+
// DO CONSTRUCT
|
64
|
+
return action(async (partial) => {
|
65
|
+
partial.mode ??= await select("mode")("Migration mode")(
|
66
|
+
["NestJS" as "nest", "SDK" as "sdk"],
|
67
|
+
(value) => (value === "NestJS" ? "nest" : "sdk"),
|
68
|
+
);
|
69
|
+
partial.input ??= await input("input")("Swagger file location");
|
70
|
+
partial.output ??= await input("output")("Output directory path");
|
71
|
+
return partial as IOutput;
|
72
|
+
});
|
73
|
+
};
|
74
|
+
}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import ts from "typescript";
|
2
2
|
|
3
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
3
4
|
import { IMigrateController } from "../structures/IMigrateController";
|
4
5
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
5
6
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
@@ -20,13 +21,14 @@ export namespace ApiFileProgrammer {
|
|
20
21
|
}
|
21
22
|
|
22
23
|
export const write =
|
24
|
+
(config: IMigrateConfig) =>
|
23
25
|
(components: ISwaggerComponents) =>
|
24
26
|
(props: IProps): ts.Statement[] => {
|
25
27
|
const importer: ImportProgrammer = new ImportProgrammer();
|
26
28
|
const statements: ts.Statement[] = props.entries
|
27
29
|
.map((p) => [
|
28
|
-
ApiFunctionProgrammer.write(components)(importer)(p),
|
29
|
-
ApiNamespaceProgrammer.write(components)(importer)(p),
|
30
|
+
ApiFunctionProgrammer.write(config)(components)(importer)(p),
|
31
|
+
ApiNamespaceProgrammer.write(config)(components)(importer)(p),
|
30
32
|
])
|
31
33
|
.flat();
|
32
34
|
return [
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import ts from "typescript";
|
2
2
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
3
|
|
4
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
4
5
|
import { IMigrateController } from "../structures/IMigrateController";
|
5
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
7
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
@@ -16,6 +17,7 @@ export namespace ApiFunctionProgrammer {
|
|
16
17
|
}
|
17
18
|
|
18
19
|
export const write =
|
20
|
+
(config: IMigrateConfig) =>
|
19
21
|
(components: ISwaggerComponents) =>
|
20
22
|
(importer: ImportProgrammer) =>
|
21
23
|
(props: IProps): ts.FunctionDeclaration =>
|
@@ -28,30 +30,18 @@ export namespace ApiFunctionProgrammer {
|
|
28
30
|
undefined,
|
29
31
|
props.alias,
|
30
32
|
undefined,
|
31
|
-
|
33
|
+
writeParameterDeclarations(components)(importer)(props),
|
32
34
|
ts.factory.createTypeReferenceNode("Promise", [
|
33
35
|
ts.factory.createTypeReferenceNode(
|
34
36
|
props.route.success === null ? "void" : `${props.alias}.Output`,
|
35
37
|
),
|
36
38
|
]),
|
37
|
-
ts.factory.createBlock(writeBody(importer)(props), true),
|
39
|
+
ts.factory.createBlock(writeBody(config)(importer)(props), true),
|
38
40
|
),
|
39
41
|
writeDescription(props),
|
40
42
|
);
|
41
43
|
|
42
|
-
const
|
43
|
-
[
|
44
|
-
...(props.route.description?.length
|
45
|
-
? [props.route.description.length, ""]
|
46
|
-
: []),
|
47
|
-
...(props.route.deprecated ? ["@deprecated"] : []),
|
48
|
-
...props.route.tags.map((value) => `@tag ${value}`),
|
49
|
-
`@controller ${props.controller.name}`,
|
50
|
-
`@path ${props.route.path}`,
|
51
|
-
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
52
|
-
].join("\n");
|
53
|
-
|
54
|
-
const writeParameteers =
|
44
|
+
export const writeParameterDeclarations =
|
55
45
|
(components: ISwaggerComponents) =>
|
56
46
|
(importer: ImportProgrammer) =>
|
57
47
|
(props: IProps): ts.ParameterDeclaration[] => [
|
@@ -77,7 +67,7 @@ export namespace ApiFunctionProgrammer {
|
|
77
67
|
...(props.route.query
|
78
68
|
? [
|
79
69
|
IdentifierFactory.parameter(
|
80
|
-
|
70
|
+
props.route.query.key,
|
81
71
|
ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
|
82
72
|
),
|
83
73
|
]
|
@@ -85,19 +75,33 @@ export namespace ApiFunctionProgrammer {
|
|
85
75
|
...(props.route.body
|
86
76
|
? [
|
87
77
|
IdentifierFactory.parameter(
|
88
|
-
|
78
|
+
props.route.body.key,
|
89
79
|
ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
|
90
80
|
),
|
91
81
|
]
|
92
82
|
: []),
|
93
83
|
];
|
94
84
|
|
85
|
+
const writeDescription = (props: IProps): string =>
|
86
|
+
[
|
87
|
+
...(props.route.description?.length
|
88
|
+
? [props.route.description.length, ""]
|
89
|
+
: []),
|
90
|
+
...(props.route.deprecated ? ["@deprecated"] : []),
|
91
|
+
...props.route.tags.map((value) => `@tag ${value}`),
|
92
|
+
`@controller ${props.controller.name}`,
|
93
|
+
`@path ${props.route.path}`,
|
94
|
+
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
95
|
+
].join("\n");
|
96
|
+
|
95
97
|
const writeBody =
|
98
|
+
(config: IMigrateConfig) =>
|
96
99
|
(importer: ImportProgrammer) =>
|
97
100
|
(props: IProps): ts.Statement[] => {
|
98
101
|
const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
|
99
102
|
const contentType: string =
|
100
103
|
props.route.success?.type ?? "application/json";
|
104
|
+
|
101
105
|
const caller = () =>
|
102
106
|
ts.factory.createCallExpression(
|
103
107
|
IdentifierFactory.access(
|
@@ -157,7 +161,7 @@ export namespace ApiFunctionProgrammer {
|
|
157
161
|
ts.factory.createIdentifier(p.key),
|
158
162
|
),
|
159
163
|
...(props.route.query
|
160
|
-
? [ts.factory.createIdentifier(
|
164
|
+
? [ts.factory.createIdentifier(props.route.query.key)]
|
161
165
|
: []),
|
162
166
|
],
|
163
167
|
),
|
@@ -169,9 +173,32 @@ export namespace ApiFunctionProgrammer {
|
|
169
173
|
],
|
170
174
|
true,
|
171
175
|
),
|
172
|
-
...(props.route.body
|
176
|
+
...(props.route.body
|
177
|
+
? [ts.factory.createIdentifier(props.route.body.key)]
|
178
|
+
: []),
|
173
179
|
],
|
174
180
|
);
|
175
|
-
|
181
|
+
if (config.simulate !== true)
|
182
|
+
return [ts.factory.createReturnStatement(caller())];
|
183
|
+
return [
|
184
|
+
ts.factory.createReturnStatement(
|
185
|
+
ts.factory.createConditionalExpression(
|
186
|
+
ts.factory.createIdentifier("!!connection.simulate"),
|
187
|
+
undefined,
|
188
|
+
ts.factory.createCallExpression(
|
189
|
+
ts.factory.createIdentifier(`${props.alias}.simulate`),
|
190
|
+
[],
|
191
|
+
[
|
192
|
+
"connection",
|
193
|
+
...props.route.parameters.map((p) => p.key),
|
194
|
+
...(props.route.query ? [props.route.query.key] : []),
|
195
|
+
...(props.route.body ? [props.route.body.key] : []),
|
196
|
+
].map((key) => ts.factory.createIdentifier(key)),
|
197
|
+
),
|
198
|
+
undefined,
|
199
|
+
caller(),
|
200
|
+
),
|
201
|
+
),
|
202
|
+
];
|
176
203
|
};
|
177
204
|
}
|