koatty 3.5.12 → 3.6.0-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/CHANGELOG.md +6 -0
- package/README.md +9 -6
- package/dist/README.md +9 -6
- package/dist/index.d.ts +19 -15
- package/dist/index.js +54 -63
- package/dist/index.mjs +47 -58
- package/dist/package.json +19 -18
- package/jest-html-reporters-attach/index.js +58 -0
- package/jest-html-reporters-attach/result.js +1 -0
- package/package.json +19 -18
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.0-0](https://github.com/thinkkoa/koatty/compare/v3.5.16...v3.6.0-0) (2022-02-21)
|
6
|
+
|
7
|
+
### [3.5.16](https://github.com/thinkkoa/koatty/compare/v3.5.14...v3.5.16) (2022-02-14)
|
8
|
+
|
9
|
+
### [3.5.14](https://github.com/thinkkoa/koatty/compare/v3.5.12...v3.5.14) (2022-01-17)
|
10
|
+
|
5
11
|
### [3.5.12](https://github.com/thinkkoa/koatty/compare/v3.5.12-3...v3.5.12) (2021-12-23)
|
6
12
|
|
7
13
|
### [3.5.12-3](https://github.com/thinkkoa/koatty/compare/v3.5.12-2...v3.5.12-3) (2021-12-23)
|
package/README.md
CHANGED
@@ -8,10 +8,9 @@ Use Typescript's decorator implement IOC and AOP.
|
|
8
8
|
|
9
9
|
## New features
|
10
10
|
|
11
|
-
* HTTP、HTTPS、HTTP2 .
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* Support loading environment configuration, support parsing command line parameters (process. argv) and environment variables (process.env)
|
11
|
+
* HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
|
12
|
+
* Support loading environment configuration, parsing command line parameters (process. argv) and environment variables (process.env)
|
13
|
+
* `@ExceptionHandler()` Register global exception handling
|
15
14
|
|
16
15
|
|
17
16
|
## Documentation
|
@@ -96,8 +95,12 @@ export class IndexController extends BaseController {
|
|
96
95
|
|
97
96
|
@RequestMapping("/:name", RequestMethod.ALL)
|
98
97
|
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
99
|
-
|
100
|
-
|
98
|
+
try {
|
99
|
+
const info = await this.testService.sayHello(name);
|
100
|
+
return this.ok("success", info);
|
101
|
+
} catch (err: Error) {
|
102
|
+
return this.fail(err.message));
|
103
|
+
}
|
101
104
|
}
|
102
105
|
|
103
106
|
@PostMapping("/test")
|
package/dist/README.md
CHANGED
@@ -8,10 +8,9 @@ Use Typescript's decorator implement IOC and AOP.
|
|
8
8
|
|
9
9
|
## New features
|
10
10
|
|
11
|
-
* HTTP、HTTPS、HTTP2 .
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* Support loading environment configuration, support parsing command line parameters (process. argv) and environment variables (process.env)
|
11
|
+
* HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
|
12
|
+
* Support loading environment configuration, parsing command line parameters (process. argv) and environment variables (process.env)
|
13
|
+
* `@ExceptionHandler()` Register global exception handling
|
15
14
|
|
16
15
|
|
17
16
|
## Documentation
|
@@ -96,8 +95,12 @@ export class IndexController extends BaseController {
|
|
96
95
|
|
97
96
|
@RequestMapping("/:name", RequestMethod.ALL)
|
98
97
|
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
99
|
-
|
100
|
-
|
98
|
+
try {
|
99
|
+
const info = await this.testService.sayHello(name);
|
100
|
+
return this.ok("success", info);
|
101
|
+
} catch (err: Error) {
|
102
|
+
return this.fail(err.message));
|
103
|
+
}
|
101
104
|
}
|
102
105
|
|
103
106
|
@PostMapping("/test")
|
package/dist/index.d.ts
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date:
|
3
|
+
* @Date: 2022-02-21 18:02:28
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
|
+
import { Config } from 'koatty_config';
|
8
9
|
import { Helper } from 'koatty_lib';
|
9
10
|
import { Koatty } from 'koatty_core';
|
10
11
|
import { KoattyContext } from 'koatty_core';
|
11
12
|
import { KoattyNext } from 'koatty_core';
|
12
13
|
import { Logger as Logger_2 } from 'koatty_logger';
|
13
|
-
import {
|
14
|
+
import { Value } from 'koatty_config';
|
14
15
|
|
15
16
|
/**
|
16
17
|
* Interface for Api input
|
@@ -40,7 +41,7 @@ export declare type AppReadyHookFunc = (app: Koatty) => Promise<any>;
|
|
40
41
|
* @implements {IController}
|
41
42
|
*/
|
42
43
|
export declare class BaseController implements IController {
|
43
|
-
app: Koatty;
|
44
|
+
readonly app: Koatty;
|
44
45
|
readonly ctx: KoattyContext;
|
45
46
|
/**
|
46
47
|
* instance of BaseController.
|
@@ -83,18 +84,18 @@ export declare class BaseController implements IController {
|
|
83
84
|
* @class Base
|
84
85
|
*/
|
85
86
|
export declare class BaseService implements IService {
|
86
|
-
app: Koatty;
|
87
|
+
readonly app: Koatty;
|
87
88
|
/**
|
88
|
-
* instance of
|
89
|
-
* @param {
|
90
|
-
* @
|
89
|
+
* instance of BaseController.
|
90
|
+
* @param {Koatty} app
|
91
|
+
* @param {KoattyContext} ctx
|
92
|
+
* @memberof BaseController
|
91
93
|
*/
|
92
94
|
/**
|
93
95
|
* init
|
94
96
|
*
|
95
97
|
* @protected
|
96
|
-
* @
|
97
|
-
* @memberof Base
|
98
|
+
* @memberof BaseController
|
98
99
|
*/
|
99
100
|
}
|
100
101
|
|
@@ -143,6 +144,8 @@ export declare function Component(identifier?: string): ClassDecorator;
|
|
143
144
|
*/
|
144
145
|
export declare function ComponentScan(scanPath?: string | string[]): ClassDecorator;
|
145
146
|
|
147
|
+
export { Config }
|
148
|
+
|
146
149
|
/**
|
147
150
|
* Define project configuration scan path
|
148
151
|
*
|
@@ -294,7 +297,7 @@ export declare class HttpController extends BaseController {
|
|
294
297
|
* Interface for Controller
|
295
298
|
*/
|
296
299
|
export declare interface IController {
|
297
|
-
app: Koatty;
|
300
|
+
readonly app: Koatty;
|
298
301
|
readonly ctx: KoattyContext;
|
299
302
|
__befor?: () => Promise<any>;
|
300
303
|
__after?: () => Promise<any>;
|
@@ -320,7 +323,7 @@ export declare interface IPlugin {
|
|
320
323
|
* Interface for Service
|
321
324
|
*/
|
322
325
|
export declare interface IService {
|
323
|
-
app: Koatty;
|
326
|
+
readonly app: Koatty;
|
324
327
|
}
|
325
328
|
|
326
329
|
/**
|
@@ -334,7 +337,7 @@ export declare const Logger: Logger_2;
|
|
334
337
|
* Indicates that an decorated class is a "middleware".
|
335
338
|
*
|
336
339
|
* @export
|
337
|
-
* @param {string} [identifier]
|
340
|
+
* @param {string} [identifier] class name
|
338
341
|
* @returns {ClassDecorator}
|
339
342
|
*/
|
340
343
|
export declare function Middleware(identifier?: string): ClassDecorator;
|
@@ -343,7 +346,7 @@ export declare function Middleware(identifier?: string): ClassDecorator;
|
|
343
346
|
* Indicates that an decorated class is a "plugin".
|
344
347
|
*
|
345
348
|
* @export
|
346
|
-
* @param {string} [identifier]
|
349
|
+
* @param {string} [identifier] class name
|
347
350
|
* @returns {ClassDecorator}
|
348
351
|
*/
|
349
352
|
export declare function Plugin(identifier?: string): ClassDecorator;
|
@@ -352,17 +355,18 @@ export declare function Plugin(identifier?: string): ClassDecorator;
|
|
352
355
|
* Indicates that an decorated class is a "service".
|
353
356
|
*
|
354
357
|
* @export
|
355
|
-
* @param {string} [identifier]
|
358
|
+
* @param {string} [identifier] class name
|
356
359
|
* @returns {ClassDecorator}
|
357
360
|
*/
|
358
361
|
export declare function Service(identifier?: string): ClassDecorator;
|
359
362
|
|
363
|
+
export { Value }
|
364
|
+
|
360
365
|
|
361
366
|
export * from "koatty_container";
|
362
367
|
export * from "koatty_core";
|
363
368
|
export * from "koatty_exception";
|
364
369
|
export * from "koatty_router";
|
365
370
|
export * from "koatty_serve";
|
366
|
-
export * from "koatty_trace";
|
367
371
|
|
368
372
|
export { }
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date:
|
3
|
+
* @Date: 2022-02-21 18:02:12
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -136,9 +136,9 @@ class BaseController {
|
|
136
136
|
* @param {KoattyContext} ctx
|
137
137
|
* @memberof BaseController
|
138
138
|
*/
|
139
|
-
constructor(ctx) {
|
139
|
+
constructor(ctx, ...arg) {
|
140
140
|
this.ctx = ctx;
|
141
|
-
this.init();
|
141
|
+
this.init(arg);
|
142
142
|
}
|
143
143
|
/**
|
144
144
|
* init
|
@@ -146,10 +146,10 @@ class BaseController {
|
|
146
146
|
* @protected
|
147
147
|
* @memberof BaseController
|
148
148
|
*/
|
149
|
-
init() {
|
149
|
+
init(...arg) {
|
150
150
|
}
|
151
151
|
// /**
|
152
|
-
// * Class pre-execution method
|
152
|
+
// * Class pre-execution method (except constructor, init, __after).
|
153
153
|
// *
|
154
154
|
// * @returns {Promise<any>}
|
155
155
|
// * @memberof BaseController
|
@@ -158,7 +158,7 @@ class BaseController {
|
|
158
158
|
// return Promise.resolve();
|
159
159
|
// }
|
160
160
|
// /**
|
161
|
-
// * Class after-execution method
|
161
|
+
// * Class after-execution method (except constructor, init, __before).
|
162
162
|
// *
|
163
163
|
// * @public
|
164
164
|
// * @returns {*}
|
@@ -462,34 +462,6 @@ function SetLogger(config) {
|
|
462
462
|
}
|
463
463
|
}
|
464
464
|
|
465
|
-
/**
|
466
|
-
* Base class
|
467
|
-
*
|
468
|
-
* @export
|
469
|
-
* @class Base
|
470
|
-
*/
|
471
|
-
class BaseService {
|
472
|
-
/**
|
473
|
-
* instance of Base.
|
474
|
-
* @param {...any[]} arg
|
475
|
-
* @memberof Base
|
476
|
-
*/
|
477
|
-
constructor(...arg) {
|
478
|
-
this.init(arg);
|
479
|
-
}
|
480
|
-
/**
|
481
|
-
* init
|
482
|
-
*
|
483
|
-
* @protected
|
484
|
-
* @param {...any[]} arg
|
485
|
-
* @memberof Base
|
486
|
-
*/
|
487
|
-
init(...arg) {
|
488
|
-
// todo
|
489
|
-
// Logger.Debug(arg)
|
490
|
-
}
|
491
|
-
}
|
492
|
-
|
493
465
|
/**
|
494
466
|
* @ author: richen
|
495
467
|
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
@@ -728,7 +700,7 @@ class Loader {
|
|
728
700
|
* @memberof Loader
|
729
701
|
*/
|
730
702
|
static async LoadMiddlewares(app, loadPath) {
|
731
|
-
var _a
|
703
|
+
var _a;
|
732
704
|
let middlewareConf = app.config(undefined, "middleware");
|
733
705
|
if (koatty_lib.Helper.isEmpty(middlewareConf)) {
|
734
706
|
middlewareConf = { config: {}, list: [] };
|
@@ -745,7 +717,6 @@ class Loader {
|
|
745
717
|
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
746
718
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
747
719
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
748
|
-
// middleware[item.id] = item.target;
|
749
720
|
}
|
750
721
|
});
|
751
722
|
const middlewareConfList = middlewareConf.list;
|
@@ -755,9 +726,6 @@ class Loader {
|
|
755
726
|
defaultList.push(item);
|
756
727
|
}
|
757
728
|
});
|
758
|
-
// if (defaultList.length > middlewareConfList.length) {
|
759
|
-
// Logger.Warn("Some middleware is loaded but not allowed to execute.");
|
760
|
-
// }
|
761
729
|
//de-duplication
|
762
730
|
const appMList = [...new Set(defaultList)];
|
763
731
|
//Automatically call middleware
|
@@ -772,11 +740,17 @@ class Loader {
|
|
772
740
|
continue;
|
773
741
|
}
|
774
742
|
if (middlewareConf.config[key] === false) {
|
775
|
-
|
776
|
-
|
743
|
+
// Default middleware cannot be disabled
|
744
|
+
if (defaultList.includes(key)) {
|
745
|
+
Logger.Warn(`Middleware ${key} cannot be disabled.`);
|
746
|
+
}
|
747
|
+
else {
|
748
|
+
Logger.Warn(`Middleware ${key} is loaded but not allowed to execute.`);
|
749
|
+
continue;
|
750
|
+
}
|
777
751
|
}
|
778
752
|
Logger.Debug(`Load middleware: ${key}`);
|
779
|
-
const result = await handle.run(
|
753
|
+
const result = await handle.run(middlewareConf.config[key] || {}, app);
|
780
754
|
if (koatty_lib.Helper.isFunction(result)) {
|
781
755
|
if (result.length < 3) {
|
782
756
|
app.use(result);
|
@@ -786,7 +760,6 @@ class Loader {
|
|
786
760
|
}
|
787
761
|
}
|
788
762
|
}
|
789
|
-
// app.setMetaData("_middlewares", middleware);
|
790
763
|
}
|
791
764
|
/**
|
792
765
|
* Load controllers
|
@@ -830,10 +803,6 @@ class Loader {
|
|
830
803
|
Logger.Debug(`Load service: ${item.id}`);
|
831
804
|
// registering to IOC
|
832
805
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "SERVICE", args: [] });
|
833
|
-
const ctl = koatty_container.IOCContainer.getInsByClass(item.target);
|
834
|
-
if (!(ctl instanceof BaseService)) {
|
835
|
-
throw new Error(`class ${item.id} does not inherit from BaseService`);
|
836
|
-
}
|
837
806
|
}
|
838
807
|
});
|
839
808
|
}
|
@@ -851,8 +820,6 @@ class Loader {
|
|
851
820
|
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
852
821
|
if (item.id && !(item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
853
822
|
Logger.Debug(`Load component: ${item.id}`);
|
854
|
-
// inject schedule
|
855
|
-
// injectSchedule(item.target, item.target.prototype, IOCContainer);
|
856
823
|
// registering to IOC
|
857
824
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
858
825
|
}
|
@@ -877,7 +844,6 @@ class Loader {
|
|
877
844
|
var _a;
|
878
845
|
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
|
879
846
|
if (item.id && (item.id).endsWith("Plugin") && koatty_lib.Helper.isClass(item.target)) {
|
880
|
-
// Logger.Debug(`Load plugin: ${item.id}`);
|
881
847
|
// registering to IOC
|
882
848
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
|
883
849
|
pluginList.push(item.id);
|
@@ -896,14 +862,13 @@ class Loader {
|
|
896
862
|
if (pluginsConf.config[key] === false) {
|
897
863
|
continue;
|
898
864
|
}
|
899
|
-
// Logger.Debug(`Execute plugin: ${key}`);
|
900
865
|
// sync exec
|
901
866
|
await handle.run((_a = pluginsConf.config[key]) !== null && _a !== void 0 ? _a : {}, app);
|
902
867
|
}
|
903
868
|
}
|
904
869
|
}
|
905
870
|
|
906
|
-
var version = "3.
|
871
|
+
var version = "3.6.0-0";
|
907
872
|
var engines = {
|
908
873
|
node: ">12.0.0"
|
909
874
|
};
|
@@ -1088,7 +1053,6 @@ function Bootstrap(bootFunc) {
|
|
1088
1053
|
* @returns {ClassDecorator}
|
1089
1054
|
*/
|
1090
1055
|
function ComponentScan(scanPath) {
|
1091
|
-
Logger.Log('think', '', 'ComponentScan');
|
1092
1056
|
return (target) => {
|
1093
1057
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1094
1058
|
throw new Error(`class does not inherit from Koatty`);
|
@@ -1105,7 +1069,6 @@ function ComponentScan(scanPath) {
|
|
1105
1069
|
* @returns {ClassDecorator}
|
1106
1070
|
*/
|
1107
1071
|
function ConfigurationScan(scanPath) {
|
1108
|
-
Logger.Log('think', '', 'ConfigurationScan');
|
1109
1072
|
return (target) => {
|
1110
1073
|
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
1111
1074
|
throw new Error(`class does not inherit from Koatty`);
|
@@ -1171,7 +1134,7 @@ function Controller(path = "") {
|
|
1171
1134
|
* Indicates that an decorated class is a "middleware".
|
1172
1135
|
*
|
1173
1136
|
* @export
|
1174
|
-
* @param {string} [identifier]
|
1137
|
+
* @param {string} [identifier] class name
|
1175
1138
|
* @returns {ClassDecorator}
|
1176
1139
|
*/
|
1177
1140
|
function Middleware(identifier) {
|
@@ -1184,7 +1147,7 @@ function Middleware(identifier) {
|
|
1184
1147
|
* Indicates that an decorated class is a "service".
|
1185
1148
|
*
|
1186
1149
|
* @export
|
1187
|
-
* @param {string} [identifier]
|
1150
|
+
* @param {string} [identifier] class name
|
1188
1151
|
* @returns {ClassDecorator}
|
1189
1152
|
*/
|
1190
1153
|
function Service(identifier) {
|
@@ -1197,7 +1160,7 @@ function Service(identifier) {
|
|
1197
1160
|
* Indicates that an decorated class is a "plugin".
|
1198
1161
|
*
|
1199
1162
|
* @export
|
1200
|
-
* @param {string} [identifier]
|
1163
|
+
* @param {string} [identifier] class name
|
1201
1164
|
* @returns {ClassDecorator}
|
1202
1165
|
*/
|
1203
1166
|
function Plugin(identifier) {
|
@@ -1211,10 +1174,44 @@ function Plugin(identifier) {
|
|
1211
1174
|
};
|
1212
1175
|
}
|
1213
1176
|
|
1177
|
+
/**
|
1178
|
+
* Base class
|
1179
|
+
*
|
1180
|
+
* @export
|
1181
|
+
* @class Base
|
1182
|
+
*/
|
1183
|
+
class BaseService {
|
1184
|
+
/**
|
1185
|
+
* instance of BaseController.
|
1186
|
+
* @param {Koatty} app
|
1187
|
+
* @param {KoattyContext} ctx
|
1188
|
+
* @memberof BaseController
|
1189
|
+
*/
|
1190
|
+
constructor(...arg) {
|
1191
|
+
this.init(arg);
|
1192
|
+
}
|
1193
|
+
/**
|
1194
|
+
* init
|
1195
|
+
*
|
1196
|
+
* @protected
|
1197
|
+
* @memberof BaseController
|
1198
|
+
*/
|
1199
|
+
init(...arg) {
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
|
1214
1203
|
Object.defineProperty(exports, 'Helper', {
|
1215
1204
|
enumerable: true,
|
1216
1205
|
get: function () { return koatty_lib.Helper; }
|
1217
1206
|
});
|
1207
|
+
Object.defineProperty(exports, 'Config', {
|
1208
|
+
enumerable: true,
|
1209
|
+
get: function () { return koatty_config.Config; }
|
1210
|
+
});
|
1211
|
+
Object.defineProperty(exports, 'Value', {
|
1212
|
+
enumerable: true,
|
1213
|
+
get: function () { return koatty_config.Value; }
|
1214
|
+
});
|
1218
1215
|
exports.BaseController = BaseController;
|
1219
1216
|
exports.BaseService = BaseService;
|
1220
1217
|
exports.BindAppReadyHook = BindAppReadyHook;
|
@@ -1258,9 +1255,3 @@ Object.keys(koatty_exception).forEach(function (k) {
|
|
1258
1255
|
get: function () { return koatty_exception[k]; }
|
1259
1256
|
});
|
1260
1257
|
});
|
1261
|
-
Object.keys(koatty_trace).forEach(function (k) {
|
1262
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
1263
|
-
enumerable: true,
|
1264
|
-
get: function () { return koatty_trace[k]; }
|
1265
|
-
});
|
1266
|
-
});
|