Skip to content

@offlinesync/protocol

Fully independent wire protocol types. Zero dependencies on other OfflineSync packages.

Incremental Sync Types

ExportKindDescription
SyncRequesttypeClient → server: clientId, mutations, cursor
SyncResponsetypeServer → client: changes, conflicts, acknowledgedMutationIds, serverCursor, errors
ChangetypeA single remote change: entity, type
ConflictInfotypeConflict detail: entityId, collectionName, clientVersion, serverVersion
ProtocolEntitytypeWire format entity: id, data, revision, createdAt, updatedAt, isDeleted
ProtocolMutationtypeWire format mutation: id, entityId, collectionName, operation, field, value, sequence, createdAt

Snapshot Sync Types

ExportKindDescription
SnapshotRequesttypeFull-state request: clientId, collections
SnapshotResponsetypeFull-state response: entitiesByCollection, serverCursor

Error Types

ExportKindDescription
ProtocolErrortype{ code: SyncErrorCode, message, classification?, retryAfter? }
SyncErrorCodetypeUnion of error code string literals
ErrorClassificationtype'RETRYABLE' | 'AUTHENTICATION' | 'PERMANENT' | 'UNKNOWN'

Handshake

ExportKindDescription
CURRENT_PROTOCOL_VERSIONconstCurrent supported protocol version
ProtocolVersiontypeParsed version: major, minor, patch
negotiateVersion(client, server)functionReturns highest mutually supported version
parseVersion(v)functionParses a version string

Type Guards

Runtime validation functions for all protocol types:

isSyncRequest(v) · isSyncResponse(v) · isSnapshotRequest(v) · isSnapshotResponse(v) · isProtocolEntity(v) · isProtocolMutation(v) · isChange(v) · isConflictInfo(v) · isProtocolError(v) · isSyncErrorCode(v) · isErrorClassification(v)

Constants

ExportDescription
SYNC_ERROR_CODEAll valid protocol error codes
ERROR_CLASSIFICATIONError classification values
ERROR_CODE_CLASSIFICATIONMaps error codes to classifications
CLASSIFICATION_RETRY_BEHAVIORMaps classifications to { shouldRetry }

Released under the MIT License.