Options
All
  • Public
  • Public/Protected
  • All
Menu

Module stream

Sociably Stream

Reactive programming stream for handling events in back-end.

⚠ This package is still on early experimental. There might be breaking changes in the future for supporting cluster. You can check the future road map here.

Install

npm install @sociably/stream
# or with yarn
yarn add @sociably/stream

Docs

Check the Reactive Programming document and the package reference.

Example

import { makeContainer, IntentRecognizer } from '@sociably/core';
import { fromApp } from '@sociably/stream';
import { map, filter } from '@sociably/stream/operators';
import app from './app';

const event$ = fromApp(app);

const textMsg$ = events$.pipe(
filter(({ event }) => event.type === 'text'),
map(
makeContainer({ deps: [IntentRecognizer] })(
(recognizer) =>
async (context) => {
const { channel, text } = context.event;
const intent = await recognizer.detectText(channel, text);
return { ...context, intent };
}
)
)
);

textMsg$.subscribe(async ({ intent, reply }) => {
const action = intent.type;
if (action) {
await reply(`start ${action}...`);
}
});

Index

Type aliases

EventContextOfApp<App>: App extends SociablyApp<any, infer Context> ? Context : never

Type parameters

OperatorFunction<T, R>: (input: Stream<T>) => Stream<R>

Type parameters

  • T

  • R

Type declaration

StreamingFrame<T>: { key: undefined | string; scope: ServiceScope; value: T }

Type parameters

  • T

Type declaration

Variables

STREAMING_KEY_I: SingularServiceInterface<unknown> = ...

Functions

  • pipe<A, B>(fn1: (a: A) => B): (a: A) => B
  • pipe<A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C
  • pipe<A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D
  • pipe<A, B, C, D, E>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (a: A) => E
  • pipe<A, B, C, D, E, F>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): (a: A) => F
  • pipe<T>(...fns: ((x: T) => T)[]): (x: T) => T
  • Type parameters

    • A

    • B

    Parameters

    • fn1: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns (a: A) => B

      • (a: A): B
      • Parameters

        • a: A

        Returns B

  • Type parameters

    • A

    • B

    • C

    Parameters

    • fn1: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fn2: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    Returns (a: A) => C

      • (a: A): C
      • Parameters

        • a: A

        Returns C

  • Type parameters

    • A

    • B

    • C

    • D

    Parameters

    • fn1: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fn2: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • fn3: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    Returns (a: A) => D

      • (a: A): D
      • Parameters

        • a: A

        Returns D

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    Parameters

    • fn1: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fn2: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • fn3: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • fn4: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    Returns (a: A) => E

      • (a: A): E
      • Parameters

        • a: A

        Returns E

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    Parameters

    • fn1: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fn2: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • fn3: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • fn4: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • fn5: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    Returns (a: A) => F

      • (a: A): F
      • Parameters

        • a: A

        Returns F

  • Type parameters

    • T

    Parameters

    • Rest ...fns: ((x: T) => T)[]

    Returns (x: T) => T

      • (x: T): T
      • Parameters

        • x: T

        Returns T

Generated using TypeDoc