///
import { QueryArgs } from "./common";
import * as stream from "stream";
export interface DragoEvent {
target: DragoDB;
time: number;
[key: string]: any;
}
export declare class DragoDB {
version: number;
/**
* `true` if the database is currently compacting, `false` otherwise.
* READ ONLY
*
* @type {boolean}
* @memberof DragoDB
*/
isCompacting: boolean;
/**
* `true` if there is an active, open transaction, `false` otherwise.
* READ ONLY
*
* @type {boolean}
* @memberof DragoDB
*/
isTx: boolean;
/**
* Holds the current key type.
* READ ONLY
*
* @type {("string" | "float" | "int" | "any")}
* @memberof DragoDB
*/
keyType: "string" | "float" | "int" | "any";
/**
* `true` if the in memory cache is enabled, `false` otherwise.
* READ ONLY
*
* @type {boolean}
* @memberof DragoDB
*/
memoryCache?: boolean;
/**
* Internal, do not touch!
*
* @type {number[]}
* @memberof DragoDB
*/
_clearCompactFiles: number[];
private _isReady;
private _path;
private _worker;
private _compactor;
private _rse;
private _hasEvents;
private _compactId;
private _database;
private _autoFlush;
private _isClosed;
/**
*Creates an instance of DragoDB.
* @param {({
* dir: string,
* key: "string" | "float" | "int" | "any",
* cache?: boolean,
* autoFlush?: number|boolean,
* singleThread?: boolean
* })} args
* @memberof DragoDB
*/
constructor(args: {
dir: string;
key?: "string" | "float" | "int" | "any";
cache?: boolean;
autoFlush?: number | boolean;
mainThread?: boolean;
} | string, keyType?: "string" | "float" | "int" | "any", cache?: boolean);
/**
* Listen for events
*
* @param {string} event
* @param {() => void} callback
* @memberof DragoDB
*/
on(event: string, callback: (event: DragoEvent) => void): void;
/**
* Turn off listener for events
*
* @param {string} event
* @param {() => void} callback
* @memberof DragoDB
*/
off(event: string, callback: (event: DragoEvent) => void): void;
/**
* Forces the log to be flushed to disk files, possibly causing a compaction.
*
* @returns {Promise}
* @memberof DragoDB
*/
flushLog(callback?: (err: any) => void): Promise;
/**
* Returns `true` if the database is ready, `false` otherwise.
*
* @returns {boolean}
* @memberof DragoDB
*/
isOpen(): boolean;
/**
* Returns `true` if the database isn't ready, `false` otherwise.
*
* @returns {boolean}
* @memberof DragoDB
*/
isClosed(): boolean;
/**
* This resolves when the database is ready to use.
*
* @returns {Promise}
* @memberof DragoDB
*/
ready(callback?: () => void): Promise;
/**
* Get a value from the database given it's key.
*
* @param {K} key
* @returns {Promise}
* @memberof DragoDB
*/
get(key: K, callback?: (err: any, value?: string) => void): Promise;
/**
* Delete a key and it's value from the data store.
*
* @param {K} key
* @returns {Promise}
* @memberof DragoDB
*/
delete(key: K, callback?: (err: any, key?: K) => void): Promise;
/**
* Delete a key and it's value from the data store.
*
* @param {K} key
* @param {(err: any) => void} [callback]
* @returns {Promise}
* @memberof DragoDB
*/
del(key: K, callback?: (err: any) => void): Promise;
/**
* Put a key and value into the data store.
* Replaces existing values with new values at the given key, otherwise creates a new key.
*
* @param {K} key
* @param {string} data
* @returns {Promise}
* @memberof DragoDB
*/
put(key: K, data: string, callback?: (err: any, response: any) => void): Promise;
/**
* API compatible version of batch query from LevelDB.
*
* @param {({type: "del"|"put", key: K, value?: string}[])} [ops]
* @param {(error: any) => void} [callback]
* @returns {*}
* @memberof DragoDB
*/
batch(ops?: {
type: "del" | "put";
key: K;
value?: string;
}[], callback?: (error: any) => void): any;
private _levelResultMutate;
/**
* LevelDB compatible createReadStream function.
*
* @param {QueryArgs} args
* @returns {stream.Readable}
* @memberof DragoDB
*/
createReadStream(args: QueryArgs): stream.Readable;
/**
* LevelDB compatible createKeyStream function.
*
* @param {QueryArgs} args
* @returns {stream.Readable}
* @memberof DragoDB
*/
createKeyStream(args: QueryArgs): stream.Readable;
/**
* LevelDB compatible createValueStream function.
*
* @param {QueryArgs} args
* @returns {stream.Readable}
* @memberof DragoDB
*/
createValueStream(args: QueryArgs): stream.Readable;
/**
* Get all keys from the data store in order, or optionally in reverse order.
*
* @param {(key: K) => void} onRecord
* @param {(err?: any) => void} onComplete
* @param {boolean} [reverse]
* @memberof DragoDB
*/
getAllKeys(onRecord: (key: K) => void, onComplete: (err?: any) => void, reverse?: boolean): void;
/**
* Get all keys from the data store in order, or optionally in reverse order.
*
* @param {boolean} [reverse]
* @returns {Promise>}
* @memberof DragoDB
*/
getAllKeysIt(reverse?: boolean): Promise>;
/**
*
*
* @param {boolean} [reverse]
* @returns {stream.Readable}
* @memberof DragoDB
*/
getAllKeysStream(reverse?: boolean): stream.Readable;
/**
* Get the total number of keys in the data store.
*
* @returns {Promise}
* @memberof DragoDB
*/
getCount(callback?: (err: any, count?: number) => void): Promise;
/**
* Get all keys and values from the store in order, or optionally in reverse order.
*
* @param {(key: K, data: string) => void} onRecord
* @param {(err?: any) => void} onComplete
* @param {boolean} [reverse]
* @memberof DragoDB
*/
getAll(onRecord: (key: K, data: string) => void, onComplete: (err?: any) => void, reverse?: boolean): void;
/**
* Get all keys and values from the store in order, or optionally in reverse order.
*
* @param {boolean} [reverse]
* @returns {Promise>}
* @memberof DragoDB
*/
getAllIt(reverse?: boolean): Promise>;
/**
* Get all keys and values from the store in order, or optionally in reverse order.
*
* @param {boolean} [reverse]
* @returns {stream.Readable}
* @memberof DragoDB
*/
getAllStream(reverse?: boolean): stream.Readable;
/**
* Gets the keys and values between a given range, inclusive. Optionally get the range in reverse order.
*
* @param {K} lower
* @param {K} higher
* @param {(key: K, data: string) => void} onRecord
* @param {(err?: any) => void} onComplete
* @param {boolean} [reverse]
* @memberof DragoDB
*/
range(lower: K, higher: K, onRecord: (key: K, data: string) => void, onComplete: (err?: any) => void, reverse?: boolean): void;
/**
* Gets the keys and values between a given range, inclusive. Optionally get the range in reverse order.
*
* @param {boolean} [reverse]
* @returns {Promise>}
* @memberof DragoDB
*/
rangeIt(lower: K, higher: K, reverse?: boolean): Promise>;
/**
* Gets the keys and values between a given range, inclusive. Optionally get the range in reverse order.
*
* @param {K} lower
* @param {K} higher
* @param {boolean} [reverse]
* @returns {stream.Readable}
* @memberof DragoDB
*/
rangeStream(lower: K, higher: K, reverse?: boolean): stream.Readable;
/**
* Get a collection of values from the keys at the given offset/limit. Optionally get the results from the end of the key set.
*
* @param {number} offset
* @param {number} limit
* @param {(key: K, data: string) => void} onRecord
* @param {(err?: any) => void} onComplete
* @param {boolean} [reverse]
* @memberof DragoDB
*/
offset(offset: number, limit: number, onRecord: (key: K, data: string) => void, onComplete: (err?: any) => void, reverse?: boolean): void;
/**
* Get a collection of values from the keys at the given offset/limit. Optionally get the results from the end of the key set.
*
* @param {boolean} [reverse]
* @returns {Promise>}
* @memberof DragoDB
*/
offsetIt(offset: number, limit: number, reverse?: boolean): Promise>;
/**
* Get a collection of values from the keys at the given offset/limit. Optionally get the results from the end of the key set.
*
* @param {number} offset
* @param {number} limit
* @param {boolean} [reverse]
* @returns {stream.Readable}
* @memberof DragoDB
*/
offsetStream(offset: number, limit: number, reverse?: boolean): stream.Readable;
/**
* Standard query for data
*
* @param {QueryArgs} args
* @param {((key: K, data: string|undefined) => void)} onRecord
* @param {(err?: any) => void} onComplete
* @memberof DragoDB
*/
query(args: QueryArgs, onRecord: (key: K, data: string | undefined) => void, onComplete: (err?: any) => void): void;
/**
* Get a collection of values from the keys at the given offset/limit. Optionally get the results from the end of the key set.
*
* @param {boolean} [reverse]
* @returns {Promise>}
* @memberof DragoDB
*/
queryIt(args: QueryArgs): Promise>;
/**
* Get a collection of values from the keys at the given offset/limit. Optionally get the results from the end of the key set.
*
* @param {QueryArgs} args
* @returns {stream.Readable}
* @memberof DragoDB
*/
queryStream(args: QueryArgs): stream.Readable;
/**
* Check if a key exists or not.
*
* @param {K} key
* @param {(err: any, exists: boolean) => void} [callback]
* @returns {Promise}
* @memberof DragoDB
*/
exists(key: K, callback?: (err: any, exists?: boolean) => void): Promise;
/**
* Begins a transaction.
*
* @returns {Promise}
* @memberof DragoDB
*/
startTx(callback?: (error: any, txNum?: number) => void): Promise;
/**
* Starts a transaction. (depreciated method, use .startTx() instead)
*
* @returns {Promise}
* @memberof DragoDB
*/
begin_transaction(): Promise;
/**
* Ends a transaction
*
* @returns {Promise}
* @memberof DragoDB
*/
endTx(callback?: (err: any, txNum?: number) => void): Promise;
/**
* Ends a transaction. (depreciated method, use .endTx() instead)
*
* @returns
* @memberof DragoDB
*/
end_transaction(): Promise;
/**
* Closes database. This isn't reversible, you must create a new DragoDB instance if you want to reconnect to this database without restarting your app.
*
* @returns {Promise}
* @memberof DragoDB
*/
close(callback?: (error?: any) => void): Promise;
/**
* Empty all keys and values from database.
*
* @returns {Promise}
* @memberof DragoDB
*/
empty(callback?: (err: any) => void): Promise;
/**
* Perform an async action after the database is ready. Does the action right away if the database is already ready.
*
* @private
* @param {(cres: (value?: unknown) => void, crej: (value?: unknown) => void) => void} callback
* @returns {Promise}
* @memberof DragoDB
*/
private _doWhenReady;
/**
* Handle messages from the compactor thread.
*
* @private
* @param {*} msg
* @memberof DragoDB
*/
private _onCompactorMessage;
/**
* Generate a message id and callback for sending messages to the worker thread.
*
* @private
* @param {(data: any) => void} cb
* @returns
* @memberof DragoDB
*/
private _msgID;
/**
* Make "any" type keys are numbers or strings
*
* @private
* @param {*} key
* @returns {*}
* @memberof DragoDB
*/
private _anyKey;
/**
* Handle work after compaction is finished.
*
* @private
* @memberof DragoDB
*/
private _cleanupCompaction;
private _streamKeysAndValues;
private _standardKeysAndValues;
/**
* Generate iterable for database queries.
*
* @private
* @param {("all"|"offset"|"range")} mode
* @param {any[]} args
* @param {boolean} reverse
* @param {string} progressEvent
* @param {string} doneEvent
* @returns {Promise>}
* @memberof DragoDB
*/
private _iterateKeysAndValues;
/**
* Generate new key iterator in the worker thread.
*
* @private
* @param {("all" | "offset" | "range")} mode
* @param {any[]} args
* @param {boolean} reverse
* @returns {Promise}
* @memberof DragoDB
*/
private _asyncNewIterator;
/**
* Increment the worker thread key iterator.
*
* @private
* @param {string} id
* @returns {Promise<{ key: K, done: boolean }>}
* @memberof DragoDB
*/
private _asyncNextIterator;
/**
* Clear an iterator from the worker thread.
*
* @private
* @param {string} id
* @returns {Promise}
* @memberof DragoDB
*/
private _asyncClearIteator;
}