UNPKG

3.85 kBTypeScriptView Raw
1import { IModel, IFinderOptions, IndexAction, IRepoOptions, ISearchProvider, IPlugin, IModelMapper, ISearchOptions, IRepoPlugin, IFinderPlugin, ModelPersistenceEventType, IPredicate } from "./Types";
2import { Coordinator } from './Coordinator';
3import { IModelType } from "./ModelTypes";
4import { IModelOptions, IKeyValue, TKeyValue, IModelAttributeOptions } from "./decorations/ModelDecorations";
5/**
6 * The core Repo implementation
7 *
8 * When requested from the coordinator,
9 * it offers itself to all configured plugins for
10 * them to attach to the model pipeline
11 *
12 *
13 */
14export declare class Repo<M extends IModel> {
15 repoClazz: any;
16 modelClazz: {
17 new (): M;
18 };
19 modelOpts: IModelOptions;
20 repoOpts: IRepoOptions;
21 modelType: IModelType;
22 mapper: any;
23 coordinator: Coordinator;
24 protected plugins: IPlugin[];
25 /**
26 * Core repo is instantiated by providing the implementing/extending
27 * class and the model that will be supported
28 *
29 * @param repoClazz
30 * @param modelClazz
31 */
32 constructor(repoClazz: any, modelClazz: {
33 new (): M;
34 });
35 protected getRepoPlugins(): IRepoPlugin<M>[];
36 protected getFinderPlugins(): IFinderPlugin[];
37 attr(name: string): IModelAttributeOptions;
38 init(coordinator: any): void;
39 start(): void;
40 getMapper<M extends IModel>(clazz: {
41 new (): M;
42 }): IModelMapper<M>;
43 /**
44 * Attach a plugin to the repo - could be a store,
45 * indexer, etc, etc
46 *
47 * @param plugin
48 * @returns {Repo}
49 */
50 attach(plugin: IPlugin): this;
51 getFinderOptions(finderKey: string): IFinderOptions;
52 getPlugins: (predicate: IPredicate) => IPlugin[];
53 /**
54 * Decorate finder by iterating all finder plugins
55 * and trying until resolved
56 *
57 * @param finderKey
58 */
59 decorateFinder(finderKey: any): void;
60 /**
61 * Decorate all finders on Repo
62 */
63 decorateFinders(): void;
64 /**
65 * Create a generic finder, in order
66 * to do this search options must have been
67 * annotated on the model
68 *
69 * @param finderKey
70 * @param searchProvider
71 * @param searchOpts
72 * @returns {any}
73 */
74 makeGenericFinder(finderKey: string, searchProvider: ISearchProvider, searchOpts: ISearchOptions<any>): (...args: any[]) => Promise<Promise<M>[]>;
75 /**
76 * Set a finder function on the repo
77 *
78 * @param finderKey
79 * @param finderFn
80 */
81 protected setFinder(finderKey: string, finderFn: (...args) => any): void;
82 /**
83 * Triggers manually attached persistence callbacks
84 * - works for internal indexing solutions, etc
85 *
86 * @param type
87 * @param models
88 */
89 triggerPersistenceEvent(type: ModelPersistenceEventType, ...models: any[]): void;
90 supportPersistenceEvents(): boolean;
91 /**
92 * Call out to the indexers
93 *
94 * @param type
95 * @param models
96 * @returns {Bluebird<boolean>}
97 */
98 index(type: IndexAction, ...models: IModel[]): Promise<boolean>;
99 indexPromise(action: IndexAction): (models: M[]) => Promise<M[]>;
100 /**
101 * Not implemented
102 *
103 * @param args
104 * @returns {null}
105 */
106 key(...args: any[]): IKeyValue;
107 /**
108 * Get one or more models with keys
109 *
110 * @param key
111 * @returns {null}
112 */
113 get(key: TKeyValue): Promise<M>;
114 /**
115 * Save model
116 *
117 * @param o
118 * @returns {null}
119 */
120 save(o: M): Promise<M>;
121 /**
122 * Remove a model
123 *
124 * @param key
125 * @returns {null}
126 */
127 remove(key: TKeyValue): Promise<any>;
128 /**
129 * Count models
130 *
131 * @returns {null}
132 */
133 count(): Promise<number>;
134 bulkGet(...keys: TKeyValue[]): Promise<M[]>;
135 bulkSave(...models: M[]): Promise<M[]>;
136 bulkRemove(...keys: TKeyValue[]): Promise<any[]>;
137}