TypedCrdtTable class final

The layer that gives OrSet and PnCounter fields their merge semantics, wrapping any CrdtTable.

The inner engine stays a plain last-write-wins record store; this decorator keeps a typed field's CRDT state in the record value and translates at the boundary:

  • Writes. put with an OrSet type takes the desired membership (a list) and folds it into the stored state — fresh unique tags for added elements, tombstones for the visible tags of removed ones. put with a PnCounter type only seeds a new counter (from a starting number); changing an existing counter's value through put throws ArgumentError — use increment, which folds a signed delta into this node's sub-counter.
  • Reads. value and liveFields resolve a typed state back to its logical value: the live elements for a set, sum(p) - sum(n) for a counter. Callers never see the internal state.
  • Merges. merge intercepts an incoming typed record when a local one exists and combines the two states (union of adds and tombstones for a set, element-wise maximum of the sub-counters for a counter) instead of letting the higher HLC win. A merge that adds nothing writes nothing, so converged replicas go quiescent.

Typed states are self-describing — they carry their type in a reserved __t key — so they survive an engine or a peer that does not store the crdt_type tag, and merge can dispatch without a side table. A document value that is itself a map with a __t key holding 'or_set' or 'pn_counter' would be misread as a typed state; treat __t as a reserved field name.

LwwRegister records (the default) pass through untouched, so an untyped collection behaves exactly as it would on the bare engine.

Collection wraps its engine in this decorator automatically; it is public on the advanced library for engine authors and tests.

Implemented types

Constructors

TypedCrdtTable(CrdtTable inner)
Wraps inner. Wrapping an already wrapped table is redundant but harmless — every layer applies the same translation to already canonical states.

Properties

hashCode → int
The hash code for this object.
no setterinherited
inner → CrdtTable
The wrapped engine, for callers that need engine-specific state (tests).
no setter
isPersistent → bool
Whether this table owns its own durability.
no setteroverride
nodeId → String
The identifier of this replica, as stamped into the node component of the HLCs this table generates.
no setteroverride
recoveries → Stream<CrdtRecovery>
Emits once if init found the local store unreadable and rebuilt it (from an on-disk snapshot, or empty).
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

atomically(Future<void> writes()) → Future<void>
The inner table's AtomicCrdtTable.atomically when it has one; the writes in turn otherwise.
changeset(String table, {String? sinceHlc, String? untilHlc}) → Future<CrdtChangeset>
Returns records in table in CrdtChangeset format.
override
close() → Future<void>
Releases resources (a disk-backed engine closes its file). The default is a no-op. Called by Collection.dispose.
override
compact(String table, {required Duration horizon}) → Future<int>
Permanently removes tombstoned records whose wall-clock time is older than horizon and returns the number of reclaimed records.
override
docFields(String table, Iterable<String> docIds) → Future<Map<String, Map<String, Object?>>>
The live field rows of the given documents, grouped by document id and keyed by bare field path (the portion of the record key after the "$docId\x1F" separator). Existence registers are not included; a document with no live field rows is absent from the result.
override
ensureQueryIndex(String table, String fieldPath) → Future<void>
Prepares an index for equality lookups on fieldPath in table, so a QueryOp.equals predicate on that path does not scan the table.
override
increment(String table, String key, num by) → Future<void>
Folds a signed by into this node's sub-counter of the PnCounter record at table/key, creating the counter (at 0 + by) if the record does not exist yet.
init() → Future<void>
Initialises the inner table once; later calls return the same future. A table may be initialised early to probe its key (see Database), and the collection that adopts it initialises it again.
override
liveFields(String table, String prefix) → Future<Map<String, Object?>>
Returns all live (non-tombstoned) records in table whose key starts with prefix, as a flat map of key → value.
override
liveKeys(String table, String prefix) → Set<String>
All live (non-tombstoned) keys in table whose key starts with prefix.
override
maxHlc(String table) → String
The highest HLC seen in table as a string, or the empty string when the table is empty.
override
merge(CrdtChangeset changeset) → Future<void>
Merges a CrdtChangeset received from a peer or loaded from storage.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String table, String key, Object? value, {bool isDeleted = false, CrdtType crdtType = const LwwRegister()}) → Future<void>
Writes or tombstones the record identified by table/key.
override
queryDocIds(String table, QuerySpec spec) → Future<List<QueryRow>>
Returns the ids of the live documents in table that satisfy spec, in the spec's total order — (order-by value, document id) — windowed by its limit and cursor.
override
rangeDigest(String table, {String? fromHlc, String? toHlc}) → Future<RangeDigest>
Summarises the records of table whose HLC lies in the half-open range (fromHlc, toHlc] (a null bound is open): how many there are, the XOR fingerprint of their identities, and the range's lowest and highest HLCs.
override
recordHlc(String table, String key) → Future<String?>
The stored HLC string of the record at table/key — tombstoned or live — or null when no record exists.
override
rekey(List<int> newKey) → Future<void>
Re-encrypts the store at rest under newKey, keeping all data.
override
toString() → String
A string representation of this object.
inherited
value(String table, String key) → Future<Object?>
Returns the live value for key in table, or null if absent or tombstoned.
override
watch(String table) → Stream<void>
A broadcast stream that emits whenever any record in table changes.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited