@grandlinex/kernel 0.26.0 → 0.27.0

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.
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,112 +8,66 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  Object.defineProperty(exports, "__esModule", { value: true });
54
12
  exports.ActionMode = void 0;
55
- var core_1 = require("@grandlinex/core");
56
- var timing_1 = require("./timing");
13
+ const core_1 = require("@grandlinex/core");
14
+ const timing_1 = require("./timing");
57
15
  var ActionMode;
58
16
  (function (ActionMode) {
59
17
  ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
60
18
  ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
61
19
  ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
62
20
  })(ActionMode = exports.ActionMode || (exports.ActionMode = {}));
63
- var BaseAction = /** @class */ (function (_super) {
64
- __extends(BaseAction, _super);
65
- function BaseAction(chanel, module) {
66
- var _this = _super.call(this, chanel, module) || this;
67
- _this.secureHandler = _this.secureHandler.bind(_this);
68
- _this.mode = ActionMode.DEFAULT;
69
- return _this;
21
+ class BaseAction extends core_1.CoreAction {
22
+ constructor(chanel, module) {
23
+ super(chanel, module);
24
+ this.secureHandler = this.secureHandler.bind(this);
25
+ this.mode = ActionMode.DEFAULT;
70
26
  }
71
- BaseAction.prototype.secureHandler = function (req, res, next) {
72
- return __awaiter(this, void 0, void 0, function () {
73
- var extension, auth, cc, dat;
74
- var _this = this;
75
- return __generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0:
78
- extension = this.initExtension(res);
79
- auth = extension.timing.start('auth');
80
- res.on('finish', function () {
81
- _this.getKernel().responseCodeFunction({
82
- code: res.statusCode,
83
- req: req,
84
- });
85
- });
86
- cc = this.getKernel().getCryptoClient();
87
- if (!cc) {
88
- res.status(504).send('internal server error');
89
- return [2 /*return*/];
90
- }
91
- if (!(this.mode === ActionMode.DMZ)) return [3 /*break*/, 2];
92
- auth.stop();
93
- return [4 /*yield*/, this.handler(req, res, next, null, extension)];
94
- case 1:
95
- _a.sent();
96
- return [2 /*return*/];
97
- case 2: return [4 /*yield*/, cc.bearerTokenValidation(req)];
98
- case 3:
99
- dat = _a.sent();
100
- auth.stop();
101
- if (!dat) return [3 /*break*/, 5];
102
- return [4 /*yield*/, this.handler(req, res, next, dat, extension)];
103
- case 4:
104
- _a.sent();
105
- return [3 /*break*/, 8];
106
- case 5:
107
- if (!(this.mode === ActionMode.DMZ_WITH_USER)) return [3 /*break*/, 7];
108
- return [4 /*yield*/, this.handler(req, res, next, null, extension)];
109
- case 6:
110
- _a.sent();
111
- return [3 /*break*/, 8];
112
- case 7:
113
- res.status(401).send('no no no ...');
114
- _a.label = 8;
115
- case 8: return [2 /*return*/];
116
- }
27
+ secureHandler(req, res, next) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const extension = this.initExtension(res);
30
+ const auth = extension.timing.start('auth');
31
+ res.on('finish', () => {
32
+ this.getKernel().responseCodeFunction({
33
+ code: res.statusCode,
34
+ req,
35
+ });
117
36
  });
37
+ const cc = this.getKernel().getCryptoClient();
38
+ if (!cc) {
39
+ res.status(504).send('internal server error');
40
+ return;
41
+ }
42
+ if (this.mode === ActionMode.DMZ) {
43
+ auth.stop();
44
+ yield this.handler(req, res, next, null, extension);
45
+ return;
46
+ }
47
+ const dat = yield cc.bearerTokenValidation(req);
48
+ auth.stop();
49
+ if (dat) {
50
+ yield this.handler(req, res, next, dat, extension);
51
+ }
52
+ else if (this.mode === ActionMode.DMZ_WITH_USER) {
53
+ yield this.handler(req, res, next, null, extension);
54
+ }
55
+ else {
56
+ res.status(401).send('no no no ...');
57
+ }
118
58
  });
119
- };
120
- BaseAction.prototype.setMode = function (mode) {
59
+ }
60
+ setMode(mode) {
121
61
  this.mode = mode;
122
- };
123
- BaseAction.prototype.initExtension = function (res) {
124
- var _a = timing_1.ExpressServerTiming.init(this, res), el = _a[0], fx = _a[1];
62
+ }
63
+ initExtension(res) {
64
+ const [el, fx] = timing_1.ExpressServerTiming.init(this, res);
125
65
  return {
126
- done: function () {
66
+ done: () => {
127
67
  fx();
128
68
  },
129
69
  timing: el,
130
70
  };
131
- };
132
- return BaseAction;
133
- }(core_1.CoreAction));
71
+ }
72
+ }
134
73
  exports.default = BaseAction;
