@midwayjs/validate 3.0.0-beta.11 → 3.0.0-beta.12

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
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
12
+ * support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
13
+
14
+
15
+
16
+
17
+
6
18
  # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
7
19
 
8
20
  **Note:** Version bump only for package @midwayjs/validate
@@ -0,0 +1,11 @@
1
+ import { MidwayError, MidwayHttpError } from '@midwayjs/core';
2
+ export declare class MidwayValidationError extends MidwayHttpError {
3
+ constructor(message: any, status: any, cause: any);
4
+ }
5
+ export declare class ValidationPropertyMissingError extends MidwayError {
6
+ constructor(key: any);
7
+ }
8
+ export declare class ValidationNotMethodPropertyError extends MidwayError {
9
+ constructor(key: any);
10
+ }
11
+ //# sourceMappingURL=error.d.ts.map
package/dist/error.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationNotMethodPropertyError = exports.ValidationPropertyMissingError = exports.MidwayValidationError = void 0;
4
+ const core_1 = require("@midwayjs/core");
5
+ const ValidateErrorCode = (0, core_1.registerErrorCode)('validate', {
6
+ VALIDATE_FAIL: 10000,
7
+ PROPERTY_MISSING: 10001,
8
+ NOT_METHOD_PROPERTY: 10002,
9
+ });
10
+ class MidwayValidationError extends core_1.MidwayHttpError {
11
+ constructor(message, status, cause) {
12
+ super(message, status, ValidateErrorCode.VALIDATE_FAIL, {
13
+ cause,
14
+ });
15
+ }
16
+ }
17
+ exports.MidwayValidationError = MidwayValidationError;
18
+ class ValidationPropertyMissingError extends core_1.MidwayError {
19
+ constructor(key) {
20
+ super(`Cannot find property of "${key}"`, ValidateErrorCode.PROPERTY_MISSING);
21
+ }
22
+ }
23
+ exports.ValidationPropertyMissingError = ValidationPropertyMissingError;
24
+ class ValidationNotMethodPropertyError extends core_1.MidwayError {
25
+ constructor(key) {
26
+ super(`"${key}" is not a method property!`, ValidateErrorCode.NOT_METHOD_PROPERTY);
27
+ }
28
+ }
29
+ exports.ValidationNotMethodPropertyError = ValidationNotMethodPropertyError;
30
+ //# sourceMappingURL=error.js.map
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from './decorator/rule';
3
3
  export * from './decorator/validate';
4
4
  export * from './dtoHelper';
5
5
  export * from './service';
6
+ export * from './error';
6
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -17,4 +17,5 @@ __exportStar(require("./decorator/rule"), exports);
17
17
  __exportStar(require("./decorator/validate"), exports);
18
18
  __exportStar(require("./dtoHelper"), exports);
19
19
  __exportStar(require("./service"), exports);
20
+ __exportStar(require("./error"), exports);
20
21
  //# sourceMappingURL=index.js.map
package/dist/service.js CHANGED
@@ -13,9 +13,9 @@ exports.ValidateService = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
14
  const DefaultConfig = require("./config/config.default");
15
15
  const constants_1 = require("./constants");
16
- const core_1 = require("@midwayjs/core");
17
16
  const Joi = require("joi");
18
17
  const i18n_1 = require("@midwayjs/i18n");
18
+ const error_1 = require("./error");
19
19
  let ValidateService = class ValidateService {
20
20
  constructor() {
21
21
  this.messages = {};
@@ -40,7 +40,7 @@ let ValidateService = class ValidateService {
40
40
  messages: this.messages,
41
41
  }, (_a = options.validationOptions) !== null && _a !== void 0 ? _a : {}));
42
42
  if (result.error) {
43
- throw new core_1.MidwayValidationError(result.error.message, (_b = options === null || options === void 0 ? void 0 : options.errorStatus) !== null && _b !== void 0 ? _b : this.validateConfig.errorStatus, result.error);
43
+ throw new error_1.MidwayValidationError(result.error.message, (_b = options === null || options === void 0 ? void 0 : options.errorStatus) !== null && _b !== void 0 ? _b : this.validateConfig.errorStatus, result.error);
44
44
  }
45
45
  else {
46
46
  return result;
package/dist/util.js CHANGED
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.merge = exports.set = exports.reach = exports.overrideMethodProperty = void 0;
4
+ const error_1 = require("./error");
4
5
  function overrideMethodProperty(object, key, method) {
5
6
  const descriptor = Object.getOwnPropertyDescriptor(object, key);
6
7
  if (!descriptor) {
7
- throw new Error(`Cannot find property of "${key}"`);
8
+ throw new error_1.ValidationPropertyMissingError(key);
8
9
  }
9
10
  const superMethod = descriptor.value;
10
11
  if (typeof superMethod !== 'function') {
11
- throw new Error(`"${key}" is not a method property!`);
12
+ throw new error_1.ValidationNotMethodPropertyError(key);
12
13
  }
13
14
  Object.defineProperty(object, key, {
14
15
  ...descriptor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/validate",
3
- "version": "3.0.0-beta.11",
3
+ "version": "3.0.0-beta.12",
4
4
  "description": "Midway Component for mongoose",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -23,15 +23,15 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@midwayjs/i18n": "^3.0.0-beta.11",
26
+ "@midwayjs/i18n": "^3.0.0-beta.12",
27
27
  "joi": "^17.2.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@midwayjs/core": "^3.0.0-beta.11",
31
- "@midwayjs/decorator": "^3.0.0-beta.11",
32
- "@midwayjs/express": "^3.0.0-beta.11",
33
- "@midwayjs/koa": "^3.0.0-beta.11",
34
- "@midwayjs/mock": "^3.0.0-beta.11"
30
+ "@midwayjs/core": "^3.0.0-beta.12",
31
+ "@midwayjs/decorator": "^3.0.0-beta.12",
32
+ "@midwayjs/express": "^3.0.0-beta.12",
33
+ "@midwayjs/koa": "^3.0.0-beta.12",
34
+ "@midwayjs/mock": "^3.0.0-beta.12"
35
35
  },
36
- "gitHead": "a2b066fd500e815e799e7f421cd216f12e0e9f8e"
36
+ "gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
37
37
  }