@geekmidas/cache 0.0.7 → 0.2.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 (73) hide show
  1. package/dist/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
  2. package/dist/expo.cjs +4 -3
  3. package/dist/expo.cjs.map +1 -0
  4. package/dist/expo.d.cts +8 -5
  5. package/dist/expo.d.cts.map +1 -0
  6. package/dist/expo.d.mts +8 -5
  7. package/dist/expo.d.mts.map +1 -0
  8. package/dist/expo.mjs +3 -2
  9. package/dist/expo.mjs.map +1 -0
  10. package/dist/{index-B6eF5Yxi.d.cts → index-BSYYdwRm.d.cts} +8 -5
  11. package/dist/index-BSYYdwRm.d.cts.map +1 -0
  12. package/dist/{index-Bv61mxVT.d.mts → index-Dx96gr-9.d.mts} +8 -5
  13. package/dist/index-Dx96gr-9.d.mts.map +1 -0
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +1 -1
  18. package/dist/memory.cjs +35 -3
  19. package/dist/memory.cjs.map +1 -0
  20. package/dist/memory.d.cts +8 -5
  21. package/dist/memory.d.cts.map +1 -0
  22. package/dist/memory.d.mts +8 -5
  23. package/dist/memory.d.mts.map +1 -0
  24. package/dist/memory.mjs +34 -3
  25. package/dist/memory.mjs.map +1 -0
  26. package/dist/{src-DVpoP03o.mjs → src-CrE4Nl5T.mjs} +2 -1
  27. package/dist/src-CrE4Nl5T.mjs.map +1 -0
  28. package/dist/{src-C7d6HaTp.cjs → src-zfYb7mdS.cjs} +3 -2
  29. package/dist/src-zfYb7mdS.cjs.map +1 -0
  30. package/dist/upstash.cjs +32 -2
  31. package/dist/upstash.cjs.map +1 -0
  32. package/dist/upstash.d.cts +8 -5
  33. package/dist/upstash.d.cts.map +1 -0
  34. package/dist/upstash.d.mts +8 -5
  35. package/dist/upstash.d.mts.map +1 -0
  36. package/dist/upstash.mjs +31 -2
  37. package/dist/upstash.mjs.map +1 -0
  38. package/package.json +6 -2
  39. package/src/__benchmarks__/memory.bench.ts +51 -0
  40. package/src/__tests__/cache.spec.ts +138 -105
  41. package/src/__tests__/integration.spec.ts +277 -268
  42. package/src/__tests__/memory.spec.ts +129 -129
  43. package/src/__tests__/upstash.spec.ts +209 -180
  44. package/src/expo.ts +45 -46
  45. package/src/index.ts +37 -36
  46. package/src/memory.ts +28 -27
  47. package/src/upstash.ts +28 -28
  48. package/tsconfig.json +9 -0
  49. package/tsdown.config.ts +1 -1
  50. package/dist/__tests__/cache.spec.cjs +0 -77
  51. package/dist/__tests__/cache.spec.d.cts +0 -1
  52. package/dist/__tests__/cache.spec.d.mts +0 -1
  53. package/dist/__tests__/cache.spec.mjs +0 -77
  54. package/dist/__tests__/integration.spec.cjs +0 -235
  55. package/dist/__tests__/integration.spec.d.cts +0 -1
  56. package/dist/__tests__/integration.spec.d.mts +0 -1
  57. package/dist/__tests__/integration.spec.mjs +0 -235
  58. package/dist/__tests__/memory.spec.cjs +0 -126
  59. package/dist/__tests__/memory.spec.d.cts +0 -1
  60. package/dist/__tests__/memory.spec.d.mts +0 -1
  61. package/dist/__tests__/memory.spec.mjs +0 -126
  62. package/dist/__tests__/upstash.spec.cjs +0 -201
  63. package/dist/__tests__/upstash.spec.d.cts +0 -1
  64. package/dist/__tests__/upstash.spec.d.mts +0 -1
  65. package/dist/__tests__/upstash.spec.mjs +0 -201
  66. package/dist/magic-string.es-CBih0MJw.mjs +0 -1014
  67. package/dist/magic-string.es-KiPEzMtt.cjs +0 -1015
  68. package/dist/memory-Csy6J-Ak.cjs +0 -39
  69. package/dist/memory-QDTnSEX5.mjs +0 -33
  70. package/dist/upstash-CXy_duOa.mjs +0 -31
  71. package/dist/upstash-u8Hs4sZG.cjs +0 -37
  72. package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +0 -14955
  73. package/dist/vi.bdSIJ99Y-CB5havZF.mjs +0 -14951
