///
import { Datastore } from "./datastore";
import { BaseModel } from "../types";
declare type PersistenceEventCallback = (message: string) => Promise;
declare type PersistenceEventEmits = "readLine" | "writeLine" | "end";
export declare class PersistenceEvent {
callbacks: {
readLine: Array;
writeLine: Array;
end: Array;
};
on(event: PersistenceEventEmits, cb: PersistenceEventCallback): void;
emit(event: PersistenceEventEmits, data: string): Promise;
}
interface PersistenceOptions> {
db: Datastore;
afterSerialization?: (raw: string) => string;
beforeDeserialization?: (encrypted: string) => string;
corruptAlertThreshold?: number;
model?: (new () => G) & {
new: (json: G) => G;
};
}
/**
* Create a new Persistence object for database options.db
*/
export declare class Persistence = any> {
db: Datastore;
ref: string;
corruptAlertThreshold: number;
afterSerialization: (s: string) => string;
beforeDeserialization: (s: string) => string;
autocompactionIntervalId: NodeJS.Timeout | undefined;
private _model;
protected _memoryIndexes: string[];
protected _memoryData: string[];
constructor(options: PersistenceOptions);
private persistAllIndexes;
private persistAllData;
private persistCachedDatabase;
/**
* Queue a rewrite of the datafile
*/
compactDatafile(): Promise;
/**
* Set automatic compaction every interval ms
*/
setAutocompactionInterval(interval?: number): void;
/**
* Stop autocompaction (do nothing if autocompaction was not running)
*/
stopAutocompaction(): void;
persistByAppendNewIndex(newDocs: any[]): Promise;
persistByAppendNewData(newDocs: any[]): Promise;
treatSingleLine(line: string): {
type: "index" | "doc" | "corrupt";
status: "add" | "remove";
data: any;
};
/**
* Load the database
* 1) Create all indexes
* 2) Insert all data
* This means pulling data out of the data file or creating it if it doesn't exist
*/
loadDatabase(): Promise;
init(): Promise;
readIndexes(event: PersistenceEvent): Promise;
readData(event: PersistenceEvent): Promise;
rewriteIndexes(event: PersistenceEvent): Promise;
rewriteData(event: PersistenceEvent): Promise;
appendIndex(data: string): Promise;
appendData(data: string): Promise;
forcefulUnlock(): Promise;
}
export {};