OSS-first docs

These docs teach the open system first: contracts, generated surfaces, runtimes, governance, and incremental adoption. Studio shows up as the operating layer on top, not as the source of truth.

Contracts Runtime Core

The framework-neutral, in-house engine for the canonical ContractSpec data-fetching protocol. It owns caching, the durable offline queue, conflict resolution, and the ports (Transport, Storage, reachability) — with no `@tanstack/*` dependency and no React coupling. It depends only on `@lssm-tech/lib.contracts-spec` and `@lssm-tech/lib.observability`.

Installation

bun add @lssm-tech/lib.contracts-runtime-core

What it provides

Transport port

One `execute(envelope, ctx)` port (+ optional `subscribe()` realtime seam). REST, MCP, WebSocket, and in-memory are interchangeable adapters behind it.

Query + cache engine

In-house cache store keyed by `createQueryKey`, request dedup, retry/backoff, background revalidation, GC, and the canonical `QueryState` machine.

Offline + conflict

Durable mutation queue with replay-on-reconnect, optimistic apply/rollback, etag conflict detection, and a per-contract conflict-resolver registry (server-wins default; CRDT via crdt-loro injection).

Storage + reachability

Storage port with secure-by-default platform variants (`/storage/indexeddb` web, `/storage/async-storage` native) and a reachability input port the engine reads but never imports integrations for.

Engine setup

import {
  createDataEngine,
  createMemoryStorage,
  createStaticReachabilitySource,
  type Transport,
  type DataEngine,
} from '@lssm-tech/lib.contracts-runtime-core';

const engine: DataEngine = createDataEngine({
  transport,            // required: a Transport adapter (REST/MCP/in-memory)
  storage,              // optional: durable Storage port (defaults to in-memory)
  reachability,         // optional: ReachabilitySource (defaults to always-online)
  contextProvider,      // optional: fresh auth/correlation ctx per replay
  refreshAuth,          // optional: () => Promise<boolean> for auth-expiry resume
});

// Surface: query / getState / subscribe / invalidateTags / refresh /
//          emitConflict / mutate / drain / resume / dispose (+ events, maintenance)

Related reading

For the full protocol, client hooks, server adapters, and rendering story, read the Data Fetching spec.