Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const listening$: HttpServerEffect = event$ =>
event$.pipe(
matchEvent(ServerEvent.listening),
map(event => event.payload),
tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
);
const listening$: HttpServerEffect = event$ =>
event$.pipe(
matchEvent(ServerEvent.listening),
map(event => event.payload),
tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
);
const event$: MsgEffect = event$ =>
event$.pipe(
matchEvent('EVENT_TEST'),
use(eventValidator$(t.number)),
map(event => event.payload),
map(payload => ({ type: 'EVENT_TEST_RESPONSE', payload: payload + 1 })),
tap(async event => {
expect(event).toEqual({ type: 'EVENT_TEST_RESPONSE', payload: 2 });
await wait();
await server.close();
await client.close();
done();
}),
);
export const add$: WsEffect = (event$, ...args) =>
event$.pipe(
matchEvent('ADD'),
use(eventValidator$(t.number)),
buffer(sum$(event$, ...args)),
map(addEvents => addEvents.reduce((a, e) => e.payload + a, 0)),
map(payload => ({ type: 'SUM_RESULT', payload })),
);
const add$: WsEffect = (event$, ...args) =>
event$.pipe(
matchEvent('ADD'),
use(eventValidator$(t.number)),
buffer(sum$(event$, ...args)),
map(addEvents => addEvents.reduce((a, e) => e.payload + a, 0)),
map(payload => ({ type: 'SUM_RESULT', payload })),
);
const event1$: MsgEffect = event$ =>
event$.pipe(
matchEvent(event1.type),
mergeMapTo(throwError(error)),
);
const teardownOnClose$ = (conn: Promise) => (event$: Observable) =>
event$.pipe(
matchEvent(ServerEvent.close),
take(1),
mergeMapTo(conn),
mergeMap(conn => conn.close()),
);
const connect$: MsgServerEffect = (event$, ctx) => {
const logger = provideLogger(ctx.ask);
const transportLayer = useContext(TransportLayerToken)(ctx.ask);
return event$.pipe(
matchEvent(ServerEvent.status),
map(event => event.payload),
distinctUntilChanged((p, c) => p.type === c.type),
filter(({ type }) => type === serverStatusMap.connect[transportLayer.type]),
tap(({ host, channel }) => logger({
tag: 'CONNECTED',
message: `Connected server to host: ${host}`,
level: LoggerLevel.INFO,
channel,
})),
);
};
const error$: MsgServerEffect = (event$, ctx) => {
const logger = provideLogger(ctx.ask);
const transportLayer = useContext(TransportLayerToken)(ctx.ask);
return event$.pipe(
matchEvent(ServerEvent.error),
map(event => event.payload),
tap(({ error }) => logger({
tag: 'ERROR',
message: `${error.name}, ${error.message}`,
level: LoggerLevel.ERROR,
channel: transportLayer.config.channel,
}))
);
};
export const sum$: WsEffect = event$ =>
event$.pipe(
matchEvent('SUM')
);