1 | import './Globals';
|
2 | import { IModel, IModelType } from "./ModelTypes";
|
3 | import { Repo } from "./Repo";
|
4 | import { ICoordinator, ICoordinatorOptions } from "./Types";
|
5 | import { IModelKey, IKeyValue, TKeyValue } from "./decorations/ModelDecorations";
|
6 |
|
7 |
|
8 |
|
9 | export declare enum PluginEventType {
|
10 | RepoInit = 1,
|
11 | ModelRegister = 2,
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 | export interface IIndexOptions {
|
17 | fields: string[];
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 | export declare enum IndexAction {
|
23 | Add = 0,
|
24 | Update = 1,
|
25 | Remove = 2,
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 | export interface IIndexerPlugin extends IRepoSupportPlugin {
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | index<M extends IModel>(type: IndexAction, options: IIndexOptions, modelType: IModelType, repo: Repo<M>, ...models: IModel[]): Promise<boolean>;
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | export declare type ISearchResultToKeyMapper<R> = (repo: Repo<any>, resultType: {
|
52 | new (): R;
|
53 | }, result: R) => IModelKey;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | export declare function DefaultKeyMapper<R extends any>(...fields: any[]): ISearchResultToKeyMapper<R>;
|
63 |
|
64 |
|
65 |
|
66 | export interface ISearchOptions<R extends any> {
|
67 | resultType: {
|
68 | new (): R;
|
69 | };
|
70 | resultKeyMapper: ISearchResultToKeyMapper<R>;
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 | export interface ISearchProvider extends IRepoSupportPlugin {
|
76 | search<R extends any>(modelType: IModelType, opts: ISearchOptions<R>, ...args: any[]): Promise<R[]>;
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 | export interface IModelSupportPlugin extends IPlugin {
|
82 | supportedModels: any[];
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 | export interface IRepoSupportPlugin extends IModelSupportPlugin {
|
88 | initRepo<T extends Repo<M>, M extends IModel>(repo: T): T;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | export interface IStorePlugin extends IRepoSupportPlugin {
|
95 | syncModels(): Promise<ICoordinator>;
|
96 | }
|
97 |
|
98 |
|
99 |
|
100 | export interface IFinderPlugin extends IModelSupportPlugin {
|
101 | decorateFinder(repo: Repo<any>, finderKey: string): any;
|
102 | }
|
103 | export interface IRepoPlugin<M extends IModel> extends IModelSupportPlugin {
|
104 | key?(...args: any[]): IKeyValue;
|
105 | get(key: TKeyValue): Promise<M>;
|
106 | bulkGet(...keys: TKeyValue[]): Promise<M[]>;
|
107 | save(o: M): Promise<M>;
|
108 | bulkSave(...o: M[]): Promise<M[]>;
|
109 | remove(key: TKeyValue): Promise<any>;
|
110 | bulkRemove(...key: TKeyValue[]): Promise<any[]>;
|
111 | count(): Promise<number>;
|
112 | }
|
113 | export declare enum PluginType {
|
114 | Indexer = 1,
|
115 | Store = 2,
|
116 | Repo = 4,
|
117 | Finder = 8,
|
118 | }
|
119 | export interface IPlugin {
|
120 | type: PluginType;
|
121 | handle(eventType: PluginEventType, ...args: any[]): boolean | any;
|
122 | init(coordinator: ICoordinator, opts: ICoordinatorOptions): Promise<ICoordinator>;
|
123 | start(): Promise<ICoordinator>;
|
124 | stop(): Promise<ICoordinator>;
|
125 | }
|