imp(websockets): Effects interface name correction
MODIFY
packages/@integration/src/effects/calculator.ws-effects.ts
packages/@integration/src/effects/calculator.ws-effects.ts
import { use, matchEvent } from '@marblejs/core';
-import { WebSocketEffect } from '@marblejs/websockets';
+import { WsEffect } from '@marblejs/websockets';
import { t, eventValidator$ } from '@marblejs/middleware-io';
import { buffer, map } from 'rxjs/operators';
-export const sum$: WebSocketEffect = event$ =>
+export const sum$: WsEffect = event$ =>
event$.pipe(
matchEvent('SUM')
);
-export const add$: WebSocketEffect = (event$, ...args) =>
+export const add$: WsEffect = (event$, ...args) =>
event$.pipe(
matchEvent('ADD'),
use(eventValidator$(t.number)),

MODIFY
packages/@integration/src/index.ts
packages/@integration/src/index.ts
-import { createServer, matchEvent, ServerEvent, ServerEffect, bind } from '@marblejs/core';
+import { createServer, matchEvent, ServerEvent, HttpServerEffect, bind } from '@marblejs/core';
import { mapToServer } from '@marblejs/websockets';
import { merge } from 'rxjs';
import { tap, map } from 'rxjs/operators';
@@ -6,7 +6,7 @@ import { httpServer } from './http.listener';
import { webSocketServer } from './ws.listener';
import { WebSocketsToken } from './tokens';
-const upgrade$: ServerEffect = (event$, _, { inject }) =>
+const upgrade$: HttpServerEffect = (event$, _, { inject }) =>
event$.pipe(
matchEvent(ServerEvent.upgrade),
mapToServer({
@@ -15,7 +15,7 @@ const upgrade$: ServerEffect = (event$, _, { inject }) =>
}),
);
-const listen$: ServerEffect = event$ =>
+const listen$: HttpServerEffect = event$ =>
event$.pipe(
matchEvent(ServerEvent.listen),
map(event => event.payload),

MODIFY
packages/@integration/src/ws.listener.ts
packages/@integration/src/ws.listener.ts
-import { webSocketListener, WebSocketConnectionError, WebSocketConnectionEffect } from '@marblejs/websockets';
+import { webSocketListener, WebSocketConnectionError, WsConnectionEffect } from '@marblejs/websockets';
import { iif, throwError, of } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { add$ } from './effects/calculator.ws-effects';
-const connection$: WebSocketConnectionEffect = req$ =>
+const connection$: WsConnectionEffect = req$ =>
req$.pipe(
mergeMap(req => iif(
() => req.headers.upgrade !== 'websocket',

MODIFY
packages/websockets/src/effects/ws-effects.interface.ts
packages/websockets/src/effects/ws-effects.interface.ts
@@ -2,26 +2,26 @@ import * as http from 'http';
import { Event, Effect } from '@marblejs/core';
import { MarbleWebSocketClient } from '../websocket.interface';
-export interface WebSocketMiddleware<
+export interface WsMiddleware<
I = Event,
O = Event,
-> extends WebSocketEffect<I, O> {}
+> extends WsEffect<I, O> {}
-export interface WebSocketErrorEffect<
+export interface WsErrorEffect<
T extends Error = Error,
U = Event,
V = Event
-> extends WebSocketEffect<U, V, MarbleWebSocketClient, T> {}
+> extends WsEffect<U, V, MarbleWebSocketClient, T> {}
-export interface WebSocketConnectionEffect<
+export interface WsConnectionEffect<
T extends http.IncomingMessage = http.IncomingMessage
-> extends WebSocketEffect<T, T, MarbleWebSocketClient> {}
+> extends WsEffect<T, T, MarbleWebSocketClient> {}
-export interface WebSocketOutputEffect<
+export interface WsOutputEffect<
T extends Event = Event
-> extends WebSocketEffect<T, Event> {}
+> extends WsEffect<T, Event> {}
-export interface WebSocketEffect<
+export interface WsEffect<
T = Event,
U = Event,
V = MarbleWebSocketClient,

MODIFY
packages/websockets/src/error/specs/ws-error.handler.spec.ts
packages/websockets/src/error/specs/ws-error.handler.spec.ts
@@ -2,7 +2,7 @@ import { EventError, EffectMetadata, createStaticInjectionContainer, createEffec
import { mapTo } from 'rxjs/operators';
import { handleEffectsError } from '../ws-error.handler';
import { MarbleWebSocketClient } from '../../websocket.interface';
-import { WebSocketErrorEffect } from '../../effects/ws-effects.interface';
+import { WsErrorEffect } from '../../effects/ws-effects.interface';
describe('#handleEffectsError', () => {
let defaultMetadata: EffectMetadata;
@@ -15,7 +15,7 @@ describe('#handleEffectsError', () => {
// given
const client = { sendResponse: jest.fn() } as any as MarbleWebSocketClient;
const error = new EventError({ type: 'EVENT' }, '');
- const error$: WebSocketErrorEffect = event$ => event$.pipe(
+ const error$: WsErrorEffect = event$ => event$.pipe(
mapTo({ type: error.event.type, error: {} }),
);

MODIFY
packages/websockets/src/error/specs/ws-error.provider.spec.ts
packages/websockets/src/error/specs/ws-error.provider.spec.ts
import { mapTo } from 'rxjs/operators';
-import { WebSocketErrorEffect } from '../../effects/ws-effects.interface';
+import { WsErrorEffect } from '../../effects/ws-effects.interface';
import { error$ as defaultError$ } from '../ws-error.effect';
import { provideErrorEffect } from '../ws-error.provider';
@@ -7,7 +7,7 @@ describe('#provideErrorEffect', () => {
test('provides passed error$', () => {
// given
const transformer = undefined;
- const error$: WebSocketErrorEffect = event$ => event$.pipe(
+ const error$: WsErrorEffect = event$ => event$.pipe(
mapTo({ type: 'ERROR', payload: 'error' }),
);

MODIFY
packages/websockets/src/error/ws-error.effect.ts
packages/websockets/src/error/ws-error.effect.ts
import { EventError } from '@marblejs/core';
import { map } from 'rxjs/operators';
-import { WebSocketErrorEffect } from '../effects/ws-effects.interface';
+import { WsErrorEffect } from '../effects/ws-effects.interface';
const DEFAULT_ERROR_CHANNEL = 'ERROR';
@@ -8,7 +8,7 @@ const errorFactory = (message: string | undefined, data: any | undefined) => ({
message, data,
});
-export const error$: WebSocketErrorEffect<EventError> = (event$, _, { error }) =>
+export const error$: WsErrorEffect<EventError> = (event$, _, { error }) =>
event$.pipe(
map(event => ({
type: event ? event.type : DEFAULT_ERROR_CHANNEL,

MODIFY
packages/websockets/src/error/ws-error.handler.ts
packages/websockets/src/error/ws-error.handler.ts
import { of } from 'rxjs';
import { EventError, EffectMetadata } from '@marblejs/core';
import { MarbleWebSocketClient } from '../websocket.interface';
-import { WebSocketErrorEffect } from '../effects/ws-effects.interface';
+import { WsErrorEffect } from '../effects/ws-effects.interface';
export const handleEffectsError = <IncomingError extends EventError>(
metadata: EffectMetadata,
client: MarbleWebSocketClient,
- error$: WebSocketErrorEffect<IncomingError, any, any> | undefined,
+ error$: WsErrorEffect<IncomingError, any, any> | undefined,
) => (error: IncomingError) => {
if (error$) {
error$(of(error.event), client, { ...metadata, error }).subscribe(client.sendResponse);

MODIFY
packages/websockets/src/error/ws-error.provider.ts
packages/websockets/src/error/ws-error.provider.ts
import { EventTransformer } from '../transformer/transformer.inteface';
-import { WebSocketErrorEffect } from '../effects/ws-effects.interface';
+import { WsErrorEffect } from '../effects/ws-effects.interface';
import { error$ as defaultError$ } from './ws-error.effect';
export const provideErrorEffect = (
- errorEffect: WebSocketErrorEffect<any, any, any> | undefined,
+ errorEffect: WsErrorEffect<any, any, any> | undefined,
eventTransformer: EventTransformer<any, any> | undefined,
) =>
!errorEffect && eventTransformer === undefined

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 { WebSocketEffect, WebSocketMiddleware, WebSocketConnectionEffect } from '../../effects/ws-effects.interface';
+import { WsEffect, WsMiddleware, WsConnectionEffect } from '../../effects/ws-effects.interface';
import { WebSocketConnectionError } from '../../error/ws-error.model';
import { EventTransformer } from '../../transformer/transformer.inteface';
import { createWebSocketsTestBed } from '../../+internal';
@@ -19,7 +19,7 @@ describe('WebSocket listener', () => {
const targetClient = testBed.getClient(0);
const httpServer = testBed.getServer();
const injector = createStaticInjectionContainer().register(httpServerToken, () => httpServer);
- const echo$: WebSocketEffect = event$ => event$;
+ const echo$: WsEffect = event$ => event$;
const event = JSON.stringify({ type: 'EVENT', payload: 'test' });
const webSocketServer = webSocketListener({ effects: [echo$] });
@@ -36,7 +36,7 @@ describe('WebSocket listener', () => {
test('echoes back to all clients', done => {
// given
- const echo$: WebSocketEffect = (event$, client) => event$.pipe(
+ const echo$: WsEffect = (event$, client) => event$.pipe(
mergeMap(client.sendBroadcastResponse),
);
const event = JSON.stringify({ type: 'EVENT', payload: 'test' });
@@ -62,7 +62,7 @@ describe('WebSocket listener', () => {
test('echoes back on upgraded http server', done => {
// given
- const echo$: WebSocketEffect = event$ => event$;
+ const echo$: WsEffect = event$ => event$;
const event = JSON.stringify({ type: 'EVENT', payload: 'test' });
const httpServer = testBed.getServer();
const injector = createStaticInjectionContainer().register(httpServerToken, () => httpServer);
@@ -89,8 +89,8 @@ describe('WebSocket listener', () => {
// given
const incomingEvent = JSON.stringify({ type: 'EVENT', payload: 0 });
const outgoingEvent = JSON.stringify({ type: 'EVENT', payload: 3 });
- const e$: WebSocketEffect = event$ => event$;
- const m$: WebSocketMiddleware = event$ => event$.pipe(
+ const e$: WsEffect = event$ => event$;
+ const m$: WsMiddleware = event$ => event$.pipe(
map(event => event as Event<number>),
tap(event => event.payload !== undefined && event.payload++)
);
@@ -146,7 +146,7 @@ describe('WebSocket listener', () => {
// given
const incomingEvent = JSON.stringify({ type: 'EVENT' });
const outgoingEvent = JSON.stringify({ type: 'EVENT', error: { message: 'test message' } });
- const effect$: WebSocketEffect = event$ => event$.pipe(
+ const effect$: WsEffect = event$ => event$.pipe(
mergeMap(event => throwError(new EventError(event, 'test message'))),
);
const targetClient = testBed.getClient(0);
@@ -174,7 +174,7 @@ describe('WebSocket listener', () => {
test('triggers connection error', done => {
// given
const error = new WebSocketConnectionError('Unauthorized', 4000);
- const connection$: WebSocketConnectionEffect = req$ => req$.pipe(mergeMap(() => throwError(error)));
+ const connection$: WsConnectionEffect = req$ => req$.pipe(mergeMap(() => throwError(error)));
const webSocketServer = webSocketListener({ connection$ });
const targetClient = testBed.getClient(0);
const httpServer = testBed.getServer();
@@ -207,7 +207,7 @@ describe('WebSocket listener', () => {
decode: event => event,
encode: event => event,
};
- const effect$: WebSocketEffect<Buffer, string> = event$ => event$.pipe(
+ const effect$: WsEffect<Buffer, string> = event$ => event$.pipe(
map(event => event.toString('utf8'))
);
const httpServer = testBed.getServer();

MODIFY
packages/websockets/src/listener/websocket.listener.ts
packages/websockets/src/listener/websocket.listener.ts
@@ -29,12 +29,12 @@ type HandleIncomingConnection =
(client: WS.WebSocketClient, request: http.IncomingMessage) => void;
export interface WebSocketListenerConfig {
- effects?: WSEffect.WebSocketEffect<any, any>[];
- middlewares?: WSEffect.WebSocketMiddleware<any, any>[];
- error$?: WSEffect.WebSocketErrorEffect<Error, any, any>;
+ effects?: WSEffect.WsEffect<any, any>[];
+ middlewares?: WSEffect.WsMiddleware<any, any>[];
+ error$?: WSEffect.WsErrorEffect<Error, any, any>;
eventTransformer?: EventTransformer<Event, any>;
- connection$?: WSEffect.WebSocketConnectionEffect;
- output$?: WSEffect.WebSocketOutputEffect;
+ connection$?: WSEffect.WsConnectionEffect;
+ output$?: WSEffect.WsOutputEffect;
}
export const webSocketListener = (config: WebSocketListenerConfig = {}) => {

MODIFY
packages/websockets/src/operators/broadcast/broadcast.operator.spec.ts
packages/websockets/src/operators/broadcast/broadcast.operator.spec.ts
import { Marbles } from '@marblejs/core/dist/+internal';
import { EMPTY } from 'rxjs';
import { broadcast } from './broadcast.operator';
-import { WebSocketEffect } from '../../effects/ws-effects.interface';
+import { WsEffect } from '../../effects/ws-effects.interface';
describe('#broadcast operator', () => {
const client = { sendBroadcastResponse: jest.fn(() => EMPTY) };
@@ -12,7 +12,7 @@ describe('#broadcast operator', () => {
const outgoingEvent = { type: 'TEST_EVENT_RESPONSE', payload: 'test_payload' };
// when
- const effect$: WebSocketEffect = (event$, client) =>
+ const effect$: WsEffect = (event$, client) =>
event$.pipe(
broadcast(client, () => outgoingEvent),
);

imp(websockets): Effects interface name correction