@yamato-daiwa/express-extensions 0.2.0 → 0.3.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/Distributable/RequestBody/parseAndValidateJSON_RequestBody.d.ts +2 -1
- package/Distributable/RequestBody/parseAndValidateJSON_RequestBody.js +9 -3
- package/Distributable/RequestBody/validateAndProcessJSON_RequestBody.d.ts +4 -3
- package/Distributable/RequestBody/validateAndProcessJSON_RequestBody.js +11 -17
- package/Distributable/Route.d.ts +1 -1
- package/Distributable/Route.js +1 -1
- package/Distributable/index.d.ts +1 -0
- package/Distributable/index.js +3 -1
- package/README.md +3 -1
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RawObjectDataProcessor, type ReadonlyParsedJSON } from "@yamato-daiwa/es-extensions";
|
|
2
|
-
export declare function parseAndValidateJSON_RequestBody<RequestData extends ReadonlyParsedJSON>(
|
|
2
|
+
export declare function parseAndValidateJSON_RequestBody<RequestData extends ReadonlyParsedJSON>({ requestBodySizeLimit__bytesPackageFormat, validationAndProcessing, mustLogDataAfterParsing }: Readonly<{
|
|
3
3
|
requestBodySizeLimit__bytesPackageFormat: string | number;
|
|
4
4
|
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification;
|
|
5
|
+
mustLogDataAfterParsing?: boolean;
|
|
5
6
|
}>): (request: unknown, response: unknown, toNextMiddleware: (error?: unknown) => void) => void;
|
|
@@ -6,16 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseAndValidateJSON_RequestBody = parseAndValidateJSON_RequestBody;
|
|
7
7
|
const body_parser_1 = __importDefault(require("body-parser"));
|
|
8
8
|
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
9
|
-
function parseAndValidateJSON_RequestBody(
|
|
9
|
+
function parseAndValidateJSON_RequestBody({ requestBodySizeLimit__bytesPackageFormat, validationAndProcessing, mustLogDataAfterParsing = false }) {
|
|
10
10
|
return (_request, _response, toNextMiddleware) => {
|
|
11
11
|
const request = _request;
|
|
12
12
|
const response = _response;
|
|
13
|
-
body_parser_1.default.json({ limit:
|
|
13
|
+
body_parser_1.default.json({ limit: requestBodySizeLimit__bytesPackageFormat })(request, response, (error) => {
|
|
14
14
|
if ((0, es_extensions_1.isNeitherUndefinedNorNull)(error)) {
|
|
15
15
|
toNextMiddleware(error);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
es_extensions_1.Logger.logInfo({
|
|
19
|
+
title: `${request.method.toUpperCase()}::${request.url}`,
|
|
20
|
+
description: "Parsed request body:",
|
|
21
|
+
additionalData: request.body,
|
|
22
|
+
mustOutputIf: mustLogDataAfterParsing
|
|
23
|
+
});
|
|
24
|
+
const requestBodyValidationAndProcessingResult = es_extensions_1.RawObjectDataProcessor.process(request.body, validationAndProcessing);
|
|
19
25
|
if (requestBodyValidationAndProcessingResult.rawDataIsInvalid) {
|
|
20
26
|
response.
|
|
21
27
|
status(es_extensions_1.HTTP_StatusCodes.badRequest).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { RawObjectDataProcessor } from "@yamato-daiwa/es-extensions";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { RawObjectDataProcessor, type ReadonlyParsedJSON } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
export declare function validateAndProcessJSON_RequestBody<RequestData extends ReadonlyParsedJSON>(validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification, { mustLogDataAfterParsing }?: Readonly<{
|
|
3
|
+
mustLogDataAfterParsing?: boolean;
|
|
4
|
+
}>): (request: unknown, response: unknown, toNextMiddleware: () => void) => void;
|
|
@@ -2,24 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAndProcessJSON_RequestBody = validateAndProcessJSON_RequestBody;
|
|
4
4
|
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
5
|
-
function validateAndProcessJSON_RequestBody(
|
|
6
|
-
return (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
messageSpecificPart: `The "request" is not object and has type "${typeof request}"`
|
|
16
|
-
}),
|
|
17
|
-
occurrenceLocation: "validateAndProcessRequestBody -> innerFunction(request, response, toNextMiddleware)"
|
|
18
|
-
});
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
5
|
+
function validateAndProcessJSON_RequestBody(validationAndProcessing, { mustLogDataAfterParsing = false } = { mustLogDataAfterParsing: false }) {
|
|
6
|
+
return (_request, _response, toNextMiddleware) => {
|
|
7
|
+
const request = _request;
|
|
8
|
+
const response = _response;
|
|
9
|
+
es_extensions_1.Logger.logInfo({
|
|
10
|
+
title: `${request.method.toUpperCase()}::${request.url}`,
|
|
11
|
+
description: "Parsed request body:",
|
|
12
|
+
additionalData: request.body,
|
|
13
|
+
mustOutputIf: mustLogDataAfterParsing
|
|
14
|
+
});
|
|
21
15
|
const requestBodyProcessingResult = es_extensions_1.RawObjectDataProcessor.
|
|
22
|
-
process(request.body,
|
|
16
|
+
process(request.body, validationAndProcessing);
|
|
23
17
|
if (requestBodyProcessingResult.rawDataIsInvalid) {
|
|
24
18
|
response.
|
|
25
19
|
status(es_extensions_1.HTTP_StatusCodes.badRequest).
|
package/Distributable/Route.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { HTTP_Methods } from "fundamental-constants";
|
|
2
|
-
export
|
|
2
|
+
export declare function Route(HTTP_Method: HTTP_Methods, pathTemplate: string): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
package/Distributable/Route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Route = Route;
|
|
4
4
|
const routing_controllers_1 = require("routing-controllers");
|
|
5
5
|
const fundamental_constants_1 = require("fundamental-constants");
|
|
6
6
|
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
package/Distributable/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { ExpressMiddleware } from "./ExpressMiddleware";
|
|
2
|
+
export { Route } from "./Route";
|
|
2
3
|
export { parseAndValidateJSON_RequestBody } from "./RequestBody/parseAndValidateJSON_RequestBody";
|
|
3
4
|
export { validateAndProcessJSON_RequestBody } from "./RequestBody/validateAndProcessJSON_RequestBody";
|
|
4
5
|
export { saveExpressSession } from "./Session/saveExpressSession";
|
package/Distributable/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.disposeExpressSession = exports.saveExpressSession = exports.validateAndProcessJSON_RequestBody = exports.parseAndValidateJSON_RequestBody = exports.ExpressMiddleware = void 0;
|
|
3
|
+
exports.disposeExpressSession = exports.saveExpressSession = exports.validateAndProcessJSON_RequestBody = exports.parseAndValidateJSON_RequestBody = exports.Route = exports.ExpressMiddleware = void 0;
|
|
4
4
|
var ExpressMiddleware_1 = require("./ExpressMiddleware");
|
|
5
5
|
Object.defineProperty(exports, "ExpressMiddleware", { enumerable: true, get: function () { return ExpressMiddleware_1.ExpressMiddleware; } });
|
|
6
|
+
var Route_1 = require("./Route");
|
|
7
|
+
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return Route_1.Route; } });
|
|
6
8
|
var parseAndValidateJSON_RequestBody_1 = require("./RequestBody/parseAndValidateJSON_RequestBody");
|
|
7
9
|
Object.defineProperty(exports, "parseAndValidateJSON_RequestBody", { enumerable: true, get: function () { return parseAndValidateJSON_RequestBody_1.parseAndValidateJSON_RequestBody; } });
|
|
8
10
|
var validateAndProcessJSON_RequestBody_1 = require("./RequestBody/validateAndProcessJSON_RequestBody");
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ The wrapper for [`session.destroy(callback)`](https://www.npmjs.com/package/expr
|
|
|
139
139
|
settings: Readonly<{
|
|
140
140
|
requestBodySizeLimit__bytesPackageFormat: string | number;
|
|
141
141
|
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification;
|
|
142
|
+
mustLogDataAfterParsing?: boolean;
|
|
142
143
|
}>
|
|
143
144
|
): ExpressMiddleware
|
|
144
145
|
```
|
|
@@ -161,7 +162,8 @@ The *alternative* to [class-transformer](https://github.com/typestack/class-tran
|
|
|
161
162
|
|
|
162
163
|
```
|
|
163
164
|
<RequestData extends ReadonlyParsedJSON>(
|
|
164
|
-
|
|
165
|
+
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification,
|
|
166
|
+
{ mustLogDataAfterParsing = false }: Readonly<{ mustLogDataAfterParsing?: boolean; }> = { mustLogDataAfterParsing: false }
|
|
165
167
|
): ExpressMiddleware
|
|
166
168
|
```
|
|
167
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamato-daiwa/express-extensions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Additional functionality for Express.js and also \"routing-controllers\" aimed to reduce the routine code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nodejs",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"express-session": "~1.18.0",
|
|
35
35
|
"routing-controllers": "~0.11.0"
|
|
36
36
|
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@yamato-daiwa/es-extensions": "1.7.2",
|
|
39
|
+
"fundamental-constants": "0.7.0"
|
|
40
|
+
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/express-session": "1.18.1",
|
|
39
43
|
"@yamato-daiwa/style_guides": "0.6.3",
|
|
@@ -49,9 +53,5 @@
|
|
|
49
53
|
"Rebuild Distributable": "rimraf Distributable && tsc",
|
|
50
54
|
"Rebuild Distributable and Realize Alpha": "npm run \"Rebuild Distributable\" && npm publish --tag alpha",
|
|
51
55
|
"Rebuild Distributable and Realize RC": "npm run \"Rebuild Distributable\" && npm publish --tag rc"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@yamato-daiwa/es-extensions": "1.7.2",
|
|
55
|
-
"fundamental-constants": "0.7.0"
|
|
56
56
|
}
|
|
57
57
|
}
|