UNPKG

json-crdt-server

Version:

JSON CRDT server and syncing local-first browser client

61 lines (60 loc) 2.46 kB
import type { StoreSnapshot, StoreIncomingBatch, StoreBatch, Store } from './store/types'; import type { Services } from '../Services'; import { type Observable } from 'rxjs'; import type { TBlockEvent } from '../../routes/block/schema'; export interface BlocksServicesOpts { /** * How many historic batches to keep per block. */ historyPerBlock: number; /** * @param seq Current block sequence number. * @param pushSize The total blob size of the patches bushed by the latest push. * @returns Whether to compact the history. */ historyCompactionDecision: (seq: number, pushSize: number) => boolean; /** * As part of GC, check if we need to delete some of the oldest blocks. * Returns the number of oldest blocks to delete. If 0, no blocks will be * deleted. * * @returns The number of oldest blocks to delete. */ spaceReclaimDecision?: () => Promise<number>; } export declare class BlocksServices { protected readonly services: Services; protected readonly store: Store; protected readonly opts: BlocksServicesOpts; protected readonly spaceReclaimDecision: Required<BlocksServicesOpts>['spaceReclaimDecision']; constructor(services: Services, store?: Store, opts?: BlocksServicesOpts); create(id: string, clientId: number, batch?: StoreIncomingBatch): Promise<import("./store/types").StoreCreateResult>; private __emitNew; private __emitUpd; get(id: string): Promise<import("./store/types").StoreGetResult>; view(id: string): Promise<Readonly<unknown>>; remove(id: string): Promise<boolean>; scan(id: string, includeStartSnapshot: boolean, offset: number | undefined, limit?: number | undefined): Promise<{ snapshot: StoreSnapshot; batches: StoreBatch[]; } | { batches: StoreBatch[]; snapshot?: undefined; }>; pull(id: string, lastKnownSeq: number, create?: boolean): Promise<{ batches: StoreBatch[]; snapshot?: StoreSnapshot; }>; edit(id: string, batch: StoreIncomingBatch, createIfNotExists: boolean, clientId: number): Promise<{ snapshot: StoreSnapshot; batch: StoreBatch; }>; protected compact(id: string, to: number): Promise<void>; listen(id: string, clientId: number): Observable<TBlockEvent>; stats(): { blocks: number; batches: number; }; protected gc(): Promise<void>; stop(): Promise<void>; }