@geekmidas/cache 0.0.3 → 0.0.5

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 (37) hide show
  1. package/README.md +512 -0
  2. package/dist/__tests__/cache.spec.cjs +30 -30
  3. package/dist/__tests__/cache.spec.d.cts +1 -0
  4. package/dist/__tests__/cache.spec.d.mts +1 -0
  5. package/dist/__tests__/cache.spec.mjs +1 -1
  6. package/dist/__tests__/integration.spec.cjs +44 -44
  7. package/dist/__tests__/integration.spec.d.cts +1 -0
  8. package/dist/__tests__/integration.spec.d.mts +1 -0
  9. package/dist/__tests__/integration.spec.mjs +1 -1
  10. package/dist/__tests__/memory.spec.cjs +44 -44
  11. package/dist/__tests__/memory.spec.d.cts +1 -0
  12. package/dist/__tests__/memory.spec.d.mts +1 -0
  13. package/dist/__tests__/memory.spec.mjs +1 -1
  14. package/dist/__tests__/upstash.spec.cjs +50 -50
  15. package/dist/__tests__/upstash.spec.d.cts +1 -0
  16. package/dist/__tests__/upstash.spec.d.mts +1 -0
  17. package/dist/__tests__/upstash.spec.mjs +1 -1
  18. package/dist/{chunk-CUT6urMc.cjs → chunk-DWy1uDak.cjs} +9 -0
  19. package/dist/expo.cjs +36 -0
  20. package/dist/expo.d.cts +12 -0
  21. package/dist/expo.d.mts +12 -0
  22. package/dist/expo.mjs +35 -0
  23. package/dist/index-CVen_7Cc.d.mts +25 -0
  24. package/dist/index-q3xYn8_0.d.cts +25 -0
  25. package/dist/index.d.cts +2 -0
  26. package/dist/index.d.mts +2 -0
  27. package/dist/memory.d.cts +11 -0
  28. package/dist/memory.d.mts +11 -0
  29. package/dist/{upstash-0RolGx7m.cjs → upstash-DiFDpOHy.cjs} +1 -1
  30. package/dist/upstash.cjs +1 -1
  31. package/dist/upstash.d.cts +12 -0
  32. package/dist/upstash.d.mts +12 -0
  33. package/dist/{vi.DgezovHB-McgltIC5.mjs → vi.bdSIJ99Y-CKSnd2bq.cjs} +3294 -1418
  34. package/dist/{vi.DgezovHB-NqP74KGR.cjs → vi.bdSIJ99Y-DffpE2Zw.mjs} +3255 -1408
  35. package/package.json +17 -9
  36. package/src/expo.ts +53 -0
  37. package/tsdown.config.ts +5 -0
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.DgezovHB-McgltIC5.mjs";
1
+ import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-DffpE2Zw.mjs";
2
2
  import { UpstashCache } from "../upstash-_05vyc5o.mjs";
3
3
 
