🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

lmdb

Package Overview
Dependencies
Maintainers
3
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lmdb - npm Package Compare versions

Comparing version
3.4.4
to
3.5.0
+322
-293
index.d.cts
declare namespace lmdb {
export function open<V = any, K extends Key = Key>(path: string, options: RootDatabaseOptions): RootDatabase<V, K>
export function open<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): RootDatabase<V, K>
export function openAsClass<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): DatabaseClass<V, K>
export function open<V = any, K extends Key = Key>(
path: string,
options: RootDatabaseOptions,
): RootDatabase<V, K>;
export function open<V = any, K extends Key = Key>(
options: RootDatabaseOptionsWithPath,
): RootDatabase<V, K>;
export function openAsClass<V = any, K extends Key = Key>(
options: RootDatabaseOptionsWithPath,
): DatabaseClass<V, K>;
class Database<V = any, K extends Key = Key> {
/**
* Get the value stored by given id/key
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
get(id: K, options?: GetOptions): V | undefined
* Get the value stored by given id/key
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
get(id: K, options?: GetOptions): V | undefined;
/**
* Get the entry stored by given id/key, which includes both the value and the version number (if available)
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
getEntry(id: K, options?: GetOptions): {
value: V
version?: number
} | undefined
* Get the entry stored by given id/key, which includes both the value and the version number (if available)
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
getEntry(
id: K,
options?: GetOptions,
):
| {
value: V;
version?: number;
}
| undefined;
/**
* Get the value stored by given id/key in binary format, as a Buffer
* @param id The key for the entry
**/
getBinary(id: K): Buffer | undefined
* Get the value stored by given id/key in binary format, as a Buffer
* @param id The key for the entry
**/
getBinary(id: K): Buffer | undefined;
/**
* Get the value stored by given id/key in binary format, as a temporary Buffer.
* This is faster, but the data is only valid until the next get operation (then it will be overwritten).
* @param id The key for the entry
**/
getBinaryFast(id: K): Buffer | undefined
* Get the value stored by given id/key in binary format, as a temporary Buffer.
* This is faster, but the data is only valid until the next get operation (then it will be overwritten).
* @param id The key for the entry
**/
getBinaryFast(id: K): Buffer | undefined;

@@ -43,19 +55,22 @@ /**

**/
retain(data: any): any
retain(data: any): any;
/**
* Asynchronously fetch the values stored by the given ids and accesses all
* pages to ensure that any hard page faults and disk I/O are performed
* asynchronously in a separate thread. Once completed, synchronous
* gets to the same entries will most likely be in memory and fast.
* @param ids The keys for the entries to prefetch
**/
prefetch(ids: K[], callback?: Function): Promise<void>
* Asynchronously fetch the values stored by the given ids and accesses all
* pages to ensure that any hard page faults and disk I/O are performed
* asynchronously in a separate thread. Once completed, synchronous
* gets to the same entries will most likely be in memory and fast.
* @param ids The keys for the entries to prefetch
**/
prefetch(ids: K[], callback?: Function): Promise<void>;
/**
* Asynchronously get the values stored by the given ids and return the
* values in array corresponding to the array of ids.
* @param ids The keys for the entries to get
**/
getMany(ids: K[], callback?: (error: any, values: V[]) => any): Promise<(V | undefined)[]>
* Asynchronously get the values stored by the given ids and return the
* values in array corresponding to the array of ids.
* @param ids The keys for the entries to get
**/
getMany(
ids: K[],
callback?: (error: any, values: V[]) => any,
): Promise<(V | undefined)[]>;

@@ -67,133 +82,139 @@ /**

*/
getAsync(id: K, options?: GetOptions, callback?: (value: V) => any): Promise<(V | undefined)[]>
getAsync(
id: K,
options?: GetOptions,
callback?: (value: V) => any,
): Promise<(V | undefined)[]>;
/**
* Store the provided value, using the provided id/key
* @param id The key for the entry
* @param value The value to store
**/
put(id: K, value: V): Promise<boolean>
* Store the provided value, using the provided id/key
* @param id The key for the entry
* @param value The value to store
**/
put(id: K, value: V): Promise<boolean>;
/**
* Store the provided value, using the provided id/key and version number, and optionally the required
* existing version
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
* @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
**/
put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>
* Store the provided value, using the provided id/key and version number, and optionally the required
* existing version
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
* @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
**/
put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>;
/**
* Remove the entry with the provided id/key
* @param id The key for the entry to remove
**/
remove(id: K): Promise<boolean>
* Remove the entry with the provided id/key
* @param id The key for the entry to remove
**/
remove(id: K): Promise<boolean>;
/**
* Remove the entry with the provided id/key, conditionally based on the provided existing version number
* @param id The key for the entry to remove
* @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
**/
remove(id: K, ifVersion: number): Promise<boolean>
* Remove the entry with the provided id/key, conditionally based on the provided existing version number
* @param id The key for the entry to remove
* @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
**/
remove(id: K, ifVersion: number): Promise<boolean>;
/**
* Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
remove(id: K, valueToRemove: V): Promise<boolean>
* Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
remove(id: K, valueToRemove: V): Promise<boolean>;
/**
* Synchronously store the provided value, using the provided id/key, will return after the data has been written.
* @param id The key for the entry
* @param value The value to store
**/
putSync(id: K, value: V): void
* Synchronously store the provided value, using the provided id/key, will return after the data has been written.
* @param id The key for the entry
* @param value The value to store
**/
putSync(id: K, value: V): void;
/**
* Synchronously store the provided value, using the provided id/key and version number
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
**/
putSync(id: K, value: V, version: number): void
* Synchronously store the provided value, using the provided id/key and version number
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
**/
putSync(id: K, value: V, version: number): void;
/**
* Synchronously store the provided value, using the provided id/key and options
* @param id The key for the entry
* @param value The value to store
* @param options The version number to assign to this entry
**/
putSync(id: K, value: V, options: PutOptions): void
* Synchronously store the provided value, using the provided id/key and options
* @param id The key for the entry
* @param value The value to store
* @param options The version number to assign to this entry
**/
putSync(id: K, value: V, options: PutOptions): void;
/**
* Synchronously remove the entry with the provided id/key
* existing version
* @param id The key for the entry to remove
**/
removeSync(id: K): boolean
* Synchronously remove the entry with the provided id/key
* existing version
* @param id The key for the entry to remove
**/
removeSync(id: K): boolean;
/**
* Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
removeSync(id: K, valueToRemove: V): boolean
* Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
removeSync(id: K, valueToRemove: V): boolean;
/**
* Get all the values for the given key (for dupsort databases)
* existing version
* @param key The key for the entry to remove
* @param options The options for the iterator
**/
getValues(key: K, options?: RangeOptions): RangeIterable<V>
* Get all the values for the given key (for dupsort databases)
* existing version
* @param key The key for the entry to remove
* @param options The options for the iterator
**/
getValues(key: K, options?: RangeOptions): RangeIterable<V>;
/**
* Get the count of all the values for the given key (for dupsort databases)
* existing version
* @param options The options for the range/iterator
**/
getValuesCount(key: K, options?: RangeOptions): number
* Get the count of all the values for the given key (for dupsort databases)
* existing version
* @param options The options for the range/iterator
**/
getValuesCount(key: K, options?: RangeOptions): number;
/**
* Get all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeys(options?: RangeOptions): RangeIterable<K>
* Get all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeys(options?: RangeOptions): RangeIterable<K>;
/**
* Get the count of all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeysCount(options?: RangeOptions): number
* Get the count of all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeysCount(options?: RangeOptions): number;
/**
* Get all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getRange(options?: RangeOptions): RangeIterable<{ key: K, value: V, version?: number }>
* Get all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getRange(
options?: RangeOptions,
): RangeIterable<{ key: K; value: V; version?: number }>;
/**
* Get the count of all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getCount(options?: RangeOptions): number
* Get the count of all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getCount(options?: RangeOptions): number;
/**
* @deprecated since version 2.0, use transaction() instead
*/
transactionAsync<T>(action: () => T): T
transactionAsync<T>(action: () => T): T;
/**
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
transaction<T>(action: () => T): Promise<T>
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
transaction<T>(action: () => T): Promise<T>;
/**
* Execute a transaction synchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
* @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
**/
transactionSync<T>(action: () => T, flags?: TransactionFlags): T
* Execute a transaction synchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
* @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
**/
transactionSync<T>(action: () => T, flags?: TransactionFlags): T;
/**
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
childTransaction<T>(action: () => T): Promise<T>
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
childTransaction<T>(action: () => T): Promise<T>;
/**

@@ -205,104 +226,107 @@ * Returns the transaction id of the currently executing transaction. This is an integer that increments with each

*/
getWriteTxnId(): number
getWriteTxnId(): number;
/**
* Returns the current transaction and marks it as in use. This can then be explicitly used for read operations
* @returns The transaction object
**/
useReadTransaction(): Transaction
* Returns the current transaction and marks it as in use. This can then be explicitly used for read operations
* @returns The transaction object
**/
useReadTransaction(): Transaction;
/**
* Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
* @param action The function to execute with a set of write operations.
**/
batch<T>(action: () => any): Promise<boolean>
* Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
* @param action The function to execute with a set of write operations.
**/
batch<T>(action: () => any): Promise<boolean>;
/**
* Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
* version number (checked atomically).
* @param id Key of the entry to check
* @param ifVersion The require version number of the entry for all actions to succeed
* @param action The function to execute with actions that will be dependent on this condition
**/
ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>
* Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
* version number (checked atomically).
* @param id Key of the entry to check
* @param ifVersion The require version number of the entry for all actions to succeed
* @param action The function to execute with actions that will be dependent on this condition
**/
ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>;
/**
* Execute writes actions that are all conditionally dependent on the entry with the provided key
* not existing (checked atomically).
* @param id Key of the entry to check
* @param action The function to execute with actions that will be dependent on this condition
**/
ifNoExists(id: K, action: () => any): Promise<boolean>
* Execute writes actions that are all conditionally dependent on the entry with the provided key
* not existing (checked atomically).
* @param id Key of the entry to check
* @param action The function to execute with actions that will be dependent on this condition
**/
ifNoExists(id: K, action: () => any): Promise<boolean>;
/**
* Check if an entry for the provided key exists
* @param id Key of the entry to check
*/
doesExist(key: K): boolean
* Check if an entry for the provided key exists
* @param id Key of the entry to check
*/
doesExist(key: K): boolean;
/**
* Check if an entry for the provided key/value exists
* @param id Key of the entry to check
* @param value Value of the entry to check (can be undefined to check for existence of the entry)
* @param options Options for existence check (can include transaction)
*/
doesExist(key: K, value: V, options?: GetOptions): boolean
* Check if an entry for the provided key/value exists
* @param id Key of the entry to check
* @param value Value of the entry to check (can be undefined to check for existence of the entry)
* @param options Options for existence check (can include transaction)
*/
doesExist(key: K, value: V, options?: GetOptions): boolean;
/**
* Check if an entry for the provided key exists with the expected version
* @param id Key of the entry to check
* @param version Expected version
*/
doesExist(key: K, version: number): boolean
* Check if an entry for the provided key exists with the expected version
* @param id Key of the entry to check
* @param version Expected version
*/
doesExist(key: K, version: number): boolean;
/**
* @deprecated since version 2.0, use drop() or dropSync() instead
*/
deleteDB(): Promise<void>
* @deprecated since version 2.0, use drop() or dropSync() instead
*/
deleteDB(): Promise<void>;
/**
* Delete this database/store (asynchronously).
**/
drop(): Promise<void>
* Delete this database/store (asynchronously).
**/
drop(): Promise<void>;
/**
* Synchronously delete this database/store.
**/
dropSync(): void
* Synchronously delete this database/store.
**/
dropSync(): void;
/**
* @deprecated since version 2.0, use clearAsync() or clearSync() instead
*/
clear(): Promise<void>
* @deprecated since version 2.0, use clearAsync() or clearSync() instead
*/
clear(): Promise<void>;
/**
* Asynchronously clear all the entries from this database/store.
**/
clearAsync(): Promise<void>
* Asynchronously clear all the entries from this database/store.
**/
clearAsync(): Promise<void>;
/**
* Synchronously clear all the entries from this database/store.
**/
clearSync(): void
* Synchronously clear all the entries from this database/store.
**/
clearSync(): void;
/** A promise-like object that resolves when previous writes have been committed. */
committed: Promise<boolean>
committed: Promise<boolean>;
/** A promise-like object that resolves when previous writes have been committed and fully flushed/synced to disk/storage. */
flushed: Promise<boolean>
flushed: Promise<boolean>;
/**
* Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
**/
readerCheck(): number
* Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
**/
readerCheck(): number;
/**
* Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
**/
readerList(): string
* Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
**/
readerList(): string;
/**
* Returns statistics about the current database
**/
getStats(): {}
* Returns statistics about the current database
**/
getStats(): {};
/**
* Explicitly force the read transaction to reset to the latest snapshot/version of the database
**/
resetReadTxn(): void
* Explicitly force the read transaction to reset to the latest snapshot/version of the database
**/
resetReadTxn(): void;
/**
* Make a snapshot copy of the current database at the indicated path
* @param path Path to store the backup
* @param compact Apply compaction while making the backup (slower and smaller)
**/
backup(path: string, compact: boolean): Promise<void>
* Make a snapshot copy of the current database at the indicated path
* @param path Path to store the backup
* @param compact Apply compaction while making the backup (slower and smaller)
**/
backup(path: string, compact: boolean): Promise<void>;
/**
* Close the current database.
**/
close(): Promise<void>
* Close the current database.
**/
close(): Promise<void>;
/**
* Add event listener
*/
on(event: 'beforecommit' | 'aftercommit', callback: (event: any) => void): void
on(
event: 'beforecommit' | 'aftercommit',
callback: (event: any) => void,
): void;
}

