ORMap
Esta página aún no está disponible en tu idioma.
Defined in: src/crdt/ORMap.ts:50
Conflict-free Replicated Data Type — a value that converges under
replication without coordination. Every implementation is a
state-based CvRDT: replicas exchange full state, and merge
forms a join-semilattice.
Three properties every implementation must satisfy — tests/unit/crdt
verifies them by hand-rolled property tests against generated samples:
- Idempotent:
merge(a, a) === a - Commutative:
merge(a, b) === merge(b, a) - Associative:
merge(merge(a, b), c) === merge(a, merge(b, c))
Together these mean: gossip can deliver state updates in any order, deduplicate, retransmit, and the world converges as long as every replica eventually sees every state.
Why state-based and not delta-state. Delta-CRDTs ship only the incremental change rather than the full state — much cheaper on the wire, but the implementation has more moving parts and you need delta acknowledgement protocols. State-based is the simplest thing that converges; we ship it first and revisit if payload size hurts.
Type Parameters
Section titled “Type Parameters”K
The concrete CRDT type. F-bounded so subclass
merge keeps the right return type without casting at every call
site.
V extends Crdt<V>
Implements
Section titled “Implements”Crdt<ORMap<K,V>>
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/crdt/ORMap.ts:146
Returns
Section titled “Returns”number
Methods
Section titled “Methods”entriesArray()
Section titled “entriesArray()”entriesArray(): readonly readonly [
K,V][]
Defined in: src/crdt/ORMap.ts:138
Snapshot of [key, value] pairs.
Returns
Section titled “Returns”readonly readonly [K, V][]
equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/crdt/ORMap.ts:225
Parameters
Section titled “Parameters”ORMap<K, V>
Returns
Section titled “Returns”boolean
get(
key):V|undefined
Defined in: src/crdt/ORMap.ts:118
Read key — undefined if not present.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”V | undefined
has(
key):boolean
Defined in: src/crdt/ORMap.ts:124
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
keys()
Section titled “keys()”keys(): readonly
K[]
Defined in: src/crdt/ORMap.ts:129
Snapshot of currently-live keys.
Returns
Section titled “Returns”readonly K[]
merge()
Section titled “merge()”merge(
other):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:152
Join two replicas. Must be a join-semilattice operation: total, idempotent, commutative, associative.
Parameters
Section titled “Parameters”ORMap<K, V>
Returns
Section titled “Returns”ORMap<K, V>
Implementation of
Section titled “Implementation of”put(
replica,key,value):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:78
Set key to value on replica.
Parameters
Section titled “Parameters”replica
Section titled “replica”string
K
V
Returns
Section titled “Returns”ORMap<K, V>
remove()
Section titled “remove()”remove(
key):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:111
Remove key. Concurrent puts with tags this remove never saw
survive — keyset-level OR-Set semantics decide liveness. We keep
the value entry around even after a remove because a future merge
with a peer that re-added the key needs both sides’ inner-CRDT
state to compute the right merged value (associativity demands
it; without it, merge(a, b).merge(c) can drop state that
merge(a, merge(b, c)) would preserve). Read APIs filter by
keyset so stale entries are invisible to users.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”ORMap<K, V>
toJSON()
Section titled “toJSON()”toJSON():
ORMapJson
Defined in: src/crdt/ORMap.ts:177
Wire-friendly representation — every CRDT must be JSON-encodable
so it can travel through the cluster transport without bespoke
codecs. toJSON() is the inverse of the static fromJSON
factory each impl exposes.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”update()
Section titled “update()”update(
replica,key,factory,mutator):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:93
Mutate the value under key in place (functionally — returns a
new map). If the key doesn’t exist yet, factory() provides the
empty CRDT. Equivalent to put(replica, key, mutator(get(key) ?? factory()))
but with a single re-tag, so concurrent update + remove
resolves the same as concurrent put + remove would.
Parameters
Section titled “Parameters”replica
Section titled “replica”string
K
factory
Section titled “factory”() => V
mutator
Section titled “mutator”(current) => V
Returns
Section titled “Returns”ORMap<K, V>
empty()
Section titled “empty()”
staticempty<K,V>(options?):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:69
Type Parameters
Section titled “Type Parameters”K
V extends Crdt<V>
Parameters
Section titled “Parameters”options?
Section titled “options?”ORMapOptions<K> = {}
Returns
Section titled “Returns”ORMap<K, V>
fromJSON()
Section titled “fromJSON()”
staticfromJSON<K,V>(json,decodeValue,options?):ORMap<K,V>
Defined in: src/crdt/ORMap.ts:202
Reconstruct an ORMap. decodeValue must build the inner CRDT
from its JSON shape — typically (json) => SomeCrdt.fromJSON(json).
The DistributedData extension provides a decodeCrdt that
dispatches across every registered CRDT kind.
Type Parameters
Section titled “Type Parameters”K
V extends Crdt<V>
Parameters
Section titled “Parameters”decodeValue
Section titled “decodeValue”(json) => V
options?
Section titled “options?”ORMapOptions<K> = {}
Returns
Section titled “Returns”ORMap<K, V>
