import { DataObject, Options } from '../common-types'; import { Model } from '../model'; import { Repository } from './repository'; /** * Filter for keys */ export type KeyValueFilter = { /** * Glob string to use to filter returned keys (i.e. `userid.*`). All * connectors are required to support `*` and `?`. They may also support * additional special characters that are specific to the backing database. */ match: string; }; /** * Key/Value operations for connector implementations */ export interface KeyValueRepository extends Repository { /** * Delete an entry by key * * @param key - Key for the entry * @param options - Options for the operation */ delete(key: string, options?: Options): Promise; /** * Delete all entries * * @param key - Key for the entry * @param options - Options for the operation */ deleteAll(options?: Options): Promise; /** * Get an entry by key * * @param key - Key for the entry * @param options - Options for the operation * @returns A promise of the entry */ get(key: string, options?: Options): Promise; /** * Set an entry with key/value * * @param key - Key for the entry * @param value - Value for the entry * @param options - Options for the operation */ set(key: string, value: DataObject, options?: Options): Promise; /** * Set up ttl for an entry by key * * @param key - Key for the entry * @param ttl - Ttl for the entry * @param options - Options for the operation */ expire(key: string, ttl: number, options?: Options): Promise; /** * Get ttl for an entry by key * * @param key - Key for the entry * @param options - Options for the operation * @returns A promise of the TTL value */ ttl?(key: string, options?: Options): Promise; /** * Get an Iterator for matching keys * * @param filter - Filter for keys * @param options - Options for the operation * @returns An async iteratable iterator of keys so that the return value can * be used with `for-await-of`. */ keys?(filter?: KeyValueFilter, options?: Options): AsyncIterable; }