@midwayjs/core 3.0.0-alpha.43 → 3.0.0-beta.10

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 (99) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/README.md +1 -1
  3. package/dist/baseFramework.d.ts +56 -22
  4. package/dist/baseFramework.js +156 -204
  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 +14 -8
  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 +7 -5
  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 +9 -4
  20. package/dist/{util → common}/webRouterCollector.js +56 -29
  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 +46 -40
  24. package/dist/context/container.js +125 -104
  25. package/dist/context/managedResolverFactory.d.ts +3 -16
  26. package/dist/context/managedResolverFactory.js +77 -77
  27. package/dist/context/requestContainer.d.ts +0 -2
  28. package/dist/context/requestContainer.js +4 -18
  29. package/dist/definitions/functionDefinition.d.ts +3 -2
  30. package/dist/definitions/objectDefinition.d.ts +3 -2
  31. package/dist/definitions/properties.d.ts +2 -13
  32. package/dist/definitions/properties.js +3 -56
  33. package/dist/error/base.d.ts +13 -0
  34. package/dist/error/base.js +19 -0
  35. package/dist/error/code.d.ts +60 -0
  36. package/dist/error/code.js +65 -0
  37. package/dist/error/framework.d.ts +24 -0
  38. package/dist/error/framework.js +58 -0
  39. package/dist/error/http.d.ts +58 -0
  40. package/dist/error/http.js +82 -0
  41. package/dist/error/index.d.ts +4 -0
  42. package/dist/error/index.js +16 -0
  43. package/dist/functional/configuration.d.ts +3 -3
  44. package/dist/functional/configuration.js +3 -3
  45. package/dist/index.d.ts +24 -11
  46. package/dist/index.js +36 -14
  47. package/dist/interface.d.ts +252 -157
  48. package/dist/interface.js +9 -1
  49. package/dist/service/aspectService.d.ts +11 -14
  50. package/dist/service/aspectService.js +114 -170
  51. package/dist/service/configService.d.ts +10 -8
  52. package/dist/service/configService.js +56 -33
  53. package/dist/service/decoratorService.d.ts +23 -0
  54. package/dist/service/decoratorService.js +149 -0
  55. package/dist/service/environmentService.js +13 -2
  56. package/dist/service/frameworkService.d.ts +26 -0
  57. package/dist/service/frameworkService.js +176 -0
  58. package/dist/service/informationService.d.ts +4 -7
  59. package/dist/service/informationService.js +39 -8
  60. package/dist/service/lifeCycleService.d.ts +14 -0
  61. package/dist/service/lifeCycleService.js +130 -0
  62. package/dist/service/loggerService.d.ts +27 -0
  63. package/dist/service/loggerService.js +132 -0
  64. package/dist/service/middlewareService.d.ts +11 -0
  65. package/dist/service/middlewareService.js +127 -0
  66. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  67. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  68. package/dist/setup.d.ts +4 -0
  69. package/dist/setup.js +119 -0
  70. package/dist/util/contextUtil.d.ts +1 -1
  71. package/dist/util/contextUtil.js +1 -1
  72. package/dist/util/index.d.ts +64 -0
  73. package/dist/util/index.js +192 -4
  74. package/dist/util/pathToRegexp.d.ts +17 -0
  75. package/dist/util/pathToRegexp.js +280 -0
  76. package/dist/util/webRouterParam.d.ts +2 -2
  77. package/dist/util/webRouterParam.js +19 -20
  78. package/package.json +9 -15
  79. package/dist/common/lodashWrap.d.ts +0 -9
  80. package/dist/common/lodashWrap.js +0 -18
  81. package/dist/common/notFoundError.d.ts +0 -8
  82. package/dist/common/notFoundError.js +0 -20
  83. package/dist/common/reflectTool.d.ts +0 -17
  84. package/dist/common/reflectTool.js +0 -83
  85. package/dist/context/resolverHandler.d.ts +0 -34
  86. package/dist/context/resolverHandler.js +0 -88
  87. package/dist/definitions/messageSource.d.ts +0 -13
  88. package/dist/definitions/messageSource.js +0 -74
  89. package/dist/definitions/resource.d.ts +0 -27
  90. package/dist/definitions/resource.js +0 -116
  91. package/dist/features/index.d.ts +0 -2
  92. package/dist/features/index.js +0 -3
  93. package/dist/logger.d.ts +0 -4
  94. package/dist/logger.js +0 -20
  95. package/dist/util/containerUtil.d.ts +0 -11
  96. package/dist/util/containerUtil.js +0 -26
  97. package/dist/util/emptyFramework.d.ts +0 -62
  98. package/dist/util/emptyFramework.js +0 -72
  99. package/dist/util/serviceFactory.d.ts +0 -15
