improvement - added separate effects.helper
MODIFY
src/effects/effects.combiner.ts
src/effects/effects.combiner.ts
@@ -2,7 +2,8 @@ import { merge, of } from 'rxjs';
import { mergeMap, switchMap } from 'rxjs/operators';
import { HttpRequest } from '../http.interface';
import { matchPath } from '../operators/matchPath.operator';
-import { EffectCombiner, MiddlewareCombiner, RoutesCombiner, isGroup } from './effects.interface';
+import { isGroup } from './effects.helpers';
+import { EffectCombiner, MiddlewareCombiner, RouteCombiner } from './effects.interface';
export const combineEffects: EffectCombiner = effects => res => req => {
const req$ = of(req);
@@ -25,5 +26,5 @@ export const combineMiddlewareEffects: MiddlewareCombiner = effects => res => re
return req$.pipe(...mappedEffects);
};
-export const combineRoutes: RoutesCombiner = (path, effects) =>
+export const combineRoutes: RouteCombiner = (path, effects) =>
({ path, effects });

ADD
src/effects/effects.helpers.ts
+import { Effect, EffectResponse, GroupedEffects } from './effects.interface';
+
+export const isGroup = (item): item is GroupedEffects =>
+ typeof item === 'object' && !!item.path && !!item.effects;
+
+export const isEffect = (item): item is Effect<EffectResponse> =>
+ !isGroup(item);

MODIFY
src/effects/effects.interface.ts
src/effects/effects.interface.ts
@@ -7,32 +7,27 @@ export interface EffectResponse {
headers?: Record<string, string>;
}
-export type Effect<T = EffectResponse, U = any> = (
- request$: Observable<HttpRequest>,
- response: HttpResponse,
- metadata: U
-) => Observable<T>;
-
-export type EffectCombiner = (
- effects: (Effect<EffectResponse> | GroupedEffects)[]
-) => (res: HttpResponse) => (req: HttpRequest) => Observable<EffectResponse>;
+export interface GroupedEffects {
+ path: string;
+ effects: Effects;
+}
-export type MiddlewareCombiner = (
- effects: Effect<HttpRequest>[]
-) => (res: HttpResponse) => (req: HttpRequest) => Observable<HttpRequest>;
+export interface EffectCombiner {
+ (effects: Effects): (res: HttpResponse) => (req: HttpRequest) => Observable<EffectResponse>;
+}
-export type RoutesCombiner = (
- path: string,
- effects: (Effect<EffectResponse> | GroupedEffects)[]
-) => GroupedEffects;
+export interface MiddlewareCombiner {
+ (effects: Effect<HttpRequest>[]): (res: HttpResponse) => (req: HttpRequest) => Observable<HttpRequest>;
+}
-export interface GroupedEffects {
- path: string;
- effects: (Effect<EffectResponse> | GroupedEffects)[];
+export interface RouteCombiner {
+ (path: string, effects: Effects): GroupedEffects;
}
-export const isGroup = (item): item is GroupedEffects =>
- typeof item === 'object' && !!item.path && !!item.effects;
+export type Effect<T = EffectResponse, U = any> = (
+ request$: Observable<HttpRequest>,
+ response: HttpResponse,
+ metadata: U
+) => Observable<T>;
-export const isEffect = (item): item is Effect<EffectResponse> =>
- !isGroup(item);
+export type Effects = (Effect<EffectResponse> | GroupedEffects)[];

MODIFY
src/http.interface.ts
src/http.interface.ts
@@ -12,6 +12,11 @@ export type HttpHeaders = Record<string, string>;
export type HttpMethod = 'POST' | 'PUT' | 'PATCH' | 'GET' | 'HEAD' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
+export type Http = {
+ req: HttpRequest;
+ res: HttpResponse;
+};
+
export enum HttpStatus {
OK = 200,
BAD_REQUEST = 400,

improvement - added separate effects.helper