memory-card
Version:
ES6 Map like Async API, with Swagger API Backend Support.
55 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageEtcd = void 0;
const etcd3_1 = require("etcd3");
const config_js_1 = require("../config.js");
const backend_js_1 = require("./backend.js");
class StorageEtcd extends backend_js_1.StorageBackend {
etcd;
constructor(name, options) {
config_js_1.log.verbose('StorageEtcd', 'constructor()');
options.type = 'etcd';
super(name, options);
options = options;
this.etcd = new etcd3_1.Etcd3({
hosts: options.hosts,
});
}
toString() {
const text = [
this.constructor.name,
'<',
this.name,
'>',
].join('');
return text;
}
async save(payload) {
config_js_1.log.verbose('StorageEtcd', 'save()');
await this.etcd
.put(this.name)
.value(JSON.stringify(payload));
}
async load() {
config_js_1.log.verbose('StorageEtcd', 'load()');
const result = await this.etcd.get(this.name).string();
if (!result) {
return {};
}
try {
return JSON.parse(result);
}
catch (e) {
config_js_1.log.warn('StorageEtcd', 'load() rejection: %s', e && e.message);
console.error(e);
return {};
}
}
async destroy() {
config_js_1.log.verbose('StorageEtcd', 'destroy()');
await this.etcd.delete().key(this.name);
}
}
exports.StorageEtcd = StorageEtcd;
exports.default = StorageEtcd;
//# sourceMappingURL=etcd.js.map