@@ -317,12 +341,17 @@ /* A constant that can be returned from a transaction to indicate that the transaction should be aborted */

/**
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(options?: DatabaseOptions & { name: string }): Database<OV, OK>
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(
options?: DatabaseOptions & { name: string },
): Database<OV, OK>;
/**
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(dbName: string, dbOptions: DatabaseOptions): Database<OV, OK>
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(
dbName: string,
dbOptions: DatabaseOptions,
): Database<OV, OK>;
}
class DatabaseClass<V = any, K extends Key = Key> {
new(name: string | null, options: DatabaseOptions): Database<V, K>
new(name: string | null, options: DatabaseOptions): Database<V, K>;
}

@@ -333,17 +362,17 @@

interface DatabaseOptions {
name?: string
cache?: boolean | {}
compression?: boolean | CompressionOptions
encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary'
sharedStructuresKey?: Key
useVersions?: boolean
keyEncoding?: 'uint32' | 'binary' | 'ordered-binary'
dupSort?: boolean
strictAsyncOrder?: boolean
name?: string;
cache?: boolean | {};
compression?: boolean | CompressionOptions;
encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary';
sharedStructuresKey?: Key;
useVersions?: boolean;
keyEncoding?: 'uint32' | 'binary' | 'ordered-binary';
dupSort?: boolean;
strictAsyncOrder?: boolean;
}
interface RootDatabaseOptions extends DatabaseOptions {
/** The maximum number of databases to be able to open (there is some extra overhead if this is set very high).*/
maxDbs?: number
maxDbs?: number;
/** Set a longer delay (in milliseconds) to wait longer before committing writes to increase the number of writes per transaction (higher latency, but more efficient) **/
commitDelay?: number
commitDelay?: number;
/**

@@ -353,3 +382,3 @@ * This can be used to specify the initial amount of how much virtual memory address space (in bytes) to allocate for mapping to the database files.

**/
mapSize?: number
mapSize?: number;
/**

@@ -359,7 +388,7 @@ * This defines the page size of the database. This defaults to the default page size of the OS (usually 4,096, except on MacOS with M-series, which is 16,384 bytes).

* Note that this only effects the page size of new databases (does not affect existing databases). */
pageSize?: number
pageSize?: number;
/** This enables committing transactions where LMDB waits for a transaction to be fully flushed to disk after the transaction has been committed and defaults to being enabled on non-Windows OSes. This option is discussed in more detail below. */
overlappingSync?: boolean
overlappingSync?: boolean;
/** Resolve asynchronous operations when commits are finished and visible and include a separate promise for when a commit is flushed to disk, as a flushed property on the commit promise. Note that you can alternately use the flushed property on the database. */
separateFlushed?: boolean
separateFlushed?: boolean;
/**

@@ -369,9 +398,9 @@ * This a flag to specify if dynamic memory mapping should be used. Enabling this generally makes read operations a little bit slower, but frees up more mapped memory, making it friendlier to other applications.

**/
remapChunks?: boolean
remapChunks?: boolean;
/** This provides a small performance boost (when not using useWritemap) for writes, by skipping zero'ing out malloc'ed data, but can leave application data in unused portions of the database. This is recommended unless there are concerns of database files being accessible. */
noMemInit?: boolean
noMemInit?: boolean;
/** Use writemaps, discouraged at this. This improves performance by reducing malloc calls, but it is possible for a stray pointer to corrupt data. */
useWritemap?: boolean
useWritemap?: boolean;
/** Treat path as a filename instead of directory (this is the default if the path appears to end with an extension and has '.' in it) */
noSubdir?: boolean
noSubdir?: boolean;
/**

@@ -381,11 +410,11 @@ * Does not explicitly flush data to disk at all. This can be useful for temporary databases where durability/integrity is not necessary, and can significantly improve write performance that is I/O bound.

**/
noSync?: boolean
noSync?: boolean;
/** This isn't as dangerous as `noSync`, but doesn't improve performance much either. */
noMetaSync?: boolean
noMetaSync?: boolean;
/** Self-descriptive */
readOnly?: boolean
readOnly?: boolean;
/** The maximum number of concurrent read transactions (readers) to be able to open ([more information](http://www.lmdb.tech/doc/group__mdb.html#gae687966c24b790630be2a41573fe40e2)). */
maxReaders?: number
maxReaders?: number;
/** This enables encryption, and the provided value is the key that is used for encryption. This may be a buffer or string, but must be 32 bytes/characters long. This uses the Chacha8 cipher for fast and secure on-disk encryption of data. */
encryptionKey?: string | Buffer
encryptionKey?: string | Buffer;
/**

@@ -397,47 +426,47 @@ * This is enabled by default and will ensure that all asynchronous write operations performed in the same event turn will be batched together into the same transaction.

**/
eventTurnBatching?: boolean
eventTurnBatching?: boolean;
/** This is the current encoder instance that is being used to serialize data */
encoder?: any
encoder?: any;
/** This is the current decoder instance that is being used to deserialize data */
decoder?: any
decoder?: any;
}
interface RootDatabaseOptionsWithPath extends RootDatabaseOptions {
path?: string
path?: string;
}
interface CompressionOptions {
threshold?: number
dictionary?: Buffer
threshold?: number;
dictionary?: Buffer;
}
interface GetOptions {
transaction?: Transaction
transaction?: Transaction;
}
interface RangeOptions {
/** Starting key for a range **/
start?: Key
start?: Key;
/** Ending key for a range **/
end?: Key
end?: Key;
/** Iterate through the entries in reverse order **/
reverse?: boolean
reverse?: boolean;
/** Include version numbers in each entry returned **/
versions?: boolean
versions?: boolean;
/** The maximum number of entries to return **/
limit?: number
limit?: number;
/** The number of entries to skip **/
offset?: number
offset?: number;
/** Use a snapshot of the database from when the iterator started **/
snapshot?: boolean
snapshot?: boolean;
/** Use the provided transaction for this range query */
transaction?: Transaction
transaction?: Transaction;
}
interface PutOptions {
/* Append to the database using MDB_APPEND, which can be faster */
append?: boolean
append?: boolean;
/* Append to a dupsort database using MDB_APPENDDUP, which can be faster */
appendDup?: boolean
appendDup?: boolean;
/* Perform put with MDB_NOOVERWRITE which will fail if the entry for the key already exists */
noOverwrite?: boolean
noOverwrite?: boolean;
/* Perform put with MDB_NODUPDATA which will fail if the entry for the key/value already exists */
noDupData?: boolean
noDupData?: boolean;
/* The version of the entry to set */
version?: number
version?: number;
}

