koatty_validation 1.2.6 → 1.2.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,14 @@
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.2.7](https://github.com/koatty/koatty_validation/compare/v1.2.6...v1.2.7) (2023-02-17)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add script ([ca82c14](https://github.com/koatty/koatty_validation/commit/ca82c14b0a2226024fb2c4476ba7353be7a2f65a))
11
+ * plainToClass convert type ([06ed46e](https://github.com/koatty/koatty_validation/commit/06ed46e21ce191dc1c9f5c18ee7d029e9b6d4abf))
12
+
5
13
  ### [1.2.6](https://github.com/koatty/koatty_validation/compare/v1.2.5...v1.2.6) (2023-01-09)
6
14
 
7
15
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2023-01-10 00:29:01
3
+ * @Date: 2023-02-17 11:33:26
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -38,11 +38,9 @@ export declare function Contains(seed: string, validationOptions?: ValidationOpt
38
38
  *
39
39
  * @param {*} clazz
40
40
  * @param {*} cls
41
- * @param {boolean} convert
42
- * @param {boolean} data
43
41
  * @returns {*} cls
44
42
  */
45
- export declare function convertDtoParamsType(clazz: any, cls: any, data: any): any;
43
+ export declare function convertDtoParamsType(clazz: any, cls: any): any;
46
44
 
47
45
  /**
48
46
  * 绑定参数类型转换
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2023-01-10 00:28:47
3
+ * @Date: 2023-02-17 11:33:12
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -75,64 +75,25 @@ function plainToClass(clazz, data, convert = false) {
75
75
  else {
76
76
  cls = Object.assign(Reflect.construct(clazz, []), data);
77
77
  }
78
- return convertOrCheckDtoParamsType(clazz, cls, convert);
79
- }
80
- return data;
81
- }
82
- /**
83
- * convertOrCheckDtoParamsType
84
- *
85
- * @param {*} clazz
86
- * @param {*} cls
87
- * @param {boolean} convert
88
- * @returns {*} cls
89
- */
90
- function convertOrCheckDtoParamsType(clazz, cls, convert) {
91
- if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
92
- for (const key in cls) {
93
- if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
94
- if (convert) {
95
- cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
96
- }
97
- else {
98
- if (!checkParamsType(cls[key], cls._typeDef[key])) {
99
- throw new Error(`parameter ${key} type error`);
100
- }
101
- }
102
- }
103
- }
104
- }
105
- else {
106
- const originMap = koatty_container.getOriginMetadata(PARAM_TYPE_KEY, clazz);
107
- for (const [key, type] of originMap) {
108
- if (key) {
109
- if (convert) {
110
- cls[key] = convertParamsType(cls[key], type);
111
- }
112
- else {
113
- if (!checkParamsType(cls[key], type)) {
114
- throw new Error(`parameter ${key} type error`);
115
- }
116
- }
117
- }
78
+ if (convert) {
79
+ return convertDtoParamsType(clazz, cls);
118
80
  }
81
+ return cls;
119
82
  }
120
- return cls;
83
+ return data;
121
84
  }
122
85
  /**
123
86
  * convertDtoParamsType
124
87
  *
125
88
  * @param {*} clazz
126
89
  * @param {*} cls
127
- * @param {boolean} convert
128
- * @param {boolean} data
129
90
  * @returns {*} cls
130
91
  */
131
- function convertDtoParamsType(clazz, cls, data) {
92
+ function convertDtoParamsType(clazz, cls) {
132
93
  if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
133
94
  for (const key in cls) {
134
95
  if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
135
- cls[key] = convertParamsType(data[key], cls._typeDef[key]);
96
+ cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
136
97
  }
137
98
  }
138
99
  }
@@ -140,7 +101,7 @@ function convertDtoParamsType(clazz, cls, data) {
140
101
  const originMap = koatty_container.getOriginMetadata(PARAM_TYPE_KEY, clazz);
141
102
  for (const [key, type] of originMap) {
142
103
  if (key) {
143
- cls[key] = convertParamsType(data[key], type);
104
+ cls[key] = convertParamsType(cls[key], type);
144
105
  }
145
106
  }
146
107
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2023-01-10 00:28:47
3
+ * @Date: 2023-02-17 11:33:12
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -51,64 +51,25 @@ function plainToClass(clazz, data, convert = false) {
51
51
  else {
52
52
  cls = Object.assign(Reflect.construct(clazz, []), data);
53
53
  }
54
- return convertOrCheckDtoParamsType(clazz, cls, convert);
55
- }
56
- return data;
57
- }
58
- /**
59
- * convertOrCheckDtoParamsType
60
- *
61
- * @param {*} clazz
62
- * @param {*} cls
63
- * @param {boolean} convert
64
- * @returns {*} cls
65
- */
66
- function convertOrCheckDtoParamsType(clazz, cls, convert) {
67
- if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
68
- for (const key in cls) {
69
- if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
70
- if (convert) {
71
- cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
72
- }
73
- else {
74
- if (!checkParamsType(cls[key], cls._typeDef[key])) {
75
- throw new Error(`parameter ${key} type error`);
76
- }
77
- }
78
- }
79
- }
80
- }
81
- else {
82
- const originMap = getOriginMetadata(PARAM_TYPE_KEY, clazz);
83
- for (const [key, type] of originMap) {
84
- if (key) {
85
- if (convert) {
86
- cls[key] = convertParamsType(cls[key], type);
87
- }
88
- else {
89
- if (!checkParamsType(cls[key], type)) {
90
- throw new Error(`parameter ${key} type error`);
91
- }
92
- }
93
- }
54
+ if (convert) {
55
+ return convertDtoParamsType(clazz, cls);
94
56
  }
57
+ return cls;
95
58
  }
96
- return cls;
59
+ return data;
97
60
  }
98
61
  /**
99
62
  * convertDtoParamsType
100
63
  *
101
64
  * @param {*} clazz
102
65
  * @param {*} cls
103
- * @param {boolean} convert
104
- * @param {boolean} data
105
66
  * @returns {*} cls
106
67
  */
107
- function convertDtoParamsType(clazz, cls, data) {
68
+ function convertDtoParamsType(clazz, cls) {
108
69
  if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
109
70
  for (const key in cls) {
110
71
  if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
111
- cls[key] = convertParamsType(data[key], cls._typeDef[key]);
72
+ cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
112
73
  }
113
74
  }
114
75
  }
@@ -116,7 +77,7 @@ function convertDtoParamsType(clazz, cls, data) {
116
77
  const originMap = getOriginMetadata(PARAM_TYPE_KEY, clazz);
117
78
  for (const [key, type] of originMap) {
118
79
  if (key) {
119
- cls[key] = convertParamsType(data[key], type);
80
+ cls[key] = convertParamsType(cls[key], type);
120
81
  }
121
82
  }
122
83
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_validation",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "Validation Util for Koatty and ThinkORM.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -50,7 +50,7 @@
50
50
  "@rollup/plugin-json": "^4.x.x",
51
51
  "@types/jest": "^27.x.x",
52
52
  "@types/koa": "^2.x.x",
53
- "@types/node": "^16.x.x",
53
+ "@types/node": "^18.x.x",
54
54
  "@types/validator": "^13.7.2",
55
55
  "@typescript-eslint/eslint-plugin": "^5.x.x",
56
56
  "@typescript-eslint/parser": "^5.x.x",
@@ -75,11 +75,11 @@
75
75
  "koatty_lib": "^1.x.x",
76
76
  "koatty_logger": "^2.x.x",
77
77
  "reflect-metadata": "^0.1.13",
78
- "tslib": "^2.4.1"
78
+ "tslib": "^2.5.0"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "koatty_container": "^1.x.x",
82
82
  "koatty_lib": "^1.x.x",
83
83
  "koatty_logger": "^2.x.x"
84
84
  }
85
- }
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_validation",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "Validation Util for Koatty and ThinkORM.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -50,7 +50,7 @@
50
50
  "@rollup/plugin-json": "^4.x.x",
51
51
  "@types/jest": "^27.x.x",
52
52
  "@types/koa": "^2.x.x",
53
- "@types/node": "^16.x.x",
53
+ "@types/node": "^18.x.x",
54
54
  "@types/validator": "^13.7.2",
55
55
  "@typescript-eslint/eslint-plugin": "^5.x.x",
56
56
  "@typescript-eslint/parser": "^5.x.x",
@@ -75,11 +75,11 @@
75
75
  "koatty_lib": "^1.x.x",
76
76
  "koatty_logger": "^2.x.x",
77
77
  "reflect-metadata": "^0.1.13",
78
- "tslib": "^2.4.1"
78
+ "tslib": "^2.5.0"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "koatty_container": "^1.x.x",
82
82
  "koatty_lib": "^1.x.x",
83
83
  "koatty_logger": "^2.x.x"
84
84
  }
85
- }
85
+ }