Skip to content

Commit

Permalink
Merge pull request #962 from samchon/features/propagate
Browse files Browse the repository at this point in the history
Add `MigrateFetcher.propagate()` function.
  • Loading branch information
samchon authored Jul 17, 2024
2 parents a0411e7 + 68c814f commit 9337ec3
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 50 deletions.
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": "3.7.0",
"version": "3.7.1",
"description": "Nestia station",
"scripts": {
"build": "node build/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "3.7.0",
"version": "3.7.1",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "../fetcher/nestia-fetcher-3.7.0.tgz",
"@nestia/fetcher": "^3.7.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@samchon/openapi": "^0.4.1",
Expand All @@ -53,7 +53,7 @@
"ws": "^7.5.3"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.7.0",
"@nestia/fetcher": ">=3.7.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/fetcher",
"version": "3.7.0",
"version": "3.7.1",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
41 changes: 41 additions & 0 deletions packages/fetcher/src/MigrateFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IMigrateRoute } from "@samchon/openapi";

import { IConnection } from "./IConnection";
import { IPropagation } from "./IPropagation";
import { PlainFetcher } from "./PlainFetcher";

export namespace MigrateFetcher {
Expand Down Expand Up @@ -48,6 +49,46 @@ export namespace MigrateFetcher {
);
}

export async function propagate(
props: IProps,
): Promise<IPropagation.IBranch<boolean, number, any>> {
const length: number =
props.route.parameters.length +
(props.route.query ? 1 : 0) +
(props.route.body ? 1 : 0);
if (props.arguments.length !== length)
throw new Error(
`Error on MigrateFetcher.propagate(): arguments length is not matched with the route (expected: ${length}, actual: ${props.arguments.length}).`,
);
else if (
props.route.body?.["x-nestia-encrypted"] === true ||
props.route.success?.["x-nestia-encrypted"] === true
)
throw new Error(
`Error on MigrateFetcher.propagate(): encrypted API is not supported yet.`,
);
return PlainFetcher.propagate(
props.connection,
{
method: props.route.method.toUpperCase() as "POST",
path: getPath(props),
template: props.route.path,
status: null,
request: props.route.body
? {
encrypted: false,
type: props.route.body.type,
}
: null,
response: {
encrypted: false,
type: props.route.success?.type ?? "application/json",
},
},
props.route.body ? props.arguments.at(-1) : undefined,
) as Promise<IPropagation.IBranch<boolean, number, any>>;
}

