// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved. // Node module: @loopback/repository // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import {Filter} from '@loopback/filter'; import {Class, Options} from '../common-types'; import {Entity, EntityData} from '../model'; import {Connector} from './connector'; /** * Key/Value operations for connector implementations */ export interface KVConnector extends Connector { /** * Delete an entry by key * @param modelClass - Model class * @param key - Key for the entry * @param options - Options for the operation * @returns Promise if an entry is deleted for the id, otherwise * Promise */ delete( modelClass: Class, key: string, options?: Options, ): Promise; /** * Delete all entries * @param modelClass - Model class * @param options - Options for the operation * @returns A promise of the number of entries deleted */ deleteAll(modelClass: Class, options?: Options): Promise; /** * Get an entry by key * @param modelClass - Model class * @param key - Key for the entry * @param options - Options for the operation * @returns A promise of the entry found for the key */ get(modelClass: Class, key: string, options?: Options): Promise; /** * Set an entry with key/value * @param modelClass - Model class * @param key - Key for the entry * @param value - Value for the entry * @param options - Options for the operation * @returns Promise if an entry is set for the key, otherwise * Promise */ set( modelClass: Class, key: string, value: EntityData, options?: Options, ): Promise; /** * Set up ttl for an entry by key * @param modelClass - Model class * @param key - Key for the entry * @param options - Options for the operation * @returns Promise if an entry is configured for the key, otherwise * Promise */ expire( modelClass: Class, key: string, ttl: number, options?: Options, ): Promise; /** * Get ttl for an entry by key * @param modelClass - Model class * @param key - Key for the entry * @param ttl - Time to live in millisenconds * @param options - Options for the operation * @returns A promise of the TTL value */ ttl?( modelClass: Class, key: string, ttl: number, options?: Options, ): Promise; /** * Fetch all keys * @param modelClass - Model class * @param key - Key for the entry * @param options - Options for the operation * @returns A promise of an array of keys for all entries */ keys?(modelClass: Class, options?: Options): Promise; /** * Get an Iterator for matching keys * @param modelClass - Model class * @param filter - Matching filter * @param options - Options for the operation * @returns A promise of an iterator of entries */ iterateKeys?( modelClass: Class, filter?: Filter, options?: Options, ): Promise>; }