Operations

Configuration reference

Check the options, types, and defaults for databases, backups, network access, device sync, and replication.

Check each option against the object that accepts it. The driver reference covers driver factories, while encryption describes key loaders and change status.

Supply every option marked required. A dash in the default column means the option is absent unless you set it; the description explains that case.

Opening databases

SirannonOptions

Pass these options to new Sirannon(options). See getting started.

OptionTypeDefaultDescription
driverSQLiteDriverrequiredSirannon opens connections through this driver.
hooksHookConfig-Sirannon calls these hooks around queries and connections. The server also calls them before subscriptions, snapshots, and device pushes.
metricsMetricsConfig-Sirannon reports query timing and row counts, database opens and closes, and delivered change events through these callbacks.
lifecycleLifecycleConfig-Sirannon applies these automatic-opening, idle-timeout, and open-database limits.
migrationsMigrationSource-Sirannon applies this migration set, or the set returned by this function, before registering a writable database.
writerWorkerboolean | WriterWorkerOptions-Every database in this registry inherits this writer-worker setting.
cdcRetentionnumber-Sirannon applies this change-log retention in milliseconds unless a database overrides it.
deviceCursorRetentionnumber-Sirannon applies this device-cursor retention in milliseconds unless a database overrides it.
maxChangesHeldForDevicenumber-Sirannon applies this limit to changes retained for one device unless a database overrides it.

LifecycleConfig

See hooks, metrics, and lifecycle.

OptionTypeDefaultDescription
autoOpen.resolver(id: string) => { path, options? } | undefined-Sirannon calls this resolver to obtain a path for an unknown database ID.
idleTimeoutnumber0Sirannon closes an idle database after these milliseconds. Zero disables the timer.
maxOpennumber0Sirannon evicts the least recently used database to enforce this limit. Zero leaves the count unbounded.

createTenantResolver builds a resolver from a basePath, an optional file extension, and defaultOptions that it applies to every tenant that it opens.

DatabaseOptions

Pass these options to sirannon.open(id, path, options).

OptionTypeDefaultDescription
readOnlybooleanfalseOpen the database read-only, which refuses every write.
readPoolSizenumber4A driver with multiple connections opens this many readers, with a minimum of one.
walModebooleantrueSirannon enables write-ahead logging when true.
synchronous'off' | 'normal' | 'full' | 'extra''normal'Sirannon configures writer durability through PRAGMA synchronous. A bulk load restores this level when it finishes.
cdcPollIntervalnumber50Sirannon polls for changes at this interval in milliseconds.
cdcRetentionnumber3600000Sirannon retains change history for this many milliseconds.
deviceCursorRetentionnumber2592000000Milliseconds that a device's cursor may hold changes back, 30 days by default. Sirannon deletes the cursor once the device's last acknowledgement, or the oldest change that the cursor holds back, is older than this, and that device then resyncs from a snapshot.
maxChangesHeldForDevicenumber0Sirannon deletes a device cursor when it retains more than this many changes from other writers. Zero sets no limit.
writerWorkerboolean | WriterWorkerOptionsfalseSirannon can execute writes on a dedicated thread. See writer worker.
backupsBackupCycleOptions-Capture this database's write-ahead log to a destination on an interval. See continuous backups.
encryptionEncryptionOptions-Supply a function returning 32 raw key bytes, or { key, id }. See encryption.

WriterWorkerOptions

OptionTypeDefaultDescription
maxPendingWritesnumber1024Sirannon refuses new writes with WRITE_OVERLOADED when this many writes are in flight.
writeTimeoutMsnumber30000Sirannon applies this per-operation deadline in milliseconds. Zero disables it.
maxRestartsnumber5Sirannon allows this many worker restarts before refusing writes with WRITER_WORKER_FATAL.

OpenOptions

Pass these options to driver.open(path, options) and to ConnectionPool.create, which application code reaches only when it opens a connection outside a Sirannon registry.

