@midwayjs/validate 3.0.0-beta.4 → 3.0.0-beta.8

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,44 @@
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.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
7
+
8
+ **Note:** Version bump only for package @midwayjs/validate
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * validate typing and config ([#1388](https://github.com/midwayjs/midway/issues/1388)) ([0883569](https://github.com/midwayjs/midway/commit/08835691942183e972359cbaa076db06b6bf85ef))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
37
+
38
+ **Note:** Version bump only for package @midwayjs/validate
39
+
40
+
41
+
42
+
43
+
6
44
  # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
45
 
8
46
 
@@ -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
@@ -1,10 +1,12 @@
1
1
  import { MidwayDecoratorService } from '@midwayjs/core';
2
+ import * as Joi from 'joi';
2
3
  import * as DefaultConfig from './config.default';
3
4
  export declare class ValidateService {
4
5
  validateConfig: typeof DefaultConfig.validate;
5
6
  validate(ClzType: new (...args: any[]) => any, value: any, options?: {
6
7
  errorStatus?: number;
7
- }): void;
8
+ validateOptions?: Joi.ValidationOptions;
9
+ }): Joi.ValidationResult<any>;
8
10
  }
9
11
  export declare class ValidateConfiguration {
10
12
  decoratorService: MidwayDecoratorService;
@@ -19,13 +19,16 @@ 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
+ }
30
+ else {
31
+ return result;
29
32
  }
30
33
  }
31
34
  }
@@ -48,9 +51,13 @@ let ValidateConfiguration = class ValidateConfiguration {
48
51
  // add aspect method
49
52
  return {
50
53
  before: (joinPoint) => {
54
+ var _a;
51
55
  for (let i = 0; i < paramTypes.length; i++) {
52
56
  const item = paramTypes[i];
53
- 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);
58
+ if (result && result.value) {
59
+ joinPoint.args[i] = result.value;
60
+ }
54
61
  }
55
62
  },
56
63
  };
@@ -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.4",
3
+ "version": "3.0.0-beta.8",
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.4",
29
- "@midwayjs/decorator": "^3.0.0-beta.4",
30
- "@midwayjs/mock": "^3.0.0-beta.4"
28
+ "@midwayjs/core": "^3.0.0-beta.8",
29
+ "@midwayjs/decorator": "^3.0.0-beta.8",
30
+ "@midwayjs/mock": "^3.0.0-beta.8"
31
31
  },
32
- "gitHead": "02e2144e302f807770b512b0d89da3145b1cbf2e"
32
+ "gitHead": "bfafbdf8798f48d4daac5dd88ad53c6b2f33c110"
33
33
  }