| … | … | @@ -0,0 +1,55 @@ |
| 1 | # hyper-svc |
| 2 | |
| 3 | Reusable per-app daemon library for the hyper-fleeky stack. Local RPC |
| 4 | over UDS + HTTP, peer RPC over Hyperswarm (Protomux channel), |
| 5 | replication via the same swarm. |
| 6 | |
| 7 | Used by `pear-git-v3`, `pgh-sidecar`, and any other daemon that wants |
| 8 | "CLI talks to me locally, peer daemons talk to me via swarm." |
| 9 | |
| 10 | ## API |
| 11 | |
| 12 | ```js |
| 13 | import { Service, Client } from 'hyper-svc' |
| 14 | |
| 15 | const svc = new Service({ |
| 16 | socketPath: '/tmp/my-app.sock', |
| 17 | port: 4040, // optional HTTP |
| 18 | swarm, // optional Hyperswarm for peer RPC |
| 19 | topic // optional swarm topic for peer RPC channel |
| 20 | }) |
| 21 | |
| 22 | svc.handle('echo', async (params) => params) |
| 23 | await svc.listen() |
| 24 | |
| 25 | // Local CLI client (UDS) |
| 26 | const client = new Client({ socketPath: '/tmp/my-app.sock' }) |
| 27 | await client.call('echo', { hello: 'world' }) |
| 28 | |
| 29 | // Peer client (over swarm) |
| 30 | import { attachRpcClient } from 'hyper-svc' |
| 31 | const peer = await attachRpcClient({ swarm, topic, peerKey }) |
| 32 | await peer.call('echo', { ... }) |
| 33 | ``` |
| 34 | |
| 35 | ## Wire format |
| 36 | |
| 37 | `encodeFrame` / `FrameDecoder` provide the length-prefixed JSON frames |
| 38 | used over both UDS and Protomux. Single source of truth for the wire |
| 39 | format — keep them in sync if you fork. |
| 40 | |
| 41 | ## Tests |
| 42 | |
| 43 | ```bash |
| 44 | npm test |
| 45 | ``` |
| 46 | |
| 47 | `examples/` has a runnable echo service. |
| 48 | |
| 49 | ## Related |
| 50 | |
| 51 | - `pear-git-v3` — primary consumer (per-daemon Service mounting all |
| 52 | RPC handlers). |
| 53 | - `pgh-sidecar` — uses Service for `~/.pgh/svc.sock`. |
| 54 | - `pgh-sidecar`'s app-lookup — apps register their UDS path here so |
| 55 | CLIs can resolve daemon → socket by name. |