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.atomicallywhen it has one; the writes in turn otherwise. -
changeset(
String table, {String? sinceHlc, String? untilHlc}) → Future< CrdtChangeset> -
Returns records in
tableinCrdtChangesetformat.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
horizonand 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
fieldPathintable, so aQueryOp.equalspredicate on that path does not scan the table.override -
increment(
String table, String key, num by) → Future< void> -
Folds a signed
byinto this node's sub-counter of the PnCounter record attable/key, creating the counter (at0 + 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
tablewhose key starts withprefix, as a flat map of key → value.override -
liveKeys(
String table, String prefix) → Set< String> -
All live (non-tombstoned) keys in
tablewhose key starts withprefix.override -
maxHlc(
String table) → String -
The highest HLC seen in
tableas a string, or the empty string when the table is empty.override -
merge(
CrdtChangeset changeset) → Future< void> -
Merges a
CrdtChangesetreceived 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
tablethat satisfyspec, 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
tablewhose HLC lies in the half-open range(fromHlc, toHlc](anullbound 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 — ornullwhen 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
keyintable, ornullif absent or tombstoned.override -
watch(
String table) → Stream< void> -
A broadcast stream that emits whenever any record in
tablechanges.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited