@midwayjs/core 3.0.0-alpha.6 → 3.0.0-beta.11

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 (113) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +1 -1
  3. package/dist/baseFramework.d.ts +56 -22
  4. package/dist/baseFramework.js +157 -232
  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 +16 -10
  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/common/serviceFactory.d.ts +15 -0
  14. package/dist/{util → common}/serviceFactory.js +16 -6
  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/common/webGenerator.js +114 -0
  19. package/dist/{util → common}/webRouterCollector.d.ts +21 -2
  20. package/dist/common/webRouterCollector.js +331 -0
  21. package/dist/config/config.default.d.ts +7 -0
  22. package/dist/config/config.default.js +28 -0
  23. package/dist/context/container.d.ts +73 -43
  24. package/dist/context/container.js +289 -271
  25. package/dist/context/definitionRegistry.d.ts +26 -0
  26. package/dist/context/definitionRegistry.js +124 -0
  27. package/dist/context/managedResolverFactory.d.ts +15 -32
  28. package/dist/context/managedResolverFactory.js +88 -317
  29. package/dist/context/providerWrapper.d.ts +2 -3
  30. package/dist/context/requestContainer.d.ts +0 -2
  31. package/dist/context/requestContainer.js +9 -26
  32. package/dist/definitions/functionDefinition.d.ts +3 -4
  33. package/dist/definitions/functionDefinition.js +0 -6
  34. package/dist/definitions/objectCreator.js +6 -6
  35. package/dist/definitions/objectDefinition.d.ts +4 -6
  36. package/dist/definitions/objectDefinition.js +0 -8
  37. package/dist/definitions/properties.d.ts +2 -15
  38. package/dist/definitions/properties.js +3 -72
  39. package/dist/error/base.d.ts +13 -0
  40. package/dist/error/base.js +19 -0
  41. package/dist/error/code.d.ts +60 -0
  42. package/dist/error/code.js +65 -0
  43. package/dist/error/framework.d.ts +24 -0
  44. package/dist/error/framework.js +58 -0
  45. package/dist/error/http.d.ts +58 -0
  46. package/dist/error/http.js +82 -0
  47. package/dist/error/index.d.ts +4 -0
  48. package/dist/error/index.js +16 -0
  49. package/dist/functional/configuration.d.ts +4 -2
  50. package/dist/functional/configuration.js +12 -2
  51. package/dist/index.d.ts +24 -11
  52. package/dist/index.js +36 -36
  53. package/dist/interface.d.ts +270 -184
  54. package/dist/interface.js +9 -1
  55. package/dist/service/aspectService.d.ts +11 -14
  56. package/dist/service/aspectService.js +116 -172
  57. package/dist/service/configService.d.ts +10 -8
  58. package/dist/service/configService.js +61 -38
  59. package/dist/service/decoratorService.d.ts +23 -0
  60. package/dist/service/decoratorService.js +149 -0
  61. package/dist/service/environmentService.js +15 -4
  62. package/dist/service/frameworkService.d.ts +26 -0
  63. package/dist/service/frameworkService.js +176 -0
  64. package/dist/service/informationService.d.ts +4 -7
  65. package/dist/service/informationService.js +41 -10
  66. package/dist/service/lifeCycleService.d.ts +14 -0
  67. package/dist/service/lifeCycleService.js +130 -0
  68. package/dist/service/loggerService.d.ts +27 -0
  69. package/dist/service/loggerService.js +132 -0
  70. package/dist/service/middlewareService.d.ts +11 -0
  71. package/dist/service/middlewareService.js +127 -0
  72. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  73. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  74. package/dist/setup.d.ts +4 -0
  75. package/dist/setup.js +119 -0
  76. package/dist/util/contextUtil.d.ts +1 -1
  77. package/dist/util/contextUtil.js +2 -2
  78. package/dist/util/index.d.ts +64 -0
  79. package/dist/util/index.js +195 -7
  80. package/dist/util/pathFileUtil.js +2 -2
  81. package/dist/util/pathToRegexp.d.ts +17 -0
  82. package/dist/util/pathToRegexp.js +280 -0
  83. package/dist/util/webRouterParam.d.ts +2 -2
  84. package/dist/util/webRouterParam.js +19 -20
  85. package/package.json +10 -15
  86. package/dist/common/lodashWrap.d.ts +0 -9
  87. package/dist/common/lodashWrap.js +0 -18
  88. package/dist/common/notFoundError.d.ts +0 -8
  89. package/dist/common/notFoundError.js +0 -20
  90. package/dist/common/reflectTool.d.ts +0 -15
  91. package/dist/common/reflectTool.js +0 -83
  92. package/dist/context/applicationContext.d.ts +0 -81
  93. package/dist/context/applicationContext.js +0 -263
  94. package/dist/context/managed.d.ts +0 -45
  95. package/dist/context/managed.js +0 -69
  96. package/dist/context/resolverHandler.d.ts +0 -34
  97. package/dist/context/resolverHandler.js +0 -88
  98. package/dist/definitions/messageSource.d.ts +0 -13
  99. package/dist/definitions/messageSource.js +0 -74
  100. package/dist/definitions/resource.d.ts +0 -27
  101. package/dist/definitions/resource.js +0 -116
  102. package/dist/features/index.d.ts +0 -2
  103. package/dist/features/index.js +0 -3
  104. package/dist/logger.d.ts +0 -4
  105. package/dist/logger.js +0 -20
  106. package/dist/util/containerUtil.d.ts +0 -9
  107. package/dist/util/containerUtil.js +0 -26
  108. package/dist/util/emptyFramework.d.ts +0 -62
  109. package/dist/util/emptyFramework.js +0 -72
  110. package/dist/util/serviceFactory.d.ts +0 -13
  111. package/dist/util/staticConfig.d.ts +0 -10
  112. package/dist/util/staticConfig.js +0 -67
  113. package/dist/util/webRouterCollector.js +0 -348
