koatty 3.10.4-2 → 3.10.4-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/CHANGELOG.md +15 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +91 -101
- package/dist/index.mjs +86 -91
- package/dist/package.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
### [3.10.4-4](https://github.com/thinkkoa/koatty/compare/v3.10.4-3...v3.10.4-4) (2023-12-23)
|
6
|
+
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* remove export ([b2eed18](https://github.com/thinkkoa/koatty/commit/b2eed18017838e9e91394f91cd60ea9790c59920))
|
11
|
+
|
12
|
+
### [3.10.4-3](https://github.com/thinkkoa/koatty/compare/v3.10.4-2...v3.10.4-3) (2023-12-16)
|
13
|
+
|
14
|
+
|
15
|
+
### Bug Fixes
|
16
|
+
|
17
|
+
* async tracer ([098bf04](https://github.com/thinkkoa/koatty/commit/098bf040dc44cb1294cf3726acab65a2856f0548))
|
18
|
+
* 集成tracer ([7f1ed23](https://github.com/thinkkoa/koatty/commit/7f1ed232e4aa1224132ce74d6a6f4b92aa884973))
|
19
|
+
|
5
20
|
### [3.10.4-2](https://github.com/thinkkoa/koatty/compare/v3.10.4-1...v3.10.4-2) (2023-12-14)
|
6
21
|
|
7
22
|
### [3.10.4-1](https://github.com/thinkkoa/koatty/compare/v3.10.4-0...v3.10.4-1) (2023-12-10)
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-12-
|
3
|
+
* @Date: 2023-12-23 11:03:07
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -250,6 +250,5 @@ export * from "koatty_container";
|
|
250
250
|
export * from "koatty_core";
|
251
251
|
export * from "koatty_exception";
|
252
252
|
export * from "koatty_serve";
|
253
|
-
export * from "koatty_trace";
|
254
253
|
|
255
254
|
export { }
|
package/dist/index.js
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-12-
|
3
|
+
* @Date: 2023-12-23 11:02:53
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
8
|
'use strict';
|
9
9
|
|
10
|
+
var koatty_container = require('koatty_container');
|
10
11
|
var koatty_core = require('koatty_core');
|
12
|
+
var koatty_serve = require('koatty_serve');
|
11
13
|
var path = require('path');
|
12
14
|
var koatty_loader = require('koatty_loader');
|
15
|
+
var koatty_exception = require('koatty_exception');
|
13
16
|
var koatty_config = require('koatty_config');
|
17
|
+
var koatty_trace = require('koatty_trace');
|
14
18
|
var koatty_lib = require('koatty_lib');
|
15
19
|
var koatty_logger = require('koatty_logger');
|
16
|
-
var koatty_exception = require('koatty_exception');
|
17
|
-
var koatty_container = require('koatty_container');
|
18
|
-
var koatty_trace = require('koatty_trace');
|
19
|
-
var koatty_serve = require('koatty_serve');
|
20
20
|
require('reflect-metadata');
|
21
21
|
|
22
22
|
function _interopNamespaceDefault(e) {
|
@@ -38,39 +38,21 @@ function _interopNamespaceDefault(e) {
|
|
38
38
|
|
39
39
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
* @param {{
|
57
|
-
* logLevel?: LogLevelType;
|
58
|
-
* logFilePath?: string;
|
59
|
-
* sensFields?: string[];
|
60
|
-
* }} config
|
61
|
-
*/
|
62
|
-
function SetLogger(app, config) {
|
63
|
-
if (config.logLevel) {
|
64
|
-
koatty_logger.DefaultLogger.setLevel(config.logLevel);
|
65
|
-
}
|
66
|
-
if (config.logFilePath && !app.silent) {
|
67
|
-
koatty_lib.Helper.define(app, "logsPath", config.logFilePath);
|
68
|
-
process.env.LOGS_PATH = config.logFilePath;
|
69
|
-
koatty_logger.DefaultLogger.setLogFilePath(config.logFilePath);
|
70
|
-
}
|
71
|
-
if (config.sensFields) {
|
72
|
-
koatty_logger.DefaultLogger.setSensFields(config.sensFields);
|
73
|
-
}
|
41
|
+
async function TraceHandler(app) {
|
42
|
+
const timeout = (app.config('http_timeout') || 10) * 1000;
|
43
|
+
const encoding = app.config('encoding') || 'utf-8';
|
44
|
+
const openTrace = app.config("open_trace") || false;
|
45
|
+
const asyncHooks = app.config("async_hooks") || false;
|
46
|
+
const options = {
|
47
|
+
RequestIdHeaderName: app.config('trace_header') || 'X-Request-Id',
|
48
|
+
RequestIdName: app.config('trace_id') || "requestId",
|
49
|
+
IdFactory: undefined,
|
50
|
+
Timeout: timeout,
|
51
|
+
Encoding: encoding,
|
52
|
+
OpenTrace: openTrace,
|
53
|
+
AsyncHooks: asyncHooks,
|
54
|
+
};
|
55
|
+
app.use(await koatty_trace.Trace(options, app));
|
74
56
|
}
|
75
57
|
|
76
58
|
/*
|
@@ -149,27 +131,6 @@ function formatApiData(msg, data, defaultCode) {
|
|
149
131
|
return obj;
|
150
132
|
}
|
151
133
|
|
152
|
-
/*
|
153
|
-
* @Description: framework constants
|
154
|
-
* @Usage:
|
155
|
-
* @Author: richen
|
156
|
-
* @Date: 2023-12-09 21:56:32
|
157
|
-
* @LastEditTime: 2023-12-09 23:00:13
|
158
|
-
* @License: BSD (3-Clause)
|
159
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
160
|
-
*/
|
161
|
-
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
162
|
-
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
163
|
-
// tslint:disable: no-irregular-whitespace
|
164
|
-
const LOGO = `
|
165
|
-
|
166
|
-
┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬
|
167
|
-
├┴┐│ │├─┤ │ │ └┬┘
|
168
|
-
┴ ┴└─┘┴ ┴ ┴ ┴ ┴
|
169
|
-
-------------------------------------------
|
170
|
-
https://github.com/koatty
|
171
|
-
`;
|
172
|
-
|
173
134
|
/*
|
174
135
|
* @Description: base controller
|
175
136
|
* @Usage:
|
@@ -256,29 +217,68 @@ class BaseController {
|
|
256
217
|
// }
|
257
218
|
// });
|
258
219
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
220
|
+
/*
|
221
|
+
* @Description: framework logger
|
222
|
+
* @Usage:
|
223
|
+
* @Author: richen
|
224
|
+
* @Date: 2023-12-09 21:56:32
|
225
|
+
* @LastEditTime: 2023-12-09 23:02:27
|
226
|
+
* @License: BSD (3-Clause)
|
227
|
+
* @Copyright (c): <richenlin(at)gmail.com>
|
228
|
+
*/
|
229
|
+
// Logger
|
230
|
+
const Logger = koatty_logger.DefaultLogger;
|
231
|
+
/**
|
232
|
+
* SetLogger
|
233
|
+
*
|
234
|
+
* @export
|
235
|
+
* @param {{
|
236
|
+
* logLevel?: LogLevelType;
|
237
|
+
* logFilePath?: string;
|
238
|
+
* sensFields?: string[];
|
239
|
+
* }} config
|
240
|
+
*/
|
241
|
+
function SetLogger(app, config) {
|
242
|
+
if (config.logLevel) {
|
243
|
+
koatty_logger.DefaultLogger.setLevel(config.logLevel);
|
244
|
+
}
|
245
|
+
if (config.logFilePath && !app.silent) {
|
246
|
+
koatty_lib.Helper.define(app, "logsPath", config.logFilePath);
|
247
|
+
process.env.LOGS_PATH = config.logFilePath;
|
248
|
+
koatty_logger.DefaultLogger.setLogFilePath(config.logFilePath);
|
249
|
+
}
|
250
|
+
if (config.sensFields) {
|
251
|
+
koatty_logger.DefaultLogger.setSensFields(config.sensFields);
|
252
|
+
}
|
274
253
|
}
|
275
254
|
|
255
|
+
/*
|
256
|
+
* @Description: framework constants
|
257
|
+
* @Usage:
|
258
|
+
* @Author: richen
|
259
|
+
* @Date: 2023-12-09 21:56:32
|
260
|
+
* @LastEditTime: 2023-12-09 23:00:13
|
261
|
+
* @License: BSD (3-Clause)
|
262
|
+
* @Copyright (c): <richenlin(at)gmail.com>
|
263
|
+
*/
|
264
|
+
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
265
|
+
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
266
|
+
// tslint:disable: no-irregular-whitespace
|
267
|
+
const LOGO = `
|
268
|
+
|
269
|
+
┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬
|
270
|
+
├┴┐│ │├─┤ │ │ └┬┘
|
271
|
+
┴ ┴└─┘┴ ┴ ┴ ┴ ┴
|
272
|
+
-------------------------------------------
|
273
|
+
https://github.com/koatty
|
274
|
+
`;
|
275
|
+
|
276
276
|
/*
|
277
277
|
* @Description: framework loader
|
278
278
|
* @Usage:
|
279
279
|
* @Author: richen
|
280
280
|
* @Date: 2023-12-09 22:55:49
|
281
|
-
* @LastEditTime: 2023-12-
|
281
|
+
* @LastEditTime: 2023-12-22 07:31:21
|
282
282
|
* @License: BSD (3-Clause)
|
283
283
|
* @Copyright (c): <richenlin(at)gmail.com>
|
284
284
|
*/
|
@@ -509,7 +509,7 @@ class Loader {
|
|
509
509
|
*/
|
510
510
|
static async LoadMiddlewares(app, loadPath) {
|
511
511
|
// Error handling middleware
|
512
|
-
TraceHandler(app);
|
512
|
+
await TraceHandler(app);
|
513
513
|
let middlewareConf = app.config(undefined, "middleware");
|
514
514
|
if (koatty_lib.Helper.isEmpty(middlewareConf)) {
|
515
515
|
middlewareConf = { config: {}, list: [] };
|
@@ -535,12 +535,10 @@ class Loader {
|
|
535
535
|
for (const key of appMList) {
|
536
536
|
const handle = koatty_container.IOCContainer.get(key, "MIDDLEWARE");
|
537
537
|
if (!handle) {
|
538
|
-
|
539
|
-
continue;
|
538
|
+
throw Error(`Middleware ${key} load error.`);
|
540
539
|
}
|
541
540
|
if (!koatty_lib.Helper.isFunction(handle.run)) {
|
542
|
-
|
543
|
-
continue;
|
541
|
+
throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
|
544
542
|
}
|
545
543
|
if (middlewareConf.config[key] === false) {
|
546
544
|
Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
|
@@ -576,7 +574,7 @@ class Loader {
|
|
576
574
|
koatty_container.IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "CONTROLLER", args: [] });
|
577
575
|
const ctl = koatty_container.IOCContainer.getInsByClass(item.target);
|
578
576
|
if (!(ctl instanceof BaseController)) {
|
579
|
-
throw
|
577
|
+
throw Error(`Controller class ${item.id} does not inherit from BaseController`);
|
580
578
|
}
|
581
579
|
controllers.push(item.id);
|
582
580
|
}
|
@@ -649,12 +647,10 @@ class Loader {
|
|
649
647
|
for (const key of pluginConfList) {
|
650
648
|
const handle = koatty_container.IOCContainer.get(key, "COMPONENT");
|
651
649
|
if (!handle) {
|
652
|
-
|
653
|
-
continue;
|
650
|
+
throw Error(`Plugin ${key} load error.`);
|
654
651
|
}
|
655
652
|
if (!koatty_lib.Helper.isFunction(handle.run)) {
|
656
|
-
|
657
|
-
continue;
|
653
|
+
throw Error(`Plugin ${key} must implements interface 'IPlugin'.`);
|
658
654
|
}
|
659
655
|
if (pluginsConf.config[key] === false) {
|
660
656
|
Logger.Warn(`Plugin ${key} already loaded but not effective.`);
|
@@ -666,7 +662,7 @@ class Loader {
|
|
666
662
|
}
|
667
663
|
}
|
668
664
|
|
669
|
-
var version = "3.10.4-
|
665
|
+
var version = "3.10.4-4";
|
670
666
|
var engines = {
|
671
667
|
node: ">12.0.0"
|
672
668
|
};
|
@@ -719,7 +715,7 @@ const checkUTRuntime = () => {
|
|
719
715
|
* @Usage:
|
720
716
|
* @Author: richen
|
721
717
|
* @Date: 2023-12-09 21:56:32
|
722
|
-
* @LastEditTime: 2023-12-
|
718
|
+
* @LastEditTime: 2023-12-22 07:31:53
|
723
719
|
* @License: BSD (3-Clause)
|
724
720
|
* @Copyright (c): <richenlin(at)gmail.com>
|
725
721
|
*/
|
@@ -1069,28 +1065,16 @@ exports.Logger = Logger;
|
|
1069
1065
|
exports.Middleware = Middleware;
|
1070
1066
|
exports.Plugin = Plugin;
|
1071
1067
|
exports.Service = Service;
|
1072
|
-
Object.keys(koatty_core).forEach(function (k) {
|
1073
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1074
|
-
enumerable: true,
|
1075
|
-
get: function () { return koatty_core[k]; }
|
1076
|
-
});
|
1077
|
-
});
|
1078
|
-
Object.keys(koatty_exception).forEach(function (k) {
|
1079
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1080
|
-
enumerable: true,
|
1081
|
-
get: function () { return koatty_exception[k]; }
|
1082
|
-
});
|
1083
|
-
});
|
1084
1068
|
Object.keys(koatty_container).forEach(function (k) {
|
1085
1069
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1086
1070
|
enumerable: true,
|
1087
1071
|
get: function () { return koatty_container[k]; }
|
1088
1072
|
});
|
1089
1073
|
});
|
1090
|
-
Object.keys(
|
1074
|
+
Object.keys(koatty_core).forEach(function (k) {
|
1091
1075
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1092
1076
|
enumerable: true,
|
1093
|
-
get: function () { return
|
1077
|
+
get: function () { return koatty_core[k]; }
|
1094
1078
|
});
|
1095
1079
|
});
|
1096
1080
|
Object.keys(koatty_serve).forEach(function (k) {
|
@@ -1099,3 +1083,9 @@ Object.keys(koatty_serve).forEach(function (k) {
|
|
1099
1083
|
get: function () { return koatty_serve[k]; }
|
1100
1084
|
});
|
1101
1085
|
});
|
1086
|
+
Object.keys(koatty_exception).forEach(function (k) {
|
1087
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1088
|
+
enumerable: true,
|
1089
|
+
get: function () { return koatty_exception[k]; }
|
1090
|
+
});
|
1091
|
+
});
|
package/dist/index.mjs
CHANGED
@@ -1,62 +1,43 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-12-
|
3
|
+
* @Date: 2023-12-23 11:02:53
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
|
+
import { IOCContainer, TAGGED_CLS } from 'koatty_container';
|
9
|
+
export * from 'koatty_container';
|
8
10
|
import { AppEventArr, Koatty } from 'koatty_core';
|
9
11
|
export * from 'koatty_core';
|
12
|
+
import { NewServe, NewRouter, BindProcessEvent, CONTROLLER_ROUTER } from 'koatty_serve';
|
13
|
+
export * from 'koatty_serve';
|
10
14
|
import * as path from 'path';
|
11
15
|
import { Load } from 'koatty_loader';
|
16
|
+
import { prevent } from 'koatty_exception';
|
17
|
+
export * from 'koatty_exception';
|
12
18
|
import { LoadConfigs } from 'koatty_config';
|
13
19
|
export { Config, Value } from 'koatty_config';
|
20
|
+
import { Trace } from 'koatty_trace';
|
14
21
|
import { Helper } from 'koatty_lib';
|
15
22
|
export { Helper } from 'koatty_lib';
|
16
23
|
import { DefaultLogger } from 'koatty_logger';
|
17
|
-
import { prevent } from 'koatty_exception';
|
18
|
-
export * from 'koatty_exception';
|
19
|
-
import { IOCContainer, TAGGED_CLS } from 'koatty_container';
|
20
|
-
export * from 'koatty_container';
|
21
|
-
import { Trace } from 'koatty_trace';
|
22
|
-
export * from 'koatty_trace';
|
23
|
-
import { NewServe, NewRouter, BindProcessEvent, CONTROLLER_ROUTER } from 'koatty_serve';
|
24
|
-
export * from 'koatty_serve';
|
25
24
|
import 'reflect-metadata';
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
* @param {{
|
43
|
-
* logLevel?: LogLevelType;
|
44
|
-
* logFilePath?: string;
|
45
|
-
* sensFields?: string[];
|
46
|
-
* }} config
|
47
|
-
*/
|
48
|
-
function SetLogger(app, config) {
|
49
|
-
if (config.logLevel) {
|
50
|
-
DefaultLogger.setLevel(config.logLevel);
|
51
|
-
}
|
52
|
-
if (config.logFilePath && !app.silent) {
|
53
|
-
Helper.define(app, "logsPath", config.logFilePath);
|
54
|
-
process.env.LOGS_PATH = config.logFilePath;
|
55
|
-
DefaultLogger.setLogFilePath(config.logFilePath);
|
56
|
-
}
|
57
|
-
if (config.sensFields) {
|
58
|
-
DefaultLogger.setSensFields(config.sensFields);
|
59
|
-
}
|
26
|
+
async function TraceHandler(app) {
|
27
|
+
const timeout = (app.config('http_timeout') || 10) * 1000;
|
28
|
+
const encoding = app.config('encoding') || 'utf-8';
|
29
|
+
const openTrace = app.config("open_trace") || false;
|
30
|
+
const asyncHooks = app.config("async_hooks") || false;
|
31
|
+
const options = {
|
32
|
+
RequestIdHeaderName: app.config('trace_header') || 'X-Request-Id',
|
33
|
+
RequestIdName: app.config('trace_id') || "requestId",
|
34
|
+
IdFactory: undefined,
|
35
|
+
Timeout: timeout,
|
36
|
+
Encoding: encoding,
|
37
|
+
OpenTrace: openTrace,
|
38
|
+
AsyncHooks: asyncHooks,
|
39
|
+
};
|
40
|
+
app.use(await Trace(options, app));
|
60
41
|
}
|
61
42
|
|
62
43
|
/*
|
@@ -135,27 +116,6 @@ function formatApiData(msg, data, defaultCode) {
|
|
135
116
|
return obj;
|
136
117
|
}
|
137
118
|
|
138
|
-
/*
|
139
|
-
* @Description: framework constants
|
140
|
-
* @Usage:
|
141
|
-
* @Author: richen
|
142
|
-
* @Date: 2023-12-09 21:56:32
|
143
|
-
* @LastEditTime: 2023-12-09 23:00:13
|
144
|
-
* @License: BSD (3-Clause)
|
145
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
146
|
-
*/
|
147
|
-
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
148
|
-
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
149
|
-
// tslint:disable: no-irregular-whitespace
|
150
|
-
const LOGO = `
|
151
|
-
|
152
|
-
┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬
|
153
|
-
├┴┐│ │├─┤ │ │ └┬┘
|
154
|
-
┴ ┴└─┘┴ ┴ ┴ ┴ ┴
|
155
|
-
-------------------------------------------
|
156
|
-
https://github.com/koatty
|
157
|
-
`;
|
158
|
-
|
159
119
|
/*
|
160
120
|
* @Description: base controller
|
161
121
|
* @Usage:
|
@@ -242,29 +202,68 @@ class BaseController {
|
|
242
202
|
// }
|
243
203
|
// });
|
244
204
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
205
|
+
/*
|
206
|
+
* @Description: framework logger
|
207
|
+
* @Usage:
|
208
|
+
* @Author: richen
|
209
|
+
* @Date: 2023-12-09 21:56:32
|
210
|
+
* @LastEditTime: 2023-12-09 23:02:27
|
211
|
+
* @License: BSD (3-Clause)
|
212
|
+
* @Copyright (c): <richenlin(at)gmail.com>
|
213
|
+
*/
|
214
|
+
// Logger
|
215
|
+
const Logger = DefaultLogger;
|
216
|
+
/**
|
217
|
+
* SetLogger
|
218
|
+
*
|
219
|
+
* @export
|
220
|
+
* @param {{
|
221
|
+
* logLevel?: LogLevelType;
|
222
|
+
* logFilePath?: string;
|
223
|
+
* sensFields?: string[];
|
224
|
+
* }} config
|
225
|
+
*/
|
226
|
+
function SetLogger(app, config) {
|
227
|
+
if (config.logLevel) {
|
228
|
+
DefaultLogger.setLevel(config.logLevel);
|
229
|
+
}
|
230
|
+
if (config.logFilePath && !app.silent) {
|
231
|
+
Helper.define(app, "logsPath", config.logFilePath);
|
232
|
+
process.env.LOGS_PATH = config.logFilePath;
|
233
|
+
DefaultLogger.setLogFilePath(config.logFilePath);
|
234
|
+
}
|
235
|
+
if (config.sensFields) {
|
236
|
+
DefaultLogger.setSensFields(config.sensFields);
|
237
|
+
}
|
260
238
|
}
|
261
239
|
|
240
|
+
/*
|
241
|
+
* @Description: framework constants
|
242
|
+
* @Usage:
|
243
|
+
* @Author: richen
|
244
|
+
* @Date: 2023-12-09 21:56:32
|
245
|
+
* @LastEditTime: 2023-12-09 23:00:13
|
246
|
+
* @License: BSD (3-Clause)
|
247
|
+
* @Copyright (c): <richenlin(at)gmail.com>
|
248
|
+
*/
|
249
|
+
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
250
|
+
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
251
|
+
// tslint:disable: no-irregular-whitespace
|
252
|
+
const LOGO = `
|
253
|
+
|
254
|
+
┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬
|
255
|
+
├┴┐│ │├─┤ │ │ └┬┘
|
256
|
+
┴ ┴└─┘┴ ┴ ┴ ┴ ┴
|
257
|
+
-------------------------------------------
|
258
|
+
https://github.com/koatty
|
259
|
+
`;
|
260
|
+
|
262
261
|
/*
|
263
262
|
* @Description: framework loader
|
264
263
|
* @Usage:
|
265
264
|
* @Author: richen
|
266
265
|
* @Date: 2023-12-09 22:55:49
|
267
|
-
* @LastEditTime: 2023-12-
|
266
|
+
* @LastEditTime: 2023-12-22 07:31:21
|
268
267
|
* @License: BSD (3-Clause)
|
269
268
|
* @Copyright (c): <richenlin(at)gmail.com>
|
270
269
|
*/
|
@@ -495,7 +494,7 @@ class Loader {
|
|
495
494
|
*/
|
496
495
|
static async LoadMiddlewares(app, loadPath) {
|
497
496
|
// Error handling middleware
|
498
|
-
TraceHandler(app);
|
497
|
+
await TraceHandler(app);
|
499
498
|
let middlewareConf = app.config(undefined, "middleware");
|
500
499
|
if (Helper.isEmpty(middlewareConf)) {
|
501
500
|
middlewareConf = { config: {}, list: [] };
|
@@ -521,12 +520,10 @@ class Loader {
|
|
521
520
|
for (const key of appMList) {
|
522
521
|
const handle = IOCContainer.get(key, "MIDDLEWARE");
|
523
522
|
if (!handle) {
|
524
|
-
|
525
|
-
continue;
|
523
|
+
throw Error(`Middleware ${key} load error.`);
|
526
524
|
}
|
527
525
|
if (!Helper.isFunction(handle.run)) {
|
528
|
-
|
529
|
-
continue;
|
526
|
+
throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
|
530
527
|
}
|
531
528
|
if (middlewareConf.config[key] === false) {
|
532
529
|
Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
|
@@ -562,7 +559,7 @@ class Loader {
|
|
562
559
|
IOCContainer.reg(item.id, item.target, { scope: "Prototype", type: "CONTROLLER", args: [] });
|
563
560
|
const ctl = IOCContainer.getInsByClass(item.target);
|
564
561
|
if (!(ctl instanceof BaseController)) {
|
565
|
-
throw
|
562
|
+
throw Error(`Controller class ${item.id} does not inherit from BaseController`);
|
566
563
|
}
|
567
564
|
controllers.push(item.id);
|
568
565
|
}
|
@@ -635,12 +632,10 @@ class Loader {
|
|
635
632
|
for (const key of pluginConfList) {
|
636
633
|
const handle = IOCContainer.get(key, "COMPONENT");
|
637
634
|
if (!handle) {
|
638
|
-
|
639
|
-
continue;
|
635
|
+
throw Error(`Plugin ${key} load error.`);
|
640
636
|
}
|
641
637
|
if (!Helper.isFunction(handle.run)) {
|
642
|
-
|
643
|
-
continue;
|
638
|
+
throw Error(`Plugin ${key} must implements interface 'IPlugin'.`);
|
644
639
|
}
|
645
640
|
if (pluginsConf.config[key] === false) {
|
646
641
|
Logger.Warn(`Plugin ${key} already loaded but not effective.`);
|
@@ -652,7 +647,7 @@ class Loader {
|
|
652
647
|
}
|
653
648
|
}
|
654
649
|
|
655
|
-
var version = "3.10.4-
|
650
|
+
var version = "3.10.4-4";
|
656
651
|
var engines = {
|
657
652
|
node: ">12.0.0"
|
658
653
|
};
|
@@ -705,7 +700,7 @@ const checkUTRuntime = () => {
|
|
705
700
|
* @Usage:
|
706
701
|
* @Author: richen
|
707
702
|
* @Date: 2023-12-09 21:56:32
|
708
|
-
* @LastEditTime: 2023-12-
|
703
|
+
* @LastEditTime: 2023-12-22 07:31:53
|
709
704
|
* @License: BSD (3-Clause)
|
710
705
|
* @Copyright (c): <richenlin(at)gmail.com>
|
711
706
|
*/
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.10.4-
|
3
|
+
"version": "3.10.4-4",
|
4
4
|
"description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
|
5
5
|
"scripts": {
|
6
6
|
"build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
|
@@ -93,6 +93,6 @@
|
|
93
93
|
"koatty_proto": "^1.1.12",
|
94
94
|
"koatty_serve": "2.1.0",
|
95
95
|
"koatty_trace": "^1.10.4",
|
96
|
-
"koatty_validation": "^1.2.
|
96
|
+
"koatty_validation": "^1.2.10"
|
97
97
|
}
|
98
98
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.10.4-
|
3
|
+
"version": "3.10.4-4",
|
4
4
|
"description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
|
5
5
|
"scripts": {
|
6
6
|
"build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
|
@@ -93,6 +93,6 @@
|
|
93
93
|
"koatty_proto": "^1.1.12",
|
94
94
|
"koatty_serve": "2.1.0",
|
95
95
|
"koatty_trace": "^1.10.4",
|
96
|
-
"koatty_validation": "^1.2.
|
96
|
+
"koatty_validation": "^1.2.10"
|
97
97
|
}
|
98
98
|
}
|