@midwayjs/core 3.0.0-beta.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/dist/baseFramework.d.ts +2 -1
  3. package/dist/baseFramework.js +17 -11
  4. package/dist/common/applicationManager.d.ts +11 -0
  5. package/dist/common/applicationManager.js +70 -0
  6. package/dist/common/dataListener.d.ts +11 -0
  7. package/dist/common/dataListener.js +43 -0
  8. package/dist/common/fileDetector.js +1 -1
  9. package/dist/common/middlewareManager.d.ts +62 -5
  10. package/dist/common/middlewareManager.js +141 -6
  11. package/dist/common/webGenerator.d.ts +3 -14
  12. package/dist/common/webGenerator.js +23 -31
  13. package/dist/common/webRouterCollector.js +7 -3
  14. package/dist/context/container.js +28 -13
  15. package/dist/context/managedResolverFactory.js +12 -5
  16. package/dist/context/requestContainer.js +2 -0
  17. package/dist/definitions/functionDefinition.d.ts +1 -0
  18. package/dist/definitions/functionDefinition.js +1 -0
  19. package/dist/definitions/objectCreator.js +9 -8
  20. package/dist/definitions/objectDefinition.d.ts +1 -0
  21. package/dist/definitions/objectDefinition.js +1 -0
  22. package/dist/error/base.d.ts +22 -3
  23. package/dist/error/base.js +34 -5
  24. package/dist/error/framework.d.ts +30 -2
  25. package/dist/error/framework.js +56 -13
  26. package/dist/error/http.d.ts +146 -41
  27. package/dist/error/http.js +164 -31
  28. package/dist/error/index.d.ts +1 -1
  29. package/dist/error/index.js +4 -1
  30. package/dist/functional/configuration.d.ts +2 -0
  31. package/dist/functional/configuration.js +10 -0
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.js +7 -1
  34. package/dist/interface.d.ts +51 -29
  35. package/dist/service/aspectService.js +1 -1
  36. package/dist/service/configService.d.ts +3 -1
  37. package/dist/service/configService.js +23 -17
  38. package/dist/service/decoratorService.js +11 -5
  39. package/dist/service/environmentService.d.ts +1 -1
  40. package/dist/service/frameworkService.d.ts +3 -2
  41. package/dist/service/frameworkService.js +17 -12
  42. package/dist/service/lifeCycleService.js +5 -5
  43. package/dist/service/loggerService.d.ts +1 -1
  44. package/dist/service/middlewareService.d.ts +3 -4
  45. package/dist/service/middlewareService.js +28 -24
  46. package/dist/setup.js +13 -5
  47. package/dist/util/extend.d.ts +2 -0
  48. package/dist/util/extend.js +55 -0
  49. package/dist/util/index.d.ts +9 -0
  50. package/dist/util/index.js +55 -1
  51. package/dist/util/webRouterParam.js +24 -4
  52. package/package.json +10 -11
  53. package/CHANGELOG.md +0 -2174
  54. package/dist/error/code.d.ts +0 -59
  55. package/dist/error/code.js +0 -64
@@ -0,0 +1,2 @@
1
+ export declare function extend(...args: any[]): any;
2
+ //# sourceMappingURL=extend.d.ts.map
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extend = void 0;
4
+ /**
5
+ * fork from https://github.com/eggjs/extend2
6
+ */
7
+ const decorator_1 = require("@midwayjs/decorator");
8
+ function extend(...args) {
9
+ let options, name, src, copy, clone;
10
+ let target = args[0];
11
+ let i = 1;
12
+ const length = args.length;
13
+ let deep = false;
14
+ // Handle a deep copy situation
15
+ if (typeof target === 'boolean') {
16
+ deep = target;
17
+ target = args[1] || {};
18
+ // skip the boolean and the target
19
+ i = 2;
20
+ }
21
+ else if ((typeof target !== 'object' && typeof target !== 'function') ||
22
+ target == null) {
23
+ target = {};
24
+ }
25
+ for (; i < length; ++i) {
26
+ options = args[i];
27
+ // Only deal with non-null/undefined values
28
+ if (options == null)
29
+ continue;
30
+ // Extend the base object
31
+ for (name in options) {
32
+ if (name === '__proto__')
33
+ continue;
34
+ src = target[name];
35
+ copy = options[name];
36
+ // Prevent never-ending loop
37
+ if (target === copy)
38
+ continue;
39
+ // Recurse if we're merging plain objects
40
+ if (deep && copy && decorator_1.Types.isPlainObject(copy)) {
41
+ clone = src && decorator_1.Types.isPlainObject(src) ? src : {};
42
+ // Never move original objects, clone them
43
+ target[name] = extend(deep, clone, copy);
44
+ // Don't bring in undefined values
45
+ }
46
+ else if (typeof copy !== 'undefined') {
47
+ target[name] = copy;
48
+ }
49
+ }
50
+ }
51
+ // Return the modified object
52
+ return target;
53
+ }
54
+ exports.extend = extend;
55
+ //# sourceMappingURL=extend.js.map
@@ -1,3 +1,4 @@
1
+ import { FunctionMiddleware } from '../interface';
1
2
  /**
2
3
  * @since 2.0.0
3
4
  * @param env
@@ -73,4 +74,12 @@ export declare const deprecatedOutput: (message: string) => void;
73
74
  */
74
75
  export declare const transformRequestObjectByType: (originValue: any, targetType?: any) => any;
75
76
  export declare function toPathMatch(pattern: any): any;
77
+ export declare function pathMatching(options: any): (ctx?: any) => any;
78
+ /**
79
+ * wrap function middleware with match and ignore
80
+ * @param mw
81
+ * @param options
82
+ */
83
+ export declare function wrapMiddleware(mw: FunctionMiddleware<any, any>, options: any): (context: any, next: any, options?: any) => any;
84
+ export declare function isIncludeProperty(obj: any, prop: string): boolean;
76
85
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
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");
@@ -237,4 +237,58 @@ function toPathMatch(pattern) {
237
237
  throw new error_1.MidwayCommonError('match/ignore pattern must be RegExp, Array or String, but got ' + pattern);
238
238
  }
239
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;
240
294
  //# sourceMappingURL=index.js.map
@@ -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,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.0.0-beta.6",
3
+ "version": "3.0.0",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
9
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
11
11
  "link": "npm link"
12
12
  },
13
13
  "keywords": [
@@ -21,21 +21,20 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.0.0-beta.6",
24
+ "@midwayjs/decorator": "^3.0.0",
25
+ "koa": "2.13.4",
25
26
  "midway-test-component": "*",
26
- "mm": "3",
27
- "sinon": "^7.2.2"
27
+ "mm": "3.2.0",
28
+ "sinon": "12.0.1"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "@midwayjs/decorator": "*"
31
32
  },
32
33
  "dependencies": {
33
34
  "@midwayjs/glob": "^1.0.2",
34
- "@midwayjs/logger": "^3.0.0-beta.6",
35
+ "@midwayjs/logger": "2.14.0",
35
36
  "class-transformer": "^0.5.1",
36
- "extend2": "^1.0.0",
37
- "picomatch": "^2.2.2",
38
- "reflect-metadata": "^0.1.13"
37
+ "picomatch": "2.3.1"
39
38
  },
40
39
  "author": "Harry Chen <czy88840616@gmail.com>",
41
40
  "repository": {
@@ -45,5 +44,5 @@
45
44
  "engines": {
46
45
  "node": ">=12"
47
46
  },
48
- "gitHead": "e4595d30b369e36bef21b36f2b3737d8bc2f802d"
47
+ "gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
49
48
  }