@jayfong/x-server 1.14.0 → 1.14.1

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
@@ -2,6 +2,13 @@
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.14.1](https://github.com/jfWorks/x-server/compare/v1.14.0...v1.14.1) (2022-04-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * requestDataSchema ([8b4f910](https://github.com/jfWorks/x-server/commit/8b4f910b1e9efbc082571b9ef407d7baf31b6319))
11
+
5
12
  ## [1.14.0](https://github.com/jfWorks/x-server/compare/v1.13.1...v1.14.0) (2022-04-26)
6
13
 
7
14
 
@@ -9,9 +9,12 @@ var _dispose = require("../services/dispose");
9
9
 
10
10
  var _http_error = require("../core/http_error");
11
11
 
12
+ var _validator = require("vtils/validator");
13
+
12
14
  class Handler {
13
15
  constructor(options) {
14
16
  this.options = options;
17
+ this.requestDataSchema = void 0;
15
18
 
16
19
  this.handle = async (data, ctx) => {
17
20
  // 前置 hook
@@ -27,11 +30,10 @@ class Handler {
27
30
  };
28
31
 
29
32
  this.handleHttp = async (data, ctx) => {
30
- // 输入验证
31
- if (this.options.requestDataSchema) {
33
+ // 请求数据验证
34
+ if (this.requestDataSchema) {
32
35
  try {
33
- data = await this.options.requestDataSchema.validate( // @ts-ignore
34
- data, {
36
+ data = await this.requestDataSchema.validate(data, {
35
37
  strict: true,
36
38
  abortEarly: true,
37
39
  stripUnknown: true
@@ -92,6 +94,10 @@ class Handler {
92
94
  dispose.dispose();
93
95
  });
94
96
  };
97
+
98
+ if (options.requestDataSchema) {
99
+ this.requestDataSchema = options.requestDataSchema(_validator.yup);
100
+ }
95
101
  }
96
102
 
97
103
  static addHook(hook) {
@@ -1,6 +1,7 @@
1
1
  import type { XHandler } from './types';
2
2
  export declare class Handler<TReqData extends any = void, TResData extends any = void, TReqMethod extends XHandler.Method = XHandler.Method> {
3
3
  readonly options: XHandler.Options<TReqData, TResData, TReqMethod>;
4
+ private requestDataSchema;
4
5
  constructor(options: XHandler.Options<TReqData, TResData, TReqMethod>);
5
6
  handle: XHandler.Handle<TReqData, TResData, TReqMethod>;
6
7
  private handleHttp;
@@ -1,9 +1,11 @@
1
1
  import { DataPacker } from 'vtils';
2
2
  import { DisposeService } from "../services/dispose";
3
3
  import { HttpError } from "../core/http_error";
4
+ import { yup } from 'vtils/validator';
4
5
  export class Handler {
5
6
  constructor(options) {
6
7
  this.options = options;
8
+ this.requestDataSchema = void 0;
7
9
 
8
10
  this.handle = async (data, ctx) => {
9
11
  // 前置 hook
@@ -19,11 +21,10 @@ export class Handler {
19
21
  };
20
22
 
21
23
  this.handleHttp = async (data, ctx) => {
22
- // 输入验证
23
- if (this.options.requestDataSchema) {
24
+ // 请求数据验证
25
+ if (this.requestDataSchema) {
24
26
  try {
25
- data = await this.options.requestDataSchema.validate( // @ts-ignore
26
- data, {
27
+ data = await this.requestDataSchema.validate(data, {
27
28
  strict: true,
28
29
  abortEarly: true,
29
30
  stripUnknown: true
@@ -84,6 +85,10 @@ export class Handler {
84
85
  dispose.dispose();
85
86
  });
86
87
  };
88
+
89
+ if (options.requestDataSchema) {
90
+ this.requestDataSchema = options.requestDataSchema(yup);
91
+ }
87
92
  }
88
93
 
89
94
  static addHook(hook) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",