import { CRUDEvents, LocalStorage } from "./storage"; import { StoreChangeEvent } from "./storage"; import { ModelSchema } from "./ModelSchema"; import { PushStream } from "./utils/PushStream"; import { Filter } from "./filters"; import { ModelReplicationConfig } from "./replication/api/ReplicationConfig"; import { ModelChangeReplication } from "./replication/mutations/MutationsQueue"; import { FetchReplicator } from "./replication/fetch/FetchReplicator"; /** * Options that describe model field */ export interface FieldOptions { /** GraphQL type */ type: string; /** GraphQL key */ key: string; format?: {}; } /** * Defines the properties expected in the Fields object for a model */ export declare type Fields = { [P in keyof T]: FieldOptions; }; /** * Model Config options */ export interface ModelConfig { /** * Model name */ name: string; /** * Model store name, defualts to `user_${name}` */ storeName?: string; /** * Model fields */ fields: Fields; } /** * Provides CRUD capabilities for a model */ export declare class Model { schema: ModelSchema; replicationConfig: ModelReplicationConfig | undefined; replication?: ModelChangeReplication; changeEventStream: PushStream; private storage; private replicator?; constructor(schema: ModelSchema, storage: LocalStorage, replicationConfig?: ModelReplicationConfig); getFields(): Record; getName(): string; getStoreName(): string; getSchema(): ModelSchema; query(filter?: Filter): Promise; queryById(id: string): Promise; save(input: Partial): Promise; setReplicator(replicator: FetchReplicator): void; getReplicator(): FetchReplicator | undefined; /** * Provide a single method to apply optional filter * to model replicator and then start replication * * @param filter */ startReplication(filter?: Filter): void; /** * Apply filters to the model's fetch replicator * * @param filter */ applyFilter(filter: Filter): void; /** * Save changes (if it doesn't exist or update records with partial input * * @param input */ saveOrUpdate(input: Partial): Promise; /** * Update set of the objects by setting common values. * * @param input * @param filter */ update(input: Partial, filter?: Filter): Promise; /** * Update object by detecting it's id and using rest of the fields that are being merged with the original object * * @param input */ updateById(input: Partial): Promise; /** * Remove any set of objects using filter * * @param filter */ remove(filter: Filter): Promise; /** * Remove objects by it's id (using index) * * @param input object that needs to be removed * We need to pass entire object to ensure it's consistency (version) */ removeById(input: any): Promise; /** * Subscribe to **local** changes that happen in the model * * TODO add ability to filter subscriptions * * @param eventType - allows you to specify what event type you are interested in. * @param listener */ subscribe(listener: (event: StoreChangeEvent) => void, eventTypes?: CRUDEvents[]): import("./utils/PushStream").Subscription; /** * Process remote changes * * @param result result from delta */ processDeltaChanges(dataResult: any[], type?: CRUDEvents): Promise; /** * **Internal method** * * Process remote changes * * @param result result from subscription */ processSubscriptionChanges(dataResult: any, type: CRUDEvents): Promise; /** * Checks if model has client side id. * Usually this means that model was not replicated and id from the server was not assigned. */ hasClientID(): boolean; private addPrimaryKeyIfNeeded; }