lambda-essentials-ts 7.0.5 → 7.0.6
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.
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { createClient } from 'redis';
|
|
2
|
+
export default function createRedisStorage(client: ReturnType<typeof createClient>): import("axios-cache-interceptor").AxiosStorage;
|
|
@@ -4,18 +4,24 @@ exports.default = createRedisStorage;
|
|
|
4
4
|
const axios_cache_interceptor_1 = require("axios-cache-interceptor");
|
|
5
5
|
const KEY_PREFIX = 'axios-cache-';
|
|
6
6
|
const MIN_TTL = 60000;
|
|
7
|
-
function createRedisStorage(
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
7
|
+
function createRedisStorage(client) {
|
|
8
|
+
const connectionPromise = client.connect();
|
|
9
|
+
const connectIfNeeded = async () => {
|
|
10
|
+
if (client.isReady) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
await connectionPromise;
|
|
14
|
+
};
|
|
11
15
|
// source https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage
|
|
12
16
|
return (0, axios_cache_interceptor_1.buildStorage)({
|
|
13
17
|
async find(key) {
|
|
18
|
+
await connectIfNeeded();
|
|
14
19
|
const result = await client.get(`${KEY_PREFIX}${key}`);
|
|
15
20
|
return result ? JSON.parse(result) : undefined;
|
|
16
21
|
},
|
|
17
22
|
// eslint-disable-next-line complexity
|
|
18
23
|
async set(key, value, req) {
|
|
24
|
+
await connectIfNeeded();
|
|
19
25
|
await client.set(`${KEY_PREFIX}${key}`, JSON.stringify(value), {
|
|
20
26
|
PXAT:
|
|
21
27
|
// We don't want to keep indefinitely values in the storage if
|
|
@@ -33,6 +39,7 @@ function createRedisStorage(redisEndpoint) {
|
|
|
33
39
|
});
|
|
34
40
|
},
|
|
35
41
|
async remove(key) {
|
|
42
|
+
await connectIfNeeded();
|
|
36
43
|
await client.del(`${KEY_PREFIX}${key}`);
|
|
37
44
|
},
|
|
38
45
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambda-essentials-ts",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.6",
|
|
4
4
|
"description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"newrelic": "^12.0.0",
|
|
83
|
-
"
|
|
83
|
+
"redis": "5.10.0"
|
|
84
84
|
}
|
|
85
85
|
}
|