UNPKG

@elsikora/nestjs-crud-automator

Version:

A library for automating the creation of CRUD operations in NestJS.

34 lines (33 loc) 2.32 kB
import { IApiBaseEntity } from '../../interface/api-base-entity.interface'; import { TApiFunctionTransactionTraceType } from '../../type/class/api/function/transaction'; import { EntityManager, Repository } from 'typeorm'; import { EApiFunctionTransactionMode } from '../../enum/decorator/api'; /** * Executes an ApiFunction callback according to its transaction mode. * @template E - Entity type owned by the function repository. * @template R - Callback result type. * @param {object} options - Transaction execution options. * @param {string} [options.action] - Custom function action used for subscriber matching. * @param {(eventManager: EntityManager | undefined) => Promise<R>} options.callback - Function body to run with the resolved transaction manager. * @param {new (...arguments_: Array<unknown>) => E} options.entity - Entity constructor associated with the function. * @param {TApiFunctionTransactionTraceType} options.functionType - Function trace type. * @param {string} [options.label] - Error message label for the decorated function primitive. * @param {string} options.methodName - Decorated service method name. * @param {EApiFunctionTransactionMode} options.mode - Transaction mode to enforce. * @param {(eventManager: EntityManager | undefined, error: Error) => Promise<void>} [options.onPreflightError] - Error hook for transaction mode conflicts before the function body starts. * @param {Repository<E>} [options.repository] - Repository used to open new transactions when required. * @param {new (...arguments_: Array<unknown>) => unknown} [options.serviceConstructor] - Observable service constructor used for subscriber matching. * @returns {Promise<R>} Callback result. */ export declare function ApiFunctionExecuteWithTransaction<E extends IApiBaseEntity, R>(options: { action?: string; callback: (eventManager: EntityManager | undefined) => Promise<R>; entity: new (...arguments_: Array<unknown>) => E; functionType: TApiFunctionTransactionTraceType; label?: string; methodName: string; mode: EApiFunctionTransactionMode; onPreflightError?: (eventManager: EntityManager | undefined, error: Error) => Promise<void>; repository?: Repository<E>; serviceConstructor?: new (...arguments_: Array<unknown>) => unknown; }): Promise<R>;