@naman_deep_singh/cache 1.6.0 → 1.7.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 +1 -1
- package/dist/cjs/adapters/index.js +7 -17
- package/dist/cjs/adapters/memcache/MemcacheCache.js +11 -10
- package/dist/cjs/adapters/memory/MemoryCache.js +15 -14
- package/dist/cjs/adapters/redis/RedisCache.js +16 -15
- package/dist/cjs/core/BaseCache.js +4 -3
- package/dist/cjs/core/factory.js +13 -10
- package/dist/cjs/core/index.js +5 -17
- package/dist/cjs/core/interfaces/index.js +0 -16
- package/dist/cjs/errors/index.js +5 -16
- package/dist/cjs/middleware/express/index.js +5 -15
- package/dist/cjs/middleware/index.js +5 -15
- package/dist/cjs/session/SessionStore.js +17 -16
- package/dist/cjs/session/index.js +3 -15
- package/dist/esm/adapters/index.js +3 -3
- package/dist/esm/adapters/memcache/MemcacheCache.js +3 -2
- package/dist/esm/adapters/memory/MemoryCache.js +3 -2
- package/dist/esm/adapters/redis/RedisCache.js +3 -2
- package/dist/esm/core/BaseCache.js +2 -1
- package/dist/esm/core/factory.js +5 -2
- package/dist/esm/core/index.js +2 -3
- package/dist/esm/core/interfaces/index.js +1 -2
- package/dist/esm/errors/index.js +2 -2
- package/dist/esm/middleware/express/index.js +1 -1
- package/dist/esm/middleware/index.js +1 -1
- package/dist/esm/session/SessionStore.js +2 -1
- package/dist/esm/session/index.js +1 -1
- package/dist/types/adapters/index.d.ts +3 -3
- package/dist/types/adapters/memcache/MemcacheCache.d.ts +1 -1
- package/dist/types/adapters/memory/MemoryCache.d.ts +1 -1
- package/dist/types/adapters/redis/RedisCache.d.ts +1 -1
- package/dist/types/core/BaseCache.d.ts +1 -1
- package/dist/types/core/factory.d.ts +1 -1
- package/dist/types/core/index.d.ts +3 -3
- package/dist/types/core/interfaces/index.d.ts +2 -2
- package/dist/types/errors/index.d.ts +2 -2
- package/dist/types/middleware/express/{cacheMiddleware.d.ts → cache.middleware.d.ts} +2 -2
- package/dist/types/middleware/express/index.d.ts +1 -1
- package/dist/types/middleware/index.d.ts +1 -1
- package/dist/types/session/SessionStore.d.ts +1 -1
- package/dist/types/session/index.d.ts +1 -1
- package/package.json +33 -2
- /package/dist/cjs/middleware/express/{cacheMiddleware.js → cache.middleware.js} +0 -0
- /package/dist/esm/middleware/express/{cacheMiddleware.js → cache.middleware.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @naman_deep_singh/cache
|
|
2
2
|
|
|
3
|
-
**Version:** 1.
|
|
3
|
+
**Version:** 1.7.0 (with Redis Clustering support)
|
|
4
4
|
|
|
5
5
|
A flexible, extensible caching layer with support for Redis, Memcache, and in-memory caches. Includes session management, health checks, and Express middleware.
|
|
6
6
|
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
exports.RedisCache = exports.MemoryCache = exports.MemcacheCache = void 0;
|
|
4
|
+
var index_js_1 = require("./memcache/index.js");
|
|
5
|
+
Object.defineProperty(exports, "MemcacheCache", { enumerable: true, get: function () { return index_js_1.MemcacheCache; } });
|
|
6
|
+
var index_js_2 = require("./memory/index.js");
|
|
7
|
+
Object.defineProperty(exports, "MemoryCache", { enumerable: true, get: function () { return index_js_2.MemoryCache; } });
|
|
8
|
+
var index_js_3 = require("./redis/index.js");
|
|
9
|
+
Object.defineProperty(exports, "RedisCache", { enumerable: true, get: function () { return index_js_3.RedisCache; } });
|
|
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MemcacheCache = void 0;
|
|
7
7
|
const memcached_1 = __importDefault(require("memcached"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const BaseCache_js_1 = require("../../core/BaseCache.js");
|
|
9
|
+
const CacheError_js_1 = require("../../errors/CacheError.js");
|
|
10
|
+
const cacheErrorCodes_js_1 = require("../../errors/cacheErrorCodes.js");
|
|
11
|
+
class MemcacheCache extends BaseCache_js_1.BaseCache {
|
|
11
12
|
constructor(memcacheConfig) {
|
|
12
13
|
super(memcacheConfig);
|
|
13
14
|
this.memcacheConfig = memcacheConfig;
|
|
@@ -30,7 +31,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
30
31
|
await this.ping();
|
|
31
32
|
}
|
|
32
33
|
catch (error) {
|
|
33
|
-
throw new
|
|
34
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_CONNECTION_FAILED, {
|
|
34
35
|
adapter: 'memcache',
|
|
35
36
|
operation: 'connect',
|
|
36
37
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -55,7 +56,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
55
56
|
return value !== null;
|
|
56
57
|
}
|
|
57
58
|
catch (error) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
59
60
|
adapter: 'memcache',
|
|
60
61
|
operation: 'exists',
|
|
61
62
|
details: { key },
|
|
@@ -83,7 +84,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
catch (error) {
|
|
86
|
-
throw new
|
|
87
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_KEY_NOT_FOUND, {
|
|
87
88
|
adapter: 'memcache',
|
|
88
89
|
operation: 'get',
|
|
89
90
|
details: { key },
|
|
@@ -100,7 +101,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
catch (error) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
104
105
|
adapter: 'memcache',
|
|
105
106
|
operation: 'set',
|
|
106
107
|
details: { key },
|
|
@@ -117,7 +118,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
catch (error) {
|
|
120
|
-
throw new
|
|
121
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
121
122
|
adapter: 'memcache',
|
|
122
123
|
operation: 'delete',
|
|
123
124
|
details: { key },
|
|
@@ -133,7 +134,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
catch (error) {
|
|
136
|
-
throw new
|
|
137
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_OPERATION_TIMEOUT, {
|
|
137
138
|
adapter: 'memcache',
|
|
138
139
|
operation: 'clear',
|
|
139
140
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -161,7 +162,7 @@ class MemcacheCache extends index_js_1.BaseCache {
|
|
|
161
162
|
this.isConnected = false;
|
|
162
163
|
}
|
|
163
164
|
catch (error) {
|
|
164
|
-
throw new
|
|
165
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
165
166
|
adapter: 'memcache',
|
|
166
167
|
operation: 'close',
|
|
167
168
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MemoryCache = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const BaseCache_js_1 = require("../../core/BaseCache.js");
|
|
5
|
+
const CacheError_js_1 = require("../../errors/CacheError.js");
|
|
6
|
+
const cacheErrorCodes_js_1 = require("../../errors/cacheErrorCodes.js");
|
|
6
7
|
/**
|
|
7
8
|
* In-memory cache adapter for development and testing
|
|
8
9
|
*/
|
|
9
|
-
class MemoryCache extends
|
|
10
|
+
class MemoryCache extends BaseCache_js_1.BaseCache {
|
|
10
11
|
constructor(memoryCacheConfig) {
|
|
11
12
|
super(memoryCacheConfig);
|
|
12
13
|
this.memoryCacheConfig = memoryCacheConfig;
|
|
@@ -50,7 +51,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
50
51
|
return entry.value;
|
|
51
52
|
}
|
|
52
53
|
catch (error) {
|
|
53
|
-
throw new
|
|
54
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_KEY_NOT_FOUND, {
|
|
54
55
|
adapter: 'memory',
|
|
55
56
|
operation: 'get',
|
|
56
57
|
details: { key },
|
|
@@ -79,7 +80,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
79
80
|
this.recordSet();
|
|
80
81
|
}
|
|
81
82
|
catch (error) {
|
|
82
|
-
throw new
|
|
83
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
83
84
|
adapter: 'memory',
|
|
84
85
|
operation: 'set',
|
|
85
86
|
details: { key },
|
|
@@ -100,7 +101,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
100
101
|
return deleted;
|
|
101
102
|
}
|
|
102
103
|
catch (error) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
104
105
|
adapter: 'memory',
|
|
105
106
|
operation: 'delete',
|
|
106
107
|
details: { key },
|
|
@@ -126,7 +127,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
126
127
|
return true;
|
|
127
128
|
}
|
|
128
129
|
catch (error) {
|
|
129
|
-
throw new
|
|
130
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
130
131
|
adapter: 'memory',
|
|
131
132
|
operation: 'exists',
|
|
132
133
|
details: { key },
|
|
@@ -153,7 +154,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
catch (error) {
|
|
156
|
-
throw new
|
|
157
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_OPERATION_TIMEOUT, {
|
|
157
158
|
adapter: 'memory',
|
|
158
159
|
operation: 'clear',
|
|
159
160
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -189,7 +190,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
189
190
|
return result;
|
|
190
191
|
}
|
|
191
192
|
catch (error) {
|
|
192
|
-
throw new
|
|
193
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
193
194
|
adapter: 'memory',
|
|
194
195
|
operation: 'getMultiple',
|
|
195
196
|
details: { keys },
|
|
@@ -211,7 +212,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
211
212
|
this.stats.sets += Object.keys(data).length;
|
|
212
213
|
}
|
|
213
214
|
catch (error) {
|
|
214
|
-
throw new
|
|
215
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
215
216
|
adapter: 'memory',
|
|
216
217
|
operation: 'setMultiple',
|
|
217
218
|
details: { keys: Object.keys(data) },
|
|
@@ -235,7 +236,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
235
236
|
return count;
|
|
236
237
|
}
|
|
237
238
|
catch (error) {
|
|
238
|
-
throw new
|
|
239
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
239
240
|
adapter: 'memory',
|
|
240
241
|
operation: 'deleteMultiple',
|
|
241
242
|
details: { keys },
|
|
@@ -262,7 +263,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
262
263
|
return value;
|
|
263
264
|
}
|
|
264
265
|
catch (error) {
|
|
265
|
-
throw new
|
|
266
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
266
267
|
adapter: 'memory',
|
|
267
268
|
operation: 'increment',
|
|
268
269
|
details: { key },
|
|
@@ -289,7 +290,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
289
290
|
return value;
|
|
290
291
|
}
|
|
291
292
|
catch (error) {
|
|
292
|
-
throw new
|
|
293
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
293
294
|
adapter: 'memory',
|
|
294
295
|
operation: 'decrement',
|
|
295
296
|
details: { key },
|
|
@@ -319,7 +320,7 @@ class MemoryCache extends index_js_1.BaseCache {
|
|
|
319
320
|
this.store.clear();
|
|
320
321
|
}
|
|
321
322
|
catch (error) {
|
|
322
|
-
throw new
|
|
323
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
323
324
|
adapter: 'memory',
|
|
324
325
|
operation: 'close',
|
|
325
326
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedisCache = void 0;
|
|
4
4
|
const redis_1 = require("redis");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const BaseCache_js_1 = require("../../core/BaseCache.js");
|
|
6
|
+
const CacheError_js_1 = require("../../errors/CacheError.js");
|
|
7
|
+
const cacheErrorCodes_js_1 = require("../../errors/cacheErrorCodes.js");
|
|
7
8
|
/**
|
|
8
9
|
* Redis cache adapter
|
|
9
10
|
*/
|
|
10
|
-
class RedisCache extends
|
|
11
|
+
class RedisCache extends BaseCache_js_1.BaseCache {
|
|
11
12
|
constructor(redisConfig) {
|
|
12
13
|
super(redisConfig);
|
|
13
14
|
this.redisConfig = redisConfig;
|
|
@@ -70,7 +71,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
catch (error) {
|
|
73
|
-
throw new
|
|
74
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_CONNECTION_FAILED, {
|
|
74
75
|
adapter: 'redis',
|
|
75
76
|
operation: 'connect',
|
|
76
77
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -101,7 +102,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
101
102
|
return this.deserialize(value);
|
|
102
103
|
}
|
|
103
104
|
catch (error) {
|
|
104
|
-
throw new
|
|
105
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
105
106
|
adapter: 'redis',
|
|
106
107
|
operation: 'get',
|
|
107
108
|
details: { key },
|
|
@@ -127,7 +128,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
127
128
|
this.recordSet();
|
|
128
129
|
}
|
|
129
130
|
catch (error) {
|
|
130
|
-
throw new
|
|
131
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
131
132
|
adapter: 'redis',
|
|
132
133
|
operation: 'set',
|
|
133
134
|
details: { key },
|
|
@@ -147,7 +148,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
147
148
|
return result > 0;
|
|
148
149
|
}
|
|
149
150
|
catch (error) {
|
|
150
|
-
throw new
|
|
151
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
151
152
|
adapter: 'redis',
|
|
152
153
|
operation: 'delete',
|
|
153
154
|
details: { key },
|
|
@@ -166,7 +167,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
166
167
|
return result > 0;
|
|
167
168
|
}
|
|
168
169
|
catch (error) {
|
|
169
|
-
throw new
|
|
170
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
170
171
|
adapter: 'redis',
|
|
171
172
|
operation: 'exists',
|
|
172
173
|
details: { key },
|
|
@@ -197,7 +198,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
catch (error) {
|
|
200
|
-
throw new
|
|
201
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_OPERATION_TIMEOUT, {
|
|
201
202
|
adapter: 'redis',
|
|
202
203
|
operation: 'clear',
|
|
203
204
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -227,7 +228,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
227
228
|
return result;
|
|
228
229
|
}
|
|
229
230
|
catch (error) {
|
|
230
|
-
throw new
|
|
231
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
231
232
|
adapter: 'redis',
|
|
232
233
|
operation: 'getMultiple',
|
|
233
234
|
details: { keys },
|
|
@@ -264,7 +265,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
264
265
|
this.stats.sets += Object.keys(data).length;
|
|
265
266
|
}
|
|
266
267
|
catch (error) {
|
|
267
|
-
throw new
|
|
268
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
268
269
|
adapter: 'redis',
|
|
269
270
|
operation: 'setMultiple',
|
|
270
271
|
details: { keys: Object.keys(data) },
|
|
@@ -284,7 +285,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
284
285
|
return result;
|
|
285
286
|
}
|
|
286
287
|
catch (error) {
|
|
287
|
-
throw new
|
|
288
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
288
289
|
adapter: 'redis',
|
|
289
290
|
operation: 'deleteMultiple',
|
|
290
291
|
details: { keys },
|
|
@@ -302,7 +303,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
302
303
|
return await this.client.incrBy(fullKey, amount);
|
|
303
304
|
}
|
|
304
305
|
catch (error) {
|
|
305
|
-
throw new
|
|
306
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
306
307
|
adapter: 'redis',
|
|
307
308
|
operation: 'increment',
|
|
308
309
|
details: { key },
|
|
@@ -320,7 +321,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
320
321
|
return await this.client.decrBy(fullKey, amount);
|
|
321
322
|
}
|
|
322
323
|
catch (error) {
|
|
323
|
-
throw new
|
|
324
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
324
325
|
adapter: 'redis',
|
|
325
326
|
operation: 'decrement',
|
|
326
327
|
details: { key },
|
|
@@ -371,7 +372,7 @@ class RedisCache extends index_js_1.BaseCache {
|
|
|
371
372
|
}
|
|
372
373
|
}
|
|
373
374
|
catch (error) {
|
|
374
|
-
throw new
|
|
375
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
375
376
|
adapter: 'redis',
|
|
376
377
|
operation: 'close',
|
|
377
378
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseCache = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CacheError_js_1 = require("../errors/CacheError.js");
|
|
5
|
+
const cacheErrorCodes_js_1 = require("../errors/cacheErrorCodes.js");
|
|
5
6
|
/**
|
|
6
7
|
* Abstract base class for all cache adapters
|
|
7
8
|
*/
|
|
@@ -31,7 +32,7 @@ class BaseCache {
|
|
|
31
32
|
return JSON.parse(data);
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
|
-
throw new
|
|
35
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_DESERIALIZE_ERROR, {
|
|
35
36
|
adapter: this.config.adapter,
|
|
36
37
|
operation: 'deserialize',
|
|
37
38
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -46,7 +47,7 @@ class BaseCache {
|
|
|
46
47
|
return JSON.stringify(value);
|
|
47
48
|
}
|
|
48
49
|
catch (error) {
|
|
49
|
-
throw new
|
|
50
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_SERIALIZE_ERROR, {
|
|
50
51
|
adapter: this.config.adapter,
|
|
51
52
|
operation: 'serialize',
|
|
52
53
|
cause: error instanceof Error ? error : undefined,
|
package/dist/cjs/core/factory.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheFactory = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const MemcacheCache_js_1 = require("../adapters/memcache/MemcacheCache.js");
|
|
5
|
+
const MemoryCache_js_1 = require("../adapters/memory/MemoryCache.js");
|
|
6
|
+
const RedisCache_js_1 = require("../adapters/redis/RedisCache.js");
|
|
7
|
+
const CacheError_js_1 = require("../errors/CacheError.js");
|
|
8
|
+
const cacheErrorCodes_js_1 = require("../errors/cacheErrorCodes.js");
|
|
6
9
|
/**
|
|
7
10
|
* Factory for creating cache instances
|
|
8
11
|
*/
|
|
@@ -16,7 +19,7 @@ class CacheFactory {
|
|
|
16
19
|
const redisConfig = config;
|
|
17
20
|
// Validate: can't use both single + cluster
|
|
18
21
|
if (redisConfig.host && redisConfig.cluster) {
|
|
19
|
-
throw new
|
|
22
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_INVALID_CONFIG, {
|
|
20
23
|
adapter: 'redis',
|
|
21
24
|
operation: 'create',
|
|
22
25
|
details: {
|
|
@@ -26,7 +29,7 @@ class CacheFactory {
|
|
|
26
29
|
}
|
|
27
30
|
// Require either single or cluster
|
|
28
31
|
if (!redisConfig.host && !redisConfig.cluster) {
|
|
29
|
-
throw new
|
|
32
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_INVALID_CONFIG, {
|
|
30
33
|
adapter: 'redis',
|
|
31
34
|
operation: 'create',
|
|
32
35
|
details: {
|
|
@@ -34,13 +37,13 @@ class CacheFactory {
|
|
|
34
37
|
},
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
|
-
return new
|
|
40
|
+
return new RedisCache_js_1.RedisCache(redisConfig);
|
|
38
41
|
case 'memcache':
|
|
39
|
-
return new
|
|
42
|
+
return new MemcacheCache_js_1.MemcacheCache(config);
|
|
40
43
|
case 'memory':
|
|
41
|
-
return new
|
|
44
|
+
return new MemoryCache_js_1.MemoryCache(config);
|
|
42
45
|
default:
|
|
43
|
-
throw new
|
|
46
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_UNSUPPORTED_ADAPTER, {
|
|
44
47
|
adapter: config.adapter,
|
|
45
48
|
operation: 'create',
|
|
46
49
|
});
|
|
@@ -60,14 +63,14 @@ class CacheFactory {
|
|
|
60
63
|
// If primary cache failed and fallback is enabled, use memory cache
|
|
61
64
|
if (config.fallback !== false) {
|
|
62
65
|
console.warn(`Failed to connect to ${config.adapter} cache, falling back to memory cache`);
|
|
63
|
-
return new
|
|
66
|
+
return new MemoryCache_js_1.MemoryCache({
|
|
64
67
|
adapter: 'memory',
|
|
65
68
|
namespace: config.namespace,
|
|
66
69
|
ttl: config.ttl,
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
// No fallback, throw error
|
|
70
|
-
throw new
|
|
73
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.CACHE_CONNECTION_FAILED, {
|
|
71
74
|
adapter: config.adapter,
|
|
72
75
|
operation: 'createWithFallback',
|
|
73
76
|
details: {
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
exports.CacheFactory = exports.BaseCache = void 0;
|
|
4
|
+
var BaseCache_js_1 = require("./BaseCache.js");
|
|
5
|
+
Object.defineProperty(exports, "BaseCache", { enumerable: true, get: function () { return BaseCache_js_1.BaseCache; } });
|
|
6
|
+
var factory_js_1 = require("./factory.js");
|
|
7
|
+
Object.defineProperty(exports, "CacheFactory", { enumerable: true, get: function () { return factory_js_1.CacheFactory; } });
|
|
@@ -1,18 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ICache.js"), exports);
|
|
18
|
-
__exportStar(require("./ISession.js"), exports);
|
package/dist/cjs/errors/index.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CACHE_ERROR_CODES = exports.CacheError = void 0;
|
|
17
4
|
const errors_1 = require("@naman_deep_singh/errors");
|
|
18
5
|
const cacheErrorCodes_js_1 = require("./cacheErrorCodes.js");
|
|
19
6
|
errors_1.errorMessageRegistry.register(cacheErrorCodes_js_1.CACHE_ERROR_CODES);
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
var CacheError_js_1 = require("./CacheError.js");
|
|
8
|
+
Object.defineProperty(exports, "CacheError", { enumerable: true, get: function () { return CacheError_js_1.CacheError; } });
|
|
9
|
+
var cacheErrorCodes_js_2 = require("./cacheErrorCodes.js");
|
|
10
|
+
Object.defineProperty(exports, "CACHE_ERROR_CODES", { enumerable: true, get: function () { return cacheErrorCodes_js_2.CACHE_ERROR_CODES; } });
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.cacheResponseMiddleware = exports.cacheHealthCheckMiddleware = exports.cacheSessionMiddleware = void 0;
|
|
4
|
+
var cache_middleware_js_1 = require("./cache.middleware.js");
|
|
5
|
+
Object.defineProperty(exports, "cacheSessionMiddleware", { enumerable: true, get: function () { return cache_middleware_js_1.cacheSessionMiddleware; } });
|
|
6
|
+
Object.defineProperty(exports, "cacheHealthCheckMiddleware", { enumerable: true, get: function () { return cache_middleware_js_1.cacheHealthCheckMiddleware; } });
|
|
7
|
+
Object.defineProperty(exports, "cacheResponseMiddleware", { enumerable: true, get: function () { return cache_middleware_js_1.cacheResponseMiddleware; } });
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.cacheResponseMiddleware = exports.cacheHealthCheckMiddleware = exports.cacheSessionMiddleware = void 0;
|
|
4
|
+
var index_js_1 = require("./express/index.js");
|
|
5
|
+
Object.defineProperty(exports, "cacheSessionMiddleware", { enumerable: true, get: function () { return index_js_1.cacheSessionMiddleware; } });
|
|
6
|
+
Object.defineProperty(exports, "cacheHealthCheckMiddleware", { enumerable: true, get: function () { return index_js_1.cacheHealthCheckMiddleware; } });
|
|
7
|
+
Object.defineProperty(exports, "cacheResponseMiddleware", { enumerable: true, get: function () { return index_js_1.cacheResponseMiddleware; } });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SessionStore = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CacheError_js_1 = require("../errors/CacheError.js");
|
|
5
|
+
const cacheErrorCodes_js_1 = require("../errors/cacheErrorCodes.js");
|
|
5
6
|
/**
|
|
6
7
|
* Session store wrapper around cache adapters
|
|
7
8
|
* Provides session management functionality
|
|
@@ -24,7 +25,7 @@ class SessionStore {
|
|
|
24
25
|
await this.cache.set(sessionId, data, ttlValue);
|
|
25
26
|
}
|
|
26
27
|
catch (error) {
|
|
27
|
-
throw new
|
|
28
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_CREATE_ERROR, {
|
|
28
29
|
adapter: 'session',
|
|
29
30
|
operation: 'create',
|
|
30
31
|
details: { sessionId },
|
|
@@ -40,7 +41,7 @@ class SessionStore {
|
|
|
40
41
|
return await this.cache.get(sessionId);
|
|
41
42
|
}
|
|
42
43
|
catch (error) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_GET_ERROR, {
|
|
44
45
|
adapter: 'session',
|
|
45
46
|
operation: 'get',
|
|
46
47
|
details: { sessionId },
|
|
@@ -55,7 +56,7 @@ class SessionStore {
|
|
|
55
56
|
try {
|
|
56
57
|
const current = await this.cache.get(sessionId);
|
|
57
58
|
if (!current) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_NOT_FOUND, {
|
|
59
60
|
adapter: 'session',
|
|
60
61
|
operation: 'update',
|
|
61
62
|
details: { sessionId },
|
|
@@ -65,10 +66,10 @@ class SessionStore {
|
|
|
65
66
|
await this.cache.set(sessionId, merged, this.options.ttl);
|
|
66
67
|
}
|
|
67
68
|
catch (error) {
|
|
68
|
-
if (error instanceof
|
|
69
|
+
if (error instanceof CacheError_js_1.CacheError) {
|
|
69
70
|
throw error;
|
|
70
71
|
}
|
|
71
|
-
throw new
|
|
72
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_UPDATE_ERROR, {
|
|
72
73
|
adapter: 'session',
|
|
73
74
|
operation: 'update',
|
|
74
75
|
details: { sessionId },
|
|
@@ -84,7 +85,7 @@ class SessionStore {
|
|
|
84
85
|
return await this.cache.delete(sessionId);
|
|
85
86
|
}
|
|
86
87
|
catch (error) {
|
|
87
|
-
throw new
|
|
88
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_DELETE_ERROR, {
|
|
88
89
|
adapter: 'session',
|
|
89
90
|
operation: 'delete',
|
|
90
91
|
details: { sessionId },
|
|
@@ -100,7 +101,7 @@ class SessionStore {
|
|
|
100
101
|
return await this.cache.exists(sessionId);
|
|
101
102
|
}
|
|
102
103
|
catch (error) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_EXISTS_ERROR, {
|
|
104
105
|
adapter: 'session',
|
|
105
106
|
operation: 'exists',
|
|
106
107
|
details: { sessionId },
|
|
@@ -116,7 +117,7 @@ class SessionStore {
|
|
|
116
117
|
await this.cache.clear();
|
|
117
118
|
}
|
|
118
119
|
catch (error) {
|
|
119
|
-
throw new
|
|
120
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_CLEAR_ERROR, {
|
|
120
121
|
adapter: 'session',
|
|
121
122
|
operation: 'clear',
|
|
122
123
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -131,7 +132,7 @@ class SessionStore {
|
|
|
131
132
|
return await this.cache.getMultiple(sessionIds);
|
|
132
133
|
}
|
|
133
134
|
catch (error) {
|
|
134
|
-
throw new
|
|
135
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_GET_MULTIPLE_ERROR, {
|
|
135
136
|
adapter: 'session',
|
|
136
137
|
operation: 'getMultiple',
|
|
137
138
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -146,7 +147,7 @@ class SessionStore {
|
|
|
146
147
|
return await this.cache.deleteMultiple(sessionIds);
|
|
147
148
|
}
|
|
148
149
|
catch (error) {
|
|
149
|
-
throw new
|
|
150
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_DELETE_MULTIPLE_ERROR, {
|
|
150
151
|
adapter: 'session',
|
|
151
152
|
operation: 'deleteMultiple',
|
|
152
153
|
cause: error instanceof Error ? error : undefined,
|
|
@@ -160,7 +161,7 @@ class SessionStore {
|
|
|
160
161
|
try {
|
|
161
162
|
const current = await this.cache.get(sessionId);
|
|
162
163
|
if (!current) {
|
|
163
|
-
throw new
|
|
164
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_NOT_FOUND, {
|
|
164
165
|
adapter: 'session',
|
|
165
166
|
operation: 'extend',
|
|
166
167
|
details: { sessionId },
|
|
@@ -170,10 +171,10 @@ class SessionStore {
|
|
|
170
171
|
await this.cache.set(sessionId, current, ttlValue);
|
|
171
172
|
}
|
|
172
173
|
catch (error) {
|
|
173
|
-
if (error instanceof
|
|
174
|
+
if (error instanceof CacheError_js_1.CacheError) {
|
|
174
175
|
throw error;
|
|
175
176
|
}
|
|
176
|
-
throw new
|
|
177
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_EXTEND_ERROR, {
|
|
177
178
|
adapter: 'session',
|
|
178
179
|
operation: 'extend',
|
|
179
180
|
details: { sessionId },
|
|
@@ -193,10 +194,10 @@ class SessionStore {
|
|
|
193
194
|
return data;
|
|
194
195
|
}
|
|
195
196
|
catch (error) {
|
|
196
|
-
if (error instanceof
|
|
197
|
+
if (error instanceof CacheError_js_1.CacheError) {
|
|
197
198
|
throw error;
|
|
198
199
|
}
|
|
199
|
-
throw new
|
|
200
|
+
throw new CacheError_js_1.CacheError(cacheErrorCodes_js_1.CACHE_ERROR_CODES.SESSION_GET_EXTEND_ERROR, {
|
|
200
201
|
adapter: 'session',
|
|
201
202
|
operation: 'getAndExtend',
|
|
202
203
|
details: { sessionId },
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.SessionStore = void 0;
|
|
4
|
+
var SessionStore_js_1 = require("./SessionStore.js");
|
|
5
|
+
Object.defineProperty(exports, "SessionStore", { enumerable: true, get: function () { return SessionStore_js_1.SessionStore; } });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { MemcacheCache } from './memcache/index.js';
|
|
2
|
+
export { MemoryCache } from './memory/index.js';
|
|
3
|
+
export { RedisCache } from './redis/index.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Memcached from 'memcached';
|
|
2
|
-
import { BaseCache } from '../../core/
|
|
3
|
-
import {
|
|
2
|
+
import { BaseCache } from '../../core/BaseCache.js';
|
|
3
|
+
import { CacheError } from '../../errors/CacheError.js';
|
|
4
|
+
import { CACHE_ERROR_CODES } from '../../errors/cacheErrorCodes.js';
|
|
4
5
|
export class MemcacheCache extends BaseCache {
|
|
5
6
|
constructor(memcacheConfig) {
|
|
6
7
|
super(memcacheConfig);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BaseCache } from '../../core/
|
|
2
|
-
import {
|
|
1
|
+
import { BaseCache } from '../../core/BaseCache.js';
|
|
2
|
+
import { CacheError } from '../../errors/CacheError.js';
|
|
3
|
+
import { CACHE_ERROR_CODES } from '../../errors/cacheErrorCodes.js';
|
|
3
4
|
/**
|
|
4
5
|
* In-memory cache adapter for development and testing
|
|
5
6
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createClient, createCluster } from 'redis';
|
|
2
|
-
import { BaseCache } from '../../core/
|
|
3
|
-
import {
|
|
2
|
+
import { BaseCache } from '../../core/BaseCache.js';
|
|
3
|
+
import { CacheError } from '../../errors/CacheError.js';
|
|
4
|
+
import { CACHE_ERROR_CODES } from '../../errors/cacheErrorCodes.js';
|
|
4
5
|
/**
|
|
5
6
|
* Redis cache adapter
|
|
6
7
|
*/
|
package/dist/esm/core/factory.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { MemcacheCache
|
|
2
|
-
import {
|
|
1
|
+
import { MemcacheCache } from '../adapters/memcache/MemcacheCache.js';
|
|
2
|
+
import { MemoryCache } from '../adapters/memory/MemoryCache.js';
|
|
3
|
+
import { RedisCache } from '../adapters/redis/RedisCache.js';
|
|
4
|
+
import { CacheError } from '../errors/CacheError.js';
|
|
5
|
+
import { CACHE_ERROR_CODES } from '../errors/cacheErrorCodes.js';
|
|
3
6
|
/**
|
|
4
7
|
* Factory for creating cache instances
|
|
5
8
|
*/
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './factory.js';
|
|
1
|
+
export { BaseCache } from './BaseCache.js';
|
|
2
|
+
export { CacheFactory } from './factory.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './ISession.js';
|
|
1
|
+
export {};
|
package/dist/esm/errors/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { errorMessageRegistry } from '@naman_deep_singh/errors';
|
|
2
2
|
import { CACHE_ERROR_CODES } from './cacheErrorCodes.js';
|
|
3
3
|
errorMessageRegistry.register(CACHE_ERROR_CODES);
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export { CacheError } from './CacheError.js';
|
|
5
|
+
export { CACHE_ERROR_CODES } from './cacheErrorCodes.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './cache.middleware.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './express/index.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CacheError } from '../errors/CacheError.js';
|
|
2
|
+
import { CACHE_ERROR_CODES } from '../errors/cacheErrorCodes.js';
|
|
2
3
|
/**
|
|
3
4
|
* Session store wrapper around cache adapters
|
|
4
5
|
* Provides session management functionality
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { SessionStore } from './SessionStore.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { MemcacheCache } from './memcache/index.js';
|
|
2
|
+
export { MemoryCache } from './memory/index.js';
|
|
3
|
+
export { RedisCache } from './redis/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseCache } from '../../core/
|
|
1
|
+
import { BaseCache } from '../../core/BaseCache.js';
|
|
2
2
|
import type { HealthCheckResponse, MemcacheCacheConfig } from '../../types.js';
|
|
3
3
|
export declare class MemcacheCache<T = unknown> extends BaseCache<T> {
|
|
4
4
|
private memcacheConfig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { type ICache, type ISession } from './interfaces/index.js';
|
|
2
|
+
export { BaseCache } from './BaseCache.js';
|
|
3
|
+
export { CacheFactory } from './factory.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { type ICache } from './ICache.js';
|
|
2
|
+
export { type ISession } from './ISession.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { CacheError } from './CacheError.js';
|
|
2
|
+
export { CACHE_ERROR_CODES, type CacheErrorCode } from './cacheErrorCodes.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import type { ICache } from '../../core/
|
|
3
|
-
import type { SessionStore } from '../../session/
|
|
2
|
+
import type { ICache } from '../../core/interfaces/ICache.js';
|
|
3
|
+
import type { SessionStore } from '../../session/SessionStore.js';
|
|
4
4
|
/**
|
|
5
5
|
* Express middleware for session management using cache
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './cache.middleware.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './express/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { SessionStore } from './SessionStore.js';
|
package/package.json
CHANGED
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naman_deep_singh/cache",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Extensible caching layer supporting Redis, Memcache, and in-memory caches with automatic fallback, namespacing, session management, and Express middleware.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
7
7
|
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": "./dist/esm/index.js",
|
|
11
12
|
"require": "./dist/cjs/index.js",
|
|
12
13
|
"types": "./dist/types/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./types": {
|
|
16
|
+
"import": "./dist/esm/types.js",
|
|
17
|
+
"require": "./dist/cjs/types.js",
|
|
18
|
+
"types": "./dist/types/types.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./errors": {
|
|
21
|
+
"import": "./dist/esm/errors/index.js",
|
|
22
|
+
"require": "./dist/cjs/errors/index.js",
|
|
23
|
+
"types": "./dist/types/errors/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./core": {
|
|
26
|
+
"import": "./dist/esm/core/index.js",
|
|
27
|
+
"require": "./dist/cjs/core/index.js",
|
|
28
|
+
"types": "./dist/types/core/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./adapters": {
|
|
31
|
+
"import": "./dist/esm/adapters/index.js",
|
|
32
|
+
"require": "./dist/cjs/adapters/index.js",
|
|
33
|
+
"types": "./dist/types/adapters/index.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./session": {
|
|
36
|
+
"import": "./dist/esm/session/index.js",
|
|
37
|
+
"require": "./dist/cjs/session/index.js",
|
|
38
|
+
"types": "./dist/types/session/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./middleware": {
|
|
41
|
+
"import": "./dist/esm/middleware/index.js",
|
|
42
|
+
"require": "./dist/cjs/middleware/index.js",
|
|
43
|
+
"types": "./dist/types/middleware/index.d.ts"
|
|
13
44
|
}
|
|
14
45
|
},
|
|
15
46
|
"sideEffects": false,
|
|
@@ -37,7 +68,7 @@
|
|
|
37
68
|
"typescript": "^5.9.3"
|
|
38
69
|
},
|
|
39
70
|
"dependencies": {
|
|
40
|
-
"@naman_deep_singh/errors": "^2.
|
|
71
|
+
"@naman_deep_singh/errors": "^2.3.0",
|
|
41
72
|
"memcached": "^2.2.2",
|
|
42
73
|
"redis": "^4.6.10"
|
|
43
74
|
},
|
|
File without changes
|
|
File without changes
|