async-invoker 1.1.2 → 2.0.0-beta.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/.github/ISSUE_TEMPLATE.md +30 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +3 -0
- package/.github/workflows/trufflehog-scan.yml +14 -0
- package/babel.config.json +5 -0
- package/lib/async.invoker.js +61 -73
- package/lib/index.js +2 -3
- package/package.json +10 -10
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Note: This is just a template, so feel free to use/remove the unnecessary things
|
|
2
|
+
|
|
3
|
+
### Description
|
|
4
|
+
- Type: Bug | Enhancement | Question
|
|
5
|
+
- Related Issue: `#abc`
|
|
6
|
+
|
|
7
|
+
---------------------------------------------------------------
|
|
8
|
+
## Bug
|
|
9
|
+
**Expected Behavior**
|
|
10
|
+
|
|
11
|
+
**Actual Behavior**
|
|
12
|
+
|
|
13
|
+
**Steps to Reproduce**
|
|
14
|
+
|
|
15
|
+
----------------------------------------------------------------
|
|
16
|
+
## Enhancement
|
|
17
|
+
|
|
18
|
+
**Reason to enhance/problem with existing solution**
|
|
19
|
+
|
|
20
|
+
**Suggested enhancement**
|
|
21
|
+
|
|
22
|
+
**Pros**
|
|
23
|
+
|
|
24
|
+
**Cons**
|
|
25
|
+
|
|
26
|
+
-----------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
## Question
|
|
29
|
+
|
|
30
|
+
**How to?**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: Trufflehog Scan
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
trufflehog-scan:
|
|
11
|
+
uses: Parsimotion/public-workflows/.github/workflows/trufflehog-scan.yml@main
|
|
12
|
+
with:
|
|
13
|
+
pr-number: ${{ github.event.pull_request.number }}
|
|
14
|
+
base-commit: ${{ github.event.pull_request.base.sha }}
|
package/lib/async.invoker.js
CHANGED
|
@@ -1,81 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
var AsyncInvoker, Promise, _, eval_,
|
|
3
|
-
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
4
|
-
slice = [].slice;
|
|
1
|
+
"use strict";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
var Promise = require("bluebird");
|
|
11
|
+
var eval_ = require("eval");
|
|
12
|
+
var _ = require("lodash");
|
|
13
|
+
var AsyncInvoker = /*#__PURE__*/function () {
|
|
14
|
+
function AsyncInvoker(code) {
|
|
15
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
16
|
+
var globals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
17
|
+
_classCallCheck(this, AsyncInvoker);
|
|
18
|
+
this.options = options;
|
|
19
|
+
_.defaults(this.options, {
|
|
20
|
+
logErrors: true
|
|
21
|
+
});
|
|
22
|
+
code = "module.exports = ".concat(code);
|
|
23
|
+
this._invoke = this._doSomething(function () {
|
|
24
|
+
return eval_(code, globals);
|
|
25
|
+
});
|
|
26
|
+
this._assertIsFunction(this._invoke);
|
|
27
|
+
}
|
|
28
|
+
return _createClass(AsyncInvoker, [{
|
|
29
|
+
key: "invoke",
|
|
30
|
+
value: function invoke() {
|
|
31
|
+
var _this = this;
|
|
32
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
+
args[_key] = arguments[_key];
|
|
17
34
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
var invoke = function invoke(functionArgs) {
|
|
36
|
+
return _this._doSomething(function () {
|
|
37
|
+
return _this._invoke.apply(null, functionArgs);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var tryLog = function tryLog(e) {
|
|
41
|
+
if (_this.options.logErrors) console.log(e);
|
|
42
|
+
};
|
|
43
|
+
return new Promise(function (resolve, reject) {
|
|
44
|
+
try {
|
|
45
|
+
var output = invoke(args.concat(resolve));
|
|
46
|
+
if (!_.isUndefined(output)) {
|
|
47
|
+
resolve(output);
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
tryLog(e);
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
23
53
|
});
|
|
24
|
-
code = "module.exports = " + code;
|
|
25
|
-
this._invoke = this._doSomething(((function(_this) {
|
|
26
|
-
return function() {
|
|
27
|
-
return eval_(code, globals);
|
|
28
|
-
};
|
|
29
|
-
})(this)));
|
|
30
|
-
this._assertIsFunction(this._invoke);
|
|
31
54
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
36
|
-
invoke = (function(_this) {
|
|
37
|
-
return function(functionArgs) {
|
|
38
|
-
return _this._doSomething((function() {
|
|
39
|
-
return _this._invoke.apply(null, functionArgs);
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
})(this);
|
|
43
|
-
tryLog = (function(_this) {
|
|
44
|
-
return function(e) {
|
|
45
|
-
if (_this.options.logErrors) {
|
|
46
|
-
return console.log(e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
})(this);
|
|
50
|
-
return new Promise((function(_this) {
|
|
51
|
-
return function(resolve, reject) {
|
|
52
|
-
var e, error, output;
|
|
53
|
-
try {
|
|
54
|
-
output = invoke(args.concat(resolve));
|
|
55
|
-
if (!_.isUndefined(output)) {
|
|
56
|
-
return resolve(output);
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
e = error;
|
|
60
|
-
tryLog(e);
|
|
61
|
-
return reject(e);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
})(this));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
AsyncInvoker.prototype._doSomething = function(doSomething) {
|
|
55
|
+
}, {
|
|
56
|
+
key: "_doSomething",
|
|
57
|
+
value: function _doSomething(doSomething) {
|
|
68
58
|
return doSomething();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "_assertIsFunction",
|
|
62
|
+
value: function _assertIsFunction(func) {
|
|
72
63
|
if (!_.isFunction(func)) {
|
|
73
64
|
throw new Error("The function is not a function");
|
|
74
65
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})();
|
|
80
|
-
|
|
81
|
-
}).call(this);
|
|
66
|
+
}
|
|
67
|
+
}]);
|
|
68
|
+
}();
|
|
69
|
+
module.exports = AsyncInvoker;
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "async-invoker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Create a runner of code asynchronous",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"
|
|
7
|
+
"test": "mocha --require @babel/register --reporter spec 'src/**/*.spec.js'",
|
|
8
|
+
"build": "rm -rf lib && babel src --out-dir lib --ignore 'src/**/*.spec.js'",
|
|
9
|
+
"prepublish": "npm run build"
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -13,15 +14,14 @@
|
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
16
|
"bluebird": "3.4.6",
|
|
16
|
-
"eval": "0.1.
|
|
17
|
-
"lodash": "4.
|
|
17
|
+
"eval": "0.1.6",
|
|
18
|
+
"lodash": "^4.18.1"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"grunt-mocha-test": "0.12.7",
|
|
21
|
+
"@babel/cli": "^7.24.0",
|
|
22
|
+
"@babel/core": "^7.24.0",
|
|
23
|
+
"@babel/preset-env": "^7.24.0",
|
|
24
|
+
"@babel/register": "^7.24.0",
|
|
25
25
|
"mocha": "3.0.2",
|
|
26
26
|
"should": "11.1.0"
|
|
27
27
|
},
|