From c45f9a255845a6a5d6cb514499bfb8230cde53a4 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2019 17:26:54 +0200 Subject: [PATCH] v 1.2.0 --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3eaa7b5..2dbc206 100644 --- a/README.md +++ b/README.md @@ -77,5 +77,51 @@ client.connect().then(async () => { }) ``` +#Experimental typing support +It is possible to declare pseudo-interfaces for servers and clients +```typescript +type MyInterface = RPCInterface<{ + Group1: { + triggerCallbacks: (...args:any[]) => Promise, + subscribe: (param:string, callback:Function) => Promise>, + unsubscribe: (uuid:string) => Promise + }, + Group2: { + echo: (x:string) => Promise + } +}> +``` +Create a client using +```typescript +RPCSocket.makeSocket(port, host).then((async (client) => { + const r = await client.Group2.echo("hee") //tsc knows about available RPCs +})) + +/* OR */ + +const client = new Frontend.RPCSocket(20000, 'localhost') +client.connect().then((async (client) => { + const r = await client.Group2.echo("hee") //tsc knows about available RPCs +})) +``` + +Create a server using +```typescript +new RPCServer<{a:string}, MyInterface>(20001, + [{ + //... + },{ + name: 'Group2', //Auto completion for names + exportRPCs: () => [{ + name: 'echo', //this name too! + call: async (x) => x+"llo World!" //the paramter and return types are known by tsc + }] + }] +) +``` + + + + # Documentation [https://gitea.frontblock.me/fw-docs/rpclibrary] diff --git a/package.json b/package.json index 150d630..dbdf2fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rpclibrary", - "version": "1.1.6", + "version": "1.2.0", "description": "rpclibrary is a websocket on steroids!", "main": "./js/Index.js", "repository": {