Plain operations: last write wins, hash-keyed events, simpler composite
CI / Node 22 (pull_request) Successful in 12s
CI / Node 26 (pull_request) Successful in 13s
CI / Node 24 (pull_request) Successful in 14s

- KV: one write primitive, write(changes) with { key, value? }; writeIfAbsent removed.
  The server executes exactly what clients send and never reads values, so they can be
  encrypted end to end. Adds setFields/getFields on the base class.
- HTTP: no server history or event ids; SSE relays every change (own writes included) and
  the client emits resync when a dropped stream reconnects.
- Composite: writes apply locally, then go to the source (undone locally if refused);
  pushed changes are applied and announced only where they differ from local values;
  offline writes go to a queue store (any KV storage); sync() = replay, diff, replay.
  Removes KVReplicaSet, KVOutbox, KeyCounter, SerialQueue and RetryTimer.
- Events: id = <time>_<sha256(time + canonical data)>, so concurrent appends never
  collide and retries can't duplicate; no versions or ConcurrencyError.
- Event-sourced documents: read, resolve, append, apply; catchUp folds in foreign events;
  getAt takes an event id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
This commit is contained in:
Claude
2026-10-23 13:33:07 +00:00
parent 1f82ec9110
commit 631c75428b
34 changed files with 814 additions and 1387 deletions
+5 -11
View File
@@ -1,4 +1,4 @@
import { BaseKVStorage, type ScanOptions } from '../src/kv-storage/base-kv-storage.js'
import { BaseKVStorage, type KVChange, type ScanOptions } from '../src/kv-storage/base-kv-storage.js'
import { KVStorageInMemory } from '../src/kv-storage/kv-storage-in-memory.js'
export async function collect<T>(iterable: AsyncIterable<T>): Promise<T[]> {
@@ -9,8 +9,8 @@ export async function collect<T>(iterable: AsyncIterable<T>): Promise<T[]> {
/**
* Wraps another KV storage and counts primitive calls. Also shows the wrapper pattern
* (e.g. an encryption layer): extend BaseKVStorage and delegate the five primitives.
* Counts are reported under the public method names (writeMany, removeMany, writeIfAbsent).
* (e.g. an encryption layer): extend BaseKVStorage and delegate the three primitives.
* Writes are counted as `writeMany`.
*/
export class KVStorageCounting extends BaseKVStorage {
calls: Record<string, number> = {}
@@ -26,14 +26,8 @@ export class KVStorageCounting extends BaseKVStorage {
readMany(keys: string[]) {
return this.count('readMany', () => this.inner.readMany(keys))
}
protected applyWrite(entries: [string, unknown][]) {
return this.count('writeMany', () => this.inner.writeMany(entries))
}
protected applyRemove(keys: string[]) {
return this.count('removeMany', () => this.inner.removeMany(keys))
}
protected applyWriteIfAbsent(entries: [string, unknown][]) {
return this.count('writeIfAbsent', () => this.inner.writeIfAbsent(entries))
protected write(changes: KVChange[]) {
return this.count('writeMany', () => this.inner.writeMany(changes))
}
scan(options?: ScanOptions) {
return this.count('scan', () => this.inner.scan(options))