@@ -1,34 +1,17 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
18
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
4
  };
20
5
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var BaseAction_1 = __importDefault(require("./BaseAction"));
22
- var BaseApiAction = /** @class */ (function (_super) {
23
- __extends(BaseApiAction, _super);
24
- function BaseApiAction(type, chanel, module, extMod) {
25
- var _this = _super.call(this, chanel, module) || this;
26
- _this.exmod = extMod;
27
- _this.type = type;
28
- return _this;
6
+ const BaseAction_1 = __importDefault(require("./BaseAction"));
7
+ class BaseApiAction extends BaseAction_1.default {
8
+ constructor(type, chanel, module, extMod) {
9
+ super(chanel, module);
10
+ this.exmod = extMod;
11
+ this.type = type;
29
12
  }
30
- BaseApiAction.prototype.register = function () {
31
- var endpoint;
13
+ register() {
14
+ let endpoint;
32
15
  if (this.exmod) {
33
16
  endpoint = this.exmod.getPresenter();
34
17
  }
@@ -36,8 +19,8 @@ var BaseApiAction = /** @class */ (function (_super) {
36
19
  endpoint = this.getModule().getPresenter();
37
20
  }
38
21
  if (endpoint) {
39
- this.debug("register ".concat(this.type, " ").concat(this.getName()));
40
- var app = endpoint.getApp();
22
+ this.debug(`register ${this.type} ${this.getName()}`);
23
+ const app = endpoint.getApp();
41
24
  switch (this.type) {
42
25
  case 'POST':
43
26
  app.post(this.getName(), this.secureHandler);
@@ -58,10 +41,9 @@ var BaseApiAction = /** @class */ (function (_super) {
58
41
  }
59
42
  }
60
43
  else {
61
- this.error("on register -> ".concat(this.getName()));
62
- this.error("No Endpoint found");
44
+ this.error(`on register -> ${this.getName()}`);
45
+ this.error(`No Endpoint found`);
63
46
  }
64
- };
65
- return BaseApiAction;
66
- }(BaseAction_1.default));
47
+ }
48
+ }
67
49
  exports.default = BaseApiAction;
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var BaseAuthProvider = /** @class */ (function () {
4
- function BaseAuthProvider() {
5
- }
6
- return BaseAuthProvider;
7
- }());
3
+ class BaseAuthProvider {
4
+ }
8
5
  exports.default = BaseAuthProvider;
@@ -1,65 +1,45 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
18
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
4
  };
20
5
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var express_1 = __importDefault(require("express"));
22
- var http_1 = __importDefault(require("http"));
23
- var body_parser_1 = require("body-parser");
24
- var core_1 = require("@grandlinex/core");
25
- var BaseEndpoint = /** @class */ (function (_super) {
26
- __extends(BaseEndpoint, _super);
27
- function BaseEndpoint(chanel, module, port) {
28
- var _this = _super.call(this, "endpoint-".concat(chanel), module) || this;
29
- _this.port = port;
30
- _this.appServer = (0, express_1.default)();
31
- _this.appServer.use((0, body_parser_1.json)());
32
- _this.httpServer = http_1.default.createServer(_this.appServer);
33
- return _this;
6
+ const express_1 = __importDefault(require("express"));
7
+ const http_1 = __importDefault(require("http"));
8
+ const body_parser_1 = require("body-parser");
9
+ const core_1 = require("@grandlinex/core");
10
+ class BaseEndpoint extends core_1.CorePresenter {
11
+ constructor(chanel, module, port) {
12
+ super(`endpoint-${chanel}`, module);
13
+ this.port = port;
14
+ this.appServer = (0, express_1.default)();
15
+ this.appServer.use((0, body_parser_1.json)());
16
+ this.httpServer = http_1.default.createServer(this.appServer);
34
17
  }
35
- BaseEndpoint.prototype.start = function () {
36
- var _this = this;
37
- return new Promise(function (resolve) {
38
- _this.httpServer
39
- .listen(_this.port, function () {
40
- _this.info("Endpoint listen on ".concat(_this.port));
18
+ start() {
19
+ return new Promise((resolve) => {
20
+ this.httpServer
21
+ .listen(this.port, () => {
22
+ this.info(`Endpoint listen on ${this.port}`);
41
23
  resolve(true);
42
24
  })
43
- .on('error', function (err) {
44
- _this.error(err);
25
+ .on('error', (err) => {
26
+ this.error(err);
45
27
  resolve(false);
46
28
  });
47
29
  });
48
- };
49
- BaseEndpoint.prototype.stop = function () {
50
- var _this = this;
51
- return new Promise(function (resolve) {
52
- if (_this.httpServer) {
53
- _this.httpServer.close(function (err) { return (err ? resolve(false) : resolve(true)); });
30
+ }
31
+ stop() {
32
+ return new Promise((resolve) => {
33
+ if (this.httpServer) {
34
+ this.httpServer.close((err) => (err ? resolve(false) : resolve(true)));
54
35
  }
55
36
  });
56
- };
57
- BaseEndpoint.prototype.getApp = function () {
37
+ }
38
+ getApp() {
58
39
  return this.appServer;
59
- };
60
- BaseEndpoint.prototype.getServer = function () {
40
+ }
41
+ getServer() {
61
42
  return this.httpServer;
62
- };
63
- return BaseEndpoint;
64
- }(core_1.CorePresenter));
43
+ }
44
+ }
65
45
  exports.default = BaseEndpoint;
@@ -1,26 +1,6 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
- var core_1 = require("@grandlinex/core");
19
- var BaseKernelModule = /** @class */ (function (_super) {
20
- __extends(BaseKernelModule, _super);
21
- function BaseKernelModule() {
22
- return _super !== null && _super.apply(this, arguments) || this;
23
- }
24
- return BaseKernelModule;
25
- }(core_1.CoreKernelModule));
3
+ const core_1 = require("@grandlinex/core");
4
+ class BaseKernelModule extends core_1.CoreKernelModule {
5
+ }
26
6
  exports.default = BaseKernelModule;
@@ -18,22 +18,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
21
- var core_1 = require("@grandlinex/core");
21
+ const core_1 = require("@grandlinex/core");
22
22
  Object.defineProperty(exports, "BaseBridge", { enumerable: true, get: function () { return core_1.CoreBridge; } });
23
23
  Object.defineProperty(exports, "BaseCache", { enumerable: true, get: function () { return core_1.CoreCache; } });
24
24
  Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return core_1.CoreClient; } });
25
25
  Object.defineProperty(exports, "BaseElement", { enumerable: true, get: function () { return core_1.CoreElement; } });
26
26
  Object.defineProperty(exports, "BaseLoopService", { enumerable: true, get: function () { return core_1.CoreLoopService; } });
27
27
  Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return core_1.CoreService; } });
28
- var BaseAction_1 = __importDefault(require("./BaseAction"));
28
+ const BaseAction_1 = __importDefault(require("./BaseAction"));
29
29
  exports.BaseAction = BaseAction_1.default;
30
- var BaseEndpoint_1 = __importDefault(require("./BaseEndpoint"));
30
+ const BaseEndpoint_1 = __importDefault(require("./BaseEndpoint"));
31
31
  exports.BaseEndpoint = BaseEndpoint_1.default;
32
- var BaseKernelModule_1 = __importDefault(require("./BaseKernelModule"));
32
+ const BaseKernelModule_1 = __importDefault(require("./BaseKernelModule"));
33
33
  exports.BaseKernelModule = BaseKernelModule_1.default;
34
- var BaseApiAction_1 = __importDefault(require("./BaseApiAction"));
34
+ const BaseApiAction_1 = __importDefault(require("./BaseApiAction"));
35
35
  exports.BaseApiAction = BaseApiAction_1.default;
36
- var BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
36
+ const BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
37
37
  exports.BaseAuthProvider = BaseAuthProvider_1.default;
38
38
  __exportStar(require("./BaseAuthProvider"), exports);
39
39
  __exportStar(require("./timing"), exports);
@@ -8,90 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var ServerTiming_1 = __importDefault(require("./ServerTiming"));
43
- var ExpressServerTiming = /** @class */ (function () {
44
- function ExpressServerTiming(baseApiAction) {
15
+ const ServerTiming_1 = __importDefault(require("./ServerTiming"));
16
+ class ExpressServerTiming {
17
+ constructor(baseApiAction) {
45
18
  this.timing = new ServerTiming_1.default();
46
19
  this.baseApiAction = baseApiAction;
47
20
  }
48
- ExpressServerTiming.prototype.start = function (chanel) {
21
+ start(chanel) {
49
22
  return this.timing.start(chanel);
50
- };
51
- ExpressServerTiming.prototype.startFunc = function (chanel, fc) {
52
- return __awaiter(this, void 0, void 0, function () {
53
- return __generator(this, function (_a) {
54
- return [2 /*return*/, this.timing.startFunc(chanel, fc)];
55
- });
23
+ }
24
+ startFunc(chanel, fc) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return this.timing.startFunc(chanel, fc);
56
27
  });
57
- };
58
- ExpressServerTiming.prototype.dbQuery = function (fc) {
59
- return __awaiter(this, void 0, void 0, function () {
60
- return __generator(this, function (_a) {
61
- return [2 /*return*/, this.timing.startFunc('db', fc)];
62
- });
28
+ }
29
+ dbQuery(fc) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this.timing.startFunc('db', fc);
63
32
  });
64
- };
65
- ExpressServerTiming.prototype.getHeader = function () {
66
- var out = [];
67
- this.timing.map.forEach(function (element, key) {
68
- var dur = 0;
69
- element.forEach(function (el) {
33
+ }
34
+ getHeader() {
35
+ const out = [];
36
+ this.timing.map.forEach((element, key) => {
37
+ let dur = 0;
38
+ element.forEach((el) => {
70
39
  dur += el.getDuration();
71
40
  });
72
- out.push("".concat(key, ";dur=").concat(dur));
41
+ out.push(`${key};dur=${dur}`);
73
42
  });
74
43
  return out.join(', ');
75
- };
76
- ExpressServerTiming.prototype.addHeader = function (res) {
44
+ }
45
+ addHeader(res) {
77
46
  if (this.timing.map.size > 0 &&
78
47
  this.baseApiAction.getKernel().getDevMode()) {
79
- var a = ['Server-Timing', this.getHeader()];
48
+ const a = ['Server-Timing', this.getHeader()];
80
49
  res.setHeader(a[0], a[1]);
81
50
  this.baseApiAction.debug(a);
82
51
  }
83
- };
84
- ExpressServerTiming.init = function (baseApiAction, res) {
85
- var el = new ExpressServerTiming(baseApiAction);
86
- var total = el.start('total');
52
+ }
53
+ static init(baseApiAction, res) {
54
+ const el = new ExpressServerTiming(baseApiAction);
55
+ const total = el.start('total');
87
56
  return [
88
57
  el,
89
- function () {
58
+ () => {
90
59
  total.stop();
91
60
  el.addHeader(res);
92
61
  },
93
62
  ];
94
- };
95
- return ExpressServerTiming;
96
- }());
63
+ }
64
+ }
97
65
  exports.default = ExpressServerTiming;
@@ -8,66 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
43
- var ServerTiming = /** @class */ (function () {
44
- function ServerTiming() {
15
+ const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
16
+ class ServerTiming {
17
+ constructor() {
45
18
  this.map = new Map();
46
19
  }
47
- ServerTiming.prototype.start = function (chanel) {
20
+ start(chanel) {
48
21
  return new ServerTimingElement_1.default(this, chanel);
49
- };
50
- ServerTiming.prototype.startFunc = function (chanel, fc) {
51
- return __awaiter(this, void 0, void 0, function () {
52
- var el, content;
53
- return __generator(this, function (_a) {
54
- switch (_a.label) {
55
- case 0:
56
- el = new ServerTimingElement_1.default(this, chanel);
57
- return [4 /*yield*/, fc()];
58
- case 1:
59
- content = _a.sent();
60
- el.stop();
61
- return [2 /*return*/, content];
62
- }
63
- });
22
+ }
23
+ startFunc(chanel, fc) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const el = new ServerTimingElement_1.default(this, chanel);
26
+ const content = yield fc();
27
+ el.stop();
28
+ return content;
64
29
  });
65
- };
66
- ServerTiming.prototype.completeElement = function (e) {
67
- var cur = this.map.get(e.chanel) || [];
30
+ }
31
+ completeElement(e) {
32
+ const cur = this.map.get(e.chanel) || [];
68
33
  cur.push(e);
69
34
  this.map.set(e.chanel, cur);
70
- };
71
- return ServerTiming;
72
- }());
35
+ }
36
+ }
73
37
  exports.default = ServerTiming;
@@ -1,24 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var ServerTimingElement = /** @class */ (function () {
4
- function ServerTimingElement(el, chanel) {
3
+ class ServerTimingElement {
4
+ constructor(el, chanel) {
5
5
  this.el = el;
6
6
  this.chanel = chanel;
7
7
  this.start = new Date().getTime();
8
8
  this.end = -1;
9
9
  }
10
- ServerTimingElement.prototype.stop = function () {
10
+ stop() {
11
11
  if (this.end === -1) {
12
12
  this.end = new Date().getTime();
13
13
  this.el.completeElement(this);
14
14
  }
15
- };
16
- ServerTimingElement.prototype.getDuration = function () {
15
+ }
16
+ getDuration() {
17
17
  if (this.end === -1) {
18
18
  return 0;
19
19
  }
20
20
  return this.end - this.start;
21
- };
22
- return ServerTimingElement;
23
- }());
21
+ }
22
+ }
24
23
  exports.default = ServerTimingElement;