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

Fix @nestia/migrate bug and support @HumanRoute() #1166

Merged
merged 2 commits into from
Dec 18, 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
12 changes: 5 additions & 7 deletions deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ const setup = ({ tag, name, directory, version }) => {
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
if (fs.existsSync(`${directory}/package-lock.json`))
fs.rmSync(`${directory}/package-lock.json`);
try {
execute({
cwd: directory,
script: `npm publish --tag ${tag} --access public${tag === "latest" ? " --provenance" : ""}`,
studio: "ignore",
});
} catch {}
execute({
cwd: directory,
script: `npm publish --tag ${tag} --access public${tag === "latest" ? " --provenance" : ""}`,
studio: "ignore",
});

// ROLLBACK THE PACKAGE.JSON
for (const r of rollbacks) r();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@nestia/station",
"version": "4.5.0",
"version": "4.5.1",
"description": "Nestia station",
"scripts": {
"build": "node deploy build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export namespace MigrateNestControllerProgrammer {
[],
[],
controller.routes.map(
MigrateNestMethodProgrammer.write(components)(importer),
MigrateNestMethodProgrammer.write(components)(importer)(controller),
),
);
return [
Expand Down
26 changes: 24 additions & 2 deletions packages/migrate/src/programmers/MigrateNestMethodProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
import { TypeFactory } from "typia/lib/factories/TypeFactory";

import { IHttpMigrateController } from "../structures/IHttpMigrateController";
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { FilePrinter } from "../utils/FilePrinter";
import { StringUtil } from "../utils/StringUtil";
Expand All @@ -15,6 +16,7 @@ export namespace MigrateNestMethodProgrammer {
export const write =
(components: OpenApi.IComponents) =>
(importer: MigrateImportProgrammer) =>
(controller: IHttpMigrateController) =>
(route: IHttpMigrateRoute): ts.MethodDeclaration => {
const output: ts.TypeNode = route.success
? MigrateSchemaProgrammer.write(components)(importer)(
Expand All @@ -24,7 +26,7 @@ export namespace MigrateNestMethodProgrammer {

const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
[
...writeMethodDecorators(components)(importer)(route),
...writeMethodDecorators(components)(importer)(controller)(route),
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
],
Expand Down Expand Up @@ -78,6 +80,7 @@ export namespace MigrateNestMethodProgrammer {
const writeMethodDecorators =
(components: OpenApi.IComponents) =>
(importer: MigrateImportProgrammer) =>
(controller: IHttpMigrateController) =>
(route: IHttpMigrateRoute): ts.Decorator[] => {
const external =
(lib: string) =>
Expand All @@ -99,7 +102,24 @@ export namespace MigrateNestMethodProgrammer {
),
);

// HUMAN-ONLY
if (route.operation()["x-samchon-human"] === true)
decorators.push(
ts.factory.createDecorator(
ts.factory.createCallExpression(
external("@nestia/core")("HumanRoute"),
undefined,
undefined,
),
),
);

// ROUTER
const localPath: string = route.emendedPath
.slice(controller.path.length)
.split("/")
.filter((str) => !!str.length)
.join("/");
const router = (instance: string) =>
ts.factory.createDecorator(
ts.factory.createCallExpression(
Expand All @@ -108,7 +128,9 @@ export namespace MigrateNestMethodProgrammer {
StringUtil.capitalize(route.method),
),
[],
[ts.factory.createStringLiteral(route.path)],
localPath.length
? [ts.factory.createStringLiteral(localPath)]
: undefined,
),
);
if (route.success?.["x-nestia-encrypted"])
Expand Down
Loading