equipped 5.0.13 → 5.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [5.0.14](https://github.com/kevinand11/equipped/compare/v5.0.13...v5.0.14) (2025-07-06)
6
+
7
+
8
+ ### Features
9
+
10
+ * make ttl in cache optional ([4e38b24](https://github.com/kevinand11/equipped/commit/4e38b241b7ecb36821e0c6418f8efc9e38db1fef))
11
+
5
12
  ### [5.0.13](https://github.com/kevinand11/equipped/compare/v5.0.12...v5.0.13) (2025-07-05)
6
13
 
7
14
  ### [5.0.12](https://github.com/kevinand11/equipped/compare/v5.0.11...v5.0.12) (2025-07-05)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cache/base.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/base.cjs"],"names":[],"mappings":"AAAO,+EAAe,MAAM;AAQ5B;ACNA;AACE;AACF,sBAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/base.cjs","sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>\n}\n",null]}
1
+ {"version":3,"sources":["../../../src/cache/base.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/base.cjs"],"names":[],"mappings":"AAAO,+EAAe,MAAM;AAQ5B;ACNA;AACE;AACF,sBAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/base.cjs","sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs?: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>\n}\n",null]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cache/base.ts"],"names":["Cache"],"mappings":"AAAO,+EAAeA,CAAM,CAQ5B,CAAA,kBAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/base.min.cjs","sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>\n}\n"]}
1
+ {"version":3,"sources":["../../../src/cache/base.ts"],"names":["Cache"],"mappings":"AAAO,+EAAeA,CAAM,CAQ5B,CAAA,kBAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/base.min.cjs","sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs?: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>\n}\n"]}
@@ -11,7 +11,7 @@ class InMemoryCache extends _basecjs.Cache {
11
11
  interval = setInterval(() => {
12
12
  const now = Date.now();
13
13
  for (const [key, record] of this.cache.entries()) {
14
- if (record.expiredAt <= now) this.cache.delete(key);
14
+ if (record.expiredAt && record.expiredAt <= now) this.cache.delete(key);
15
15
  }
16
16
  }, 5e3);
17
17
  },
@@ -27,11 +27,11 @@ class InMemoryCache extends _basecjs.Cache {
27
27
  }
28
28
  async get(key) {
29
29
  const record = this.cache.get(this.getScopedKey(key));
30
- if (record && record.expiredAt > Date.now()) return record.data;
30
+ if (record && (record.expiredAt === void 0 || record.expiredAt > Date.now())) return record.data;
31
31
  return null;
32
32
  }
33
33
  async set(key, data, ttlInSecs) {
34
- this.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1e3 });
34
+ this.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1e3 : void 0 });
35
35
  }
36
36
  async getOrSet(key, fn, ttlInSecs) {
37
37
  const cached = await this.get(key);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/in-memory.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/types/in-memory.cjs"],"names":[],"mappings":"AAAA,6HAAyB;AACzB,sCAAsB;AAOf,MAAM,cAAA,QAAsB,eAAM;AAAA,iBACvB,MAAA,kBAAQ,IAAI,GAAA,CAAwB,EAAA;AAAA,EAErD,WAAA,CAAA,EAAc;AACb,IAAA,KAAA,CAAM,4CAAA;AACN,IAAA,IAAI,QAAA;AACJ,IAAA,kBAAA,CAAS,EAAA;AAAA,MACR,OAAA;AAAA,MACA,MAAA,CAAA,EAAA,GAAY;AACX,QAAA,SAAA,EAAW,WAAA,CAAY,CAAA,EAAA,GAAM;AAC5B,UAAA,MAAM,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAA;AACrB,UAAA,IAAA,CAAA,MAAW,CAAC,GAAA,EAAK,MAAM,EAAA,GAAK,IAAA,CAAK,KAAA,CAAM,OAAA,CAAQ,CAAA,EAAG;AACjD,YAAA,GAAA,CAAI,MAAA,CAAO,UAAA,GAAa,GAAA,EAAK,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,GAAG,CAAA;AAAA,UACnD;AAAA,QACD,CAAA,EAAG,GAAI,CAAA;AAAA,MACR,CAAA;AAAA,MACA;AAAA,IACD,CAAA;AACA,IAAA,kBAAA,CAAS,EAAA,CAAG,OAAA,EAAS,MAAA,CAAA,EAAA,GAAY,aAAA,CAAc,QAAQ,CAAA,EAAG,CAAC,CAAA;AAAA,EAC5D;AAAA,EAEQ,YAAA,CAAa,GAAA,EAAqB;AACzC,IAAA,OAAO,kBAAA,CAAS,GAAA,CAAI,CAAA,CAAE,aAAA,CAAc,GAAA,EAAK,GAAG,CAAA;AA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["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && record.expiredAt > Date.now()) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1000 })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n",null]}