@@ -450,14 +479,14 @@ export enum TransactionFlags {

/* Indicates that the function can return before the transaction has been flushed to disk */
NO_SYNC_FLUSH = 0x10000
NO_SYNC_FLUSH = 0x10000,
}
class RangeIterable<T> implements Iterable<T> {
map<U>(callback: (entry: T) => U): RangeIterable<U>
flatMap<U>(callback: (entry: T) => U[]): RangeIterable<U>
slice(start: number, end: number): RangeIterable<T>
filter(callback: (entry: T) => any): RangeIterable<T>
[Symbol.iterator]() : Iterator<T>
forEach(callback: (entry: T) => any): void
mapError<U>(callback: (error: Error) => U): RangeIterable<U>
onDone?: Function
asArray: T[]
map<U>(callback: (entry: T) => U): RangeIterable<U>;
flatMap<U>(callback: (entry: T) => U[]): RangeIterable<U>;
slice(start: number, end: number): RangeIterable<T>;
filter(callback: (entry: T) => any): RangeIterable<T>;
[Symbol.iterator](): Iterator<T>;
forEach(callback: (entry: T) => any): void;
mapError<U>(callback: (error: Error) => U): RangeIterable<U>;
onDone?: Function;
asArray: Promise<T[]>;
}

@@ -468,15 +497,15 @@ class Transaction {

*/
done(): void
done(): void;
}
export function getLastVersion(): number
export function compareKeys(a: Key, b: Key): number
export function getLastVersion(): number;
export function compareKeys(a: Key, b: Key): number;
class Binary {}
/* Wrap a Buffer/Uint8Array for direct assignment as a value bypassing any encoding, for put (and doesExist) operations.
*/
export function asBinary(buffer: Uint8Array): Binary
*/
export function asBinary(buffer: Uint8Array): Binary;
/* Indicates if V8 accelerated functions are enabled. If this is false, some functions will be a little slower, and you may want to npm install --build-from-source to enable maximum performance */
export let v8AccelerationEnabled: boolean
export let v8AccelerationEnabled: boolean;
/* Return database augmented with methods to better conform to levelup */
export function levelup(database: Database): Database
export function levelup(database: Database): Database;
}
export = lmdb
export = lmdb;
+322
-293
declare namespace lmdb {
export function open<V = any, K extends Key = Key>(path: string, options: RootDatabaseOptions): RootDatabase<V, K>
export function open<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): RootDatabase<V, K>
export function openAsClass<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): DatabaseClass<V, K>
export function open<V = any, K extends Key = Key>(
path: string,
options: RootDatabaseOptions,
): RootDatabase<V, K>;
export function open<V = any, K extends Key = Key>(
options: RootDatabaseOptionsWithPath,
): RootDatabase<V, K>;
export function openAsClass<V = any, K extends Key = Key>(
options: RootDatabaseOptionsWithPath,
): DatabaseClass<V, K>;
class Database<V = any, K extends Key = Key> {
/**
* Get the value stored by given id/key
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
get(id: K, options?: GetOptions): V | undefined
* Get the value stored by given id/key
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
get(id: K, options?: GetOptions): V | undefined;
/**
* Get the entry stored by given id/key, which includes both the value and the version number (if available)
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
getEntry(id: K, options?: GetOptions): {
value: V
version?: number
} | undefined
* Get the entry stored by given id/key, which includes both the value and the version number (if available)
* @param id The key for the entry
* @param options Additional options for the retrieval
**/
getEntry(
id: K,
options?: GetOptions,
):
| {
value: V;
version?: number;
}
| undefined;
/**
* Get the value stored by given id/key in binary format, as a Buffer
* @param id The key for the entry
**/
getBinary(id: K): Buffer | undefined
* Get the value stored by given id/key in binary format, as a Buffer
* @param id The key for the entry
**/
getBinary(id: K): Buffer | undefined;
/**
* Get the value stored by given id/key in binary format, as a temporary Buffer.
* This is faster, but the data is only valid until the next get operation (then it will be overwritten).
* @param id The key for the entry
**/
getBinaryFast(id: K): Buffer | undefined
* Get the value stored by given id/key in binary format, as a temporary Buffer.
* This is faster, but the data is only valid until the next get operation (then it will be overwritten).
* @param id The key for the entry
**/
getBinaryFast(id: K): Buffer | undefined;

@@ -43,19 +55,22 @@ /**

**/
retain(data: any): any
retain(data: any): any;
/**
* Asynchronously fetch the values stored by the given ids and accesses all
* pages to ensure that any hard page faults and disk I/O are performed
* asynchronously in a separate thread. Once completed, synchronous
* gets to the same entries will most likely be in memory and fast.
* @param ids The keys for the entries to prefetch
**/
prefetch(ids: K[], callback?: Function): Promise<void>
* Asynchronously fetch the values stored by the given ids and accesses all
* pages to ensure that any hard page faults and disk I/O are performed
* asynchronously in a separate thread. Once completed, synchronous
* gets to the same entries will most likely be in memory and fast.
* @param ids The keys for the entries to prefetch
**/
prefetch(ids: K[], callback?: Function): Promise<void>;
/**
* Asynchronously get the values stored by the given ids and return the
* values in array corresponding to the array of ids.
* @param ids The keys for the entries to get
**/
getMany(ids: K[], callback?: (error: any, values: V[]) => any): Promise<(V | undefined)[]>
* Asynchronously get the values stored by the given ids and return the
* values in array corresponding to the array of ids.
* @param ids The keys for the entries to get
**/
getMany(
ids: K[],
callback?: (error: any, values: V[]) => any,
): Promise<(V | undefined)[]>;

@@ -67,133 +82,139 @@ /**

*/
getAsync(id: K, options?: GetOptions, callback?: (value: V) => any): Promise<(V | undefined)[]>
getAsync(
id: K,
options?: GetOptions,
callback?: (value: V) => any,
): Promise<(V | undefined)[]>;
/**
* Store the provided value, using the provided id/key
* @param id The key for the entry
* @param value The value to store
**/
put(id: K, value: V): Promise<boolean>
* Store the provided value, using the provided id/key
* @param id The key for the entry
* @param value The value to store
**/
put(id: K, value: V): Promise<boolean>;
/**
* Store the provided value, using the provided id/key and version number, and optionally the required
* existing version
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
* @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
**/
put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>
* Store the provided value, using the provided id/key and version number, and optionally the required
* existing version
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
* @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
**/
put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>;
/**
* Remove the entry with the provided id/key
* @param id The key for the entry to remove
**/
remove(id: K): Promise<boolean>
* Remove the entry with the provided id/key
* @param id The key for the entry to remove
**/
remove(id: K): Promise<boolean>;
/**
* Remove the entry with the provided id/key, conditionally based on the provided existing version number
* @param id The key for the entry to remove
* @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
**/
remove(id: K, ifVersion: number): Promise<boolean>
* Remove the entry with the provided id/key, conditionally based on the provided existing version number
* @param id The key for the entry to remove
* @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
**/
remove(id: K, ifVersion: number): Promise<boolean>;
/**
* Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
remove(id: K, valueToRemove: V): Promise<boolean>
* Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
remove(id: K, valueToRemove: V): Promise<boolean>;
/**
* Synchronously store the provided value, using the provided id/key, will return after the data has been written.
* @param id The key for the entry
* @param value The value to store
**/
putSync(id: K, value: V): void
* Synchronously store the provided value, using the provided id/key, will return after the data has been written.
* @param id The key for the entry
* @param value The value to store
**/
putSync(id: K, value: V): void;
/**
* Synchronously store the provided value, using the provided id/key and version number
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
**/
putSync(id: K, value: V, version: number): void
* Synchronously store the provided value, using the provided id/key and version number
* @param id The key for the entry
* @param value The value to store
* @param version The version number to assign to this entry
**/
putSync(id: K, value: V, version: number): void;
/**
* Synchronously store the provided value, using the provided id/key and options
* @param id The key for the entry
* @param value The value to store
* @param options The version number to assign to this entry
**/
putSync(id: K, value: V, options: PutOptions): void
* Synchronously store the provided value, using the provided id/key and options
* @param id The key for the entry
* @param value The value to store
* @param options The version number to assign to this entry
**/
putSync(id: K, value: V, options: PutOptions): void;
/**
* Synchronously remove the entry with the provided id/key
* existing version
* @param id The key for the entry to remove
**/
removeSync(id: K): boolean
* Synchronously remove the entry with the provided id/key
* existing version
* @param id The key for the entry to remove
**/
removeSync(id: K): boolean;
/**
* Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
removeSync(id: K, valueToRemove: V): boolean
* Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
* existing version
* @param id The key for the entry to remove
* @param valueToRemove The value for the entry to remove
**/
removeSync(id: K, valueToRemove: V): boolean;
/**
* Get all the values for the given key (for dupsort databases)
* existing version
* @param key The key for the entry to remove
* @param options The options for the iterator
**/
getValues(key: K, options?: RangeOptions): RangeIterable<V>
* Get all the values for the given key (for dupsort databases)
* existing version
* @param key The key for the entry to remove
* @param options The options for the iterator
**/
getValues(key: K, options?: RangeOptions): RangeIterable<V>;
/**
* Get the count of all the values for the given key (for dupsort databases)
* existing version
* @param options The options for the range/iterator
**/
getValuesCount(key: K, options?: RangeOptions): number
* Get the count of all the values for the given key (for dupsort databases)
* existing version
* @param options The options for the range/iterator
**/
getValuesCount(key: K, options?: RangeOptions): number;
/**
* Get all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeys(options?: RangeOptions): RangeIterable<K>
* Get all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeys(options?: RangeOptions): RangeIterable<K>;
/**
* Get the count of all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeysCount(options?: RangeOptions): number
* Get the count of all the unique keys for the given range
* existing version
* @param options The options for the range/iterator
**/
getKeysCount(options?: RangeOptions): number;
/**
* Get all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getRange(options?: RangeOptions): RangeIterable<{ key: K, value: V, version?: number }>
* Get all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getRange(
options?: RangeOptions,
): RangeIterable<{ key: K; value: V; version?: number }>;
/**
* Get the count of all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getCount(options?: RangeOptions): number
* Get the count of all the entries for the given range
* existing version
* @param options The options for the range/iterator
**/
getCount(options?: RangeOptions): number;
/**
* @deprecated since version 2.0, use transaction() instead
*/
transactionAsync<T>(action: () => T): T
transactionAsync<T>(action: () => T): T;
/**
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
transaction<T>(action: () => T): Promise<T>
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
transaction<T>(action: () => T): Promise<T>;
/**
* Execute a transaction synchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
* @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
**/
transactionSync<T>(action: () => T, flags?: TransactionFlags): T
* Execute a transaction synchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
* @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
**/
transactionSync<T>(action: () => T, flags?: TransactionFlags): T;
/**
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
childTransaction<T>(action: () => T): Promise<T>
* Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
* and committing the transaction after the action callback completes.
* existing version
* @param action The function to execute within the transaction
**/
childTransaction<T>(action: () => T): Promise<T>;
/**

@@ -205,104 +226,107 @@ * Returns the transaction id of the currently executing transaction. This is an integer that increments with each

*/
getWriteTxnId(): number
getWriteTxnId(): number;
/**
* Returns the current transaction and marks it as in use. This can then be explicitly used for read operations
* @returns The transaction object
**/
useReadTransaction(): Transaction
* Returns the current transaction and marks it as in use. This can then be explicitly used for read operations
* @returns The transaction object
**/
useReadTransaction(): Transaction;
/**
* Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
* @param action The function to execute with a set of write operations.
**/
batch<T>(action: () => any): Promise<boolean>
* Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
* @param action The function to execute with a set of write operations.
**/
batch<T>(action: () => any): Promise<boolean>;
/**
* Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
* version number (checked atomically).
* @param id Key of the entry to check
* @param ifVersion The require version number of the entry for all actions to succeed
* @param action The function to execute with actions that will be dependent on this condition
**/
ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>
* Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
* version number (checked atomically).
* @param id Key of the entry to check
* @param ifVersion The require version number of the entry for all actions to succeed
* @param action The function to execute with actions that will be dependent on this condition
**/
ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>;
/**
* Execute writes actions that are all conditionally dependent on the entry with the provided key
* not existing (checked atomically).
* @param id Key of the entry to check
* @param action The function to execute with actions that will be dependent on this condition
**/
ifNoExists(id: K, action: () => any): Promise<boolean>
* Execute writes actions that are all conditionally dependent on the entry with the provided key
* not existing (checked atomically).
* @param id Key of the entry to check
* @param action The function to execute with actions that will be dependent on this condition
**/
ifNoExists(id: K, action: () => any): Promise<boolean>;
/**
* Check if an entry for the provided key exists
* @param id Key of the entry to check
*/
doesExist(key: K): boolean
* Check if an entry for the provided key exists
* @param id Key of the entry to check
*/
doesExist(key: K): boolean;
/**
* Check if an entry for the provided key/value exists
* @param id Key of the entry to check
* @param value Value of the entry to check (can be undefined to check for existence of the entry)
* @param options Options for existence check (can include transaction)
*/
doesExist(key: K, value: V, options?: GetOptions): boolean
* Check if an entry for the provided key/value exists
* @param id Key of the entry to check
* @param value Value of the entry to check (can be undefined to check for existence of the entry)
* @param options Options for existence check (can include transaction)
*/
doesExist(key: K, value: V, options?: GetOptions): boolean;
/**
* Check if an entry for the provided key exists with the expected version
* @param id Key of the entry to check
* @param version Expected version
*/
doesExist(key: K, version: number): boolean
* Check if an entry for the provided key exists with the expected version
* @param id Key of the entry to check
* @param version Expected version
*/
doesExist(key: K, version: number): boolean;
/**
* @deprecated since version 2.0, use drop() or dropSync() instead
*/
deleteDB(): Promise<void>
* @deprecated since version 2.0, use drop() or dropSync() instead
*/
deleteDB(): Promise<void>;
/**
* Delete this database/store (asynchronously).
**/
drop(): Promise<void>
* Delete this database/store (asynchronously).
**/
drop(): Promise<void>;
/**
* Synchronously delete this database/store.
**/
dropSync(): void
* Synchronously delete this database/store.
**/
dropSync(): void;
/**
* @deprecated since version 2.0, use clearAsync() or clearSync() instead
*/
clear(): Promise<void>
* @deprecated since version 2.0, use clearAsync() or clearSync() instead
*/
clear(): Promise<void>;
/**
* Asynchronously clear all the entries from this database/store.
**/
clearAsync(): Promise<void>
* Asynchronously clear all the entries from this database/store.
**/
clearAsync(): Promise<void>;
/**
* Synchronously clear all the entries from this database/store.
**/
clearSync(): void
* Synchronously clear all the entries from this database/store.
**/
clearSync(): void;
/** A promise-like object that resolves when previous writes have been committed. */
committed: Promise<boolean>
committed: Promise<boolean>;
/** A promise-like object that resolves when previous writes have been committed and fully flushed/synced to disk/storage. */
flushed: Promise<boolean>
flushed: Promise<boolean>;
/**
* Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
**/
readerCheck(): number
* Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
**/
readerCheck(): number;
/**
* Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
**/
readerList(): string
* Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
**/
readerList(): string;
/**
* Returns statistics about the current database
**/
getStats(): {}
* Returns statistics about the current database
**/
getStats(): {};
/**
* Explicitly force the read transaction to reset to the latest snapshot/version of the database
**/
resetReadTxn(): void
* Explicitly force the read transaction to reset to the latest snapshot/version of the database
**/
resetReadTxn(): void;
/**
* Make a snapshot copy of the current database at the indicated path
* @param path Path to store the backup
* @param compact Apply compaction while making the backup (slower and smaller)
**/
backup(path: string, compact: boolean): Promise<void>
* Make a snapshot copy of the current database at the indicated path
* @param path Path to store the backup
* @param compact Apply compaction while making the backup (slower and smaller)
**/
backup(path: string, compact: boolean): Promise<void>;
/**
* Close the current database.
**/
close(): Promise<void>
* Close the current database.
**/
close(): Promise<void>;
/**
* Add event listener
*/
on(event: 'beforecommit' | 'aftercommit', callback: (event: any) => void): void
on(
event: 'beforecommit' | 'aftercommit',
callback: (event: any) => void,
): void;
}