4
4
  //#region src/__tests__/upstash.spec.ts
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
8
11
  var __copyProps = (to, from, except, desc) => {
9
12
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
13
  key = keys[i];
@@ -22,6 +25,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
25
 
23
26
  //#endregion
24
27
 
28
+ Object.defineProperty(exports, '__commonJS', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return __commonJS;
32
+ }
33
+ });
25
34
  Object.defineProperty(exports, '__toESM', {
26
35
  enumerable: true,
27
36
  get: function () {
package/dist/expo.cjs ADDED
@@ -0,0 +1,36 @@
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const date_fns = require_chunk.__toESM(require("date-fns"));
3
+ const expo_secure_store = require_chunk.__toESM(require("expo-secure-store"));
4
+
5
+ //#region src/expo.ts
6
+ var ExpoSecureCache = class ExpoSecureCache {
7
+ static getExpiryKey(key) {
8
+ return `${key}:expiresAt`;
9
+ }
10
+ async getExpiration(key) {
11
+ const result = await expo_secure_store.getItemAsync(ExpoSecureCache.getExpiryKey(key));
12
+ if (!result) return 0;
13
+ const date = new Date(JSON.parse(result));
14
+ const secondsLeft = (0, date_fns.differenceInSeconds)(date, /* @__PURE__ */ new Date());
15
+ return Math.max(secondsLeft, 0);
16
+ }
17
+ async get(key) {
18
+ const result = await expo_secure_store.getItemAsync(key);
19
+ if (!result) return void 0;
20
+ const expiresAt = await this.getExpiration(key);
21
+ if (expiresAt === 0) return void 0;
22
+ return JSON.parse(result);
23
+ }
24
+ async set(key, value, ttl) {
25
+ const expiresAt = ttl ? Date.now() + ttl * 1e3 : 0;
26
+ await expo_secure_store.setItemAsync(key, JSON.stringify(value));
27
+ await expo_secure_store.setItemAsync(ExpoSecureCache.getExpiryKey(key), JSON.stringify(expiresAt));
28
+ }
29
+ async delete(key) {
30
+ await expo_secure_store.deleteItemAsync(key);
31
+ await expo_secure_store.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
32
+ }
33
+ };
34
+
35
+ //#endregion
36
+ exports.ExpoSecureCache = ExpoSecureCache;
@@ -0,0 +1,12 @@
1
+ import { Cache } from "./index-q3xYn8_0.cjs";
2
+
3
+ //#region src/expo.d.ts
4
+ declare class ExpoSecureCache<T> implements Cache<T> {
5
+ static getExpiryKey(key: string): string;
6
+ private getExpiration;
7
+ get(key: string): Promise<T | undefined>;
8
+ set(key: string, value: T, ttl?: number): Promise<void>;
9
+ delete(key: string): Promise<void>;
10
+ }
11
+ //#endregion
12
+ export { ExpoSecureCache };
@@ -0,0 +1,12 @@
1
+ import { Cache } from "./index-CVen_7Cc.mjs";
2
+
3
+ //#region src/expo.d.ts
4
+ declare class ExpoSecureCache<T> implements Cache<T> {
5
+ static getExpiryKey(key: string): string;
6
+ private getExpiration;
7
+ get(key: string): Promise<T | undefined>;
8
+ set(key: string, value: T, ttl?: number): Promise<void>;
9
+ delete(key: string): Promise<void>;
10
+ }
11
+ //#endregion
12
+ export { ExpoSecureCache };
package/dist/expo.mjs ADDED
@@ -0,0 +1,35 @@
1
+ import { differenceInSeconds } from "date-fns";
2
+ import * as SecureStore from "expo-secure-store";
3
+
4
+ //#region src/expo.ts
5
+ var ExpoSecureCache = class ExpoSecureCache {
6
+ static getExpiryKey(key) {
7
+ return `${key}:expiresAt`;
8
+ }
9
+ async getExpiration(key) {
10
+ const result = await SecureStore.getItemAsync(ExpoSecureCache.getExpiryKey(key));
11
+ if (!result) return 0;
12
+ const date = new Date(JSON.parse(result));
13
+ const secondsLeft = differenceInSeconds(date, /* @__PURE__ */ new Date());
14
+ return Math.max(secondsLeft, 0);
15
+ }
16
+ async get(key) {
17
+ const result = await SecureStore.getItemAsync(key);
18
+ if (!result) return void 0;
19
+ const expiresAt = await this.getExpiration(key);
20
+ if (expiresAt === 0) return void 0;
21
+ return JSON.parse(result);
22
+ }
23
+ async set(key, value, ttl) {
24
+ const expiresAt = ttl ? Date.now() + ttl * 1e3 : 0;
25
+ await SecureStore.setItemAsync(key, JSON.stringify(value));
26
+ await SecureStore.setItemAsync(ExpoSecureCache.getExpiryKey(key), JSON.stringify(expiresAt));
27
+ }
28
+ async delete(key) {
29
+ await SecureStore.deleteItemAsync(key);
30
+ await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { ExpoSecureCache };
@@ -0,0 +1,25 @@
1
+ //#region src/index.d.ts
2
+ interface Cache<T> {
3
+ /**
4
+ * Retrieves a value from the cache.
5
+ *
6
+ * @param key The key to retrieve the value for.
7
+ */
8
+ get(key: string): Promise<T | undefined>;
9
+ /**
10
+ * Sets a value in the cache.
11
+ *
12
+ * @param key The key to set the value for.
13
+ * @param value The value to cache.
14
+ * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
15
+ */
16
+ set(key: string, value: T, ttl?: number): Promise<void>;
17
+ /**
18
+ * Deletes a value from the cache.
19
+ *
20
+ * @param key The key to delete from the cache.
21
+ */
22
+ delete(key: string): Promise<void>;
23
+ }
24
+ //#endregion
25
+ export { Cache };
@@ -0,0 +1,25 @@
1
+ //#region src/index.d.ts
2
+ interface Cache<T> {
3
+ /**
4
+ * Retrieves a value from the cache.
5
+ *
6
+ * @param key The key to retrieve the value for.
7
+ */
8
+ get(key: string): Promise<T | undefined>;
9
+ /**
10
+ * Sets a value in the cache.
11
+ *
12
+ * @param key The key to set the value for.
13
+ * @param value The value to cache.
14
+ * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
15
+ */
16
+ set(key: string, value: T, ttl?: number): Promise<void>;
17
+ /**
18
+ * Deletes a value from the cache.
19
+ *
20
+ * @param key The key to delete from the cache.
21
+ */
22
+ delete(key: string): Promise<void>;
23
+ }
24
+ //#endregion
25
+ export { Cache };
@@ -0,0 +1,2 @@
1
+ import { Cache } from "./index-q3xYn8_0.cjs";
2
+ export { Cache };
@@ -0,0 +1,2 @@
1
+ import { Cache } from "./index-CVen_7Cc.mjs";
2
+ export { Cache };
@@ -0,0 +1,11 @@
1
+ import { Cache } from "./index-q3xYn8_0.cjs";
2
+
3
+ //#region src/memory.d.ts
4
+ declare class InMemoryCache<T> implements Cache<T> {
5
+ private store;
6
+ get(key: string): Promise<T | undefined>;
7
+ set(key: string, value: T): Promise<void>;
8
+ delete(key: string): Promise<void>;
9
+ }
10
+ //#endregion
11
+ export { InMemoryCache };
@@ -0,0 +1,11 @@
1
+ import { Cache } from "./index-CVen_7Cc.mjs";
2
+
3
+ //#region src/memory.d.ts
4
+ declare class InMemoryCache<T> implements Cache<T> {
5
+ private store;
6
+ get(key: string): Promise<T | undefined>;
7
+ set(key: string, value: T): Promise<void>;
8
+ delete(key: string): Promise<void>;
9
+ }
10
+ //#endregion
11
+ export { InMemoryCache };
@@ -1,4 +1,4 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
2
  const __upstash_redis = require_chunk.__toESM(require("@upstash/redis"));
3
3
 
4
4
  //#region src/upstash.ts
package/dist/upstash.cjs CHANGED
@@ -1,3 +1,3 @@
1
- const require_upstash = require('./upstash-0RolGx7m.cjs');
1
+ const require_upstash = require('./upstash-DiFDpOHy.cjs');
2
2
 
3
3
  exports.UpstashCache = require_upstash.UpstashCache;
@@ -0,0 +1,12 @@
1
+ import { Cache } from "./index-q3xYn8_0.cjs";
2
+
3
+ //#region src/upstash.d.ts
4
+ declare class UpstashCache<T> implements Cache<T> {
5
+ private client;
6
+ constructor(url: string, token: string);
7
+ get(key: string): Promise<T | undefined>;
8
+ set(key: string, value: T, ttl?: number): Promise<void>;
9
+ delete(key: string): Promise<void>;
10
+ }
11
+ //#endregion
12
+ export { UpstashCache };
@@ -0,0 +1,12 @@
1
+ import { Cache } from "./index-CVen_7Cc.mjs";
2
+
3
+ //#region src/upstash.d.ts
4
+ declare class UpstashCache<T> implements Cache<T> {
5
+ private client;
6
+ constructor(url: string, token: string);
7
+ get(key: string): Promise<T | undefined>;
8
+ set(key: string, value: T, ttl?: number): Promise<void>;
9
+ delete(key: string): Promise<void>;
10
+ }
11
+ //#endregion
12
+ export { UpstashCache };