imp(middleware-body): exported `RequestBodyParser` interface
MODIFY
packages/middleware-body/src/body.middleware.ts
packages/middleware-body/src/body.middleware.ts
@@ -2,13 +2,13 @@ import { HttpError, HttpStatus, HttpMiddlewareEffect } from '@marblejs/core';
import { of, throwError, iif } from 'rxjs';
import { catchError, map, switchMap, tap, mapTo } from 'rxjs/operators';
import { defaultParser } from './serializers';
-import { BodyParser } from './body.model';
+import { RequestBodyParser } from './body.model';
import { matchType, getBody, hasBody } from './body.util';
const PARSEABLE_METHODS = ['POST', 'PUT', 'PATCH'];
interface BodyParserOptions {
- parser?: BodyParser;
+ parser?: RequestBodyParser;
type?: string[];
}

MODIFY
packages/middleware-body/src/body.model.ts
packages/middleware-body/src/body.model.ts
import { HttpRequest } from '@marblejs/core';
-export type BodyParser = (req: HttpRequest) => (body: Buffer) => Buffer | object | string | undefined;
+export type RequestBodyParser = (req: HttpRequest) => (body: Buffer) => Buffer | object | string | undefined;

MODIFY
packages/middleware-body/src/index.ts
packages/middleware-body/src/index.ts
export { bodyParser$ } from './body.middleware';
+export { RequestBodyParser } from './body.model';
export { defaultParser, jsonParser, urlEncodedParser, textParser, rawParser } from './serializers';

MODIFY
packages/middleware-body/src/serializers/default.body.parser.ts
packages/middleware-body/src/serializers/default.body.parser.ts
import { ContentType } from '@marblejs/core/dist/+internal';
-import { BodyParser } from '../body.model';
+import { RequestBodyParser } from '../body.model';
import { jsonParser } from './json.body.parser';
import { textParser } from './text.body.parser';
import { rawParser } from './raw.body.parser';
import { urlEncodedParser } from './url.body.parser';
-export const defaultParser: BodyParser = req => body => {
+export const defaultParser: RequestBodyParser = req => body => {
switch (req.headers['content-type']) {
case ContentType.APPLICATION_JSON:
return jsonParser(req)(body);

MODIFY
packages/middleware-body/src/serializers/json.body.parser.ts
packages/middleware-body/src/serializers/json.body.parser.ts
-import { BodyParser } from '../body.model';
+import { RequestBodyParser } from '../body.model';
-export const jsonParser: BodyParser = _ => body =>
+export const jsonParser: RequestBodyParser = _ => body =>
JSON.parse(body.toString());

MODIFY
packages/middleware-body/src/serializers/raw.body.parser.ts
packages/middleware-body/src/serializers/raw.body.parser.ts
-import { BodyParser } from '../body.model';
+import { RequestBodyParser } from '../body.model';
-export const rawParser: BodyParser = _ => body => body;
+export const rawParser: RequestBodyParser = _ => body => body;

MODIFY
packages/middleware-body/src/serializers/text.body.parser.ts
packages/middleware-body/src/serializers/text.body.parser.ts
-import { BodyParser } from '../body.model';
+import { RequestBodyParser } from '../body.model';
-export const textParser: BodyParser = _ => body =>
+export const textParser: RequestBodyParser = _ => body =>
body.toString();

MODIFY
packages/middleware-body/src/serializers/url.body.parser.ts
packages/middleware-body/src/serializers/url.body.parser.ts
import { compose } from '@marblejs/core/dist/+internal';
-import { BodyParser } from '../body.model';
+import { RequestBodyParser } from '../body.model';
const decodeComponent = (urlEncoded: string) => urlEncoded
.split('&')
@@ -9,5 +9,5 @@ const decodeComponent = (urlEncoded: string) => urlEncoded
[key]: isNaN(+value) ? value : +value,
}), {});
-export const urlEncodedParser: BodyParser = _ => body =>
+export const urlEncodedParser: RequestBodyParser = _ => body =>
compose(decodeComponent, decodeURIComponent)(body.toString());

imp(middleware-body): exported `RequestBodyParser` interface