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/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2021-12-23 15:31:08
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
  /**
@@ -119,9 +119,9 @@ class BaseController {
119
119
  * @param {KoattyContext} ctx
120
120
  * @memberof BaseController
121
121
  */
122
- constructor(ctx) {
122
+ constructor(ctx, ...arg) {
123
123
  this.ctx = ctx;
124
- this.init();
124
+ this.init(arg);
125
125
  }
126
126
  /**
127
127
  * init
@@ -129,10 +129,10 @@ class BaseController {
129
129
  * @protected
130
130
  * @memberof BaseController
131
131
  */
132
- init() {
132
+ init(...arg) {
133
133
  }
134
134
  // /**
135
- // * Class pre-execution method, executed before each class member methods (except constructor, init, __after) are executed.
135
+ // * Class pre-execution method (except constructor, init, __after).
136
136
  // *
137
137
  // * @returns {Promise<any>}
138
138
  // * @memberof BaseController
@@ -141,7 +141,7 @@ class BaseController {
141
141
  // return Promise.resolve();
142
142
  // }
143
143
  // /**
144
- // * Class after-execution method,after each class member methods (except constructor, init, __before) are executed.
144
+ // * Class after-execution method (except constructor, init, __before).
145
145
  // *
146
146
  // * @public
147
147
  // * @returns {*}
@@ -445,34 +445,6 @@ function SetLogger(config) {
445
445
  }
446
446
  }
447
447
 
448
- /**
449
- * Base class
450
- *
451
- * @export
452
- * @class Base
453
- */
454
- class BaseService {
455
- /**
456
- * instance of Base.
457
- * @param {...any[]} arg
458
- * @memberof Base
459
- */
460
- constructor(...arg) {
461
- this.init(arg);
462
- }
463
- /**
464
- * init
465
- *
466
- * @protected
467
- * @param {...any[]} arg
468
- * @memberof Base
469
- */
470
- init(...arg) {
471
- // todo
472
- // Logger.Debug(arg)
473
- }
474
- }
475
-
476
448
  /**
477
449
  * @ author: richen
478
450
  * @ copyright: Copyright (c) - <richenlin(at)gmail.com>
@@ -711,7 +683,7 @@ class Loader {
711
683
  * @memberof Loader
712
684
  */
713
685
  static async LoadMiddlewares(app, loadPath) {
714
- var _a, _b;
686
+ var _a;
715
687
  let middlewareConf = app.config(undefined, "middleware");
716
688
  if (Helper.isEmpty(middlewareConf)) {
717
689
  middlewareConf = { config: {}, list: [] };
@@ -728,7 +700,6 @@ class Loader {
728
700
  item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
729
701
  if (item.id && Helper.isClass(item.target)) {
730
702
  IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
731
- // middleware[item.id] = item.target;
732
703
  }
733
704
  });
734
705
  const middlewareConfList = middlewareConf.list;
@@ -738,9 +709,6 @@ class Loader {
738
709
  defaultList.push(item);
739
710
  }
740
711
  });
741
- // if (defaultList.length > middlewareConfList.length) {
742
- // Logger.Warn("Some middleware is loaded but not allowed to execute.");
743
- // }
744
712
  //de-duplication
745
713
  const appMList = [...new Set(defaultList)];
746
714
  //Automatically call middleware
@@ -755,11 +723,17 @@ class Loader {
755
723
  continue;
756
724
  }
757
725
  if (middlewareConf.config[key] === false) {
758
- Logger.Warn(`Middleware ${key} is loaded but not allowed to execute.`);
759
- 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
+ }
760
734
  }
761
735
  Logger.Debug(`Load middleware: ${key}`);
762
- 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);
763
737
  if (Helper.isFunction(result)) {
764
738
  if (result.length < 3) {
765
739
  app.use(result);
@@ -769,7 +743,6 @@ class Loader {
769
743
  }
770
744
  }
771
745
  }
772
- // app.setMetaData("_middlewares", middleware);
773
746
  }
