mikro-orm-cache-adapter-redis
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -26,14 +26,2 @@ 'use strict'; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -80,18 +68,32 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var _a; | ||
var _b = options.debug, debug = _b === void 0 ? false : _b, expiration = options.expiration, keyPrefix = options.keyPrefix; | ||
var _b = options.debug, debug = _b === void 0 ? false : _b, expiration = options.expiration, _c = options.keyPrefix, keyPrefix = _c === void 0 ? "" : _c; | ||
this.logger = (_a = options.logger) !== null && _a !== void 0 ? _a : console.log; | ||
this.keyPrefix = keyPrefix || "mikro"; | ||
this.keyPrefix = this.computeKeyPrefix(options, keyPrefix); | ||
this.client = this.createRedisClient(options); | ||
this.debug = debug; | ||
this.expiration = expiration; | ||
this.logDebugMessage("The Redis client for cache has been created! | Cache expiration: ".concat(this.expiration, "ms")); | ||
} | ||
RedisCacheAdapter.prototype.computeKeyPrefix = function (options, localKeyPrefix) { | ||
var _a; | ||
if ((_a = options.client) === null || _a === void 0 ? void 0 : _a.options.keyPrefix) { | ||
return localKeyPrefix ? ":".concat(localKeyPrefix) : ""; | ||
} | ||
// Default to 'mikro' if keyPrefix is not provided and there's no client options key prefix | ||
return localKeyPrefix || "mikro"; | ||
}; | ||
RedisCacheAdapter.prototype.createRedisClient = function (options) { | ||
if (options.client) { | ||
this.client = options.client; | ||
return options.client; | ||
} | ||
else { | ||
var redisOpt = __rest(options, []); | ||
this.client = new IORedis__default["default"](redisOpt); | ||
var redisOpt = options; | ||
return new IORedis__default["default"](redisOpt); | ||
} | ||
this.debug = debug; | ||
this.expiration = expiration; | ||
}; | ||
RedisCacheAdapter.prototype.logDebugMessage = function (message) { | ||
if (this.debug) { | ||
this.logger("The Redis client for cache has been created! | Cache expiration: ".concat(this.expiration, "ms")); | ||
this.logger(message); | ||
} | ||
} | ||
}; | ||
RedisCacheAdapter.prototype._getKey = function (name) { | ||
@@ -103,13 +105,11 @@ return "".concat(this.keyPrefix, ":").concat(name); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var completKey, data; | ||
var completeKey, data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
completKey = this._getKey(key); | ||
return [4 /*yield*/, this.client.get(completKey)]; | ||
completeKey = this._getKey(key); | ||
return [4 /*yield*/, this.client.get(completeKey)]; | ||
case 1: | ||
data = _a.sent(); | ||
if (this.debug) { | ||
this.logger("Get \"".concat(completKey, "\": \"").concat(data, "\"")); | ||
} | ||
this.logDebugMessage("Get \"".concat(completeKey, "\": \"").concat(data, "\"")); | ||
if (!data) | ||
@@ -133,5 +133,3 @@ return [2 /*return*/, undefined]; | ||
completeKey = this._getKey(key); | ||
if (this.debug) { | ||
this.logger("Set \"".concat(completeKey, "\": \"").concat(stringData, "\" with cache expiration ").concat(expiration, "ms")); | ||
} | ||
this.logDebugMessage("Set \"".concat(completeKey, "\": \"").concat(stringData, "\" with cache expiration ").concat(expiration, "ms")); | ||
if (!expiration) return [3 /*break*/, 2]; | ||
@@ -158,2 +156,3 @@ return [4 /*yield*/, this.client.set(completeKey, stringData, "PX", expiration)]; | ||
completeKey = this._getKey(name); | ||
this.logDebugMessage("Remove specific key cache =>> ".concat(completeKey)); | ||
return [4 /*yield*/, this.client.del(completeKey)]; | ||
@@ -171,5 +170,3 @@ case 1: | ||
return __generator(this, function (_a) { | ||
if (this.debug) { | ||
this.logger("Clearing cache..."); | ||
} | ||
this.logDebugMessage("Clearing cache..."); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
@@ -190,10 +187,6 @@ var stream = _this.client.scanStream({ | ||
if (err) { | ||
if (_this.debug) { | ||
_this.logger("Error clearing cache"); | ||
} | ||
_this.logDebugMessage("Error clearing cache"); | ||
return reject(err); | ||
} | ||
if (_this.debug) { | ||
_this.logger("Cleared cache"); | ||
} | ||
_this.logDebugMessage("Cleared cache"); | ||
resolve(); | ||
@@ -200,0 +193,0 @@ }); |
@@ -18,14 +18,2 @@ import IORedis from 'ioredis'; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -72,18 +60,32 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var _a; | ||
var _b = options.debug, debug = _b === void 0 ? false : _b, expiration = options.expiration, keyPrefix = options.keyPrefix; | ||
var _b = options.debug, debug = _b === void 0 ? false : _b, expiration = options.expiration, _c = options.keyPrefix, keyPrefix = _c === void 0 ? "" : _c; | ||
this.logger = (_a = options.logger) !== null && _a !== void 0 ? _a : console.log; | ||
this.keyPrefix = keyPrefix || "mikro"; | ||
this.keyPrefix = this.computeKeyPrefix(options, keyPrefix); | ||
this.client = this.createRedisClient(options); | ||
this.debug = debug; | ||
this.expiration = expiration; | ||
this.logDebugMessage("The Redis client for cache has been created! | Cache expiration: ".concat(this.expiration, "ms")); | ||
} | ||
RedisCacheAdapter.prototype.computeKeyPrefix = function (options, localKeyPrefix) { | ||
var _a; | ||
if ((_a = options.client) === null || _a === void 0 ? void 0 : _a.options.keyPrefix) { | ||
return localKeyPrefix ? ":".concat(localKeyPrefix) : ""; | ||
} | ||
// Default to 'mikro' if keyPrefix is not provided and there's no client options key prefix | ||
return localKeyPrefix || "mikro"; | ||
}; | ||
RedisCacheAdapter.prototype.createRedisClient = function (options) { | ||
if (options.client) { | ||
this.client = options.client; | ||
return options.client; | ||
} | ||
else { | ||
var redisOpt = __rest(options, []); | ||
this.client = new IORedis(redisOpt); | ||
var redisOpt = options; | ||
return new IORedis(redisOpt); | ||
} | ||
this.debug = debug; | ||
this.expiration = expiration; | ||
}; | ||
RedisCacheAdapter.prototype.logDebugMessage = function (message) { | ||
if (this.debug) { | ||
this.logger("The Redis client for cache has been created! | Cache expiration: ".concat(this.expiration, "ms")); | ||
this.logger(message); | ||
} | ||
} | ||
}; | ||
RedisCacheAdapter.prototype._getKey = function (name) { | ||
@@ -95,13 +97,11 @@ return "".concat(this.keyPrefix, ":").concat(name); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var completKey, data; | ||
var completeKey, data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
completKey = this._getKey(key); | ||
return [4 /*yield*/, this.client.get(completKey)]; | ||
completeKey = this._getKey(key); | ||
return [4 /*yield*/, this.client.get(completeKey)]; | ||
case 1: | ||
data = _a.sent(); | ||
if (this.debug) { | ||
this.logger("Get \"".concat(completKey, "\": \"").concat(data, "\"")); | ||
} | ||
this.logDebugMessage("Get \"".concat(completeKey, "\": \"").concat(data, "\"")); | ||
if (!data) | ||
@@ -125,5 +125,3 @@ return [2 /*return*/, undefined]; | ||
completeKey = this._getKey(key); | ||
if (this.debug) { | ||
this.logger("Set \"".concat(completeKey, "\": \"").concat(stringData, "\" with cache expiration ").concat(expiration, "ms")); | ||
} | ||
this.logDebugMessage("Set \"".concat(completeKey, "\": \"").concat(stringData, "\" with cache expiration ").concat(expiration, "ms")); | ||
if (!expiration) return [3 /*break*/, 2]; | ||
@@ -150,2 +148,3 @@ return [4 /*yield*/, this.client.set(completeKey, stringData, "PX", expiration)]; | ||
completeKey = this._getKey(name); | ||
this.logDebugMessage("Remove specific key cache =>> ".concat(completeKey)); | ||
return [4 /*yield*/, this.client.del(completeKey)]; | ||
@@ -163,5 +162,3 @@ case 1: | ||
return __generator(this, function (_a) { | ||
if (this.debug) { | ||
this.logger("Clearing cache..."); | ||
} | ||
this.logDebugMessage("Clearing cache..."); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
@@ -182,10 +179,6 @@ var stream = _this.client.scanStream({ | ||
if (err) { | ||
if (_this.debug) { | ||
_this.logger("Error clearing cache"); | ||
} | ||
_this.logDebugMessage("Error clearing cache"); | ||
return reject(err); | ||
} | ||
if (_this.debug) { | ||
_this.logger("Cleared cache"); | ||
} | ||
_this.logDebugMessage("Cleared cache"); | ||
resolve(); | ||
@@ -192,0 +185,0 @@ }); |
@@ -22,2 +22,5 @@ import type { CacheAdapter } from "@mikro-orm/core"; | ||
constructor(options: RedisCacheAdapterOptions); | ||
private computeKeyPrefix; | ||
private createRedisClient; | ||
private logDebugMessage; | ||
_getKey(name: string): string; | ||
@@ -24,0 +27,0 @@ get<T = any>(key: string): Promise<T | undefined>; |
{ | ||
"name": "mikro-orm-cache-adapter-redis", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "A redis cache adapter for mikro-orm", | ||
@@ -17,5 +17,3 @@ "main": "dist/index.cjs.js", | ||
}, | ||
"dependencies": { | ||
"@types/ioredis": "^4.19.1" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -28,10 +26,10 @@ "@mikro-orm/core": "^5.0.5", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"ioredis": "^4.24.4", | ||
"ioredis": "^5.3.2", | ||
"prettier": "2.6.0", | ||
"rollup": "^2.42.4", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"rollup-plugin-typescript2": "0.31.0", | ||
"typescript": "^4.1.3" | ||
}, | ||
"peerDependencies": { | ||
"ioredis": "^4.22.0" | ||
"ioredis": "^5.3.2" | ||
}, | ||
@@ -38,0 +36,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24237
1
413
+ Added@ioredis/commands@1.2.0(transitive)
+ Addeddenque@2.1.0(transitive)
+ Addedioredis@5.4.1(transitive)
- Removed@types/ioredis@^4.19.1
- Removed@types/ioredis@4.28.10(transitive)
- Removed@types/node@22.9.3(transitive)
- Removeddenque@1.5.1(transitive)
- Removedioredis@4.28.5(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedp-map@2.1.0(transitive)
- Removedredis-commands@1.7.0(transitive)
- Removedundici-types@6.19.8(transitive)