koatty_validation 1.2.7 → 1.2.9
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 +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -12
- package/dist/index.mjs +54 -12
- package/dist/package.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
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.9](https://github.com/koatty/koatty_validation/compare/v1.2.8...v1.2.9) (2023-09-01)
|
|
6
|
+
|
|
7
|
+
### [1.2.8](https://github.com/koatty/koatty_validation/compare/v1.2.7...v1.2.8) (2023-02-17)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* convert type ([924449d](https://github.com/koatty/koatty_validation/commit/924449d9f5fd7b14cbe3c1532f96416e69cc4eed))
|
|
13
|
+
|
|
5
14
|
### [1.2.7](https://github.com/koatty/koatty_validation/compare/v1.2.6...v1.2.7) (2023-02-17)
|
|
6
15
|
|
|
7
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2023-
|
|
3
|
+
* @Date: 2023-09-01 11:55:18
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -355,7 +355,7 @@ export declare enum paramterTypes {
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
|
-
*
|
|
358
|
+
* plain object convert to class instance
|
|
359
359
|
*
|
|
360
360
|
* @export
|
|
361
361
|
* @param {*} clazz
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2023-
|
|
3
|
+
* @Date: 2023-09-01 11:54:57
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -55,7 +55,7 @@ function setExpose(object, propertyName) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* plain object convert to class instance
|
|
59
59
|
*
|
|
60
60
|
* @export
|
|
61
61
|
* @param {*} clazz
|
|
@@ -65,22 +65,63 @@ function setExpose(object, propertyName) {
|
|
|
65
65
|
*/
|
|
66
66
|
function plainToClass(clazz, data, convert = false) {
|
|
67
67
|
if (helper__namespace.isClass(clazz)) {
|
|
68
|
-
let cls;
|
|
69
68
|
if (!helper__namespace.isObject(data)) {
|
|
70
69
|
data = {};
|
|
71
70
|
}
|
|
72
71
|
if (data instanceof clazz) {
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
cls = Object.assign(Reflect.construct(clazz, []), data);
|
|
72
|
+
return data;
|
|
77
73
|
}
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
return assignDtoParams(clazz, data, convert);
|
|
75
|
+
}
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* assign dto params
|
|
80
|
+
* @param clazz
|
|
81
|
+
* @param data
|
|
82
|
+
* @param convert
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
function assignDtoParams(clazz, data, convert = false) {
|
|
86
|
+
const cls = Reflect.construct(clazz, []);
|
|
87
|
+
if (convert) {
|
|
88
|
+
return convertAssignDtoParams(clazz, cls, data);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for (const key in cls) {
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(data, key) &&
|
|
93
|
+
data[key] !== undefined) {
|
|
94
|
+
cls[key] = data[key];
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
return cls;
|
|
82
98
|
}
|
|
83
|
-
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* convert type and assign dto params
|
|
102
|
+
* @param clazz
|
|
103
|
+
* @param cls
|
|
104
|
+
* @param data
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
function convertAssignDtoParams(clazz, cls, data) {
|
|
108
|
+
if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
|
|
109
|
+
for (const key in cls) {
|
|
110
|
+
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key) &&
|
|
111
|
+
data[key] !== undefined) {
|
|
112
|
+
cls[key] = convertParamsType(data[key], cls._typeDef[key]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const originMap = koatty_container.getOriginMetadata(PARAM_TYPE_KEY, clazz);
|
|
118
|
+
for (const [key, type] of originMap) {
|
|
119
|
+
if (key && data[key] !== undefined) {
|
|
120
|
+
cls[key] = convertParamsType(data[key], type);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return cls;
|
|
84
125
|
}
|
|
85
126
|
/**
|
|
86
127
|
* convertDtoParamsType
|
|
@@ -92,7 +133,8 @@ function plainToClass(clazz, data, convert = false) {
|
|
|
92
133
|
function convertDtoParamsType(clazz, cls) {
|
|
93
134
|
if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
|
|
94
135
|
for (const key in cls) {
|
|
95
|
-
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key) &&
|
|
137
|
+
cls[key] !== undefined) {
|
|
96
138
|
cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
|
|
97
139
|
}
|
|
98
140
|
}
|
|
@@ -100,7 +142,7 @@ function convertDtoParamsType(clazz, cls) {
|
|
|
100
142
|
else {
|
|
101
143
|
const originMap = koatty_container.getOriginMetadata(PARAM_TYPE_KEY, clazz);
|
|
102
144
|
for (const [key, type] of originMap) {
|
|
103
|
-
if (key) {
|
|
145
|
+
if (key && cls[key] !== undefined) {
|
|
104
146
|
cls[key] = convertParamsType(cls[key], type);
|
|
105
147
|
}
|
|
106
148
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2023-
|
|
3
|
+
* @Date: 2023-09-01 11:54:57
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -31,7 +31,7 @@ function setExpose(object, propertyName) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* plain object convert to class instance
|
|
35
35
|
*
|
|
36
36
|
* @export
|
|
37
37
|
* @param {*} clazz
|
|
@@ -41,22 +41,63 @@ function setExpose(object, propertyName) {
|
|
|
41
41
|
*/
|
|
42
42
|
function plainToClass(clazz, data, convert = false) {
|
|
43
43
|
if (helper.isClass(clazz)) {
|
|
44
|
-
let cls;
|
|
45
44
|
if (!helper.isObject(data)) {
|
|
46
45
|
data = {};
|
|
47
46
|
}
|
|
48
47
|
if (data instanceof clazz) {
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
cls = Object.assign(Reflect.construct(clazz, []), data);
|
|
48
|
+
return data;
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
return assignDtoParams(clazz, data, convert);
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* assign dto params
|
|
56
|
+
* @param clazz
|
|
57
|
+
* @param data
|
|
58
|
+
* @param convert
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
function assignDtoParams(clazz, data, convert = false) {
|
|
62
|
+
const cls = Reflect.construct(clazz, []);
|
|
63
|
+
if (convert) {
|
|
64
|
+
return convertAssignDtoParams(clazz, cls, data);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
for (const key in cls) {
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(data, key) &&
|
|
69
|
+
data[key] !== undefined) {
|
|
70
|
+
cls[key] = data[key];
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
73
|
return cls;
|
|
58
74
|
}
|
|
59
|
-
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* convert type and assign dto params
|
|
78
|
+
* @param clazz
|
|
79
|
+
* @param cls
|
|
80
|
+
* @param data
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
function convertAssignDtoParams(clazz, cls, data) {
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
|
|
85
|
+
for (const key in cls) {
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key) &&
|
|
87
|
+
data[key] !== undefined) {
|
|
88
|
+
cls[key] = convertParamsType(data[key], cls._typeDef[key]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const originMap = getOriginMetadata(PARAM_TYPE_KEY, clazz);
|
|
94
|
+
for (const [key, type] of originMap) {
|
|
95
|
+
if (key && data[key] !== undefined) {
|
|
96
|
+
cls[key] = convertParamsType(data[key], type);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return cls;
|
|
60
101
|
}
|
|
61
102
|
/**
|
|
62
103
|
* convertDtoParamsType
|
|
@@ -68,7 +109,8 @@ function plainToClass(clazz, data, convert = false) {
|
|
|
68
109
|
function convertDtoParamsType(clazz, cls) {
|
|
69
110
|
if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
|
|
70
111
|
for (const key in cls) {
|
|
71
|
-
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)
|
|
112
|
+
if (Object.prototype.hasOwnProperty.call(cls._typeDef, key) &&
|
|
113
|
+
cls[key] !== undefined) {
|
|
72
114
|
cls[key] = convertParamsType(cls[key], cls._typeDef[key]);
|
|
73
115
|
}
|
|
74
116
|
}
|
|
@@ -76,7 +118,7 @@ function convertDtoParamsType(clazz, cls) {
|
|
|
76
118
|
else {
|
|
77
119
|
const originMap = getOriginMetadata(PARAM_TYPE_KEY, clazz);
|
|
78
120
|
for (const [key, type] of originMap) {
|
|
79
|
-
if (key) {
|
|
121
|
+
if (key && cls[key] !== undefined) {
|
|
80
122
|
cls[key] = convertParamsType(cls[key], type);
|
|
81
123
|
}
|
|
82
124
|
}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koatty_validation",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"koatty_lib": "^1.x.x",
|
|
76
76
|
"koatty_logger": "^2.x.x",
|
|
77
77
|
"reflect-metadata": "^0.1.13",
|
|
78
|
-
"tslib": "^2.
|
|
78
|
+
"tslib": "^2.6.2"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"koatty_container": "^1.x.x",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koatty_validation",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"koatty_lib": "^1.x.x",
|
|
76
76
|
"koatty_logger": "^2.x.x",
|
|
77
77
|
"reflect-metadata": "^0.1.13",
|
|
78
|
-
"tslib": "^2.
|
|
78
|
+
"tslib": "^2.6.2"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"koatty_container": "^1.x.x",
|