UNPKG

@hapiness/etcd3

Version:
153 lines (152 loc) 5.4 kB
/// <reference types="node" /> import { Etcd3, Namespace, Watcher, Lock, IPutResponse, IDeleteRangeResponse, Lease } from 'etcd3'; import { Observable } from 'rxjs'; import { ResponseFormat } from '../interfaces'; import { Etcd3Config } from '../interfaces'; export declare class Etcd3Manager { private _basePath; private _etcd3client; private _client; private _config; constructor(config: Etcd3Config); readonly client: Etcd3; readonly namespace: Namespace; readonly config: Etcd3Config; protected _fixKey(key: string): string; /** * * @returns {string} The value of the base path * */ readonly basePath: string; /****************************************************************************************** * * KV operations * ******************************************************************************************/ /** * * Get the value stored at path `key`. * * @param {string} key The key you want to retrieve the value * @param {ResponseFormat} format The format you want for the result (default is string) * * @returns {string | object | number | Buffer | null | Error} The value of the object stored * */ get(_key: string, format?: ResponseFormat): Observable<string | object | Buffer | number | null | Error>; /** * * Get all keys and values stored under the given `prefix`. * * @param {string} prefix The prefix under which you want to start looking * * @returns { { [key: string]: string } } An object having all path as keys and all values stored under them * */ getWithPrefix(_prefix: string): Observable<{ [key: string]: string; }>; /** * * Delete the key `key`. * * @param {string} key The key you want to delete * * @returns {IDeleteRangeResponse} The result of the operation * */ delete(_key: string): Observable<IDeleteRangeResponse>; /** * * Delete all registered keys for the etcd3 client. * * @returns {IDeleteRangeResponse} The result of the operation * */ deleteAll(): Observable<IDeleteRangeResponse>; /** * * Append the value `value` at path `key`. * * @param {string} key The key you want to retrieve the value * @param {string | Buffer | number} value The format you want for the result (default is string) * @param {boolean} returnResult If you want to retrieve the value that was put * * @returns {IPutResponse} The result of the operation * */ put(_key: string, value: string | number | Object | Buffer, returnResult?: boolean): Observable<IPutResponse | string | number | Object | Buffer>; /****************************************************************************************** * * Watch operations * ******************************************************************************************/ /** * * Create a watcher for a specific key. * * @param {string} key The key you want to watch * @param {string} prefix The prefix you want to watch * * @returns {Watcher} The watcher instance created * */ createWatcher(_key: string, prefix?: boolean): Observable<Watcher>; /****************************************************************************************** * * Lock operations * ******************************************************************************************/ /** * * Create and acquire a lock for a key `key` specifying a ttl. * It will automatically contact etcd to keep the connection live. * When the connection is broken (end of process or lock released), * the TTL is the time after when the lock will be released. * * @param {string} key The key * @param {number} ttl The TTL value in seconds. Default value is 1 * * @returns {Lock} The lock instance created * */ acquireLock(_key: string, ttl?: number): Observable<Lock>; /****************************************************************************************** * * Lease Operations * ******************************************************************************************/ /** * * Create a lease object with a ttl. * The lease is automatically keeping alive until it is close. * * @param {number} ttl The TTL value in seconds. Default value is 1 * * @returns {Lease} The lease instance created * */ createLease(ttl?: number): Observable<Lease>; /** * * Create a lease object with a ttl and attach directly a key-value to it. * The lease is automatically keeping alive until it is close. * * NOTE: Once the lease is closed, the key-value will be destroyed by etcd. * * @param {string} key The key where to store the value * @param {string | Buffer | number} value The value that will be stored at `key` path * @param {number} ttl The TTL value in seconds. Default value is 1 * * @returns {Lease} The lease instance created * */ createLeaseWithValue(_key: string, value: string | Buffer, ttl?: number): Observable<Lease>; /** * * Frees resources associated with the client. * */ close(): void; }