@grandlinex/kernel 0.24.0 → 0.25.2
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 +8 -0
- package/dist/actions/ApiVersionAction.d.ts +3 -2
- package/dist/actions/ApiVersionAction.js +4 -2
- package/dist/actions/GetTokenAction.d.ts +2 -1
- package/dist/actions/GetTokenAction.js +7 -3
- package/dist/classes/BaseAction.d.ts +10 -4
- package/dist/classes/BaseAction.js +36 -12
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.js +1 -0
- package/dist/classes/timing/ExpressServerTiming.d.ts +17 -0
- package/dist/classes/timing/ExpressServerTiming.js +97 -0
- package/dist/classes/timing/ServerTiming.d.ts +8 -0
- package/dist/classes/timing/ServerTiming.js +73 -0
- package/dist/classes/timing/ServerTimingElement.d.ts +12 -0
- package/dist/classes/timing/ServerTimingElement.js +24 -0
- package/dist/classes/timing/index.d.ts +4 -0
- package/dist/classes/timing/index.js +12 -0
- package/dist/lib/index.d.ts +2 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [v0.25.2] - 2022-08-07
|
|
5
|
+
### Added
|
|
6
|
+
- Add express timing api in dev mode
|
|
7
|
+
|
|
8
|
+
## [v0.25.0] - 2022-07-23
|
|
9
|
+
### Changed
|
|
10
|
+
- Update to core 0.25.0
|
|
11
|
+
|
|
4
12
|
|
|
5
13
|
## [v0.18.0] - 2022-01-10
|
|
6
14
|
### Changed
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import e from 'express';
|
|
2
2
|
import { IBaseKernelModule } from '../lib';
|
|
3
3
|
import { BaseApiAction } from '../classes';
|
|
4
|
+
import { IExtensionInterface } from '../classes/timing/ExpressServerTiming';
|
|
4
5
|
/**
|
|
5
6
|
* @name ApiVersionAction
|
|
6
7
|
*
|
|
@@ -25,6 +26,6 @@ import { BaseApiAction } from '../classes';
|
|
|
25
26
|
*
|
|
26
27
|
*/
|
|
27
28
|
export default class ApiVersionAction extends BaseApiAction {
|
|
28
|
-
constructor(module: IBaseKernelModule
|
|
29
|
-
handler(req: e.Request, res: e.Response, next: () => void): Promise<void>;
|
|
29
|
+
constructor(module: IBaseKernelModule);
|
|
30
|
+
handler(req: e.Request, res: e.Response, next: () => void, data: any, ex: IExtensionInterface): Promise<void>;
|
|
30
31
|
}
|
|
@@ -52,6 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
var classes_1 = require("../classes");
|
|
55
|
+
var BaseAction_1 = require("../classes/BaseAction");
|
|
55
56
|
/**
|
|
56
57
|
* @name ApiVersionAction
|
|
57
58
|
*
|
|
@@ -80,12 +81,13 @@ var ApiVersionAction = /** @class */ (function (_super) {
|
|
|
80
81
|
function ApiVersionAction(module) {
|
|
81
82
|
var _this = _super.call(this, 'GET', '/version', module) || this;
|
|
82
83
|
_this.handler = _this.handler.bind(_this);
|
|
83
|
-
_this.
|
|
84
|
+
_this.setMode(BaseAction_1.ActionMode.DMZ);
|
|
84
85
|
return _this;
|
|
85
86
|
}
|
|
86
|
-
ApiVersionAction.prototype.handler = function (req, res, next) {
|
|
87
|
+
ApiVersionAction.prototype.handler = function (req, res, next, data, ex) {
|
|
87
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
88
89
|
return __generator(this, function (_a) {
|
|
90
|
+
ex.done();
|
|
89
91
|
res.status(200).send({ api: 1 });
|
|
90
92
|
return [2 /*return*/];
|
|
91
93
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
2
|
import { IBaseKernelModule } from '../lib';
|
|
3
3
|
import { BaseApiAction } from '../classes';
|
|
4
|
+
import { IExtensionInterface } from '../classes/timing/ExpressServerTiming';
|
|
4
5
|
/**
|
|
5
6
|
* @openapi
|
|
6
7
|
* /token:
|
|
@@ -39,5 +40,5 @@ export default class GetTokenAction extends BaseApiAction {
|
|
|
39
40
|
* @param module Parent Module
|
|
40
41
|
*/
|
|
41
42
|
constructor(module: IBaseKernelModule<any, any, any, any>);
|
|
42
|
-
handler(req: Request, res: Response, next: () => void): Promise<void>;
|
|
43
|
+
handler(req: Request, res: Response, next: () => void, data: any, ex: IExtensionInterface): Promise<void>;
|
|
43
44
|
}
|
|
@@ -52,6 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
var classes_1 = require("../classes");
|
|
55
|
+
var BaseAction_1 = require("../classes/BaseAction");
|
|
55
56
|
/**
|
|
56
57
|
* @openapi
|
|
57
58
|
* /token:
|
|
@@ -93,10 +94,10 @@ var GetTokenAction = /** @class */ (function (_super) {
|
|
|
93
94
|
function GetTokenAction(module) {
|
|
94
95
|
var _this = _super.call(this, 'POST', '/token', module) || this;
|
|
95
96
|
_this.handler = _this.handler.bind(_this);
|
|
96
|
-
_this.
|
|
97
|
+
_this.setMode(BaseAction_1.ActionMode.DMZ);
|
|
97
98
|
return _this;
|
|
98
99
|
}
|
|
99
|
-
GetTokenAction.prototype.handler = function (req, res, next) {
|
|
100
|
+
GetTokenAction.prototype.handler = function (req, res, next, data, ex) {
|
|
100
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
101
102
|
var cc, _a, username, token, valid, jwt;
|
|
102
103
|
return __generator(this, function (_b) {
|
|
@@ -112,7 +113,9 @@ var GetTokenAction = /** @class */ (function (_super) {
|
|
|
112
113
|
return [2 /*return*/];
|
|
113
114
|
}
|
|
114
115
|
_a = req.body, username = _a.username, token = _a.token;
|
|
115
|
-
return [4 /*yield*/,
|
|
116
|
+
return [4 /*yield*/, ex.timing.startFunc('validation', function () {
|
|
117
|
+
return cc.apiTokenValidation(username, token, 'api');
|
|
118
|
+
})];
|
|
116
119
|
case 1:
|
|
117
120
|
valid = _b.sent();
|
|
118
121
|
if (valid.valid && valid.userId) {
|
|
@@ -120,6 +123,7 @@ var GetTokenAction = /** @class */ (function (_super) {
|
|
|
120
123
|
userid: valid.userId,
|
|
121
124
|
username: username,
|
|
122
125
|
});
|
|
126
|
+
ex.done();
|
|
123
127
|
res.status(200).send({ token: jwt });
|
|
124
128
|
}
|
|
125
129
|
else {
|
|
@@ -2,12 +2,18 @@ import { Request, Response } from 'express';
|
|
|
2
2
|
import { CoreAction, IDataBase } from '@grandlinex/core';
|
|
3
3
|
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib';
|
|
4
4
|
import { JwtToken } from './BaseAuthProvider';
|
|
5
|
+
import { IExtensionInterface } from './timing/ExpressServerTiming';
|
|
6
|
+
export declare enum ActionMode {
|
|
7
|
+
'DEFAULT' = 0,
|
|
8
|
+
'DMZ' = 1,
|
|
9
|
+
'DMZ_WITH_USER' = 2
|
|
10
|
+
}
|
|
5
11
|
export default abstract class BaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends CoreAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
6
|
-
|
|
12
|
+
mode: ActionMode;
|
|
7
13
|
constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
|
|
8
|
-
abstract handler(req: Request, res: Response, next: () => void, data: JwtToken | null): Promise<void>;
|
|
14
|
+
abstract handler(req: Request, res: Response, next: () => void, data: JwtToken | null, extension: IExtensionInterface): Promise<void>;
|
|
9
15
|
secureHandler(req: Request, res: Response, next: () => void): Promise<void>;
|
|
16
|
+
setMode(mode: ActionMode): void;
|
|
10
17
|
abstract register(): void;
|
|
11
|
-
|
|
12
|
-
getDmz(): boolean;
|
|
18
|
+
private initExtension;
|
|
13
19
|
}
|
|
@@ -51,22 +51,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.ActionMode = void 0;
|
|
54
55
|
var core_1 = require("@grandlinex/core");
|
|
56
|
+
var timing_1 = require("./timing");
|
|
57
|
+
var ActionMode;
|
|
58
|
+
(function (ActionMode) {
|
|
59
|
+
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
60
|
+
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
61
|
+
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
62
|
+
})(ActionMode = exports.ActionMode || (exports.ActionMode = {}));
|
|
55
63
|
var BaseAction = /** @class */ (function (_super) {
|
|
56
64
|
__extends(BaseAction, _super);
|
|
57
65
|
function BaseAction(chanel, module) {
|
|
58
66
|
var _this = _super.call(this, chanel, module) || this;
|
|
59
|
-
_this.dmz = false;
|
|
60
67
|
_this.secureHandler = _this.secureHandler.bind(_this);
|
|
68
|
+
_this.mode = ActionMode.DEFAULT;
|
|
61
69
|
return _this;
|
|
62
70
|
}
|
|
63
71
|
BaseAction.prototype.secureHandler = function (req, res, next) {
|
|
64
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var cc, dat;
|
|
73
|
+
var extension, auth, cc, dat;
|
|
66
74
|
var _this = this;
|
|
67
75
|
return __generator(this, function (_a) {
|
|
68
76
|
switch (_a.label) {
|
|
69
77
|
case 0:
|
|
78
|
+
extension = this.initExtension(res);
|
|
79
|
+
auth = extension.timing.start('auth');
|
|
70
80
|
res.on('finish', function () {
|
|
71
81
|
_this.getKernel().responseCodeFunction({
|
|
72
82
|
code: res.statusCode,
|
|
@@ -78,32 +88,46 @@ var BaseAction = /** @class */ (function (_super) {
|
|
|
78
88
|
res.status(504).send('internal server error');
|
|
79
89
|
return [2 /*return*/];
|
|
80
90
|
}
|
|
81
|
-
if (!this.
|
|
82
|
-
|
|
91
|
+
if (!(this.mode === ActionMode.DMZ)) return [3 /*break*/, 2];
|
|
92
|
+
auth.stop();
|
|
93
|
+
return [4 /*yield*/, this.handler(req, res, next, null, extension)];
|
|
83
94
|
case 1:
|
|
84
95
|
_a.sent();
|
|
85
96
|
return [2 /*return*/];
|
|
86
97
|
case 2: return [4 /*yield*/, cc.bearerTokenValidation(req)];
|
|
87
98
|
case 3:
|
|
88
99
|
dat = _a.sent();
|
|
100
|
+
auth.stop();
|
|
89
101
|
if (!dat) return [3 /*break*/, 5];
|
|
90
|
-
return [4 /*yield*/, this.handler(req, res, next, dat)];
|
|
102
|
+
return [4 /*yield*/, this.handler(req, res, next, dat, extension)];
|
|
91
103
|
case 4:
|
|
92
104
|
_a.sent();
|
|
93
|
-
return [3 /*break*/,
|
|
105
|
+
return [3 /*break*/, 8];
|
|
94
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:
|
|
95
113
|
res.status(401).send('no no no ...');
|
|
96
|
-
_a.label =
|
|
97
|
-
case
|
|
114
|
+
_a.label = 8;
|
|
115
|
+
case 8: return [2 /*return*/];
|
|
98
116
|
}
|
|
99
117
|
});
|
|
100
118
|
});
|
|
101
119
|
};
|
|
102
|
-
BaseAction.prototype.
|
|
103
|
-
this.
|
|
120
|
+
BaseAction.prototype.setMode = function (mode) {
|
|
121
|
+
this.mode = mode;
|
|
104
122
|
};
|
|
105
|
-
BaseAction.prototype.
|
|
106
|
-
|
|
123
|
+
BaseAction.prototype.initExtension = function (res) {
|
|
124
|
+
var _a = timing_1.ExpressServerTiming.init(this, res), el = _a[0], fx = _a[1];
|
|
125
|
+
return {
|
|
126
|
+
done: function () {
|
|
127
|
+
fx();
|
|
128
|
+
},
|
|
129
|
+
timing: el,
|
|
130
|
+
};
|
|
107
131
|
};
|
|
108
132
|
return BaseAction;
|
|
109
133
|
}(core_1.CoreAction));
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ import BaseKernelModule from './BaseKernelModule';
|
|
|
5
5
|
import BaseApiAction from './BaseApiAction';
|
|
6
6
|
import BaseAuthProvider from './BaseAuthProvider';
|
|
7
7
|
export * from './BaseAuthProvider';
|
|
8
|
+
export * from './timing';
|
|
8
9
|
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, };
|
package/dist/classes/index.js
CHANGED
|
@@ -36,3 +36,4 @@ exports.BaseApiAction = BaseApiAction_1.default;
|
|
|
36
36
|
var BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
|
|
37
37
|
exports.BaseAuthProvider = BaseAuthProvider_1.default;
|
|
38
38
|
__exportStar(require("./BaseAuthProvider"), exports);
|
|
39
|
+
__exportStar(require("./timing"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Response } from 'express';
|
|
2
|
+
import { CoreElement } from '@grandlinex/core';
|
|
3
|
+
export declare type IExtensionInterface = {
|
|
4
|
+
done: () => void;
|
|
5
|
+
timing: ExpressServerTiming;
|
|
6
|
+
};
|
|
7
|
+
export default class ExpressServerTiming {
|
|
8
|
+
private timing;
|
|
9
|
+
private baseApiAction;
|
|
10
|
+
constructor(baseApiAction: CoreElement<any>);
|
|
11
|
+
start(chanel: string): import("./ServerTimingElement").default;
|
|
12
|
+
startFunc<T>(chanel: string, fc: () => Promise<T>): Promise<T>;
|
|
13
|
+
dbQuery<T>(fc: () => Promise<T>): Promise<T>;
|
|
14
|
+
getHeader(): string;
|
|
15
|
+
addHeader(res: Response): void;
|
|
16
|
+
static init(baseApiAction: CoreElement<any>, res: Response): [ExpressServerTiming, () => void];
|
|
17
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
43
|
+
var ExpressServerTiming = /** @class */ (function () {
|
|
44
|
+
function ExpressServerTiming(baseApiAction) {
|
|
45
|
+
this.timing = new ServerTiming_1.default();
|
|
46
|
+
this.baseApiAction = baseApiAction;
|
|
47
|
+
}
|
|
48
|
+
ExpressServerTiming.prototype.start = function (chanel) {
|
|
49
|
+
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
|
+
});
|
|
56
|
+
});
|
|
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
|
+
});
|
|
63
|
+
});
|
|
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) {
|
|
70
|
+
dur += el.getDuration();
|
|
71
|
+
});
|
|
72
|
+
out.push("".concat(key, ";dur=").concat(dur));
|
|
73
|
+
});
|
|
74
|
+
return out.join(', ');
|
|
75
|
+
};
|
|
76
|
+
ExpressServerTiming.prototype.addHeader = function (res) {
|
|
77
|
+
if (this.timing.map.size > 0 &&
|
|
78
|
+
this.baseApiAction.getKernel().getDevMode()) {
|
|
79
|
+
var a = ['Server-Timing', this.getHeader()];
|
|
80
|
+
res.setHeader(a[0], a[1]);
|
|
81
|
+
this.baseApiAction.debug(a);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
ExpressServerTiming.init = function (baseApiAction, res) {
|
|
85
|
+
var el = new ExpressServerTiming(baseApiAction);
|
|
86
|
+
var total = el.start('total');
|
|
87
|
+
return [
|
|
88
|
+
el,
|
|
89
|
+
function () {
|
|
90
|
+
total.stop();
|
|
91
|
+
el.addHeader(res);
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
};
|
|
95
|
+
return ExpressServerTiming;
|
|
96
|
+
}());
|
|
97
|
+
exports.default = ExpressServerTiming;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ServerTimingElement, { IServerElement } from './ServerTimingElement';
|
|
2
|
+
export default class ServerTiming implements IServerElement {
|
|
3
|
+
map: Map<string, ServerTimingElement[]>;
|
|
4
|
+
constructor();
|
|
5
|
+
start(chanel: string): ServerTimingElement;
|
|
6
|
+
startFunc<T>(chanel: string, fc: () => Promise<T>): Promise<T>;
|
|
7
|
+
completeElement(e: ServerTimingElement): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
43
|
+
var ServerTiming = /** @class */ (function () {
|
|
44
|
+
function ServerTiming() {
|
|
45
|
+
this.map = new Map();
|
|
46
|
+
}
|
|
47
|
+
ServerTiming.prototype.start = function (chanel) {
|
|
48
|
+
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
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
ServerTiming.prototype.completeElement = function (e) {
|
|
67
|
+
var cur = this.map.get(e.chanel) || [];
|
|
68
|
+
cur.push(e);
|
|
69
|
+
this.map.set(e.chanel, cur);
|
|
70
|
+
};
|
|
71
|
+
return ServerTiming;
|
|
72
|
+
}());
|
|
73
|
+
exports.default = ServerTiming;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type IServerElement = {
|
|
2
|
+
completeElement: (e: ServerTimingElement) => void;
|
|
3
|
+
};
|
|
4
|
+
export default class ServerTimingElement {
|
|
5
|
+
private el;
|
|
6
|
+
readonly chanel: string;
|
|
7
|
+
private readonly start;
|
|
8
|
+
private end;
|
|
9
|
+
constructor(el: IServerElement, chanel: string);
|
|
10
|
+
stop(): void;
|
|
11
|
+
getDuration(): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ServerTimingElement = /** @class */ (function () {
|
|
4
|
+
function ServerTimingElement(el, chanel) {
|
|
5
|
+
this.el = el;
|
|
6
|
+
this.chanel = chanel;
|
|
7
|
+
this.start = new Date().getTime();
|
|
8
|
+
this.end = -1;
|
|
9
|
+
}
|
|
10
|
+
ServerTimingElement.prototype.stop = function () {
|
|
11
|
+
if (this.end === -1) {
|
|
12
|
+
this.end = new Date().getTime();
|
|
13
|
+
this.el.completeElement(this);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
ServerTimingElement.prototype.getDuration = function () {
|
|
17
|
+
if (this.end === -1) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
return this.end - this.start;
|
|
21
|
+
};
|
|
22
|
+
return ServerTimingElement;
|
|
23
|
+
}());
|
|
24
|
+
exports.default = ServerTimingElement;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import ExpressServerTiming, { IExtensionInterface } from './ExpressServerTiming';
|
|
2
|
+
import ServerTiming from './ServerTiming';
|
|
3
|
+
import ServerTimingElement from './ServerTimingElement';
|
|
4
|
+
export { ExpressServerTiming, ServerTimingElement, ServerTiming, IExtensionInterface, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ServerTiming = exports.ServerTimingElement = exports.ExpressServerTiming = void 0;
|
|
7
|
+
var ExpressServerTiming_1 = __importDefault(require("./ExpressServerTiming"));
|
|
8
|
+
exports.ExpressServerTiming = ExpressServerTiming_1.default;
|
|
9
|
+
var ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
10
|
+
exports.ServerTiming = ServerTiming_1.default;
|
|
11
|
+
var ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
12
|
+
exports.ServerTimingElement = ServerTimingElement_1.default;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import express, { Request, Response } from 'express';
|
|
2
2
|
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
3
3
|
import { IAuthProvider, JwtToken } from '../classes/BaseAuthProvider';
|
|
4
|
+
import { IExtensionInterface } from '../classes/timing/ExpressServerTiming';
|
|
4
5
|
export declare type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
5
6
|
export interface ICClient extends ICoreCClient {
|
|
6
7
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
@@ -31,5 +32,5 @@ export declare type IBaseBrige = ICoreBridge;
|
|
|
31
32
|
export declare type IBaseCache<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> = ICoreCache<K, T, P, C, E>;
|
|
32
33
|
export declare type IBaseElement<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> = ICoreElement<K, T, P, C, E>;
|
|
33
34
|
export interface IBaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends ICoreAction<K, T, P, C, E> {
|
|
34
|
-
handler(req: Request, res: Response, next: () => void, data: JwtToken | null): Promise<void>;
|
|
35
|
+
handler(req: Request, res: Response, next: () => void, data: JwtToken | null, extension: IExtensionInterface): Promise<void>;
|
|
35
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.2",
|
|
4
4
|
"description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "BSD-3-Clause",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@grandlinex/core": "^0.
|
|
31
|
-
"axios": "^0.
|
|
32
|
-
"body-parser": "^1.
|
|
33
|
-
"express": "^4.
|
|
30
|
+
"@grandlinex/core": "^0.25.1",
|
|
31
|
+
"axios": "^0.27.2",
|
|
32
|
+
"body-parser": "^1.20.0",
|
|
33
|
+
"express": "^4.18.1",
|
|
34
34
|
"jsonwebtoken": "^8.5.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@grandlinex/docs-to-openapi": "^0.6.0",
|
|
38
|
-
"@types/express": "^4.17.
|
|
38
|
+
"@types/express": "^4.17.4",
|
|
39
39
|
"@types/jest": "^27.4.0",
|
|
40
40
|
"@types/jsonwebtoken": "^8.5.6",
|
|
41
41
|
"@types/node": "^16.11.12",
|