UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

66 lines 1.83 kB
/** * A key for a key-value store. An array of one or more strings. * * @since 0.5.0 */ import * as dntShim from "../_dnt.shims.js"; export type KvKey = readonly [string] | readonly [string, ...string[]]; /** * Additional options for setting a value in a key-value store. * * @since 0.5.0 */ export interface KvStoreSetOptions { /** * The time-to-live (TTL) for the value. */ ttl?: dntShim.Temporal.Duration; } /** * An abstract interface for a key-value store. * * @since 0.5.0 */ export interface KvStore { /** * Gets the value for the given key. * @param key The key to get the value for. * @returns The value for the key, or `undefined` if the key does not exist. * @typeParam T The type of the value to get. */ get<T = unknown>(key: KvKey): Promise<T | undefined>; /** * Sets the value for the given key. * @param key The key to set the value for. * @param value The value to set. * @param options Additional options for setting the value. */ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>; /** * Deletes the value for the given key. * @param key The key to delete. */ delete(key: KvKey): Promise<void>; } /** * A key-value store that stores values in memory. * Do not use this in production as it does not persist values. * * @since 0.5.0 */ export declare class MemoryKvStore implements KvStore { #private; /** * {@inheritDoc KvStore.get} */ get<T = unknown>(key: KvKey): Promise<T | undefined>; /** * {@inheritDoc KvStore.set} */ set(key: KvKey, value: unknown, options?: KvStoreSetOptions): Promise<void>; /** * {@inheritDoc KvStore.delete} */ delete(key: KvKey): Promise<void>; } //# sourceMappingURL=kv.d.ts.map