@geekmidas/cache 0.0.3 → 0.0.4
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/README.md +512 -0
- package/dist/__tests__/cache.spec.cjs +30 -29
- package/dist/__tests__/cache.spec.d.cts +1 -0
- package/dist/__tests__/cache.spec.d.mts +1 -0
- package/dist/__tests__/cache.spec.mjs +18 -18
- package/dist/__tests__/integration.spec.cjs +45 -44
- package/dist/__tests__/integration.spec.d.cts +1 -0
- package/dist/__tests__/integration.spec.d.mts +1 -0
- package/dist/__tests__/integration.spec.mjs +26 -26
- package/dist/__tests__/memory.spec.cjs +45 -44
- package/dist/__tests__/memory.spec.d.cts +1 -0
- package/dist/__tests__/memory.spec.d.mts +1 -0
- package/dist/__tests__/memory.spec.mjs +23 -23
- package/dist/__tests__/upstash.spec.cjs +50 -49
- package/dist/__tests__/upstash.spec.d.cts +1 -0
- package/dist/__tests__/upstash.spec.d.mts +1 -0
- package/dist/__tests__/upstash.spec.mjs +23 -23
- package/dist/index-BPnJ3lrS.d.mts +25 -0
- package/dist/index-q3xYn8_0.d.cts +25 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/memory.d.cts +11 -0
- package/dist/memory.d.mts +11 -0
- package/dist/memory.mjs +1 -1
- package/dist/upstash.d.cts +12 -0
- package/dist/upstash.d.mts +12 -0
- package/dist/upstash.mjs +1 -1
- package/package.json +7 -7
- package/dist/magic-string.es-BvJNBYzY.mjs +0 -1014
- package/dist/magic-string.es-CKiDiYoS.cjs +0 -1015
- package/dist/vi.DgezovHB-McgltIC5.mjs +0 -13079
- package/dist/vi.DgezovHB-NqP74KGR.cjs +0 -13104
- /package/dist/{memory-YteQXj7m.mjs → memory-NQi0XmZ2.mjs} +0 -0
- /package/dist/{upstash-_05vyc5o.mjs → upstash-CTY-M8vR.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { InMemoryCache } from "../memory-NQi0XmZ2.mjs";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
|
|
4
4
|
//#region src/__tests__/memory.spec.ts
|
|
5
5
|
describe("InMemoryCache", () => {
|
|
@@ -10,12 +10,12 @@ describe("InMemoryCache", () => {
|
|
|
10
10
|
describe("get", () => {
|
|
11
11
|
it("should return undefined for non-existent key", async () => {
|
|
12
12
|
const result = await cache.get("non-existent");
|
|
13
|
-
|
|
13
|
+
expect(result).toBeUndefined();
|
|
14
14
|
});
|
|
15
15
|
it("should return value for existing key", async () => {
|
|
16
16
|
await cache.set("test-key", "test-value");
|
|
17
17
|
const result = await cache.get("test-key");
|
|
18
|
-
|
|
18
|
+
expect(result).toBe("test-value");
|
|
19
19
|
});
|
|
20
20
|
it("should handle different data types", async () => {
|
|
21
21
|
const objectValue = {
|
|
@@ -33,17 +33,17 @@ describe("InMemoryCache", () => {
|
|
|
33
33
|
await cache.set("array", arrayValue);
|
|
34
34
|
await cache.set("number", numberValue);
|
|
35
35
|
await cache.set("boolean", booleanValue);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
expect(await cache.get("object")).toEqual(objectValue);
|
|
37
|
+
expect(await cache.get("array")).toEqual(arrayValue);
|
|
38
|
+
expect(await cache.get("number")).toBe(numberValue);
|
|
39
|
+
expect(await cache.get("boolean")).toBe(booleanValue);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
describe("set", () => {
|
|
43
43
|
it("should store string value", async () => {
|
|
44
44
|
await cache.set("string-key", "string-value");
|
|
45
45
|
const result = await cache.get("string-key");
|
|
46
|
-
|
|
46
|
+
expect(result).toBe("string-value");
|
|
47
47
|
});
|
|
48
48
|
it("should store object value", async () => {
|
|
49
49
|
const value = {
|
|
@@ -52,18 +52,18 @@ describe("InMemoryCache", () => {
|
|
|
52
52
|
};
|
|
53
53
|
await cache.set("object-key", value);
|
|
54
54
|
const result = await cache.get("object-key");
|
|
55
|
-
|
|
55
|
+
expect(result).toEqual(value);
|
|
56
56
|
});
|
|
57
57
|
it("should overwrite existing value", async () => {
|
|
58
58
|
await cache.set("key", "initial-value");
|
|
59
59
|
await cache.set("key", "updated-value");
|
|
60
60
|
const result = await cache.get("key");
|
|
61
|
-
|
|
61
|
+
expect(result).toBe("updated-value");
|
|
62
62
|
});
|
|
63
63
|
it("should handle null values", async () => {
|
|
64
64
|
await cache.set("null-key", null);
|
|
65
65
|
const result = await cache.get("null-key");
|
|
66
|
-
|
|
66
|
+
expect(result).toBeNull();
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
describe("delete", () => {
|
|
@@ -71,17 +71,17 @@ describe("InMemoryCache", () => {
|
|
|
71
71
|
await cache.set("to-delete", "value");
|
|
72
72
|
await cache.delete("to-delete");
|
|
73
73
|
const result = await cache.get("to-delete");
|
|
74
|
-
|
|
74
|
+
expect(result).toBeUndefined();
|
|
75
75
|
});
|
|
76
76
|
it("should not throw error for non-existent key", async () => {
|
|
77
|
-
await
|
|
77
|
+
await expect(cache.delete("non-existent")).resolves.not.toThrow();
|
|
78
78
|
});
|
|
79
79
|
it("should only delete specified key", async () => {
|
|
80
80
|
await cache.set("key1", "value1");
|
|
81
81
|
await cache.set("key2", "value2");
|
|
82
82
|
await cache.delete("key1");
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
expect(await cache.get("key1")).toBeUndefined();
|
|
84
|
+
expect(await cache.get("key2")).toBe("value2");
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
describe("multiple operations", () => {
|
|
@@ -89,9 +89,9 @@ describe("InMemoryCache", () => {
|
|
|
89
89
|
await cache.set("key1", "value1");
|
|
90
90
|
await cache.set("key2", "value2");
|
|
91
91
|
await cache.set("key3", "value3");
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
expect(await cache.get("key1")).toBe("value1");
|
|
93
|
+
expect(await cache.get("key2")).toBe("value2");
|
|
94
|
+
expect(await cache.get("key3")).toBe("value3");
|
|
95
95
|
});
|
|
96
96
|
it("should maintain data integrity across operations", async () => {
|
|
97
97
|
const data = { count: 0 };
|
|
@@ -99,25 +99,25 @@ describe("InMemoryCache", () => {
|
|
|
99
99
|
const retrieved = await cache.get("counter");
|
|
100
100
|
retrieved.count = 5;
|
|
101
101
|
const original = await cache.get("counter");
|
|
102
|
-
|
|
102
|
+
expect(original.count).toBe(5);
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
describe("edge cases", () => {
|
|
106
106
|
it("should handle empty string as key", async () => {
|
|
107
107
|
await cache.set("", "empty-key-value");
|
|
108
108
|
const result = await cache.get("");
|
|
109
|
-
|
|
109
|
+
expect(result).toBe("empty-key-value");
|
|
110
110
|
});
|
|
111
111
|
it("should handle special characters in keys", async () => {
|
|
112
112
|
const specialKey = "key!@#$%^&*()_+{}|:\"<>?[]\\;',./?`~";
|
|
113
113
|
await cache.set(specialKey, "special-value");
|
|
114
114
|
const result = await cache.get(specialKey);
|
|
115
|
-
|
|
115
|
+
expect(result).toBe("special-value");
|
|
116
116
|
});
|
|
117
117
|
it("should handle undefined values", async () => {
|
|
118
118
|
await cache.set("undefined-key", void 0);
|
|
119
119
|
const result = await cache.get("undefined-key");
|
|
120
|
-
|
|
120
|
+
expect(result).toBeUndefined();
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
123
|
});
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
1
2
|
const require_upstash = require('../upstash-0RolGx7m.cjs');
|
|
2
|
-
const
|
|
3
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
3
4
|
|
|
4
5
|
//#region src/__tests__/upstash.spec.ts
|
|
5
|
-
|
|
6
|
+
(0, vitest.describe)("UpstashCache", () => {
|
|
6
7
|
let cache;
|
|
7
8
|
const testKeyPrefix = `test:${Date.now()}:`;
|
|
8
9
|
let testKeys = [];
|
|
9
|
-
|
|
10
|
+
(0, vitest.beforeEach)(() => {
|
|
10
11
|
cache = new require_upstash.UpstashCache("http://localhost:8079", "example_token");
|
|
11
12
|
testKeys = [];
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
+
(0, vitest.afterEach)(async () => {
|
|
14
15
|
for (const key of testKeys) try {
|
|
15
16
|
await cache.delete(key);
|
|
16
17
|
} catch (error) {}
|
|
@@ -20,13 +21,13 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
20
21
|
testKeys.push(key);
|
|
21
22
|
return key;
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
(0, vitest.describe)("get", () => {
|
|
25
|
+
(0, vitest.it)("should return undefined for non-existent key", async () => {
|
|
25
26
|
const key = getTestKey("non-existent");
|
|
26
27
|
const result = await cache.get(key);
|
|
27
|
-
|
|
28
|
+
(0, vitest.expect)(result).toBeUndefined();
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
+
(0, vitest.it)("should parse and return JSON value", async () => {
|
|
30
31
|
const key = getTestKey("object");
|
|
31
32
|
const testValue = {
|
|
32
33
|
id: 1,
|
|
@@ -34,30 +35,30 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
34
35
|
};
|
|
35
36
|
await cache.set(key, testValue);
|
|
36
37
|
const result = await cache.get(key);
|
|
37
|
-
|
|
38
|
+
(0, vitest.expect)(result).toEqual(testValue);
|
|
38
39
|
});
|
|
39
|
-
|
|
40
|
+
(0, vitest.it)("should handle string values", async () => {
|
|
40
41
|
const key = getTestKey("string");
|
|
41
42
|
const testValue = "simple string";
|
|
42
43
|
await cache.set(key, testValue);
|
|
43
44
|
const result = await cache.get(key);
|
|
44
|
-
|
|
45
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
+
(0, vitest.it)("should handle number values", async () => {
|
|
47
48
|
const key = getTestKey("number");
|
|
48
49
|
const testValue = 42;
|
|
49
50
|
await cache.set(key, testValue);
|
|
50
51
|
const result = await cache.get(key);
|
|
51
|
-
|
|
52
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
52
53
|
});
|
|
53
|
-
|
|
54
|
+
(0, vitest.it)("should handle boolean values", async () => {
|
|
54
55
|
const key = getTestKey("boolean");
|
|
55
56
|
const testValue = true;
|
|
56
57
|
await cache.set(key, testValue);
|
|
57
58
|
const result = await cache.get(key);
|
|
58
|
-
|
|
59
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
59
60
|
});
|
|
60
|
-
|
|
61
|
+
(0, vitest.it)("should handle array values", async () => {
|
|
61
62
|
const key = getTestKey("array");
|
|
62
63
|
const testArray = [
|
|
63
64
|
1,
|
|
@@ -67,17 +68,17 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
67
68
|
];
|
|
68
69
|
await cache.set(key, testArray);
|
|
69
70
|
const result = await cache.get(key);
|
|
70
|
-
|
|
71
|
+
(0, vitest.expect)(result).toEqual(testArray);
|
|
71
72
|
});
|
|
72
|
-
|
|
73
|
+
(0, vitest.it)("should handle null values as undefined", async () => {
|
|
73
74
|
const key = getTestKey("null");
|
|
74
75
|
await cache.set(key, null);
|
|
75
76
|
const result = await cache.get(key);
|
|
76
|
-
|
|
77
|
+
(0, vitest.expect)(result).toBeUndefined();
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
(0, vitest.describe)("set", () => {
|
|
81
|
+
(0, vitest.it)("should store and retrieve object value", async () => {
|
|
81
82
|
const key = getTestKey("set-object");
|
|
82
83
|
const testValue = {
|
|
83
84
|
id: 1,
|
|
@@ -85,30 +86,30 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
85
86
|
};
|
|
86
87
|
await cache.set(key, testValue);
|
|
87
88
|
const result = await cache.get(key);
|
|
88
|
-
|
|
89
|
+
(0, vitest.expect)(result).toEqual(testValue);
|
|
89
90
|
});
|
|
90
|
-
|
|
91
|
+
(0, vitest.it)("should store and retrieve string values", async () => {
|
|
91
92
|
const key = getTestKey("set-string");
|
|
92
93
|
const testValue = "test string";
|
|
93
94
|
await cache.set(key, testValue);
|
|
94
95
|
const result = await cache.get(key);
|
|
95
|
-
|
|
96
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
96
97
|
});
|
|
97
|
-
|
|
98
|
+
(0, vitest.it)("should store and retrieve number values", async () => {
|
|
98
99
|
const key = getTestKey("set-number");
|
|
99
100
|
const testValue = 42;
|
|
100
101
|
await cache.set(key, testValue);
|
|
101
102
|
const result = await cache.get(key);
|
|
102
|
-
|
|
103
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
103
104
|
});
|
|
104
|
-
|
|
105
|
+
(0, vitest.it)("should store and retrieve boolean values", async () => {
|
|
105
106
|
const key = getTestKey("set-boolean");
|
|
106
107
|
const testValue = true;
|
|
107
108
|
await cache.set(key, testValue);
|
|
108
109
|
const result = await cache.get(key);
|
|
109
|
-
|
|
110
|
+
(0, vitest.expect)(result).toBe(testValue);
|
|
110
111
|
});
|
|
111
|
-
|
|
112
|
+
(0, vitest.it)("should store and retrieve array values", async () => {
|
|
112
113
|
const key = getTestKey("set-array");
|
|
113
114
|
const testArray = [
|
|
114
115
|
1,
|
|
@@ -117,46 +118,46 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
117
118
|
];
|
|
118
119
|
await cache.set(key, testArray);
|
|
119
120
|
const result = await cache.get(key);
|
|
120
|
-
|
|
121
|
+
(0, vitest.expect)(result).toEqual(testArray);
|
|
121
122
|
});
|
|
122
|
-
|
|
123
|
+
(0, vitest.it)("should not store and retrieve null values", async () => {
|
|
123
124
|
const key = getTestKey("set-null");
|
|
124
125
|
await cache.set(key, null);
|
|
125
126
|
const result = await cache.get(key);
|
|
126
|
-
|
|
127
|
+
(0, vitest.expect)(result).toBeUndefined();
|
|
127
128
|
});
|
|
128
|
-
|
|
129
|
+
(0, vitest.it)("should overwrite existing values", async () => {
|
|
129
130
|
const key = getTestKey("overwrite");
|
|
130
131
|
await cache.set(key, "initial");
|
|
131
132
|
await cache.set(key, "updated");
|
|
132
133
|
const result = await cache.get(key);
|
|
133
|
-
|
|
134
|
+
(0, vitest.expect)(result).toBe("updated");
|
|
134
135
|
});
|
|
135
136
|
});
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
(0, vitest.describe)("delete", () => {
|
|
138
|
+
(0, vitest.it)("should delete existing key", async () => {
|
|
138
139
|
const key = getTestKey("delete-test");
|
|
139
140
|
await cache.set(key, "value-to-delete");
|
|
140
141
|
await cache.delete(key);
|
|
141
142
|
const result = await cache.get(key);
|
|
142
|
-
|
|
143
|
+
(0, vitest.expect)(result).toBeUndefined();
|
|
143
144
|
});
|
|
144
|
-
|
|
145
|
+
(0, vitest.it)("should handle deletion of non-existent key", async () => {
|
|
145
146
|
const key = getTestKey("non-existent-delete");
|
|
146
|
-
await
|
|
147
|
+
await (0, vitest.expect)(cache.delete(key)).resolves.not.toThrow();
|
|
147
148
|
});
|
|
148
|
-
|
|
149
|
+
(0, vitest.it)("should only delete specified key", async () => {
|
|
149
150
|
const key1 = getTestKey("delete-key1");
|
|
150
151
|
const key2 = getTestKey("delete-key2");
|
|
151
152
|
await cache.set(key1, "value1");
|
|
152
153
|
await cache.set(key2, "value2");
|
|
153
154
|
await cache.delete(key1);
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
(0, vitest.expect)(await cache.get(key1)).toBeUndefined();
|
|
156
|
+
(0, vitest.expect)(await cache.get(key2)).toBe("value2");
|
|
156
157
|
});
|
|
157
158
|
});
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
(0, vitest.describe)("integration scenarios", () => {
|
|
160
|
+
(0, vitest.it)("should handle round-trip operations", async () => {
|
|
160
161
|
const key = getTestKey("user-session");
|
|
161
162
|
const testData = {
|
|
162
163
|
user: {
|
|
@@ -168,9 +169,9 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
168
169
|
};
|
|
169
170
|
await cache.set(key, testData);
|
|
170
171
|
const result = await cache.get(key);
|
|
171
|
-
|
|
172
|
+
(0, vitest.expect)(result).toEqual(testData);
|
|
172
173
|
});
|
|
173
|
-
|
|
174
|
+
(0, vitest.it)("should handle complex nested objects", async () => {
|
|
174
175
|
const key = getTestKey("complex");
|
|
175
176
|
const complexObject = { level1: { level2: { level3: {
|
|
176
177
|
data: "deep nested value",
|
|
@@ -178,9 +179,9 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
178
179
|
} } } };
|
|
179
180
|
await cache.set(key, complexObject);
|
|
180
181
|
const result = await cache.get(key);
|
|
181
|
-
|
|
182
|
+
(0, vitest.expect)(result).toEqual(complexObject);
|
|
182
183
|
});
|
|
183
|
-
|
|
184
|
+
(0, vitest.it)("should handle concurrent operations", async () => {
|
|
184
185
|
const keys = [
|
|
185
186
|
"concurrent1",
|
|
186
187
|
"concurrent2",
|
|
@@ -193,7 +194,7 @@ require_vi_DgezovHB.describe("UpstashCache", () => {
|
|
|
193
194
|
];
|
|
194
195
|
await Promise.all(keys.map((key, i) => cache.set(key, values[i])));
|
|
195
196
|
const results = await Promise.all(keys.map((key) => cache.get(key)));
|
|
196
|
-
|
|
197
|
+
(0, vitest.expect)(results).toEqual(values);
|
|
197
198
|
});
|
|
198
199
|
});
|
|
199
200
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { UpstashCache } from "../upstash-CTY-M8vR.mjs";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(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 expect(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
|
+
expect(await cache.get(key1)).toBeUndefined();
|
|
155
|
+
expect(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
|
+
expect(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
|
+
expect(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
|
+
expect(results).toEqual(values);
|
|
197
197
|
});
|
|
198
198
|
});
|
|
199
199
|
});
|
|
@@ -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 };
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
|
@@ -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-BPnJ3lrS.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 };
|
package/dist/memory.mjs
CHANGED
|
@@ -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-BPnJ3lrS.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 };
|