Interfaces
Complete reference for key interfaces used in NestJS CRUD Automator.
Core Interfaces
IApiBaseEntity
Base interface for all entities.
interface IApiBaseEntity {
[key: string]: unknown;
}All entities must implement this interface (implicitly through TypeScript’s structural typing).
IApiGetListResponseResult<E>
Response structure for paginated list operations.
interface IApiGetListResponseResult<E> {
items: E[];
total: number;
page: number;
limit: number;
totalPages: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
}Related:
Controller Interfaces
IApiControllerProperties<E>
Configuration options for @ApiController.
interface IApiControllerProperties<E> {
entity: Type<E>;
name?: string;
path?: string;
routes: {
[K in EApiRouteType]?: TApiControllerPropertiesRoute<E, K>;
};
}IApiControllerAuthentication
Authentication configuration for routes.
interface IApiControllerAuthentication {
guard: Type<CanActivate>;
bearerStrategies: string[];
}Subscriber Interfaces
IApiSubscriberRouteExecutionContext<E, Result, Input>
Execution context for route subscribers.
interface IApiSubscriberRouteExecutionContext<E, Result, Input = unknown> {
readonly ENTITY: E;
readonly DATA: Input;
readonly ROUTE_TYPE: EApiRouteType;
result: Result;
}Use IApiSubscriberRouteExecutionContextData<E, R> for before hooks (route metadata + optional authorizationDecision) and IApiSubscriberRouteExecutionContextDataExtended<E, R> for after/error hooks when you need authentication, headers, IP, or request payload fields:
interface IApiSubscriberRouteExecutionContextData<E extends IApiBaseEntity, R> {
entityMetadata: IApiEntity<E>;
method: EApiRouteType;
methodName: string;
properties: IApiControllerProperties<E>;
authorizationDecision?: IApiAuthorizationDecision<E, R>;
}
interface IApiSubscriberRouteExecutionContextDataExtended<E extends IApiBaseEntity, R> extends IApiSubscriberRouteExecutionContextData<E, R> {
authenticationRequest?: IApiAuthenticationRequest;
headers: Record<string, string>;
ip: string;
body?: DeepPartial<E>;
parameters?: Partial<E>;
query?: TApiControllerGetListQuery<E>;
}Related:
IApiSubscriberFunctionExecutionContext<E, Result, Input>
Execution context for function subscribers.
interface IApiSubscriberFunctionExecutionContext<E, Result, Input = unknown> {
readonly ENTITY: E;
readonly DATA: Input;
readonly FUNCTION_TYPE: EApiFunctionType;
result: Result;
}Use IApiSubscriberFunctionExecutionContextData<E> to access eventManager, repository, and operation metadata:
interface IApiSubscriberFunctionExecutionContextData<E extends IApiBaseEntity> {
eventManager?: EntityManager;
repository: Repository<E>;
criteria?: TApiFunctionDeleteCriteria<E> | TApiFunctionUpdateCriteria<E>;
properties?: TApiFunctionCreateProperties<E> | TApiFunctionGetProperties<E> | TApiFunctionGetListProperties<E> | TApiFunctionGetManyProperties<E>;
getProperties?: TApiFunctionGetProperties<E>;
getListProperties?: TApiFunctionGetListProperties<E>;
getManyProperties?: TApiFunctionGetManyProperties<E>;
}Related:
IApiSubscriberRoute<E>
Interface for route subscribers.
interface IApiSubscriberRoute<E> {
onBeforeCreate?(context: TApiSubscriberRouteBeforeCreateContext<E>): Promise<TApiSubscriberRouteBeforeCreateContext<E>["result"] | undefined>;
onAfterCreate?(context: TApiSubscriberRouteAfterCreateContext<E>): Promise<E | undefined>;
onBeforeGetList?(context: TApiSubscriberRouteBeforeGetListContext<E>): Promise<TApiSubscriberRouteBeforeGetListContext<E>["result"] | undefined>;
onAfterGetList?(context: TApiSubscriberRouteAfterGetListContext<E>): Promise<IApiGetListResponseResult<E> | undefined>;
onBeforeUpdate?(context: TApiSubscriberRouteBeforeUpdateContext<E>): Promise<TApiSubscriberRouteBeforeUpdateContext<E>["result"] | undefined>;
onAfterUpdate?(context: TApiSubscriberRouteAfterUpdateContext<E>): Promise<E | undefined>;
onBeforePartialUpdate?(context: TApiSubscriberRouteBeforePartialUpdateContext<E>): Promise<TApiSubscriberRouteBeforePartialUpdateContext<E>["result"] | undefined>;
onAfterPartialUpdate?(context: TApiSubscriberRouteAfterPartialUpdateContext<E>): Promise<E | undefined>;
onBeforeDelete?(context: TApiSubscriberRouteBeforeDeleteContext<E>): Promise<TApiSubscriberRouteBeforeDeleteContext<E>["result"] | undefined>;
onAfterDelete?(context: TApiSubscriberRouteAfterDeleteContext<E>): Promise<Partial<E> | undefined>;
// ... error hooks follow the same operation names (onBeforeErrorCreate, onAfterErrorUpdate, etc.)
}IApiSubscriberFunction<E>
Interface for function subscribers.
interface IApiSubscriberFunction<E> {
onBeforeCreate?(context: TApiSubscriberFunctionBeforeCreateContext<E>): Promise<TApiFunctionCreateProperties<E> | undefined>;
onAfterCreate?(context: TApiSubscriberFunctionAfterCreateContext<E>): Promise<E | undefined>;
onBeforeGetList?(context: TApiSubscriberFunctionBeforeGetListContext<E>): Promise<TApiFunctionGetListProperties<E> | undefined>;
onAfterGetList?(context: TApiSubscriberFunctionAfterGetListContext<E>): Promise<IApiGetListResponseResult<E> | undefined>;
onBeforeDelete?(context: TApiSubscriberFunctionBeforeDeleteContext<E>): Promise<TApiFunctionDeleteCriteria<E> | undefined>;
onAfterDelete?(context: TApiSubscriberFunctionAfterDeleteContext<E>): Promise<E | undefined>;
// ... error hooks follow the same operation names (onBeforeErrorCreate, onAfterErrorUpdate, etc.)
}Authentication Interface
IApiAuthenticationRequest
Authentication request data available in subscribers.
interface IApiAuthenticationRequest {
user?: {
id: string;
[key: string]: unknown;
};
[key: string]: unknown;
}Entity Metadata Interface
IApiEntity<E>
Entity metadata information.
interface IApiEntity<E> {
name: string;
primaryKey: string | null;
columns: string[];
relations: string[];
[key: string]: unknown;
}Property Validation Interfaces
IApiDtoValidator
Custom class-validator configuration for auto-generated DTOs.
interface IApiDtoValidator {
constraintClass: Function;
options?: Array<unknown>;
}IApiRequestValidator
Runtime request validator for controller routes.
interface IApiRequestValidator<E> {
errorType: EErrorStringAction;
exception: TApiException;
validationFunction: (entity: Partial<E> | TApiControllerGetListQuery<E>) => boolean | Promise<boolean>;
}Related:
Request Transformer Types
TApiRequestTransformer
Request/response transformer configuration.
type TApiRequestTransformer<E> = {
key: keyof Partial<E> | keyof IApiGetListResponseResult<E> | "limit" | "page";
shouldSetValueEvenIfMissing?: boolean;
} & (
| {
type: EApiControllerRequestTransformerType.DYNAMIC;
value: (typeof TRANSFORMER_VALUE_DTO_CONSTANT)[keyof typeof TRANSFORMER_VALUE_DTO_CONSTANT];
}
| {
type: EApiControllerRequestTransformerType.STATIC;
value: string;
}
);Related:
Next Steps
- Enums - Enumeration values
- Types - Type aliases
- Subscriber System - Subscriber interfaces usage