typespeed 2.1.1 → 2.1.3
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.
- package/dist/route.decorator.js +13 -10
- package/dist/scaffold/templates/package.json.tpl +3 -2
- package/dist/typespeed.d.ts +2 -2
- package/package.json +2 -2
- package/src/route.decorator.ts +14 -10
- package/src/scaffold/templates/package.json.tpl +3 -2
- package/src/typespeed.d.ts +2 -2
- package/test/src/test-request.class.ts +2 -2
package/dist/route.decorator.js
CHANGED
|
@@ -149,18 +149,21 @@ function reqBody(target, propertyKey, parameterIndex) {
|
|
|
149
149
|
routerParams[key] = (req, res, next) => req.body;
|
|
150
150
|
}
|
|
151
151
|
exports.reqBody = reqBody;
|
|
152
|
-
function reqParam(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
152
|
+
function reqParam(target, propertyKey, parameterIndex) {
|
|
153
|
+
const key = [target.constructor.name, propertyKey, parameterIndex].toString();
|
|
154
|
+
const paramName = getParamInFunction(target[propertyKey], parameterIndex);
|
|
155
|
+
routerParams[key] = (req, res, next) => req.params[paramName];
|
|
157
156
|
}
|
|
158
157
|
exports.reqParam = reqParam;
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
function getParamInFunction(fn, index) {
|
|
159
|
+
const code = fn.toString().replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, '').replace(/=>.*$/mg, '').replace(/=[^,]+/mg, '');
|
|
160
|
+
const result = code.slice(code.indexOf('(') + 1, code.indexOf(')')).match(/([^\s,]+)/g);
|
|
161
|
+
return result[index] || null;
|
|
162
|
+
}
|
|
163
|
+
function reqQuery(target, propertyKey, parameterIndex) {
|
|
164
|
+
const key = [target.constructor.name, propertyKey, parameterIndex].toString();
|
|
165
|
+
const paramName = getParamInFunction(target[propertyKey], parameterIndex);
|
|
166
|
+
routerParams[key] = (req, res, next) => req.query[paramName];
|
|
164
167
|
}
|
|
165
168
|
exports.reqQuery = reqQuery;
|
|
166
169
|
function reqForm(paramName) {
|
package/dist/typespeed.d.ts
CHANGED
|
@@ -178,9 +178,9 @@ declare function next(target: any, propertyKey: string, parameterIndex: number)
|
|
|
178
178
|
/** request.body 对象装饰器,作为路由页面方法参数,获取 request.body 对象 */
|
|
179
179
|
declare function reqBody(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
180
180
|
/** request.param 值装饰器,作为路由页面方法参数,获取 request.params 内容 */
|
|
181
|
-
declare function reqParam(
|
|
181
|
+
declare function reqParam(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
182
182
|
/** request.query 值装饰器,作为路由页面方法参数,获取 request.query 内容 */
|
|
183
|
-
declare function reqQuery(
|
|
183
|
+
declare function reqQuery(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
184
184
|
/** request 表单值装饰器,作为路由页面方法参数,获取 request.body 表单内容 */
|
|
185
185
|
declare function reqForm(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
|
|
186
186
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespeed",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "A new Framework for TypeScript.",
|
|
5
5
|
"author": "speedphp",
|
|
6
6
|
"license": "MIT License",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"commander": "^9.4.0",
|
|
35
35
|
"compression": "^1.7.4",
|
|
36
36
|
"connect-redis": "^6.1.3",
|
|
37
|
-
"consolidate": "
|
|
37
|
+
"consolidate": "1.0.1",
|
|
38
38
|
"cookie-parser": "^1.4.6",
|
|
39
39
|
"cron": "^2.3.0",
|
|
40
40
|
"express": "^4.18.1",
|
package/src/route.decorator.ts
CHANGED
|
@@ -143,18 +143,22 @@ function reqBody(target: any, propertyKey: string, parameterIndex: number) {
|
|
|
143
143
|
routerParams[key] = (req, res, next) => req.body;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
function reqParam(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
146
|
+
function reqParam(target: any, propertyKey: string, parameterIndex: number) {
|
|
147
|
+
const key = [target.constructor.name, propertyKey, parameterIndex].toString();
|
|
148
|
+
const paramName = getParamInFunction(target[propertyKey], parameterIndex);
|
|
149
|
+
routerParams[key] = (req, res, next) => req.params[paramName];
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
function getParamInFunction(fn: Function, index: number) {
|
|
153
|
+
const code = fn.toString().replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, '').replace(/=>.*$/mg, '').replace(/=[^,]+/mg, '');
|
|
154
|
+
const result = code.slice(code.indexOf('(') + 1, code.indexOf(')')).match(/([^\s,]+)/g);
|
|
155
|
+
return result[index] || null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function reqQuery(target: any, propertyKey: string, parameterIndex: number) {
|
|
159
|
+
const key = [target.constructor.name, propertyKey, parameterIndex].toString();
|
|
160
|
+
const paramName = getParamInFunction(target[propertyKey], parameterIndex);
|
|
161
|
+
routerParams[key] = (req, res, next) => req.query[paramName];
|
|
158
162
|
}
|
|
159
163
|
|
|
160
164
|
function reqForm(paramName: string) {
|
package/src/typespeed.d.ts
CHANGED
|
@@ -178,9 +178,9 @@ declare function next(target: any, propertyKey: string, parameterIndex: number)
|
|
|
178
178
|
/** request.body 对象装饰器,作为路由页面方法参数,获取 request.body 对象 */
|
|
179
179
|
declare function reqBody(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
180
180
|
/** request.param 值装饰器,作为路由页面方法参数,获取 request.params 内容 */
|
|
181
|
-
declare function reqParam(
|
|
181
|
+
declare function reqParam(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
182
182
|
/** request.query 值装饰器,作为路由页面方法参数,获取 request.query 内容 */
|
|
183
|
-
declare function reqQuery(
|
|
183
|
+
declare function reqQuery(target: any, propertyKey: string, parameterIndex: number) : void;
|
|
184
184
|
/** request 表单值装饰器,作为路由页面方法参数,获取 request.body 表单内容 */
|
|
185
185
|
declare function reqForm(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
|
|
186
186
|
|
|
@@ -12,7 +12,7 @@ export default class TestRequest {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
@getMapping("/request/query")
|
|
15
|
-
async testQuery(req, res, @reqQuery
|
|
15
|
+
async testQuery(req, res, @reqQuery id: number): Promise<MutilUsers> {
|
|
16
16
|
log("id: " + id);
|
|
17
17
|
return Promise.resolve(new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]));
|
|
18
18
|
}
|
|
@@ -30,7 +30,7 @@ export default class TestRequest {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
@getMapping("/request/param/:id")
|
|
33
|
-
testParam(@res res, @reqParam
|
|
33
|
+
testParam(@res res, @reqParam id: number) {
|
|
34
34
|
log("id: " + id);
|
|
35
35
|
res.send("test param");
|
|
36
36
|
}
|