OptionTypeDefaultDescription
readonlybooleanfalseOpen the connection read-only.
encryption{ key: Uint8Array }-Supply the raw 32-byte key for this separate connection.
walModebooleantrueSirannon enables write-ahead logging when true.
synchronousSynchronousLevel'normal'SQLite applies this durability level.
walAutoCheckpointnumber-SQLite checkpoints after this many log frames. Zero disables automatic checkpoints, which Sirannon sets when continuous backups are enabled.

Running statements

QueryOptions

Pass these options to local methods that accept QueryOptions. Remote methods accept the concerns described in the client guide.

OptionTypeDefaultDescription
readConcern{ level: 'local' | 'majority' | 'linearizable' }-Coordinator mode enforces this read concern, while static mode ignores it.
writeConcern{ level, timeoutMs? }a local commit in static mode, 'majority' in coordinator modeThis concern specifies how many nodes must acknowledge a write. timeoutMs defaults to 5,000. A replica that forwards the write sends this concern with it, and the primary waits for it.

BulkLoadOptions

OptionTypeDefaultDescription
durability'off' | 'normal''off'SQLite applies this durability level during the load.
checkpointbooleantrueSirannon checkpoints after the load unless continuous backups control checkpointing.

LiveQueryOptions

OptionTypeDefaultDescription
rereadJitterMsnumber25Sirannon waits up to this many milliseconds before rereading.
maxTransactionChangesnumber10000Sirannon rereads the query when a transaction exceeds this change count.
onError(error: Error) => void-Sirannon reports a listener's throw or rejected promise through this callback.

Only local queries use rereadJitterMs and maxTransactionChanges; remote queries use the server's defaults. Both local and remote queries accept onError. React's UseLiveQueryOptions adds enabled, which disables the query while false.

Backups

BackupCycleOptions

Pass these options as backups in DatabaseOptions. See continuous backups.

OptionTypeDefaultDescription
destinationBackupDestinationrequiredSirannon stores full copies, change pieces, and chain records through this destination.
intervalMsnumber60000Sirannon captures at this interval. Zero disables the recurring timer, while startup, shutdown, and explicit captures remain.
fullCopyIntervalMsnumber86400000Sirannon starts a new full copy after the chain reaches this age.
chainNamestring'sirannon-backup-chain'The destination stores the chain list under this name.
namePrefixstring'sirannon-backup'Sirannon prefixes each backup identifier with this value.
pieceBytesnumber16777216Sirannon uses this many bytes for each complete piece. A streamed copy needs a multiple of 512.
fingerprintbooleantrueSirannon computes a SHA-256 digest when true.
stagingDirstringa directory beside the database fileSirannon stages captures in this directory before transfer.
maxUncapturedLogBytesnumberunboundedSirannon limits the write-ahead log to these bytes across turns that capture nothing.
replicationGroupBackupGroupSource-Sirannon obtains this node's group membership through this source. See backups in a replication group.
preferredNode'replica' | 'primary' | { nodeId }'replica'Sirannon uses this preference to select an eligible backup node.
pagesPerStepnumber256SQLite copies this many pages per step of a full copy.
restartLimitnumber3Sirannon refuses more full-copy restarts with BACKUP_RESTARTED.
noProgressStepLimitnumber256Sirannon limits consecutive steps without copying a new page.
stallTimeoutMsnumber30000Sirannon fails with BACKUP_STALLED after this many milliseconds without a completed step.
destinationTimeoutMsnumber600000Sirannon limits each destination call to these milliseconds. Zero removes the deadline.
onRun(report: BackupRunReport) => void-Sirannon calls this function with each completed backup report.
onProgress(progress: BackupProgress) => void-Sirannon calls this function after each copy step and stored piece.
onSkip(skip: BackupSkip) => void-Sirannon reports each skipped turn and its reason through this callback.
onError(error: Error) => void-Sirannon reports capture, transfer, and checkpoint failures through this callback. Configure it.

BackupToDestinationOptions

Pass these options to db.backupTo(options). See backup destinations.

