@statesync/core
@statesync/core
@statesync/core -- Revision-based state synchronization primitives.
This is the core package of the state-sync library. It provides a transport-agnostic engine that keeps local state in sync with an authoritative server using revision-based invalidation.
Key concepts
- Topic -- A string identifier that scopes a sync loop to a specific resource.
- Revision -- A canonical decimal u64 string used to totally order state versions.
- Invalidation event -- A lightweight notification telling the client that the server's revision has advanced (i.e. "your data is stale").
- Snapshot -- The full authoritative state fetched from the server, wrapped in a SnapshotEnvelope with its revision.
Quick start
ts
import {
createRevisionSync,
createConsoleLogger,
} from '@statesync/core';
const handle = createRevisionSync({
topic: 'user-profile',
subscriber: myWebSocketSubscriber,
provider: { getSnapshot: () => fetch('/api/snapshot').then(r => r.json()) },
applier: { apply: ({ data }) => store.setState(data) },
logger: createConsoleLogger({ debug: true }),
});
await handle.start();Interfaces
- ConsoleLoggerOptions
- InvalidationEvent
- InvalidationSubscriber
- InvalidationThrottlingOptions
- Logger
- RetryPolicy
- RetryReportingOptions
- RevisionSyncHandle
- RevisionSyncOptions
- SnapshotApplier
- SnapshotEnvelope
- SnapshotProvider
- SyncErrorContext
- ThrottledHandler
