import { AbstractLevel, AbstractDatabaseOptions, AbstractOpenOptions, AbstractGetOptions, AbstractGetManyOptions, AbstractPutOptions, AbstractDelOptions, AbstractBatchOperation, AbstractBatchOptions, AbstractChainedBatch, AbstractChainedBatchWriteOptions, AbstractIteratorOptions, AbstractIterator, AbstractKeyIterator, AbstractKeyIteratorOptions, AbstractValueIterator, AbstractValueIteratorOptions, Transcoder, NodeCallback } from 'abstract-level' /** * An {@link AbstractLevel} database backed by * [LevelDB](https://github.com/google/leveldb). * * @template KDefault The default type of keys if not overridden on operations. * @template VDefault The default type of values if not overridden on operations. */ declare class ClassicLevel extends AbstractLevel { /** * Database constructor. * * @param location Directory path (relative or absolute) where LevelDB will * store its files. * @param options Options, of which some will be forwarded to {@link open}. */ constructor ( location: string, options?: DatabaseOptions | undefined ) /** * Location that was passed to the constructor. */ get location (): string open (): Promise open (options: OpenOptions): Promise open (callback: NodeCallback): void open (options: OpenOptions, callback: NodeCallback): void get (key: KDefault): Promise get (key: KDefault, callback: NodeCallback): void get (key: K, options: GetOptions): Promise get (key: K, options: GetOptions, callback: NodeCallback): void getMany (keys: KDefault[]): Promise getMany (keys: KDefault[], callback: NodeCallback): void getMany (keys: K[], options: GetManyOptions): Promise getMany (keys: K[], options: GetManyOptions, callback: NodeCallback): void put (key: KDefault, value: VDefault): Promise put (key: KDefault, value: VDefault, callback: NodeCallback): void put (key: K, value: V, options: PutOptions): Promise put (key: K, value: V, options: PutOptions, callback: NodeCallback): void del (key: KDefault): Promise del (key: KDefault, callback: NodeCallback): void del (key: K, options: DelOptions): Promise del (key: K, options: DelOptions, callback: NodeCallback): void batch (operations: Array>): Promise batch (operations: Array>, callback: NodeCallback): void batch (operations: Array>, options: BatchOptions): Promise batch (operations: Array>, options: BatchOptions, callback: NodeCallback): void batch (): ChainedBatch iterator (): Iterator iterator (options: IteratorOptions): Iterator keys (): KeyIterator keys (options: KeyIteratorOptions): KeyIterator values (): ValueIterator values (options: ValueIteratorOptions): ValueIterator /** * Get the approximate number of bytes of file system space used by the range * `[start..end)`. */ approximateSize (start: KDefault, end: KDefault): Promise approximateSize (start: KDefault, end: KDefault, callback: NodeCallback): void approximateSize (start: K, end: K, options: StartEndOptions): Promise approximateSize (start: K, end: K, options: StartEndOptions, callback: NodeCallback): void /** * Manually trigger a database compaction in the range `[start..end)`. */ compactRange (start: KDefault, end: KDefault): Promise compactRange (start: KDefault, end: KDefault, callback: NodeCallback): void compactRange (start: K, end: K, options: StartEndOptions): Promise compactRange (start: K, end: K, options: StartEndOptions, callback: NodeCallback): void /** * Get internal details from LevelDB. */ getProperty (property: string): string /** * Completely remove an existing LevelDB database directory. Can be used in * place of a full directory removal to only remove LevelDB-related files. */ static destroy (location: string): Promise static destroy (location: string, callback: NodeCallback): void /** * Attempt a restoration of a damaged database. Can also be used to perform * a compaction of the LevelDB log into table files. */ static repair (location: string): Promise static repair (location: string, callback: NodeCallback): void } /** * Options for the database constructor. */ export interface DatabaseOptions extends AbstractDatabaseOptions, Omit {} /** * Options for the {@link ClassicLevel.open} method. */ export interface OpenOptions extends AbstractOpenOptions { /** * Unless set to `false`, all _compressible_ data will be run through the * Snappy compression algorithm before being stored. Snappy is very fast so * leave this on unless you have good reason to turn it off. * * @defaultValue `true` */ compression?: boolean | undefined /** * The size (in bytes) of the in-memory * [LRU](http://en.wikipedia.org/wiki/Least_Recently_Used) * cache with frequently used uncompressed block contents. * * @defaultValue `8 * 1024 * 1024` */ cacheSize?: number | undefined /** * The maximum size (in bytes) of the log (in memory and stored in the `.log` * file on disk). Beyond this size, LevelDB will convert the log data to the * first level of sorted table files. From LevelDB documentation: * * > Larger values increase performance, especially during bulk loads. Up to * > two write buffers may be held in memory at the same time, so you may * > wish to adjust this parameter to control memory usage. Also, a larger * > write buffer will result in a longer recovery time the next time the * > database is opened. * * @defaultValue `4 * 1024 * 1024` */ writeBufferSize?: number | undefined /** * The _approximate_ size of the blocks that make up the table files. The * size relates to uncompressed data (hence "approximate"). Blocks are * indexed in the table file and entry-lookups involve reading an entire * block and parsing to discover the required entry. * * @defaultValue `4096` */ blockSize?: number | undefined /** * The maximum number of files that LevelDB is allowed to have open at a * time. If your database is likely to have a large working set, you may * increase this value to prevent file descriptor churn. To calculate the * number of files required for your working set, divide your total data size * by `maxFileSize`. * * @defaultValue 1000 */ maxOpenFiles?: number | undefined /** * The number of entries before restarting the "delta encoding" of keys * within blocks. Each "restart" point stores the full key for the entry, * between restarts, the common prefix of the keys for those entries is * omitted. Restarts are similar to the concept of keyframes in video * encoding and are used to minimise the amount of space required to store * keys. This is particularly helpful when using deep namespacing / prefixing * in your keys. * * @defaultValue `16` */ blockRestartInterval?: number | undefined /** * The maximum amount of bytes to write to a file before switching to a new * one. From LevelDB documentation: * * > If your filesystem is more efficient with larger files, you could * > consider increasing the value. The downside will be longer compactions * > and hence longer latency / performance hiccups. Another reason to * > increase this parameter might be when you are initially populating a * > large database. * * @defaultValue `2 * 1024 * 1024` */ maxFileSize?: number | undefined /** * Allows multi-threaded access to a single DB instance for sharing a DB * across multiple worker threads within the same process. * * @defaultValue `false` */ multithreading?: boolean | undefined } /** * Additional options for the {@link ClassicLevel.get} and {@link ClassicLevel.getMany} * methods. */ declare interface ReadOptions { /** * Unless set to `false`, LevelDB will fill its in-memory * [LRU](http://en.wikipedia.org/wiki/Least_Recently_Used) cache with data * that was read. * * @defaultValue `true` */ fillCache?: boolean | undefined } /** * Options for the {@link ClassicLevel.get} method. */ export interface GetOptions extends AbstractGetOptions, ReadOptions {} /** * Options for the {@link ClassicLevel.getMany} method. */ export interface GetManyOptions extends AbstractGetManyOptions, ReadOptions {} /** * Additional options for the {@link ClassicLevel.iterator}, {@link ClassicLevel.keys} * and {@link ClassicLevel.values} methods. */ export interface AdditionalIteratorOptions { /** * If set to `true`, LevelDB will fill its in-memory * [LRU](http://en.wikipedia.org/wiki/Least_Recently_Used) cache with data * that was read. * * @defaultValue `false` */ fillCache?: boolean | undefined /** * Limit the amount of data that the iterator will hold in memory. */ highWaterMarkBytes?: number | undefined } /** * Additional options for the {@link ClassicLevel.put}, {@link ClassicLevel.del} * and {@link ClassicLevel.batch} methods. */ declare interface WriteOptions { /** * If set to `true`, LevelDB will perform a synchronous write of the data * although the operation will be asynchronous as far as Node.js or Electron * is concerned. Normally, LevelDB passes the data to the operating system * for writing and returns immediately. In contrast, a synchronous write will * use [`fsync()`](https://man7.org/linux/man-pages/man2/fsync.2.html) or * equivalent, so the operation will not complete until the data is actually * on disk. Synchronous writes are significantly slower than asynchronous * writes. * * @defaultValue `false` */ sync?: boolean | undefined } /** * Options for the {@link ClassicLevel.put} method. */ export interface PutOptions extends AbstractPutOptions, WriteOptions {} /** * Options for the {@link ClassicLevel.del} method. */ export interface DelOptions extends AbstractDelOptions, WriteOptions {} /** * Options for the {@link ClassicLevel.batch} method. */ export interface BatchOptions extends AbstractBatchOptions, WriteOptions {} /** * Options for the {@link ChainedBatch.write} method. */ export interface ChainedBatchWriteOptions extends AbstractChainedBatchWriteOptions, WriteOptions {} export class ChainedBatch extends AbstractChainedBatch { write (): Promise write (options: ChainedBatchWriteOptions): Promise write (callback: NodeCallback): void write (options: ChainedBatchWriteOptions, callback: NodeCallback): void } /** * Options for the {@link ClassicLevel.approximateSize} and * {@link ClassicLevel.compactRange} methods. */ export interface StartEndOptions { /** * Custom key encoding for this operation, used to encode `start` and `end`. */ keyEncoding?: string | Transcoder.PartialEncoder | undefined } // Export remaining types so that consumers don't have to guess whether they're extended export type BatchOperation = AbstractBatchOperation export type Iterator = AbstractIterator export type KeyIterator = AbstractKeyIterator export type ValueIterator = AbstractValueIterator export type IteratorOptions = AbstractIteratorOptions & AdditionalIteratorOptions export type KeyIteratorOptions = AbstractKeyIteratorOptions & AdditionalIteratorOptions export type ValueIteratorOptions = AbstractValueIteratorOptions & AdditionalIteratorOptions