koatty 4.0.0 → 4.0.4

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-11-02 10:59:26
3
+ * @Date: 2026-01-28 16:08:37
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: 2025-11-02 10:59:15
3
+ * @Date: 2026-01-28 16:08:28
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -19,9 +19,9 @@ var a = require("koatty_lib");
19
19
 
20
20
  var n = require("koatty_router");
21
21
 
22
- var s = require("koatty_logger");
22
+ var i = require("koatty_logger");
23
23
 
24
- var i = require("koatty_loader");
24
+ var s = require("koatty_loader");
25
25
 
26
26
  var l = require("koatty_serve");
27
27
 
@@ -48,7 +48,7 @@ function d(e) {
48
48
 
49
49
  var f = d(c);
50
50
 
51
- var u = "3.14.0-beta.1";
51
+ var u = "4.0.4";
52
52
 
53
53
  var g = {
54
54
  node: ">=18.0.0"
@@ -62,24 +62,24 @@ var g = {
62
62
  * @LastEditTime: 2024-10-31 17:52:43
63
63
  * @License: BSD (3-Clause)
64
64
  * @Copyright (c): <richenlin(at)gmail.com>
65
- */ const y = s.DefaultLogger;
65
+ */ const y = i.DefaultLogger;
66
66
 
67
- function h(e, t) {
68
- if (!e.appDebug) s.DefaultLogger.enableBuffering({
67
+ function L(e, t) {
68
+ if (!e.appDebug) i.DefaultLogger.enableBuffering({
69
69
  maxBufferSize: 200,
70
70
  flushInterval: 500,
71
71
  flushOnLevel: "error"
72
72
  });
73
- if (t.logLevel) s.DefaultLogger.setLevel(t.logLevel);
73
+ if (t.logLevel) i.DefaultLogger.setLevel(t.logLevel);
74
74
  if (t.logFilePath && !e.silent) {
75
75
  a.Helper.define(e, "logsPath", t.logFilePath);
76
76
  process.env.LOGS_PATH = t.logFilePath;
77
- s.DefaultLogger.setLogFilePath(t.logFilePath);
77
+ i.DefaultLogger.setLogFilePath(t.logFilePath);
78
78
  }
79
- if (t.sensFields) s.DefaultLogger.setSensFields(t.sensFields);
79
+ if (t.sensFields) i.DefaultLogger.setSensFields(t.sensFields);
80
80
  e.once(o.AppEvent.appStop, async () => {
81
- await s.DefaultLogger.flush();
82
- await s.DefaultLogger.destroy();
81
+ await i.DefaultLogger.flush();
82
+ await i.DefaultLogger.destroy();
83
83
  });
84
84
  }
85
85
 
@@ -91,11 +91,11 @@ function h(e, t) {
91
91
  * @LastEditTime: 2025-01-14 16:14:10
92
92
  * @License: BSD (3-Clause)
93
93
  * @Copyright (c): <richenlin(at)gmail.com>
94
- */ const L = u;
94
+ */ const v = u;
95
95
 
96
- const v = g.node.slice(1) || "12.0.0";
96
+ const E = g.node.slice(1) || "12.0.0";
97
97
 
98
- function C(e, t, o, r) {
98
+ function h(e, t, o, r) {
99
99
  if (a.Helper.isClass(o) && o.name != e) throw Error(`The file(${t}) name should be always the same as class name.`);
100
100
  if (o["__esModule"]) if (o.name === void 0) {
101
101
  const r = Object.keys(o);
@@ -107,8 +107,8 @@ function C(e, t, o, r) {
107
107
  return;
108
108
  }
109
109
 
110
- function m() {
111
- let e = v;
110
+ function C() {
111
+ let e = E;
112
112
  e = e.slice(0, e.lastIndexOf("."));
113
113
  let t = process.version;
114
114
  if (t[0] === "v") t = t.slice(1);
@@ -119,7 +119,7 @@ function m() {
119
119
  }
120
120
  }
121
121
 
122
- const E = () => {
122
+ const m = () => {
123
123
  let e = !1;
124
124
  const t = JSON.stringify(process.argv[1]);
125
125
  if (t.indexOf("jest") > -1) e = !0;
@@ -134,9 +134,9 @@ const E = () => {
134
134
  * @LastEditTime: 2023-12-09 23:00:13
135
135
  * @License: BSD (3-Clause)
136
136
  * @Copyright (c): <richenlin(at)gmail.com>
137
- */ const O = "COMPONENT_SCAN";
137
+ */ const w = "COMPONENT_SCAN";
138
138
 
139
- const w = "CONFIGURATION_SCAN";
139
+ const O = "CONFIGURATION_SCAN";
140
140
 
141
141
  const A = `\n\n┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬\n├┴┐│ │├─┤ │ │ └┬┘\n┴ ┴└─┘┴ ┴ ┴ ┴ ┴ \n-------------------------------------------\nhttps://github.com/koatty\n`
142
142
  /*
@@ -168,6 +168,7 @@ class Loader {
168
168
  e.version = e.version || t.version;
169
169
  }
170
170
  }
171
+ y.Warn("Using process.env for paths is deprecated. Use app.rootPath, app.appPath, app.koattyPath instead.");
171
172
  process.env.ROOT_PATH = t;
172
173
  process.env.APP_PATH = o;
173
174
  process.env.KOATTY_PATH = r;
@@ -176,13 +177,13 @@ class Loader {
176
177
  }
177
178
  static GetComponentMeta(e, o) {
178
179
  let r = [];
179
- const n = t.IOC.getClassMetadata(t.TAGGED_CLS, O, o);
180
+ const n = t.IOC.getClassMetadata(t.TAGGED_CLS, w, o);
180
181
  if (n) if (a.Helper.isArray(n)) r = n; else r.push(n);
181
182
  if (r.length < 1) r = [ e.appPath ];
182
183
  return r;
183
184
  }
184
185
  static GetConfigurationMeta(e, o) {
185
- const r = t.IOC.getClassMetadata(t.TAGGED_CLS, w, o);
186
+ const r = t.IOC.getClassMetadata(t.TAGGED_CLS, O, o);
186
187
  let n = [];
187
188
  if (r) if (a.Helper.isArray(r)) n = r; else n.push(r);
188
189
  return n;
@@ -191,8 +192,8 @@ class Loader {
191
192
  const o = Loader.GetComponentMeta(e, t);
192
193
  const r = Loader.GetConfigurationMeta(e, t);
193
194
  const a = new Set;
194
- i.Load(o, "", (e, t, o) => {
195
- C(e, t, o, a);
195
+ s.Load(o, "", (e, t, o) => {
196
+ h(e, t, o, a);
196
197
  }, [ "**/**.js", "**/**.ts", "!**/**.d.ts" ], [ ...r, `${t.name || ".no"}.ts` ]);
197
198
  a.clear();
198
199
  }
@@ -206,7 +207,7 @@ class Loader {
206
207
  if (t.logsLevel) r = t.logsLevel.toLowerCase();
207
208
  if (t.logsPath) a = t.logsPath;
208
209
  if (t.sensFields) n = t.sensFields;
209
- h(e, {
210
+ L(e, {
210
211
  logLevel: r,
211
212
  logFilePath: a,
212
213
  sensFields: n
@@ -216,78 +217,96 @@ class Loader {
216
217
  static LoadAppEventHooks(e, r) {
217
218
  const n = new Map;
218
219
  for (const e of o.AppEventArr) {
219
- let s;
220
+ let i;
220
221
  switch (e) {
221
222
  case o.AppEvent.appBoot:
222
- s = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appBoot, r);
223
- if (a.Helper.isArray(s)) n.set(o.AppEvent.appBoot, s);
223
+ i = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appBoot, r);
224
+ if (a.Helper.isArray(i)) n.set(o.AppEvent.appBoot, i);
224
225
  break;
225
226
 
226
227
  case o.AppEvent.appReady:
227
- s = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appReady, r);
228
- if (a.Helper.isArray(s)) n.set(o.AppEvent.appReady, s);
228
+ i = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appReady, r);
229
+ if (a.Helper.isArray(i)) n.set(o.AppEvent.appReady, i);
229
230
  break;
230
231
 
231
232
  case o.AppEvent.appStart:
232
- s = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appStart, r);
233
- if (a.Helper.isArray(s)) n.set(o.AppEvent.appStart, s);
233
+ i = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appStart, r);
234
+ if (a.Helper.isArray(i)) n.set(o.AppEvent.appStart, i);
234
235
  break;
235
236
 
236
237
  case o.AppEvent.appStop:
237
- s = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appStop, r);
238
- if (a.Helper.isArray(s)) n.set(o.AppEvent.appStop, s);
238
+ i = t.IOC.getClassMetadata(t.TAGGED_CLS, o.AppEvent.appStop, r);
239
+ if (a.Helper.isArray(i)) n.set(o.AppEvent.appStop, i);
239
240
  break;
240
241
  }
241
242
  }
242
243
  for (const [t, o] of n) for (const r of o) e.once(t, () => r(e));
243
244
  }
244
- static async LoadAllComponents(e, o) {
245
- var r, n, s;
245
+ static async LoadAllComponents(e, r) {
246
246
  try {
247
247
  if (a.Helper.isFunction(t.IOC.preloadMetadata)) t.IOC.preloadMetadata();
248
248
  } catch {
249
249
  y.Warn("[Loader] preloadMetadata is optional, ignore if not available");
250
250
  }
251
251
  y.Log("Koatty", "", "Load Configurations ...");
252
- const i = Loader.GetConfigurationMeta(e, o);
253
- const l = new Loader(e);
254
- l.LoadConfigs(i);
252
+ const n = Loader.GetConfigurationMeta(e, r);
253
+ const i = new Loader(e);
254
+ i.LoadConfigs(n);
255
255
  Loader.SetLogger(e);
256
- const p = (r = e.config("server")) !== null && r !== void 0 ? r : {
257
- protocol: "http"
258
- };
259
- const c = (n = p.protocol) !== null && n !== void 0 ? n : "http";
260
- const d = (s = e.config(void 0, "router")) !== null && s !== void 0 ? s : {};
261
- const f = a.Helper.isArray(c) ? c : [ c ];
262
- const u = Loader.CreateServers(e, p, f);
263
- a.Helper.define(e, "server", u);
264
- const g = Loader.CreateRouters(e, d, f);
265
- a.Helper.define(e, "router", g);
256
+ y.Log("Koatty", "", "Emit Config Loaded ...");
257
+ await o.asyncEvent(e, o.AppEvent.configLoaded);
258
+ y.Log("Koatty", "", "Initializing Component Manager ...");
259
+ const s = new o.ComponentManager(e);
260
+ a.Helper.define(e, "componentManager", s);
261
+ s.discoverPlugins();
262
+ s.registerCorePluginHooks();
263
+ const l = s.getStats();
264
+ y.Log("Koatty", "", `Discovered ${l.corePlugins} core plugins, ${l.userPlugins} user plugins`);
265
+ y.Log("Koatty", "", "Emit Before Component Load ...");
266
+ await o.asyncEvent(e, o.AppEvent.beforeComponentLoad);
266
267
  y.Log("Koatty", "", "Load Components ...");
267
- await l.LoadComponents();
268
+ await i.LoadComponents(s);
269
+ y.Log("Koatty", "", "Emit After Component Load ...");
270
+ await o.asyncEvent(e, o.AppEvent.afterComponentLoad);
271
+ y.Log("Koatty", "", "Emit Before Middleware Load ...");
272
+ await o.asyncEvent(e, o.AppEvent.beforeMiddlewareLoad);
268
273
  y.Log("Koatty", "", "Load Middlewares ...");
269
- await l.LoadMiddlewares();
274
+ await i.LoadMiddlewares();
275
+ y.Log("Koatty", "", "Emit After Middleware Load ...");
276
+ await o.asyncEvent(e, o.AppEvent.afterMiddlewareLoad);
277
+ y.Log("Koatty", "", "Emit Before Service Load ...");
278
+ await o.asyncEvent(e, o.AppEvent.beforeServiceLoad);
270
279
  y.Log("Koatty", "", "Load Services ...");
271
- await l.LoadServices();
280
+ await i.LoadServices();
281
+ y.Log("Koatty", "", "Emit After Service Load ...");
282
+ await o.asyncEvent(e, o.AppEvent.afterServiceLoad);
283
+ y.Log("Koatty", "", "Emit Before Controller Load ...");
284
+ await o.asyncEvent(e, o.AppEvent.beforeControllerLoad);
272
285
  y.Log("Koatty", "", "Load Controllers ...");
273
- const h = await l.LoadControllers();
286
+ const p = await i.LoadControllers();
287
+ y.Log("Koatty", "", "Emit After Controller Load ...");
288
+ await o.asyncEvent(e, o.AppEvent.afterControllerLoad);
289
+ y.Log("Koatty", "", "Emit Before Router Load ...");
290
+ await o.asyncEvent(e, o.AppEvent.beforeRouterLoad);
274
291
  y.Log("Koatty", "", "Load Routers ...");
275
- await l.LoadRouter(h);
292
+ await i.LoadRouter(p);
293
+ y.Log("Koatty", "", "Emit After Router Load ...");
294
+ await o.asyncEvent(e, o.AppEvent.afterRouterLoad);
276
295
  }
277
296
  static CreateServers(e, t, o) {
278
297
  if (o.length > 1) {
279
298
  const r = [];
280
299
  const n = a.Helper.isArray(t.port) ? t.port : [ t.port ];
281
- const s = [];
282
- for (let e = 0; e < o.length; e++) if (e < n.length) s.push(a.Helper.toNumber(n[e])); else s.push(a.Helper.toNumber(n[0]) + e);
300
+ const i = [];
301
+ for (let e = 0; e < o.length; e++) if (e < n.length) i.push(a.Helper.toNumber(n[e])); else i.push(a.Helper.toNumber(n[0]) + e);
283
302
  for (let a = 0; a < o.length; a++) {
284
303
  const n = o[a];
285
- const i = {
304
+ const s = {
286
305
  ...t,
287
306
  protocol: n,
288
- port: s[a]
307
+ port: i[a]
289
308
  };
290
- r.push(l.NewServe(e, i));
309
+ r.push(l.NewServe(e, s));
291
310
  }
292
311
  return r;
293
312
  } else {
@@ -321,7 +340,7 @@ class Loader {
321
340
  }
322
341
  LoadConfigs(t) {
323
342
  const o = {};
324
- i.Load([ "./config" ], this.app.koattyPath, function(e, t, r) {
343
+ s.Load([ "./config" ], this.app.koattyPath, function(e, t, r) {
325
344
  o[e] = r;
326
345
  });
327
346
  if (a.Helper.isArray(t)) t = t.length > 0 ? t : [ "./config" ];
@@ -340,13 +359,13 @@ class Loader {
340
359
  } catch (e) {
341
360
  y.Warn(`Trace middleware failed to load: ${e.message}`);
342
361
  }
343
- let s = this.app.config(void 0, "middleware");
344
- if (a.Helper.isEmpty(s)) s = {
362
+ let i = this.app.config(void 0, "middleware");
363
+ if (a.Helper.isEmpty(i)) i = {
345
364
  config: {},
346
365
  list: []
347
366
  };
348
- const i = (r = t.IOC.listClass("MIDDLEWARE")) !== null && r !== void 0 ? r : [];
349
- i.forEach(e => {
367
+ const s = (r = t.IOC.listClass("MIDDLEWARE")) !== null && r !== void 0 ? r : [];
368
+ s.forEach(e => {
350
369
  var r;
351
370
  e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("MIDDLEWARE:", "");
352
371
  if (e.id && a.Helper.isClass(e.target)) {
@@ -359,19 +378,19 @@ class Loader {
359
378
  if (!o.implementsMiddlewareInterface(r)) throw Error(`The middleware ${e.id} must implements interface 'IMiddleware'.`);
360
379
  }
361
380
  });
362
- const l = s.list || [];
381
+ const l = i.list || [];
363
382
  const c = new Set([]);
364
383
  l.forEach(e => {
365
384
  c.add(e);
366
385
  });
367
- const d = s.config || {};
386
+ const d = i.config || {};
368
387
  for (const e of c) {
369
388
  const r = t.IOC.get(e, "MIDDLEWARE");
370
389
  if (!r) throw Error(`Middleware ${e} load error.`);
371
390
  if (!a.Helper.isFunction(r.run)) throw Error(`The middleware ${e} must implements interface 'IMiddleware'.`);
372
391
  y.Debug(`Load middleware: ${e}`);
373
- const s = d[e] || {};
374
- const l = (n = i.find(t => t.id === e)) === null || n === void 0 ? void 0 : n.target;
392
+ const i = d[e] || {};
393
+ const l = (n = s.find(t => t.id === e)) === null || n === void 0 ? void 0 : n.target;
375
394
  let p = {};
376
395
  if (l) try {
377
396
  p = t.IOC.getPropertyData(o.MIDDLEWARE_OPTIONS, l, e) || {};
@@ -380,7 +399,7 @@ class Loader {
380
399
  }
381
400
  const c = {
382
401
  ...p,
383
- ...s
402
+ ...i
384
403
  };
385
404
  if (c.enabled === !1) {
386
405
  y.Warn(`The middleware ${e} has been loaded but is disabled.`);
@@ -419,27 +438,26 @@ class Loader {
419
438
  return r;
420
439
  }
421
440
  async LoadServices() {
422
- const e = t.IOC.listClass("SERVICE");
423
- e.forEach(e => {
424
- var r;
425
- e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("SERVICE:", "");
426
- if (e.id && a.Helper.isClass(e.target)) {
427
- y.Debug(`Load service: ${e.id}`);
428
- t.IOC.reg(e.id, e.target, {
441
+ var e;
442
+ const r = t.IOC.listClass("SERVICE");
443
+ for (const n of r) {
444
+ n.id = ((e = n.id) !== null && e !== void 0 ? e : "").replace("SERVICE:", "");
445
+ if (n.id && a.Helper.isClass(n.target)) {
446
+ y.Debug(`Load service: ${n.id}`);
447
+ t.IOC.reg(n.id, n.target, {
429
448
  scope: "Singleton",
430
449
  type: "SERVICE",
431
450
  args: []
432
451
  });
433
- const r = t.IOC.getInsByClass(e.target);
434
- if (!o.implementsServiceInterface(r)) throw Error(`The service ${e.id} must implements interface 'IService'.`);
452
+ const e = t.IOC.getInsByClass(n.target);
453
+ if (!o.implementsServiceInterface(e)) throw Error(`The service ${n.id} must implements interface 'IService'.`);
435
454
  }
436
- });
455
+ }
437
456
  }
438
- async LoadComponents() {
439
- var e, r;
440
- const n = t.IOC.listClass("COMPONENT");
441
- const s = [];
442
- n.forEach(async e => {
457
+ async LoadComponents(e) {
458
+ var r, n;
459
+ const i = t.IOC.listClass("COMPONENT");
460
+ i.forEach(e => {
443
461
  var r;
444
462
  e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("COMPONENT:", "");
445
463
  if (a.Helper.isClass(e.target)) {
@@ -448,32 +466,30 @@ class Loader {
448
466
  type: "COMPONENT",
449
467
  args: []
450
468
  });
451
- if (e.id && e.id.endsWith("Plugin")) {
452
- const r = t.IOC.getInsByClass(e.target);
453
- if (!o.implementsPluginInterface(r)) throw Error(`The plugin ${e.id} must implements interface 'IPlugin'.`);
454
- s.push(e.id);
455
- }
456
469
  if (e.id && e.id.endsWith("Aspect")) {
457
470
  const r = t.IOC.getInsByClass(e.target);
458
471
  if (!o.implementsAspectInterface(r)) throw Error(`The aspect ${e.id} must implements interface 'IAspect'.`);
459
472
  }
460
473
  }
461
474
  });
462
- let i = this.app.config(void 0, "plugin");
463
- if (a.Helper.isEmpty(i)) i = {
464
- config: {},
465
- list: []
466
- };
467
- const l = (e = i.list) !== null && e !== void 0 ? e : [];
468
- for (const e of l) {
469
- const o = t.IOC.get(e, "COMPONENT");
470
- if (!o) throw Error(`Plugin ${e} load error.`);
471
- if (!a.Helper.isFunction(o.run)) throw Error(`Plugin ${e} must implements interface 'IPlugin'.`);
472
- if (i.config[e] === !1) {
473
- y.Warn(`Plugin ${e} already loaded but not effective.`);
474
- continue;
475
+ if (e) await e.loadUserPlugins(); else {
476
+ y.Warn("Loading plugins in legacy mode");
477
+ let e = this.app.config(void 0, "plugin");
478
+ if (a.Helper.isEmpty(e)) e = {
479
+ config: {},
480
+ list: []
481
+ };
482
+ const o = (r = e.list) !== null && r !== void 0 ? r : [];
483
+ for (const r of o) {
484
+ const o = t.IOC.get(r, "COMPONENT");
485
+ if (!o) throw Error(`Plugin ${r} load error.`);
486
+ if (!a.Helper.isFunction(o.run)) throw Error(`Plugin ${r} must implements interface 'IPlugin'.`);
487
+ if (e.config[r] === !1) {
488
+ y.Warn(`Plugin ${r} already loaded but not effective.`);
489
+ continue;
490
+ }
491
+ await o.run((n = e.config[r]) !== null && n !== void 0 ? n : {}, this.app);
475
492
  }
476
- await o.run((r = i.config[e]) !== null && r !== void 0 ? r : {}, this.app);
477
493
  }
478
494
  }
479
495
  async LoadRouter(e) {
@@ -514,81 +530,109 @@ class Loader {
514
530
  */ function b(e) {
515
531
  return function(t) {
516
532
  if (!(t.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
517
- R(t, e);
533
+ H(t, e);
518
534
  return t;
519
535
  };
520
536
  }
521
537
 
522
- function I(e) {
538
+ function P(e) {
523
539
  return async t => {
524
540
  if (!(t.prototype instanceof o.Koatty)) throw new Error(`class ${t.name} does not inherit from Koatty`);
525
- return await R(t, e, !0);
541
+ return await H(t, e, !0);
526
542
  };
527
543
  }
528
544
 
529
- function H(e) {
545
+ function S(e) {
530
546
  return r => {
531
547
  if (!(r.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
532
548
  e = e !== null && e !== void 0 ? e : "";
533
- t.IOC.saveClassMetadata(t.TAGGED_CLS, O, e, r);
549
+ t.IOC.saveClassMetadata(t.TAGGED_CLS, w, e, r);
534
550
  };
535
551
  }
536
552
 
537
- function P(e) {
553
+ function I(e) {
538
554
  return r => {
539
555
  if (!(r.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
540
556
  e = e !== null && e !== void 0 ? e : "";
541
- t.IOC.saveClassMetadata(t.TAGGED_CLS, w, e, r);
557
+ t.IOC.saveClassMetadata(t.TAGGED_CLS, O, e, r);
542
558
  };
543
559
  }
544
560
 
545
- function S(e, o, r) {
561
+ function K(e, o, r) {
546
562
  t.IOC.attachClassMetadata(t.TAGGED_CLS, e, o, r);
547
563
  }
548
564
 
549
- const R = async function(e, r, n = !1) {
550
- m();
551
- const s = E();
552
- if (!n && s) return;
553
- const i = Reflect.construct(e, []);
554
- if (s) {
555
- i.silent = !0;
565
+ const H = async function(e, r, n = !1) {
566
+ C();
567
+ const i = m();
568
+ if (!n && i) return;
569
+ const s = Reflect.construct(e, []);
570
+ if (i) {
571
+ s.silent = !0;
556
572
  y.enable(!1);
557
573
  }
558
574
  try {
559
- if (!i.silent) console.log(A);
560
- if (!(i instanceof o.Koatty)) throw new Error(`class ${e.name} does not inherit from Koatty`);
561
- Loader.initialize(i);
575
+ if (!s.silent) console.log(A);
576
+ if (!(s instanceof o.Koatty)) throw new Error(`class ${e.name} does not inherit from Koatty`);
577
+ Loader.initialize(s);
562
578
  if (a.Helper.isFunction(r)) {
563
579
  y.Log("Koatty", "", "Execute bootFunc ...");
564
- await r(i);
580
+ await r(s);
565
581
  }
566
- t.IOC.setApp(i);
582
+ t.IOC.setApp(s);
567
583
  y.Log("Koatty", "", "ComponentScan ...");
568
- Loader.CheckAllComponents(i, e);
569
- Loader.LoadAppEventHooks(i, e);
584
+ Loader.CheckAllComponents(s, e);
585
+ Loader.LoadAppEventHooks(s, e);
570
586
  y.Log("Koatty", "", "Emit App Boot ...");
571
- await o.asyncEvent(i, o.AppEvent.appBoot);
572
- await Loader.LoadAllComponents(i, e);
587
+ await o.asyncEvent(s, o.AppEvent.appBoot);
588
+ await Loader.LoadAllComponents(s, e);
573
589
  y.Log("Koatty", "", "Emit App Ready ...");
574
- await o.asyncEvent(i, o.AppEvent.appReady);
575
- if (!s) i.listen(T);
576
- return i;
590
+ await o.asyncEvent(s, o.AppEvent.appReady);
591
+ if (!i) {
592
+ y.Log("Koatty", "", "Emit Before Server Start ...");
593
+ await o.asyncEvent(s, o.AppEvent.beforeServerStart);
594
+ s.listen(M);
595
+ y.Log("Koatty", "", "Emit After Server Start ...");
596
+ await o.asyncEvent(s, o.AppEvent.afterServerStart);
597
+ }
598
+ return s;
577
599
  } catch (e) {
578
600
  y.Fatal(e);
579
601
  process.exit(1);
580
602
  }
581
603
  };
582
604
 
583
- const T = e => {
605
+ const M = e => {
584
606
  y.Log("Koatty", "", "====================================");
585
607
  y.Log("Koatty", "", `Nodejs Version: ${process.version}`);
586
- y.Log("Koatty", "", `Koatty Version: v${L}`);
608
+ y.Log("Koatty", "", `Koatty Version: v${v}`);
587
609
  y.Log("Koatty", "", `App Environment: ${e.env}`);
588
610
  if (e.appDebug) y.Warn(`Running in debug mode.`);
589
611
  y.Log("Koatty", "", "====================================");
590
612
  };
591
613
 
614
+ /*
615
+ * @Description: framework main file
616
+ * @Usage:
617
+ * @Author: richen
618
+ * @Date: 2023-12-09 21:56:32
619
+ * @LastEditTime: 2025-01-14 16:12:41
620
+ * @License: BSD (3-Clause)
621
+ * @Copyright (c): <richenlin(at)gmail.com>
622
+ */ function R() {
623
+ try {
624
+ require("koatty_router/dist/RouterPlugin");
625
+ } catch (e) {}
626
+ try {
627
+ require("koatty_serve/dist/ServePlugin");
628
+ } catch (e) {}
629
+ try {
630
+ require("koatty_trace/dist/TracePlugin");
631
+ } catch (e) {}
632
+ }
633
+
634
+ R();
635
+
592
636
  Object.defineProperty(exports, "Config", {
593
637
  enumerable: !0,
594
638
  get: function() {
@@ -603,15 +647,15 @@ Object.defineProperty(exports, "Helper", {
603
647
  }
604
648
  });
605
649
 
606
- exports.BindEventHook = S;
650
+ exports.BindEventHook = K;
607
651
 
608
652
  exports.Bootstrap = b;
609
653
 
610
- exports.ComponentScan = H;
654
+ exports.ComponentScan = S;
611
655
 
612
- exports.ConfigurationScan = P;
656
+ exports.ConfigurationScan = I;
613
657
 
614
- exports.ExecBootStrap = I;
658
+ exports.ExecBootStrap = P;
615
659
 
616
660
  exports.Logger = y;
617
661