koatty 3.9.5 → 3.10.1
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/.vscode/settings.json +4 -0
- package/CHANGELOG.md +22 -0
- package/README.md +2 -0
- package/dist/README.md +2 -0
- package/dist/index.d.ts +11 -11
- package/dist/index.js +66 -35
- package/dist/index.mjs +67 -36
- package/dist/package.json +3 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,28 @@
|
|
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.1](https://github.com/thinkkoa/koatty/compare/v3.10.0...v3.10.1) (2023-11-09)
|
6
|
+
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* jsdoc ([993970e](https://github.com/thinkkoa/koatty/commit/993970e77dab26af1b81e7d2abfeac93263648ae))
|
11
|
+
* readme ([73078be](https://github.com/thinkkoa/koatty/commit/73078be36cc7a89767ded165dc91a7b3f11fd228))
|
12
|
+
|
13
|
+
## [3.10.0](https://github.com/thinkkoa/koatty/compare/v3.9.5...v3.10.0) (2023-11-08)
|
14
|
+
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* add app event bind ([66e7a48](https://github.com/thinkkoa/koatty/commit/66e7a488c2aa833e37e1418a9d17c91b0872d255))
|
19
|
+
* Custom decorator based on app events ([aa9d96c](https://github.com/thinkkoa/koatty/commit/aa9d96c8bda8364793d868c20eca5d479acb4f88))
|
20
|
+
|
21
|
+
|
22
|
+
### Bug Fixes
|
23
|
+
|
24
|
+
* key is null ([d851dc5](https://github.com/thinkkoa/koatty/commit/d851dc525933de9225ddf43bcbedc2ac29922648))
|
25
|
+
* readme ([84ed9f4](https://github.com/thinkkoa/koatty/commit/84ed9f4261d9c338c1a70d685f3b44deb35a40ee))
|
26
|
+
|
5
27
|
### [3.9.5](https://github.com/thinkkoa/koatty/compare/v3.9.4...v3.9.5) (2023-09-12)
|
6
28
|
|
7
29
|
|
package/README.md
CHANGED
@@ -12,6 +12,7 @@ Use Typescript's decorator implement IOC and AOP.
|
|
12
12
|
* Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
|
13
13
|
* `@ExceptionHandler()` Register global exception handling
|
14
14
|
* graceful shutdown and pre-exit event
|
15
|
+
* custom decorator based on app events
|
15
16
|
|
16
17
|
|
17
18
|
## Documentation
|
@@ -144,6 +145,7 @@ if you use vscode , edit the `.vscode/launch.json` , like this:
|
|
144
145
|
"sourceMaps": true,
|
145
146
|
"cwd": "${workspaceRoot}",
|
146
147
|
"protocol": "inspector",
|
148
|
+
"outputCapture": "std",
|
147
149
|
"internalConsoleOptions": "neverOpen"
|
148
150
|
}
|
149
151
|
]
|
package/dist/README.md
CHANGED
@@ -12,6 +12,7 @@ Use Typescript's decorator implement IOC and AOP.
|
|
12
12
|
* Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
|
13
13
|
* `@ExceptionHandler()` Register global exception handling
|
14
14
|
* graceful shutdown and pre-exit event
|
15
|
+
* custom decorator based on app events
|
15
16
|
|
16
17
|
|
17
18
|
## Documentation
|
@@ -144,6 +145,7 @@ if you use vscode , edit the `.vscode/launch.json` , like this:
|
|
144
145
|
"sourceMaps": true,
|
145
146
|
"cwd": "${workspaceRoot}",
|
146
147
|
"protocol": "inspector",
|
148
|
+
"outputCapture": "std",
|
147
149
|
"internalConsoleOptions": "neverOpen"
|
148
150
|
}
|
149
151
|
]
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-09
|
3
|
+
* @Date: 2023-11-09 23:03:18
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
|
+
import { AppEvent } from 'koatty_core';
|
8
9
|
import { Config } from 'koatty_config';
|
10
|
+
import { EventHookFunc } from 'koatty_core';
|
9
11
|
import { Helper } from 'koatty_lib';
|
10
12
|
import { Koatty } from 'koatty_core';
|
11
13
|
import { KoattyContext } from 'koatty_core';
|
@@ -31,8 +33,6 @@ export declare interface ApiOutput {
|
|
31
33
|
data: any;
|
32
34
|
}
|
33
35
|
|
34
|
-
export declare type AppBootHookFunc = (app: Koatty) => Promise<any>;
|
35
|
-
|
36
36
|
/**
|
37
37
|
* Base controller
|
38
38
|
*
|
@@ -100,22 +100,22 @@ export declare class BaseService implements IService {
|
|
100
100
|
}
|
101
101
|
|
102
102
|
/**
|
103
|
-
* bind
|
103
|
+
* @description: bind App event hook func
|
104
104
|
* example:
|
105
105
|
* export function TestDecorator(): ClassDecorator {
|
106
|
-
* return (target:
|
107
|
-
*
|
106
|
+
* return (target: Function) => {
|
107
|
+
* BindEventHook(AppEvent.appBoot, (app: Koatty) => {
|
108
108
|
* // todo
|
109
109
|
* return Promise.resolve();
|
110
110
|
* }, target)
|
111
111
|
* }
|
112
112
|
* }
|
113
|
-
*
|
114
|
-
* @
|
115
|
-
* @param {
|
116
|
-
* @
|
113
|
+
* @param {AppEvent} eventName
|
114
|
+
* @param {EventHookFunc} eventFunc
|
115
|
+
* @param {any} target
|
116
|
+
* @return {*}
|
117
117
|
*/
|
118
|
-
export declare function
|
118
|
+
export declare function BindEventHook(eventName: AppEvent, eventFunc: EventHookFunc, target: any): void;
|
119
119
|
|
120
120
|
/**
|
121
121
|
* Bootstrap application
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-09
|
3
|
+
* @Date: 2023-11-09 23:03:05
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -152,7 +152,6 @@ function formatApiData(msg, data, defaultCode) {
|
|
152
152
|
*/
|
153
153
|
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
154
154
|
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
155
|
-
const APP_BOOT_HOOK = "APP_BOOT_HOOK";
|
156
155
|
// tslint:disable: no-irregular-whitespace
|
157
156
|
const LOGO = `
|
158
157
|
|
@@ -294,10 +293,10 @@ class Loader {
|
|
294
293
|
// define path
|
295
294
|
const rootPath = app.rootPath || process.cwd();
|
296
295
|
const appPath = app.appPath || path__namespace.resolve(rootPath, env.indexOf('ts-node') > -1 ? 'src' : 'dist');
|
297
|
-
const
|
296
|
+
const koattyPath = path__namespace.resolve(__dirname, '..');
|
298
297
|
koatty_lib.Helper.define(app, 'rootPath', rootPath);
|
299
298
|
koatty_lib.Helper.define(app, 'appPath', appPath);
|
300
|
-
koatty_lib.Helper.define(app, '
|
299
|
+
koatty_lib.Helper.define(app, 'koattyPath', koattyPath);
|
301
300
|
//
|
302
301
|
if (koatty_lib.Helper.isEmpty(app.name)) {
|
303
302
|
const pkg = koatty_lib.Helper.safeRequire(`${path__namespace.dirname(appPath)}/package.json`);
|
@@ -308,12 +307,11 @@ class Loader {
|
|
308
307
|
}
|
309
308
|
process.env.ROOT_PATH = rootPath;
|
310
309
|
process.env.APP_PATH = appPath;
|
311
|
-
process.env.
|
310
|
+
process.env.KOATTY_PATH = koattyPath;
|
312
311
|
// Compatible with old version, will be deprecated
|
313
312
|
koatty_lib.Helper.define(app, 'prevent', koatty_exception.prevent);
|
314
|
-
koatty_lib.Helper.define(app, '
|
315
|
-
|
316
|
-
koatty_lib.Helper.define(app, 'think_path', thinkPath);
|
313
|
+
koatty_lib.Helper.define(app, 'thinkPath', koattyPath);
|
314
|
+
process.env.THINK_PATH = koattyPath;
|
317
315
|
}
|
318
316
|
/**
|
319
317
|
* Get component metadata
|
@@ -411,20 +409,49 @@ class Loader {
|
|
411
409
|
}
|
412
410
|
}
|
413
411
|
/**
|
414
|
-
* Load app
|
412
|
+
* Load app event hook funcs
|
415
413
|
*
|
416
414
|
* @static
|
417
415
|
* @param {Koatty} app
|
418
416
|
* @param {*} target
|
419
417
|
* @memberof Loader
|
420
418
|
*/
|
421
|
-
static
|
422
|
-
const
|
423
|
-
|
424
|
-
funcs
|
425
|
-
|
426
|
-
|
427
|
-
|
419
|
+
static LoadAppEventHooks(app, target) {
|
420
|
+
const eventFuncs = new Map();
|
421
|
+
for (const event of koatty_core.AppEventArr) {
|
422
|
+
let funcs;
|
423
|
+
switch (event) {
|
424
|
+
case "appBoot" /* AppEvent.appBoot */:
|
425
|
+
funcs = koatty_container.IOCContainer.getClassMetadata(koatty_container.TAGGED_CLS, "appBoot" /* AppEvent.appBoot */, target);
|
426
|
+
if (koatty_lib.Helper.isArray(funcs)) {
|
427
|
+
eventFuncs.set("appBoot" /* AppEvent.appBoot */, funcs);
|
428
|
+
}
|
429
|
+
break;
|
430
|
+
case "appReady" /* AppEvent.appReady */:
|
431
|
+
funcs = koatty_container.IOCContainer.getClassMetadata(koatty_container.TAGGED_CLS, "appReady" /* AppEvent.appReady */, target);
|
432
|
+
if (koatty_lib.Helper.isArray(funcs)) {
|
433
|
+
eventFuncs.set("appReady" /* AppEvent.appReady */, funcs);
|
434
|
+
}
|
435
|
+
break;
|
436
|
+
case "appStart" /* AppEvent.appStart */:
|
437
|
+
funcs = koatty_container.IOCContainer.getClassMetadata(koatty_container.TAGGED_CLS, "appStart" /* AppEvent.appStart */, target);
|
438
|
+
if (koatty_lib.Helper.isArray(funcs)) {
|
439
|
+
eventFuncs.set("appStart" /* AppEvent.appStart */, funcs);
|
440
|
+
}
|
441
|
+
break;
|
442
|
+
case "appStop" /* AppEvent.appStop */:
|
443
|
+
funcs = koatty_container.IOCContainer.getClassMetadata(koatty_container.TAGGED_CLS, "appStop" /* AppEvent.appStop */, target);
|
444
|
+
if (koatty_lib.Helper.isArray(funcs)) {
|
445
|
+
eventFuncs.set("appStop" /* AppEvent.appStop */, funcs);
|
446
|
+
}
|
447
|
+
break;
|
448
|
+
}
|
449
|
+
}
|
450
|
+
// loop event emit
|
451
|
+
for (const [event, funcs] of eventFuncs) {
|
452
|
+
for (const func of funcs) {
|
453
|
+
app.once(event, () => func(app));
|
454
|
+
}
|
428
455
|
}
|
429
456
|
}
|
430
457
|
/**
|
@@ -438,7 +465,7 @@ class Loader {
|
|
438
465
|
static LoadConfigs(app, loadPath) {
|
439
466
|
const frameConfig = {};
|
440
467
|
// Logger.Debug(`Load configuration path: ${app.thinkPath}/config`);
|
441
|
-
koatty_loader.Load(["./config"], app.
|
468
|
+
koatty_loader.Load(["./config"], app.koattyPath, function (name, path, exp) {
|
442
469
|
frameConfig[name] = exp;
|
443
470
|
});
|
444
471
|
if (koatty_lib.Helper.isArray(loadPath)) {
|
@@ -462,7 +489,7 @@ class Loader {
|
|
462
489
|
middlewareConf = { config: {}, list: [] };
|
463
490
|
}
|
464
491
|
//Mount default middleware
|
465
|
-
koatty_loader.Load(loadPath || ["./middleware"], app.
|
492
|
+
koatty_loader.Load(loadPath || ["./middleware"], app.koattyPath);
|
466
493
|
//Mount application middleware
|
467
494
|
// const middleware: any = {};
|
468
495
|
const appMiddleware = koatty_container.IOCContainer.listClass("MIDDLEWARE") ?? [];
|
@@ -602,8 +629,12 @@ class Loader {
|
|
602
629
|
const pluginConfList = pluginsConf.list;
|
603
630
|
for (const key of pluginConfList) {
|
604
631
|
const handle = koatty_container.IOCContainer.get(key, "COMPONENT");
|
632
|
+
if (!handle) {
|
633
|
+
Logger.Error(`Plugin ${key} load error.`);
|
634
|
+
continue;
|
635
|
+
}
|
605
636
|
if (!koatty_lib.Helper.isFunction(handle.run)) {
|
606
|
-
Logger.Error(`
|
637
|
+
Logger.Error(`Plugin ${key} must be implements method 'run'.`);
|
607
638
|
continue;
|
608
639
|
}
|
609
640
|
if (pluginsConf.config[key] === false) {
|
@@ -616,7 +647,7 @@ class Loader {
|
|
616
647
|
}
|
617
648
|
}
|
618
649
|
|
619
|
-
var version = "3.
|
650
|
+
var version = "3.10.1";
|
620
651
|
var engines = {
|
621
652
|
node: ">12.0.0"
|
622
653
|
};
|
@@ -713,10 +744,10 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
713
744
|
// configuration metadata
|
714
745
|
const configurationMetas = Loader.GetConfigurationMetas(app, target);
|
715
746
|
Loader.LoadConfigs(app, configurationMetas);
|
716
|
-
// Load App
|
717
|
-
Loader.
|
718
|
-
|
719
|
-
await asyncEvent(app,
|
747
|
+
// Load App event hooks
|
748
|
+
Loader.LoadAppEventHooks(app, target);
|
749
|
+
Logger.Log('Koatty', '', 'Emit App Boot ...');
|
750
|
+
await asyncEvent(app, "appBoot" /* AppEvent.appBoot */);
|
720
751
|
// Load Plugin
|
721
752
|
Logger.Log('Koatty', '', 'Load Plugins ...');
|
722
753
|
await Loader.LoadPlugins(app);
|
@@ -740,7 +771,7 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
740
771
|
koatty_lib.Helper.define(app, "router", koatty_serve.NewRouter(app));
|
741
772
|
// Emit app ready event
|
742
773
|
Logger.Log('Koatty', '', 'Emit App Ready ...');
|
743
|
-
await asyncEvent(app,
|
774
|
+
await asyncEvent(app, "appReady" /* AppEvent.appReady */);
|
744
775
|
// Load Routers
|
745
776
|
Logger.Log('Koatty', '', 'Load Routers ...');
|
746
777
|
app.router.LoadRouter(controllers);
|
@@ -857,23 +888,23 @@ function ConfigurationScan(scanPath) {
|
|
857
888
|
};
|
858
889
|
}
|
859
890
|
/**
|
860
|
-
* bind
|
891
|
+
* @description: bind App event hook func
|
861
892
|
* example:
|
862
893
|
* export function TestDecorator(): ClassDecorator {
|
863
|
-
* return (target:
|
864
|
-
*
|
894
|
+
* return (target: Function) => {
|
895
|
+
* BindEventHook(AppEvent.appBoot, (app: Koatty) => {
|
865
896
|
* // todo
|
866
897
|
* return Promise.resolve();
|
867
898
|
* }, target)
|
868
899
|
* }
|
869
900
|
* }
|
870
|
-
*
|
871
|
-
* @
|
872
|
-
* @param {
|
873
|
-
* @
|
901
|
+
* @param {AppEvent} eventName
|
902
|
+
* @param {EventHookFunc} eventFunc
|
903
|
+
* @param {any} target
|
904
|
+
* @return {*}
|
874
905
|
*/
|
875
|
-
function
|
876
|
-
koatty_container.IOCContainer.attachClassMetadata(koatty_container.TAGGED_CLS,
|
906
|
+
function BindEventHook(eventName, eventFunc, target) {
|
907
|
+
koatty_container.IOCContainer.attachClassMetadata(koatty_container.TAGGED_CLS, eventName, eventFunc, target);
|
877
908
|
}
|
878
909
|
|
879
910
|
/**
|
@@ -993,7 +1024,7 @@ Object.defineProperty(exports, 'Helper', {
|
|
993
1024
|
});
|
994
1025
|
exports.BaseController = BaseController;
|
995
1026
|
exports.BaseService = BaseService;
|
996
|
-
exports.
|
1027
|
+
exports.BindEventHook = BindEventHook;
|
997
1028
|
exports.Bootstrap = Bootstrap;
|
998
1029
|
exports.Component = Component;
|
999
1030
|
exports.ComponentScan = ComponentScan;
|
package/dist/index.mjs
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2023-09
|
3
|
+
* @Date: 2023-11-09 23:03:05
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
8
|
import 'reflect-metadata';
|
9
|
-
import { Koatty } from 'koatty_core';
|
9
|
+
import { AppEventArr, Koatty } from 'koatty_core';
|
10
10
|
export * from 'koatty_core';
|
11
11
|
import * as path from 'path';
|
12
12
|
import { Load } from 'koatty_loader';
|
@@ -138,7 +138,6 @@ function formatApiData(msg, data, defaultCode) {
|
|
138
138
|
*/
|
139
139
|
const COMPONENT_SCAN = 'COMPONENT_SCAN';
|
140
140
|
const CONFIGURATION_SCAN = 'CONFIGURATION_SCAN';
|
141
|
-
const APP_BOOT_HOOK = "APP_BOOT_HOOK";
|
142
141
|
// tslint:disable: no-irregular-whitespace
|
143
142
|
const LOGO = `
|
144
143
|
|
@@ -280,10 +279,10 @@ class Loader {
|
|
280
279
|
// define path
|
281
280
|
const rootPath = app.rootPath || process.cwd();
|
282
281
|
const appPath = app.appPath || path.resolve(rootPath, env.indexOf('ts-node') > -1 ? 'src' : 'dist');
|
283
|
-
const
|
282
|
+
const koattyPath = path.resolve(__dirname, '..');
|
284
283
|
Helper.define(app, 'rootPath', rootPath);
|
285
284
|
Helper.define(app, 'appPath', appPath);
|
286
|
-
Helper.define(app, '
|
285
|
+
Helper.define(app, 'koattyPath', koattyPath);
|
287
286
|
//
|
288
287
|
if (Helper.isEmpty(app.name)) {
|
289
288
|
const pkg = Helper.safeRequire(`${path.dirname(appPath)}/package.json`);
|
@@ -294,12 +293,11 @@ class Loader {
|
|
294
293
|
}
|
295
294
|
process.env.ROOT_PATH = rootPath;
|
296
295
|
process.env.APP_PATH = appPath;
|
297
|
-
process.env.
|
296
|
+
process.env.KOATTY_PATH = koattyPath;
|
298
297
|
// Compatible with old version, will be deprecated
|
299
298
|
Helper.define(app, 'prevent', prevent);
|
300
|
-
Helper.define(app, '
|
301
|
-
|
302
|
-
Helper.define(app, 'think_path', thinkPath);
|
299
|
+
Helper.define(app, 'thinkPath', koattyPath);
|
300
|
+
process.env.THINK_PATH = koattyPath;
|
303
301
|
}
|
304
302
|
/**
|
305
303
|
* Get component metadata
|
@@ -397,20 +395,49 @@ class Loader {
|
|
397
395
|
}
|
398
396
|
}
|
399
397
|
/**
|
400
|
-
* Load app
|
398
|
+
* Load app event hook funcs
|
401
399
|
*
|
402
400
|
* @static
|
403
401
|
* @param {Koatty} app
|
404
402
|
* @param {*} target
|
405
403
|
* @memberof Loader
|
406
404
|
*/
|
407
|
-
static
|
408
|
-
const
|
409
|
-
|
410
|
-
funcs
|
411
|
-
|
412
|
-
|
413
|
-
|
405
|
+
static LoadAppEventHooks(app, target) {
|
406
|
+
const eventFuncs = new Map();
|
407
|
+
for (const event of AppEventArr) {
|
408
|
+
let funcs;
|
409
|
+
switch (event) {
|
410
|
+
case "appBoot" /* AppEvent.appBoot */:
|
411
|
+
funcs = IOCContainer.getClassMetadata(TAGGED_CLS, "appBoot" /* AppEvent.appBoot */, target);
|
412
|
+
if (Helper.isArray(funcs)) {
|
413
|
+
eventFuncs.set("appBoot" /* AppEvent.appBoot */, funcs);
|
414
|
+
}
|
415
|
+
break;
|
416
|
+
case "appReady" /* AppEvent.appReady */:
|
417
|
+
funcs = IOCContainer.getClassMetadata(TAGGED_CLS, "appReady" /* AppEvent.appReady */, target);
|
418
|
+
if (Helper.isArray(funcs)) {
|
419
|
+
eventFuncs.set("appReady" /* AppEvent.appReady */, funcs);
|
420
|
+
}
|
421
|
+
break;
|
422
|
+
case "appStart" /* AppEvent.appStart */:
|
423
|
+
funcs = IOCContainer.getClassMetadata(TAGGED_CLS, "appStart" /* AppEvent.appStart */, target);
|
424
|
+
if (Helper.isArray(funcs)) {
|
425
|
+
eventFuncs.set("appStart" /* AppEvent.appStart */, funcs);
|
426
|
+
}
|
427
|
+
break;
|
428
|
+
case "appStop" /* AppEvent.appStop */:
|
429
|
+
funcs = IOCContainer.getClassMetadata(TAGGED_CLS, "appStop" /* AppEvent.appStop */, target);
|
430
|
+
if (Helper.isArray(funcs)) {
|
431
|
+
eventFuncs.set("appStop" /* AppEvent.appStop */, funcs);
|
432
|
+
}
|
433
|
+
break;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
// loop event emit
|
437
|
+
for (const [event, funcs] of eventFuncs) {
|
438
|
+
for (const func of funcs) {
|
439
|
+
app.once(event, () => func(app));
|
440
|
+
}
|
414
441
|
}
|
415
442
|
}
|
416
443
|
/**
|
@@ -424,7 +451,7 @@ class Loader {
|
|
424
451
|
static LoadConfigs(app, loadPath) {
|
425
452
|
const frameConfig = {};
|
426
453
|
// Logger.Debug(`Load configuration path: ${app.thinkPath}/config`);
|
427
|
-
Load(["./config"], app.
|
454
|
+
Load(["./config"], app.koattyPath, function (name, path, exp) {
|
428
455
|
frameConfig[name] = exp;
|
429
456
|
});
|
430
457
|
if (Helper.isArray(loadPath)) {
|
@@ -448,7 +475,7 @@ class Loader {
|
|
448
475
|
middlewareConf = { config: {}, list: [] };
|
449
476
|
}
|
450
477
|
//Mount default middleware
|
451
|
-
Load(loadPath || ["./middleware"], app.
|
478
|
+
Load(loadPath || ["./middleware"], app.koattyPath);
|
452
479
|
//Mount application middleware
|
453
480
|
// const middleware: any = {};
|
454
481
|
const appMiddleware = IOCContainer.listClass("MIDDLEWARE") ?? [];
|
@@ -588,8 +615,12 @@ class Loader {
|
|
588
615
|
const pluginConfList = pluginsConf.list;
|
589
616
|
for (const key of pluginConfList) {
|
590
617
|
const handle = IOCContainer.get(key, "COMPONENT");
|
618
|
+
if (!handle) {
|
619
|
+
Logger.Error(`Plugin ${key} load error.`);
|
620
|
+
continue;
|
621
|
+
}
|
591
622
|
if (!Helper.isFunction(handle.run)) {
|
592
|
-
Logger.Error(`
|
623
|
+
Logger.Error(`Plugin ${key} must be implements method 'run'.`);
|
593
624
|
continue;
|
594
625
|
}
|
595
626
|
if (pluginsConf.config[key] === false) {
|
@@ -602,7 +633,7 @@ class Loader {
|
|
602
633
|
}
|
603
634
|
}
|
604
635
|
|
605
|
-
var version = "3.
|
636
|
+
var version = "3.10.1";
|
606
637
|
var engines = {
|
607
638
|
node: ">12.0.0"
|
608
639
|
};
|
@@ -699,10 +730,10 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
699
730
|
// configuration metadata
|
700
731
|
const configurationMetas = Loader.GetConfigurationMetas(app, target);
|
701
732
|
Loader.LoadConfigs(app, configurationMetas);
|
702
|
-
// Load App
|
703
|
-
Loader.
|
704
|
-
|
705
|
-
await asyncEvent(app,
|
733
|
+
// Load App event hooks
|
734
|
+
Loader.LoadAppEventHooks(app, target);
|
735
|
+
Logger.Log('Koatty', '', 'Emit App Boot ...');
|
736
|
+
await asyncEvent(app, "appBoot" /* AppEvent.appBoot */);
|
706
737
|
// Load Plugin
|
707
738
|
Logger.Log('Koatty', '', 'Load Plugins ...');
|
708
739
|
await Loader.LoadPlugins(app);
|
@@ -726,7 +757,7 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
726
757
|
Helper.define(app, "router", NewRouter(app));
|
727
758
|
// Emit app ready event
|
728
759
|
Logger.Log('Koatty', '', 'Emit App Ready ...');
|
729
|
-
await asyncEvent(app,
|
760
|
+
await asyncEvent(app, "appReady" /* AppEvent.appReady */);
|
730
761
|
// Load Routers
|
731
762
|
Logger.Log('Koatty', '', 'Load Routers ...');
|
732
763
|
app.router.LoadRouter(controllers);
|
@@ -843,23 +874,23 @@ function ConfigurationScan(scanPath) {
|
|
843
874
|
};
|
844
875
|
}
|
845
876
|
/**
|
846
|
-
* bind
|
877
|
+
* @description: bind App event hook func
|
847
878
|
* example:
|
848
879
|
* export function TestDecorator(): ClassDecorator {
|
849
|
-
* return (target:
|
850
|
-
*
|
880
|
+
* return (target: Function) => {
|
881
|
+
* BindEventHook(AppEvent.appBoot, (app: Koatty) => {
|
851
882
|
* // todo
|
852
883
|
* return Promise.resolve();
|
853
884
|
* }, target)
|
854
885
|
* }
|
855
886
|
* }
|
856
|
-
*
|
857
|
-
* @
|
858
|
-
* @param {
|
859
|
-
* @
|
887
|
+
* @param {AppEvent} eventName
|
888
|
+
* @param {EventHookFunc} eventFunc
|
889
|
+
* @param {any} target
|
890
|
+
* @return {*}
|
860
891
|
*/
|
861
|
-
function
|
862
|
-
IOCContainer.attachClassMetadata(TAGGED_CLS,
|
892
|
+
function BindEventHook(eventName, eventFunc, target) {
|
893
|
+
IOCContainer.attachClassMetadata(TAGGED_CLS, eventName, eventFunc, target);
|
863
894
|
}
|
864
895
|
|
865
896
|
/**
|
@@ -965,4 +996,4 @@ class BaseService {
|
|
965
996
|
}
|
966
997
|
}
|
967
998
|
|
968
|
-
export { BaseController, BaseService,
|
999
|
+
export { BaseController, BaseService, BindEventHook, Bootstrap, Component, ComponentScan, ConfigurationScan, Controller, ExecBootStrap, Logger, Middleware, Plugin, Service };
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.10.1",
|
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",
|
@@ -80,8 +80,8 @@
|
|
80
80
|
"dependencies": {
|
81
81
|
"koa": "^2.14.2",
|
82
82
|
"koatty_config": "^1.1.6",
|
83
|
-
"koatty_container": "^1.8.
|
84
|
-
"koatty_core": "^1.
|
83
|
+
"koatty_container": "^1.8.2",
|
84
|
+
"koatty_core": "^1.8.2",
|
85
85
|
"koatty_exception": "^1.2.8",
|
86
86
|
"koatty_lib": "^1.3.4",
|
87
87
|
"koatty_loader": "^1.1.0",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.10.1",
|
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",
|
@@ -80,8 +80,8 @@
|
|
80
80
|
"dependencies": {
|
81
81
|
"koa": "^2.14.2",
|
82
82
|
"koatty_config": "^1.1.6",
|
83
|
-
"koatty_container": "^1.8.
|
84
|
-
"koatty_core": "^1.
|
83
|
+
"koatty_container": "^1.8.2",
|
84
|
+
"koatty_core": "^1.8.2",
|
85
85
|
"koatty_exception": "^1.2.8",
|
86
86
|
"koatty_lib": "^1.3.4",
|
87
87
|
"koatty_loader": "^1.1.0",
|