koatty_validation 1.2.2 → 1.2.5

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.
@@ -0,0 +1,63 @@
1
+ /*
2
+ * @Description:
3
+ * @Usage:
4
+ * @Author: richen
5
+ * @Date: 2021-12-17 10:20:44
6
+ * @LastEditTime: 2021-12-18 11:58:46
7
+ */
8
+ import json from "@rollup/plugin-json";
9
+ import typescript from 'rollup-plugin-typescript2';
10
+ // import babel from '@rollup/plugin-babel';
11
+
12
+ export default [
13
+ {
14
+ input: './src/index.ts',
15
+ output: [{
16
+ format: 'cjs',
17
+ file: './dist/index.js',
18
+ banner: require('./scripts/copyright')
19
+ }],
20
+ plugins: [
21
+ // babel({
22
+ // babelHelpers: "runtime",
23
+ // configFile: './babel.config.js',
24
+ // exclude: 'node_modules/**',
25
+ // }),
26
+ json(),
27
+ typescript({
28
+ tsconfigOverride: {
29
+ compilerOptions: {
30
+ declaration: false,
31
+ declarationMap: false,
32
+ module: "ESNext"
33
+ }
34
+ }
35
+ })
36
+ ]
37
+ },
38
+ {
39
+ input: './src/index.ts',
40
+ output: [{
41
+ format: 'es',
42
+ file: './dist/index.mjs',
43
+ banner: require('./scripts/copyright')
44
+ }],
45
+ plugins: [
46
+ // babel({
47
+ // babelHelpers: "runtime",
48
+ // configFile: './babel.config.js',
49
+ // exclude: 'node_modules/**',
50
+ // }),
51
+ json(),
52
+ typescript({
53
+ tsconfigOverride: {
54
+ compilerOptions: {
55
+ declaration: false,
56
+ declarationMap: false,
57
+ module: "ESNext"
58
+ }
59
+ }
60
+ })
61
+ ]
62
+ }
63
+ ]
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
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.5](https://github.com/koatty/koatty_validation/compare/v1.2.4...v1.2.5) (2022-08-19)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * merge ([52c65f4](https://github.com/koatty/koatty_validation/commit/52c65f41c46a02a3fc5735e6e22ee6a3ed5337f8))
11
+
12
+ ### [1.2.4](https://github.com/koatty/koatty_validation/compare/v1.2.3...v1.2.4) (2022-05-27)
13
+
14
+ ### [1.2.3](https://github.com/koatty/koatty_validation/compare/v1.2.2...v1.2.3) (2022-03-09)
15
+
5
16
  ### [1.2.2](https://github.com/koatty/koatty_validation/compare/v1.2.0...v1.2.2) (2022-02-25)
6
17
 
7
18
  ## [1.2.0](https://github.com/koatty/koatty_validation/compare/v1.1.0...v1.2.0) (2022-02-25)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-25 10:59:08
3
+ * @Date: 2022-08-19 14:24:55
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -38,8 +38,9 @@ export declare function Contains(seed: string, validationOptions?: ValidationOpt
38
38
  *
39
39
  * @param {*} clazz
40
40
  * @param {*} cls
41
- * @param {*} data
42
- * @returns {*}
41
+ * @param {boolean} convert
42
+ * @param {boolean} data
43
+ * @returns {*} cls
43
44
  */
44
45
  export declare function convertDtoParamsType(clazz: any, cls: any, data: any): any;
45
46
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-25 10:58:54
3
+ * @Date: 2022-08-19 14:24:42
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -15,21 +15,21 @@ var koatty_container = require('koatty_container');
15
15
  var classValidator = require('class-validator');
16
16
 
17
17
  function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
29
27
  });
30
- }
31
- n["default"] = e;
32
- return Object.freeze(n);
28
+ }
29
+ });
30
+ }
31
+ n["default"] = e;
32
+ return Object.freeze(n);
33
33
  }
34
34
 
35
35
  var helper__namespace = /*#__PURE__*/_interopNamespace(helper);
@@ -73,36 +73,73 @@ function plainToClass(clazz, data, convert = false) {
73
73
  cls = data;
74
74
  }
75
75
  else {
76
- cls = Reflect.construct(clazz, []);
76
+ cls = Object.assign(Reflect.construct(clazz, []), data);
77
77
  }
78
- if (convert) {
79
- return convertDtoParamsType(clazz, cls, data);
80
- }
81
- return Object.assign(cls, data);
78
+ return convertOrCheckDtoParamsType(clazz, cls, convert);
82
79
  }
83
80
  return data;
