import { DocumentNode } from 'graphql'; import { BehaviorSubject, Observable } from 'rxjs'; import { StateSwitch } from 'state-switch'; import { _ModelMutationType } from '../generated-schemas/'; import { Apollo, Db, MutationUpdaterFn } from './db'; import { log } from './config'; export interface StoreSettings { dataKey: string; gqlQueryAll: DocumentNode; gqlSubscribe: DocumentNode; } export interface StoreAction { type: _ModelMutationType; node: any; } export declare abstract class Store { protected db: Db; protected settings: StoreSettings; protected state: StateSwitch; private itemListSubscription?; protected apollo?: Apollo; protected log: typeof log; protected itemList$: BehaviorSubject; itemList: Observable; constructor(db: Db, settings: StoreSettings); private open(); private refresh(apollo); private close(); private initSubscribeToMore(itemQuery); private initSubscription(itemQuery); private mutationReducer(state, action); protected mutationUpdateFnFactory(mutationType: _ModelMutationType, mutationDataKey: string): MutationUpdaterFn; /** * CRUD: * 1. create() * 2. read() * 3. update() * 4. delete() */ read(id: string): Promise; /** * TO BE IMPLEMENT in the sub class */ abstract delete(id: string): Promise; abstract create(newItem: Partial): Promise; abstract update(id: string, props: T): Promise; }