| … | … | @@ -0,0 +1,59 @@ |
| 1 | # pgh-runtime |
| 2 | |
| 3 | Per-app OTA updater for `pgh`-installed apps. Embedded in each app; |
| 4 | polls a release source, materializes new tree closures into the local |
| 5 | TreeStore, emits events. The app decides when to apply (typically on |
| 6 | next restart, via a supervisor signal). |
| 7 | |
| 8 | Mirrors `pear-runtime-updater`'s shape but uses `hyper-overlay` |
| 9 | content-addressing instead of Hyperdrive. |
| 10 | |
| 11 | ## Usage |
| 12 | |
| 13 | ```js |
| 14 | import { PghRuntime } from 'pgh-runtime' |
| 15 | |
| 16 | const runtime = new PghRuntime({ |
| 17 | name: 'my-app', |
| 18 | currentTreeHash: process.env.PGH_CURRENT_TREE_HASH, |
| 19 | fetcher, // { getLatestRelease, getTree, getContent } |
| 20 | store, // TreeStore-compatible |
| 21 | interval: 60 * 60 * 1000 // 1h; 0 = no polling |
| 22 | }) |
| 23 | |
| 24 | runtime.on('updating', () => console.log('downloading...')) |
| 25 | runtime.on('updated', (i) => console.log('ready:', i.newTreeHash)) |
| 26 | runtime.on('error', (e) => console.error(e)) |
| 27 | |
| 28 | await runtime.start() |
| 29 | ``` |
| 30 | |
| 31 | ## Required interfaces |
| 32 | |
| 33 | ``` |
| 34 | fetcher: |
| 35 | async getLatestRelease(name) -> { treeHash, version, ... } | null |
| 36 | async getTree(hash) -> { entries: [...], size } |
| 37 | async getContent(hash) -> Buffer |
| 38 | |
| 39 | store (TreeStore-compatible): |
| 40 | init() |
| 41 | hasTree(hash) -> boolean |
| 42 | materialize(hash, entries, { fetchContent, fetchTree, source? }) |
| 43 | ``` |
| 44 | |
| 45 | Transport-agnostic — any fetcher conforming to the shape above works. |
| 46 | `pgh`'s `NetworkFetcher` provides the Hyperswarm implementation, |
| 47 | talking to `pgh-sidecar`'s release-registry advertiser + DeployServer. |
| 48 | |
| 49 | ## Tests |
| 50 | |
| 51 | ```bash |
| 52 | npm test |
| 53 | ``` |
| 54 | |
| 55 | ## Related |
| 56 | |
| 57 | - `pgh-sidecar` — release-registry source / DeployServer. |
| 58 | - `pgh` — the CLI / supervisor that wires this runtime into apps. |
| 59 | - `hyper-overlay` — the underlying content-addressed tree format. |