@midwayjs/core 3.0.0-beta.8 → 3.0.2
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/baseFramework.js.map +1 -0
- package/dist/common/applicationManager.d.ts +11 -0
- package/dist/common/applicationManager.js +70 -0
- package/dist/common/applicationManager.js.map +1 -0
- package/dist/common/constants.js.map +1 -0
- package/dist/common/dataListener.d.ts +11 -0
- package/dist/common/dataListener.js +43 -0
- package/dist/common/dataListener.js.map +1 -0
- package/dist/common/fileDetector.js +1 -1
- package/dist/common/fileDetector.js.map +1 -0
- package/dist/common/filterManager.js.map +1 -0
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/middlewareManager.js.map +1 -0
- package/dist/common/serviceFactory.js.map +1 -0
- package/dist/common/triggerCollector.js.map +1 -0
- package/dist/common/webGenerator.d.ts +3 -14
- package/dist/common/webGenerator.js +21 -33
- package/dist/common/webGenerator.js.map +1 -0
- package/dist/common/webRouterCollector.js +7 -3
- package/dist/common/webRouterCollector.js.map +1 -0
- package/dist/config/config.default.js.map +1 -0
- package/dist/context/container.js +28 -13
- package/dist/context/container.js.map +1 -0
- package/dist/context/definitionRegistry.js.map +1 -0
- package/dist/context/managedResolverFactory.d.ts +1 -0
- package/dist/context/managedResolverFactory.js +20 -5
- package/dist/context/managedResolverFactory.js.map +1 -0
- package/dist/context/providerWrapper.js.map +1 -0
- package/dist/context/requestContainer.js +2 -0
- package/dist/context/requestContainer.js.map +1 -0
- package/dist/definitions/functionDefinition.d.ts +1 -0
- package/dist/definitions/functionDefinition.js +1 -0
- package/dist/definitions/functionDefinition.js.map +1 -0
- package/dist/definitions/objectCreator.js +9 -8
- package/dist/definitions/objectCreator.js.map +1 -0
- package/dist/definitions/objectDefinition.d.ts +1 -0
- package/dist/definitions/objectDefinition.js +1 -0
- package/dist/definitions/objectDefinition.js.map +1 -0
- package/dist/definitions/properties.js.map +1 -0
- package/dist/error/base.d.ts +22 -3
- package/dist/error/base.js +34 -5
- package/dist/error/base.js.map +1 -0
- package/dist/error/framework.d.ts +27 -2
- package/dist/error/framework.js +51 -14
- package/dist/error/framework.js.map +1 -0
- package/dist/error/http.d.ts +146 -41
- package/dist/error/http.js +164 -31
- package/dist/error/http.js.map +1 -0
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +4 -1
- package/dist/error/index.js.map +1 -0
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/functional/configuration.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -0
- package/dist/interface.d.ts +51 -29
- package/dist/interface.js.map +1 -0
- package/dist/service/aspectService.js +1 -1
- package/dist/service/aspectService.js.map +1 -0
- package/dist/service/configService.d.ts +3 -1
- package/dist/service/configService.js +23 -17
- package/dist/service/configService.js.map +1 -0
- package/dist/service/decoratorService.js +25 -13
- package/dist/service/decoratorService.js.map +1 -0
- package/dist/service/environmentService.d.ts +1 -1
- package/dist/service/environmentService.js.map +1 -0
- package/dist/service/frameworkService.d.ts +3 -2
- package/dist/service/frameworkService.js +17 -12
- package/dist/service/frameworkService.js.map +1 -0
- package/dist/service/informationService.js.map +1 -0
- package/dist/service/lifeCycleService.js +5 -5
- package/dist/service/lifeCycleService.js.map +1 -0
- package/dist/service/loggerService.d.ts +1 -1
- package/dist/service/loggerService.js.map +1 -0
- package/dist/service/middlewareService.d.ts +3 -4
- package/dist/service/middlewareService.js +7 -11
- package/dist/service/middlewareService.js.map +1 -0
- package/dist/service/pipelineService.js.map +1 -0
- package/dist/setup.js +13 -5
- package/dist/setup.js.map +1 -0
- package/dist/util/contextUtil.js.map +1 -0
- package/dist/util/extend.d.ts +2 -0
- package/dist/util/extend.js +55 -0
- package/dist/util/extend.js.map +1 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/pathFileUtil.js.map +1 -0
- package/dist/util/pathToRegexp.js.map +1 -0
- package/dist/util/webRouterParam.js +24 -4
- package/dist/util/webRouterParam.js.map +1 -0
- package/package.json +12 -13
- package/CHANGELOG.md +0 -2197
- 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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/error/http.ts"],"names":[],"mappings":";;;AAAA,iCAAuD;AAEvD,IAAY,UAiDX;AAjDD,WAAY,UAAU;IACpB,qDAAc,CAAA;IACd,2EAAyB,CAAA;IACzB,yDAAgB,CAAA;IAChB,yDAAgB,CAAA;IAChB,yCAAQ,CAAA;IACR,mDAAa,CAAA;IACb,qDAAc,CAAA;IACd,+FAAmC,CAAA;IACnC,yDAAgB,CAAA;IAChB,+DAAmB,CAAA;IACnB,mEAAqB,CAAA;IACrB,uDAAe,CAAA;IACf,uEAAuB,CAAA;IACvB,+CAAW,CAAA;IACX,uDAAe,CAAA;IACf,6DAAkB,CAAA;IAClB,yEAAwB,CAAA;IACxB,yEAAwB,CAAA;IACxB,2DAAiB,CAAA;IACjB,6DAAkB,CAAA;IAClB,qEAAsB,CAAA;IACtB,uDAAe,CAAA;IACf,uDAAe,CAAA;IACf,yEAAwB,CAAA;IACxB,iEAAoB,CAAA;IACpB,+FAAmC,CAAA;IACnC,mEAAqB,CAAA;IACrB,qDAAc,CAAA;IACd,6CAAU,CAAA;IACV,mEAAqB,CAAA;IACrB,2EAAyB,CAAA;IACzB,uEAAuB,CAAA;IAC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CAAC,CAAC;IAClD,CAAC;CACF;AAJD,kDAIC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,sBAAe;IAClD,YAAY,eAA6B,aAAa;QACpD,KAAK,CAAC,YAAY,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;CACF;AAJD,0CAIC;AAED;;GAEG;AACH,MAAa,uBAAwB,SAAQ,sBAAe;IAC1D,YAAY,eAA6B,qBAAqB;QAC5D,KAAK,CAAC,YAAY,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACtD,CAAC;CACF;AAJD,0DAIC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,sBAAe;IACtD,YAAY,eAA6B,iBAAiB;QACxD,KAAK,CAAC,YAAY,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC;CACF;AAJD,kDAIC;AAEY,QAAA,SAAS,GAAG;IACvB,eAAe;IACf,iBAAiB;IACjB,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,mBAAmB;IACnB,aAAa;IACb,SAAS;IACT,oBAAoB;IACpB,yBAAyB;IACzB,wBAAwB;IACxB,wBAAwB;IACxB,mBAAmB;IACnB,eAAe;IACf,uBAAuB;IACvB,mBAAmB;CACpB,CAAC","sourcesContent":["import { MidwayHttpError, ResOrMessage } from './base';\n\nexport enum HttpStatus {\n CONTINUE = 100,\n SWITCHING_PROTOCOLS = 101,\n PROCESSING = 102,\n EARLYHINTS = 103,\n OK = 200,\n CREATED = 201,\n ACCEPTED = 202,\n NON_AUTHORITATIVE_INFORMATION = 203,\n NO_CONTENT = 204,\n RESET_CONTENT = 205,\n PARTIAL_CONTENT = 206,\n AMBIGUOUS = 300,\n MOVED_PERMANENTLY = 301,\n FOUND = 302,\n SEE_OTHER = 303,\n NOT_MODIFIED = 304,\n TEMPORARY_REDIRECT = 307,\n PERMANENT_REDIRECT = 308,\n BAD_REQUEST = 400,\n UNAUTHORIZED = 401,\n PAYMENT_REQUIRED = 402,\n FORBIDDEN = 403,\n NOT_FOUND = 404,\n METHOD_NOT_ALLOWED = 405,\n NOT_ACCEPTABLE = 406,\n PROXY_AUTHENTICATION_REQUIRED = 407,\n REQUEST_TIMEOUT = 408,\n CONFLICT = 409,\n GONE = 410,\n LENGTH_REQUIRED = 411,\n PRECONDITION_FAILED = 412,\n PAYLOAD_TOO_LARGE = 413,\n URI_TOO_LONG = 414,\n UNSUPPORTED_MEDIA_TYPE = 415,\n REQUESTED_RANGE_NOT_SATISFIABLE = 416,\n EXPECTATION_FAILED = 417,\n I_AM_A_TEAPOT = 418,\n MISDIRECTED = 421,\n UNPROCESSABLE_ENTITY = 422,\n FAILED_DEPENDENCY = 424,\n PRECONDITION_REQUIRED = 428,\n TOO_MANY_REQUESTS = 429,\n INTERNAL_SERVER_ERROR = 500,\n NOT_IMPLEMENTED = 501,\n BAD_GATEWAY = 502,\n SERVICE_UNAVAILABLE = 503,\n GATEWAY_TIMEOUT = 504,\n HTTP_VERSION_NOT_SUPPORTED = 505,\n}\n\n/**\n * 400 http error, Means that the request can be fulfilled because of the bad syntax.\n */\nexport class BadRequestError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Bad Request') {\n super(resOrMessage, HttpStatus.BAD_REQUEST);\n }\n}\n\n/**\n * 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.\n */\nexport class UnauthorizedError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Unauthorized') {\n super(resOrMessage, HttpStatus.UNAUTHORIZED);\n }\n}\n\n/**\n * \t4o4 http error, Means that the requested page cannot be found at the moment, but it may be available again in the future.\n */\nexport class NotFoundError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Not Found') {\n super(resOrMessage, HttpStatus.NOT_FOUND);\n }\n}\n\n/**\n * 403 http error, Means that the request is legal, but the server is rejecting to answer it.\n */\nexport class ForbiddenError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Forbidden') {\n super(resOrMessage, HttpStatus.FORBIDDEN);\n }\n}\n\n/**\n * 406 http error, Means that the server can only generate an answer which the client doesn't accept.\n */\nexport class NotAcceptableError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Not Acceptable') {\n super(resOrMessage, HttpStatus.NOT_ACCEPTABLE);\n }\n}\n\n/**\n * 408 http error, Means that the server timed out waiting for the request.\n */\nexport class RequestTimeoutError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Request Timeout') {\n super(resOrMessage, HttpStatus.REQUEST_TIMEOUT);\n }\n}\n\n/**\n * 409 http error, Means that the request cannot be completed, because of a conflict in the request.\n */\nexport class ConflictError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Conflict') {\n super(resOrMessage, HttpStatus.CONFLICT);\n }\n}\n\n/**\n * 410 http error, Means that the requested page is not available anymore.\n */\nexport class GoneError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Gone') {\n super(resOrMessage, HttpStatus.GONE);\n }\n}\n\n/**\n * 413 http error, Means that the request entity is too large and that's why the server won't accept the request.\n */\nexport class PayloadTooLargeError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Request Entity Too Large') {\n super(resOrMessage, HttpStatus.PAYLOAD_TOO_LARGE);\n }\n}\n\n/**\n * 415 http error, Means that the media type is not supported and that's why the server won't accept the request.\n */\nexport class UnsupportedMediaTypeError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Unsupported Media Type') {\n super(resOrMessage, HttpStatus.UNSUPPORTED_MEDIA_TYPE);\n }\n}\n\nexport class UnprocessableEntityError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Unprocessable Entity') {\n super(resOrMessage, HttpStatus.UNPROCESSABLE_ENTITY);\n }\n}\n\n/**\n * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.\n */\nexport class InternalServerErrorError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Internal Server Error') {\n super(resOrMessage, HttpStatus.INTERNAL_SERVER_ERROR);\n }\n}\n\n/**\n * 501 http error, Means that the server doesn't recognize the request method or it lacks the ability to fulfill the request.\n */\nexport class NotImplementedError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Not Implemented') {\n super(resOrMessage, HttpStatus.NOT_IMPLEMENTED);\n }\n}\n\n/**\n * 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.\n */\nexport class BadGatewayError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Bad Gateway') {\n super(resOrMessage, HttpStatus.BAD_GATEWAY);\n }\n}\n\n/**\n * 503 http error, Means that the server is not available now (It may be overloaded or down).\n */\nexport class ServiceUnavailableError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Service Unavailable') {\n super(resOrMessage, HttpStatus.SERVICE_UNAVAILABLE);\n }\n}\n\n/**\n * 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.\n */\nexport class GatewayTimeoutError extends MidwayHttpError {\n constructor(resOrMessage: ResOrMessage = 'Gateway Timeout') {\n super(resOrMessage, HttpStatus.GATEWAY_TIMEOUT);\n }\n}\n\nexport const httpError = {\n BadRequestError,\n UnauthorizedError,\n NotFoundError,\n ForbiddenError,\n NotAcceptableError,\n RequestTimeoutError,\n ConflictError,\n GoneError,\n PayloadTooLargeError,\n UnsupportedMediaTypeError,\n UnprocessableEntityError,\n InternalServerErrorError,\n NotImplementedError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n};\n"]}
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yCAAuB;AACvB,+BAA+C;AAAtC,kGAAA,UAAU,OAAA;AAAE,iGAAA,SAAS,OAAA;AAC9B,8CAA4B","sourcesContent":["export * from './base';\nexport { HttpStatus, httpError } from './http';\nexport * from './framework';\n"]}
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/functional/configuration.ts"],"names":[],"mappings":";;;AAGA,MAAa,uBAAuB;IAOlC,YAAY,OAAsC;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,iBAAiB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAClC,IAAI,CAAC,kBAAkB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IACrC,CAAC;IAED,YAAY,CACV,iBAEoB,EACpB,GAAwB;QAExB,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE;YAC3C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;SAC5C;aAAM;YACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;SACvD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,YAEoB,EACpB,GAAwB;QAExB,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE;YACtC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;SAClC;aAAM;YACL,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;SAC7C;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CACX,kBAEoB,EACpB,GAAwB;QAExB,IAAI,OAAO,kBAAkB,KAAK,UAAU,EAAE;YAC5C,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;SAC9C;aAAM;YACL,OAAO,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;SACzD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CACJ,WAEoB,EACpB,GAAwB;QAExB,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE;YACrC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;SAChC;aAAM;YACL,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uBAAuB;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA1ED,0DA0EC;AAEM,MAAM,mBAAmB,GAAG,CAAC,OAAsC,EAAE,EAAE;IAC5E,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["import { IMidwayApplication, IMidwayContainer } from '../interface';\nimport { InjectionConfigurationOptions } from '@midwayjs/decorator';\n\nexport class FunctionalConfiguration {\n private readyHandler;\n private stopHandler;\n private configLoadHandler;\n private serverReadyHandler;\n private options: InjectionConfigurationOptions;\n\n constructor(options: InjectionConfigurationOptions) {\n this.options = options;\n this.readyHandler = () => {};\n this.stopHandler = () => {};\n this.configLoadHandler = () => {};\n this.serverReadyHandler = () => {};\n }\n\n onConfigLoad(\n configLoadHandler:\n | ((container: IMidwayContainer, app: IMidwayApplication) => any)\n | IMidwayContainer,\n app?: IMidwayApplication\n ) {\n if (typeof configLoadHandler === 'function') {\n this.configLoadHandler = configLoadHandler;\n } else {\n return this.configLoadHandler(configLoadHandler, app);\n }\n return this;\n }\n\n onReady(\n readyHandler:\n | ((container: IMidwayContainer, app: IMidwayApplication) => void)\n | IMidwayContainer,\n app?: IMidwayApplication\n ) {\n if (typeof readyHandler === 'function') {\n this.readyHandler = readyHandler;\n } else {\n return this.readyHandler(readyHandler, app);\n }\n return this;\n }\n\n onServerReady(\n serverReadyHandler:\n | ((container: IMidwayContainer, app: IMidwayApplication) => void)\n | IMidwayContainer,\n app?: IMidwayApplication\n ) {\n if (typeof serverReadyHandler === 'function') {\n this.serverReadyHandler = serverReadyHandler;\n } else {\n return this.serverReadyHandler(serverReadyHandler, app);\n }\n return this;\n }\n\n onStop(\n stopHandler:\n | ((container: IMidwayContainer, app: IMidwayApplication) => void)\n | IMidwayContainer,\n app?: IMidwayApplication\n ) {\n if (typeof stopHandler === 'function') {\n this.stopHandler = stopHandler;\n } else {\n return this.stopHandler(stopHandler, app);\n }\n return this;\n }\n\n getConfigurationOptions() {\n return this.options;\n }\n}\n\nexport const createConfiguration = (options: InjectionConfigurationOptions) => {\n return new FunctionalConfiguration(options);\n};\n"]}
|
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"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B,0CAAwB;AAExB;;GAEG;AACH,iDAA0D;AAAjD,gHAAA,mBAAmB,OAAA","sourcesContent":["export * from './interface';\nexport * from './context/container';\nexport { MidwayRequestContainer } from './context/requestContainer';\nexport { BaseFramework } from './baseFramework';\nexport * from './context/providerWrapper';\nexport * from './common/constants';\nexport {\n safelyGet,\n safeRequire,\n delegateTargetPrototypeMethod,\n delegateTargetMethod,\n delegateTargetProperties,\n deprecatedOutput,\n transformRequestObjectByType,\n pathMatching,\n wrapMiddleware,\n} from './util/';\nexport { extend } from './util/extend';\nexport * from './util/pathFileUtil';\nexport * from './util/webRouterParam';\nexport * from './common/webRouterCollector';\nexport * from './common/triggerCollector';\nexport { createConfiguration } from './functional/configuration';\nexport { MidwayConfigService } from './service/configService';\nexport { MidwayEnvironmentService } from './service/environmentService';\nexport { MidwayInformationService } from './service/informationService';\nexport { MidwayLoggerService } from './service/loggerService';\nexport { MidwayFrameworkService } from './service/frameworkService';\nexport { MidwayAspectService } from './service/aspectService';\nexport { MidwayLifeCycleService } from './service/lifeCycleService';\nexport { MidwayMiddlewareService } from './service/middlewareService';\nexport { MidwayDecoratorService } from './service/decoratorService';\nexport * from './service/pipelineService';\nexport * from './util/contextUtil';\nexport * from './common/serviceFactory';\nexport * from './common/dataListener';\nexport * from './common/fileDetector';\nexport * from './common/webGenerator';\nexport * from './common/middlewareManager';\nexport * from './util/pathToRegexp';\nexport * from './common/filterManager';\nexport * from './common/applicationManager';\nexport * from './setup';\nexport * from './error';\n\n/**\n * proxy\n */\nexport { MidwayFrameworkType } from '@midwayjs/decorator';\nexport { ILogger, IMidwayLogger } from '@midwayjs/logger';\n"]}
|
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,13 +412,17 @@ 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[];
|
|
403
|
-
globalConfig?: {
|
|
423
|
+
globalConfig?: Array<{
|
|
404
424
|
[environmentName: string]: Record<string, any>;
|
|
405
|
-
}
|
|
425
|
+
}> | Record<string, any>;
|
|
406
426
|
}
|
|
407
427
|
export interface IConfigurationOptions {
|
|
408
428
|
logger?: ILogger;
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AAiGA,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,kDAA0B,CAAA;IAC1B,8DAAsC,CAAA;IACtC,4DAAoC,CAAA;IACpC,sDAA8B,CAAA;IAC9B,8DAAsC,CAAA;AACxC,CAAC,EANW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAM/B;AAkJY,QAAA,eAAe,GAAG,KAAK,CAAC;AACxB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AACjC,QAAA,eAAe,GAAG,qBAAqB,CAAC;AAqGrD,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,oDAA2B,CAAA;IAC3B,wCAAe,CAAA;AACjB,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAkPY,QAAA,2BAA2B,GAAG,6BAA6B,CAAC","sourcesContent":["import {\n ObjectIdentifier,\n IManagedInstance,\n IMethodAspect,\n ScopeEnum,\n FrameworkType,\n} from '@midwayjs/decorator';\nimport { ILogger, LoggerOptions } from '@midwayjs/logger';\nimport * as EventEmitter from 'events';\nimport { ContextMiddlewareManager } from './common/middlewareManager';\nimport _default from './config/config.default';\n\nexport type PowerPartial<T> = {\n [U in keyof T]?: T[U] extends {} ? PowerPartial<T[U]> : T[U];\n};\n\nexport type ServiceFactoryConfigOption<OPTIONS> = {\n default?: PowerPartial<OPTIONS>;\n client?: PowerPartial<OPTIONS>;\n clients?: {\n [key: string]: PowerPartial<OPTIONS>;\n };\n};\n\ntype ConfigType<T> = T extends (...args: any[]) => any\n ? Writable<PowerPartial<ReturnType<T>>>\n : Writable<PowerPartial<T>>;\n\n/**\n * Get definition from config\n */\nexport type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T>\n ? Pick<ConfigType<T>, K>\n : ConfigType<T>;\n\n/**\n * Make object property writeable\n */\nexport type Writable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\n/**\n * Lifecycle Definition\n * 生命周期定义\n */\nexport interface ILifeCycle extends Partial<IObjectLifeCycle> {\n onConfigLoad?(\n container: IMidwayContainer,\n mainApp?: IMidwayApplication\n ): Promise<any>;\n onReady?(\n container: IMidwayContainer,\n mainApp?: IMidwayApplication\n ): Promise<void>;\n onServerReady?(\n container: IMidwayContainer,\n mainApp?: IMidwayApplication\n ): Promise<void>;\n onStop?(\n container: IMidwayContainer,\n mainApp?: IMidwayApplication\n ): Promise<void>;\n}\n\nexport type ObjectContext = {\n originName?: string;\n};\n\n/**\n * Abstract Object Factory\n * 对象容器抽象\n */\nexport interface IObjectFactory {\n registry: IObjectDefinitionRegistry;\n get<T>(\n identifier: new (...args) => T,\n args?: any[],\n objectContext?: ObjectContext\n ): T;\n get<T>(\n identifier: ObjectIdentifier,\n args?: any[],\n objectContext?: ObjectContext\n ): T;\n getAsync<T>(\n identifier: new (...args) => T,\n args?: any[],\n objectContext?: ObjectContext\n ): Promise<T>;\n getAsync<T>(\n identifier: ObjectIdentifier,\n args?: any[],\n objectContext?: ObjectContext\n ): Promise<T>;\n}\n\nexport enum ObjectLifeCycleEvent {\n BEFORE_BIND = 'beforeBind',\n BEFORE_CREATED = 'beforeObjectCreated',\n AFTER_CREATED = 'afterObjectCreated',\n AFTER_INIT = 'afterObjectInit',\n BEFORE_DESTROY = 'beforeObjectDestroy',\n}\n\ninterface ObjectLifeCycleOptions {\n context: IMidwayContainer;\n definition: IObjectDefinition;\n}\n\nexport interface ObjectBeforeBindOptions extends ObjectLifeCycleOptions {\n replaceCallback: (newDefinition: IObjectDefinition) => void;\n}\n\nexport interface ObjectBeforeCreatedOptions extends ObjectLifeCycleOptions {\n constructorArgs: any[];\n}\n\nexport interface ObjectCreatedOptions<T> extends ObjectLifeCycleOptions {\n replaceCallback: (ins: T) => void;\n}\n\nexport interface ObjectInitOptions extends ObjectLifeCycleOptions {}\n\nexport interface ObjectBeforeDestroyOptions extends ObjectLifeCycleOptions {}\n\n/**\n * Object Lifecycle\n * 对象生命周期\n */\nexport interface IObjectLifeCycle {\n onBeforeBind(fn: (Clzz: any, options: ObjectBeforeBindOptions) => void);\n onBeforeObjectCreated(\n fn: (Clzz: any, options: ObjectBeforeCreatedOptions) => void\n );\n onObjectCreated<T>(fn: (ins: T, options: ObjectCreatedOptions<T>) => void);\n onObjectInit<T>(fn: (ins: T, options: ObjectInitOptions) => void);\n onBeforeObjectDestroy<T>(\n fn: (ins: T, options: ObjectBeforeDestroyOptions) => void\n );\n}\n\n/**\n * Object Definition\n * 对象描述定义\n */\nexport interface IObjectDefinition {\n namespace?: string;\n creator: IObjectCreator;\n id: string;\n name: string;\n initMethod: string;\n destroyMethod: string;\n constructMethod: string;\n srcPath: string;\n path: any;\n export: string;\n dependsOn: ObjectIdentifier[];\n constructorArgs: IManagedInstance[];\n properties: IProperties;\n scope: ScopeEnum;\n isAsync(): boolean;\n isSingletonScope(): boolean;\n isRequestScope(): boolean;\n hasDependsOn(): boolean;\n hasConstructorArgs(): boolean;\n getAttr(key: ObjectIdentifier): any;\n hasAttr(key: ObjectIdentifier): boolean;\n setAttr(key: ObjectIdentifier, value: any): void;\n // 自定义装饰器的 key、propertyName\n handlerProps: Array<{\n /**\n * decorator property name set\n */\n propertyName: string;\n /**\n * decorator uuid key\n */\n key: string;\n /**\n * custom decorator set metadata\n */\n metadata: any;\n }>;\n createFrom: 'framework' | 'file' | 'module';\n allowDowngrade: boolean;\n}\n\nexport interface IObjectCreator {\n load(): any;\n doConstruct(Clzz: any, args?: any, context?: IMidwayContainer): any;\n doConstructAsync(\n Clzz: any,\n args?: any,\n context?: IMidwayContainer\n ): Promise<any>;\n doInit(obj: any): void;\n doInitAsync(obj: any): Promise<void>;\n doDestroy(obj: any): void;\n doDestroyAsync(obj: any): Promise<void>;\n}\n/**\n * Object Definition Registry\n * 对象定义存储容器\n */\nexport interface IObjectDefinitionRegistry {\n readonly identifiers: ObjectIdentifier[];\n readonly count: number;\n registerDefinition(\n identifier: ObjectIdentifier,\n definition: IObjectDefinition\n );\n getSingletonDefinitionIds(): ObjectIdentifier[];\n getDefinition(identifier: ObjectIdentifier): IObjectDefinition;\n getDefinitionByName(name: string): IObjectDefinition[];\n removeDefinition(identifier: ObjectIdentifier): void;\n hasDefinition(identifier: ObjectIdentifier): boolean;\n clearAll(): void;\n hasObject(identifier: ObjectIdentifier): boolean;\n registerObject(identifier: ObjectIdentifier, target: any);\n getObject(identifier: ObjectIdentifier): any;\n getIdentifierRelation(): IIdentifierRelationShip;\n setIdentifierRelation(identifierRelation: IIdentifierRelationShip);\n}\n/**\n * 属性配置抽象\n */\nexport interface IProperties extends Map<ObjectIdentifier, any> {\n getProperty(key: ObjectIdentifier, defaultValue?: any): any;\n setProperty(key: ObjectIdentifier, value: any): any;\n propertyKeys(): ObjectIdentifier[];\n}\n\n/**\n * 解析内部管理的属性、json、ref等实例的解析器\n * 同时创建这些对象的实际使用的对象\n */\nexport interface IManagedResolver {\n type: string;\n resolve(managed: IManagedInstance): any;\n resolveAsync(managed: IManagedInstance): Promise<any>;\n}\n\nexport interface IManagedResolverFactoryCreateOptions {\n definition: IObjectDefinition;\n args?: any;\n namespace?: string;\n}\n\nexport const REQUEST_CTX_KEY = 'ctx';\nexport const REQUEST_OBJ_CTX_KEY = '_req_ctx';\nexport const HTTP_SERVER_KEY = '_midway_http_server';\n\nexport type HandlerFunction = (\n /**\n * decorator uuid key\n */\n key: string,\n /**\n * decorator set metadata\n */\n meta: any,\n instance: any\n) => any;\n\nexport type MethodHandlerFunction = (options: {\n target: new (...args) => any;\n propertyName: string;\n metadata: any;\n}) => IMethodAspect;\nexport type ParameterHandlerFunction = (options: {\n target: new (...args) => any;\n propertyName: string;\n metadata: any;\n originArgs: Array<any>;\n originParamType: any;\n parameterIndex: number;\n}) => IMethodAspect;\n\nexport interface IIdentifierRelationShip {\n saveClassRelation(module: any, namespace?: string);\n saveFunctionRelation(ObjectIdentifier, uuid);\n hasRelation(id: ObjectIdentifier): boolean;\n getRelation(id: ObjectIdentifier): string;\n}\n\nexport interface IMidwayContainer extends IObjectFactory, IObjectLifeCycle {\n parent: IMidwayContainer;\n identifierMapping: IIdentifierRelationShip;\n objectCreateEventTarget: EventEmitter;\n ready();\n stop(): Promise<void>;\n registerObject(identifier: ObjectIdentifier, target: any);\n load(module?: any);\n hasNamespace(namespace: string): boolean;\n hasDefinition(identifier: ObjectIdentifier);\n hasObject(identifier: ObjectIdentifier);\n bind<T>(target: T, options?: Partial<IObjectDefinition>): void;\n bind<T>(\n identifier: ObjectIdentifier,\n target: T,\n options?: Partial<IObjectDefinition>\n ): void;\n bindClass(exports, options?: Partial<IObjectDefinition>);\n setFileDetector(fileDetector: IFileDetector);\n createChild(): IMidwayContainer;\n /**\n * Set value to app attribute map\n * @param key\n * @param value\n */\n setAttr(key: string, value: any);\n\n /**\n * Get value from app attribute map\n * @param key\n */\n getAttr<T>(key: string): T;\n}\n\n/**\n * @deprecated\n */\nexport type IApplicationContext = IMidwayContainer;\n\nexport interface IFileDetector {\n run(container: IMidwayContainer);\n}\n\nexport interface IConfigService {\n add(configFilePaths: any[]);\n addObject(obj: object);\n load();\n getConfiguration(configKey?: string);\n clearAllConfig();\n}\n\nexport interface IInformationService {\n getPkg(): any;\n getProjectName(): any;\n getBaseDir(): string;\n getAppDir(): string;\n getHome(): string;\n getRoot(): string;\n}\n\nexport interface IEnvironmentService {\n getCurrentEnvironment(): string;\n setCurrentEnvironment(environment: string);\n isDevelopmentEnvironment(): boolean;\n}\n\nexport enum MidwayProcessTypeEnum {\n APPLICATION = 'APPLICATION',\n AGENT = 'AGENT',\n}\n\nexport interface Context {\n /**\n * Custom properties.\n */\n requestContext: IMidwayContainer;\n logger: ILogger;\n getLogger(name?: string): ILogger;\n startTime: number;\n /**\n * Set value to app attribute map\n * @param key\n * @param value\n */\n setAttr(key: string, value: any);\n\n /**\n * Get value from app attribute map\n * @param key\n */\n getAttr<T>(key: string): T;\n}\n\nexport type IMidwayContext<FrameworkContext = unknown> = Context &\n FrameworkContext;\nexport type NextFunction = () => Promise<any>;\n\n/**\n * Common middleware definition\n */\nexport interface IMiddleware<CTX, R, N = unknown> {\n resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N> | Promise<FunctionMiddleware<CTX, R, N>>;\n match?: (ctx?: CTX) => boolean;\n ignore?: (ctx?: CTX) => boolean;\n}\nexport type FunctionMiddleware<CTX, R, N = unknown> = N extends true\n ? (req: CTX, res: R, next: N) => any\n : (context: CTX, next: R, options?: any) => any;\nexport type ClassMiddleware<CTX, R, N> = new (...args) => IMiddleware<\n CTX,\n R,\n N\n>;\nexport type CommonMiddleware<CTX, R, N> =\n | ClassMiddleware<CTX, R, N>\n | FunctionMiddleware<CTX, R, N>;\nexport type CommonMiddlewareUnion<CTX, R, N> =\n | CommonMiddleware<CTX, R, N>\n | Array<CommonMiddleware<CTX, R, N>>;\nexport type MiddlewareRespond<CTX, R, N> = (\n context: CTX,\n nextOrRes?: N extends true ? R : NextFunction,\n next?: N\n) => Promise<{ result: any; error: Error | undefined }>;\n\n/**\n * Common Exception Filter definition\n */\nexport interface IFilter<CTX, R, N> {\n catch?(err: Error, ctx: CTX, res?: R, next?: N): any;\n match?(result: any, ctx: CTX, res?: R, next?: N): any;\n}\nexport type CommonFilterUnion<CTX, R, N> =\n | (new (...args) => IFilter<CTX, R, N>)\n | Array<new (...args) => IFilter<CTX, R, N>>;\n\nexport interface IMidwayBaseApplication<CTX extends IMidwayContext> {\n /**\n * Get a base directory for project, with src or dist\n */\n getBaseDir(): string;\n\n /**\n * Get a project root directory, without src or dist\n */\n getAppDir(): string;\n\n /**\n * Get a environment value, read from MIDWAY_SERVER_ENV\n */\n getEnv(): string;\n\n /**\n * Get current framework type in MidwayFrameworkType enum\n */\n getFrameworkType(): FrameworkType;\n\n /**\n * Get current running process type, app or agent, just for egg\n */\n getProcessType(): MidwayProcessTypeEnum;\n\n /**\n * Get global Midway IoC Container\n */\n getApplicationContext(): IMidwayContainer;\n\n /**\n * Get all configuration values or get the specified configuration through parameters\n * @param key config key\n */\n getConfig(key?: string): any;\n\n /**\n * Get default logger object or get the specified logger through parameters\n * @param name\n */\n getLogger(name?: string): ILogger;\n\n /**\n * Get core logger\n */\n getCoreLogger(): ILogger;\n\n /**\n * Create a logger by name and options\n * @param name\n * @param options\n */\n createLogger(name: string, options: LoggerOptions): ILogger;\n\n /**\n * Get project name, just package.json name\n */\n getProjectName(): string;\n\n /**\n * create a context with RequestContainer\n * @param args\n */\n createAnonymousContext(...args): CTX;\n\n /**\n * Set a context logger class to change default context logger format\n * @param BaseContextLoggerClass\n */\n setContextLoggerClass(BaseContextLoggerClass: any): void;\n\n /**\n * Add new value to current config\n * @param obj\n */\n addConfigObject(obj: any);\n\n /**\n * Set value to app attribute map\n * @param key\n * @param value\n */\n setAttr(key: string, value: any);\n\n /**\n * Get value from app attribute map\n * @param key\n */\n getAttr<T>(key: string): T;\n\n /**\n * add global filter to app\n * @param Middleware\n */\n useMiddleware<R, N>(Middleware: CommonMiddlewareUnion<CTX, R, N>): void;\n\n /**\n * get global middleware\n */\n getMiddleware<R, N>(): ContextMiddlewareManager<CTX, R, N>;\n\n /**\n * add exception filter\n * @param Filter\n */\n useFilter<R, N>(Filter: CommonFilterUnion<CTX, R, N>): void;\n}\n\nexport type IMidwayApplication<\n T extends IMidwayContext = IMidwayContext,\n FrameworkApplication = unknown\n> = IMidwayBaseApplication<T> & FrameworkApplication;\n\nexport interface IMidwayBootstrapOptions {\n [customPropertyKey: string]: any;\n baseDir?: string;\n appDir?: string;\n applicationContext?: IMidwayContainer;\n preloadModules?: any[];\n /**\n * @deprecated please use 'imports'\n */\n configurationModule?: any | any[];\n imports?: any | any[];\n moduleDetector?: 'file' | IFileDetector | false;\n logger?: boolean | ILogger;\n ignore?: string[];\n globalConfig?:\n | Array<{ [environmentName: string]: Record<string, any> }>\n | Record<string, any>;\n}\n\nexport interface IConfigurationOptions {\n logger?: ILogger;\n appLogger?: ILogger;\n ContextLoggerClass?: any;\n ContextLoggerApplyLogger?: string;\n}\n\nexport interface IMidwayFramework<\n APP extends IMidwayApplication<CTX>,\n CTX extends IMidwayContext,\n CONFIG extends IConfigurationOptions,\n ResOrNext = unknown,\n Next = unknown\n> {\n app: APP;\n configurationOptions: CONFIG;\n configure(options?: CONFIG);\n isEnable(): boolean;\n initialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;\n run(): Promise<void>;\n stop(): Promise<void>;\n getApplication(): APP;\n getApplicationContext(): IMidwayContainer;\n getConfiguration(key?: string): any;\n getCurrentEnvironment(): string;\n getFrameworkType(): FrameworkType;\n getFrameworkName(): string;\n getAppDir(): string;\n getBaseDir(): string;\n getLogger(name?: string): ILogger;\n getCoreLogger(): ILogger;\n createLogger(name: string, options: LoggerOptions): ILogger;\n getProjectName(): string;\n getDefaultContextLoggerClass(): any;\n useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;\n getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;\n applyMiddleware(\n lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>\n ): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;\n useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>);\n}\n\nexport const MIDWAY_LOGGER_WRITEABLE_DIR = 'MIDWAY_LOGGER_WRITEABLE_DIR';\n\nexport interface MidwayAppInfo {\n pkg: Record<string, any>;\n name: string;\n baseDir: string;\n appDir: string;\n HOME: string;\n root: string;\n env: string;\n}\n\n/**\n * midway global config definition\n */\nexport interface MidwayConfig extends FileConfigOption<typeof _default> {\n [customConfigKey: string]: unknown;\n}\n"]}
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aspectService.js","sourceRoot":"","sources":["../../src/service/aspectService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAW6B;AAC7B,gCAAgC;AAKhC,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,YAAqB,kBAAoC;QAApC,uBAAkB,G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/B;AA7JY,kDAAmB","sourcesContent":["import {\n ASPECT_KEY,\n AspectMetadata,\n getClassMetadata,\n IMethodAspect,\n Types,\n listModule,\n Provide,\n Scope,\n ScopeEnum,\n JoinPoint,\n} from '@midwayjs/decorator';\nimport * as pm from 'picomatch';\nimport { IMidwayContainer } from '../interface';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class MidwayAspectService {\n constructor(readonly applicationContext: IMidwayContainer) {}\n\n /**\n * load aspect method for container\n */\n public async loadAspect() {\n // for aop implementation\n const aspectModules = listModule(ASPECT_KEY);\n // sort for aspect target\n let aspectDataList = [];\n for (const module of aspectModules) {\n const data = getClassMetadata(ASPECT_KEY, module);\n aspectDataList = aspectDataList.concat(\n data.map(el => {\n el.aspectModule = module;\n return el;\n })\n );\n }\n\n // sort priority\n aspectDataList.sort((pre, next) => {\n return (next.priority || 0) - (pre.priority || 0);\n });\n\n for (const aspectData of aspectDataList) {\n // aspect instance init\n const aspectIns = await this.applicationContext.getAsync<IMethodAspect>(\n aspectData.aspectModule\n );\n await this.addAspect(aspectIns, aspectData);\n }\n }\n\n private async addAspect(\n aspectIns: IMethodAspect,\n aspectData: AspectMetadata\n ) {\n const module = aspectData.aspectTarget;\n const names = Object.getOwnPropertyNames(module.prototype);\n const isMatch = aspectData.match ? pm(aspectData.match) : () => true;\n\n for (const name of names) {\n if (name === 'constructor' || !isMatch(name)) {\n continue;\n }\n const descriptor = Object.getOwnPropertyDescriptor(\n module.prototype,\n name\n );\n if (!descriptor || descriptor.writable === false) {\n continue;\n }\n\n this.interceptPrototypeMethod(module, name, aspectIns);\n }\n }\n\n /**\n * intercept class method in prototype\n * @param Clz class you want to intercept\n * @param methodName method name you want to intercept\n * @param aspectObject aspect object, before, round, etc.\n */\n public interceptPrototypeMethod(\n Clz: new (...args) => any,\n methodName: string,\n aspectObject: IMethodAspect | (() => IMethodAspect)\n ) {\n const originMethod = Clz.prototype[methodName];\n\n if (Types.isAsyncFunction(Clz.prototype[methodName])) {\n Clz.prototype[methodName] = async function (...args) {\n let error, result;\n const newProceed = (...args) => {\n return originMethod.apply(this, args);\n };\n const joinPoint = {\n methodName,\n target: this,\n args: args,\n proceed: newProceed,\n } as JoinPoint;\n\n if (typeof aspectObject === 'function') {\n aspectObject = aspectObject();\n }\n\n try {\n await aspectObject.before?.(joinPoint);\n if (aspectObject.around) {\n result = await aspectObject.around(joinPoint);\n } else {\n result = await originMethod.call(this, ...joinPoint.args);\n }\n joinPoint.proceed = undefined;\n const resultTemp = await aspectObject.afterReturn?.(\n joinPoint,\n result\n );\n result = typeof resultTemp === 'undefined' ? result : resultTemp;\n return result;\n } catch (err) {\n joinPoint.proceed = undefined;\n error = err;\n if (aspectObject.afterThrow) {\n await aspectObject.afterThrow(joinPoint, error);\n } else {\n throw err;\n }\n } finally {\n await aspectObject.after?.(joinPoint, result, error);\n }\n };\n } else {\n Clz.prototype[methodName] = function (...args) {\n let error, result;\n const newProceed = (...args) => {\n return originMethod.apply(this, args);\n };\n const joinPoint = {\n methodName,\n target: this,\n args: args,\n proceed: newProceed,\n } as JoinPoint;\n\n if (typeof aspectObject === 'function') {\n aspectObject = aspectObject();\n }\n\n try {\n aspectObject.before?.(joinPoint);\n if (aspectObject.around) {\n result = aspectObject.around(joinPoint);\n } else {\n result = originMethod.call(this, ...joinPoint.args);\n }\n joinPoint.proceed = undefined;\n const resultTemp = aspectObject.afterReturn?.(joinPoint, result);\n result = typeof resultTemp === 'undefined' ? result : resultTemp;\n return result;\n } catch (err) {\n joinPoint.proceed = undefined;\n error = err;\n if (aspectObject.afterThrow) {\n aspectObject.afterThrow(joinPoint, error);\n } else {\n throw err;\n }\n } finally {\n aspectObject.after?.(joinPoint, result, error);\n }\n };\n }\n }\n}\n"]}
|