@@ -1,18 +1,33 @@
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 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);
@@ -29,8 +44,7 @@ const safeRequire = (p, enabledCache = true) => {
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
@@ -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
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ /**
3
+ * this file fork from path-to-regexp package v1.8.0
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pathToRegexp = void 0;
7
+ /**
8
+ * The main path matching regexp utility.
9
+ *
10
+ * @type {RegExp}
11
+ */
12
+ const PATH_REGEXP = new RegExp([
13
+ // Match escaped characters that would otherwise appear in future matches.
14
+ // This allows the user to escape special characters that won't transform.
15
+ '(\\\\.)',
16
+ // Match Express-style parameters and un-named parameters with a prefix
17
+ // and optional suffixes. Matches appear as:
18
+ //
19
+ // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
20
+ // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
21
+ // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
22
+ '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))',
23
+ ].join('|'), 'g');
24
+ /**
25
+ * Parse a string for the raw tokens.
26
+ *
27
+ * @param {string} str
28
+ * @param {Object=} options
29
+ * @return {!Array}
30
+ */
31
+ function parse(str, options) {
32
+ const tokens = [];
33
+ let key = 0;
34
+ let index = 0;
35
+ let path = '';
36
+ const defaultDelimiter = (options && options.delimiter) || '/';
37
+ let res;
38
+ while ((res = PATH_REGEXP.exec(str)) != null) {
39
+ const m = res[0];
40
+ const escaped = res[1];
41
+ const offset = res.index;
42
+ path += str.slice(index, offset);
43
+ index = offset + m.length;
44
+ // Ignore already escaped sequences.
45
+ if (escaped) {
46
+ path += escaped[1];
47
+ continue;
48
+ }
49
+ const next = str[index];
50
+ const prefix = res[2];
51
+ const name = res[3];
52
+ const capture = res[4];
53
+ const group = res[5];
54
+ const modifier = res[6];
55
+ const asterisk = res[7];
56
+ // Push the current path onto the tokens.
57
+ if (path) {
58
+ tokens.push(path);
59
+ path = '';
60
+ }
61
+ const partial = prefix != null && next != null && next !== prefix;
62
+ const repeat = modifier === '+' || modifier === '*';
63
+ const optional = modifier === '?' || modifier === '*';
64
+ const delimiter = res[2] || defaultDelimiter;
65
+ const pattern = capture || group;
66
+ tokens.push({
67
+ name: name || key++,
68
+ prefix: prefix || '',
69
+ delimiter: delimiter,
70
+ optional: optional,
71
+ repeat: repeat,
72
+ partial: partial,
73
+ asterisk: !!asterisk,
74
+ pattern: pattern
75
+ ? escapeGroup(pattern)
76
+ : asterisk
77
+ ? '.*'
78
+ : '[^' + escapeString(delimiter) + ']+?',
79
+ });
80
+ }
81
+ // Match any characters still remaining.
82
+ if (index < str.length) {
83
+ path += str.substr(index);
84
+ }
85
+ // If the path exists, push it onto the end.
86
+ if (path) {
87
+ tokens.push(path);
88
+ }
89
+ return tokens;
90
+ }
91
+ /**
92
+ * Escape a regular expression string.
93
+ *
94
+ * @param {string} str
95
+ * @return {string}
96
+ */
97
+ function escapeString(str) {
98
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
99
+ }
100
+ /**
101
+ * Escape the capturing group by escaping special characters and meaning.
102
+ *
103
+ * @param {string} group
104
+ * @return {string}
105
+ */
106
+ function escapeGroup(group) {
107
+ return group.replace(/([=!:$/()])/g, '\\$1');
108
+ }
109
+ /**
110
+ * Attach the keys as a property of the regexp.
111
+ *
112
+ * @param {!RegExp} re
113
+ * @param {Array} keys
114
+ * @return {!RegExp}
115
+ */
116
+ function attachKeys(re, keys) {
117
+ re.keys = keys;
118
+ return re;
119
+ }
120
+ /**
121
+ * Get the flags for a regexp from the options.
122
+ *
123
+ * @param {Object} options
124
+ * @return {string}
125
+ */
126
+ function flags(options) {
127
+ return options && options.sensitive ? '' : 'i';
128
+ }
129
+ /**
130
+ * Pull out keys from a regexp.
131
+ *
132
+ * @param {!RegExp} path
133
+ * @param {!Array} keys
134
+ * @return {!RegExp}
135
+ */
136
+ function regexpToRegexp(path, keys) {
137
+ // Use a negative lookahead to match only capturing groups.
138
+ const groups = path.source.match(/\((?!\?)/g);
139
+ if (groups) {
140
+ for (let i = 0; i < groups.length; i++) {
141
+ keys.push({
142
+ name: i,
143
+ prefix: null,
144
+ delimiter: null,
145
+ optional: false,
146
+ repeat: false,
147
+ partial: false,
148
+ asterisk: false,
149
+ pattern: null,
150
+ });
151
+ }
152
+ }
153
+ return attachKeys(path, keys);
154
+ }
155
+ /**
156
+ * Transform an array into a regexp.
157
+ *
158
+ * @param {!Array} path
159
+ * @param {Array} keys
160
+ * @param {!Object} options
161
+ * @return {!RegExp}
162
+ */
163
+ function arrayToRegexp(path, keys, options) {
164
+ const parts = [];
165
+ for (let i = 0; i < path.length; i++) {
166
+ parts.push(pathToRegexp(path[i], keys, options).source);
167
+ }
168
+ const regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
169
+ return attachKeys(regexp, keys);
170
+ }
171
+ /**
172
+ * Create a path regexp from string input.
173
+ *
174
+ * @param {string} path
175
+ * @param {!Array} keys
176
+ * @param {!Object} options
177
+ * @return {!RegExp}
178
+ */
179
+ function stringToRegexp(path, keys, options) {
180
+ return tokensToRegExp(parse(path, options), keys, options);
181
+ }
182
+ /**
183
+ * Expose a function for taking tokens and returning a RegExp.
184
+ *
185
+ * @param {!Array} tokens
186
+ * @param {(Array|Object)=} keys
187
+ * @param {Object=} options
188
+ * @return {!RegExp}
189
+ */
190
+ function tokensToRegExp(tokens, keys, options) {
191
+ if (!Array.isArray(keys)) {
192
+ options = /** @type {!Object} */ keys || options;
193
+ keys = [];
194
+ }
195
+ options = options || {};
196
+ const strict = options.strict;
197
+ const end = options.end !== false;
198
+ let route = '';
199
+ // Iterate over the tokens and create our regexp string.
200
+ for (let i = 0; i < tokens.length; i++) {
201
+ const token = tokens[i];
202
+ if (typeof token === 'string') {
203
+ route += escapeString(token);
204
+ }
205
+ else {
206
+ const prefix = escapeString(token.prefix);
207
+ let capture = '(?:' + token.pattern + ')';
208
+ keys.push(token);
209
+ if (token.repeat) {
210
+ capture += '(?:' + prefix + capture + ')*';
211
+ }
212
+ if (token.optional) {
213
+ if (!token.partial) {
214
+ capture = '(?:' + prefix + '(' + capture + '))?';
215
+ }
216
+ else {
217
+ capture = prefix + '(' + capture + ')?';
218
+ }
219
+ }
220
+ else {
221
+ capture = prefix + '(' + capture + ')';
222
+ }
223
+ route += capture;
224
+ }
225
+ }
226
+ const delimiter = escapeString(options.delimiter || '/');
227
+ const endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
228
+ // In non-strict mode we allow a slash at the end of match. If the path to
229
+ // match already ends with a slash, we remove it for consistency. The slash
230
+ // is valid at the end of a path match, not in the middle. This is important
231
+ // in non-ending mode, where "/test/" shouldn't match "/test//route".
232
+ if (!strict) {
233
+ route =
234
+ (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) +
235
+ '(?:' +
236
+ delimiter +
237
+ '(?=$))?';
238
+ }
239
+ if (end) {
240
+ route += '$';
241
+ }
242
+ else {
243
+ // In non-ending mode, we need the capturing groups to match as much as
244
+ // possible by using a positive lookahead to the end or next path segment.
245
+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
246
+ }
247
+ return attachKeys(new RegExp('^' + route, flags(options)), keys);
248
+ }
249
+ /**
250
+ * Normalize the given path string, returning a regular expression.
251
+ *
252
+ * An empty array can be passed in for the keys, which will hold the
253
+ * placeholder key descriptions. For example, using `/user/:id`, `keys` will
254
+ * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
255
+ *
256
+ * @param {(string|RegExp|Array)} path
257
+ * @param {(Array|Object)=} keys
258
+ * @param {Object=} options
259
+ * @return {!RegExp}
260
+ */
261
+ function pathToRegexp(path, keys, options) {
262
+ if (!Array.isArray(keys)) {
263
+ options = /** @type {!Object} */ keys || options;
264
+ keys = [];
265
+ }
266
+ options = options || {};
267
+ if (path instanceof RegExp) {
268
+ return regexpToRegexp(path, /** @type {!Array} */ keys);
269
+ }
270
+ if (Array.isArray(path)) {
271
+ return arrayToRegexp(
272
+ /** @type {!Array} */ path,
273
+ /** @type {!Array} */ keys, options);
274
+ }
275
+ return stringToRegexp(
276
+ /** @type {string} */ path,
277
+ /** @type {!Array} */ keys, options);
278
+ }
279
+ exports.pathToRegexp = pathToRegexp;
280
+ //# sourceMappingURL=pathToRegexp.js.map
@@ -1,3 +1,3 @@
1
- export declare const extractKoaLikeValue: (key: any, data: any) => (ctx: any, next: any) => Promise<any>;
2
- export declare const extractExpressLikeValue: (key: any, data: any) => (req: any, res: any, next: any) => Promise<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,26 +2,25 @@
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
  }
9
- return async function (ctx, next) {
10
+ return function (ctx, next) {
10
11
  switch (key) {
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
25
  return ctx.getFileStream && ctx.getFileStream(data);
27
26
  case decorator_1.RouteParamTypes.FILESSTREAM:
@@ -32,10 +31,10 @@ const extractKoaLikeValue = (key, data) => {
32
31
  return ctx['ip'];
33
32
  case decorator_1.RouteParamTypes.QUERIES:
34
33
  if (ctx.queries) {
35
- return data ? ctx.queries[data] : ctx.queries;
34
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.queries[data] : ctx.queries, paramType);
36
35
  }
37
36
  else {
38
- return data ? ctx.query[data] : ctx.query;
37
+ return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
39
38
  }
40
39
  default:
41
40
  return null;
@@ -43,24 +42,24 @@ const extractKoaLikeValue = (key, data) => {
43
42
  };
44
43
  };
45
44
  exports.extractKoaLikeValue = extractKoaLikeValue;
46
- const extractExpressLikeValue = (key, data) => {
45
+ const extractExpressLikeValue = (key, data, paramType) => {
47
46
  if (decorator_1.ALL === data) {
48
47
  data = undefined;
49
48
  }
50
- return async function (req, res, next) {
49
+ return function (req, res, next) {
51
50
  switch (key) {
52
51
  case decorator_1.RouteParamTypes.NEXT:
53
52
  return next;
54
53
  case decorator_1.RouteParamTypes.BODY:
55
- return data && req.body ? req.body[data] : req.body;
54
+ return (0, index_1.transformRequestObjectByType)(data && req.body ? req.body[data] : req.body, paramType);
56
55
  case decorator_1.RouteParamTypes.PARAM:
57
- return data ? req.params[data] : req.params;
56
+ return (0, index_1.transformRequestObjectByType)(data ? req.params[data] : req.params, paramType);
58
57
  case decorator_1.RouteParamTypes.QUERY:
59
- return data ? req.query[data] : req.query;
58
+ return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
60
59
  case decorator_1.RouteParamTypes.HEADERS:
61
- return data ? req.get(data) : req.headers;
60
+ return (0, index_1.transformRequestObjectByType)(data ? req.get(data) : req.headers, paramType);
62
61
  case decorator_1.RouteParamTypes.SESSION:
63
- return data ? req.session[data] : req.session;
62
+ return (0, index_1.transformRequestObjectByType)(data ? req.session[data] : req.session, paramType);
64
63
  case decorator_1.RouteParamTypes.FILESTREAM:
65
64
  return req.getFileStream && req.getFileStream(data);
66
65
  case decorator_1.RouteParamTypes.FILESSTREAM:
@@ -71,10 +70,10 @@ const extractExpressLikeValue = (key, data) => {
71
70
  return req['ip'];
72
71
  case decorator_1.RouteParamTypes.QUERIES:
73
72
  if (req.queries) {
74
- return data ? req.queries[data] : req.queries;
73
+ return (0, index_1.transformRequestObjectByType)(data ? req.queries[data] : req.queries, paramType);
75
74
  }
76
75
  else {
77
- return data ? req.query[data] : req.query;
76
+ return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
78
77
  }
79
78
  default:
80
79
  return null;