import './Globals'; import { IModel, IModelType } from "./ModelTypes"; import { Repo } from "./Repo"; import { ICoordinator, ICoordinatorOptions } from "./Types"; import { IModelKey, IKeyValue, TKeyValue } from "./decorations/ModelDecorations"; /** * Model persistence events */ export declare enum PluginEventType { RepoInit = 1, ModelRegister = 2, } /** * Indexer options */ export interface IIndexOptions { fields: string[]; } /** * Different indexing actions */ export declare enum IndexAction { Add = 0, Update = 1, Remove = 2, } /** * Responsible for indexing given models */ export interface IIndexerPlugin extends IRepoSupportPlugin { /** * Called in persistence chain after put/save * before return. * * Note: indexing can be done asynchronously based on your * requirements, but we suggest whenever possible to do this sync * * Obviously if you have a high write throughput solution * THIS IS A BAD IDEA - do indexing async or offline * * @param modelType * @param options * @param modelType * @param repo */ index(type: IndexAction, options: IIndexOptions, modelType: IModelType, repo: Repo, ...models: IModel[]): Promise; } /** * Maps search results to keys for a given repo */ export declare type ISearchResultToKeyMapper = (repo: Repo, resultType: { new (): R; }, result: R) => IModelKey; /** * Super simply default key mapper for search results * field names in, key out, must all be top level in result object * * @param fields * @returns {function(Repo, {new(): R}, R): IModelKey} * @constructor */ export declare function DefaultKeyMapper(...fields: any[]): ISearchResultToKeyMapper; /** * Custom search options for search(s) */ export interface ISearchOptions { resultType: { new (): R; }; resultKeyMapper: ISearchResultToKeyMapper; } /** * Custom external search provider */ export interface ISearchProvider extends IRepoSupportPlugin { search(modelType: IModelType, opts: ISearchOptions, ...args: any[]): Promise; } /** * A plugin that supports specific models */ export interface IModelSupportPlugin extends IPlugin { supportedModels: any[]; } /** * A plugin that provides repo capabilities */ export interface IRepoSupportPlugin extends IModelSupportPlugin { initRepo, M extends IModel>(repo: T): T; } /** * Store interface that must be fulfilled for * a valid store to work */ export interface IStorePlugin extends IRepoSupportPlugin { syncModels(): Promise; } /** * Plugin that provides finders */ export interface IFinderPlugin extends IModelSupportPlugin { decorateFinder(repo: Repo, finderKey: string): any; } export interface IRepoPlugin extends IModelSupportPlugin { key?(...args: any[]): IKeyValue; get(key: TKeyValue): Promise; bulkGet(...keys: TKeyValue[]): Promise; save(o: M): Promise; bulkSave(...o: M[]): Promise; remove(key: TKeyValue): Promise; bulkRemove(...key: TKeyValue[]): Promise; count(): Promise; } export declare enum PluginType { Indexer = 1, Store = 2, Repo = 4, Finder = 8, } export interface IPlugin { type: PluginType; handle(eventType: PluginEventType, ...args: any[]): boolean | any; init(coordinator: ICoordinator, opts: ICoordinatorOptions): Promise; start(): Promise; stop(): Promise; }