@midwayjs/core 3.0.0-beta.10 → 3.0.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,49 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.14](https://github.com/midwayjs/midway/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2022-01-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * cos config definition & 3.x doc update ([#1515](https://github.com/midwayjs/midway/issues/1515)) ([0ac7ac5](https://github.com/midwayjs/midway/commit/0ac7ac5805b7ab8873f8792fc1712a74e3223172))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
18
+
19
+
20
+ ### Features
21
+
22
+ * 404 error ([#1465](https://github.com/midwayjs/midway/issues/1465)) ([e7e8a9d](https://github.com/midwayjs/midway/commit/e7e8a9dedfa7198ac05b161b41024c2871f93965))
23
+ * add custom decorator filter ([#1477](https://github.com/midwayjs/midway/issues/1477)) ([97501a9](https://github.com/midwayjs/midway/commit/97501a989abc211b0c7400b1df45e050bb237c6a))
24
+
25
+
26
+
27
+
28
+
29
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
30
+
31
+
32
+ ### Features
33
+
34
+ * custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
35
+ * support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
36
+
37
+
38
+
39
+
40
+
41
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
42
+
43
+ **Note:** Version bump only for package @midwayjs/core
44
+
45
+
46
+
47
+
48
+
6
49
  # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
7
50
 
8
51
 
@@ -151,8 +151,8 @@ class ContextMiddlewareManager extends Array {
151
151
  * @param middleware
152
152
  */
153
153
  getMiddlewareName(middleware) {
154
- var _a;
155
- return (_a = middleware._name) !== null && _a !== void 0 ? _a : middleware.name;
154
+ var _a, _b;
155
+ return ((_b = (_a = (middleware.getName && middleware.getName())) !== null && _a !== void 0 ? _a : middleware._name) !== null && _b !== void 0 ? _b : middleware.name);
156
156
  }
157
157
  /**
158
158
  * remove a middleware
@@ -57,6 +57,7 @@ class WebControllerGenerator {
57
57
  };
58
58
  }
59
59
  async loadMidwayController(globalPrefix, routerHandler) {
60
+ var _a, _b;
60
61
  const collector = new index_1.WebRouterCollector('', {
61
62
  globalPrefix,
62
63
  });
@@ -76,6 +77,7 @@ class WebControllerGenerator {
76
77
  ...routerInfo.routerOptions,
77
78
  });
78
79
  // add router middleware
80
+ routerInfo.middleware = (_a = routerInfo.middleware) !== null && _a !== void 0 ? _a : [];
79
81
  if (routerInfo.middleware.length) {
80
82
  const routerMiddlewareFn = await middlewareService.compose(routerInfo.middleware, this.app);
81
83
  newRouter.use(routerMiddlewareFn);
@@ -85,6 +87,7 @@ class WebControllerGenerator {
85
87
  for (const routeInfo of routes) {
86
88
  // get middleware
87
89
  const methodMiddlewares = [];
90
+ routeInfo.middleware = (_b = routeInfo.middleware) !== null && _b !== void 0 ? _b : [];
88
91
  if (routeInfo.middleware.length) {
89
92
  const routeMiddlewareFn = await middlewareService.compose(routeInfo.middleware, this.app);
90
93
  methodMiddlewares.push(routeMiddlewareFn);
@@ -319,7 +319,7 @@ class WebRouterCollector {
319
319
  item.requestMethod === routerInfo.requestMethod);
320
320
  });
321
321
  if (matched && matched.length) {
322
- throw new Error(`Duplicate router "${routerInfo.requestMethod} ${routerInfo.url}" at "${matched[0].handlerName}" and "${routerInfo.handlerName}"`);
322
+ throw new error_1.MidwayDuplicateRouteError(`${routerInfo.requestMethod} ${routerInfo.url}`, `${matched[0].handlerName}`, `${routerInfo.handlerName}`);
323
323
  }
324
324
  prefixList.push(routerInfo);
325
325
  }
@@ -56,14 +56,14 @@ class ManagedResolverFactory {
56
56
  resolveManaged(managed, originPropertyName) {
57
57
  const resolver = this.resolvers[managed.type];
58
58
  if (!resolver || resolver.type !== managed.type) {
59
- throw new Error(`${managed.type} resolver is not exists!`);
59
+ throw new error_1.MidwayResolverMissingError(managed.type);
60
60
  }
61
61
  return resolver.resolve(managed, originPropertyName);
62
62
  }
63
63
  async resolveManagedAsync(managed, originPropertyName) {
64
64
  const resolver = this.resolvers[managed.type];
65
65
  if (!resolver || resolver.type !== managed.type) {
66
- throw new Error(`${managed.type} resolver is not exists!`);
66
+ throw new error_1.MidwayResolverMissingError(managed.type);
67
67
  }
68
68
  return resolver.resolveAsync(managed, originPropertyName);
69
69
  }
@@ -187,7 +187,7 @@ class ManagedResolverFactory {
187
187
  inst = await definition.creator.doConstructAsync(Clzz, constructorArgs, this.context);
188
188
  if (!inst) {
189
189
  this.removeCreateStatus(definition, false);
190
- throw new Error(`${definition.id} construct return undefined`);
190
+ throw new error_1.MidwayCommonError(`${definition.id} construct return undefined`);
191
191
  }
192
192
  // binding ctx object
193
193
  if (definition.isRequestScope() &&
@@ -13,6 +13,8 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
13
13
  this.ctx = ctx;
14
14
  // register ctx
15
15
  this.registerObject(interface_1.REQUEST_CTX_KEY, ctx);
16
+ // register res
17
+ this.registerObject('res', {});
16
18
  if (ctx.logger) {
17
19
  // register contextLogger
18
20
  this.registerObject('logger', ctx.logger);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectCreator = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
+ const error_1 = require("../error");
5
6
  class ObjectCreator {
6
7
  constructor(definition) {
7
8
  this.definition = definition;
@@ -87,12 +88,12 @@ class ObjectCreator {
87
88
  if (this.definition.initMethod && inst[this.definition.initMethod]) {
88
89
  if ((0, decorator_1.isGeneratorFunction)(inst[this.definition.initMethod]) ||
89
90
  (0, decorator_1.isAsyncFunction)(inst[this.definition.initMethod])) {
90
- throw new Error(`${this.definition.id} not valid by context.get, Use context.getAsync instead!`);
91
+ throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
91
92
  }
92
93
  else {
93
94
  const rt = inst[this.definition.initMethod].call(inst);
94
95
  if ((0, decorator_1.isPromise)(rt)) {
95
- throw new Error(`${this.definition.id} not valid by context.get, Use context.getAsync instead!`);
96
+ throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
96
97
  }
97
98
  }
98
99
  }
@@ -2,12 +2,31 @@ interface ErrorOption {
2
2
  cause?: Error;
3
3
  status?: number;
4
4
  }
5
+ interface Convertable {
6
+ [key: string]: string | number;
7
+ }
8
+ declare type ConvertString<T extends Convertable, Group extends string> = {
9
+ [P in keyof T]: P extends string ? T[P] extends number ? `${Uppercase<Group>}_${T[P]}` : never : never;
10
+ };
11
+ /**
12
+ * Register error group and code, return the standard ErrorCode
13
+ * @param errorGroup
14
+ * @param errorCodeMapping
15
+ */
16
+ export declare function registerErrorCode<T extends Convertable, G extends string>(errorGroup: G, errorCodeMapping: T): ConvertString<T, G>;
5
17
  export declare class MidwayError extends Error {
6
- code: number;
7
- status: number;
18
+ code: number | string;
8
19
  cause: Error;
9
20
  constructor(message: string, options?: ErrorOption);
10
- constructor(message: string, code: number, options?: ErrorOption);
21
+ constructor(message: string, code: string, options?: ErrorOption);
22
+ }
23
+ export declare type ResOrMessage = string | {
24
+ message: string;
25
+ };
26
+ export declare class MidwayHttpError extends MidwayError {
27
+ status: number;
28
+ constructor(resOrMessage: ResOrMessage, status: number);
29
+ constructor(resOrMessage: ResOrMessage, status: number, code: string, options?: ErrorOption);
11
30
  }
12
31
  export {};
13
32
  //# sourceMappingURL=base.d.ts.map
@@ -1,19 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayError = void 0;
4
- const code_1 = require("./code");
3
+ exports.MidwayHttpError = exports.MidwayError = exports.registerErrorCode = void 0;
4
+ const codeGroup = new Set();
5
+ /**
6
+ * Register error group and code, return the standard ErrorCode
7
+ * @param errorGroup
8
+ * @param errorCodeMapping
9
+ */
10
+ function registerErrorCode(errorGroup, errorCodeMapping) {
11
+ if (codeGroup.has(errorGroup)) {
12
+ throw new MidwayError(`Error group ${errorGroup} is duplicated, please check before adding.`);
13
+ }
14
+ else {
15
+ codeGroup.add(errorGroup);
16
+ }
17
+ const newCodeEnum = {};
18
+ // ERROR => GROUP_10000
19
+ for (const errKey in errorCodeMapping) {
20
+ newCodeEnum[errKey] =
21
+ errorGroup.toUpperCase() +
22
+ '_' +
23
+ String(errorCodeMapping[errKey]).toUpperCase();
24
+ }
25
+ return newCodeEnum;
26
+ }
27
+ exports.registerErrorCode = registerErrorCode;
5
28
  class MidwayError extends Error {
6
29
  constructor(message, code, options) {
7
30
  super(message);
8
- if (typeof code !== 'number') {
31
+ if (!code || typeof code === 'object') {
9
32
  options = code;
10
- code = code_1.FrameworkErrorEnum.UNKNOWN;
33
+ code = 'MIDWAY_10000';
11
34
  }
12
35
  this.name = this.constructor.name;
13
36
  this.code = code;
14
37
  this.cause = options === null || options === void 0 ? void 0 : options.cause;
15
- this.status = options === null || options === void 0 ? void 0 : options.status;
16
38
  }
17
39
  }
18
40
  exports.MidwayError = MidwayError;
41
+ class MidwayHttpError extends MidwayError {
42
+ constructor(resOrMessage, status, code, options) {
43
+ super(typeof resOrMessage === 'string' ? resOrMessage : resOrMessage.message, code !== null && code !== void 0 ? code : String(status), options);
44
+ this.status = status;
45
+ }
46
+ }
47
+ exports.MidwayHttpError = MidwayHttpError;
19
48
  //# sourceMappingURL=base.js.map
@@ -1,5 +1,17 @@
1
1
  import { MidwayError } from './base';
2
2
  import { ObjectIdentifier } from '@midwayjs/decorator';
3
+ export declare const FrameworkErrorEnum: {
4
+ readonly UNKNOWN: "MIDWAY_10000";
5
+ readonly COMMON: "MIDWAY_10001";
6
+ readonly PARAM_TYPE: "MIDWAY_10002";
7
+ readonly DEFINITION_NOT_FOUND: "MIDWAY_10003";
8
+ readonly FEATURE_NO_LONGER_SUPPORTED: "MIDWAY_10004";
9
+ readonly FEATURE_NOT_IMPLEMENTED: "MIDWAY_10004";
10
+ readonly MISSING_CONFIG: "MIDWAY_10006";
11
+ readonly MISSING_RESOLVER: "MIDWAY_10007";
12
+ readonly DUPLICATE_ROUTER: "MIDWAY_10008";
13
+ readonly USE_WRONG_METHOD: "MIDWAY_10009";
14
+ };
3
15
  export declare class MidwayCommonError extends MidwayError {
4
16
  constructor(message: string);
5
17
  }
@@ -15,10 +27,19 @@ export declare class MidwayDefinitionNotFoundError extends MidwayError {
15
27
  export declare class MidwayFeatureNoLongerSupportedError extends MidwayError {
16
28
  constructor(message?: string);
17
29
  }
18
- export declare class MidwayValidationError extends MidwayError {
19
- constructor(message: any, status: any, cause: any);
30
+ export declare class MidwayFeatureNotImplementedError extends MidwayError {
31
+ constructor(message?: string);
20
32
  }
21
33
  export declare class MidwayConfigMissingError extends MidwayError {
22
34
  constructor(configKey: string);
23
35
  }
36
+ export declare class MidwayResolverMissingError extends MidwayError {
37
+ constructor(type: string);
38
+ }
39
+ export declare class MidwayDuplicateRouteError extends MidwayError {
40
+ constructor(routerUrl: string, existPos: string, existPosOther: string);
41
+ }
42
+ export declare class MidwayUseWrongMethodError extends MidwayError {
43
+ constructor(wrongMethod: string, replacedMethod: string, describeKey?: string);
44
+ }
24
45
  //# sourceMappingURL=framework.d.ts.map
@@ -1,23 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayConfigMissingError = exports.MidwayValidationError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = void 0;
3
+ exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
4
4
  const base_1 = require("./base");
5
- const code_1 = require("./code");
5
+ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
6
+ UNKNOWN: 10000,
7
+ COMMON: 10001,
8
+ PARAM_TYPE: 10002,
9
+ DEFINITION_NOT_FOUND: 10003,
10
+ FEATURE_NO_LONGER_SUPPORTED: 10004,
11
+ FEATURE_NOT_IMPLEMENTED: 10004,
12
+ MISSING_CONFIG: 10006,
13
+ MISSING_RESOLVER: 10007,
14
+ DUPLICATE_ROUTER: 10008,
15
+ USE_WRONG_METHOD: 10009,
16
+ });
6
17
  class MidwayCommonError extends base_1.MidwayError {
7
18
  constructor(message) {
8
- super(message, code_1.FrameworkErrorEnum.COMMON);
19
+ super(message, exports.FrameworkErrorEnum.COMMON);
9
20
  }
10
21
  }
11
22
  exports.MidwayCommonError = MidwayCommonError;
12
23
  class MidwayParameterError extends base_1.MidwayError {
13
24
  constructor(message) {
14
- super(message !== null && message !== void 0 ? message : 'Parameter type not match', code_1.FrameworkErrorEnum.PARAM_TYPE);
25
+ super(message !== null && message !== void 0 ? message : 'Parameter type not match', exports.FrameworkErrorEnum.PARAM_TYPE);
15
26
  }
16
27
  }
17
28
  exports.MidwayParameterError = MidwayParameterError;
18
29
  class MidwayDefinitionNotFoundError extends base_1.MidwayError {
19
30
  constructor(identifier) {
20
- super(`${identifier} is not valid in current context`, code_1.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
31
+ super(`${identifier} is not valid in current context`, exports.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
21
32
  this[MidwayDefinitionNotFoundError.type] =
22
33
  MidwayDefinitionNotFoundError.type;
23
34
  }
@@ -36,23 +47,41 @@ exports.MidwayDefinitionNotFoundError = MidwayDefinitionNotFoundError;
36
47
  MidwayDefinitionNotFoundError.type = Symbol.for('#NotFoundError');
37
48
  class MidwayFeatureNoLongerSupportedError extends base_1.MidwayError {
38
49
  constructor(message) {
39
- super('This feature no longer supported \n' + message, code_1.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
50
+ super('This feature no longer supported \n' + message, exports.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
40
51
  }
41
52
  }
42
53
  exports.MidwayFeatureNoLongerSupportedError = MidwayFeatureNoLongerSupportedError;
43
- class MidwayValidationError extends base_1.MidwayError {
44
- constructor(message, status, cause) {
45
- super(message, code_1.FrameworkErrorEnum.VALIDATE_FAIL, {
46
- status,
47
- cause,
48
- });
54
+ class MidwayFeatureNotImplementedError extends base_1.MidwayError {
55
+ constructor(message) {
56
+ super('This feature not implemented \n' + message, exports.FrameworkErrorEnum.FEATURE_NOT_IMPLEMENTED);
49
57
  }
50
58
  }
51
- exports.MidwayValidationError = MidwayValidationError;
59
+ exports.MidwayFeatureNotImplementedError = MidwayFeatureNotImplementedError;
52
60
  class MidwayConfigMissingError extends base_1.MidwayError {
53
61
  constructor(configKey) {
54
- super(`Can't found config key "${configKey}" in your config, please set it first`, code_1.FrameworkErrorEnum.MISSING_CONFIG);
62
+ super(`Can't found config key "${configKey}" in your config, please set it first`, exports.FrameworkErrorEnum.MISSING_CONFIG);
55
63
  }
56
64
  }
57
65
  exports.MidwayConfigMissingError = MidwayConfigMissingError;
66
+ class MidwayResolverMissingError extends base_1.MidwayError {
67
+ constructor(type) {
68
+ super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
69
+ }
70
+ }
71
+ exports.MidwayResolverMissingError = MidwayResolverMissingError;
72
+ class MidwayDuplicateRouteError extends base_1.MidwayError {
73
+ constructor(routerUrl, existPos, existPosOther) {
74
+ super(`Duplicate router "${routerUrl}" at "${existPos}" and "${existPosOther}"`, exports.FrameworkErrorEnum.DUPLICATE_ROUTER);
75
+ }
76
+ }
77
+ exports.MidwayDuplicateRouteError = MidwayDuplicateRouteError;
78
+ class MidwayUseWrongMethodError extends base_1.MidwayError {
79
+ constructor(wrongMethod, replacedMethod, describeKey) {
80
+ const text = describeKey
81
+ ? `${describeKey} not valid by ${wrongMethod}, Use ${replacedMethod} instead!`
82
+ : `You should not invoked by ${wrongMethod}, Use ${replacedMethod} instead!`;
83
+ super(text, exports.FrameworkErrorEnum.USE_WRONG_METHOD);
84
+ }
85
+ }
86
+ exports.MidwayUseWrongMethodError = MidwayUseWrongMethodError;
58
87
  //# sourceMappingURL=framework.js.map
@@ -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 UnprocessableError 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
+ 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;
@@ -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");
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;
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 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,
@@ -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>> : PowerPartial<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,6 +56,10 @@ export declare enum ObjectLifeCycleEvent {
46
56
  AFTER_INIT = "afterObjectInit",
47
57
  BEFORE_DESTROY = "beforeObjectDestroy"
48
58
  }
59
+ /**
60
+ * Object Lifecycle
61
+ * 对象生命周期
62
+ */
49
63
  export interface IObjectLifeCycle {
50
64
  onBeforeBind(fn: (Clzz: any, options: {
51
65
  context: IMidwayContainer;
@@ -72,6 +86,7 @@ export interface IObjectLifeCycle {
72
86
  }) => void): any;
73
87
  }
74
88
  /**
89
+ * Object Definition
75
90
  * 对象描述定义
76
91
  */
77
92
  export interface IObjectDefinition {
@@ -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 {
@@ -450,6 +466,7 @@ export interface MidwayAppInfo {
450
466
  * midway global config definition
451
467
  */
452
468
  export interface MidwayConfig extends FileConfigOption<typeof _default> {
469
+ [customConfigKey: string]: unknown;
453
470
  }
454
471
  export interface TranslateOptions {
455
472
  lang?: string;
@@ -30,7 +30,10 @@ let MidwayDecoratorService = class MidwayDecoratorService {
30
30
  if (methodDecoratorMetadataList) {
31
31
  // loop it, save this order for decorator run
32
32
  for (const meta of methodDecoratorMetadataList) {
33
- const { propertyName, key, metadata } = meta;
33
+ const { propertyName, key, metadata, impl } = meta;
34
+ if (!impl) {
35
+ continue;
36
+ }
34
37
  // add aspect implementation first
35
38
  this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
36
39
  const methodDecoratorHandler = this.methodDecoratorMap.get(key);
@@ -57,7 +60,10 @@ let MidwayDecoratorService = class MidwayDecoratorService {
57
60
  // joinPoint.args
58
61
  const newArgs = [...joinPoint.args];
59
62
  for (const meta of parameterDecoratorMetadata[methodName]) {
60
- const { propertyName, key, metadata, parameterIndex } = meta;
63
+ const { propertyName, key, metadata, parameterIndex, impl } = meta;
64
+ if (!impl) {
65
+ continue;
66
+ }
61
67
  const parameterDecoratorHandler = this.parameterDecoratorMap.get(key);
62
68
  if (!parameterDecoratorHandler) {
63
69
  throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
@@ -6,6 +6,5 @@ export declare class MidwayMiddlewareService<T, R, N = unknown> {
6
6
  (context: any, next?: any): Promise<any>;
7
7
  _name: string;
8
8
  }>;
9
- getMiddlewareName(mw: any): any;
10
9
  }
11
10
  //# sourceMappingURL=middlewareService.d.ts.map
@@ -113,10 +113,6 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
113
113
  }
114
114
  return composeFn;
115
115
  }
116
- getMiddlewareName(mw) {
117
- var _a;
118
- return (_a = mw.name) !== null && _a !== void 0 ? _a : mw._name;
119
- }
120
116
  };
121
117
  MidwayMiddlewareService = __decorate([
122
118
  (0, decorator_1.Provide)(),
@@ -22,9 +22,25 @@ const extractKoaLikeValue = (key, data, paramType) => {
22
22
  case decorator_1.RouteParamTypes.SESSION:
23
23
  return (0, index_1.transformRequestObjectByType)(data ? ctx.session[data] : ctx.session, paramType);
24
24
  case decorator_1.RouteParamTypes.FILESTREAM:
25
- return ctx.getFileStream && ctx.getFileStream(data);
25
+ if (ctx.getFileStream) {
26
+ return ctx.getFileStream(data);
27
+ }
28
+ else if (ctx.files) {
29
+ return ctx.files[0];
30
+ }
31
+ else {
32
+ return undefined;
33
+ }
26
34
  case decorator_1.RouteParamTypes.FILESSTREAM:
27
- return ctx.multipart && ctx.multipart(data);
35
+ if (ctx.multipart) {
36
+ return ctx.multipart(data);
37
+ }
38
+ else if (ctx.files) {
39
+ return ctx.files;
40
+ }
41
+ else {
42
+ return undefined;
43
+ }
28
44
  case decorator_1.RouteParamTypes.REQUEST_PATH:
29
45
  return ctx['path'];
30
46
  case decorator_1.RouteParamTypes.REQUEST_IP:
@@ -36,6 +52,8 @@ const extractKoaLikeValue = (key, data, paramType) => {
36
52
  else {
37
53
  return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
38
54
  }
55
+ case decorator_1.RouteParamTypes.FIELDS:
56
+ return data ? ctx.fields[data] : ctx.fields;
39
57
  default:
40
58
  return null;
41
59
  }
@@ -61,9 +79,9 @@ const extractExpressLikeValue = (key, data, paramType) => {
61
79
  case decorator_1.RouteParamTypes.SESSION:
62
80
  return (0, index_1.transformRequestObjectByType)(data ? req.session[data] : req.session, paramType);
63
81
  case decorator_1.RouteParamTypes.FILESTREAM:
64
- return req.getFileStream && req.getFileStream(data);
82
+ return req.files ? req.files[0] : undefined;
65
83
  case decorator_1.RouteParamTypes.FILESSTREAM:
66
- return req.multipart && req.multipart(data);
84
+ return req.files;
67
85
  case decorator_1.RouteParamTypes.REQUEST_PATH:
68
86
  return req['baseUrl'];
69
87
  case decorator_1.RouteParamTypes.REQUEST_IP:
@@ -75,6 +93,8 @@ const extractExpressLikeValue = (key, data, paramType) => {
75
93
  else {
76
94
  return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
77
95
  }
96
+ case decorator_1.RouteParamTypes.FIELDS:
97
+ return data ? req.fields[data] : req.fields;
78
98
  default:
79
99
  return null;
80
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.0.0-beta.10",
3
+ "version": "3.0.0-beta.14",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,18 +21,18 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.0.0-beta.10",
25
- "koa": "^2.13.4",
24
+ "@midwayjs/decorator": "^3.0.0-beta.14",
25
+ "koa": "2.13.4",
26
26
  "midway-test-component": "*",
27
- "mm": "3",
28
- "sinon": "^7.2.2"
27
+ "mm": "3.2.0",
28
+ "sinon": "12.0.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@midwayjs/decorator": "*"
32
32
  },
33
33
  "dependencies": {
34
34
  "@midwayjs/glob": "^1.0.2",
35
- "@midwayjs/logger": "^3.0.0-beta.10",
35
+ "@midwayjs/logger": "2.14.0",
36
36
  "class-transformer": "^0.5.1",
37
37
  "extend2": "^1.0.0",
38
38
  "picomatch": "^2.3.0"
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "153870f2e2dd6b17673ec7591e49224a6bd51b36"
48
+ "gitHead": "95695ada36190cf376e93a1a8866b3fb6dde06bc"
49
49
  }
@@ -1,60 +0,0 @@
1
- export declare enum HttpStatus {
2
- CONTINUE = 100,
3
- SWITCHING_PROTOCOLS = 101,
4
- PROCESSING = 102,
5
- EARLYHINTS = 103,
6
- OK = 200,
7
- CREATED = 201,
8
- ACCEPTED = 202,
9
- NON_AUTHORITATIVE_INFORMATION = 203,
10
- NO_CONTENT = 204,
11
- RESET_CONTENT = 205,
12
- PARTIAL_CONTENT = 206,
13
- AMBIGUOUS = 300,
14
- MOVED_PERMANENTLY = 301,
15
- FOUND = 302,
16
- SEE_OTHER = 303,
17
- NOT_MODIFIED = 304,
18
- TEMPORARY_REDIRECT = 307,
19
- PERMANENT_REDIRECT = 308,
20
- BAD_REQUEST = 400,
21
- UNAUTHORIZED = 401,
22
- PAYMENT_REQUIRED = 402,
23
- FORBIDDEN = 403,
24
- NOT_FOUND = 404,
25
- METHOD_NOT_ALLOWED = 405,
26
- NOT_ACCEPTABLE = 406,
27
- PROXY_AUTHENTICATION_REQUIRED = 407,
28
- REQUEST_TIMEOUT = 408,
29
- CONFLICT = 409,
30
- GONE = 410,
31
- LENGTH_REQUIRED = 411,
32
- PRECONDITION_FAILED = 412,
33
- PAYLOAD_TOO_LARGE = 413,
34
- URI_TOO_LONG = 414,
35
- UNSUPPORTED_MEDIA_TYPE = 415,
36
- REQUESTED_RANGE_NOT_SATISFIABLE = 416,
37
- EXPECTATION_FAILED = 417,
38
- I_AM_A_TEAPOT = 418,
39
- MISDIRECTED = 421,
40
- UNPROCESSABLE_ENTITY = 422,
41
- FAILED_DEPENDENCY = 424,
42
- PRECONDITION_REQUIRED = 428,
43
- TOO_MANY_REQUESTS = 429,
44
- INTERNAL_SERVER_ERROR = 500,
45
- NOT_IMPLEMENTED = 501,
46
- BAD_GATEWAY = 502,
47
- SERVICE_UNAVAILABLE = 503,
48
- GATEWAY_TIMEOUT = 504,
49
- HTTP_VERSION_NOT_SUPPORTED = 505
50
- }
51
- export declare enum FrameworkErrorEnum {
52
- UNKNOWN = 10000,
53
- COMMON = 10001,
54
- PARAM_TYPE = 10002,
55
- DEFINITION_NOT_FOUND = 10003,
56
- FEATURE_NO_LONGER_SUPPORTED = 10004,
57
- VALIDATE_FAIL = 10005,
58
- MISSING_CONFIG = 10006
59
- }
60
- //# sourceMappingURL=code.d.ts.map
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FrameworkErrorEnum = exports.HttpStatus = void 0;
4
- var HttpStatus;
5
- (function (HttpStatus) {
6
- HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
7
- HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
8
- HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
9
- HttpStatus[HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
10
- HttpStatus[HttpStatus["OK"] = 200] = "OK";
11
- HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
12
- HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
13
- HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
14
- HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
15
- HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
16
- HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
17
- HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
18
- HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
19
- HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
20
- HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
21
- HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
22
- HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
23
- HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
24
- HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
25
- HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
26
- HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
27
- HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
28
- HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
29
- HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
30
- HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
31
- HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
32
- HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
33
- HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
34
- HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
35
- HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
36
- HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
37
- HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
38
- HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
39
- HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
40
- HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
41
- HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
42
- HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
43
- HttpStatus[HttpStatus["MISDIRECTED"] = 421] = "MISDIRECTED";
44
- HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
45
- HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
46
- HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
47
- HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
48
- HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
49
- HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
50
- HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
51
- HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
52
- HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
53
- HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
54
- })(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));
55
- var FrameworkErrorEnum;
56
- (function (FrameworkErrorEnum) {
57
- FrameworkErrorEnum[FrameworkErrorEnum["UNKNOWN"] = 10000] = "UNKNOWN";
58
- FrameworkErrorEnum[FrameworkErrorEnum["COMMON"] = 10001] = "COMMON";
59
- FrameworkErrorEnum[FrameworkErrorEnum["PARAM_TYPE"] = 10002] = "PARAM_TYPE";
60
- FrameworkErrorEnum[FrameworkErrorEnum["DEFINITION_NOT_FOUND"] = 10003] = "DEFINITION_NOT_FOUND";
61
- FrameworkErrorEnum[FrameworkErrorEnum["FEATURE_NO_LONGER_SUPPORTED"] = 10004] = "FEATURE_NO_LONGER_SUPPORTED";
62
- FrameworkErrorEnum[FrameworkErrorEnum["VALIDATE_FAIL"] = 10005] = "VALIDATE_FAIL";
63
- FrameworkErrorEnum[FrameworkErrorEnum["MISSING_CONFIG"] = 10006] = "MISSING_CONFIG";
64
- })(FrameworkErrorEnum = exports.FrameworkErrorEnum || (exports.FrameworkErrorEnum = {}));
65
- //# sourceMappingURL=code.js.map