UNPKG

@launchdarkly/js-server-sdk-common

Version:
73 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class InMemoryFeatureStore { constructor() { this._allData = {}; this._initCalled = false; } _addItem(kind, key, item) { let items = this._allData[kind.namespace]; if (!items) { items = {}; this._allData[kind.namespace] = items; } if (Object.hasOwnProperty.call(items, key)) { const old = items[key]; if (!old || old.version < item.version) { items[key] = item; } } else { items[key] = item; } } get(kind, key, callback) { const items = this._allData[kind.namespace]; if (items) { if (Object.prototype.hasOwnProperty.call(items, key)) { const item = items[key]; if (item && !item.deleted) { return callback === null || callback === void 0 ? void 0 : callback(item); } } } return callback === null || callback === void 0 ? void 0 : callback(null); } all(kind, callback) { var _a; const result = {}; const items = (_a = this._allData[kind.namespace]) !== null && _a !== void 0 ? _a : {}; Object.entries(items).forEach(([key, item]) => { if (item && !item.deleted) { result[key] = item; } }); callback === null || callback === void 0 ? void 0 : callback(result); } init(allData, callback) { this._initCalled = true; this._allData = allData; callback === null || callback === void 0 ? void 0 : callback(); } delete(kind, key, version, callback) { const deletedItem = { version, deleted: true }; this._addItem(kind, key, deletedItem); callback === null || callback === void 0 ? void 0 : callback(); } upsert(kind, data, callback) { this._addItem(kind, data.key, data); callback === null || callback === void 0 ? void 0 : callback(); } initialized(callback) { return callback === null || callback === void 0 ? void 0 : callback(this._initCalled); } /* eslint-disable class-methods-use-this */ close() { // For the memory store this is a no-op. } getDescription() { return 'memory'; } } exports.default = InMemoryFeatureStore; //# sourceMappingURL=InMemoryFeatureStore.js.map