Skip to content

Stream

Stream<S> = object

Defined in: Core/Stream.ts:42

An event stream pipeline for a typed message schema S.

Stream provides typed event emission, sequence matching, state reduction, and structural stream forwarding.

type AppMessages = {
  userLoggedIn: { userId: string };
  checkoutStarted: { amount: number };
};

const appStream = Stream.make<AppMessages>();

const subscription = Stream.listen(
  appStream,
  ["userLoggedIn", "checkoutStarted"],
  { ordered: true }
).reduce(
  (msg, state) => {
    if (msg.kind === "checkoutStarted") {
      return { count: state.count + 1 };
    }
    return state;
  },
  { count: 0 }
);

Stream.emit(appStream, {
  kind: "userLoggedIn",
  value: { userId: "user-1" },
});

S extends Record<string, unknown>

readonly optional options?: Options

Defined in: Core/Stream.ts:43