84
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("invalid arguments type");
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("invalid arguments type");
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ return cls;
121
+ }
85
122
  /**
86
123
  * convertDtoParamsType
87
124
  *
88
125
  * @param {*} clazz
89
126
  * @param {*} cls
90
- * @param {*} data
91
- * @returns {*}
127
+ * @param {boolean} convert
128
+ * @param {boolean} data
129
+ * @returns {*} cls
92
130
  */
93
131
  function convertDtoParamsType(clazz, cls, data) {
94
132
  if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
95
133
  for (const key in cls) {
96
- if (Object.prototype.hasOwnProperty.call(data, key)
97
- && Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
98
- data[key] = convertParamsType(data[key], cls._typeDef[key]);
134
+ if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
135
+ cls[key] = convertParamsType(data[key], cls._typeDef[key]);
99
136
  }
100
137
  }
101
138
  }
102
139
  else {
103
140
  const originMap = koatty_container.getOriginMetadata(PARAM_TYPE_KEY, clazz);
104
141
  for (const [key, type] of originMap) {
105
- if (key && Object.prototype.hasOwnProperty.call(data, key)) {
142
+ if (key) {
106
143
  cls[key] = convertParamsType(data[key], type);
107
144
  }
108
145
  }
@@ -314,7 +351,7 @@ function plateNumber(value) {
314
351
  * @Usage:
315
352
  * @Author: richen
316
353
  * @Date: 2021-11-25 10:47:04
317
- * @LastEditTime: 2022-02-25 10:33:20
354
+ * @LastEditTime: 2022-08-19 14:21:20
318
355
  */
319
356
  // constant
320
357
  const PARAM_TYPE_KEY = 'PARAM_TYPE_KEY';
@@ -629,7 +666,7 @@ Object.keys(ValidFuncs).forEach((key) => {
629
666
  if (helper__namespace.isString(options)) {
630
667
  options = { message: options, value: null };
631
668
  }
632
- if (!ValidFuncs[key](value, options)) {
669
+ if (!ValidFuncs[key](value, options.value)) {
633
670
  throw new Error(options.message || `ValidatorError: invalid arguments.`);
634
671
  }
635
672
  };
@@ -640,7 +677,7 @@ Object.keys(ValidFuncs).forEach((key) => {
640
677
  * @Usage:
641
678
  * @Author: richen
642
679
  * @Date: 2021-11-25 10:46:57
643
- * @LastEditTime: 2022-02-24 15:33:34
680
+ * @LastEditTime: 2022-08-19 14:21:12
644
681
  */
645
682
  /**
646
683
  * Validation parameter's type and values.
@@ -660,9 +697,10 @@ function Valid(rule, options) {
660
697
  rules = rule;
661
698
  }
662
699
  return (target, propertyKey, descriptor) => {
700
+ var _a;
663
701
  // 获取成员参数类型
664
702
  const paramTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
665
- const type = (paramTypes[descriptor] && paramTypes[descriptor].name) ? paramTypes[descriptor].name : "object";
703
+ const type = ((_a = paramTypes[descriptor]) === null || _a === void 0 ? void 0 : _a.name) ? paramTypes[descriptor].name : 'object';
666
704
  if (helper__namespace.isString(options)) {
667
705
  options = { message: options, value: null };
668
706
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-02-25 10:58:54
3
+ * @Date: 2022-08-19 14:24:42
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -49,36 +49,73 @@ function plainToClass(clazz, data, convert = false) {
49
49
  cls = data;
50
50
  }
51
51
  else {
52
- cls = Reflect.construct(clazz, []);
52
+ cls = Object.assign(Reflect.construct(clazz, []), data);
53
53
  }
54
- if (convert) {
55
- return convertDtoParamsType(clazz, cls, data);
56
- }
57
- return Object.assign(cls, data);
54
+ return convertOrCheckDtoParamsType(clazz, cls, convert);
58
55
  }
59
56
  return data;
60
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("invalid arguments type");
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("invalid arguments type");
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ return cls;
97
+ }
61
98
  /**
62
99
  * convertDtoParamsType
63
100
  *
64
101
  * @param {*} clazz
65
102
  * @param {*} cls
66
- * @param {*} data
67
- * @returns {*}
103
+ * @param {boolean} convert
104
+ * @param {boolean} data
105
+ * @returns {*} cls
68
106
  */
69
107
  function convertDtoParamsType(clazz, cls, data) {
70
108
  if (Object.prototype.hasOwnProperty.call(cls, "_typeDef")) {
71
109
  for (const key in cls) {
72
- if (Object.prototype.hasOwnProperty.call(data, key)
73
- && Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
74
- data[key] = convertParamsType(data[key], cls._typeDef[key]);
110
+ if (Object.prototype.hasOwnProperty.call(cls._typeDef, key)) {
111
+ cls[key] = convertParamsType(data[key], cls._typeDef[key]);
75
112
  }
76
113
  }
77
114
  }
78
115
  else {
79
116
  const originMap = getOriginMetadata(PARAM_TYPE_KEY, clazz);
80
117
  for (const [key, type] of originMap) {
81
- if (key && Object.prototype.hasOwnProperty.call(data, key)) {
118
+ if (key) {
82
119
  cls[key] = convertParamsType(data[key], type);
83
120
  }
84
121
  }
@@ -290,7 +327,7 @@ function plateNumber(value) {
290
327
  * @Usage:
291
328
  * @Author: richen
292
329
  * @Date: 2021-11-25 10:47:04
293
- * @LastEditTime: 2022-02-25 10:33:20
330
+ * @LastEditTime: 2022-08-19 14:21:20
294
331
  */
295
332
  // constant
296
333
  const PARAM_TYPE_KEY = 'PARAM_TYPE_KEY';
@@ -605,7 +642,7 @@ Object.keys(ValidFuncs).forEach((key) => {
605
642
  if (helper.isString(options)) {
606
643
  options = { message: options, value: null };
607
644
  }
608
- if (!ValidFuncs[key](value, options)) {
645
+ if (!ValidFuncs[key](value, options.value)) {
609
646
  throw new Error(options.message || `ValidatorError: invalid arguments.`);
610
647
  }
611
648
  };
@@ -616,7 +653,7 @@ Object.keys(ValidFuncs).forEach((key) => {
616
653
  * @Usage:
617
654
  * @Author: richen
618
655
  * @Date: 2021-11-25 10:46:57
619
- * @LastEditTime: 2022-02-24 15:33:34
656
+ * @LastEditTime: 2022-08-19 14:21:12
620
657
  */
621
658
  /**
622
659
  * Validation parameter's type and values.
@@ -636,9 +673,10 @@ function Valid(rule, options) {
636
673
  rules = rule;
637
674
  }
638
675
  return (target, propertyKey, descriptor) => {
676
+ var _a;
639
677
  // 获取成员参数类型
640
678
  const paramTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
641
- const type = (paramTypes[descriptor] && paramTypes[descriptor].name) ? paramTypes[descriptor].name : "object";
679
+ const type = ((_a = paramTypes[descriptor]) === null || _a === void 0 ? void 0 : _a.name) ? paramTypes[descriptor].name : 'object';
642
680
  if (helper.isString(options)) {
643
681
  options = { message: options, value: null };
644
682
  }
package/dist/package.json CHANGED
@@ -1,24 +1,18 @@
1
1
  {
2
2
  "name": "koatty_validation",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
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",
7
7
  "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
- "build:js": "del-cli --force dist && npx rollup -c",
8
+ "build:js": "del-cli --force dist && npx rollup -c .rollup.config.js",
9
9
  "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
10
  "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
11
  "eslint": "eslint --ext .ts,.js ./",
12
12
  "prepublishOnly": "npm test && npm run build",
13
13
  "prerelease": "npm test && npm run build",
14
14
  "release": "standard-version",
15
- "release:pre": "npm run release -- --prerelease",
16
- "release:major": "npm run release -- --release-as major",
17
- "release:minor": "npm run release -- --release-as minor",
18
- "pub": "git push --follow-tags origin && npm publish",
19
- "test": "npm run eslint && jest --passWithNoTests",
20
- "test:cov": "jest --collectCoverage --detectOpenHandles",
21
- "version": "conventional-changelog -p angular -i CHANGELOG.md -s"
15
+ "test": "npm run eslint && jest --passWithNoTests"
22
16
  },
23
17
  "main": "./dist/index.js",
24
18
  "exports": {
@@ -48,29 +42,29 @@
48
42
  }
49
43
  ],
50
44
  "devDependencies": {
45
+ "@commitlint/cli": "^17.x.x",
46
+ "@commitlint/config-conventional": "^17.x.x",
51
47
  "@microsoft/api-documenter": "^7.x.x",
52
48
  "@microsoft/api-extractor": "^7.x.x",
53
49
  "@rollup/plugin-json": "^4.x.x",
54
50
  "@types/jest": "^27.x.x",
55
51
  "@types/koa": "^2.x.x",
56
52
  "@types/node": "^16.x.x",
57
- "@types/validator": "^13.x.x",
53
+ "@types/validator": "^13.7.2",
58
54
  "@typescript-eslint/eslint-plugin": "^5.x.x",
59
55
  "@typescript-eslint/parser": "^5.x.x",
60
- "commitlint": "^15.x.x",
61
- "commitlint-config-gitmoji": "^2.x.x",
62
56
  "conventional-changelog-cli": "^2.x.x",
63
57
  "copyfiles": "^2.x.x",
64
58
  "del-cli": "^4.x.x",
65
59
  "eslint": "^8.x.x",
66
- "eslint-plugin-jest": "^25.x.x",
67
- "husky": "^7.x.x",
68
- "jest": "^27.x.x",
69
- "jest-html-reporters": "^2.x.x",
60
+ "eslint-plugin-jest": "^26.x.x",
61
+ "husky": "^4.x.x",
62
+ "jest": "^28.x.x",
63
+ "jest-html-reporters": "^3.x.x",
70
64
  "rollup": "^2.x.x",
71
65
  "rollup-plugin-typescript2": "^0.x.x",
72
66
  "standard-version": "^9.x.x",
73
- "ts-jest": "^27.x.x",
67
+ "ts-jest": "^28.x.x",
74
68
  "ts-node": "^10.x.x",
75
69
  "typescript": "^4.x.x"
76
70
  },
@@ -80,7 +74,7 @@
80
74
  "koatty_lib": "^1.x.x",
81
75
  "koatty_logger": "^1.x.x",
82
76
  "reflect-metadata": "^0.1.13",
83
- "tslib": "^2.3.1"
77
+ "tslib": "^2.4.0"
84
78
  },
85
79
  "peerDependencies": {
86
80
  "koatty_container": "^1.x.x",
package/package.json CHANGED
@@ -1,24 +1,18 @@
1
1
  {
2
2
  "name": "koatty_validation",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
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",
7
7
  "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
- "build:js": "del-cli --force dist && npx rollup -c",
8
+ "build:js": "del-cli --force dist && npx rollup -c .rollup.config.js",
9
9
  "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
10
  "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
11
  "eslint": "eslint --ext .ts,.js ./",
12
12
  "prepublishOnly": "npm test && npm run build",
13
13
  "prerelease": "npm test && npm run build",
14
14
  "release": "standard-version",
15
- "release:pre": "npm run release -- --prerelease",
16
- "release:major": "npm run release -- --release-as major",
17
- "release:minor": "npm run release -- --release-as minor",
18
- "pub": "git push --follow-tags origin && npm publish",
19
- "test": "npm run eslint && jest --passWithNoTests",
20
- "test:cov": "jest --collectCoverage --detectOpenHandles",
21
- "version": "conventional-changelog -p angular -i CHANGELOG.md -s"
15
+ "test": "npm run eslint && jest --passWithNoTests"
22
16
  },
23
17
  "main": "./dist/index.js",
24
18
  "exports": {
@@ -48,29 +42,29 @@
48
42
  }
49
43
  ],
50
44
  "devDependencies": {
45
+ "@commitlint/cli": "^17.x.x",
46
+ "@commitlint/config-conventional": "^17.x.x",
51
47
  "@microsoft/api-documenter": "^7.x.x",
52
48
  "@microsoft/api-extractor": "^7.x.x",
53
49
  "@rollup/plugin-json": "^4.x.x",
54
50
  "@types/jest": "^27.x.x",
55
51
  "@types/koa": "^2.x.x",
56
52
  "@types/node": "^16.x.x",
57
- "@types/validator": "^13.x.x",
53
+ "@types/validator": "^13.7.2",
58
54
  "@typescript-eslint/eslint-plugin": "^5.x.x",
59
55
  "@typescript-eslint/parser": "^5.x.x",
60
- "commitlint": "^15.x.x",
61
- "commitlint-config-gitmoji": "^2.x.x",
62
56
  "conventional-changelog-cli": "^2.x.x",
63
57
  "copyfiles": "^2.x.x",
64
58
  "del-cli": "^4.x.x",
65
59
  "eslint": "^8.x.x",
66
- "eslint-plugin-jest": "^25.x.x",
67
- "husky": "^7.x.x",
68
- "jest": "^27.x.x",
69
- "jest-html-reporters": "^2.x.x",
60
+ "eslint-plugin-jest": "^26.x.x",
61
+ "husky": "^4.x.x",
62
+ "jest": "^28.x.x",
63
+ "jest-html-reporters": "^3.x.x",
70
64
  "rollup": "^2.x.x",
71
65
  "rollup-plugin-typescript2": "^0.x.x",
72
66
  "standard-version": "^9.x.x",
73
- "ts-jest": "^27.x.x",
67
+ "ts-jest": "^28.x.x",
74
68
  "ts-node": "^10.x.x",
75
69
  "typescript": "^4.x.x"
76
70
  },
@@ -80,7 +74,7 @@
80
74
  "koatty_lib": "^1.x.x",
81
75
  "koatty_logger": "^1.x.x",
82
76
  "reflect-metadata": "^0.1.13",
83
- "tslib": "^2.3.1"
77
+ "tslib": "^2.4.0"
84
78
  },
85
79
  "peerDependencies": {
86
80
  "koatty_container": "^1.x.x",