@geekmidas/cache 0.0.4 → 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.
- package/dist/__tests__/cache.spec.cjs +30 -31
- package/dist/__tests__/cache.spec.mjs +18 -18
- package/dist/__tests__/integration.spec.cjs +44 -45
- package/dist/__tests__/integration.spec.mjs +26 -26
- package/dist/__tests__/memory.spec.cjs +44 -45
- package/dist/__tests__/memory.spec.mjs +23 -23
- package/dist/__tests__/upstash.spec.cjs +50 -51
- package/dist/__tests__/upstash.spec.mjs +23 -23
- package/dist/{chunk-CUT6urMc.cjs → chunk-DWy1uDak.cjs} +9 -0
- package/dist/expo.cjs +36 -0
- package/dist/expo.d.cts +12 -0
- package/dist/expo.d.mts +12 -0
- package/dist/expo.mjs +35 -0
- package/dist/index.d.mts +1 -1
- package/dist/magic-string.es-BvJNBYzY.mjs +1014 -0
- package/dist/magic-string.es-CKiDiYoS.cjs +1015 -0
- package/dist/memory.d.mts +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/{upstash-0RolGx7m.cjs → upstash-DiFDpOHy.cjs} +1 -1
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.d.mts +1 -1
- package/dist/upstash.mjs +1 -1
- package/dist/vi.bdSIJ99Y-CKSnd2bq.cjs +14955 -0
- package/dist/vi.bdSIJ99Y-DffpE2Zw.mjs +14951 -0
- package/package.json +11 -3
- package/src/expo.ts +53 -0
- package/tsdown.config.ts +5 -0
- /package/dist/{index-BPnJ3lrS.d.mts → index-CVen_7Cc.d.mts} +0 -0
- /package/dist/{memory-NQi0XmZ2.mjs → memory-YteQXj7m.mjs} +0 -0
- /package/dist/{upstash-CTY-M8vR.mjs → upstash-_05vyc5o.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-DffpE2Zw.mjs";
|
|
2
|
+
import { UpstashCache } from "../upstash-_05vyc5o.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/__tests__/upstash.spec.ts
|
|
5
5
|
describe("UpstashCache", () => {
|
|
@@ -24,7 +24,7 @@ describe("UpstashCache", () => {
|
|
|
24
24
|
it("should return undefined for non-existent key", async () => {
|
|
25
25
|
const key = getTestKey("non-existent");
|
|
26
26
|
const result = await cache.get(key);
|
|
27
|
-
|
|
27
|
+
globalExpect(result).toBeUndefined();
|
|
28
28
|
});
|
|
29
29
|
it("should parse and return JSON value", async () => {
|
|
30
30
|
const key = getTestKey("object");
|
|
@@ -34,28 +34,28 @@ describe("UpstashCache", () => {
|
|
|
34
34
|
};
|
|
35
35
|
await cache.set(key, testValue);
|
|
36
36
|
const result = await cache.get(key);
|
|
37
|
-
|
|
37
|
+
globalExpect(result).toEqual(testValue);
|
|
38
38
|
});
|
|
39
39
|
it("should handle string values", async () => {
|
|
40
40
|
const key = getTestKey("string");
|
|
41
41
|
const testValue = "simple string";
|
|
42
42
|
await cache.set(key, testValue);
|
|
43
43
|
const result = await cache.get(key);
|
|
44
|
-
|
|
44
|
+
globalExpect(result).toBe(testValue);
|
|
45
45
|
});
|
|
46
46
|
it("should handle number values", async () => {
|
|
47
47
|
const key = getTestKey("number");
|
|
48
48
|
const testValue = 42;
|
|
49
49
|
await cache.set(key, testValue);
|
|
50
50
|
const result = await cache.get(key);
|
|
51
|
-
|
|
51
|
+
globalExpect(result).toBe(testValue);
|
|
52
52
|
});
|
|
53
53
|
it("should handle boolean values", async () => {
|
|
54
54
|
const key = getTestKey("boolean");
|
|
55
55
|
const testValue = true;
|
|
56
56
|
await cache.set(key, testValue);
|
|
57
57
|
const result = await cache.get(key);
|
|
58
|
-
|
|
58
|
+
globalExpect(result).toBe(testValue);
|
|
59
59
|
});
|
|
60
60
|
it("should handle array values", async () => {
|
|
61
61
|
const key = getTestKey("array");
|
|
@@ -67,13 +67,13 @@ describe("UpstashCache", () => {
|
|
|
67
67
|
];
|
|
68
68
|
await cache.set(key, testArray);
|
|
69
69
|
const result = await cache.get(key);
|
|
70
|
-
|
|
70
|
+
globalExpect(result).toEqual(testArray);
|
|
71
71
|
});
|
|
72
72
|
it("should handle null values as undefined", async () => {
|
|
73
73
|
const key = getTestKey("null");
|
|
74
74
|
await cache.set(key, null);
|
|
75
75
|
const result = await cache.get(key);
|
|
76
|
-
|
|
76
|
+
globalExpect(result).toBeUndefined();
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
describe("set", () => {
|
|
@@ -85,28 +85,28 @@ describe("UpstashCache", () => {
|
|
|
85
85
|
};
|
|
86
86
|
await cache.set(key, testValue);
|
|
87
87
|
const result = await cache.get(key);
|
|
88
|
-
|
|
88
|
+
globalExpect(result).toEqual(testValue);
|
|
89
89
|
});
|
|
90
90
|
it("should store and retrieve string values", async () => {
|
|
91
91
|
const key = getTestKey("set-string");
|
|
92
92
|
const testValue = "test string";
|
|
93
93
|
await cache.set(key, testValue);
|
|
94
94
|
const result = await cache.get(key);
|
|
95
|
-
|
|
95
|
+
globalExpect(result).toBe(testValue);
|
|
96
96
|
});
|
|
97
97
|
it("should store and retrieve number values", async () => {
|
|
98
98
|
const key = getTestKey("set-number");
|
|
99
99
|
const testValue = 42;
|
|
100
100
|
await cache.set(key, testValue);
|
|
101
101
|
const result = await cache.get(key);
|
|
102
|
-
|
|
102
|
+
globalExpect(result).toBe(testValue);
|
|
103
103
|
});
|
|
104
104
|
it("should store and retrieve boolean values", async () => {
|
|
105
105
|
const key = getTestKey("set-boolean");
|
|
106
106
|
const testValue = true;
|
|
107
107
|
await cache.set(key, testValue);
|
|
108
108
|
const result = await cache.get(key);
|
|
109
|
-
|
|
109
|
+
globalExpect(result).toBe(testValue);
|
|
110
110
|
});
|
|
111
111
|
it("should store and retrieve array values", async () => {
|
|
112
112
|
const key = getTestKey("set-array");
|
|
@@ -117,20 +117,20 @@ describe("UpstashCache", () => {
|
|
|
117
117
|
];
|
|
118
118
|
await cache.set(key, testArray);
|
|
119
119
|
const result = await cache.get(key);
|
|
120
|
-
|
|
120
|
+
globalExpect(result).toEqual(testArray);
|
|
121
121
|
});
|
|
122
122
|
it("should not store and retrieve null values", async () => {
|
|
123
123
|
const key = getTestKey("set-null");
|
|
124
124
|
await cache.set(key, null);
|
|
125
125
|
const result = await cache.get(key);
|
|
126
|
-
|
|
126
|
+
globalExpect(result).toBeUndefined();
|
|
127
127
|
});
|
|
128
128
|
it("should overwrite existing values", async () => {
|
|
129
129
|
const key = getTestKey("overwrite");
|
|
130
130
|
await cache.set(key, "initial");
|
|
131
131
|
await cache.set(key, "updated");
|
|
132
132
|
const result = await cache.get(key);
|
|
133
|
-
|
|
133
|
+
globalExpect(result).toBe("updated");
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
describe("delete", () => {
|
|
@@ -139,11 +139,11 @@ describe("UpstashCache", () => {
|
|
|
139
139
|
await cache.set(key, "value-to-delete");
|
|
140
140
|
await cache.delete(key);
|
|
141
141
|
const result = await cache.get(key);
|
|
142
|
-
|
|
142
|
+
globalExpect(result).toBeUndefined();
|
|
143
143
|
});
|
|
144
144
|
it("should handle deletion of non-existent key", async () => {
|
|
145
145
|
const key = getTestKey("non-existent-delete");
|
|
146
|
-
await
|
|
146
|
+
await globalExpect(cache.delete(key)).resolves.not.toThrow();
|
|
147
147
|
});
|
|
148
148
|
it("should only delete specified key", async () => {
|
|
149
149
|
const key1 = getTestKey("delete-key1");
|
|
@@ -151,8 +151,8 @@ describe("UpstashCache", () => {
|
|
|
151
151
|
await cache.set(key1, "value1");
|
|
152
152
|
await cache.set(key2, "value2");
|
|
153
153
|
await cache.delete(key1);
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
globalExpect(await cache.get(key1)).toBeUndefined();
|
|
155
|
+
globalExpect(await cache.get(key2)).toBe("value2");
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
describe("integration scenarios", () => {
|
|
@@ -168,7 +168,7 @@ describe("UpstashCache", () => {
|
|
|
168
168
|
};
|
|
169
169
|
await cache.set(key, testData);
|
|
170
170
|
const result = await cache.get(key);
|
|
171
|
-
|
|
171
|
+
globalExpect(result).toEqual(testData);
|
|
172
172
|
});
|
|
173
173
|
it("should handle complex nested objects", async () => {
|
|
174
174
|
const key = getTestKey("complex");
|
|
@@ -178,7 +178,7 @@ describe("UpstashCache", () => {
|
|
|
178
178
|
} } } };
|
|
179
179
|
await cache.set(key, complexObject);
|
|
180
180
|
const result = await cache.get(key);
|
|
181
|
-
|
|
181
|
+
globalExpect(result).toEqual(complexObject);
|
|
182
182
|
});
|
|
183
183
|
it("should handle concurrent operations", async () => {
|
|
184
184
|
const keys = [
|
|
@@ -193,7 +193,7 @@ describe("UpstashCache", () => {
|
|
|
193
193
|
];
|
|
194
194
|
await Promise.all(keys.map((key, i) => cache.set(key, values[i])));
|
|
195
195
|
const results = await Promise.all(keys.map((key) => cache.get(key)));
|
|
196
|
-
|
|
196
|
+
globalExpect(results).toEqual(values);
|
|
197
197
|
});
|
|
198
198
|
});
|
|
199
199
|
});
|
|
@@ -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;
|
package/dist/expo.d.cts
ADDED
|
@@ -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 };
|
package/dist/expo.d.mts
ADDED
|
@@ -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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-CVen_7Cc.mjs";
|
|
2
2
|
export { Cache };
|