durable-streams
- 14 skills
- 0 followers
- 6 hours ago last updated
- ▌ Forking · durable-streamsCreating and using forked streams. Fork a source stream at a specific offset using Stream-Forked-From and Stream-Fork-Offset headers via DurableStream.create(). Reads transparently stitch inherited and fork data. Covers fork creation, fresh handle pattern, TTL/expiry inheritance, content-type inheritance, and deletion lifecycle. Load when forking, branching, or creating a stream variant from an existing stream.
- ▌ Stream DB · durable-streamsStream-backed reactive database with @durable-streams/state. createStreamDB() with schema and stream options, db.preload() lazy initialization, db.collections for TanStack DB collections, optimistic actions with onMutate and mutationFn, db.utils.awaitTxId() for transaction confirmation, control events (snapshot-start, snapshot-end, reset), db.close() cleanup, re-exported TanStack DB operators (eq, gt, and, or, count, sum, avg, min, max).
- ▌ State Schema · durable-streamsDefining typed state schemas for @durable-streams/state. createStateSchema() with CollectionDefinition (schema, type, primaryKey), Standard Schema validators (Zod, Valibot, ArkType), event helpers insert/update/delete/upsert, ChangeEvent and ControlEvent types, State Protocol operations, transaction IDs (txid) for write confirmation. Load when defining entity types, choosing a schema validator, or creating typed change events.
- ▌ Writing Data · durable-streamsWriting data to durable streams. DurableStream.create() with contentType, DurableStream.append() for simple writes, IdempotentProducer for high-throughput exactly-once delivery with autoClaim, fire-and-forget append(), flush(), close(), StaleEpochError handling, JSON mode vs byte stream mode, stream closure. Load when writing, producing, or appending data to a durable stream.
- ▌ Getting Started · durable-streamsFirst-time setup for Durable Streams. Install @durable-streams/client, create a stream with DurableStream.create(), read with stream(), subscribe to live updates, resume from saved offsets. Covers offset semantics ("-1", "now", opaque tokens), LiveMode (false, true, "long-poll", "sse"), and StreamResponse consumption (.json(), .text(), .subscribeJson()).
- ▌ Reading Streams · durable-streams bundleAll stream reading patterns for @durable-streams/client. stream() function, DurableStream.stream(), LiveMode (false, true, "long-poll", "sse"), StreamResponse state machine, .json(), .text(), .jsonStream(), .textStream(), .subscribeJson(), .subscribeBytes(), .subscribeText(), SSE resilience with auto-fallback to long-poll, visibility-based pause, binary SSE base64 auto-decode, dynamic headers for auth token refresh, backoff config, StreamErrorHandler onError for error recovery.
- ▌ Go To Production · durable-streamsProduction readiness checklist for durable streams. Switch from dev server to Caddy binary, configure CDN caching with offset-based URLs, Cache-Control and ETag headers, Stream-Cursor for cache collision prevention, TTL and Stream-Expires-At for stream lifecycle, HTTPS requirement, request collapsing for fan-out, CORS configuration. Load before deploying durable streams to production.
- ▌ Server Deployment · durable-streamsRunning durable stream servers. DurableStreamTestServer for development (Node.js, @durable-streams/server, not for production), Caddy plugin for production with Caddyfile configuration, data_dir for file-backed persistence, max_file_handles tuning, long_poll_timeout, server binary downloads for macOS Linux Windows, @durable-streams/cli tool setup, conformance test runner.
- ▌ Yjs Sync · durable-streamsYjsProvider deep-dive for @durable-streams/y-durable-streams. Provider options, connection lifecycle (connect, disconnect, destroy), synced/status/error events, connection state machine, dynamic auth headers, liveMode (sse vs long-poll), error recovery behavior. Load when configuring provider behavior beyond basic setup.
- ▌ Yjs Server · durable-streamsDeploy Yjs collaborative editing. YjsServer setup with compaction threshold, Caddy reverse proxy with flush_interval -1 for SSE, 3-layer architecture (Browser → Caddy → YjsServer → DS Server), Electric Cloud managed alternative with @electric-sql/cli provisioning. Load when deploying y-durable-streams to production or configuring server infrastructure.
- ▌ Vercel AI Sdk · durable-streamsVercel AI SDK integration with Durable Streams. createDurableChatTransport() for useChat(), toDurableStreamResponse() for server-side streaming, resumable chat sessions with reconnectToStream(), read proxy pattern for auth. Load when building chat apps with Vercel AI SDK (@ai-sdk/react) and durable streams.
- ▌ Yjs Editors · durable-streamsIntegrate Yjs collaborative editing with TipTap v3 and CodeMirror 6 over durable streams. Canonical React pattern: doc+awareness in useState, provider in useEffect with connect:false (listeners before connect). TipTap: Collaboration + CollaborationCaret extensions, -caret not -cursor package. CodeMirror: yCollab binding. Covers awareness wiring, multi-document navigation with key={docId}, SSR ssr:false requirement. Critical anti-patterns that crash agents documented.
- ▌ Tanstack AI · durable-streamsTanStack AI integration with Durable Streams. durableStreamConnection() for useChat(), toDurableChatSessionResponse() for server-side streaming, SSR hydration with materializeSnapshotFromDurableStream(), multi-client sync with live: true, chunk sanitization, read proxy pattern. Load when building chat apps with TanStack AI (@tanstack/ai-react) and durable streams.
- ▌ Yjs Getting Started · durable-streamsFirst-time setup for @durable-streams/y-durable-streams. Install peer deps, start dev servers (DurableStreamTestServer + YjsServer), create a collaborative Y.Doc, connect with YjsProvider, verify sync, add awareness for presence. Load when setting up Yjs collaborative editing for the first time.