@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.
- package/dist/Kernel.js +20 -49
- package/dist/KernelModule.js +18 -72
- package/dist/actions/ApiAuthTestAction.js +11 -59
- package/dist/actions/ApiVersionAction.js +13 -61
- package/dist/actions/GetTokenAction.js +33 -89
- package/dist/actions/index.js +3 -3
- package/dist/api/KernelEndpoint.js +3 -23
- package/dist/api/index.js +1 -1
- package/dist/classes/BaseAction.js +45 -106
- package/dist/classes/BaseApiAction.js +14 -32
- package/dist/classes/BaseAuthProvider.js +2 -5
- package/dist/classes/BaseEndpoint.js +29 -49
- package/dist/classes/BaseKernelModule.js +3 -23
- package/dist/classes/index.js +6 -6
- package/dist/classes/timing/ExpressServerTiming.js +29 -61
- package/dist/classes/timing/ServerTiming.js +16 -52
- package/dist/classes/timing/ServerTimingElement.js +7 -8
- package/dist/classes/timing/index.js +3 -3
- package/dist/index.js +2 -2
- package/dist/modules/crypto/CryptoClient.js +60 -119
- package/dist/modules/crypto/index.js +1 -1
- package/dist/modules/crypto/utils/cors.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
59
|
+
}
|
|
60
|
+
setMode(mode) {
|
|
121
61
|
this.mode = mode;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
62
|
+
}
|
|
63
|
+
initExtension(res) {
|
|
64
|
+
const [el, fx] = timing_1.ExpressServerTiming.init(this, res);
|
|
125
65
|
return {
|
|
126
|
-
done:
|
|
66
|
+
done: () => {
|
|
127
67
|
fx();
|
|
128
68
|
},
|
|
129
69
|
timing: el,
|
|
130
70
|
};
|
|
131
|
-
}
|
|
132
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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(
|
|
40
|
-
|
|
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(
|
|
62
|
-
this.error(
|
|
44
|
+
this.error(`on register -> ${this.getName()}`);
|
|
45
|
+
this.error(`No Endpoint found`);
|
|
63
46
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
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',
|
|
44
|
-
|
|
25
|
+
.on('error', (err) => {
|
|
26
|
+
this.error(err);
|
|
45
27
|
resolve(false);
|
|
46
28
|
});
|
|
47
29
|
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
37
|
+
}
|
|
38
|
+
getApp() {
|
|
58
39
|
return this.appServer;
|
|
59
|
-
}
|
|
60
|
-
|
|
40
|
+
}
|
|
41
|
+
getServer() {
|
|
61
42
|
return this.httpServer;
|
|
62
|
-
}
|
|
63
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
package/dist/classes/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
28
|
+
const BaseAction_1 = __importDefault(require("./BaseAction"));
|
|
29
29
|
exports.BaseAction = BaseAction_1.default;
|
|
30
|
-
|
|
30
|
+
const BaseEndpoint_1 = __importDefault(require("./BaseEndpoint"));
|
|
31
31
|
exports.BaseEndpoint = BaseEndpoint_1.default;
|
|
32
|
-
|
|
32
|
+
const BaseKernelModule_1 = __importDefault(require("./BaseKernelModule"));
|
|
33
33
|
exports.BaseKernelModule = BaseKernelModule_1.default;
|
|
34
|
-
|
|
34
|
+
const BaseApiAction_1 = __importDefault(require("./BaseApiAction"));
|
|
35
35
|
exports.BaseApiAction = BaseApiAction_1.default;
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
21
|
+
start(chanel) {
|
|
49
22
|
return this.timing.start(chanel);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
return
|
|
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
|
-
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
return
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
this.timing.map.forEach(
|
|
68
|
-
|
|
69
|
-
element.forEach(
|
|
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(
|
|
41
|
+
out.push(`${key};dur=${dur}`);
|
|
73
42
|
});
|
|
74
43
|
return out.join(', ');
|
|
75
|
-
}
|
|
76
|
-
|
|
44
|
+
}
|
|
45
|
+
addHeader(res) {
|
|
77
46
|
if (this.timing.map.size > 0 &&
|
|
78
47
|
this.baseApiAction.getKernel().getDevMode()) {
|
|
79
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
58
|
+
() => {
|
|
90
59
|
total.stop();
|
|
91
60
|
el.addHeader(res);
|
|
92
61
|
},
|
|
93
62
|
];
|
|
94
|
-
}
|
|
95
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
16
|
+
class ServerTiming {
|
|
17
|
+
constructor() {
|
|
45
18
|
this.map = new Map();
|
|
46
19
|
}
|
|
47
|
-
|
|
20
|
+
start(chanel) {
|
|
48
21
|
return new ServerTimingElement_1.default(this, chanel);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
+
}
|
|
16
|
+
getDuration() {
|
|
17
17
|
if (this.end === -1) {
|
|
18
18
|
return 0;
|
|
19
19
|
}
|
|
20
20
|
return this.end - this.start;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
24
23
|
exports.default = ServerTimingElement;
|