@@ -317,12 +341,17 @@ /* A constant that can be returned from a transaction to indicate that the transaction should be aborted */

/**
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(options?: DatabaseOptions & { name: string }): Database<OV, OK>
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(
options?: DatabaseOptions & { name: string },
): Database<OV, OK>;
/**
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(dbName: string, dbOptions: DatabaseOptions): Database<OV, OK>
* Open a database store using the provided options.
**/
openDB<OV = V, OK extends Key = K>(
dbName: string,
dbOptions: DatabaseOptions,
): Database<OV, OK>;
}
class DatabaseClass<V = any, K extends Key = Key> {
new(name: string | null, options: DatabaseOptions): Database<V, K>
new(name: string | null, options: DatabaseOptions): Database<V, K>;
}

@@ -333,17 +362,17 @@

interface DatabaseOptions {
name?: string
cache?: boolean | {}
compression?: boolean | CompressionOptions
encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary'
sharedStructuresKey?: Key
useVersions?: boolean
keyEncoding?: 'uint32' | 'binary' | 'ordered-binary'
dupSort?: boolean
strictAsyncOrder?: boolean
name?: string;
cache?: boolean | {};
compression?: boolean | CompressionOptions;
encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary';
sharedStructuresKey?: Key;
useVersions?: boolean;
keyEncoding?: 'uint32' | 'binary' | 'ordered-binary';
dupSort?: boolean;
strictAsyncOrder?: boolean;
}
interface RootDatabaseOptions extends DatabaseOptions {
/** The maximum number of databases to be able to open (there is some extra overhead if this is set very high).*/
maxDbs?: number
maxDbs?: number;
/** Set a longer delay (in milliseconds) to wait longer before committing writes to increase the number of writes per transaction (higher latency, but more efficient) **/
commitDelay?: number
commitDelay?: number;
/**

@@ -353,3 +382,3 @@ * This can be used to specify the initial amount of how much virtual memory address space (in bytes) to allocate for mapping to the database files.

**/
mapSize?: number
mapSize?: number;
/**

@@ -359,7 +388,7 @@ * This defines the page size of the database. This defaults to the default page size of the OS (usually 4,096, except on MacOS with M-series, which is 16,384 bytes).

* Note that this only effects the page size of new databases (does not affect existing databases). */
pageSize?: number
pageSize?: number;
/** This enables committing transactions where LMDB waits for a transaction to be fully flushed to disk after the transaction has been committed and defaults to being enabled on non-Windows OSes. This option is discussed in more detail below. */
overlappingSync?: boolean
overlappingSync?: boolean;
/** Resolve asynchronous operations when commits are finished and visible and include a separate promise for when a commit is flushed to disk, as a flushed property on the commit promise. Note that you can alternately use the flushed property on the database. */
separateFlushed?: boolean
separateFlushed?: boolean;
/**

@@ -369,9 +398,9 @@ * This a flag to specify if dynamic memory mapping should be used. Enabling this generally makes read operations a little bit slower, but frees up more mapped memory, making it friendlier to other applications.

**/
remapChunks?: boolean
remapChunks?: boolean;
/** This provides a small performance boost (when not using useWritemap) for writes, by skipping zero'ing out malloc'ed data, but can leave application data in unused portions of the database. This is recommended unless there are concerns of database files being accessible. */
noMemInit?: boolean
noMemInit?: boolean;
/** Use writemaps, discouraged at this. This improves performance by reducing malloc calls, but it is possible for a stray pointer to corrupt data. */
useWritemap?: boolean
useWritemap?: boolean;
/** Treat path as a filename instead of directory (this is the default if the path appears to end with an extension and has '.' in it) */
noSubdir?: boolean
noSubdir?: boolean;
/**

@@ -381,11 +410,11 @@ * Does not explicitly flush data to disk at all. This can be useful for temporary databases where durability/integrity is not necessary, and can significantly improve write performance that is I/O bound.

**/
noSync?: boolean
noSync?: boolean;
/** This isn't as dangerous as `noSync`, but doesn't improve performance much either. */
noMetaSync?: boolean
noMetaSync?: boolean;
/** Self-descriptive */
readOnly?: boolean
readOnly?: boolean;
/** The maximum number of concurrent read transactions (readers) to be able to open ([more information](http://www.lmdb.tech/doc/group__mdb.html#gae687966c24b790630be2a41573fe40e2)). */
maxReaders?: number
maxReaders?: number;
/** This enables encryption, and the provided value is the key that is used for encryption. This may be a buffer or string, but must be 32 bytes/characters long. This uses the Chacha8 cipher for fast and secure on-disk encryption of data. */
encryptionKey?: string | Buffer
encryptionKey?: string | Buffer;
/**

@@ -397,47 +426,47 @@ * This is enabled by default and will ensure that all asynchronous write operations performed in the same event turn will be batched together into the same transaction.

**/
eventTurnBatching?: boolean
eventTurnBatching?: boolean;
/** This is the current encoder instance that is being used to serialize data */
encoder?: any
encoder?: any;
/** This is the current decoder instance that is being used to deserialize data */
decoder?: any
decoder?: any;
}
interface RootDatabaseOptionsWithPath extends RootDatabaseOptions {
path?: string
path?: string;
}
interface CompressionOptions {
threshold?: number
dictionary?: Buffer
threshold?: number;
dictionary?: Buffer;
}
interface GetOptions {
transaction?: Transaction
transaction?: Transaction;
}
interface RangeOptions {
/** Starting key for a range **/
start?: Key
start?: Key;
/** Ending key for a range **/
end?: Key
end?: Key;
/** Iterate through the entries in reverse order **/
reverse?: boolean
reverse?: boolean;
/** Include version numbers in each entry returned **/
versions?: boolean
versions?: boolean;
/** The maximum number of entries to return **/
limit?: number
limit?: number;
/** The number of entries to skip **/
offset?: number
offset?: number;
/** Use a snapshot of the database from when the iterator started **/
snapshot?: boolean
snapshot?: boolean;
/** Use the provided transaction for this range query */
transaction?: Transaction
transaction?: Transaction;
}
interface PutOptions {
/* Append to the database using MDB_APPEND, which can be faster */
append?: boolean
append?: boolean;
/* Append to a dupsort database using MDB_APPENDDUP, which can be faster */
appendDup?: boolean
appendDup?: boolean;
/* Perform put with MDB_NOOVERWRITE which will fail if the entry for the key already exists */
noOverwrite?: boolean
noOverwrite?: boolean;
/* Perform put with MDB_NODUPDATA which will fail if the entry for the key/value already exists */
noDupData?: boolean
noDupData?: boolean;
/* The version of the entry to set */
version?: number
version?: number;
}

