diff --git a/package.json b/package.json index 298bb1936..612f778b3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@nestia/station", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "description": "Nestia station", "scripts": { "build": "node deploy build", diff --git a/packages/core/package.json b/packages/core/package.json index d9140a82a..e160295ab 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/core", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "description": "Super-fast validation decorators of NestJS", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -52,7 +52,7 @@ "ws": "^7.5.3" }, "peerDependencies": { - "@nestia/fetcher": ">=4.4.0-dev.20241216", + "@nestia/fetcher": ">=4.4.0-dev.20241216-3", "@nestjs/common": ">=7.0.1", "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12", diff --git a/packages/core/src/decorators/TypedParam.ts b/packages/core/src/decorators/TypedParam.ts index f17e0da9f..3ea0a6a8f 100644 --- a/packages/core/src/decorators/TypedParam.ts +++ b/packages/core/src/decorators/TypedParam.ts @@ -5,7 +5,7 @@ import { } from "@nestjs/common"; import type express from "express"; import type { FastifyRequest } from "fastify"; -import typia, { TypeGuardError } from "typia"; +import typia, { IValidation, TypeGuardError } from "typia"; import { NoTransformConfigurationError } from "./NoTransformConfigurationError"; @@ -35,6 +35,7 @@ import { NoTransformConfigurationError } from "./NoTransformConfigurationError"; export function TypedParam( name: string, assert?: (value: string) => T, + validate?: boolean, ): ParameterDecorator { if (assert === undefined) { NoTransformConfigurationError("TypedParam"); @@ -52,14 +53,24 @@ export function TypedParam( try { return assert(str); } catch (exp) { - if (typia.is(exp)) - throw new BadRequestException({ - path: exp.path, - reason: exp.message, + if (typia.is(exp)) { + const trace: IValidation.IError = { + path: exp.path ?? "$input", expected: exp.expected, value: exp.value, + }; + throw new BadRequestException({ message: `Invalid URL parameter value on "${name}".`, + ...(validate === true + ? { + errors: [trace], + } + : { + ...trace, + reason: exp.message, + }), }); + } throw exp; } })(name); diff --git a/packages/core/src/options/INestiaTransformOptions.ts b/packages/core/src/options/INestiaTransformOptions.ts index 595a6a874..11e2eb843 100644 --- a/packages/core/src/options/INestiaTransformOptions.ts +++ b/packages/core/src/options/INestiaTransformOptions.ts @@ -1,6 +1,12 @@ export interface INestiaTransformOptions { - validate?: // NORMAL - | "assert" + validate?: INestiaTransformOptions.Validate; + stringify?: INestiaTransformOptions.Stringify | null; + throws?: boolean; +} +export namespace INestiaTransformOptions { + export type Validate = + // NORMAL + | "assert" | "is" | "validate" // STRICT @@ -13,12 +19,11 @@ export interface INestiaTransformOptions { // PRUNE | "assertPrune" | "validatePrune"; - stringify?: + + export type Stringify = | "stringify" | "assert" | "is" | "validate" - | "validate.log" - | null; - throws?: boolean; + | "validate.log"; } diff --git a/packages/core/src/programmers/TypedParamProgrammer.ts b/packages/core/src/programmers/TypedParamProgrammer.ts index 83df17c5a..feec2596c 100644 --- a/packages/core/src/programmers/TypedParamProgrammer.ts +++ b/packages/core/src/programmers/TypedParamProgrammer.ts @@ -25,6 +25,9 @@ export namespace TypedParamProgrammer { type: props.type, name: undefined, }), + ...(props.context.options?.validate?.startsWith("validate") + ? [ts.factory.createTrue()] + : []), ]; }; } diff --git a/packages/editor/package.json b/packages/editor/package.json index 829b37430..5f3424c57 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/editor", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "typings": "lib/index.d.ts", "main": "lib/index.js", "module": "lib/index.mjs", diff --git a/packages/fetcher/package.json b/packages/fetcher/package.json index 9c5c31141..da2da5536 100644 --- a/packages/fetcher/package.json +++ b/packages/fetcher/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/fetcher", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "description": "Fetcher library of Nestia SDK", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/migrate/package.json b/packages/migrate/package.json index c35e9724b..e909fea15 100644 --- a/packages/migrate/package.json +++ b/packages/migrate/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/migrate", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "description": "Migration program from swagger to NestJS", "typings": "lib/index.d.ts", "main": "lib/index.js", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 0899c9896..8e139076c 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/sdk", - "version": "4.4.0-dev.20241216", + "version": "4.4.0-dev.20241216-3", "description": "Nestia SDK and Swagger generator", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -47,8 +47,8 @@ "typia": "^7.4.0" }, "peerDependencies": { - "@nestia/core": ">=4.4.0-dev.20241216", - "@nestia/fetcher": ">=4.4.0-dev.20241216", + "@nestia/core": ">=4.4.0-dev.20241216-3", + "@nestia/fetcher": ">=4.4.0-dev.20241216-3", "@nestjs/common": ">=7.0.1", "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12", diff --git a/test/features/param-validate/nestia.config.ts b/test/features/param-validate/nestia.config.ts new file mode 100644 index 000000000..057c9c13d --- /dev/null +++ b/test/features/param-validate/nestia.config.ts @@ -0,0 +1,16 @@ +import { INestiaConfig } from "@nestia/sdk"; + +export const NESTIA_CONFIG: INestiaConfig = { + input: ["src/controllers"], + output: "src/api", + swagger: { + beautify: true, + output: "swagger.json", + security: { + bearer: { + type: "apiKey", + }, + }, + }, +}; +export default NESTIA_CONFIG; diff --git a/test/features/param-validate/src/Backend.ts b/test/features/param-validate/src/Backend.ts new file mode 100644 index 000000000..7e69bc6bd --- /dev/null +++ b/test/features/param-validate/src/Backend.ts @@ -0,0 +1,28 @@ +import core from "@nestia/core"; +import { INestApplication } from "@nestjs/common"; +import { NestFactory } from "@nestjs/core"; + +export class Backend { + private application_?: INestApplication; + + public async open(): Promise { + this.application_ = await NestFactory.create( + await core.EncryptedModule.dynamic(__dirname + "/controllers", { + key: "A".repeat(32), + iv: "B".repeat(16), + }), + { logger: false }, + ); + await core.WebSocketAdaptor.upgrade(this.application_); + await this.application_.listen(37_000); + } + + public async close(): Promise { + if (this.application_ === undefined) return; + + const app = this.application_; + await app.close(); + + delete this.application_; + } +} diff --git a/test/features/param-validate/src/api/HttpError.ts b/test/features/param-validate/src/api/HttpError.ts new file mode 100644 index 000000000..5df328ae4 --- /dev/null +++ b/test/features/param-validate/src/api/HttpError.ts @@ -0,0 +1 @@ +export { HttpError } from "@nestia/fetcher"; diff --git a/test/features/param-validate/src/api/IConnection.ts b/test/features/param-validate/src/api/IConnection.ts new file mode 100644 index 000000000..107bdb8f8 --- /dev/null +++ b/test/features/param-validate/src/api/IConnection.ts @@ -0,0 +1 @@ +export type { IConnection } from "@nestia/fetcher"; diff --git a/test/features/param-validate/src/api/Primitive.ts b/test/features/param-validate/src/api/Primitive.ts new file mode 100644 index 000000000..ebdcd7620 --- /dev/null +++ b/test/features/param-validate/src/api/Primitive.ts @@ -0,0 +1 @@ +export type { Primitive } from "typia"; diff --git a/test/features/param-validate/src/api/Resolved.ts b/test/features/param-validate/src/api/Resolved.ts new file mode 100644 index 000000000..7cf4920b0 --- /dev/null +++ b/test/features/param-validate/src/api/Resolved.ts @@ -0,0 +1 @@ +export type { Resolved } from "typia"; diff --git a/test/features/param-validate/src/api/functional/calculate/index.ts b/test/features/param-validate/src/api/functional/calculate/index.ts new file mode 100644 index 000000000..98352bca5 --- /dev/null +++ b/test/features/param-validate/src/api/functional/calculate/index.ts @@ -0,0 +1,51 @@ +/** + * @packageDocumentation + * @module api.functional.calculate + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +//================================================================ +import type { IConnection } from "@nestia/fetcher"; +import { WebSocketConnector } from "tgrid"; +import type { Driver } from "tgrid"; +import type { Format } from "typia/lib/tags/Format"; + +import type { ICalculator } from "../../structures/ICalculator"; +import type { IListener } from "../../structures/IListener"; +import type { IPrecision } from "../../structures/IPrecision"; + +/** + * @controller CalculateController.connect + * @path /calculate/:id + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function connect( + connection: IConnection, + id: string & Format<"uuid">, + provider: connect.Provider, +): Promise { + const connector: WebSocketConnector< + connect.Header, + connect.Provider, + connect.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(id)}`, + ); + const driver: Driver = connector.getDriver(); + return { + connector, + driver, + }; +} +export namespace connect { + export type Output = { + connector: WebSocketConnector; + driver: Driver; + }; + export type Header = IPrecision; + export type Provider = IListener; + export type Listener = ICalculator; + + export const path = (id: string & Format<"uuid">) => + `/calculate/${encodeURIComponent(id?.toString() ?? "null")}`; +} diff --git a/test/features/param-validate/src/api/functional/health/index.ts b/test/features/param-validate/src/api/functional/health/index.ts new file mode 100644 index 000000000..36ae23908 --- /dev/null +++ b/test/features/param-validate/src/api/functional/health/index.ts @@ -0,0 +1,35 @@ +/** + * @packageDocumentation + * @module api.functional.health + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +//================================================================ +import type { IConnection } from "@nestia/fetcher"; +import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; + +/** + * @controller HealthController.get + * @path GET /health + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function get(connection: IConnection): Promise { + return PlainFetcher.fetch(connection, { + ...get.METADATA, + template: get.METADATA.path, + path: get.path(), + }); +} +export namespace get { + export const METADATA = { + method: "GET", + path: "/health", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = () => "/health"; +} diff --git a/test/features/param-validate/src/api/functional/index.ts b/test/features/param-validate/src/api/functional/index.ts new file mode 100644 index 000000000..63fd4d7d0 --- /dev/null +++ b/test/features/param-validate/src/api/functional/index.ts @@ -0,0 +1,10 @@ +/** + * @packageDocumentation + * @module api.functional + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +//================================================================ +export * as calculate from "./calculate"; +export * as health from "./health"; +export * as performance from "./performance"; +export * as param from "./param"; diff --git a/test/features/param-validate/src/api/functional/param/index.ts b/test/features/param-validate/src/api/functional/param/index.ts new file mode 100644 index 000000000..6c0a6cd38 --- /dev/null +++ b/test/features/param-validate/src/api/functional/param/index.ts @@ -0,0 +1,391 @@ +/** + * @packageDocumentation + * @module api.functional.param + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +//================================================================ +import type { IConnection } from "@nestia/fetcher"; +import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; +import type { Primitive } from "typia"; +import type { Format } from "typia/lib/tags/Format"; + +/** + * Composite path parameters. + * + * @param value The first value. + * The first string value. + * @param value2 The second value. + * The second string value. + * @returns Concatenated string. + * + * @controller TypedParamController.composite + * @path GET /param/:value/composite/:value2 + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function composite( + connection: IConnection, + value: string, + value2: string, +): Promise { + return PlainFetcher.fetch(connection, { + ...composite.METADATA, + template: composite.METADATA.path, + path: composite.path(value, value2), + }); +} +export namespace composite { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/composite/:value2", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: string, value2: string) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/composite/${encodeURIComponent(value2?.toString() ?? "null")}`; +} + +/** + * Boolean path parameter. + * + * @param value The boolean value. + * The boolean value as a path parameter. + * @returns The same boolean value. + * + * @controller TypedParamController.boolean + * @path GET /param/:value/boolean + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function boolean( + connection: IConnection, + value: false | true, +): Promise { + return PlainFetcher.fetch(connection, { + ...boolean.METADATA, + template: boolean.METADATA.path, + path: boolean.path(value), + }); +} +export namespace boolean { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/boolean", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: false | true) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/boolean`; +} + +/** + * The number. + * @controller TypedParamController.number + * @path GET /param/:value/number + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function number( + connection: IConnection, + value: number, +): Promise { + return PlainFetcher.fetch(connection, { + ...number.METADATA, + template: number.METADATA.path, + path: number.path(value), + }); +} +export namespace number { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/number", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: number) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/number`; +} + +/** + * The bigint. + * @controller TypedParamController.bigint + * @path GET /param/:value/bigint + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function bigint( + connection: IConnection, + value: bigint, +): Promise { + return PlainFetcher.fetch(connection, { + ...bigint.METADATA, + template: bigint.METADATA.path, + path: bigint.path(value), + }); +} +export namespace bigint { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/bigint", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: bigint) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/bigint`; +} + +/** + * The string. + * @controller TypedParamController.string + * @path GET /param/:value/string + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function string( + connection: IConnection, + value: string, +): Promise { + return PlainFetcher.fetch(connection, { + ...string.METADATA, + template: string.METADATA.path, + path: string.path(value), + }); +} +export namespace string { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/string", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: string) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/string`; +} + +/** + * @controller TypedParamController.nullable + * @path GET /param/:value/nullable + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function nullable( + connection: IConnection, + value: null | string, +): Promise { + return PlainFetcher.fetch(connection, { + ...nullable.METADATA, + template: nullable.METADATA.path, + path: nullable.path(value), + }); +} +export namespace nullable { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/nullable", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: null | string) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/nullable`; +} + +/** + * @controller TypedParamController.literal + * @path GET /param/:value/literal + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function literal( + connection: IConnection, + value: "A" | "B" | "C", +): Promise { + return PlainFetcher.fetch(connection, { + ...literal.METADATA, + template: literal.METADATA.path, + path: literal.path(value), + }); +} +export namespace literal { + export type Output = Primitive<"A" | "B" | "C">; + + export const METADATA = { + method: "GET", + path: "/param/:value/literal", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: "A" | "B" | "C") => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/literal`; +} + +/** + * @controller TypedParamController.uuid + * @path GET /param/:value/uuid + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function uuid( + connection: IConnection, + value: string & Format<"uuid">, +): Promise { + return PlainFetcher.fetch(connection, { + ...uuid.METADATA, + template: uuid.METADATA.path, + path: uuid.path(value), + }); +} +export namespace uuid { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/uuid", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: string & Format<"uuid">) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/uuid`; +} + +/** + * @controller TypedParamController.date + * @path GET /param/:value/date + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function date( + connection: IConnection, + value: string & Format<"date">, +): Promise { + return PlainFetcher.fetch(connection, { + ...date.METADATA, + template: date.METADATA.path, + path: date.path(value), + }); +} +export namespace date { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/date", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: string & Format<"date">) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/date`; +} + +/** + * @controller TypedParamController.uuid_nullable + * @path GET /param/:value/uuid_nullable + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function uuid_nullable( + connection: IConnection, + value: null | (string & Format<"uuid">), +): Promise { + return PlainFetcher.fetch(connection, { + ...uuid_nullable.METADATA, + template: uuid_nullable.METADATA.path, + path: uuid_nullable.path(value), + }); +} +export namespace uuid_nullable { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/uuid_nullable", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: null | (string & Format<"uuid">)) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/uuid_nullable`; +} + +/** + * @controller TypedParamController.date_nullable + * @path GET /param/:value/date_nullable + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function date_nullable( + connection: IConnection, + value: null | (string & Format<"date">), +): Promise { + return PlainFetcher.fetch(connection, { + ...date_nullable.METADATA, + template: date_nullable.METADATA.path, + path: date_nullable.path(value), + }); +} +export namespace date_nullable { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/param/:value/date_nullable", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = (value: null | (string & Format<"date">)) => + `/param/${encodeURIComponent(value?.toString() ?? "null")}/date_nullable`; +} diff --git a/test/features/param-validate/src/api/functional/performance/index.ts b/test/features/param-validate/src/api/functional/performance/index.ts new file mode 100644 index 000000000..c4be76f56 --- /dev/null +++ b/test/features/param-validate/src/api/functional/performance/index.ts @@ -0,0 +1,40 @@ +/** + * @packageDocumentation + * @module api.functional.performance + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +//================================================================ +import type { IConnection } from "@nestia/fetcher"; +import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; +import type { Primitive } from "typia"; + +import type { IPerformance } from "../../structures/IPerformance"; + +/** + * @controller PerformanceController.get + * @path GET /performance + * @nestia Generated by Nestia - https://github.com/samchon/nestia + */ +export async function get(connection: IConnection): Promise { + return PlainFetcher.fetch(connection, { + ...get.METADATA, + template: get.METADATA.path, + path: get.path(), + }); +} +export namespace get { + export type Output = Primitive; + + export const METADATA = { + method: "GET", + path: "/performance", + request: null, + response: { + type: "application/json", + encrypted: false, + }, + status: 200, + } as const; + + export const path = () => "/performance"; +} diff --git a/test/features/param-validate/src/api/index.ts b/test/features/param-validate/src/api/index.ts new file mode 100644 index 000000000..1705f43c8 --- /dev/null +++ b/test/features/param-validate/src/api/index.ts @@ -0,0 +1,4 @@ +import * as api from "./module"; + +export * from "./module"; +export default api; diff --git a/test/features/param-validate/src/api/module.ts b/test/features/param-validate/src/api/module.ts new file mode 100644 index 000000000..2137b4473 --- /dev/null +++ b/test/features/param-validate/src/api/module.ts @@ -0,0 +1,6 @@ +export type * from "./IConnection"; +export type * from "./Primitive"; +export type * from "./Resolved"; +export * from "./HttpError"; + +export * as functional from "./functional"; diff --git a/test/features/param-validate/src/api/structures/ICalculator.ts b/test/features/param-validate/src/api/structures/ICalculator.ts new file mode 100644 index 000000000..f7315a089 --- /dev/null +++ b/test/features/param-validate/src/api/structures/ICalculator.ts @@ -0,0 +1,9 @@ +import { tags } from "typia"; + +export interface ICalculator { + getId(): string & tags.Format<"uuid">; + plus(x: number, y: number): number; + minus(x: number, y: number): number; + multiply(x: number, y: number): number; + divide(x: number, y: number): number; +} diff --git a/test/features/param-validate/src/api/structures/IListener.ts b/test/features/param-validate/src/api/structures/IListener.ts new file mode 100644 index 000000000..27bf00791 --- /dev/null +++ b/test/features/param-validate/src/api/structures/IListener.ts @@ -0,0 +1,11 @@ +export interface IListener { + on(event: IListener.IEvent): void; +} +export namespace IListener { + export interface IEvent { + operator: "plus" | "minus" | "multiply" | "divide"; + x: number; + y: number; + z: number; + } +} diff --git a/test/features/param-validate/src/api/structures/IPerformance.ts b/test/features/param-validate/src/api/structures/IPerformance.ts new file mode 100644 index 000000000..22b8f2840 --- /dev/null +++ b/test/features/param-validate/src/api/structures/IPerformance.ts @@ -0,0 +1,10 @@ +/** + * Performance info. + * + * @author Samchon + */ +export interface IPerformance { + cpu: NodeJS.CpuUsage; + memory: NodeJS.MemoryUsage; + resource: NodeJS.ResourceUsage; +} diff --git a/test/features/param-validate/src/api/structures/IPrecision.ts b/test/features/param-validate/src/api/structures/IPrecision.ts new file mode 100644 index 000000000..5fbe8947d --- /dev/null +++ b/test/features/param-validate/src/api/structures/IPrecision.ts @@ -0,0 +1,3 @@ +export interface IPrecision { + value: number; +} diff --git a/test/features/param-validate/src/api/structures/ISystem.ts b/test/features/param-validate/src/api/structures/ISystem.ts new file mode 100644 index 000000000..0e135bede --- /dev/null +++ b/test/features/param-validate/src/api/structures/ISystem.ts @@ -0,0 +1,81 @@ +/** + * System Information. + * + * @author Jeongho Nam + */ +export interface ISystem { + /** + * Random Unique ID. + */ + uid: number; + + /** + * `process.argv` + */ + arguments: string[]; + + /** + * Git commit info. + */ + commit: ISystem.ICommit; + + /** + * `package.json` + */ + package: ISystem.IPackage; + + /** + * Creation time of this server. + */ + created_at: string; +} + +export namespace ISystem { + /** + * Git commit info. + */ + export interface ICommit { + shortHash: string; + branch: string; + hash: string; + subject: string; + sanitizedSubject: string; + body: string; + author: ICommit.IUser; + committer: ICommit.IUser; + authored_at: string; + commited_at: string; + notes?: string; + tags: string[]; + } + export namespace ICommit { + /** + * Git user account info. + */ + export interface IUser { + name: string; + email: string; + } + } + + /** + * NPM package info. + */ + export interface IPackage { + name: string; + version: string; + description: string; + main?: string; + typings?: string; + scripts: Record; + repository: { type: "git"; url: string }; + author: string; + license: string; + bugs: { url: string }; + homepage: string; + devDependencies?: Record; + dependencies: Record; + publishConfig?: { registry: string }; + files?: string[]; + } +} diff --git a/test/features/param-validate/src/controllers/CalculateController.ts b/test/features/param-validate/src/controllers/CalculateController.ts new file mode 100644 index 000000000..86fdb3329 --- /dev/null +++ b/test/features/param-validate/src/controllers/CalculateController.ts @@ -0,0 +1,44 @@ +import core from "@nestia/core"; +import { Controller } from "@nestjs/common"; +import { Driver, WebSocketAcceptor } from "tgrid"; +import { tags } from "typia"; + +import { ICalculator } from "@api/lib/structures/ICalculator"; +import { IListener } from "@api/lib/structures/IListener"; +import { IPrecision } from "@api/lib/structures/IPrecision"; + +@Controller("calculate") +export class CalculateController { + @core.WebSocketRoute(":id") + public async connect( + @core.WebSocketRoute.Param("id") id: string & tags.Format<"uuid">, + @core.WebSocketRoute.Acceptor() + adaptor: WebSocketAcceptor, + @core.WebSocketRoute.Driver() + driver: Driver, + ): Promise { + await adaptor.accept({ + getId: () => id, + plus: (x, y) => { + const z: number = x + y; + driver.on({ operator: "plus", x, y, z }).catch(() => {}); + return z; + }, + minus: (x, y) => { + const z: number = x - y; + driver.on({ operator: "minus", x, y, z }).catch(() => {}); + return z; + }, + multiply: (x, y) => { + const z: number = x * y; + driver.on({ operator: "multiply", x, y, z }).catch(() => {}); + return z; + }, + divide: (x, y) => { + const z: number = x / y; + driver.on({ operator: "divide", x, y, z }).catch(() => {}); + return z; + }, + }); + } +} diff --git a/test/features/param-validate/src/controllers/HealthController.ts b/test/features/param-validate/src/controllers/HealthController.ts new file mode 100644 index 000000000..f7e06aef4 --- /dev/null +++ b/test/features/param-validate/src/controllers/HealthController.ts @@ -0,0 +1,8 @@ +import core from "@nestia/core"; +import { Controller } from "@nestjs/common"; + +@Controller("health") +export class HealthController { + @core.TypedRoute.Get() + public get(): void {} +} diff --git a/test/features/param-validate/src/controllers/PerformanceController.ts b/test/features/param-validate/src/controllers/PerformanceController.ts new file mode 100644 index 000000000..616548cf8 --- /dev/null +++ b/test/features/param-validate/src/controllers/PerformanceController.ts @@ -0,0 +1,16 @@ +import core from "@nestia/core"; +import { Controller } from "@nestjs/common"; + +import { IPerformance } from "@api/lib/structures/IPerformance"; + +@Controller("performance") +export class PerformanceController { + @core.TypedRoute.Get() + public async get(): Promise { + return { + cpu: process.cpuUsage(), + memory: process.memoryUsage(), + resource: process.resourceUsage(), + }; + } +} diff --git a/test/features/param-validate/src/controllers/TypedParamController.ts b/test/features/param-validate/src/controllers/TypedParamController.ts new file mode 100644 index 000000000..82dc1aaf0 --- /dev/null +++ b/test/features/param-validate/src/controllers/TypedParamController.ts @@ -0,0 +1,119 @@ +import core from "@nestia/core"; +import { Controller } from "@nestjs/common"; +import { tags } from "typia"; + +@Controller("param") +export class TypedParamController { + /** + * Composite path parameters. + * + * @param value The first value. + * The first string value. + * @param value2 The second value. + * The second string value. + * @returns Concatenated string. + */ + @core.TypedRoute.Get(":value/composite/:value2") + public composite( + @core.TypedParam("value") value: string, + @core.TypedParam("value2") value2: string, + ): string { + return value + value2; + } + + /** + * Boolean path parameter. + * + * @param value The boolean value. + * The boolean value as a path parameter. + * @returns The same boolean value. + */ + @core.TypedRoute.Get(":value/boolean") + public boolean(@core.TypedParam("value") value: boolean): boolean { + return value; + } + + /** + * The number. + */ + @core.TypedRoute.Get(":value/number") + public number( + /** + * Description in the parameter. + */ + @core.TypedParam("value") + value: number, + ): number { + return value; + } + + /** + * The bigint. + */ + @core.TypedRoute.Get(":value/bigint") + public bigint( + /** + * Description in the parameter. + */ + @core.TypedParam("value") + value: bigint, + ): number { + return Number(value); + } + + /** + * The string. + */ + @core.TypedRoute.Get(":value/string") + public string( + /** + * @title Yaho + * @description Yoohoo + */ + @core.TypedParam("value") value: string, + ): string { + return value; + } + + @core.TypedRoute.Get(":value/nullable") + public nullable( + @core.TypedParam("value") value: string | null, + ): string | null { + return value; + } + + @core.TypedRoute.Get(":value/literal") + public literal( + @core.TypedParam("value") value: "A" | "B" | "C", + ): "A" | "B" | "C" { + return value; + } + + @core.TypedRoute.Get(":value/uuid") + public uuid( + @core.TypedParam("value") value: string & tags.Format<"uuid">, + ): string { + return value; + } + + @core.TypedRoute.Get(":value/date") + public date( + @core.TypedParam("value") value: string & tags.Format<"date">, + ): string { + return value; + } + + @core.TypedRoute.Get(":value/uuid_nullable") + public uuid_nullable( + @core.TypedParam("value") value: (string & tags.Format<"uuid">) | null, + ): string | null { + return value; + } + + @core.TypedRoute.Get(":value/date_nullable") + public date_nullable( + @core.TypedParam("value") value: (string & tags.Format<"date">) | null, + ): string | null { + return value; + } +} diff --git a/test/features/param-validate/src/test/features/api/test_api_calculate.ts b/test/features/param-validate/src/test/features/api/test_api_calculate.ts new file mode 100644 index 000000000..7cba7e1ca --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_calculate.ts @@ -0,0 +1,55 @@ +import { TestValidator } from "@nestia/e2e"; +import { sleep_for } from "tstl"; +import typia from "typia"; +import { v4 } from "uuid"; + +import api from "@api"; +import { IListener } from "@api/lib/structures/IListener"; + +export const test_api_calculate = async ( + connection: api.IConnection, +): Promise => { + const events: IListener.IEvent[] = []; + const listener: IListener = { + on: (e) => events.push(e), + }; + const id: string = v4(); + const { connector, driver } = await api.functional.calculate.connect( + connection, + id, + listener, + ); + const expected: IListener.IEvent[] = new Array(100).fill(0).map(() => { + const operator = typia.random(); + const x: number = 10; + const y: number = 5; + return { + operator, + x, + y, + z: + operator === "plus" + ? x + y + : operator === "minus" + ? x - y + : operator === "divide" + ? x / y + : operator === "multiply" + ? x * y + : 0, + }; + }); + try { + for (const e of expected) { + const z: number = await driver[e.operator](e.x, e.y); + TestValidator.equals("result")(z)(e.z); + } + await TestValidator.equals("id")(id)(await driver.getId()); + await sleep_for(100); + TestValidator.equals("events")(events)(expected); + } catch (exp) { + throw exp; + } finally { + await connector.close(); + } +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_health_check.ts b/test/features/param-validate/src/test/features/api/test_api_health_check.ts new file mode 100644 index 000000000..4dceb4cec --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_health_check.ts @@ -0,0 +1,5 @@ +import api from "@api"; + +export const test_api_monitor_health_check = ( + connection: api.IConnection, +): Promise => api.functional.health.get(connection); diff --git a/test/features/param-validate/src/test/features/api/test_api_param_bigint.ts b/test/features/param-validate/src/test/features/api/test_api_param_bigint.ts new file mode 100644 index 000000000..27b0274a9 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_bigint.ts @@ -0,0 +1,21 @@ +import { TestValidator } from "@nestia/e2e"; +import typia from "typia"; + +import api from "@api"; + +export const test_api_param_number = async ( + connection: api.IConnection, +): Promise => { + const value: number = await api.functional.param.bigint( + connection, + BigInt(1), + ); + typia.assert(value); + + await TestValidator.httpError("boolean")(400)(() => + api.functional.param.bigint(connection, true as any), + ); + await TestValidator.httpError("string")(400)(() => + api.functional.param.bigint(connection, "string" as any), + ); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_boolean.ts b/test/features/param-validate/src/test/features/api/test_api_param_boolean.ts new file mode 100644 index 000000000..1d0344864 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_boolean.ts @@ -0,0 +1,25 @@ +import { TestValidator } from "@nestia/e2e"; +import typia from "typia"; + +import api from "@api"; + +export const test_api_param_boolean = async ( + connection: api.IConnection, +): Promise => { + const value: boolean = await api.functional.param.boolean(connection, false); + typia.assert(value); + + TestValidator.equals("false")(false)( + await api.functional.param.boolean(connection, 0 as any), + ); + TestValidator.equals("true")(true)( + await api.functional.param.boolean(connection, 1 as any), + ); + + await TestValidator.httpError("number")(400)(() => + api.functional.param.boolean(connection, 2 as any), + ); + await TestValidator.httpError("string")(400)(() => + api.functional.param.boolean(connection, "string" as any), + ); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_date.ts b/test/features/param-validate/src/test/features/api/test_api_param_date.ts new file mode 100644 index 000000000..49c1bdbd2 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_date.ts @@ -0,0 +1,27 @@ +import { TestValidator } from "@nestia/e2e"; + +import api from "@api"; + +export const test_api_param_date = async ( + connection: api.IConnection, +): Promise => { + const date = random(); + const value = await api.functional.param.date(connection, date); + TestValidator.equals("date")(date)(value); + + await TestValidator.error("null")(() => + api.functional.param.date(connection, null!), + ); + await TestValidator.error("invalid")(() => + api.functional.param.date(connection, "20140102"), + ); +}; + +const random = () => { + const date: Date = new Date(Math.floor(Math.random() * Date.now() * 2)); + return [ + date.getFullYear(), + (date.getMonth() + 1).toString().padStart(2, "0"), + date.getDate().toString().padStart(2, "0"), + ].join("-"); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_date_nullable.ts b/test/features/param-validate/src/test/features/api/test_api_param_date_nullable.ts new file mode 100644 index 000000000..8c31e621b --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_date_nullable.ts @@ -0,0 +1,28 @@ +import { TestValidator } from "@nestia/e2e"; + +import api from "@api"; + +export const test_api_param_date_nullable = async ( + connection: api.IConnection, +): Promise => { + const date = random(); + const value = await api.functional.param.date_nullable(connection, date); + TestValidator.equals("date")(date)(value!); + + TestValidator.equals("null")( + await api.functional.param.date_nullable(connection, null), + )(null); + + await TestValidator.error("invalid")(() => + api.functional.param.date_nullable(connection, "20140102"), + ); +}; + +const random = () => { + const date: Date = new Date(Math.floor(Math.random() * Date.now() * 2)); + return [ + date.getFullYear(), + (date.getMonth() + 1).toString().padStart(2, "0"), + date.getDate().toString().padStart(2, "0"), + ].join("-"); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_error_message.ts b/test/features/param-validate/src/test/features/api/test_api_param_error_message.ts new file mode 100644 index 000000000..96e14b9c4 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_error_message.ts @@ -0,0 +1,17 @@ +import typia, { IValidation } from "typia"; + +import api from "@api"; + +export const test_api_param_error_message = async ( + connection: api.IConnection, +): Promise => { + try { + await api.functional.param.number(connection, "two" as any); + } catch (exp) { + const message: string = (exp as Error).message; + typia.assertEquals<{ + message: string; + errors: IValidation.IError[]; + }>(JSON.parse(message)); + } +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_number.ts b/test/features/param-validate/src/test/features/api/test_api_param_number.ts new file mode 100644 index 000000000..f112b09bd --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_number.ts @@ -0,0 +1,18 @@ +import { TestValidator } from "@nestia/e2e"; +import typia from "typia"; + +import api from "@api"; + +export const test_api_param_number = async ( + connection: api.IConnection, +): Promise => { + const value: number = await api.functional.param.number(connection, 1); + typia.assert(value); + + await TestValidator.httpError("boolean")(400)(() => + api.functional.param.number(connection, true as any), + ); + await TestValidator.httpError("string")(400)(() => + api.functional.param.number(connection, "string" as any), + ); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_string.ts b/test/features/param-validate/src/test/features/api/test_api_param_string.ts new file mode 100644 index 000000000..c41d1248f --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_string.ts @@ -0,0 +1,10 @@ +import typia from "typia"; + +import api from "@api"; + +export const test_api_param_string = async ( + connection: api.IConnection, +): Promise => { + const value: string = await api.functional.param.string(connection, "string"); + typia.assert(value); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_uuid.ts b/test/features/param-validate/src/test/features/api/test_api_param_uuid.ts new file mode 100644 index 000000000..740ede01a --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_uuid.ts @@ -0,0 +1,19 @@ +import { TestValidator } from "@nestia/e2e"; +import { v4 } from "uuid"; + +import api from "@api"; + +export const test_api_param_uuid = async ( + connection: api.IConnection, +): Promise => { + const uuid = v4(); + const value = await api.functional.param.uuid(connection, uuid); + TestValidator.equals("uuid")(uuid)(value); + + await TestValidator.error("null")(() => + api.functional.param.uuid(connection, null!), + ); + await TestValidator.error("invalid")(() => + api.functional.param.uuid(connection, "12345678"), + ); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_param_uuid_nullable.ts b/test/features/param-validate/src/test/features/api/test_api_param_uuid_nullable.ts new file mode 100644 index 000000000..def636c06 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_param_uuid_nullable.ts @@ -0,0 +1,20 @@ +import { TestValidator } from "@nestia/e2e"; +import { v4 } from "uuid"; + +import api from "@api"; + +export const test_api_param_uuid_nullable = async ( + connection: api.IConnection, +): Promise => { + const uuid = v4(); + const value = await api.functional.param.uuid_nullable(connection, uuid); + TestValidator.equals("uuid")(uuid)(value!); + + TestValidator.equals("null")( + await api.functional.param.uuid_nullable(connection, null), + )(null); + + await TestValidator.error("invalid")(() => + api.functional.param.uuid_nullable(connection, "12345678"), + ); +}; diff --git a/test/features/param-validate/src/test/features/api/test_api_performance.ts b/test/features/param-validate/src/test/features/api/test_api_performance.ts new file mode 100644 index 000000000..df2b434d7 --- /dev/null +++ b/test/features/param-validate/src/test/features/api/test_api_performance.ts @@ -0,0 +1,12 @@ +import typia from "typia"; + +import api from "@api"; +import { IPerformance } from "@api/lib/structures/IPerformance"; + +export const test_api_monitor_performance = async ( + connection: api.IConnection, +): Promise => { + const performance: IPerformance = + await api.functional.performance.get(connection); + typia.assert(performance); +}; diff --git a/test/features/param-validate/src/test/index.ts b/test/features/param-validate/src/test/index.ts new file mode 100644 index 000000000..7e8f43d54 --- /dev/null +++ b/test/features/param-validate/src/test/index.ts @@ -0,0 +1,47 @@ +import { DynamicExecutor } from "@nestia/e2e"; + +import { Backend } from "../Backend"; + +async function main(): Promise { + const server: Backend = new Backend(); + await server.open(); + + const report: DynamicExecutor.IReport = await DynamicExecutor.validate({ + extension: __filename.substring(__filename.length - 2), + prefix: "test", + parameters: () => [ + { + host: "http://127.0.0.1:37000", + encryption: { + key: "A".repeat(32), + iv: "B".repeat(16), + }, + }, + ], + location: `${__dirname}/features`, + onComplete: (exec) => { + const elapsed: number = + new Date(exec.completed_at).getTime() - + new Date(exec.started_at).getTime(); + console.log(` - ${exec.name}: ${elapsed.toLocaleString()} ms`); + }, + }); + await server.close(); + + const exceptions: Error[] = report.executions + .filter((exec) => exec.error !== null) + .map((exec) => exec.error!); + if (exceptions.length === 0) { + console.log("Success"); + console.log("Elapsed time", report.time.toLocaleString(), `ms`); + } else { + for (const exp of exceptions) console.log(exp); + console.log("Failed"); + console.log("Elapsed time", report.time.toLocaleString(), `ms`); + process.exit(-1); + } +} +main().catch((exp) => { + console.log(exp); + process.exit(-1); +}); diff --git a/test/features/param-validate/swagger.json b/test/features/param-validate/swagger.json new file mode 100644 index 000000000..8673bf981 --- /dev/null +++ b/test/features/param-validate/swagger.json @@ -0,0 +1,582 @@ +{ + "openapi": "3.1.0", + "servers": [ + { + "url": "https://github.com/samchon/nestia", + "description": "insert your server url" + } + ], + "info": { + "version": "4.0.4", + "title": "@samchon/nestia-test", + "description": "Test program of Nestia", + "license": { + "name": "MIT" + } + }, + "paths": { + "/health": { + "get": { + "tags": [], + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": {} + } + } + } + } + }, + "/performance": { + "get": { + "tags": [], + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/IPerformance" + } + } + } + } + } + } + }, + "/param/{value}/composite/{value2}": { + "get": { + "summary": "Composite path parameters", + "description": "Composite path parameters.", + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "title": "The first value", + "description": " The first value.\r\nThe first string value." + }, + { + "name": "value2", + "in": "path", + "schema": { + "type": "string" + }, + "required": true, + "title": "The second value", + "description": " The second value.\r\nThe second string value." + } + ], + "responses": { + "200": { + "description": "Concatenated string.", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/param/{value}/boolean": { + "get": { + "summary": "Boolean path parameter", + "description": "Boolean path parameter.", + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "boolean" + }, + "required": true, + "title": "The boolean value", + "description": " The boolean value.\r\nThe boolean value as a path parameter." + } + ], + "responses": { + "200": { + "description": "The same boolean value.", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + } + } + } + }, + "/param/{value}/number": { + "get": { + "summary": "The number", + "description": "The number.", + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "number" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "number" + } + } + } + } + } + } + }, + "/param/{value}/bigint": { + "get": { + "summary": "The bigint", + "description": "The bigint.", + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "integer" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "number" + } + } + } + } + } + } + }, + "/param/{value}/string": { + "get": { + "summary": "The string", + "description": "The string.", + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "string" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/param/{value}/nullable": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] + } + } + } + } + } + } + }, + "/param/{value}/literal": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "oneOf": [ + { + "const": "A" + }, + { + "const": "B" + }, + { + "const": "C" + } + ] + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "const": "A" + }, + { + "const": "B" + }, + { + "const": "C" + } + ] + } + } + } + } + } + } + }, + "/param/{value}/uuid": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "string", + "format": "uuid" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/param/{value}/date": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "type": "string", + "format": "date" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/param/{value}/uuid_nullable": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string", + "format": "uuid" + } + ] + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] + } + } + } + } + } + } + }, + "/param/{value}/date_nullable": { + "get": { + "tags": [], + "parameters": [ + { + "name": "value", + "in": "path", + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string", + "format": "date" + } + ] + }, + "required": true + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "IPerformance": { + "type": "object", + "properties": { + "cpu": { + "$ref": "#/components/schemas/process.global.NodeJS.CpuUsage" + }, + "memory": { + "$ref": "#/components/schemas/process.global.NodeJS.MemoryUsage" + }, + "resource": { + "$ref": "#/components/schemas/process.global.NodeJS.ResourceUsage" + } + }, + "required": [ + "cpu", + "memory", + "resource" + ], + "description": "Performance info." + }, + "process.global.NodeJS.CpuUsage": { + "type": "object", + "properties": { + "user": { + "type": "number" + }, + "system": { + "type": "number" + } + }, + "required": [ + "user", + "system" + ] + }, + "process.global.NodeJS.MemoryUsage": { + "type": "object", + "properties": { + "rss": { + "type": "number" + }, + "heapTotal": { + "type": "number" + }, + "heapUsed": { + "type": "number" + }, + "external": { + "type": "number" + }, + "arrayBuffers": { + "type": "number" + } + }, + "required": [ + "rss", + "heapTotal", + "heapUsed", + "external", + "arrayBuffers" + ] + }, + "process.global.NodeJS.ResourceUsage": { + "type": "object", + "properties": { + "fsRead": { + "type": "number" + }, + "fsWrite": { + "type": "number" + }, + "involuntaryContextSwitches": { + "type": "number" + }, + "ipcReceived": { + "type": "number" + }, + "ipcSent": { + "type": "number" + }, + "majorPageFault": { + "type": "number" + }, + "maxRSS": { + "type": "number" + }, + "minorPageFault": { + "type": "number" + }, + "sharedMemorySize": { + "type": "number" + }, + "signalsCount": { + "type": "number" + }, + "swappedOut": { + "type": "number" + }, + "systemCPUTime": { + "type": "number" + }, + "unsharedDataSize": { + "type": "number" + }, + "unsharedStackSize": { + "type": "number" + }, + "userCPUTime": { + "type": "number" + }, + "voluntaryContextSwitches": { + "type": "number" + } + }, + "required": [ + "fsRead", + "fsWrite", + "involuntaryContextSwitches", + "ipcReceived", + "ipcSent", + "majorPageFault", + "maxRSS", + "minorPageFault", + "sharedMemorySize", + "signalsCount", + "swappedOut", + "systemCPUTime", + "unsharedDataSize", + "unsharedStackSize", + "userCPUTime", + "voluntaryContextSwitches" + ] + } + }, + "securitySchemes": { + "bearer": { + "type": "apiKey" + } + } + }, + "tags": [], + "x-samchon-emended": true +} \ No newline at end of file diff --git a/test/features/param-validate/tsconfig.json b/test/features/param-validate/tsconfig.json new file mode 100644 index 000000000..ee78d7ab9 --- /dev/null +++ b/test/features/param-validate/tsconfig.json @@ -0,0 +1,101 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */// "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "paths": { + "@api": ["./src/api"], + "@api/lib/*": ["./src/api/*"], + }, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./bin", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. *//* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "plugins": [ + { "transform": "typescript-transform-paths" }, + { "transform": "typia/lib/transform" }, + { + "transform": "@nestia/core/lib/transform", + "validate": "validate", + }, + ], + } + } \ No newline at end of file diff --git a/test/features/param/nestia.config.ts b/test/features/param/nestia.config.ts index b704b4adc..057c9c13d 100644 --- a/test/features/param/nestia.config.ts +++ b/test/features/param/nestia.config.ts @@ -3,7 +3,6 @@ import { INestiaConfig } from "@nestia/sdk"; export const NESTIA_CONFIG: INestiaConfig = { input: ["src/controllers"], output: "src/api", - e2e: "src/test", swagger: { beautify: true, output: "swagger.json", diff --git a/test/features/param/src/test/features/api/automated/test_api_health_get.ts b/test/features/param/src/test/features/api/automated/test_api_health_get.ts deleted file mode 100644 index 8766b1129..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_health_get.ts +++ /dev/null @@ -1,8 +0,0 @@ -import typia from "typia"; - -import api from "../../../../api"; - -export const test_api_health_get = async (connection: api.IConnection) => { - const output = await api.functional.health.get(connection); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_bigint.ts b/test/features/param/src/test/features/api/automated/test_api_param_bigint.ts deleted file mode 100644 index 599ae7326..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_bigint.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_bigint = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.bigint( - connection, - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_boolean.ts b/test/features/param/src/test/features/api/automated/test_api_param_boolean.ts deleted file mode 100644 index 342f54337..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_boolean.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_boolean = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.boolean( - connection, - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_composite.ts b/test/features/param/src/test/features/api/automated/test_api_param_composite.ts deleted file mode 100644 index b5f08b0d5..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_composite.ts +++ /dev/null @@ -1,13 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_composite = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.composite( - connection, - typia.random(), - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_date.ts b/test/features/param/src/test/features/api/automated/test_api_param_date.ts deleted file mode 100644 index 740668a0b..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_date.ts +++ /dev/null @@ -1,13 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; -import type { Format } from "typia/lib/tags/Format"; - -import api from "../../../../api"; - -export const test_api_param_date = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.date( - connection, - typia.random>(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_date_nullable.ts b/test/features/param/src/test/features/api/automated/test_api_param_date_nullable.ts deleted file mode 100644 index b494b1eef..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_date_nullable.ts +++ /dev/null @@ -1,16 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; -import type { Format } from "typia/lib/tags/Format"; - -import api from "../../../../api"; - -export const test_api_param_date_nullable = async ( - connection: api.IConnection, -) => { - const output: Primitive = - await api.functional.param.date_nullable( - connection, - typia.random)>(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_literal.ts b/test/features/param/src/test/features/api/automated/test_api_param_literal.ts deleted file mode 100644 index 86e39ac26..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_literal.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_literal = async (connection: api.IConnection) => { - const output: Primitive<"A" | "B" | "C"> = await api.functional.param.literal( - connection, - typia.random<"A" | "B" | "C">(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_nullable.ts b/test/features/param/src/test/features/api/automated/test_api_param_nullable.ts deleted file mode 100644 index 3580fd80a..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_nullable.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_nullable = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.nullable( - connection, - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_number.ts b/test/features/param/src/test/features/api/automated/test_api_param_number.ts deleted file mode 100644 index ec583984d..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_number.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_number = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.number( - connection, - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_string.ts b/test/features/param/src/test/features/api/automated/test_api_param_string.ts deleted file mode 100644 index b4726cec5..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_string.ts +++ /dev/null @@ -1,12 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; - -export const test_api_param_string = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.string( - connection, - typia.random(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_uuid.ts b/test/features/param/src/test/features/api/automated/test_api_param_uuid.ts deleted file mode 100644 index 7107a6518..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_uuid.ts +++ /dev/null @@ -1,13 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; -import type { Format } from "typia/lib/tags/Format"; - -import api from "../../../../api"; - -export const test_api_param_uuid = async (connection: api.IConnection) => { - const output: Primitive = await api.functional.param.uuid( - connection, - typia.random>(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_param_uuid_nullable.ts b/test/features/param/src/test/features/api/automated/test_api_param_uuid_nullable.ts deleted file mode 100644 index 42c26fbff..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_param_uuid_nullable.ts +++ /dev/null @@ -1,16 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; -import type { Format } from "typia/lib/tags/Format"; - -import api from "../../../../api"; - -export const test_api_param_uuid_nullable = async ( - connection: api.IConnection, -) => { - const output: Primitive = - await api.functional.param.uuid_nullable( - connection, - typia.random)>(), - ); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/automated/test_api_performance_get.ts b/test/features/param/src/test/features/api/automated/test_api_performance_get.ts deleted file mode 100644 index f3cb15bed..000000000 --- a/test/features/param/src/test/features/api/automated/test_api_performance_get.ts +++ /dev/null @@ -1,11 +0,0 @@ -import typia from "typia"; -import type { Primitive } from "typia"; - -import api from "../../../../api"; -import type { IPerformance } from "../../../../api/structures/IPerformance"; - -export const test_api_performance_get = async (connection: api.IConnection) => { - const output: Primitive = - await api.functional.performance.get(connection); - typia.assert(output); -}; diff --git a/test/features/param/src/test/features/api/test_api_param_error_message.ts b/test/features/param/src/test/features/api/test_api_param_error_message.ts new file mode 100644 index 000000000..4d998557c --- /dev/null +++ b/test/features/param/src/test/features/api/test_api_param_error_message.ts @@ -0,0 +1,19 @@ +import typia, { IValidation } from "typia"; + +import api from "@api"; + +export const test_api_param_error_message = async ( + connection: api.IConnection, +): Promise => { + try { + await api.functional.param.number(connection, "two" as any); + } catch (exp) { + const message: string = (exp as Error).message; + typia.assertEquals< + { + message: string; + reason: string; + } & IValidation.IError + >(JSON.parse(message)); + } +};