@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,18 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
3
+ exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
4
4
  const path_1 = require("path");
5
5
  const fs_1 = require("fs");
6
6
  const util_1 = require("util");
7
+ const transformer = require("class-transformer");
8
+ const pathToRegexp_1 = require("./pathToRegexp");
9
+ const error_1 = require("../error");
7
10
  const debug = (0, util_1.debuglog)('midway:container:util');
11
+ /**
12
+ * @since 2.0.0
13
+ * @param env
14
+ */
8
15
  const isDevelopmentEnvironment = env => {
9
16
  return ['local', 'test', 'unittest'].includes(env);
10
17
  };
11
18
  exports.isDevelopmentEnvironment = isDevelopmentEnvironment;
19
+ /**
20
+ * @since 2.0.0
21
+ */
12
22
  const getCurrentEnvironment = () => {
13
23
  return process.env['MIDWAY_SERVER_ENV'] || process.env['NODE_ENV'] || 'prod';
14
24
  };
15
25
  exports.getCurrentEnvironment = getCurrentEnvironment;
26
+ /**
27
+ * @param p
28
+ * @param enabledCache
29
+ * @since 2.0.0
30
+ */
16
31
  const safeRequire = (p, enabledCache = true) => {
17
32
  if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
18
33
  p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
@@ -41,6 +56,7 @@ exports.safeRequire = safeRequire;
41
56
  * safelyGet(['a','1'],{a: {b: 2}}) // => undefined
42
57
  * safelyGet('a.b',{a: {b: 2}}) // => 2
43
58
  * safelyGet('a.b',{c: {b: 2}}) // => undefined
59
+ * @since 2.0.0
44
60
  */
45
61
  function safelyGet(list, obj) {
46
62
  if (arguments.length === 1) {
@@ -66,6 +82,7 @@ exports.safelyGet = safelyGet;
66
82
  /**
67
83
  * 剔除 @ 符号
68
84
  * @param provideId provideId
85
+ * @since 2.0.0
69
86
  */
70
87
  function parsePrefix(provideId) {
71
88
  if (provideId.includes('@')) {
@@ -79,6 +96,7 @@ function getUserHome() {
79
96
  }
80
97
  exports.getUserHome = getUserHome;
81
98
  function joinURLPath(...strArray) {
99
+ strArray = strArray.filter(item => !!item);
82
100
  if (strArray.length === 0) {
83
101
  return '';
84
102
  }
@@ -94,6 +112,7 @@ exports.joinURLPath = joinURLPath;
94
112
  * 代理目标所有的原型方法,不包括构造器和内部隐藏方法
95
113
  * @param derivedCtor
96
114
  * @param constructors
115
+ * @since 2.0.0
97
116
  */
98
117
  function delegateTargetPrototypeMethod(derivedCtor, constructors) {
99
118
  constructors.forEach(baseCtor => {
@@ -111,6 +130,7 @@ exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
111
130
  * 代理目标原型上的特定方法
112
131
  * @param derivedCtor
113
132
  * @param methods
133
+ * @since 2.0.0
114
134
  */
115
135
  function delegateTargetMethod(derivedCtor, methods) {
116
136
  methods.forEach(name => {
@@ -124,6 +144,7 @@ exports.delegateTargetMethod = delegateTargetMethod;
124
144
  * 代理目标原型属性
125
145
  * @param derivedCtor
126
146
  * @param properties
147
+ * @since 2.0.0
127
148
  */
128
149
  function delegateTargetProperties(derivedCtor, properties) {
129
150
  properties.forEach(name => {
@@ -135,6 +156,11 @@ function delegateTargetProperties(derivedCtor, properties) {
135
156
  });
136
157
  }
137
158
  exports.delegateTargetProperties = delegateTargetProperties;
159
+ /**
160
+ * 代理目标原型属性
161
+ * @since 2.0.0
162
+ * @param timestamp
163
+ */
138
164
  const getCurrentDateString = (timestamp = Date.now()) => {
139
165
  const d = new Date(timestamp);
140
166
  return `${d.getFullYear()}-${(d.getMonth() + 1)
@@ -142,4 +168,127 @@ const getCurrentDateString = (timestamp = Date.now()) => {
142
168
  .padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
143
169
  };
144
170
  exports.getCurrentDateString = getCurrentDateString;
171
+ /**
172
+ *
173
+ * @param message
174
+ * @since 3.0.0
175
+ */
176
+ const deprecatedOutput = (message) => {
177
+ console.warn('DeprecationWarning: ' + message);
178
+ };
179
+ exports.deprecatedOutput = deprecatedOutput;
180
+ /**
181
+ * transform request object to definition type
182
+ *
183
+ * @param originValue
184
+ * @param targetType
185
+ * @since 3.0.0
186
+ */
187
+ const transformRequestObjectByType = (originValue, targetType) => {
188
+ if (targetType === undefined ||
189
+ targetType === null ||
190
+ targetType === Object) {
191
+ return originValue;
192
+ }
193
+ switch (targetType) {
194
+ case Number:
195
+ return Number(originValue);
196
+ case String:
197
+ return String(originValue);
198
+ case Boolean:
199
+ if (originValue === '0' || originValue === 'false') {
200
+ return false;
201
+ }
202
+ return Boolean(originValue);
203
+ default:
204
+ if (originValue instanceof targetType) {
205
+ return originValue;
206
+ }
207
+ else {
208
+ const transformToInstance = transformer['plainToClass'] || transformer['plainToInstance'];
209
+ return transformToInstance(targetType, originValue);
210
+ }
211
+ }
212
+ };
213
+ exports.transformRequestObjectByType = transformRequestObjectByType;
214
+ function toPathMatch(pattern) {
215
+ if (typeof pattern === 'boolean') {
216
+ return ctx => pattern;
217
+ }
218
+ if (typeof pattern === 'string') {
219
+ const reg = (0, pathToRegexp_1.pathToRegexp)(pattern, [], { end: false });
220
+ if (reg.global)
221
+ reg.lastIndex = 0;
222
+ return ctx => reg.test(ctx.path);
223
+ }
224
+ if (pattern instanceof RegExp) {
225
+ return ctx => {
226
+ if (pattern.global)
227
+ pattern.lastIndex = 0;
228
+ return pattern.test(ctx.path);
229
+ };
230
+ }
231
+ if (typeof pattern === 'function')
232
+ return pattern;
233
+ if (Array.isArray(pattern)) {
234
+ const matchs = pattern.map(item => toPathMatch(item));
235
+ return ctx => matchs.some(match => match(ctx));
236
+ }
237
+ throw new error_1.MidwayCommonError('match/ignore pattern must be RegExp, Array or String, but got ' + pattern);
238
+ }
239
+ exports.toPathMatch = toPathMatch;
240
+ function pathMatching(options) {
241
+ options = options || {};
242
+ if (options.match && options.ignore)
243
+ throw new error_1.MidwayCommonError('options.match and options.ignore can not both present');
244
+ if (!options.match && !options.ignore)
245
+ return () => true;
246
+ const matchFn = options.match
247
+ ? toPathMatch(options.match)
248
+ : toPathMatch(options.ignore);
249
+ return function pathMatch(ctx) {
250
+ const matched = matchFn(ctx);
251
+ return options.match ? matched : !matched;
252
+ };
253
+ }
254
+ exports.pathMatching = pathMatching;
255
+ /**
256
+ * wrap function middleware with match and ignore
257
+ * @param mw
258
+ * @param options
259
+ */
260
+ function wrapMiddleware(mw, options) {
261
+ // support options.enable
262
+ if (options.enable === false)
263
+ return null;
264
+ // support options.match and options.ignore
265
+ if (!options.match && !options.ignore)
266
+ return mw;
267
+ const match = pathMatching(options);
268
+ const fn = (ctx, next) => {
269
+ if (!match(ctx))
270
+ return next();
271
+ return mw(ctx, next);
272
+ };
273
+ fn._name = mw._name + 'middlewareWrapper';
274
+ return fn;
275
+ }
276
+ exports.wrapMiddleware = wrapMiddleware;
277
+ function isOwnPropertyWritable(obj, prop) {
278
+ if (obj == null)
279
+ return false;
280
+ const type = typeof obj;
281
+ if (type !== 'object' && type !== 'function')
282
+ return false;
283
+ return !!Object.getOwnPropertyDescriptor(obj, prop);
284
+ }
285
+ function isIncludeProperty(obj, prop) {
286
+ while (obj) {
287
+ if (isOwnPropertyWritable(obj, prop))
288
+ return true;
289
+ obj = Object.getPrototypeOf(obj);
290
+ }
291
+ return false;
292
+ }
293
+ exports.isIncludeProperty = isIncludeProperty;
145
294
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- export declare const extractKoaLikeValue: (key: any, data: any) => (ctx: any, next: any) => any;
2
- export declare const extractExpressLikeValue: (key: any, data: any) => (req: any, res: any, next: any) => any;
1
+ export declare const extractKoaLikeValue: (key: any, data: any, paramType?: any) => (ctx: any, next: any) => any;
2
+ export declare const extractExpressLikeValue: (key: any, data: any, paramType?: any) => (req: any, res: any, next: any) => any;
3
3
  //# sourceMappingURL=webRouterParam.d.ts.map
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractExpressLikeValue = exports.extractKoaLikeValue = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
- const extractKoaLikeValue = (key, data) => {
5
+ const index_1 = require("./index");
6
+ const extractKoaLikeValue = (key, data, paramType) => {
6
7
  if (decorator_1.ALL === data) {
7
8
  data = undefined;
8
9
  }
@@ -11,39 +12,55 @@ const extractKoaLikeValue = (key, data) => {
11
12
  case decorator_1.RouteParamTypes.NEXT:
12
13
  return next;
13
14
  case decorator_1.RouteParamTypes.BODY:
14
- return data && ctx.request.body
15
- ? ctx.request.body[data]
16
- : ctx.request.body;
15
+ return (0, index_1.transformRequestObjectByType)(data && ctx.request.body ? ctx.request.body[data] : ctx.request.body, paramType);
17
16
  case decorator_1.RouteParamTypes.PARAM:
18
- return data ? ctx.params[data] : ctx.params;
17
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.params[data] : ctx.params, paramType);
19
18
  case decorator_1.RouteParamTypes.QUERY:
20
- return data ? ctx.query[data] : ctx.query;
19
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
21
20
  case decorator_1.RouteParamTypes.HEADERS:
22
- return data ? ctx.get(data) : ctx.headers;
21
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.get(data) : ctx.headers, paramType);
23
22
  case decorator_1.RouteParamTypes.SESSION:
24
- return data ? ctx.session[data] : ctx.session;
23
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.session[data] : ctx.session, paramType);
25
24
  case decorator_1.RouteParamTypes.FILESTREAM:
26
- 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
+ }
27
34
  case decorator_1.RouteParamTypes.FILESSTREAM:
28
- 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
+ }
29
44
  case decorator_1.RouteParamTypes.REQUEST_PATH:
30
45
  return ctx['path'];
31
46
  case decorator_1.RouteParamTypes.REQUEST_IP:
32
47
  return ctx['ip'];
33
48
  case decorator_1.RouteParamTypes.QUERIES:
34
49
  if (ctx.queries) {
35
- return data ? ctx.queries[data] : ctx.queries;
50
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.queries[data] : ctx.queries, paramType);
36
51
  }
37
52
  else {
38
- return data ? ctx.query[data] : ctx.query;
53
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
39
54
  }
55
+ case decorator_1.RouteParamTypes.FIELDS:
56
+ return data ? ctx.fields[data] : ctx.fields;
40
57
  default:
41
58
  return null;
42
59
  }
43
60
  };
44
61
  };
45
62
  exports.extractKoaLikeValue = extractKoaLikeValue;
46
- const extractExpressLikeValue = (key, data) => {
63
+ const extractExpressLikeValue = (key, data, paramType) => {
47
64
  if (decorator_1.ALL === data) {
48
65
  data = undefined;
49
66
  }
@@ -52,30 +69,32 @@ const extractExpressLikeValue = (key, data) => {
52
69
  case decorator_1.RouteParamTypes.NEXT:
53
70
  return next;
54
71
  case decorator_1.RouteParamTypes.BODY:
55
- return data && req.body ? req.body[data] : req.body;
72
+ return (0, index_1.transformRequestObjectByType)(data && req.body ? req.body[data] : req.body, paramType);
56
73
  case decorator_1.RouteParamTypes.PARAM:
57
- return data ? req.params[data] : req.params;
74
+ return (0, index_1.transformRequestObjectByType)(data ? req.params[data] : req.params, paramType);
58
75
  case decorator_1.RouteParamTypes.QUERY:
59
- return data ? req.query[data] : req.query;
76
+ return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
60
77
  case decorator_1.RouteParamTypes.HEADERS:
61
- return data ? req.get(data) : req.headers;
78
+ return (0, index_1.transformRequestObjectByType)(data ? req.get(data) : req.headers, paramType);
62
79
  case decorator_1.RouteParamTypes.SESSION:
63
- return data ? req.session[data] : req.session;
80
+ return (0, index_1.transformRequestObjectByType)(data ? req.session[data] : req.session, paramType);
64
81
  case decorator_1.RouteParamTypes.FILESTREAM:
65
- return req.getFileStream && req.getFileStream(data);
82
+ return req.files ? req.files[0] : undefined;
66
83
  case decorator_1.RouteParamTypes.FILESSTREAM:
67
- return req.multipart && req.multipart(data);
84
+ return req.files;
68
85
  case decorator_1.RouteParamTypes.REQUEST_PATH:
69
86
  return req['baseUrl'];
70
87
  case decorator_1.RouteParamTypes.REQUEST_IP:
71
88
  return req['ip'];
72
89
  case decorator_1.RouteParamTypes.QUERIES:
73
90
  if (req.queries) {
74
- return data ? req.queries[data] : req.queries;
91
+ return (0, index_1.transformRequestObjectByType)(data ? req.queries[data] : req.queries, paramType);
75
92
  }
76
93
  else {
77
- return data ? req.query[data] : req.query;
94
+ return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
78
95
  }
96
+ case decorator_1.RouteParamTypes.FIELDS:
97
+ return data ? req.fields[data] : req.fields;
79
98
  default:
80
99
  return null;
81
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.13",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,7 +21,8 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.0.0-beta.1",
24
+ "@midwayjs/decorator": "^3.0.0-beta.13",
25
+ "koa": "^2.13.4",
25
26
  "midway-test-component": "*",
26
27
  "mm": "3",
27
28
  "sinon": "^7.2.2"
@@ -31,11 +32,10 @@
31
32
  },
32
33
  "dependencies": {
33
34
  "@midwayjs/glob": "^1.0.2",
34
- "@midwayjs/logger": "^3.0.0-beta.1",
35
- "class-transformer": "^0.3.1",
35
+ "@midwayjs/logger": "^3.0.0-beta.13",
36
+ "class-transformer": "^0.5.1",
36
37
  "extend2": "^1.0.0",
37
- "picomatch": "^2.2.2",
38
- "reflect-metadata": "^0.1.13"
38
+ "picomatch": "^2.3.0"
39
39
  },
40
40
  "author": "Harry Chen <czy88840616@gmail.com>",
41
41
  "repository": {
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "72e4d20c678e65a5440c4e9a6d3b70046daa497c"
48
+ "gitHead": "d3c47770fee9dce33a8d148882173fd7782864ad"
49
49
  }
@@ -1,59 +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
- NO_FRAMEWORK_FOUND = 10005
58
- }
59
- //# sourceMappingURL=code.d.ts.map
@@ -1,64 +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["NO_FRAMEWORK_FOUND"] = 10005] = "NO_FRAMEWORK_FOUND";
63
- })(FrameworkErrorEnum = exports.FrameworkErrorEnum || (exports.FrameworkErrorEnum = {}));
64
- //# sourceMappingURL=code.js.map
@@ -1,13 +0,0 @@
1
- import { CommonExceptionFilterUnion, IMidwayContainer, IMidwayContext } from '../interface';
2
- export declare class ExceptionFilterManager<T extends IMidwayContext = IMidwayContext, R = any, N = any> {
3
- private filterList;
4
- private exceptionMap;
5
- private defaultFilter;
6
- useFilter(Filter: CommonExceptionFilterUnion<T, R, N>): void;
7
- init(applicationContext: IMidwayContainer): Promise<void>;
8
- run(err: Error, ctx: T, res?: R, next?: N): Promise<{
9
- result: any;
10
- error: any;
11
- }>;
12
- }
13
- //# sourceMappingURL=exceptionFilterManager.d.ts.map
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExceptionFilterManager = void 0;
4
- const decorator_1 = require("@midwayjs/decorator");
5
- class ExceptionFilterManager {
6
- constructor() {
7
- this.filterList = [];
8
- this.exceptionMap = new WeakMap();
9
- this.defaultFilter = undefined;
10
- }
11
- useFilter(Filter) {
12
- if (Array.isArray(Filter)) {
13
- this.filterList.push(...Filter);
14
- }
15
- else {
16
- this.filterList.push(Filter);
17
- }
18
- }
19
- async init(applicationContext) {
20
- for (const FilterClass of this.filterList) {
21
- const filter = await applicationContext.getAsync(FilterClass);
22
- const exceptionMetadata = (0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, FilterClass);
23
- if (exceptionMetadata && exceptionMetadata.catchTargets) {
24
- for (const Exception of exceptionMetadata.catchTargets) {
25
- this.exceptionMap.set(Exception, filter);
26
- }
27
- }
28
- else {
29
- // default filter
30
- this.defaultFilter = filter;
31
- }
32
- }
33
- }
34
- async run(err, ctx, res, next) {
35
- let result, error;
36
- if (this.exceptionMap.has(err.constructor)) {
37
- const filter = this.exceptionMap.get(err.constructor);
38
- result = await filter.catch(err, ctx, res, next);
39
- }
40
- else if (this.defaultFilter) {
41
- result = await this.defaultFilter.catch(err, ctx, res, next);
42
- }
43
- else {
44
- error = err;
45
- }
46
- return {
47
- result,
48
- error,
49
- };
50
- }
51
- }
52
- exports.ExceptionFilterManager = ExceptionFilterManager;
53
- //# sourceMappingURL=exceptionFilterManager.js.map
@@ -1,11 +0,0 @@
1
- import { CommonMiddleware, CommonMiddlewareUnion, IMidwayContext } from '../interface';
2
- export declare class ContextMiddlewareManager<T extends IMidwayContext = IMidwayContext, R = any, N = any> extends Array<CommonMiddleware<T, R, N>> {
3
- insertFirst(middleware: CommonMiddlewareUnion<T, R, N>): void;
4
- insertBefore(middleware: CommonMiddlewareUnion<T, R, N>, idxOrBeforeMiddleware: number): any;
5
- insertBefore(middleware: CommonMiddlewareUnion<T, R, N>, idxOrBeforeMiddleware: CommonMiddlewareUnion<T, R, N>): any;
6
- insertAfter(middleware: CommonMiddlewareUnion<T, R, N>, idxOrAfterMiddleware: number): any;
7
- insertAfter(middleware: CommonMiddlewareUnion<T, R, N>, idxOrAfterMiddleware: CommonMiddlewareUnion<T, R, N>): any;
8
- insertLast(middleware: CommonMiddlewareUnion<T, R, N>): void;
9
- private findItemIndex;
10
- }
11
- //# sourceMappingURL=middlewareManager.d.ts.map
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContextMiddlewareManager = void 0;
4
- class ContextMiddlewareManager extends Array {
5
- insertFirst(middleware) {
6
- if (Array.isArray(middleware)) {
7
- this.unshift(...middleware);
8
- }
9
- else {
10
- this.unshift(middleware);
11
- }
12
- }
13
- insertBefore(middleware, idxOrBeforeMiddleware) {
14
- if (typeof idxOrBeforeMiddleware !== 'number') {
15
- idxOrBeforeMiddleware = this.findItemIndex(idxOrBeforeMiddleware);
16
- }
17
- if (Array.isArray(middleware)) {
18
- this.splice(idxOrBeforeMiddleware, 0, ...middleware);
19
- }
20
- else {
21
- this.splice(idxOrBeforeMiddleware, 0, middleware);
22
- }
23
- }
24
- insertAfter(middleware, idxOrAfterMiddleware) {
25
- if (typeof idxOrAfterMiddleware !== 'number') {
26
- idxOrAfterMiddleware = this.findItemIndex(idxOrAfterMiddleware);
27
- }
28
- if (Array.isArray(middleware)) {
29
- this.splice(idxOrAfterMiddleware + 1, 0, ...middleware);
30
- }
31
- else {
32
- this.splice(idxOrAfterMiddleware + 1, 0, middleware);
33
- }
34
- }
35
- insertLast(middleware) {
36
- if (Array.isArray(middleware)) {
37
- this.push(...middleware);
38
- }
39
- else {
40
- this.push(middleware);
41
- }
42
- }
43
- findItemIndex(middleware) {
44
- return this.findIndex(item => item === middleware);
45
- }
46
- }
47
- exports.ContextMiddlewareManager = ContextMiddlewareManager;
48
- //# sourceMappingURL=middlewareManager.js.map
@@ -1,30 +0,0 @@
1
- /**
2
- * wrap controller string to middleware function
3
- * @param controllerMapping like FooController.index
4
- * @param routeArgsInfo
5
- * @param routerResponseData
6
- */
7
- import { MidwayFrameworkType, RouterParamValue } from '@midwayjs/decorator';
8
- import { IMidwayContainer } from '../';
9
- import { ILogger } from '@midwayjs/logger';
10
- export declare abstract class WebControllerGenerator<Router extends {
11
- use: (...args: any[]) => void;
12
- }> {
13
- readonly applicationContext: IMidwayContainer;
14
- readonly frameworkType: MidwayFrameworkType;
15
- readonly logger?: ILogger;
16
- private controllerIds;
17
- protected constructor(applicationContext: IMidwayContainer, frameworkType: MidwayFrameworkType, logger?: ILogger);
18
- /**
19
- * wrap controller string to middleware function
20
- * @param controllerMapping like FooController.index
21
- * @param routeArgsInfo
22
- * @param routerResponseData
23
- */
24
- generateKoaController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): (ctx: any, next: any) => Promise<void>;
25
- loadMidwayController(routerHandler?: (newRouter: Router) => void): Promise<void>;
26
- abstract createRouter(routerOptions: any): Router;
27
- abstract generateController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): any;
28
- protected handlerWebMiddleware(middlewares: any[], handlerCallback: (middlewareImpl: any) => void): Promise<void>;
29
- }
30
- //# sourceMappingURL=webGenerator.d.ts.map