descript-redis-cache 4.0.3 → 4.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 +1 -4
- package/build/index.d.ts +7 -5
- package/build/index.js +37 -21
- 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
@@ -15,7 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
15
|
};
|
16
16
|
var _Cache_instances, _Cache_client, _Cache_logger, _Cache_options, _Cache_normalizeKey, _Cache_log;
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.Cache = void 0;
|
18
|
+
exports.EVENT = exports.Cache = void 0;
|
19
19
|
const node_crypto_1 = require("node:crypto");
|
20
20
|
const descript_1 = __importDefault(require("descript"));
|
21
21
|
const ioredis_1 = require("ioredis");
|
@@ -36,10 +36,10 @@ class Cache {
|
|
36
36
|
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Cluster(__classPrivateFieldGet(this, _Cache_options, "f").redis.startupNodes, __classPrivateFieldGet(this, _Cache_options, "f").redis.options), "f");
|
37
37
|
}
|
38
38
|
else {
|
39
|
-
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Redis(__classPrivateFieldGet(this, _Cache_options, "f").redis
|
39
|
+
__classPrivateFieldSet(this, _Cache_client, new ioredis_1.Redis(__classPrivateFieldGet(this, _Cache_options, "f").redis), "f");
|
40
40
|
}
|
41
41
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
42
|
-
type:
|
42
|
+
type: EVENT.REDIS_CACHE_INITIALIZED,
|
43
43
|
options: { ...__classPrivateFieldGet(this, _Cache_options, "f") },
|
44
44
|
});
|
45
45
|
}
|
@@ -50,7 +50,7 @@ class Cache {
|
|
50
50
|
const normalizedKey = __classPrivateFieldGet(this, _Cache_instances, "m", _Cache_normalizeKey).call(this, key);
|
51
51
|
return new Promise((resolve, reject) => {
|
52
52
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
53
|
-
type:
|
53
|
+
type: EVENT.REDIS_CACHE_READ_START,
|
54
54
|
key,
|
55
55
|
normalizedKey,
|
56
56
|
});
|
@@ -62,7 +62,7 @@ class Cache {
|
|
62
62
|
const networkTimer = process.hrtime(networkTimerStart);
|
63
63
|
const totalTimer = process.hrtime(totalTimerStart);
|
64
64
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
65
|
-
type:
|
65
|
+
type: EVENT.REDIS_CACHE_READ_TIMEOUT,
|
66
66
|
key,
|
67
67
|
normalizedKey,
|
68
68
|
timers: {
|
@@ -71,7 +71,7 @@ class Cache {
|
|
71
71
|
},
|
72
72
|
});
|
73
73
|
reject(descript_1.default.error({
|
74
|
-
id:
|
74
|
+
id: EVENT.REDIS_CACHE_READ_TIMEOUT,
|
75
75
|
}));
|
76
76
|
}, __classPrivateFieldGet(this, _Cache_options, "f").readTimeout);
|
77
77
|
__classPrivateFieldGet(this, _Cache_client, "f").get(normalizedKey, (error, data) => {
|
@@ -83,7 +83,7 @@ class Cache {
|
|
83
83
|
if (error) {
|
84
84
|
const totalTimer = process.hrtime(totalTimerStart);
|
85
85
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
86
|
-
type:
|
86
|
+
type: EVENT.REDIS_CACHE_READ_ERROR,
|
87
87
|
error,
|
88
88
|
key,
|
89
89
|
normalizedKey,
|
@@ -93,13 +93,13 @@ class Cache {
|
|
93
93
|
},
|
94
94
|
});
|
95
95
|
reject(descript_1.default.error({
|
96
|
-
id:
|
96
|
+
id: EVENT.REDIS_CACHE_READ_ERROR,
|
97
97
|
}));
|
98
98
|
}
|
99
99
|
else if (!data) {
|
100
100
|
const totalTimer = process.hrtime(totalTimerStart);
|
101
101
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
102
|
-
type:
|
102
|
+
type: EVENT.REDIS_CACHE_READ_KEY_NOT_FOUND,
|
103
103
|
key,
|
104
104
|
normalizedKey,
|
105
105
|
timers: {
|
@@ -108,7 +108,7 @@ class Cache {
|
|
108
108
|
},
|
109
109
|
});
|
110
110
|
reject(descript_1.default.error({
|
111
|
-
id:
|
111
|
+
id: EVENT.REDIS_CACHE_READ_KEY_NOT_FOUND,
|
112
112
|
}));
|
113
113
|
}
|
114
114
|
else {
|
@@ -119,7 +119,7 @@ class Cache {
|
|
119
119
|
catch (error) {
|
120
120
|
const totalTimer = process.hrtime(totalTimerStart);
|
121
121
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
122
|
-
type:
|
122
|
+
type: EVENT.REDIS_CACHE_JSON_PARSING_FAILED,
|
123
123
|
data,
|
124
124
|
error,
|
125
125
|
key,
|
@@ -130,13 +130,13 @@ class Cache {
|
|
130
130
|
},
|
131
131
|
});
|
132
132
|
reject(descript_1.default.error({
|
133
|
-
id:
|
133
|
+
id: EVENT.REDIS_CACHE_JSON_PARSING_FAILED,
|
134
134
|
}));
|
135
135
|
return;
|
136
136
|
}
|
137
137
|
const totalTimer = process.hrtime(totalTimerStart);
|
138
138
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
139
|
-
type:
|
139
|
+
type: EVENT.REDIS_CACHE_READ_DONE,
|
140
140
|
data,
|
141
141
|
key,
|
142
142
|
normalizedKey,
|
@@ -158,7 +158,7 @@ class Cache {
|
|
158
158
|
const normalizedKey = __classPrivateFieldGet(this, _Cache_instances, "m", _Cache_normalizeKey).call(this, key);
|
159
159
|
return new Promise((resolve, reject) => {
|
160
160
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
161
|
-
type:
|
161
|
+
type: EVENT.REDIS_CACHE_WRITE_START,
|
162
162
|
key,
|
163
163
|
normalizedKey,
|
164
164
|
});
|
@@ -169,7 +169,7 @@ class Cache {
|
|
169
169
|
catch (error) {
|
170
170
|
const totalTimer = process.hrtime(totalTimerStart);
|
171
171
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
172
|
-
type:
|
172
|
+
type: EVENT.REDIS_CACHE_JSON_STRINGIFY_FAILED,
|
173
173
|
data: value,
|
174
174
|
error,
|
175
175
|
key,
|
@@ -179,7 +179,7 @@ class Cache {
|
|
179
179
|
},
|
180
180
|
});
|
181
181
|
reject(descript_1.default.error({
|
182
|
-
id:
|
182
|
+
id: EVENT.REDIS_CACHE_JSON_STRINGIFY_FAILED,
|
183
183
|
}));
|
184
184
|
return;
|
185
185
|
}
|
@@ -190,7 +190,7 @@ class Cache {
|
|
190
190
|
const totalTimer = process.hrtime(totalTimerStart);
|
191
191
|
if (error) {
|
192
192
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
193
|
-
type:
|
193
|
+
type: EVENT.REDIS_CACHE_WRITE_ERROR,
|
194
194
|
error,
|
195
195
|
key,
|
196
196
|
normalizedKey,
|
@@ -200,12 +200,12 @@ class Cache {
|
|
200
200
|
},
|
201
201
|
});
|
202
202
|
reject(descript_1.default.error({
|
203
|
-
id:
|
203
|
+
id: EVENT.REDIS_CACHE_WRITE_ERROR,
|
204
204
|
}));
|
205
205
|
}
|
206
206
|
else if (!done) {
|
207
207
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
208
|
-
type:
|
208
|
+
type: EVENT.REDIS_CACHE_WRITE_FAILED,
|
209
209
|
key,
|
210
210
|
normalizedKey,
|
211
211
|
timers: {
|
@@ -214,12 +214,12 @@ class Cache {
|
|
214
214
|
},
|
215
215
|
});
|
216
216
|
reject(descript_1.default.error({
|
217
|
-
id:
|
217
|
+
id: EVENT.REDIS_CACHE_WRITE_FAILED,
|
218
218
|
}));
|
219
219
|
}
|
220
220
|
else {
|
221
221
|
__classPrivateFieldGet(this, _Cache_instances, "m", _Cache_log).call(this, {
|
222
|
-
type:
|
222
|
+
type: EVENT.REDIS_CACHE_WRITE_DONE,
|
223
223
|
data: json,
|
224
224
|
key,
|
225
225
|
normalizedKey,
|
@@ -243,3 +243,19 @@ _Cache_client = new WeakMap(), _Cache_logger = new WeakMap(), _Cache_options = n
|
|
243
243
|
__classPrivateFieldGet(this, _Cache_logger, "f").log(event);
|
244
244
|
}
|
245
245
|
};
|
246
|
+
var EVENT;
|
247
|
+
(function (EVENT) {
|
248
|
+
EVENT["REDIS_CACHE_INITIALIZED"] = "REDIS_CACHE_INITIALIZED";
|
249
|
+
EVENT["REDIS_CACHE_ERROR"] = "REDIS_CACHE_ERROR";
|
250
|
+
EVENT["REDIS_CACHE_JSON_PARSING_FAILED"] = "REDIS_CACHE_JSON_PARSING_FAILED";
|
251
|
+
EVENT["REDIS_CACHE_JSON_STRINGIFY_FAILED"] = "REDIS_CACHE_JSON_STRINGIFY_FAILED";
|
252
|
+
EVENT["REDIS_CACHE_READ_DONE"] = "REDIS_CACHE_READ_DONE";
|
253
|
+
EVENT["REDIS_CACHE_READ_ERROR"] = "REDIS_CACHE_READ_ERROR";
|
254
|
+
EVENT["REDIS_CACHE_READ_KEY_NOT_FOUND"] = "REDIS_CACHE_READ_KEY_NOT_FOUND";
|
255
|
+
EVENT["REDIS_CACHE_READ_START"] = "REDIS_CACHE_READ_START";
|
256
|
+
EVENT["REDIS_CACHE_READ_TIMEOUT"] = "REDIS_CACHE_READ_TIMEOUT";
|
257
|
+
EVENT["REDIS_CACHE_WRITE_DONE"] = "REDIS_CACHE_WRITE_DONE";
|
258
|
+
EVENT["REDIS_CACHE_WRITE_ERROR"] = "REDIS_CACHE_WRITE_ERROR";
|
259
|
+
EVENT["REDIS_CACHE_WRITE_FAILED"] = "REDIS_CACHE_WRITE_FAILED";
|
260
|
+
EVENT["REDIS_CACHE_WRITE_START"] = "REDIS_CACHE_WRITE_START";
|
261
|
+
})(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.4",
|
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
|
}
|