SyncResourceAdapter

Resource-specific glue for the generic loop in SyncEngine. Implement one of these (plus the wire DTO mapping) to make a new resource syncable — the contract logic (ack guard, pending guard, full-snapshot reconciliation, pagination drain, fullResyncRequired) lives in the engine, not here, so it holds identically for every resource.

Type Parameters

E

entity type (carries SyncableEntity bookkeeping)

U

upsert DTO, D delete DTO, C server-change DTO

Properties

Link copied to clipboard
abstract val resourceName: String

Functions

Link copied to clipboard
abstract suspend fun activeRows(): List<E>

Active (non-deleted) rows, for full-snapshot tombstone reconciliation.

Link copied to clipboard
abstract suspend fun api(request: SyncRequest<U, D>): SyncResponse<C>
Link copied to clipboard
abstract fun changeKey(change: C): String
Link copied to clipboard
abstract suspend fun findExisting(change: C): E?
Link copied to clipboard
abstract fun isChangeDeleted(change: C): Boolean
Link copied to clipboard
abstract suspend fun pending(): List<E>
Link copied to clipboard
abstract suspend fun purgeSynced()

Drop clean synced rows for fullResyncRequired.

Link copied to clipboard
abstract suspend fun reload(entity: E): E?

Re-read the row for the ack guard (detects edits made during the in-flight request).

Link copied to clipboard
abstract fun syncKey(entity: E): String

Canonical business key; MUST equal the server's applied[].key and changeKey.

Link copied to clipboard
abstract fun toDelete(entity: E): D
Link copied to clipboard
abstract fun toEntity(change: C, existing: E?): E
Link copied to clipboard
abstract fun toUpsert(entity: E): U
Link copied to clipboard
abstract suspend fun upsert(entity: E)
Link copied to clipboard
open suspend fun upsertAll(entities: List<E>)

Writes a batch of rows produced from one ack set, one page of server changes, or one tombstone sweep. The default calls upsert per row; override it to write the batch in a single database transaction. The engine reads rows before calling this method, so a transaction around these writes alone does not make its guards atomic with concurrent local edits. Adapters must also enforce conditional writes against the current local version when local editing can race sync persistence.