import { type DeleteRangeOptions } from './delete-range.ts'; import { type BatchOperation, type ConditionalBatchCondition, type ScanOptions, type Storage, type StorageCapabilities } from './interface.ts'; /** * {@link Storage} decorator that transparently prefixes all keys with a * namespace, isolating a logical partition of a shared backing store. * * Reads and writes pass through to the underlying storage with the scope prefix * prepended; keys returned by `scan` and `keys` are stripped back to their * unprefixed form. Use {@link scopedStorage} to construct one without `new`. * * @example * ```ts * import { MemoryStorage, ScopedStorage } from '@lostgradient/weft'; * * await using raw = new MemoryStorage(); * const scopeA = new ScopedStorage(raw, 'scope:a'); * const scopeB = new ScopedStorage(raw, 'scope:b'); * * await scopeA.put('setting', new TextEncoder().encode('dark')); * await scopeB.put('setting', new TextEncoder().encode('light')); * * // Keys are isolated — scopeA cannot see scopeB's data * console.log(await scopeA.has('setting')); // true * console.log(await scopeB.get('setting')); // Uint8Array for 'light' * ``` */ export declare class ScopedStorage implements Storage { #private; constructor(storage: Storage, prefix: string); capabilities(): StorageCapabilities; scoped(prefix: string): ScopedStorage; get(key: string): Promise; put(key: string, value: Uint8Array): Promise; delete(key: string): Promise; scan(prefix: string, options?: ScanOptions): AsyncIterable<[string, Uint8Array]>; batch(operations: BatchOperation[]): Promise; conditionalBatch(conditions: ConditionalBatchCondition[], operations: BatchOperation[]): Promise; has(key: string): Promise; deletePrefix(prefix: string): Promise; deleteRange(prefix: string, options: DeleteRangeOptions): Promise; keys(prefix: string, options?: ScanOptions): AsyncIterable; count(prefix: string): Promise; [Symbol.dispose](): void; } /** * Factory that creates a {@link ScopedStorage} view of `storage` under the * given `prefix`. * * This is an ergonomic alternative to `new ScopedStorage(...)`: it avoids * `new` at call sites and reads naturally when storage is being decorated * inline. The return type and behavior are identical to constructing * `ScopedStorage` directly. * * @example * ```ts * import { workflow, Engine, MemoryStorage, scopedStorage } from '@lostgradient/weft'; * * await using raw = new MemoryStorage(); * * // Give each engine its own key namespace in the same backing store * await using engine = new Engine({ storage: scopedStorage(raw, 'eng:v1') }); * engine.register(workflow({ name: 'ping' }).execute(async function* () { return 'pong'; })); * * const handle = await engine.start('ping', null); * console.log(await handle.result()); // 'pong' * ``` */ export declare function scopedStorage(storage: Storage, prefix: string): ScopedStorage;