@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
24 lines (23 loc) • 1.89 kB
TypeScript
import { IApiControllerGetListQueryPlan } from '../../../interface/class/api/controller/get-list/query';
import { IApiControllerPropertiesRouteAutoDtoConfig } from '../../../interface/decorator/api';
import { IApiEntity } from '../../../interface/entity';
import { Type } from '@nestjs/common';
import { IAuthGuard } from '@nestjs/passport';
import { ObjectLiteral } from 'typeorm';
import { EApiDtoType, EApiRouteType } from '../../../enum/decorator/api';
/**
* Core utility for DTO generation that determines which properties should be included in the DTO.
* Builds decorators, handles special cases like filter queries, and generates the appropriate class
* based on entity metadata, route type, and DTO type.
* @param {ObjectLiteral} entity - The entity class or prototype
* @param {IApiEntity<E>} entityMetadata - The entity metadata containing column information
* @param {EApiRouteType} method - The API route type (CREATE, DELETE, GET, etc.)
* @param {EApiDtoType} dtoType - The type of DTO (REQUEST, RESPONSE, etc.)
* @param {IApiControllerPropertiesRouteAutoDtoConfig} [dtoConfig] - Optional configuration for automatic DTO generation
* @param {Type<IAuthGuard>} [currentGuard] - Optional authentication guard for property visibility control
* @param {IApiControllerGetListQueryPlan} [queryPlan] - Normalized route plan that narrows generated GET_LIST query fields.
* @returns {Type<unknown> | undefined} The generated DTO class or undefined if no DTO should be generated
* @throws {Error} When primary key metadata is missing
* @template E - The entity type
*/
export declare function DtoGenerate<E>(entity: ObjectLiteral, entityMetadata: IApiEntity<E>, method: EApiRouteType, dtoType: EApiDtoType, dtoConfig?: IApiControllerPropertiesRouteAutoDtoConfig, currentGuard?: Type<IAuthGuard>, queryPlan?: IApiControllerGetListQueryPlan): Type<unknown> | undefined;