@midwayjs/validate 3.0.0-beta.6 → 3.0.0-beta.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
@@ -3,6 +3,17 @@
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.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * validate typing and config ([#1388](https://github.com/midwayjs/midway/issues/1388)) ([0883569](https://github.com/midwayjs/midway/commit/08835691942183e972359cbaa076db06b6bf85ef))
12
+
13
+
14
+
15
+
16
+
6
17
  # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
7
18
 
8
19
 
@@ -1,5 +1,5 @@
1
1
  export declare const validate: {
2
- allowUnknown: boolean;
2
+ validationOptions: {};
3
3
  errorStatus: number;
4
4
  };
5
5
  //# sourceMappingURL=config.default.d.ts.map
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validate = void 0;
4
4
  exports.validate = {
5
- allowUnknown: false,
5
+ validationOptions: {},
6
6
  errorStatus: 422,
7
7
  };
8
8
  //# sourceMappingURL=config.default.js.map
@@ -19,13 +19,13 @@ const DefaultConfig = require("./config.default");
19
19
  const debug = util.debuglog('midway:debug');
20
20
  let ValidateService = class ValidateService {
21
21
  validate(ClzType, value, options) {
22
- var _a;
22
+ var _a, _b;
23
23
  const rules = (0, decorator_1.getClassExtendedMetadata)(constants_1.RULES_KEY, ClzType);
24
24
  if (rules) {
25
25
  const schema = Joi.object(rules);
26
- const result = schema.validate(value);
26
+ const result = schema.validate(value, Object.assign(this.validateConfig.validationOptions, (_a = options.validateOptions) !== null && _a !== void 0 ? _a : {}));
27
27
  if (result.error) {
28
- throw new core_1.MidwayValidationError(result.error.message, (_a = options === null || options === void 0 ? void 0 : options.errorStatus) !== null && _a !== void 0 ? _a : this.validateConfig.errorStatus, result.error);
28
+ 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);
29
29
  }
30
30
  else {
31
31
  return result;
@@ -51,9 +51,10 @@ let ValidateConfiguration = class ValidateConfiguration {
51
51
  // add aspect method
52
52
  return {
53
53
  before: (joinPoint) => {
54
+ var _a;
54
55
  for (let i = 0; i < paramTypes.length; i++) {
55
56
  const item = paramTypes[i];
56
- const result = this.validateService.validate(item, joinPoint.args[i], options.metadata);
57
+ const result = this.validateService.validate(item, joinPoint.args[i], (_a = options.metadata) === null || _a === void 0 ? void 0 : _a.options);
57
58
  if (result && result.value) {
58
59
  joinPoint.args[i] = result.value;
59
60
  }
@@ -1,5 +1,7 @@
1
+ import * as Joi from 'joi';
1
2
  export interface ValidateOptions {
2
3
  errorStatus?: number;
4
+ validateOptions?: Joi.ValidationOptions;
3
5
  }
4
6
  export declare function Validate(options?: ValidateOptions): MethodDecorator;
5
7
  //# sourceMappingURL=validate.d.ts.map
package/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  export * from './dist/index';
2
-
3
- import { validate } from './dist/config.default';
2
+ import * as Joi from 'joi';
4
3
 
5
4
  declare module '@midwayjs/core/dist/interface' {
6
5
  interface MidwayConfig {
7
- validate?: validate;
6
+ validate?: {
7
+ validationOptions?: Joi.ValidationOptions;
8
+ errorStatus?: number;
9
+ };
8
10
  }
9
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/validate",
3
- "version": "3.0.0-beta.6",
3
+ "version": "3.0.0-beta.7",
4
4
  "description": "Midway Component for mongoose",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -25,9 +25,9 @@
25
25
  "joi": "^17.2.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@midwayjs/core": "^3.0.0-beta.6",
29
- "@midwayjs/decorator": "^3.0.0-beta.6",
30
- "@midwayjs/mock": "^3.0.0-beta.6"
28
+ "@midwayjs/core": "^3.0.0-beta.7",
29
+ "@midwayjs/decorator": "^3.0.0-beta.7",
30
+ "@midwayjs/mock": "^3.0.0-beta.7"
31
31
  },
32
- "gitHead": "e4595d30b369e36bef21b36f2b3737d8bc2f802d"
32
+ "gitHead": "24590729121d9110e2d960db5b5e587cf55a1efc"
33
33
  }