package/dist/setup.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.destroyGlobalApplicationContext = exports.initializeGlobalApplicationContext = void 0;
4
+ const _1 = require("./");
5
+ const config_default_1 = require("./config/config.default");
6
+ const decorator_1 = require("@midwayjs/decorator");
7
+ const util = require("util");
8
+ const path_1 = require("path");
9
+ const logger_1 = require("@midwayjs/logger");
10
+ const debug = util.debuglog('midway:debug');
11
+ async function initializeGlobalApplicationContext(globalOptions) {
12
+ var _a, _b, _c, _d;
13
+ debug('[core]: start "initializeGlobalApplicationContext"');
14
+ const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
15
+ const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
16
+ // new container
17
+ const applicationContext = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
18
+ // bind container to decoratorManager
19
+ debug('[core]: delegate module map from decoratorManager');
20
+ (0, decorator_1.bindContainer)(applicationContext);
21
+ global['MIDWAY_APPLICATION_CONTEXT'] = applicationContext;
22
+ // register baseDir and appDir
23
+ applicationContext.registerObject('baseDir', baseDir);
24
+ applicationContext.registerObject('appDir', appDir);
25
+ if (globalOptions.moduleDetector !== false) {
26
+ if (globalOptions.moduleDetector === undefined ||
27
+ globalOptions.moduleDetector === 'file') {
28
+ applicationContext.setFileDetector(new _1.DirectoryFileDetector({
29
+ loadDir: baseDir,
30
+ ignore: (_d = globalOptions.ignore) !== null && _d !== void 0 ? _d : [],
31
+ }));
32
+ }
33
+ else if (globalOptions.moduleDetector) {
34
+ applicationContext.setFileDetector(globalOptions.moduleDetector);
35
+ }
36
+ }
37
+ // bind inner service
38
+ applicationContext.bindClass(_1.MidwayEnvironmentService);
39
+ applicationContext.bindClass(_1.MidwayInformationService);
40
+ applicationContext.bindClass(_1.MidwayDecoratorService);
41
+ applicationContext.bindClass(_1.MidwayConfigService);
42
+ applicationContext.bindClass(_1.MidwayAspectService);
43
+ applicationContext.bindClass(_1.MidwayLoggerService);
44
+ applicationContext.bindClass(_1.MidwayFrameworkService);
45
+ applicationContext.bindClass(_1.MidwayMiddlewareService);
46
+ applicationContext.bindClass(_1.MidwayLifeCycleService);
47
+ applicationContext.bindClass(_1.MidwayApplicationManager);
48
+ // bind preload module
49
+ if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
50
+ for (const preloadModule of globalOptions.preloadModules) {
51
+ applicationContext.bindClass(preloadModule);
52
+ }
53
+ }
54
+ // init default config
55
+ const configService = await applicationContext.getAsync(_1.MidwayConfigService);
56
+ configService.add([
57
+ {
58
+ default: config_default_1.default,
59
+ },
60
+ ]);
61
+ // init aop support
62
+ await applicationContext.getAsync(_1.MidwayAspectService, [applicationContext]);
63
+ // init decorator service
64
+ await applicationContext.getAsync(_1.MidwayDecoratorService, [
65
+ applicationContext,
66
+ ]);
67
+ if (!globalOptions.configurationModule) {
68
+ globalOptions.configurationModule = [
69
+ (0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
70
+ ];
71
+ }
72
+ for (const configurationModule of [].concat(globalOptions.configurationModule)) {
73
+ // load configuration and component
74
+ applicationContext.load(configurationModule);
75
+ }
76
+ // bind user code module
77
+ await applicationContext.ready();
78
+ if (globalOptions.globalConfig) {
79
+ if (Array.isArray(globalOptions.globalConfig)) {
80
+ configService.add(globalOptions.globalConfig);
81
+ }
82
+ else {
83
+ configService.addObject(globalOptions.globalConfig);
84
+ }
85
+ }
86
+ // merge config
87
+ await configService.load();
88
+ debug('[core]: Current config = %j', configService.getConfiguration());
89
+ // init logger
90
+ await applicationContext.getAsync(_1.MidwayLoggerService, [applicationContext]);
91
+ // middleware support
92
+ await applicationContext.getAsync(_1.MidwayMiddlewareService, [
93
+ applicationContext,
94
+ ]);
95
+ // framework/config/plugin/logger/app decorator support
96
+ await applicationContext.getAsync(_1.MidwayFrameworkService, [
97
+ applicationContext,
98
+ globalOptions,
99
+ ]);
100
+ // lifecycle support
101
+ await applicationContext.getAsync(_1.MidwayLifeCycleService, [
102
+ applicationContext,
103
+ ]);
104
+ return applicationContext;
105
+ }
106
+ exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
107
+ async function destroyGlobalApplicationContext(applicationContext) {
108
+ // stop lifecycle
109
+ const lifecycleService = await applicationContext.getAsync(_1.MidwayLifeCycleService);
110
+ await lifecycleService.stop();
111
+ // stop container
112
+ await applicationContext.stop();
113
+ (0, decorator_1.clearBindContainer)();
114
+ logger_1.loggers.close();
115
+ global['MIDWAY_APPLICATION_CONTEXT'] = undefined;
116
+ global['MIDWAY_MAIN_FRAMEWORK'] = undefined;
117
+ }
118
+ exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
119
+ //# sourceMappingURL=setup.js.map
@@ -1,5 +1,5 @@
1
1
  import { IConfigurationOptions, IMidwayContainer, IMidwayFramework } from '../interface';
