koatty 3.11.2-6 → 3.11.2-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +4 -74
- package/dist/index.js +51 -171
- package/dist/index.mjs +47 -170
- package/dist/package.json +5 -4
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,19 @@
|
|
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.11.2-8](https://github.com/thinkkoa/koatty/compare/v3.11.2-7...v3.11.2-8) (2024-01-16)
|
6
|
+
|
7
|
+
### [3.11.2-7](https://github.com/thinkkoa/koatty/compare/v3.11.2-6...v3.11.2-7) (2024-01-15)
|
8
|
+
|
9
|
+
|
10
|
+
### Refactor
|
11
|
+
|
12
|
+
* export router interface ([b6bc181](https://github.com/thinkkoa/koatty/commit/b6bc1819ca97817e5c26376a5b4d12c8992bbe62))
|
13
|
+
* output ([286f57a](https://github.com/thinkkoa/koatty/commit/286f57ae7e4133a1bf3c6e3d58c870fb218bd575))
|
14
|
+
* output interface ([53cd320](https://github.com/thinkkoa/koatty/commit/53cd3207ba5db6fc9fa6cf3d94543df208576833))
|
15
|
+
* remove base class ([cebc6d7](https://github.com/thinkkoa/koatty/commit/cebc6d734bae800fe9be3321acef48760210292b))
|
16
|
+
* 调整router、server初始化 ([2af33b8](https://github.com/thinkkoa/koatty/commit/2af33b8df554bfee4bbeac7bcac3d219fd9a7af0))
|
17
|
+
|
5
18
|
### [3.11.2-6](https://github.com/thinkkoa/koatty/compare/v3.11.2-5...v3.11.2-6) (2024-01-14)
|
6
19
|
|
7
20
|
### [3.11.2-5](https://github.com/thinkkoa/koatty/compare/v3.11.2-4...v3.11.2-5) (2024-01-07)
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2024-01-
|
3
|
+
* @Date: 2024-01-16 08:38:27
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -20,7 +20,7 @@ import { Value } from 'koatty_config';
|
|
20
20
|
/**
|
21
21
|
* Interface for Api input
|
22
22
|
*/
|
23
|
-
|
23
|
+
declare interface ApiInput {
|
24
24
|
code?: number;
|
25
25
|
message?: string;
|
26
26
|
data?: any;
|
@@ -29,83 +29,12 @@ export declare interface ApiInput {
|
|
29
29
|
/**
|
30
30
|
* Interface for Api output
|
31
31
|
*/
|
32
|
-
|
32
|
+
declare interface ApiOutput {
|
33
33
|
code: number;
|
34
34
|
message: string;
|
35
35
|
data: any;
|
36
36
|
}
|
37
37
|
|
38
|
-
/**
|
39
|
-
* Base controller
|
40
|
-
*
|
41
|
-
* @export
|
42
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
43
|
-
* @class BaseController
|
44
|
-
* @implements {IController}
|
45
|
-
*/
|
46
|
-
export declare class BaseController implements IController {
|
47
|
-
readonly app: Koatty;
|
48
|
-
readonly ctx: KoattyContext;
|
49
|
-
/**
|
50
|
-
* instance of BaseController.
|
51
|
-
* @param {Koatty} app
|
52
|
-
* @param {KoattyContext} ctx
|
53
|
-
* @memberof BaseController
|
54
|
-
*/
|
55
|
-
/**
|
56
|
-
* init
|
57
|
-
*
|
58
|
-
* @memberof BaseController
|
59
|
-
*/
|
60
|
-
init(...arg: any[]): void;
|
61
|
-
/**
|
62
|
-
* Response to normalize json format content for success
|
63
|
-
*
|
64
|
-
* @deprecated 使用 Output.ok 代替
|
65
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
66
|
-
* @param {*} [data] 待处理的数据
|
67
|
-
* @param {number} [code=200] 错误码,默认0
|
68
|
-
* @returns {*}
|
69
|
-
* @memberof BaseController
|
70
|
-
*/
|
71
|
-
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
72
|
-
/**
|
73
|
-
* Response to normalize json format content for fail
|
74
|
-
*
|
75
|
-
* @deprecated 使用 Output.fail 代替
|
76
|
-
* @param {(string | ApiInput)} msg
|
77
|
-
* @param {*} [data]
|
78
|
-
* @param {number} [code=1]
|
79
|
-
* @returns {*}
|
80
|
-
* @memberof BaseController
|
81
|
-
*/
|
82
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number): void;
|
83
|
-
}
|
84
|
-
|
85
|
-
/**
|
86
|
-
* Base service
|
87
|
-
*
|
88
|
-
* @export
|
89
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
90
|
-
* @class Base
|
91
|
-
*/
|
92
|
-
export declare class BaseService implements IService {
|
93
|
-
readonly app: Koatty;
|
94
|
-
/**
|
95
|
-
* instance of BaseController.
|
96
|
-
* @param {Koatty} app
|
97
|
-
* @param {KoattyContext} ctx
|
98
|
-
* @memberof BaseController
|
99
|
-
*/
|
100
|
-
/**
|
101
|
-
* init
|
102
|
-
*
|
103
|
-
* @protected
|
104
|
-
* @memberof BaseController
|
105
|
-
*/
|
106
|
-
init(...arg: any[]): void;
|
107
|
-
}
|
108
|
-
|
109
38
|
/**
|
110
39
|
* @description: bind App event hook func
|
111
40
|
* example:
|
@@ -312,6 +241,7 @@ export { Value }
|
|
312
241
|
export * from "koatty_container";
|
313
242
|
export * from "koatty_core";
|
314
243
|
export * from "koatty_exception";
|
244
|
+
export * from "koatty_router";
|
315
245
|
export * from "koatty_serve";
|
316
246
|
|
317
247
|
export { }
|
package/dist/index.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2024-01-
|
3
|
+
* @Date: 2024-01-16 08:38:15
|
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_router = require('koatty_router');
|
10
11
|
var koatty_container = require('koatty_container');
|
11
12
|
var koatty_core = require('koatty_core');
|
12
13
|
var koatty_serve = require('koatty_serve');
|
@@ -60,7 +61,7 @@ function TraceHandler(app) {
|
|
60
61
|
* @Usage:
|
61
62
|
* @Author: richen
|
62
63
|
* @Date: 2023-12-09 21:56:32
|
63
|
-
* @LastEditTime:
|
64
|
+
* @LastEditTime: 2024-01-16 01:20:17
|
64
65
|
* @License: BSD (3-Clause)
|
65
66
|
* @Copyright (c): <richenlin(at)gmail.com>
|
66
67
|
*/
|
@@ -100,36 +101,6 @@ function checkClass(fileName, xpath, target, exSet) {
|
|
100
101
|
exSet.add(fileName);
|
101
102
|
return;
|
102
103
|
}
|
103
|
-
/**
|
104
|
-
* Format api interface data format
|
105
|
-
*
|
106
|
-
* @private
|
107
|
-
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
108
|
-
* @param {*} data 待返回的数据
|
109
|
-
* @param {number} defaultCode 默认错误码
|
110
|
-
* @returns {ApiOutput} 格式化之后的接口数据
|
111
|
-
* @memberof BaseController
|
112
|
-
*/
|
113
|
-
function formatApiData(msg, data, defaultCode) {
|
114
|
-
let obj = {
|
115
|
-
code: defaultCode,
|
116
|
-
message: '',
|
117
|
-
data: null,
|
118
|
-
};
|
119
|
-
if (koatty_lib.Helper.isError(msg)) {
|
120
|
-
const { code, message } = msg;
|
121
|
-
obj.code = code || defaultCode;
|
122
|
-
obj.message = message;
|
123
|
-
}
|
124
|
-
else if (koatty_lib.Helper.isObject(msg)) {
|
125
|
-
obj = { ...obj, ...msg };
|
126
|
-
}
|
127
|
-
else {
|
128
|
-
obj.message = msg;
|
129
|
-
obj.data = data;
|
130
|
-
}
|
131
|
-
return obj;
|
132
|
-
}
|
133
104
|
|
134
105
|
/*
|
135
106
|
* @Description: framework logger
|
@@ -171,7 +142,7 @@ function SetLogger(app, config) {
|
|
171
142
|
* @Usage:
|
172
143
|
* @Author: richen
|
173
144
|
* @Date: 2023-12-09 21:56:32
|
174
|
-
* @LastEditTime: 2024-01-
|
145
|
+
* @LastEditTime: 2024-01-16 01:17:46
|
175
146
|
* @License: BSD (3-Clause)
|
176
147
|
* @Copyright (c): <richenlin(at)gmail.com>
|
177
148
|
*/
|
@@ -200,7 +171,7 @@ function Controller(path = "") {
|
|
200
171
|
return (target) => {
|
201
172
|
const identifier = koatty_container.IOCContainer.getIdentifier(target);
|
202
173
|
koatty_container.IOCContainer.saveClass("CONTROLLER", target, identifier);
|
203
|
-
koatty_container.IOCContainer.savePropertyData(
|
174
|
+
koatty_container.IOCContainer.savePropertyData(koatty_router.CONTROLLER_ROUTER, path, target, identifier);
|
204
175
|
};
|
205
176
|
}
|
206
177
|
/**
|
@@ -716,7 +687,7 @@ class Loader {
|
|
716
687
|
}
|
717
688
|
}
|
718
689
|
|
719
|
-
var version = "3.11.2-
|
690
|
+
var version = "3.11.2-8";
|
720
691
|
var engines = {
|
721
692
|
node: ">12.0.0"
|
722
693
|
};
|
@@ -769,7 +740,7 @@ const checkUTRuntime = () => {
|
|
769
740
|
* @Usage:
|
770
741
|
* @Author: richen
|
771
742
|
* @Date: 2021-12-09 21:56:32
|
772
|
-
* @LastEditTime: 2024-01-
|
743
|
+
* @LastEditTime: 2024-01-16 01:06:26
|
773
744
|
* @License: BSD (3-Clause)
|
774
745
|
* @Copyright (c): <richenlin(at)gmail.com>
|
775
746
|
*/
|
@@ -822,6 +793,12 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
822
793
|
Loader.LoadAppEventHooks(app, target);
|
823
794
|
Logger.Log('Koatty', '', 'Emit App Boot ...');
|
824
795
|
await asyncEvent(app, "appBoot" /* AppEvent.appBoot */);
|
796
|
+
// Create Server
|
797
|
+
// app.server = newServe(app);
|
798
|
+
koatty_lib.Helper.define(app, "server", koatty_serve.NewServe(app));
|
799
|
+
// Create router
|
800
|
+
// app.router = newRouter(app);
|
801
|
+
koatty_lib.Helper.define(app, "router", koatty_router.NewRouter(app));
|
825
802
|
// Load Components
|
826
803
|
Logger.Log('Koatty', '', 'Load Components ...');
|
827
804
|
await Loader.LoadComponents(app);
|
@@ -834,18 +811,12 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
834
811
|
// Load Controllers
|
835
812
|
Logger.Log('Koatty', '', 'Load Controllers ...');
|
836
813
|
const controllers = Loader.LoadControllers(app);
|
837
|
-
// Create Server
|
838
|
-
// app.server = newServe(app);
|
839
|
-
koatty_lib.Helper.define(app, "server", koatty_serve.NewServe(app));
|
840
|
-
// Create router
|
841
|
-
// app.router = newRouter(app);
|
842
|
-
koatty_lib.Helper.define(app, "router", koatty_serve.NewRouter(app));
|
843
814
|
// Emit app ready event
|
844
815
|
Logger.Log('Koatty', '', 'Emit App Ready ...');
|
845
816
|
await asyncEvent(app, "appReady" /* AppEvent.appReady */);
|
846
817
|
// Load Routers
|
847
818
|
Logger.Log('Koatty', '', 'Load Routers ...');
|
848
|
-
app.router.LoadRouter(controllers);
|
819
|
+
app.router.LoadRouter(app, controllers);
|
849
820
|
if (!isUTRuntime) {
|
850
821
|
// Start Server
|
851
822
|
app.listen(listenCallback);
|
@@ -978,137 +949,12 @@ function BindEventHook(eventName, eventFunc, target) {
|
|
978
949
|
koatty_container.IOCContainer.attachClassMetadata(koatty_container.TAGGED_CLS, eventName, eventFunc, target);
|
979
950
|
}
|
980
951
|
|
981
|
-
/*
|
982
|
-
* @Description: base service
|
983
|
-
* @Usage:
|
984
|
-
* @Author: richen
|
985
|
-
* @Date: 2023-12-09 21:56:32
|
986
|
-
* @LastEditTime: 2024-01-03 21:57:26
|
987
|
-
* @License: BSD (3-Clause)
|
988
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
989
|
-
*/
|
990
|
-
/**
|
991
|
-
* Base service
|
992
|
-
*
|
993
|
-
* @export
|
994
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
995
|
-
* @class Base
|
996
|
-
*/
|
997
|
-
class BaseService {
|
998
|
-
/**
|
999
|
-
* instance of BaseController.
|
1000
|
-
* @param {Koatty} app
|
1001
|
-
* @param {KoattyContext} ctx
|
1002
|
-
* @memberof BaseController
|
1003
|
-
*/
|
1004
|
-
constructor(...arg) {
|
1005
|
-
this.init(arg);
|
1006
|
-
}
|
1007
|
-
/**
|
1008
|
-
* init
|
1009
|
-
*
|
1010
|
-
* @protected
|
1011
|
-
* @memberof BaseController
|
1012
|
-
*/
|
1013
|
-
init(...arg) {
|
1014
|
-
}
|
1015
|
-
}
|
1016
|
-
|
1017
|
-
/*
|
1018
|
-
* @Description: base controller
|
1019
|
-
* @Usage:
|
1020
|
-
* @Author: richen
|
1021
|
-
* @Date: 2023-12-09 21:56:32
|
1022
|
-
* @LastEditTime: 2024-01-03 21:57:20
|
1023
|
-
* @License: BSD (3-Clause)
|
1024
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
1025
|
-
*/
|
1026
|
-
/**
|
1027
|
-
* Base controller
|
1028
|
-
*
|
1029
|
-
* @export
|
1030
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
1031
|
-
* @class BaseController
|
1032
|
-
* @implements {IController}
|
1033
|
-
*/
|
1034
|
-
class BaseController {
|
1035
|
-
/**
|
1036
|
-
* instance of BaseController.
|
1037
|
-
* @param {Koatty} app
|
1038
|
-
* @param {KoattyContext} ctx
|
1039
|
-
* @memberof BaseController
|
1040
|
-
*/
|
1041
|
-
constructor(ctx, ...arg) {
|
1042
|
-
this.ctx = ctx;
|
1043
|
-
this.init(arg);
|
1044
|
-
}
|
1045
|
-
/**
|
1046
|
-
* init
|
1047
|
-
*
|
1048
|
-
* @memberof BaseController
|
1049
|
-
*/
|
1050
|
-
init(...arg) {
|
1051
|
-
}
|
1052
|
-
/**
|
1053
|
-
* Response to normalize json format content for success
|
1054
|
-
*
|
1055
|
-
* @deprecated 使用 Output.ok 代替
|
1056
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
1057
|
-
* @param {*} [data] 待处理的数据
|
1058
|
-
* @param {number} [code=200] 错误码,默认0
|
1059
|
-
* @returns {*}
|
1060
|
-
* @memberof BaseController
|
1061
|
-
*/
|
1062
|
-
ok(msg, data, code = 0) {
|
1063
|
-
const obj = formatApiData(msg, data, code);
|
1064
|
-
return Promise.resolve(obj);
|
1065
|
-
}
|
1066
|
-
/**
|
1067
|
-
* Response to normalize json format content for fail
|
1068
|
-
*
|
1069
|
-
* @deprecated 使用 Output.fail 代替
|
1070
|
-
* @param {(string | ApiInput)} msg
|
1071
|
-
* @param {*} [data]
|
1072
|
-
* @param {number} [code=1]
|
1073
|
-
* @returns {*}
|
1074
|
-
* @memberof BaseController
|
1075
|
-
*/
|
1076
|
-
fail(msg, data, code = 1) {
|
1077
|
-
const obj = formatApiData(msg, data, code);
|
1078
|
-
this.ctx.body = obj.data;
|
1079
|
-
this.ctx.throw(obj.message, obj.code, 200);
|
1080
|
-
}
|
1081
|
-
}
|
1082
|
-
// const properties = ["constructor", "init"];
|
1083
|
-
// export const BaseController = new Proxy(Base, {
|
1084
|
-
// set(target, key, value, receiver) {
|
1085
|
-
// if (Reflect.get(target, key, receiver) === undefined) {
|
1086
|
-
// return Reflect.set(target, key, value, receiver);
|
1087
|
-
// } else if (key === "init") {
|
1088
|
-
// return Reflect.set(target, key, value, receiver);
|
1089
|
-
// } else {
|
1090
|
-
// throw Error("Cannot redefine getter-only property");
|
1091
|
-
// }
|
1092
|
-
// },
|
1093
|
-
// deleteProperty(target, key) {
|
1094
|
-
// throw Error("Cannot delete getter-only property");
|
1095
|
-
// },
|
1096
|
-
// construct(target, args, newTarget) {
|
1097
|
-
// Reflect.ownKeys(target.prototype).map((n) => {
|
1098
|
-
// if (newTarget.prototype.hasOwnProperty(n) && !properties.includes(Helper.toString(n))) {
|
1099
|
-
// throw Error(`Cannot override the final method "${Helper.toString(n)}"`);
|
1100
|
-
// }
|
1101
|
-
// });
|
1102
|
-
// return Reflect.construct(target, args, newTarget);
|
1103
|
-
// }
|
1104
|
-
// });
|
1105
|
-
|
1106
952
|
/*
|
1107
953
|
* @Description: output data
|
1108
954
|
* @Usage:
|
1109
955
|
* @Author: richen
|
1110
956
|
* @Date: 2024-01-03 22:03:34
|
1111
|
-
* @LastEditTime: 2024-01-
|
957
|
+
* @LastEditTime: 2024-01-16 01:20:36
|
1112
958
|
* @License: BSD (3-Clause)
|
1113
959
|
* @Copyright (c): <richenlin(at)gmail.com>
|
1114
960
|
*/
|
@@ -1143,6 +989,36 @@ class Output {
|
|
1143
989
|
ctx.throw(obj.message, obj.code, 200);
|
1144
990
|
}
|
1145
991
|
}
|
992
|
+
/**
|
993
|
+
* Format api interface data format
|
994
|
+
*
|
995
|
+
* @private
|
996
|
+
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
997
|
+
* @param {*} data 待返回的数据
|
998
|
+
* @param {number} defaultCode 默认错误码
|
999
|
+
* @returns {ApiOutput} 格式化之后的接口数据
|
1000
|
+
* @memberof BaseController
|
1001
|
+
*/
|
1002
|
+
function formatApiData(msg, data, defaultCode) {
|
1003
|
+
let obj = {
|
1004
|
+
code: defaultCode,
|
1005
|
+
message: '',
|
1006
|
+
data: null,
|
1007
|
+
};
|
1008
|
+
if (koatty_lib.Helper.isError(msg)) {
|
1009
|
+
const { code, message } = msg;
|
1010
|
+
obj.code = code || defaultCode;
|
1011
|
+
obj.message = message;
|
1012
|
+
}
|
1013
|
+
else if (koatty_lib.Helper.isObject(msg)) {
|
1014
|
+
obj = { ...obj, ...msg };
|
1015
|
+
}
|
1016
|
+
else {
|
1017
|
+
obj.message = msg;
|
1018
|
+
obj.data = data;
|
1019
|
+
}
|
1020
|
+
return obj;
|
1021
|
+
}
|
1146
1022
|
|
1147
1023
|
Object.defineProperty(exports, 'Config', {
|
1148
1024
|
enumerable: true,
|
@@ -1156,8 +1032,6 @@ Object.defineProperty(exports, 'Helper', {
|
|
1156
1032
|
enumerable: true,
|
1157
1033
|
get: function () { return koatty_lib.Helper; }
|
1158
1034
|
});
|
1159
|
-
exports.BaseController = BaseController;
|
1160
|
-
exports.BaseService = BaseService;
|
1161
1035
|
exports.BindEventHook = BindEventHook;
|
1162
1036
|
exports.Bootstrap = Bootstrap;
|
1163
1037
|
exports.Component = Component;
|
@@ -1175,6 +1049,12 @@ exports.implementsControllerInterface = implementsControllerInterface;
|
|
1175
1049
|
exports.implementsMiddlewareInterface = implementsMiddlewareInterface;
|
1176
1050
|
exports.implementsPluginInterface = implementsPluginInterface;
|
1177
1051
|
exports.implementsServiceInterface = implementsServiceInterface;
|
1052
|
+
Object.keys(koatty_router).forEach(function (k) {
|
1053
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1054
|
+
enumerable: true,
|
1055
|
+
get: function () { return koatty_router[k]; }
|
1056
|
+
});
|
1057
|
+
});
|
1178
1058
|
Object.keys(koatty_container).forEach(function (k) {
|
1179
1059
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
1180
1060
|
enumerable: true,
|
package/dist/index.mjs
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date: 2024-01-
|
3
|
+
* @Date: 2024-01-16 08:38:15
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
7
7
|
*/
|
8
|
+
import { CONTROLLER_ROUTER, NewRouter } from 'koatty_router';
|
9
|
+
export * from 'koatty_router';
|
8
10
|
import { IOCContainer, TAGGED_CLS } from 'koatty_container';
|
9
11
|
export * from 'koatty_container';
|
10
12
|
import { AppEventArr, Koatty } from 'koatty_core';
|
11
13
|
export * from 'koatty_core';
|
12
|
-
import {
|
14
|
+
import { NewServe, BindProcessEvent } from 'koatty_serve';
|
13
15
|
export * from 'koatty_serve';
|
14
16
|
import * as path from 'path';
|
15
17
|
import { Load } from 'koatty_loader';
|
@@ -45,7 +47,7 @@ function TraceHandler(app) {
|
|
45
47
|
* @Usage:
|
46
48
|
* @Author: richen
|
47
49
|
* @Date: 2023-12-09 21:56:32
|
48
|
-
* @LastEditTime:
|
50
|
+
* @LastEditTime: 2024-01-16 01:20:17
|
49
51
|
* @License: BSD (3-Clause)
|
50
52
|
* @Copyright (c): <richenlin(at)gmail.com>
|
51
53
|
*/
|
@@ -85,36 +87,6 @@ function checkClass(fileName, xpath, target, exSet) {
|
|
85
87
|
exSet.add(fileName);
|
86
88
|
return;
|
87
89
|
}
|
88
|
-
/**
|
89
|
-
* Format api interface data format
|
90
|
-
*
|
91
|
-
* @private
|
92
|
-
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
93
|
-
* @param {*} data 待返回的数据
|
94
|
-
* @param {number} defaultCode 默认错误码
|
95
|
-
* @returns {ApiOutput} 格式化之后的接口数据
|
96
|
-
* @memberof BaseController
|
97
|
-
*/
|
98
|
-
function formatApiData(msg, data, defaultCode) {
|
99
|
-
let obj = {
|
100
|
-
code: defaultCode,
|
101
|
-
message: '',
|
102
|
-
data: null,
|
103
|
-
};
|
104
|
-
if (Helper.isError(msg)) {
|
105
|
-
const { code, message } = msg;
|
106
|
-
obj.code = code || defaultCode;
|
107
|
-
obj.message = message;
|
108
|
-
}
|
109
|
-
else if (Helper.isObject(msg)) {
|
110
|
-
obj = { ...obj, ...msg };
|
111
|
-
}
|
112
|
-
else {
|
113
|
-
obj.message = msg;
|
114
|
-
obj.data = data;
|
115
|
-
}
|
116
|
-
return obj;
|
117
|
-
}
|
118
90
|
|
119
91
|
/*
|
120
92
|
* @Description: framework logger
|
@@ -156,7 +128,7 @@ function SetLogger(app, config) {
|
|
156
128
|
* @Usage:
|
157
129
|
* @Author: richen
|
158
130
|
* @Date: 2023-12-09 21:56:32
|
159
|
-
* @LastEditTime: 2024-01-
|
131
|
+
* @LastEditTime: 2024-01-16 01:17:46
|
160
132
|
* @License: BSD (3-Clause)
|
161
133
|
* @Copyright (c): <richenlin(at)gmail.com>
|
162
134
|
*/
|
@@ -701,7 +673,7 @@ class Loader {
|
|
701
673
|
}
|
702
674
|
}
|
703
675
|
|
704
|
-
var version = "3.11.2-
|
676
|
+
var version = "3.11.2-8";
|
705
677
|
var engines = {
|
706
678
|
node: ">12.0.0"
|
707
679
|
};
|
@@ -754,7 +726,7 @@ const checkUTRuntime = () => {
|
|
754
726
|
* @Usage:
|
755
727
|
* @Author: richen
|
756
728
|
* @Date: 2021-12-09 21:56:32
|
757
|
-
* @LastEditTime: 2024-01-
|
729
|
+
* @LastEditTime: 2024-01-16 01:06:26
|
758
730
|
* @License: BSD (3-Clause)
|
759
731
|
* @Copyright (c): <richenlin(at)gmail.com>
|
760
732
|
*/
|
@@ -807,6 +779,12 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
807
779
|
Loader.LoadAppEventHooks(app, target);
|
808
780
|
Logger.Log('Koatty', '', 'Emit App Boot ...');
|
809
781
|
await asyncEvent(app, "appBoot" /* AppEvent.appBoot */);
|
782
|
+
// Create Server
|
783
|
+
// app.server = newServe(app);
|
784
|
+
Helper.define(app, "server", NewServe(app));
|
785
|
+
// Create router
|
786
|
+
// app.router = newRouter(app);
|
787
|
+
Helper.define(app, "router", NewRouter(app));
|
810
788
|
// Load Components
|
811
789
|
Logger.Log('Koatty', '', 'Load Components ...');
|
812
790
|
await Loader.LoadComponents(app);
|
@@ -819,18 +797,12 @@ const executeBootstrap = async function (target, bootFunc, isInitiative = false)
|
|
819
797
|
// Load Controllers
|
820
798
|
Logger.Log('Koatty', '', 'Load Controllers ...');
|
821
799
|
const controllers = Loader.LoadControllers(app);
|
822
|
-
// Create Server
|
823
|
-
// app.server = newServe(app);
|
824
|
-
Helper.define(app, "server", NewServe(app));
|
825
|
-
// Create router
|
826
|
-
// app.router = newRouter(app);
|
827
|
-
Helper.define(app, "router", NewRouter(app));
|
828
800
|
// Emit app ready event
|
829
801
|
Logger.Log('Koatty', '', 'Emit App Ready ...');
|
830
802
|
await asyncEvent(app, "appReady" /* AppEvent.appReady */);
|
831
803
|
// Load Routers
|
832
804
|
Logger.Log('Koatty', '', 'Load Routers ...');
|
833
|
-
app.router.LoadRouter(controllers);
|
805
|
+
app.router.LoadRouter(app, controllers);
|
834
806
|
if (!isUTRuntime) {
|
835
807
|
// Start Server
|
836
808
|
app.listen(listenCallback);
|
@@ -963,137 +935,12 @@ function BindEventHook(eventName, eventFunc, target) {
|
|
963
935
|
IOCContainer.attachClassMetadata(TAGGED_CLS, eventName, eventFunc, target);
|
964
936
|
}
|
965
937
|
|
966
|
-
/*
|
967
|
-
* @Description: base service
|
968
|
-
* @Usage:
|
969
|
-
* @Author: richen
|
970
|
-
* @Date: 2023-12-09 21:56:32
|
971
|
-
* @LastEditTime: 2024-01-03 21:57:26
|
972
|
-
* @License: BSD (3-Clause)
|
973
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
974
|
-
*/
|
975
|
-
/**
|
976
|
-
* Base service
|
977
|
-
*
|
978
|
-
* @export
|
979
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
980
|
-
* @class Base
|
981
|
-
*/
|
982
|
-
class BaseService {
|
983
|
-
/**
|
984
|
-
* instance of BaseController.
|
985
|
-
* @param {Koatty} app
|
986
|
-
* @param {KoattyContext} ctx
|
987
|
-
* @memberof BaseController
|
988
|
-
*/
|
989
|
-
constructor(...arg) {
|
990
|
-
this.init(arg);
|
991
|
-
}
|
992
|
-
/**
|
993
|
-
* init
|
994
|
-
*
|
995
|
-
* @protected
|
996
|
-
* @memberof BaseController
|
997
|
-
*/
|
998
|
-
init(...arg) {
|
999
|
-
}
|
1000
|
-
}
|
1001
|
-
|
1002
|
-
/*
|
1003
|
-
* @Description: base controller
|
1004
|
-
* @Usage:
|
1005
|
-
* @Author: richen
|
1006
|
-
* @Date: 2023-12-09 21:56:32
|
1007
|
-
* @LastEditTime: 2024-01-03 21:57:20
|
1008
|
-
* @License: BSD (3-Clause)
|
1009
|
-
* @Copyright (c): <richenlin(at)gmail.com>
|
1010
|
-
*/
|
1011
|
-
/**
|
1012
|
-
* Base controller
|
1013
|
-
*
|
1014
|
-
* @export
|
1015
|
-
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
1016
|
-
* @class BaseController
|
1017
|
-
* @implements {IController}
|
1018
|
-
*/
|
1019
|
-
class BaseController {
|
1020
|
-
/**
|
1021
|
-
* instance of BaseController.
|
1022
|
-
* @param {Koatty} app
|
1023
|
-
* @param {KoattyContext} ctx
|
1024
|
-
* @memberof BaseController
|
1025
|
-
*/
|
1026
|
-
constructor(ctx, ...arg) {
|
1027
|
-
this.ctx = ctx;
|
1028
|
-
this.init(arg);
|
1029
|
-
}
|
1030
|
-
/**
|
1031
|
-
* init
|
1032
|
-
*
|
1033
|
-
* @memberof BaseController
|
1034
|
-
*/
|
1035
|
-
init(...arg) {
|
1036
|
-
}
|
1037
|
-
/**
|
1038
|
-
* Response to normalize json format content for success
|
1039
|
-
*
|
1040
|
-
* @deprecated 使用 Output.ok 代替
|
1041
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
1042
|
-
* @param {*} [data] 待处理的数据
|
1043
|
-
* @param {number} [code=200] 错误码,默认0
|
1044
|
-
* @returns {*}
|
1045
|
-
* @memberof BaseController
|
1046
|
-
*/
|
1047
|
-
ok(msg, data, code = 0) {
|
1048
|
-
const obj = formatApiData(msg, data, code);
|
1049
|
-
return Promise.resolve(obj);
|
1050
|
-
}
|
1051
|
-
/**
|
1052
|
-
* Response to normalize json format content for fail
|
1053
|
-
*
|
1054
|
-
* @deprecated 使用 Output.fail 代替
|
1055
|
-
* @param {(string | ApiInput)} msg
|
1056
|
-
* @param {*} [data]
|
1057
|
-
* @param {number} [code=1]
|
1058
|
-
* @returns {*}
|
1059
|
-
* @memberof BaseController
|
1060
|
-
*/
|
1061
|
-
fail(msg, data, code = 1) {
|
1062
|
-
const obj = formatApiData(msg, data, code);
|
1063
|
-
this.ctx.body = obj.data;
|
1064
|
-
this.ctx.throw(obj.message, obj.code, 200);
|
1065
|
-
}
|
1066
|
-
}
|
1067
|
-
// const properties = ["constructor", "init"];
|
1068
|
-
// export const BaseController = new Proxy(Base, {
|
1069
|
-
// set(target, key, value, receiver) {
|
1070
|
-
// if (Reflect.get(target, key, receiver) === undefined) {
|
1071
|
-
// return Reflect.set(target, key, value, receiver);
|
1072
|
-
// } else if (key === "init") {
|
1073
|
-
// return Reflect.set(target, key, value, receiver);
|
1074
|
-
// } else {
|
1075
|
-
// throw Error("Cannot redefine getter-only property");
|
1076
|
-
// }
|
1077
|
-
// },
|
1078
|
-
// deleteProperty(target, key) {
|
1079
|
-
// throw Error("Cannot delete getter-only property");
|
1080
|
-
// },
|
1081
|
-
// construct(target, args, newTarget) {
|
1082
|
-
// Reflect.ownKeys(target.prototype).map((n) => {
|
1083
|
-
// if (newTarget.prototype.hasOwnProperty(n) && !properties.includes(Helper.toString(n))) {
|
1084
|
-
// throw Error(`Cannot override the final method "${Helper.toString(n)}"`);
|
1085
|
-
// }
|
1086
|
-
// });
|
1087
|
-
// return Reflect.construct(target, args, newTarget);
|
1088
|
-
// }
|
1089
|
-
// });
|
1090
|
-
|
1091
938
|
/*
|
1092
939
|
* @Description: output data
|
1093
940
|
* @Usage:
|
1094
941
|
* @Author: richen
|
1095
942
|
* @Date: 2024-01-03 22:03:34
|
1096
|
-
* @LastEditTime: 2024-01-
|
943
|
+
* @LastEditTime: 2024-01-16 01:20:36
|
1097
944
|
* @License: BSD (3-Clause)
|
1098
945
|
* @Copyright (c): <richenlin(at)gmail.com>
|
1099
946
|
*/
|
@@ -1128,5 +975,35 @@ class Output {
|
|
1128
975
|
ctx.throw(obj.message, obj.code, 200);
|
1129
976
|
}
|
1130
977
|
}
|
978
|
+
/**
|
979
|
+
* Format api interface data format
|
980
|
+
*
|
981
|
+
* @private
|
982
|
+
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
983
|
+
* @param {*} data 待返回的数据
|
984
|
+
* @param {number} defaultCode 默认错误码
|
985
|
+
* @returns {ApiOutput} 格式化之后的接口数据
|
986
|
+
* @memberof BaseController
|
987
|
+
*/
|
988
|
+
function formatApiData(msg, data, defaultCode) {
|
989
|
+
let obj = {
|
990
|
+
code: defaultCode,
|
991
|
+
message: '',
|
992
|
+
data: null,
|
993
|
+
};
|
994
|
+
if (Helper.isError(msg)) {
|
995
|
+
const { code, message } = msg;
|
996
|
+
obj.code = code || defaultCode;
|
997
|
+
obj.message = message;
|
998
|
+
}
|
999
|
+
else if (Helper.isObject(msg)) {
|
1000
|
+
obj = { ...obj, ...msg };
|
1001
|
+
}
|
1002
|
+
else {
|
1003
|
+
obj.message = msg;
|
1004
|
+
obj.data = data;
|
1005
|
+
}
|
1006
|
+
return obj;
|
1007
|
+
}
|
1131
1008
|
|
1132
|
-
export {
|
1009
|
+
export { BindEventHook, Bootstrap, Component, ComponentScan, ConfigurationScan, Controller, ExecBootStrap, Logger, Middleware, Output, Plugin, Service, implementsAspectInterface, implementsControllerInterface, implementsMiddlewareInterface, implementsPluginInterface, implementsServiceInterface };
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.11.2-
|
3
|
+
"version": "3.11.2-8",
|
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",
|
@@ -85,14 +85,15 @@
|
|
85
85
|
"koa": "~2.15.0",
|
86
86
|
"koatty_config": "~1.1.6",
|
87
87
|
"koatty_container": "~1.8.10",
|
88
|
-
"koatty_core": "~1.
|
88
|
+
"koatty_core": "~1.9.0",
|
89
89
|
"koatty_exception": "~1.2.8",
|
90
90
|
"koatty_lib": "~1.3.4",
|
91
91
|
"koatty_loader": "~1.1.0",
|
92
92
|
"koatty_logger": "~2.1.4",
|
93
93
|
"koatty_proto": "~1.1.12",
|
94
|
-
"
|
95
|
-
"
|
94
|
+
"koatty_router": "~1.9.0",
|
95
|
+
"koatty_serve": "~2.1.2",
|
96
|
+
"koatty_trace": "~1.11.2",
|
96
97
|
"koatty_validation": "~1.3.2"
|
97
98
|
}
|
98
99
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "koatty",
|
3
|
-
"version": "3.11.2-
|
3
|
+
"version": "3.11.2-8",
|
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",
|
@@ -85,14 +85,15 @@
|
|
85
85
|
"koa": "~2.15.0",
|
86
86
|
"koatty_config": "~1.1.6",
|
87
87
|
"koatty_container": "~1.8.10",
|
88
|
-
"koatty_core": "~1.
|
88
|
+
"koatty_core": "~1.9.0",
|
89
89
|
"koatty_exception": "~1.2.8",
|
90
90
|
"koatty_lib": "~1.3.4",
|
91
91
|
"koatty_loader": "~1.1.0",
|
92
92
|
"koatty_logger": "~2.1.4",
|
93
93
|
"koatty_proto": "~1.1.12",
|
94
|
-
"
|
95
|
-
"
|
94
|
+
"koatty_router": "~1.9.0",
|
95
|
+
"koatty_serve": "~2.1.2",
|
96
|
+
"koatty_trace": "~1.11.2",
|
96
97
|
"koatty_validation": "~1.3.2"
|
97
98
|
}
|
98
99
|
}
|