Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare @nestia/migrate's next update #1118

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/migrate",
"version": "0.20.0",
"version": "0.21.0-dev.20241127",
"description": "Migration program from swagger to NestJS",
"typings": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down Expand Up @@ -37,10 +37,10 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/benchmark": "^0.2.3",
"@nestia/core": "^3.19.1",
"@nestia/benchmark": "^0.3.0-dev.20241127-2",
"@nestia/core": "^4.0.0-dev.20241127-4",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "^3.19.1",
"@nestia/fetcher": "^4.0.0-dev.20241127-4",
"@nestjs/common": "^10.3.8",
"@nestjs/core": "^10.3.8",
"@nestjs/platform-express": "^10.3.8",
Expand All @@ -51,13 +51,15 @@
"@types/cli-progress": "^3.11.5",
"@types/express": "^4.17.21",
"@types/inquirer": "^9.0.7",
"@types/multer": "^1.4.12",
"@types/node": "^20.3.3",
"@types/swagger-ui-express": "^4.1.6",
"chalk": "4.1.2",
"cli-progress": "^3.12.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
"express": "^4.19.2",
"multer": "^1.4.5-lts.1",
"rimraf": "^5.0.1",
"rollup": "^4.24.3",
"serialize-error": "^4.1.0",
Expand All @@ -69,13 +71,14 @@
"typescript-transform-paths": "^3.5.2"
},
"dependencies": {
"@nestia/sdk": "^4.0.0-dev.20241127-4",
"@samchon/openapi": "^2.0.0-dev.20241127-2",
"commander": "10.0.0",
"inquirer": "8.2.5",
"prettier": "^3.2.5",
"tstl": "^3.0.0",
"typescript": "~5.6.3",
"typia": "^7.0.0-dev.20241027-2"
"typia": "^7.0.0-dev.20241127-2"
},
"files": [
"lib",
Expand Down
12 changes: 8 additions & 4 deletions packages/migrate/src/programmers/MigrateApiFunctionProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export namespace MigrateApiFunctionProgrammer {
name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
}),
),
)("fetch"),
"fetch",
),
undefined,
[
contentType && contentType !== "multipart/form-data"
Expand All @@ -130,7 +131,8 @@ export namespace MigrateApiFunctionProgrammer {
ts.factory.createSpreadAssignment(
IdentifierFactory.access(
ts.factory.createIdentifier("connection"),
)("headers"),
"headers",
),
),
ts.factory.createPropertyAssignment(
ts.factory.createStringLiteral("Content-Type"),
Expand All @@ -149,14 +151,16 @@ export namespace MigrateApiFunctionProgrammer {
ts.factory.createSpreadAssignment(
IdentifierFactory.access(
ts.factory.createIdentifier(route.accessor.at(-1)!),
)("METADATA"),
"METADATA",
),
),
ts.factory.createPropertyAssignment(
"path",
ts.factory.createCallExpression(
IdentifierFactory.access(
ts.factory.createIdentifier(route.accessor.at(-1)!),
)("path"),
"path",
),
undefined,
[
...route.parameters.map((p) =>
Expand Down
16 changes: 10 additions & 6 deletions packages/migrate/src/programmers/MigrateApiNamespaceProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export namespace MigrateApiNamespaceProgrammer {
ts.factory.createPropertyAssignment(
"request",
route.body
? LiteralFactory.generate({
? LiteralFactory.write({
type: route.body.type,
encrypted: !!route.body["x-nestia-encrypted"],
})
Expand All @@ -126,7 +126,7 @@ export namespace MigrateApiNamespaceProgrammer {
ts.factory.createPropertyAssignment(
"response",
route.method.toUpperCase() !== "HEAD"
? LiteralFactory.generate({
? LiteralFactory.write({
type: route.success?.type ?? "application/json",
encrypted: !!route.success?.["x-nestia-encrypted"],
})
Expand Down Expand Up @@ -306,7 +306,8 @@ export namespace MigrateApiNamespaceProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(
ts.factory.createIdentifier(variables),
)("append"),
"append",
),
undefined,
[
ts.factory.createIdentifier("key"),
Expand All @@ -325,7 +326,8 @@ export namespace MigrateApiNamespaceProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(
ts.factory.createIdentifier(variables),
)("set"),
"set",
),
undefined,
[
ts.factory.createIdentifier("key"),
Expand All @@ -347,7 +349,8 @@ export namespace MigrateApiNamespaceProgrammer {
ExpressionFactory.number(0),
IdentifierFactory.access(
ts.factory.createIdentifier(variables),
)("size"),
"size",
),
),
undefined,
ts.factory.createIdentifier("location"),
Expand All @@ -363,7 +366,8 @@ export namespace MigrateApiNamespaceProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(
ts.factory.createIdentifier(variables),
)("toString"),
"toString",
),
undefined,
undefined,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export namespace MigrateApiSimulatationProgrammer {
name: "typia",
}),
),
)("random"),
"random",
),
[output],
[ts.factory.createIdentifier("g")],
),
Expand Down Expand Up @@ -147,9 +148,9 @@ export namespace MigrateApiSimulatationProgrammer {
];
if (parameters.length === 0) return [];

const validator = StatementFactory.constant(
"assert",
ts.factory.createCallExpression(
const validator = StatementFactory.constant({
name: "assert",
value: ts.factory.createCallExpression(
IdentifierFactory.access(
ts.factory.createIdentifier(
importer.external({
Expand All @@ -158,7 +159,8 @@ export namespace MigrateApiSimulatationProgrammer {
name: "NestiaSimulator",
}),
),
)("assert"),
"assert",
),
undefined,
[
ts.factory.createObjectLiteralExpression(
Expand Down Expand Up @@ -186,14 +188,15 @@ export namespace MigrateApiSimulatationProgrammer {
),
],
),
);
});
const individual = parameters
.map((p) =>
ts.factory.createCallExpression(
(() => {
const base = IdentifierFactory.access(
ts.factory.createIdentifier("assert"),
)(p.category);
p.category,
);
if (p.category !== "param") return base;
return ts.factory.createCallExpression(base, undefined, [
ts.factory.createStringLiteral(p.name),
Expand All @@ -216,7 +219,8 @@ export namespace MigrateApiSimulatationProgrammer {
name: "typia",
}),
),
)("assert"),
"assert",
),
undefined,
[
ts.factory.createIdentifier(
Expand Down Expand Up @@ -251,7 +255,8 @@ export namespace MigrateApiSimulatationProgrammer {
name: "typia",
}),
),
)("is"),
"is",
),
[
ts.factory.createTypeReferenceNode(
importer.external({
Expand Down
8 changes: 4 additions & 4 deletions packages/migrate/src/programmers/MigrateApiStartProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export namespace MigrateApiStartProgrammer {
(document: OpenApi.IDocument) =>
(importer: MigrateImportProgrammer) =>
(route: IHttpMigrateRoute): ts.VariableStatement =>
StatementFactory.constant(
"main",
ts.factory.createArrowFunction(
StatementFactory.constant({
name: "main",
value: ts.factory.createArrowFunction(
[ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
undefined,
[],
Expand All @@ -71,7 +71,7 @@ export namespace MigrateApiStartProgrammer {
true,
),
),
);
});

const writeConnection =
(config: IHttpMigrateProgram.IConfig) =>
Expand Down
68 changes: 50 additions & 18 deletions packages/migrate/src/programmers/MigrateNestMethodProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export namespace MigrateNestMethodProgrammer {
name: "typia",
}),
),
)("random"),
"random",
),
[output],
undefined,
),
Expand Down Expand Up @@ -102,7 +103,8 @@ export namespace MigrateNestMethodProgrammer {
const router = (instance: string) =>
ts.factory.createDecorator(
ts.factory.createCallExpression(
IdentifierFactory.access(external("@nestia/core")(instance))(
IdentifierFactory.access(
external("@nestia/core")(instance),
StringUtil.capitalize(route.method),
),
[],
Expand Down Expand Up @@ -196,9 +198,11 @@ export namespace MigrateNestMethodProgrammer {
),
...(route.headers
? [
writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
components,
)(importer)({
writeDtoParameter({
method: "TypedHeaders",
variable: "headers",
arguments: [],
})(components)(importer)({
required: true,
schema: route.headers.schema,
example: route.headers.example(),
Expand All @@ -208,9 +212,11 @@ export namespace MigrateNestMethodProgrammer {
: []),
...(route.query
? [
writeDtoParameter({ method: "TypedQuery", variable: "query" })(
components,
)(importer)({
writeDtoParameter({
method: "TypedQuery",
variable: "query",
arguments: [],
})(components)(importer)({
required: true,
schema: route.query.schema,
example: route.query.example(),
Expand All @@ -233,6 +239,29 @@ export namespace MigrateNestMethodProgrammer {
? ["TypedFormData", "Body"]
: "TypedBody",
variable: "body",
arguments:
route.body.type === "multipart/form-data"
? [
ts.factory.createArrowFunction(
undefined,
undefined,
[],
undefined,
undefined,
ts.factory.createCallExpression(
ts.factory.createIdentifier(
importer.external({
type: "default",
library: "multer",
name: "Multer",
}),
),
undefined,
undefined,
),
),
]
: [],
})(components)(importer)({
schema: route.body.schema,
required: !(
Expand All @@ -248,7 +277,11 @@ export namespace MigrateNestMethodProgrammer {
];

const writeDtoParameter =
(accessor: { method: string | [string, string]; variable: string }) =>
(accessor: {
method: string | [string, string];
variable: string;
arguments: ts.Expression[];
}) =>
(components: OpenApi.IComponents) =>
(importer: MigrateImportProgrammer) =>
(props: {
Expand All @@ -274,9 +307,9 @@ export namespace MigrateNestMethodProgrammer {
ts.factory.createCallExpression(
typeof accessor.method === "string"
? instance
: IdentifierFactory.access(instance)(accessor.method[1]),
undefined,
: IdentifierFactory.access(instance, accessor.method[1]),
undefined,
accessor.arguments,
),
),
],
Expand Down Expand Up @@ -308,9 +341,10 @@ export namespace MigrateNestMethodProgrammer {
name: "SwaggerExample",
}),
),
)(kind),
kind,
),
[],
[LiteralFactory.generate(media.example)],
[LiteralFactory.write(media.example)],
),
),
]
Expand All @@ -326,12 +360,10 @@ export namespace MigrateNestMethodProgrammer {
name: "SwaggerExample",
}),
),
)(kind),
kind,
),
[],
[
ts.factory.createStringLiteral(key),
LiteralFactory.generate(value),
],
[ts.factory.createStringLiteral(key), LiteralFactory.write(value)],
),
),
),
Expand Down
Loading