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