@jayfong/x-server 2.18.0 → 2.19.0
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/lib/_cjs/core/handler.js +5 -2
- package/lib/core/handler.d.ts +2 -1
- package/lib/core/handler.js +5 -2
- package/lib/core/types.d.ts +1 -1
- package/package.json +2 -2
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -34,11 +34,14 @@ class Handler {
|
|
|
34
34
|
// 请求数据验证
|
|
35
35
|
// vae
|
|
36
36
|
if (this.requestDataSchemaVae) {
|
|
37
|
-
const res = this.requestDataSchemaVae.parse(
|
|
37
|
+
const res = this.requestDataSchemaVae.parse(
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
data, {
|
|
38
40
|
abortEarly: true,
|
|
39
41
|
preserveUnknownKeys: false
|
|
40
42
|
});
|
|
41
43
|
if (res.success) {
|
|
44
|
+
// @ts-ignore
|
|
42
45
|
data = res.data;
|
|
43
46
|
} else {
|
|
44
47
|
throw new _http_error.HttpError.BadRequest(
|
|
@@ -133,7 +136,7 @@ class Handler {
|
|
|
133
136
|
});
|
|
134
137
|
};
|
|
135
138
|
if (options.requestDataSchemaVae) {
|
|
136
|
-
this.requestDataSchemaVae = options.requestDataSchemaVae(vae.v);
|
|
139
|
+
this.requestDataSchemaVae = typeof options.requestDataSchemaVae === 'function' ? options.requestDataSchemaVae(vae.v) : options.requestDataSchemaVae;
|
|
137
140
|
} else if (options.requestDataSchema) {
|
|
138
141
|
this.requestDataSchema = options.requestDataSchema(_validator.yup);
|
|
139
142
|
}
|
package/lib/core/handler.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import * as vae from 'vtils/vae';
|
|
1
2
|
import type { XHandler } from './types';
|
|
2
3
|
export type { HandlerMethodMap, HandlerPath, HandlerPayloadMap, HandlerResultMap } from '.x/routes';
|
|
3
4
|
export declare class Handler<TReqData extends any = void, TResData extends any = void, TReqMethod extends XHandler.Method = XHandler.Method> {
|
|
4
5
|
readonly options: XHandler.Options<TReqData, TResData, TReqMethod>;
|
|
5
6
|
private requestDataSchema;
|
|
6
|
-
|
|
7
|
+
readonly requestDataSchemaVae: vae.VaeSchemaOf<TReqData> | undefined;
|
|
7
8
|
constructor(options: XHandler.Options<TReqData, TResData, TReqMethod>);
|
|
8
9
|
handle: XHandler.Handle<TReqData, TResData, TReqMethod>;
|
|
9
10
|
private handleHttp;
|
package/lib/core/handler.js
CHANGED
|
@@ -29,11 +29,14 @@ export class Handler {
|
|
|
29
29
|
// 请求数据验证
|
|
30
30
|
// vae
|
|
31
31
|
if (this.requestDataSchemaVae) {
|
|
32
|
-
const res = this.requestDataSchemaVae.parse(
|
|
32
|
+
const res = this.requestDataSchemaVae.parse(
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
data, {
|
|
33
35
|
abortEarly: true,
|
|
34
36
|
preserveUnknownKeys: false
|
|
35
37
|
});
|
|
36
38
|
if (res.success) {
|
|
39
|
+
// @ts-ignore
|
|
37
40
|
data = res.data;
|
|
38
41
|
} else {
|
|
39
42
|
throw new HttpError.BadRequest(
|
|
@@ -128,7 +131,7 @@ export class Handler {
|
|
|
128
131
|
});
|
|
129
132
|
};
|
|
130
133
|
if (options.requestDataSchemaVae) {
|
|
131
|
-
this.requestDataSchemaVae = options.requestDataSchemaVae(vae.v);
|
|
134
|
+
this.requestDataSchemaVae = typeof options.requestDataSchemaVae === 'function' ? options.requestDataSchemaVae(vae.v) : options.requestDataSchemaVae;
|
|
132
135
|
} else if (options.requestDataSchema) {
|
|
133
136
|
this.requestDataSchema = options.requestDataSchema(yup);
|
|
134
137
|
}
|
package/lib/core/types.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ export declare namespace XHandler {
|
|
|
135
135
|
/**
|
|
136
136
|
* 请求数据验证结构(vae)
|
|
137
137
|
*/
|
|
138
|
-
requestDataSchemaVae?: (_: typeof vae.v) => vae.VaeSchemaOf<TReqData
|
|
138
|
+
requestDataSchemaVae?: vae.VaeSchemaOf<TReqData> | ((_: typeof vae.v) => vae.VaeSchemaOf<TReqData>);
|
|
139
139
|
/**
|
|
140
140
|
* 处理器
|
|
141
141
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tsx": "^3.12.7",
|
|
68
68
|
"utf-8-validate": "^5.0.9",
|
|
69
69
|
"vscode-generate-index-standalone": "^1.7.1",
|
|
70
|
-
"vtils": "^4.
|
|
70
|
+
"vtils": "^4.90.0",
|
|
71
71
|
"yaml": "^2.3.1",
|
|
72
72
|
"yargs": "^17.4.1"
|
|
73
73
|
},
|