koatty 3.6.4 → 3.6.7
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 +6 -0
- package/dist/index.d.ts +6 -26
- package/dist/index.js +21 -57
- package/dist/index.mjs +21 -57
- package/dist/package.json +7 -7
- package/jest-html-reporters-attach/result.js +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
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.7](https://github.com/thinkkoa/koatty/compare/v3.6.6...v3.6.7) (2022-03-09)
|
6
|
+
|
7
|
+
### [3.6.6](https://github.com/thinkkoa/koatty/compare/v3.6.5...v3.6.6) (2022-03-02)
|
8
|
+
|
9
|
+
### [3.6.5](https://github.com/thinkkoa/koatty/compare/v3.6.4...v3.6.5) (2022-03-02)
|
10
|
+
|
5
11
|
### [3.6.4](https://github.com/thinkkoa/koatty/compare/v3.6.3...v3.6.4) (2022-02-25)
|
6
12
|
|
7
13
|
### [3.6.3](https://github.com/thinkkoa/koatty/compare/v3.6.2...v3.6.3) (2022-02-25)
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-
|
3
|
+
* @Date: 2022-03-09 18:51:23
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -74,7 +74,7 @@ export declare class BaseController implements IController {
|
|
74
74
|
* @returns {*}
|
75
75
|
* @memberof BaseController
|
76
76
|
*/
|
77
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number):
|
77
|
+
fail(msg: Error | string | ApiInput, data?: any, code?: number): void;
|
78
78
|
}
|
79
79
|
|
80
80
|
/**
|
@@ -268,10 +268,10 @@ export declare class HttpController extends BaseController {
|
|
268
268
|
* @param {*} data
|
269
269
|
* @param {string} [contentType]
|
270
270
|
* @param {string} [encoding]
|
271
|
-
* @returns
|
271
|
+
* @returns void
|
272
272
|
* @memberof HttpController
|
273
273
|
*/
|
274
|
-
body(data: any, contentType?: string, encoding?: string):
|
274
|
+
body(data: any, contentType?: string, encoding?: string): void;
|
275
275
|
/**
|
276
276
|
* Respond to json formatted content
|
277
277
|
*
|
@@ -279,27 +279,7 @@ export declare class HttpController extends BaseController {
|
|
279
279
|
* @returns {Promise<any>}
|
280
280
|
* @memberof HttpController
|
281
281
|
*/
|
282
|
-
json(data: any):
|
283
|
-
/**
|
284
|
-
* Response to normalize json format content for success
|
285
|
-
*
|
286
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
287
|
-
* @param {*} [data] 待处理的数据
|
288
|
-
* @param {number} [code=200] 错误码,默认0
|
289
|
-
* @returns {*}
|
290
|
-
* @memberof HttpController
|
291
|
-
*/
|
292
|
-
ok(msg: string | ApiInput, data?: any, code?: number): Promise<any>;
|
293
|
-
/**
|
294
|
-
* Response to normalize json format content for fail
|
295
|
-
*
|
296
|
-
* @param {(string | ApiInput)} msg
|
297
|
-
* @param {*} [data]
|
298
|
-
* @param {number} [code=1]
|
299
|
-
* @returns {*}
|
300
|
-
* @memberof HttpController
|
301
|
-
*/
|
302
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number): Promise<any>;
|
282
|
+
json(data: any): void;
|
303
283
|
}
|
304
284
|
|
305
285
|
/**
|
@@ -310,8 +290,8 @@ export declare interface IController {
|
|
310
290
|
readonly ctx: KoattyContext;
|
311
291
|
__befor?: () => Promise<any>;
|
312
292
|
__after?: () => Promise<any>;
|
313
|
-
readonly fail: (msg?: Error | string | ApiInput, data?: any, ret?: number) => Promise<any>;
|
314
293
|
readonly ok: (msg?: string | ApiInput, data?: any, ret?: number) => Promise<any>;
|
294
|
+
readonly fail: (msg?: Error | string | ApiInput, data?: any, ret?: number) => void;
|
315
295
|
}
|
316
296
|
|
317
297
|
/**
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-
|
3
|
+
* @Date: 2022-03-09 18:51:08
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -195,7 +195,8 @@ class BaseController {
|
|
195
195
|
*/
|
196
196
|
fail(msg, data, code = 1) {
|
197
197
|
const obj = formatApiData(msg, data, code);
|
198
|
-
|
198
|
+
this.ctx.body = obj.data;
|
199
|
+
this.ctx.throw(obj.message, obj.code, 200);
|
199
200
|
}
|
200
201
|
}
|
201
202
|
// const properties = ["constructor", "init"];
|
@@ -359,7 +360,7 @@ class HttpController extends BaseController {
|
|
359
360
|
* @param {*} data
|
360
361
|
* @param {string} [contentType]
|
361
362
|
* @param {string} [encoding]
|
362
|
-
* @returns
|
363
|
+
* @returns void
|
363
364
|
* @memberof HttpController
|
364
365
|
*/
|
365
366
|
body(data, contentType, encoding) {
|
@@ -379,32 +380,6 @@ class HttpController extends BaseController {
|
|
379
380
|
json(data) {
|
380
381
|
return this.body(data, "application/json");
|
381
382
|
}
|
382
|
-
/**
|
383
|
-
* Response to normalize json format content for success
|
384
|
-
*
|
385
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
386
|
-
* @param {*} [data] 待处理的数据
|
387
|
-
* @param {number} [code=200] 错误码,默认0
|
388
|
-
* @returns {*}
|
389
|
-
* @memberof HttpController
|
390
|
-
*/
|
391
|
-
ok(msg, data, code = 0) {
|
392
|
-
const obj = formatApiData(msg, data, code);
|
393
|
-
return this.json(obj);
|
394
|
-
}
|
395
|
-
/**
|
396
|
-
* Response to normalize json format content for fail
|
397
|
-
*
|
398
|
-
* @param {(string | ApiInput)} msg
|
399
|
-
* @param {*} [data]
|
400
|
-
* @param {number} [code=1]
|
401
|
-
* @returns {*}
|
402
|
-
* @memberof HttpController
|
403
|
-
*/
|
404
|
-
fail(msg, data, code = 1) {
|
405
|
-
const obj = formatApiData(msg, data, code);
|
406
|
-
return this.json(obj);
|
407
|
-
}
|
408
383
|
}
|
409
384
|
// const properties = ["constructor", "init"];
|
410
385
|
// export const HttpController = new Proxy(Base, {
|
@@ -516,14 +491,13 @@ class Loader {
|
|
516
491
|
* @memberof Loader
|
517
492
|
*/
|
518
493
|
static initialize(app) {
|
519
|
-
|
520
|
-
const env = ((_a = process.execArgv) !== null && _a !== void 0 ? _a : []).join(",");
|
494
|
+
const env = (process.execArgv ?? []).join(",");
|
521
495
|
if (env.indexOf('ts-node') > -1 || env.indexOf('--debug') > -1) {
|
522
496
|
app.appDebug = true;
|
523
497
|
}
|
524
498
|
// app.env
|
525
499
|
app.env = process.env.KOATTY_ENV || process.env.NODE_ENV;
|
526
|
-
if ((env.indexOf('--production') > -1) || ((
|
500
|
+
if ((env.indexOf('--production') > -1) || ((app.env ?? '').indexOf('pro') > -1)) {
|
527
501
|
app.appDebug = false;
|
528
502
|
}
|
529
503
|
if (app.appDebug) {
|
@@ -627,8 +601,7 @@ class Loader {
|
|
627
601
|
* @memberof Loader
|
628
602
|
*/
|
629
603
|
static SetLogger(app) {
|
630
|
-
|
631
|
-
const configs = (_a = app.getMetaData("_configs")) !== null && _a !== void 0 ? _a : {};
|
604
|
+
const configs = app.getMetaData("_configs") ?? {};
|
632
605
|
//Logger
|
633
606
|
if (configs.config) {
|
634
607
|
const opt = configs.config;
|
@@ -704,7 +677,6 @@ class Loader {
|
|
704
677
|
* @memberof Loader
|
705
678
|
*/
|
706
679
|
static async LoadMiddlewares(app, loadPath) {
|
707
|
-
var _a;
|
708
680
|
let middlewareConf = app.config(undefined, "middleware");
|
709
681
|
if (koatty_lib.Helper.isEmpty(middlewareConf)) {
|
710
682
|
middlewareConf = { config: {}, list: [] };
|
@@ -713,12 +685,11 @@ class Loader {
|
|
713
685
|
koatty_loader.Load(loadPath || ["./middleware"], app.thinkPath);
|
714
686
|
//Mount application middleware
|
715
687
|
// const middleware: any = {};
|
716
|
-
const appMiddleware =
|
688
|
+
const appMiddleware = koatty_container.IOCContainer.listClass("MIDDLEWARE") ?? [];
|
717
689
|
appMiddleware.push({ id: "TraceMiddleware", target: TraceMiddleware });
|
718
690
|
appMiddleware.push({ id: "PayloadMiddleware", target: PayloadMiddleware });
|
719
691
|
appMiddleware.forEach((item) => {
|
720
|
-
|
721
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
692
|
+
item.id = (item.id ?? "").replace("MIDDLEWARE:", "");
|
722
693
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
723
694
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
724
695
|
}
|
@@ -776,8 +747,7 @@ class Loader {
|
|
776
747
|
const controllerList = koatty_container.IOCContainer.listClass("CONTROLLER");
|
777
748
|
const controllers = {};
|
778
749
|
controllerList.forEach((item) => {
|
779
|
-
|
780
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("CONTROLLER:", "");
|
750
|
+
item.id = (item.id ?? "").replace("CONTROLLER:", "");
|
781
751
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
782
752
|
Logger.Debug(`Load controller: ${item.id}`);
|
783
753
|
// registering to IOC
|
@@ -801,8 +771,7 @@ class Loader {
|
|
801
771
|
static LoadServices(app) {
|
802
772
|
const serviceList = koatty_container.IOCContainer.listClass("SERVICE");
|
803
773
|
serviceList.forEach((item) => {
|
804
|
-
|
805
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("SERVICE:", "");
|
774
|
+
item.id = (item.id ?? "").replace("SERVICE:", "");
|
806
775
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
807
776
|
Logger.Debug(`Load service: ${item.id}`);
|
808
777
|
// registering to IOC
|
@@ -820,8 +789,7 @@ class Loader {
|
|
820
789
|
static LoadComponents(app) {
|
821
790
|
const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
|
822
791
|
componentList.forEach((item) => {
|
823
|
-
|
824
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
792
|
+
item.id = (item.id ?? "").replace("COMPONENT:", "");
|
825
793
|
if (item.id && !(item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
826
794
|
Logger.Debug(`Load component: ${item.id}`);
|
827
795
|
// registering to IOC
|
@@ -837,7 +805,6 @@ class Loader {
|
|
837
805
|
* @memberof Loader
|
838
806
|
*/
|
839
807
|
static async LoadPlugins(app) {
|
840
|
-
var _a;
|
841
808
|
const componentList = koatty_container.IOCContainer.listClass("COMPONENT");
|
842
809
|
let pluginsConf = app.config(undefined, "plugin");
|
843
810
|
if (koatty_lib.Helper.isEmpty(pluginsConf)) {
|
@@ -845,8 +812,7 @@ class Loader {
|
|
845
812
|
}
|
846
813
|
const pluginList = [];
|
847
814
|
componentList.forEach(async (item) => {
|
848
|
-
|
849
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
815
|
+
item.id = (item.id ?? "").replace("COMPONENT:", "");
|
850
816
|
if (item.id && (item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
851
817
|
// registering to IOC
|
852
818
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
@@ -867,12 +833,12 @@ class Loader {
|
|
867
833
|
continue;
|
868
834
|
}
|
869
835
|
// sync exec
|
870
|
-
await handle.run(
|
836
|
+
await handle.run(pluginsConf.config[key] ?? {}, app);
|
871
837
|
}
|
872
838
|
}
|
873
839
|
}
|
874
840
|
|
875
|
-
var version = "3.6.
|
841
|
+
var version = "3.6.7";
|
876
842
|
var engines = {
|
877
843
|
node: ">12.0.0"
|
878
844
|
};
|
@@ -1026,9 +992,8 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
1026
992
|
* @returns {*}
|
1027
993
|
*/
|
1028
994
|
const newRouter = function (app) {
|
1029
|
-
var _a;
|
1030
995
|
const protocol = app.config("protocol") || "http";
|
1031
|
-
const options =
|
996
|
+
const options = app.config(undefined, 'router') ?? {};
|
1032
997
|
const router = koatty_router.NewRouter(app, options, protocol);
|
1033
998
|
koatty_lib.Helper.define(app, "router", router);
|
1034
999
|
return router;
|
@@ -1058,12 +1023,11 @@ const listenCallback = (app, options) => {
|
|
1058
1023
|
* @returns {*}
|
1059
1024
|
*/
|
1060
1025
|
const newServe = function (app) {
|
1061
|
-
var _a, _b, _c;
|
1062
1026
|
const protocol = app.config("protocol") || "http";
|
1063
1027
|
const port = process.env.PORT || process.env.APP_PORT ||
|
1064
1028
|
app.config('app_port') || 3000;
|
1065
1029
|
const hostname = process.env.IP ||
|
1066
|
-
|
1030
|
+
process.env.HOSTNAME?.replace(/-/g, '.') || app.config('app_host') || '127.0.0.1';
|
1067
1031
|
const options = {
|
1068
1032
|
hostname,
|
1069
1033
|
port,
|
@@ -1076,8 +1040,8 @@ const newServe = function (app) {
|
|
1076
1040
|
};
|
1077
1041
|
const pm = new Set(["https", "http2", "wss"]);
|
1078
1042
|
if (pm.has(options.protocol)) {
|
1079
|
-
const keyFile =
|
1080
|
-
const crtFile =
|
1043
|
+
const keyFile = app.config("key_file") ?? "";
|
1044
|
+
const crtFile = app.config("crt_file") ?? "";
|
1081
1045
|
options.ext.key = fs__default["default"].readFileSync(keyFile).toString();
|
1082
1046
|
options.ext.cert = fs__default["default"].readFileSync(crtFile).toString();
|
1083
1047
|
}
|
@@ -1150,7 +1114,7 @@ function ComponentScan(scanPath) {
|
|
1150
1114
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1151
1115
|
throw new Error(`class does not inherit from Koatty`);
|
1152
1116
|
}
|
1153
|
-
scanPath = scanPath
|
1117
|
+
scanPath = scanPath ?? '';
|
1154
1118
|
koatty_container.IOCContainer.saveClassMetadata(koatty_container.TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
|
1155
1119
|
};
|
1156
1120
|
}
|
@@ -1166,7 +1130,7 @@ function ConfigurationScan(scanPath) {
|
|
1166
1130
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1167
1131
|
throw new Error(`class does not inherit from Koatty`);
|
1168
1132
|
}
|
1169
|
-
scanPath = scanPath
|
1133
|
+
scanPath = scanPath ?? '';
|
1170
1134
|
koatty_container.IOCContainer.saveClassMetadata(koatty_container.TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
|
1171
1135
|
};
|
1172
1136
|
}
|
package/dist/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2022-
|
3
|
+
* @Date: 2022-03-09 18:51:08
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -175,7 +175,8 @@ class BaseController {
|
|
175
175
|
*/
|
176
176
|
fail(msg, data, code = 1) {
|
177
177
|
const obj = formatApiData(msg, data, code);
|
178
|
-
|
178
|
+
this.ctx.body = obj.data;
|
179
|
+
this.ctx.throw(obj.message, obj.code, 200);
|
179
180
|
}
|
180
181
|
}
|
181
182
|
// const properties = ["constructor", "init"];
|
@@ -339,7 +340,7 @@ class HttpController extends BaseController {
|
|
339
340
|
* @param {*} data
|
340
341
|
* @param {string} [contentType]
|
341
342
|
* @param {string} [encoding]
|
342
|
-
* @returns
|
343
|
+
* @returns void
|
343
344
|
* @memberof HttpController
|
344
345
|
*/
|
345
346
|
body(data, contentType, encoding) {
|
@@ -359,32 +360,6 @@ class HttpController extends BaseController {
|
|
359
360
|
json(data) {
|
360
361
|
return this.body(data, "application/json");
|
361
362
|
}
|
362
|
-
/**
|
363
|
-
* Response to normalize json format content for success
|
364
|
-
*
|
365
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
366
|
-
* @param {*} [data] 待处理的数据
|
367
|
-
* @param {number} [code=200] 错误码,默认0
|
368
|
-
* @returns {*}
|
369
|
-
* @memberof HttpController
|
370
|
-
*/
|
371
|
-
ok(msg, data, code = 0) {
|
372
|
-
const obj = formatApiData(msg, data, code);
|
373
|
-
return this.json(obj);
|
374
|
-
}
|
375
|
-
/**
|
376
|
-
* Response to normalize json format content for fail
|
377
|
-
*
|
378
|
-
* @param {(string | ApiInput)} msg
|
379
|
-
* @param {*} [data]
|
380
|
-
* @param {number} [code=1]
|
381
|
-
* @returns {*}
|
382
|
-
* @memberof HttpController
|
383
|
-
*/
|
384
|
-
fail(msg, data, code = 1) {
|
385
|
-
const obj = formatApiData(msg, data, code);
|
386
|
-
return this.json(obj);
|
387
|
-
}
|
388
363
|
}
|
389
364
|
// const properties = ["constructor", "init"];
|
390
365
|
// export const HttpController = new Proxy(Base, {
|
@@ -496,14 +471,13 @@ class Loader {
|
|
496
471
|
* @memberof Loader
|
497
472
|
*/
|
498
473
|
static initialize(app) {
|
499
|
-
|
500
|
-
const env = ((_a = process.execArgv) !== null && _a !== void 0 ? _a : []).join(",");
|
474
|
+
const env = (process.execArgv ?? []).join(",");
|
501
475
|
if (env.indexOf('ts-node') > -1 || env.indexOf('--debug') > -1) {
|
502
476
|
app.appDebug = true;
|
503
477
|
}
|
504
478
|
// app.env
|
505
479
|
app.env = process.env.KOATTY_ENV || process.env.NODE_ENV;
|
506
|
-
if ((env.indexOf('--production') > -1) || ((
|
480
|
+
if ((env.indexOf('--production') > -1) || ((app.env ?? '').indexOf('pro') > -1)) {
|
507
481
|
app.appDebug = false;
|
508
482
|
}
|
509
483
|
if (app.appDebug) {
|
@@ -607,8 +581,7 @@ class Loader {
|
|
607
581
|
* @memberof Loader
|
608
582
|
*/
|
609
583
|
static SetLogger(app) {
|
610
|
-
|
611
|
-
const configs = (_a = app.getMetaData("_configs")) !== null && _a !== void 0 ? _a : {};
|
584
|
+
const configs = app.getMetaData("_configs") ?? {};
|
612
585
|
//Logger
|
613
586
|
if (configs.config) {
|
614
587
|
const opt = configs.config;
|
@@ -684,7 +657,6 @@ class Loader {
|
|
684
657
|
* @memberof Loader
|
685
658
|
*/
|
686
659
|
static async LoadMiddlewares(app, loadPath) {
|
687
|
-
var _a;
|
688
660
|
let middlewareConf = app.config(undefined, "middleware");
|
689
661
|
if (Helper.isEmpty(middlewareConf)) {
|
690
662
|
middlewareConf = { config: {}, list: [] };
|
@@ -693,12 +665,11 @@ class Loader {
|
|
693
665
|
Load(loadPath || ["./middleware"], app.thinkPath);
|
694
666
|
//Mount application middleware
|
695
667
|
// const middleware: any = {};
|
696
|
-
const appMiddleware =
|
668
|
+
const appMiddleware = IOCContainer.listClass("MIDDLEWARE") ?? [];
|
697
669
|
appMiddleware.push({ id: "TraceMiddleware", target: TraceMiddleware });
|
698
670
|
appMiddleware.push({ id: "PayloadMiddleware", target: PayloadMiddleware });
|
699
671
|
appMiddleware.forEach((item) => {
|
700
|
-
|
701
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
672
|
+
item.id = (item.id ?? "").replace("MIDDLEWARE:", "");
|
702
673
|
if (item.id && Helper.isClass(item.target)) {
|
703
674
|
IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
704
675
|
}
|
@@ -756,8 +727,7 @@ class Loader {
|
|
756
727
|
const controllerList = IOCContainer.listClass("CONTROLLER");
|
757
728
|
const controllers = {};
|
758
729
|
controllerList.forEach((item) => {
|
759
|
-
|
760
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("CONTROLLER:", "");
|
730
|
+
item.id = (item.id ?? "").replace("CONTROLLER:", "");
|
761
731
|
if (item.id && Helper.isClass(item.target)) {
|
762
732
|
Logger.Debug(`Load controller: ${item.id}`);
|
763
733
|
// registering to IOC
|
@@ -781,8 +751,7 @@ class Loader {
|
|
781
751
|
static LoadServices(app) {
|
782
752
|
const serviceList = IOCContainer.listClass("SERVICE");
|
783
753
|
serviceList.forEach((item) => {
|
784
|
-
|
785
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("SERVICE:", "");
|
754
|
+
item.id = (item.id ?? "").replace("SERVICE:", "");
|
786
755
|
if (item.id && Helper.isClass(item.target)) {
|
787
756
|
Logger.Debug(`Load service: ${item.id}`);
|
788
757
|
// registering to IOC
|
@@ -800,8 +769,7 @@ class Loader {
|
|
800
769
|
static LoadComponents(app) {
|
801
770
|
const componentList = IOCContainer.listClass("COMPONENT");
|
802
771
|
componentList.forEach((item) => {
|
803
|
-
|
804
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
772
|
+
item.id = (item.id ?? "").replace("COMPONENT:", "");
|
805
773
|
if (item.id && !(item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
|
806
774
|
Logger.Debug(`Load component: ${item.id}`);
|
807
775
|
// registering to IOC
|
@@ -817,7 +785,6 @@ class Loader {
|
|
817
785
|
* @memberof Loader
|
818
786
|
*/
|
819
787
|
static async LoadPlugins(app) {
|
820
|
-
var _a;
|
821
788
|
const componentList = IOCContainer.listClass("COMPONENT");
|
822
789
|
let pluginsConf = app.config(undefined, "plugin");
|
823
790
|
if (Helper.isEmpty(pluginsConf)) {
|
@@ -825,8 +792,7 @@ class Loader {
|
|
825
792
|
}
|
826
793
|
const pluginList = [];
|
827
794
|
componentList.forEach(async (item) => {
|
828
|
-
|
829
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
795
|
+
item.id = (item.id ?? "").replace("COMPONENT:", "");
|
830
796
|
if (item.id && (item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
|
831
797
|
// registering to IOC
|
832
798
|
IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
@@ -847,12 +813,12 @@ class Loader {
|
|
847
813
|
continue;
|
848
814
|
}
|
849
815
|
// sync exec
|
850
|
-
await handle.run(
|
816
|
+
await handle.run(pluginsConf.config[key] ?? {}, app);
|
851
817
|
}
|
852
818
|
}
|
853
819
|
}
|
854
820
|
|
855
|
-
var version = "3.6.
|
821
|
+
var version = "3.6.7";
|
856
822
|
var engines = {
|
857
823
|
node: ">12.0.0"
|
858
824
|
};
|
@@ -1006,9 +972,8 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
1006
972
|
* @returns {*}
|
1007
973
|
*/
|
1008
974
|
const newRouter = function (app) {
|
1009
|
-
var _a;
|
1010
975
|
const protocol = app.config("protocol") || "http";
|
1011
|
-
const options =
|
976
|
+
const options = app.config(undefined, 'router') ?? {};
|
1012
977
|
const router = NewRouter(app, options, protocol);
|
1013
978
|
Helper.define(app, "router", router);
|
1014
979
|
return router;
|
@@ -1038,12 +1003,11 @@ const listenCallback = (app, options) => {
|
|
1038
1003
|
* @returns {*}
|
1039
1004
|
*/
|
1040
1005
|
const newServe = function (app) {
|
1041
|
-
var _a, _b, _c;
|
1042
1006
|
const protocol = app.config("protocol") || "http";
|
1043
1007
|
const port = process.env.PORT || process.env.APP_PORT ||
|
1044
1008
|
app.config('app_port') || 3000;
|
1045
1009
|
const hostname = process.env.IP ||
|
1046
|
-
|
1010
|
+
process.env.HOSTNAME?.replace(/-/g, '.') || app.config('app_host') || '127.0.0.1';
|
1047
1011
|
const options = {
|
1048
1012
|
hostname,
|
1049
1013
|
port,
|
@@ -1056,8 +1020,8 @@ const newServe = function (app) {
|
|
1056
1020
|
};
|
1057
1021
|
const pm = new Set(["https", "http2", "wss"]);
|
1058
1022
|
if (pm.has(options.protocol)) {
|
1059
|
-
const keyFile =
|
1060
|
-
const crtFile =
|
1023
|
+
const keyFile = app.config("key_file") ?? "";
|
1024
|
+
const crtFile = app.config("crt_file") ?? "";
|
1061
1025
|
options.ext.key = fs.readFileSync(keyFile).toString();
|
1062
1026
|
options.ext.cert = fs.readFileSync(crtFile).toString();
|
1063
1027
|
}
|
@@ -1130,7 +1094,7 @@ function ComponentScan(scanPath) {
|
|
1130
1094
|
if (!(target.prototype instanceof Koatty)) {
|
1131
1095
|
throw new Error(`class does not inherit from Koatty`);
|
1132
1096
|
}
|
1133
|
-
scanPath = scanPath
|
1097
|
+
scanPath = scanPath ?? '';
|
1134
1098
|
IOCContainer.saveClassMetadata(TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
|
1135
1099
|
};
|
1136
1100
|
}
|
@@ -1146,7 +1110,7 @@ function ConfigurationScan(scanPath) {
|
|
1146
1110
|
if (!(target.prototype instanceof Koatty)) {
|
1147
1111
|
throw new Error(`class does not inherit from Koatty`);
|
1148
1112
|
}
|
1149
|
-
scanPath = scanPath
|
1113
|
+
scanPath = scanPath ?? '';
|
1150
1114
|
IOCContainer.saveClassMetadata(TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
|
1151
1115
|
};
|
1152
1116
|
}
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.6.
|
3
|
+
"version": "3.6.7",
|
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",
|
@@ -70,6 +70,7 @@
|
|
70
70
|
"husky": "^4.x.x",
|
71
71
|
"jest": "^27.x.x",
|
72
72
|
"jest-html-reporters": "^2.x.x",
|
73
|
+
"koatty_validation": "^1.x.x",
|
73
74
|
"rollup": "^2.x.x",
|
74
75
|
"rollup-plugin-typescript2": "^0.x.x",
|
75
76
|
"standard-version": "^9.x.x",
|
@@ -80,18 +81,17 @@
|
|
80
81
|
"dependencies": {
|
81
82
|
"koa": "2.13.4",
|
82
83
|
"koatty_config": "1.1.2",
|
83
|
-
"koatty_container": "1.7.
|
84
|
+
"koatty_container": "1.7.7",
|
84
85
|
"koatty_core": "1.6.1",
|
85
|
-
"koatty_exception": "1.2.
|
86
|
+
"koatty_exception": "1.2.6",
|
86
87
|
"koatty_lib": "1.2.10",
|
87
88
|
"koatty_loader": "1.0.2",
|
88
89
|
"koatty_logger": "1.3.12",
|
89
|
-
"koatty_payload": "1.3.
|
90
|
+
"koatty_payload": "1.3.15",
|
90
91
|
"koatty_proto": "1.1.6",
|
91
|
-
"koatty_router": "1.7.
|
92
|
+
"koatty_router": "1.7.3",
|
92
93
|
"koatty_serve": "1.4.8",
|
93
|
-
"koatty_trace": "1.6.
|
94
|
-
"koatty_validation": "1.2.2",
|
94
|
+
"koatty_trace": "1.6.6",
|
95
95
|
"reflect-metadata": "0.1.13",
|
96
96
|
"tslib": "2.3.1"
|
97
97
|
}
|
@@ -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":1646823066488,"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":1646823066530,"_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.7",
|
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",
|
@@ -70,6 +70,7 @@
|
|
70
70
|
"husky": "^4.x.x",
|
71
71
|
"jest": "^27.x.x",
|
72
72
|
"jest-html-reporters": "^2.x.x",
|
73
|
+
"koatty_validation": "^1.x.x",
|
73
74
|
"rollup": "^2.x.x",
|
74
75
|
"rollup-plugin-typescript2": "^0.x.x",
|
75
76
|
"standard-version": "^9.x.x",
|
@@ -80,18 +81,17 @@
|
|
80
81
|
"dependencies": {
|
81
82
|
"koa": "2.13.4",
|
82
83
|
"koatty_config": "1.1.2",
|
83
|
-
"koatty_container": "1.7.
|
84
|
+
"koatty_container": "1.7.7",
|
84
85
|
"koatty_core": "1.6.1",
|
85
|
-
"koatty_exception": "1.2.
|
86
|
+
"koatty_exception": "1.2.6",
|
86
87
|
"koatty_lib": "1.2.10",
|
87
88
|
"koatty_loader": "1.0.2",
|
88
89
|
"koatty_logger": "1.3.12",
|
89
|
-
"koatty_payload": "1.3.
|
90
|
+
"koatty_payload": "1.3.15",
|
90
91
|
"koatty_proto": "1.1.6",
|
91
|
-
"koatty_router": "1.7.
|
92
|
+
"koatty_router": "1.7.3",
|
92
93
|
"koatty_serve": "1.4.8",
|
93
|
-
"koatty_trace": "1.6.
|
94
|
-
"koatty_validation": "1.2.2",
|
94
|
+
"koatty_trace": "1.6.6",
|
95
95
|
"reflect-metadata": "0.1.13",
|
96
96
|
"tslib": "2.3.1"
|
97
97
|
}
|