Document Runtime (BETA)
Use @series-inc/rundot-document to build collaborative documents, knowledge bases, world bibles, inventory ledgers, or wiki-style state inside RUN applications.
The document runtime provides:
State-based Sequence CRDT:
TextRegisterprovides commutative RGA merges without whole-field clobbering.Dual-mode Operation: Seamlessly works offline with single-user Merkle sessions and 3-way CAS auto-rebase, or online in multi-user authoritative rooms.
Cross-tab Sync: Native multi-tab synchronization via
TabSyncBusandSynchronizedLocalStorage.Collaborative Discussions: Span-anchored inline suggestions, Google Docs-style comments, review approvals, and entity-level change tracking.
Zero Runtime Dependencies: Pure TypeScript ESM designed with a zero-dependency sealed boundary. Platform storage is injected, not imported.
Install
npm install @series-inc/rundot-document
# or
pnpm add @series-inc/rundot-documentThe document runtime is a separate package. It uses appStorage and standard room transports via structural duck-typing, but it does not import the RUN game SDK at runtime. You can use the version of the game SDK that your game already has.
1. Storage Integration (Venus Platform)
Inject your game's appStorage into the document runtime. Because @series-inc/rundot-document uses the structural adapter pattern, you never need to align SDK versions:
installVenusDocumentStore validates the presence of required storage primitives (getItem, setItem, removeItem, getAllKeys / getAllItems, and compareAndSwap) immediately at startup.
While raw appStorage normally forces full-object rewrites, @series-inc/rundot-document isolates state into granular delta commits and compacted snapshot buckets, preventing monolithic serialization lockups.
2. Define a Document Schema
Schemas declare the top-level registers, entity collections, and rigidity policies:
3. Single-User Session (Offline First with Multi-Tab Sync)
For solo editing or offline-first experiences, create a SingleUserSession. It writes through a local Merkle commit tree, coordinates across browser tabs using BroadcastChannel, and performs optimistic atomic CAS commits against appStorage:
Multi-Tab Synchronization
SingleUserSession automatically connects to TabSyncBus. When the user edits the document in another tab or window, the background tab automatically detects the commit via Web Locks and BroadcastChannel, rebasing remote commits without overwriting local uncommitted drafts.
4. Realtime Collaborative Room (Authoritative Multiplayer)
For real-time multi-user editing, use DocumentAuthorityRoom on the room server and DocumentRoomClient in the browser or mobile client:
Server-Side Room Authority
Client-Side Awareness & Presence
DocumentRoomClient handles ephemeral presence, cursor tracking, and chunked WebSocket frame synchronization:
5. Discussions, Comments & Span Suggestions
The Document Runtime includes first-class support for Google Docs-style inline suggestions, review threads, and entity change proposals:
6. Architecture & Design Rules
@series-inc/rundot-document enforces strict architectural invariants:
Zero Runtime Dependencies:
dependenciesinpackage.jsonis empty. Everything is bundled or injected through ports.Storage Injection: Storage is never imported from global packages. Pass
appStorageviainstallVenusDocumentStoreor customStructuralStorageApiadapters.No Node Builtins: Runs purely in web standards (
crypto.subtle,BroadcastChannel,localStorage).Deterministic Merges: All text operations converge deterministically regardless of message arrival order.
Last updated