imp(core, websockets): HttpMiddleware -> HttpMiddlewareEffect + WsMiddleware  -> WsMiddlewareEffect
MODIFY
packages/@integration/src/middlewares/auth.middleware.ts
packages/@integration/src/middlewares/auth.middleware.ts
-import { HttpError, HttpStatus, HttpMiddleware } from '@marblejs/core';
+import { HttpError, HttpStatus, HttpMiddlewareEffect } from '@marblejs/core';
import { iif, of, throwError } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { isAuthorized } from '../fakes/auth.fake';
-export const authorize$: HttpMiddleware = req$ =>
+export const authorize$: HttpMiddlewareEffect = req$ =>
req$.pipe(
switchMap(req => iif(
() => !isAuthorized(req),

MODIFY
packages/core/src/effects/http-effects.interface.ts
packages/core/src/effects/http-effects.interface.ts
@@ -10,7 +10,7 @@ export interface HttpEffectResponse<T = any> {
body?: T;
}
-export interface HttpMiddleware<
+export interface HttpMiddlewareEffect<
I extends HttpRequest = HttpRequest,
O extends HttpRequest = HttpRequest,
> extends HttpEffect<I, O> {}

MODIFY
packages/core/src/effects/specs/effects.combiner.spec.ts
packages/core/src/effects/specs/effects.combiner.spec.ts
import { tap, mapTo, filter } from 'rxjs/operators';
-import { HttpMiddleware, HttpEffect } from '../http-effects.interface';
+import { HttpMiddlewareEffect, HttpEffect } from '../http-effects.interface';
import { combineMiddlewares, combineEffects } from '../effects.combiner';
import { Marbles, createHttpRequest } from '../../+internal';
describe('#combineMiddlewares', () => {
test('combines middlewares into one stream', () => {
// given
- const a$: HttpMiddleware = req$ => req$.pipe(tap(req => { req.test = 1; }));
- const b$: HttpMiddleware = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
- const c$: HttpMiddleware = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
+ const a$: HttpMiddlewareEffect = req$ => req$.pipe(tap(req => { req.test = 1; }));
+ const b$: HttpMiddlewareEffect = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
+ const c$: HttpMiddlewareEffect = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
const incomingRequest = createHttpRequest({ url: '/' });
const outgoingRequest = createHttpRequest({ url: '/', test: 3 });

MODIFY
packages/core/src/listener/http.listener.spec.ts
packages/core/src/listener/http.listener.spec.ts
@@ -3,7 +3,7 @@ import { of, throwError } from 'rxjs';
import { mapTo, switchMap } from 'rxjs/operators';
import { httpListener } from './http.listener';
import { EffectFactory } from '../effects/effects.factory';
-import { HttpMiddleware } from '../effects/http-effects.interface';
+import { HttpMiddlewareEffect } from '../effects/http-effects.interface';
describe('Http listener', () => {
let effectsCombiner;
@@ -16,7 +16,7 @@ describe('Http listener', () => {
.matchType('GET')
.use(req$ => req$.pipe(mapTo( {} )));
- const middleware$: HttpMiddleware = req$ => req$;
+ const middleware$: HttpMiddlewareEffect = req$ => req$;
beforeEach(() => {
jest.unmock('../error/error.effect.ts');

MODIFY
packages/core/src/listener/http.listener.ts
packages/core/src/listener/http.listener.ts
@@ -4,7 +4,7 @@ import { catchError, defaultIfEmpty, mergeMap, tap, takeWhile } from 'rxjs/opera
import { combineMiddlewares } from '../effects/effects.combiner';
import {
HttpEffectResponse,
- HttpMiddleware,
+ HttpMiddlewareEffect,
HttpErrorEffect,
HttpOutputEffect,
} from '../effects/http-effects.interface';
@@ -18,7 +18,7 @@ import { createStaticInjectionContainer } from '../server/server.injector';
import { createEffectMetadata } from '../effects/effectsMetadata.factory';
export interface HttpListenerConfig {
- middlewares?: HttpMiddleware[];
+ middlewares?: HttpMiddlewareEffect[];
effects: (RouteEffect | RouteEffectGroup)[];
error$?: HttpErrorEffect;
output$?: HttpOutputEffect;

MODIFY
packages/core/src/router/router.factory.ts
packages/core/src/router/router.factory.ts
-import { HttpMiddleware } from '../effects/http-effects.interface';
+import { HttpMiddlewareEffect } from '../effects/http-effects.interface';
import { combineMiddlewares } from '../effects/effects.combiner';
import { isRouteEffectGroup } from './router.helpers';
import {
@@ -12,7 +12,7 @@ import { factorizeRegExpWithParams } from './router.params.factory';
export const factorizeRouting = (
routes: (RouteEffect | RouteEffectGroup)[],
- middlewares: HttpMiddleware[] = [],
+ middlewares: HttpMiddlewareEffect[] = [],
parentPath = '',
): Routing => {
const routing: Routing = [];

MODIFY
packages/core/src/router/router.interface.ts
packages/core/src/router/router.interface.ts
import { HttpMethod, HttpRequest } from '../http.interface';
-import { HttpEffect, HttpMiddleware, HttpEffectResponse } from '../effects/http-effects.interface';
+import { HttpEffect, HttpMiddlewareEffect, HttpEffectResponse } from '../effects/http-effects.interface';
// Route
export interface RouteEffect<T extends HttpRequest = HttpRequest> {
path: string;
method: HttpMethod;
effect: HttpEffect<T, HttpEffectResponse>;
- middleware?: HttpMiddleware;
+ middleware?: HttpMiddlewareEffect;
}
export interface RouteEffectGroup {
path: string;
- middlewares: HttpMiddleware[];
+ middlewares: HttpMiddlewareEffect[];
effects: (RouteEffect | RouteEffectGroup)[];
}
// Combiner
export interface RouteCombinerConfig {
- middlewares?: HttpMiddleware[];
+ middlewares?: HttpMiddlewareEffect[];
effects: (RouteEffect | RouteEffectGroup)[];
}
@@ -30,7 +30,7 @@ export interface ParametricRegExp {
export interface RoutingMethod {
parameters?: string[] | undefined;
- middleware?: HttpMiddleware | undefined;
+ middleware?: HttpMiddlewareEffect | undefined;
effect: HttpEffect;
}
@@ -41,7 +41,7 @@ export interface RoutingItem {
}
export interface RouteMatched {
- middleware?: HttpMiddleware | undefined;
+ middleware?: HttpMiddlewareEffect | undefined;
effect: HttpEffect;
params: Record<string, string>;
}

MODIFY
packages/core/src/router/specs/router.combiner.spec.ts
packages/core/src/router/specs/router.combiner.spec.ts
import { mapTo } from 'rxjs/operators';
import { combineRoutes } from '../router.combiner';
import { EffectFactory } from '../../effects/effects.factory';
-import { HttpMiddleware, HttpEffect } from '../../effects/http-effects.interface';
+import { HttpMiddlewareEffect, HttpEffect } from '../../effects/http-effects.interface';
describe('#combineRoutes', () => {
test('factorizes combined routes for effects only', () => {
@@ -27,8 +27,8 @@ describe('#combineRoutes', () => {
const a$ = EffectFactory.matchPath('/a').matchType('GET').use(effect$);
const b$ = EffectFactory.matchPath('/b').matchType('GET').use(effect$);
- const m1$: HttpMiddleware = req$ => req$;
- const m2$: HttpMiddleware = req$ => req$;
+ const m1$: HttpMiddlewareEffect = req$ => req$;
+ const m2$: HttpMiddlewareEffect = req$ => req$;
// when
const combiner = combineRoutes('/test', {

MODIFY
packages/core/src/router/specs/router.factory.spec.ts
packages/core/src/router/specs/router.factory.spec.ts
import { mapTo } from 'rxjs/operators';
-import { HttpEffect, HttpMiddleware } from '../../effects/http-effects.interface';
+import { HttpEffect, HttpMiddlewareEffect } from '../../effects/http-effects.interface';
import { RouteEffect, RouteEffectGroup, Routing } from '../router.interface';
import { factorizeRouting } from '../router.factory';
@@ -13,7 +13,7 @@ describe('#factorizeRouting', () => {
test('factorizes routing with nested groups', () => {
// given
- const m$: HttpMiddleware = req$ => req$;
+ const m$: HttpMiddlewareEffect = req$ => req$;
const e1$: HttpEffect = req$ => req$.pipe(mapTo({ body: 'test1' }));
const e2$: HttpEffect = req$ => req$.pipe(mapTo({ body: 'test2' }));
const e3$: HttpEffect = req$ => req$.pipe(mapTo({ body: 'test3' }));

MODIFY
packages/core/src/router/specs/router.resolver.spec.ts
packages/core/src/router/specs/router.resolver.spec.ts
import { mapTo, tap, map } from 'rxjs/operators';
-import { HttpEffect, HttpMiddleware } from '../../effects/http-effects.interface';
+import { HttpEffect, HttpMiddlewareEffect } from '../../effects/http-effects.interface';
import { EffectMetadata } from '../../effects/effects.interface';
import { findRoute, resolveRouting } from '../router.resolver';
import { HttpRequest, HttpResponse, HttpMethod } from '../../http.interface';
@@ -185,7 +185,7 @@ describe('#resolveRouting', () => {
test('applies middlewares to found effect', done => {
// given
- const middleware$: HttpMiddleware = req$ => req$.pipe(tap(req => req.test = 'test' ));
+ const middleware$: HttpMiddlewareEffect = req$ => req$.pipe(tap(req => req.test = 'test' ));
const effect$: HttpEffect = req$ => req$.pipe(map(req => ({ body: req.test }) ));
const expectedMachingResult: RouteMatched = { middleware: middleware$, effect: effect$, params: {} };

MODIFY
packages/middleware-body/src/index.ts
packages/middleware-body/src/index.ts
-import { HttpError, HttpRequest, HttpStatus, HttpMiddleware } from '@marblejs/core';
+import { HttpError, HttpRequest, HttpStatus, HttpMiddlewareEffect } from '@marblejs/core';
import { ContentType } from '@marblejs/core/dist/+internal';
import { Observable, of, throwError } from 'rxjs';
import { catchError, map, switchMap, tap, toArray, mapTo } from 'rxjs/operators';
@@ -44,7 +44,7 @@ const getBody = (req: HttpRequest) =>
})
);
-export const bodyParser$: HttpMiddleware = req$ =>
+export const bodyParser$: HttpMiddlewareEffect = req$ =>
req$.pipe(
switchMap(req =>
PARSEABLE_METHODS.includes(req.method)

MODIFY
packages/middleware-jwt/src/jwt.middleware.ts
packages/middleware-jwt/src/jwt.middleware.ts
import { throwError, of, Observable } from 'rxjs';
import { map, flatMap, catchError, tap } from 'rxjs/operators';
-import { HttpError, HttpStatus, HttpMiddleware, HttpRequest } from '@marblejs/core';
+import { HttpError, HttpStatus, HttpMiddlewareEffect, HttpRequest } from '@marblejs/core';
import { parseAuthorizationHeader } from './jwt.util';
import { verifyToken$, VerifyOptions } from './jwt.factory';
@@ -11,7 +11,7 @@ const assignPayloadToRequest = (req: HttpRequest) => (payload: object) => req.us
export const authorize$ = (
config: AuthorizeMiddlewareConfig,
verifyPayload$: (payload: any) => Observable<object>,
-): HttpMiddleware => req$ =>
+): HttpMiddlewareEffect => req$ =>
req$.pipe(
flatMap(req => of(req).pipe(
map(parseAuthorizationHeader),

MODIFY
packages/middleware-logger/src/logger.middleware.ts
packages/middleware-logger/src/logger.middleware.ts
-import { HttpMiddleware } from '@marblejs/core';
+import { HttpMiddlewareEffect } from '@marblejs/core';
import { timestamp, tap, map } from 'rxjs/operators';
import { LoggerOptions } from './logger.model';
import { loggerHandler } from './logger.handler';
@@ -8,13 +8,13 @@ import { loggerHandler } from './logger.handler';
* [#2] will be deleted in version 2.0,
* [#3] use loggerWithOpts$ instead,
*/
-export const logger$: HttpMiddleware = (req$, res, injector) => {
+export const logger$: HttpMiddlewareEffect = (req$, res, injector) => {
// tslint:disable-next-line:max-line-length
console.warn('Deprecation warning: logger$ is deprecated since v1.2 and will be removed in v2.0. Use loggerWithOpts$ instead.');
return loggerWithOpts$()(req$, res, injector);
};
-export const loggerWithOpts$ = (opts: LoggerOptions = {}): HttpMiddleware => (req$, res) =>
+export const loggerWithOpts$ = (opts: LoggerOptions = {}): HttpMiddlewareEffect => (req$, res) =>
req$.pipe(
timestamp(),
tap(loggerHandler(res, opts)),

MODIFY
packages/websockets/src/effects/ws-effects.interface.ts
packages/websockets/src/effects/ws-effects.interface.ts
@@ -2,7 +2,7 @@ import * as http from 'http';
import { Event, Effect } from '@marblejs/core';
import { MarbleWebSocketClient } from '../websocket.interface';
-export interface WsMiddleware<
+export interface WsMiddlewareEffect<
I = Event,
O = Event,
> extends WsEffect<I, O> {}

MODIFY
packages/websockets/src/listener/specs/websocket.listener.spec.ts
packages/websockets/src/listener/specs/websocket.listener.spec.ts
@@ -2,7 +2,7 @@ import { Event, EventError, createStaticInjectionContainer, httpServerToken } fr
import { throwError, fromEvent, forkJoin } from 'rxjs';
import { tap, map, mergeMap, first, toArray, take } from 'rxjs/operators';
import { webSocketListener } from '../websocket.listener';
-import { WsEffect, WsMiddleware, WsConnectionEffect } from '../../effects/ws-effects.interface';
+import { WsEffect, WsMiddlewareEffect, WsConnectionEffect } from '../../effects/ws-effects.interface';
import { WebSocketConnectionError } from '../../error/ws-error.model';
import { EventTransformer } from '../../transformer/transformer.inteface';
import { createWebSocketsTestBed } from '../../+internal';
@@ -90,7 +90,7 @@ describe('WebSocket listener', () => {
const incomingEvent = JSON.stringify({ type: 'EVENT', payload: 0 });
const outgoingEvent = JSON.stringify({ type: 'EVENT', payload: 3 });
const e$: WsEffect = event$ => event$;
- const m$: WsMiddleware = event$ => event$.pipe(
+ const m$: WsMiddlewareEffect = event$ => event$.pipe(
map(event => event as Event<number>),
tap(event => event.payload !== undefined && event.payload++)
);

MODIFY
packages/websockets/src/listener/websocket.listener.ts
packages/websockets/src/listener/websocket.listener.ts
@@ -30,7 +30,7 @@ type HandleIncomingConnection =
export interface WebSocketListenerConfig {
effects?: WSEffect.WsEffect<any, any>[];
- middlewares?: WSEffect.WsMiddleware<any, any>[];
+ middlewares?: WSEffect.WsMiddlewareEffect<any, any>[];
error$?: WSEffect.WsErrorEffect<Error, any, any>;
eventTransformer?: EventTransformer<Event, any>;
connection$?: WSEffect.WsConnectionEffect;

imp(core, websockets): HttpMiddleware -> HttpMiddlewareEffect + WsMiddleware  -> WsMiddlewareEffect