///
import { UnwrapPromise } from '../../utils/types';
import { IDatabaseTransaction } from './transaction';
import { DatabaseIteratorOptions, DatabaseKeyRange, DatabaseSchema, IDatabaseEncoding, SchemaKey, SchemaValue } from './types';
export type IDatabaseStoreOptions = {
/** The unique name of the store inside of the database */
name: string;
/** The encoding used to encode and decode keys in the database */
keyEncoding: IDatabaseEncoding>;
/** The encoding used to encode and decode values in the database */
valueEncoding: IDatabaseEncoding>;
};
/**
* A collection of keys with associated values that exist within a {@link IDatabase}
* you can have many of these inside of a database. All the values inside the store
* have a consistent type specified by the generic parameter.
*
* Use [[`IDatabase.addStore`]] before you open the database to create an [[`IDatabaseStore`]]
*
* You can operate on one or more stores atomically using {@link IDatabase.transaction}
*/
export interface IDatabaseStore {
/** The unique name of the store inside of the database */
name: string;
/** The [[`IDatabaseEncoding`]] used to serialize keys to store in the database */
keyEncoding: IDatabaseEncoding>;
/** The [[`IDatabaseEncoding`]] used to serialize values to store in the database */
valueEncoding: IDatabaseEncoding>;
encode(key: Readonly>): [Buffer];
/**
* Used to serialize the key and value for the database
*
* @returns An array with the serialized key and value as Buffers
*/
encode(key: Readonly>, value: SchemaValue): [Buffer, Buffer];
getAll(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): Promise, SchemaValue]>>;
getAllIter(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): AsyncGenerator<[SchemaKey, SchemaValue]>;
getAllValuesIter(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): AsyncGenerator>;
getAllValues(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): Promise>>;
getAllKeysIter(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): AsyncGenerator>;
getAllKeys(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): Promise>>;
/**
* Delete every key in the {@link IDatastore}
*
* @returns resolves when all keys have been deleted
*/
clear(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange): Promise;
/**
* Used to get a value from the store at a given key
* @param key - The key to fetch
* @param transaction - If provided, the operation will use the transaction.
*
* @returns resolves with the value if found, or undefined if not found.
*/
get(key: Readonly>, transaction?: IDatabaseTransaction): Promise | undefined>;
/**
* Used to check if the database has a given key
* @param key - The key to check
* @param transaction - If provided, the operation will use the transaction.
*
* @returns resolves with true if the key is in the database, or false if it is missing.
*/
has(key: Readonly>, transaction?: IDatabaseTransaction): Promise;
/**
* Put a value into the store with the given key.
* @param key - The key to insert
* @param value - The value to insert
* @param transaction - If provided, the operation will be executed atomically when the transaction is {@link IDatabaseTransaction.commit | committed}.
*
* @returns A promise that resolves when the operation has been either executed, or added to the transaction.
*/
put(key: Readonly>, value: SchemaValue, transaction?: IDatabaseTransaction): Promise;
/**
* Add a value to the database with the given key.
*
* If the key already exists, an {@link DuplicateKeyError} will be thrown. If you do not want to throw an error on insert, use {@link IDatabaseStore.put}
* @param key - The key to insert
* @param value - The value to insert
* @param transaction - If provided, the operation will be executed atomically when the transaction is {@link IDatabaseTransaction.commit | committed}.
*
* @returns A promise that resolves when the operation has been either executed, or added to the transaction.
* @throws {@link DuplicateKeyError} if the key already exists in the transaction or database
*/
add(key: Readonly>, value: SchemaValue, transaction?: IDatabaseTransaction): Promise;
/**
* Delete a value with the given key.
*
* @param key - The key stored in the database to delete
* @param transaction - If provided, the operation will be executed atomically when the transaction is {@link IDatabaseTransaction.commit | committed}.
*
* @returns A promise that resolves when the operation has been either executed, or added to the transaction.
*/
del(key: Readonly>, transaction?: IDatabaseTransaction): Promise;
}
export declare abstract class DatabaseStore implements IDatabaseStore {
name: string;
keyEncoding: IDatabaseEncoding>;
valueEncoding: IDatabaseEncoding>;
constructor(options: IDatabaseStoreOptions);
abstract encode(key: Readonly>): [Buffer];
abstract encode(key: Readonly>, value: SchemaValue): [Buffer, Buffer];
abstract get(key: Readonly>, transaction?: IDatabaseTransaction): Promise | undefined>;
abstract getAllIter(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): AsyncGenerator<[SchemaKey, SchemaValue]>;
abstract getAll(transaction?: IDatabaseTransaction, keyRange?: DatabaseKeyRange, iteratorOptions?: DatabaseIteratorOptions): Promise, SchemaValue]>>;
abstract getAllValuesIter(transaction?: IDatabaseTransaction): AsyncGenerator>;
abstract getAllValues(transaction?: IDatabaseTransaction): Promise>>;
abstract getAllKeysIter(transaction?: IDatabaseTransaction): AsyncGenerator>;
abstract getAllKeys(transaction?: IDatabaseTransaction): Promise>>;
abstract clear(): Promise;
abstract has(key: Readonly>, transaction?: IDatabaseTransaction): Promise;
abstract put(key: Readonly>, value: SchemaValue, transaction?: IDatabaseTransaction): Promise;
abstract add(key: Readonly>, value: SchemaValue, transaction?: IDatabaseTransaction): Promise;
abstract del(key: Readonly>, transaction?: IDatabaseTransaction): Promise;
}
export type DatabaseStoreValue = TStore extends IDatabaseStore ? Exclude>, undefined> : never;
export type DatabaseStoreKey = TStore extends IDatabaseStore ? Parameters[0] : never;
//# sourceMappingURL=store.d.ts.map