koatty 3.11.9 → 3.13.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/.rollup.config.js +28 -6
- package/CHANGELOG.md +1877 -184
- package/README.md +122 -139
- package/dist/README.md +122 -139
- package/dist/index.d.ts +56 -26
- package/dist/index.js +466 -749
- package/dist/index.mjs +406 -707
- package/dist/package.json +15 -16
- package/package.json +15 -16
package/dist/index.js
CHANGED
@@ -1,45 +1,55 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2025-
|
3
|
+
* @Date: 2025-04-19 23:06:49
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
|
-
|
9
|
-
|
10
|
-
var
|
11
|
-
|
12
|
-
var
|
13
|
-
|
14
|
-
var
|
15
|
-
|
16
|
-
var
|
17
|
-
|
18
|
-
var
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
var e = require("koatty_config");
|
11
|
+
|
12
|
+
var t = require("koatty_container");
|
13
|
+
|
14
|
+
var o = require("koatty_core");
|
15
|
+
|
16
|
+
var r = require("koatty_exception");
|
17
|
+
|
18
|
+
var a = require("koatty_lib");
|
19
|
+
|
20
|
+
var n = require("koatty_router");
|
21
|
+
|
22
|
+
var s = require("koatty_logger");
|
23
|
+
|
24
|
+
var i = require("koatty_loader");
|
25
|
+
|
26
|
+
var l = require("koatty_serve");
|
27
|
+
|
28
|
+
var c = require("path");
|
29
|
+
|
30
|
+
function p(e) {
|
31
|
+
var t = Object.create(null);
|
32
|
+
if (e) Object.keys(e).forEach((function(o) {
|
33
|
+
if (o !== "default") {
|
34
|
+
var r = Object.getOwnPropertyDescriptor(e, o);
|
35
|
+
Object.defineProperty(t, o, r.get ? r : {
|
36
|
+
enumerable: !0,
|
37
|
+
get: function() {
|
38
|
+
return e[o];
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}));
|
43
|
+
t.default = e;
|
44
|
+
return Object.freeze(t);
|
36
45
|
}
|
37
46
|
|
38
|
-
var
|
47
|
+
var f = p(c);
|
48
|
+
|
49
|
+
var d = "3.13.0";
|
39
50
|
|
40
|
-
var
|
41
|
-
|
42
|
-
node: ">12.0.0"
|
51
|
+
var u = {
|
52
|
+
node: ">12.0.0"
|
43
53
|
};
|
44
54
|
|
45
55
|
/*
|
@@ -50,31 +60,16 @@ var engines = {
|
|
50
60
|
* @LastEditTime: 2024-10-31 17:52:43
|
51
61
|
* @License: BSD (3-Clause)
|
52
62
|
* @Copyright (c): <richenlin(at)gmail.com>
|
53
|
-
*/
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
* sensFields?: string[];
|
64
|
-
* }} config
|
65
|
-
*/
|
66
|
-
function SetLogger(app, config) {
|
67
|
-
if (config.logLevel) {
|
68
|
-
koatty_logger.DefaultLogger.setLevel(config.logLevel);
|
69
|
-
}
|
70
|
-
if (config.logFilePath && !app.silent) {
|
71
|
-
koatty_lib.Helper.define(app, "logsPath", config.logFilePath);
|
72
|
-
process.env.LOGS_PATH = config.logFilePath;
|
73
|
-
koatty_logger.DefaultLogger.setLogFilePath(config.logFilePath);
|
74
|
-
}
|
75
|
-
if (config.sensFields) {
|
76
|
-
koatty_logger.DefaultLogger.setSensFields(config.sensFields);
|
77
|
-
}
|
63
|
+
*/ const g = s.DefaultLogger;
|
64
|
+
|
65
|
+
function h(e, t) {
|
66
|
+
if (t.logLevel) s.DefaultLogger.setLevel(t.logLevel);
|
67
|
+
if (t.logFilePath && !e.silent) {
|
68
|
+
a.Helper.define(e, "logsPath", t.logFilePath);
|
69
|
+
process.env.LOGS_PATH = t.logFilePath;
|
70
|
+
s.DefaultLogger.setLogFilePath(t.logFilePath);
|
71
|
+
}
|
72
|
+
if (t.sensFields) s.DefaultLogger.setSensFields(t.sensFields);
|
78
73
|
}
|
79
74
|
|
80
75
|
/*
|
@@ -85,75 +80,39 @@ function SetLogger(app, config) {
|
|
85
80
|
* @LastEditTime: 2025-01-14 16:14:10
|
86
81
|
* @License: BSD (3-Clause)
|
87
82
|
* @Copyright (c): <richenlin(at)gmail.com>
|
88
|
-
*/
|
89
|
-
|
90
|
-
const
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
*/
|
103
|
-
function checkClass(fileName, xpath, target, exSet) {
|
104
|
-
if (koatty_lib.Helper.isClass(target) && target.name != fileName) { // export default class name{}
|
105
|
-
throw Error(`The file(${xpath}) name should be always the same as class name.`);
|
106
|
-
}
|
107
|
-
if (target["__esModule"]) {
|
108
|
-
if (target.name === undefined) { // export class name{}
|
109
|
-
const keys = Object.keys(target);
|
110
|
-
if (keys[0] != fileName && koatty_lib.Helper.isClass(target[keys[0]])) {
|
111
|
-
throw Error(`The file(${xpath}) name should be always the same as class name.`);
|
112
|
-
}
|
113
|
-
}
|
114
|
-
else if (target.name != fileName) { // export default class {}
|
115
|
-
throw Error(`The file(${xpath}) name should be always the same as class name.`);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
if (!exSet) {
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
if (exSet.has(fileName)) {
|
122
|
-
throw new Error(`A same class already exists. at \`${xpath}\`.`);
|
123
|
-
}
|
124
|
-
exSet.add(fileName);
|
125
|
-
return;
|
83
|
+
*/ const y = d;
|
84
|
+
|
85
|
+
const C = u.node.slice(1) || "12.0.0";
|
86
|
+
|
87
|
+
function m(e, t, o, r) {
|
88
|
+
if (a.Helper.isClass(o) && o.name != e) throw Error(`The file(${t}) name should be always the same as class name.`);
|
89
|
+
if (o["__esModule"]) if (o.name === void 0) {
|
90
|
+
const r = Object.keys(o);
|
91
|
+
if (r[0] != e && a.Helper.isClass(o[r[0]])) throw Error(`The file(${t}) name should be always the same as class name.`);
|
92
|
+
} else if (o.name != e) throw Error(`The file(${t}) name should be always the same as class name.`);
|
93
|
+
if (!r) return;
|
94
|
+
if (r.has(e)) throw new Error(`A same class already exists. at \`${t}\`.`);
|
95
|
+
r.add(e);
|
96
|
+
return;
|
126
97
|
}
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf('.'));
|
139
|
-
if (koatty_lib.Helper.toNumber(nodeEngines) > koatty_lib.Helper.toNumber(nodeVersion)) {
|
140
|
-
Logger.Error(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
|
141
|
-
process.exit(-1);
|
142
|
-
}
|
98
|
+
|
99
|
+
function L() {
|
100
|
+
let e = C;
|
101
|
+
e = e.slice(0, e.lastIndexOf("."));
|
102
|
+
let t = process.version;
|
103
|
+
if (t[0] === "v") t = t.slice(1);
|
104
|
+
t = t.slice(0, t.lastIndexOf("."));
|
105
|
+
if (a.Helper.toNumber(e) > a.Helper.toNumber(t)) {
|
106
|
+
g.Error(`Koatty need node version > ${e}, current version is ${t}, please upgrade it.`);
|
107
|
+
process.exit(-1);
|
108
|
+
}
|
143
109
|
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
let isUTRuntime = false;
|
151
|
-
// UT运行环境判断,暂时先只判断jest
|
152
|
-
const argv = JSON.stringify(process.argv[1]);
|
153
|
-
if (argv.indexOf('jest') > -1) {
|
154
|
-
isUTRuntime = true;
|
155
|
-
}
|
156
|
-
return isUTRuntime;
|
110
|
+
|
111
|
+
const v = () => {
|
112
|
+
let e = !1;
|
113
|
+
const t = JSON.stringify(process.argv[1]);
|
114
|
+
if (t.indexOf("jest") > -1) e = !0;
|
115
|
+
return e;
|
157
116
|
};
|
158
117
|
|
159
118
|
/*
|
@@ -164,442 +123,282 @@ const checkUTRuntime = () => {
|
|
164
123
|
* @LastEditTime: 2023-12-09 23:00:13
|
165
124
|
* @License: BSD (3-Clause)
|
166
125
|
* @Copyright (c): <richenlin(at)gmail.com>
|
167
|
-
*/
|
168
|
-
|
169
|
-
const
|
170
|
-
// tslint:disable: no-irregular-whitespace
|
171
|
-
const LOGO = `
|
172
|
-
|
173
|
-
┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬
|
174
|
-
├┴┐│ │├─┤ │ │ └┬┘
|
175
|
-
┴ ┴└─┘┴ ┴ ┴ ┴ ┴
|
176
|
-
-------------------------------------------
|
177
|
-
https://github.com/koatty
|
178
|
-
`;
|
126
|
+
*/ const E = "COMPONENT_SCAN";
|
127
|
+
|
128
|
+
const O = "CONFIGURATION_SCAN";
|
179
129
|
|
130
|
+
const w = `\n\n┬┌─┌─┐┌─┐┌┬┐┌┬┐┬ ┬\n├┴┐│ │├─┤ │ │ └┬┘\n┴ ┴└─┘┴ ┴ ┴ ┴ ┴ \n-------------------------------------------\nhttps://github.com/koatty\n`
|
180
131
|
/*
|
181
132
|
* @Description: framework loader
|
182
133
|
* @Usage:
|
183
134
|
* @Author: richen
|
184
135
|
* @Date: 2023-12-09 22:55:49
|
185
|
-
* @LastEditTime: 2025-
|
136
|
+
* @LastEditTime: 2025-03-13 16:44:39
|
186
137
|
* @License: BSD (3-Clause)
|
187
138
|
* @Copyright (c): <richenlin(at)gmail.com>
|
188
|
-
|
189
|
-
|
190
|
-
*
|
191
|
-
*/
|
139
|
+
*/;
|
140
|
+
|
192
141
|
class Loader {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
Logger.setLevel("debug");
|
211
|
-
}
|
212
|
-
else {
|
213
|
-
Logger.setLevel("info");
|
214
|
-
}
|
215
|
-
// define path
|
216
|
-
const rootPath = app.rootPath || process.cwd();
|
217
|
-
const appPath = app.appPath || path__namespace.resolve(rootPath, app.appDebug ? 'src' : 'dist');
|
218
|
-
const koattyPath = path__namespace.resolve(__dirname, '..');
|
219
|
-
koatty_lib.Helper.define(app, 'rootPath', rootPath);
|
220
|
-
koatty_lib.Helper.define(app, 'appPath', appPath);
|
221
|
-
koatty_lib.Helper.define(app, 'koattyPath', koattyPath);
|
222
|
-
//
|
223
|
-
if (koatty_lib.Helper.isEmpty(app.name)) {
|
224
|
-
const pkg = koatty_lib.Helper.safeRequire(`${path__namespace.dirname(appPath)}/package.json`);
|
225
|
-
if (pkg.name) {
|
226
|
-
app.name = pkg.name;
|
227
|
-
app.version = app.version || pkg.version;
|
228
|
-
}
|
229
|
-
}
|
230
|
-
process.env.ROOT_PATH = rootPath;
|
231
|
-
process.env.APP_PATH = appPath;
|
232
|
-
process.env.KOATTY_PATH = koattyPath;
|
233
|
-
// Compatible with old version, will be deprecated
|
234
|
-
koatty_lib.Helper.define(app, 'thinkPath', koattyPath);
|
235
|
-
process.env.THINK_PATH = koattyPath;
|
236
|
-
}
|
237
|
-
/**
|
238
|
-
* Get component metadata
|
239
|
-
*
|
240
|
-
* @static
|
241
|
-
* @param {KoattyApplication} app
|
242
|
-
* @param {*} target
|
243
|
-
* @returns {*} {any[]}
|
244
|
-
* @memberof Loader
|
245
|
-
*/
|
246
|
-
static GetComponentMeta(app, target) {
|
247
|
-
let componentMetas = [];
|
248
|
-
const componentMeta = koatty_container.IOC.getClassMetadata(koatty_container.TAGGED_CLS, COMPONENT_SCAN, target);
|
249
|
-
if (componentMeta) {
|
250
|
-
if (koatty_lib.Helper.isArray(componentMeta)) {
|
251
|
-
componentMetas = componentMeta;
|
252
|
-
}
|
253
|
-
else {
|
254
|
-
componentMetas.push(componentMeta);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
if (componentMetas.length < 1) {
|
258
|
-
componentMetas = [app.appPath];
|
259
|
-
}
|
260
|
-
return componentMetas;
|
261
|
-
}
|
262
|
-
/**
|
263
|
-
* Get configuration metadata
|
264
|
-
*
|
265
|
-
* @static
|
266
|
-
* @param {KoattyApplication} app
|
267
|
-
* @param {*} target
|
268
|
-
* @returns {*} {any[]}
|
269
|
-
* @memberof Loader
|
270
|
-
*/
|
271
|
-
static GetConfigurationMeta(app, target) {
|
272
|
-
const confMeta = koatty_container.IOC.getClassMetadata(koatty_container.TAGGED_CLS, CONFIGURATION_SCAN, target);
|
273
|
-
let configurationMetas = [];
|
274
|
-
if (confMeta) {
|
275
|
-
if (koatty_lib.Helper.isArray(confMeta)) {
|
276
|
-
configurationMetas = confMeta;
|
277
|
-
}
|
278
|
-
else {
|
279
|
-
configurationMetas.push(confMeta);
|
280
|
-
}
|
281
|
-
}
|
282
|
-
return configurationMetas;
|
283
|
-
}
|
284
|
-
/**
|
285
|
-
* Load all bean, excepted config/*、App.ts
|
286
|
-
*
|
287
|
-
* @static
|
288
|
-
* @param {KoattyApplication} app
|
289
|
-
* @param {*} target
|
290
|
-
* @memberof Loader
|
291
|
-
*/
|
292
|
-
static CheckAllComponents(app, target) {
|
293
|
-
// component metadata
|
294
|
-
const componentMetas = Loader.GetComponentMeta(app, target);
|
295
|
-
// configuration metadata
|
296
|
-
const configurationMetas = Loader.GetConfigurationMeta(app, target);
|
297
|
-
const exSet = new Set();
|
298
|
-
koatty_loader.Load(componentMetas, '', (fileName, xpath, xTarget) => {
|
299
|
-
checkClass(fileName, xpath, xTarget, exSet);
|
300
|
-
}, ['**/**.js', '**/**.ts', '!**/**.d.ts'], [...configurationMetas, `${target.name || '.no'}.ts`]);
|
301
|
-
exSet.clear();
|
302
|
-
}
|
303
|
-
/**
|
304
|
-
* Set Logger level
|
305
|
-
*
|
306
|
-
* @static
|
307
|
-
* @param {KoattyApplication} app
|
308
|
-
* @memberof Loader
|
309
|
-
*/
|
310
|
-
static SetLogger(app) {
|
311
|
-
const data = app.getMetaData('_configs') || [];
|
312
|
-
const configs = data[0] || {};
|
313
|
-
//Logger
|
314
|
-
if (configs.config) {
|
315
|
-
const opt = configs.config;
|
316
|
-
let logLevel = "debug", logFilePath = "", sensFields = [];
|
317
|
-
if (app.env === "production") {
|
318
|
-
logLevel = "info";
|
319
|
-
}
|
320
|
-
if (opt.logs_level) {
|
321
|
-
logLevel = (opt.logs_level).toLowerCase();
|
322
|
-
}
|
323
|
-
if (opt.logs_path) {
|
324
|
-
logFilePath = opt.logs_path;
|
325
|
-
}
|
326
|
-
if (opt.sens_fields) {
|
327
|
-
sensFields = opt.sens_fields;
|
328
|
-
}
|
329
|
-
SetLogger(app, { logLevel, logFilePath, sensFields });
|
330
|
-
}
|
142
|
+
constructor(e) {
|
143
|
+
this.app = e;
|
144
|
+
}
|
145
|
+
static initialize(e) {
|
146
|
+
if (e.env == "development") g.setLevel("debug"); else g.setLevel("info");
|
147
|
+
const t = e.rootPath || process.cwd();
|
148
|
+
const o = e.appPath || f.resolve(t, e.appDebug ? "src" : "dist");
|
149
|
+
const r = f.resolve(__dirname, "..");
|
150
|
+
a.Helper.define(e, "rootPath", t);
|
151
|
+
a.Helper.define(e, "appPath", o);
|
152
|
+
a.Helper.define(e, "koattyPath", r);
|
153
|
+
if (a.Helper.isEmpty(e.name)) {
|
154
|
+
const t = a.Helper.safeRequire(`${f.dirname(o)}/package.json`);
|
155
|
+
if (t.name) {
|
156
|
+
e.name = t.name;
|
157
|
+
e.version = e.version || t.version;
|
158
|
+
}
|
331
159
|
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
}
|
376
|
-
}
|
160
|
+
process.env.ROOT_PATH = t;
|
161
|
+
process.env.APP_PATH = o;
|
162
|
+
process.env.KOATTY_PATH = r;
|
163
|
+
a.Helper.define(e, "thinkPath", r);
|
164
|
+
process.env.THINK_PATH = r;
|
165
|
+
}
|
166
|
+
static GetComponentMeta(e, o) {
|
167
|
+
let r = [];
|
168
|
+
const n = t.IOC.getClassMetadata(t.TAGGED_CLS, E, o);
|
169
|
+
if (n) if (a.Helper.isArray(n)) r = n; else r.push(n);
|
170
|
+
if (r.length < 1) r = [ e.appPath ];
|
171
|
+
return r;
|
172
|
+
}
|
173
|
+
static GetConfigurationMeta(e, o) {
|
174
|
+
const r = t.IOC.getClassMetadata(t.TAGGED_CLS, O, o);
|
175
|
+
let n = [];
|
176
|
+
if (r) if (a.Helper.isArray(r)) n = r; else n.push(r);
|
177
|
+
return n;
|
178
|
+
}
|
179
|
+
static CheckAllComponents(e, t) {
|
180
|
+
const o = Loader.GetComponentMeta(e, t);
|
181
|
+
const r = Loader.GetConfigurationMeta(e, t);
|
182
|
+
const a = new Set;
|
183
|
+
i.Load(o, "", ((e, t, o) => {
|
184
|
+
m(e, t, o, a);
|
185
|
+
}), [ "**/**.js", "**/**.ts", "!**/**.d.ts" ], [ ...r, `${t.name || ".no"}.ts` ]);
|
186
|
+
a.clear();
|
187
|
+
}
|
188
|
+
static SetLogger(e) {
|
189
|
+
const t = e.getMetaData("_configs") || [];
|
190
|
+
const o = t[0] || {};
|
191
|
+
if (o.config) {
|
192
|
+
const t = o.config;
|
193
|
+
let r = "debug", a = "", n = [];
|
194
|
+
if (e.env === "production") r = "info";
|
195
|
+
if (t.logsLevel) r = t.logsLevel.toLowerCase();
|
196
|
+
if (t.logsPath) a = t.logsPath;
|
197
|
+
if (t.sensFields) n = t.sensFields;
|
198
|
+
h(e, {
|
199
|
+
logLevel: r,
|
200
|
+
logFilePath: a,
|
201
|
+
sensFields: n
|
202
|
+
});
|
377
203
|
}
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
await loader.LoadComponents();
|
405
|
-
// Load Middleware
|
406
|
-
Logger.Log('Koatty', '', 'Load Middlewares ...');
|
407
|
-
await loader.LoadMiddlewares();
|
408
|
-
// Load Services
|
409
|
-
Logger.Log('Koatty', '', 'Load Services ...');
|
410
|
-
await loader.LoadServices();
|
411
|
-
// Load Controllers
|
412
|
-
Logger.Log('Koatty', '', 'Load Controllers ...');
|
413
|
-
const controllers = await loader.LoadControllers();
|
414
|
-
// Load Routers
|
415
|
-
Logger.Log('Koatty', '', 'Load Routers ...');
|
416
|
-
loader.LoadRouter(controllers);
|
204
|
+
}
|
205
|
+
static LoadAppEventHooks(e, r) {
|
206
|
+
const n = new Map;
|
207
|
+
for (const e of o.AppEventArr) {
|
208
|
+
let o;
|
209
|
+
switch (e) {
|
210
|
+
case "appBoot":
|
211
|
+
o = t.IOC.getClassMetadata(t.TAGGED_CLS, "appBoot", r);
|
212
|
+
if (a.Helper.isArray(o)) n.set("appBoot", o);
|
213
|
+
break;
|
214
|
+
|
215
|
+
case "appReady":
|
216
|
+
o = t.IOC.getClassMetadata(t.TAGGED_CLS, "appReady", r);
|
217
|
+
if (a.Helper.isArray(o)) n.set("appReady", o);
|
218
|
+
break;
|
219
|
+
|
220
|
+
case "appStart":
|
221
|
+
o = t.IOC.getClassMetadata(t.TAGGED_CLS, "appStart", r);
|
222
|
+
if (a.Helper.isArray(o)) n.set("appStart", o);
|
223
|
+
break;
|
224
|
+
|
225
|
+
case "appStop":
|
226
|
+
o = t.IOC.getClassMetadata(t.TAGGED_CLS, "appStop", r);
|
227
|
+
if (a.Helper.isArray(o)) n.set("appStop", o);
|
228
|
+
break;
|
229
|
+
}
|
417
230
|
}
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
231
|
+
for (const [t, o] of n) for (const r of o) e.once(t, (() => r(e)));
|
232
|
+
}
|
233
|
+
static async LoadAllComponents(e, t) {
|
234
|
+
var o, r, s;
|
235
|
+
g.Log("Koatty", "", "Load Configurations ...");
|
236
|
+
const i = Loader.GetConfigurationMeta(e, t);
|
237
|
+
const c = new Loader(e);
|
238
|
+
c.LoadConfigs(i);
|
239
|
+
const p = (o = e.config("server")) !== null && o !== void 0 ? o : {
|
240
|
+
protocol: "http"
|
241
|
+
};
|
242
|
+
const f = (r = p.protocol) !== null && r !== void 0 ? r : "http";
|
243
|
+
a.Helper.define(e, "server", l.NewServe(e, p));
|
244
|
+
const d = (s = e.config(void 0, "router")) !== null && s !== void 0 ? s : {};
|
245
|
+
a.Helper.define(e, "router", n.NewRouter(e, {
|
246
|
+
protocol: f,
|
247
|
+
...d
|
248
|
+
}));
|
249
|
+
g.Log("Koatty", "", "Load Components ...");
|
250
|
+
await c.LoadComponents();
|
251
|
+
g.Log("Koatty", "", "Load Middlewares ...");
|
252
|
+
await c.LoadMiddlewares();
|
253
|
+
g.Log("Koatty", "", "Load Services ...");
|
254
|
+
await c.LoadServices();
|
255
|
+
g.Log("Koatty", "", "Load Controllers ...");
|
256
|
+
const u = await c.LoadControllers();
|
257
|
+
g.Log("Koatty", "", "Load Routers ...");
|
258
|
+
c.LoadRouter(u);
|
259
|
+
}
|
260
|
+
LoadConfigs(t) {
|
261
|
+
const o = {};
|
262
|
+
i.Load([ "./config" ], this.app.koattyPath, (function(e, t, r) {
|
263
|
+
o[e] = r;
|
264
|
+
}));
|
265
|
+
if (a.Helper.isArray(t)) t = t.length > 0 ? t : [ "./config" ];
|
266
|
+
let r = e.LoadConfigs(t, this.app.appPath);
|
267
|
+
r = a.Helper.extend(o, r, !0);
|
268
|
+
this.app.setMetaData("_configs", r);
|
269
|
+
}
|
270
|
+
async LoadMiddlewares() {
|
271
|
+
var e;
|
272
|
+
let r = this.app.config(void 0, "middleware");
|
273
|
+
if (a.Helper.isEmpty(r)) r = {
|
274
|
+
config: {},
|
275
|
+
list: [],
|
276
|
+
routeList: []
|
277
|
+
};
|
278
|
+
const n = (e = t.IOC.listClass("MIDDLEWARE")) !== null && e !== void 0 ? e : [];
|
279
|
+
n.forEach((e => {
|
280
|
+
var r;
|
281
|
+
e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("MIDDLEWARE:", "");
|
282
|
+
if (e.id && a.Helper.isClass(e.target)) {
|
283
|
+
t.IOC.reg(e.id, e.target, {
|
284
|
+
scope: "Prototype",
|
285
|
+
type: "MIDDLEWARE",
|
286
|
+
args: []
|
429
287
|
});
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
288
|
+
const r = t.IOC.getInsByClass(e.target);
|
289
|
+
if (!o.implementsMiddlewareInterface(r)) throw Error(`The middleware ${e.id} must implements interface 'IMiddleware'.`);
|
290
|
+
}
|
291
|
+
}));
|
292
|
+
const s = r.list || [];
|
293
|
+
const i = new Set([]);
|
294
|
+
s.forEach((e => {
|
295
|
+
i.add(e);
|
296
|
+
}));
|
297
|
+
const l = r.routeList || [];
|
298
|
+
const c = new Set([]);
|
299
|
+
l.forEach((e => {
|
300
|
+
c.add(e);
|
301
|
+
}));
|
302
|
+
const p = r.config || {};
|
303
|
+
for (const e of i) {
|
304
|
+
const o = t.IOC.get(e, "MIDDLEWARE");
|
305
|
+
if (!o) throw Error(`Middleware ${e} load error.`);
|
306
|
+
if (!a.Helper.isFunction(o.run)) throw Error(`The middleware ${e} must implements interface 'IMiddleware'.`);
|
307
|
+
g.Debug(`Load middleware: ${e}`);
|
308
|
+
const r = p[e] || {};
|
309
|
+
const n = await o.run(r, this.app);
|
310
|
+
if (a.Helper.isFunction(n)) if (n.length < 3) this.app.use(n); else this.app.useExp(n);
|
436
311
|
}
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
let middlewareConf = this.app.config(undefined, "middleware");
|
445
|
-
if (koatty_lib.Helper.isEmpty(middlewareConf)) {
|
446
|
-
middlewareConf = { config: {}, list: [] };
|
447
|
-
}
|
448
|
-
//Mount default middleware
|
449
|
-
// Load(loadPath || ["./middleware"], app.koattyPath);
|
450
|
-
//Mount application middleware
|
451
|
-
// const middleware: any = {};
|
452
|
-
const appMiddleware = (_a = koatty_container.IOC.listClass("MIDDLEWARE")) !== null && _a !== void 0 ? _a : [];
|
453
|
-
appMiddleware.forEach((item) => {
|
454
|
-
var _a;
|
455
|
-
item.id = ((_a = item.id) !== null && _a !== void 0 ? _a : "").replace("MIDDLEWARE:", "");
|
456
|
-
if (item.id && koatty_lib.Helper.isClass(item.target)) {
|
457
|
-
koatty_container.IOC.reg(item.id, item.target, { scope: "Prototype", type: "MIDDLEWARE", args: [] });
|
458
|
-
const ctl = koatty_container.IOC.getInsByClass(item.target);
|
459
|
-
if (!koatty_core.implementsMiddlewareInterface(ctl)) {
|
460
|
-
throw Error(`The middleware ${item.id} must implements interface 'IMiddleware'.`);
|
461
|
-
}
|
462
|
-
}
|
463
|
-
});
|
464
|
-
const middlewareConfList = middlewareConf.list || [];
|
465
|
-
//de-duplication
|
466
|
-
const appMList = new Set([]);
|
467
|
-
middlewareConfList.forEach((item) => {
|
468
|
-
appMList.add(item);
|
469
|
-
});
|
470
|
-
//Automatically call middleware
|
471
|
-
const middlewareConfig = middlewareConf.config || {};
|
472
|
-
for (const key of appMList) {
|
473
|
-
const handle = koatty_container.IOC.get(key, "MIDDLEWARE");
|
474
|
-
if (!handle) {
|
475
|
-
throw Error(`Middleware ${key} load error.`);
|
476
|
-
}
|
477
|
-
if (!koatty_lib.Helper.isFunction(handle.run)) {
|
478
|
-
throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
|
479
|
-
}
|
480
|
-
if (middlewareConfig[key] === false) {
|
481
|
-
Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
|
482
|
-
continue;
|
483
|
-
}
|
484
|
-
Logger.Debug(`Load middleware: ${key}`);
|
485
|
-
const result = await handle.run(middlewareConfig[key] || {}, this.app);
|
486
|
-
if (koatty_lib.Helper.isFunction(result)) {
|
487
|
-
if (result.length < 3) {
|
488
|
-
this.app.use(result);
|
489
|
-
}
|
490
|
-
else {
|
491
|
-
this.app.useExp(result);
|
492
|
-
}
|
493
|
-
}
|
494
|
-
}
|
312
|
+
for (const e of c) {
|
313
|
+
const r = t.IOC.get(e, "MIDDLEWARE");
|
314
|
+
if (!r) throw Error(`Router middleware ${e} load error.`);
|
315
|
+
if (!a.Helper.isFunction(r.run)) throw Error(`The router middleware ${e} must implements interface 'IMiddleware'.`);
|
316
|
+
g.Debug(`Load router middleware: ${e}`);
|
317
|
+
const n = await r.run(p[e] || {}, this.app);
|
318
|
+
if (a.Helper.isFunction(n)) this.app.setMetaData(`routerMiddleware_${e}`, n.length > 2 ? o.parseExp(n) : n);
|
495
319
|
}
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
// registering to IOC
|
510
|
-
koatty_container.IOC.reg(item.id, item.target, { scope: "Prototype", type: "CONTROLLER", args: [] });
|
511
|
-
const ctl = koatty_container.IOC.getInsByClass(item.target);
|
512
|
-
if (!koatty_core.implementsControllerInterface(ctl)) {
|
513
|
-
throw Error(`The controller ${item.id} must implements interface 'IController'.`);
|
514
|
-
}
|
515
|
-
controllers.push(item.id);
|
516
|
-
}
|
320
|
+
}
|
321
|
+
async LoadControllers() {
|
322
|
+
const e = t.IOC.listClass("CONTROLLER");
|
323
|
+
const r = [];
|
324
|
+
e.forEach((e => {
|
325
|
+
var n;
|
326
|
+
e.id = ((n = e.id) !== null && n !== void 0 ? n : "").replace("CONTROLLER:", "");
|
327
|
+
if (e.id && a.Helper.isClass(e.target)) {
|
328
|
+
g.Debug(`Load controller: ${e.id}`);
|
329
|
+
t.IOC.reg(e.id, e.target, {
|
330
|
+
scope: "Prototype",
|
331
|
+
type: "CONTROLLER",
|
332
|
+
args: []
|
517
333
|
});
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
throw Error(`The service ${item.id} must implements interface 'IService'.`);
|
537
|
-
}
|
538
|
-
}
|
334
|
+
const a = t.IOC.getInsByClass(e.target);
|
335
|
+
if (!o.implementsControllerInterface(a)) throw Error(`The controller ${e.id} must implements interface 'IController'.`);
|
336
|
+
r.push(e.id);
|
337
|
+
}
|
338
|
+
}));
|
339
|
+
return r;
|
340
|
+
}
|
341
|
+
async LoadServices() {
|
342
|
+
const e = t.IOC.listClass("SERVICE");
|
343
|
+
e.forEach((e => {
|
344
|
+
var r;
|
345
|
+
e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("SERVICE:", "");
|
346
|
+
if (e.id && a.Helper.isClass(e.target)) {
|
347
|
+
g.Debug(`Load service: ${e.id}`);
|
348
|
+
t.IOC.reg(e.id, e.target, {
|
349
|
+
scope: "Singleton",
|
350
|
+
type: "SERVICE",
|
351
|
+
args: []
|
539
352
|
});
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
const ctl = koatty_container.IOC.getInsByClass(item.target);
|
558
|
-
if (!koatty_core.implementsPluginInterface(ctl)) {
|
559
|
-
throw Error(`The plugin ${item.id} must implements interface 'IPlugin'.`);
|
560
|
-
}
|
561
|
-
pluginList.push(item.id);
|
562
|
-
}
|
563
|
-
if (item.id && (item.id).endsWith("Aspect")) {
|
564
|
-
const ctl = koatty_container.IOC.getInsByClass(item.target);
|
565
|
-
if (!koatty_core.implementsAspectInterface(ctl)) {
|
566
|
-
throw Error(`The aspect ${item.id} must implements interface 'IAspect'.`);
|
567
|
-
}
|
568
|
-
}
|
569
|
-
}
|
353
|
+
const r = t.IOC.getInsByClass(e.target);
|
354
|
+
if (!o.implementsServiceInterface(r)) throw Error(`The service ${e.id} must implements interface 'IService'.`);
|
355
|
+
}
|
356
|
+
}));
|
357
|
+
}
|
358
|
+
async LoadComponents() {
|
359
|
+
var e, r;
|
360
|
+
const n = t.IOC.listClass("COMPONENT");
|
361
|
+
const s = [];
|
362
|
+
n.forEach((async e => {
|
363
|
+
var r;
|
364
|
+
e.id = ((r = e.id) !== null && r !== void 0 ? r : "").replace("COMPONENT:", "");
|
365
|
+
if (a.Helper.isClass(e.target)) {
|
366
|
+
t.IOC.reg(e.id, e.target, {
|
367
|
+
scope: "Singleton",
|
368
|
+
type: "COMPONENT",
|
369
|
+
args: []
|
570
370
|
});
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
371
|
+
if (e.id && e.id.endsWith("Plugin")) {
|
372
|
+
const r = t.IOC.getInsByClass(e.target);
|
373
|
+
if (!o.implementsPluginInterface(r)) throw Error(`The plugin ${e.id} must implements interface 'IPlugin'.`);
|
374
|
+
s.push(e.id);
|
575
375
|
}
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
const handle = koatty_container.IOC.get(key, "COMPONENT");
|
580
|
-
if (!handle) {
|
581
|
-
throw Error(`Plugin ${key} load error.`);
|
582
|
-
}
|
583
|
-
if (!koatty_lib.Helper.isFunction(handle.run)) {
|
584
|
-
throw Error(`Plugin ${key} must implements interface 'IPlugin'.`);
|
585
|
-
}
|
586
|
-
if (pluginsConf.config[key] === false) {
|
587
|
-
Logger.Warn(`Plugin ${key} already loaded but not effective.`);
|
588
|
-
continue;
|
589
|
-
}
|
590
|
-
// sync exec
|
591
|
-
await handle.run((_b = pluginsConf.config[key]) !== null && _b !== void 0 ? _b : {}, this.app);
|
376
|
+
if (e.id && e.id.endsWith("Aspect")) {
|
377
|
+
const r = t.IOC.getInsByClass(e.target);
|
378
|
+
if (!o.implementsAspectInterface(r)) throw Error(`The aspect ${e.id} must implements interface 'IAspect'.`);
|
592
379
|
}
|
380
|
+
}
|
381
|
+
}));
|
382
|
+
let i = this.app.config(void 0, "plugin");
|
383
|
+
if (a.Helper.isEmpty(i)) i = {
|
384
|
+
config: {},
|
385
|
+
list: []
|
386
|
+
};
|
387
|
+
const l = (e = i.list) !== null && e !== void 0 ? e : [];
|
388
|
+
for (const e of l) {
|
389
|
+
const o = t.IOC.get(e, "COMPONENT");
|
390
|
+
if (!o) throw Error(`Plugin ${e} load error.`);
|
391
|
+
if (!a.Helper.isFunction(o.run)) throw Error(`Plugin ${e} must implements interface 'IPlugin'.`);
|
392
|
+
if (i.config[e] === !1) {
|
393
|
+
g.Warn(`Plugin ${e} already loaded but not effective.`);
|
394
|
+
continue;
|
395
|
+
}
|
396
|
+
await o.run((r = i.config[e]) !== null && r !== void 0 ? r : {}, this.app);
|
593
397
|
}
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
*/
|
599
|
-
async LoadRouter(ctls) {
|
600
|
-
// load router
|
601
|
-
await this.app.router.LoadRouter(this.app, ctls);
|
602
|
-
}
|
398
|
+
}
|
399
|
+
async LoadRouter(e) {
|
400
|
+
await this.app.router.LoadRouter(this.app, e);
|
401
|
+
}
|
603
402
|
}
|
604
403
|
|
605
404
|
/*
|
@@ -610,229 +409,147 @@ class Loader {
|
|
610
409
|
* @LastEditTime: 2025-01-14 16:11:21
|
611
410
|
* @License: BSD (3-Clause)
|
612
411
|
* @Copyright (c): <richenlin(at)gmail.com>
|
613
|
-
*/
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
* @param {Function} [bootFunc]
|
619
|
-
* @returns {ClassDecorator}
|
620
|
-
*/
|
621
|
-
function Bootstrap(bootFunc) {
|
622
|
-
return function (target) {
|
623
|
-
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
624
|
-
throw new Error(`class does not inherit from Koatty`);
|
625
|
-
}
|
626
|
-
executeBootstrap(target, bootFunc);
|
627
|
-
};
|
412
|
+
*/ function I(e) {
|
413
|
+
return function(t) {
|
414
|
+
if (!(t.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
|
415
|
+
S(t, e);
|
416
|
+
};
|
628
417
|
}
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
*/
|
636
|
-
function ExecBootStrap(bootFunc) {
|
637
|
-
return async (target) => {
|
638
|
-
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
639
|
-
throw new Error(`class ${target.name} does not inherit from Koatty`);
|
640
|
-
}
|
641
|
-
return await executeBootstrap(target, bootFunc, true);
|
642
|
-
};
|
418
|
+
|
419
|
+
function P(e) {
|
420
|
+
return async t => {
|
421
|
+
if (!(t.prototype instanceof o.Koatty)) throw new Error(`class ${t.name} does not inherit from Koatty`);
|
422
|
+
return await S(t, e, !0);
|
423
|
+
};
|
643
424
|
}
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
function ComponentScan(scanPath) {
|
652
|
-
return (target) => {
|
653
|
-
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
654
|
-
throw new Error(`class does not inherit from Koatty`);
|
655
|
-
}
|
656
|
-
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
657
|
-
koatty_container.IOC.saveClassMetadata(koatty_container.TAGGED_CLS, COMPONENT_SCAN, scanPath, target);
|
658
|
-
};
|
425
|
+
|
426
|
+
function b(e) {
|
427
|
+
return r => {
|
428
|
+
if (!(r.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
|
429
|
+
e = e !== null && e !== void 0 ? e : "";
|
430
|
+
t.IOC.saveClassMetadata(t.TAGGED_CLS, E, e, r);
|
431
|
+
};
|
659
432
|
}
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
function ConfigurationScan(scanPath) {
|
668
|
-
return (target) => {
|
669
|
-
if (!(target.prototype instanceof koatty_core.Koatty)) {
|
670
|
-
throw new Error(`class does not inherit from Koatty`);
|
671
|
-
}
|
672
|
-
scanPath = scanPath !== null && scanPath !== void 0 ? scanPath : '';
|
673
|
-
koatty_container.IOC.saveClassMetadata(koatty_container.TAGGED_CLS, CONFIGURATION_SCAN, scanPath, target);
|
674
|
-
};
|
433
|
+
|
434
|
+
function A(e) {
|
435
|
+
return r => {
|
436
|
+
if (!(r.prototype instanceof o.Koatty)) throw new Error(`class does not inherit from Koatty`);
|
437
|
+
e = e !== null && e !== void 0 ? e : "";
|
438
|
+
t.IOC.saveClassMetadata(t.TAGGED_CLS, O, e, r);
|
439
|
+
};
|
675
440
|
}
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
* export function TestDecorator(): ClassDecorator {
|
680
|
-
* return (target: Function) => {
|
681
|
-
* BindEventHook(AppEvent.appBoot, (app: KoattyApplication) => {
|
682
|
-
* // todo
|
683
|
-
* return Promise.resolve();
|
684
|
-
* }, target)
|
685
|
-
* }
|
686
|
-
* }
|
687
|
-
* @param {AppEvent} eventName
|
688
|
-
* @param {EventHookFunc} eventFunc
|
689
|
-
* @param {any} target
|
690
|
-
* @return {*}
|
691
|
-
*/
|
692
|
-
function BindEventHook(eventName, eventFunc, target) {
|
693
|
-
koatty_container.IOC.attachClassMetadata(koatty_container.TAGGED_CLS, eventName, eventFunc, target);
|
441
|
+
|
442
|
+
function H(e, o, r) {
|
443
|
+
t.IOC.attachClassMetadata(t.TAGGED_CLS, e, o, r);
|
694
444
|
}
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
if (
|
710
|
-
|
711
|
-
|
712
|
-
const app = Reflect.construct(target, []);
|
713
|
-
// unittest does not print startup logs
|
714
|
-
if (isUTRuntime) {
|
715
|
-
app.silent = true;
|
716
|
-
Logger.enable(false);
|
717
|
-
}
|
718
|
-
try {
|
719
|
-
if (!app.silent)
|
720
|
-
Logger.Log("Koatty", LOGO);
|
721
|
-
if (!(app instanceof koatty_core.Koatty)) {
|
722
|
-
throw new Error(`class ${target.name} does not inherit from Koatty`);
|
723
|
-
}
|
724
|
-
// Initialize env
|
725
|
-
Loader.initialize(app);
|
726
|
-
// exec bootFunc
|
727
|
-
if (koatty_lib.Helper.isFunction(bootFunc)) {
|
728
|
-
Logger.Log('Koatty', '', 'Execute bootFunc ...');
|
729
|
-
await bootFunc(app);
|
730
|
-
}
|
731
|
-
// Set IOC.app
|
732
|
-
koatty_container.IOC.setApp(app);
|
733
|
-
// Check all bean
|
734
|
-
Logger.Log('Koatty', '', 'ComponentScan ...');
|
735
|
-
Loader.CheckAllComponents(app, target);
|
736
|
-
// Load App event hooks
|
737
|
-
Loader.LoadAppEventHooks(app, target);
|
738
|
-
Logger.Log('Koatty', '', 'Emit App Boot ...');
|
739
|
-
await asyncEvent(app, "appBoot" /* AppEvent.appBoot */);
|
740
|
-
// Load All components
|
741
|
-
await Loader.LoadAllComponents(app, target);
|
742
|
-
// Emit app ready event
|
743
|
-
Logger.Log('Koatty', '', 'Emit App Ready ...');
|
744
|
-
await asyncEvent(app, "appReady" /* AppEvent.appReady */);
|
745
|
-
if (!isUTRuntime) {
|
746
|
-
// Start Server
|
747
|
-
app.listen(listenCallback);
|
748
|
-
}
|
749
|
-
return app;
|
750
|
-
}
|
751
|
-
catch (err) {
|
752
|
-
Logger.Error(err);
|
753
|
-
process.exit();
|
754
|
-
}
|
755
|
-
};
|
756
|
-
/**
|
757
|
-
* Listening callback function
|
758
|
-
*
|
759
|
-
* @param {Koatty} app
|
760
|
-
* @returns {*}
|
761
|
-
*/
|
762
|
-
const listenCallback = (app) => {
|
763
|
-
let servers = [];
|
764
|
-
if (!Array.isArray(app.server)) {
|
765
|
-
servers = [app.server];
|
766
|
-
}
|
767
|
-
else {
|
768
|
-
servers = app.server;
|
445
|
+
|
446
|
+
const S = async function(e, r, n = !1) {
|
447
|
+
L();
|
448
|
+
const s = v();
|
449
|
+
if (!n && s) return;
|
450
|
+
const i = Reflect.construct(e, []);
|
451
|
+
if (s) {
|
452
|
+
i.silent = !0;
|
453
|
+
g.enable(!1);
|
454
|
+
}
|
455
|
+
try {
|
456
|
+
if (!i.silent) g.Log("Koatty", w);
|
457
|
+
if (!(i instanceof o.Koatty)) throw new Error(`class ${e.name} does not inherit from Koatty`);
|
458
|
+
Loader.initialize(i);
|
459
|
+
if (a.Helper.isFunction(r)) {
|
460
|
+
g.Log("Koatty", "", "Execute bootFunc ...");
|
461
|
+
await r(i);
|
769
462
|
}
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
if (
|
780
|
-
|
781
|
-
|
782
|
-
|
463
|
+
t.IOC.setApp(i);
|
464
|
+
g.Log("Koatty", "", "ComponentScan ...");
|
465
|
+
Loader.CheckAllComponents(i, e);
|
466
|
+
Loader.LoadAppEventHooks(i, e);
|
467
|
+
g.Log("Koatty", "", "Emit App Boot ...");
|
468
|
+
await o.asyncEvent(i, "appBoot");
|
469
|
+
await Loader.LoadAllComponents(i, e);
|
470
|
+
g.Log("Koatty", "", "Emit App Ready ...");
|
471
|
+
await o.asyncEvent(i, "appReady");
|
472
|
+
if (!s) i.listen(M);
|
473
|
+
return i;
|
474
|
+
} catch (e) {
|
475
|
+
g.Error(e);
|
476
|
+
process.exit();
|
477
|
+
}
|
783
478
|
};
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
return event.removeAllListeners(eventName);
|
479
|
+
|
480
|
+
const M = e => {
|
481
|
+
let t = [];
|
482
|
+
if (!Array.isArray(e.server)) t = [ e.server ]; else t = e.server;
|
483
|
+
g.Log("Koatty", "", "====================================");
|
484
|
+
g.Log("Koatty", "", `Nodejs Version: ${process.version}`);
|
485
|
+
g.Log("Koatty", "", `Koatty Version: v${y}`);
|
486
|
+
g.Log("Koatty", "", `App Environment: ${e.env}`);
|
487
|
+
t.forEach((e => {
|
488
|
+
g.Log("Koatty", "", `Server: ${e.options.protocol.toUpperCase()} running at ${e.options.protocol === "http2" ? "https" : e.options.protocol}://${e.options.hostname || "127.0.0.1"}:${e.options.port}/`);
|
489
|
+
}));
|
490
|
+
g.Log("Koatty", "", "====================================");
|
491
|
+
if (e.appDebug) g.Warn(`Running in debug mode.`);
|
492
|
+
Loader.SetLogger(e);
|
799
493
|
};
|
800
494
|
|
801
495
|
Object.defineProperty(exports, "Config", {
|
802
|
-
enumerable:
|
803
|
-
get: function
|
496
|
+
enumerable: !0,
|
497
|
+
get: function() {
|
498
|
+
return e.Config;
|
499
|
+
}
|
804
500
|
});
|
501
|
+
|
805
502
|
Object.defineProperty(exports, "Helper", {
|
806
|
-
enumerable:
|
807
|
-
get: function
|
503
|
+
enumerable: !0,
|
504
|
+
get: function() {
|
505
|
+
return a.Helper;
|
506
|
+
}
|
808
507
|
});
|
809
|
-
|
810
|
-
exports.
|
811
|
-
|
812
|
-
exports.
|
813
|
-
|
814
|
-
exports.
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
508
|
+
|
509
|
+
exports.BindEventHook = H;
|
510
|
+
|
511
|
+
exports.Bootstrap = I;
|
512
|
+
|
513
|
+
exports.ComponentScan = b;
|
514
|
+
|
515
|
+
exports.ConfigurationScan = A;
|
516
|
+
|
517
|
+
exports.ExecBootStrap = P;
|
518
|
+
|
519
|
+
exports.Logger = g;
|
520
|
+
|
521
|
+
Object.keys(t).forEach((function(e) {
|
522
|
+
if (e !== "default" && !Object.prototype.hasOwnProperty.call(exports, e)) Object.defineProperty(exports, e, {
|
523
|
+
enumerable: !0,
|
524
|
+
get: function() {
|
525
|
+
return t[e];
|
526
|
+
}
|
819
527
|
});
|
820
|
-
});
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
528
|
+
}));
|
529
|
+
|
530
|
+
Object.keys(o).forEach((function(e) {
|
531
|
+
if (e !== "default" && !Object.prototype.hasOwnProperty.call(exports, e)) Object.defineProperty(exports, e, {
|
532
|
+
enumerable: !0,
|
533
|
+
get: function() {
|
534
|
+
return o[e];
|
535
|
+
}
|
825
536
|
});
|
826
|
-
});
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
537
|
+
}));
|
538
|
+
|
539
|
+
Object.keys(r).forEach((function(e) {
|
540
|
+
if (e !== "default" && !Object.prototype.hasOwnProperty.call(exports, e)) Object.defineProperty(exports, e, {
|
541
|
+
enumerable: !0,
|
542
|
+
get: function() {
|
543
|
+
return r[e];
|
544
|
+
}
|
831
545
|
});
|
832
|
-
});
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
546
|
+
}));
|
547
|
+
|
548
|
+
Object.keys(n).forEach((function(e) {
|
549
|
+
if (e !== "default" && !Object.prototype.hasOwnProperty.call(exports, e)) Object.defineProperty(exports, e, {
|
550
|
+
enumerable: !0,
|
551
|
+
get: function() {
|
552
|
+
return n[e];
|
553
|
+
}
|
837
554
|
});
|
838
|
-
});
|
555
|
+
}));
|