How to use the @marblejs/middleware-io.eventValidator$ function in @marblejs/middleware-io

To help you get started, we’ve selected a few @marblejs/middleware-io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / marble / packages / @integration / src / effects / calculator.ws-effects.ts View on Github external
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 })),
  );
github marblejs / marble / packages / @integration / src / messaging / server.ts View on Github external
const fibonacci$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent('FIB'),
    use(eventValidator$(t.number)),
    tap(event => { if (event.payload >= 45) throw new Error('Too high number!') }),
    map(event => fib(event.payload)),
    map(payload => ({ type: 'FIB_RESULT', payload })),
  );
github marblejs / marble / packages / messaging / src / server / specs / messaging.server.amqp.spec.ts View on Github external
const rpc$: MsgEffect = event$ =>
      event$.pipe(
        matchEvent('RPC_TEST'),
        delay(250),
        use(eventValidator$(t.number)),
        map(event => event.payload),
        map(payload => ({ type: 'RPC_TEST_RESULT', payload: payload + 1 })),
      );
github marblejs / marble / packages / messaging / src / server / specs / messaging.server.redis.spec.ts View on Github external
const rpc$: MsgEffect = event$ =>
      event$.pipe(
        matchEvent('RPC_TEST'),
        use(eventValidator$(t.number)),
        map(event => event.payload),
        map(payload => ({ type: 'RPC_TEST_RESULT', payload: payload + 1 })),
      );