API Reference

Use this page to find contracts exported from each package root. Follow the package links for behavior examples and lifecycle details.

Prepaint

Install package: @firsttx/prepaint

ExportRole
createFirstTxRootConnect React root creation to Prepaint handoff
bootReplay a stored snapshot during boot
setupCaptureRegister snapshot capture
handoffTransfer control from the replay overlay to current React UI
PrepaintErrorBase Prepaint error class
BootError, CaptureError, PrepaintStorageErrorConcrete error classes
HydrationErrorDeprecated error class retained for legacy consumers

Public types and helper:

ExportContract
HandoffStrategy"has-prepaint" | "cold-start"
CreateFirstTxRootOptionstransition, onCapture, onHandoff, deprecated onHydrationError
PrepaintPolicyroutes, ttlMs, maxSnapshotBytes, includeStyles
convertDOMExceptionConvert a DOM storage error into PrepaintStorageError

The Vite subpath @firsttx/prepaint/plugin/vite exports firstTx and FirstTxPluginOptions. The overlay and overlayRoutes options are deprecated; the current restore path uses an overlay.

Details: Prepaint

Local-First

Install package: @firsttx/local-first

ExportRole
defineModelDefine a model with Zod schema, version, initialData, TTL, and merge
StorageIndexedDB storage access
useModelSubscribe to the model external-store snapshot
useSyncedModelConnect model snapshots to server revalidation
useSuspenseSyncedModelReturn synced T through a Suspense boundary
FirstTxError, StorageError, ValidationErrorLocal-First error classes

ModelOptions<T> provides schema, version, initialData, ttl, and merge. useModel returns { data, status, error, history, patch }; useSyncedModel adds sync and isSyncing.

Public typeContract
Model<T>patch, replace, getSnapshot, getHistory, and synchronous cached snapshot methods
StoredModel<T>_v, updatedAt, and data persisted in IndexedDB
ModelHistoryupdatedAt, age, isStale, and currently always-false isConflicted
SyncOptions<T>syncOnMount, onSuccess, and onError
SyncedModelResult<T>data, status, patch, sync, isSyncing, error, and history
Fetcher<T>, SuspenseFetcher<T>Receive current data or null and return Promise<T>
SuspenseSyncOptions<T>revalidateOnMount, onSuccess, and onError
StorageErrorCode"QUOTA_EXCEEDED" | "PERMISSION_DENIED" | "UNKNOWN"

useSuspenseSyncedModel checks IndexedDB through getSyncPromise() when the memory snapshot has no data. If stored data is found, revalidateOnMount controls its background revalidation. When the memory snapshot already has data, the hook returns immediately without starting another revalidation.

The main StorageError properties are code, storageCode, recoverable, and storageContext; the class implements isRecoverable().

Details: Local-First

Tx

Install package: @firsttx/tx

ExportRole
startTransactionCreate an imperative transaction
useTxConnect optimistic, request, and rollback lifecycle to React
DEFAULT_RETRY_CONFIG, RETRY_PRESETSRetry defaults and presets
TxErrorBase Tx error class
TransactionTimeoutError, RetryExhaustedErrorTimeout and exhausted retry errors
CompensationFailedError, TransactionStateErrorCompensation failure and invalid state errors

TxOptions provides id, transition, and timeout. Each run step can receive compensate, retry, and signal options.

Public typeContract
TxStatus"pending" | "running" | "committed" | "rolled-back" | "failed"
StepOptionscompensate, retry, and signal
RetryConfigmaxAttempts, delayMs, and backoff
UseTxConfigoptimistic, rollback, request, transition, retry, callbacks, and cancelOnUnmount
UseTxResultmutate, mutateAsync, cancel, pending/error/success state, and error

CompensationFailedError stores compensation failures and completedSteps; it does not retain the original step error that triggered rollback.

Details: Tx

Runtime event contract

Every event contains id, category, type, timestamp, data, and priority.

CategoryRepresentative types
prepaintcapture, restore, handoff, storage.error
modelinit, load, patch, replace, sync.*, broadcast, broadcast.fallback, broadcast.skipped, validation.error
txstart, step.*, commit, rollback.*, timeout
systemBridge readiness and internal status events

Runtime package emitters own the observable payload contract. The @firsttx/devtools bridge types are an internal consumer schema for the extension and should not be treated as a stable public API.

Observation: DevTools

Shared error usage

Each package error base class provides a user message, debug details, and recoverability.

Error classDistinct public properties
BootErrorphase, cause
CaptureErrorphase, route, cause
HydrationErrormismatchType, cause
PrepaintStorageErrorstorageCode, operation, cause
StorageErrorstorageCode, recoverable, storageContext
ValidationErrormodelName, zodError
TransactionTimeoutErrortimeoutMs, elapsedMs
RetryExhaustedErrorstepId, attempts, errors
CompensationFailedErrorfailures, completedSteps
TransactionStateErrorcurrentState, attemptedAction, transactionId
ts
import { TxError } from "@firsttx/tx";

try {
  await operation();
} catch (error) {
  if (error instanceof TxError) {
    console.error(error.getDebugInfo());
    if (error.isRecoverable()) {
      showRetryAction();
    }
  }
}

See Troubleshooting for symptom-based decisions and manual recovery scope.