Skip to Content

Overview

Streamsy is a toolkit for working with Durable Streams in Effect

Streamsy is an Effect implementation of the Durable Streams protocol:

  • Declare byte, json or state streams.
  • Create, Read and Append with effects.
  • Checkpointed reads with Projections
  • Provide storage via layers
  • Serve the http protocol
import { Effect, Schema, Stream } from "effect";
import { MemoryStorage, Streamsy } from "@streamsy/core";

class Notes extends Streamsy.json<Notes>()("App/Notes", "notes", {
  params: {},
  schema: Schema.Struct({ text: Schema.String }),
}) {}

const program = Effect.gen(function* () {
  const notes = yield* Notes;
  yield* notes.create({});
  yield* notes.append({}, [{ text: "hello" }]);
  return yield* notes.read({}).pipe(
    Stream.flatMap((batch) => Stream.fromIterable(batch.items)),
    Stream.runCollect,
  );
});

await Effect.runPromise(program.pipe(Effect.provide(MemoryStorage.layer(Streamsy.group(Notes)))));

Install

The example above needs only @streamsy/core and effect. Streamsy requires Effect 4.

bun add @streamsy/core effect

Where Next?

SectionContents
StreamsDeclare, create, read, and write streams
ProjectionsDerive streams and state from other streams
StorageChoose a storage Layer, use SQLite, or write a storage adapter
Servers and clientsServe streams over HTTP, connect to a server, and run a server
ReferenceEvery export, by package
ExamplesRunnable example applications

On this page