import * as Transcoder from 'level-transcoder' import { AbstractSublevel } from './abstract-sublevel' import { AbstractResource } from './interfaces' export class AbstractChainedBatch implements AbstractResource { constructor (db: TDatabase) /** * A reference to the database that created this chained batch. */ db: TDatabase /** * The number of queued operations on the current batch. */ get length (): number /** * Queue a _put_ operation on this batch, not committed until {@link write} is * called. */ put (key: KDefault, value: VDefault): this put ( key: K, value: V, options: AbstractChainedBatchPutOptions ): this /** * Queue a _del_ operation on this batch, not committed until {@link write} is * called. */ del (key: KDefault): this del (key: K, options: AbstractChainedBatchDelOptions): this /** * Clear all queued operations on this batch. */ clear (): this /** * Commit the queued operations for this batch. All operations will be written * atomically, that is, they will either all succeed or fail with no partial * commits. */ write (): Promise write (options: AbstractChainedBatchWriteOptions): Promise /** * Free up underlying resources. This should be done even if the chained batch has * zero queued operations. Automatically called by {@link write} so normally not * necessary to call, unless the intent is to discard a chained batch without * committing it. */ close (): Promise /** * Close the batch. */ [Symbol.asyncDispose] (): Promise } /** * Options for the {@link AbstractChainedBatch.put} method. */ export interface AbstractChainedBatchPutOptions { /** * Custom key encoding for this _put_ operation, used to encode the `key`. */ keyEncoding?: string | Transcoder.PartialEncoder | undefined /** * Custom value encoding for this _put_ operation, used to encode the `value`. */ valueEncoding?: string | Transcoder.PartialEncoder | undefined /** * Act as though the _put_ operation is performed on the given sublevel, to similar * effect as: * * ```js * await sublevel.batch().put(key, value).write() * ``` * * This allows atomically committing data to multiple sublevels. The `key` will be * prefixed with the `prefix` of the sublevel, and the `key` and `value` will be * encoded by the sublevel (using the default encodings of the sublevel unless * {@link keyEncoding} and / or {@link valueEncoding} are provided). */ sublevel?: AbstractSublevel | undefined } /** * Options for the {@link AbstractChainedBatch.del} method. */ export interface AbstractChainedBatchDelOptions { /** * Custom key encoding for this _del_ operation, used to encode the `key`. */ keyEncoding?: string | Transcoder.PartialEncoder | undefined /** * Act as though the _del_ operation is performed on the given sublevel, to similar * effect as: * * ```js * await sublevel.batch().del(key).write() * ``` * * This allows atomically committing data to multiple sublevels. The `key` will be * prefixed with the `prefix` of the sublevel, and the `key` will be encoded by the * sublevel (using the default key encoding of the sublevel unless {@link keyEncoding} * is provided). */ sublevel?: AbstractSublevel | undefined } /** * Options for the {@link AbstractChainedBatch.write} method. */ export interface AbstractChainedBatchWriteOptions { // There are no abstract options but implementations may add theirs. }