774
747
  /**
775
748
  * Load controllers
@@ -813,10 +786,6 @@ class Loader {
813
786
  Logger.Debug(`Load service: ${item.id}`);
814
787
  // registering to IOC
815
788
  IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "SERVICE", args: [] });
816
- const ctl = IOCContainer.getInsByClass(item.target);
817
- if (!(ctl instanceof BaseService)) {
818
- throw new Error(`class ${item.id} does not inherit from BaseService`);
819
- }
820
789
  }
821
790
  });
822
791
  }
@@ -834,8 +803,6 @@ class Loader {
834
803
  item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
835
804
  if (item.id && !(item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
836
805
  Logger.Debug(`Load component: ${item.id}`);
837
- // inject schedule
838
- // injectSchedule(item.target, item.target.prototype, IOCContainer);
839
806
  // registering to IOC
840
807
  IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
841
808
  }
@@ -860,7 +827,6 @@ class Loader {
860
827
  var _a;
861
828
  item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("COMPONENT:", "");
862
829
  if (item.id && (item.id).endsWith("Plugin") && Helper.isClass(item.target)) {
863
- // Logger.Debug(`Load plugin: ${item.id}`);
864
830
  // registering to IOC
865
831
  IOCContainer.reg(item.id, item.target, { scope: "Singleton", type: "COMPONENT", args: [] });
866
832
  pluginList.push(item.id);
@@ -879,14 +845,13 @@ class Loader {
879
845
  if (pluginsConf.config[key] === false) {
880
846
  continue;
881
847
  }
882
- // Logger.Debug(`Execute plugin: ${key}`);
883
848
  // sync exec
884
849
  await handle.run((_a = pluginsConf.config[key]) !== null && _a !== void 0 ? _a : {}, app);
885
850
  }
886
851
  }
887
852
  }
888
853
 
889
- var version = "3.5.12";
854
+ var version = "3.6.0-0";
890
855
  var engines = {
891
856
  node: ">12.0.0"
892
857
  };
@@ -1071,7 +1036,6 @@ function Bootstrap(bootFunc) {
1071
1036
  * @returns {ClassDecorator}
1072
1037
  */
1073
1038
  function ComponentScan(scanPath) {
1074
- Logger.Log('think', '', 'ComponentScan');
1075
1039
  return (target) => {
1076
1040
  if (!(target.prototype instanceof Koatty)) {
1077
1041
  throw new Error(`class does not inherit from Koatty`);
@@ -1088,7 +1052,6 @@ function ComponentScan(scanPath) {
1088
1052
  * @returns {ClassDecorator}
1089
1053
  */
1090
1054
  function ConfigurationScan(scanPath) {
1091
- Logger.Log('think', '', 'ConfigurationScan');
1092
1055
  return (target) => {
1093
1056
  if (!(target.prototype instanceof Koatty)) {
1094
1057
  throw new Error(`class does not inherit from Koatty`);
@@ -1154,7 +1117,7 @@ function Controller(path = "") {
1154
1117
  * Indicates that an decorated class is a "middleware".
1155
1118
  *
1156
1119
  * @export
1157
- * @param {string} [identifier] middleware name
1120
+ * @param {string} [identifier] class name
1158
1121
  * @returns {ClassDecorator}
1159
1122
  */
1160
1123
  function Middleware(identifier) {
@@ -1167,7 +1130,7 @@ function Middleware(identifier) {
1167
1130
  * Indicates that an decorated class is a "service".
1168
1131
  *
1169
1132
  * @export
1170
- * @param {string} [identifier] middleware name
1133
+ * @param {string} [identifier] class name
1171
1134
  * @returns {ClassDecorator}
1172
1135
  */
1173
1136
  function Service(identifier) {
@@ -1180,7 +1143,7 @@ function Service(identifier) {
1180
1143
  * Indicates that an decorated class is a "plugin".
1181
1144
  *
1182
1145
  * @export
1183
- * @param {string} [identifier]
1146
+ * @param {string} [identifier] class name
1184
1147
  * @returns {ClassDecorator}
1185
1148
  */
1186
1149
  function Plugin(identifier) {
@@ -1194,4 +1157,30 @@ function Plugin(identifier) {
1194
1157
  };
1195
1158
  }
1196
1159
 
1160
+ /**
1161
+ * Base class
1162
+ *
1163
+ * @export
1164
+ * @class Base
1165
+ */
1166
+ class BaseService {
1167
+ /**
1168
+ * instance of BaseController.
1169
+ * @param {Koatty} app
1170
+ * @param {KoattyContext} ctx
1171
+ * @memberof BaseController
1172
+ */
1173
+ constructor(...arg) {
1174
+ this.init(arg);
1175
+ }
1176
+ /**
1177
+ * init
1178
+ *
1179
+ * @protected
1180
+ * @memberof BaseController
1181
+ */
1182
+ init(...arg) {
1183
+ }
1184
+ }
1185
+
1197
1186
  export { BaseController, BaseService, BindAppReadyHook, Bootstrap, Component, ComponentScan, ConfigurationScan, Controller, HttpController, Logger, Middleware, Plugin, Service };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "3.5.12",
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.4.14",
87
- "koatty_exception": "^1.0.6",
88
- "koatty_lib": "^1.2.8",
89
- "koatty_loader": "^1.0.2",
90
- "koatty_logger": "^1.3.12",
91
- "koatty_payload": "^1.3.10",
92
- "koatty_router": "^1.6.4",
93
- "koatty_serve": "^1.4.4",
94
- "koatty_trace": "^1.5.2",
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
  }