{"id":16000637,"url":"https://github.com/huakunshen/comlink-stdio","last_synced_at":"2025-03-27T10:32:31.790Z","repository":{"id":257813919,"uuid":"869052496","full_name":"HuakunShen/comlink-stdio","owner":"HuakunShen","description":"Comlink and RPC-style IPC channel over stdio, make IPC between 2 js/ts processes easier.","archived":false,"fork":false,"pushed_at":"2024-10-16T06:31:33.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-17T14:13:40.067Z","etag":null,"topics":["bun","comlink","deno","ipc","nodejs","rpc","typescript"],"latest_commit_sha":null,"homepage":"https://huakunshen.github.io/comlink-stdio/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuakunShen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T16:29:20.000Z","updated_at":"2024-10-16T06:31:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"5caef375-543d-4a97-9af1-2f92e46ffb96","html_url":"https://github.com/HuakunShen/comlink-stdio","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":"0.11111111111111116","last_synced_commit":"10d1377be6a0b49c164af614e253de155fa5f120"},"previous_names":["huakunshen/comlink-stdio"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fcomlink-stdio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fcomlink-stdio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fcomlink-stdio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuakunShen%2Fcomlink-stdio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuakunShen","download_url":"https://codeload.github.com/HuakunShen/comlink-stdio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222237010,"owners_count":16953514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","comlink","deno","ipc","nodejs","rpc","typescript"],"created_at":"2024-10-08T09:05:17.193Z","updated_at":"2025-03-27T10:32:31.769Z","avatar_url":"https://github.com/HuakunShen.png","language":"TypeScript","readme":"\n\u003e [!CAUTION]\n\u003e This project is archived and migrated to https://github.com/kunkunsh/kkrpc\n\n# comlink-stdio\n\n[![NPM Version](https://img.shields.io/npm/v/comlink-stdio)](https://www.npmjs.com/package/comlink-stdio)\n[![Publish](https://github.com/HuakunShen/comlink-stdio/actions/workflows/jsr-publish.yml/badge.svg)](https://github.com/HuakunShen/comlink-stdio/actions/workflows/jsr-publish.yml)\n\n- [TypeDoc Documentation](https://huakunshen.github.io/comlink-stdio/)\n- [JSR Documentation](https://jsr.io/@hk/comlink-stdio/doc)\n\nThis project is a stdio version of comlink. Making it easier to do IPC between TypeScript processes using RPC style API calls.\n\n\u003e Regular js/ts files can directly import/require each other as libraries, this package isn't designed for these normal use cases, but designed for special scenarios where 2 JS processes are not in the same environment. \n\u003e e.g. I am running main process with Tauri in a web brower, it needs to run a Deno process (which has more acess to the OS resources), in this scenario both sides are js/ts but they can't import each other as libraries. Instead of starting an http server using Deno/Node/Bun, stdio is more lightweight. \n\u003e However, stdio's `argv`, `stdin`, `stdout` is too low level, implementing API calls with them requires CLI-style programming, which is very inconvenient.\n\u003e `comlink-stdio` mimics `comlink` style API, making RPC-style API calls over stdio very easy.\n\n\u003e This package is a completly TypeScript project, no JS bundle will be generated. If you write JS, you lose the main benefit of this package, which is RPC with type auto-complete.\n\n## Support\n\n- Node.JS\n- Deno\n- Bun\n\n## Usage\n\nSee `examples`,\n\n```bash\nbun examples/parent.ts\n```\n\n`parent.ts`, run `bun examples/parent.ts`\n\n```ts\nimport { RPCChannel } from \"../src/bidirectional.ts\";\nimport { apiMethods, type API } from \"../src/api.ts\";\nimport { spawn } from \"child_process\";\nimport { NodeStdio } from \"../src/stdio/index.ts\";\n\nconst worker = spawn(\"deno\", [\"examples/deno-child.ts\"]);\n// or\nconst worker = spawn(\"bun\", [\"examples/node-child.ts\"]);\nworker.stderr.pipe(process.stdout);\n\nconst stdio = new NodeStdio(worker.stdout, worker.stdin);\nconst parent = new RPCChannel\u003c{}, API\u003e(stdio, {});\nconst api = parent.getApi();\n\nawait api.add(1, 2).then(console.log); // 3\nawait api.subtract(1, 2).then(console.log); // -1\nworker.kill();\n```\n\n`examples/node-child.ts`\n\n```ts\nimport { RPCChannel } from \"../src/bidirectional.ts\";\nimport { apiMethods } from \"./api.ts\";\nimport { DenoStdio, NodeStdio } from \"../src/stdio/index.ts\";\n\nconst stdio = new NodeStdio(process.stdin, process.stdout);\nconst child = new RPCChannel(stdio, apiMethods);\n```\n\n\n`examples/deno-child.ts`\n\n```ts\nimport { RPCChannel } from \"../src/bidirectional.ts\";\nimport { apiMethods } from \"./api.ts\";\nimport { DenoStdio, NodeStdio } from \"../src/stdio/index.ts\";\n\nconst stdio = new DenoStdio(Deno.stdin.readable, Deno.stdout.writable);\nconst child = new RPCChannel(stdio, apiMethods);\n```\n\n\n`RPCChannel` is a bidirectional IPC channel, it can send and receive messages between processes.\nJavaScript proxy is used to forward API calls over stdio. You just need to pass an API interface to `RPCChannel` as generic, then you get full auto-complete and type safety.\n\nSince `RPCChannel` is a bidirectional channel, both process can serve as API server, and they can call each other's API.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuakunshen%2Fcomlink-stdio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuakunshen%2Fcomlink-stdio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuakunshen%2Fcomlink-stdio/lists"}