koatty 3.5.16 → 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 CHANGED
@@ -2,6 +2,8 @@
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
+
5
7
  ### [3.5.16](https://github.com/thinkkoa/koatty/compare/v3.5.14...v3.5.16) (2022-02-14)
6
8
 
7
9
  ### [3.5.14](https://github.com/thinkkoa/koatty/compare/v3.5.12...v3.5.14) (2022-01-17)
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
- * gRPC server.
13
- * WebSocket server. (unstable)
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
- const info = await this.testService.sayHello(name).catch((err: any) => this.fail(err.message));
100
- return info;
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
- * gRPC server.
13
- * WebSocket server. (unstable)
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
- const info = await this.testService.sayHello(name).catch((err: any) => this.fail(err.message));
100
- return info;
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,15 +1,17 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-14 14:58:36
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';
14
+ import { Value } from 'koatty_config';
13
15
 
14
16
  /**
15
17
  * Interface for Api input
@@ -142,6 +144,8 @@ export declare function Component(identifier?: string): ClassDecorator;
142
144
  */
143
145
  export declare function ComponentScan(scanPath?: string | string[]): ClassDecorator;
144
146
 
147
+ export { Config }
148
+
145
149
  /**
146
150
  * Define project configuration scan path
147
151
  *
@@ -356,12 +360,13 @@ export declare function Plugin(identifier?: string): ClassDecorator;
356
360
  */
357
361
  export declare function Service(identifier?: string): ClassDecorator;
358
362
 
363
+ export { Value }
364
+
359
365
 
360
366
  export * from "koatty_container";
361
367
  export * from "koatty_core";
362
368
  export * from "koatty_exception";
363
369
  export * from "koatty_router";
364
370
  export * from "koatty_serve";
365
- export * from "koatty_trace";
366
371
 
367
372
  export { }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-14 14:58:23
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/
@@ -700,7 +700,7 @@ class Loader {
700
700
  * @memberof Loader
701
701
  */
702
702
  static async LoadMiddlewares(app, loadPath) {
703
- var _a, _b;
703
+ var _a;
704
704
  let middlewareConf = app.config(undefined, "middleware");
705
705
  if (koatty_lib.Helper.isEmpty(middlewareConf)) {
706
706
  middlewareConf = { config: {}, list: [] };
@@ -717,7 +717,6 @@ class Loader {
717
717
  item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
718
718
  if (item.id && koatty_lib.Helper.isClass(item.target)) {
719
719
  koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
720
- // middleware[item.id] = item.target;
721
720
  }
722
721
  });
723
722
  const middlewareConfList = middlewareConf.list;
@@ -727,9 +726,6 @@ class Loader {
727
726
  defaultList.push(item);
728
727
  }
729
728
  });
730
- // if (defaultList.length > middlewareConfList.length) {
731
- // Logger.Warn("Some middleware is loaded but not allowed to execute.");
732
- // }
733
729
  //de-duplication
734
730
  const appMList = [...new Set(defaultList)];
735
731
  //Automatically call middleware
@@ -744,11 +740,17 @@ class Loader {
744
740
  continue;
745
741
  }
746
742
  if (middlewareConf.config[key] === false) {
747
- Logger.Warn(`Middleware ${key} is loaded but not allowed to execute.`);
748
- continue;
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
+ }
749
751
  }
750
752
  Logger.Debug(`Load middleware: ${key}`);
751
- const result = await handle.run((_b = middlewareConf.config[key]) !== null && _b !== void 0 ? _b : {}, app);
753
+ const result = await handle.run(middlewareConf.config[key] || {}, app);
752
754
  if (koatty_lib.Helper.isFunction(result)) {
753
755
  if (result.length < 3) {
754
756
  app.use(result);
@@ -758,7 +760,6 @@ class Loader {
758
760
  }
759
761
  }
760
762
  }
761
- // app.setMetaData("_middlewares", middleware);
762
763
  }
763
764
  /**
764
765
  * Load controllers
@@ -867,7 +868,7 @@ class Loader {
867
868
  }
868
869
  }
869
870
 
870
- var version = "3.5.16";
871
+ var version = "3.6.0-0";
871
872
  var engines = {
872
873
  node: ">12.0.0"
873
874
  };
@@ -1052,7 +1053,6 @@ function Bootstrap(bootFunc) {
1052
1053
  * @returns {ClassDecorator}
1053
1054
  */
