@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 +8 -8
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/_moon_flock.d.ts +3 -3
- package/src/_moon_flock.ts +1128 -1114
- package/src/index.ts +40 -46
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
|
|
23
|
-
const peerId = crypto.
|
|
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
|
|
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?:
|
|
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:
|
|
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:
|
|
82
|
-
- `peerId():
|
|
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
|
|