@daiso-tech/core 0.44.0 → 0.46.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.
- package/README.md +50 -41
- package/dist/cache/contracts/cache.errors.d.ts +3 -3
- package/dist/cache/contracts/cache.errors.js +1 -1
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +8 -8
- package/dist/cache/contracts/cache.events.js +1 -1
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -48
- package/dist/cache/contracts/database-cache-adapter.contract.js +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.js.map +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +24 -19
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +138 -134
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -8
- package/dist/cache/implementations/derivables/cache/cache.js +3 -8
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +3 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +49 -64
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +5 -10
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -4
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +240 -238
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +141 -36
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +0 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +215 -630
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +3 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.d.ts +11 -8
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js +3 -8
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.d.ts +4 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js +2 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js +2 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -8
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +3 -8
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +2 -2
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +2 -4
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +4 -4
- package/dist/lock/contracts/lock.errors.js +1 -1
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +11 -8
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +3 -8
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/namespace/contracts/_module-exports.d.ts +1 -0
- package/dist/namespace/contracts/_module-exports.js +2 -0
- package/dist/namespace/contracts/_module-exports.js.map +1 -0
- package/dist/namespace/contracts/_module.d.ts +1 -0
- package/dist/namespace/contracts/_module.js +2 -0
- package/dist/namespace/contracts/_module.js.map +1 -0
- package/dist/namespace/contracts/namespace.contract.d.ts +17 -0
- package/dist/namespace/contracts/namespace.contract.js +5 -0
- package/dist/namespace/contracts/namespace.contract.js.map +1 -0
- package/dist/namespace/implementations/_module-exports.d.ts +2 -0
- package/dist/namespace/implementations/_module-exports.js +3 -0
- package/dist/namespace/implementations/_module-exports.js.map +1 -0
- package/dist/namespace/implementations/_module.d.ts +2 -0
- package/dist/namespace/implementations/_module.js +3 -0
- package/dist/namespace/implementations/_module.js.map +1 -0
- package/dist/namespace/{namespace.d.ts → implementations/namespace.d.ts} +18 -33
- package/dist/namespace/{namespace.js → implementations/namespace.js} +20 -4
- package/dist/namespace/implementations/namespace.js.map +1 -0
- package/dist/namespace/implementations/no-op-namespace.d.ts +14 -0
- package/dist/namespace/implementations/no-op-namespace.js +34 -0
- package/dist/namespace/implementations/no-op-namespace.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.d.ts +21 -9
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js +30 -10
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.d.ts +38 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js +75 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.d.ts +21 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js +25 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js +2 -4
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js +2 -4
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.errors.d.ts +4 -4
- package/dist/semaphore/contracts/semaphore.errors.js +1 -1
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +11 -8
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +3 -8
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +4 -4
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +2 -4
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +7 -7
- package/dist/shared-lock/contracts/shared-lock.errors.js +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +11 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +3 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +4 -4
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +2 -4
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -1
- package/dist/task/implementations/task.d.ts +1 -1
- package/dist/task/implementations/task.js +1 -1
- package/dist/task/implementations/task.js.map +1 -1
- package/dist/time-span/implementations/time-span.d.ts +17 -0
- package/dist/time-span/implementations/time-span.js +27 -1
- package/dist/time-span/implementations/time-span.js.map +1 -1
- package/dist/utilities/functions/error-policy.d.ts +1 -1
- package/dist/utilities/functions/error-policy.js +1 -2
- package/dist/utilities/functions/error-policy.js.map +1 -1
- package/package.json +48 -65
- package/dist/namespace/_module-exports.d.ts +0 -1
- package/dist/namespace/_module-exports.js +0 -2
- package/dist/namespace/_module-exports.js.map +0 -1
- package/dist/namespace/_module.d.ts +0 -1
- package/dist/namespace/_module.js +0 -2
- package/dist/namespace/_module.js.map +0 -1
- package/dist/namespace/namespace.js.map +0 -1
|
@@ -57,649 +57,234 @@ export function databaseCacheAdapterTestSuite(settings) {
|
|
|
57
57
|
const { expect, test, createAdapter, describe, beforeEach } = settings;
|
|
58
58
|
let adapter;
|
|
59
59
|
beforeEach(async () => {
|
|
60
|
-
adapter = await createAdapter();
|
|
60
|
+
adapter = (await createAdapter());
|
|
61
61
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const insertData = {
|
|
69
|
-
key: "a",
|
|
70
|
-
value: 1,
|
|
71
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
72
|
-
};
|
|
73
|
-
await adapter.insert(insertData);
|
|
74
|
-
const findData = await adapter.find(insertData.key);
|
|
75
|
-
const result = {
|
|
76
|
-
expiration: insertData.expiration,
|
|
77
|
-
value: insertData.value,
|
|
78
|
-
};
|
|
79
|
-
expect(findData).toStrictEqual(result);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe("method: insert", () => {
|
|
83
|
-
test("Should throw an error when key exists", async () => {
|
|
84
|
-
const insertData = {
|
|
85
|
-
key: "a",
|
|
86
|
-
value: 1,
|
|
87
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
88
|
-
};
|
|
89
|
-
await adapter.insert(insertData);
|
|
90
|
-
const promise = adapter.insert(insertData);
|
|
91
|
-
await expect(promise).rejects.toBeDefined();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe("method: upsert", () => {
|
|
95
|
-
test("Should return null when key doesnt exist", async () => {
|
|
96
|
-
const upsertData = {
|
|
97
|
-
key: "a",
|
|
98
|
-
value: 1,
|
|
99
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
100
|
-
};
|
|
101
|
-
const prevData = await adapter.upsert(upsertData);
|
|
102
|
-
expect(prevData).toBeNull();
|
|
103
|
-
});
|
|
104
|
-
test("Should return previous key expiration when key exist", async () => {
|
|
105
|
-
const upsertData1 = {
|
|
106
|
-
key: "a",
|
|
107
|
-
value: 1,
|
|
108
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
109
|
-
};
|
|
110
|
-
await adapter.upsert(upsertData1);
|
|
111
|
-
const upsertData2 = {
|
|
112
|
-
key: "a",
|
|
113
|
-
value: 2,
|
|
114
|
-
expiration: TimeSpan.fromMilliseconds(50).toEndDate(),
|
|
115
|
-
};
|
|
116
|
-
const prevData = await adapter.upsert(upsertData2);
|
|
117
|
-
const result = {
|
|
118
|
-
expiration: upsertData1.expiration,
|
|
119
|
-
};
|
|
120
|
-
expect({ expiration: prevData?.expiration }).toStrictEqual(result);
|
|
121
|
-
});
|
|
122
|
-
test("Should persist insertion when key doesnt exist", async () => {
|
|
123
|
-
const upsertData = {
|
|
124
|
-
key: "a",
|
|
125
|
-
value: 1,
|
|
126
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
127
|
-
};
|
|
128
|
-
await adapter.upsert(upsertData);
|
|
129
|
-
const findData = await adapter.find(upsertData.key);
|
|
130
|
-
const result = {
|
|
131
|
-
value: upsertData.value,
|
|
132
|
-
expiration: upsertData.expiration,
|
|
133
|
-
};
|
|
134
|
-
expect(findData).toStrictEqual(result);
|
|
135
|
-
});
|
|
136
|
-
test("Should persist update when key exist", async () => {
|
|
137
|
-
const upsertData1 = {
|
|
138
|
-
key: "a",
|
|
139
|
-
value: 1,
|
|
140
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
141
|
-
};
|
|
142
|
-
await adapter.upsert(upsertData1);
|
|
143
|
-
const upsertData2 = {
|
|
144
|
-
key: "a",
|
|
145
|
-
value: 2,
|
|
146
|
-
expiration: TimeSpan.fromMilliseconds(50).toEndDate(),
|
|
147
|
-
};
|
|
148
|
-
await adapter.upsert(upsertData2);
|
|
149
|
-
const findData = await adapter.find(upsertData2.key);
|
|
150
|
-
const result = {
|
|
151
|
-
value: upsertData2.value,
|
|
152
|
-
expiration: upsertData2.expiration,
|
|
153
|
-
};
|
|
154
|
-
expect(findData).toStrictEqual(result);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe("method: updateExpired", () => {
|
|
158
|
-
test("Should not persist update when key has no expiration", async () => {
|
|
159
|
-
const insertData = {
|
|
160
|
-
key: "a",
|
|
161
|
-
value: 1,
|
|
162
|
-
expiration: null,
|
|
163
|
-
};
|
|
164
|
-
await adapter.insert(insertData);
|
|
165
|
-
const updateData = {
|
|
166
|
-
key: "a",
|
|
167
|
-
value: 2,
|
|
168
|
-
expiration: null,
|
|
169
|
-
};
|
|
170
|
-
await adapter.updateExpired(updateData);
|
|
171
|
-
const findData = await adapter.find(updateData.key);
|
|
172
|
-
const result = {
|
|
173
|
-
value: insertData.value,
|
|
174
|
-
expiration: insertData.expiration,
|
|
175
|
-
};
|
|
176
|
-
expect(findData).toStrictEqual(result);
|
|
177
|
-
});
|
|
178
|
-
test("Should return 0 when key has no expiration", async () => {
|
|
179
|
-
const insertData = {
|
|
180
|
-
key: "a",
|
|
181
|
-
value: 1,
|
|
182
|
-
expiration: null,
|
|
183
|
-
};
|
|
184
|
-
await adapter.insert(insertData);
|
|
185
|
-
const updateData = {
|
|
186
|
-
key: "a",
|
|
187
|
-
value: 2,
|
|
188
|
-
expiration: null,
|
|
189
|
-
};
|
|
190
|
-
const result = await adapter.updateExpired(updateData);
|
|
191
|
-
expect(result).toBe(0);
|
|
192
|
-
});
|
|
193
|
-
test("Should not persist update when key has expiration but not expired", async () => {
|
|
194
|
-
const insertData = {
|
|
195
|
-
key: "a",
|
|
196
|
-
value: 1,
|
|
197
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
198
|
-
};
|
|
199
|
-
await adapter.insert(insertData);
|
|
200
|
-
const updateData = {
|
|
201
|
-
key: "a",
|
|
202
|
-
value: 2,
|
|
203
|
-
expiration: null,
|
|
204
|
-
};
|
|
205
|
-
await adapter.updateExpired(updateData);
|
|
206
|
-
const findData = await adapter.find(updateData.key);
|
|
207
|
-
const result = {
|
|
208
|
-
value: insertData.value,
|
|
209
|
-
expiration: insertData.expiration,
|
|
210
|
-
};
|
|
211
|
-
expect(findData).toStrictEqual(result);
|
|
212
|
-
});
|
|
213
|
-
test("Should return 0 update when key has expiration but not expired", async () => {
|
|
214
|
-
const insertData = {
|
|
215
|
-
key: "a",
|
|
216
|
-
value: 1,
|
|
217
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
218
|
-
};
|
|
219
|
-
await adapter.insert(insertData);
|
|
220
|
-
const updateData = {
|
|
221
|
-
key: "a",
|
|
222
|
-
value: 2,
|
|
223
|
-
expiration: null,
|
|
224
|
-
};
|
|
225
|
-
const result = await adapter.updateExpired(updateData);
|
|
226
|
-
expect(result).toBe(0);
|
|
227
|
-
});
|
|
228
|
-
test("Should persist update when key has expiration and expired", async () => {
|
|
229
|
-
const insertData = {
|
|
230
|
-
key: "a",
|
|
231
|
-
value: 1,
|
|
232
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
233
|
-
};
|
|
234
|
-
await adapter.insert(insertData);
|
|
235
|
-
const updateData = {
|
|
236
|
-
key: "a",
|
|
237
|
-
value: 2,
|
|
238
|
-
expiration: null,
|
|
239
|
-
};
|
|
240
|
-
await adapter.updateExpired(updateData);
|
|
241
|
-
const findData = await adapter.find(updateData.key);
|
|
242
|
-
const result = {
|
|
243
|
-
value: updateData.value,
|
|
244
|
-
expiration: updateData.expiration,
|
|
245
|
-
};
|
|
246
|
-
expect(findData).toStrictEqual(result);
|
|
247
|
-
});
|
|
248
|
-
test("Should return 1 update when key has expiration and expired", async () => {
|
|
249
|
-
const insertData = {
|
|
250
|
-
key: "a",
|
|
251
|
-
value: 1,
|
|
252
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
253
|
-
};
|
|
254
|
-
await adapter.insert(insertData);
|
|
255
|
-
const updateData = {
|
|
256
|
-
key: "a",
|
|
257
|
-
value: 2,
|
|
258
|
-
expiration: null,
|
|
259
|
-
};
|
|
260
|
-
const result = await adapter.updateExpired(updateData);
|
|
261
|
-
expect(result).toBe(1);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
describe("method: updateUnexpired", () => {
|
|
265
|
-
test("Should persist update when key has no expiration", async () => {
|
|
266
|
-
const insertData = {
|
|
267
|
-
key: "a",
|
|
268
|
-
value: 1,
|
|
269
|
-
expiration: null,
|
|
270
|
-
};
|
|
271
|
-
await adapter.insert(insertData);
|
|
272
|
-
const updateData = {
|
|
273
|
-
key: "a",
|
|
274
|
-
value: 2,
|
|
275
|
-
};
|
|
276
|
-
await adapter.updateUnexpired(updateData);
|
|
277
|
-
const findData = await adapter.find(updateData.key);
|
|
278
|
-
const result = {
|
|
279
|
-
value: updateData.value,
|
|
280
|
-
expiration: insertData.expiration,
|
|
281
|
-
};
|
|
282
|
-
expect(findData).toStrictEqual(result);
|
|
283
|
-
});
|
|
284
|
-
test("Should return 1 when key has no expiration", async () => {
|
|
285
|
-
const insertData = {
|
|
286
|
-
key: "a",
|
|
287
|
-
value: 1,
|
|
288
|
-
expiration: null,
|
|
289
|
-
};
|
|
290
|
-
await adapter.insert(insertData);
|
|
291
|
-
const updateData = {
|
|
292
|
-
key: "a",
|
|
293
|
-
value: 2,
|
|
294
|
-
};
|
|
295
|
-
const result = await adapter.updateUnexpired(updateData);
|
|
296
|
-
expect(result).toBe(1);
|
|
297
|
-
});
|
|
298
|
-
test("Should persist update when key has expiration but not expired", async () => {
|
|
299
|
-
const insertData = {
|
|
300
|
-
key: "a",
|
|
301
|
-
value: 1,
|
|
302
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
303
|
-
};
|
|
304
|
-
await adapter.insert(insertData);
|
|
305
|
-
const updateData = {
|
|
306
|
-
key: "a",
|
|
307
|
-
value: 2,
|
|
308
|
-
};
|
|
309
|
-
await adapter.updateUnexpired(updateData);
|
|
310
|
-
const findData = await adapter.find(updateData.key);
|
|
311
|
-
const result = {
|
|
312
|
-
value: updateData.value,
|
|
313
|
-
expiration: insertData.expiration,
|
|
314
|
-
};
|
|
315
|
-
expect(findData).toStrictEqual(result);
|
|
316
|
-
});
|
|
317
|
-
test("Should return 1 update when key has expiration but not expired", async () => {
|
|
318
|
-
const insertData = {
|
|
319
|
-
key: "a",
|
|
320
|
-
value: 1,
|
|
321
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
322
|
-
};
|
|
323
|
-
await adapter.insert(insertData);
|
|
324
|
-
const updateData = {
|
|
325
|
-
key: "a",
|
|
326
|
-
value: 2,
|
|
327
|
-
};
|
|
328
|
-
const result = await adapter.updateUnexpired(updateData);
|
|
329
|
-
expect(result).toBe(1);
|
|
330
|
-
});
|
|
331
|
-
test("Should not persist update when key has expiration and expired", async () => {
|
|
332
|
-
const insertData = {
|
|
333
|
-
key: "a",
|
|
334
|
-
value: 1,
|
|
335
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
336
|
-
};
|
|
337
|
-
await adapter.insert(insertData);
|
|
338
|
-
const updateData = {
|
|
339
|
-
key: "a",
|
|
340
|
-
value: 2,
|
|
341
|
-
};
|
|
342
|
-
await adapter.updateUnexpired(updateData);
|
|
343
|
-
const findData = await adapter.find(updateData.key);
|
|
344
|
-
const result = {
|
|
345
|
-
value: insertData.value,
|
|
346
|
-
expiration: insertData.expiration,
|
|
347
|
-
};
|
|
348
|
-
expect(findData).toStrictEqual(result);
|
|
349
|
-
});
|
|
350
|
-
test("Should return 0 update when key has expiration and expired", async () => {
|
|
351
|
-
const insertData = {
|
|
352
|
-
key: "a",
|
|
353
|
-
value: 1,
|
|
354
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
355
|
-
};
|
|
356
|
-
await adapter.insert(insertData);
|
|
357
|
-
const updateData = {
|
|
358
|
-
key: "a",
|
|
359
|
-
value: 2,
|
|
360
|
-
};
|
|
361
|
-
const result = await adapter.updateUnexpired(updateData);
|
|
362
|
-
expect(result).toBe(0);
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
describe("method: incrementUnexpired", () => {
|
|
366
|
-
test("Should persist update when key has no expiration", async () => {
|
|
367
|
-
const insertData = {
|
|
368
|
-
key: "a",
|
|
369
|
-
value: 1,
|
|
370
|
-
expiration: null,
|
|
371
|
-
};
|
|
372
|
-
await adapter.insert(insertData);
|
|
373
|
-
const updateData = {
|
|
374
|
-
key: "a",
|
|
375
|
-
value: 2,
|
|
376
|
-
};
|
|
377
|
-
await adapter.incrementUnexpired(updateData);
|
|
378
|
-
const findData = await adapter.find(updateData.key);
|
|
379
|
-
const result = {
|
|
380
|
-
value: insertData.value + updateData.value,
|
|
381
|
-
expiration: insertData.expiration,
|
|
382
|
-
};
|
|
383
|
-
expect(findData).toStrictEqual(result);
|
|
384
|
-
});
|
|
385
|
-
test("Should return 1 when key has no expiration", async () => {
|
|
386
|
-
const insertData = {
|
|
387
|
-
key: "a",
|
|
388
|
-
value: 1,
|
|
389
|
-
expiration: null,
|
|
390
|
-
};
|
|
391
|
-
await adapter.insert(insertData);
|
|
392
|
-
const updateData = {
|
|
393
|
-
key: "a",
|
|
394
|
-
value: 2,
|
|
395
|
-
};
|
|
396
|
-
const result = await adapter.incrementUnexpired(updateData);
|
|
397
|
-
expect(result).toBe(1);
|
|
398
|
-
});
|
|
399
|
-
test("Should persist update when key has expiration but not expired", async () => {
|
|
400
|
-
const insertData = {
|
|
401
|
-
key: "a",
|
|
402
|
-
value: 1,
|
|
403
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
404
|
-
};
|
|
405
|
-
await adapter.insert(insertData);
|
|
406
|
-
const updateData = {
|
|
407
|
-
key: "a",
|
|
408
|
-
value: 2,
|
|
409
|
-
};
|
|
410
|
-
await adapter.incrementUnexpired(updateData);
|
|
411
|
-
const findData = await adapter.find(updateData.key);
|
|
412
|
-
const result = {
|
|
413
|
-
value: insertData.value + updateData.value,
|
|
414
|
-
expiration: insertData.expiration,
|
|
415
|
-
};
|
|
416
|
-
expect(findData).toStrictEqual(result);
|
|
417
|
-
});
|
|
418
|
-
test("Should return 1 update when key has expiration but not expired", async () => {
|
|
419
|
-
const insertData = {
|
|
420
|
-
key: "a",
|
|
421
|
-
value: 1,
|
|
422
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
423
|
-
};
|
|
424
|
-
await adapter.insert(insertData);
|
|
425
|
-
const updateData = {
|
|
426
|
-
key: "a",
|
|
427
|
-
value: 2,
|
|
428
|
-
};
|
|
429
|
-
const result = await adapter.incrementUnexpired(updateData);
|
|
430
|
-
expect(result).toBe(1);
|
|
431
|
-
});
|
|
432
|
-
test("Should not persist update when key has expiration and expired", async () => {
|
|
433
|
-
const insertData = {
|
|
434
|
-
key: "a",
|
|
435
|
-
value: 1,
|
|
436
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
437
|
-
};
|
|
438
|
-
await adapter.insert(insertData);
|
|
439
|
-
const updateData = {
|
|
440
|
-
key: "a",
|
|
441
|
-
value: 2,
|
|
442
|
-
};
|
|
443
|
-
await adapter.incrementUnexpired(updateData);
|
|
444
|
-
const findData = await adapter.find(updateData.key);
|
|
445
|
-
const result = {
|
|
446
|
-
value: insertData.value,
|
|
447
|
-
expiration: insertData.expiration,
|
|
448
|
-
};
|
|
449
|
-
expect(findData).toStrictEqual(result);
|
|
450
|
-
});
|
|
451
|
-
test("Should return 0 update when key has expiration and expired", async () => {
|
|
452
|
-
const insertData = {
|
|
453
|
-
key: "a",
|
|
454
|
-
value: 1,
|
|
455
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
456
|
-
};
|
|
457
|
-
await adapter.insert(insertData);
|
|
458
|
-
const updateData = {
|
|
459
|
-
key: "a",
|
|
460
|
-
value: 2,
|
|
461
|
-
};
|
|
462
|
-
const result = await adapter.incrementUnexpired(updateData);
|
|
463
|
-
expect(result).toBe(0);
|
|
464
|
-
});
|
|
465
|
-
test("Should throw an error when incrementing a number error", async () => {
|
|
466
|
-
await adapter.insert({
|
|
467
|
-
key: "a",
|
|
468
|
-
value: "A",
|
|
469
|
-
expiration: null,
|
|
62
|
+
const KEY = "a";
|
|
63
|
+
describe("Reusable tests:", () => {
|
|
64
|
+
describe("method: find", () => {
|
|
65
|
+
test("Should return null when key does not exists", async () => {
|
|
66
|
+
const data = await adapter.find(KEY);
|
|
67
|
+
expect(data).toBeNull();
|
|
470
68
|
});
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
69
|
+
test("Should return value when key exists", async () => {
|
|
70
|
+
const value = "1";
|
|
71
|
+
await adapter.transaction(async (trx) => {
|
|
72
|
+
await trx.upsert(KEY, value);
|
|
73
|
+
});
|
|
74
|
+
const storedValue = await adapter.find(KEY);
|
|
75
|
+
expect(storedValue).toEqual({
|
|
76
|
+
value,
|
|
77
|
+
expiration: null,
|
|
78
|
+
});
|
|
474
79
|
});
|
|
475
|
-
await expect(promise).rejects.toBeDefined();
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
describe("method: removeExpiredMany", () => {
|
|
479
|
-
test("Should not persist removal when key has no expiration", async () => {
|
|
480
|
-
const insertData = {
|
|
481
|
-
key: "a",
|
|
482
|
-
value: 1,
|
|
483
|
-
expiration: null,
|
|
484
|
-
};
|
|
485
|
-
await adapter.insert(insertData);
|
|
486
|
-
await adapter.removeExpiredMany([insertData.key]);
|
|
487
|
-
const findData = await adapter.find(insertData.key);
|
|
488
|
-
const result = {
|
|
489
|
-
value: insertData.value,
|
|
490
|
-
expiration: insertData.expiration,
|
|
491
|
-
};
|
|
492
|
-
expect(findData).toStrictEqual(result);
|
|
493
|
-
});
|
|
494
|
-
test("Should return 0 when key has no expiration", async () => {
|
|
495
|
-
const insertData = {
|
|
496
|
-
key: "a",
|
|
497
|
-
value: 1,
|
|
498
|
-
expiration: null,
|
|
499
|
-
};
|
|
500
|
-
await adapter.insert(insertData);
|
|
501
|
-
const result = await adapter.removeExpiredMany([insertData.key]);
|
|
502
|
-
expect(result).toBe(0);
|
|
503
|
-
});
|
|
504
|
-
test("Should not persist removal when key has expiration but not expired", async () => {
|
|
505
|
-
const insertData = {
|
|
506
|
-
key: "a",
|
|
507
|
-
value: 1,
|
|
508
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
509
|
-
};
|
|
510
|
-
await adapter.insert(insertData);
|
|
511
|
-
await adapter.removeExpiredMany([insertData.key]);
|
|
512
|
-
const findData = await adapter.find(insertData.key);
|
|
513
|
-
const result = {
|
|
514
|
-
value: insertData.value,
|
|
515
|
-
expiration: insertData.expiration,
|
|
516
|
-
};
|
|
517
|
-
expect(findData).toStrictEqual(result);
|
|
518
|
-
});
|
|
519
|
-
test("Should return 0 removal when key has expiration but not expired", async () => {
|
|
520
|
-
const insertData = {
|
|
521
|
-
key: "a",
|
|
522
|
-
value: 1,
|
|
523
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
524
|
-
};
|
|
525
|
-
await adapter.insert(insertData);
|
|
526
|
-
const result = await adapter.removeExpiredMany([insertData.key]);
|
|
527
|
-
expect(result).toBe(0);
|
|
528
|
-
});
|
|
529
|
-
test("Should persist removal when key has expiration and expired", async () => {
|
|
530
|
-
const insertData = {
|
|
531
|
-
key: "a",
|
|
532
|
-
value: 1,
|
|
533
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
534
|
-
};
|
|
535
|
-
await adapter.insert(insertData);
|
|
536
|
-
await adapter.removeExpiredMany([insertData.key]);
|
|
537
|
-
const findData = await adapter.find(insertData.key);
|
|
538
|
-
expect(findData).toBeNull();
|
|
539
|
-
});
|
|
540
|
-
test("Should return number of removed keys when all keys has expiration and are expired", async () => {
|
|
541
|
-
const insertData1 = {
|
|
542
|
-
key: "a",
|
|
543
|
-
value: 1,
|
|
544
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
545
|
-
};
|
|
546
|
-
const insertData2 = {
|
|
547
|
-
key: "b",
|
|
548
|
-
value: 1,
|
|
549
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
550
|
-
};
|
|
551
|
-
await adapter.insert(insertData1);
|
|
552
|
-
await adapter.insert(insertData2);
|
|
553
|
-
const result = await adapter.removeExpiredMany([
|
|
554
|
-
insertData1.key,
|
|
555
|
-
insertData2.key,
|
|
556
|
-
]);
|
|
557
|
-
expect(result).toBe(2);
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
describe("method: removeUnexpiredMany", () => {
|
|
561
|
-
test("Should persist removal when key has no expiration", async () => {
|
|
562
|
-
const insertData = {
|
|
563
|
-
key: "a",
|
|
564
|
-
value: 1,
|
|
565
|
-
expiration: null,
|
|
566
|
-
};
|
|
567
|
-
await adapter.insert(insertData);
|
|
568
|
-
await adapter.removeUnexpiredMany([insertData.key]);
|
|
569
|
-
const findData = await adapter.find(insertData.key);
|
|
570
|
-
expect(findData).toBeNull();
|
|
571
|
-
});
|
|
572
|
-
test("Should return number of removed keys when all keys has no expiration", async () => {
|
|
573
|
-
const insertData1 = {
|
|
574
|
-
key: "a",
|
|
575
|
-
value: 1,
|
|
576
|
-
expiration: null,
|
|
577
|
-
};
|
|
578
|
-
const insertData2 = {
|
|
579
|
-
key: "b",
|
|
580
|
-
value: 1,
|
|
581
|
-
expiration: null,
|
|
582
|
-
};
|
|
583
|
-
await adapter.insert(insertData1);
|
|
584
|
-
await adapter.insert(insertData2);
|
|
585
|
-
const result = await adapter.removeUnexpiredMany([
|
|
586
|
-
insertData1.key,
|
|
587
|
-
insertData2.key,
|
|
588
|
-
]);
|
|
589
|
-
expect(result).toBe(2);
|
|
590
|
-
});
|
|
591
|
-
test("Should persist removal when key has expiration but not expired", async () => {
|
|
592
|
-
const insertData = {
|
|
593
|
-
key: "a",
|
|
594
|
-
value: 1,
|
|
595
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
596
|
-
};
|
|
597
|
-
await adapter.insert(insertData);
|
|
598
|
-
await adapter.removeUnexpiredMany([insertData.key]);
|
|
599
|
-
const findData = await adapter.find(insertData.key);
|
|
600
|
-
expect(findData).toBeNull();
|
|
601
|
-
});
|
|
602
|
-
test("Should return number of removed keys when all key has expiration but not expired", async () => {
|
|
603
|
-
const insertData1 = {
|
|
604
|
-
key: "a",
|
|
605
|
-
value: 1,
|
|
606
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
607
|
-
};
|
|
608
|
-
const insertData2 = {
|
|
609
|
-
key: "b",
|
|
610
|
-
value: 1,
|
|
611
|
-
expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
|
|
612
|
-
};
|
|
613
|
-
await adapter.insert(insertData1);
|
|
614
|
-
await adapter.insert(insertData2);
|
|
615
|
-
const result = await adapter.removeUnexpiredMany([
|
|
616
|
-
insertData1.key,
|
|
617
|
-
insertData2.key,
|
|
618
|
-
]);
|
|
619
|
-
expect(result).toBe(2);
|
|
620
|
-
});
|
|
621
|
-
test("Should not persist removal when key has expiration and expired", async () => {
|
|
622
|
-
const insertData = {
|
|
623
|
-
key: "a",
|
|
624
|
-
value: 1,
|
|
625
|
-
expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
|
|
626
|
-
};
|
|
627
|
-
await adapter.insert(insertData);
|
|
628
|
-
await adapter.removeUnexpiredMany([insertData.key]);
|
|
629
|
-
const findData = await adapter.find(insertData.key);
|
|
630
|
-
const result = {
|
|
631
|
-
expiration: insertData.expiration,
|
|
632
|
-
value: insertData.value,
|
|
633
|
-
};
|
|
634
|
-
expect(findData).toStrictEqual(result);
|
|
635
80
|
});
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
81
|
+
describe("method: transaction find", () => {
|
|
82
|
+
test("Should return null when key does not exists", async () => {
|
|
83
|
+
const data = await adapter.transaction(async (trx) => {
|
|
84
|
+
return await trx.find(KEY);
|
|
85
|
+
});
|
|
86
|
+
expect(data).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
test("Should return value when key exists", async () => {
|
|
89
|
+
const value = "1";
|
|
90
|
+
const storedValue = await adapter.transaction(async (trx) => {
|
|
91
|
+
await trx.upsert(KEY, value);
|
|
92
|
+
return await trx.find(KEY);
|
|
93
|
+
});
|
|
94
|
+
expect(storedValue).toEqual({
|
|
95
|
+
value,
|
|
96
|
+
expiration: null,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
645
99
|
});
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
100
|
+
describe("method: transaction upsert", () => {
|
|
101
|
+
test("Should add without expiration when key doesnt exists and expiration is null", async () => {
|
|
102
|
+
const value = "a-1";
|
|
103
|
+
const expiration = null;
|
|
104
|
+
await adapter.transaction(async (trx) => {
|
|
105
|
+
await trx.upsert(KEY, value, expiration);
|
|
106
|
+
});
|
|
107
|
+
const storedValue = await adapter.find(KEY);
|
|
108
|
+
expect(storedValue).toEqual({
|
|
109
|
+
value,
|
|
110
|
+
expiration,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
test("Should add without expiration when key doesnt exists and expiration is an Date", async () => {
|
|
114
|
+
const value = "a-1";
|
|
115
|
+
const currentDate = new Date("2025-01-07");
|
|
116
|
+
const expiration = TimeSpan.fromSeconds(10).toEndDate(currentDate);
|
|
117
|
+
await adapter.transaction(async (trx) => {
|
|
118
|
+
await trx.upsert(KEY, value, expiration);
|
|
119
|
+
});
|
|
120
|
+
const storedValue = await adapter.find(KEY);
|
|
121
|
+
expect(storedValue).toEqual({
|
|
122
|
+
value,
|
|
123
|
+
expiration,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
test("Should add without expiration when key doesnt exists and expiration is undefined", async () => {
|
|
127
|
+
const value = "a-1";
|
|
128
|
+
await adapter.transaction(async (trx) => {
|
|
129
|
+
await trx.upsert(KEY, value);
|
|
130
|
+
});
|
|
131
|
+
const storedValue = await adapter.find(KEY);
|
|
132
|
+
expect(storedValue).toEqual({
|
|
133
|
+
value,
|
|
134
|
+
expiration: null,
|
|
135
|
+
});
|
|
653
136
|
});
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
expiration
|
|
137
|
+
test("Should update only value when key exists and expiration is undefined", async () => {
|
|
138
|
+
const value = "a-1";
|
|
139
|
+
const currentDate = new Date("2026-01-17");
|
|
140
|
+
const expiration = TimeSpan.fromSeconds(6).toEndDate(currentDate);
|
|
141
|
+
const newValue = "2";
|
|
142
|
+
await adapter.transaction(async (trx) => {
|
|
143
|
+
await trx.upsert(KEY, value, expiration);
|
|
144
|
+
await trx.upsert(KEY, newValue);
|
|
145
|
+
});
|
|
146
|
+
const storedValue = await adapter.find(KEY);
|
|
147
|
+
expect(storedValue).toEqual({
|
|
148
|
+
value: newValue,
|
|
149
|
+
expiration,
|
|
150
|
+
});
|
|
658
151
|
});
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
152
|
+
test("Should update value and expiration when key exists and expiration is null", async () => {
|
|
153
|
+
const value = "a-1";
|
|
154
|
+
const expiration = TimeSpan.fromSeconds(6).toEndDate(new Date("2026-01-17"));
|
|
155
|
+
const newValue = "2";
|
|
156
|
+
const newExpiration = null;
|
|
157
|
+
await adapter.transaction(async (trx) => {
|
|
158
|
+
await trx.upsert(KEY, value, expiration);
|
|
159
|
+
await trx.upsert(KEY, newValue, newExpiration);
|
|
160
|
+
});
|
|
161
|
+
const storedValue = await adapter.find(KEY);
|
|
162
|
+
expect(storedValue).toEqual({
|
|
163
|
+
value: newValue,
|
|
164
|
+
expiration: newExpiration,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
test("Should update value and expiration when key exists and expiration is an Date", async () => {
|
|
168
|
+
const value = "a-1";
|
|
169
|
+
const expiration = TimeSpan.fromSeconds(6).toEndDate(new Date("2026-01-17"));
|
|
170
|
+
const newValue = "2";
|
|
171
|
+
const newExpiration = TimeSpan.fromSeconds(6).toEndDate(new Date("2027-01-17"));
|
|
172
|
+
await adapter.transaction(async (trx) => {
|
|
173
|
+
await trx.upsert(KEY, value, expiration);
|
|
174
|
+
await trx.upsert(KEY, newValue, newExpiration);
|
|
175
|
+
});
|
|
176
|
+
const storedValue = await adapter.find(KEY);
|
|
177
|
+
expect(storedValue).toEqual({
|
|
178
|
+
value: newValue,
|
|
179
|
+
expiration: newExpiration,
|
|
180
|
+
});
|
|
663
181
|
});
|
|
664
|
-
await adapter.removeAll();
|
|
665
|
-
expect([
|
|
666
|
-
await adapter.find("cache/a"),
|
|
667
|
-
await adapter.find("cache/b"),
|
|
668
|
-
await adapter.find("c"),
|
|
669
|
-
]).toEqual([null, null, null]);
|
|
670
182
|
});
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
key: "cache/a",
|
|
676
|
-
value: 1,
|
|
677
|
-
expiration: null,
|
|
183
|
+
describe("method: removeMany", () => {
|
|
184
|
+
test("Should return empty array when given empty array as keys", async () => {
|
|
185
|
+
const data = await adapter.removeMany([KEY]);
|
|
186
|
+
expect(data).toEqual([]);
|
|
678
187
|
});
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
188
|
+
test("Should return array of ICacheDataExpiration when keys exists", async () => {
|
|
189
|
+
const currentDate = new Date("2026-01-17");
|
|
190
|
+
const key1 = "a";
|
|
191
|
+
const value1 = "1";
|
|
192
|
+
const expiration1 = TimeSpan.fromSeconds(3).toEndDate(currentDate);
|
|
193
|
+
const key2 = "b";
|
|
194
|
+
const value2 = "2";
|
|
195
|
+
const expiration2 = null;
|
|
196
|
+
const noneExistingKey = "c";
|
|
197
|
+
await adapter.transaction(async (trx) => {
|
|
198
|
+
await trx.upsert(key1, value1, expiration1);
|
|
199
|
+
await trx.upsert(key2, value2, expiration2);
|
|
200
|
+
});
|
|
201
|
+
const data = await adapter.removeMany([
|
|
202
|
+
key1,
|
|
203
|
+
noneExistingKey,
|
|
204
|
+
key2,
|
|
205
|
+
]);
|
|
206
|
+
expect(data).toEqual([
|
|
207
|
+
{ expiration: expiration1 },
|
|
208
|
+
{ expiration: expiration2 },
|
|
209
|
+
]);
|
|
683
210
|
});
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
211
|
+
test("Should remove keys", async () => {
|
|
212
|
+
const currentDate = new Date("2026-01-17");
|
|
213
|
+
const key1 = "a";
|
|
214
|
+
const value1 = "1";
|
|
215
|
+
const expiration1 = TimeSpan.fromSeconds(3).toEndDate(currentDate);
|
|
216
|
+
const key2 = "b";
|
|
217
|
+
const value2 = "2";
|
|
218
|
+
const expiration2 = null;
|
|
219
|
+
await adapter.transaction(async (trx) => {
|
|
220
|
+
await trx.upsert(key1, value1, expiration1);
|
|
221
|
+
await trx.upsert(key2, value2, expiration2);
|
|
222
|
+
});
|
|
223
|
+
await adapter.removeMany([key1, key2]);
|
|
224
|
+
const storedKey1 = await adapter.find(key1);
|
|
225
|
+
const storedKey2 = await adapter.find(key2);
|
|
226
|
+
expect(storedKey1).toBeNull();
|
|
227
|
+
expect(storedKey2).toBeNull();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe("method: removeAll", () => {
|
|
231
|
+
test("Should remove all keys", async () => {
|
|
232
|
+
const currentDate = new Date("2026-01-17");
|
|
233
|
+
const key1 = "a";
|
|
234
|
+
const value1 = "1";
|
|
235
|
+
const expiration1 = TimeSpan.fromSeconds(3).toEndDate(currentDate);
|
|
236
|
+
const key2 = "b";
|
|
237
|
+
const value2 = "2";
|
|
238
|
+
const expiration2 = TimeSpan.fromSeconds(6).toEndDate(currentDate);
|
|
239
|
+
const key3 = "c";
|
|
240
|
+
const value3 = "3";
|
|
241
|
+
const expiration3 = null;
|
|
242
|
+
await adapter.transaction(async (trx) => {
|
|
243
|
+
await trx.upsert(key1, value1, expiration1);
|
|
244
|
+
await trx.upsert(key2, value2, expiration2);
|
|
245
|
+
await trx.upsert(key3, value3, expiration3);
|
|
246
|
+
});
|
|
247
|
+
await adapter.removeAll();
|
|
248
|
+
const storedValue1 = await adapter.find(key1);
|
|
249
|
+
const storedValue2 = await adapter.find(key2);
|
|
250
|
+
const storedValue3 = await adapter.find(key3);
|
|
251
|
+
expect(storedValue1).toBeNull();
|
|
252
|
+
expect(storedValue2).toBeNull();
|
|
253
|
+
expect(storedValue3).toBeNull();
|
|
688
254
|
});
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
255
|
+
});
|
|
256
|
+
describe("method: removeByKeyPrefix", () => {
|
|
257
|
+
test("Should remove all keys that match prefix", async () => {
|
|
258
|
+
const keyA1 = "a/1";
|
|
259
|
+
const keyA2 = "a/2";
|
|
260
|
+
const keyB1 = "b/1";
|
|
261
|
+
const keyB2 = "b/2";
|
|
262
|
+
const valueA1 = "a-1";
|
|
263
|
+
const valueA2 = "a-2";
|
|
264
|
+
const valueB1 = "b-1";
|
|
265
|
+
const valueB2 = "b-2";
|
|
266
|
+
await adapter.transaction(async (trx) => {
|
|
267
|
+
await trx.upsert(keyA1, valueA1);
|
|
268
|
+
await trx.upsert(keyA2, valueA2);
|
|
269
|
+
await trx.upsert(keyB1, valueB1);
|
|
270
|
+
await trx.upsert(keyB2, valueB2);
|
|
271
|
+
});
|
|
272
|
+
await adapter.removeByKeyPrefix("a/");
|
|
273
|
+
const storedValueA1 = await adapter.find(keyA1);
|
|
274
|
+
const storedValueA2 = await adapter.find(keyA2);
|
|
275
|
+
const storedValueB1 = await adapter.find(keyB1);
|
|
276
|
+
const storedValueB2 = await adapter.find(keyB2);
|
|
277
|
+
expect(storedValueA1).toBeNull();
|
|
278
|
+
expect(storedValueA2).toBeNull();
|
|
279
|
+
expect(storedValueB1).toEqual({
|
|
280
|
+
value: valueB1,
|
|
281
|
+
expiration: null,
|
|
282
|
+
});
|
|
283
|
+
expect(storedValueB2).toEqual({
|
|
284
|
+
value: valueB2,
|
|
700
285
|
expiration: null,
|
|
701
|
-
}
|
|
702
|
-
|
|
286
|
+
});
|
|
287
|
+
});
|
|
703
288
|
});
|
|
704
289
|
});
|
|
705
290
|
}
|