Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugojosefson/rpc-proxy
RPC for TS/JS using Proxy
https://github.com/hugojosefson/rpc-proxy
deno proxy rpc typescript web
Last synced: 3 days ago
JSON representation
RPC for TS/JS using Proxy
- Host: GitHub
- URL: https://github.com/hugojosefson/rpc-proxy
- Owner: hugojosefson
- Created: 2021-08-07T19:59:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-07T20:19:28.000Z (over 3 years ago)
- Last Synced: 2024-12-04T18:20:47.196Z (2 months ago)
- Topics: deno, proxy, rpc, typescript, web
- Language: TypeScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rpc-proxy
## Overview
RPC implementation for TypeScript / JavaScript, where these conditions are true:
- Two processes run in different runtime contexts (JS instances).
- Two processes can communicate with each other:
- bi-directionally
- asynchronously
- ordered
- through messages that each is one string.
- All accessible methods on the target object, or on any object given to it, are
`async` (return a `Promise`).
- All accessible properties on the target object, or on any object given to it,
are `readonly`.
- All accessible properties on the target object, or on any object given to it,
have a `Promise` assigned.The two processes are free to:
- Run as the same or different users.
- Run in the same or different machines.
- Have access to the same source code for typing and API purposes.## Use
### Example
```typescript
import { createRpcProxy } from "https://deno.land/x/rpc-proxy/mod.ts";class Person {
readonly name: Promise;constructor(name: string) {
this.name = Promise.resolve(name);
}async greet(greeting: string): Promise {
return `Why, hello to you too! Thank you for saying "${greeting}" to me :)`;
}
}class MyService {
async sayHelloTo(whom: Person): Promise {
const name: string = await whom.name;
const theirResponse: string = await whom.greet(`Hello, ${name}!`);
return `I said hello to ${name}, and they responded:\n\n${theirResponse}`;
}
}const myService: MyService = createRpcProxy({
typeTemplate: {} as MyService,
StringReader: // TODO: simple way to obtain them in a way that shows their versatility. TCP sockets?
});const myFriend: Person = new Person("Ada");
const outcome: string = await myService.sayHelloTo(myFriend);
console.log(outcome);
```...results in this on your console:
```
I said hello to Ada, and they responded:Why, hello to you too! Thank you for saying "Hello, Ada!" to me :)
```### API