koatty 3.6.7 → 3.6.8-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/.vscode/launch.json +17 -1
- package/CHANGELOG.md +4 -0
- package/README.md +10 -6
- package/dist/README.md +10 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +55 -42
- package/dist/index.mjs +56 -43
- package/dist/package.json +12 -7
- package/jest-html-reporters-attach/result.js +1 -1
- package/package.json +12 -7
- package/tsconfig.test.json +15 -0
- package/.vscode/settings.json +0 -3
package/.vscode/launch.json
CHANGED
@@ -14,12 +14,28 @@
|
|
14
14
|
"ts-node/register"
|
15
15
|
],
|
16
16
|
"env": {
|
17
|
-
"NODE_ENV": "development"
|
17
|
+
"NODE_ENV": "development"
|
18
18
|
},
|
19
19
|
"sourceMaps": true,
|
20
20
|
"cwd": "${workspaceRoot}",
|
21
21
|
"protocol": "inspector",
|
22
22
|
"internalConsoleOptions": "neverOpen"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"type": "node",
|
26
|
+
"name": "vscode-jest-tests",
|
27
|
+
"request": "launch",
|
28
|
+
"console": "integratedTerminal",
|
29
|
+
"internalConsoleOptions": "neverOpen",
|
30
|
+
"disableOptimisticBPs": true,
|
31
|
+
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
32
|
+
"cwd": "${workspaceFolder}",
|
33
|
+
"args": [
|
34
|
+
"--config",
|
35
|
+
"jest.config.js",
|
36
|
+
"--runInBand",
|
37
|
+
"--watchAll=false"
|
38
|
+
]
|
23
39
|
}
|
24
40
|
]
|
25
41
|
}
|
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
### [3.6.8-0](https://github.com/thinkkoa/koatty/compare/v3.6.7...v3.6.8-0) (2022-03-14)
|
6
|
+
|
7
|
+
### [3.6.8-0](https://github.com/thinkkoa/koatty/compare/v3.6.7...v3.6.8-0) (2022-03-14)
|
8
|
+
|
5
9
|
### [3.6.7](https://github.com/thinkkoa/koatty/compare/v3.6.6...v3.6.7) (2022-03-09)
|
6
10
|
|
7
11
|
### [3.6.6](https://github.com/thinkkoa/koatty/compare/v3.6.5...v3.6.6) (2022-03-02)
|
package/README.md
CHANGED
@@ -103,22 +103,26 @@ export class IndexController extends BaseController {
|
|
103
103
|
```javascript
|
104
104
|
import request from 'supertest';
|
105
105
|
import { ExecBootStrap } from 'koatty';
|
106
|
-
|
107
106
|
import { App } from '../src/App';
|
108
107
|
|
109
108
|
describe('UT example', () => {
|
110
109
|
|
111
|
-
let server;
|
110
|
+
let server: any;
|
112
111
|
beforeAll(async () => {
|
112
|
+
jest.useFakeTimers();
|
113
113
|
const appInstance = await ExecBootStrap()(App);
|
114
|
-
server = appInstance.
|
114
|
+
server = await appInstance.listen();
|
115
115
|
});
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
expect(rsp.status).toBe(200);
|
117
|
+
afterAll(done => {
|
118
|
+
server.close();
|
120
119
|
done();
|
121
120
|
});
|
121
|
+
|
122
|
+
it('request', async () => {
|
123
|
+
const rsp = await request(server).get('/');
|
124
|
+
expect(rsp.status).toBe(200);
|
125
|
+
});
|
122
126
|
});
|
123
127
|
|
124
128
|
```
|
package/dist/README.md
CHANGED
@@ -103,22 +103,26 @@ export class IndexController extends BaseController {
|
|
103
103
|
```javascript
|
104
104
|
import request from 'supertest';
|
105
105
|
import { ExecBootStrap } from 'koatty';
|
106
|
-
|
107
106
|
import { App } from '../src/App';
|
108
107
|
|
109
108
|
describe('UT example', () => {
|
110
109
|
|
111
|
-
let server;
|
110
|
+
let server: any;
|
112
111
|
beforeAll(async () => {
|
112
|
+
jest.useFakeTimers();
|
113
113
|
const appInstance = await ExecBootStrap()(App);
|
114
|
-
server = appInstance.
|
114
|
+
server = await appInstance.listen();
|
115
115
|
});
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
expect(rsp.status).toBe(200);
|
117
|
+
afterAll(done => {
|
118
|
+
server.close();
|
120
119
|
done();
|
121
120
|
});
|
121
|
+
|
122
|
+
it('request', async () => {
|
123
|
+
const rsp = await request(server).get('/');
|
124
|
+
expect(rsp.status).toBe(200);
|
125
|
+
});
|
122
126
|
});
|
123
127
|
|
124
128
|
```
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-03-
|
3
|
+
* @Date: 2022-03-14 18:27:53
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -171,7 +171,7 @@ export declare function Controller(path?: string): ClassDecorator;
|
|
171
171
|
* @param {Function} [bootFunc] callback function
|
172
172
|
* @returns
|
173
173
|
*/
|
174
|
-
export declare function ExecBootStrap(bootFunc?: Function): (target: any) => Promise<
|
174
|
+
export declare function ExecBootStrap(bootFunc?: Function): (target: any) => Promise<Koatty>;
|
175
175
|
|
176
176
|
export { Helper }
|
177
177
|
|
@@ -225,7 +225,7 @@ export declare class HttpController extends BaseController {
|
|
225
225
|
* @returns
|
226
226
|
* @memberof HttpController
|
227
227
|
*/
|
228
|
-
param(name?: string): any
|
228
|
+
param(name?: string): Promise<any>;
|
229
229
|
/**
|
230
230
|
* Set response content-type
|
231
231
|
*
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-03-
|
3
|
+
* @Date: 2022-03-14 18:27:34
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -491,13 +491,14 @@ class Loader {
|
|
491
491
|
* @memberof Loader
|
492
492
|
*/
|
493
493
|
static initialize(app) {
|
494
|
-
|
494
|
+
var _a, _b;
|
495
|
+
const env = ((_a = process.execArgv) !== null && _a !== void 0 ? _a : []).join(",");
|
495
496
|
if (env.indexOf('ts-node') > -1 || env.indexOf('--debug') > -1) {
|
496
497
|
app.appDebug = true;
|
497
498
|
}
|
498
499
|
// app.env
|
499
500
|
app.env = process.env.KOATTY_ENV || process.env.NODE_ENV;
|
500
|
-
if ((env.indexOf('--production') > -1) || ((app.env
|
501
|
+
if ((env.indexOf('--production') > -1) || (((_b = app.env) !== null && _b !== void 0 ? _b : '').indexOf('pro') > -1)) {
|
501
502
|
app.appDebug = false;
|
502
503
|
}
|
503
504
|
if (app.appDebug) {
|
@@ -601,7 +602,8 @@ class Loader {
|
|
601
602
|
* @memberof Loader
|
602
603
|
*/
|
603
604
|
static SetLogger(app) {
|
604
|
-
|
605
|
+
var _a;
|
606
|
+
const configs = (_a = app.getMetaData("_configs")) !== null && _a !== void 0 ? _a : {};
|
605
607
|
//Logger
|
606
608
|
if (configs.config) {
|
607
609
|
const opt = configs.config;
|
@@ -677,6 +679,7 @@ class Loader {
|
|
677
679
|
* @memberof Loader
|
678
680
|
*/
|
679
681
|
static async LoadMiddlewares(app, loadPath) {
|
682
|
+
var _a;
|
680
683
|
let middlewareConf = app.config(undefined, "middleware");
|
681
684
|
if (koatty_lib.Helper.isEmpty(middlewareConf)) {
|
682
685
|
middlewareConf = { config: {}, list: [] };
|
@@ -685,11 +688,12 @@ class Loader {
|
|
685
688
|
koatty_loader.Load(loadPath || ["./middleware"], app.thinkPath);
|
686
689
|
//Mount application middleware
|
687
690
|
// const middleware: any = {};
|
688
|
-
const appMiddleware = koatty_container.IOCContainer.listClass("MIDDLEWARE")
|
691
|
+
const appMiddleware = (_a = koatty_container.IOCContainer.listClass("MIDDLEWARE")) !== null && _a !== void 0 ? _a : [];
|
689
692
|
appMiddleware.push({ id: "TraceMiddleware", target: TraceMiddleware });
|
690
693
|
appMiddleware.push({ id: "PayloadMiddleware", target: PayloadMiddleware });
|
691
694
|
appMiddleware.forEach((item) => {
|
692
|
-
|
695
|
+
var _a;
|
696
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
693
697
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
694
698
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
695
699
|
}
|
@@ -745,9 +749,10 @@ class Loader {
|
|
745
749
|
*/
|
746
750
|
static LoadControllers(app) {
|
747
751
|
const controllerList = koatty_container.IOCContainer.listClass("CONTROLLER");
|
748
|
-
const controllers =
|
752
|
+
const controllers = [];
|
749
753
|
controllerList.forEach((item) => {
|
750
|
-
|
754
|
+
var _a;
|
755
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("CONTROLLER:", "");
|
751
756
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
752
757
|
Logger.Debug(`Load controller: ${item.id}`);
|
753
758
|
// registering to IOC
|
@@ -756,10 +761,10 @@ class Loader {
|
|
756
761
|
if (!(ctl instanceof BaseController)) {
|
757
762
|
throw new Error(`class ${item.id} does not inherit from BaseController`);
|
758
763
|
}
|
759
|
-
controllers
|
764
|
+
controllers.push(item.id);
|
760
765
|
}
|
761
766
|
});
|
762
|
-
|
767
|
+
return controllers;
|
763
768
|
}
|
764
769
|
/**
|
765
770
|
* Load services
|
@@ -771,7 +776,8 @@ class Loader {
|
|
771
776
|
static LoadServices(app) {
|
772
777
|
const serviceList = koatty_container.IOCContainer.listClass("SERVICE");
|
773
778
|
serviceList.forEach((item) => {
|
774
|
-
|
779
|
+
var _a;
|
780
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("SERVICE:", "");
|
775
781
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
776
782
|
Logger.Debug(`Load service: ${item.id}`);
|
777
783
|
// registering to IOC
|
@@ -789,7 +795,8 @@ class Loader {
|
|
789
795
|
static LoadComponents(app) {
|
790
796
|
const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
|
791
797
|
componentList.forEach((item) => {
|
792
|
-
|
798
|
+
var _a;
|
799
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
793
800
|
if (item.id && !(item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
794
801
|
Logger.Debug(`Load component: ${item.id}`);
|
795
802
|
// registering to IOC
|
@@ -805,6 +812,7 @@ class Loader {
|
|
805
812
|
* @memberof Loader
|
806
813
|
*/
|
807
814
|
static async LoadPlugins(app) {
|
815
|
+
var _a;
|
808
816
|
const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
|
809
817
|
let pluginsConf = app.config(undefined, "plugin");
|
810
818
|
if (koatty_lib.Helper.isEmpty(pluginsConf)) {
|
@@ -812,7 +820,8 @@ class Loader {
|
|
812
820
|
}
|
813
821
|
const pluginList = [];
|
814
822
|
componentList.forEach(async (item) => {
|
815
|
-
|
823
|
+
var _a;
|
824
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
816
825
|
if (item.id && (item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
817
826
|
// registering to IOC
|
818
827
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
@@ -833,12 +842,12 @@ class Loader {
|
|
833
842
|
continue;
|
834
843
|
}
|
835
844
|
// sync exec
|
836
|
-
await handle.run(pluginsConf.config[key]
|
845
|
+
await handle.run((_a = pluginsConf.config[key]) !== null && _a !== void 0 ? _a : {}, app);
|
837
846
|
}
|
838
847
|
}
|
839
848
|
}
|
840
849
|
|
841
|
-
var version = "3.6.
|
850
|
+
var version = "3.6.8-0";
|
842
851
|
var engines = {
|
843
852
|
node: ">12.0.0"
|
844
853
|
};
|
@@ -949,6 +958,10 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
949
958
|
Loader.LoadAppReadyHooks(app, target);
|
950
959
|
// New router
|
951
960
|
const KoattyRouter = newRouter(app);
|
961
|
+
koatty_lib.Helper.define(app, "router", KoattyRouter);
|
962
|
+
// Create Server
|
963
|
+
app.server = newServe(app);
|
964
|
+
koatty_lib.Helper.define(app, "listenCallback", listenCallback(app));
|
952
965
|
// Load Middleware
|
953
966
|
Logger.Log('think', '', 'Load Middlewares ...');
|
954
967
|
await Loader.LoadMiddlewares(app);
|
@@ -960,24 +973,17 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
960
973
|
Loader.LoadServices(app);
|
961
974
|
// Load Controllers
|
962
975
|
Logger.Log('think', '', 'Load Controllers ...');
|
963
|
-
Loader.LoadControllers(app);
|
976
|
+
const controllers = Loader.LoadControllers(app);
|
977
|
+
// Load Routers
|
978
|
+
Logger.Log('think', '', 'Load Routers ...');
|
979
|
+
KoattyRouter.LoadRouter(controllers);
|
964
980
|
// Emit app ready event
|
965
981
|
Logger.Log('think', '', 'Emit App Ready ...');
|
966
|
-
// app.emit("appReady");
|
967
982
|
await asyncEvent(app, 'appReady');
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
// Start server
|
973
|
-
const server = newServe(app);
|
974
|
-
app.listen(server, listenCallback(app, server.options));
|
975
|
-
// app.emit("appStart");
|
976
|
-
// Emit app started event
|
977
|
-
Logger.Log('think', '', 'Emit App Start ...');
|
978
|
-
asyncEvent(app, 'appStart');
|
979
|
-
// binding event "appStop"
|
980
|
-
koatty_serve.BindProcessEvent(app, 'appStop');
|
983
|
+
if (!isUTRuntime) {
|
984
|
+
app.listen();
|
985
|
+
}
|
986
|
+
return app;
|
981
987
|
}
|
982
988
|
catch (err) {
|
983
989
|
Logger.Error(err);
|
@@ -992,26 +998,34 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
992
998
|
* @returns {*}
|
993
999
|
*/
|
994
1000
|
const newRouter = function (app) {
|
1001
|
+
var _a;
|
995
1002
|
const protocol = app.config("protocol") || "http";
|
996
|
-
const options = app.config(undefined, 'router')
|
1003
|
+
const options = (_a = app.config(undefined, 'router')) !== null && _a !== void 0 ? _a : {};
|
997
1004
|
const router = koatty_router.NewRouter(app, options, protocol);
|
998
|
-
koatty_lib.Helper.define(app, "router", router);
|
999
1005
|
return router;
|
1000
1006
|
};
|
1001
1007
|
/**
|
1002
1008
|
* Listening callback function
|
1003
1009
|
*
|
1004
1010
|
* @param {Koatty} app
|
1005
|
-
* @param {ListeningOptions} options
|
1006
1011
|
* @returns {*}
|
1007
1012
|
*/
|
1008
|
-
const listenCallback = (app
|
1013
|
+
const listenCallback = (app) => {
|
1014
|
+
const options = app.server.options;
|
1009
1015
|
return function () {
|
1016
|
+
// Emit app started event
|
1017
|
+
Logger.Log('think', '', 'Emit App Start ...');
|
1018
|
+
asyncEvent(app, 'appStart');
|
1019
|
+
Logger.Log('think', '', '====================================');
|
1010
1020
|
Logger.Log("think", "", `Nodejs Version: ${process.version}`);
|
1011
1021
|
Logger.Log("think", "", `Koatty Version: v${app.version}`);
|
1012
1022
|
Logger.Log("think", "", `App Environment: ${app.env}`);
|
1023
|
+
Logger.Log('think', '', `Server Protocol: ${(options.protocol).toUpperCase()}`);
|
1013
1024
|
Logger.Log("think", "", `Server running at ${options.protocol === "http2" ? "https" : options.protocol}://${options.hostname || '127.0.0.1'}:${options.port}/`);
|
1014
1025
|
Logger.Log("think", "", "====================================");
|
1026
|
+
// binding event "appStop"
|
1027
|
+
Logger.Log('think', '', 'Bind App Stop event ...');
|
1028
|
+
koatty_serve.BindProcessEvent(app, 'appStop');
|
1015
1029
|
// tslint:disable-next-line: no-unused-expression
|
1016
1030
|
app.appDebug && Logger.Warn(`Running in debug mode.`);
|
1017
1031
|
};
|
@@ -1023,11 +1037,12 @@ const listenCallback = (app, options) => {
|
|
1023
1037
|
* @returns {*}
|
1024
1038
|
*/
|
1025
1039
|
const newServe = function (app) {
|
1040
|
+
var _a, _b, _c;
|
1026
1041
|
const protocol = app.config("protocol") || "http";
|
1027
1042
|
const port = process.env.PORT || process.env.APP_PORT ||
|
1028
1043
|
app.config('app_port') || 3000;
|
1029
1044
|
const hostname = process.env.IP ||
|
1030
|
-
process.env.HOSTNAME
|
1045
|
+
((_a = process.env.HOSTNAME) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '.')) || app.config('app_host') || '127.0.0.1';
|
1031
1046
|
const options = {
|
1032
1047
|
hostname,
|
1033
1048
|
port,
|
@@ -1040,8 +1055,8 @@ const newServe = function (app) {
|
|
1040
1055
|
};
|
1041
1056
|
const pm = new Set(["https", "http2", "wss"]);
|
1042
1057
|
if (pm.has(options.protocol)) {
|
1043
|
-
const keyFile = app.config("key_file")
|
1044
|
-
const crtFile = app.config("crt_file")
|
1058
|
+
const keyFile = (_b = app.config("key_file")) !== null && _b !== void 0 ? _b : "";
|
1059
|
+
const crtFile = (_c = app.config("crt_file")) !== null && _c !== void 0 ? _c : "";
|
1045
1060
|
options.ext.key = fs__default["default"].readFileSync(keyFile).toString();
|
1046
1061
|
options.ext.cert = fs__default["default"].readFileSync(crtFile).toString();
|
1047
1062
|
}
|
@@ -1052,9 +1067,7 @@ const newServe = function (app) {
|
|
1052
1067
|
const proto = app.config("protoFile", "router");
|
1053
1068
|
options.ext.protoFile = proto;
|
1054
1069
|
}
|
1055
|
-
|
1056
|
-
koatty_lib.Helper.define(app, "server", server);
|
1057
|
-
return server;
|
1070
|
+
return koatty_serve.Serve(app, options);
|
1058
1071
|
};
|
1059
1072
|
/**
|
1060
1073
|
* Execute event as async
|
@@ -1114,7 +1127,7 @@ function ComponentScan(scanPath) {
|
|
1114
1127
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1115
1128
|
throw new Error(`class does not inherit from Koatty`);
|
1116
1129
|
}
|
1117
|
-
scanPath = scanPath
|
1130
|
+
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
1118
1131
|
koatty_container.IOCContainer.saveClassMetadata(koatty_container.TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
|
1119
1132
|
};
|
1120
1133
|
}
|
@@ -1130,7 +1143,7 @@ function ConfigurationScan(scanPath) {
|
|
1130
1143
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1131
1144
|
throw new Error(`class does not inherit from Koatty`);
|
1132
1145
|
}
|
1133
|
-
scanPath = scanPath
|
1146
|
+
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
1134
1147
|
koatty_container.IOCContainer.saveClassMetadata(koatty_container.TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
|
1135
1148
|
};
|
1136
1149
|
}
|
package/dist/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-03-
|
3
|
+
* @Date: 2022-03-14 18:27:34
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -15,7 +15,7 @@ import { NewRouter, CONTROLLER_ROUTER } from 'koatty_router';
|
|
15
15
|
export * from 'koatty_router';
|
16
16
|
import { IOCContainer, TAGGED_CLS } from 'koatty_container';
|
17
17
|
export * from 'koatty_container';
|
18
|
-
import {
|
18
|
+
import { Serve, BindProcessEvent } from 'koatty_serve';
|
19
19
|
export * from 'koatty_serve';
|
20
20
|
import * as path from 'path';
|
21
21
|
import { Load } from 'koatty_loader';
|
@@ -471,13 +471,14 @@ class Loader {
|
|
471
471
|
* @memberof Loader
|
472
472
|
*/
|
473
473
|
static initialize(app) {
|
474
|
-
|
474
|
+
var _a, _b;
|
475
|
+
const env = ((_a = process.execArgv) !== null && _a !== void 0 ? _a : []).join(",");
|
475
476
|
if (env.indexOf('ts-node') > -1 || env.indexOf('--debug') > -1) {
|
476
477
|
app.appDebug = true;
|
477
478
|
}
|
478
479
|
// app.env
|
479
480
|
app.env = process.env.KOATTY_ENV || process.env.NODE_ENV;
|
480
|
-
if ((env.indexOf('--production') > -1) || ((app.env
|
481
|
+
if ((env.indexOf('--production') > -1) || (((_b = app.env) !== null && _b !== void 0 ? _b : '').indexOf('pro') > -1)) {
|
481
482
|
app.appDebug = false;
|
482
483
|
}
|
483
484
|
if (app.appDebug) {
|
@@ -581,7 +582,8 @@ class Loader {
|
|
581
582
|
* @memberof Loader
|
582
583
|
*/
|
583
584
|
static SetLogger(app) {
|
584
|
-
|
585
|
+
var _a;
|
586
|
+
const configs = (_a = app.getMetaData("_configs")) !== null && _a !== void 0 ? _a : {};
|
585
587
|
//Logger
|
586
588
|
if (configs.config) {
|
587
589
|
const opt = configs.config;
|
@@ -657,6 +659,7 @@ class Loader {
|
|
657
659
|
* @memberof Loader
|
658
660
|
*/
|
659
661
|
static async LoadMiddlewares(app, loadPath) {
|
662
|
+
var _a;
|
660
663
|
let middlewareConf = app.config(undefined, "middleware");
|
661
664
|
if (Helper.isEmpty(middlewareConf)) {
|
662
665
|
middlewareConf = { config: {}, list: [] };
|
@@ -665,11 +668,12 @@ class Loader {
|
|
665
668
|
Load(loadPath || ["./middleware"], app.thinkPath);
|
666
669
|
//Mount application middleware
|
667
670
|
// const middleware: any = {};
|
668
|
-
const appMiddleware = IOCContainer.listClass("MIDDLEWARE")
|
671
|
+
const appMiddleware = (_a = IOCContainer.listClass("MIDDLEWARE")) !== null && _a !== void 0 ? _a : [];
|
669
672
|
appMiddleware.push({ id: "TraceMiddleware", target: TraceMiddleware });
|
670
673
|
appMiddleware.push({ id: "PayloadMiddleware", target: PayloadMiddleware });
|
671
674
|
appMiddleware.forEach((item) => {
|
672
|
-
|
675
|
+
var _a;
|
676
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
673
677
|
if (item.id && Helper.isClass(item.target)) {
|
674
678
|
IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
675
679
|
}
|
@@ -725,9 +729,10 @@ class Loader {
|
|
725
729
|
*/
|
726
730
|
static LoadControllers(app) {
|
727
731
|
const controllerList = IOCContainer.listClass("CONTROLLER");
|
728
|
-
const controllers =
|
732
|
+
const controllers = [];
|
729
733
|
controllerList.forEach((item) => {
|
730
|
-
|
734
|
+
var _a;
|
735
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("CONTROLLER:", "");
|
731
736
|
if (item.id && Helper.isClass(item.target)) {
|
732
737
|
Logger.Debug(`Load controller: ${item.id}`);
|
733
738
|
// registering to IOC
|
@@ -736,10 +741,10 @@ class Loader {
|
|
736
741
|
if (!(ctl instanceof BaseController)) {
|
737
742
|
throw new Error(`class ${item.id} does not inherit from BaseController`);
|
738
743
|
}
|
739
|
-
controllers
|
744
|
+
controllers.push(item.id);
|
740
745
|
}
|
741
746
|
});
|
742
|
-
|
747
|
+
return controllers;
|
743
748
|
}
|
744
749
|
/**
|
745
750
|
* Load services
|
@@ -751,7 +756,8 @@ class Loader {
|
|
751
756
|
static LoadServices(app) {
|
752
757
|
const serviceList = IOCContainer.listClass("SERVICE");
|
753
758
|
serviceList.forEach((item) => {
|
754
|
-
|
759
|
+
var _a;
|
760
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("SERVICE:", "");
|
755
761
|
if (item.id && Helper.isClass(item.target)) {
|
756
762
|
Logger.Debug(`Load service: ${item.id}`);
|
757
763
|
// registering to IOC
|
@@ -769,7 +775,8 @@ class Loader {
|
|
769
775
|
static LoadComponents(app) {
|
770
776
|
const componentList = IOCContainer.listClass("COMPONENT");
|
771
777
|
componentList.forEach((item) => {
|
772
|
-
|
778
|
+
var _a;
|
779
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
773
780
|
if (item.id && !(item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
|
774
781
|
Logger.Debug(`Load component: ${item.id}`);
|
775
782
|
// registering to IOC
|
@@ -785,6 +792,7 @@ class Loader {
|
|
785
792
|
* @memberof Loader
|
786
793
|
*/
|
787
794
|
static async LoadPlugins(app) {
|
795
|
+
var _a;
|
788
796
|
const componentList = IOCContainer.listClass("COMPONENT");
|
789
797
|
let pluginsConf = app.config(undefined, "plugin");
|
790
798
|
if (Helper.isEmpty(pluginsConf)) {
|
@@ -792,7 +800,8 @@ class Loader {
|
|
792
800
|
}
|
793
801
|
const pluginList = [];
|
794
802
|
componentList.forEach(async (item) => {
|
795
|
-
|
803
|
+
var _a;
|
804
|
+
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
796
805
|
if (item.id && (item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
|
797
806
|
// registering to IOC
|
798
807
|
IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
@@ -813,12 +822,12 @@ class Loader {
|
|
813
822
|
continue;
|
814
823
|
}
|
815
824
|
// sync exec
|
816
|
-
await handle.run(pluginsConf.config[key]
|
825
|
+
await handle.run((_a = pluginsConf.config[key]) !== null && _a !== void 0 ? _a : {}, app);
|
817
826
|
}
|
818
827
|
}
|
819
828
|
}
|
820
829
|
|
821
|
-
var version = "3.6.
|
830
|
+
var version = "3.6.8-0";
|
822
831
|
var engines = {
|
823
832
|
node: ">12.0.0"
|
824
833
|
};
|
@@ -929,6 +938,10 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
929
938
|
Loader.LoadAppReadyHooks(app, target);
|
930
939
|
// New router
|
931
940
|
const KoattyRouter = newRouter(app);
|
941
|
+
Helper.define(app, "router", KoattyRouter);
|
942
|
+
// Create Server
|
943
|
+
app.server = newServe(app);
|
944
|
+
Helper.define(app, "listenCallback", listenCallback(app));
|
932
945
|
// Load Middleware
|
933
946
|
Logger.Log('think', '', 'Load Middlewares ...');
|
934
947
|
await Loader.LoadMiddlewares(app);
|
@@ -940,24 +953,17 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
940
953
|
Loader.LoadServices(app);
|
941
954
|
// Load Controllers
|
942
955
|
Logger.Log('think', '', 'Load Controllers ...');
|
943
|
-
Loader.LoadControllers(app);
|
956
|
+
const controllers = Loader.LoadControllers(app);
|
957
|
+
// Load Routers
|
958
|
+
Logger.Log('think', '', 'Load Routers ...');
|
959
|
+
KoattyRouter.LoadRouter(controllers);
|
944
960
|
// Emit app ready event
|
945
961
|
Logger.Log('think', '', 'Emit App Ready ...');
|
946
|
-
// app.emit("appReady");
|
947
962
|
await asyncEvent(app, 'appReady');
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
// Start server
|
953
|
-
const server = newServe(app);
|
954
|
-
app.listen(server, listenCallback(app, server.options));
|
955
|
-
// app.emit("appStart");
|
956
|
-
// Emit app started event
|
957
|
-
Logger.Log('think', '', 'Emit App Start ...');
|
958
|
-
asyncEvent(app, 'appStart');
|
959
|
-
// binding event "appStop"
|
960
|
-
BindProcessEvent(app, 'appStop');
|
963
|
+
if (!isUTRuntime) {
|
964
|
+
app.listen();
|
965
|
+
}
|
966
|
+
return app;
|
961
967
|
}
|
962
968
|
catch (err) {
|
963
969
|
Logger.Error(err);
|
@@ -972,26 +978,34 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
972
978
|
* @returns {*}
|
973
979
|
*/
|
974
980
|
const newRouter = function (app) {
|
981
|
+
var _a;
|
975
982
|
const protocol = app.config("protocol") || "http";
|
976
|
-
const options = app.config(undefined, 'router')
|
983
|
+
const options = (_a = app.config(undefined, 'router')) !== null && _a !== void 0 ? _a : {};
|
977
984
|
const router = NewRouter(app, options, protocol);
|
978
|
-
Helper.define(app, "router", router);
|
979
985
|
return router;
|
980
986
|
};
|
981
987
|
/**
|
982
988
|
* Listening callback function
|
983
989
|
*
|
984
990
|
* @param {Koatty} app
|
985
|
-
* @param {ListeningOptions} options
|
986
991
|
* @returns {*}
|
987
992
|
*/
|
988
|
-
const listenCallback = (app
|
993
|
+
const listenCallback = (app) => {
|
994
|
+
const options = app.server.options;
|
989
995
|
return function () {
|
996
|
+
// Emit app started event
|
997
|
+
Logger.Log('think', '', 'Emit App Start ...');
|
998
|
+
asyncEvent(app, 'appStart');
|
999
|
+
Logger.Log('think', '', '====================================');
|
990
1000
|
Logger.Log("think", "", `Nodejs Version: ${process.version}`);
|
991
1001
|
Logger.Log("think", "", `Koatty Version: v${app.version}`);
|
992
1002
|
Logger.Log("think", "", `App Environment: ${app.env}`);
|
1003
|
+
Logger.Log('think', '', `Server Protocol: ${(options.protocol).toUpperCase()}`);
|
993
1004
|
Logger.Log("think", "", `Server running at ${options.protocol === "http2" ? "https" : options.protocol}://${options.hostname || '127.0.0.1'}:${options.port}/`);
|
994
1005
|
Logger.Log("think", "", "====================================");
|
1006
|
+
// binding event "appStop"
|
1007
|
+
Logger.Log('think', '', 'Bind App Stop event ...');
|
1008
|
+
BindProcessEvent(app, 'appStop');
|
995
1009
|
// tslint:disable-next-line: no-unused-expression
|
996
1010
|
app.appDebug && Logger.Warn(`Running in debug mode.`);
|
997
1011
|
};
|
@@ -1003,11 +1017,12 @@ const listenCallback = (app, options) => {
|
|
1003
1017
|
* @returns {*}
|
1004
1018
|
*/
|
1005
1019
|
const newServe = function (app) {
|
1020
|
+
var _a, _b, _c;
|
1006
1021
|
const protocol = app.config("protocol") || "http";
|
1007
1022
|
const port = process.env.PORT || process.env.APP_PORT ||
|
1008
1023
|
app.config('app_port') || 3000;
|
1009
1024
|
const hostname = process.env.IP ||
|
1010
|
-
process.env.HOSTNAME
|
1025
|
+
((_a = process.env.HOSTNAME) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '.')) || app.config('app_host') || '127.0.0.1';
|
1011
1026
|
const options = {
|
1012
1027
|
hostname,
|
1013
1028
|
port,
|
@@ -1020,8 +1035,8 @@ const newServe = function (app) {
|
|
1020
1035
|
};
|
1021
1036
|
const pm = new Set(["https", "http2", "wss"]);
|
1022
1037
|
if (pm.has(options.protocol)) {
|
1023
|
-
const keyFile = app.config("key_file")
|
1024
|
-
const crtFile = app.config("crt_file")
|
1038
|
+
const keyFile = (_b = app.config("key_file")) !== null && _b !== void 0 ? _b : "";
|
1039
|
+
const crtFile = (_c = app.config("crt_file")) !== null && _c !== void 0 ? _c : "";
|
1025
1040
|
options.ext.key = fs.readFileSync(keyFile).toString();
|
1026
1041
|
options.ext.cert = fs.readFileSync(crtFile).toString();
|
1027
1042
|
}
|
@@ -1032,9 +1047,7 @@ const newServe = function (app) {
|
|
1032
1047
|
const proto = app.config("protoFile", "router");
|
1033
1048
|
options.ext.protoFile = proto;
|
1034
1049
|
}
|
1035
|
-
|
1036
|
-
Helper.define(app, "server", server);
|
1037
|
-
return server;
|
1050
|
+
return Serve(app, options);
|
1038
1051
|
};
|
1039
1052
|
/**
|
1040
1053
|
* Execute event as async
|
@@ -1094,7 +1107,7 @@ function ComponentScan(scanPath) {
|
|
1094
1107
|
if (!(target.prototype instanceof Koatty)) {
|
1095
1108
|
throw new Error(`class does not inherit from Koatty`);
|
1096
1109
|
}
|
1097
|
-
scanPath = scanPath
|
1110
|
+
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
1098
1111
|
IOCContainer.saveClassMetadata(TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
|
1099
1112
|
};
|
1100
1113
|
}
|
@@ -1110,7 +1123,7 @@ function ConfigurationScan(scanPath) {
|
|
1110
1123
|
if (!(target.prototype instanceof Koatty)) {
|
1111
1124
|
throw new Error(`class does not inherit from Koatty`);
|
1112
1125
|
}
|
1113
|
-
scanPath = scanPath
|
1126
|
+
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
1114
1127
|
IOCContainer.saveClassMetadata(TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
|
1115
1128
|
};
|
1116
1129
|
}
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.6.
|
3
|
+
"version": "3.6.8-0",
|
4
4
|
"description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
|
5
5
|
"scripts": {
|
6
6
|
"build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
|
@@ -50,6 +50,8 @@
|
|
50
50
|
}
|
51
51
|
],
|
52
52
|
"devDependencies": {
|
53
|
+
"@commitlint/cli": "^12.x.x",
|
54
|
+
"@commitlint/config-conventional": "^15.x.x",
|
53
55
|
"@microsoft/api-documenter": "^7.x.x",
|
54
56
|
"@microsoft/api-extractor": "^7.x.x",
|
55
57
|
"@rollup/plugin-json": "^4.x.x",
|
@@ -57,11 +59,10 @@
|
|
57
59
|
"@types/koa": "^2.x.x",
|
58
60
|
"@types/koa__router": "^8.x.x",
|
59
61
|
"@types/node": "^16.x.x",
|
62
|
+
"@types/supertest": "^2.x.x",
|
60
63
|
"@types/ws": "^8.x.x",
|
61
64
|
"@typescript-eslint/eslint-plugin": "^5.x.x",
|
62
65
|
"@typescript-eslint/parser": "^5.x.x",
|
63
|
-
"commitlint": "^11.x.x",
|
64
|
-
"commitlint-config-gitmoji": "^2.x.x",
|
65
66
|
"conventional-changelog-cli": "^2.x.x",
|
66
67
|
"copyfiles": "^2.x.x",
|
67
68
|
"del-cli": "^4.x.x",
|
@@ -70,10 +71,14 @@
|
|
70
71
|
"husky": "^4.x.x",
|
71
72
|
"jest": "^27.x.x",
|
72
73
|
"jest-html-reporters": "^2.x.x",
|
74
|
+
"koatty_cacheable": "^1.x.x",
|
75
|
+
"koatty_schedule": "^1.x.x",
|
76
|
+
"koatty_store": "^1.x.x",
|
73
77
|
"koatty_validation": "^1.x.x",
|
74
78
|
"rollup": "^2.x.x",
|
75
79
|
"rollup-plugin-typescript2": "^0.x.x",
|
76
80
|
"standard-version": "^9.x.x",
|
81
|
+
"supertest": "^6.x.x",
|
77
82
|
"ts-jest": "^27.x.x",
|
78
83
|
"ts-node": "^10.x.x",
|
79
84
|
"typescript": "^4.x.x"
|
@@ -82,15 +87,15 @@
|
|
82
87
|
"koa": "2.13.4",
|
83
88
|
"koatty_config": "1.1.2",
|
84
89
|
"koatty_container": "1.7.7",
|
85
|
-
"koatty_core": "1.6.
|
90
|
+
"koatty_core": "1.6.5",
|
86
91
|
"koatty_exception": "1.2.6",
|
87
92
|
"koatty_lib": "1.2.10",
|
88
93
|
"koatty_loader": "1.0.2",
|
89
94
|
"koatty_logger": "1.3.12",
|
90
|
-
"koatty_payload": "1.3.
|
95
|
+
"koatty_payload": "1.3.16",
|
91
96
|
"koatty_proto": "1.1.6",
|
92
|
-
"koatty_router": "1.7.
|
93
|
-
"koatty_serve": "1.4.
|
97
|
+
"koatty_router": "1.7.5",
|
98
|
+
"koatty_serve": "1.4.9",
|
94
99
|
"koatty_trace": "1.6.6",
|
95
100
|
"reflect-metadata": "0.1.13",
|
96
101
|
"tslib": "2.3.1"
|
@@ -1 +1 @@
|
|
1
|
-
window.jest_html_reporters_callback__({"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":0,"numTotalTests":0,"startTime":
|
1
|
+
window.jest_html_reporters_callback__({"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":0,"numTotalTests":0,"startTime":1647253651754,"success":false,"testResults":[],"wasInterrupted":false,"config":{"bail":0,"changedFilesWithAncestor":false,"collectCoverage":true,"collectCoverageFrom":[],"coverageDirectory":"coverage","coverageProvider":"babel","coverageReporters":["html","lcov","json","text","clover","text-summary"],"detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"expand":false,"findRelatedTests":false,"forceExit":false,"json":false,"lastCommit":false,"listTests":false,"logHeapUsage":false,"maxConcurrency":5,"maxWorkers":7,"noStackTrace":false,"nonFlagArgs":[],"notify":false,"notifyMode":"failure-change","onlyChanged":false,"onlyFailures":false,"passWithNoTests":true,"projects":[],"reporters":[["default",{}],["/Users/richen/Workspace/nodejs/koatty/node_modules/jest-html-reporters/index.js",{}]],"rootDir":"/Users/richen/Workspace/nodejs/koatty","runTestsByPath":false,"skipFilter":false,"testFailureExitCode":1,"testPathPattern":"","testSequencer":"/Users/richen/Workspace/nodejs/koatty/node_modules/@jest/test-sequencer/build/index.js","updateSnapshot":"new","useStderr":false,"watch":false,"watchAll":false,"watchman":true},"endTime":1647253651795,"_reporterOptions":{"publicPath":"/Users/richen/Workspace/nodejs/koatty","filename":"jest_html_reporters.html","expand":false,"pageTitle":"","hideIcon":false,"testCommand":"npx jest","openReport":false,"failureMessageOnly":false,"enableMergeData":false,"dataMergeLevel":1},"attachInfos":{}})
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.6.
|
3
|
+
"version": "3.6.8-0",
|
4
4
|
"description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
|
5
5
|
"scripts": {
|
6
6
|
"build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
|
@@ -50,6 +50,8 @@
|
|
50
50
|
}
|
51
51
|
],
|
52
52
|
"devDependencies": {
|
53
|
+
"@commitlint/cli": "^12.x.x",
|
54
|
+
"@commitlint/config-conventional": "^15.x.x",
|
53
55
|
"@microsoft/api-documenter": "^7.x.x",
|
54
56
|
"@microsoft/api-extractor": "^7.x.x",
|
55
57
|
"@rollup/plugin-json": "^4.x.x",
|
@@ -57,11 +59,10 @@
|
|
57
59
|
"@types/koa": "^2.x.x",
|
58
60
|
"@types/koa__router": "^8.x.x",
|
59
61
|
"@types/node": "^16.x.x",
|
62
|
+
"@types/supertest": "^2.x.x",
|
60
63
|
"@types/ws": "^8.x.x",
|
61
64
|
"@typescript-eslint/eslint-plugin": "^5.x.x",
|
62
65
|
"@typescript-eslint/parser": "^5.x.x",
|
63
|
-
"commitlint": "^11.x.x",
|
64
|
-
"commitlint-config-gitmoji": "^2.x.x",
|
65
66
|
"conventional-changelog-cli": "^2.x.x",
|
66
67
|
"copyfiles": "^2.x.x",
|
67
68
|
"del-cli": "^4.x.x",
|
@@ -70,10 +71,14 @@
|
|
70
71
|
"husky": "^4.x.x",
|
71
72
|
"jest": "^27.x.x",
|
72
73
|
"jest-html-reporters": "^2.x.x",
|
74
|
+
"koatty_cacheable": "^1.x.x",
|
75
|
+
"koatty_schedule": "^1.x.x",
|
76
|
+
"koatty_store": "^1.x.x",
|
73
77
|
"koatty_validation": "^1.x.x",
|
74
78
|
"rollup": "^2.x.x",
|
75
79
|
"rollup-plugin-typescript2": "^0.x.x",
|
76
80
|
"standard-version": "^9.x.x",
|
81
|
+
"supertest": "^6.x.x",
|
77
82
|
"ts-jest": "^27.x.x",
|
78
83
|
"ts-node": "^10.x.x",
|
79
84
|
"typescript": "^4.x.x"
|
@@ -82,15 +87,15 @@
|
|
82
87
|
"koa": "2.13.4",
|
83
88
|
"koatty_config": "1.1.2",
|
84
89
|
"koatty_container": "1.7.7",
|
85
|
-
"koatty_core": "1.6.
|
90
|
+
"koatty_core": "1.6.5",
|
86
91
|
"koatty_exception": "1.2.6",
|
87
92
|
"koatty_lib": "1.2.10",
|
88
93
|
"koatty_loader": "1.0.2",
|
89
94
|
"koatty_logger": "1.3.12",
|
90
|
-
"koatty_payload": "1.3.
|
95
|
+
"koatty_payload": "1.3.16",
|
91
96
|
"koatty_proto": "1.1.6",
|
92
|
-
"koatty_router": "1.7.
|
93
|
-
"koatty_serve": "1.4.
|
97
|
+
"koatty_router": "1.7.5",
|
98
|
+
"koatty_serve": "1.4.9",
|
94
99
|
"koatty_trace": "1.6.6",
|
95
100
|
"reflect-metadata": "0.1.13",
|
96
101
|
"tslib": "2.3.1"
|
package/.vscode/settings.json
DELETED