UNPKG

@ixily/activ

Version:

Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.

98 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheStorageModule = exports.resetData = exports.removeDataByPattern = exports.removeData = exports.updateData = exports.getData = exports.addData = void 0; const __1 = require("../.."); let cache; const state = { dbParams: undefined, isBrowser: false, module: null, useCache: true, configured: false, }; const config = async (_config) => { state.dbParams = _config.dbParams; state.isBrowser = _config.isBrowser; state.module = _config.module; state.useCache = _config.useCache; cache = _config.module; }; const inflateStr = async (dt) => { if (typeof dt !== 'string') return dt; return __1.CompressorModule.inflate(dt); }; const deflateStr = async (dt) => { if (typeof dt !== 'string') return dt; return __1.CompressorModule.deflate(dt); }; const addData = async (key, data, expiration) => { if (!state.useCache) return; await asureCache(); data = await deflateStr(data); return cache.addData(key, data, expiration); }; exports.addData = addData; const asureCache = async () => { if (cache === undefined) { throw new Error('CacheStorageModule not configured'); } if (!state.configured) { await cache.config(state); } }; const getData = async (key) => { if (!state.useCache) return undefined; await asureCache(); const dt = await cache.getData(key); const dtInf = await inflateStr(dt); return dtInf; }; exports.getData = getData; const updateData = async (key, data, expiration) => { if (!state.useCache) return; await asureCache(); data = await deflateStr(data); return cache.updateData(key, data, expiration); }; exports.updateData = updateData; const removeData = async (key) => { if (!state.useCache) return; await asureCache(); return cache.removeData(key); }; exports.removeData = removeData; const removeDataByPattern = async (pattern) => { if (!state.useCache) return; await asureCache(); if ((await cache.removeDataByPattern) !== undefined) { await cache.removeDataByPattern(pattern); } else { throw new Error('removeDataByPattern is not defined'); } }; exports.removeDataByPattern = removeDataByPattern; const resetData = async () => { if (!state.useCache) return; await asureCache(); await cache.resetData(); }; exports.resetData = resetData; exports.CacheStorageModule = { config, addData: exports.addData, getData: exports.getData, updateData: exports.updateData, removeData: exports.removeData, removeDataByPattern: exports.removeDataByPattern, resetData: exports.resetData, }; //# sourceMappingURL=cache-storage.module.js.map