1
+ {"version":3,"sources":["../../../../src/cache/types/in-memory.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/types/in-memory.cjs"],"names":[],"mappings":"AAAA,6HAAyB;AACzB,sCAAsB;AAOf,MAAM,cAAA,QAAsB,eAAM;AAAA,iBACvB,MAAA,kBAAQ,IAAI,GAAA,CAAwB,EAAA;AAAA,EAErD,WAA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AAc,KAAA,EAAA,GAAa,MAAA,CAAO,UAAA,EAAY,IAAA,CAAK,GAAA,CAAI,CAAA,CAAA,EAAI,OAAO,MAAA,CAAO,IAAA;AAC/F,IAAA,OAAO,IAAA;AAAA,EACR;AAAA,EAEA,MAAM,GAAA,CAAI,GAAA,EAAa,IAAA,EAAc,SAAA,EAAoB;AACxD,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAA,EAAG,EAAE,IAAA,EAAM,SAAA,EAAW,UAAA,EAAY,IAAA,CAAK,GAAA,CAAI,EAAA,EAAI,UAAA,EAAY,IAAA,EAAO,KAAA,EAAU,CAAC,CAAA;AAAA,EAClH;AAAA,EAEA,MAAM,QAAA,CAAY,GAAA,EAAa,EAAA,EAAsB,SAAA,EAAgC;AACpF,IAAA,MAAM,OAAA,EAAS,MAAM,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA;AACjC,IAAA,GAAA,CAAI,MAAA,EAAQ,OAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAEpC,IAAA,MAAM,OAAA,EAAS,MAAM,EAAA,CAAG,CAAA;AACxB,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG,SAAS,CAAA;AACrD,IAAA,OAAO,MAAA;AAAA,EACR;AACD;ACZA;AACE;AACF,sCAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/in-memory.cjs","sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt?: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt && record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && (record.expiredAt === undefined || record.expiredAt > Date.now())) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1000 : undefined })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n",null]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _indexmincjs = require('../../instance/index.min.cjs');var _basemincjs = require('../base.min.cjs');class h extends _basemincjs.Cache{__init() {this.cache=new Map}constructor(){super();h.prototype.__init.call(this);;let e;_indexmincjs.Instance.on("start",async()=>{e=setInterval(()=>{const t=Date.now();for(const[r,n]of this.cache.entries())n.expiredAt<=t&&this.cache.delete(r)},5e3)},1),_indexmincjs.Instance.on("close",async()=>clearInterval(e),1)}getScopedKey(e){return _indexmincjs.Instance.get().getScopedName(e,":")}async delete(e){this.cache.delete(this.getScopedKey(e))}async get(e){const t=this.cache.get(this.getScopedKey(e));return t&&t.expiredAt>Date.now()?t.data:null}async set(e,t,r){this.cache.set(this.getScopedKey(e),{data:t,expiredAt:Date.now()+r*1e3})}async getOrSet(e,t,r){const n=await this.get(e);if(n)return JSON.parse(n);const a=await t();return await this.set(e,JSON.stringify(a),r),a}}exports.InMemoryCache = h;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _indexmincjs = require('../../instance/index.min.cjs');var _basemincjs = require('../base.min.cjs');class p extends _basemincjs.Cache{__init() {this.cache=new Map}constructor(){super();p.prototype.__init.call(this);;let e;_indexmincjs.Instance.on("start",async()=>{e=setInterval(()=>{const t=Date.now();for(const[r,n]of this.cache.entries())n.expiredAt&&n.expiredAt<=t&&this.cache.delete(r)},5e3)},1),_indexmincjs.Instance.on("close",async()=>clearInterval(e),1)}getScopedKey(e){return _indexmincjs.Instance.get().getScopedName(e,":")}async delete(e){this.cache.delete(this.getScopedKey(e))}async get(e){const t=this.cache.get(this.getScopedKey(e));return t&&(t.expiredAt===void 0||t.expiredAt>Date.now())?t.data:null}async set(e,t,r){this.cache.set(this.getScopedKey(e),{data:t,expiredAt:r?Date.now()+r*1e3:void 0})}async getOrSet(e,t,r){const n=await this.get(e);if(n)return JSON.parse(n);const a=await t();return await this.set(e,JSON.stringify(a),r),a}}exports.InMemoryCache = p;
2
2
  //# sourceMappingURL=in-memory.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"names":["interval","now","key","record","Instance","data","ttlInSecs","fn","cached","result"],"mappings":"AAAA,oIACS,6CAQS,MAAY,EAE7B,QAAA,iBAAA,gBAAA,KACC,CAAA,IAAM,IACN,WAEC,CAAA,CAAA,CAAA,KACA,CAAA,gCAAA,CAAA,IAAY,CACXA,CAAAA,qBAAW,CAAA,EAAA,CAAA,OAAA,CAAY,KACtB,CAAA,CAAA,EAAA,CAAA,CAAMC,CAAAA,WAAe,CACrB,CAAA,CAAA,EAAA,CAAA,MAAYC,CAAKC,CAAM,IAAK,CAAA,GAAA,CAAK,CAAA,CAAA,GAAA,CAAM,KAAA,C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AAMA,CAAM,EAEpC,CAAA,CAAA,CAAA,OAAe,IAAMD,CAAAA,KACrB,CAAA,CAAA,CAAA,CAAA,MAAA,CAAM,CAAA,MAAK,CAAA,CAAIL,CAAAA,CAAK,OAAK,MAAA,IAAgB,CAAGI,GACrCG,CACR,CACD,CAAA,IAAA,CAAA,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,0BAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/in-memory.min.cjs","sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && record.expiredAt > Date.now()) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1000 })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"names":["interval","now","key","record","Instance","data","ttlInSecs","cached","fn","result"],"mappings":"AAAA,oIACS,6CAQS,MAAY,EAE7B,QAAA,iBAAA,gBAAA,KACC,CAAA,IAAM,IACN,WAEC,CAAA,CAAA,CAAA,KACA,CAAA,gCAAA,CAAA,IAAY,CACXA,CAAAA,qBAAW,CAAA,EAAA,CAAA,OAAA,CAAY,KACtB,CAAA,CAAA,EAAA,CAAA,CAAMC,CAAAA,WAAe,CACrB,CAAA,CAAA,EAAA,CAAA,MAAYC,CAAKC,CAAM,IAAK,CAAA,GAAA,CAAK,CAAA,CAAA,GAAA,CAAM,KAAA,CAAA,CAAA,CAAQ,CAAA,CAC1CA,GAAO,IAAA,CAAA,KAAaA,CAAAA,OAAO,CAAA,CAAA,CAAA,CAAA,CAAaF,SAAU,EAAA,CAAA,CAAA,SAAgB,EAExE,CAAG,EAAA,IAEJ,CACD,KACS,CAAA,MAAG,CAAA,CAAA,CAAS,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAY,CAAA,CAAA,qBAAA,CAAA,EAAA,CAAA,OAAcD,CAAQ,KAGhD,CAAA,CAAA,EAAA,aACP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAOI,CAAAA,YAAe,CAAA,CAAA,CAAA,CAAA,OAAmB,qBAAA,CAAA,GAG1C,CAAA,CAAA,CAAA,aACC,CAAA,CAAA,CAAA,GAAK,CAAA,CAAA,MAAM,MAAO,CAAA,CAAA,CAAK,CAAA,IAAA,CAAA,KAAA,CAAA,MAGxB,CAAA,IAAM,CAAA,YACCD,CAAAA,CAAS,CAAA,CAAA,CAAA,MAAK,GAAM,CAAA,CAAA,CAAI,CAAA,MAAK,CAAA,CAAA,IAAA,CAAA,KAAgB,CAAC,GACpD,CAAA,IAAA,CAAIA,YAAkB,CAAA,CAAA,CAAA,CAAA,CAAA,OAAc,CAAA,EAAaA,CAAO,CAAA,CAAA,SAAY,GAAA,KAAS,CAAA,EAAWA,CAAAA,CAAO,SAEhG,CAEA,IAAA,CAAA,GAAM,CAAA,CAAID,CAAAA,CAAaG,CAAAA,CAAcC,IACpC,CAAA,IAAK,CAAA,MAAM,GAAI,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,KAAgB,CAAA,GAAK,CAAA,IAAAD,CAAM,YAAuB,CAAA,CAAA,CAAA,CAAA,CAAK,IAAI,CAAA,CAAIC,CAAAA,SAAmB,CAAA,CAAU,CAAC,IAGlH,CAAA,GAAM,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAYJ,KAAmCI,CAAgC,CACpF,CAAA,CAAA,MAAe,QAAM,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAIJ,CAAG,MAC7BK,CAAQ,CAAA,MAAO,IAAA,CAAK,GAAA,CAAA,CAAA,CAAMA,CAAM,EAEpC,CAAA,CAAA,CAAA,OAAe,IAAMC,CAAAA,KACrB,CAAA,CAAA,CAAA,CAAA,MAAA,CAAM,CAAA,MAAK,CAAA,CAAIN,CAAAA,CAAK,OAAK,MAAA,IAAgB,CAAGI,GACrCG,CACR,CACD,CAAA,IAAA,CAAA,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,0BAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/in-memory.min.cjs","sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt?: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt && record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && (record.expiredAt === undefined || record.expiredAt > Date.now())) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1000 : undefined })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"]}
@@ -38,7 +38,7 @@ class RedisCache extends _basecjs.Cache {
38
38
  return await this.client.get(this.getScopedKey(key));
39
39
  }
