@midwayjs/core 3.0.0-beta.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/dist/baseFramework.d.ts +2 -1
  3. package/dist/baseFramework.js +17 -11
  4. package/dist/common/applicationManager.d.ts +11 -0
  5. package/dist/common/applicationManager.js +70 -0
  6. package/dist/common/dataListener.d.ts +11 -0
  7. package/dist/common/dataListener.js +43 -0
  8. package/dist/common/fileDetector.js +1 -1
  9. package/dist/common/middlewareManager.d.ts +62 -5
  10. package/dist/common/middlewareManager.js +141 -6
  11. package/dist/common/webGenerator.d.ts +3 -14
  12. package/dist/common/webGenerator.js +23 -31
  13. package/dist/common/webRouterCollector.js +7 -3
  14. package/dist/context/container.js +28 -13
  15. package/dist/context/managedResolverFactory.js +12 -5
  16. package/dist/context/requestContainer.js +2 -0
  17. package/dist/definitions/functionDefinition.d.ts +1 -0
  18. package/dist/definitions/functionDefinition.js +1 -0
  19. package/dist/definitions/objectCreator.js +9 -8
  20. package/dist/definitions/objectDefinition.d.ts +1 -0
  21. package/dist/definitions/objectDefinition.js +1 -0
  22. package/dist/error/base.d.ts +22 -3
  23. package/dist/error/base.js +34 -5
  24. package/dist/error/framework.d.ts +30 -2
  25. package/dist/error/framework.js +56 -13
  26. package/dist/error/http.d.ts +146 -41
  27. package/dist/error/http.js +164 -31
  28. package/dist/error/index.d.ts +1 -1
  29. package/dist/error/index.js +4 -1
  30. package/dist/functional/configuration.d.ts +2 -0
  31. package/dist/functional/configuration.js +10 -0
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.js +7 -1
  34. package/dist/interface.d.ts +51 -29
  35. package/dist/service/aspectService.js +1 -1
  36. package/dist/service/configService.d.ts +3 -1
  37. package/dist/service/configService.js +23 -17
  38. package/dist/service/decoratorService.js +11 -5
  39. package/dist/service/environmentService.d.ts +1 -1
  40. package/dist/service/frameworkService.d.ts +3 -2
  41. package/dist/service/frameworkService.js +17 -12
  42. package/dist/service/lifeCycleService.js +5 -5
  43. package/dist/service/loggerService.d.ts +1 -1
  44. package/dist/service/middlewareService.d.ts +3 -4
  45. package/dist/service/middlewareService.js +28 -24
  46. package/dist/setup.js +13 -5
  47. package/dist/util/extend.d.ts +2 -0
  48. package/dist/util/extend.js +55 -0
  49. package/dist/util/index.d.ts +9 -0
  50. package/dist/util/index.js +55 -1
  51. package/dist/util/webRouterParam.js +24 -4
  52. package/package.json +10 -11
  53. package/CHANGELOG.md +0 -2174
  54. package/dist/error/code.d.ts +0 -59
  55. package/dist/error/code.js +0 -64
