@cero-base/cero 1.16.1 → 1.17.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": "1.16.1",
3
+ "version": "1.17.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.16.1",
98
+ "@cero-base/core": "^1.17.0",
99
99
  "b4a": "^1.8.1",
100
100
  "bare-abort-controller": "^1.1.2",
101
101
  "bare-crypto": "^1.15.3",
@@ -15,11 +15,11 @@ export const main = {
15
15
  sig: required(bytes),
16
16
  isIndexer: bool,
17
17
  ts: int,
18
- // Who this writer belongs to, and at what rank. Admission carries its own
19
- // authorization so add-writer can refuse exactly when the paired
20
- // add-member would the two apply independently, so without this a
21
- // refused grant still leaves an admitted writer behind. Absent on a
22
- // device you add for yourself (bootstrap), where there is nothing to cap.
18
+ // Who this writer belongs to. The paired add-member decides the rank in
19
+ // the same transaction, and a refused grant discards this admission with
20
+ // itso `role` is unread since 77e5ed0 and stays only for older peers.
21
+ // Absent on a device you add for yourself (recovery), where the device
22
+ // binds to the master identity.
23
23
  memberId: string,
24
24
  role: string
25
25
  },
@@ -598,11 +598,9 @@ export class Handle extends ReadyResource {
598
598
  sig,
599
599
  master: this.identity.publicKey,
600
600
  writer: writerKey,
601
- // admission carries who and at what rank, so a grant we cannot make
602
- // admits nobody — the two ops apply independently and cannot roll
603
- // each other back
601
+ // the device binds to the joiner; add-member in the same transaction
602
+ // decides the rank, and a refusal discards both
604
603
  memberId: member.id,
605
- role,
606
604
  ts: member.updatedAt || Date.now()
607
605
  })
608
606
  await tx.call('add-member', member)
@@ -684,21 +682,25 @@ export class Handle extends ReadyResource {
684
682
 
685
683
  const ts = Date.now()
686
684
  const writerKey = child.store.writerKey
687
- await child.store.call('add-writer', {
688
- master: this.identity.publicKey,
689
- writer: writerKey,
690
- sig: this.identity.sign(
691
- addWriterPayload(child.store.key, writerKey, child.store.writerKey)
692
- ),
693
- ts
694
- })
695
- await child.store.call('add-member', {
696
- id: this.identity.id,
697
- key: writerKey,
698
- role: 'owner',
699
- name: null,
700
- createdAt: ts,
701
- updatedAt: ts
685
+ // admit the core and seat the owner in one append — the same shape as
686
+ // accept(), so a room's first two ops land together like every later pair
687
+ await child.store.tx(async (tx) => {
688
+ await tx.call('add-writer', {
689
+ master: this.identity.publicKey,
690
+ writer: writerKey,
691
+ sig: this.identity.sign(
692
+ addWriterPayload(child.store.key, writerKey, child.store.writerKey)
693
+ ),
694
+ ts
695
+ })
696
+ await tx.call('add-member', {
697
+ id: this.identity.id,
698
+ key: writerKey,
699
+ role: 'owner',
700
+ name: null,
701
+ createdAt: ts,
702
+ updatedAt: ts
703
+ })
702
704
  })
703
705
  await this.store.call('add-handle', {
704
706
  id,