UNPKG

1.61 kBTypeScriptView Raw
1import Dexie from 'dexie';
2import { ICoordinator, ICoordinatorOptions, Repo, IModel, PluginType, IStorePlugin, IModelType, PluginEventType } from 'typestore';
3/**
4 * Options interface
5 */
6export interface IIndexedDBOptions {
7 /**
8 * Database name for Dexie/indexdb
9 */
10 databaseName?: string;
11 provider?: {
12 indexedDB: any;
13 IDBKeyRange: any;
14 };
15 version?: number;
16}
17/**
18 * Default options
19 */
20export declare const LocalStorageOptionDefaults: {
21 databaseName: string;
22 version: number;
23};
24/**
25 * Uses dexie under the covers - its a mature library - and i'm lazy
26 */
27export declare class IndexedDBPlugin implements IStorePlugin {
28 private opts;
29 type: PluginType;
30 supportedModels: any[];
31 private coordinator;
32 private internalDb;
33 private repoPlugins;
34 private tables;
35 constructor(opts?: IIndexedDBOptions, ...supportedModels: any[]);
36 private newDexie();
37 private open();
38 readonly db: Dexie;
39 handle(eventType: PluginEventType, ...args: any[]): boolean | any;
40 table(modelType: IModelType): Dexie.Table<any, any>;
41 init(coordinator: ICoordinator, opts: ICoordinatorOptions): Promise<ICoordinator>;
42 start(): Promise<ICoordinator>;
43 stop(): Promise<ICoordinator>;
44 syncModels(): Promise<ICoordinator>;
45 /**
46 * Initialize a new repo
47 * TODO: verify this logic works - just reading it makes me think we could be
48 * asked to init a repo a second time with the same type and do nothing
49 *
50 * @param repo
51 * @returns {T}
52 */
53 initRepo<T extends Repo<M>, M extends IModel>(repo: T): T;
54}