40
40
  async set(key, data, ttlInSecs) {
41
- if (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
41
+ if (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
42
42
  else this.client.set(this.getScopedKey(key), data);
43
43
  }
44
44
  async getOrSet(key, fn, ttlInSecs) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/redis.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.cjs"],"names":[],"mappings":"AAAA,2GAA6C;AAE7C,kDAA8B;AAC9B,qDAAyB;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AACvE,IAAA,MAAM,OAAA,EAAS,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAC,CAAA;AACpD,IAAA,GAAA,CAAI,MAAA,EAAQ,OAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAEpC,IAAA,MAAM,OAAA,EAAS,MAAM,EAAA,CAAG,CAAA;AACxB,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG,SAAS,CAAA;AAAA,EACzE;AACD;ACXA;AACE;AACF,gCAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.cjs","sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tif (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n",null]}
1
+ {"version":3,"sources":["../../../../src/cache/types/redis.ts","/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.cjs"],"names":[],"mappings":"AAAA,2GAA6C;AAE7C,kDAA8B;AAC9B,qDAAyB;AACzB,sCAAsB;AAGf,MAAM,WAAA,QAAmB,eAAM;AAAA,EACrC;AAAA,EAEA,WAAA,CAAY,QAAA,EAAuB,WAAA,EAAqC;AACvE,IAAA,KAAA,CAAM,CAAA;AACN,IAAA,MAAM,KAAA,EAAO;AAAA,MACZ,GAAI,QAAA,CAAS,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA,CAAS,KAAK,EAAA,EAAI,CAAC,CAAA;AAAA,MAC/C,GAAI,QAAA,CAAS,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA,CAAS,KAAK,EAAA,EAAI,CAAC;AAAA,IAChD,CAAA;AACA,IAAA,MAAM,OAAA,EAAS;AAAA,MACd,GAAG,WAAA;AAAA,MACH,GAAI,QAAA,CAAS,SAAA,EAAW,EAAE,QAAA,EAAU,QAAA,CAAS,SAAS,EAAA,EAAI,CAAC,CAAA;AAAA,MAC3D,GAAI,QAAA,CAAS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M,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAC,CAAA;AAAA,EAC7C;AAAA,EAEA,MAAM,GAAA,CAAI,GAAA,EAAa;AACtB,IAAA,OAAO,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAC,CAAA;AAAA,EACpD;AAAA,EAEA,MAAM,GAAA,CAAI,GAAA,EAAa,IAAA,EAAc,SAAA,EAAoB;AACxD,IAAA,GAAA,CAAI,SAAA,EAAW,MAAM,IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,IAAA,CAAK,YAAA,CAAa,GAAG,CAAA,EAAG,SAAA,EAAW,IAAI,CAAA;AAAA,IAAA,KACzE,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAA,EAAG,IAAI,CAAA;AAAA,EAClD;AAAA,EAEA,MAAM,QAAA,CAAY,GAAA,EAAa,EAAA,EAAsB,SAAA,EAAoB;AACxE,IAAA,MAAM,OAAA,EAAS,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAC,CAAA;AACpD,IAAA,GAAA,CAAI,MAAA,EAAQ,OAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAEpC,IAAA,MAAM,OAAA,EAAS,MAAM,EAAA,CAAG,CAAA;AACxB,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,GAAG,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG,SAAS,CAAA;AAAA,EACzE;AACD;ACXA;AACE;AACF,gCAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.cjs","sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tif (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n",null]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _ioredis = require('ioredis');var _indexmincjs = require('../../errors/index.min.cjs');var _indexmincjs3 = require('../../instance/index.min.cjs');var _basemincjs = require('../base.min.cjs');class f extends _basemincjs.Cache{constructor(e,t){super();const s={...e.host?{host:e.host}:{},...e.port?{port:e.port}:{}},r={...t,...e.password?{password:e.password}:{},...e.username?{username:e.username}:{},...e.tls?{tls:{}}:{},lazyConnect:!0};this.client=e.cluster?new (0, _ioredis.Cluster)([s],{...t,redisOptions:r,lazyConnect:!0}):new (0, _ioredis.Redis)({...r,...s}),this.client.on("error",async o=>{_indexmincjs3.Instance.crash(new (0, _indexmincjs.EquippedError)("Redis failed with error",{},o))}),t||_indexmincjs3.Instance.on("start",async()=>this.client.connect(),1),_indexmincjs3.Instance.on("close",async()=>this.client.quit(),1)}getScopedKey(e){return _indexmincjs3.Instance.get().getScopedName(e,":")}async delete(e){await this.client.del(this.getScopedKey(e))}async get(e){return await this.client.get(this.getScopedKey(e))}async set(e,t,s){s>0?await this.client.setex(this.getScopedKey(e),s,t):this.client.set(this.getScopedKey(e),t)}async getOrSet(e,t,s){const r=await this.get(this.getScopedKey(e));if(r)return JSON.parse(r);const o=await t();await this.set(this.getScopedKey(e),JSON.stringify(o),s)}}exports.RedisCache = f;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _ioredis = require('ioredis');var _indexmincjs = require('../../errors/index.min.cjs');var _indexmincjs3 = require('../../instance/index.min.cjs');var _basemincjs = require('../base.min.cjs');class f extends _basemincjs.Cache{constructor(e,t){super();const s={...e.host?{host:e.host}:{},...e.port?{port:e.port}:{}},r={...t,...e.password?{password:e.password}:{},...e.username?{username:e.username}:{},...e.tls?{tls:{}}:{},lazyConnect:!0};this.client=e.cluster?new (0, _ioredis.Cluster)([s],{...t,redisOptions:r,lazyConnect:!0}):new (0, _ioredis.Redis)({...r,...s}),this.client.on("error",async o=>{_indexmincjs3.Instance.crash(new (0, _indexmincjs.EquippedError)("Redis failed with error",{},o))}),t||_indexmincjs3.Instance.on("start",async()=>this.client.connect(),1),_indexmincjs3.Instance.on("close",async()=>this.client.quit(),1)}getScopedKey(e){return _indexmincjs3.Instance.get().getScopedName(e,":")}async delete(e){await this.client.del(this.getScopedKey(e))}async get(e){return await this.client.get(this.getScopedKey(e))}async set(e,t,s){s?await this.client.setex(this.getScopedKey(e),s,t):this.client.set(this.getScopedKey(e),t)}async getOrSet(e,t,s){const r=await this.get(this.getScopedKey(e));if(r)return JSON.parse(r);const o=await t();await this.set(this.getScopedKey(e),JSON.stringify(o),s)}}exports.RedisCache = f;
2
2
  //# sourceMappingURL=redis.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"names":["settings","node","common","extraConfig","Redis","error","Instance","key","data","ttlInSecs","fn"],"mappings":"AAAA,2GAA6C,yDAGpC,4DACa,6CAMTA,MACX,EAAA,QACA,iBAAMC,CAAAA,WACuBD,CAAAA,CAAS,CAAA,CAAA,CAAA,CAAK,KAC1C,CAAA,CAAA,CAAIA,MAAS,CAAO,CAAE,CAAA,GAAA,CAAMA,CAAAA,IAAS,CAAK,CAAA,IAC3C,CACME,CAAAA,CAAS,IACXC,CAAAA,CACH,CAAA,CAAA,CAAIH,GAAS,CAAA,CAAA,IAAA,CAAA,CAAW,IAAE,CAAA,CAAA,CAAA,IAAUA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,GAAK,CAAA,CAC3D,GAAIA,CAAAA,CAAS,QAAA,CAAW,CAAE,QAAA,CAAUA,CAAAA,CAAS,QAAS,CAAA,CAAI,CAAC,CAAA,CAC3D,GAAIA,CAAAA,CAAS,QAAQ,CAAK,CAAC,QAC3B,CAAA,CAAA,CAAA,QAAa,CACd,CAAA,CACA,CAAA,CAAA,GAAK,CAAA,CAAA,GAAA,CAAA,CAASA,GAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACpB,CAAA,WACA,CAAA,CAAGG,CAAAA,CACH,CAAA,IAAA,CAAA,MAA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A,YAAK,CAAA,CAAA,CAAA,CAAaF,CAAG,CAAA,CAAGC,CAAI,CAClD,IAEA,CAAA,MAAM,CAAA,GAAA,CAAYD,IAAmCE,CAAAA,YACrC,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,MAAS,QAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MACnC,CAAA,CAAA,MAAY,IAAO,CAAA,GAAA,CAAK,IAAA,CAAA,YAET,CAAA,CAAA,CAAA,CAAA,CAAA,EAAMC,CAAG,CAAA,CACxB,OAAM,IAAK,CAAA,KAAI,CAAA,CAAA,CAAK,CAAA,MAAA,CAAA,CAAA,MAAgB,CAAG,CAAA,CAAA,CAAA,MAAK,IAAA,CAAA,GAAgB,CAAGD,IAEjE,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,uBAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.min.cjs","sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tif (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"names":["settings","node","common","extraConfig","Redis","error","Instance","key","data","ttlInSecs","fn"],"mappings":"AAAA,2GAA6C,yDAGpC,4DACa,6CAMTA,MACX,EAAA,QACA,iBAAMC,CAAAA,WACuBD,CAAAA,CAAS,CAAA,CAAA,CAAA,CAAK,KAC1C,CAAA,CAAA,CAAIA,MAAS,CAAO,CAAE,CAAA,GAAA,CAAMA,CAAAA,IAAS,CAAK,CAAA,IAC3C,CACME,CAAAA,CAAS,IACXC,CAAAA,CACH,CAAA,CAAA,CAAIH,GAAS,CAAA,CAAA,IAAA,CAAA,CAAW,IAAE,CAAA,CAAA,CAAA,IAAUA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,GAAK,CAAA,CAC3D,GAAIA,CAAAA,CAAS,QAAA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A,YAAW,CAAA,CAAA,CAAA,CAAO,CAAA,MAAI,GAAK,CAAA,CAAA,CAAA,CAAA,OAAA,MAGnC,IAAA,CAAM,MAAiBC,CAAAA,GAAkC,CACpDC,IAAW,CAAA,YAAW,CAAA,CAAA,CAAO,CAAA,CAAA,MAAM,GAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAmBA,IAAe,CACzE,MAAK,CAAA,KAAO,CAAA,IAAI,CAAA,YAAK,CAAA,CAAA,CAAA,CAAaF,CAAG,CAAA,CAAGC,CAAI,CAClD,IAEA,CAAA,MAAM,CAAA,GAAA,CAAYD,IAAmCE,CAAAA,YACrC,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,MAAS,QAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MACnC,CAAA,CAAA,MAAY,IAAO,CAAA,GAAA,CAAK,IAAA,CAAA,YAET,CAAA,CAAA,CAAA,CAAA,CAAA,EAAMC,CAAG,CAAA,CACxB,OAAM,IAAK,CAAA,KAAI,CAAA,CAAA,CAAK,CAAA,MAAA,CAAA,CAAA,MAAgB,CAAG,CAAA,CAAA,CAAA,MAAK,IAAA,CAAA,GAAgB,CAAGD,IAEjE,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,uBAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/cache/types/redis.min.cjs","sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tif (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cache/base.ts"],"sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>\n}\n"],"mappings":"AAAO,MAAeA,CAAM,CAQ5B","names":["Cache"]}
1
+ {"version":3,"sources":["../../../src/cache/base.ts"],"sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs?: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>\n}\n"],"mappings":"AAAO,MAAeA,CAAM,CAQ5B","names":["Cache"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cache/base.ts"],"sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>\n}\n"],"mappings":"AAAO,MAAe,MAAM;AAQ5B;","names":[]}
1
+ {"version":3,"sources":["../../../src/cache/base.ts"],"sourcesContent":["export abstract class Cache {\n\tabstract set(key: string, data: string, ttlInSecs?: number): Promise<void>\n\n\tabstract get(key: string): Promise<string | null>\n\n\tabstract delete(key: string): Promise<void>\n\n\tabstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>\n}\n"],"mappings":"AAAO,MAAe,MAAM;AAQ5B;","names":[]}
@@ -1,2 +1,2 @@
1
- import{Instance as s}from "../../instance/index.min.mjs";import{Cache as c}from "../base.min.mjs";class h extends c{cache=new Map;constructor(){super();let e;s.on("start",async()=>{e=setInterval(()=>{const t=Date.now();for(const[r,n]of this.cache.entries())n.expiredAt<=t&&this.cache.delete(r)},5e3)},1),s.on("close",async()=>clearInterval(e),1)}getScopedKey(e){return s.get().getScopedName(e,":")}async delete(e){this.cache.delete(this.getScopedKey(e))}async get(e){const t=this.cache.get(this.getScopedKey(e));return t&&t.expiredAt>Date.now()?t.data:null}async set(e,t,r){this.cache.set(this.getScopedKey(e),{data:t,expiredAt:Date.now()+r*1e3})}async getOrSet(e,t,r){const n=await this.get(e);if(n)return JSON.parse(n);const a=await t();return await this.set(e,JSON.stringify(a),r),a}}export{h as InMemoryCache};
1
+ import{Instance as s}from "../../instance/index.min.mjs";import{Cache as i}from "../base.min.mjs";class p extends i{cache=new Map;constructor(){super();let e;s.on("start",async()=>{e=setInterval(()=>{const t=Date.now();for(const[r,n]of this.cache.entries())n.expiredAt&&n.expiredAt<=t&&this.cache.delete(r)},5e3)},1),s.on("close",async()=>clearInterval(e),1)}getScopedKey(e){return s.get().getScopedName(e,":")}async delete(e){this.cache.delete(this.getScopedKey(e))}async get(e){const t=this.cache.get(this.getScopedKey(e));return t&&(t.expiredAt===void 0||t.expiredAt>Date.now())?t.data:null}async set(e,t,r){this.cache.set(this.getScopedKey(e),{data:t,expiredAt:r?Date.now()+r*1e3:void 0})}async getOrSet(e,t,r){const n=await this.get(e);if(n)return JSON.parse(n);const a=await t();return await this.set(e,JSON.stringify(a),r),a}}export{p as InMemoryCache};
2
2
  //# sourceMappingURL=in-memory.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && record.expiredAt > Date.now()) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1000 })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,iBACzB,OAAS,SAAAC,MAAa,UAOf,MAAMC,UAAsBD,CAAM,CACvB,MAAQ,IAAI,IAE7B,aAAc,CACb,MAAM,EACN,IAAIE,EACJH,EAAS,GACR,QACA,SAAY,CACXG,EAAW,YAAY,IAAM,CAC5B,MAAMC,EAAM,KAAK,IAAI,EACrB,SAAW,CAACC,EAAKC,CAAM,IAAK,KAAK,MAAM,QAAQ,EAC1CA,EAAO,WAAaF,GAAK,KAAK,MAAM,OAAOC,CAAG,CAEpD,EAAG,GAAI,CACR,EACA,CACD,EACAL,EAAS,GAAG,QAAS,SAAY,cAAcG,CAAQ,EAAG,CAAC,CAC5D,CAEQ,aAAaE,EAAqB,CACzC,OAAOL,EAAS,IAAI,EAAE,cAAcK,EAAK,GAAG,CAC7C,CAEA,MAAM,OAAOA,EAAa,CACzB,KAAK,MAAM,OAAO,KAAK,aAAaA,CAAG,CAAC,CACzC,CAEA,MAAM,IAAIA,EAAa,CACtB,MAAMC,EAAS,KAAK,MAAM,IAAI,KAAK,aAAaD,CAAG,CAAC,EACpD,OAAIC,GAAUA,EAAO,UAAY,KAAK,IAAI,EAAUA,EAAO,KACpD,IACR,CAEA,MAAM,IAAID,EAAaE,EAAcC,EAAmB,CACvD,KAAK,MAAM,IAAI,KAAK,aAAaH,CAAG,EAAG,CAAE,KAAAE,EAAM,UAAW,KAAK,IAAI,EAAIC,EAAY,GAAK,CAAC,CAC1F,CAEA,MAAM,SAAYH,EAAaI,EAAsBD,EAA+B,CACnF,MAAME,EAAS,MAAM,KAAK,IAAIL,CAAG,EACjC,GAAIK,EAAQ,OAAO,KAAK,MAAMA,CAAM,EAEpC,MAAMC,EAAS,MAAMF,EAAG,EACxB,aAAM,KAAK,IAAIJ,EAAK,KAAK,UAAUM,CAAM,EAAGH,CAAS,EAC9CG,CACR,CACD","names":["Instance","Cache","InMemoryCache","interval","now","key","record","data","ttlInSecs","fn","cached","result"]}
1
+ {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt?: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt && record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && (record.expiredAt === undefined || record.expiredAt > Date.now())) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1000 : undefined })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,iBACzB,OAAS,SAAAC,MAAa,UAOf,MAAMC,UAAsBD,CAAM,CACvB,MAAQ,IAAI,IAE7B,aAAc,CACb,MAAM,EACN,IAAIE,EACJH,EAAS,GACR,QACA,SAAY,CACXG,EAAW,YAAY,IAAM,CAC5B,MAAMC,EAAM,KAAK,IAAI,EACrB,SAAW,CAACC,EAAKC,CAAM,IAAK,KAAK,MAAM,QAAQ,EAC1CA,EAAO,WAAaA,EAAO,WAAaF,GAAK,KAAK,MAAM,OAAOC,CAAG,CAExE,EAAG,GAAI,CACR,EACA,CACD,EACAL,EAAS,GAAG,QAAS,SAAY,cAAcG,CAAQ,EAAG,CAAC,CAC5D,CAEQ,aAAaE,EAAqB,CACzC,OAAOL,EAAS,IAAI,EAAE,cAAcK,EAAK,GAAG,CAC7C,CAEA,MAAM,OAAOA,EAAa,CACzB,KAAK,MAAM,OAAO,KAAK,aAAaA,CAAG,CAAC,CACzC,CAEA,MAAM,IAAIA,EAAa,CACtB,MAAMC,EAAS,KAAK,MAAM,IAAI,KAAK,aAAaD,CAAG,CAAC,EACpD,OAAIC,IAAWA,EAAO,YAAc,QAAaA,EAAO,UAAY,KAAK,IAAI,GAAWA,EAAO,KACxF,IACR,CAEA,MAAM,IAAID,EAAaE,EAAcC,EAAoB,CACxD,KAAK,MAAM,IAAI,KAAK,aAAaH,CAAG,EAAG,CAAE,KAAAE,EAAM,UAAWC,EAAY,KAAK,IAAI,EAAIA,EAAY,IAAO,MAAU,CAAC,CAClH,CAEA,MAAM,SAAYH,EAAaI,EAAsBD,EAAgC,CACpF,MAAME,EAAS,MAAM,KAAK,IAAIL,CAAG,EACjC,GAAIK,EAAQ,OAAO,KAAK,MAAMA,CAAM,EAEpC,MAAMC,EAAS,MAAMF,EAAG,EACxB,aAAM,KAAK,IAAIJ,EAAK,KAAK,UAAUM,CAAM,EAAGH,CAAS,EAC9CG,CACR,CACD","names":["Instance","Cache","InMemoryCache","interval","now","key","record","data","ttlInSecs","fn","cached","result"]}
@@ -11,7 +11,7 @@ class InMemoryCache extends Cache {
11
11
  interval = setInterval(() => {
12
12
  const now = Date.now();
13
13
  for (const [key, record] of this.cache.entries()) {
14
- if (record.expiredAt <= now) this.cache.delete(key);
14
+ if (record.expiredAt && record.expiredAt <= now) this.cache.delete(key);
15
15
  }
16
16
  }, 5e3);
17
17
  },
@@ -27,11 +27,11 @@ class InMemoryCache extends Cache {
27
27
  }
28
28
  async get(key) {
29
29
  const record = this.cache.get(this.getScopedKey(key));
30
- if (record && record.expiredAt > Date.now()) return record.data;
30
+ if (record && (record.expiredAt === void 0 || record.expiredAt > Date.now())) return record.data;
31
31
  return null;
32
32
  }
33
33
  async set(key, data, ttlInSecs) {
34
- this.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1e3 });
34
+ this.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1e3 : void 0 });
35
35
  }
