@midwayjs/core 3.0.0-beta.1 → 3.0.0-beta.13
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 +138 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +13 -10
- package/dist/baseFramework.js +32 -23
- package/dist/common/applicationManager.d.ts +12 -0
- package/dist/common/applicationManager.js +66 -0
- package/dist/{util → common}/fileDetector.d.ts +0 -0
- package/dist/{util → common}/fileDetector.js +0 -0
- package/dist/common/filterManager.d.ts +19 -0
- package/dist/common/filterManager.js +85 -0
- package/dist/common/middlewareManager.d.ts +68 -0
- package/dist/common/middlewareManager.js +183 -0
- package/dist/{util → common}/serviceFactory.d.ts +0 -0
- package/dist/{util → common}/serviceFactory.js +0 -0
- package/dist/{util → common}/triggerCollector.d.ts +0 -0
- package/dist/{util → common}/triggerCollector.js +0 -0
- package/dist/common/webGenerator.d.ts +16 -0
- package/dist/{util → common}/webGenerator.js +36 -51
- package/dist/{util → common}/webRouterCollector.d.ts +9 -4
- package/dist/{util → common}/webRouterCollector.js +53 -29
- package/dist/config/config.default.d.ts +3 -17
- package/dist/context/container.js +13 -2
- package/dist/context/managedResolverFactory.js +5 -5
- package/dist/definitions/objectCreator.js +3 -2
- package/dist/error/base.d.ts +24 -3
- package/dist/error/base.js +34 -4
- package/dist/error/framework.d.ts +26 -2
- package/dist/error/framework.js +48 -10
- package/dist/error/http.d.ts +145 -38
- package/dist/error/http.js +162 -30
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +13 -11
- package/dist/interface.d.ts +59 -30
- package/dist/service/configService.js +4 -5
- package/dist/service/decoratorService.js +33 -25
- package/dist/service/frameworkService.d.ts +6 -4
- package/dist/service/frameworkService.js +26 -11
- package/dist/service/lifeCycleService.js +7 -5
- package/dist/service/loggerService.d.ts +1 -2
- package/dist/service/loggerService.js +1 -10
- package/dist/service/middlewareService.d.ts +3 -4
- package/dist/service/middlewareService.js +28 -46
- package/dist/setup.js +10 -2
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/index.d.ts +46 -0
- package/dist/util/index.js +150 -1
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +41 -22
- package/package.json +7 -7
- package/dist/error/code.d.ts +0 -59
- package/dist/error/code.js +0 -64
- package/dist/util/exceptionFilterManager.d.ts +0 -13
- package/dist/util/exceptionFilterManager.js +0 -53
- package/dist/util/middlewareManager.d.ts +0 -11
- package/dist/util/middlewareManager.js +0 -48
- package/dist/util/webGenerator.d.ts +0 -30
package/dist/error/http.js
CHANGED
|
@@ -1,67 +1,199 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.InternalServerErrorError = exports.UnprocessableError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
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 UnprocessableError extends
|
|
146
|
+
class UnprocessableError extends base_1.MidwayHttpError {
|
|
147
|
+
constructor(resOrMessage = 'Unprocessable Entity') {
|
|
148
|
+
super(resOrMessage, HttpStatus.UNPROCESSABLE_ENTITY);
|
|
149
|
+
}
|
|
48
150
|
}
|
|
49
151
|
exports.UnprocessableError = UnprocessableError;
|
|
50
|
-
|
|
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
|
+
/**
|
|
170
|
+
* 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.
|
|
171
|
+
*/
|
|
172
|
+
class BadGatewayError extends base_1.MidwayHttpError {
|
|
173
|
+
constructor(resOrMessage = 'Bad Gateway') {
|
|
174
|
+
super(resOrMessage, HttpStatus.BAD_GATEWAY);
|
|
175
|
+
}
|
|
56
176
|
}
|
|
57
177
|
exports.BadGatewayError = BadGatewayError;
|
|
58
|
-
|
|
178
|
+
/**
|
|
179
|
+
* 503 http error, Means that the server is not available now (It may be overloaded or down).
|
|
180
|
+
*/
|
|
181
|
+
class ServiceUnavailableError extends base_1.MidwayHttpError {
|
|
182
|
+
constructor(resOrMessage = 'Service Unavailable') {
|
|
183
|
+
super(resOrMessage, HttpStatus.SERVICE_UNAVAILABLE);
|
|
184
|
+
}
|
|
59
185
|
}
|
|
60
186
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
61
|
-
|
|
187
|
+
/**
|
|
188
|
+
* 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.
|
|
189
|
+
*/
|
|
190
|
+
class GatewayTimeoutError extends base_1.MidwayHttpError {
|
|
191
|
+
constructor(resOrMessage = 'Gateway Timeout') {
|
|
192
|
+
super(resOrMessage, HttpStatus.GATEWAY_TIMEOUT);
|
|
193
|
+
}
|
|
62
194
|
}
|
|
63
195
|
exports.GatewayTimeoutError = GatewayTimeoutError;
|
|
64
|
-
exports.
|
|
196
|
+
exports.httpError = {
|
|
65
197
|
BadRequestError,
|
|
66
198
|
UnauthorizedError,
|
|
67
199
|
NotFoundError,
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -10,6 +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
|
+
__exportStar(require("./base"), exports);
|
|
13
14
|
__exportStar(require("./http"), exports);
|
|
14
15
|
__exportStar(require("./framework"), exports);
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,11 @@ export { MidwayRequestContainer } from './context/requestContainer';
|
|
|
4
4
|
export { BaseFramework } from './baseFramework';
|
|
5
5
|
export * from './context/providerWrapper';
|
|
6
6
|
export * from './common/constants';
|
|
7
|
-
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, } from './util/';
|
|
7
|
+
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
|
|
8
8
|
export * from './util/pathFileUtil';
|
|
9
9
|
export * from './util/webRouterParam';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export { plainToClass, classToPlain } from 'class-transformer';
|
|
10
|
+
export * from './common/webRouterCollector';
|
|
11
|
+
export * from './common/triggerCollector';
|
|
13
12
|
export { createConfiguration } from './functional/configuration';
|
|
14
13
|
export { MidwayConfigService } from './service/configService';
|
|
15
14
|
export { MidwayEnvironmentService } from './service/environmentService';
|
|
@@ -22,12 +21,13 @@ export { MidwayMiddlewareService } from './service/middlewareService';
|
|
|
22
21
|
export { MidwayDecoratorService } from './service/decoratorService';
|
|
23
22
|
export * from './service/pipelineService';
|
|
24
23
|
export * from './util/contextUtil';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './
|
|
28
|
-
export * from './
|
|
24
|
+
export * from './common/serviceFactory';
|
|
25
|
+
export * from './common/fileDetector';
|
|
26
|
+
export * from './common/webGenerator';
|
|
27
|
+
export * from './common/middlewareManager';
|
|
29
28
|
export * from './util/pathToRegexp';
|
|
30
|
-
export * from './
|
|
29
|
+
export * from './common/filterManager';
|
|
30
|
+
export * from './common/applicationManager';
|
|
31
31
|
export * from './setup';
|
|
32
32
|
export * from './error';
|
|
33
33
|
/**
|
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.
|
|
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;
|
|
14
14
|
__exportStar(require("./interface"), exports);
|
|
15
15
|
__exportStar(require("./context/container"), exports);
|
|
16
16
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -25,13 +25,14 @@ Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function
|
|
|
25
25
|
Object.defineProperty(exports, "delegateTargetPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetPrototypeMethod; } });
|
|
26
26
|
Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get: function () { return util_1.delegateTargetMethod; } });
|
|
27
27
|
Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
|
|
28
|
+
Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: function () { return util_1.deprecatedOutput; } });
|
|
29
|
+
Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
|
|
30
|
+
Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
|
|
31
|
+
Object.defineProperty(exports, "wrapMiddleware", { enumerable: true, get: function () { return util_1.wrapMiddleware; } });
|
|
28
32
|
__exportStar(require("./util/pathFileUtil"), exports);
|
|
29
33
|
__exportStar(require("./util/webRouterParam"), exports);
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
32
|
-
var class_transformer_1 = require("class-transformer");
|
|
33
|
-
Object.defineProperty(exports, "plainToClass", { enumerable: true, get: function () { return class_transformer_1.plainToClass; } });
|
|
34
|
-
Object.defineProperty(exports, "classToPlain", { enumerable: true, get: function () { return class_transformer_1.classToPlain; } });
|
|
34
|
+
__exportStar(require("./common/webRouterCollector"), exports);
|
|
35
|
+
__exportStar(require("./common/triggerCollector"), exports);
|
|
35
36
|
var configuration_1 = require("./functional/configuration");
|
|
36
37
|
Object.defineProperty(exports, "createConfiguration", { enumerable: true, get: function () { return configuration_1.createConfiguration; } });
|
|
37
38
|
var configService_1 = require("./service/configService");
|
|
@@ -54,12 +55,13 @@ var decoratorService_1 = require("./service/decoratorService");
|
|
|
54
55
|
Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get: function () { return decoratorService_1.MidwayDecoratorService; } });
|
|
55
56
|
__exportStar(require("./service/pipelineService"), exports);
|
|
56
57
|
__exportStar(require("./util/contextUtil"), exports);
|
|
57
|
-
__exportStar(require("./
|
|
58
|
-
__exportStar(require("./
|
|
59
|
-
__exportStar(require("./
|
|
60
|
-
__exportStar(require("./
|
|
58
|
+
__exportStar(require("./common/serviceFactory"), exports);
|
|
59
|
+
__exportStar(require("./common/fileDetector"), exports);
|
|
60
|
+
__exportStar(require("./common/webGenerator"), exports);
|
|
61
|
+
__exportStar(require("./common/middlewareManager"), exports);
|
|
61
62
|
__exportStar(require("./util/pathToRegexp"), exports);
|
|
62
|
-
__exportStar(require("./
|
|
63
|
+
__exportStar(require("./common/filterManager"), exports);
|
|
64
|
+
__exportStar(require("./common/applicationManager"), exports);
|
|
63
65
|
__exportStar(require("./setup"), exports);
|
|
64
66
|
__exportStar(require("./error"), exports);
|
|
65
67
|
/**
|
package/dist/interface.d.ts
CHANGED
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
import { ObjectIdentifier, IManagedInstance, IMethodAspect, ScopeEnum, FrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
4
4
|
import * as EventEmitter from 'events';
|
|
5
|
-
import { ContextMiddlewareManager } from './
|
|
5
|
+
import { ContextMiddlewareManager } from './common/middlewareManager';
|
|
6
|
+
import _default from './config/config.default';
|
|
7
|
+
export declare type PowerPartial<T> = {
|
|
8
|
+
[U in keyof T]?: T[U] extends {} ? PowerPartial<T[U]> : T[U];
|
|
9
|
+
};
|
|
10
|
+
export declare type ServiceFactoryConfigOption<OPTIONS> = {
|
|
11
|
+
default?: PowerPartial<OPTIONS>;
|
|
12
|
+
client?: PowerPartial<OPTIONS>;
|
|
13
|
+
clients?: {
|
|
14
|
+
[key: string]: PowerPartial<OPTIONS>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare type ConfigType<T> = T extends (...args: any[]) => any ? PowerPartial<ReturnType<T>> : PowerPartial<T>;
|
|
18
|
+
export declare type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T> ? Pick<ConfigType<T>, K> : ConfigType<T>;
|
|
6
19
|
/**
|
|
7
20
|
* 生命周期定义
|
|
8
21
|
*/
|
|
9
22
|
export interface ILifeCycle extends Partial<IObjectLifeCycle> {
|
|
10
|
-
onConfigLoad?(container: IMidwayContainer,
|
|
11
|
-
onReady?(container: IMidwayContainer,
|
|
12
|
-
onServerReady?(container: IMidwayContainer,
|
|
13
|
-
onStop?(container: IMidwayContainer,
|
|
23
|
+
onConfigLoad?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<any>;
|
|
24
|
+
onReady?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
25
|
+
onServerReady?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
26
|
+
onStop?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
14
27
|
}
|
|
15
28
|
export declare type ObjectContext = {
|
|
16
29
|
originName?: string;
|
|
@@ -172,6 +185,7 @@ export declare type ParameterHandlerFunction = (options: {
|
|
|
172
185
|
propertyName: string;
|
|
173
186
|
metadata: any;
|
|
174
187
|
originArgs: Array<any>;
|
|
188
|
+
originParamType: any;
|
|
175
189
|
parameterIndex: number;
|
|
176
190
|
}) => IMethodAspect;
|
|
177
191
|
export interface IIdentifierRelationShip {
|
|
@@ -260,30 +274,32 @@ export interface Context {
|
|
|
260
274
|
getAttr<T>(key: string): T;
|
|
261
275
|
}
|
|
262
276
|
export declare type IMidwayContext<FrameworkContext = unknown> = Context & FrameworkContext;
|
|
277
|
+
export declare type NextFunction = () => Promise<any>;
|
|
263
278
|
/**
|
|
264
279
|
* Common middleware definition
|
|
265
280
|
*/
|
|
266
|
-
export interface IMiddleware<
|
|
267
|
-
resolve: () => FunctionMiddleware<
|
|
268
|
-
match?: () => boolean;
|
|
269
|
-
ignore?: () => boolean;
|
|
281
|
+
export interface IMiddleware<CTX, R, N = unknown> {
|
|
282
|
+
resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N>;
|
|
283
|
+
match?: (ctx?: CTX) => boolean;
|
|
284
|
+
ignore?: (ctx?: CTX) => boolean;
|
|
270
285
|
}
|
|
271
|
-
export declare type FunctionMiddleware<
|
|
272
|
-
export declare type ClassMiddleware<
|
|
273
|
-
export declare type CommonMiddleware<
|
|
274
|
-
export declare type CommonMiddlewareUnion<
|
|
275
|
-
export declare type MiddlewareRespond<
|
|
286
|
+
export declare type FunctionMiddleware<CTX, R, N = unknown> = N extends true ? (req: CTX, res: R, next: N) => any : (context: CTX, next: R, options?: any) => any;
|
|
287
|
+
export declare type ClassMiddleware<CTX, R, N> = new (...args: any[]) => IMiddleware<CTX, R, N>;
|
|
288
|
+
export declare type CommonMiddleware<CTX, R, N> = ClassMiddleware<CTX, R, N> | FunctionMiddleware<CTX, R, N>;
|
|
289
|
+
export declare type CommonMiddlewareUnion<CTX, R, N> = CommonMiddleware<CTX, R, N> | Array<CommonMiddleware<CTX, R, N>>;
|
|
290
|
+
export declare type MiddlewareRespond<CTX, R, N> = (context: CTX, nextOrRes?: N extends true ? R : NextFunction, next?: N) => Promise<{
|
|
276
291
|
result: any;
|
|
277
292
|
error: Error | undefined;
|
|
278
293
|
}>;
|
|
279
294
|
/**
|
|
280
295
|
* Common Exception Filter definition
|
|
281
296
|
*/
|
|
282
|
-
export interface
|
|
283
|
-
catch(err: Error, ctx:
|
|
297
|
+
export interface IFilter<CTX, R, N> {
|
|
298
|
+
catch?(err: Error, ctx: CTX, res?: R, next?: N): any;
|
|
299
|
+
match?(result: any, ctx: CTX, res?: R, next?: N): any;
|
|
284
300
|
}
|
|
285
|
-
export declare type
|
|
286
|
-
export interface IMidwayBaseApplication<
|
|
301
|
+
export declare type CommonFilterUnion<CTX, R, N> = (new (...args: any[]) => IFilter<CTX, R, N>) | Array<new (...args: any[]) => IFilter<CTX, R, N>>;
|
|
302
|
+
export interface IMidwayBaseApplication<CTX extends IMidwayContext> {
|
|
287
303
|
/**
|
|
288
304
|
* Get a base directory for project, with src or dist
|
|
289
305
|
*/
|
|
@@ -336,7 +352,7 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
336
352
|
* create a context with RequestContainer
|
|
337
353
|
* @param args
|
|
338
354
|
*/
|
|
339
|
-
createAnonymousContext(...args: any[]):
|
|
355
|
+
createAnonymousContext(...args: any[]): CTX;
|
|
340
356
|
/**
|
|
341
357
|
* Set a context logger class to change default context logger format
|
|
342
358
|
* @param BaseContextLoggerClass
|
|
@@ -362,16 +378,16 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
362
378
|
* add global filter to app
|
|
363
379
|
* @param Middleware
|
|
364
380
|
*/
|
|
365
|
-
useMiddleware<R
|
|
381
|
+
useMiddleware<R, N>(Middleware: CommonMiddlewareUnion<CTX, R, N>): void;
|
|
366
382
|
/**
|
|
367
383
|
* get global middleware
|
|
368
384
|
*/
|
|
369
|
-
getMiddleware<R
|
|
385
|
+
getMiddleware<R, N>(): ContextMiddlewareManager<CTX, R, N>;
|
|
370
386
|
/**
|
|
371
387
|
* add exception filter
|
|
372
388
|
* @param Filter
|
|
373
389
|
*/
|
|
374
|
-
useFilter(Filter:
|
|
390
|
+
useFilter<R, N>(Filter: CommonFilterUnion<CTX, R, N>): void;
|
|
375
391
|
}
|
|
376
392
|
export declare type IMidwayApplication<T extends IMidwayContext = IMidwayContext, FrameworkApplication = unknown> = IMidwayBaseApplication<T> & FrameworkApplication;
|
|
377
393
|
export interface IMidwayBootstrapOptions {
|
|
@@ -384,9 +400,9 @@ export interface IMidwayBootstrapOptions {
|
|
|
384
400
|
moduleDetector?: 'file' | IFileDetector | false;
|
|
385
401
|
logger?: boolean | ILogger;
|
|
386
402
|
ignore?: string[];
|
|
387
|
-
globalConfig?: {
|
|
403
|
+
globalConfig?: Array<{
|
|
388
404
|
[environmentName: string]: Record<string, any>;
|
|
389
|
-
}
|
|
405
|
+
}> | Record<string, any>;
|
|
390
406
|
}
|
|
391
407
|
export interface IConfigurationOptions {
|
|
392
408
|
logger?: ILogger;
|
|
@@ -394,10 +410,10 @@ export interface IConfigurationOptions {
|
|
|
394
410
|
ContextLoggerClass?: any;
|
|
395
411
|
ContextLoggerApplyLogger?: string;
|
|
396
412
|
}
|
|
397
|
-
export interface IMidwayFramework<APP extends IMidwayApplication,
|
|
413
|
+
export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
|
|
398
414
|
app: APP;
|
|
399
|
-
configurationOptions:
|
|
400
|
-
configure(options?:
|
|
415
|
+
configurationOptions: CONFIG;
|
|
416
|
+
configure(options?: CONFIG): any;
|
|
401
417
|
isEnable(): boolean;
|
|
402
418
|
initialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
403
419
|
run(): Promise<void>;
|
|
@@ -415,9 +431,10 @@ export interface IMidwayFramework<APP extends IMidwayApplication, T extends ICon
|
|
|
415
431
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
416
432
|
getProjectName(): string;
|
|
417
433
|
getDefaultContextLoggerClass(): any;
|
|
418
|
-
useMiddleware(Middleware: CommonMiddlewareUnion<
|
|
419
|
-
getMiddleware
|
|
420
|
-
|
|
434
|
+
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
435
|
+
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
436
|
+
applyMiddleware(lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
437
|
+
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): any;
|
|
421
438
|
}
|
|
422
439
|
export declare const MIDWAY_LOGGER_WRITEABLE_DIR = "MIDWAY_LOGGER_WRITEABLE_DIR";
|
|
423
440
|
export interface MidwayAppInfo {
|
|
@@ -429,4 +446,16 @@ export interface MidwayAppInfo {
|
|
|
429
446
|
root: string;
|
|
430
447
|
env: string;
|
|
431
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* midway global config definition
|
|
451
|
+
*/
|
|
452
|
+
export interface MidwayConfig extends FileConfigOption<typeof _default> {
|
|
453
|
+
[customConfigKey: string]: unknown;
|
|
454
|
+
}
|
|
455
|
+
export interface TranslateOptions {
|
|
456
|
+
lang?: string;
|
|
457
|
+
group?: string;
|
|
458
|
+
args?: any;
|
|
459
|
+
}
|
|
460
|
+
export {};
|
|
432
461
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -95,10 +95,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
95
95
|
// merge set
|
|
96
96
|
const target = {};
|
|
97
97
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
98
|
-
let config = filename;
|
|
99
|
-
if (typeof filename === 'string') {
|
|
100
|
-
config = await this.loadConfig(filename);
|
|
101
|
-
}
|
|
98
|
+
let config = await this.loadConfig(filename);
|
|
102
99
|
if ((0, decorator_1.isFunction)(config)) {
|
|
103
100
|
// eslint-disable-next-line prefer-spread
|
|
104
101
|
config = config.apply(null, [
|
|
@@ -143,7 +140,9 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
143
140
|
return this.configuration;
|
|
144
141
|
}
|
|
145
142
|
async loadConfig(configFilename) {
|
|
146
|
-
let exports =
|
|
143
|
+
let exports = typeof configFilename === 'string'
|
|
144
|
+
? require(configFilename)
|
|
145
|
+
: configFilename;
|
|
147
146
|
if (exports && exports['default'] && Object.keys(exports).length === 1) {
|
|
148
147
|
exports = exports['default'];
|
|
149
148
|
}
|
|
@@ -24,7 +24,30 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
24
24
|
}
|
|
25
25
|
async init() {
|
|
26
26
|
// add custom method decorator listener
|
|
27
|
-
this.applicationContext.onBeforeBind(
|
|
27
|
+
this.applicationContext.onBeforeBind(Clzz => {
|
|
28
|
+
// find custom method decorator metadata, include method decorator information array
|
|
29
|
+
const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
|
|
30
|
+
if (methodDecoratorMetadataList) {
|
|
31
|
+
// loop it, save this order for decorator run
|
|
32
|
+
for (const meta of methodDecoratorMetadataList) {
|
|
33
|
+
const { propertyName, key, metadata, impl } = meta;
|
|
34
|
+
if (!impl) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// add aspect implementation first
|
|
38
|
+
this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
|
|
39
|
+
const methodDecoratorHandler = this.methodDecoratorMap.get(key);
|
|
40
|
+
if (!methodDecoratorHandler) {
|
|
41
|
+
throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
|
|
42
|
+
}
|
|
43
|
+
return this.methodDecoratorMap.get(key)({
|
|
44
|
+
target: Clzz,
|
|
45
|
+
propertyName,
|
|
46
|
+
metadata,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
28
51
|
// find custom param decorator metadata
|
|
29
52
|
const parameterDecoratorMetadata = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PARAM, Clzz);
|
|
30
53
|
if (parameterDecoratorMetadata) {
|
|
@@ -37,17 +60,22 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
37
60
|
// joinPoint.args
|
|
38
61
|
const newArgs = [...joinPoint.args];
|
|
39
62
|
for (const meta of parameterDecoratorMetadata[methodName]) {
|
|
40
|
-
const { propertyName, key, metadata, parameterIndex } = meta;
|
|
63
|
+
const { propertyName, key, metadata, parameterIndex, impl } = meta;
|
|
64
|
+
if (!impl) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
41
67
|
const parameterDecoratorHandler = this.parameterDecoratorMap.get(key);
|
|
42
68
|
if (!parameterDecoratorHandler) {
|
|
43
69
|
throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
|
|
44
70
|
}
|
|
71
|
+
const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
|
|
45
72
|
newArgs[parameterIndex] = await parameterDecoratorHandler({
|
|
46
73
|
metadata,
|
|
47
74
|
propertyName,
|
|
48
75
|
parameterIndex,
|
|
49
76
|
target: Clzz,
|
|
50
77
|
originArgs: joinPoint.args,
|
|
78
|
+
originParamType: paramTypes[parameterIndex],
|
|
51
79
|
});
|
|
52
80
|
}
|
|
53
81
|
joinPoint.args = newArgs;
|
|
@@ -56,26 +84,6 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
56
84
|
});
|
|
57
85
|
}
|
|
58
86
|
}
|
|
59
|
-
// find custom method decorator metadata, include method decorator information array
|
|
60
|
-
const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
|
|
61
|
-
if (methodDecoratorMetadataList) {
|
|
62
|
-
// loop it, save this order for decorator run
|
|
63
|
-
for (const meta of methodDecoratorMetadataList) {
|
|
64
|
-
const { propertyName, key, metadata } = meta;
|
|
65
|
-
// add aspect implementation first
|
|
66
|
-
this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
|
|
67
|
-
const methodDecoratorHandler = this.methodDecoratorMap.get(key);
|
|
68
|
-
if (!methodDecoratorHandler) {
|
|
69
|
-
throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
|
|
70
|
-
}
|
|
71
|
-
return this.methodDecoratorMap.get(key)({
|
|
72
|
-
target: Clzz,
|
|
73
|
-
propertyName,
|
|
74
|
-
metadata,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
87
|
});
|
|
80
88
|
// add custom property decorator listener
|
|
81
89
|
this.applicationContext.onObjectCreated((instance, options) => {
|
|
@@ -93,15 +101,15 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
93
101
|
});
|
|
94
102
|
}
|
|
95
103
|
registerPropertyHandler(decoratorKey, fn) {
|
|
96
|
-
debug(`[core
|
|
104
|
+
debug(`[core]: Register property decorator key="${decoratorKey}"`);
|
|
97
105
|
this.propertyHandlerMap.set(decoratorKey, fn);
|
|
98
106
|
}
|
|
99
107
|
registerMethodHandler(decoratorKey, fn) {
|
|
100
|
-
debug(`[core
|
|
108
|
+
debug(`[core]: Register method decorator key="${decoratorKey}"`);
|
|
101
109
|
this.methodDecoratorMap.set(decoratorKey, fn);
|
|
102
110
|
}
|
|
103
111
|
registerParameterHandler(decoratorKey, fn) {
|
|
104
|
-
debug(`[core
|
|
112
|
+
debug(`[core]: Register parameter decorator key="${decoratorKey}"`);
|
|
105
113
|
this.parameterDecoratorMap.set(decoratorKey, fn);
|
|
106
114
|
}
|
|
107
115
|
/**
|