UNPKG

3.99 kBTypeScriptView Raw
1import { Repo } from "./Repo";
2import { IModel, IModelType } from "./ModelTypes";
3import { IIndexOptions, IPlugin } from "./PluginTypes";
4export * from './ModelTypes';
5export * from './PluginTypes';
6export declare enum ModelPersistenceEventType {
7 Save = 1,
8 Remove = 2,
9}
10export declare type ModelPersistenceEventCallback<M> = (type: ModelPersistenceEventType, ...models: M[]) => void;
11/**
12 * Options for repo decorations
13 */
14export interface IRepoOptions {
15 indexes?: Array<IIndexOptions>;
16}
17/**
18 * Options for finder decorations
19 */
20export interface IFinderOptions {
21 optional?: boolean;
22 single?: boolean;
23}
24/**
25 * Finder request for paging, etc
26 */
27export 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}
37export interface IFinderItemMetadata {
38 score?: number;
39 finderName?: string;
40}
41/**
42 * Finder result array - not implemented yet, mostly
43 */
44export 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 */
56export declare class DefaultModel implements IModel {
57 readonly clazzType: any;
58}
59/**
60 * Sync strategy for updating models in the store
61 */
62export declare enum SyncStrategy {
63 Overwrite = 0,
64 Update = 1,
65 None = 2,
66}
67export declare namespace SyncStrategy {
68 const toString: (strategy: SyncStrategy) => string;
69}
70/**
71 * Coordinator configuration, this is usually extend
72 * by individual store providers
73 */
74export interface ICoordinatorOptions {
75 immutable?: boolean;
76 syncStrategy?: SyncStrategy;
77 autoRegisterModels?: boolean;
78}
79/**
80 * Coordinator options default implementation
81 */
82export declare class CoordinatorOptions implements ICoordinatorOptions {
83 /**
84 * Default manager options
85 *
86 * @type {{autoRegisterModules: boolean, syncStrategy: SyncStrategy, immutable: boolean}}
87 */
88 static Defaults: {
89 autoRegisterModules: boolean;
90 syncStrategy: SyncStrategy;
91 immutable: boolean;
92 };
93 constructor(opts?: {});
94}
95export interface IModelMapperDecorator<M> {
96 (json: any, model: M): M;
97}
98/**
99 * Mapper interface for transforming objects back and forth between json
100 * and their respective models
101 */
102export 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 * Predicate for searching
110 */
111export interface IPredicate {
112 (val: any): boolean;
113}
114/**
115 * Makes a predicate for reuse
116 */
117export interface IPredicateFactory {
118 (...args: any[]): IPredicate;
119}
120/**
121 * Predicate for searching
122 */
123export interface ITypedPredicate<T> {
124 (val: T): boolean;
125}
126/**
127 * Makes a predicate for reuse
128 */
129export interface ITypedPredicateFactory<T> {
130 (type: {
131 new (): T;
132 }, ...args: any[]): ITypedPredicate<T>;
133}
134/**
135 * Coordinator interface for store provider development
136 * and end user management
137 *
138 * TODO: Rename coordinator
139 */
140export 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}