UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

61 lines (60 loc) 3.12 kB
import "./validation"; import { Model } from "@decaf-ts/decorator-validation"; import { OperationKeys } from "../operations/constants"; import { IRepository } from "../interfaces/IRepository"; import { Context } from "../repository/Context"; import { RepositoryFlags } from "../repository/types"; /** * Marks the property as readonly. * * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES.READONLY.INVALID} * * @decorator readonly * * @category Decorators */ export declare function readonly(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any; export declare function timestampHandler<M extends Model, R extends IRepository<M, F, C>, V, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M): Promise<void>; /** * Marks the property as timestamp. * Makes it {@link required} * Makes it a {@link date} * * Date Format: * * <pre> * Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java), * I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify. * You can display date, time, AM/PM, etc. * * Date and Time Patterns * yy = 2-digit year; yyyy = full year * M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name * EEEE = full weekday name; EEE = short weekday name * d = digit day; dd = 2-digit day * h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours * m = minutes; mm = 2-digit minutes; aaa = AM/PM * s = seconds; ss = 2-digit seconds * S = miliseconds * </pre> * * @param {string[]} operation The {@link DBOperations} to act on. Defaults to {@link DBOperations.CREATE_UPDATE} * @param {string} [format] The TimeStamp format. defaults to {@link DEFAULT_TIMESTAMP_FORMAT} * @param {{new: UpdateValidator}} [validator] defaults to {@link TimestampValidator} * * @decorator timestamp * * @category Decorators */ export declare function timestamp(operation?: OperationKeys[], format?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any; export declare function serializeOnCreateUpdate<M extends Model, R extends IRepository<M, F, C>, V, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M): Promise<void>; export declare function serializeAfterAll<M extends Model, R extends IRepository<M, F, C>, V, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>>(this: R, context: C, data: V, key: keyof M, model: M): Promise<void>; /** * @summary Serialize Decorator * @description properties decorated will the serialized before stored in the db * * @function serialize * * @memberOf module:wallet-db.Decorators */ export declare function serialize(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;