@withjoy/limiter 0.2.0 → 0.2.1
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/limiter.js +16 -1
- package/package.json +1 -1
package/limiter.js
CHANGED
|
@@ -179,11 +179,26 @@ class Limiter {
|
|
|
179
179
|
class LimiterProcessor {
|
|
180
180
|
|
|
181
181
|
constructor(console) {
|
|
182
|
-
this._console = console;
|
|
182
|
+
this._console = this._normalizeConsole(console);
|
|
183
183
|
this._operationList = [];
|
|
184
184
|
this._limitdRedis = connection;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Normalize logger interface to ensure .info method exists
|
|
189
|
+
* Maps .log or .verbose to .info if .info doesn't exist
|
|
190
|
+
*
|
|
191
|
+
* TODO: Once we migrate to TypeScript and define a formal ILimiterLogger interface,
|
|
192
|
+
* this normalization should no longer be needed. The interface will enforce the
|
|
193
|
+
* required .info() and .error() methods at compile time.
|
|
194
|
+
*/
|
|
195
|
+
_normalizeConsole(console) {
|
|
196
|
+
if (!console.info) {
|
|
197
|
+
console.info = (console.log || console.verbose || (() => {})).bind(console);
|
|
198
|
+
}
|
|
199
|
+
return console;
|
|
200
|
+
}
|
|
201
|
+
|
|
187
202
|
/*
|
|
188
203
|
Go through the log of things we did and do the opposite
|
|
189
204
|
*/
|