2
2
  export declare const getCurrentApplicationContext: () => IMidwayContainer;
3
- export declare const getCurrentMainFramework: <APP extends import("../interface").IMidwayBaseApplication<import("../interface").Context>, T extends IConfigurationOptions>() => IMidwayFramework<APP, T>;
3
+ export declare const getCurrentMainFramework: <APP extends import("../interface").IMidwayBaseApplication<CTX>, CTX extends import("../interface").Context, CONFIG extends IConfigurationOptions>() => IMidwayFramework<APP, CTX, CONFIG, unknown, unknown>;
4
4
  export declare const getCurrentMainApp: <APP extends import("../interface").IMidwayBaseApplication<import("../interface").Context>>() => APP;
5
5
  //# sourceMappingURL=contextUtil.d.ts.map
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCurrentMainApp = exports.getCurrentMainFramework = exports.getCurrentApplicationContext = void 0;
4
4
  const getCurrentApplicationContext = () => {
5
- return exports.getCurrentMainFramework().getApplicationContext();
5
+ return global['MIDWAY_APPLICATION_CONTEXT'];
6
6
  };
7
7
  exports.getCurrentApplicationContext = getCurrentApplicationContext;
8
8
  const getCurrentMainFramework = () => {
@@ -10,7 +10,7 @@ const getCurrentMainFramework = () => {
10
10
  };
11
11
  exports.getCurrentMainFramework = getCurrentMainFramework;
12
12
  const getCurrentMainApp = () => {
13
- return exports.getCurrentMainFramework().getApplication();
13
+ return (0, exports.getCurrentMainFramework)().getApplication();
14
14
  };
15
15
  exports.getCurrentMainApp = getCurrentMainApp;
16
16
  //# sourceMappingURL=contextUtil.js.map
@@ -1,5 +1,18 @@
1
+ import { FunctionMiddleware } from '../interface';
2
+ /**
3
+ * @since 2.0.0
4
+ * @param env
5
+ */
1
6
  export declare const isDevelopmentEnvironment: (env: any) => boolean;
7
+ /**
8
+ * @since 2.0.0
9
+ */
2
10
  export declare const getCurrentEnvironment: () => string;
11
+ /**
12
+ * @param p
13
+ * @param enabledCache
14
+ * @since 2.0.0
15
+ */
3
16
  export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
4
17
  /**
5
18
  * safelyGet(['a','b'],{a: {b: 2}}) // => 2
@@ -8,14 +21,65 @@ export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
8
21
  * safelyGet(['a','1'],{a: {b: 2}}) // => undefined
9
22
  * safelyGet('a.b',{a: {b: 2}}) // => 2
10
23
  * safelyGet('a.b',{c: {b: 2}}) // => undefined
24
+ * @since 2.0.0
11
25
  */
12
26
  export declare function safelyGet(list: string | string[], obj?: Record<string, unknown>): any;
13
27
  /**
14
28
  * 剔除 @ 符号
15
29
  * @param provideId provideId
30
+ * @since 2.0.0
16
31
  */
17
32
  export declare function parsePrefix(provideId: string): string;
18
33
  export declare function getUserHome(): string;
19
34
  export declare function joinURLPath(...strArray: any[]): string;
35
+ /**
36
+ * 代理目标所有的原型方法,不包括构造器和内部隐藏方法
37
+ * @param derivedCtor
38
+ * @param constructors
39
+ * @since 2.0.0
40
+ */
20
41
  export declare function delegateTargetPrototypeMethod(derivedCtor: any, constructors: any[]): void;
42
+ /**
43
+ * 代理目标原型上的特定方法
44
+ * @param derivedCtor
45
+ * @param methods
46
+ * @since 2.0.0
47
+ */
48
+ export declare function delegateTargetMethod(derivedCtor: any, methods: string[]): void;
49
+ /**
50
+ * 代理目标原型属性
51
+ * @param derivedCtor
52
+ * @param properties
53
+ * @since 2.0.0
54
+ */
55
+ export declare function delegateTargetProperties(derivedCtor: any, properties: string[]): void;
56
+ /**
57
+ * 代理目标原型属性
58
+ * @since 2.0.0
59
+ * @param timestamp
60
+ */
61
+ export declare const getCurrentDateString: (timestamp?: number) => string;
62
+ /**
63
+ *
64
+ * @param message
65
+ * @since 3.0.0
66
+ */
67
+ export declare const deprecatedOutput: (message: string) => void;
68
+ /**
69
+ * transform request object to definition type
70
+ *
71
+ * @param originValue
72
+ * @param targetType
73
+ * @since 3.0.0
74
+ */
75
+ export declare const transformRequestObjectByType: (originValue: any, targetType?: any) => any;
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;
21
85
  //# sourceMappingURL=index.d.ts.map
@@ -1,36 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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 debug = util_1.debuglog('midway:container:util');
7
+ const transformer = require("class-transformer");
8
+ const pathToRegexp_1 = require("./pathToRegexp");
9
+ const error_1 = require("../error");
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
- p = path_1.resolve(path_1.dirname(module.parent.filename), p);
33
+ p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
19
34
  }