@@ -450,14 +479,14 @@ export enum TransactionFlags {

/* Indicates that the function can return before the transaction has been flushed to disk */
NO_SYNC_FLUSH = 0x10000
NO_SYNC_FLUSH = 0x10000,
}
class RangeIterable<T> implements Iterable<T> {
map<U>(callback: (entry: T) => U): RangeIterable<U>
flatMap<U>(callback: (entry: T) => U[]): RangeIterable<U>
slice(start: number, end: number): RangeIterable<T>
filter(callback: (entry: T) => any): RangeIterable<T>
[Symbol.iterator]() : Iterator<T>
forEach(callback: (entry: T) => any): void
mapError<U>(callback: (error: Error) => U): RangeIterable<U>
onDone?: Function
asArray: T[]
map<U>(callback: (entry: T) => U): RangeIterable<U>;
flatMap<U>(callback: (entry: T) => U[]): RangeIterable<U>;
slice(start: number, end: number): RangeIterable<T>;
filter(callback: (entry: T) => any): RangeIterable<T>;
[Symbol.iterator](): Iterator<T>;
forEach(callback: (entry: T) => any): void;
mapError<U>(callback: (error: Error) => U): RangeIterable<U>;
onDone?: Function;
asArray: Promise<T[]>;
}

@@ -468,15 +497,15 @@ class Transaction {

*/
done(): void
done(): void;
}
export function getLastVersion(): number
export function compareKeys(a: Key, b: Key): number
export function getLastVersion(): number;
export function compareKeys(a: Key, b: Key): number;
class Binary {}
/* Wrap a Buffer/Uint8Array for direct assignment as a value bypassing any encoding, for put (and doesExist) operations.
*/
export function asBinary(buffer: Uint8Array): Binary
*/
export function asBinary(buffer: Uint8Array): Binary;
/* Indicates if V8 accelerated functions are enabled. If this is false, some functions will be a little slower, and you may want to npm install --build-from-source to enable maximum performance */
export let v8AccelerationEnabled: boolean
export let v8AccelerationEnabled: boolean;
/* Return database augmented with methods to better conform to levelup */
export function levelup(database: Database): Database
export function levelup(database: Database): Database;
}
export = lmdb
export = lmdb;
+47
-14

