UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

53 lines (52 loc) 3.4 kB
import { Model } from "@decaf-ts/decorator-validation"; import { IRepository } from "../interfaces/IRepository"; import { Context } from "../repository/Context"; import { CrudOperations } from "../operations"; import { RepositoryFlags } from "../repository/types"; /** * * @param {str} str * @memberOf db-decorators.model */ export declare function hashOnCreateUpdate<M extends Model, R extends IRepository<M, F, C>, V extends object, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M, oldModel?: M): void; export declare function hash(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void; export type ComposedFromMetadata = { args: string[]; separator: string; hashResult: boolean; type: "keys" | "values"; prefix?: string; suffix?: string; }; export declare function composedFromCreateUpdate<M extends Model, R extends IRepository<M, F, C>, V extends ComposedFromMetadata, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M): void; export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void; export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void; /** * Creates a decorator function that updates the version of a model during create or update operations. * * @param {CrudOperations} operation - The type of operation being performed (CREATE or UPDATE). * @returns {function} A function that updates the version of the model based on the operation type. * * @template M - Type extending Model * @template V - Type extending IRepository<M> * * @this {V} - The repository instance * @param {Context<M>} context - The context of the operation * @param {unknown} data - Additional data for the operation (not used in this function) * @param {string} key - The key of the version property in the model * @param {M} model - The model being updated * @throws {InternalError} If an invalid operation is provided or if version update fails */ export declare function versionCreateUpdate(operation: CrudOperations): <M extends Model, R extends IRepository<M, F, C>, V extends object, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M) => void; /** * @description Creates a decorator for versioning a property in a model. * @summary This decorator applies multiple sub-decorators to handle version management during create and update operations. * * @returns {Function} A composite decorator that: * - Sets the type of the property to Number * - Applies a version update on create operations * - Applies a version update on update operations * - Adds metadata indicating this property is used for versioning */ export declare function version(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void; export declare function transient(): (model: any, attribute: string) => void;