@loro-dev/flock 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,8 +19,8 @@ The library ships ESM, CommonJS, and TypeScript declaration files. It has no run
19
19
  ```ts
20
20
  import { Flock } from "@loro-dev/flock";
21
21
 
22
- // Each replica uses a stable 32-byte peer id to maintain version vectors.
23
- const peerId = crypto.getRandomValues(new Uint8Array(32));
22
+ // Each replica uses a stable UTF-8 peer id (<128 bytes) to maintain version vectors.
23
+ const peerId = crypto.randomUUID();
24
24
  const store = new Flock(peerId);
25
25
 
26
26
  store.put(["users", "42"], { name: "Ada", online: true });
@@ -59,7 +59,7 @@ unsubscribe();
59
59
  - `KeyPart`: `string | number | boolean`. Keys are arrays of parts (e.g. `["users", 42]`). Invalid keys raise at runtime.
60
60
  - `ExportRecord`: `{ c: string; d?: Value }` – CRDT payload with hybrid logical clock data.
61
61
  - `ExportBundle`: `Record<string, ExportRecord>` mapping composite keys to last-writer metadata.
62
- - `VersionVector`: `Record<string, { physicalTime: number; logicalCounter: number }>` indexed by hex peer identifiers.
62
+ - `VersionVector`: `Record<string, { physicalTime: number; logicalCounter: number }>` indexed by peer identifiers (UTF-8 strings ordered by their byte representation).
63
63
  - `ScanRow`: `{ key: KeyPart[]; raw: ExportRecord; value?: Value }` returned by `scan()`.
64
64
  - `EventBatch`: `{ source: string; events: Array<{ key: KeyPart[]; value?: Value }> }` emitted to subscribers.
65
65
 
@@ -69,17 +69,17 @@ All types are exported from the package entry point for use in TypeScript projec
69
69
 
70
70
  ### Constructor
71
71
 
72
- `new Flock(peerId?: Uint8Array)` – creates a replica. When omitted, a random 256-bit peer id is generated. The id persists only in memory; persist it yourself for durable replicas.
72
+ `new Flock(peerId?: string)` – creates a replica. When omitted, a random 64-character hex peer id is generated. The id persists only in memory; persist it yourself for durable replicas.
73
73
 
74
74
  ### Static Members
75
75
 
76
- - `Flock.fromJson(bundle: ExportBundle, peerId: Uint8Array): Flock` – instantiate directly from a full snapshot bundle.
76
+ - `Flock.fromJson(bundle: ExportBundle, peerId: string): Flock` – instantiate directly from a full snapshot bundle.
77
77
  - `Flock.checkConsistency(a: Flock, b: Flock): boolean` – deep equality check useful for tests; returns `true` when both replicas expose the same key/value pairs and metadata.
78
78
 
79
79
  ### Replica Management
80
80
 
81
- - `setPeerId(peerId: Uint8Array): void` – replace the current peer id. Use cautiously; changing ids affects causality tracking.
82
- - `peerId(): Uint8Array` – returns the 32-byte identifier for the replica.
81
+ - `setPeerId(peerId: string): void` – replace the current peer id. Use cautiously; changing ids affects causality tracking.
82
+ - `peerId(): string` – returns the identifier for the replica.
83
83
  - `getMaxPhysicalTime(): number` – highest physical timestamp observed by this replica (same units as the timestamps you pass to `now`, e.g. `Date.now()` output). Helpful for synchronising clocks and diagnosing divergence.
84
84
  - `version(): VersionVector` – current version vector including logical counters per peer.
85
85
  - `checkInvariants(): void` – throws if internal CRDT invariants are violated. Intended for assertions in tests or diagnostics, not for production control flow.
@@ -109,7 +109,7 @@ All types are exported from the package entry point for use in TypeScript projec
109
109
 
110
110
  ### Events
111
111
 
112
- - `subscribe(listener: (batch: EventBatch) => void): () => void` – register for mutation batches. Each callback receives the `source` ("local" for writes on this replica, peer id for remote batches when available) and an ordered list of events. Return value unsubscribes the listener.
112
+ - `subscribe(listener: (batch: EventBatch) => void): () => void` – register for mutation batches. Each callback receives the `source` ("local" for writes on this replica, peer id string for remote batches when available) and an ordered list of events. Return value unsubscribes the listener.
113
113
 
114
114
  ### Utilities
115
115