@@ -9,17 +9,29 @@ import { EventEmitter } from 'events';

orderedBinary.enableNullTermination();
setExternals({
arch, fs, tmpdir, MsgpackrEncoder, WeakLRUCache, orderedBinary,
EventEmitter, os: platform(), onExit(callback) {
arch,
fs,
tmpdir,
MsgpackrEncoder,
WeakLRUCache,
orderedBinary,
EventEmitter,
os: platform(),
onExit(callback) {
if (process.getMaxListeners() < process.listenerCount('exit') + 8)
process.setMaxListeners(process.listenerCount('exit') + 8);
process.on('exit', callback);
}, isLittleEndian: endianness() == 'LE'
},
isLittleEndian: endianness() == 'LE',
});
export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
export {
toBufferKey as keyValueToBuffer,
compareKeys,
compareKeys as compareKey,
fromBufferKey as bufferToKeyValue,
} from 'ordered-binary';
export { ABORT, IF_EXISTS, asBinary } from './write.js';
import { ABORT, IF_EXISTS, asBinary } from './write.js';
export { levelup } from './level.js';
export { SKIP } from './util/RangeIterable.js';
export { SKIP } from '@harperfast/extended-iterable';
import { levelup } from './level.js';

@@ -31,5 +43,5 @@ export { clearKeptObjects, version } from './native.js';

if (endianness() == 'BE') {
return new Uint8Array([0,0,0,0,1,1,1,1]);
return new Uint8Array([0, 0, 0, 0, 1, 1, 1, 1]);
} else {
return new Uint8Array([1,1,1,1,0,0,0,0]);
return new Uint8Array([1, 1, 1, 1, 0, 0, 0, 0]);
}

@@ -39,5 +51,5 @@ })();

if (endianness() == 'BE') {
return new Uint8Array([0,0,0,0,2,1,1,1]);
return new Uint8Array([0, 0, 0, 0, 2, 1, 1, 1]);
} else {
return new Uint8Array([1,1,1,2,0,0,0,0]);
return new Uint8Array([1, 1, 1, 2, 0, 0, 0, 0]);
}

@@ -48,6 +60,16 @@ })();

