UNPKG

@grouparoo/core

Version:
43 lines (42 loc) 1.65 kB
import { Model } from "sequelize-typescript"; import { NonAbstract } from "sequelize-typescript/dist/shared/types"; import { Attributes } from "sequelize"; export declare type CommonModelStatic<M> = (new () => M) & NonAbstract<typeof CommonModel>; export declare abstract class CommonModel<T> extends Model { /** * return the prefix for this type of class' id */ abstract idPrefix(): string; uniqueIdentifier?: string[]; id: string; static generateId<T>(instance: CommonModel<T>): void; static generateIds<T>(instances: CommonModel<T>[]): void; static validateId<T>(instance: CommonModel<T>): void; static validateIds<T>(instances: CommonModel<T>[]): void; createdAt: Date; updatedAt: Date; touch(): Promise<this>; idIsDefault(): boolean; abstract apiData(): Promise<{ [key: string]: any; }>; /** * Find an instance of this class, regardless of scope. * Throw if the instance cannot be found. */ static findById<T extends Model>(this: CommonModelStatic<T>, id: string): Promise<T>; /** * Update many instances at once, never exceeding a set batch size for */ static updateAllInBatches<T extends Model>(this: CommonModelStatic<T>, instances: CommonModel<T>[], values: Partial<{ [key in keyof Attributes<T>]: T[key]; }>): Promise<void>; /** * Ensures there isn't a duplicate version of this instance based on name or key. */ static ensureUnique<T extends CommonModel<T> & { name?: string; key?: string; state?: string; }>(this: CommonModelStatic<T>, instance: T): Promise<void>; }