UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.debugInOut = debugInOut;
7
8function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
9
10function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
11
12function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
13
14function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
15
16function debugInOut(target, name, descriptor) {
17 var original = descriptor.value;
18
19 descriptor.value = function () {
20 var debug = this.debug || name === "init" && arguments[0];
21 var objName = this.name;
22 var argsArr = Array.prototype.slice.call(arguments);
23
24 if (debug) {
25 var _console;
26
27 (_console = console).log.apply(_console, ["[trezor-link] Calling ".concat(objName, ".").concat(name, "(")].concat(_toConsumableArray(argsArr.map(function (f) {
28 if (typeof f === "string") {
29 if (f.length > 1000) {
30 return "".concat(f.substring(0, 1000), "...");
31 }
32 }
33
34 return f;
35 })), [")"]));
36 } // assuming that the function is a promise
37
38
39 var resP = original.apply(this, arguments);
40 return resP.then(function (res) {
41 if (debug) {
42 if (res == null) {
43 console.log("[trezor-link] Done ".concat(objName, ".").concat(name));
44 } else {
45 console.log("[trezor-link] Done ".concat(objName, ".").concat(name, ", result "), res);
46 }
47 }
48
49 return res;
50 }, function (err) {
51 if (debug) {
52 console.error("[trezor-link] Error in ".concat(objName, ".").concat(name), err);
53 }
54
55 throw err;
56 });
57 };
58
59 return descriptor;
60}
\No newline at end of file