Skip to content

routier-collection


routier-collection / plugins/replication/src / HttpSwrDbPluginOptions

Interface: HttpSwrDbPluginOptions ​

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:68

SWR-specific options for HttpSwrDbPlugin.

Extends ​

Properties ​

getUrl() ​

getUrl: (collectionName) => string

Defined in: plugins/replication/src/HttpDbPlugin.ts:30

Parameters ​

collectionName ​

string

Returns ​

string

Inherited from ​

HttpConnectionOptions.getUrl


databaseName? ​

optional databaseName: string

Defined in: plugins/replication/src/HttpDbPlugin.ts:40

See IDbPlugin.databaseName. getUrl is a caller-supplied function of collection name, so there is no origin this plugin can read without inventing a collection to ask about — hence a plain option with a shared default.

Set it whenever an application talks to more than one HTTP backend over the same schema: leaving both on the default makes them one database as far as subscriptions are concerned, and each would be notified of the other's writes.

Inherited from ​

HttpConnectionOptions.databaseName


getHeaders()? ​

optional getHeaders: () => Record<string, string> | Promise<Record<string, string>>

Defined in: plugins/replication/src/HttpDbPlugin.ts:42

Headers for every request (e.g. Authorization). Can be async. Re-evaluated per retry attempt.

Returns ​

Record<string, string> | Promise<Record<string, string>>

Inherited from ​

HttpConnectionOptions.getHeaders


ignoreQueryForCollections? ​

optional ignoreQueryForCollections: string[]

Defined in: plugins/replication/src/HttpDbPlugin.ts:47

Collection names for which to ignore the query and select everything. No filter, sort, skip, or take is sent; server returns full allowed set.

Inherited from ​

HttpConnectionOptions.ignoreQueryForCollections


requestTimeoutMs? ​

optional requestTimeoutMs: number

Defined in: plugins/replication/src/HttpDbPlugin.ts:49

Per-request timeout (ms); a hung connection fails instead of stalling forever. Default 30_000; 0 disables.

Inherited from ​

HttpConnectionOptions.requestTimeoutMs


minRequestIntervalMs? ​

optional minRequestIntervalMs: number

Defined in: plugins/replication/src/HttpDbPlugin.ts:58

Minimum gap between requests to the same URL (reads) or collection (writes). Default 100.

This plugin is the only place HTTP actually leaves the process, so pacing lives here: a composing plugin cannot leak past it, and an app using this plugin directly gets the same protection. Concurrent GETs for one URL collapse into a single request. 0 removes the gap; calls for one key still never overlap.

Inherited from ​

HttpConnectionOptions.minRequestIntervalMs


writeBatchDelayMs? ​

optional writeBatchDelayMs: number

Defined in: plugins/replication/src/HttpDbPlugin.ts:66

Quiet window (ms) used to batch writes to the same URL. Default 25.

Every POST accepted during the window contributes its adds/updates/removes (and opIds) to one request. The timer restarts when another write arrives, so a burst of ten saves becomes one POST rather than ten serialized POSTs. Set to 0 to disable batching.

Inherited from ​

HttpConnectionOptions.writeBatchDelayMs


translateRemoteResponse()? ​

optional translateRemoteResponse: (schema, data) => unknown

Defined in: plugins/replication/src/HttpDbPlugin.ts:68

Parameters ​

schema ​

CompiledSchema<UnknownRecord>

data ​

unknown

Returns ​

unknown

Inherited from ​

HttpConnectionOptions.translateRemoteResponse


autoSync? ​

optional autoSync: boolean | AutoSyncOptions

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:77

Background sync policy. Omit for the automatic default (retry on a backing-off timer plus an immediate flush when connectivity returns), pass an object to tune it, or pass false to turn it off entirely and drive syncNow() yourself.

Turning it off does not turn off queueing — changes are still recorded durably before every ack. It only means nothing replays them until you ask.


postOnPersist? ​

optional postOnPersist: boolean

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:94

Whether a save also POSTs immediately, or is left to the batching flush. Default true.

true is the low-latency path: the write enters HttpDbPlugin's short batching window immediately, and its response can be reconciled through translatePersistResponse. Rapid writes to the same URL share one POST by default (writeBatchDelayMs controls the window), while an isolated write pays only that short delay.

false acknowledges locally, records the change durably as always, and leaves delivery to the paced queue flush — one request per collection per flush, however many saves went into it. This adds up to autoSync.delayMs of latency and skips echo reconciliation (the flush has no schema to translate with), but is useful when delivery should happen only on the background/manual sync cadence.

With autoSync: false as well, nothing is delivered until you call syncNow().


maxAgeMs? ​

optional maxAgeMs: number

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:96

Max time (ms) to consider cache fresh; after this, the next read triggers a background revalidate. Default 60_000.


conditionalRevalidation? ​

optional conditionalRevalidation: boolean

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:97


translatePersistResponse()? ​

optional translatePersistResponse: (schema, responseBody) => unknown[]

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:103

Reconciles the POST response into the SWR store: given the response body, return the canonical entities the server echoed (or null to skip). Fixes server-assigned ids and timestamps drifting from the optimistic local copy.

Parameters ​

schema ​

CompiledSchema<UnknownRecord>

responseBody ​

unknown

Returns ​

unknown[]


unsyncedQueueStore ​

unsyncedQueueStore: IDbPlugin

Defined in: plugins/replication/src/HttpSwrDbPlugin.ts:111

IDbPlugin to use for persisting the unsynced queue (e.g. same as swrStore). No datastore required. The queue is stored via query/bulkPersist in a reserved collection (_routier_unsynced).

Required: UnsyncedQueue has no default store. Pass a durable plugin to survive a refresh with unsynced items intact, or a MemoryPlugin to accept losing them.


onEvent()? ​

optional onEvent: (event) => void

Defined in: plugins/replication/src/syncHooks.ts:59

Parameters ​

event ​

SyncEvent

Returns ​

void

Inherited from ​

SyncHooks.onEvent


onError()? ​

optional onError: (error) => void

Defined in: plugins/replication/src/syncHooks.ts:60

Parameters ​

error ​

SwrRequestError

Returns ​

void

Inherited from ​

SyncHooks.onError

Released under the MIT License.