@midwayjs/core 3.0.0-beta.1 → 3.0.0-beta.13

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