@cero-base/cero 2.11.0 → 2.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cero-base/cero",
3
- "version": "2.11.0",
3
+ "version": "2.12.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,
@@ -113,7 +113,7 @@
113
113
  "test:node": "find test -name '*.test.js' | sort | xargs -P4 -n1 brittle-node"
114
114
  },
115
115
  "dependencies": {
116
- "@cero-base/core": "^2.11.0",
116
+ "@cero-base/core": "^2.12.0",
117
117
  "b4a": "^1.9.0",
118
118
  "bare-abort-controller": "^1.1.2",
119
119
  "bare-crypto": "^1.15.4",
@@ -25,7 +25,8 @@ export async function mirror(from, row, fields, to, id) {
25
25
  const prev = idOf(was[k])
26
26
  if (!file) {
27
27
  out[k] = row[k]
28
- changed ||= was[k] !== row[k]
28
+ // a field the source never set is the null the row reads back
29
+ changed ||= (was[k] ?? null) !== (row[k] ?? null)
29
30
  } else if (prev && (await get(to.handle.files, prev)).data?.from === file) {
30
31
  out[k] = prev
31
32
  } else {
@@ -406,6 +406,11 @@ export class Handle extends ReadyResource {
406
406
  return this.store.rotate()
407
407
  }
408
408
 
409
+ /** @private */
410
+ _removed(id) {
411
+ return this.store.removed(id)
412
+ }
413
+
409
414
  // the same context, its refs writing into one batch; a fn that ignores it would write outside
410
415
  /** @private */
411
416
  async _tx(fn) {
@@ -417,6 +417,19 @@ export function deny(ctx, request, reason = '') {
417
417
  return ctx._answer(request.id, { accept: false, reason })
418
418
  }
419
419
 
420
+ /**
421
+ * Whether a member is out of a handle for good, as this device has seen it: `'removed'` by another
422
+ * member, `'left'` on her own, or null while she is a member, never was one, or her going has not
423
+ * reached this device. Someone let in again after is a member: null.
424
+ *
425
+ * @param {Context} ctx
426
+ * @param {string} id The member's id.
427
+ * @returns {Promise<'removed' | 'left' | null>}
428
+ */
429
+ export function removed(ctx, id) {
430
+ return ctx._removed(id)
431
+ }
432
+
420
433
  /**
421
434
  * Quit a handle for good: it leaves your list and closes on this device.
422
435
  *
package/src/rpc/client.js CHANGED
@@ -29,6 +29,7 @@ export const {
29
29
  accept,
30
30
  deny,
31
31
  leave,
32
+ removed,
32
33
  close,
33
34
  cancel,
34
35
  suspend,
@@ -365,6 +366,11 @@ const operators = {
365
366
  await this.rpc.leave({ handle: this.id })
366
367
  },
367
368
 
369
+ /** @private */
370
+ _removed(id) {
371
+ return this._verb('removed', id)
372
+ },
373
+
368
374
  /** @private */
369
375
  _cancel(invite) {
370
376
  return this._verb('cancel', invite)
package/src/rpc/server.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  invite,
16
16
  revoke,
17
17
  rotate,
18
+ removed,
18
19
  accept,
19
20
  deny,
20
21
  cancel,
@@ -35,6 +36,7 @@ const VERBS = new Map(
35
36
  invite,
36
37
  revoke,
37
38
  rotate,
39
+ removed,
38
40
  accept,
39
41
  deny,
40
42
  cancel,
@@ -42,6 +42,7 @@ export declare const cero: {
42
42
  deny(ctx: operators.Context, request: {
43
43
  id: string;
44
44
  }, reason?: string): Promise<void>;
45
+ removed(ctx: operators.Context, id: string): Promise<'removed' | 'left' | null>;
45
46
  leave(ctx: operators.Context): Promise<void>;
46
47
  close(ctx: operators.Context): Promise<void>;
47
48
  cancel(me: operators.Context, code: string): Promise<boolean>;
@@ -282,6 +282,8 @@ export declare class Handle extends ReadyResource {
282
282
  /** @private */
283
283
  private _rotate;
284
284
  /** @private */
285
+ private _removed;
286
+ /** @private */
285
287
  private _tx;
286
288
  /** @private */
287
289
  private _leave;
@@ -177,6 +177,16 @@ export declare function accept(ctx: Context, request: {
177
177
  export declare function deny(ctx: Context, request: {
178
178
  id: string;
179
179
  }, reason?: string): Promise<void>;
180
+ /**
181
+ * Whether a member is out of a handle for good, as this device has seen it: `'removed'` by another
182
+ * member, `'left'` on her own, or null while she is a member, never was one, or her going has not
183
+ * reached this device. Someone let in again after is a member: null.
184
+ *
185
+ * @param {Context} ctx
186
+ * @param {string} id The member's id.
187
+ * @returns {Promise<'removed' | 'left' | null>}
188
+ */
189
+ export declare function removed(ctx: Context, id: string): Promise<'removed' | 'left' | null>;
180
190
  /**
181
191
  * Quit a handle for good: it leaves your list and closes on this device.
182
192
  *
@@ -34,6 +34,7 @@ declare const remote: {
34
34
  deny(ctx: verbs.Context, request: {
35
35
  id: string;
36
36
  }, reason?: string): Promise<void>;
37
+ removed(ctx: verbs.Context, id: string): Promise<'removed' | 'left' | null>;
37
38
  leave(ctx: verbs.Context): Promise<void>;
38
39
  close(ctx: verbs.Context): Promise<void>;
39
40
  cancel(me: verbs.Context, code: string): Promise<boolean>;
@@ -64,7 +65,7 @@ declare const remote: {
64
65
  topic?: string;
65
66
  }): Promise<void>;
66
67
  };
67
- export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
68
+ export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, removed: typeof verbs.removed, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
68
69
  export { t, schema };
69
70
  export type BaseRPCClient = import('@cero-base/core/rpc').RPCClient;
70
71
  export type RefInfo = import('../lib/spec.js').RefInfo;