koatty 4.1.6 → 4.1.8

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,501 +1,796 @@
1
+ import { LoadConfigs } from 'koatty_config';
2
+ export { Config } from 'koatty_config';
3
+ import { IOC, TAGGED_CLS } from 'koatty_container';
4
+ export * from 'koatty_container';
5
+ import { AppEvent, AppEventArr, asyncEvent, ComponentManager, implementsMiddlewareInterface, MIDDLEWARE_OPTIONS, protocolMiddleware, implementsControllerInterface, implementsServiceInterface, implementsAspectInterface, Koatty } from 'koatty_core';
6
+ export * from 'koatty_core';
7
+ export * from 'koatty_exception';
8
+ import { Helper } from 'koatty_lib';
9
+ export { Helper } from 'koatty_lib';
10
+ export * from 'koatty_router';
11
+ export * from 'koatty_serve';
12
+ import { DefaultLogger } from 'koatty_logger';
13
+ export { Log, LogLevelType, DefaultLogger as Logger } from 'koatty_logger';
14
+ import { Load } from 'koatty_loader';
15
+ import { Trace } from 'koatty_trace';
16
+ import * as path from 'path';
17
+
1
18
  /*!
2
19
  * @Author: richen
3
- * @Date: 2026-02-04 10:57:35
20
+ * @Date: 2026-02-10 09:13:30
4
21
  * @License: BSD (3-Clause)
5
22
  * @Copyright (c) - <richenlin(at)gmail.com>
6
23
  * @HomePage: https://koatty.org/
7
24
  */
8
- import { LoadConfigs as t } from "koatty_config";
9
-
10
- export { Config } from "koatty_config";
11
-
12
- import { IOC as e, TAGGED_CLS as o } from "koatty_container";
13
-
14
- export * from "koatty_container";
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 f, implementsAspectInterface as p, Koatty as g } from "koatty_core";
17
-
18
- export * from "koatty_core";
19
-
20
- export * from "koatty_exception";
21
-
22
- import { Helper as m } from "koatty_lib";
23
-
24
- export { Helper } from "koatty_lib";
25
-
26
- export * from "koatty_router";
27
-
28
- export * from "koatty_serve";
29
-
30
- import { DefaultLogger as u } from "koatty_logger";
31
-
32
- export { Log, DefaultLogger as Logger } from "koatty_logger";
33
-
34
- import { Load as h } from "koatty_loader";
35
-
36
- import { Trace as y } from "koatty_trace";
37
-
38
- import * as L from "path";
39
-
40
- /*
41
- * @Description: framework helper
42
- * @Usage:
43
- * @Author: richen
44
- * @Date: 2023-12-09 21:56:32
45
- * @LastEditTime: 2025-01-14 16:14:10
46
- * @License: BSD (3-Clause)
47
- * @Copyright (c): <richenlin(at)gmail.com>
48
- */ const v = require("../../package.json");
49
-
50
- const {engines: w, version: C} = v;
51
-
52
- const E = C;
53
-
54
- const b = w.node.slice(1) || "12.0.0";
25
+ var __defProp = Object.defineProperty;
26
+ var __getOwnPropNames = Object.getOwnPropertyNames;
27
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
28
+ var __commonJS = (cb, mod) => function __require2() {
29
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30
+ };
55
31
 