function getPath(props: Pick<IProps, "arguments" | "route">): string {
let path: string = props.route.emendedPath;
props.route.parameters.forEach((p, i) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "3.7.0",
"version": "3.7.1",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -32,8 +32,8 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "../fetcher/nestia-fetcher-3.7.0.tgz",
"@nestia/core": "../core/nestia-core-3.7.0.tgz",
"@nestia/fetcher": "^3.7.1",
"@nestia/core": "^3.7.1",
"@samchon/openapi": "^0.4.1",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
Expand All @@ -47,8 +47,8 @@
"typia": "^6.5.0"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.7.0",
"@nestia/core": ">=3.7.0",
"@nestia/fetcher": ">=3.7.1",
"@nestia/core": ">=3.7.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
Expand Down
56 changes: 27 additions & 29 deletions test/features/migrate/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"articles",
"post"
],
"headers": null,
"parameters": [],
"headers": null,
"query": null,
"body": {
"type": "application/json",
Expand Down Expand Up @@ -39,14 +39,14 @@
"articles",
"patch"
],
"headers": null,
"parameters": [],
"headers": null,
"query": {
"name": "query",
"key": "query",
"schema": {
"$ref": "#/components/schemas/IApiBbsArticles.PatchQuery"
}
},
"name": "query",
"key": "query"
},
"body": null,
"success": {
Expand All @@ -68,18 +68,17 @@
"articles",
"getById"
],
"headers": null,
"parameters": [
{
"name": "id",
"key": "id",
"schema": {
"type": "string",
"format": "uuid",
"description": ""
"format": "uuid"
}
}
],
"headers": null,
"query": null,
"body": null,
"success": {
Expand All @@ -101,18 +100,17 @@
"articles",
"putById"
],
"headers": null,
"parameters": [
{
"name": "id",
"key": "id",
"schema": {
"type": "string",
"format": "uuid",
"description": ""
"format": "uuid"
}
}
],
"headers": null,
"query": null,
"body": {
"type": "application/json",
Expand All @@ -133,8 +131,8 @@
"multipart",
"post"
],
"headers": null,
"parameters": [],
"headers": null,
"query": null,
"body": {
"type": "multipart/form-data",
Expand Down Expand Up @@ -163,14 +161,14 @@
"typed",
"get"
],
"headers": null,
"parameters": [],
"headers": null,
"query": {
"name": "query",
"key": "query",
"schema": {
"$ref": "#/components/schemas/IApiQueryTyped.GetQuery"
}
},
"name": "query",
"key": "query"
},
"body": null,
"success": {
Expand All @@ -192,14 +190,14 @@
"nest",
"get"
],
"headers": null,
"parameters": [],
"headers": null,
"query": {
"name": "query",
"key": "query",
"schema": {
"$ref": "#/components/schemas/IApiQueryNest.GetQuery"
}
},
"name": "query",
"key": "query"
},
"body": null,
"success": {
Expand All @@ -221,14 +219,14 @@
"individual",
"get"
],
"headers": null,
"parameters": [],
"headers": null,
"query": {
"name": "query",
"key": "query",
"schema": {
"$ref": "#/components/schemas/IApiQueryIndividual.GetQuery"
}
},
"name": "query",
"key": "query"
},
"body": null,
"success": {
Expand All @@ -250,14 +248,14 @@
"composite",
"get"
],
"headers": null,
"parameters": [],
"headers": null,
"query": {
"name": "query",
"key": "query",
"schema": {
"$ref": "#/components/schemas/IApiQueryComposite.GetQuery"
}
},
"name": "query",
"key": "query"
},
"body": null,
"success": {
Expand All @@ -279,8 +277,8 @@
"body",
"post"
],
"headers": null,
"parameters": [],
"headers": null,
"query": null,
"body": {
"type": "application/x-www-form-urlencoded",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IPropagation } from "@nestia/fetcher";
import { MigrateFetcher } from "@nestia/fetcher/lib/MigrateFetcher";
import typia from "typia";
import { v4 } from "uuid";
Expand All @@ -15,4 +16,12 @@ export const test_api_bbs_article_at = async (
arguments: [v4()],
});
typia.assert(article);

const propa: IPropagation.IBranch<boolean, number, any> =
await MigrateFetcher.propagate({
route: props.route("get", "/bbs/articles/{id}"),
connection: props.connection,
arguments: [v4()],
});
typia.assert(propa);
};
2 changes: 1 addition & 1 deletion test/features/migrate/swagger.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import type { IMember } from "../../../../api/structures/IMember";
import type { INotFound } from "../../../../api/structures/INotFound";

export const test_api_members_login = async (connection: api.IConnection) => {
const output: IPropagation<{
201: IMember;
403: IForbidden;
404: INotFound;
422: IForbidden.IExpired;
}> = await api.functional.members.login(
const output: IPropagation<
{
201: IMember;
403: IForbidden;
404: INotFound;
422: IForbidden.IExpired;
},
201
> = await api.functional.members.login(
connection,
typia.random<IMember.ILogin>(),
);
Expand Down
8 changes: 4 additions & 4 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@samchon/nestia-test",
"version": "3.7.0",
"version": "3.7.1",
"description": "Test program of Nestia",
"main": "index.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/sdk": "../packages/sdk/nestia-sdk-3.7.0.tgz",
"@nestia/sdk": "^3.7.1",
"@nestjs/swagger": "^7.1.2",
"@samchon/openapi": "^0.4.1",
"@types/express": "^4.17.17",
Expand All @@ -40,9 +40,9 @@
},
"dependencies": {
"@fastify/multipart": "^8.1.0",
"@nestia/core": "../packages/core/nestia-core-3.7.0.tgz",
"@nestia/core": "^3.7.1",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "../packages/fetcher/nestia-fetcher-3.7.0.tgz",
"@nestia/fetcher": "^3.7.1",
"@nestjs/common": "^10.3.5",
"@nestjs/core": "^10.3.5",
"@nestjs/platform-express": "^10.3.5",
Expand Down

0 comments on commit 9337ec3

Please sign in to comment.