1054
1055
  function ComponentScan(scanPath) {
1055
- Logger.Log('think', '', 'ComponentScan');
1056
1056
  return (target) => {
1057
1057
  if (!(target.prototype instanceof koatty_core.Koatty)) {
1058
1058
  throw new Error(`class does not inherit from Koatty`);
@@ -1069,7 +1069,6 @@ function ComponentScan(scanPath) {
1069
1069
  * @returns {ClassDecorator}
1070
1070
  */
1071
1071
  function ConfigurationScan(scanPath) {
1072
- Logger.Log('think', '', 'ConfigurationScan');
1073
1072
  return (target) => {
1074
1073
  if (!(target.prototype instanceof koatty_core.Koatty)) {
1075
1074
  throw new Error(`class does not inherit from Koatty`);
@@ -1205,6 +1204,14 @@ Object.defineProperty(exports, 'Helper', {
1205
1204
  enumerable: true,
1206
1205
  get: function () { return koatty_lib.Helper; }
1207
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
+ });
1208
1215
  exports.BaseController = BaseController;
1209
1216
  exports.BaseService = BaseService;
1210
1217
  exports.BindAppReadyHook = BindAppReadyHook;
@@ -1248,9 +1255,3 @@ Object.keys(koatty_exception).forEach(function (k) {
1248
1255
  get: function () { return koatty_exception[k]; }
1249
1256
  });
1250
1257
  });
1251
- Object.keys(koatty_trace).forEach(function (k) {
1252
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
1253
- enumerable: true,
1254
- get: function () { return koatty_trace[k]; }
1255
- });
1256
- });
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-14 14:58:23
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/
@@ -19,11 +19,11 @@ export * from 'koatty_container';
19
19
  import * as path from 'path';
20
20
  import { Load } from 'koatty_loader';
21
21
  import { LoadConfigs } from 'koatty_config';
22
+ export { Config, Value } from 'koatty_config';
22
23
  import { DefaultLogger } from 'koatty_logger';
23
24
  import { prevent } from 'koatty_exception';
24
25
  export * from 'koatty_exception';
25
26
  import { Trace } from 'koatty_trace';
26
- export * from 'koatty_trace';
27
27
  import { Payload } from 'koatty_payload';
28
28
 
29
29
  /**
@@ -683,7 +683,7 @@ class Loader {
683
683
  * @memberof Loader
684
684
  */
685
685
  static async LoadMiddlewares(app, loadPath) {
686
- var _a, _b;
686
+ var _a;
687
687
  let middlewareConf = app.config(undefined, "middleware");
688
688
  if (Helper.isEmpty(middlewareConf)) {
689
689
  middlewareConf = { config: {}, list: [] };
@@ -700,7 +700,6 @@ class Loader {
700
700
  item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
701
701
  if (item.id && Helper.isClass(item.target)) {
702
702
  IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
703
- // middleware[item.id] = item.target;
704
703
  }
705
704
  });
706
705
  const middlewareConfList = middlewareConf.list;
@@ -710,9 +709,6 @@ class Loader {
710
709
  defaultList.push(item);
711
710
  }
712
711
  });
713
- // if (defaultList.length > middlewareConfList.length) {
714
- // Logger.Warn("Some middleware is loaded but not allowed to execute.");
715
- // }
716
712
  //de-duplication
717
713
  const appMList = [...new Set(defaultList)];
718
714
  //Automatically call middleware
@@ -727,11 +723,17 @@ class Loader {
727
723
  continue;
728
724
  }
729
725
  if (middlewareConf.config[key] === false) {
730
- Logger.Warn(`Middleware ${key} is loaded but not allowed to execute.`);
731
- continue;
726
+ // Default middleware cannot be disabled
727
+ if (defaultList.includes(key)) {
728
+ Logger.Warn(`Middleware ${key} cannot be disabled.`);
729
+ }
730
+ else {
731
+ Logger.Warn(`Middleware ${key} is loaded but not allowed to execute.`);
732
+ continue;
733
+ }
732
734
  }
733
735
  Logger.Debug(`Load middleware: ${key}`);
734
- const result = await handle.run((_b = middlewareConf.config[key]) !== null && _b !== void 0 ? _b : {}, app);
736
+ const result = await handle.run(middlewareConf.config[key] || {}, app);
735
737
  if (Helper.isFunction(result)) {
736
738
  if (result.length < 3) {
737
739
  app.use(result);
@@ -741,7 +743,6 @@ class Loader {
741
743
  }
742
744
  }
743
745
  }
744
- // app.setMetaData("_middlewares", middleware);
745
746
  }
746
747
  /**
747
748
  * Load controllers
@@ -850,7 +851,7 @@ class Loader {
850
851
  }
851
852
  }
852
853
 
853
- var version = "3.5.16";
854
+ var version = "3.6.0-0";
854
855
  var engines = {
855
856
  node: ">12.0.0"
856
857
  };
@@ -1035,7 +1036,6 @@ function Bootstrap(bootFunc) {
1035
1036
  * @returns {ClassDecorator}
1036
1037
  */
1037
1038
  function ComponentScan(scanPath) {
1038
- Logger.Log('think', '', 'ComponentScan');
1039
1039
  return (target) => {
1040
1040
  if (!(target.prototype instanceof Koatty)) {
1041
1041
  throw new Error(`class does not inherit from Koatty`);
@@ -1052,7 +1052,6 @@ function ComponentScan(scanPath) {
1052
1052
  * @returns {ClassDecorator}
1053
1053
  */
1054
1054
  function ConfigurationScan(scanPath) {
1055
- Logger.Log('think', '', 'ConfigurationScan');
1056
1055
  return (target) => {
1057
1056
  if (!(target.prototype instanceof Koatty)) {
1058
1057
  throw new Error(`class does not inherit from Koatty`);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "3.5.16",
3
+ "version": "3.6.0-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",
@@ -58,18 +58,17 @@
58
58
  "@types/koa": "^2.x.x",
59
59
  "@types/koa__router": "^8.x.x",
60
60
  "@types/node": "^16.x.x",
61
- "@types/uuid": "^8.x.x",
62
61
  "@types/ws": "^8.x.x",
63
62
  "@typescript-eslint/eslint-plugin": "^5.x.x",
64
63
  "@typescript-eslint/parser": "^5.x.x",
65
- "commitlint": "^15.x.x",
64
+ "commitlint": "^11.x.x",
66
65
  "commitlint-config-gitmoji": "^2.x.x",
67
66
  "conventional-changelog-cli": "^2.x.x",
68
67
  "copyfiles": "^2.x.x",
69
68
  "del-cli": "^4.x.x",
70
69
  "eslint": "^8.x.x",
71
70
  "eslint-plugin-jest": "^25.x.x",
72
- "husky": "^7.x.x",
71
+ "husky": "^4.x.x",
73
72
  "jest": "^27.x.x",
74
73
  "jest-html-reporters": "^2.x.x",
75
74
  "rollup": "^2.x.x",
@@ -80,19 +79,21 @@
80
79
  "typescript": "^4.x.x"
81
80
  },
82
81
  "dependencies": {
83
- "koa": "^2.13.4",
84
- "koatty_config": "^1.0.6",
85
- "koatty_container": "^1.6.16",
86
- "koatty_core": "^1.5.2",
87
- "koatty_exception": "^1.1.2",
88
- "koatty_lib": "^1.2.8",
89
- "koatty_loader": "^1.0.2",
90
- "koatty_logger": "^1.3.12",
91
- "koatty_payload": "^1.3.11",
92
- "koatty_router": "^1.6.4",
93
- "koatty_serve": "^1.4.4",
94
- "koatty_trace": "^1.5.4",
95
- "reflect-metadata": "^0.1.13",
96
- "tslib": "^2.3.1"
82
+ "koa": "2.13.4",
83
+ "koatty_config": "1.1.2",
84
+ "koatty_container": "1.7.4",
85
+ "koatty_core": "1.6.0",
86
+ "koatty_exception": "1.2.2",
87
+ "koatty_lib": "1.2.10",
88
+ "koatty_loader": "1.0.2",
89
+ "koatty_logger": "1.3.12",
90
+ "koatty_payload": "1.3.14",
91
+ "koatty_proto": "1.1.6",
92
+ "koatty_router": "1.7.0",
93
+ "koatty_serve": "1.4.6",
94
+ "koatty_trace": "1.6.0",
95
+ "koatty_validation": "1.1.0",
96
+ "reflect-metadata": "0.1.13",
97
+ "tslib": "2.3.1"
97
98
  }
98
99
  }