@@ -1 +0,0 @@
1
- export { };
@@ -1,201 +0,0 @@
1
- import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-CB5havZF.mjs";
2
- import { UpstashCache } from "../upstash-CXy_duOa.mjs";
3
-
4
- //#region src/__tests__/upstash.spec.ts
5
- describe("UpstashCache", () => {
6
- let cache;
7
- const testKeyPrefix = `test:${Date.now()}:`;
8
- let testKeys = [];
9
- beforeEach(() => {
10
- cache = new UpstashCache("http://localhost:8079", "example_token");
11
- testKeys = [];
12
- });
13
- afterEach(async () => {
14
- for (const key of testKeys) try {
15
- await cache.delete(key);
16
- } catch (error) {}
17
- });
18
- const getTestKey = (suffix) => {
19
- const key = `${testKeyPrefix}${suffix}`;
20
- testKeys.push(key);
21
- return key;
22
- };
23
- describe("get", () => {
24
- it("should return undefined for non-existent key", async () => {
25
- const key = getTestKey("non-existent");
26
- const result = await cache.get(key);
27
- globalExpect(result).toBeUndefined();
28
- });
29
- it("should parse and return JSON value", async () => {
30
- const key = getTestKey("object");
31
- const testValue = {
32
- id: 1,
33
- name: "test"
34
- };
35
- await cache.set(key, testValue);
36
- const result = await cache.get(key);
37
- globalExpect(result).toEqual(testValue);
38
- });
39
- it("should handle string values", async () => {
40
- const key = getTestKey("string");
41
- const testValue = "simple string";
42
- await cache.set(key, testValue);
43
- const result = await cache.get(key);
44
- globalExpect(result).toBe(testValue);
45
- });
46
- it("should handle number values", async () => {
47
- const key = getTestKey("number");
48
- const testValue = 42;
49
- await cache.set(key, testValue);
50
- const result = await cache.get(key);
51
- globalExpect(result).toBe(testValue);
52
- });
53
- it("should handle boolean values", async () => {
54
- const key = getTestKey("boolean");
55
- const testValue = true;
56
- await cache.set(key, testValue);
57
- const result = await cache.get(key);
58
- globalExpect(result).toBe(testValue);
59
- });
60
- it("should handle array values", async () => {
61
- const key = getTestKey("array");
62
- const testArray = [
63
- 1,
64
- 2,
65
- 3,
66
- "test"
67
- ];
68
- await cache.set(key, testArray);
69
- const result = await cache.get(key);
70
- globalExpect(result).toEqual(testArray);
71
- });
72
- it("should handle null values as undefined", async () => {
73
- const key = getTestKey("null");
74
- await cache.set(key, null);
75
- const result = await cache.get(key);
76
- globalExpect(result).toBeUndefined();
77
- });
78
- });
79
- describe("set", () => {
80
- it("should store and retrieve object value", async () => {
81
- const key = getTestKey("set-object");
82
- const testValue = {
83
- id: 1,
84
- name: "test"
85
- };
86
- await cache.set(key, testValue);
87
- const result = await cache.get(key);
88
- globalExpect(result).toEqual(testValue);
89
- });
90
- it("should store and retrieve string values", async () => {
91
- const key = getTestKey("set-string");
92
- const testValue = "test string";
93
- await cache.set(key, testValue);
94
- const result = await cache.get(key);
95
- globalExpect(result).toBe(testValue);
96
- });
97
- it("should store and retrieve number values", async () => {
98
- const key = getTestKey("set-number");
99
- const testValue = 42;
100
- await cache.set(key, testValue);
101
- const result = await cache.get(key);
102
- globalExpect(result).toBe(testValue);
103
- });
104
- it("should store and retrieve boolean values", async () => {
105
- const key = getTestKey("set-boolean");
106
- const testValue = true;
107
- await cache.set(key, testValue);
108
- const result = await cache.get(key);
109
- globalExpect(result).toBe(testValue);
110
- });
111
- it("should store and retrieve array values", async () => {
112
- const key = getTestKey("set-array");
113
- const testArray = [
114
- 1,
115
- 2,
116
- 3
117
- ];
118
- await cache.set(key, testArray);
119
- const result = await cache.get(key);
120
- globalExpect(result).toEqual(testArray);
121
- });
122
- it("should not store and retrieve null values", async () => {
123
- const key = getTestKey("set-null");
124
- await cache.set(key, null);
125
- const result = await cache.get(key);
126
- globalExpect(result).toBeUndefined();
127
- });
128
- it("should overwrite existing values", async () => {
129
- const key = getTestKey("overwrite");
130
- await cache.set(key, "initial");
131
- await cache.set(key, "updated");
132
- const result = await cache.get(key);
133
- globalExpect(result).toBe("updated");
134
- });
135
- });
136
- describe("delete", () => {
137
- it("should delete existing key", async () => {
138
- const key = getTestKey("delete-test");
139
- await cache.set(key, "value-to-delete");
140
- await cache.delete(key);
141
- const result = await cache.get(key);
142
- globalExpect(result).toBeUndefined();
143
- });
144
- it("should handle deletion of non-existent key", async () => {
145
- const key = getTestKey("non-existent-delete");
146
- await globalExpect(cache.delete(key)).resolves.not.toThrow();
147
- });
148
- it("should only delete specified key", async () => {
149
- const key1 = getTestKey("delete-key1");
150
- const key2 = getTestKey("delete-key2");
151
- await cache.set(key1, "value1");
152
- await cache.set(key2, "value2");
153
- await cache.delete(key1);
154
- globalExpect(await cache.get(key1)).toBeUndefined();
155
- globalExpect(await cache.get(key2)).toBe("value2");
156
- });
157
- });
158
- describe("integration scenarios", () => {
159
- it("should handle round-trip operations", async () => {
160
- const key = getTestKey("user-session");
161
- const testData = {
162
- user: {
163
- id: 1,
164
- name: "John"
165
- },
166
- preferences: ["dark-mode", "notifications"],
167
- count: 42
168
- };
169
- await cache.set(key, testData);
170
- const result = await cache.get(key);
171
- globalExpect(result).toEqual(testData);
172
- });
173
- it("should handle complex nested objects", async () => {
174
- const key = getTestKey("complex");
175
- const complexObject = { level1: { level2: { level3: {
176
- data: "deep nested value",
177
- array: [{ id: 1 }, { id: 2 }]
178
- } } } };
179
- await cache.set(key, complexObject);
180
- const result = await cache.get(key);
181
- globalExpect(result).toEqual(complexObject);
182
- });
183
- it("should handle concurrent operations", async () => {
184
- const keys = [
185
- "concurrent1",
186
- "concurrent2",
187
- "concurrent3"
188
- ].map((suffix) => getTestKey(suffix));
189
- const values = [
190
- "value1",
191
- "value2",
192
- "value3"
193
- ];
194
- await Promise.all(keys.map((key, i) => cache.set(key, values[i])));
195
- const results = await Promise.all(keys.map((key) => cache.get(key)));
196
- globalExpect(results).toEqual(values);
197
- });
198
- });
199
- });
200
-
201
- //#endregion