20
35
  try {
21
36
  if (enabledCache) {
22
37
  return require(p);
23
38
  }
24
39
  else {
25
- const content = fs_1.readFileSync(p, {
40
+ const content = (0, fs_1.readFileSync)(p, {
26
41
  encoding: 'utf-8',
27
42
  });
28
43
  return JSON.parse(content);
29
44
  }
30
45
  }
31
46
  catch (err) {
32
- debug('SafeRequire Warning');
33
- debug(err);
47
+ debug(`SafeRequire Warning, message = ${err.message}`);
34
48
  return undefined;
35
49
  }
36
50
  };
@@ -42,6 +56,7 @@ exports.safeRequire = safeRequire;
42
56
  * safelyGet(['a','1'],{a: {b: 2}}) // => undefined
43
57
  * safelyGet('a.b',{a: {b: 2}}) // => 2
44
58
  * safelyGet('a.b',{c: {b: 2}}) // => undefined
59
+ * @since 2.0.0
45
60
  */
46
61
  function safelyGet(list, obj) {
47
62
  if (arguments.length === 1) {
@@ -67,6 +82,7 @@ exports.safelyGet = safelyGet;
67
82
  /**
68
83
  * 剔除 @ 符号
69
84
  * @param provideId provideId
85
+ * @since 2.0.0
70
86
  */
71
87
  function parsePrefix(provideId) {
72
88
  if (provideId.includes('@')) {
@@ -80,6 +96,7 @@ function getUserHome() {
80
96
  }
81
97
  exports.getUserHome = getUserHome;
82
98
  function joinURLPath(...strArray) {
99
+ strArray = strArray.filter(item => !!item);
83
100
  if (strArray.length === 0) {
84
101
  return '';
85
102
  }
@@ -91,11 +108,17 @@ function joinURLPath(...strArray) {
91
108
  return p;
92
109
  }
93
110
  exports.joinURLPath = joinURLPath;
111
+ /**
112
+ * 代理目标所有的原型方法,不包括构造器和内部隐藏方法
113
+ * @param derivedCtor
114
+ * @param constructors
115
+ * @since 2.0.0
116
+ */
94
117
  function delegateTargetPrototypeMethod(derivedCtor, constructors) {
95
118
  constructors.forEach(baseCtor => {
96
119
  Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
97
120
  if (name !== 'constructor' && !/^_/.test(name)) {
98
- derivedCtor.prototype[name] = async function (...args) {
121
+ derivedCtor.prototype[name] = function (...args) {
99
122
  return this.instance[name](...args);
100
123
  };
101
124
  }
@@ -103,4 +126,169 @@ function delegateTargetPrototypeMethod(derivedCtor, constructors) {
103
126
  });
104
127
  }
105
128
  exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
129
+ /**
130
+ * 代理目标原型上的特定方法
131
+ * @param derivedCtor
132
+ * @param methods
133
+ * @since 2.0.0
134
+ */
135
+ function delegateTargetMethod(derivedCtor, methods) {
136
+ methods.forEach(name => {
137
+ derivedCtor.prototype[name] = function (...args) {
138
+ return this.instance[name](...args);
139
+ };
140
+ });
141
+ }
142
+ exports.delegateTargetMethod = delegateTargetMethod;
143
+ /**
144
+ * 代理目标原型属性
145
+ * @param derivedCtor
146
+ * @param properties
147
+ * @since 2.0.0
148
+ */
149
+ function delegateTargetProperties(derivedCtor, properties) {
150
+ properties.forEach(name => {
151
+ Object.defineProperty(derivedCtor.prototype, name, {
152
+ get() {
153
+ return this.instance[name];
154
+ },
155
+ });
156
+ });
157
+ }
158
+ exports.delegateTargetProperties = delegateTargetProperties;
159
+ /**
160
+ * 代理目标原型属性
161
+ * @since 2.0.0
162
+ * @param timestamp
163
+ */
164
+ const getCurrentDateString = (timestamp = Date.now()) => {
165
+ const d = new Date(timestamp);
166
+ return `${d.getFullYear()}-${(d.getMonth() + 1)
167
+ .toString()
168
+ .padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
169
+ };
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;
106
294
  //# sourceMappingURL=index.js.map
@@ -15,12 +15,12 @@ exports.PathFileUtil = {
15
15
  if (!one || !two) {
16
16
  return false;
17
17
  }
18
- const ext = path_1.extname(one);
18
+ const ext = (0, path_1.extname)(one);
19
19
  return one.replace(ext, '') === two;
20
20
  },
21
21
  getFileContentSync(filePath, encoding) {
22
22
  return typeof filePath === 'string'
23
- ? fs_1.readFileSync(filePath, {
23
+ ? (0, fs_1.readFileSync)(filePath, {
24
24
  encoding,
25
25
  })
26
26
  : filePath;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * this file fork from path-to-regexp package v1.8.0
3
+ */
4
+ /**
5
+ * Normalize the given path string, returning a regular expression.
6
+ *
7
+ * An empty array can be passed in for the keys, which will hold the
8
+ * placeholder key descriptions. For example, using `/user/:id`, `keys` will
9
+ * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
10
+ *
11
+ * @param {(string|RegExp|Array)} path
12
+ * @param {(Array|Object)=} keys
13
+ * @param {Object=} options
14
+ * @return {!RegExp}
15
+ */
16
+ export declare function pathToRegexp(path: any, keys: any, options: any): any;
17
+ //# sourceMappingURL=pathToRegexp.d.ts.map