@geekmidas/cache 10.0.0-alpha.99 → 10.0.0

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
  3. package/dist/expo.cjs +10 -10
  4. package/dist/expo.cjs.map +1 -1
  5. package/dist/expo.d.cts +6 -2
  6. package/dist/expo.d.cts.map +1 -1
  7. package/dist/expo.d.mts +6 -2
  8. package/dist/expo.d.mts.map +1 -1
  9. package/dist/expo.mjs +6 -4
  10. package/dist/expo.mjs.map +1 -1
  11. package/dist/file.cjs +19 -16
  12. package/dist/file.cjs.map +1 -1
  13. package/dist/file.d.cts +6 -3
  14. package/dist/file.d.cts.map +1 -1
  15. package/dist/file.d.mts +6 -3
  16. package/dist/file.d.mts.map +1 -1
  17. package/dist/file.mjs +12 -7
  18. package/dist/file.mjs.map +1 -1
  19. package/dist/index-BSYYdwRm.d.cts +36 -0
  20. package/dist/index-BSYYdwRm.d.cts.map +1 -0
  21. package/dist/index-Dx96gr-9.d.mts +36 -0
  22. package/dist/index-Dx96gr-9.d.mts.map +1 -0
  23. package/dist/index.cjs +2 -17
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.mts +2 -2
  26. package/dist/index.mjs +2 -12
  27. package/dist/memory.cjs +11 -8
  28. package/dist/memory.cjs.map +1 -1
  29. package/dist/memory.d.cts +6 -2
  30. package/dist/memory.d.cts.map +1 -1
  31. package/dist/memory.d.mts +6 -2
  32. package/dist/memory.d.mts.map +1 -1
  33. package/dist/memory.mjs +8 -5
  34. package/dist/memory.mjs.map +1 -1
  35. package/dist/src-CrE4Nl5T.mjs +14 -0
  36. package/dist/src-CrE4Nl5T.mjs.map +1 -0
  37. package/dist/src-zfYb7mdS.cjs +20 -0
  38. package/dist/src-zfYb7mdS.cjs.map +1 -0
  39. package/dist/upstash.cjs +6 -46
  40. package/dist/upstash.cjs.map +1 -1
  41. package/dist/upstash.d.cts +6 -27
  42. package/dist/upstash.d.cts.map +1 -1
  43. package/dist/upstash.d.mts +6 -27
  44. package/dist/upstash.d.mts.map +1 -1
  45. package/dist/upstash.mjs +4 -41
  46. package/dist/upstash.mjs.map +1 -1
  47. package/package.json +6 -53
  48. package/src/__benchmarks__/memory.bench.ts +51 -0
  49. package/src/__tests__/cache.spec.ts +144 -0
  50. package/src/__tests__/file.spec.ts +192 -0
  51. package/src/__tests__/integration.spec.ts +282 -0
  52. package/src/__tests__/memory.spec.ts +134 -0
  53. package/src/__tests__/upstash.spec.ts +276 -0
  54. package/src/expo.ts +50 -0
  55. package/src/file.ts +126 -0
  56. package/src/index.ts +48 -0
  57. package/src/memory.ts +38 -0
  58. package/src/upstash.ts +41 -0
  59. package/tsconfig.json +9 -0
  60. package/tsdown.config.ts +5 -0
  61. package/dist/index-BbdGhmWP.d.cts +0 -62
  62. package/dist/index-BbdGhmWP.d.cts.map +0 -1
  63. package/dist/index-BbdGhmWP.d.mts +0 -62
  64. package/dist/index-BbdGhmWP.d.mts.map +0 -1
  65. package/dist/index.cjs.map +0 -1
  66. package/dist/index.mjs.map +0 -1
  67. package/dist/postgres.cjs +0 -185
  68. package/dist/postgres.cjs.map +0 -1
  69. package/dist/postgres.d.cts +0 -71
  70. package/dist/postgres.d.cts.map +0 -1
  71. package/dist/postgres.d.mts +0 -71
  72. package/dist/postgres.d.mts.map +0 -1
  73. package/dist/postgres.mjs +0 -180
  74. package/dist/postgres.mjs.map +0 -1
  75. package/dist/redis.cjs +0 -88
  76. package/dist/redis.cjs.map +0 -1
  77. package/dist/redis.d.cts +0 -27
  78. package/dist/redis.d.cts.map +0 -1
  79. package/dist/redis.d.mts +0 -27
  80. package/dist/redis.d.mts.map +0 -1
  81. package/dist/redis.mjs +0 -85
  82. package/dist/redis.mjs.map +0 -1
  83. package/dist/registry.cjs +0 -48
  84. package/dist/registry.cjs.map +0 -1
  85. package/dist/registry.d.cts +0 -2
  86. package/dist/registry.d.mts +0 -2
  87. package/dist/registry.mjs +0 -44
  88. package/dist/registry.mjs.map +0 -1
  89. package/dist/telemetry.cjs +0 -38
  90. package/dist/telemetry.cjs.map +0 -1
  91. package/dist/telemetry.d.cts +0 -6
  92. package/dist/telemetry.d.cts.map +0 -1
  93. package/dist/telemetry.d.mts +0 -6
  94. package/dist/telemetry.d.mts.map +0 -1
  95. package/dist/telemetry.mjs +0 -37
  96. package/dist/telemetry.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,13 +1,3 @@
