UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

75 lines (74 loc) 2.79 kB
import { IRepository } from "../interfaces/IRepository"; import { DecoratorMetadata } from "@decaf-ts/reflection"; import { Constructor, Model } from "@decaf-ts/decorator-validation"; import { Context } from "./Context"; import { RepositoryFlags } from "./types"; /** * @description Context arguments for repository operations. * @summary Represents the context and arguments for repository operations. * This type is used to pass context and arguments between repository methods. * @template F - The repository flags type, defaults to RepositoryFlags * @template C - The context type, defaults to Context<F> * @typedef {Object} ContextArgs * @property {C} context - The operation context * @property {any[]} args - The operation arguments * @memberOf module:db-decorators */ export type ContextArgs<F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>> = { context: C; args: any[]; }; /** * @summary retrieves the arguments for the handler * @param {any} dec the decorator * @param {string} prop the property name * @param {{}} m the model * @param {{}} [accum] accumulator used for internal recursiveness * * @function getHandlerArgs * @memberOf module:db-decorators.Repository */ export declare const getHandlerArgs: (dec: any, prop: string, m: Constructor<any>, accum?: Record<string, { args: string[]; }>) => Record<string, { args: string[]; }> | void; /** * * @param {IRepository<T>} repo * @param context * @param {T} model * @param operation * @param prefix * * @param oldModel * @function enforceDBPropertyDecoratorsAsync * * @memberOf db-decorators.utils */ export declare function enforceDBDecorators<M extends Model, R extends IRepository<M, F, C>, V extends object = object, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(repo: R, context: C, model: M, operation: string, prefix: string, oldModel?: M): Promise<void>; /** * Specific for DB Decorators * @param {T} model * @param {string} operation CRUD {@link OperationKeys} * @param {string} [extraPrefix] * * @function getDbPropertyDecorators * * @memberOf db-decorators.utils */ export declare function getDbDecorators<T extends Model>(model: T, operation: string, extraPrefix?: string): Record<string, DecoratorMetadata[]> | undefined; /** * @summary Retrieves the decorators for an object's properties prefixed by {@param prefixes} recursively * @param model * @param accum * @param prefixes * * @function getAllPropertyDecoratorsRecursive * @memberOf module:db-decorators.Repository */ export declare const getAllPropertyDecoratorsRecursive: <T extends Model>(model: T, accum: { [indexer: string]: any[]; } | undefined, ...prefixes: string[]) => { [indexer: string]: any[]; } | undefined;