@mingjue8888/express-plus 1.2.6 → 1.2.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/package.json +2 -2
- package/valid-body.ts +3 -8
- package/valid-param.ts +3 -8
- package/valid-query.ts +3 -8
- package/valid-send.ts +4 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mingjue8888/express-plus",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"repository": "github:mingjue8888/express-plus",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"router"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mingjue8888/base-dependencies": "^1.
|
|
15
|
+
"@mingjue8888/base-dependencies": "^1.6.0",
|
|
16
16
|
"@types/compression": "^1.8.1",
|
|
17
17
|
"@types/cors": "^2.8.19",
|
|
18
18
|
"@types/express": "^5.0.6",
|
package/valid-body.ts
CHANGED
|
@@ -4,13 +4,8 @@ import WrongParamsResponseError from "./wrong-params-response-error";
|
|
|
4
4
|
|
|
5
5
|
export default function validBody(sch: Record<string, Joi.AnySchema>) {
|
|
6
6
|
return asyncMiddleware(async function (req, _res) {
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
if (error) {
|
|
12
|
-
throw new WrongParamsResponseError("WrongParamsError", error.message);
|
|
13
|
-
}
|
|
14
|
-
req.valid.body = value;
|
|
7
|
+
req.valid.body = await Joi.object(sch)
|
|
8
|
+
.validateAsync(req.body, { allowUnknown: true })
|
|
9
|
+
.catch(err => new WrongParamsResponseError("WrongParamsError", err.message));
|
|
15
10
|
});
|
|
16
11
|
}
|
package/valid-param.ts
CHANGED
|
@@ -4,13 +4,8 @@ import WrongParamsResponseError from "./wrong-params-response-error";
|
|
|
4
4
|
|
|
5
5
|
export default function validParam(sch: Record<string, Joi.AnySchema>) {
|
|
6
6
|
return asyncMiddleware(async function (req, _res) {
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
if (error) {
|
|
12
|
-
throw new WrongParamsResponseError("WrongParamsError", error.message);
|
|
13
|
-
}
|
|
14
|
-
req.valid.param = value;
|
|
7
|
+
req.valid.param = await Joi.object(sch)
|
|
8
|
+
.validateAsync(req.params, { allowUnknown: true })
|
|
9
|
+
.catch(err => new WrongParamsResponseError("WrongParamsError", err.message));
|
|
15
10
|
});
|
|
16
11
|
}
|
package/valid-query.ts
CHANGED
|
@@ -4,13 +4,8 @@ import WrongParamsResponseError from "./wrong-params-response-error";
|
|
|
4
4
|
|
|
5
5
|
export default function validQuery(sch: Record<string, Joi.AnySchema>) {
|
|
6
6
|
return asyncMiddleware(async function (req, _res) {
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
if (error) {
|
|
12
|
-
throw new WrongParamsResponseError("WrongParamsError", error.message);
|
|
13
|
-
}
|
|
14
|
-
req.valid.query = value;
|
|
7
|
+
req.valid.query = await Joi.object(sch)
|
|
8
|
+
.validateAsync(req.query, { allowUnknown: true })
|
|
9
|
+
.catch(err => new WrongParamsResponseError("WrongParamsError", err.message));
|
|
15
10
|
});
|
|
16
11
|
}
|
package/valid-send.ts
CHANGED
|
@@ -4,14 +4,11 @@ import ServerErrorResponseError from "./server-error-response-error";
|
|
|
4
4
|
|
|
5
5
|
export default function validSend(sch: Record<string, Joi.AnySchema>) {
|
|
6
6
|
return asyncMiddleware(async function (_req, res) {
|
|
7
|
-
const
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
if (error)
|
|
12
|
-
throw new ServerErrorResponseError("WrongResponseError", error.message);
|
|
7
|
+
const data = await Joi.object(sch)
|
|
8
|
+
.validateAsync(res.body)
|
|
9
|
+
.catch(err => new ServerErrorResponseError("WrongResponseError", err.message));
|
|
13
10
|
|
|
14
11
|
res.status(200)
|
|
15
|
-
.send(
|
|
12
|
+
.send(data);
|
|
16
13
|
});
|
|
17
14
|
}
|