{"id":25025471,"url":"https://github.com/mattijsf/tango-rpc","last_synced_at":"2025-03-30T15:15:51.309Z","repository":{"id":170758838,"uuid":"646993885","full_name":"mattijsf/tango-rpc","owner":"mattijsf","description":"This library provides an easy and type-safe method for remote procedure calls (RPCs) over a string-based communication channel in TypeScript.","archived":false,"fork":false,"pushed_at":"2023-05-30T10:52:10.000Z","size":169,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-18T21:50:24.771Z","etag":null,"topics":["rpc","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tango-rpc","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/mattijsf.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":"2023-05-29T20:30:26.000Z","updated_at":"2023-06-11T15:06:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3e780f7-30db-43df-b3d3-8d6f94d71709","html_url":"https://github.com/mattijsf/tango-rpc","commit_stats":null,"previous_names":["mattijsf/simple-ts-rpc","mattijsf/tango-rpc"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattijsf%2Ftango-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattijsf%2Ftango-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattijsf%2Ftango-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattijsf%2Ftango-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattijsf","download_url":"https://codeload.github.com/mattijsf/tango-rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246207178,"owners_count":20740721,"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":["rpc","typescript"],"created_at":"2025-02-05T16:39:51.562Z","updated_at":"2025-03-30T15:15:51.245Z","avatar_url":"https://github.com/mattijsf.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tango-rpc\n\nTypeScript-based Remote Procedure Call (RPC) library that is almost too simple.\n\n## Key Features\n\n- Typescript\n- No dependencies\n- Proxy-based client\n- Ultra simple string-based `Channel` interface:\n```typescript\ninterface Channel = {\n    sendMessage(message: string): void\n    addMessageListener(listener: (message: string) =\u003e void): void\n    removeMessageListener(listener: (message: string) =\u003e void): void\n}\n```\n- Support for methods with on or more callback parameters\n- Support for subscription/event callbacks\n- Server-side error handling\n- Lacks most other features\n\n\n## Installation\n\n```sh\nnpm install tango-rpc\n```\nor\n```sh\nyarn add tango-rpc\n```\n\n\n## Usage\n\nTo use this library, you need to define an API interface and supply the API implementation to the server. You'll also need to provide a `Channel` implementation which depends on your use case.\n\nSee [tango-rpc.test.ts](src/__tests__/tango-rpc.test.ts) for example usage.\n\n```typescript\ninterface MyAPI {\n  add(a: number, b: number): Promise\u003cnumber\u003e;\n  greet(name: string): Promise\u003cstring\u003e;\n  processItems(items: string[], callback: (processedItem: string) =\u003e void): Promise\u003cvoid\u003e;\n  subscribeToEvents(callback: (event: string) =\u003e void): Promise\u003cvoid\u003e;\n  triggerEvent(event: string): Promise\u003cvoid\u003e;\n  errorProne(): Promise\u003cvoid\u003e;\n}\n\nclass MyAPIServer implements MyAPI {\n  // Implement your API methods here...\n}\n```\n\nYou need to instantiate a `Server` and `Client` with your API and channel.\n\n```typescript\nconst testChannel = new TestChannel();\nconst myAPIServer = new MyAPIServer();\nconst server = new Server\u003cMyAPI\u003e(testChannel, myAPIServer);\nconst client = new Client\u003cMyAPI\u003e(testChannel);\n```\n\nYou can use the client's proxy to call API methods as if they were local.\n\n```typescript\nconst myAPIClient = client.proxy;\nmyAPIClient.add(1, 2).then(result =\u003e console.log(`1 + 2 = ${result}`));\nmyAPIClient.greet('World').then(result =\u003e console.log(result));\nmyAPIClient.processItems(['apple', 'banana', 'cherry'], item =\u003e console.log(`Processed item: ${item}`));\nmyAPIClient.subscribeToEvents(event =\u003e console.log(`Received event: ${event}`));\nmyAPIClient.triggerEvent('Test event');\nmyAPIClient.errorProne().catch(error =\u003e console.log(`Caught error: ${error.message}`));\n```\n\nIn case you need to wait until the the server \u0026 client are ready you can use the client's `onConnect` event which ensures that the proxy is ready for interaction:\n\n```typescript\nclient.onConnect(() =\u003e {\n  console.log(client.isConnected) // true\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattijsf%2Ftango-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattijsf%2Ftango-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattijsf%2Ftango-rpc/lists"}