koatty 4.1.0 → 4.1.2

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.
@@ -1,17 +1,17 @@
1
1
 
2
2
  
3
- > koatty@4.1.0 build /Users/richen/Workspace/nodejs/koatty-monorepo/packages/koatty
3
+ > koatty@4.1.2 build /Users/richen/Workspace/nodejs/koatty-monorepo/packages/koatty
4
4
  > npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp
5
5
 
6
6
 
7
- > koatty@4.1.0 build:js
7
+ > koatty@4.1.2 build:js
8
8
  > npx rollup --bundleConfigAsCjs -c .rollup.config.js
9
9
 
10
10
  
11
11
  ./src/index.ts → ./dist/index.js, ./dist/index.mjs...
12
- created ./dist/index.js, ./dist/index.mjs in 993ms
12
+ created ./dist/index.js, ./dist/index.mjs in 1s
13
13
  ⠙⠙
14
- > koatty@4.1.0 build:dts
14
+ > koatty@4.1.2 build:dts
15
15
  > bash scripts/build-dts.sh
16
16
 
17
17
  🔨 Building type declarations for koatty...
@@ -33,7 +33,7 @@
33
33
  ✅ All dependencies ready (waited 2ms)
34
34
  📝 Running TypeScript compiler...
35
35
  ⠙📦 Running API Extractor...
36
- 
36
+ ⠙
37
37
  api-extractor 7.55.2  - https://api-extractor.com/
38
38
  
39
39
  Using configuration from ./api-extractor.json
@@ -64,7 +64,7 @@ Analysis will use the bundled TypeScript version 5.8.2
64
64
  API Extractor completed successfully
65
65
  ⠙✅ Type declarations built successfully
66
66
  ⠙
67
- > koatty@4.1.0 build:doc
67
+ > koatty@4.1.2 build:doc
68
68
  > npx api-documenter markdown --input temp --output docs/api
69
69
 
70
70
  
@@ -75,7 +75,7 @@ Reading koatty.api.json
75
75
  Deleting old output from docs/api
76
76
  Writing koatty package
77
77
  ⠙⠙
78
- > koatty@4.1.0 build:cp
78
+ > koatty@4.1.2 build:cp
79
79
  > node scripts/copyFiles && node scripts/postBuild
80
80
 
81
81
  Copied package.json to dist/
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - build
8
+ - Updated dependencies
9
+ - koatty_serve@3.1.1
10
+ - koatty_trace@2.1.1
11
+
12
+ ## 4.1.1
13
+
14
+ ### Patch Changes
15
+
16
+ - build
17
+
3
18
  ## 4.1.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -23,7 +23,7 @@ Koa + TypeScript + IOC = Koatty. **Koatty** is a progressive Node.js framework f
23
23
  - ✅ **Protocol-Specific Middleware** - Bind middleware to specific protocols with `@Middleware({ protocol: [...] })`
24
24
  - ✅ **Graceful Shutdown** - Enhanced connection pool management and cleanup handlers
25
25
  - ✅ **Enhanced gRPC Support** - Timeout detection, duplicate call protection, streaming improvements
26
- - ✅ **Application Lifecycle Hooks** - Custom decorators with `BindEventHook` API for boot/ready/stop events
26
+ - ✅ **Application Lifecycle Hooks** - Custom decorators with `@OnEvent` decorator API for framework lifecycle events
27
27
  - ✅ **Version Conflict Detection** - Automatic detection and resolution of dependency conflicts
28
28
  - ✅ **GraphQL over HTTP/2** - Automatic HTTP/2 upgrade with SSL for multiplexing and compression
29
29
  - ✅ **Global Exception Handling** - `@ExceptionHandler()` decorator for centralized error management
