UNPKG

@fdm-monster/server

Version:

FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.

58 lines (57 loc) 1.8 kB
//#region src/utils/cache/key-diff.cache.ts var KeyDiffCache = class { deletedKeys = []; updatedKeys = []; keyValueStore = /* @__PURE__ */ new Map(); async getAllValues() { return Array.from(this.keyValueStore.values()); } async getAllKeyValues() { return Object.fromEntries(this.keyValueStore); } async getValue(key) { return this.keyValueStore.get(key); } async setKeyValuesBatch(keyValues, markUpdated = true) { for (const { key, value } of keyValues) await this.setKeyValue(key, value, false); if (markUpdated) { const updatedKeys = keyValues.map(({ key }) => key); this.batchMarkUpdated(updatedKeys); } } async deleteKeysBatch(keys, markDeleted = true) { for (const key of keys) await this.deleteKeyValue(key, false); if (markDeleted) this.batchMarkDeleted(keys); } async setKeyValue(key, value, markUpdated = true) { this.keyValueStore.set(key, value); if (markUpdated) this.markUpdated(key); } async deleteKeyValue(key, markDeleted = true) { this.keyValueStore.delete(key); if (markDeleted) this.markDeleted(key); } batchMarkDeleted(keys) { for (const key of keys) this.markDeleted(key); } markUpdated(key) { const deletedIndex = this.deletedKeys.indexOf(key); if (deletedIndex !== -1) this.deletedKeys.splice(deletedIndex, 1); if (!this.updatedKeys.includes(key)) this.updatedKeys.push(key); } markDeleted(key) { const updatedIndex = this.updatedKeys.indexOf(key); if (updatedIndex !== -1) this.updatedKeys.splice(updatedIndex, 1); if (!this.deletedKeys.includes(key)) this.deletedKeys.push(key); } resetDiffs() { this.deletedKeys = []; this.updatedKeys = []; } batchMarkUpdated(keys) { for (const key of keys) this.markUpdated(key); } }; //#endregion export { KeyDiffCache }; //# sourceMappingURL=key-diff.cache.js.map