OptionTypeDefaultDescription
destinationBackupDestinationrequiredSirannon stores and retrieves pieces through this destination.
namestringbackup-{ISO timestamp}.dbThe destination stores pieces under this name.
chainIdstringA random identifier.Sirannon includes this chain identifier in the report.
pieceBytesnumber16777216Sirannon uses this many bytes for each complete piece.
fingerprintbooleantrueSirannon computes a SHA-256 digest over the copy.
pagesPerStepnumber256SQLite copies this many pages per step.
restartLimitnumber3Sirannon refuses more restarts after this count.
noProgressStepLimitnumber256Sirannon limits consecutive steps without copying a new page.
stallTimeoutMsnumber30000Sirannon fails after these milliseconds without a completed copy step.
destinationTimeoutMsnumber600000Sirannon limits each destination call to these milliseconds.
stagingDirstringthe host temporary directorySirannon writes the staged local copy in this directory.
onProgress(progress: BackupProgress) => void-Sirannon reports copy steps and transferred pieces through this callback.

BackupScheduleOptions

Pass these options to db.scheduleBackup(options). See backups.

OptionTypeDefaultDescription
cronstringrequiredSupply five fields for minute resolution, or six to add seconds at the front.
destDirstringrequiredSirannon writes scheduled copies into this directory.
maxFilesnumber5Sirannon keeps this many matching copies by modification time; zero or less disables rotation.
timezonestringthe host zoneSirannon evaluates the expression in this IANA time zone.
onBackup(report: BackupFileReport) => void | Promise<void>-Sirannon calls this function after each completed copy, before rotating older copies.
onBackupTimeoutMsnumber600000Sirannon waits these milliseconds for onBackup. Zero removes the deadline.
onError(error: Error) => void-Sirannon reports each failure through this callback. Configure it.

BackupRestoreOptions

Pass these options to restoreBackup(options) from @delali/sirannon-db/backup. See restoring a database.

OptionTypeDefaultDescription
destinationBackupDestinationrequiredSirannon retrieves backups and their records through this destination.
driverSQLiteDriverrequiredSirannon opens the restored database through this driver.
destPathstringrequiredSirannon writes the restored database to this path.
encryptionEncryptionOptions-Supply the key for the selected backup chain.
momentnumbernowSupply the target time in epoch milliseconds.
chainNamestring'sirannon-backup-chain'Sirannon reads the chain list under this destination name.
replaceExistingbooleanfalseSirannon replaces an existing target when true.
batchSizenumber16Sirannon replays this many change pieces between checkpoints, up to 4,096.
destinationTimeoutMsnumber600000Sirannon limits each destination call to these milliseconds.
onProgress(progress: BackupRestoreProgress) => void-Sirannon reports progress after each piece and batch.

Serving over the network

ServerOptions

Pass these options to createServer(sirannon, options). See server.

OptionTypeDefaultDescription
hoststring'127.0.0.1'The server binds to this address.
portnumber9876The server listens on this port.
corsboolean | CorsOptionsfalseThe server applies these cross-origin settings.
maxBodyBytesnumber1048576The server accepts bodies and messages up to these bytes, as a positive integer no larger than 4,294,967,295.
maxWebSocketBackpressureBytesnumberthe larger of 16777216 and maxBodyBytesThe server closes a connection when its outbound buffer exceeds these bytes.
cdcRetentionMsnumber3600000The server retains changes for these milliseconds, which limits cursor resumption.
deviceCursorRetentionMsnumber2592000000Milliseconds that a device's cursor may hold changes back before the server deletes it, 30 days by default. A database's explicit deviceCursorRetention overrides it.
maxChangesHeldForDevicenumber0The server deletes a cursor when it retains more than this many changes. Zero sets no limit, and a database's explicit option overrides it.
maxUnacknowledgedChangesnumber1000The server pauses delivery after this many unacknowledged changes.
authenticateAuthenticateHook<Identity>-The server calls this hook before database routes and WebSocket upgrades.
operationsOperationRegistry<Identity>-The server exposes these registered reads and writes for each database ID.
sharedOperationsDatabaseOperations<Identity>-The server exposes these shared reads and writes on every database, including one opened after startup. A database-specific operation takes precedence over a shared operation with the same identifier.
acceptSqlbooleanfalseThe server accepts network SQL when true. It also accepts table subscriptions without an onBeforeSubscribe hook.
acceptEncryptionChangebooleanfalseOpen the encryption-change route; requires authenticate and encryptionKeys.
encryptionKeys(databaseId: string, keyRef: string) => EncryptionKey | Promise<EncryptionKey>-Resolve an operator's key reference inside the server.
acceptBackupRestorebooleanfalseWhether the server rebuilds a database from its backups over the network. A server that sets it without authenticate refuses to start, with INVALID_BACKUP_RESTORE.
acceptDeviceSyncbooleanfalseWhether the server serves device sync. A server that sets it without authenticate refuses to start, with INVALID_DEVICE_SYNC.
resolveExecutionTargetServerExecutionTargetResolver-The server calls this resolver to obtain the execution target that enforces replication authority.
getReplicationStatus() => ReplicationStatusInfo | null-The server calls this function for replication state at GET /health/ready.
getClusterStatus(databaseId: string) => ClusterStatusInfo | null-The server calls this function for routing metadata at GET /db/{id}/cluster.
authorizeClusterStatusClusterStatusAuthorizer-The server calls this function to authorise access to node addresses in cluster status.