@@ -274,24 +274,34 @@ export class LoggerPlugin implements IPlugin {
274
274
 
275
275
  **Application Lifecycle Events:**
276
276
  ```typescript
277
- // Use BindEventHook to customize application behavior
278
- export function CustomDecorator(): ClassDecorator {
279
- return (target: Function) => {
280
- BindEventHook(AppEvent.appBoot, async (app: KoattyApplication) => {
281
- // Executed during application boot
282
- console.log('App is booting...');
283
- }, target);
284
-
285
- BindEventHook(AppEvent.appReady, async (app: KoattyApplication) => {
286
- // Executed when app is ready
287
- console.log('App is ready!');
288
- }, target);
289
-
290
- BindEventHook(AppEvent.appStop, async (app: KoattyApplication) => {
291
- // Executed during graceful shutdown
292
- console.log('App is stopping...');
293
- }, target);
294
- };
277
+ // Use @OnEvent to hook into application lifecycle events
278
+ @Component("MyComponent", {
279
+ scope: 'user',
280
+ priority: 50,
281
+ description: 'Custom component example'
282
+ })
283
+ export class MyComponent {
284
+
285
+ // Execute when router loads
286
+ @OnEvent(AppEvent.loadRouter)
287
+ async initRouter(app: KoattyApplication) {
288
+ console.log('Initializing router...');
289
+ // Custom router initialization logic
290
+ }
291
+
292
+ // Execute when application is ready
293
+ @OnEvent(AppEvent.appReady)
294
+ async onReady(app: KoattyApplication) {
295
+ console.log('Application ready');
296
+ // Service registration, connection pool initialization, etc.
297
+ }
298
+
299
+ // Execute when application stops
300
+ @OnEvent(AppEvent.appStop)
301
+ async cleanup(app: KoattyApplication) {
302
+ console.log('Cleaning up resources...');
303
+ // Close connections, release resources
304
+ }
295
305
  }
296
306
  ```
297
307
 
package/dist/README.md CHANGED
@@ -23,7 +23,7 @@ Koa + TypeScript + IOC = Koatty. **Koatty** is a progressive Node.js framework f
23
23
  - ✅ **Protocol-Specific Middleware** - Bind middleware to specific protocols with `@Middleware({ protocol: [...] })`
24
24
  - ✅ **Graceful Shutdown** - Enhanced connection pool management and cleanup handlers
25
25
  - ✅ **Enhanced gRPC Support** - Timeout detection, duplicate call protection, streaming improvements
26
- - ✅ **Application Lifecycle Hooks** - Custom decorators with `BindEventHook` API for boot/ready/stop events
26
+ - ✅ **Application Lifecycle Hooks** - Custom decorators with `@OnEvent` decorator API for framework lifecycle events
27
27
  - ✅ **Version Conflict Detection** - Automatic detection and resolution of dependency conflicts
28
28
  - ✅ **GraphQL over HTTP/2** - Automatic HTTP/2 upgrade with SSL for multiplexing and compression
29
29
  - ✅ **Global Exception Handling** - `@ExceptionHandler()` decorator for centralized error management
@@ -274,24 +274,34 @@ export class LoggerPlugin implements IPlugin {
274
274
 
275
275
  **Application Lifecycle Events:**
276
276
  ```typescript
277
- // Use BindEventHook to customize application behavior
278
- export function CustomDecorator(): ClassDecorator {
279
- return (target: Function) => {
280
- BindEventHook(AppEvent.appBoot, async (app: KoattyApplication) => {
281
- // Executed during application boot
282
- console.log('App is booting...');
283
- }, target);
284
-
285
- BindEventHook(AppEvent.appReady, async (app: KoattyApplication) => {
286
- // Executed when app is ready
287
- console.log('App is ready!');
288
- }, target);
289
-
290
- BindEventHook(AppEvent.appStop, async (app: KoattyApplication) => {
291
- // Executed during graceful shutdown
292
- console.log('App is stopping...');
293
- }, target);
294
- };
277
+ // Use @OnEvent to hook into application lifecycle events
278
+ @Component("MyComponent", {
279
+ scope: 'user',
280
+ priority: 50,
281
+ description: 'Custom component example'
282
+ })
283
+ export class MyComponent {
284
+
285
+ // Execute when router loads
286
+ @OnEvent(AppEvent.loadRouter)
287
+ async initRouter(app: KoattyApplication) {
288
+ console.log('Initializing router...');
289
+ // Custom router initialization logic
290
+ }
291
+
292
+ // Execute when application is ready
293
+ @OnEvent(AppEvent.appReady)
294
+ async onReady(app: KoattyApplication) {
295
+ console.log('Application ready');
296
+ // Service registration, connection pool initialization, etc.
297
+ }
298
+
299
+ // Execute when application stops
300
+ @OnEvent(AppEvent.appStop)
301
+ async cleanup(app: KoattyApplication) {
302
+ console.log('Cleaning up resources...');
303
+ // Close connections, release resources
304
+ }
295
305
  }
296
306
  ```
297
307
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2026-01-31 09:50:38
3
+ * @Date: 2026-02-03 10:52:27
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2026-01-31 09:50:32
3
+ * @Date: 2026-02-03 10:52:21
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -165,7 +165,6 @@ class Loader {
165
165
  e.version = e.version || t.version;
166
166
  }
167
167
  }
168
- u.Warn("Using process.env for paths is deprecated. Use app.rootPath, app.appPath, app.koattyPath instead.");
169
168
  process.env.ROOT_PATH = t;
170
169
  process.env.APP_PATH = o;
171
170
  process.env.KOATTY_PATH = a;
@@ -458,7 +457,7 @@ class Loader {
458
457
  return function(a) {
459
458
  if (!(a.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
460
459
  t.IOC.saveClass("COMPONENT", a, "KOATTY_APP");
461
- k(a, e);
460
+ H(a, e);
462
461
  return a;
463
462
  };
464
463
  }
@@ -466,7 +465,7 @@ class Loader {
466
465
  function A(e) {
467
466
  return async t => {
468
467
  if (!(t.prototype instanceof o.Koatty)) throw new Error(`class ${t.name} does not inherit from Koatty`);
469
- return await k(t, e, !0);
468
+ return await H(t, e, !0);
470
469
  };
471
470
  }
472
471
 
@@ -486,7 +485,7 @@ function M(e) {
486
485
  };
487
486
  }
488
487
 
489
- const k = async function(e, a, n = !1) {
488
+ const H = async function(e, a, n = !1) {
490
489
  if (process.env.NODE_DEBUG) {
491
490
  const e = process.env.NODE_DEBUG.split(",").filter(e => !e.includes("winston")).join(",");
492
491
  process.env.NODE_DEBUG = e;
@@ -511,14 +510,14 @@ const k = async function(e, a, n = !1) {
511
510
  u.Log("Koatty", "", "ComponentScan ...");
512
511
  Loader.CheckAllComponents(i, e);
513
512
  await Loader.LoadAllComponents(i, e);
514
- if (!s) i.listen(H);
513
+ if (!s) i.listen(T);
515
514
  return i;
516
515
  } catch (e) {
517
516
  u.Fatal(e);
518
517
  }
519
518
  };
520
519
 
521
- const H = e => {
520
+ const T = e => {
522
521
  u.Log("Koatty", "", "====================================");
523
522
  u.Log("Koatty", "", `Nodejs Version: ${process.version}`);
524
523
  u.Log("Koatty", "", `Koatty Version: v${m}`);
package/dist/index.mjs CHANGED
@@ -1,19 +1,19 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2026-01-31 09:50:32
3
+ * @Date: 2026-02-03 10:52:21
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
7
7
  */
8
- import { LoadConfigs as t } from "koatty_config";
8
+ import { LoadConfigs as e } from "koatty_config";
9
9
 
10
10
  export { Config } from "koatty_config";
11
11
 
12
- import { IOC as e, TAGGED_CLS as o } from "koatty_container";
12
+ import { IOC as t, TAGGED_CLS as o } from "koatty_container";
13
13
 
14
14
  export * from "koatty_container";
15
15
 
16
- import { AppEvent as a, AppEventArr as s, asyncEvent as n, ComponentManager as i, implementsMiddlewareInterface as r, MIDDLEWARE_OPTIONS as l, protocolMiddleware as c, implementsControllerInterface as d, implementsServiceInterface as p, implementsAspectInterface as f, Koatty as g } from "koatty_core";
16
+ import { AppEvent as a, AppEventArr as s, asyncEvent as n, ComponentManager as i, implementsMiddlewareInterface as r, MIDDLEWARE_OPTIONS as l, protocolMiddleware as c, implementsControllerInterface as d, implementsServiceInterface as f, implementsAspectInterface as p, Koatty as g } from "koatty_core";
17
17
 
18
18
  export * from "koatty_core";
19
19
 
@@ -46,22 +46,22 @@ import * as v from "path";
46
46
  */
47
47
  const L = u;
48
48
 
49
- function w(t, e) {
50
- if (!t.appDebug) {
49
+ function w(e, t) {
50
+ if (!e.appDebug) {
51
51
  u.enableBatch(!0);
52
52
  u.setBatchConfig({
53
53
  maxSize: 200,
54
54
  flushInterval: 500
55
55
  });
56
56
  }
57
- if (e.logLevel) u.setLevel(e.logLevel);
58
- if (e.logFilePath && !t.silent) {
59
- m.define(t, "logsPath", e.logFilePath);
60
- process.env.LOGS_PATH = e.logFilePath;
61
- u.setLogFilePath(e.logFilePath);
57
+ if (t.logLevel) u.setLevel(t.logLevel);
58
+ if (t.logFilePath && !e.silent) {
59
+ m.define(e, "logsPath", t.logFilePath);
60
+ process.env.LOGS_PATH = t.logFilePath;
61
+ u.setLogFilePath(t.logFilePath);
62
62
  }
63
- if (e.sensFields) u.setSensFields(e.sensFields);
64
- t.once(a.appStop, async () => {
63
+ if (t.sensFields) u.setSensFields(t.sensFields);
64
+ e.once(a.appStop, async () => {
65
65
  await u.flushBatch();
66
66
  await u.destroy();
67
67
  });
@@ -81,34 +81,34 @@ const {engines: E, version: P} = C;
81
81
 
82
82
  const b = P;
83
83
 
84
- const k = E.node.slice(1) || "12.0.0";
84
+ const M = E.node.slice(1) || "12.0.0";
85
85
 
86
- function M(t, e, o, a) {
87
- if (m.isClass(o) && o.name != t) throw Error(`The file(${e}) name should be always the same as class name.`);
86
+ function k(e, t, o, a) {
87
+ if (m.isClass(o) && o.name != e) throw Error(`The file(${t}) name should be always the same as class name.`);
88
88
  if (o["__esModule"]) if (o.name === void 0) {
89
89
  const a = Object.keys(o);
90
- if (a[0] != t && m.isClass(o[a[0]])) throw Error(`The file(${e}) name should be always the same as class name.`);
91
- } else if (o.name != t) throw Error(`The file(${e}) name should be always the same as class name.`);
90
+ if (a[0] != e && m.isClass(o[a[0]])) throw Error(`The file(${t}) name should be always the same as class name.`);
91
+ } else if (o.name != e) throw Error(`The file(${t}) name should be always the same as class name.`);
92
92
  if (!a) return;
93
- if (a.has(t)) throw new Error(`A same class already exists. at \`${e}\`.`);
94
- a.add(t);
93
+ if (a.has(e)) throw new Error(`A same class already exists. at \`${t}\`.`);
94
+ a.add(e);
95
95
  return;
96
96
  }
97
97
 
98
98
  function O() {
99
- let t = k;
100
- t = t.slice(0, t.lastIndexOf("."));
101
- let e = process.version;
102
- if (e[0] === "v") e = e.slice(1);
99
+ let e = M;
103
100
  e = e.slice(0, e.lastIndexOf("."));
104
- if (m.toNumber(t) > m.toNumber(e)) L.Fatal(`Koatty need node version > ${t}, current version is ${e}, please upgrade it.`);
101
+ let t = process.version;
102
+ if (t[0] === "v") t = t.slice(1);
103
+ t = t.slice(0, t.lastIndexOf("."));
104
+ if (m.toNumber(e) > m.toNumber(t)) L.Fatal(`Koatty need node version > ${e}, current version is ${t}, please upgrade it.`);
105
105
  }
106
106
 
107
107
  const T = () => {
108
- let t = !1;
109
- const e = JSON.stringify(process.argv[1]);
110
- if (e.indexOf("jest") > -1) t = !0;
111
- return t;
108
+ let e = !1;
109
+ const t = JSON.stringify(process.argv[1]);
110
+ if (t.indexOf("jest") > -1) e = !0;
111
+ return e;
112
112
  };
113
113
 
114
114
  /*
@@ -135,95 +135,94 @@ const $ = `\n\n┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬\n├┴┐
135
135
  */;
136
136
 
137
137
  class Loader {
138
- constructor(t) {
139
- this.app = t;
138
+ constructor(e) {
139
+ this.app = e;
140
140
  }
141
- static initialize(t) {
142
- if (t.env == "development") L.setLevel("debug"); else L.setLevel("info");
143
- const e = t.rootPath || process.cwd();
144
- const o = t.appPath || v.resolve(e, t.appDebug ? "src" : "dist");
141
+ static initialize(e) {
142
+ if (e.env == "development") L.setLevel("debug"); else L.setLevel("info");
143
+ const t = e.rootPath || process.cwd();
144
+ const o = e.appPath || v.resolve(t, e.appDebug ? "src" : "dist");
145
145
  const a = v.resolve(__dirname, "..");
146
- m.define(t, "rootPath", e);
147
- m.define(t, "appPath", o);
148
- m.define(t, "koattyPath", a);
149
- if (m.isEmpty(t.name)) {
150
- const e = m.safeRequire(`${v.dirname(o)}/package.json`);
151
- if (e.name) {
152
- t.name = e.name;
153
- t.version = t.version || e.version;
146
+ m.define(e, "rootPath", t);
147
+ m.define(e, "appPath", o);
148
+ m.define(e, "koattyPath", a);
149
+ if (m.isEmpty(e.name)) {
150
+ const t = m.safeRequire(`${v.dirname(o)}/package.json`);
151
+ if (t.name) {
152
+ e.name = t.name;
153
+ e.version = e.version || t.version;
154
154
  }
155
155
  }
156
- L.Warn("Using process.env for paths is deprecated. Use app.rootPath, app.appPath, app.koattyPath instead.");
157
- process.env.ROOT_PATH = e;
156
+ process.env.ROOT_PATH = t;
158
157
  process.env.APP_PATH = o;
159
158
  process.env.KOATTY_PATH = a;
160
- m.define(t, "thinkPath", a);
159
+ m.define(e, "thinkPath", a);
161
160
  process.env.THINK_PATH = a;
162
161
  }
163
- static GetComponentMeta(t, a) {
162
+ static GetComponentMeta(e, a) {
164
163
  let s = [];
165
- const n = e.getClassMetadata(o, _, a);
164
+ const n = t.getClassMetadata(o, _, a);
166
165
  if (n) if (m.isArray(n)) s = n; else s.push(n);
167
- if (s.length < 1) s = [ t.appPath ];
166
+ if (s.length < 1) s = [ e.appPath ];
168
167
  return s;
169
168
  }
170
- static GetConfigurationMeta(t, a) {
171
- const s = e.getClassMetadata(o, A, a);
169
+ static GetConfigurationMeta(e, a) {
170
+ const s = t.getClassMetadata(o, A, a);
172
171
  let n = [];
173
172
  if (s) if (m.isArray(s)) n = s; else n.push(s);
174
173
  return n;
175
174
  }
176
- static CheckAllComponents(t, e) {
177
- const o = Loader.GetComponentMeta(t, e);
178
- const a = Loader.GetConfigurationMeta(t, e);
175
+ static CheckAllComponents(e, t) {
176
+ const o = Loader.GetComponentMeta(e, t);
177
+ const a = Loader.GetConfigurationMeta(e, t);
179
178
  const s = new Set;
180
- h(o, "", (t, e, o) => {
181
- M(t, e, o, s);
182
- }, [ "**/**.js", "**/**.ts", "!**/**.d.ts" ], [ ...a, `${e.name || ".no"}.ts` ]);
179
+ h(o, "", (e, t, o) => {
180
+ k(e, t, o, s);
181
+ }, [ "**/**.js", "**/**.ts", "!**/**.d.ts" ], [ ...a, `${t.name || ".no"}.ts` ]);
183
182
  s.clear();
184
183
  }
185
- static SetLogger(t) {
186
- const e = t.getMetaData("_configs") || [];
187
- const o = e[0] || {};
184
+ static SetLogger(e) {
185
+ const t = e.getMetaData("_configs") || [];
186
+ const o = t[0] || {};
188
187
  if (o.config) {
189
- const e = o.config;
188
+ const t = o.config;
190
189
  let a = "debug", s = "", n = [];
191
- if (t.env === "production") a = "info";
192
- if (e.logsLevel) a = e.logsLevel.toLowerCase();
193
- if (e.logsPath) s = e.logsPath;
194
- if (e.sensFields) n = e.sensFields;
195
- w(t, {
190
+ if (e.env === "production") a = "info";
191
+ if (t.logsLevel) a = t.logsLevel.toLowerCase();
192
+ if (t.logsPath) s = t.logsPath;
193
+ if (t.sensFields) n = t.sensFields;
194
+ w(e, {
196
195
  logLevel: a,
197
196
  logFilePath: s,
198
197
  sensFields: n
199
198
  });
200
199
  }
201
200
  }
202
- static async LoadAllComponents(t, o) {
201
+ static async LoadAllComponents(e, o) {
203
202
  try {
204
- if (m.isFunction(e.preloadMetadata)) e.preloadMetadata();
203
+ if (m.isFunction(t.preloadMetadata)) t.preloadMetadata();
205
204
  } catch {
206
205
  L.Warn("[Loader] preloadMetadata is optional, ignore if not available");
207
206
  }
208
- const r = Loader.GetConfigurationMeta(t, o);
209
- const l = new Loader(t);
210
- for (const e of s) switch (e) {
207
+ const r = Loader.GetConfigurationMeta(e, o);
208
+ const l = new Loader(e);
209
+ for (const t of s) switch (t) {
211
210
  case a.appBoot:
212
211
  L.Log("Koatty", "", "Load Configurations ...");
213
212
  l.LoadConfigs(r);
214
- Loader.SetLogger(t);
215
- await n(t, e);
213
+ Loader.SetLogger(e);
214
+ await n(e, t);
216
215
  break;
217
216
 
218
217
  case a.loadConfigure:
219
218
  L.Log("Koatty", "", "Emit loadConfigure ...");
220
- await n(t, e);
219
+ await n(e, t);
221
220
  break;
222
221
 
223
222
  case a.loadComponent:
224
223
  L.Log("Koatty", "", "Initializing Component Manager ...");
225
- const s = new i(t);
226
- m.define(t, "componentManager", s);
224
+ const s = new i(e);
225
+ m.define(e, "componentManager", s);
227
226
  s.discoverComponents();
228
227
  const c = s.getStats();
229
228
  L.Log("Koatty", "", `Discovered ${c.coreComponents} core components, ${c.userComponents} user components`);
@@ -231,108 +230,108 @@ class Loader {
231
230
  await l.LoadComponents(s);
232
231
  s.registerAppEvents(o);
233
232
  s.registerCoreComponentHooks();
234
- await n(t, e);
233
+ await n(e, t);
235
234
  break;
236
235
 
237
236
  case a.loadPlugin:
238
237
  L.Log("Koatty", "", "Emit loadPlugin ...");
239
- await n(t, e);
238
+ await n(e, t);
240
239
  break;
241
240
 
242
241
  case a.loadMiddleware:
243
242
  L.Log("Koatty", "", "Load Middlewares ...");
244
243
  await l.LoadMiddlewares();
245
- await n(t, e);
244
+ await n(e, t);
246
245
  break;
247
246
 
248
247
  case a.loadService:
249
248
  L.Log("Koatty", "", "Load Services ...");
250
249
  await l.LoadServices();
251
- await n(t, e);
250
+ await n(e, t);
252
251
  break;
253
252
 
254
253
  case a.loadController:
255
254
  L.Log("Koatty", "", "Load Controllers ...");
256
255
  await l.LoadControllers();
257
- await n(t, e);
256
+ await n(e, t);
258
257
  break;
259
258
 
260
259
  case a.loadRouter:
261
260
  L.Log("Koatty", "", "Initialize Router and Load Routes ...");
262
- await n(t, e);
261
+ await n(e, t);
263
262
  break;
264
263
 
265
264
  case a.loadServe:
266
265
  L.Log("Koatty", "", "Emit loadServe ...");
267
- await n(t, e);
266
+ await n(e, t);
268
267
  break;
269
268
 
270
269
  case a.appReady:
271
270
  L.Log("Koatty", "", "Emit appReady ...");
272
- await n(t, e);
271
+ await n(e, t);
273
272
  break;
274
273
 
275
274
  default:
276
- await n(t, e);
275
+ await n(e, t);
277
276
  break;
278
277
  }
279
278
  }
280
- LoadConfigs(e) {
279
+ LoadConfigs(t) {
281
280
  const o = {};
282
- h([ "./config" ], this.app.koattyPath, function(t, e, a) {
283
- o[t] = a;
281
+ h([ "./config" ], this.app.koattyPath, function(e, t, a) {
282
+ o[e] = a;
284
283
  });
285
- if (m.isArray(e)) e = e.length > 0 ? e : [ "./config" ];
286
- let a = t(e, this.app.appPath);
284
+ if (m.isArray(t)) t = t.length > 0 ? t : [ "./config" ];
285
+ let a = e(t, this.app.appPath);
287
286
  a = m.extend(o, a, !0);
288
287
  this.app.setMetaData("_configs", a);
289
288
  }
290
289
  async LoadMiddlewares() {
291
- var t, o, a, s;
290
+ var e, o, a, s;
292
291
  let n = this.app.config(void 0, "middleware");
293
292
  if (m.isEmpty(n)) n = {
294
293
  config: {},
295
294
  list: []
296
295
  };
297
296
  try {
298
- const e = (o = (t = n.config) === null || t === void 0 ? void 0 : t.trace) !== null && o !== void 0 ? o : {};
299
- const a = y(e, this.app);
297
+ const t = (o = (e = n.config) === null || e === void 0 ? void 0 : e.trace) !== null && o !== void 0 ? o : {};
298
+ const a = y(t, this.app);
300
299
  m.define(this.app, "tracer", a);
301
300
  this.app.use(a);
302
301
  L.Debug(`Trace middleware registered`);
303
- } catch (t) {
304
- L.Warn(`Trace middleware failed to load: ${t.message}`);
302
+ } catch (e) {
303
+ L.Warn(`Trace middleware failed to load: ${e.message}`);
305
304
  }
306
- const i = (a = e.listClass("MIDDLEWARE")) !== null && a !== void 0 ? a : [];
307
- i.forEach(t => {
305
+ const i = (a = t.listClass("MIDDLEWARE")) !== null && a !== void 0 ? a : [];
306
+ i.forEach(e => {
308
307
  var o;
309
- t.id = ((o = t.id) !== null && o !== void 0 ? o : "").replace("MIDDLEWARE:", "");
310
- if (t.id && m.isClass(t.target)) {
311
- e.reg(t.id, t.target, {
308
+ e.id = ((o = e.id) !== null && o !== void 0 ? o : "").replace("MIDDLEWARE:", "");
309
+ if (e.id && m.isClass(e.target)) {
310
+ t.reg(e.id, e.target, {
312
311
  scope: "Prototype",
313
312
  type: "MIDDLEWARE",
314
313
  args: []
315
314
  });
316
- const o = e.getInsByClass(t.target);
317
- if (!r(o)) throw Error(`The middleware ${t.id} must implements interface 'IMiddleware'.`);
315
+ const o = t.getInsByClass(e.target);
316
+ if (!r(o)) throw Error(`The middleware ${e.id} must implements interface 'IMiddleware'.`);
318
317
  }
319
318
  });
320
319
  const d = n.list || [];
321
- const p = new Set([]);
322
- d.forEach(t => {
323
- p.add(t);
320
+ const f = new Set([]);
321
+ d.forEach(e => {
322
+ f.add(e);
324
323
  });
325
- const f = n.config || {};
326
- for (const t of Array.from(p)) {
327
- const o = e.get(t, "MIDDLEWARE");
328
- if (!o) throw Error(`Middleware ${t} load error.`);
329
- if (!m.isFunction(o.run)) throw Error(`The middleware ${t} must implements interface 'IMiddleware'.`);
330
- L.Debug(`Load middleware: ${t}`);
331
- const a = f[t] || {};
332
- const n = (s = i.find(e => e.id === t)) === null || s === void 0 ? void 0 : s.target;
324
+ const p = n.config || {};
325
+ for (const e of Array.from(f)) {
326
+ const o = t.get(e, "MIDDLEWARE");
327
+ if (!o) throw Error(`Middleware ${e} load error.`);
328
+ if (!m.isFunction(o.run)) throw Error(`The middleware ${e} must implements interface 'IMiddleware'.`);
329
+ L.Debug(`Load middleware: ${e}`);
330
+ const a = p[e] || {};
331
+ const n = (s = i.find(t => t.id === e)) === null || s === void 0 ? void 0 : s.target;
333
332
  let r = {};
334
333
  if (n) try {
335
- r = e.getPropertyData(l, n, t) || {};
334
+ r = t.getPropertyData(l, n, e) || {};
336
335
  } catch {
337
336
  r = {};
338
337
  }
@@ -341,94 +340,94 @@ class Loader {
341
340
  ...a
342
341
  };
343
342
  if (d.enabled === !1) {
344
- L.Warn(`The middleware ${t} has been loaded but is disabled.`);
343
+ L.Warn(`The middleware ${e} has been loaded but is disabled.`);
345
344
  continue;
346
345
  }
347
- const p = await o.run(d, this.app);
348
- if (m.isFunction(p)) {
349
- let e = p;
346
+ const f = await o.run(d, this.app);
347
+ if (m.isFunction(f)) {
348
+ let t = f;
350
349
  if (d.protocol) {
351
350
  const o = m.isArray(d.protocol) ? d.protocol : [ d.protocol ];
352
- L.Log("Koatty", "", `Middleware ${t} limited to protocols: ${o.join(", ")}`);
353
- e = c(o, p);
351
+ L.Log("Koatty", "", `Middleware ${e} limited to protocols: ${o.join(", ")}`);
352
+ t = c(o, f);
354
353
  }
355
- if (e.length < 3) this.app.use(e); else this.app.useExp(e);
354
+ if (t.length < 3) this.app.use(t); else this.app.useExp(t);
356
355
  }
357
356
  }
358
357
  }
359
358
  async LoadControllers() {
360
- const t = e.listClass("CONTROLLER");
359
+ const e = t.listClass("CONTROLLER");
361
360
  const o = [];
362
- t.forEach(t => {
361
+ e.forEach(e => {
363
362
  var a;
364
- t.id = ((a = t.id) !== null && a !== void 0 ? a : "").replace("CONTROLLER:", "");
365
- if (t.id && m.isClass(t.target)) {
366
- L.Debug(`Load controller: ${t.id}`);
367
- e.reg(t.id, t.target, {
363
+ e.id = ((a = e.id) !== null && a !== void 0 ? a : "").replace("CONTROLLER:", "");
364
+ if (e.id && m.isClass(e.target)) {
365
+ L.Debug(`Load controller: ${e.id}`);
366
+ t.reg(e.id, e.target, {
368
367
  scope: "Prototype",
369
368
  type: "CONTROLLER",
370
369
  args: []
371
370
  });
372
- const a = e.getInsByClass(t.target);
373
- if (!d(a)) throw Error(`The controller ${t.id} must implements interface 'IController'.`);
374
- o.push(t.id);
371
+ const a = t.getInsByClass(e.target);
372
+ if (!d(a)) throw Error(`The controller ${e.id} must implements interface 'IController'.`);
373
+ o.push(e.id);
375
374
  }
376
375
  });
377
376
  this.app.setMetaData("_controllers", o);
378
377
  return o;
379
378
  }
380
379
  async LoadServices() {
381
- var t;
382
- const o = e.listClass("SERVICE");
380
+ var e;
381
+ const o = t.listClass("SERVICE");
383
382
  for (const a of o) {
384
- a.id = ((t = a.id) !== null && t !== void 0 ? t : "").replace("SERVICE:", "");
383
+ a.id = ((e = a.id) !== null && e !== void 0 ? e : "").replace("SERVICE:", "");
385
384
  if (a.id && m.isClass(a.target)) {
386
385
  L.Debug(`Load service: ${a.id}`);
387
- e.reg(a.id, a.target, {
386
+ t.reg(a.id, a.target, {
388
387
  scope: "Singleton",
389
388
  type: "SERVICE",
390
389
  args: []
391
390
  });
392
- const t = e.getInsByClass(a.target);
393
- if (!p(t)) throw Error(`The service ${a.id} must implements interface 'IService'.`);
391
+ const e = t.getInsByClass(a.target);
392
+ if (!f(e)) throw Error(`The service ${a.id} must implements interface 'IService'.`);
394
393
  }
395
394
  }
396
395
  }
397
- async LoadComponents(t) {
396
+ async LoadComponents(e) {
398
397
  var o, a;
399
- const s = e.listClass("COMPONENT");
400
- s.forEach(t => {
398
+ const s = t.listClass("COMPONENT");
399
+ s.forEach(e => {
401
400
  var o;
402
- t.id = ((o = t.id) !== null && o !== void 0 ? o : "").replace("COMPONENT:", "");
403
- if (m.isClass(t.target)) {
404
- e.reg(t.id, t.target, {
401
+ e.id = ((o = e.id) !== null && o !== void 0 ? o : "").replace("COMPONENT:", "");
402
+ if (m.isClass(e.target)) {
403
+ t.reg(e.id, e.target, {
405
404
  scope: "Singleton",
406
405
  type: "COMPONENT",
407
406
  args: []
408
407
  });
409
- if (t.id && t.id.endsWith("Aspect")) {
410
- const o = e.getInsByClass(t.target);
411
- if (!f(o)) throw Error(`The aspect ${t.id} must implements interface 'IAspect'.`);
408
+ if (e.id && e.id.endsWith("Aspect")) {
409
+ const o = t.getInsByClass(e.target);
410
+ if (!p(o)) throw Error(`The aspect ${e.id} must implements interface 'IAspect'.`);
412
411
  }
413
412
  }
414
413
  });
415
- if (t) await t.loadUserComponents(); else {
414
+ if (e) await e.loadUserComponents(); else {
416
415
  L.Warn("Loading plugins in legacy mode");
417
- let t = this.app.config(void 0, "plugin");
418
- if (m.isEmpty(t)) t = {
416
+ let e = this.app.config(void 0, "plugin");
417
+ if (m.isEmpty(e)) e = {
419
418
  config: {},
420
419
  list: []
421
420
  };
422
- const s = (o = t.list) !== null && o !== void 0 ? o : [];
421
+ const s = (o = e.list) !== null && o !== void 0 ? o : [];
423
422
  for (const o of s) {
424
- const s = e.get(o, "COMPONENT");
423
+ const s = t.get(o, "COMPONENT");
425
424
  if (!s) throw Error(`Plugin ${o} load error.`);
426
425
  if (!m.isFunction(s.run)) throw Error(`Plugin ${o} must implements interface 'IPlugin'.`);
427
- if (t.config[o] === !1) {
426
+ if (e.config[o] === !1) {
428
427
  L.Warn(`Plugin ${o} already loaded but not effective.`);
429
428
  continue;
430
429
  }
431
- await s.run((a = t.config[o]) !== null && a !== void 0 ? a : {}, this.app);
430
+ await s.run((a = e.config[o]) !== null && a !== void 0 ? a : {}, this.app);
432
431
  }
433
432
  }
434
433
  }
@@ -442,78 +441,78 @@ class Loader {
442
441
  * @LastEditTime: 2025-01-14 16:11:21
443
442
  * @License: BSD (3-Clause)
444
443
  * @Copyright (c): <richenlin(at)gmail.com>
445
- */ function K(t) {
444
+ */ function K(e) {
446
445
  return function(o) {
447
446
  if (!(o.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
448
- e.saveClass("COMPONENT", o, "KOATTY_APP");
449
- I(o, t);
447
+ t.saveClass("COMPONENT", o, "KOATTY_APP");
448
+ I(o, e);
450
449
  return o;
451
450
  };
452
451
  }
453
452
 
454
- function N(t) {
455
- return async e => {
456
- if (!(e.prototype instanceof g)) throw new Error(`class ${e.name} does not inherit from Koatty`);
457
- return await I(e, t, !0);
453
+ function N(e) {
454
+ return async t => {
455
+ if (!(t.prototype instanceof g)) throw new Error(`class ${t.name} does not inherit from Koatty`);
456
+ return await I(t, e, !0);
458
457
  };
459
458
  }
460
459
 
461
- function D(t) {
460
+ function D(e) {
462
461
  return a => {
463
462
  if (!(a.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
464
- t = t !== null && t !== void 0 ? t : "";
465
- e.saveClassMetadata(o, _, t, a);
463
+ e = e !== null && e !== void 0 ? e : "";
464
+ t.saveClassMetadata(o, _, e, a);
466
465
  };
467
466
  }
468
467
 
469
- function S(t) {
468
+ function S(e) {
470
469
  return a => {
471
470
  if (!(a.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
472
- t = t !== null && t !== void 0 ? t : "";
473
- e.saveClassMetadata(o, A, t, a);
471
+ e = e !== null && e !== void 0 ? e : "";
472
+ t.saveClassMetadata(o, A, e, a);
474
473
  };
475
474
  }
476
475
 
477
- const I = async function(t, o, a = !1) {
476
+ const I = async function(e, o, a = !1) {
478
477
  if (process.env.NODE_DEBUG) {
479
- const t = process.env.NODE_DEBUG.split(",").filter(t => !t.includes("winston")).join(",");
480
- process.env.NODE_DEBUG = t;
478
+ const e = process.env.NODE_DEBUG.split(",").filter(e => !e.includes("winston")).join(",");
479
+ process.env.NODE_DEBUG = e;
481
480
  }
482
481
  O();
483
482
  const s = T();
484
483
  if (!a && s) return;
485
- const n = Reflect.construct(t, []);
484
+ const n = Reflect.construct(e, []);
486
485
  if (s) {
487
486
  n.silent = !0;
488
487
  L.enable(!1);
489
488
  }
490
489
  try {
491
490
  if (!n.silent) console.log($);
492
- if (!(n instanceof g)) throw new Error(`class ${t.name} does not inherit from Koatty`);
491
+ if (!(n instanceof g)) throw new Error(`class ${e.name} does not inherit from Koatty`);
493
492
  Loader.initialize(n);
494
493
  if (m.isFunction(o)) {
495
494
  L.Log("Koatty", "", "Execute bootFunc ...");
496
495
  await o(n);
497
496
  }
498
- e.setApp(n);
497
+ t.setApp(n);
499
498
  L.Log("Koatty", "", "ComponentScan ...");
500
- Loader.CheckAllComponents(n, t);
501
- await Loader.LoadAllComponents(n, t);
499
+ Loader.CheckAllComponents(n, e);
500
+ await Loader.LoadAllComponents(n, e);
502
501
  if (!s) n.listen(R);
503
502
  return n;
504
- } catch (t) {
505
- L.Fatal(t);
503
+ } catch (e) {
504
+ L.Fatal(e);
506
505
  }
507
506
  };
508
507
 
509
- const R = t => {
508
+ const R = e => {
510
509
  L.Log("Koatty", "", "====================================");
511
510
  L.Log("Koatty", "", `Nodejs Version: ${process.version}`);
512
511
  L.Log("Koatty", "", `Koatty Version: v${b}`);
513
- L.Log("Koatty", "", `App Environment: ${t.env}`);
514
- if (t.appDebug) L.Warn(`Running in debug mode.`);
512
+ L.Log("Koatty", "", `App Environment: ${e.env}`);
513
+ if (e.appDebug) L.Warn(`Running in debug mode.`);
515
514
  L.Log("Koatty", "", "====================================");
516
- n(t, a.appStart);
515
+ n(e, a.appStart);
517
516
  };
518
517
 
519
518
  export { K as Bootstrap, D as ComponentScan, S as ConfigurationScan, N as ExecBootStrap, L as Logger };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "Koa + 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",
@@ -91,8 +91,8 @@
91
91
  "koatty_loader": "^1.1.4",
92
92
  "koatty_logger": "^2.4.0",
93
93
  "koatty_router": "^2.1.0",
94
- "koatty_serve": "^3.1.0",
95
- "koatty_trace": "^2.1.0",
94
+ "koatty_serve": "^3.1.1",
95
+ "koatty_trace": "^2.1.1",
96
96
  "ts-morph": "^27.0.2"
97
97
  }
98
98
  }
@@ -11,8 +11,11 @@
11
11
  ],
12
12
  "author": "richenlin",
13
13
  "license": "BSD-3-Clause",
14
+ "scripts": {
15
+ "dev": "node --nolazy -r ts-node/register ./src/App.ts"
16
+ },
14
17
  "devDependencies": {
15
- "@types/node": "^24.9.1",
18
+ "@types/node": "^25.1.0",
16
19
  "ts-node": "^10.x.x",
17
20
  "tsconfig-paths": "^4.x.x",
18
21
  "typescript": "^5.x.x"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "Koa + Typescript = koatty. Use Typescript's decorator implement auto injection.",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -75,15 +75,15 @@
75
75
  "koa": "^3.1.1",
76
76
  "ts-morph": "^27.0.2",
77
77
  "koatty_config": "1.2.9",
78
- "koatty_core": "2.1.0",
78
+ "koatty_container": "2.0.0",
79
79
  "koatty_exception": "2.1.0",
80
+ "koatty_core": "2.1.0",
80
81
  "koatty_lib": "1.4.5",
81
82
  "koatty_logger": "2.4.0",
82
- "koatty_loader": "1.1.4",
83
- "koatty_serve": "3.1.0",
84
- "koatty_trace": "2.1.0",
85
83
  "koatty_router": "2.1.0",
86
- "koatty_container": "2.0.0"
84
+ "koatty_trace": "2.1.1",
85
+ "koatty_serve": "3.1.1",
86
+ "koatty_loader": "1.1.4"
87
87
  },
88
88
  "scripts": {
89
89
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",