36
36
  async getOrSet(key, fn, ttlInSecs) {
37
37
  const cached = await this.get(key);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && record.expiredAt > Date.now()) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1000 })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAOf,MAAM,sBAAsB,MAAM;AAAA,EACvB,QAAQ,oBAAI,IAAwB;AAAA,EAErD,cAAc;AACb,UAAM;AACN,QAAI;AACJ,aAAS;AAAA,MACR;AAAA,MACA,YAAY;AACX,mBAAW,YAAY,MAAM;AAC5B,gBAAM,MAAM,KAAK,IAAI;AACrB,qBAAW,CAAC,KAAK,MAAM,KAAK,KAAK,MAAM,QAAQ,GAAG;AACjD,gBAAI,OAAO,aAAa,IAAK,MAAK,MAAM,OAAO,GAAG;AAAA,UACnD;AAAA,QACD,GAAG,GAAI;AAAA,MACR;AAAA,MACA;AAAA,IACD;AACA,aAAS,GAAG,SAAS,YAAY,cAAc,QAAQ,GAAG,CAAC;AAAA,EAC5D;AAAA,EAEQ,aAAa,KAAqB;AACzC,WAAO,SAAS,IAAI,EAAE,cAAc,KAAK,GAAG;AAAA,EAC7C;AAAA,EAEA,MAAM,OAAO,KAAa;AACzB,SAAK,MAAM,OAAO,KAAK,aAAa,GAAG,CAAC;AAAA,EACzC;AAAA,EAEA,MAAM,IAAI,KAAa;AACtB,UAAM,SAAS,KAAK,MAAM,IAAI,KAAK,aAAa,GAAG,CAAC;AACpD,QAAI,UAAU,OAAO,YAAY,KAAK,IAAI,EAAG,QAAO,OAAO;AAC3D,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,IAAI,KAAa,MAAc,WAAmB;AACvD,SAAK,MAAM,IAAI,KAAK,aAAa,GAAG,GAAG,EAAE,MAAM,WAAW,KAAK,IAAI,IAAI,YAAY,IAAK,CAAC;AAAA,EAC1F;AAAA,EAEA,MAAM,SAAY,KAAa,IAAsB,WAA+B;AACnF,UAAM,SAAS,MAAM,KAAK,IAAI,GAAG;AACjC,QAAI,OAAQ,QAAO,KAAK,MAAM,MAAM;AAEpC,UAAM,SAAS,MAAM,GAAG;AACxB,UAAM,KAAK,IAAI,KAAK,KAAK,UAAU,MAAM,GAAG,SAAS;AACrD,WAAO;AAAA,EACR;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/cache/types/in-memory.ts"],"sourcesContent":["import { Instance } from '../../instance'\nimport { Cache } from '../base'\n\ntype CacheEntry = {\n\tdata: string\n\texpiredAt?: number\n}\n\nexport class InMemoryCache extends Cache {\n\tprivate readonly cache = new Map<string, CacheEntry>()\n\n\tconstructor() {\n\t\tsuper()\n\t\tlet interval: ReturnType<typeof setInterval> | undefined\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tinterval = setInterval(() => {\n\t\t\t\t\tconst now = Date.now()\n\t\t\t\t\tfor (const [key, record] of this.cache.entries()) {\n\t\t\t\t\t\tif (record.expiredAt && record.expiredAt <= now) this.cache.delete(key)\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t},\n\t\t\t1,\n\t\t)\n\t\tInstance.on('close', async () => clearInterval(interval), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tthis.cache.delete(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\tconst record = this.cache.get(this.getScopedKey(key))\n\t\tif (record && (record.expiredAt === undefined || record.expiredAt > Date.now())) return record.data\n\t\treturn null\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tthis.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1000 : undefined })\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T> {\n\t\tconst cached = await this.get(key)\n\t\tif (cached) return JSON.parse(cached) as T\n\n\t\tconst result = await fn()\n\t\tawait this.set(key, JSON.stringify(result), ttlInSecs)\n\t\treturn result\n\t}\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAOf,MAAM,sBAAsB,MAAM;AAAA,EACvB,QAAQ,oBAAI,IAAwB;AAAA,EAErD,cAAc;AACb,UAAM;AACN,QAAI;AACJ,aAAS;AAAA,MACR;AAAA,MACA,YAAY;AACX,mBAAW,YAAY,MAAM;AAC5B,gBAAM,MAAM,KAAK,IAAI;AACrB,qBAAW,CAAC,KAAK,MAAM,KAAK,KAAK,MAAM,QAAQ,GAAG;AACjD,gBAAI,OAAO,aAAa,OAAO,aAAa,IAAK,MAAK,MAAM,OAAO,GAAG;AAAA,UACvE;AAAA,QACD,GAAG,GAAI;AAAA,MACR;AAAA,MACA;AAAA,IACD;AACA,aAAS,GAAG,SAAS,YAAY,cAAc,QAAQ,GAAG,CAAC;AAAA,EAC5D;AAAA,EAEQ,aAAa,KAAqB;AACzC,WAAO,SAAS,IAAI,EAAE,cAAc,KAAK,GAAG;AAAA,EAC7C;AAAA,EAEA,MAAM,OAAO,KAAa;AACzB,SAAK,MAAM,OAAO,KAAK,aAAa,GAAG,CAAC;AAAA,EACzC;AAAA,EAEA,MAAM,IAAI,KAAa;AACtB,UAAM,SAAS,KAAK,MAAM,IAAI,KAAK,aAAa,GAAG,CAAC;AACpD,QAAI,WAAW,OAAO,cAAc,UAAa,OAAO,YAAY,KAAK,IAAI,GAAI,QAAO,OAAO;AAC/F,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,IAAI,KAAa,MAAc,WAAoB;AACxD,SAAK,MAAM,IAAI,KAAK,aAAa,GAAG,GAAG,EAAE,MAAM,WAAW,YAAY,KAAK,IAAI,IAAI,YAAY,MAAO,OAAU,CAAC;AAAA,EAClH;AAAA,EAEA,MAAM,SAAY,KAAa,IAAsB,WAAgC;AACpF,UAAM,SAAS,MAAM,KAAK,IAAI,GAAG;AACjC,QAAI,OAAQ,QAAO,KAAK,MAAM,MAAM;AAEpC,UAAM,SAAS,MAAM,GAAG;AACxB,UAAM,KAAK,IAAI,KAAK,KAAK,UAAU,MAAM,GAAG,SAAS;AACrD,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -1,2 +1,2 @@
1
- import{Cluster as n,Redis as c}from"ioredis";import{EquippedError as a}from "../../errors/index.min.mjs";import{Instance as i}from "../../instance/index.min.mjs";import{Cache as p}from "../base.min.mjs";class f extends p{client;constructor(e,t){super();const s={...e.host?{host:e.host}:{},...e.port?{port:e.port}:{}},r={...t,...e.password?{password:e.password}:{},...e.username?{username:e.username}:{},...e.tls?{tls:{}}:{},lazyConnect:!0};this.client=e.cluster?new n([s],{...t,redisOptions:r,lazyConnect:!0}):new c({...r,...s}),this.client.on("error",async o=>{i.crash(new a("Redis failed with error",{},o))}),t||i.on("start",async()=>this.client.connect(),1),i.on("close",async()=>this.client.quit(),1)}getScopedKey(e){return i.get().getScopedName(e,":")}async delete(e){await this.client.del(this.getScopedKey(e))}async get(e){return await this.client.get(this.getScopedKey(e))}async set(e,t,s){s>0?await this.client.setex(this.getScopedKey(e),s,t):this.client.set(this.getScopedKey(e),t)}async getOrSet(e,t,s){const r=await this.get(this.getScopedKey(e));if(r)return JSON.parse(r);const o=await t();await this.set(this.getScopedKey(e),JSON.stringify(o),s)}}export{f as RedisCache};
1
+ import{Cluster as n,Redis as c}from"ioredis";import{EquippedError as a}from "../../errors/index.min.mjs";import{Instance as i}from "../../instance/index.min.mjs";import{Cache as p}from "../base.min.mjs";class f extends p{client;constructor(e,t){super();const s={...e.host?{host:e.host}:{},...e.port?{port:e.port}:{}},r={...t,...e.password?{password:e.password}:{},...e.username?{username:e.username}:{},...e.tls?{tls:{}}:{},lazyConnect:!0};this.client=e.cluster?new n([s],{...t,redisOptions:r,lazyConnect:!0}):new c({...r,...s}),this.client.on("error",async o=>{i.crash(new a("Redis failed with error",{},o))}),t||i.on("start",async()=>this.client.connect(),1),i.on("close",async()=>this.client.quit(),1)}getScopedKey(e){return i.get().getScopedName(e,":")}async delete(e){await this.client.del(this.getScopedKey(e))}async get(e){return await this.client.get(this.getScopedKey(e))}async set(e,t,s){s?await this.client.setex(this.getScopedKey(e),s,t):this.client.set(this.getScopedKey(e),t)}async getOrSet(e,t,s){const r=await this.get(this.getScopedKey(e));if(r)return JSON.parse(r);const o=await t();await this.set(this.getScopedKey(e),JSON.stringify(o),s)}}export{f as RedisCache};
2
2
  //# sourceMappingURL=redis.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tif (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"],"mappings":"AAAA,OAAS,WAAAA,EAAS,SAAAC,MAA2B,UAE7C,OAAS,iBAAAC,MAAqB,eAC9B,OAAS,YAAAC,MAAgB,iBACzB,OAAS,SAAAC,MAAa,UAGf,MAAMC,UAAm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GE,EAAWD,CAAI,EAC7E,KAAK,OAAO,IAAI,KAAK,aAAaD,CAAG,EAAGC,CAAI,CAClD,CAEA,MAAM,SAAYD,EAAaG,EAAsBD,EAAmB,CACvE,MAAME,EAAS,MAAM,KAAK,IAAI,KAAK,aAAaJ,CAAG,CAAC,EACpD,GAAII,EAAQ,OAAO,KAAK,MAAMA,CAAM,EAEpC,MAAMC,EAAS,MAAMF,EAAG,EACxB,MAAM,KAAK,IAAI,KAAK,aAAaH,CAAG,EAAG,KAAK,UAAUK,CAAM,EAAGH,CAAS,CACzE,CACD","names":["Cluster","Redis","EquippedError","Instance","Cache","RedisCache","settings","extraConfig","node","common","error","key","data","ttlInSecs","fn","cached","result"]}
1
+ {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tif (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"],"mappings":"AAAA,OAAS,WAAAA,EAAS,SAAAC,MAA2B,UAE7C,OAAS,iBAAAC,MAAqB,eAC9B,OAAS,YAAAC,MAAgB,iBACzB,OAAS,SAAAC,MAAa,UAGf,MAAMC,UAAmBD,CAAM,CACrC,OAEA,YAAYE,EAAuBC,EAAqC,CACvE,MAAM,EACN,MAAMC,EAAO,CACZ,GAAIF,EAAS,KAAO,CAAE,KAAMA,EAAS,IAAK,EAAI,CAAC,EAC/C,GAAIA,EAAS,KAAO,CAAE,KAAMA,EAAS,IAAK,EAAI,CAAC,CAChD,EACMG,EAAS,CACd,GAAGF,EACH,GAAID,EAAS,SAAW,CAAE,SAAUA,EAAS,QAAS,EAAI,CAAC,EAC3D,GAAIA,EAAS,SAAW,CAAE,SAAUA,EAAS,QAAS,EAAI,CAAC,EAC3D,GAAIA,EAAS,IAAM,CAAE,IAAK,CAAC,CAAE,EAAI,CAAC,EAClC,YAAa,EACd,EACA,KAAK,OAASA,EAAS,QACpB,IAAIN,EAAQ,CAACQ,CAAI,EAAG,CACpB,GAAGD,EACH,aAAcE,EACd,YAAa,EACd,CAAC,EACA,IAAIR,EAAM,CAAE,GAAGQ,EAAQ,GAAGD,CAAK,CAAC,EACnC,KAAK,OAAO,GAAG,QAAS,MAAOE,GAAU,CACxCP,EAAS,MAAM,IAAID,EAAc,0BAA2B,CAAC,EAAGQ,CAAK,CAAC,CACvE,CAAC,EACIH,GAAaJ,EAAS,GAAG,QAAS,SAAY,KAAK,OAAO,QAAQ,EAAG,CAAC,EAC3EA,EAAS,GAAG,QAAS,SAAY,KAAK,OAAO,KAAK,EAAG,CAAC,CACvD,CAEQ,aAAaQ,EAAqB,CACzC,OAAOR,EAAS,IAAI,EAAE,cAAcQ,EAAK,GAAG,CAC7C,CAEA,MAAM,OAAOA,EAAa,CACzB,MAAM,KAAK,OAAO,IAAI,KAAK,aAAaA,CAAG,CAAC,CAC7C,CAEA,MAAM,IAAIA,EAAa,CACtB,OAAO,MAAM,KAAK,OAAO,IAAI,KAAK,aAAaA,CAAG,CAAC,CACpD,CAEA,MAAM,IAAIA,EAAaC,EAAcC,EAAoB,CACpDA,EAAW,MAAM,KAAK,OAAO,MAAM,KAAK,aAAaF,CAAG,EAAGE,EAAWD,CAAI,EACzE,KAAK,OAAO,IAAI,KAAK,aAAaD,CAAG,EAAGC,CAAI,CAClD,CAEA,MAAM,SAAYD,EAAaG,EAAsBD,EAAoB,CACxE,MAAME,EAAS,MAAM,KAAK,IAAI,KAAK,aAAaJ,CAAG,CAAC,EACpD,GAAII,EAAQ,OAAO,KAAK,MAAMA,CAAM,EAEpC,MAAMC,EAAS,MAAMF,EAAG,EACxB,MAAM,KAAK,IAAI,KAAK,aAAaH,CAAG,EAAG,KAAK,UAAUK,CAAM,EAAGH,CAAS,CACzE,CACD","names":["Cluster","Redis","EquippedError","Instance","Cache","RedisCache","settings","extraConfig","node","common","error","key","data","ttlInSecs","fn","cached","result"]}
@@ -38,7 +38,7 @@ class RedisCache extends Cache {
38
38
  return await this.client.get(this.getScopedKey(key));
39
39
  }
40
40
  async set(key, data, ttlInSecs) {
41
- if (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
41
+ if (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
42
42
  else this.client.set(this.getScopedKey(key), data);
43
43
  }
44
44
  async getOrSet(key, fn, ttlInSecs) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs: number) {\n\t\tif (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"],"mappings":"AAAA,SAAS,SAAS,aAA2B;AAE7C,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAGf,MAAM,mBAAmB,MAAM;AAAA,EACrC;AAAA,EAEA,YAAY,UAAuB,aAAqC;AACvE,UAAM;AACN,UAAM,OAAO;AAAA,MACZ,GAAI,SAAS,OAAO,EAAE,MAAM,SAAS,KAAK,IAAI,CAAC;AAAA,MAC/C,GAAI,SAAS,OAAO,EAAE,MAAM,SAAS,KAAK,IAAI,CAAC;AAAA,IAChD;AACA,UAAM,SAAS;AAAA,MACd,GAAG;AAAA,MACH,GAAI,SAAS,WAAW,EAAE,UAAU,SAAS,SAAS,IAAI,CAAC;AAAA,MAC3D,GAAI,SAAS,WAAW,EAAE,UAAU,SAAS,SAAS,IAAI,CAAC;AAAA,MAC3D,GAAI,SAAS,MAAM,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC;AAAA,MAClC,aAAa;AAAA,IACd;AACA,SAAK,SAAS,SAAS,UACpB,IAAI,QAAQ,CAAC,IAAI,GAAG;AAAA,MACpB,GAAG;AAAA,MACH,cAAc;AAAA,MACd,aAAa;AAAA,IACd,CAAC,IACA,IAAI,MAAM,EAAE,GAAG,QAAQ,GAAG,KAAK,CAAC;AACnC,SAAK,OAAO,GAAG,SAAS,OAAO,UAAU;AACxC,eAAS,MAAM,IAAI,cAAc,2BAA2B,CAAC,GAAG,KAAK,CAAC;AAAA,IACvE,CAAC;AACD,QAAI,CAAC,YAAa,UAAS,GAAG,SAAS,YAAY,KAAK,OAAO,QAAQ,GAAG,CAAC;AAC3E,aAAS,GAAG,SAAS,YAAY,KAAK,OAAO,KAAK,GAAG,CAAC;AAAA,EACvD;AAAA,EAEQ,aAAa,KAAqB;AACzC,WAAO,SAAS,IAAI,EAAE,cAAc,KAAK,GAAG;AAAA,EAC7C;AAAA,EAEA,MAAM,OAAO,KAAa;AACzB,UAAM,KAAK,OAAO,IAAI,KAAK,aAAa,GAAG,CAAC;AAAA,EAC7C;AAAA,EAEA,MAAM,IAAI,KAAa;AACtB,WAAO,MAAM,KAAK,OAAO,IAAI,KAAK,aAAa,GAAG,CAAC;AAAA,EACpD;AAAA,EAEA,MAAM,IAAI,KAAa,MAAc,WAAmB;AACvD,QAAI,YAAY,EAAG,OAAM,KAAK,OAAO,MAAM,KAAK,aAAa,GAAG,GAAG,WAAW,IAAI;AAAA,QAC7E,MAAK,OAAO,IAAI,KAAK,aAAa,GAAG,GAAG,IAAI;AAAA,EAClD;AAAA,EAEA,MAAM,SAAY,KAAa,IAAsB,WAAmB;AACvE,UAAM,SAAS,MAAM,KAAK,IAAI,KAAK,aAAa,GAAG,CAAC;AACpD,QAAI,OAAQ,QAAO,KAAK,MAAM,MAAM;AAEpC,UAAM,SAAS,MAAM,GAAG;AACxB,UAAM,KAAK,IAAI,KAAK,aAAa,GAAG,GAAG,KAAK,UAAU,MAAM,GAAG,SAAS;AAAA,EACzE;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/cache/types/redis.ts"],"sourcesContent":["import { Cluster, Redis, RedisOptions } from 'ioredis'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { Cache } from '../base'\nimport { RedisConfig } from '../pipes'\n\nexport class RedisCache extends Cache {\n\tclient: Redis | Cluster\n\n\tconstructor(settings: RedisConfig, extraConfig?: Partial<RedisOptions>) {\n\t\tsuper()\n\t\tconst node = {\n\t\t\t...(settings.host ? { host: settings.host } : {}),\n\t\t\t...(settings.port ? { port: settings.port } : {}),\n\t\t}\n\t\tconst common = {\n\t\t\t...extraConfig,\n\t\t\t...(settings.password ? { password: settings.password } : {}),\n\t\t\t...(settings.username ? { username: settings.username } : {}),\n\t\t\t...(settings.tls ? { tls: {} } : {}),\n\t\t\tlazyConnect: true,\n\t\t}\n\t\tthis.client = settings.cluster\n\t\t\t? new Cluster([node], {\n\t\t\t\t\t...extraConfig,\n\t\t\t\t\tredisOptions: common,\n\t\t\t\t\tlazyConnect: true,\n\t\t\t\t})\n\t\t\t: new Redis({ ...common, ...node })\n\t\tthis.client.on('error', async (error) => {\n\t\t\tInstance.crash(new EquippedError(`Redis failed with error`, {}, error))\n\t\t})\n\t\tif (!extraConfig) Instance.on('start', async () => this.client.connect(), 1)\n\t\tInstance.on('close', async () => this.client.quit(), 1)\n\t}\n\n\tprivate getScopedKey(key: string): string {\n\t\treturn Instance.get().getScopedName(key, ':')\n\t}\n\n\tasync delete(key: string) {\n\t\tawait this.client.del(this.getScopedKey(key))\n\t}\n\n\tasync get(key: string) {\n\t\treturn await this.client.get(this.getScopedKey(key))\n\t}\n\n\tasync set(key: string, data: string, ttlInSecs?: number) {\n\t\tif (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data)\n\t\telse this.client.set(this.getScopedKey(key), data)\n\t}\n\n\tasync getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number) {\n\t\tconst cached = await this.get(this.getScopedKey(key))\n\t\tif (cached) return JSON.parse(cached)\n\n\t\tconst result = await fn()\n\t\tawait this.set(this.getScopedKey(key), JSON.stringify(result), ttlInSecs)\n\t}\n}\n"],"mappings":"AAAA,SAAS,SAAS,aAA2B;AAE7C,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAGf,MAAM,mBAAmB,MAAM;AAAA,EACrC;AAAA,EAEA,YAAY,UAAuB,aAAqC;AACvE,UAAM;AACN,UAAM,OAAO;AAAA,MACZ,GAAI,SAAS,OAAO,EAAE,MAAM,SAAS,KAAK,IAAI,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OAAO,IAAI,KAAK,aAAa,GAAG,GAAG,IAAI;AAAA,EAClD;AAAA,EAEA,MAAM,SAAY,KAAa,IAAsB,WAAoB;AACxE,UAAM,SAAS,MAAM,KAAK,IAAI,KAAK,aAAa,GAAG,CAAC;AACpD,QAAI,OAAQ,QAAO,KAAK,MAAM,MAAM;AAEpC,UAAM,SAAS,MAAM,GAAG;AACxB,UAAM,KAAK,IAAI,KAAK,aAAa,GAAG,GAAG,KAAK,UAAU,MAAM,GAAG,SAAS;AAAA,EACzE;AACD;","names":[]}
@@ -1,8 +1,8 @@
1
1
  declare abstract class Cache {
2
- abstract set(key: string, data: string, ttlInSecs: number): Promise<void>;
2
+ abstract set(key: string, data: string, ttlInSecs?: number): Promise<void>;
3
3
  abstract get(key: string): Promise<string | null>;
4
4
  abstract delete(key: string): Promise<void>;
5
- abstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>;
5
+ abstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>;
6
6
  }
7
7
 
8
8
  export { Cache as C };
@@ -1,4 +1,4 @@
1
- import { C as Cache } from '../base-k4t2NepI.js';
1
+ import { C as Cache } from '../base-8yVXb67P.js';
2
2
  import * as valleyed from 'valleyed';
3
3
  import { PipeOutput } from 'valleyed';
4
4
  import { Redis, Cluster, RedisOptions } from 'ioredis';
@@ -26,8 +26,8 @@ declare class InMemoryCache extends Cache {
26
26
  private getScopedKey;
27
27
  delete(key: string): Promise<void>;
28
28
  get(key: string): Promise<string | null>;
29
- set(key: string, data: string, ttlInSecs: number): Promise<void>;
30
- getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>;
29
+ set(key: string, data: string, ttlInSecs?: number): Promise<void>;
30
+ getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<T>;
31
31
  }
32
32
 
33
33
  declare class RedisCache extends Cache {
@@ -36,8 +36,8 @@ declare class RedisCache extends Cache {
36
36
  private getScopedKey;
37
37
  delete(key: string): Promise<void>;
38
38
  get(key: string): Promise<string | null>;
39
- set(key: string, data: string, ttlInSecs: number): Promise<void>;
40
- getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<any>;
39
+ set(key: string, data: string, ttlInSecs?: number): Promise<void>;
40
+ getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs?: number): Promise<any>;
41
41
  }
42
42
 
43
43
  export { Cache, InMemoryCache, RedisCache, type RedisConfig, redisConfigPipe };
@@ -11,7 +11,7 @@ class InMemoryCache extends Cache {
11
11
  interval = setInterval(() => {
12
12
  const now = Date.now();
13
13
  for (const [key, record] of this.cache.entries()) {
14
- if (record.expiredAt <= now) this.cache.delete(key);
14
+ if (record.expiredAt && record.expiredAt <= now) this.cache.delete(key);
15
15
  }
16
16
  }, 5e3);
17
17
  },
@@ -27,11 +27,11 @@ class InMemoryCache extends Cache {
27
27
  }
28
28
  async get(key) {
29
29
  const record = this.cache.get(this.getScopedKey(key));
30
- if (record && record.expiredAt > Date.now()) return record.data;
30
+ if (record && (record.expiredAt === void 0 || record.expiredAt > Date.now())) return record.data;
31
31
  return null;
32
32
  }
33
33
  async set(key, data, ttlInSecs) {
34
- this.cache.set(this.getScopedKey(key), { data, expiredAt: Date.now() + ttlInSecs * 1e3 });
34
+ this.cache.set(this.getScopedKey(key), { data, expiredAt: ttlInSecs ? Date.now() + ttlInSecs * 1e3 : void 0 });
35
35
  }
36
36
  async getOrSet(key, fn, ttlInSecs) {
37
37
  const cached = await this.get(key);
@@ -38,7 +38,7 @@ class RedisCache extends Cache {
38
38
  return await this.client.get(this.getScopedKey(key));
39
39
  }
40
40
  async set(key, data, ttlInSecs) {
41
- if (ttlInSecs > 0) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
41
+ if (ttlInSecs) await this.client.setex(this.getScopedKey(key), ttlInSecs, data);
42
42
  else this.client.set(this.getScopedKey(key), data);
43
43
  }
44
44
  async getOrSet(key, fn, ttlInSecs) {
@@ -1,7 +1,7 @@
1
1
  import * as valleyed from 'valleyed';
2
2
  import { PipeOutput, ConditionalObjectKeys, PipeInput, IsInTypeList, DataClass, Pipe } from 'valleyed';
3
3
  import { Logger } from 'pino';
4
- import { C as Cache } from './base-k4t2NepI.js';
4
+ import { C as Cache } from './base-8yVXb67P.js';
5
5
  import { E as EventBus } from './kafka-DrqkU2KH.js';
6
6
  import { E as Entity, j as MongoDb } from './index-CegB2bgP.js';
7
7
  import { RedisJob } from './jobs/index.js';
@@ -1,7 +1,7 @@
1
- export { I as Instance } from './index-BtF0VClz.js';
1
+ export { I as Instance } from './index-5Qkb5V68.js';
2
2
  import 'valleyed';
3
3
  import 'pino';
4
- import './base-k4t2NepI.js';
4
+ import './base-8yVXb67P.js';
5
5
  import './kafka-DrqkU2KH.js';
6
6
  import './overrides-6Hxg764S.js';
7
7
  import './index-CegB2bgP.js';
@@ -1,8 +1,8 @@
1
1
  import 'valleyed';
2
- export { I as Instance } from '../index-BtF0VClz.js';
2
+ export { I as Instance } from '../index-5Qkb5V68.js';
3
3
  import '../requests-DBqR41Uw.js';
4
4
  import 'pino';
5
- import '../base-k4t2NepI.js';
5
+ import '../base-8yVXb67P.js';
6
6
  import '../kafka-DrqkU2KH.js';
7
7
  import '../overrides-6Hxg764S.js';
8
8
  import '../index-CegB2bgP.js';
@@ -1,12 +1,12 @@
1
- import { S as Server, a as ServerConfig } from '../index-BtF0VClz.js';
2
- export { B as BaseApiKeysUtility, b as BaseTokensUtility, C as CacheTokensUtility, O as OnJoinFn, R as Router, c as SocketCallbacks, d as SocketEmitter, s as serverPipe } from '../index-BtF0VClz.js';
1
+ import { S as Server, a as ServerConfig } from '../index-5Qkb5V68.js';
2
+ export { B as BaseApiKeysUtility, b as BaseTokensUtility, C as CacheTokensUtility, O as OnJoinFn, R as Router, c as SocketCallbacks, d as SocketEmitter, s as serverPipe } from '../index-5Qkb5V68.js';
3
3
  import express from 'express';
4
4
  import { FastifyRequest, FastifyReply } from 'fastify';
5
5
  import { a as Request, c as RouteDefToReqRes, d as RouteDef, e as Route } from '../requests-DBqR41Uw.js';
6
6
  export { D as DefaultHeaders, I as IncomingFile, j as MergeRouteDefs, M as Methods, f as MethodsEnum, b as Response, h as RouteConfig, k as RouteDefHandler, i as RouterConfig, S as StatusCodes, g as StatusCodesEnum, l as makeErrorMiddleware, m as makeMiddleware } from '../requests-DBqR41Uw.js';
7
7
  import 'valleyed';
8
8
  import 'pino';
9
- import '../base-k4t2NepI.js';
9
+ import '../base-8yVXb67P.js';
10
10
  import '../kafka-DrqkU2KH.js';
11
11
  import '../overrides-6Hxg764S.js';
12
12
  import '../index-CegB2bgP.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "equipped",
3
- "version": "5.0.13",
3
+ "version": "5.0.14",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "type": "module",