@@ -1,42 +1,148 @@
1
- import { MidwayError } from './base';
2
- export declare class HttpError extends MidwayError {
3
- status: number;
4
- constructor(response: any, status: any);
5
- }
6
- export declare class BadRequestError extends HttpError {
7
- constructor(response: any);
8
- }
9
- export declare class UnauthorizedError extends HttpError {
10
- }
11
- export declare class NotFoundError extends HttpError {
12
- }
13
- export declare class ForbiddenError extends HttpError {
14
- }
15
- export declare class NotAcceptableError extends HttpError {
16
- }
17
- export declare class RequestTimeoutError extends HttpError {
18
- }
19
- export declare class ConflictError extends HttpError {
20
- }
21
- export declare class GoneError extends HttpError {
22
- }
23
- export declare class PayloadTooLargeError extends HttpError {
24
- }
25
- export declare class UnsupportedMediaTypeError extends HttpError {
26
- }
27
- export declare class UnprocessableError extends HttpError {
28
- }
29
- export declare class InternalServerErrorError extends HttpError {
30
- }
31
- declare class NotImplementedError extends HttpError {
32
- }
33
- export declare class BadGatewayError extends HttpError {
34
- }
35
- export declare class ServiceUnavailableError extends HttpError {
36
- }
37
- export declare class GatewayTimeoutError extends HttpError {
38
- }
39
- export declare const http: {
1
+ import { MidwayHttpError, ResOrMessage } from './base';
2
+ export declare enum HttpStatus {
3
+ CONTINUE = 100,
4
+ SWITCHING_PROTOCOLS = 101,
5
+ PROCESSING = 102,
6
+ EARLYHINTS = 103,
7
+ OK = 200,
8
+ CREATED = 201,
9
+ ACCEPTED = 202,
10
+ NON_AUTHORITATIVE_INFORMATION = 203,
11
+ NO_CONTENT = 204,
12
+ RESET_CONTENT = 205,
13
+ PARTIAL_CONTENT = 206,
14
+ AMBIGUOUS = 300,
15
+ MOVED_PERMANENTLY = 301,
16
+ FOUND = 302,
17
+ SEE_OTHER = 303,
18
+ NOT_MODIFIED = 304,
19
+ TEMPORARY_REDIRECT = 307,
20
+ PERMANENT_REDIRECT = 308,
21
+ BAD_REQUEST = 400,
22
+ UNAUTHORIZED = 401,
23
+ PAYMENT_REQUIRED = 402,
24
+ FORBIDDEN = 403,
25
+ NOT_FOUND = 404,
26
+ METHOD_NOT_ALLOWED = 405,
27
+ NOT_ACCEPTABLE = 406,
28
+ PROXY_AUTHENTICATION_REQUIRED = 407,
29
+ REQUEST_TIMEOUT = 408,
30
+ CONFLICT = 409,
31
+ GONE = 410,
32
+ LENGTH_REQUIRED = 411,
33
+ PRECONDITION_FAILED = 412,
34
+ PAYLOAD_TOO_LARGE = 413,
35
+ URI_TOO_LONG = 414,
36
+ UNSUPPORTED_MEDIA_TYPE = 415,
37
+ REQUESTED_RANGE_NOT_SATISFIABLE = 416,
38
+ EXPECTATION_FAILED = 417,
39
+ I_AM_A_TEAPOT = 418,
40
+ MISDIRECTED = 421,
41
+ UNPROCESSABLE_ENTITY = 422,
42
+ FAILED_DEPENDENCY = 424,
43
+ PRECONDITION_REQUIRED = 428,
44
+ TOO_MANY_REQUESTS = 429,
45
+ INTERNAL_SERVER_ERROR = 500,
46
+ NOT_IMPLEMENTED = 501,
47
+ BAD_GATEWAY = 502,
48
+ SERVICE_UNAVAILABLE = 503,
49
+ GATEWAY_TIMEOUT = 504,
50
+ HTTP_VERSION_NOT_SUPPORTED = 505
51
+ }
52
+ /**
53
+ * 400 http error, Means that the request can be fulfilled because of the bad syntax.
54
+ */
55
+ export declare class BadRequestError extends MidwayHttpError {
56
+ constructor(resOrMessage?: ResOrMessage);
57
+ }
58
+ /**
59
+ * 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.
60
+ */
61
+ export declare class UnauthorizedError extends MidwayHttpError {
62
+ constructor(resOrMessage?: ResOrMessage);
63
+ }
64
+ /**
65
+ * 4o4 http error, Means that the requested page cannot be found at the moment, but it may be available again in the future.
66
+ */
67
+ export declare class NotFoundError extends MidwayHttpError {
68
+ constructor(resOrMessage?: ResOrMessage);
69
+ }
70
+ /**
71
+ * 403 http error, Means that the request is legal, but the server is rejecting to answer it.
72
+ */
73
+ export declare class ForbiddenError extends MidwayHttpError {
74
+ constructor(resOrMessage?: ResOrMessage);
75
+ }
76
+ /**
77
+ * 406 http error, Means that the server can only generate an answer which the client doesn't accept.
78
+ */
79
+ export declare class NotAcceptableError extends MidwayHttpError {
80
+ constructor(resOrMessage?: ResOrMessage);
81
+ }
82
+ /**
83
+ * 408 http error, Means that the server timed out waiting for the request.
84
+ */
85
+ export declare class RequestTimeoutError extends MidwayHttpError {
86
+ constructor(resOrMessage?: ResOrMessage);
87
+ }
88
+ /**
89
+ * 409 http error, Means that the request cannot be completed, because of a conflict in the request.
90
+ */
91
+ export declare class ConflictError extends MidwayHttpError {
92
+ constructor(resOrMessage?: ResOrMessage);
93
+ }
94
+ /**
95
+ * 410 http error, Means that the requested page is not available anymore.
96
+ */
97
+ export declare class GoneError extends MidwayHttpError {
98
+ constructor(resOrMessage?: ResOrMessage);
99
+ }
100
+ /**
101
+ * 413 http error, Means that the request entity is too large and that's why the server won't accept the request.
102
+ */
103
+ export declare class PayloadTooLargeError extends MidwayHttpError {
104
+ constructor(resOrMessage?: ResOrMessage);
105
+ }
106
+ /**
107
+ * 415 http error, Means that the media type is not supported and that's why the server won't accept the request.
108
+ */
109
+ export declare class UnsupportedMediaTypeError extends MidwayHttpError {
110
+ constructor(resOrMessage?: ResOrMessage);
111
+ }
112
+ export declare class UnprocessableEntityError extends MidwayHttpError {
113
+ constructor(resOrMessage?: ResOrMessage);
114
+ }
115
+ /**
116
+ * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
117
+ */
118
+ export declare class InternalServerErrorError extends MidwayHttpError {
119
+ constructor(resOrMessage?: ResOrMessage);
120
+ }
121
+ /**
122
+ * 501 http error, Means that the server doesn't recognize the request method or it lacks the ability to fulfill the request.
123
+ */
124
+ export declare class NotImplementedError extends MidwayHttpError {
125
+ constructor(resOrMessage?: ResOrMessage);
126
+ }
127
+ /**
128
+ * 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.
129
+ */
130
+ export declare class BadGatewayError extends MidwayHttpError {
131
+ constructor(resOrMessage?: ResOrMessage);
132
+ }
133
+ /**
134
+ * 503 http error, Means that the server is not available now (It may be overloaded or down).
135
+ */
136
+ export declare class ServiceUnavailableError extends MidwayHttpError {
137
+ constructor(resOrMessage?: ResOrMessage);
138
+ }
139
+ /**
140
+ * 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.
141
+ */
142
+ export declare class GatewayTimeoutError extends MidwayHttpError {
143
+ constructor(resOrMessage?: ResOrMessage);
144
+ }
145
+ export declare const httpError: {
40
146
  BadRequestError: typeof BadRequestError;
41
147
  UnauthorizedError: typeof UnauthorizedError;
42
148
  NotFoundError: typeof NotFoundError;
@@ -47,12 +153,11 @@ export declare const http: {
47
153
  GoneError: typeof GoneError;
48
154
  PayloadTooLargeError: typeof PayloadTooLargeError;
49
155
  UnsupportedMediaTypeError: typeof UnsupportedMediaTypeError;
50
- UnprocessableError: typeof UnprocessableError;
156
+ UnprocessableEntityError: typeof UnprocessableEntityError;
51
157
  InternalServerErrorError: typeof InternalServerErrorError;
52
158
  NotImplementedError: typeof NotImplementedError;
53
159
  BadGatewayError: typeof BadGatewayError;
54
160
  ServiceUnavailableError: typeof ServiceUnavailableError;
55
161
  GatewayTimeoutError: typeof GatewayTimeoutError;
56
162
  };
57
- export {};
58
163
  //# sourceMappingURL=http.d.ts.map
@@ -1,67 +1,200 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.http = 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.HttpError = void 0;
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
- class HttpError extends base_1.MidwayError {
7
- constructor(response, status) {
8
- super(typeof response === 'string' ? response : response.message);
9
- this.status = status;
10
- this.name = this.constructor.name;
11
- }
12
- }
13
- exports.HttpError = HttpError;
14
- class BadRequestError extends HttpError {
15
- constructor(response) {
16
- super(response, code_1.HttpStatus.BAD_REQUEST);
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
- class UnauthorizedError extends HttpError {
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
- class NotFoundError extends HttpError {
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
- class ForbiddenError extends HttpError {
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
- class NotAcceptableError extends HttpError {
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
- class RequestTimeoutError extends HttpError {
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
- class ConflictError extends HttpError {
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
- class GoneError extends HttpError {
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
- class PayloadTooLargeError extends HttpError {
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
- class UnsupportedMediaTypeError extends HttpError {
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 HttpError {
146
+ class UnprocessableEntityError extends base_1.MidwayHttpError {
147
+ constructor(resOrMessage = 'Unprocessable Entity') {
148
+ super(resOrMessage, HttpStatus.UNPROCESSABLE_ENTITY);
149
+ }
48
150
  }
49
- exports.UnprocessableError = UnprocessableError;
50
- class InternalServerErrorError extends HttpError {
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
- class NotImplementedError extends HttpError {
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
- class BadGatewayError extends HttpError {
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
- class ServiceUnavailableError extends HttpError {
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
- class GatewayTimeoutError extends HttpError {
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.http = {
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
- UnprocessableError,
208
+ UnprocessableEntityError,
76
209
  InternalServerErrorError,
77
210
  NotImplementedError,
78
211
  BadGatewayError,
@@ -1,4 +1,4 @@
1
1
  export * from './base';
2
- export * from './http';
2
+ export { HttpStatus, httpError } from './http';
3
3
  export * from './framework';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -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
- __exportStar(require("./http"), exports);
15
+ var http_1 = require("./http");
16
+ Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return http_1.HttpStatus; } });
17
+ Object.defineProperty(exports, "httpError", { enumerable: true, get: function () { return http_1.httpError; } });
15
18
  __exportStar(require("./framework"), exports);
16
19
  //# sourceMappingURL=index.js.map
@@ -4,10 +4,12 @@ export declare class FunctionalConfiguration {
4
4
  private readyHandler;
5
5
  private stopHandler;
6
6
  private configLoadHandler;
7
+ private serverReadyHandler;
7
8
  private options;
8
9
  constructor(options: InjectionConfigurationOptions);
9
10
  onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): any;
10
11
  onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
12
+ onServerReady(serverReadyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
11
13
  onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
12
14
  getConfigurationOptions(): InjectionConfigurationOptions;
13
15
  }
@@ -7,6 +7,7 @@ class FunctionalConfiguration {
7
7
  this.readyHandler = () => { };
8
8
  this.stopHandler = () => { };
9
9
  this.configLoadHandler = () => { };
10
+ this.serverReadyHandler = () => { };
10
11
  }
11
12
  onConfigLoad(configLoadHandler, app) {
12
13
  if (typeof configLoadHandler === 'function') {
@@ -26,6 +27,15 @@ class FunctionalConfiguration {
26
27
  }
27
28
  return this;
28
29
  }
30
+ onServerReady(serverReadyHandler, app) {
31
+ if (typeof serverReadyHandler === 'function') {
32
+ this.serverReadyHandler = serverReadyHandler;
33
+ }
34
+ else {
35
+ return this.serverReadyHandler(serverReadyHandler, app);
36
+ }
37
+ return this;
38
+ }
29
39
  onStop(stopHandler, app) {
30
40
  if (typeof stopHandler === 'function') {
31
41
  this.stopHandler = stopHandler;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ 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, deprecatedOutput, transformRequestObjectByType, } from './util/';
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.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");
@@ -27,6 +27,10 @@ Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get:
27
27
  Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
28
28
  Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: function () { return util_1.deprecatedOutput; } });
29
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; } });
32
+ var extend_1 = require("./util/extend");
33
+ Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
30
34
  __exportStar(require("./util/pathFileUtil"), exports);
31
35
  __exportStar(require("./util/webRouterParam"), exports);
32
36
  __exportStar(require("./common/webRouterCollector"), exports);
@@ -54,11 +58,13 @@ Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get
54
58
  __exportStar(require("./service/pipelineService"), exports);
55
59
  __exportStar(require("./util/contextUtil"), exports);
56
60
  __exportStar(require("./common/serviceFactory"), exports);
61
+ __exportStar(require("./common/dataListener"), exports);
57
62
  __exportStar(require("./common/fileDetector"), exports);
58
63
  __exportStar(require("./common/webGenerator"), exports);
59
64
  __exportStar(require("./common/middlewareManager"), exports);
60
65
  __exportStar(require("./util/pathToRegexp"), exports);
61
66
  __exportStar(require("./common/filterManager"), exports);
67
+ __exportStar(require("./common/applicationManager"), exports);
62
68
  __exportStar(require("./setup"), exports);
63
69
  __exportStar(require("./error"), exports);
64
70
  /**