UNPKG

fewer

Version:

A minimal ORM for Node.js.

70 lines (69 loc) 2.4 kB
export declare const IsModel: unique symbol; export declare const Dirty: unique symbol; export declare const Changed: unique symbol; export declare const Changes: unique symbol; export declare const Valid: unique symbol; export declare const Errors: unique symbol; export declare const Symbols: { /** * Used to check if an object is a fewer model. */ readonly isModel: typeof IsModel; /** * Used to determine if any of the properties on the model have been changed. */ readonly dirty: typeof Dirty; /** * Used to determine the set of properties on the model that have been changed. */ readonly changed: typeof Changed; /** * Used to determine the original value of properties that have changed on the model. */ readonly changes: typeof Changes; /** * Used to determine if the model is valid. */ readonly valid: typeof Valid; /** * Used to get the errors that are currently attached to the model. */ readonly errors: typeof Errors; }; export interface SymbolProperties<T = any> { readonly [Symbols.isModel]: true; readonly [Symbols.dirty]: boolean; readonly [Symbols.changed]: (keyof T)[]; readonly [Symbols.changes]: { [P in keyof T]?: T[P]; }; readonly [Symbols.valid]: boolean; readonly [Symbols.errors]: ValidationError<T>[]; } declare const SetErrors: unique symbol; declare const HasValidationRun: unique symbol; declare const DynAssign: unique symbol; export declare const InternalSymbols: { setErrors: typeof SetErrors; hasValidationRun: typeof HasValidationRun; dynAssign: typeof DynAssign; }; export interface InternalSymbolProperties { [InternalSymbols.setErrors]: (newErrors: ValidationError[]) => void; [InternalSymbols.hasValidationRun]: boolean; [InternalSymbols.dynAssign]: (nextObj: object) => void; } export interface ValidationError<T = any> { /** * The field that contained the validation error. * If the validation error occured on the entire model, then this field should be omitted. */ on?: keyof T; /** * The message for the validation error. */ message: string; } export declare type Model<RepoType, T> = T & Partial<RepoType> & SymbolProperties<RepoType>; export default function createModel<RepoType, T extends object>(initialObj: T): Model<RepoType, T>; export {};