| … | … | @@ -0,0 +1,83 @@ |
| 1 | # hyper-rooms |
| 2 | |
| 3 | Multi-writer "rooms" built on Autobase + Hyperbee view, with pluggable |
| 4 | schemas. The substrate under `hyper-issues`, `hyper-orgs`, and any other |
| 5 | "one autobase per namespace" use case in the hyper-fleeky stack. |
| 6 | |
| 7 | ## What you get |
| 8 | |
| 9 | - One Autobase per room (keet-pattern config: `optimistic: true, |
| 10 | ackInterval: 1000, ackThreshold: 4`). |
| 11 | - Hyperbee view, schema-driven apply. |
| 12 | - Generic `addWriter` / `removeWriter` / `listWriters` / `ackWriter` API. |
| 13 | - Pattern B writer registration (no pinned keyPair — corestore-derived |
| 14 | per-namespace local writer; `addWriter` takes the peer's `localKeyHex`). |
| 15 | |
| 16 | ## Install |
| 17 | |
| 18 | ```bash |
| 19 | npm install hyper-rooms |
| 20 | ``` |
| 21 | |
| 22 | ## Usage |
| 23 | |
| 24 | ```js |
| 25 | import { Room } from 'hyper-rooms' |
| 26 | |
| 27 | const room = new Room(corestore, { |
| 28 | schema: todosSchema, // { encodeOp, decodeOp, validateOp, apply } |
| 29 | namespace: 'todos-alice', |
| 30 | bootstrapKey: null // null = create new; or pass another room's key |
| 31 | }) |
| 32 | await room.ready() |
| 33 | |
| 34 | // Append a domain op |
| 35 | await room.append({ type: 'create-todo', id: 1, text: 'milk' }) |
| 36 | |
| 37 | // Read the view |
| 38 | const todo = await room.view.get('todo:1') |
| 39 | |
| 40 | // Add a peer as a writer (you obtain their localKeyHex out-of-band) |
| 41 | await room.addWriter('bob', { writerKey: bobLocalKeyHex, role: 'owner' }) |
| 42 | |
| 43 | // Replicate |
| 44 | swarm.on('connection', (conn) => room.corestore.replicate(conn)) |
| 45 | ``` |
| 46 | |
| 47 | `role: 'owner'` registers the peer as an autobase indexer. Plain |
| 48 | `'writer'` is the default — works because the keet-pattern config above |
| 49 | acks plain writers without manual `forceAck()`. |
| 50 | |
| 51 | ## Schema shape |
| 52 | |
| 53 | ```js |
| 54 | const schema = { |
| 55 | encodeOp(op) { return JSON.stringify(op) }, |
| 56 | decodeOp(buf) { return JSON.parse(buf.toString()) }, |
| 57 | validateOp(op) { /* throw on invalid */ }, |
| 58 | apply(batch, op, host) { |
| 59 | // batch: hyperbee batch (put / del / get) |
| 60 | // host: { addWriter, removeWriter, ackWriter, interrupt } |
| 61 | } |
| 62 | } |
| 63 | ``` |
| 64 | |
| 65 | See `examples/cli.js` for a runnable todos example. |
| 66 | |
| 67 | ## Tests |
| 68 | |
| 69 | ```bash |
| 70 | npm test |
| 71 | ``` |
| 72 | |
| 73 | `test/room.test.js` covers the canonical Pattern B flow: |
| 74 | roomA creates → roomB joins via `bootstrapKey` → A.addWriter('bob', |
| 75 | {writerKey: B.localKeyHex}) → both rooms converge. |
| 76 | |
| 77 | ## Related |
| 78 | |
| 79 | - `pear-git-v3` — uses this for orgs and per-repo issue trackers. |
| 80 | - `hyper-identity` — does NOT use this (identity uses pinned keyPair + |
| 81 | pre-computed addWriter — different pattern). |
| 82 | - `.claude/skills/autobase/SKILL.md` in hypercore-kb — Pattern A vs B, |
| 83 | keet-pattern config. |