import * as s from './store.ts'; import { Logger } from './Reactor.js'; import { InstaQLResponse, ValidQuery } from './queryTypes.ts'; import { EntitiesDef, IContainEntitiesAndLinks } from './schemaTypes.ts'; import { StoreInterface } from './index.ts'; type StartMsg = { op: 'start-sync'; q: string; }; type EndMsg = { op: 'remove-sync'; 'subscription-id': string; 'keep-subscription': boolean; }; type ResyncMsg = { op: 'resync-table'; 'subscription-id': string; 'tx-id': number; token: string; }; type SendMsg = StartMsg | EndMsg | ResyncMsg; type StartSyncOkMsg = { 'subscription-id': string; 'client-event-id': string; q: string; token: string; }; type Triple = [string, string, any, number]; type SyncLoadBatchMsg = { 'subscription-id': string; 'join-rows': Array; }; type SyncInitFinishMsg = { 'subscription-id': string; 'tx-id': number; }; type SyncUpdateTriplesMsg = { 'subscription-id': string; txes: { 'tx-id': number; changes: { action: 'added' | 'removed'; triple: Triple; }[]; }[]; }; type TrySend = (eventId: string, msg: SendMsg) => void; type Config = { useDateObjects: boolean; }; type CreateStore = (triples: Triple[]) => s.Store; export declare enum CallbackEventType { InitialSyncBatch = "InitialSyncBatch", InitialSyncComplete = "InitialSyncComplete", LoadFromStorage = "LoadFromStorage", SyncTransaction = "SyncTransaction", Error = "Error" } type QueryEntities, Q extends ValidQuery, UseDates extends boolean> = InstaQLResponse[keyof InstaQLResponse]; type QueryEntity, Q extends ValidQuery, UseDates extends boolean> = QueryEntities extends (infer E)[] ? E : never; type ChangedFields = { [K in keyof Entity]?: { oldValue: Entity[K]; newValue: Entity[K]; }; }; export interface BaseCallbackEvent, Q extends ValidQuery, UseDates extends boolean> { type: CallbackEventType; data: InstaQLResponse; } export interface InitialSyncBatch, Q extends ValidQuery, UseDates extends boolean> extends BaseCallbackEvent { type: CallbackEventType.InitialSyncBatch; batch: QueryEntities; } export interface InitialSyncComplete, Q extends ValidQuery, UseDates extends boolean> extends BaseCallbackEvent { type: CallbackEventType.InitialSyncComplete; } export interface SyncTransaction, Q extends ValidQuery, UseDates extends boolean> extends BaseCallbackEvent { type: CallbackEventType.SyncTransaction; added: QueryEntities; removed: QueryEntities; updated: { oldEntity: QueryEntity; newEntity: QueryEntity; changedFields: ChangedFields>; }[]; } export interface LoadFromStorage, Q extends ValidQuery, UseDates extends boolean> extends BaseCallbackEvent { type: CallbackEventType.LoadFromStorage; } export interface SetupError, Q extends ValidQuery, UseDates extends boolean> extends BaseCallbackEvent { type: CallbackEventType.Error; error: { message: string; hint?: any; type: string; status: number; }; } export type CallbackEvent, Q extends ValidQuery, UseDates extends boolean> = InitialSyncBatch | InitialSyncComplete | SyncTransaction | LoadFromStorage | SetupError; export type SyncTableCallback, Q extends ValidQuery, UseDates extends boolean> = (event: CallbackEvent) => void; export declare class SyncTable { private trySend; private subs; private callbacks; private config; private idToHash; private log; private createStore; private getAttrs; constructor(trySend: TrySend, storage: StoreInterface, config: Config, log: Logger, createStore: CreateStore, getAttrs: () => s.AttrsStore); beforeUnload(): void; subscribe(q: any, cb: SyncTableCallback): (opts?: { keepSubscription?: boolean | null | undefined; } | null | undefined) => void; private unsubscribe; private sendStart; private sendResync; private sendRemove; private initSubscription; flushPending(): Promise; onStartSyncOk(msg: StartSyncOkMsg): void; private notifyCbs; onSyncLoadBatch(msg: SyncLoadBatchMsg): void; onSyncInitFinish(msg: SyncInitFinishMsg): void; onSyncUpdateTriples(msg: SyncUpdateTriplesMsg): void; private clearSubscriptionData; onStartSyncError(msg: { op: 'error'; 'original-event': StartMsg; 'client-event-id': string; status: number; type: string; message?: string; hint?: any; }): void; onResyncError(msg: { op: 'error'; 'original-event': ResyncMsg; status: number; type: string; }): void; } export {}; //# sourceMappingURL=SyncTable.d.ts.map