helene
Version:
Real-time Web Apps for Node.js
58 lines (57 loc) • 1.97 kB
TypeScript
/**
* Handle every persistence-related task
* The interface Datastore expects to be implemented is
* * Persistence.loadDatabase(callback) and callback has signature err
* * Persistence.persistNewState(newDocs, callback) where newDocs is an array of documents and callback has signature err
*/
import { Collection } from './collection';
import { IStorage } from './types';
type Options = {
db: Collection;
corruptAlertThreshold?: number;
afterSerialization?: (s: string) => string;
beforeDeserialization?: (s: string) => string;
};
export declare class Persistence {
db: Collection;
inMemoryOnly: boolean;
name: string;
corruptAlertThreshold: number;
afterSerialization: (s: string) => string;
beforeDeserialization: (s: string) => string;
autocompactionIntervalId: NodeJS.Timeout | null;
storage: IStorage;
constructor(options?: Options);
loadDatabase(): Promise<any>;
throttleEmitUpdate: import("lodash").DebouncedFuncLeading<() => void>;
persistenceQueue: (() => Promise<void>)[];
/**
* This is the entry-point.
*/
persistNewState(newDocs: any): Promise<any>;
queuedPersistState(newDocs: any): void;
debouncedPersistState: import("lodash").DebouncedFunc<() => Promise<void>>;
persistCachedDatabase(): Promise<any>;
/**
* Queue a rewrite of the datafile
*/
compactDatafile(): Promise<any>;
/**
* Set automatic compaction every interval ms
* @param {Number} interval in milliseconds, with an enforced minimum of 5 seconds
*/
setAutocompactionInterval(interval: any): void;
/**
* Stop autocompaction (do nothing if autocompaction was not running)
*/
stopAutocompaction(): void;
/**
* From a database's raw data, return the corresponding
* machine understandable collection
*/
treatRawData(rawData: string): {
data: any[];
indexes: Record<string, any>;
};
}
export {};