koatty_router 1.7.6 → 1.7.7

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.7.7](https://github.com/koatty/koatty_router/compare/v1.7.6...v1.7.7) (2022-08-19)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * 移除强制类型转换,增加类型检查 ([199fa8d](https://github.com/koatty/koatty_router/commit/199fa8d16a3a8bc271f445e8a39a7e760afa982b))
11
+
5
12
  ### [1.7.6](https://github.com/koatty/koatty_router/compare/v1.7.5...v1.7.6) (2022-05-27)
6
13
 
7
14
  ### [1.7.5](https://github.com/koatty/koatty_router/compare/v1.7.4...v1.7.5) (2022-03-14)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 10:03:18
3
+ * @Date: 2022-08-19 14:40:28
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 10:02:58
3
+ * @Date: 2022-08-19 14:40:12
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -46,7 +46,7 @@ var KoaRouter__default = /*#__PURE__*/_interopDefaultLegacy(KoaRouter);
46
46
  * @Usage:
47
47
  * @Author: richen
48
48
  * @Date: 2021-11-24 23:21:26
49
- * @LastEditTime: 2022-03-15 17:11:03
49
+ * @LastEditTime: 2022-08-19 14:33:52
50
50
  */
51
51
  /**
52
52
  * Parameter binding assignment.
@@ -90,26 +90,26 @@ async function getParamter(app, ctx, params) {
90
90
  */
91
91
  async function checkParams(app, value, opt) {
92
92
  try {
93
+ //@Validated
93
94
  if (opt.isDto) {
94
95
  // DTO class
95
96
  if (!opt.clazz) {
96
97
  opt.clazz = koatty_container.IOCContainer.getClass(opt.type, "COMPONENT");
97
98
  }
98
99
  if (opt.dtoCheck) {
99
- value = await koatty_validation.ClassValidator.valid(opt.clazz, value, true);
100
+ value = await koatty_validation.ClassValidator.valid(opt.clazz, value, false);
100
101
  }
101
102
  else {
102
- value = koatty_validation.plainToClass(opt.clazz, value, true);
103
+ value = koatty_validation.plainToClass(opt.clazz, value, false);
103
104
  }
104
105
  }
105
106
  else {
106
- value = koatty_validation.convertParamsType(value, opt.type);
107
107
  //@Valid()
108
- if (opt) {
109
- const { type, validRule, validOpt } = opt;
110
- if (type && validRule) {
111
- validatorFuncs(`${opt.index}`, value, type, validRule, validOpt, false);
112
- }
108
+ if (opt.validRule) {
109
+ validatorFuncs(`${opt.index}`, value, opt.type, opt.validRule, opt.validOpt);
110
+ }
111
+ if (!koatty_validation.checkParamsType(value, opt.type)) {
112
+ throw new koatty_exception.Exception(`TypeError: invalid arguments`, 1, 400);
113
113
  }
114
114
  }
115
115
  return value;
@@ -130,11 +130,7 @@ async function checkParams(app, value, opt) {
130
130
  * @param {boolean} [checkType=true]
131
131
  * @returns
132
132
  */
133
- function validatorFuncs(name, value, type, rule, options, checkType = true) {
134
- // check type
135
- if (checkType && !koatty_validation.checkParamsType(value, type)) {
136
- throw new koatty_exception.Exception(options.message || `TypeError: invalid arguments '${name}'.`, 1, 400);
137
- }
133
+ function validatorFuncs(name, value, type, rule, options) {
138
134
  if (Helper__namespace.isFunction(rule)) {
139
135
  // Function no return value
140
136
  rule(value);
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 10:02:58
3
+ * @Date: 2022-08-19 14:40:12
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -11,7 +11,7 @@ import { IOCContainer, RecursiveGetMetadata, TAGGED_PARAM, getOriginMetadata } f
11
11
  import { LoadProto, ListServices } from 'koatty_proto';
12
12
  import { DefaultLogger } from 'koatty_logger';
13
13
  import { Exception } from 'koatty_exception';
14
- import { ClassValidator, plainToClass, convertParamsType, checkParamsType, FunctionValidator, PARAM_RULE_KEY, PARAM_CHECK_KEY, PARAM_TYPE_KEY, paramterTypes } from 'koatty_validation';
14
+ import { ClassValidator, plainToClass, checkParamsType, FunctionValidator, PARAM_RULE_KEY, PARAM_CHECK_KEY, PARAM_TYPE_KEY, paramterTypes } from 'koatty_validation';
15
15
  import 'reflect-metadata';
16
16
  import KoaRouter from '@koa/router';
17
17
 
@@ -20,7 +20,7 @@ import KoaRouter from '@koa/router';
20
20
  * @Usage:
21
21
  * @Author: richen
22
22
  * @Date: 2021-11-24 23:21:26
23
- * @LastEditTime: 2022-03-15 17:11:03
23
+ * @LastEditTime: 2022-08-19 14:33:52
24
24
  */
25
25
  /**
26
26
  * Parameter binding assignment.
@@ -64,26 +64,26 @@ async function getParamter(app, ctx, params) {
64
64
  */
65
65
  async function checkParams(app, value, opt) {
66
66
  try {
67
+ //@Validated
67
68
  if (opt.isDto) {
68
69
  // DTO class
69
70
  if (!opt.clazz) {
70
71
  opt.clazz = IOCContainer.getClass(opt.type, "COMPONENT");
71
72
  }
72
73
  if (opt.dtoCheck) {
73
- value = await ClassValidator.valid(opt.clazz, value, true);
74
+ value = await ClassValidator.valid(opt.clazz, value, false);
74
75
  }
75
76
  else {
76
- value = plainToClass(opt.clazz, value, true);
77
+ value = plainToClass(opt.clazz, value, false);
77
78
  }
78
79
  }
79
80
  else {
80
- value = convertParamsType(value, opt.type);
81
81
  //@Valid()
82
- if (opt) {
83
- const { type, validRule, validOpt } = opt;
84
- if (type && validRule) {
85
- validatorFuncs(`${opt.index}`, value, type, validRule, validOpt, false);
86
- }
82
+ if (opt.validRule) {
83
+ validatorFuncs(`${opt.index}`, value, opt.type, opt.validRule, opt.validOpt);
84
+ }
85
+ if (!checkParamsType(value, opt.type)) {
86
+ throw new Exception(`TypeError: invalid arguments`, 1, 400);
87
87
  }
88
88
  }
89
89
  return value;
@@ -104,11 +104,7 @@ async function checkParams(app, value, opt) {
104
104
  * @param {boolean} [checkType=true]
105
105
  * @returns
106
106
  */
107
- function validatorFuncs(name, value, type, rule, options, checkType = true) {
108
- // check type
109
- if (checkType && !checkParamsType(value, type)) {
110
- throw new Exception(options.message || `TypeError: invalid arguments '${name}'.`, 1, 400);
111
- }
107
+ function validatorFuncs(name, value, type, rule, options) {
112
108
  if (Helper.isFunction(rule)) {
113
109
  // Function no return value
114
110
  rule(value);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_router",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "Koatty routing component, adapt to http1/2, websocket, gRPC.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -58,7 +58,7 @@
58
58
  "typescript": "^4.x.x"
59
59
  },
60
60
  "dependencies": {
61
- "@koa/router": "^10.1.1",
61
+ "@koa/router": "^12.0.0",
62
62
  "koatty_container": "^1.x.x",
63
63
  "koatty_core": "^1.x.x",
64
64
  "koatty_exception": "^1.x.x",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_router",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "Koatty routing component, adapt to http1/2, websocket, gRPC.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -58,7 +58,7 @@
58
58
  "typescript": "^4.x.x"
59
59
  },
60
60
  "dependencies": {
61
- "@koa/router": "^10.1.1",
61
+ "@koa/router": "^12.0.0",
62
62
  "koatty_container": "^1.x.x",
63
63
  "koatty_core": "^1.x.x",
64
64
  "koatty_exception": "^1.x.x",