@midwayjs/core 3.0.0-beta.7 → 3.0.1

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 +13 -10
  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 +27 -2
  25. package/dist/error/framework.js +51 -14
  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 +25 -13
  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 +12 -25
  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 +8 -0
  50. package/dist/util/index.js +38 -1
  51. package/dist/util/webRouterParam.js +24 -4
  52. package/package.json +10 -12
  53. package/CHANGELOG.md +0 -2186
  54. package/dist/error/code.d.ts +0 -60
  55. package/dist/error/code.js +0 -65
package/dist/setup.js CHANGED
@@ -22,7 +22,7 @@ async function initializeGlobalApplicationContext(globalOptions) {
22
22
  // register baseDir and appDir
23
23
  applicationContext.registerObject('baseDir', baseDir);
24
24
  applicationContext.registerObject('appDir', appDir);
25
- if (globalOptions.moduleDirector !== false) {
25
+ if (globalOptions.moduleDetector !== false) {
26
26
  if (globalOptions.moduleDetector === undefined ||
27
27
  globalOptions.moduleDetector === 'file') {
28
28
  applicationContext.setFileDetector(new _1.DirectoryFileDetector({
@@ -44,6 +44,7 @@ async function initializeGlobalApplicationContext(globalOptions) {
44
44
  applicationContext.bindClass(_1.MidwayFrameworkService);
45
45
  applicationContext.bindClass(_1.MidwayMiddlewareService);
46
46
  applicationContext.bindClass(_1.MidwayLifeCycleService);
47
+ applicationContext.bindClass(_1.MidwayApplicationManager);
47
48
  // bind preload module
48
49
  if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
49
50
  for (const preloadModule of globalOptions.preloadModules) {
@@ -63,19 +64,26 @@ async function initializeGlobalApplicationContext(globalOptions) {
63
64
  await applicationContext.getAsync(_1.MidwayDecoratorService, [
64
65
  applicationContext,
65
66
  ]);
66
- if (!globalOptions.configurationModule) {
67
- globalOptions.configurationModule = [
67
+ if (!globalOptions.imports) {
68
+ globalOptions.imports = [
68
69
  (0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
69
70
  ];
70
71
  }
71
- for (const configurationModule of [].concat(globalOptions.configurationModule)) {
72
+ for (const configurationModule of []
73
+ .concat(globalOptions.imports)
74
+ .concat(globalOptions.configurationModule)) {
72
75
  // load configuration and component
73
76
  applicationContext.load(configurationModule);
74
77
  }
75
78
  // bind user code module
76
79
  await applicationContext.ready();
77
80
  if (globalOptions.globalConfig) {
78
- configService.add([globalOptions.globalConfig]);
81
+ if (Array.isArray(globalOptions.globalConfig)) {
82
+ configService.add(globalOptions.globalConfig);
83
+ }
84
+ else {
85
+ configService.addObject(globalOptions.globalConfig);
86
+ }
79
87
  }
80
88
  // merge config
81
89
  await configService.load();
@@ -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,5 +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;
76
84
  export declare function isIncludeProperty(obj: any, prop: string): boolean;
77
85
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIncludeProperty = 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,6 +237,43 @@ 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;
240
277
  function isOwnPropertyWritable(obj, prop) {
241
278
  if (obj == null)
242
279
  return false;
@@ -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.7",
3
+ "version": "3.0.1",
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,22 +21,20 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.0.0-beta.7",
25
- "koa": "^2.13.4",
24
+ "@midwayjs/decorator": "^3.0.0",
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.7",
35
+ "@midwayjs/logger": "^2.14.0",
36
36
  "class-transformer": "^0.5.1",
37
- "extend2": "^1.0.0",
38
- "picomatch": "^2.2.2",
39
- "reflect-metadata": "^0.1.13"
37
+ "picomatch": "2.3.1"
40
38
  },
41
39
  "author": "Harry Chen <czy88840616@gmail.com>",
42
40
  "repository": {
@@ -46,5 +44,5 @@
46
44
  "engines": {
47
45
  "node": ">=12"
48
46
  },
49
- "gitHead": "24590729121d9110e2d960db5b5e587cf55a1efc"
47
+ "gitHead": "f345b4ed0392e5c3b9e815438ef0a377ad6da076"
50
48
  }