ServerCloseOptions

Pass to server.close(options) before sirannon.shutdown().

OptionTypeDefaultDescription
timeoutMsnumber30000Wait this many milliseconds for requests to drain; accepts whole numbers from 0 to 2,147,483,647.

ClientOptions

Pass these options to new SirannonClient(url, options). See client SDK.

OptionTypeDefaultDescription
transport'websocket' | 'http''websocket'The client uses this transport.
headersRecord<string, string>-The client sends these headers on HTTP requests and Node or Bun WebSocket upgrades. A browser client that sets it without webSocketProtocols on the WebSocket transport fails with INVALID_ARGUMENT.
webSocketProtocolsstring | string[]-The client offers these subprotocols during the upgrade so that a browser can send a credential. The client offers sirannon.v1 ahead of them.
autoReconnectbooleantrueThe client reconnects after a recoverable WebSocket disconnect when true.
reconnectIntervalnumber1000The client waits these milliseconds before reconnecting.
requestTimeoutnumber30000The client waits these milliseconds for a WebSocket reply. Zero waits indefinitely.

TopologyAwareClientOptions

Accepted by TopologyAwareClient from @delali/sirannon-db/client/topology, alongside every ClientOptions field. SirannonClient refuses each of these with INVALID_ARGUMENT. See topology-aware routing.

OptionTypeDefaultDescription
endpointsstring[]-The client requests coordinator routing metadata through these starter endpoints.
primarystring-The client sends static-mode writes to this primary endpoint.
replicasstring[]-The client uses these replica endpoints directly in static mode.
readPreference'primary' | 'replica' | 'nearest''primary'The client selects a read node using this preference.
discovery'static' | 'coordinator''static'The client obtains routes from configuration in static mode and from cluster metadata in coordinator mode.
readConcern'local' | 'majority' | 'linearizable''majority' in coordinator modeThe client applies this read concern when selecting a node.

LoadAllOptions

OptionTypeDefaultDescription
batchSizenumber1000The client sends up to this many rows per request. Each batch must fit within the server's maxBodyBytes.
durability'off' | 'normal''off'The server applies this durability level while loading each batch.

Device sync

SyncControllerOptions

Pass these options to new SyncController(db, options). See device sync.

