descript-redis-cache 4.0.3 → 4.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/README.md +1 -4
- package/build/index.d.ts +7 -5
- package/build/index.js +45 -32
- package/package.json +5 -5
package/README.md
CHANGED
@@ -38,10 +38,7 @@ export interface Options {
|
|
38
38
|
generation?: number;
|
39
39
|
// read timeout in milliseconds (default: 100)
|
40
40
|
readTimeout?: number;
|
41
|
-
redis:
|
42
|
-
{ startupNodes: ClusterNode[], options?: ClusterOptions } |
|
43
|
-
{ options: RedisOptions }
|
44
|
-
);
|
41
|
+
redis: RedisOptions | { startupNodes: ClusterNode[], options?: ClusterOptions };
|
45
42
|
}
|
46
43
|
```
|
47
44
|
|
package/build/index.d.ts
CHANGED
@@ -5,12 +5,10 @@ export interface Options {
|
|
5
5
|
defaultKeyTTL?: number;
|
6
6
|
generation?: number;
|
7
7
|
readTimeout?: number;
|
8
|
-
redis:
|
8
|
+
redis: RedisOptions | {
|
9
9
|
startupNodes: ClusterNode[];
|
10
10
|
options?: ClusterOptions;
|
11
|
-
}
|
12
|
-
options: RedisOptions;
|
13
|
-
});
|
11
|
+
};
|
14
12
|
}
|
15
13
|
interface Logger {
|
16
14
|
log(event: LoggerEvent): void;
|
@@ -18,6 +16,9 @@ interface Logger {
|
|
18
16
|
export type LoggerEvent = ({
|
19
17
|
type: EVENT.REDIS_CACHE_INITIALIZED;
|
20
18
|
options: Options;
|
19
|
+
} | {
|
20
|
+
type: EVENT.REDIS_CACHE_ERROR;
|
21
|
+
error: Error;
|
21
22
|
} | {
|
22
23
|
type: EVENT.REDIS_CACHE_READ_START;
|
23
24
|
key: string;
|
@@ -119,8 +120,9 @@ export declare class Cache<Result> implements CacheInterface<Result> {
|
|
119
120
|
maxage?: number;
|
120
121
|
}): Promise<void>;
|
121
122
|
}
|
122
|
-
export declare
|
123
|
+
export declare enum EVENT {
|
123
124
|
REDIS_CACHE_INITIALIZED = "REDIS_CACHE_INITIALIZED",
|
125
|
+
REDIS_CACHE_ERROR = "REDIS_CACHE_ERROR",
|
124
126
|
REDIS_CACHE_JSON_PARSING_FAILED = "REDIS_CACHE_JSON_PARSING_FAILED",
|
125
127
|
REDIS_CACHE_JSON_STRINGIFY_FAILED = "REDIS_CACHE_JSON_STRINGIFY_FAILED",
|
126
128
|
REDIS_CACHE_READ_DONE = "REDIS_CACHE_READ_DONE",
|
package/build/index.js
CHANGED
@@ -10,14 +10,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
12
|
};
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
|
-
};
|
16
13
|
var _Cache_instances, _Cache_client, _Cache_logger, _Cache_options, _Cache_normalizeKey, _Cache_log;
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.Cache = void 0;
|
15
|
+
exports.EVENT = exports.Cache = void 0;
|
19
16
|
const node_crypto_1 = require("node:crypto");
|
20
|
-
const descript_1 =
|
17
|
+
const descript_1 = require("descript");
|
21
18
|
const ioredis_1 = require("ioredis");
|
22
19
|
class Cache {
|
23
20
|
constructor(options, logger) {
|
@@ -36,10 +33,10 @@ class Cache {
|
|
36
33
|
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Cluster(__classPrivateFieldGet(this, _Cache_options, "f").redis.startupNodes, __classPrivateFieldGet(this, _Cache_options, "f").redis.options), "f");
|
37
34
|
}
|
38
35
|
else {
|
39
|
-
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Redis(__classPrivateFieldGet(this, _Cache_options, "f").redis
|
36
|
+
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Redis(__classPrivateFieldGet(this, _Cache_options, "f").redis), "f");
|
40
37
|
}
|
41
38
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
42
|
-
type:
|
39
|
+
type: EVENT.REDIS_CACHE_INITIALIZED,
|
43
40
|
options: { ...__classPrivateFieldGet(this, _Cache_options, "f") },
|
44
41
|
});
|
45
42
|
}
|
@@ -50,7 +47,7 @@ class Cache {
|
|
50
47
|
const normalizedKey = __classPrivateFieldGet(this, _Cache_instances, "m", _Cache_normalizeKey).call(this, key);
|
51
48
|
return new Promise((resolve, reject) => {
|
52
49
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
53
|
-
type:
|
50
|
+
type: EVENT.REDIS_CACHE_READ_START,
|
54
51
|
key,
|
55
52
|
normalizedKey,
|
56
53
|
});
|
@@ -62,7 +59,7 @@ class Cache {
|
|
62
59
|
const networkTimer = process.hrtime(networkTimerStart);
|
63
60
|
const totalTimer = process.hrtime(totalTimerStart);
|
64
61
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
65
|
-
type:
|
62
|
+
type: EVENT.REDIS_CACHE_READ_TIMEOUT,
|
66
63
|
key,
|
67
64
|
normalizedKey,
|
68
65
|
timers: {
|
@@ -70,8 +67,8 @@ class Cache {
|
|
70
67
|
total: totalTimer,
|
71
68
|
},
|
72
69
|
});
|
73
|
-
reject(descript_1.
|
74
|
-
id:
|
70
|
+
reject((0, descript_1.error)({
|
71
|
+
id: EVENT.REDIS_CACHE_READ_TIMEOUT,
|
75
72
|
}));
|
76
73
|
}, __classPrivateFieldGet(this, _Cache_options, "f").readTimeout);
|
77
74
|
__classPrivateFieldGet(this, _Cache_client, "f").get(normalizedKey, (error, data) => {
|
@@ -83,7 +80,7 @@ class Cache {
|
|
83
80
|
if (error) {
|
84
81
|
const totalTimer = process.hrtime(totalTimerStart);
|
85
82
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
86
|
-
type:
|
83
|
+
type: EVENT.REDIS_CACHE_READ_ERROR,
|
87
84
|
error,
|
88
85
|
key,
|
89
86
|
normalizedKey,
|
@@ -92,14 +89,14 @@ class Cache {
|
|
92
89
|
total: totalTimer,
|
93
90
|
},
|
94
91
|
});
|
95
|
-
reject(descript_1.
|
96
|
-
id:
|
92
|
+
reject((0, descript_1.error)({
|
93
|
+
id: EVENT.REDIS_CACHE_READ_ERROR,
|
97
94
|
}));
|
98
95
|
}
|
99
96
|
else if (!data) {
|
100
97
|
const totalTimer = process.hrtime(totalTimerStart);
|
101
98
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
102
|
-
type:
|
99
|
+
type: EVENT.REDIS_CACHE_READ_KEY_NOT_FOUND,
|
103
100
|
key,
|
104
101
|
normalizedKey,
|
105
102
|
timers: {
|
@@ -107,8 +104,8 @@ class Cache {
|
|
107
104
|
total: totalTimer,
|
108
105
|
},
|
109
106
|
});
|
110
|
-
reject(descript_1.
|
111
|
-
id:
|
107
|
+
reject((0, descript_1.error)({
|
108
|
+
id: EVENT.REDIS_CACHE_READ_KEY_NOT_FOUND,
|
112
109
|
}));
|
113
110
|
}
|
114
111
|
else {
|
@@ -119,7 +116,7 @@ class Cache {
|
|
119
116
|
catch (error) {
|
120
117
|
const totalTimer = process.hrtime(totalTimerStart);
|
121
118
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
122
|
-
type:
|
119
|
+
type: EVENT.REDIS_CACHE_JSON_PARSING_FAILED,
|
123
120
|
data,
|
124
121
|
error,
|
125
122
|
key,
|
@@ -129,14 +126,14 @@ class Cache {
|
|
129
126
|
total: totalTimer,
|
130
127
|
},
|
131
128
|
});
|
132
|
-
reject(descript_1.
|
133
|
-
id:
|
129
|
+
reject((0, descript_1.error)({
|
130
|
+
id: EVENT.REDIS_CACHE_JSON_PARSING_FAILED,
|
134
131
|
}));
|
135
132
|
return;
|
136
133
|
}
|
137
134
|
const totalTimer = process.hrtime(totalTimerStart);
|
138
135
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
139
|
-
type:
|
136
|
+
type: EVENT.REDIS_CACHE_READ_DONE,
|
140
137
|
data,
|
141
138
|
key,
|
142
139
|
normalizedKey,
|
@@ -158,7 +155,7 @@ class Cache {
|
|
158
155
|
const normalizedKey = __classPrivateFieldGet(this, _Cache_instances, "m", _Cache_normalizeKey).call(this, key);
|
159
156
|
return new Promise((resolve, reject) => {
|
160
157
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
161
|
-
type:
|
158
|
+
type: EVENT.REDIS_CACHE_WRITE_START,
|
162
159
|
key,
|
163
160
|
normalizedKey,
|
164
161
|
});
|
@@ -169,7 +166,7 @@ class Cache {
|
|
169
166
|
catch (error) {
|
170
167
|
const totalTimer = process.hrtime(totalTimerStart);
|
171
168
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
172
|
-
type:
|
169
|
+
type: EVENT.REDIS_CACHE_JSON_STRINGIFY_FAILED,
|
173
170
|
data: value,
|
174
171
|
error,
|
175
172
|
key,
|
@@ -178,8 +175,8 @@ class Cache {
|
|
178
175
|
total: totalTimer,
|
179
176
|
},
|
180
177
|
});
|
181
|
-
reject(descript_1.
|
182
|
-
id:
|
178
|
+
reject((0, descript_1.error)({
|
179
|
+
id: EVENT.REDIS_CACHE_JSON_STRINGIFY_FAILED,
|
183
180
|
}));
|
184
181
|
return;
|
185
182
|
}
|
@@ -190,7 +187,7 @@ class Cache {
|
|
190
187
|
const totalTimer = process.hrtime(totalTimerStart);
|
191
188
|
if (error) {
|
192
189
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
193
|
-
type:
|
190
|
+
type: EVENT.REDIS_CACHE_WRITE_ERROR,
|
194
191
|
error,
|
195
192
|
key,
|
196
193
|
normalizedKey,
|
@@ -199,13 +196,13 @@ class Cache {
|
|
199
196
|
total: totalTimer,
|
200
197
|
},
|
201
198
|
});
|
202
|
-
reject(descript_1.
|
203
|
-
id:
|
199
|
+
reject((0, descript_1.error)({
|
200
|
+
id: EVENT.REDIS_CACHE_WRITE_ERROR,
|
204
201
|
}));
|
205
202
|
}
|
206
203
|
else if (!done) {
|
207
204
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
208
|
-
type:
|
205
|
+
type: EVENT.REDIS_CACHE_WRITE_FAILED,
|
209
206
|
key,
|
210
207
|
normalizedKey,
|
211
208
|
timers: {
|
@@ -213,13 +210,13 @@ class Cache {
|
|
213
210
|
total: totalTimer,
|
214
211
|
},
|
215
212
|
});
|
216
|
-
reject(descript_1.
|
217
|
-
id:
|
213
|
+
reject((0, descript_1.error)({
|
214
|
+
id: EVENT.REDIS_CACHE_WRITE_FAILED,
|
218
215
|
}));
|
219
216
|
}
|
220
217
|
else {
|
221
218
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
222
|
-
type:
|
219
|
+
type: EVENT.REDIS_CACHE_WRITE_DONE,
|
223
220
|
data: json,
|
224
221
|
key,
|
225
222
|
normalizedKey,
|
@@ -243,3 +240,19 @@ _Cache_client = new WeakMap(), _Cache_logger = new WeakMap(), _Cache_options = n
|
|
243
240
|
__classPrivateFieldGet(this, _Cache_logger, "f").log(event);
|
244
241
|
}
|
245
242
|
};
|
243
|
+
var EVENT;
|
244
|
+
(function (EVENT) {
|
245
|
+
EVENT["REDIS_CACHE_INITIALIZED"] = "REDIS_CACHE_INITIALIZED";
|
246
|
+
EVENT["REDIS_CACHE_ERROR"] = "REDIS_CACHE_ERROR";
|
247
|
+
EVENT["REDIS_CACHE_JSON_PARSING_FAILED"] = "REDIS_CACHE_JSON_PARSING_FAILED";
|
248
|
+
EVENT["REDIS_CACHE_JSON_STRINGIFY_FAILED"] = "REDIS_CACHE_JSON_STRINGIFY_FAILED";
|
249
|
+
EVENT["REDIS_CACHE_READ_DONE"] = "REDIS_CACHE_READ_DONE";
|
250
|
+
EVENT["REDIS_CACHE_READ_ERROR"] = "REDIS_CACHE_READ_ERROR";
|
251
|
+
EVENT["REDIS_CACHE_READ_KEY_NOT_FOUND"] = "REDIS_CACHE_READ_KEY_NOT_FOUND";
|
252
|
+
EVENT["REDIS_CACHE_READ_START"] = "REDIS_CACHE_READ_START";
|
253
|
+
EVENT["REDIS_CACHE_READ_TIMEOUT"] = "REDIS_CACHE_READ_TIMEOUT";
|
254
|
+
EVENT["REDIS_CACHE_WRITE_DONE"] = "REDIS_CACHE_WRITE_DONE";
|
255
|
+
EVENT["REDIS_CACHE_WRITE_ERROR"] = "REDIS_CACHE_WRITE_ERROR";
|
256
|
+
EVENT["REDIS_CACHE_WRITE_FAILED"] = "REDIS_CACHE_WRITE_FAILED";
|
257
|
+
EVENT["REDIS_CACHE_WRITE_START"] = "REDIS_CACHE_WRITE_START";
|
258
|
+
})(EVENT || (exports.EVENT = EVENT = {}));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "descript-redis-cache",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.5",
|
4
4
|
"description": "plugin for descript to use redis as cache",
|
5
5
|
"main": "./build/index.js",
|
6
6
|
"types": "./build/index.d.ts",
|
@@ -40,11 +40,11 @@
|
|
40
40
|
"@eslint/js": "^9.14.0",
|
41
41
|
"@stylistic/eslint-plugin-ts": "^2.11.0",
|
42
42
|
"@types/eslint__js": "^8.42.3",
|
43
|
-
"@types/node": "^22.
|
43
|
+
"@types/node": "^22.10.0",
|
44
44
|
"descript": "^4.0.5",
|
45
45
|
"eslint": "^9.15.0",
|
46
|
-
"typescript": "^5.
|
47
|
-
"typescript-eslint": "^8.
|
48
|
-
"vitest": "^2.1.
|
46
|
+
"typescript": "^5.7.2",
|
47
|
+
"typescript-eslint": "^8.16.0",
|
48
|
+
"vitest": "^2.1.6"
|
49
49
|
}
|
50
50
|
}
|