let uint32 = new Uint32Array(destArray.buffer, 0, 2);
endianness() == 'BE' ? uint32[0] = uint32Value : uint32[1] = uint32Value;
endianness() == 'BE' ? (uint32[0] = uint32Value) : (uint32[1] = uint32Value);
}
export { open, openAsClass, getLastVersion, allDbs, getLastTxnId } from './open.js';
import { toBufferKey as keyValueToBuffer, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
export {
open,
openAsClass,
getLastVersion,
allDbs,
getLastTxnId,
} from './open.js';
import {
toBufferKey as keyValueToBuffer,
compareKeys as compareKey,
fromBufferKey as bufferToKeyValue,
} from 'ordered-binary';
import { open, openAsClass, getLastVersion } from './open.js';

@@ -61,3 +83,14 @@ export const TransactionFlags = {

export default {
open, openAsClass, getLastVersion, compareKey, keyValueToBuffer, bufferToKeyValue, ABORT, IF_EXISTS, asBinary, levelup, TransactionFlags, version
open,
openAsClass,
getLastVersion,
compareKey,
keyValueToBuffer,
bufferToKeyValue,
ABORT,
IF_EXISTS,
asBinary,
levelup,
TransactionFlags,
version,
};
{
"name": "lmdb",
"author": "Kris Zyp",
"version": "3.4.4",
"version": "3.5.0",
"description": "Simple, efficient, scalable, high-performance LMDB interface",

@@ -71,3 +71,3 @@ "license": "MIT",

"prebuildify": "prebuildify-platform-packages --debug --napi --target 22.11.0",
"full-publish": "cd prebuilds/win32-x64 && npm publish --access public && cd ../win32-arm64 && npm publish --access public && cd ../darwin-x64 && npm publish --access public && cd ../darwin-arm64 && npm publish --access public && cd ../linux-x64 && npm publish --access public && cd ../linux-arm64 && npm publish --access public && cd ../linux-arm && npm publish --access public && cd ../.. && npm publish && node util/remove-optional-deps.cjs",
"full-publish": "cd prebuilds/darwin-x64 && npm publish --access public && cd ../darwin-arm64 && npm publish --access public && cd ../linux-x64 && npm publish --access public && cd ../linux-arm64 && npm publish --access public && cd ../linux-arm && npm publish --access public && cd ../.. && npm publish && node util/remove-optional-deps.cjs",
"recompile": "node-gyp clean && node-gyp configure && node-gyp build",

@@ -83,2 +83,3 @@ "recompile-v1": "node-gyp clean && set LMDB_DATA_V1=true&& node-gyp configure && set LMDB_DATA_V1=true&& node-gyp build",

"dependencies": {
"@harperfast/extended-iterable": "^1.0.3",
"msgpackr": "^1.11.2",

@@ -116,10 +117,9 @@ "node-addon-api": "^6.1.0",

"optionalDependencies": {
"@lmdb/lmdb-darwin-arm64": "3.4.4",
"@lmdb/lmdb-darwin-x64": "3.4.4",
"@lmdb/lmdb-linux-arm": "3.4.4",
"@lmdb/lmdb-linux-arm64": "3.4.4",
"@lmdb/lmdb-linux-x64": "3.4.4",
"@lmdb/lmdb-win32-arm64": "3.4.4",
"@lmdb/lmdb-win32-x64": "3.4.4"
"@lmdb/lmdb-darwin-arm64": "3.5.0",
"@lmdb/lmdb-darwin-x64": "3.5.0",
"@lmdb/lmdb-linux-arm": "3.5.0",
"@lmdb/lmdb-linux-arm64": "3.5.0",
"@lmdb/lmdb-linux-x64": "3.5.0",
"@lmdb/lmdb-win32-x64": "3.5.0"
}
}
+11
-3

@@ -1,2 +0,2 @@

import { RangeIterable } from './util/RangeIterable.js';
import { ExtendedIterable } from '@harperfast/extended-iterable';
import {

@@ -359,2 +359,5 @@ getAddress,

},
getSync(id, options) {
return this.get(id, options);
},
getEntry(id, options) {

@@ -427,6 +430,11 @@ let value = this.get(id, options);

// simplified API
tryLock(id, callback) {
return this.attemptLock(id, 0, callback);
},
unlock(id, version, onlyCheck) {
if (!env.address) throw new Error('Can not operate on a closed database');
keyBytes.dataView.setUint32(0, this.db.dbi);
keyBytes.dataView.setFloat64(4, version);
keyBytes.dataView.setFloat64(4, version ?? 0);
let keySize = this.writeKey(id, keyBytes, 12);

@@ -517,3 +525,3 @@ return unlock(env.address, keySize, onlyCheck);

getRange(options) {
let iterable = new RangeIterable();
let iterable = new ExtendedIterable();
let textDecoder = new TextDecoder();

@@ -520,0 +528,0 @@ if (!options) options = {};

@@ -305,3 +305,6 @@ #include "lmdb-js.h"

maxFreeSpaceToRetain = option.As<Number>();
unsigned int permissionsMode = 0664;
option = options.Get("permissionsMode");
if (option.IsNumber())
permissionsMode = option.As<Number>();
Napi::Value encryptionKey = options.Get("encryptionKey");

@@ -320,3 +323,3 @@ std::string encryptKey;

napiEnv = info.Env();
rc = openEnv(flags, jsFlags, (const char*)pathString.c_str(), (char*) keyBuffer, compression, maxDbs, maxReaders, mapSize, pageSize, maxFreeSpaceToLoad, maxFreeSpaceToRetain, encryptKey.empty() ? nullptr : (char*)encryptKey.c_str());
rc = openEnv(flags, jsFlags, (const char*)pathString.c_str(), (char*) keyBuffer, compression, maxDbs, maxReaders, mapSize, pageSize, maxFreeSpaceToLoad, maxFreeSpaceToRetain, encryptKey.empty() ? nullptr : (char*)encryptKey.c_str(), permissionsMode);
//delete[] pathBytes;

@@ -329,3 +332,3 @@ if (rc != 0)

int EnvWrap::openEnv(int flags, int jsFlags, const char* path, char* keyBuffer, Compression* compression, int maxDbs,
int maxReaders, mdb_size_t mapSize, int pageSize, unsigned int max_free_to_load, unsigned int max_free_to_retain, char* encryptionKey) {
int maxReaders, mdb_size_t mapSize, int pageSize, unsigned int max_free_to_load, unsigned int max_free_to_retain, char* encryptionKey, unsigned int permissionsMode) {
this->keyBuffer = keyBuffer;

@@ -382,3 +385,3 @@ this->compression = compression;

pthread_mutex_lock(envTracking->envsLock);
rc = mdb_env_open(env, path, flags, 0664);
rc = mdb_env_open(env, path, flags, permissionsMode);

@@ -385,0 +388,0 @@ if (rc != 0) {

@@ -361,3 +361,3 @@ #ifndef NODE_LMDB_H

int openEnv(int flags, int jsFlags, const char* path, char* keyBuffer, Compression* compression, int maxDbs,
int maxReaders, mdb_size_t mapSize, int pageSize, unsigned int max_free_to_load, unsigned int max_free_to_retain, char* encryptionKey);
int maxReaders, mdb_size_t mapSize, int pageSize, unsigned int max_free_to_load, unsigned int max_free_to_retain, char* encryptionKey, unsigned int permissionsMode);

@@ -364,0 +364,0 @@ /*

@@ -18,3 +18,3 @@ #include "lmdb-js.h"

napi_unwrap(info.Env(), info[0], (void**)&ew);
if (ew->env == nullptr) throwError(info.Env(), "Attempt to start a transaction on a database environment that is closed");
if (ew == nullptr || ew->env == nullptr) throwError(info.Env(), "Attempt to start a transaction on a database environment that is closed");
int flags = 0;

@@ -21,0 +21,0 @@ TxnWrap *parentTw;

export const SKIP = {};
const DONE = {
value: null,
done: true,
};
const RETURN_DONE = {
// we allow this one to be mutated
value: null,
done: true,
};
if (!Symbol.asyncIterator) {
Symbol.asyncIterator = Symbol.for('Symbol.asyncIterator');
}
const NO_OPTIONS = {};
export class RangeIterable {
constructor(sourceArray) {
if (sourceArray) {
this.iterate = sourceArray[Symbol.iterator].bind(sourceArray);
}
}
map(func) {
let source = this;
let iterable = new RangeIterable();
iterable.iterate = (options = NO_OPTIONS) => {
const { async } = options;
let iterator =
source[async ? Symbol.asyncIterator : Symbol.iterator](options);
if (!async) source.isSync = true;
let i = -1;
return {
next(resolvedResult) {
let result;
do {
let iteratorResult;
try {
if (resolvedResult) {
iteratorResult = resolvedResult;
resolvedResult = null; // don't go in this branch on next iteration
} else {
i++;
iteratorResult = iterator.next();
if (iteratorResult.then) {
if (!async) {
this.throw(
new Error(
'Can not synchronously iterate with promises as iterator results',
),
);
}
return iteratorResult.then(
(iteratorResult) => this.next(iteratorResult),
(error) => {
return this.throw(error);
},
);
}
}
if (iteratorResult.done === true) {
this.done = true;
if (iterable.onDone) iterable.onDone();
return iteratorResult;
}
try {
result = func.call(source, iteratorResult.value, i);
if (result && result.then && async) {
// if async, wait for promise to resolve before returning iterator result
return result.then(
(result) =>
result === SKIP
? this.next()
: {
value: result,
},
(error) => {
if (options.continueOnRecoverableError)
error.continueIteration = true;
return this.throw(error);
},
);
}
} catch (error) {
// if the error came from the user function, we can potentially mark it for continuing iteration
if (options.continueOnRecoverableError)
error.continueIteration = true;
throw error; // throw to next catch to handle
}
} catch (error) {
if (iterable.handleError) {
// if we have handleError, we can use it to further handle errors
try {
result = iterable.handleError(error, i);
} catch (error2) {
return this.throw(error2);
}
} else return this.throw(error);
}
} while (result === SKIP);
if (result === DONE) {
return this.return();
}
return {
value: result,
};
},
return(value) {
if (!this.done) {
RETURN_DONE.value = value;
this.done = true;
if (iterable.onDone) iterable.onDone();
iterator.return?.();
}
return RETURN_DONE;
},
throw(error) {
if (error.continueIteration) {
// if it's a recoverable error, we can return or throw without closing the iterator
if (iterable.returnRecoverableErrors)
try {
return {
value: iterable.returnRecoverableErrors(error),
};
} catch (error) {
// if this throws, we need to go back to closing the iterator
this.return();
throw error;
}
if (options.continueOnRecoverableError) throw error; // throw without closing iterator
}
// else we are done with the iterator (and can throw)
this.return();
throw error;
},
};
};
return iterable;
}
[Symbol.asyncIterator](options) {
if (options) options = { ...options, async: true };
else options = { async: true };
return (this.iterator = this.iterate(options));
}
[Symbol.iterator](options) {
return (this.iterator = this.iterate(options));
}
filter(func) {
let iterable = this.map((element) => {
let result = func(element);
// handle promise
if (result?.then)
return result.then((result) => (result ? element : SKIP));
else return result ? element : SKIP;
});
let iterate = iterable.iterate;
iterable.iterate = (options = NO_OPTIONS) => {
// explicitly prevent continue on recoverable error with filter
if (options.continueOnRecoverableError)
options = { ...options, continueOnRecoverableError: false };
return iterate(options);
};
return iterable;
}
forEach(callback) {
let iterator = (this.iterator = this.iterate());
let result;
while ((result = iterator.next()).done !== true) {
callback(result.value);
}
}
concat(secondIterable) {
let concatIterable = new RangeIterable();
concatIterable.iterate = (options = NO_OPTIONS) => {
let iterator = (this.iterator = this.iterate(options));
let isFirst = true;
function iteratorDone(result) {
if (isFirst) {
try {
isFirst = false;
iterator =
secondIterable[
options.async ? Symbol.asyncIterator : Symbol.iterator
]();
result = iterator.next();
if (concatIterable.onDone) {
if (result.then) {
if (!options.async)
throw new Error(
'Can not synchronously iterate with promises as iterator results',
);
result.then(
(result) => {
if (result.done()) concatIterable.onDone();
},
(error) => {
this.return();
throw error;
},
);
} else if (result.done) concatIterable.onDone();
}
} catch (error) {
this.throw(error);
}
} else {
if (concatIterable.onDone) concatIterable.onDone();
}
return result;
}
return {
next() {
try {
let result = iterator.next();
if (result.then) {
if (!options.async)
throw new Error(
'Can not synchronously iterate with promises as iterator results',
);
return result.then((result) => {
if (result.done) return iteratorDone(result);
return result;
});
}
if (result.done) return iteratorDone(result);
return result;
} catch (error) {
this.throw(error);
}
},
return(value) {
if (!this.done) {
RETURN_DONE.value = value;
this.done = true;
if (concatIterable.onDone) concatIterable.onDone();
iterator.return();
}
return RETURN_DONE;
},
throw(error) {
if (options.continueOnRecoverableError) throw error;
this.return();
throw error;
},
};
};
return concatIterable;
}
flatMap(callback) {
let mappedIterable = new RangeIterable();
mappedIterable.iterate = (options = NO_OPTIONS) => {
let iterator = (this.iterator = this.iterate(options));
let isFirst = true;
let currentSubIterator;
return {
next(resolvedResult) {
try {
do {
if (currentSubIterator) {
let result;
if (resolvedResult) {
result = resolvedResult;
resolvedResult = undefined;
} else result = currentSubIterator.next();
if (result.then) {
if (!options.async)
throw new Error(
'Can not synchronously iterate with promises as iterator results',
);
return result.then((result) => this.next(result));
}
if (!result.done) {
return result;
}
}
let result;
if (resolvedResult != undefined) {
result = resolvedResult;
resolvedResult = undefined;
} else result = iterator.next();
if (result.then) {
if (!options.async)
throw new Error(
'Can not synchronously iterate with promises as iterator results',
);
currentSubIterator = undefined;
return result.then((result) => this.next(result));
}
if (result.done) {
if (mappedIterable.onDone) mappedIterable.onDone();
return result;
}
try {
let value = callback(result.value);
if (value?.then) {
if (!options.async)
throw new Error(
'Can not synchronously iterate with promises as iterator results',
);
return value.then(
(value) => {
if (
Array.isArray(value) ||
value instanceof RangeIterable
) {
currentSubIterator = value[Symbol.iterator]();
return this.next();
} else {
currentSubIterator = null;
return { value };
}
},
(error) => {
if (options.continueOnRecoverableError)
error.continueIteration = true;
this.throw(error);
},
);
}
if (Array.isArray(value) || value instanceof RangeIterable)
currentSubIterator = value[Symbol.iterator]();
else {
currentSubIterator = null;
return { value };
}
} catch (error) {
if (options.continueOnRecoverableError)
error.continueIteration = true;
throw error;
}
} while (true);
} catch (error) {
this.throw(error);
}
},
return() {
if (mappedIterable.onDone) mappedIterable.onDone();
if (currentSubIterator) currentSubIterator.return();
return iterator.return();
},
throw(error) {
if (options.continueOnRecoverableError) throw error;
if (mappedIterable.onDone) mappedIterable.onDone();
if (currentSubIterator) currentSubIterator.return();
this.return();
throw error;
},
};
};
return mappedIterable;
}
slice(start, end) {
let iterable = this.map((element, i) => {
if (i < start) return SKIP;
if (i >= end) {
DONE.value = element;
return DONE;
}
return element;
});
iterable.handleError = (error, i) => {
if (i < start) return SKIP;
if (i >= end) {
return DONE;
}
throw error;
};
return iterable;
}
mapError(catch_callback) {
let iterable = this.map((element) => {
return element;
});
let iterate = iterable.iterate;
iterable.iterate = (options = NO_OPTIONS) => {
// we need to ensure the whole stack
// of iterables is set up to handle recoverable errors and continue iteration
return iterate({ ...options, continueOnRecoverableError: true });
};
iterable.returnRecoverableErrors = catch_callback;
return iterable;
}
next() {
if (!this.iterator) this.iterator = this.iterate();
return this.iterator.next();
}
toJSON() {
if (this.asArray && this.asArray.forEach) {
return this.asArray;
}
const error = new Error(
'Can not serialize async iterables without first calling resolving asArray',
);
error.resolution = this.asArray;
throw error;
//return Array.from(this)
}
get asArray() {
if (this._asArray) return this._asArray;
let promise = new Promise((resolve, reject) => {
let iterator = this.iterate(true);
let array = [];
let iterable = this;
Object.defineProperty(array, 'iterable', { value: iterable });
function next(result) {
while (result.done !== true) {
if (result.then) {
return result.then(next);
} else {
array.push(result.value);
}
result = iterator.next();
}
resolve((iterable._asArray = array));
}
next(iterator.next());
});
promise.iterable = this;
return this._asArray || (this._asArray = promise);
}
resolveData() {
return this.asArray;
}
at(index) {
for (let entry of this) {
if (index-- === 0) return entry;
}
}
}
RangeIterable.prototype.DONE = DONE;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display