56
- function P(t, e, o, a) {
57
- if (m.isClass(o) && o.name != t) throw Error(`The file(${e}) name should be always the same as class name.`);
58
- if (o["__esModule"]) if (o.name === void 0) {
59
- const a = Object.keys(o);
60
- if (a[0] != t && m.isClass(o[a[0]])) throw Error(`The file(${e}) name should be always the same as class name.`);
61
- } else if (o.name != t) throw Error(`The file(${e}) name should be always the same as class name.`);
62
- if (!a) return;
63
- if (a.has(t)) throw new Error(`A same class already exists. at \`${e}\`.`);
64
- a.add(t);
32
+ // package.json
33
+ var require_package = __commonJS({
34
+ "package.json"(exports$1, module) {
35
+ module.exports = {
36
+ name: "koatty",
37
+ version: "4.1.8",
38
+ description: "Koa + Typescript = koatty. Use Typescript's decorator implement auto injection.",
39
+ scripts: {
40
+ build: "pnpm run build:js && pnpm run build:dts && pnpm run build:doc && pnpm run build:cp",
41
+ "build:js": "tsup",
42
+ "build:dts": "bash scripts/build-dts.sh",
43
+ "build:doc": "api-documenter markdown --input temp --output docs/api",
44
+ "build:cp": "node scripts/copyFiles && node ../../scripts/postBuild.js",
45
+ clean: "rimraf dist temp docs/api",
46
+ lint: "eslint --ext .ts,.js ./src",
47
+ test: "pnpm run lint && jest --passWithNoTests",
48
+ "test:cov": "jest --collectCoverage --detectOpenHandles"
49
+ },
50
+ main: "./dist/index.js",
51
+ exports: {
52
+ ".": {
53
+ types: "./dist/index.d.ts",
54
+ import: "./dist/index.mjs",
55
+ require: "./dist/index.js"
56
+ }
57
+ },
58
+ keywords: [
59
+ "koatty",
60
+ "koa",
61
+ "typescript",
62
+ "framework",
63
+ "mvc",
64
+ "http",
65
+ "https",
66
+ "websocket",
67
+ "grpc",
68
+ "quic",
69
+ "http2",
70
+ "http3",
71
+ "di",
72
+ "aop",
73
+ "ioc",
74
+ "inversion of control",
75
+ "dependency injection",
76
+ "aspect-oriented programming",
77
+ "decorator",
78
+ "decorator pattern",
79
+ "decorator factory"
80
+ ],
81
+ directories: {
82
+ doc: "docs"
83
+ },
84
+ repository: {
85
+ type: "git",
86
+ url: "git+https://github.com/koatty/koatty.git"
87
+ },
88
+ engines: {
89
+ node: ">=18.0.0"
90
+ },
91
+ author: {
92
+ name: "richenlin",
93
+ email: "richenlin@gmail.com"
94
+ },
95
+ license: "BSD-3-Clause",
96
+ bugs: {
97
+ url: "https://github.com/koatty/koatty/issues"
98
+ },
99
+ homepage: "https://github.com/koatty/koatty",
100
+ maintainers: [
101
+ {
102
+ name: "richenlin",
103
+ email: "richenlin@gmail.com"
104
+ }
105
+ ],
106
+ devDependencies: {
107
+ "@grpc/grpc-js": "^1.12.2",
108
+ "@microsoft/api-documenter": "^7.26.x",
109
+ "@microsoft/api-extractor": "^7.52.x",
110
+ "@types/formidable": "^3.x.x",
111
+ "@types/jest": "^29.5.x",
112
+ "@types/koa": "^2.x.x",
113
+ "@types/koa-compose": "^3.x.x",
114
+ "@types/lodash": "^4.x.x",
115
+ "@types/node": "^22.x.x",
116
+ "@types/on-finished": "^2.x.x",
117
+ "@types/supertest": "^6.x.x",
118
+ "@types/ws": "^8.x.x",
119
+ "@typescript-eslint/eslint-plugin": "^8.x.x",
120
+ "@typescript-eslint/parser": "^8.x.x",
121
+ eslint: "^8.x.x",
122
+ "eslint-plugin-jest": "^28.x.x",
123
+ jest: "^29.x.x",
124
+ "jest-html-reporters": "^3.x.x",
125
+ koatty_validation: "workspace:*",
126
+ "reflect-metadata": "^0.2.2",
127
+ supertest: "^7.x.x",
128
+ "ts-jest": "^29.x.x",
129
+ tslib: "^2.x.x"
130
+ },
131
+ dependencies: {
132
+ koa: "^3.1.1",
133
+ koatty_config: "workspace:*",
134
+ koatty_container: "workspace:*",
135
+ koatty_core: "workspace:*",
136
+ koatty_exception: "workspace:*",
137
+ koatty_lib: "workspace:*",
138
+ koatty_loader: "workspace:*",
139
+ koatty_logger: "workspace:*",
140
+ koatty_router: "workspace:*",
141
+ koatty_serve: "workspace:*",
142
+ koatty_trace: "workspace:*",
143
+ "ts-morph": "^27.0.2"
144
+ },
145
+ types: "./dist/index.d.ts"
146
+ };
147
+ }
148
+ });
149
+ var pkg = require_package();
150
+ var { engines, version } = pkg;
151
+ var KOATTY_VERSION = version;
152
+ var ENGINES_VERSION = engines.node.slice(1) || "12.0.0";
153
+ function checkClass(fileName, xpath, target, exSet) {
154
+ if (Helper.isClass(target) && target.name != fileName) {
155
+ throw Error(`The file(${xpath}) name should be always the same as class name.`);
156
+ }
157
+ if (target["__esModule"]) {
158
+ if (target.name === void 0) {
159
+ const keys = Object.keys(target);
160
+ if (keys[0] != fileName && Helper.isClass(target[keys[0]])) {
161
+ throw Error(`The file(${xpath}) name should be always the same as class name.`);
162
+ }
163
+ } else if (target.name != fileName) {
164
+ throw Error(`The file(${xpath}) name should be always the same as class name.`);
165
+ }
166
+ }
167
+ if (!exSet) {
168
+ return;
169
+ }
170
+ if (exSet.has(fileName)) {
171
+ throw new Error(`A same class already exists. at \`${xpath}\`.`);
172
+ }
173
+ exSet.add(fileName);
65
174
  return;
66
175
  }
67
-
68
- function k() {
69
- let t = b;
70
- t = t.slice(0, t.lastIndexOf("."));
71
- let e = process.version;
72
- if (e[0] === "v") e = e.slice(1);
73
- e = e.slice(0, e.lastIndexOf("."));
74
- if (m.toNumber(t) > m.toNumber(e)) u.Fatal(`Koatty need node version > ${t}, current version is ${e}, please upgrade it.`);
176
+ __name(checkClass, "checkClass");
177
+ function checkRuntime() {
178
+ let nodeEngines = ENGINES_VERSION;
179
+ nodeEngines = nodeEngines.slice(0, nodeEngines.lastIndexOf("."));
180
+ let nodeVersion = process.version;
181
+ if (nodeVersion[0] === "v") {
182
+ nodeVersion = nodeVersion.slice(1);
183
+ }
184
+ nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf("."));
185
+ if (Helper.toNumber(nodeEngines) > Helper.toNumber(nodeVersion)) {
186
+ DefaultLogger.Fatal(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
187
+ }
75
188
  }
76
-
77
- const M = () => {
78
- let t = !1;
79
- const e = JSON.stringify(process.argv[1]);
80
- if (e.indexOf("jest") > -1) t = !0;
81
- return t;
82
- };
83
-
84
- /*
85
- * @Description: framework constants
86
- * @Usage:
87
- * @Author: richen
88
- * @Date: 2023-12-09 21:56:32
89
- * @LastEditTime: 2023-12-09 23:00:13
90
- * @License: BSD (3-Clause)
91
- * @Copyright (c): <richenlin(at)gmail.com>
92
- */ const O = "COMPONENT_SCAN";
93
-
94
- const _ = "CONFIGURATION_SCAN";
95
-
96
- const T = `\n\n┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬\n├┴┐│ │├─┤ │ │ └┬┘\n┴ ┴└─┘┴ ┴ ┴ ┴ ┴ \n-------------------------------------------\nhttps://github.com/koatty\n`
97
- /*
98
- * @Description: framework loader
99
- * @Usage:
100
- * @Author: richen
101
- * @Date: 2023-12-09 22:55:49
102
- * @LastEditTime: 2025-03-13 16:44:39
103
- * @License: BSD (3-Clause)
104
- * @Copyright (c): <richenlin(at)gmail.com>
105
- */;
106
-
107
- class Loader {
108
- constructor(t) {
109
- this.app = t;
189
+ __name(checkRuntime, "checkRuntime");
190
+ var checkUTRuntime = /* @__PURE__ */ __name(() => {
191
+ let isUTRuntime = false;
192
+ const argv = JSON.stringify(process.argv[1]);
193
+ if (argv.indexOf("jest") > -1) {
194
+ isUTRuntime = true;
195
+ }
196
+ return isUTRuntime;
197
+ }, "checkUTRuntime");
198
+
199
+ // src/core/Constants.ts
200
+ var COMPONENT_SCAN = "COMPONENT_SCAN";
201
+ var CONFIGURATION_SCAN = "CONFIGURATION_SCAN";
202
+ var LOGO = `
203
+
204
+ \u252C\u250C\u2500\u250C\u2500\u2510\u250C\u2500\u2510\u250C\u252C\u2510\u250C\u252C\u2510\u252C \u252C
205
+ \u251C\u2534\u2510\u2502 \u2502\u251C\u2500\u2524 \u2502 \u2502 \u2514\u252C\u2518
206
+ \u2534 \u2534\u2514\u2500\u2518\u2534 \u2534 \u2534 \u2534 \u2534
207
+ -------------------------------------------
208
+ https://github.com/koatty
209
+ `;
210
+ var Loader = class _Loader {
211
+ static {
212
+ __name(this, "Loader");
110
213
  }
111
- static initialize(t) {
112
- if (t.env == "development") u.setLevel("debug"); else u.setLevel("info");
113
- const e = t.rootPath || process.cwd();
114
- const o = t.appPath || L.resolve(e, t.appDebug ? "src" : "dist");
115
- const a = L.resolve(__dirname, "..");
116
- m.define(t, "rootPath", e);
117
- m.define(t, "appPath", o);
118
- m.define(t, "koattyPath", a);
119
- if (m.isEmpty(t.name)) {
120
- const e = m.safeRequire(`${L.dirname(o)}/package.json`);
121
- if (e.name) {
122
- t.name = e.name;
123
- t.version = t.version || e.version;
214
+ app;
215
+ /**
216
+ * Creates an instance of Loader.
217
+ * @param {KoattyApplication} app
218
+ * @memberof Loader
219
+ */
220
+ constructor(app) {
221
+ this.app = app;
222
+ }
223
+ /**
224
+ * Initialize application configuration and environment settings.
225
+ * Sets up logging levels, defines essential paths, and loads application metadata.
226
+ *
227
+ * @param {KoattyApplication} app - The Koatty application instance
228
+ * - Sets logging level based on environment
229
+ * - Defines root, app and framework paths on app object
230
+ * - Loads application name and version from package.json
231
+ * - Sets environment variables for paths
232
+ * - Maintains backward compatibility with legacy path variables
233
+ */
234
+ static initialize(app) {
235
+ if (app.env == "development") {
236
+ DefaultLogger.setLevel("debug");
237
+ } else {
238
+ DefaultLogger.setLevel("info");
239
+ }
240
+ const rootPath = app.rootPath || process.cwd();
241
+ const appPath = app.appPath || path.resolve(rootPath, app.appDebug ? "src" : "dist");
242
+ const koattyPath = path.resolve(__dirname, "..");
243
+ Helper.define(app, "rootPath", rootPath);
244
+ Helper.define(app, "appPath", appPath);
245
+ Helper.define(app, "koattyPath", koattyPath);
246
+ if (Helper.isEmpty(app.name)) {
247
+ const pkg2 = Helper.safeRequire(`${path.dirname(appPath)}/package.json`);
248
+ if (pkg2.name) {
249
+ app.name = pkg2.name;
250
+ app.version = app.version || pkg2.version;
124
251
  }
125
252
  }
126
- process.env.ROOT_PATH = e;
127
- process.env.APP_PATH = o;
128
- process.env.KOATTY_PATH = a;
129
- process.env.THINK_PATH = a;
130
- m.define(t, "thinkPath", a);
253
+ process.env.ROOT_PATH = rootPath;
254
+ process.env.APP_PATH = appPath;
255
+ process.env.KOATTY_PATH = koattyPath;
256
+ process.env.THINK_PATH = koattyPath;
257
+ Helper.define(app, "thinkPath", koattyPath);
131
258
  }
132
- static GetComponentMeta(t, a) {
133
- let s = [];
134
- const n = e.getClassMetadata(o, O, a);
135
- if (n) if (m.isArray(n)) s = n; else s.push(n);
136
- if (s.length < 1) s = [ t.appPath ];
137
- return s;
259
+ /**
260
+ * Get component metadata from target class.
261
+ *
262
+ * @param {KoattyApplication} app - The Koatty application instance
263
+ * @param {any} target - The target class to get metadata from
264
+ * @returns {any[]} Array of component metadata paths
265
+ *
266
+ * @static
267
+ * @public
268
+ */
269
+ static GetComponentMeta(app, target) {
270
+ let componentMetas = [];
271
+ const componentMeta = IOC.getClassMetadata(TAGGED_CLS, COMPONENT_SCAN, target);
272
+ if (componentMeta) {
273
+ if (Helper.isArray(componentMeta)) {
274
+ componentMetas = componentMeta;
275
+ } else {
276
+ componentMetas.push(componentMeta);
277
+ }
278
+ }
279
+ if (componentMetas.length < 1) {
280
+ componentMetas = [
281
+ app.appPath
282
+ ];
283
+ }
284
+ return componentMetas;
138
285
  }
139
- static GetConfigurationMeta(t, a) {
140
- const s = e.getClassMetadata(o, _, a);
141
- let n = [];
142
- if (s) if (m.isArray(s)) n = s; else n.push(s);
143
- return n;
286
+ /**
287
+ * Get configuration metadata from target class.
288
+ *
289
+ * @param {KoattyApplication} app Application instance
290
+ * @param {any} target Target class
291
+ * @returns {any[]} Array of configuration metadata
292
+ */
293
+ static GetConfigurationMeta(app, target) {
294
+ const confMeta = IOC.getClassMetadata(TAGGED_CLS, CONFIGURATION_SCAN, target);
295
+ let configurationMetas = [];
296
+ if (confMeta) {
297
+ if (Helper.isArray(confMeta)) {
298
+ configurationMetas = confMeta;
299
+ } else {
300
+ configurationMetas.push(confMeta);
301
+ }
302
+ }
303
+ return configurationMetas;
144
304
  }
145
- static CheckAllComponents(t, e) {
146
- const o = Loader.GetComponentMeta(t, e);
147
- const a = Loader.GetConfigurationMeta(t, e);
148
- const s = new Set;
149
- h(o, "", (t, e, o) => {
150
- P(t, e, o, s);
151
- }, [ "**/**.js", "**/**.ts", "!**/**.d.ts" ], [ ...a, `${e.name || ".no"}.ts` ]);
152
- s.clear();
305
+ /**
306
+ * Check and load all components(excepted config/*、App.ts) in the application.
307
+ *
308
+ * @param {KoattyApplication} app - The Koatty application instance
309
+ * @param {any} target - The target class or object to check components from
310
+ * @static
311
+ * @public
312
+ */
313
+ static CheckAllComponents(app, target) {
314
+ const componentMetas = _Loader.GetComponentMeta(app, target);
315
+ const configurationMetas = _Loader.GetConfigurationMeta(app, target);
316
+ const exSet = /* @__PURE__ */ new Set();
317
+ Load(componentMetas, "", (fileName, xpath, xTarget) => {
318
+ checkClass(fileName, xpath, xTarget, exSet);
319
+ }, [
320
+ "**/**.js",
321
+ "**/**.ts",
322
+ "!**/**.d.ts"
323
+ ], [
324
+ ...configurationMetas,
325
+ `${target.name || ".no"}.ts`
326
+ ]);
327
+ exSet.clear();
153
328
  }
154
- static SetLogger(t) {
155
- const e = t.getMetaData("_configs") || [];
156
- const o = e[0] || {};
157
- if (o.config) {
158
- const e = o.config;
159
- let s = "debug", n = "", i = [];
160
- if (t.env === "production") s = "info";
161
- if (e.logsLevel) s = e.logsLevel.toLowerCase();
162
- if (e.logsPath) n = e.logsPath;
163
- if (e.sensFields) i = e.sensFields;
164
- if (!t.appDebug) {
165
- u.enableBatch(!0);
166
- u.setBatchConfig({
329
+ /**
330
+ * Set logger configuration for the Koatty application.
331
+ *
332
+ * @param {KoattyApplication} app - The Koatty application instance
333
+ * @description Configures logging settings based on application environment and config options.
334
+ * Handles log level, log file path, and sensitive fields configuration.
335
+ * In production environment, default log level is 'info', otherwise 'debug'.
336
+ */
337
+ static SetLogger(app) {
338
+ const data = app.getMetaData("_configs") || [];
339
+ const configs = data[0] || {};
340
+ if (configs.config) {
341
+ const opt = configs.config;
342
+ let logLevel = "debug", logFilePath = "", sensFields = [];
343
+ if (app.env === "production") {
344
+ logLevel = "info";
345
+ }
346
+ if (opt.logsLevel) {
347
+ logLevel = opt.logsLevel.toLowerCase();
348
+ }
349
+ if (opt.logsPath) {
350
+ logFilePath = opt.logsPath;
351
+ }
352
+ if (opt.sensFields) {
353
+ sensFields = opt.sensFields;
354
+ }
355
+ if (!app.appDebug) {
356
+ DefaultLogger.enableBatch(true);
357
+ DefaultLogger.setBatchConfig({
167
358
  maxSize: 200,
168
359
  flushInterval: 500
169
360
  });
170
361
  }
171
- if (s) u.setLevel(s);
172
- if (n && !t.silent) {
173
- m.define(t, "logsPath", n);
174
- process.env.LOGS_PATH = n;
175
- u.setLogFilePath(n);
362
+ if (logLevel) {
363
+ DefaultLogger.setLevel(logLevel);
176
364
  }
177
- if (i) u.setSensFields(i);
178
- t.once(a.appStop, async () => {
179
- await u.flushBatch();
180
- await u.destroy();
365
+ if (logFilePath && !app.silent) {
366
+ Helper.define(app, "logsPath", logFilePath);
367
+ process.env.LOGS_PATH = logFilePath;
368
+ DefaultLogger.setLogFilePath(logFilePath);
369
+ }
370
+ if (sensFields) {
371
+ DefaultLogger.setSensFields(sensFields);
372
+ }
373
+ app.once(AppEvent.appStop, async () => {
374
+ await DefaultLogger.flushBatch();
375
+ await DefaultLogger.destroy();
181
376
  });
182
377
  }
183
378
  }
184
- static async LoadAllComponents(t, o) {
379
+ /**
380
+ * Load all components and initialize the application.
381
+ *
382
+ * @param app - The KoattyApplication instance
383
+ * @param target - The target class or object containing configuration metadata
384
+ *
385
+ * This method performs the following initialization steps:
386
+ * 1. Loads configurations
387
+ * 2. Creates server and router instances
388
+ * 3. Loads components, middlewares, services and controllers
389
+ * 4. Sets up routing
390
+ *
391
+ * @static
392
+ * @async
393
+ */
394
+ static async LoadAllComponents(app, target) {
185
395
  try {
186
- if (m.isFunction(e.preloadMetadata)) e.preloadMetadata();
396
+ if (Helper.isFunction(IOC.preloadMetadata)) {
397
+ IOC.preloadMetadata();
398
+ }
187
399
  } catch {
188
- u.Warn("[Loader] preloadMetadata is optional, ignore if not available");
400
+ DefaultLogger.Warn("[Loader] preloadMetadata is optional, ignore if not available");
189
401
  }
190
- const r = Loader.GetConfigurationMeta(t, o);
191
- const l = new Loader(t);
192
- for (const e of s) switch (e) {
193
- case a.appBoot:
194
- u.Log("Koatty", "", "Load Configurations ...");
195
- l.LoadConfigs(r);
196
- Loader.SetLogger(t);
197
- await n(t, e);
198
- break;
199
-
200
- case a.loadConfigure:
201
- u.Log("Koatty", "", "Emit loadConfigure ...");
202
- await n(t, e);
203
- break;
204
-
205
- case a.loadComponent:
206
- u.Log("Koatty", "", "Initializing Component Manager ...");
207
- const s = new i(t);
208
- m.define(t, "componentManager", s);
209
- s.discoverComponents();
210
- const c = s.getStats();
211
- u.Log("Koatty", "", `Discovered ${c.coreComponents} core components, ${c.userComponents} user components`);
212
- u.Log("Koatty", "", "Load Components ...");
213
- await l.LoadComponents(s);
214
- s.registerAppEvents(o);
215
- s.registerCoreComponentHooks();
216
- await n(t, e);
217
- break;
218
-
219
- case a.loadPlugin:
220
- u.Log("Koatty", "", "Emit loadPlugin ...");
221
- await n(t, e);
222
- break;
223
-
224
- case a.loadMiddleware:
225
- u.Log("Koatty", "", "Load Middlewares ...");
226
- await l.LoadMiddlewares();
227
- await n(t, e);
228
- break;
229
-
230
- case a.loadService:
231
- u.Log("Koatty", "", "Load Services ...");
232
- await l.LoadServices();
233
- await n(t, e);
234
- break;
235
-
236
- case a.loadController:
237
- u.Log("Koatty", "", "Load Controllers ...");
238
- await l.LoadControllers();
239
- await n(t, e);
240
- break;
241
-
242
- case a.loadRouter:
243
- u.Log("Koatty", "", "Initialize Router and Load Routes ...");
244
- await n(t, e);
245
- break;
246
-
247
- case a.loadServe:
248
- u.Log("Koatty", "", "Emit loadServe ...");
249
- await n(t, e);
250
- break;
251
-
252
- case a.appReady:
253
- u.Log("Koatty", "", "Emit appReady ...");
254
- await n(t, e);
255
- break;
256
-
257
- default:
258
- await n(t, e);
259
- break;
402
+ const configurationMeta = _Loader.GetConfigurationMeta(app, target);
403
+ const loader = new _Loader(app);
404
+ for (const event of AppEventArr) {
405
+ switch (event) {
406
+ case AppEvent.appBoot:
407
+ DefaultLogger.Log("Koatty", "", "Load Configurations ...");
408
+ loader.LoadConfigs(configurationMeta);
409
+ _Loader.SetLogger(app);
410
+ await asyncEvent(app, event);
411
+ break;
412
+ case AppEvent.loadConfigure:
413
+ DefaultLogger.Log("Koatty", "", "Emit loadConfigure ...");
414
+ await asyncEvent(app, event);
415
+ break;
416
+ case AppEvent.loadComponent:
417
+ DefaultLogger.Log("Koatty", "", "Initializing Component Manager ...");
418
+ const componentManager = new ComponentManager(app);
419
+ Helper.define(app, "componentManager", componentManager);
420
+ componentManager.discoverComponents();
421
+ const stats = componentManager.getStats();
422
+ DefaultLogger.Log("Koatty", "", `Discovered ${stats.coreComponents} core components, ${stats.userComponents} user components`);
423
+ DefaultLogger.Log("Koatty", "", "Load Components ...");
424
+ await loader.LoadComponents(componentManager);
425
+ componentManager.registerAppEvents(target);
426
+ componentManager.registerCoreComponentHooks();
427
+ await asyncEvent(app, event);
428
+ break;
429
+ case AppEvent.loadPlugin:
430
+ DefaultLogger.Log("Koatty", "", "Emit loadPlugin ...");
431
+ await asyncEvent(app, event);
432
+ break;
433
+ case AppEvent.loadMiddleware:
434
+ DefaultLogger.Log("Koatty", "", "Load Middlewares ...");
435
+ await loader.LoadMiddlewares();
436
+ await asyncEvent(app, event);
437
+ break;
438
+ case AppEvent.loadService:
439
+ DefaultLogger.Log("Koatty", "", "Load Services ...");
440
+ await loader.LoadServices();
441
+ await asyncEvent(app, event);
442
+ break;
443
+ case AppEvent.loadController:
444
+ DefaultLogger.Log("Koatty", "", "Load Controllers ...");
445
+ await loader.LoadControllers();
446
+ await asyncEvent(app, event);
447
+ break;
448
+ case AppEvent.loadRouter:
449
+ DefaultLogger.Log("Koatty", "", "Initialize Router and Load Routes ...");
450
+ await asyncEvent(app, event);
451
+ break;
452
+ case AppEvent.loadServe:
453
+ DefaultLogger.Log("Koatty", "", "Emit loadServe ...");
454
+ await asyncEvent(app, event);
455
+ break;
456
+ case AppEvent.appReady:
457
+ DefaultLogger.Log("Koatty", "", "Emit appReady ...");
458
+ await asyncEvent(app, event);
459
+ break;
460
+ default:
461
+ await asyncEvent(app, event);
462
+ break;
463
+ }
260
464
  }
261
465
  }
262
- LoadConfigs(e) {
263
- const o = {};
264
- h([ "./config" ], this.app.koattyPath, function(t, e, a) {
265
- o[t] = a;
466
+ /**
467
+ * Load configuration files from specified paths.
468
+ * First loads framework configurations from './config' directory,
469
+ * then loads application configurations from custom paths.
470
+ * Finally merges both configurations with framework configs as lower priority.
471
+ *
472
+ * @protected
473
+ * @param {string[]} [loadPath] - Optional array of paths to load application configs from
474
+ */
475
+ LoadConfigs(loadPath) {
476
+ const frameConfig = {};
477
+ Load([
478
+ "./config"
479
+ ], this.app.koattyPath, function(name, path2, exp) {
480
+ frameConfig[name] = exp;
266
481
  });
267
- if (m.isArray(e)) e = e.length > 0 ? e : [ "./config" ];
268
- let a = t(e, this.app.appPath);
269
- a = m.extend(o, a, !0);
270
- this.app.setMetaData("_configs", a);
482
+ if (Helper.isArray(loadPath)) {
483
+ loadPath = loadPath.length > 0 ? loadPath : [
484
+ "./config"
485
+ ];
486
+ }
487
+ let appConfig = LoadConfigs(loadPath, this.app.appPath);
488
+ appConfig = Helper.extend(frameConfig, appConfig, true);
489
+ this.app.setMetaData("_configs", appConfig);
271
490
  }
491
+ /**
492
+ * Load and register middleware components.
493
+ * Processes middleware configuration, registers middleware classes with IOC container,
494
+ * and mounts middleware to the application.
495
+ * Supports protocol-specific middleware mounting via @Middleware({ protocol }) option.
496
+ *
497
+ * @protected
498
+ * @returns {Promise<void>}
499
+ * @throws {Error} When middleware doesn't implement IMiddleware interface
500
+ * @throws {Error} When middleware loading fails
501
+ */
272
502
  async LoadMiddlewares() {
273
- var t, o, a, s;
274
- let n = this.app.config(void 0, "middleware");
275
- if (m.isEmpty(n)) n = {
276
- config: {},
277
- list: []
278
- };
503
+ let middlewareConf = this.app.config(void 0, "middleware");
504
+ if (Helper.isEmpty(middlewareConf)) {
505
+ middlewareConf = {
506
+ config: {},
507
+ list: []
508
+ };
509
+ }
279
510
  try {
280
- const e = (o = (t = n.config) === null || t === void 0 ? void 0 : t.trace) !== null && o !== void 0 ? o : {};
281
- const a = y(e, this.app);
282
- m.define(this.app, "tracer", a);
283
- this.app.use(a);
284
- u.Debug(`Trace middleware registered`);
285
- } catch (t) {
286
- u.Warn(`Trace middleware failed to load: ${t.message}`);
511
+ const traceOptions = middlewareConf.config?.trace ?? {};
512
+ const tracer = Trace(traceOptions, this.app);
513
+ Helper.define(this.app, "tracer", tracer);
514
+ this.app.use(tracer);
515
+ DefaultLogger.Debug(`Trace middleware registered`);
516
+ } catch (error) {
517
+ DefaultLogger.Warn(`Trace middleware failed to load: ${error.message}`);
287
518
  }
288
- const i = (a = e.listClass("MIDDLEWARE")) !== null && a !== void 0 ? a : [];
289
- i.forEach(t => {
290
- var o;
291
- t.id = ((o = t.id) !== null && o !== void 0 ? o : "").replace("MIDDLEWARE:", "");
292
- if (t.id && m.isClass(t.target)) {
293
- e.reg(t.id, t.target, {
519
+ const appMiddleware = IOC.listClass("MIDDLEWARE") ?? [];
520
+ appMiddleware.forEach((item) => {
521
+ item.id = (item.id ?? "").replace("MIDDLEWARE:", "");
522
+ if (item.id && Helper.isClass(item.target)) {
523
+ IOC.reg(item.id, item.target, {
294
524
  scope: "Prototype",
295
525
  type: "MIDDLEWARE",
296
526
  args: []
297
527
  });
298
- const o = e.getInsByClass(t.target);
299
- if (!r(o)) throw Error(`The middleware ${t.id} must implements interface 'IMiddleware'.`);
528
+ const ctl = IOC.getInsByClass(item.target);
529
+ if (!implementsMiddlewareInterface(ctl)) {
530
+ throw Error(`The middleware ${item.id} must implements interface 'IMiddleware'.`);
531
+ }
300
532
  }
301
533
  });
302
- const d = n.list || [];
303
- const f = new Set([]);
304
- d.forEach(t => {
305
- f.add(t);
534
+ const middlewareList = middlewareConf.list || [];
535
+ const appMList = /* @__PURE__ */ new Set([]);
536
+ middlewareList.forEach((item) => {
537
+ appMList.add(item);
306
538
  });
307
- const p = n.config || {};
308
- for (const t of Array.from(f)) {
309
- const o = e.get(t, "MIDDLEWARE");
310
- if (!o) throw Error(`Middleware ${t} load error.`);
311
- if (!m.isFunction(o.run)) throw Error(`The middleware ${t} must implements interface 'IMiddleware'.`);
312
- u.Debug(`Load middleware: ${t}`);
313
- const a = p[t] || {};
314
- const n = (s = i.find(e => e.id === t)) === null || s === void 0 ? void 0 : s.target;
315
- let r = {};
316
- if (n) try {
317
- r = e.getPropertyData(l, n, t) || {};
318
- } catch {
319
- r = {};
539
+ const middlewareConfig = middlewareConf.config || {};
540
+ for (const key of Array.from(appMList)) {
541
+ const handle = IOC.get(key, "MIDDLEWARE");
542
+ if (!handle) {
543
+ throw Error(`Middleware ${key} load error.`);
544
+ }
545
+ if (!Helper.isFunction(handle.run)) {
546
+ throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
547
+ }
548
+ DefaultLogger.Debug(`Load middleware: ${key}`);
549
+ const middlewareOpt = middlewareConfig[key] || {};
550
+ const middlewareClass = appMiddleware.find((m) => m.id === key)?.target;
551
+ let decoratorOptions = {};
552
+ if (middlewareClass) {
553
+ try {
554
+ decoratorOptions = IOC.getPropertyData(MIDDLEWARE_OPTIONS, middlewareClass, key) || {};
555
+ } catch {
556
+ decoratorOptions = {};
557
+ }
320
558
  }
321
- const d = {
322
- ...r,
323
- ...a
559
+ const mergedOptions = {
560
+ ...decoratorOptions,
561
+ ...middlewareOpt
324
562
  };
325
- if (d.enabled === !1) {
326
- u.Warn(`The middleware ${t} has been loaded but is disabled.`);
563
+ if (mergedOptions.enabled === false) {
564
+ DefaultLogger.Warn(`The middleware ${key} has been loaded but is disabled.`);
327
565
  continue;
328
566
  }
329
- const f = await o.run(d, this.app);
330
- if (m.isFunction(f)) {
331
- let e = f;
332
- if (d.protocol) {
333
- const o = m.isArray(d.protocol) ? d.protocol : [ d.protocol ];
334
- u.Log("Koatty", "", `Middleware ${t} limited to protocols: ${o.join(", ")}`);
335
- e = c(o, f);
567
+ const result = await handle.run(mergedOptions, this.app);
568
+ if (Helper.isFunction(result)) {
569
+ let middleware = result;
570
+ if (mergedOptions.protocol) {
571
+ const protocols = Helper.isArray(mergedOptions.protocol) ? mergedOptions.protocol : [
572
+ mergedOptions.protocol
573
+ ];
574
+ DefaultLogger.Log("Koatty", "", `Middleware ${key} limited to protocols: ${protocols.join(", ")}`);
575
+ middleware = protocolMiddleware(protocols, result);
576
+ }
577
+ if (middleware.length < 3) {
578
+ this.app.use(middleware);
579
+ } else {
580
+ this.app.useExp(middleware);
336
581
  }
337
- if (e.length < 3) this.app.use(e); else this.app.useExp(e);
338
582
  }
339
583
  }
340
584
  }
585
+ /**
586
+ * Load and register controller classes from IOC container.
587
+ * Each controller must implement the IController interface.
588
+ *
589
+ * @returns {Promise<string[]>} A promise that resolves to an array of controller IDs.
590
+ * @protected
591
+ * @throws {Error} If a controller does not implement the IController interface.
592
+ */
341
593
  async LoadControllers() {
342
- const t = e.listClass("CONTROLLER");
343
- const o = [];
344
- t.forEach(t => {
345
- var a;
346
- t.id = ((a = t.id) !== null && a !== void 0 ? a : "").replace("CONTROLLER:", "");
347
- if (t.id && m.isClass(t.target)) {
348
- u.Debug(`Load controller: ${t.id}`);
349
- e.reg(t.id, t.target, {
594
+ const controllerList = IOC.listClass("CONTROLLER");
595
+ const controllers = [];
596
+ controllerList.forEach((item) => {
597
+ item.id = (item.id ?? "").replace("CONTROLLER:", "");
598
+ if (item.id && Helper.isClass(item.target)) {
599
+ DefaultLogger.Debug(`Load controller: ${item.id}`);
600
+ IOC.reg(item.id, item.target, {
350
601
  scope: "Prototype",
351
602
  type: "CONTROLLER",
352
603
  args: []
353
604
  });
354
- const a = e.getInsByClass(t.target);
355
- if (!d(a)) throw Error(`The controller ${t.id} must implements interface 'IController'.`);
356
- o.push(t.id);
605
+ const ctl = IOC.getInsByClass(item.target);
606
+ if (!implementsControllerInterface(ctl)) {
607
+ throw Error(`The controller ${item.id} must implements interface 'IController'.`);
608
+ }
609
+ controllers.push(item.id);
357
610
  }
358
611
  });
359
- this.app.setMetaData("_controllers", o);
360
- return o;
612
+ this.app.setMetaData("_controllers", controllers);
613
+ return controllers;
361
614
  }
615
+ /**
616
+ * Load and register service components into IOC container.
617
+ * Each service must implement the IService interface.
618
+ * Services are registered with singleton scope.
619
+ *
620
+ * @protected
621
+ * @returns {Promise<void>}
622
+ * @throws {Error} When service does not implement IService interface
623
+ */
362
624
  async LoadServices() {
363
- var t;
364
- const o = e.listClass("SERVICE");
365
- for (const a of o) {
366
- a.id = ((t = a.id) !== null && t !== void 0 ? t : "").replace("SERVICE:", "");
367
- if (a.id && m.isClass(a.target)) {
368
- u.Debug(`Load service: ${a.id}`);
369
- e.reg(a.id, a.target, {
625
+ const serviceList = IOC.listClass("SERVICE");
626
+ for (const item of serviceList) {
627
+ item.id = (item.id ?? "").replace("SERVICE:", "");
628
+ if (item.id && Helper.isClass(item.target)) {
629
+ DefaultLogger.Debug(`Load service: ${item.id}`);
630
+ IOC.reg(item.id, item.target, {
370
631
  scope: "Singleton",
371
632
  type: "SERVICE",
372
633
  args: []
373
634
  });
374
- const t = e.getInsByClass(a.target);
375
- if (!f(t)) throw Error(`The service ${a.id} must implements interface 'IService'.`);
635
+ const ctl = IOC.getInsByClass(item.target);
636
+ if (!implementsServiceInterface(ctl)) {
637
+ throw Error(`The service ${item.id} must implements interface 'IService'.`);
638
+ }
376
639
  }
377
640
  }
378
641
  }
379
- async LoadComponents(t) {
380
- var o, a;
381
- const s = e.listClass("COMPONENT");
382
- s.forEach(t => {
383
- var o;
384
- t.id = ((o = t.id) !== null && o !== void 0 ? o : "").replace("COMPONENT:", "");
385
- if (m.isClass(t.target)) {
386
- e.reg(t.id, t.target, {
642
+ /**
643
+ * Load and initialize components, plugins and aspects.
644
+ * Components with suffix 'Plugin' must implement IPlugin interface.
645
+ * Components with suffix 'Aspect' must implement IAspect interface.
646
+ * Plugins are loaded based on configuration and executed synchronously.
647
+ *
648
+ * @protected
649
+ * @returns {Promise<void>}
650
+ * @throws {Error} When plugin/aspect doesn't implement required interface
651
+ * @throws {Error} When plugin loading fails
652
+ */
653
+ async LoadComponents(componentManager) {
654
+ const componentList = IOC.listClass("COMPONENT");
655
+ componentList.forEach((item) => {
656
+ item.id = (item.id ?? "").replace("COMPONENT:", "");
657
+ if (Helper.isClass(item.target)) {
658
+ IOC.reg(item.id, item.target, {
387
659
  scope: "Singleton",
388
660
  type: "COMPONENT",
389
661
  args: []
390
662
  });
391
- if (t.id && t.id.endsWith("Aspect")) {
392
- const o = e.getInsByClass(t.target);
393
- if (!p(o)) throw Error(`The aspect ${t.id} must implements interface 'IAspect'.`);
663
+ if (item.id && item.id.endsWith("Aspect")) {
664
+ const ctl = IOC.getInsByClass(item.target);
665
+ if (!implementsAspectInterface(ctl)) {
666
+ throw Error(`The aspect ${item.id} must implements interface 'IAspect'.`);
667
+ }
394
668
  }
395
669
  }
396
670
  });
397
- if (t) await t.loadUserComponents(); else {
398
- u.Warn("Loading plugins in legacy mode");
399
- let t = this.app.config(void 0, "plugin");
400
- if (m.isEmpty(t)) t = {
401
- config: {},
402
- list: []
403
- };
404
- const s = (o = t.list) !== null && o !== void 0 ? o : [];
405
- for (const o of s) {
406
- const s = e.get(o, "COMPONENT");
407
- if (!s) throw Error(`Plugin ${o} load error.`);
408
- if (!m.isFunction(s.run)) throw Error(`Plugin ${o} must implements interface 'IPlugin'.`);
409
- if (t.config[o] === !1) {
410
- u.Warn(`Plugin ${o} already loaded but not effective.`);
671
+ if (componentManager) {
672
+ await componentManager.loadUserComponents();
673
+ } else {
674
+ DefaultLogger.Warn("Loading plugins in legacy mode");
675
+ let pluginsConf = this.app.config(void 0, "plugin");
676
+ if (Helper.isEmpty(pluginsConf)) {
677
+ pluginsConf = {
678
+ config: {},
679
+ list: []
680
+ };
681
+ }
682
+ const pluginConfList = pluginsConf.list ?? [];
683
+ for (const key of pluginConfList) {
684
+ const handle = IOC.get(key, "COMPONENT");
685
+ if (!handle) {
686
+ throw Error(`Plugin ${key} load error.`);
687
+ }
688
+ if (!Helper.isFunction(handle.run)) {
689
+ throw Error(`Plugin ${key} must implements interface 'IPlugin'.`);
690
+ }
691
+ if (pluginsConf.config[key] === false) {
692
+ DefaultLogger.Warn(`Plugin ${key} already loaded but not effective.`);
411
693
  continue;
412
694
  }
413
- await s.run((a = t.config[o]) !== null && a !== void 0 ? a : {}, this.app);
695
+ await handle.run(pluginsConf.config[key] ?? {}, this.app);
414
696
  }
415
697
  }
416
698
  }
417
- }
418
-
419
- /*
420
- * @Description: framework bootstrap
421
- * @Usage:
422
- * @Author: richen
423
- * @Date: 2021-12-09 21:56:32
424
- * @LastEditTime: 2025-01-14 16:11:21
425
- * @License: BSD (3-Clause)
426
- * @Copyright (c): <richenlin(at)gmail.com>
427
- */ function A(t) {
428
- return async e => {
429
- if (!(e.prototype instanceof g)) throw new Error(`class ${e.name} does not inherit from Koatty`);
430
- return await $(e, t, !0);
699
+ };
700
+ function ExecBootStrap(bootFunc) {
701
+ return async (target) => {
702
+ if (!(target.prototype instanceof Koatty)) {
703
+ throw new Error(`class ${target.name} does not inherit from Koatty`);
704
+ }
705
+ return await executeBootstrap(target, bootFunc, true);
431
706
  };
432
707
  }
433
-
434
- const $ = async function(t, o, a = !1) {
708
+ __name(ExecBootStrap, "ExecBootStrap");
709
+ var executeBootstrap = /* @__PURE__ */ __name(async function(target, bootFunc, isInitiative = false) {
435
710
  if (process.env.NODE_DEBUG) {
436
- const t = process.env.NODE_DEBUG.split(",").filter(t => !t.includes("winston")).join(",");
437
- process.env.NODE_DEBUG = t;
711
+ const debugModules = process.env.NODE_DEBUG.split(",").filter((m) => !m.includes("winston")).join(",");
712
+ process.env.NODE_DEBUG = debugModules;
713
+ }
714
+ checkRuntime();
715
+ const isUTRuntime = checkUTRuntime();
716
+ if (!isInitiative && isUTRuntime) {
717
+ return;
438
718
  }
439
- k();
440
- const s = M();
441
- if (!a && s) return;
442
- const n = Reflect.construct(t, []);
443
- if (s) {
444
- n.silent = !0;
445
- u.enable(!1);
719
+ const app = Reflect.construct(target, []);
720
+ if (isUTRuntime) {
721
+ app.silent = true;
722
+ DefaultLogger.enable(false);
446
723
  }
447
724
  try {
448
- if (!n.silent) console.log(T);
449
- if (!(n instanceof g)) throw new Error(`class ${t.name} does not inherit from Koatty`);
450
- Loader.initialize(n);
451
- if (m.isFunction(o)) {
452
- u.Log("Koatty", "", "Execute bootFunc ...");
453
- await o(n);
725
+ if (!app.silent) console.log(LOGO);
726
+ if (!(app instanceof Koatty)) {
727
+ throw new Error(`class ${target.name} does not inherit from Koatty`);
454
728
  }
455
- e.setApp(n);
456
- u.Log("Koatty", "", "ComponentScan ...");
457
- Loader.CheckAllComponents(n, t);
458
- await Loader.LoadAllComponents(n, t);
459
- if (!s) n.listen(K);
460
- return n;
461
- } catch (t) {
462
- u.Fatal(t);
729
+ Loader.initialize(app);
730
+ if (Helper.isFunction(bootFunc)) {
731
+ DefaultLogger.Log("Koatty", "", "Execute bootFunc ...");
732
+ await bootFunc(app);
733
+ }
734
+ IOC.setApp(app);
735
+ DefaultLogger.Log("Koatty", "", "ComponentScan ...");
736
+ Loader.CheckAllComponents(app, target);
737
+ await Loader.LoadAllComponents(app, target);
738
+ if (!isUTRuntime) {
739
+ app.listen(listenCallback);
740
+ }
741
+ return app;
742
+ } catch (err) {
743
+ DefaultLogger.Fatal(err);
463
744
  }
464
- };
465
-
466
- const K = t => {
467
- u.Log("Koatty", "", "====================================");
468
- u.Log("Koatty", "", `Nodejs Version: ${process.version}`);
469
- u.Log("Koatty", "", `Koatty Version: v${E}`);
470
- u.Log("Koatty", "", `App Environment: ${t.env}`);
471
- if (t.appDebug) u.Warn(`Running in debug mode.`);
472
- u.Log("Koatty", "", "====================================");
473
- n(t, a.appStart);
474
- };
475
-
476
- function D(t) {
477
- return function(o) {
478
- if (!(o.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
479
- e.saveClass("COMPONENT", o, "KOATTY_APP");
480
- A(t)(o);
481
- return o;
745
+ }, "executeBootstrap");
746
+ var listenCallback = /* @__PURE__ */ __name((app) => {
747
+ DefaultLogger.Log("Koatty", "", "====================================");
748
+ DefaultLogger.Log("Koatty", "", `Nodejs Version: ${process.version}`);
749
+ DefaultLogger.Log("Koatty", "", `Koatty Version: v${KOATTY_VERSION}`);
750
+ DefaultLogger.Log("Koatty", "", `App Environment: ${app.env}`);
751
+ if (app.appDebug) DefaultLogger.Warn(`Running in debug mode.`);
752
+ DefaultLogger.Log("Koatty", "", "====================================");
753
+ asyncEvent(app, AppEvent.appStart);
754
+ }, "listenCallback");
755
+ function Bootstrap(bootFunc) {
756
+ return function(target) {
757
+ if (!(target.prototype instanceof Koatty)) {
758
+ throw new Error(`class does not inherit from Koatty`);
759
+ }
760
+ IOC.saveClass("COMPONENT", target, "KOATTY_APP");
761
+ ExecBootStrap(bootFunc)(target);
762
+ return target;
482
763
  };
483
764
  }
484
-
485
- function N(t) {
486
- return a => {
487
- if (!(a.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
488
- t = t !== null && t !== void 0 ? t : "";
489
- e.saveClassMetadata(o, O, t, a);
765
+ __name(Bootstrap, "Bootstrap");
766
+ function ComponentScan(scanPath) {
767
+ return (target) => {
768
+ if (!(target.prototype instanceof Koatty)) {
769
+ throw new Error(`class does not inherit from Koatty`);
770
+ }
771
+ scanPath = scanPath ?? "";
772
+ IOC.saveClassMetadata(TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
490
773
  };
491
774
  }
492
-
493
- function S(t) {
494
- return a => {
495
- if (!(a.prototype instanceof g)) throw new Error(`class does not inherit from Koatty`);
496
- t = t !== null && t !== void 0 ? t : "";
497
- e.saveClassMetadata(o, _, t, a);
775
+ __name(ComponentScan, "ComponentScan");
776
+ function ConfigurationScan(scanPath) {
777
+ return (target) => {
778
+ if (!(target.prototype instanceof Koatty)) {
779
+ throw new Error(`class does not inherit from Koatty`);
780
+ }
781
+ scanPath = scanPath ?? "";
782
+ IOC.saveClassMetadata(TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
498
783
  };
499
784
  }
500
-
501
- export { D as Bootstrap, N as ComponentScan, S as ConfigurationScan, A as ExecBootStrap };
785
+ __name(ConfigurationScan, "ConfigurationScan");
786
+ /**
787
+ * Decorator for Koatty framework
788
+ * @author richen
789
+ * @copyright Copyright (c) - <richenlin(at)gmail.com>
790
+ * @license BSD (3-Clause)
791
+ * @version 2026-02-03 10:00:00
792
+ */
793
+
794
+ export { Bootstrap, ComponentScan, ConfigurationScan, ExecBootStrap };
795
+ //# sourceMappingURL=index.mjs.map
796
+ //# sourceMappingURL=index.mjs.map