1 | import { Repo } from "./Repo";
|
2 | import { IModel, IModelType } from "./ModelTypes";
|
3 | import { IIndexOptions, IPlugin } from "./PluginTypes";
|
4 | export * from './ModelTypes';
|
5 | export * from './PluginTypes';
|
6 | export declare enum ModelPersistenceEventType {
|
7 | Save = 1,
|
8 | Remove = 2,
|
9 | }
|
10 | export declare type ModelPersistenceEventCallback<M> = (type: ModelPersistenceEventType, ...models: M[]) => void;
|
11 |
|
12 |
|
13 |
|
14 | export interface IRepoOptions {
|
15 | indexes?: Array<IIndexOptions>;
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 | export interface IFinderOptions {
|
21 | optional?: boolean;
|
22 | single?: boolean;
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | export declare class FinderRequest {
|
28 | extra: any;
|
29 | limit: number;
|
30 | offset: number;
|
31 | sort: string[];
|
32 | sortDirection: 'desc' | 'asc';
|
33 | includeModels: boolean;
|
34 | constructor(obj: any);
|
35 | constructor(limit: number, offset: number, includeModels?: boolean, sort?: string[], sortDirection?: 'asc' | 'desc', extra?: any);
|
36 | }
|
37 | export interface IFinderItemMetadata {
|
38 | score?: number;
|
39 | finderName?: string;
|
40 | }
|
41 | /**
|
42 | * Finder result array - not implemented yet, mostly
|
43 | */
|
44 | export declare class FinderResultArray<T> extends Array<T> {
|
45 | total: number;
|
46 | request: FinderRequest;
|
47 | itemMetadata: IFinderItemMetadata[];
|
48 | pageNumber: number;
|
49 | pageCount: number;
|
50 | constructor(items: T[], total: number, request?: FinderRequest, itemMetadata?: IFinderItemMetadata[]);
|
51 | }
|
52 | /**
|
53 | * Simple base model implementation
|
54 | * uses reflection to determine type
|
55 | */
|
56 | export declare class DefaultModel implements IModel {
|
57 | readonly clazzType: any;
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 | export declare enum SyncStrategy {
|
63 | Overwrite = 0,
|
64 | Update = 1,
|
65 | None = 2,
|
66 | }
|
67 | export declare namespace SyncStrategy {
|
68 | const toString: (strategy: SyncStrategy) => string;
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | export interface ICoordinatorOptions {
|
75 | immutable?: boolean;
|
76 | syncStrategy?: SyncStrategy;
|
77 | autoRegisterModels?: boolean;
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 | export declare class CoordinatorOptions implements ICoordinatorOptions {
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | static Defaults: {
|
89 | autoRegisterModules: boolean;
|
90 | syncStrategy: SyncStrategy;
|
91 | immutable: boolean;
|
92 | };
|
93 | constructor(opts?: {});
|
94 | }
|
95 | export interface IModelMapperDecorator<M> {
|
96 | (json: any, model: M): M;
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | export interface IModelMapper<M extends IModel> {
|
103 | toObject(o: M): Object;
|
104 | toJson(o: M): string;
|
105 | fromObject(json: Object, decorator?: IModelMapperDecorator<M>): M;
|
106 | fromJson(json: string, decorator?: IModelMapperDecorator<M>): M;
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 | export interface IPredicate {
|
112 | (val: any): boolean;
|
113 | }
|
114 |
|
115 |
|
116 |
|
117 | export interface IPredicateFactory {
|
118 | (...args: any[]): IPredicate;
|
119 | }
|
120 |
|
121 |
|
122 |
|
123 | export interface ITypedPredicate<T> {
|
124 | (val: T): boolean;
|
125 | }
|
126 |
|
127 |
|
128 |
|
129 | export interface ITypedPredicateFactory<T> {
|
130 | (type: {
|
131 | new (): T;
|
132 | }, ...args: any[]): ITypedPredicate<T>;
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | export interface ICoordinator {
|
141 | getOptions(): ICoordinatorOptions;
|
142 | getModels(): IModelType[];
|
143 | getModel(clazz: any): IModelType;
|
144 | getModelByName(name: string): any;
|
145 | start(...models: any[]): Promise<ICoordinator>;
|
146 | init(opts: ICoordinatorOptions, ...plugins: IPlugin[]): Promise<ICoordinator>;
|
147 | reset(): Promise<ICoordinator>;
|
148 | getRepo<T extends Repo<M>, M extends IModel>(clazz: {
|
149 | new (): T;
|
150 | }): T;
|
151 | }
|