{"_id":"@byterygon/portex","name":"@byterygon/portex","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@byterygon/portex","version":"0.0.0","description":"Lightweight bidirectional RPC over MessageChannel with typed procedures, events, abort, progress, and transferable support","type":"module","main":"dist/portex.cjs","module":"dist/portex.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/portex.js","require":"./dist/portex.cjs","types":"./dist/index.d.ts"}},"sideEffects":false,"devDependencies":{"typescript":"~5.9.3","vite":"^8.0.0"},"scripts":{"build":"vite build","test":"vitest run","typecheck":"tsc --noEmit"},"_id":"@byterygon/portex@0.0.0","_integrity":"sha512-2+0JuVBPWeGqRpJzN2bS0OqrKpeI6sg8hvGMe8DSiC2uSMm1wUXRfdb0BO8PJ3YcL2hzjFCc0PS+cC7As3UTUg==","_resolved":"/tmp/bb7d4aef964f06e5bea518c99f84c2e1/byterygon-portex-0.0.0.tgz","_from":"file:byterygon-portex-0.0.0.tgz","_nodeVersion":"20.20.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-2+0JuVBPWeGqRpJzN2bS0OqrKpeI6sg8hvGMe8DSiC2uSMm1wUXRfdb0BO8PJ3YcL2hzjFCc0PS+cC7As3UTUg==","shasum":"8da560a6dc97e678fb64a19cdf192ce8cb1c5e02","tarball":"https://registry.npmjs.org/@byterygon/portex/-/portex-0.0.0.tgz","fileCount":6,"unpackedSize":22937,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDZh3Q4IBV8tMujFIhXsayx2kLALamGcjKS5CbfBgzznQIgRt9dGodHGbJ1CDg1lTVBuJuwqjhQBhrb6MxMghNRTBc="}]},"_npmUser":{"name":"sontu_mw","email":"byterygon@gmail.com"},"directories":{},"maintainers":[{"name":"sontu_mw","email":"byterygon@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/portex_0.0.0_1773906174060_0.7123681414352985"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-19T07:42:53.965Z","0.0.0":"2026-03-19T07:42:54.208Z","modified":"2026-03-19T07:42:54.460Z"},"maintainers":[{"name":"sontu_mw","email":"byterygon@gmail.com"}],"description":"Lightweight bidirectional RPC over MessageChannel with typed procedures, events, abort, progress, and transferable support","readme":"# @byterygon/portex\n\nLightweight bidirectional RPC over MessageChannel with typed procedures, events, abort, progress, and transferable support.\n\n## Features\n\n- **Bidirectional RPC** — call remote procedures, get typed results\n- **Event push** — fire-and-forget events in either direction\n- **AbortController** — cancel in-flight calls with native `AbortSignal`\n- **Typed progress** — stream progress feedback from handler to caller\n- **Transferable support** — zero-copy `ArrayBuffer` transfer on calls, events, and progress\n- **Ready handshake** — queue messages until the remote side is ready\n- **Type-safe** — full TypeScript inference via `defineLink()`, no manual type maps\n- **Tiny** — under 2 KB gzipped\n\n## Install\n\n```bash\nnpm install @byterygon/portex\n```\n\n## Quick Start\n\n```ts\nimport { defineLink, createPair } from '@byterygon/portex';\n\nconst serverDef = defineLink({\n  procedures: {\n    greet: (name: string) => `Hello, ${name}!`,\n    add: (a: number, b: number) => a + b,\n  },\n});\n\nconst [client, server] = createPair(serverDef);\n\nconsole.log(await client.call('greet', 'world')); // \"Hello, world!\"\nconsole.log(await client.call('add', 1, 2)); // 3\n\nclient.destroy();\nserver.destroy();\n```\n\n## Worker Example\n\n```ts\n// main.ts\nimport { MsgLink } from '@byterygon/portex';\nimport type { workerDef } from './worker';\n\nconst worker = new Worker('./worker.ts', { type: 'module' });\nconst link = new MsgLink<{}, typeof workerDef>(worker, { waitReady: true });\n\nconst result = await link.call('compute', 42);\n// calls are queued until the worker signals ready\n```\n\n```ts\n// worker.ts\nimport { MsgLink, defineLink } from '@byterygon/portex';\n\nexport const workerDef = defineLink({\n  procedures: {\n    compute: (n: number) => n * n,\n  },\n});\n\nconst link = new MsgLink(self, workerDef);\nlink.ready(); // flush queued messages on the main side\n```\n\n## Progress & Abort\n\n```ts\nconst controller = new AbortController();\n\nconst result = await link.call('processFile', file, {\n  signal: controller.signal,\n  onProgress: ({ step, total }) => console.log(`${step}/${total}`),\n});\n\n// Cancel anytime:\ncontroller.abort();\n```\n\n## API Overview\n\n| Method                             | Description                                                     |\n| ---------------------------------- | --------------------------------------------------------------- |\n| `defineLink(config)`               | Create a typed `LinkDefinition` from handler functions          |\n| `createPair(def?)`                 | Create a connected `[client, server]` pair via `MessageChannel` |\n| `new MsgLink(port, def?, opts?)`   | Attach to any `MessageChannel`-compatible transport             |\n| `.call(method, ...args, opts?)`    | Call a remote procedure, returns `Promise`                      |\n| `.procedure(name, handler)`        | Register a procedure handler                                    |\n| `.emit(name, payload?, transfer?)` | Send a fire-and-forget event                                    |\n| `.on(name, handler)`               | Subscribe to events, returns unsubscribe function               |\n| `.off(name, handler)`              | Unsubscribe from events                                         |\n| `.ready()`                         | Signal readiness to the other side                              |\n| `.waitForReady()`                  | Wait until the other side signals ready                         |\n| `.destroy()`                       | Clean up listeners, reject pending calls                        |\n\n## Documentation\n\n- [Architecture & Wire Protocol](../../docs/architecture.md)\n- [Type System](../../docs/type-system.md)\n- [API Reference](../../docs/api.md)\n- [Implementation Details](../../docs/implementation.md)\n- [Testing Patterns](../../docs/testing.md)\n\n## License\n\n[MIT](../../LICENSE)\n","readmeFilename":"README.md","_rev":"1-9ac975114a58a60b18fcd1eb4f889dc5"}