OptionTypeDefaultDescription
urlstringrequiredSupply the server's base URL.
databaseIdstringrequiredSupply the database ID that the server opened.
tablesreadonly string[]requiredSupply at least one table for the pull subscription.
headersRecord<string, string>-The controller sends these headers on push, snapshot, and migration requests, and on Node or Bun pull upgrades.
webSocketProtocolsstring | string[]-The controller offers these subprotocols on the pull upgrade so that a browser device can send a credential.
batchSizenumber100Each push contains up to this many changes, with an integer limit from 1 to 1000.
pushIntervalMsnumber1000The controller schedules pushes at this interval and uses it as the base retry delay.
ackIntervalMsnumber2000The device acknowledges applied changes at this interval in milliseconds.
maxPushRetryDelayMsnumber30000The controller limits push and pull retry delays to these milliseconds.
requestTimeoutnumber30000The controller limits each HTTP request to these milliseconds; zero removes the deadline.
autoResyncbooleantrueThe controller automatically downloads a snapshot when a resync is required. A new device needs an explicit first snapshot.
snapshotRetryDelayMsnumber5000The controller waits these milliseconds before retrying a failed snapshot.
maxSnapshotRetryDelayMsnumber300000The controller limits snapshot retry delays to these milliseconds.
snapshotPageSizenumber500Each page contains up to this many rows, with an integer limit from 1 to 1000.
immediateAckAfterChangesnumberHalf the server's window, or 500.The device acknowledges when outstanding changes reach this count.
resolverConflictResolver | ((table: string) => ConflictResolver)LWWResolverThe controller resolves pulled changes through this resolver.
onChange(event: ChangeEvent) => void-The controller calls this function for each pulled change after local commit.
onStatusChange(status: SyncStatus) => void-The controller reports status changes, pushes, applied pulls, resync requirements, and error changes through this callback.
onResyncRequired() => void-The controller calls this function when it marks a resync as required. A manual download needs a separate application guard.
onSnapshotProgress(progress: SnapshotProgress) => void-The controller reports table and row progress through this callback.
onSnapshotComplete(outcome: SnapshotOutcome) => void-The controller reports whether the local database is usable after a snapshot load through this callback.

SnapshotDownloadOptions

Accepted by downloadDatabaseSnapshot(db.deviceSync(), options), which copies a server database into a local one outside a SyncController. See device sync recovery.

OptionTypeDefaultDescription
urlstringrequiredSupply the server's base URL.
databaseIdstringrequiredSupply the database ID to copy.
headersRecord<string, string>-The downloader sends these headers on manifest and page requests.
pageSizenumber500Each page contains up to this many rows, with an integer limit from 1 to 1000.
requestTimeoutMsnumber30000The downloader limits each request to these milliseconds.
onProgress(progress: SnapshotProgress) => void-The downloader reports table and row progress through this callback.

Replication

ReplicationOptions

Pass these options to new ReplicationEngine(db, writerConn, options). See distributed replication.

OptionTypeDefaultDescription
nodeIdstringgenerated in static modeSupply a node identifier. Coordinator mode needs a stable, persisted value.
topologyTopologyrequiredThe engine applies this topology, such as PrimaryReplicaTopology.
transportReplicationTransportrequiredThe engine sends peer traffic through this transport.
transportConfigTransportConfig{}Configure peer endpoints in static mode; coordinator mode refuses endpoints.
writeForwardingbooleanfalseA replica forwards writes to the primary when true.
defaultConflictResolverConflictResolverLWWResolverThe engine resolves conflicts through this resolver by default.
conflictResolversRecord<string, ConflictResolver>-The engine applies these table-specific resolvers.
batchSizenumber100The engine sends up to this many changes per replication batch.
batchIntervalMsnumber100The engine schedules outgoing batches at this interval in milliseconds.
maxClockDriftMsnumber60000How far an incoming batch's newest timestamp may exceed the local clock. Older batches pass whatever their age.
maxPendingBatchesnumber10The engine limits in-flight batches per peer to this count.
maxBatchChangesnumber1000The engine accepts up to this many changes per inbound batch.
ackTimeoutMsnumber5000The engine waits these milliseconds for a batch acknowledgement.
initialSyncbooleantrueThe engine requests a full snapshot when joining a cluster if true.
syncBatchSizenumber10000The source sends up to this many rows per first-sync batch.
maxConcurrentSyncsnumber2The source serves up to this many simultaneous sync sessions.
maxSyncDurationMsnumber1800000The source abandons a sync after these milliseconds.
maxSyncLagBeforeReadynumber100The engine requires catch-up lag at or below this count before readiness.
syncAckTimeoutMsnumber30000The source waits these milliseconds for each sync-batch acknowledgement.
catchUpDeadlineMsnumber600000Sirannon uses this catch-up deadline in milliseconds.
resumeFromSeqbigint-The engine starts replication from this sequence after an out-of-band sync.
snapshotConnectionFactory() => Promise<SQLiteConnection>-The source calls this factory for read-only snapshot connections.
changeTrackerChangeTracker-The source uses this change tracker during first sync.
flowControl{ maxLagSeconds?, onLagExceeded? }-The engine reports replication lag through these callbacks.
onBeforeForwardedQuery(sql, params?) => void-The primary calls this validation hook before each forwarded statement.
coordinatorCoordinatorModeConfig-The engine enables coordinator-backed authority and failover with this configuration.

