Перейти к содержимому
Русский

ORMap

Это содержимое пока не доступно на вашем языке.

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.

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>

get size(): number

Defined in: src/crdt/ORMap.ts:146

number

entriesArray(): readonly readonly [K, V][]

Defined in: src/crdt/ORMap.ts:138

Snapshot of [key, value] pairs.

readonly readonly [K, V][]


equals(other): boolean

Defined in: src/crdt/ORMap.ts:225

ORMap<K, V>

boolean


get(key): V | undefined

Defined in: src/crdt/ORMap.ts:118

Read keyundefined if not present.

K

V | undefined


has(key): boolean

Defined in: src/crdt/ORMap.ts:124

K

boolean


keys(): readonly K[]

Defined in: src/crdt/ORMap.ts:129

Snapshot of currently-live keys.

readonly K[]


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.

ORMap<K, V>

ORMap<K, V>

Crdt.merge


put(replica, key, value): ORMap<K, V>

Defined in: src/crdt/ORMap.ts:78

Set key to value on replica.

string

K

V

ORMap<K, V>


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.

K

ORMap<K, V>


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.

ORMapJson

Crdt.toJSON


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.

string

K

() => V

(current) => V

ORMap<K, V>


static empty<K, V>(options?): ORMap<K, V>

Defined in: src/crdt/ORMap.ts:69

K

V extends Crdt<V>

ORMapOptions<K> = {}

ORMap<K, V>


static fromJSON<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.

K

V extends Crdt<V>

ORMapJson

(json) => V

ORMapOptions<K> = {}

ORMap<K, V>