Skip to content

Commit

Permalink
Merge pull request #982 from samchon/feature/transform
Browse files Browse the repository at this point in the history
Developing #980: to boost up `@nestia/sdk` performance.
  • Loading branch information
samchon authored Aug 14, 2024
2 parents 8e180be + fe9e637 commit b207205
Show file tree
Hide file tree
Showing 768 changed files with 23,687 additions and 10,189 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"reflect-metadata": "^0.2.2",
"tgrid": "^1.0.3",
"tstl": "^3.0.0",
"typia": "^6.7.0"
"typia": "^6.8.0"
},
"devDependencies": {
"@types/autocannon": "^7.9.0",
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": "3.10.0",
"version": "3.11.0-dev.20240814",
"description": "Nestia station",
"scripts": {
"build": "node build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"ts-patch": "^3.2.1",
"typescript": "^5.5.4",
"typescript-transform-paths": "^3.4.7",
"typia": "^6.7.0",
"typia": "^6.8.0",
"uuid": "^10.0.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestia",
"version": "5.6.0",
"version": "5.7.0",
"description": "Nestia CLI tool",
"main": "bin/index.js",
"bin": {
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ npx nestia [command] [options?]
7. npx nestia swagger
8. npx nestia openai
9. npx nestia e2e
10. npx nestia all
`;

function halt(desc: string): never {
Expand Down Expand Up @@ -46,7 +47,8 @@ async function main(): Promise<void> {
type === "sdk" ||
type === "openai" ||
type === "swagger" ||
type === "e2e"
type === "e2e" ||
type === "all"
) {
try {
require.resolve("@nestia/sdk/lib/executable/sdk");
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "3.10.0",
"version": "3.11.0-dev.20240814",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -11,7 +11,7 @@
},
"scripts": {
"build": "rimraf lib && tsc",
"dev": "npm run build -- --watch",
"dev": "tsc -p tsconfig.test.json --watch",
"eslint": "eslint ./**/*.ts",
"eslint:fix": "eslint ./**/*.ts --fix",
"prepare": "ts-patch install && typia patch"
Expand All @@ -36,10 +36,10 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^3.10.0",
"@nestia/fetcher": "../fetcher/nestia-fetcher-3.11.0-dev.20240814.tgz",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@samchon/openapi": "^0.4.3",
"@samchon/openapi": "^0.4.5",
"detect-ts-node": "^1.0.5",
"get-function-location": "^2.0.0",
"glob": "^7.2.0",
Expand All @@ -49,16 +49,16 @@
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.3",
"tgrid": "^1.0.0",
"typia": "^6.7.0",
"typia": "^6.8.0",
"ws": "^7.5.3"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.10.0",
"@nestia/fetcher": ">=3.11.0-dev.20240814",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.3",
"typia": ">=6.7.0 <7.0.0"
"typia": ">=6.8.0 <7.0.0"
},
"devDependencies": {
"@fastify/multipart": "^8.1.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/decorators/DynamicModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ export namespace DynamicModule {
export async function mount(
path: string | string[] | { include: string[]; exclude?: string[] },
metadata: Omit<ModuleMetadata, "controllers"> = {},
isTsNode?: boolean,
): Promise<object> {
// LOAD CONTROLLERS
const controllers: Creator<object>[] = await load_controllers(path);
const controllers: Creator<object>[] = await load_controllers(
path,
isTsNode,
);

// RETURN WITH DECORATING
@Module({ ...metadata, controllers })
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/decorators/EncryptedModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ export namespace EncryptedModule {
path: string | string[] | { include: string[]; exclude?: string[] },
password: IEncryptionPassword | IEncryptionPassword.Closure,
options: Omit<Parameters<typeof Module>[0], "controllers"> = {},
isTsNode?: boolean,
): Promise<object> {
// LOAD CONTROLLERS
const controllers: Creator<object>[] = await load_controllers(path);
const controllers: Creator<object>[] = await load_controllers(
path,
isTsNode,
);

// RETURNS WITH DECORATING
@EncryptedModule(
Expand Down
86 changes: 62 additions & 24 deletions packages/core/src/decorators/TypedException.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* > You must configure the generic argument `T`
*
* Exception decorator.
*
* `TypedException` is a decorator function describing HTTP exception and its type
* which could be occured in the method.
*
* For reference, this decorator function does not affect to the method's behavior,
* but only affects to the swagger documents generation. Also, it does not affect to
* the SDK library generation yet, but will be used in the future.
*
* @param props Properties for the exception
* @returns Method decorator
* @author Jeongho Nam - https://github.com/samchon
*/
export function TypedException(props: TypedException.IProps<unknown>): never;

/**
* > You must configure the generic argument `T`
*
Expand All @@ -14,13 +32,35 @@
* @param description Description about the exception
* @returns Method decorator
*
* @deprecated Use {@link TypedException.IProps} typed function instead.
* This typed function is deprecated and will be removed in the next major update.
* @author Jeongho Nam - https://github.com/samchon
*/
export function TypedException(
status: number | "2XX" | "3XX" | "4XX" | "5XX",
description?: string | undefined,
): never;

/**
* Exception decorator.
*
* `TypedException` is a decorator function describing HTTP exception and its type
* which could be occured in the method.
*
* For reference, this decorator function does not affect to the method's behavior,
* but only affects to the swagger documents generation. Also, it does not affect to
* the SDK library generation yet, but will be used in the future.
*
* @template T Type of the exception
* @param props Properties for the exception
* @returns Method decorator
*
* @author Jeongho Nam - https://github.com/samchon
*/
export function TypedException<T>(
props: TypedException.IProps<T>,
): MethodDecorator;

/**
* Exception decorator.
*
Expand All @@ -36,6 +76,8 @@ export function TypedException(
* @param description Description about the exception
* @returns Method decorator
*
* @deprecated Use {@link TypedException.IProps} typed function instead.
* This typed function is deprecated and will be removed in the next major update.
* @author Jeongho Nam - https://github.com/samchon
*/
export function TypedException<T>(
Expand All @@ -46,45 +88,41 @@ export function TypedException<T>(
/**
* @internal
*/
export function TypedException<T>(
status: number | "2XX" | "3XX" | "4XX" | "5XX",
description?: string | undefined,
type?: string | undefined,
): MethodDecorator {
export function TypedException<T>(...args: any[]): MethodDecorator {
const props: TypedException.IProps<T> =
typeof args[0] === "object"
? args[0]
: { status: args[0], description: args[1] };
return function TypedException(
target: Object | T,
propertyKey: string | symbol,
descriptor: TypedPropertyDescriptor<any>,
) {
const array: IProps[] = (() => {
const oldbie: IProps[] | undefined = Reflect.getMetadata(
"nestia/TypedException",
(target as any)[propertyKey],
);
const array: TypedException.IProps<any>[] = (() => {
const oldbie: TypedException.IProps<any>[] | undefined =
Reflect.getMetadata(
"nestia/TypedException",
(target as any)[propertyKey],
);
if (oldbie !== undefined) return oldbie;

const newbie: IProps[] = [];
const newbie: TypedException.IProps<any>[] = [];
Reflect.defineMetadata(
"nestia/TypedException",
newbie,
(target as any)[propertyKey],
);
return newbie;
})();
array.push({
status,
description,
type: type!,
});
array.push(props);
return descriptor;
};
}

/**
* @internal
*/
interface IProps {
status: number | "2XX" | "3XX" | "4XX" | "5XX";
description?: string | undefined;
type: string;
export namespace TypedException {
export interface IProps<T> {
status: number | "2XX" | "3XX" | "4XX" | "5XX";
description?: string | undefined;
example?: T;
examples?: Record<string, T>;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @internal
*/
export function NoTransformConfigureError(method: string): never {
if (NoTransformConfigureError.throws === true)
throw new Error(
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/decorators/internal/load_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SourceFinder } from "../../utils/SourceFinder";
*/
export const load_controllers = async (
path: string | string[] | { include: string[]; exclude?: string[] },
isTsNode?: boolean,
): Promise<Creator<object>[]> => {
const sources: string[] = await SourceFinder.find({
include: Array.isArray(path)
Expand All @@ -20,7 +21,7 @@ export const load_controllers = async (
? path.exclude ?? []
: [],
filter:
EXTENSION === "ts"
isTsNode === true || EXTENSION === "ts"
? (file) =>
file.substring(file.length - 3) === ".ts" &&
file.substring(file.length - 5) !== ".d.ts"
Expand Down
71 changes: 0 additions & 71 deletions packages/core/src/programmers/TypedExceptionProgrammer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/transformers/FileTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export namespace FileTransformer {
(node as any).parent ??= file;

// REPORT DIAGNOSTIC
const diagnostic = ts.createDiagnosticForNode(node, {
const diagnostic = (ts as any).createDiagnosticForNode(node, {
key: exp.code,
category: ts.DiagnosticCategory.Error,
message: exp.message,
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/transformers/MethodTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ts from "typescript";

import { INestiaTransformProject } from "../options/INestiaTransformProject";
import { TypedExceptionTransformer } from "./TypedExceptionTransformer";
import { TypedRouteTransformer } from "./TypedRouteTransformer";
import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";

Expand All @@ -24,10 +23,12 @@ export namespace MethodTransformer {
if (escaped === undefined) return method;

const operator = (decorator: ts.Decorator): ts.Decorator => {
decorator = TypedExceptionTransformer.transform(project)(decorator);
decorator =
TypedRouteTransformer.transform(project)(escaped)(decorator);
WebSocketRouteTransformer.validate(project)(decorator, method);
decorator = WebSocketRouteTransformer.validate(project)(
decorator,
method,
);
return decorator;
};
if (ts.getDecorators !== undefined)
Expand Down
Loading

0 comments on commit b207205

Please sign in to comment.