Skip to content

Commit

Permalink
Merge pull request #1128 from samchon/feat/ws
Browse files Browse the repository at this point in the history
Fix `@WebSocketRoute.Header()` blocks SDK library generation.
  • Loading branch information
samchon authored Dec 3, 2024
2 parents 89da54e + a36194c commit 5d29e01
Show file tree
Hide file tree
Showing 31 changed files with 489 additions and 149 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"physical-cpu-count": "^2.0.0",
"randexp": "^0.5.3",
"reflect-metadata": "^0.2.2",
"tgrid": "^1.0.3",
"tgrid": "^1.1.0",
"tstl": "^3.0.0",
"typia": "^7.0.1"
},
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.0.1",
"version": "4.0.2",
"description": "Nestia station",
"scripts": {
"build": "node build/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"uuid": "^10.0.0"
},
"dependencies": {
"@nestia/fetcher": "^4.0.0",
"tgrid": "^1.0.3",
"@nestia/fetcher": "^4.0.1",
"tgrid": "^1.1.0",
"tstl": "^3.0.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Downloads](https://img.shields.io/npm/dm/@nestia/fetcher.svg)](https://www.npmjs.com/package/@nestia/fetcher)
[![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
[![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)
[![Discord Badge](https://img.shields.io/badge/discord-NestJS/Nestia-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.com/channels/520622812742811698/1197293125434093701)](https://discord.com/channels/520622812742811698/1181877086797967420)
[![Discord Badge](https://img.shields.io/badge/discord-samchon-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.gg/E94XhzrUCZ)](https://discord.gg/E94XhzrUCZ)

Nestia is a set of helper libraries for NestJS, supporting below features:

Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "4.0.1",
"version": "4.0.2",
"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": "^4.0.1",
"@nestia/fetcher": "^4.0.2",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@samchon/openapi": "^2.0.0",
Expand All @@ -47,12 +47,12 @@
"raw-body": "^2.0.0",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.3",
"tgrid": "^1.0.0",
"tgrid": "^1.1.0",
"typia": "^7.0.1",
"ws": "^7.5.3"
},
"peerDependencies": {
"@nestia/fetcher": ">=4.0.1",
"@nestia/fetcher": ">=4.0.2",
"@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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Downloads](https://img.shields.io/npm/dm/@nestia/fetcher.svg)](https://www.npmjs.com/package/@nestia/fetcher)
[![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
[![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)
[![Discord Badge](https://img.shields.io/badge/discord-NestJS/Nestia-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.com/channels/520622812742811698/1197293125434093701)](https://discord.com/channels/520622812742811698/1181877086797967420)
[![Discord Badge](https://img.shields.io/badge/discord-samchon-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.gg/E94XhzrUCZ)](https://discord.gg/E94XhzrUCZ)

Nestia is a set of helper libraries for NestJS, supporting below features:

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": "4.0.1",
"version": "4.0.2",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"serialize-error": "^4.1.0",
"source-map-support": "^0.5.21",
"swagger-ui-express": "^5.0.0",
"tgrid": "^1.0.3",
"tgrid": "^1.1.0",
"ts-node": "^10.9.1",
"ts-patch": "^3.2.1",
"typescript-transform-paths": "^3.5.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Downloads](https://img.shields.io/npm/dm/@nestia/fetcher.svg)](https://www.npmjs.com/package/@nestia/fetcher)
[![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
[![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)
[![Discord Badge](https://img.shields.io/badge/discord-NestJS/Nestia-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.com/channels/520622812742811698/1197293125434093701)](https://discord.com/channels/520622812742811698/1181877086797967420)
[![Discord Badge](https://img.shields.io/badge/discord-samchon-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.gg/E94XhzrUCZ)](https://discord.gg/E94XhzrUCZ)

Nestia is a set of helper libraries for NestJS, supporting below features:

Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "4.0.1",
"version": "4.0.2",
"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/core": "^4.0.1",
"@nestia/fetcher": "^4.0.1",
"@nestia/core": "^4.0.2",
"@nestia/fetcher": "^4.0.2",
"@samchon/openapi": "^2.0.0",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
Expand All @@ -47,8 +47,8 @@
"typia": "^7.0.1"
},
"peerDependencies": {
"@nestia/core": ">=4.0.1",
"@nestia/fetcher": ">=4.0.1",
"@nestia/core": ">=4.0.2",
"@nestia/fetcher": ">=4.0.2",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
Expand All @@ -68,7 +68,7 @@
"eslint": "^8.29.0",
"eslint-plugin-deprecation": "^1.4.1",
"rimraf": "^3.0.2",
"tgrid": "^1.0.3",
"tgrid": "^1.1.0",
"ts-patch": "^3.2.1",
"typescript": "~5.6.3",
"typescript-transform-paths": "^3.4.4",
Expand Down
11 changes: 7 additions & 4 deletions packages/sdk/src/analyses/ReflectWebSocketOperationAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ export namespace ReflectWebSocketOperationAnalyzer {
description: matched.description,
jsDocTags: matched.jsDocTags,
} satisfies IReflectWebSocketOperationParameter.IParam;

// UNKNOWN TYPE, MAYBE NEW FEATURE
return errors.push(
`@WebSocketRoute.${StringUtil.capitalize(p.category)}() has not been supported yet. How about upgrading the nestia packages?`,
);
else {
if (p.category !== "header")
errors.push(
`@WebSocketRoute.${StringUtil.capitalize(p.category)}() has not been supported yet. How about upgrading the nestia packages?`,
);
return null;
}
})
.filter((p): p is IReflectWebSocketOperationParameter => !!p);

Expand Down
186 changes: 167 additions & 19 deletions test/features/websocket/src/api/functional/calculate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,192 @@
*/
//================================================================
import type { IConnection } from "@nestia/fetcher";
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher";
import { WebSocketConnector } from "tgrid";
import type { Driver } from "tgrid";
import type { Primitive } from "typia";

import type { ICalculator } from "../../structures/ICalculator";
import type { IListener } from "../../structures/IListener";
import type { IPrecision } from "../../structures/IPrecision";
import type { ICalcConfig } from "../../interfaces/ICalcConfig";
import type { ICalcEventListener } from "../../interfaces/ICalcEventListener";
import type { ICompositeCalculator } from "../../interfaces/ICompositeCalculator";
import type { IScientificCalculator } from "../../interfaces/IScientificCalculator";
import type { ISimpleCalculator } from "../../interfaces/ISimpleCalculator";
import type { IStatisticsCalculator } from "../../interfaces/IStatisticsCalculator";

/**
* @controller CalculateController.connect
* @path /calculate
* Health check API (HTTP GET).
* @controller CalculateController.health
* @path GET /calculate/health
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function connect(
connection: IConnection<connect.Header>,
provider: connect.Provider,
): Promise<connect.Output> {
export async function health(connection: IConnection): Promise<health.Output> {
return PlainFetcher.fetch(connection, {
...health.METADATA,
template: health.METADATA.path,
path: health.path(),
});
}
export namespace health {
export type Output = Primitive<string>;

export const METADATA = {
method: "GET",
path: "/calculate/health",
request: null,
response: {
type: "application/json",
encrypted: false,
},
status: 200,
} as const;

export const path = () => "/calculate/health";
}

/**
* Prepare a composite calculator.
*
* @controller CalculateController.composite
* @path /calculate/composite
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function composite(
connection: IConnection<composite.Header>,
provider: composite.Provider,
): Promise<composite.Output> {
const connector: WebSocketConnector<
composite.Header,
composite.Provider,
composite.Listener
> = new WebSocketConnector(connection.headers ?? ({} as any), provider);
await connector.connect(
`${connection.host.endsWith("/") ? connection.host.substring(0, connection.host.length - 1) : connection.host}${composite.path()}`,
);
const driver: Driver<composite.Listener> = connector.getDriver();
return {
connector,
driver,
};
}
export namespace composite {
export type Output = {
connector: WebSocketConnector<Header, Provider, Listener>;
driver: Driver<Listener>;
};
export type Header = ICalcConfig;
export type Provider = ICalcEventListener;
export type Listener = ICompositeCalculator;

export const path = () => "/calculate/composite";
}

/**
* Prepare a simple calculator.
*
* @controller CalculateController.simple
* @path /calculate/simple
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function simple(
connection: IConnection<simple.Header>,
provider: simple.Provider,
): Promise<simple.Output> {
const connector: WebSocketConnector<
simple.Header,
simple.Provider,
simple.Listener
> = new WebSocketConnector(connection.headers ?? ({} as any), provider);
await connector.connect(
`${connection.host.endsWith("/") ? connection.host.substring(0, connection.host.length - 1) : connection.host}${simple.path()}`,
);
const driver: Driver<simple.Listener> = connector.getDriver();
return {
connector,
driver,
};
}
export namespace simple {
export type Output = {
connector: WebSocketConnector<Header, Provider, Listener>;
driver: Driver<Listener>;
};
export type Header = ICalcConfig;
export type Provider = ICalcEventListener;
export type Listener = ISimpleCalculator;

export const path = () => "/calculate/simple";
}

/**
* Prepare a scientific calculator.
*
* @controller CalculateController.scientific
* @path /calculate/scientific
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function scientific(
connection: IConnection<scientific.Header>,
provider: scientific.Provider,
): Promise<scientific.Output> {
const connector: WebSocketConnector<
scientific.Header,
scientific.Provider,
scientific.Listener
> = new WebSocketConnector(connection.headers ?? ({} as any), provider);
await connector.connect(
`${connection.host.endsWith("/") ? connection.host.substring(0, connection.host.length - 1) : connection.host}${scientific.path()}`,
);
const driver: Driver<scientific.Listener> = connector.getDriver();
return {
connector,
driver,
};
}
export namespace scientific {
export type Output = {
connector: WebSocketConnector<Header, Provider, Listener>;
driver: Driver<Listener>;
};
export type Header = ICalcConfig;
export type Provider = ICalcEventListener;
export type Listener = IScientificCalculator;

export const path = () => "/calculate/scientific";
}

/**
* Prepare a statistics calculator.
*
* @controller CalculateController.statistics
* @path /calculate/statistics
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function statistics(
connection: IConnection<statistics.Header>,
provider: statistics.Provider,
): Promise<statistics.Output> {
const connector: WebSocketConnector<
connect.Header,
connect.Provider,
connect.Listener
statistics.Header,
statistics.Provider,
statistics.Listener
> = new WebSocketConnector(connection.headers ?? ({} as any), provider);
await connector.connect(
`${connection.host.endsWith("/") ? connection.host.substring(0, connection.host.length - 1) : connection.host}${connect.path()}`,
`${connection.host.endsWith("/") ? connection.host.substring(0, connection.host.length - 1) : connection.host}${statistics.path()}`,
);
const driver: Driver<connect.Listener> = connector.getDriver();
const driver: Driver<statistics.Listener> = connector.getDriver();
return {
connector,
driver,
};
}
export namespace connect {
export namespace statistics {
export type Output = {
connector: WebSocketConnector<Header, Provider, Listener>;
driver: Driver<Listener>;
};
export type Header = IPrecision;
export type Provider = IListener;
export type Listener = ICalculator;
export type Header = ICalcConfig;
export type Provider = ICalcEventListener;
export type Listener = IStatisticsCalculator;

export const path = () => "/calculate";
export const path = () => "/calculate/statistics";
}
3 changes: 3 additions & 0 deletions test/features/websocket/src/api/interfaces/ICalcConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ICalcConfig {
precision: number;
}
5 changes: 5 additions & 0 deletions test/features/websocket/src/api/interfaces/ICalcEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ICalcEvent {
type: string;
input: number[];
output: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ICalcEvent } from "./ICalcEvent";

export interface ICalcEventListener {
on(event: ICalcEvent): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IScientificCalculator } from "./IScientificCalculator";
import { ISimpleCalculator } from "./ISimpleCalculator";
import { IStatisticsCalculator } from "./IStatisticsCalculator";

export interface ICompositeCalculator extends ISimpleCalculator {
scientific: IScientificCalculator;
statistics: IStatisticsCalculator;
}
Loading

0 comments on commit 5d29e01

Please sign in to comment.