CoordinatorModeConfig

OptionTypeDefaultDescription
clusterIdstringrequiredThe coordinator isolates this cluster under this identifier.
groupIdstringrequiredThis identifier selects the replication group for one database.
endpointstring-The node publishes this application endpoint for client discovery.
replicationEndpointstring-The node publishes this peer address in its coordinator session.
votingDataBearingNodeIdsstring[]-The coordinator uses this voter set to create an unregistered group and calculate write concerns.
coordinatorClusterCoordinatorrequiredThe engine accesses cluster authority through this coordinator adapter.
sessionTtlMsnumber10000The node retains its session lease for these milliseconds between renewals.
controllerboolean | CoordinatorControllerConfigenabledThe engine enables the controller loop or applies the supplied controller configuration.
compatibilityCoordinatorCompatibilityMetadata-The coordinator checks these package, specification, and protocol versions before promotion.

CoordinatorControllerConfig accepts enabled, holderId, leaseTtlMs (10,000 milliseconds by default), and tickIntervalMs (1,000 milliseconds by default).

EtcdClusterCoordinatorOptions

Accepted by createEtcdCoordinator from @delali/sirannon-db/replication/coordinator/etcd.

OptionTypeDefaultDescription
hostsstring | string[]requiredSupply etcd endpoints with https unless allowInsecure is true.
keyPrefixstringrequiredThe coordinator stores this cluster's keys under this prefix.
credentialsetcd credentials-The coordinator authenticates through this root certificate, private key, and certificate chain.
authetcd auth-The coordinator authenticates through this username and password.
grpcOptionsRecord<string, unknown>-The coordinator forwards these options to the etcd gRPC channel.
dialTimeoutMsnumberThe etcd client's default.The coordinator limits connection setup to these milliseconds.
defaultCallTimeoutMsnumber-The coordinator limits each call to these milliseconds.
allowInsecurebooleanfalseThe coordinator accepts plain http endpoints when true. Restrict this setting to tests.
onWatcherError(error: Error) => void-The coordinator reports watcher failures through this callback.

TransportConfig

ReplicationEngine.start() fills in the role, the group, the term, and the protocol version. Set them yourself only when you use a ReplicationTransport without the engine.

OptionTypeDescription
endpointsstring[]The transport connects to these peers in static mode; coordinator mode refuses this list.
localRole'primary' | 'replica'The engine supplies the local topology role.
groupIdstringThe engine identifies the replication group during coordinator-mode handshakes.
primaryTermbigintThe engine supplies the current fencing term from coordinator state.
protocolVersionstringThe engine supplies this protocol version to peers.
encryptedbooleanAnnounce whether this node's database is encrypted; the engine supplies it.
metadataRecord<string, unknown>The transport receives this application metadata.

GrpcReplicationOptions

Accepted by GrpcReplicationTransport from @delali/sirannon-db/transport/grpc.

OptionTypeDefaultDescription
hoststring'0.0.0.0'The transport listens for replication traffic on this address.
portnumber0The server listens on this port. Zero takes an ephemeral one.
tlsCertstring-The transport loads this node's certificate from this path.
tlsKeystring-The transport loads this node's private key from this path.
tlsCaCertstring-The transport loads the certificate authority for peer verification from this path.
insecurebooleanfalseThe transport omits TLS when true; use that mode only in local development.
forwardDeadlineMsnumber30000The transport limits a forwarded write to these milliseconds, including the primary's wait for write concern.