koatty 4.3.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +331 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +340 -43
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +21 -14
- package/package.json +20 -13
- package/.rollup.config.js +0 -89
- package/.turbo/turbo-build.log +0 -99
- package/.turbo/turbo-clean.log +0 -4
- package/.turbo/turbo-lint.log +0 -18
- package/.turbo/turbo-test.log +0 -114
- package/TASKS.md +0 -1227
- package/examples/README.md +0 -172
- package/examples/basic-app/README.md +0 -72
- package/examples/basic-app/package.json +0 -23
- package/examples/basic-app/pnpm-workspace.yaml +0 -4
- package/examples/basic-app/resource/data.json +0 -2
- package/examples/basic-app/resource/graphql/User.graphql +0 -22
- package/examples/basic-app/resource/proto/.gitkeep +0 -0
- package/examples/basic-app/resource/proto/hello.proto +0 -19
- package/examples/basic-app/static/.gitkeep +0 -0
- package/examples/basic-app/static/favicon.ico +0 -0
- package/examples/basic-app/test-app.js +0 -28
- package/examples/basic-app/test-logger.js +0 -19
- package/examples/basic-app/test-simple.ts +0 -13
- package/examples/basic-app/view/index.html +0 -25
- package/tsconfig.test.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
- package/tsup.config.ts +0 -6
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var koatty_logger = require('koatty_logger');
|
|
|
11
11
|
var koatty_loader = require('koatty_loader');
|
|
12
12
|
var koatty_trace = require('koatty_trace');
|
|
13
13
|
var path = require('path');
|
|
14
|
+
var fs = require('fs');
|
|
14
15
|
|
|
15
16
|
function _interopNamespace(e) {
|
|
16
17
|
if (e && e.__esModule) return e;
|
|
@@ -31,10 +32,11 @@ function _interopNamespace(e) {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
35
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
34
36
|
|
|
35
37
|
/*!
|
|
36
38
|
* @Author: richen
|
|
37
|
-
* @Date: 2026-09-
|
|
39
|
+
* @Date: 2026-09-30 05:09:10
|
|
38
40
|
* @License: BSD (3-Clause)
|
|
39
41
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
40
42
|
* @HomePage: https://koatty.org/
|
|
@@ -51,7 +53,7 @@ var require_package = __commonJS({
|
|
|
51
53
|
"package.json"(exports$1, module) {
|
|
52
54
|
module.exports = {
|
|
53
55
|
name: "koatty",
|
|
54
|
-
version: "
|
|
56
|
+
version: "5.0.0",
|
|
55
57
|
description: "Koa + Typescript = koatty. Use Typescript's decorator implement auto injection.",
|
|
56
58
|
scripts: {
|
|
57
59
|
build: "pnpm run build:js && pnpm run build:dts && pnpm run build:doc && pnpm run build:cp",
|
|
@@ -62,7 +64,8 @@ var require_package = __commonJS({
|
|
|
62
64
|
clean: "rimraf dist temp docs/api",
|
|
63
65
|
lint: "eslint --ext .ts,.js ./src",
|
|
64
66
|
test: "pnpm run lint && jest --passWithNoTests",
|
|
65
|
-
"test:cov": "jest --collectCoverage --detectOpenHandles"
|
|
67
|
+
"test:cov": "jest --collectCoverage --detectOpenHandles",
|
|
68
|
+
"test:example": "jest --config examples/mcp-order-service/jest.config.js --coverage=false"
|
|
66
69
|
},
|
|
67
70
|
main: "./dist/index.js",
|
|
68
71
|
exports: {
|
|
@@ -159,7 +162,13 @@ var require_package = __commonJS({
|
|
|
159
162
|
koatty_trace: "workspace:*",
|
|
160
163
|
"ts-morph": "^27.0.2"
|
|
161
164
|
},
|
|
162
|
-
types: "./dist/index.d.ts"
|
|
165
|
+
types: "./dist/index.d.ts",
|
|
166
|
+
files: [
|
|
167
|
+
"dist",
|
|
168
|
+
"README.md",
|
|
169
|
+
"CHANGELOG.md",
|
|
170
|
+
"LICENSE"
|
|
171
|
+
]
|
|
163
172
|
};
|
|
164
173
|
}
|
|
165
174
|
});
|
|
@@ -206,7 +215,7 @@ function checkRuntime() {
|
|
|
206
215
|
__name(checkRuntime, "checkRuntime");
|
|
207
216
|
var checkUTRuntime = /* @__PURE__ */ __name(() => {
|
|
208
217
|
let isUTRuntime = false;
|
|
209
|
-
const argv =
|
|
218
|
+
const argv = String(process.argv[1] ?? "");
|
|
210
219
|
if (argv.indexOf("jest") > -1) {
|
|
211
220
|
isUTRuntime = true;
|
|
212
221
|
}
|
|
@@ -224,11 +233,264 @@ var LOGO = `
|
|
|
224
233
|
-------------------------------------------
|
|
225
234
|
https://github.com/koatty
|
|
226
235
|
`;
|
|
236
|
+
|
|
237
|
+
// src/config/config.ts
|
|
238
|
+
var config_default = {
|
|
239
|
+
/*app config*/
|
|
240
|
+
logsLevel: "debug"
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/config/middleware.ts
|
|
244
|
+
var middleware_default = {
|
|
245
|
+
// List of loaded middleware(except for the middleware loaded by default),
|
|
246
|
+
// executed in the order of elements
|
|
247
|
+
list: [],
|
|
248
|
+
// middleware configuration
|
|
249
|
+
config: {
|
|
250
|
+
// ============================================
|
|
251
|
+
// Trace Middleware - 请求链路追踪中间件
|
|
252
|
+
// ============================================
|
|
253
|
+
// Koatty-Trace 用于追踪请求链路、记录日志、收集指标
|
|
254
|
+
// 它会自动作为第一个中间件加载,无需添加到 list 中
|
|
255
|
+
trace: {
|
|
256
|
+
// response timeout in milliseconds
|
|
257
|
+
timeout: 1e4,
|
|
258
|
+
// request id header name
|
|
259
|
+
requestIdHeaderName: "X-Request-Id",
|
|
260
|
+
// request id name
|
|
261
|
+
requestIdName: "requestId",
|
|
262
|
+
// id generator function
|
|
263
|
+
// idFactory: Function,
|
|
264
|
+
// encoding
|
|
265
|
+
encoding: "utf-8",
|
|
266
|
+
// Whether to enable trace (default: false)
|
|
267
|
+
enableTrace: false,
|
|
268
|
+
// asynchooks enabled
|
|
269
|
+
asyncHooks: false,
|
|
270
|
+
/**
|
|
271
|
+
* Metrics configuration
|
|
272
|
+
*/
|
|
273
|
+
metricsConf: {
|
|
274
|
+
/**
|
|
275
|
+
* Metrics reporter function
|
|
276
|
+
*/
|
|
277
|
+
// reporter: (metrics: {
|
|
278
|
+
// duration: number,
|
|
279
|
+
// status: number,
|
|
280
|
+
// path: string,
|
|
281
|
+
// attributes: Record<string, any>,
|
|
282
|
+
// }) => void,
|
|
283
|
+
/**
|
|
284
|
+
* Default attributes for metrics
|
|
285
|
+
*/
|
|
286
|
+
defaultAttributes: {},
|
|
287
|
+
/**
|
|
288
|
+
* Prometheus metrics endpoint (production only)
|
|
289
|
+
*/
|
|
290
|
+
metricsEndpoint: "/metrics",
|
|
291
|
+
/**
|
|
292
|
+
* Metrics report interval in milliseconds (default: 5000)
|
|
293
|
+
*/
|
|
294
|
+
reportInterval: 5e3,
|
|
295
|
+
/**
|
|
296
|
+
* Prometheus metrics port (default: 9464)
|
|
297
|
+
*/
|
|
298
|
+
metricsPort: 9464
|
|
299
|
+
},
|
|
300
|
+
/**
|
|
301
|
+
* OpenTelemetry configuration
|
|
302
|
+
*/
|
|
303
|
+
opentelemetryConf: {
|
|
304
|
+
/**
|
|
305
|
+
* OTLP endpoint URL
|
|
306
|
+
*/
|
|
307
|
+
endpoint: "http://localhost:4318/v1/traces",
|
|
308
|
+
/**
|
|
309
|
+
* Whether to enable topology analysis (default: same as enableTrace)
|
|
310
|
+
*
|
|
311
|
+
*/
|
|
312
|
+
enableTopology: false,
|
|
313
|
+
/**
|
|
314
|
+
* OTLP headers
|
|
315
|
+
*/
|
|
316
|
+
headers: {},
|
|
317
|
+
/**
|
|
318
|
+
* Resource attributes
|
|
319
|
+
*/
|
|
320
|
+
resourceAttributes: {},
|
|
321
|
+
/**
|
|
322
|
+
* Instrumentations to enable
|
|
323
|
+
*/
|
|
324
|
+
instrumentations: [],
|
|
325
|
+
/**
|
|
326
|
+
* Exporter timeout in milliseconds
|
|
327
|
+
*/
|
|
328
|
+
timeout: 1e4,
|
|
329
|
+
/**
|
|
330
|
+
* Maximum lifetime for a span in milliseconds
|
|
331
|
+
*/
|
|
332
|
+
spanTimeout: 3e4,
|
|
333
|
+
/**
|
|
334
|
+
* Maximum number of active spans in memory (default: 1000)
|
|
335
|
+
*/
|
|
336
|
+
maxActiveSpans: 1e3,
|
|
337
|
+
/**
|
|
338
|
+
* Request attributes to be added to the span
|
|
339
|
+
*/
|
|
340
|
+
// spanAttributes: (ctx: KoattyContext) => Record<string, any>,
|
|
341
|
+
/**
|
|
342
|
+
* Sampling rate (0.0 - 1.0)
|
|
343
|
+
*/
|
|
344
|
+
samplingRate: 1,
|
|
345
|
+
/**
|
|
346
|
+
* Maximum number of spans in batch queue
|
|
347
|
+
*/
|
|
348
|
+
batchMaxQueueSize: 2048,
|
|
349
|
+
/**
|
|
350
|
+
* Maximum number of spans to export in one batch
|
|
351
|
+
*/
|
|
352
|
+
batchMaxExportSize: 512,
|
|
353
|
+
/**
|
|
354
|
+
* Delay between batch exports in milliseconds
|
|
355
|
+
*/
|
|
356
|
+
batchDelayMillis: 5e3,
|
|
357
|
+
/**
|
|
358
|
+
* Timeout for batch export in milliseconds
|
|
359
|
+
*/
|
|
360
|
+
batchExportTimeout: 3e4
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Retry configuration
|
|
364
|
+
*/
|
|
365
|
+
retryConf: {
|
|
366
|
+
/**
|
|
367
|
+
* Whether to enable retry mechanism (default: false)
|
|
368
|
+
*/
|
|
369
|
+
enabled: false,
|
|
370
|
+
/**
|
|
371
|
+
* Max retry count when error occurs (default: 3)
|
|
372
|
+
*/
|
|
373
|
+
count: 3,
|
|
374
|
+
/**
|
|
375
|
+
* Retry interval in milliseconds (default: 1000)
|
|
376
|
+
*/
|
|
377
|
+
interval: 1e3
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/config/plugin.ts
|
|
384
|
+
var plugin_default = {
|
|
385
|
+
// ============================================================
|
|
386
|
+
// User plugin loading list (executed in order)
|
|
387
|
+
// Note: Core components (@Component) are loaded automatically
|
|
388
|
+
// ============================================================
|
|
389
|
+
list: [],
|
|
390
|
+
// ============================================================
|
|
391
|
+
// Component/Plugin configuration
|
|
392
|
+
// ============================================================
|
|
393
|
+
config: {
|
|
394
|
+
// --- Core components (@Component) ---
|
|
395
|
+
// Framework built-in components, usually do not need to modify
|
|
396
|
+
// Can be disabled by setting enabled: false
|
|
397
|
+
RouterComponent: {
|
|
398
|
+
enabled: true
|
|
399
|
+
},
|
|
400
|
+
ServeComponent: {
|
|
401
|
+
enabled: true
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/config/router.ts
|
|
407
|
+
var router_default = {
|
|
408
|
+
/**
|
|
409
|
+
* prefix of the router
|
|
410
|
+
*/
|
|
411
|
+
// prefix: string,
|
|
412
|
+
/**
|
|
413
|
+
* Methods which should be supported by the router.
|
|
414
|
+
*/
|
|
415
|
+
// methods?: string[];
|
|
416
|
+
// routerPath?: string;
|
|
417
|
+
/**
|
|
418
|
+
* Whether or not routing should be case-sensitive.
|
|
419
|
+
*/
|
|
420
|
+
// sensitive?: boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Whether or not routes should matched strictly.
|
|
423
|
+
*
|
|
424
|
+
* If strict matching is enabled, the trailing slash is taken into
|
|
425
|
+
* account when matching routes.
|
|
426
|
+
*/
|
|
427
|
+
// strict?: boolean;
|
|
428
|
+
/**
|
|
429
|
+
* payload options
|
|
430
|
+
*
|
|
431
|
+
*/
|
|
432
|
+
payload: {
|
|
433
|
+
extTypes: {
|
|
434
|
+
json: [
|
|
435
|
+
"application/json"
|
|
436
|
+
],
|
|
437
|
+
form: [
|
|
438
|
+
"application/x-www-form-urlencoded"
|
|
439
|
+
],
|
|
440
|
+
text: [
|
|
441
|
+
"text/plain"
|
|
442
|
+
],
|
|
443
|
+
multipart: [
|
|
444
|
+
"multipart/form-data"
|
|
445
|
+
],
|
|
446
|
+
xml: [
|
|
447
|
+
"text/xml"
|
|
448
|
+
],
|
|
449
|
+
grpc: [
|
|
450
|
+
"application/grpc"
|
|
451
|
+
],
|
|
452
|
+
graphql: [
|
|
453
|
+
"application/graphql+json"
|
|
454
|
+
],
|
|
455
|
+
websocket: [
|
|
456
|
+
"application/websocket"
|
|
457
|
+
]
|
|
458
|
+
},
|
|
459
|
+
// body-size limit intentionally unset (ADR-102): the security profile
|
|
460
|
+
// decides (1mb in production, 20mb in development) unless the project
|
|
461
|
+
// config/router.ts sets payload.limit explicitly
|
|
462
|
+
encoding: "utf-8",
|
|
463
|
+
multiples: true
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/config/server.ts
|
|
468
|
+
var server_default = {
|
|
469
|
+
hostname: process.env.IP || "127.0.0.1",
|
|
470
|
+
// server port: single value (e.g. 3000) or array (e.g. [3000, 3001])
|
|
471
|
+
// For multi-protocol: if port is array, each port maps to corresponding protocol
|
|
472
|
+
// If port is single value, first protocol uses it, others auto-increment (3000, 3001, 3002...)
|
|
473
|
+
port: process.env.PORT || process.env.APP_PORT || 3e3,
|
|
474
|
+
// Server protocol: 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss' | 'graphql'
|
|
475
|
+
// For multi-protocol: use array like ["http", "grpc"] and configure ext below
|
|
476
|
+
protocol: "http",
|
|
477
|
+
trace: false,
|
|
478
|
+
ssl: {
|
|
479
|
+
mode: "auto",
|
|
480
|
+
key: "",
|
|
481
|
+
cert: "",
|
|
482
|
+
ca: ""
|
|
483
|
+
// ca file path
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// src/core/Loader.ts
|
|
227
488
|
var Loader = class _Loader {
|
|
228
489
|
static {
|
|
229
490
|
__name(this, "Loader");
|
|
230
491
|
}
|
|
231
492
|
app;
|
|
493
|
+
static loggingApps = /* @__PURE__ */ new Set();
|
|
232
494
|
/**
|
|
233
495
|
* Creates an instance of Loader.
|
|
234
496
|
* @param {KoattyApplication} app
|
|
@@ -267,6 +529,11 @@ var Loader = class _Loader {
|
|
|
267
529
|
app.version = app.version || pkg2.version;
|
|
268
530
|
}
|
|
269
531
|
}
|
|
532
|
+
koatty_lib.Helper.define(app, "paths", {
|
|
533
|
+
rootPath,
|
|
534
|
+
appPath,
|
|
535
|
+
koattyPath
|
|
536
|
+
});
|
|
270
537
|
process.env.ROOT_PATH = rootPath;
|
|
271
538
|
process.env.APP_PATH = appPath;
|
|
272
539
|
process.env.KOATTY_PATH = koattyPath;
|
|
@@ -331,16 +598,31 @@ var Loader = class _Loader {
|
|
|
331
598
|
const componentMetas = _Loader.GetComponentMeta(app, target);
|
|
332
599
|
const configurationMetas = _Loader.GetConfigurationMeta(app, target);
|
|
333
600
|
const exSet = /* @__PURE__ */ new Set();
|
|
334
|
-
|
|
601
|
+
const manifestFile = path__namespace.join(app.rootPath, ".koatty", "manifest.json");
|
|
602
|
+
koatty_loader.Load(componentMetas, app.rootPath, (fileName, xpath, xTarget) => {
|
|
335
603
|
checkClass(fileName, xpath, xTarget, exSet);
|
|
604
|
+
const exports$1 = typeof xTarget === "function" ? [
|
|
605
|
+
xTarget
|
|
606
|
+
] : Object.values(xTarget ?? {});
|
|
607
|
+
for (const component of exports$1) {
|
|
608
|
+
if (koatty_lib.Helper.isClass(component)) app.container.saveClass(koatty_container.IOC.getType(component), component, koatty_container.IOC.getIdentifier(component));
|
|
609
|
+
}
|
|
336
610
|
}, [
|
|
337
611
|
"**/**.js",
|
|
338
612
|
"**/**.ts",
|
|
339
613
|
"!**/**.d.ts"
|
|
340
614
|
], [
|
|
341
615
|
...configurationMetas,
|
|
342
|
-
`${target.name || ".no"}.ts
|
|
343
|
-
|
|
616
|
+
`${target.name || ".no"}.ts`,
|
|
617
|
+
`${target.name || ".no"}.js`
|
|
618
|
+
], {
|
|
619
|
+
manifestFile: app.env === "production" && fs__namespace.existsSync(manifestFile) ? manifestFile : void 0
|
|
620
|
+
});
|
|
621
|
+
for (const item of koatty_container.IOC.listClass("COMPONENT")) {
|
|
622
|
+
const id = koatty_container.IOC.getIdentifier(item.target);
|
|
623
|
+
const options = koatty_container.IOC.getPropertyData("COMPONENT_OPTIONS", item.target, id);
|
|
624
|
+
if (options?.scope === "core") app.container.saveClass("COMPONENT", item.target, id);
|
|
625
|
+
}
|
|
344
626
|
exSet.clear();
|
|
345
627
|
}
|
|
346
628
|
/**
|
|
@@ -355,6 +637,7 @@ var Loader = class _Loader {
|
|
|
355
637
|
const data = app.getMetaData("_configs") || [];
|
|
356
638
|
const configs = data[0] || {};
|
|
357
639
|
if (configs.config) {
|
|
640
|
+
_Loader.loggingApps.add(app);
|
|
358
641
|
const opt = configs.config;
|
|
359
642
|
let logLevel = "debug", logFilePath = "", sensFields = [];
|
|
360
643
|
if (app.env === "production") {
|
|
@@ -389,7 +672,8 @@ var Loader = class _Loader {
|
|
|
389
672
|
}
|
|
390
673
|
app.once(koatty_core.AppEvent.appStop, async () => {
|
|
391
674
|
await koatty_logger.DefaultLogger.flushBatch();
|
|
392
|
-
|
|
675
|
+
_Loader.loggingApps.delete(app);
|
|
676
|
+
if (_Loader.loggingApps.size === 0) koatty_logger.DefaultLogger.enableBatch(false);
|
|
393
677
|
});
|
|
394
678
|
}
|
|
395
679
|
}
|
|
@@ -410,8 +694,8 @@ var Loader = class _Loader {
|
|
|
410
694
|
*/
|
|
411
695
|
static async LoadAllComponents(app, target) {
|
|
412
696
|
try {
|
|
413
|
-
if (koatty_lib.Helper.isFunction(
|
|
414
|
-
|
|
697
|
+
if (koatty_lib.Helper.isFunction(app.container.preloadMetadata)) {
|
|
698
|
+
app.container.preloadMetadata();
|
|
415
699
|
}
|
|
416
700
|
} catch (error) {
|
|
417
701
|
koatty_logger.DefaultLogger.Error("[Loader] preloadMetadata failed:", error);
|
|
@@ -467,12 +751,15 @@ var Loader = class _Loader {
|
|
|
467
751
|
await koatty_core.asyncEvent(app, event);
|
|
468
752
|
break;
|
|
469
753
|
case koatty_core.AppEvent.loadServe:
|
|
754
|
+
await app.container?.ready?.();
|
|
470
755
|
koatty_logger.DefaultLogger.Log("Koatty", "", "Emit loadServe ...");
|
|
471
756
|
await koatty_core.asyncEvent(app, event);
|
|
472
757
|
break;
|
|
473
758
|
case koatty_core.AppEvent.appReady:
|
|
474
759
|
koatty_logger.DefaultLogger.Log("Koatty", "", "Emit appReady ...");
|
|
475
760
|
await koatty_core.asyncEvent(app, event);
|
|
761
|
+
await app.container?.ready?.();
|
|
762
|
+
app.container?.seal?.();
|
|
476
763
|
break;
|
|
477
764
|
default:
|
|
478
765
|
await koatty_core.asyncEvent(app, event);
|
|
@@ -490,18 +777,23 @@ var Loader = class _Loader {
|
|
|
490
777
|
* @param {string[]} [loadPath] - Optional array of paths to load application configs from
|
|
491
778
|
*/
|
|
492
779
|
LoadConfigs(loadPath) {
|
|
493
|
-
const frameConfig = {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
780
|
+
const frameConfig = koatty_lib.Helper.clone({
|
|
781
|
+
config: config_default,
|
|
782
|
+
middleware: middleware_default,
|
|
783
|
+
plugin: plugin_default,
|
|
784
|
+
router: router_default,
|
|
785
|
+
server: server_default
|
|
786
|
+
}, true);
|
|
499
787
|
if (koatty_lib.Helper.isArray(loadPath)) {
|
|
500
788
|
loadPath = loadPath.length > 0 ? loadPath : [
|
|
501
789
|
"./config"
|
|
502
790
|
];
|
|
503
791
|
}
|
|
504
|
-
|
|
792
|
+
const manifest = path__namespace.join(this.app.rootPath, ".koatty/manifest.json");
|
|
793
|
+
let appConfig = koatty_config.LoadConfigs(loadPath, this.app.appPath, void 0, void 0, void 0, this.app.env === "production" && fs__namespace.existsSync(manifest) ? {
|
|
794
|
+
manifestFile: manifest,
|
|
795
|
+
baseDir: this.app.rootPath
|
|
796
|
+
} : void 0);
|
|
505
797
|
appConfig = koatty_lib.Helper.extend(frameConfig, appConfig, true);
|
|
506
798
|
this.app.setMetaData("_configs", appConfig);
|
|
507
799
|
}
|
|
@@ -533,16 +825,16 @@ var Loader = class _Loader {
|
|
|
533
825
|
} catch (error) {
|
|
534
826
|
koatty_logger.DefaultLogger.Warn(`Trace middleware failed to load: ${error.message}`);
|
|
535
827
|
}
|
|
536
|
-
const appMiddleware =
|
|
828
|
+
const appMiddleware = this.app.container.listClass("MIDDLEWARE") ?? [];
|
|
537
829
|
appMiddleware.forEach((item) => {
|
|
538
830
|
item.id = (item.id ?? "").replace("MIDDLEWARE:", "");
|
|
539
831
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
|
540
|
-
|
|
832
|
+
this.app.container.reg(item.id, item.target, {
|
|
541
833
|
scope: "Prototype",
|
|
542
834
|
type: "MIDDLEWARE",
|
|
543
835
|
args: []
|
|
544
836
|
});
|
|
545
|
-
const ctl =
|
|
837
|
+
const ctl = this.app.container.getInsByClass(item.target);
|
|
546
838
|
if (!koatty_core.implementsMiddlewareInterface(ctl)) {
|
|
547
839
|
throw Error(`The middleware ${item.id} must implements interface 'IMiddleware'.`);
|
|
548
840
|
}
|
|
@@ -555,7 +847,7 @@ var Loader = class _Loader {
|
|
|
555
847
|
});
|
|
556
848
|
const middlewareConfig = middlewareConf.config || {};
|
|
557
849
|
for (const key of Array.from(appMList)) {
|
|
558
|
-
const handle =
|
|
850
|
+
const handle = this.app.container.get(key, "MIDDLEWARE");
|
|
559
851
|
if (!handle) {
|
|
560
852
|
throw Error(`Middleware ${key} load error.`);
|
|
561
853
|
}
|
|
@@ -568,7 +860,7 @@ var Loader = class _Loader {
|
|
|
568
860
|
let decoratorOptions = {};
|
|
569
861
|
if (middlewareClass) {
|
|
570
862
|
try {
|
|
571
|
-
decoratorOptions =
|
|
863
|
+
decoratorOptions = this.app.container.getPropertyData(koatty_core.MIDDLEWARE_OPTIONS, middlewareClass, key) || {};
|
|
572
864
|
} catch {
|
|
573
865
|
decoratorOptions = {};
|
|
574
866
|
}
|
|
@@ -608,21 +900,17 @@ var Loader = class _Loader {
|
|
|
608
900
|
* @throws {Error} If a controller does not implement the IController interface.
|
|
609
901
|
*/
|
|
610
902
|
async LoadControllers() {
|
|
611
|
-
const controllerList =
|
|
903
|
+
const controllerList = this.app.container.listClass("CONTROLLER");
|
|
612
904
|
const controllers = [];
|
|
613
905
|
controllerList.forEach((item) => {
|
|
614
906
|
item.id = (item.id ?? "").replace("CONTROLLER:", "");
|
|
615
907
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
|
616
908
|
koatty_logger.DefaultLogger.Debug(`Load controller: ${item.id}`);
|
|
617
|
-
|
|
909
|
+
this.app.container.reg(item.id, item.target, {
|
|
618
910
|
scope: "Prototype",
|
|
619
911
|
type: "CONTROLLER",
|
|
620
912
|
args: []
|
|
621
913
|
});
|
|
622
|
-
const ctl = koatty_container.IOC.getInsByClass(item.target);
|
|
623
|
-
if (!koatty_core.implementsControllerInterface(ctl)) {
|
|
624
|
-
throw Error(`The controller ${item.id} must implements interface 'IController'.`);
|
|
625
|
-
}
|
|
626
914
|
controllers.push(item.id);
|
|
627
915
|
}
|
|
628
916
|
});
|
|
@@ -639,17 +927,20 @@ var Loader = class _Loader {
|
|
|
639
927
|
* @throws {Error} When service does not implement IService interface
|
|
640
928
|
*/
|
|
641
929
|
async LoadServices() {
|
|
642
|
-
const serviceList =
|
|
930
|
+
const serviceList = this.app.container.listClass("SERVICE");
|
|
643
931
|
for (const item of serviceList) {
|
|
644
932
|
item.id = (item.id ?? "").replace("SERVICE:", "");
|
|
645
933
|
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
|
646
934
|
koatty_logger.DefaultLogger.Debug(`Load service: ${item.id}`);
|
|
647
|
-
|
|
935
|
+
const options = this.app.container.getPropertyData("SERVICE_OPTIONS", item.target, item.id) ?? {};
|
|
936
|
+
this.app.container.reg(item.id, item.target, {
|
|
648
937
|
scope: "Singleton",
|
|
938
|
+
...options,
|
|
649
939
|
type: "SERVICE",
|
|
650
|
-
args: []
|
|
940
|
+
args: options.args ?? []
|
|
651
941
|
});
|
|
652
|
-
|
|
942
|
+
if (options.scope === "Request") continue;
|
|
943
|
+
const ctl = this.app.container.getInsByClass(item.target);
|
|
653
944
|
if (!koatty_core.implementsServiceInterface(ctl)) {
|
|
654
945
|
throw Error(`The service ${item.id} must implements interface 'IService'.`);
|
|
655
946
|
}
|
|
@@ -668,17 +959,17 @@ var Loader = class _Loader {
|
|
|
668
959
|
* @throws {Error} When plugin loading fails
|
|
669
960
|
*/
|
|
670
961
|
async LoadComponents(componentManager) {
|
|
671
|
-
const componentList =
|
|
962
|
+
const componentList = this.app.container.listClass("COMPONENT");
|
|
672
963
|
componentList.forEach((item) => {
|
|
673
964
|
item.id = (item.id ?? "").replace("COMPONENT:", "");
|
|
674
965
|
if (koatty_lib.Helper.isClass(item.target)) {
|
|
675
|
-
|
|
966
|
+
this.app.container.reg(item.id, item.target, {
|
|
676
967
|
scope: "Singleton",
|
|
677
968
|
type: "COMPONENT",
|
|
678
969
|
args: []
|
|
679
970
|
});
|
|
680
971
|
if (item.id && item.id.endsWith("Aspect")) {
|
|
681
|
-
const ctl =
|
|
972
|
+
const ctl = this.app.container.getInsByClass(item.target);
|
|
682
973
|
if (!koatty_core.implementsAspectInterface(ctl)) {
|
|
683
974
|
throw Error(`The aspect ${item.id} must implements interface 'IAspect'.`);
|
|
684
975
|
}
|
|
@@ -698,7 +989,7 @@ var Loader = class _Loader {
|
|
|
698
989
|
}
|
|
699
990
|
const pluginConfList = pluginsConf.list ?? [];
|
|
700
991
|
for (const key of pluginConfList) {
|
|
701
|
-
const handle =
|
|
992
|
+
const handle = this.app.container.get(key, "COMPONENT");
|
|
702
993
|
if (!handle) {
|
|
703
994
|
throw Error(`Plugin ${key} load error.`);
|
|
704
995
|
}
|
|
@@ -747,7 +1038,8 @@ var bootstrapApplication = /* @__PURE__ */ __name(async function(target, bootFun
|
|
|
747
1038
|
koatty_logger.DefaultLogger.Log("Koatty", "", "Execute bootFunc ...");
|
|
748
1039
|
await bootFunc(app);
|
|
749
1040
|
}
|
|
750
|
-
koatty_container.IOC.
|
|
1041
|
+
if (!app.container || app.container === koatty_container.IOC) app.container = new koatty_container.Container();
|
|
1042
|
+
app.container.setApp(app);
|
|
751
1043
|
koatty_logger.DefaultLogger.Log("Koatty", "", "ComponentScan ...");
|
|
752
1044
|
Loader.CheckAllComponents(app, target);
|
|
753
1045
|
await Loader.LoadAllComponents(app, target);
|
|
@@ -789,7 +1081,6 @@ var listenCallback = /* @__PURE__ */ __name((app) => {
|
|
|
789
1081
|
koatty_logger.DefaultLogger.Log("Koatty", "", `App Environment: ${app.env}`);
|
|
790
1082
|
if (app.appDebug) koatty_logger.DefaultLogger.Warn(`Running in debug mode.`);
|
|
791
1083
|
koatty_logger.DefaultLogger.Log("Koatty", "", "====================================");
|
|
792
|
-
koatty_core.asyncEvent(app, koatty_core.AppEvent.appStart);
|
|
793
1084
|
}, "listenCallback");
|
|
794
1085
|
function Bootstrap(bootFunc) {
|
|
795
1086
|
return koatty_container.IOC.createDecorator((target, _context) => {
|
|
@@ -797,6 +1088,7 @@ function Bootstrap(bootFunc) {
|
|
|
797
1088
|
throw new Error(`class does not inherit from Koatty`);
|
|
798
1089
|
}
|
|
799
1090
|
koatty_container.IOC.saveClass("COMPONENT", target, "KOATTY_APP");
|
|
1091
|
+
if (checkUTRuntime()) return;
|
|
800
1092
|
ExecBootStrap(bootFunc)(target).catch((err) => {
|
|
801
1093
|
koatty_logger.DefaultLogger.Fatal(err);
|
|
802
1094
|
process.exitCode = 1;
|
|
@@ -844,10 +1136,6 @@ Object.defineProperty(exports, "Log", {
|
|
|
844
1136
|
enumerable: true,
|
|
845
1137
|
get: function () { return koatty_logger.Log; }
|
|
846
1138
|
});
|
|
847
|
-
Object.defineProperty(exports, "LogLevelType", {
|
|
848
|
-
enumerable: true,
|
|
849
|
-
get: function () { return koatty_logger.LogLevelType; }
|
|
850
|
-
});
|
|
851
1139
|
Object.defineProperty(exports, "Logger", {
|
|
852
1140
|
enumerable: true,
|
|
853
1141
|
get: function () { return koatty_logger.DefaultLogger; }
|