1
- import { UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes } from "./registry.mjs";
2
- import { differenceInSeconds } from "date-fns";
3
- //#region src/index.ts
4
- const getExpirationInSeconds = (expiresAt) => {
5
- if (!expiresAt) return 0;
6
- const expirationDate = new Date(expiresAt);
7
- const secondsLeft = differenceInSeconds(expirationDate, /* @__PURE__ */ new Date());
8
- return Math.max(secondsLeft, 0);
9
- };
10
- //#endregion
11
- export { UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
1
+ import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
12
2
 
13
- //# sourceMappingURL=index.mjs.map
3
+ export { getExpirationInSeconds };
package/dist/memory.cjs CHANGED
@@ -1,25 +1,28 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_index = require("./index.cjs");
3
- let date_fns = require("date-fns");
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_src = require('./src-zfYb7mdS.cjs');
3
+ const date_fns = require_chunk.__toESM(require("date-fns"));
4
+
4
5
  //#region src/memory.ts
5
6
  var InMemoryCache = class {
6
7
  store = /* @__PURE__ */ new Map();
7
8
  expirations = /* @__PURE__ */ new Map();
8
9
  async get(key) {
9
- if (!await this.ttl(key)) {
10
+ const expiration = await this.ttl(key);
11
+ if (!expiration) {
10
12
  await this.delete(key);
11
- return;
13
+ return void 0;
12
14
  }
13
15
  return this.store.get(key);
14
16
  }
15
17
  async ttl(key) {
16
18
  const expiration = this.expirations.get(key);
17
19
  if (!expiration) return 0;
18
- return require_index.getExpirationInSeconds(expiration);
20
+ return require_src.getExpirationInSeconds(expiration);
19
21
  }
20
22
  async set(key, value, ttl = 600) {
21
23
  this.store.set(key, value);
22
- const expiresAt = (0, date_fns.addSeconds)(/* @__PURE__ */ new Date(), ttl);
24
+ const now = /* @__PURE__ */ new Date();
25
+ const expiresAt = (0, date_fns.addSeconds)(now, ttl);
23
26
  this.expirations.set(key, expiresAt);
24
27
  }
25
28
  async delete(key) {
@@ -27,7 +30,7 @@ var InMemoryCache = class {
27
30
  this.expirations.delete(key);
28
31
  }
29
32
  };
33
+
30
34
  //#endregion
31
35
  exports.InMemoryCache = InMemoryCache;
32
-
33
36
  //# sourceMappingURL=memory.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.cjs","names":["getExpirationInSeconds","addSeconds"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,wBAAsC,IAAI,IAAI;CAC9C,8BAAyC,IAAI,IAAI;CAEjD,MAAM,IAAO,KAAqC;EAEjD,IAAI,CAAC,MADoB,KAAK,IAAI,GAAG,GACpB;GAChB,MAAM,KAAK,OAAO,GAAG;GACrB;EACD;EAEA,OAAO,KAAK,MAAM,IAAI,GAAG;CAC1B;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,GAAG;EAC3C,IAAI,CAAC,YACJ,OAAO;EAGR,OAAOA,cAAAA,uBAAuB,UAAU;CACzC;CAEA,MAAM,IAAO,KAAa,OAAU,MAAc,KAAoB;EACrE,KAAK,MAAM,IAAI,KAAK,KAAK;EAEzB,MAAM,aAAA,GAAYC,SAAAA,WAAAA,iBAAW,IADb,KACe,GAAG,GAAG;EACrC,KAAK,YAAY,IAAI,KAAK,SAAS;CACpC;CAEA,MAAM,OAAO,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;EACrB,KAAK,YAAY,OAAO,GAAG;CAC5B;AACD"}
1
+ {"version":3,"file":"memory.cjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,mCAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,yBAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
package/dist/memory.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import { t as Cache } from "./index-BbdGhmWP.cjs";
1
+ import { Cache } from "./index-BSYYdwRm.cjs";
2
+
2
3
  //#region src/memory.d.ts
3
- export declare class InMemoryCache implements Cache {
4
+ declare class InMemoryCache implements Cache {
4
5
  private store;
5
6
  private expirations;
6
7
  get<T>(key: string): Promise<T | undefined>;
@@ -8,5 +9,8 @@ export declare class InMemoryCache implements Cache {
8
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
10
  delete(key: string): Promise<void>;
10
11
  }
12
+ //# sourceMappingURL=memory.d.ts.map
13
+
11
14
  //#endregion
15
+ export { InMemoryCache };
12
16
  //# sourceMappingURL=memory.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"mappings":";;qBAGa,yBAAyB;UAC7B;UACA;EAEF,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,cAAc;EASlB,IAAI,GAAG,aAAa,OAAO,GAAG,eAAoB;EAOlD,OAAO,cAAc"}
1
+ {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
package/dist/memory.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { t as Cache } from "./index-BbdGhmWP.mjs";
1
+ import { Cache } from "./index-Dx96gr-9.mjs";
2
+
2
3
  //#region src/memory.d.ts
3
- export declare class InMemoryCache implements Cache {
4
+ declare class InMemoryCache implements Cache {
4
5
  private store;
5
6
  private expirations;
6
7
  get<T>(key: string): Promise<T | undefined>;
@@ -8,5 +9,8 @@ export declare class InMemoryCache implements Cache {
8
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
10
  delete(key: string): Promise<void>;
10
11
  }
12
+ //# sourceMappingURL=memory.d.ts.map
13
+
11
14
  //#endregion
15
+ export { InMemoryCache };
12
16
  //# sourceMappingURL=memory.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"mappings":";;qBAGa,yBAAyB;UAC7B;UACA;EAEF,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,cAAc;EASlB,IAAI,GAAG,aAAa,OAAO,GAAG,eAAoB;EAOlD,OAAO,cAAc"}
1
+ {"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
package/dist/memory.mjs CHANGED
@@ -1,13 +1,15 @@
1
- import { getExpirationInSeconds } from "./index.mjs";
1
+ import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
2
2
  import { addSeconds } from "date-fns";
3
+
3
4
  //#region src/memory.ts
4
5
  var InMemoryCache = class {
5
6
  store = /* @__PURE__ */ new Map();
6
7
  expirations = /* @__PURE__ */ new Map();
7
8
  async get(key) {
8
- if (!await this.ttl(key)) {
9
+ const expiration = await this.ttl(key);
10
+ if (!expiration) {
9
11
  await this.delete(key);
10
- return;
12
+ return void 0;
11
13
  }
12
14
  return this.store.get(key);
13
15
  }
@@ -18,7 +20,8 @@ var InMemoryCache = class {
18
20
  }
19
21
  async set(key, value, ttl = 600) {
20
22
  this.store.set(key, value);
21
- const expiresAt = addSeconds(/* @__PURE__ */ new Date(), ttl);
23
+ const now = /* @__PURE__ */ new Date();
24
+ const expiresAt = addSeconds(now, ttl);
22
25
  this.expirations.set(key, expiresAt);
23
26
  }
24
27
  async delete(key) {
@@ -26,7 +29,7 @@ var InMemoryCache = class {
26
29
  this.expirations.delete(key);
27
30
  }
28
31
  };
32
+
29
33
  //#endregion
30
34
  export { InMemoryCache };
31
-
32
35
  //# sourceMappingURL=memory.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.mjs","names":[],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,wBAAsC,IAAI,IAAI;CAC9C,8BAAyC,IAAI,IAAI;CAEjD,MAAM,IAAO,KAAqC;EAEjD,IAAI,CAAC,MADoB,KAAK,IAAI,GAAG,GACpB;GAChB,MAAM,KAAK,OAAO,GAAG;GACrB;EACD;EAEA,OAAO,KAAK,MAAM,IAAI,GAAG;CAC1B;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,GAAG;EAC3C,IAAI,CAAC,YACJ,OAAO;EAGR,OAAO,uBAAuB,UAAU;CACzC;CAEA,MAAM,IAAO,KAAa,OAAU,MAAc,KAAoB;EACrE,KAAK,MAAM,IAAI,KAAK,KAAK;EAEzB,MAAM,YAAY,2BAAW,IADb,KACe,GAAG,GAAG;EACrC,KAAK,YAAY,IAAI,KAAK,SAAS;CACpC;CAEA,MAAM,OAAO,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;EACrB,KAAK,YAAY,OAAO,GAAG;CAC5B;AACD"}
1
+ {"version":3,"file":"memory.mjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,uBAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,WAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
@@ -0,0 +1,14 @@
1
+ import { differenceInSeconds } from "date-fns";
2
+
3
+ //#region src/index.ts
4
+ const getExpirationInSeconds = (expiresAt) => {
5
+ if (!expiresAt) return 0;
6
+ const expirationDate = new Date(expiresAt);
7
+ const now = /* @__PURE__ */ new Date();
8
+ const secondsLeft = differenceInSeconds(expirationDate, now);
9
+ return Math.max(secondsLeft, 0);
10
+ };
11
+
12
+ //#endregion
13
+ export { getExpirationInSeconds };
14
+ //# sourceMappingURL=src-CrE4Nl5T.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-CrE4Nl5T.mjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n"],"mappings":";;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
@@ -0,0 +1,20 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const date_fns = require_chunk.__toESM(require("date-fns"));
3
+
4
+ //#region src/index.ts
5
+ const getExpirationInSeconds = (expiresAt) => {
6
+ if (!expiresAt) return 0;
7
+ const expirationDate = new Date(expiresAt);
8
+ const now = /* @__PURE__ */ new Date();
9
+ const secondsLeft = (0, date_fns.differenceInSeconds)(expirationDate, now);
10
+ return Math.max(secondsLeft, 0);
11
+ };
12
+
13
+ //#endregion
14
+ Object.defineProperty(exports, 'getExpirationInSeconds', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return getExpirationInSeconds;
18
+ }
19
+ });
20
+ //# sourceMappingURL=src-zfYb7mdS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-zfYb7mdS.cjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
package/dist/upstash.cjs CHANGED
@@ -1,10 +1,11 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let _upstash_redis = require("@upstash/redis");
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const __upstash_redis = require_chunk.__toESM(require("@upstash/redis"));
3
+
3
4
  //#region src/upstash.ts
4
5
  var UpstashCache = class {
5
6
  client;
6
7
  constructor(url, token) {
7
- this.client = new _upstash_redis.Redis({
8
+ this.client = new __upstash_redis.Redis({
8
9
  url,
9
10
  token
10
11
  });
@@ -16,7 +17,7 @@ var UpstashCache = class {
16
17
  }
17
18
  async get(key) {
18
19
  const v = await this.client.get(key);
19
- if (v === null) return;
20
+ if (v === null) return void 0;
20
21
  return v;
21
22
  }
22
23
  async set(key, value, ttl = 3600) {
@@ -26,48 +27,7 @@ var UpstashCache = class {
26
27
  await this.client.del(key);
27
28
  }
28
29
  };
29
- /**
30
- * The `https://` and `http://` driver.
31
- *
32
- * The token travels in the URL's userinfo, because an address and the
33
- * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
34
- * that is Upstash's host over TLS; locally it is the `serverless-redis-http`
35
- * proxy in front of a Redis container, and the client cannot tell the
36
- * difference. That is the whole point of choosing this backend.
37
- */
38
- const upstashCacheDriver = {
39
- scheme: "https:",
40
- create: (url) => {
41
- const { endpoint, token } = parseUpstashUrl(url);
42
- return new UpstashCache(endpoint, token);
43
- }
44
- };
45
- /** The same driver for plain HTTP, which is what the local proxy speaks. */
46
- const upstashInsecureCacheDriver = {
47
- ...upstashCacheDriver,
48
- scheme: "http:"
49
- };
50
- /**
51
- * Split a cache URL into what the client takes.
52
- *
53
- * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
54
- * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
55
- * else differs.
56
- */
57
- function parseUpstashUrl(url) {
58
- const parsed = new URL(url);
59
- const token = decodeURIComponent(parsed.password || parsed.username);
60
- parsed.username = "";
61
- parsed.password = "";
62
- return {
63
- endpoint: parsed.origin,
64
- token
65
- };
66
- }
30
+
67
31
  //#endregion
68
32
  exports.UpstashCache = UpstashCache;
69
- exports.parseUpstashUrl = parseUpstashUrl;
70
- exports.upstashCacheDriver = upstashCacheDriver;
71
- exports.upstashInsecureCacheDriver = upstashInsecureCacheDriver;
72
-
73
33
  //# sourceMappingURL=upstash.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.cjs","names":["Redis"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\nimport type { CacheDriver } from './registry';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n\n/**\n * The `https://` and `http://` driver.\n *\n * The token travels in the URL's userinfo, because an address and the\n * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed\n * that is Upstash's host over TLS; locally it is the `serverless-redis-http`\n * proxy in front of a Redis container, and the client cannot tell the\n * difference. That is the whole point of choosing this backend.\n */\nexport const upstashCacheDriver: CacheDriver = {\n\tscheme: 'https:',\n\tcreate: (url) => {\n\t\tconst { endpoint, token } = parseUpstashUrl(url);\n\t\treturn new UpstashCache(endpoint, token);\n\t},\n};\n\n/** The same driver for plain HTTP, which is what the local proxy speaks. */\nexport const upstashInsecureCacheDriver: CacheDriver = {\n\t...upstashCacheDriver,\n\tscheme: 'http:',\n};\n\n/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */\nexport interface UpstashAddress {\n\tendpoint: string;\n\ttoken: string;\n}\n\n/**\n * Split a cache URL into what the client takes.\n *\n * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',\n * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing\n * else differs.\n */\nexport function parseUpstashUrl(url: string): UpstashAddress {\n\tconst parsed = new URL(url);\n\tconst token = decodeURIComponent(parsed.password || parsed.username);\n\n\tparsed.username = '';\n\tparsed.password = '';\n\n\treturn {\n\t\t// `origin` drops the trailing slash `toString()` would add, which the\n\t\t// client would otherwise send as part of every path.\n\t\tendpoint: parsed.origin,\n\t\ttoken,\n\t};\n}\n"],"mappings":";;;AAIA,IAAa,eAAb,MAA2C;CAC1C;CAEA,YAAY,KAAa,OAAe;EACvC,KAAK,SAAS,IAAIA,eAAAA,MAAM;GACvB;GACA;EACD,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,GAAG;EAErC,IAAI,QAAQ,IACX,OAAO;EAGR,OAAO;CACR;CAEA,MAAM,IAAO,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,GAAG;EAEnC,IAAI,MAAM,MACT;EAGD,OAAO;CACR;CAEA,MAAM,IAAO,KAAa,OAAU,MAAM,MAAqB;EAC9D,MAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAI,CAAC;CAC9C;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,KAAK,OAAO,IAAI,GAAG;CAC1B;AACD;;;;;;;;;;AAWA,MAAa,qBAAkC;CAC9C,QAAQ;CACR,SAAS,QAAQ;EAChB,MAAM,EAAE,UAAU,UAAU,gBAAgB,GAAG;EAC/C,OAAO,IAAI,aAAa,UAAU,KAAK;CACxC;AACD;;AAGA,MAAa,6BAA0C;CACtD,GAAG;CACH,QAAQ;AACT;;;;;;;;AAeA,SAAgB,gBAAgB,KAA6B;CAC5D,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,QAAQ,mBAAmB,OAAO,YAAY,OAAO,QAAQ;CAEnE,OAAO,WAAW;CAClB,OAAO,WAAW;CAElB,OAAO;EAGN,UAAU,OAAO;EACjB;CACD;AACD"}
1
+ {"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAIC,sBAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
@@ -1,6 +1,7 @@
1
- import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.cjs";
1
+ import { Cache } from "./index-BSYYdwRm.cjs";
2
+
2
3
  //#region src/upstash.d.ts
3
- export declare class UpstashCache implements Cache {
4
+ declare class UpstashCache implements Cache {
4
5
  private client;
5
6
  constructor(url: string, token: string);
6
7
  ttl(key: string): Promise<number>;
@@ -8,30 +9,8 @@ export declare class UpstashCache implements Cache {
8
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
10
  delete(key: string): Promise<void>;
10
11
  }
11
- /**
12
- * The `https://` and `http://` driver.
13
- *
14
- * The token travels in the URL's userinfo, because an address and the
15
- * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
16
- * that is Upstash's host over TLS; locally it is the `serverless-redis-http`
17
- * proxy in front of a Redis container, and the client cannot tell the
18
- * difference. That is the whole point of choosing this backend.
19
- */
20
- export declare const upstashCacheDriver: CacheDriver;
21
- /** The same driver for plain HTTP, which is what the local proxy speaks. */
22
- export declare const upstashInsecureCacheDriver: CacheDriver;
23
- /** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
24
- export interface UpstashAddress {
25
- endpoint: string;
26
- token: string;
27
- }
28
- /**
29
- * Split a cache URL into what the client takes.
30
- *
31
- * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
32
- * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
33
- * else differs.
34
- */
35
- export declare function parseUpstashUrl(url: string): UpstashAddress;
12
+ //# sourceMappingURL=upstash.d.ts.map
13
+
36
14
  //#endregion
15
+ export { UpstashCache };
37
16
  //# sourceMappingURL=upstash.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"mappings":";;qBAIa,wBAAwB;UAC5B;EAER,YAAY,aAAa;EAOnB,IAAI,cAAc;EAUlB,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAa;EAI3C,OAAO,cAAc;;;;;;;;;;;qBAcf,oBAAoB;;qBASpB,4BAA4B;;iBAMxB;EAChB;EACA;;;;;;;;;wBAUe,gBAAgB,cAAc"}
1
+ {"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
@@ -1,6 +1,7 @@
1
- import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.mjs";
1
+ import { Cache } from "./index-Dx96gr-9.mjs";
2
+
2
3
  //#region src/upstash.d.ts
3
- export declare class UpstashCache implements Cache {
4
+ declare class UpstashCache implements Cache {
4
5
  private client;
5
6
  constructor(url: string, token: string);
6
7
  ttl(key: string): Promise<number>;
@@ -8,30 +9,8 @@ export declare class UpstashCache implements Cache {
8
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
10
  delete(key: string): Promise<void>;
10
11
  }
11
- /**
12
- * The `https://` and `http://` driver.
13
- *
14
- * The token travels in the URL's userinfo, because an address and the
15
- * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
16
- * that is Upstash's host over TLS; locally it is the `serverless-redis-http`
17
- * proxy in front of a Redis container, and the client cannot tell the
18
- * difference. That is the whole point of choosing this backend.
19
- */
20
- export declare const upstashCacheDriver: CacheDriver;
21
- /** The same driver for plain HTTP, which is what the local proxy speaks. */
22
- export declare const upstashInsecureCacheDriver: CacheDriver;
23
- /** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
24
- export interface UpstashAddress {
25
- endpoint: string;
26
- token: string;
27
- }
28
- /**
29
- * Split a cache URL into what the client takes.
30
- *
31
- * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
32
- * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
33
- * else differs.
34
- */
35
- export declare function parseUpstashUrl(url: string): UpstashAddress;
12
+ //# sourceMappingURL=upstash.d.ts.map
13
+
36
14
  //#endregion
15
+ export { UpstashCache };
37
16
  //# sourceMappingURL=upstash.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"mappings":";;qBAIa,wBAAwB;UAC5B;EAER,YAAY,aAAa;EAOnB,IAAI,cAAc;EAUlB,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAa;EAI3C,OAAO,cAAc;;;;;;;;;;;qBAcf,oBAAoB;;qBASpB,4BAA4B;;iBAMxB;EAChB;EACA;;;;;;;;;wBAUe,gBAAgB,cAAc"}
1
+ {"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
package/dist/upstash.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Redis } from "@upstash/redis";
2
+
2
3
  //#region src/upstash.ts
3
4
  var UpstashCache = class {
4
5
  client;
@@ -15,7 +16,7 @@ var UpstashCache = class {
15
16
  }
16
17
  async get(key) {
17
18
  const v = await this.client.get(key);
18
- if (v === null) return;
19
+ if (v === null) return void 0;
19
20
  return v;
20
21
  }
21
22
  async set(key, value, ttl = 3600) {
@@ -25,45 +26,7 @@ var UpstashCache = class {
25
26
  await this.client.del(key);
26
27
  }
27
28
  };
28
- /**
29
- * The `https://` and `http://` driver.
30
- *
31
- * The token travels in the URL's userinfo, because an address and the
32
- * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
33
- * that is Upstash's host over TLS; locally it is the `serverless-redis-http`
34
- * proxy in front of a Redis container, and the client cannot tell the
35
- * difference. That is the whole point of choosing this backend.
36
- */
37
- const upstashCacheDriver = {
38
- scheme: "https:",
39
- create: (url) => {
40
- const { endpoint, token } = parseUpstashUrl(url);
41
- return new UpstashCache(endpoint, token);
42
- }
43
- };
44
- /** The same driver for plain HTTP, which is what the local proxy speaks. */
45
- const upstashInsecureCacheDriver = {
46
- ...upstashCacheDriver,
47
- scheme: "http:"
48
- };
49
- /**
50
- * Split a cache URL into what the client takes.
51
- *
52
- * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
53
- * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
54
- * else differs.
55
- */
56
- function parseUpstashUrl(url) {
57
- const parsed = new URL(url);
58
- const token = decodeURIComponent(parsed.password || parsed.username);
59
- parsed.username = "";
60
- parsed.password = "";
61
- return {
62
- endpoint: parsed.origin,
63
- token
64
- };
65
- }
66
- //#endregion
67
- export { UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
68
29
 
30
+ //#endregion
31
+ export { UpstashCache };
69
32
  //# sourceMappingURL=upstash.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.mjs","names":[],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\nimport type { CacheDriver } from './registry';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n\n/**\n * The `https://` and `http://` driver.\n *\n * The token travels in the URL's userinfo, because an address and the\n * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed\n * that is Upstash's host over TLS; locally it is the `serverless-redis-http`\n * proxy in front of a Redis container, and the client cannot tell the\n * difference. That is the whole point of choosing this backend.\n */\nexport const upstashCacheDriver: CacheDriver = {\n\tscheme: 'https:',\n\tcreate: (url) => {\n\t\tconst { endpoint, token } = parseUpstashUrl(url);\n\t\treturn new UpstashCache(endpoint, token);\n\t},\n};\n\n/** The same driver for plain HTTP, which is what the local proxy speaks. */\nexport const upstashInsecureCacheDriver: CacheDriver = {\n\t...upstashCacheDriver,\n\tscheme: 'http:',\n};\n\n/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */\nexport interface UpstashAddress {\n\tendpoint: string;\n\ttoken: string;\n}\n\n/**\n * Split a cache URL into what the client takes.\n *\n * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',\n * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing\n * else differs.\n */\nexport function parseUpstashUrl(url: string): UpstashAddress {\n\tconst parsed = new URL(url);\n\tconst token = decodeURIComponent(parsed.password || parsed.username);\n\n\tparsed.username = '';\n\tparsed.password = '';\n\n\treturn {\n\t\t// `origin` drops the trailing slash `toString()` would add, which the\n\t\t// client would otherwise send as part of every path.\n\t\tendpoint: parsed.origin,\n\t\ttoken,\n\t};\n}\n"],"mappings":";;AAIA,IAAa,eAAb,MAA2C;CAC1C;CAEA,YAAY,KAAa,OAAe;EACvC,KAAK,SAAS,IAAI,MAAM;GACvB;GACA;EACD,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,GAAG;EAErC,IAAI,QAAQ,IACX,OAAO;EAGR,OAAO;CACR;CAEA,MAAM,IAAO,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,GAAG;EAEnC,IAAI,MAAM,MACT;EAGD,OAAO;CACR;CAEA,MAAM,IAAO,KAAa,OAAU,MAAM,MAAqB;EAC9D,MAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAI,CAAC;CAC9C;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,KAAK,OAAO,IAAI,GAAG;CAC1B;AACD;;;;;;;;;;AAWA,MAAa,qBAAkC;CAC9C,QAAQ;CACR,SAAS,QAAQ;EAChB,MAAM,EAAE,UAAU,UAAU,gBAAgB,GAAG;EAC/C,OAAO,IAAI,aAAa,UAAU,KAAK;CACxC;AACD;;AAGA,MAAa,6BAA0C;CACtD,GAAG;CACH,QAAQ;AACT;;;;;;;;AAeA,SAAgB,gBAAgB,KAA6B;CAC5D,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,QAAQ,mBAAmB,OAAO,YAAY,OAAO,QAAQ;CAEnE,OAAO,WAAW;CAClB,OAAO,WAAW;CAElB,OAAO;EAGN,UAAU,OAAO;EACjB;CACD;AACD"}
1
+ {"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAI,MAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/cache",
3
- "version": "10.0.0-alpha.99",
3
+ "version": "10.0.0",
4
4
  "description": "Unified cache interface with multiple storage implementations",
5
5
  "private": false,
6
6
  "type": "module",
@@ -35,26 +35,6 @@
35
35
  "default": "./dist/upstash.cjs"
36
36
  }
37
37
  },
38
- "./redis": {
39
- "import": {
40
- "types": "./dist/redis.d.mts",
41
- "default": "./dist/redis.mjs"
42
- },
43
- "require": {
44
- "types": "./dist/redis.d.cts",
45
- "default": "./dist/redis.cjs"
46
- }
47
- },
48
- "./postgres": {
49
- "import": {
50
- "types": "./dist/postgres.d.mts",
51
- "default": "./dist/postgres.mjs"
52
- },
53
- "require": {
54
- "types": "./dist/postgres.d.cts",
55
- "default": "./dist/postgres.cjs"
56
- }
57
- },
58
38
  "./expo": {
59
39
  "import": {
60
40
  "types": "./dist/expo.d.mts",
@@ -76,9 +56,6 @@
76
56
  }
77
57
  }
78
58
  },
79
- "files": [
80
- "dist"
81
- ],
82
59
  "repository": {
83
60
  "type": "git",
84
61
  "url": "https://github.com/geekmidas/toolbox"
@@ -88,38 +65,14 @@
88
65
  "access": "public"
89
66
  },
90
67
  "dependencies": {
91
- "@opentelemetry/api": "~1.9.1",
92
- "date-fns": "~4.4.0",
93
- "proper-lockfile": "~4.1.2"
68
+ "date-fns": "~4.1.0",
69
+ "proper-lockfile": "^4.1.2"
94
70
  },
95
71
  "peerDependencies": {
96
- "@upstash/redis": ">=1.39.0",
97
- "expo-secure-store": "^14.2.3",
98
- "ioredis": ">=6.0.0",
99
- "pg": ">=8.23.0"
72
+ "@upstash/redis": "~1.35.1",
73
+ "expo-secure-store": "^14.2.3"
100
74
  },
101
75
  "devDependencies": {
102
- "@opentelemetry/sdk-trace-node": "~2.11.0",
103
- "@types/pg": "~8.23.1",
104
- "@types/proper-lockfile": "~4.1.4",
105
- "ioredis": "~6.0.0",
106
- "pg": "~8.23.0"
107
- },
108
- "peerDependenciesMeta": {
109
- "@upstash/redis": {
110
- "optional": true
111
- },
112
- "expo-secure-store": {
113
- "optional": true
114
- },
115
- "ioredis": {
116
- "optional": true
117
- },
118
- "pg": {
119
- "optional": true
120
- }
121
- },
122
- "scripts": {
123
- "build": "tsdown --config ../../tsdown.config.ts --filter ."
76
+ "@types/proper-lockfile": "^4.1.4"
124
77
  }
125
78
  }
@@ -0,0 +1,51 @@
1
+ import { bench, describe } from 'vitest';
2
+ import { InMemoryCache } from '../memory';
3
+
4
+ describe('InMemoryCache', () => {
5
+ const cache = new InMemoryCache();
6
+
7
+ bench('set with TTL', async () => {
8
+ await cache.set('key', 'value', 3600);
9
+ });
10
+
11
+ bench('get (cache hit)', async () => {
12
+ await cache.set('hit-key', 'value', 3600);
13
+ await cache.get('hit-key');
14
+ });
15
+
16
+ bench('get (cache miss)', async () => {
17
+ await cache.get('nonexistent-key');
18
+ });
19
+
20
+ bench('delete', async () => {
21
+ await cache.set('delete-key', 'value', 3600);
22
+ await cache.delete('delete-key');
23
+ });
24
+
25
+ bench('set + get cycle', async () => {
26
+ const key = `cycle-${Math.random()}`;
27
+ await cache.set(key, 'value', 3600);
28
+ await cache.get(key);
29
+ });
30
+ });
31
+
32
+ describe('InMemoryCache - Large Scale', () => {
33
+ bench('1000 sequential sets', async () => {
34
+ const cache = new InMemoryCache();
35
+ for (let i = 0; i < 1000; i++) {
36
+ await cache.set(`key-${i}`, `value-${i}`, 3600);
37
+ }
38
+ });
39
+
40
+ bench('1000 sequential gets', async () => {
41
+ const cache = new InMemoryCache();
42
+ // Pre-populate
43
+ for (let i = 0; i < 1000; i++) {
44
+ await cache.set(`key-${i}`, `value-${i}`, 3600);
45
+ }
46
+ // Benchmark gets
47
+ for (let i = 0; i < 1000; i++) {
48
+ await cache.get(`key-${i}`);
49
+ }
50
+ });
51
+ });