kareem 2.3.3 → 2.3.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/CHANGELOG.md +5 -0
- package/index.js +16 -28
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ Kareem.prototype.execPre = function(name, context, args, callback) {
|
|
|
10
10
|
callback = args;
|
|
11
11
|
args = [];
|
|
12
12
|
}
|
|
13
|
-
var pres =
|
|
13
|
+
var pres = this._pres.get(name) || [];
|
|
14
14
|
var numPres = pres.length;
|
|
15
15
|
var numAsyncPres = pres.numAsync || 0;
|
|
16
16
|
var currentPre = 0;
|
|
@@ -109,7 +109,7 @@ Kareem.prototype.execPre = function(name, context, args, callback) {
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
Kareem.prototype.execPreSync = function(name, context, args) {
|
|
112
|
-
var pres =
|
|
112
|
+
var pres = this._pres.get(name) || [];
|
|
113
113
|
var numPres = pres.length;
|
|
114
114
|
|
|
115
115
|
for (var i = 0; i < numPres; ++i) {
|
|
@@ -122,7 +122,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
|
|
|
122
122
|
callback = options;
|
|
123
123
|
options = null;
|
|
124
124
|
}
|
|
125
|
-
var posts =
|
|
125
|
+
var posts = this._posts.get(name) || [];
|
|
126
126
|
var numPosts = posts.length;
|
|
127
127
|
var currentPost = 0;
|
|
128
128
|
|
|
@@ -151,7 +151,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
|
|
|
151
151
|
|
|
152
152
|
if (firstError) {
|
|
153
153
|
if (post.length === numArgs + 2) {
|
|
154
|
-
|
|
154
|
+
const _cb = decorateNextFn(function(error) {
|
|
155
155
|
if (error) {
|
|
156
156
|
firstError = error;
|
|
157
157
|
}
|
|
@@ -210,7 +210,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
|
|
|
210
210
|
return callback.apply(null, [error].concat(args));
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
next(
|
|
213
|
+
next();
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
};
|
|
@@ -219,7 +219,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
|
|
|
219
219
|
};
|
|
220
220
|
|
|
221
221
|
Kareem.prototype.execPostSync = function(name, context, args) {
|
|
222
|
-
const posts =
|
|
222
|
+
const posts = this._posts.get(name) || [];
|
|
223
223
|
const numPosts = posts.length;
|
|
224
224
|
|
|
225
225
|
for (let i = 0; i < numPosts; ++i) {
|
|
@@ -242,14 +242,11 @@ Kareem.prototype.createWrapperSync = function(name, fn) {
|
|
|
242
242
|
|
|
243
243
|
function _handleWrapError(instance, error, name, context, args, options, callback) {
|
|
244
244
|
if (options.useErrorHandlers) {
|
|
245
|
-
|
|
246
|
-
return instance.execPost(name, context, args, _options, function(error) {
|
|
245
|
+
return instance.execPost(name, context, args, { error: error }, function(error) {
|
|
247
246
|
return typeof callback === 'function' && callback(error);
|
|
248
247
|
});
|
|
249
248
|
} else {
|
|
250
|
-
return typeof callback === 'function'
|
|
251
|
-
callback(error) :
|
|
252
|
-
undefined;
|
|
249
|
+
return typeof callback === 'function' && callback(error);
|
|
253
250
|
}
|
|
254
251
|
}
|
|
255
252
|
|
|
@@ -300,8 +297,8 @@ Kareem.prototype.wrap = function(name, fn, context, args, options) {
|
|
|
300
297
|
}
|
|
301
298
|
|
|
302
299
|
function _cb() {
|
|
303
|
-
const
|
|
304
|
-
|
|
300
|
+
const argsWithoutError = Array.from(arguments);
|
|
301
|
+
argsWithoutError.shift();
|
|
305
302
|
if (options.nullResultByDefault && argsWithoutError.length === 0) {
|
|
306
303
|
argsWithoutError.push(null);
|
|
307
304
|
}
|
|
@@ -377,23 +374,21 @@ Kareem.prototype.createWrapper = function(name, fn, context, options) {
|
|
|
377
374
|
}
|
|
378
375
|
return function() {
|
|
379
376
|
var _context = context || this;
|
|
380
|
-
|
|
381
|
-
_this.wrap(name, fn, _context, args, options);
|
|
377
|
+
_this.wrap(name, fn, _context, Array.from(arguments), options);
|
|
382
378
|
};
|
|
383
379
|
};
|
|
384
380
|
|
|
385
381
|
Kareem.prototype.pre = function(name, isAsync, fn, error, unshift) {
|
|
386
382
|
let options = {};
|
|
387
|
-
if (typeof isAsync === 'object' && isAsync
|
|
383
|
+
if (typeof isAsync === 'object' && isAsync !== null) {
|
|
388
384
|
options = isAsync;
|
|
389
385
|
isAsync = options.isAsync;
|
|
390
386
|
} else if (typeof arguments[1] !== 'boolean') {
|
|
391
|
-
error = fn;
|
|
392
387
|
fn = isAsync;
|
|
393
388
|
isAsync = false;
|
|
394
389
|
}
|
|
395
390
|
|
|
396
|
-
const pres =
|
|
391
|
+
const pres = this._pres.get(name) || [];
|
|
397
392
|
this._pres.set(name, pres);
|
|
398
393
|
|
|
399
394
|
if (isAsync) {
|
|
@@ -415,7 +410,7 @@ Kareem.prototype.pre = function(name, isAsync, fn, error, unshift) {
|
|
|
415
410
|
};
|
|
416
411
|
|
|
417
412
|
Kareem.prototype.post = function(name, options, fn, unshift) {
|
|
418
|
-
const hooks =
|
|
413
|
+
const hooks = this._posts.get(name) || [];
|
|
419
414
|
|
|
420
415
|
if (typeof options === 'function') {
|
|
421
416
|
unshift = !!fn;
|
|
@@ -456,7 +451,7 @@ Kareem.prototype.merge = function(other, clone) {
|
|
|
456
451
|
var ret = clone ? this.clone() : this;
|
|
457
452
|
|
|
458
453
|
for (let key of other._pres.keys()) {
|
|
459
|
-
const sourcePres =
|
|
454
|
+
const sourcePres = ret._pres.get(key) || [];
|
|
460
455
|
const deduplicated = other._pres.get(key).
|
|
461
456
|
// Deduplicate based on `fn`
|
|
462
457
|
filter(p => sourcePres.map(_p => _p.fn).indexOf(p.fn) === -1);
|
|
@@ -466,7 +461,7 @@ Kareem.prototype.merge = function(other, clone) {
|
|
|
466
461
|
ret._pres.set(key, combined);
|
|
467
462
|
}
|
|
468
463
|
for (let key of other._posts.keys()) {
|
|
469
|
-
const sourcePosts =
|
|
464
|
+
const sourcePosts = ret._posts.get(key) || [];
|
|
470
465
|
const deduplicated = other._posts.get(key).
|
|
471
466
|
filter(p => sourcePosts.indexOf(p) === -1);
|
|
472
467
|
ret._posts.set(key, sourcePosts.concat(deduplicated));
|
|
@@ -475,13 +470,6 @@ Kareem.prototype.merge = function(other, clone) {
|
|
|
475
470
|
return ret;
|
|
476
471
|
};
|
|
477
472
|
|
|
478
|
-
function get(map, key, def) {
|
|
479
|
-
if (map.has(key)) {
|
|
480
|
-
return map.get(key);
|
|
481
|
-
}
|
|
482
|
-
return def;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
473
|
function callMiddlewareFunction(fn, context, args, next) {
|
|
486
474
|
let maybePromise;
|
|
487
475
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kareem",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "Next-generation take on pre/post function hooks",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"acquit": "1.x",
|
|
16
16
|
"acquit-ignore": "0.1.x",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"mocha": "9.2.0",
|
|
18
|
+
"nyc": "15.1.0"
|
|
19
19
|
},
|
|
20
20
|
"author": "Valeri Karpov <val@karpov.io>",
|
|
21
21
|
"license": "Apache-2.0"
|