UNPKG

@reptilbud/etcd3-temp

Version:
135 lines (134 loc) 4.61 kB
/// <reference types="node" /> import { Etcd3, Namespace, Watcher, Lock, IPutResponse, Lease } from 'etcd3'; import { Observable } from 'rxjs'; import { ResponseFormat } from '../interfaces'; export declare class Etcd3Service { private _manager; /** * * @member {string} _basePath The base path from which all future key will be added * */ private _basePath; /** * * @member {Namespace} _client The client having the base path to not concat manually all entry keys * */ private _client; constructor(_manager: any); /** * * @returns {string} The value of the base path * */ readonly basePath: string; /** * * Retrieve the client without basePath consideration * * @returns {Namespace} the client for the namespace * */ readonly client: Namespace; /** * * Retrieve the client without basePath consideration * * @returns {Etcd3} the normal client (without namespace consideration) * */ etcd3Client(): Etcd3; /****************************************************************************************** * * 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 | null | Error>; /** * * 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) * * @returns {IPutResponse} The result of the operation * */ put(key: string, value: string | number | Object | Buffer): Observable<IPutResponse>; /****************************************************************************************** * * Watch operations * ******************************************************************************************/ /** * * Create a watcher for a specific key. * * @param {string} key The key you want to watch * * @returns {Watcher} The watcher instance created * */ createWatcher(key: string): 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>; }