import type { SimpleStore } from "../databases/SimpleStoreBase.ts"; export declare const PREFIX_TRENCH = "trench"; export declare const PREFIX_EPHEMERAL = "ephemeral"; export declare const PREFIX_PERMANENT = "permanent"; export type Evacuated = () => Promise; type CommittableDequeuedValue = Promise<{ key: string; value: T; cancelCount: number; pendingItems: number; commit: () => Promise; cancel: () => void; } | undefined>; /** * Represents a Trench, which is a memory utility class for managing data storage. */ export declare class Trench { _db: SimpleStore; _flushTask: Promise | undefined; /** * Constructs a new instance of the Trench class. * @param db The SimpleStore instance used for storing data. * @param flushExistItems Determines whether to flush existing items from the database. */ constructor(db: SimpleStore, flushExistItems?: boolean); /** * Deletes all ephemeral keys from the SimpleStore. * @returns {Promise} A promise that resolves when all ephemeral keys are deleted. */ eraseAllEphemerals(): Promise; /** * Deletes all permanences from the SimpleStore. * @returns {Promise} A promise that resolves when all permanences are deleted. */ eraseAllPermanences(): Promise; concealing: Map; /** * Conceals an object by generating a unique key and storing the object in SimpleStore. * The object can later be retrieved using the generated key. * @param obj - The object to be concealed. * @returns The generated key used to retrieve the concealed object. */ conceal(obj: T): string; /** * Dispose concealed object. * @param key - The key to bury. */ bury(key: string): Promise; /** * Exposes a concealed object by its key. * The object is removed from the database after being exposed. * @param key - The key of the concealed object. * @returns The exposed object. */ expose(key: string): Promise; _evacuate(storeTask: Promise, key: string): Evacuated; /** * Evacuates a promise by storing its resolved value in the database and returning an `Evacuated` object. * @param task The promise to be evacuated. * @returns An `Evacuated` object representing the evacuated promise. */ evacuatePromise(task: Promise): Evacuated; /** * Evacuates an object by storing it in the database and returning an `Evacuated` object. * If the object is a Promise, it is first evacuated using the `evacuatePromise` method. * @param obj - The object to be evacuated. * @returns An `Evacuated` object representing the evacuated object. */ evacuate(obj: T): Evacuated; _queue(type: string, key: string, obj: T, index: number | undefined): Promise; _dequeue(type: string, key: string): Promise; _dequeueWithCommit(type: string, key: string): CommittableDequeuedValue; /** * Queues an object with the specified key and optional index. * * @template T - The type of the object being queued. * @param {string} key - The key to associate with the object. * @param {T} obj - The object to be queued. * @param {number} [index] - The optional index at which to insert the object in the queue. * @returns {Promise} A promise that resolves when the object is queued. */ queue(key: string, obj: T, index?: number): Promise; /** * Removes and returns the first element from the queue associated with the specified key. * * @template T - The type of elements in the queue. * @param key - The key associated with the queue. * @returns The first element from the queue, or undefined if the queue is empty. */ dequeue(key: string): Promise; /** * Dequeues an item. you can commit or cancel the dequeue operation. * * @template T - The type of the item being dequeued. * @param key - The key of the item to dequeue. * @returns The dequeued item. */ dequeueWithCommit(key: string): CommittableDequeuedValue; /** * Queues an object permanently in the SimpleStore. * * @template T - The type of the object being queued. * @param key - The key to associate with the object. * @param obj - The object to be queued. * @param index - Optional. The index at which to insert the object in the queue. * @returns The updated queue. */ queuePermanent(key: string, obj: T, index?: number): Promise; /** * Dequeues an permanent item from the SimpleStore with the specified key. * * @template T - The type of the item to dequeue. * @param key - The key of the item to dequeue. * @returns The dequeued item. */ dequeuePermanent(key: string): Promise; /** * Dequeues an permanent item from the SimpleStore. we can commit or cancel the dequeue operation. * * @template T - The type of the item being dequeued. * @param key - The key of the item to dequeue. * @returns The dequeued item. */ dequeuePermanentWithCommit(key: string): CommittableDequeuedValue; } export {};