import { Duration } from './duration.js'; /** * Most basic interface for a storage implementation. This is designed to be * quite easily implemented by users to plug in any new underlying storage. */ type StorageAdapter = { set: (key: string, value: T) => Promise | void; get: (key: string) => Promise | T | undefined; delete: (key: string) => Promise | void; clear: () => Promise | void; }; /** Most basic interface for stored object. */ type StoredObject = { value: T; storedMs: number; expiryMs: number; }; /** * Full interface for a storage implementation. Each method can be either sync * or async, and the interface works with either implementation scheme. * * Note: We are using `interface` instead of `type ... &` because typedoc * cannot handle the `&` syntax to merge types. */ interface FullStorageAdapter extends StorageAdapter { set: (key: string, value: T, expiryDeltaMs?: number | Duration) => Promise | void; getStoredObject: (key: string) => Promise | undefined> | StoredObject | undefined; forEach(callback: (key: string, value: T, expiryMs: number, storedMs: number) => void | Promise): Promise | void; size(): Promise | number; asMap(): Promise>> | Map>; gc: () => Promise | void; gcNow: () => Promise | void; } export type { FullStorageAdapter, StorageAdapter, StoredObject };