@cero-base/cero 1.6.0 → 1.7.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.
Files changed (2) hide show
  1. package/README.md +51 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -234,6 +234,57 @@ self-heal — a `del` without an explicit `rotate` triggers an automatic re-key
234
234
  from any online admin device. Standalone rotations (no removal) are valid too,
235
235
  as periodic key hygiene. Full design: [`docs/key-rotation.md`](../../docs/key-rotation.md).
236
236
 
237
+ ### Watching removals
238
+
239
+ There is no separate removal event — `members` is a collection, so the normal
240
+ streams already are the membership feed. A removal arrives as an ordinary
241
+ delete (`next: null`), carrying the row that was removed:
242
+
243
+ ```js
244
+ for await (const { changes } of cero.changes(room.members)) {
245
+ for (const { prev, next } of changes) {
246
+ if (next === null) console.log('removed:', prev.name)
247
+ }
248
+ }
249
+ ```
250
+
251
+ To detect **your own** removal — the signal an app renders as "you were removed
252
+ from this room" — listen for the store losing writability:
253
+
254
+ ```js
255
+ room.store.on('unwritable', () => onRemoved()) // freeze the UI, close the room
256
+ ```
257
+
258
+ This works even when the removal is followed by a rotation: the removal lands
259
+ before the new key, so a removed member always receives it. After that their
260
+ streams stay open but go silent — reads freeze at the moment of removal and
261
+ writes reject with `NOT_WRITABLE`.
262
+
263
+ ### Store events
264
+
265
+ Beyond the ref streams, the store reports its own lifecycle:
266
+
267
+ ```js
268
+ room.store.on('writable', () => {}) // admitted — this device can write
269
+ room.store.on('unwritable', () => {}) // access ended (removed)
270
+ room.store.on('update', () => {}) // an apply batch committed
271
+ room.store.on('behind', (v) => {}) // ops from a newer app version — see below
272
+ room.store.on('rebuild', () => {}) // view replayed after catching up
273
+ ```
274
+
275
+ `before`/`after` hooks only fire on the device performing the write. To observe
276
+ **every** applied op — local _and_ replicated — use `onApply`, which returns an
277
+ unsubscribe fn:
278
+
279
+ ```js
280
+ const off = room.store.onApply(({ op, name, row, writerKey, seq }) => {
281
+ if (op === 'del' && name === 'member') auditLog(row)
282
+ })
283
+ ```
284
+
285
+ The callback runs synchronously inside apply, so keep it cheap — enqueue and
286
+ return. It costs nothing when nobody is subscribed.
287
+
237
288
  ### `cero.before(ref, fn, opts?)` / `cero.after(ref, fn, opts?)`
238
289
 
239
290
  Hook into writes to a ref. `before` runs **in-path** before the write commits — return `false` to cancel, or mutate `ctx.row`. `after` is a non-blocking **event** that fires once the write has committed. Both return an unsubscribe fn — call it to stop early, ignore it for a subscription that lives as long as the handle, or pass `{ signal }` to unsubscribe when an `AbortSignal` fires (e.g. `{ signal: me.signal }` to stop on close).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cero-base/cero",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "The ideal p2p API — everything is a handle, handles contain refs, refs contain rows.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "test:node": "ls test/*.test.js | xargs -P1 -n1 brittle-node"
96
96
  },
97
97
  "dependencies": {
98
- "@cero-base/core": "^1.6.0",
98
+ "@cero-base/core": "^1.7.0",
99
99
  "b4a": "^1.8.1",
100
100
  "bare-abort-controller": "^1.1.2",
101
101
  "bare-crypto": "^1.15.3",