@midwayjs/core 3.0.0-beta.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseFramework.d.ts +2 -1
- package/dist/baseFramework.js +13 -10
- package/dist/common/applicationManager.d.ts +11 -0
- package/dist/common/applicationManager.js +70 -0
- package/dist/common/dataListener.d.ts +11 -0
- package/dist/common/dataListener.js +43 -0
- package/dist/common/fileDetector.js +1 -1
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/webGenerator.d.ts +3 -14
- package/dist/common/webGenerator.js +21 -33
- package/dist/common/webRouterCollector.js +3 -3
- package/dist/context/container.js +21 -11
- package/dist/context/managedResolverFactory.js +12 -5
- package/dist/context/requestContainer.js +2 -0
- package/dist/definitions/functionDefinition.d.ts +1 -0
- package/dist/definitions/functionDefinition.js +1 -0
- package/dist/definitions/objectCreator.js +9 -8
- package/dist/definitions/objectDefinition.d.ts +1 -0
- package/dist/definitions/objectDefinition.js +1 -0
- package/dist/error/base.d.ts +22 -3
- package/dist/error/base.js +34 -5
- package/dist/error/framework.d.ts +27 -2
- package/dist/error/framework.js +51 -14
- package/dist/error/http.d.ts +146 -41
- package/dist/error/http.js +164 -31
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +4 -1
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/interface.d.ts +49 -27
- package/dist/service/aspectService.js +1 -1
- package/dist/service/configService.d.ts +3 -1
- package/dist/service/configService.js +23 -17
- package/dist/service/decoratorService.js +11 -5
- package/dist/service/environmentService.d.ts +1 -1
- package/dist/service/frameworkService.d.ts +3 -2
- package/dist/service/frameworkService.js +17 -12
- package/dist/service/lifeCycleService.js +5 -5
- package/dist/service/loggerService.d.ts +1 -1
- package/dist/service/middlewareService.d.ts +3 -4
- package/dist/service/middlewareService.js +7 -11
- package/dist/setup.js +7 -4
- package/dist/util/extend.d.ts +2 -0
- package/dist/util/extend.js +55 -0
- package/dist/util/webRouterParam.js +24 -4
- package/package.json +10 -12
- package/CHANGELOG.md +0 -2208
- package/dist/error/code.d.ts +0 -60
- package/dist/error/code.js +0 -65
package/dist/error/http.js
CHANGED
|
@@ -1,67 +1,200 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const code_1 = require("./code");
|
|
3
|
+
exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerErrorError = exports.UnprocessableEntityError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
|
|
5
4
|
const base_1 = require("./base");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
var HttpStatus;
|
|
6
|
+
(function (HttpStatus) {
|
|
7
|
+
HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
|
|
8
|
+
HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
9
|
+
HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
|
|
10
|
+
HttpStatus[HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
|
|
11
|
+
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
|
12
|
+
HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
|
|
13
|
+
HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
|
|
14
|
+
HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
15
|
+
HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
16
|
+
HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
17
|
+
HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
18
|
+
HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
|
|
19
|
+
HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
20
|
+
HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
|
|
21
|
+
HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
22
|
+
HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
23
|
+
HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
24
|
+
HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
25
|
+
HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
26
|
+
HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
27
|
+
HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
28
|
+
HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
29
|
+
HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
30
|
+
HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
31
|
+
HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
32
|
+
HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
33
|
+
HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
34
|
+
HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
|
|
35
|
+
HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
|
|
36
|
+
HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
37
|
+
HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
38
|
+
HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
39
|
+
HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
40
|
+
HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
41
|
+
HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
42
|
+
HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
43
|
+
HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
44
|
+
HttpStatus[HttpStatus["MISDIRECTED"] = 421] = "MISDIRECTED";
|
|
45
|
+
HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
46
|
+
HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
47
|
+
HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
48
|
+
HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
49
|
+
HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
50
|
+
HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
51
|
+
HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
52
|
+
HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
53
|
+
HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
54
|
+
HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
55
|
+
})(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));
|
|
56
|
+
/**
|
|
57
|
+
* 400 http error, Means that the request can be fulfilled because of the bad syntax.
|
|
58
|
+
*/
|
|
59
|
+
class BadRequestError extends base_1.MidwayHttpError {
|
|
60
|
+
constructor(resOrMessage = 'Bad Request') {
|
|
61
|
+
super(resOrMessage, HttpStatus.BAD_REQUEST);
|
|
17
62
|
}
|
|
18
63
|
}
|
|
19
64
|
exports.BadRequestError = BadRequestError;
|
|
20
|
-
|
|
65
|
+
/**
|
|
66
|
+
* 401 http error, Means that the request was legal, but the server is rejecting to answer it. For the use when authentication is required and has failed or has not yet been provided.
|
|
67
|
+
*/
|
|
68
|
+
class UnauthorizedError extends base_1.MidwayHttpError {
|
|
69
|
+
constructor(resOrMessage = 'Unauthorized') {
|
|
70
|
+
super(resOrMessage, HttpStatus.UNAUTHORIZED);
|
|
71
|
+
}
|
|
21
72
|
}
|
|
22
73
|
exports.UnauthorizedError = UnauthorizedError;
|
|
23
|
-
|
|
74
|
+
/**
|
|
75
|
+
* 4o4 http error, Means that the requested page cannot be found at the moment, but it may be available again in the future.
|
|
76
|
+
*/
|
|
77
|
+
class NotFoundError extends base_1.MidwayHttpError {
|
|
78
|
+
constructor(resOrMessage = 'Not Found') {
|
|
79
|
+
super(resOrMessage, HttpStatus.NOT_FOUND);
|
|
80
|
+
}
|
|
24
81
|
}
|
|
25
82
|
exports.NotFoundError = NotFoundError;
|
|
26
|
-
|
|
83
|
+
/**
|
|
84
|
+
* 403 http error, Means that the request is legal, but the server is rejecting to answer it.
|
|
85
|
+
*/
|
|
86
|
+
class ForbiddenError extends base_1.MidwayHttpError {
|
|
87
|
+
constructor(resOrMessage = 'Forbidden') {
|
|
88
|
+
super(resOrMessage, HttpStatus.FORBIDDEN);
|
|
89
|
+
}
|
|
27
90
|
}
|
|
28
91
|
exports.ForbiddenError = ForbiddenError;
|
|
29
|
-
|
|
92
|
+
/**
|
|
93
|
+
* 406 http error, Means that the server can only generate an answer which the client doesn't accept.
|
|
94
|
+
*/
|
|
95
|
+
class NotAcceptableError extends base_1.MidwayHttpError {
|
|
96
|
+
constructor(resOrMessage = 'Not Acceptable') {
|
|
97
|
+
super(resOrMessage, HttpStatus.NOT_ACCEPTABLE);
|
|
98
|
+
}
|
|
30
99
|
}
|
|
31
100
|
exports.NotAcceptableError = NotAcceptableError;
|
|
32
|
-
|
|
101
|
+
/**
|
|
102
|
+
* 408 http error, Means that the server timed out waiting for the request.
|
|
103
|
+
*/
|
|
104
|
+
class RequestTimeoutError extends base_1.MidwayHttpError {
|
|
105
|
+
constructor(resOrMessage = 'Request Timeout') {
|
|
106
|
+
super(resOrMessage, HttpStatus.REQUEST_TIMEOUT);
|
|
107
|
+
}
|
|
33
108
|
}
|
|
34
109
|
exports.RequestTimeoutError = RequestTimeoutError;
|
|
35
|
-
|
|
110
|
+
/**
|
|
111
|
+
* 409 http error, Means that the request cannot be completed, because of a conflict in the request.
|
|
112
|
+
*/
|
|
113
|
+
class ConflictError extends base_1.MidwayHttpError {
|
|
114
|
+
constructor(resOrMessage = 'Conflict') {
|
|
115
|
+
super(resOrMessage, HttpStatus.CONFLICT);
|
|
116
|
+
}
|
|
36
117
|
}
|
|
37
118
|
exports.ConflictError = ConflictError;
|
|
38
|
-
|
|
119
|
+
/**
|
|
120
|
+
* 410 http error, Means that the requested page is not available anymore.
|
|
121
|
+
*/
|
|
122
|
+
class GoneError extends base_1.MidwayHttpError {
|
|
123
|
+
constructor(resOrMessage = 'Gone') {
|
|
124
|
+
super(resOrMessage, HttpStatus.GONE);
|
|
125
|
+
}
|
|
39
126
|
}
|
|
40
127
|
exports.GoneError = GoneError;
|
|
41
|
-
|
|
128
|
+
/**
|
|
129
|
+
* 413 http error, Means that the request entity is too large and that's why the server won't accept the request.
|
|
130
|
+
*/
|
|
131
|
+
class PayloadTooLargeError extends base_1.MidwayHttpError {
|
|
132
|
+
constructor(resOrMessage = 'Request Entity Too Large') {
|
|
133
|
+
super(resOrMessage, HttpStatus.PAYLOAD_TOO_LARGE);
|
|
134
|
+
}
|
|
42
135
|
}
|
|
43
136
|
exports.PayloadTooLargeError = PayloadTooLargeError;
|
|
44
|
-
|
|
137
|
+
/**
|
|
138
|
+
* 415 http error, Means that the media type is not supported and that's why the server won't accept the request.
|
|
139
|
+
*/
|
|
140
|
+
class UnsupportedMediaTypeError extends base_1.MidwayHttpError {
|
|
141
|
+
constructor(resOrMessage = 'Unsupported Media Type') {
|
|
142
|
+
super(resOrMessage, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
|
143
|
+
}
|
|
45
144
|
}
|
|
46
145
|
exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
|
|
47
|
-
class
|
|
146
|
+
class UnprocessableEntityError extends base_1.MidwayHttpError {
|
|
147
|
+
constructor(resOrMessage = 'Unprocessable Entity') {
|
|
148
|
+
super(resOrMessage, HttpStatus.UNPROCESSABLE_ENTITY);
|
|
149
|
+
}
|
|
48
150
|
}
|
|
49
|
-
exports.
|
|
50
|
-
|
|
151
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
152
|
+
/**
|
|
153
|
+
* 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
|
|
154
|
+
*/
|
|
155
|
+
class InternalServerErrorError extends base_1.MidwayHttpError {
|
|
156
|
+
constructor(resOrMessage = 'Internal Server Error') {
|
|
157
|
+
super(resOrMessage, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
158
|
+
}
|
|
51
159
|
}
|
|
52
160
|
exports.InternalServerErrorError = InternalServerErrorError;
|
|
53
|
-
|
|
161
|
+
/**
|
|
162
|
+
* 501 http error, Means that the server doesn't recognize the request method or it lacks the ability to fulfill the request.
|
|
163
|
+
*/
|
|
164
|
+
class NotImplementedError extends base_1.MidwayHttpError {
|
|
165
|
+
constructor(resOrMessage = 'Not Implemented') {
|
|
166
|
+
super(resOrMessage, HttpStatus.NOT_IMPLEMENTED);
|
|
167
|
+
}
|
|
54
168
|
}
|
|
55
|
-
|
|
169
|
+
exports.NotImplementedError = NotImplementedError;
|
|
170
|
+
/**
|
|
171
|
+
* 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.
|
|
172
|
+
*/
|
|
173
|
+
class BadGatewayError extends base_1.MidwayHttpError {
|
|
174
|
+
constructor(resOrMessage = 'Bad Gateway') {
|
|
175
|
+
super(resOrMessage, HttpStatus.BAD_GATEWAY);
|
|
176
|
+
}
|
|
56
177
|
}
|
|
57
178
|
exports.BadGatewayError = BadGatewayError;
|
|
58
|
-
|
|
179
|
+
/**
|
|
180
|
+
* 503 http error, Means that the server is not available now (It may be overloaded or down).
|
|
181
|
+
*/
|
|
182
|
+
class ServiceUnavailableError extends base_1.MidwayHttpError {
|
|
183
|
+
constructor(resOrMessage = 'Service Unavailable') {
|
|
184
|
+
super(resOrMessage, HttpStatus.SERVICE_UNAVAILABLE);
|
|
185
|
+
}
|
|
59
186
|
}
|
|
60
187
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
61
|
-
|
|
188
|
+
/**
|
|
189
|
+
* 504 http error, Means that the server was acting as a gateway or proxy and it didn't get answer on time from the upstream server.
|
|
190
|
+
*/
|
|
191
|
+
class GatewayTimeoutError extends base_1.MidwayHttpError {
|
|
192
|
+
constructor(resOrMessage = 'Gateway Timeout') {
|
|
193
|
+
super(resOrMessage, HttpStatus.GATEWAY_TIMEOUT);
|
|
194
|
+
}
|
|
62
195
|
}
|
|
63
196
|
exports.GatewayTimeoutError = GatewayTimeoutError;
|
|
64
|
-
exports.
|
|
197
|
+
exports.httpError = {
|
|
65
198
|
BadRequestError,
|
|
66
199
|
UnauthorizedError,
|
|
67
200
|
NotFoundError,
|
|
@@ -72,7 +205,7 @@ exports.http = {
|
|
|
72
205
|
GoneError,
|
|
73
206
|
PayloadTooLargeError,
|
|
74
207
|
UnsupportedMediaTypeError,
|
|
75
|
-
|
|
208
|
+
UnprocessableEntityError,
|
|
76
209
|
InternalServerErrorError,
|
|
77
210
|
NotImplementedError,
|
|
78
211
|
BadGatewayError,
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -10,7 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.httpError = exports.HttpStatus = void 0;
|
|
13
14
|
__exportStar(require("./base"), exports);
|
|
14
|
-
|
|
15
|
+
var http_1 = require("./http");
|
|
16
|
+
Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return http_1.HttpStatus; } });
|
|
17
|
+
Object.defineProperty(exports, "httpError", { enumerable: true, get: function () { return http_1.httpError; } });
|
|
15
18
|
__exportStar(require("./framework"), exports);
|
|
16
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,10 +4,12 @@ export declare class FunctionalConfiguration {
|
|
|
4
4
|
private readyHandler;
|
|
5
5
|
private stopHandler;
|
|
6
6
|
private configLoadHandler;
|
|
7
|
+
private serverReadyHandler;
|
|
7
8
|
private options;
|
|
8
9
|
constructor(options: InjectionConfigurationOptions);
|
|
9
10
|
onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): any;
|
|
10
11
|
onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
|
|
12
|
+
onServerReady(serverReadyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
|
|
11
13
|
onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
|
|
12
14
|
getConfigurationOptions(): InjectionConfigurationOptions;
|
|
13
15
|
}
|
|
@@ -7,6 +7,7 @@ class FunctionalConfiguration {
|
|
|
7
7
|
this.readyHandler = () => { };
|
|
8
8
|
this.stopHandler = () => { };
|
|
9
9
|
this.configLoadHandler = () => { };
|
|
10
|
+
this.serverReadyHandler = () => { };
|
|
10
11
|
}
|
|
11
12
|
onConfigLoad(configLoadHandler, app) {
|
|
12
13
|
if (typeof configLoadHandler === 'function') {
|
|
@@ -26,6 +27,15 @@ class FunctionalConfiguration {
|
|
|
26
27
|
}
|
|
27
28
|
return this;
|
|
28
29
|
}
|
|
30
|
+
onServerReady(serverReadyHandler, app) {
|
|
31
|
+
if (typeof serverReadyHandler === 'function') {
|
|
32
|
+
this.serverReadyHandler = serverReadyHandler;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return this.serverReadyHandler(serverReadyHandler, app);
|
|
36
|
+
}
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
29
39
|
onStop(stopHandler, app) {
|
|
30
40
|
if (typeof stopHandler === 'function') {
|
|
31
41
|
this.stopHandler = stopHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { BaseFramework } from './baseFramework';
|
|
|
5
5
|
export * from './context/providerWrapper';
|
|
6
6
|
export * from './common/constants';
|
|
7
7
|
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
|
|
8
|
+
export { extend } from './util/extend';
|
|
8
9
|
export * from './util/pathFileUtil';
|
|
9
10
|
export * from './util/webRouterParam';
|
|
10
11
|
export * from './common/webRouterCollector';
|
|
@@ -22,11 +23,13 @@ export { MidwayDecoratorService } from './service/decoratorService';
|
|
|
22
23
|
export * from './service/pipelineService';
|
|
23
24
|
export * from './util/contextUtil';
|
|
24
25
|
export * from './common/serviceFactory';
|
|
26
|
+
export * from './common/dataListener';
|
|
25
27
|
export * from './common/fileDetector';
|
|
26
28
|
export * from './common/webGenerator';
|
|
27
29
|
export * from './common/middlewareManager';
|
|
28
30
|
export * from './util/pathToRegexp';
|
|
29
31
|
export * from './common/filterManager';
|
|
32
|
+
export * from './common/applicationManager';
|
|
30
33
|
export * from './setup';
|
|
31
34
|
export * from './error';
|
|
32
35
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
13
|
+
exports.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
14
14
|
__exportStar(require("./interface"), exports);
|
|
15
15
|
__exportStar(require("./context/container"), exports);
|
|
16
16
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: func
|
|
|
29
29
|
Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
|
|
30
30
|
Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
|
|
31
31
|
Object.defineProperty(exports, "wrapMiddleware", { enumerable: true, get: function () { return util_1.wrapMiddleware; } });
|
|
32
|
+
var extend_1 = require("./util/extend");
|
|
33
|
+
Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
|
|
32
34
|
__exportStar(require("./util/pathFileUtil"), exports);
|
|
33
35
|
__exportStar(require("./util/webRouterParam"), exports);
|
|
34
36
|
__exportStar(require("./common/webRouterCollector"), exports);
|
|
@@ -56,11 +58,13 @@ Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get
|
|
|
56
58
|
__exportStar(require("./service/pipelineService"), exports);
|
|
57
59
|
__exportStar(require("./util/contextUtil"), exports);
|
|
58
60
|
__exportStar(require("./common/serviceFactory"), exports);
|
|
61
|
+
__exportStar(require("./common/dataListener"), exports);
|
|
59
62
|
__exportStar(require("./common/fileDetector"), exports);
|
|
60
63
|
__exportStar(require("./common/webGenerator"), exports);
|
|
61
64
|
__exportStar(require("./common/middlewareManager"), exports);
|
|
62
65
|
__exportStar(require("./util/pathToRegexp"), exports);
|
|
63
66
|
__exportStar(require("./common/filterManager"), exports);
|
|
67
|
+
__exportStar(require("./common/applicationManager"), exports);
|
|
64
68
|
__exportStar(require("./setup"), exports);
|
|
65
69
|
__exportStar(require("./error"), exports);
|
|
66
70
|
/**
|
package/dist/interface.d.ts
CHANGED
|
@@ -14,9 +14,19 @@ export declare type ServiceFactoryConfigOption<OPTIONS> = {
|
|
|
14
14
|
[key: string]: PowerPartial<OPTIONS>;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
declare type ConfigType<T> = T extends (...args: any[]) => any ? PowerPartial<ReturnType<T
|
|
17
|
+
declare type ConfigType<T> = T extends (...args: any[]) => any ? Writable<PowerPartial<ReturnType<T>>> : Writable<PowerPartial<T>>;
|
|
18
|
+
/**
|
|
19
|
+
* Get definition from config
|
|
20
|
+
*/
|
|
18
21
|
export declare type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T> ? Pick<ConfigType<T>, K> : ConfigType<T>;
|
|
19
22
|
/**
|
|
23
|
+
* Make object property writeable
|
|
24
|
+
*/
|
|
25
|
+
export declare type Writable<T> = {
|
|
26
|
+
-readonly [P in keyof T]: T[P];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Lifecycle Definition
|
|
20
30
|
* 生命周期定义
|
|
21
31
|
*/
|
|
22
32
|
export interface ILifeCycle extends Partial<IObjectLifeCycle> {
|
|
@@ -29,8 +39,8 @@ export declare type ObjectContext = {
|
|
|
29
39
|
originName?: string;
|
|
30
40
|
};
|
|
31
41
|
/**
|
|
42
|
+
* Abstract Object Factory
|
|
32
43
|
* 对象容器抽象
|
|
33
|
-
* 默认用Xml容器实现一个
|
|
34
44
|
*/
|
|
35
45
|
export interface IObjectFactory {
|
|
36
46
|
registry: IObjectDefinitionRegistry;
|
|
@@ -46,32 +56,36 @@ export declare enum ObjectLifeCycleEvent {
|
|
|
46
56
|
AFTER_INIT = "afterObjectInit",
|
|
47
57
|
BEFORE_DESTROY = "beforeObjectDestroy"
|
|
48
58
|
}
|
|
59
|
+
interface ObjectLifeCycleOptions {
|
|
60
|
+
context: IMidwayContainer;
|
|
61
|
+
definition: IObjectDefinition;
|
|
62
|
+
}
|
|
63
|
+
export interface ObjectBeforeBindOptions extends ObjectLifeCycleOptions {
|
|
64
|
+
replaceCallback: (newDefinition: IObjectDefinition) => void;
|
|
65
|
+
}
|
|
66
|
+
export interface ObjectBeforeCreatedOptions extends ObjectLifeCycleOptions {
|
|
67
|
+
constructorArgs: any[];
|
|
68
|
+
}
|
|
69
|
+
export interface ObjectCreatedOptions<T> extends ObjectLifeCycleOptions {
|
|
70
|
+
replaceCallback: (ins: T) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface ObjectInitOptions extends ObjectLifeCycleOptions {
|
|
73
|
+
}
|
|
74
|
+
export interface ObjectBeforeDestroyOptions extends ObjectLifeCycleOptions {
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Object Lifecycle
|
|
78
|
+
* 对象生命周期
|
|
79
|
+
*/
|
|
49
80
|
export interface IObjectLifeCycle {
|
|
50
|
-
onBeforeBind(fn: (Clzz: any, options:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
onBeforeObjectCreated(fn: (Clzz: any, options: {
|
|
56
|
-
context: IMidwayContainer;
|
|
57
|
-
definition: IObjectDefinition;
|
|
58
|
-
constructorArgs: any[];
|
|
59
|
-
}) => void): any;
|
|
60
|
-
onObjectCreated<T>(fn: (ins: T, options: {
|
|
61
|
-
context: IMidwayContainer;
|
|
62
|
-
definition: IObjectDefinition;
|
|
63
|
-
replaceCallback: (ins: T) => void;
|
|
64
|
-
}) => void): any;
|
|
65
|
-
onObjectInit<T>(fn: (ins: T, options: {
|
|
66
|
-
context: IMidwayContainer;
|
|
67
|
-
definition: IObjectDefinition;
|
|
68
|
-
}) => void): any;
|
|
69
|
-
onBeforeObjectDestroy<T>(fn: (ins: T, options: {
|
|
70
|
-
context: IMidwayContainer;
|
|
71
|
-
definition: IObjectDefinition;
|
|
72
|
-
}) => void): any;
|
|
81
|
+
onBeforeBind(fn: (Clzz: any, options: ObjectBeforeBindOptions) => void): any;
|
|
82
|
+
onBeforeObjectCreated(fn: (Clzz: any, options: ObjectBeforeCreatedOptions) => void): any;
|
|
83
|
+
onObjectCreated<T>(fn: (ins: T, options: ObjectCreatedOptions<T>) => void): any;
|
|
84
|
+
onObjectInit<T>(fn: (ins: T, options: ObjectInitOptions) => void): any;
|
|
85
|
+
onBeforeObjectDestroy<T>(fn: (ins: T, options: ObjectBeforeDestroyOptions) => void): any;
|
|
73
86
|
}
|
|
74
87
|
/**
|
|
88
|
+
* Object Definition
|
|
75
89
|
* 对象描述定义
|
|
76
90
|
*/
|
|
77
91
|
export interface IObjectDefinition {
|
|
@@ -112,6 +126,7 @@ export interface IObjectDefinition {
|
|
|
112
126
|
metadata: any;
|
|
113
127
|
}>;
|
|
114
128
|
createFrom: 'framework' | 'file' | 'module';
|
|
129
|
+
allowDowngrade: boolean;
|
|
115
130
|
}
|
|
116
131
|
export interface IObjectCreator {
|
|
117
132
|
load(): any;
|
|
@@ -123,6 +138,7 @@ export interface IObjectCreator {
|
|
|
123
138
|
doDestroyAsync(obj: any): Promise<void>;
|
|
124
139
|
}
|
|
125
140
|
/**
|
|
141
|
+
* Object Definition Registry
|
|
126
142
|
* 对象定义存储容器
|
|
127
143
|
*/
|
|
128
144
|
export interface IObjectDefinitionRegistry {
|
|
@@ -279,7 +295,7 @@ export declare type NextFunction = () => Promise<any>;
|
|
|
279
295
|
* Common middleware definition
|
|
280
296
|
*/
|
|
281
297
|
export interface IMiddleware<CTX, R, N = unknown> {
|
|
282
|
-
resolve: () => FunctionMiddleware<CTX, R, N
|
|
298
|
+
resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N> | Promise<FunctionMiddleware<CTX, R, N>>;
|
|
283
299
|
match?: (ctx?: CTX) => boolean;
|
|
284
300
|
ignore?: (ctx?: CTX) => boolean;
|
|
285
301
|
}
|
|
@@ -396,7 +412,11 @@ export interface IMidwayBootstrapOptions {
|
|
|
396
412
|
appDir?: string;
|
|
397
413
|
applicationContext?: IMidwayContainer;
|
|
398
414
|
preloadModules?: any[];
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated please use 'imports'
|
|
417
|
+
*/
|
|
399
418
|
configurationModule?: any | any[];
|
|
419
|
+
imports?: any | any[];
|
|
400
420
|
moduleDetector?: 'file' | IFileDetector | false;
|
|
401
421
|
logger?: boolean | ILogger;
|
|
402
422
|
ignore?: string[];
|
|
@@ -432,7 +452,8 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
432
452
|
getProjectName(): string;
|
|
433
453
|
getDefaultContextLoggerClass(): any;
|
|
434
454
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
435
|
-
getMiddleware(
|
|
455
|
+
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
456
|
+
applyMiddleware(lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
436
457
|
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): any;
|
|
437
458
|
}
|
|
438
459
|
export declare const MIDWAY_LOGGER_WRITEABLE_DIR = "MIDWAY_LOGGER_WRITEABLE_DIR";
|
|
@@ -449,6 +470,7 @@ export interface MidwayAppInfo {
|
|
|
449
470
|
* midway global config definition
|
|
450
471
|
*/
|
|
451
472
|
export interface MidwayConfig extends FileConfigOption<typeof _default> {
|
|
473
|
+
[customConfigKey: string]: unknown;
|
|
452
474
|
}
|
|
453
475
|
export {};
|
|
454
476
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -64,7 +64,7 @@ let MidwayAspectService = class MidwayAspectService {
|
|
|
64
64
|
*/
|
|
65
65
|
interceptPrototypeMethod(Clz, methodName, aspectObject) {
|
|
66
66
|
const originMethod = Clz.prototype[methodName];
|
|
67
|
-
if (
|
|
67
|
+
if (decorator_1.Types.isAsyncFunction(Clz.prototype[methodName])) {
|
|
68
68
|
Clz.prototype[methodName] = async function (...args) {
|
|
69
69
|
var _a, _b, _c;
|
|
70
70
|
let error, result;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IConfigService } from '../interface';
|
|
1
|
+
import { IConfigService, MidwayAppInfo } from '../interface';
|
|
2
2
|
import { MidwayEnvironmentService } from './environmentService';
|
|
3
3
|
import { MidwayInformationService } from './informationService';
|
|
4
4
|
export declare class MidwayConfigService implements IConfigService {
|
|
@@ -7,8 +7,10 @@ export declare class MidwayConfigService implements IConfigService {
|
|
|
7
7
|
protected configuration: any;
|
|
8
8
|
protected isReady: boolean;
|
|
9
9
|
protected externalObject: Record<string, unknown>[];
|
|
10
|
+
protected appInfo: MidwayAppInfo;
|
|
10
11
|
protected environmentService: MidwayEnvironmentService;
|
|
11
12
|
protected informationService: MidwayInformationService;
|
|
13
|
+
protected init(): Promise<void>;
|
|
12
14
|
add(configFilePaths: any[]): void;
|
|
13
15
|
addObject(obj: Record<string, unknown>): void;
|
|
14
16
|
private getEnvSet;
|
|
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayConfigService = void 0;
|
|
13
|
-
const extend = require("extend2");
|
|
14
13
|
const path_1 = require("path");
|
|
15
14
|
const util_1 = require("../util");
|
|
16
15
|
const fs_1 = require("fs");
|
|
@@ -18,6 +17,7 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
18
17
|
const util = require("util");
|
|
19
18
|
const environmentService_1 = require("./environmentService");
|
|
20
19
|
const informationService_1 = require("./informationService");
|
|
20
|
+
const extend_1 = require("../util/extend");
|
|
21
21
|
const debug = util.debuglog('midway:debug');
|
|
22
22
|
let MidwayConfigService = class MidwayConfigService {
|
|
23
23
|
constructor() {
|
|
@@ -29,6 +29,17 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
29
29
|
this.isReady = false;
|
|
30
30
|
this.externalObject = [];
|
|
31
31
|
}
|
|
32
|
+
async init() {
|
|
33
|
+
this.appInfo = {
|
|
34
|
+
pkg: this.informationService.getPkg(),
|
|
35
|
+
name: this.informationService.getProjectName(),
|
|
36
|
+
baseDir: this.informationService.getBaseDir(),
|
|
37
|
+
appDir: this.informationService.getAppDir(),
|
|
38
|
+
HOME: this.informationService.getHome(),
|
|
39
|
+
root: this.informationService.getRoot(),
|
|
40
|
+
env: this.environmentService.getCurrentEnvironment(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
32
43
|
add(configFilePaths) {
|
|
33
44
|
for (const dir of configFilePaths) {
|
|
34
45
|
if (typeof dir === 'string') {
|
|
@@ -63,7 +74,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
63
74
|
}
|
|
64
75
|
addObject(obj) {
|
|
65
76
|
if (this.isReady) {
|
|
66
|
-
extend(true, this.configuration, obj);
|
|
77
|
+
(0, extend_1.extend)(true, this.configuration, obj);
|
|
67
78
|
}
|
|
68
79
|
else {
|
|
69
80
|
this.externalObject.push(obj);
|
|
@@ -96,20 +107,9 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
96
107
|
const target = {};
|
|
97
108
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
98
109
|
let config = await this.loadConfig(filename);
|
|
99
|
-
if (
|
|
110
|
+
if (decorator_1.Types.isFunction(config)) {
|
|
100
111
|
// eslint-disable-next-line prefer-spread
|
|
101
|
-
config = config.apply(null, [
|
|
102
|
-
{
|
|
103
|
-
pkg: this.informationService.getPkg(),
|
|
104
|
-
name: this.informationService.getProjectName(),
|
|
105
|
-
baseDir: this.informationService.getBaseDir(),
|
|
106
|
-
appDir: this.informationService.getAppDir(),
|
|
107
|
-
HOME: this.informationService.getHome(),
|
|
108
|
-
root: this.informationService.getRoot(),
|
|
109
|
-
env: this.environmentService.getCurrentEnvironment(),
|
|
110
|
-
},
|
|
111
|
-
target,
|
|
112
|
-
]);
|
|
112
|
+
config = config.apply(null, [this.appInfo, target]);
|
|
113
113
|
}
|
|
114
114
|
if (!config) {
|
|
115
115
|
continue;
|
|
@@ -120,13 +120,13 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
120
120
|
else {
|
|
121
121
|
debug('[config]: Loaded config %j', config);
|
|
122
122
|
}
|
|
123
|
-
extend(true, target, config);
|
|
123
|
+
(0, extend_1.extend)(true, target, config);
|
|
124
124
|
}
|
|
125
125
|
if (this.externalObject.length) {
|
|
126
126
|
for (const externalObject of this.externalObject) {
|
|
127
127
|
if (externalObject) {
|
|
128
128
|
debug('[config]: Loaded external object %j', externalObject);
|
|
129
|
-
extend(true, target, externalObject);
|
|
129
|
+
(0, extend_1.extend)(true, target, externalObject);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -160,6 +160,12 @@ __decorate([
|
|
|
160
160
|
(0, decorator_1.Inject)(),
|
|
161
161
|
__metadata("design:type", informationService_1.MidwayInformationService)
|
|
162
162
|
], MidwayConfigService.prototype, "informationService", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
(0, decorator_1.Init)(),
|
|
165
|
+
__metadata("design:type", Function),
|
|
166
|
+
__metadata("design:paramtypes", []),
|
|
167
|
+
__metadata("design:returntype", Promise)
|
|
168
|
+
], MidwayConfigService.prototype, "init", null);
|
|
163
169
|
MidwayConfigService = __decorate([
|
|
164
170
|
(0, decorator_1.Provide)(),
|
|
165
171
|
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|