This commit is contained in:
2019-09-22 10:52:33 +02:00
parent ab6121c8c8
commit 2bab836faf
12 changed files with 244 additions and 140 deletions
+27 -19
View File
@@ -2,6 +2,8 @@
# Class: RPCServer <**SubResType**>
A Websocket-server-on-steroids with built-in RPC capabilities
## Type parameters
**SubResType**
@@ -41,17 +43,19 @@
### constructor
\+ **new RPCServer**(`port`: number, `exporters`: [Exporter](../interfaces/_interfaces_.exporter.md)SubResType[], `conf`: T.SocketConf): *[RPCServer](_backend_.rpcserver.md)*
\+ **new RPCServer**(`port`: number, `exporters`: [RPCExporter](../interfaces/_interfaces_.rpcexporter.md)SubResType[], `conf`: T.SocketConf): *[RPCServer](_backend_.rpcserver.md)*
Defined in Backend.ts:19
Defined in Backend.ts:22
**`throws`** On RPC with no name
**Parameters:**
Name | Type | Default |
------ | ------ | ------ |
`port` | number | - |
`exporters` | [Exporter](../interfaces/_interfaces_.exporter.md)SubResType[] | [] |
`conf` | T.SocketConf | {} |
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`port` | number | - | The port to listen on |
`exporters` | [RPCExporter](../interfaces/_interfaces_.rpcexporter.md)SubResType[] | [] | A list of [RPCExporter](../interfaces/_interfaces_.rpcexporter.md) to publish |
`conf` | T.SocketConf | {} | A [SocketConf](../modules/_types_.md#socketconf) object with optional settings |
**Returns:** *[RPCServer](_backend_.rpcserver.md)*
@@ -61,7 +65,7 @@ Name | Type | Default |
**closeHandler**: *T.CloseHandler*
Defined in Backend.ts:17
Defined in Backend.ts:20
___
@@ -69,7 +73,7 @@ ___
**connectionHandler**: *T.ConnectionHandler*
Defined in Backend.ts:19
Defined in Backend.ts:22
___
@@ -77,15 +81,17 @@ ___
**errorHandler**: *T.ErrorHandler*
Defined in Backend.ts:18
Defined in Backend.ts:21
___
### `Private` exporters
**exporters**: *[Exporter](../interfaces/_interfaces_.exporter.md)SubResType[]*
**exporters**: *[RPCExporter](../interfaces/_interfaces_.rpcexporter.md)SubResType[]*
Defined in Backend.ts:23
Defined in Backend.ts:32
A list of [RPCExporter](../interfaces/_interfaces_.rpcexporter.md) to publish
___
@@ -93,7 +99,7 @@ ___
**io**: *any* = bsock.createServer()
Defined in Backend.ts:15
Defined in Backend.ts:18
___
@@ -101,7 +107,9 @@ ___
**port**: *number*
Defined in Backend.ts:22
Defined in Backend.ts:31
The port to listen on
___
@@ -109,7 +117,7 @@ ___
**visibility**: *T.Visibility*
Defined in Backend.ts:16
Defined in Backend.ts:19
___
@@ -117,7 +125,7 @@ ___
**ws**: *Server* = http.createServer()
Defined in Backend.ts:14
Defined in Backend.ts:17
## Methods
@@ -127,7 +135,7 @@ Defined in Backend.ts:14
*Implementation of [Destroyable](../interfaces/_interfaces_.destroyable.md)*
Defined in Backend.ts:80
Defined in Backend.ts:89
**Returns:** *Promisevoid*
@@ -137,7 +145,7 @@ ___
**initRPCs**(`socket`: [Socket](../interfaces/_interfaces_.socket.md)): *void*
Defined in Backend.ts:73
Defined in Backend.ts:82
**Parameters:**
@@ -153,6 +161,6 @@ ___
**startWebsocket**(): *void*
Defined in Backend.ts:57
Defined in Backend.ts:66
**Returns:** *void*
+80 -42
View File
@@ -2,6 +2,8 @@
# Class: RPCSocket
A websocket-on-steroids with built-in RPC capabilities
## Hierarchy
* **RPCSocket**
@@ -43,15 +45,15 @@
\+ **new RPCSocket**(`port`: number, `server`: string, `tls`: boolean): *[RPCSocket](_frontend_.rpcsocket.md)*
Defined in Frontend.ts:15
Defined in Frontend.ts:20
**Parameters:**
Name | Type | Default |
------ | ------ | ------ |
`port` | number | - |
`server` | string | - |
`tls` | boolean | false |
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`port` | number | - | Port to connect to |
`server` | string | - | Server address |
`tls` | boolean | false | @default false use TLS |
**Returns:** *[RPCSocket](_frontend_.rpcsocket.md)*
@@ -63,7 +65,9 @@ Name | Type | Default |
*Implementation of [Socket](../interfaces/_interfaces_.socket.md).[port](../interfaces/_interfaces_.socket.md#port)*
Defined in Frontend.ts:16
Defined in Frontend.ts:28
Port to connect to
___
@@ -71,7 +75,9 @@ ___
**server**: *string*
Defined in Frontend.ts:16
Defined in Frontend.ts:28
Server address
___
@@ -79,7 +85,7 @@ ___
**socket**: *[Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:15
Defined in Frontend.ts:20
___
@@ -87,7 +93,9 @@ ___
**tls**: *boolean*
Defined in Frontend.ts:16
Defined in Frontend.ts:28
@default false use TLS
## Methods
@@ -95,14 +103,16 @@ Defined in Frontend.ts:16
**call**(`rpcname`: T.Name, ...`args`: T.Any[]): *PromiseT.Any*
Defined in Frontend.ts:40
Defined in Frontend.ts:77
Trigger a hooked handler on the server
**Parameters:**
Name | Type |
------ | ------ |
`rpcname` | T.Name |
`...args` | T.Any[] |
Name | Type | Description |
------ | ------ | ------ |
`rpcname` | T.Name | The function to call |
`...args` | T.Any[] | other arguments |
**Returns:** *PromiseT.Any*
@@ -112,14 +122,16 @@ ___
**callGenerator**(`fnName`: T.Name, `fnArgs`: T.Arg[]): *T.AsyncFunction*
Defined in Frontend.ts:73
Defined in Frontend.ts:126
Utility [AsyncFunction](../modules/_types_.md#asyncfunction) generator
**Parameters:**
Name | Type |
------ | ------ |
`fnName` | T.Name |
`fnArgs` | T.Arg[] |
Name | Type | Description |
------ | ------ | ------ |
`fnName` | T.Name | The function name |
`fnArgs` | T.Arg[] | A string-list of parameters |
**Returns:** *T.AsyncFunction*
@@ -131,7 +143,9 @@ ___
*Implementation of [Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:36
Defined in Frontend.ts:68
Closes the socket. It may attempt to reconnect.
**Returns:** *void*
@@ -141,7 +155,9 @@ ___
**connect**(): *Promisevoid*
Defined in Frontend.ts:48
Defined in Frontend.ts:93
Connects to the server and attaches available RPCs to this object
**Returns:** *Promisevoid*
@@ -153,7 +169,9 @@ ___
*Implementation of [Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:32
Defined in Frontend.ts:61
Destroys the socket
**Returns:** *void*
@@ -161,18 +179,20 @@ ___
### fire
**fire**(`rpcname`: T.Name, ...`args`: T.Any[]): *PromiseT.Any*
**fire**(`rpcname`: T.Name, ...`args`: T.Any[]): *Promisevoid*
Defined in Frontend.ts:44
Defined in Frontend.ts:86
An alternative to call that does not wait for confirmation and doesn't return a value.
**Parameters:**
Name | Type |
------ | ------ |
`rpcname` | T.Name |
`...args` | T.Any[] |
Name | Type | Description |
------ | ------ | ------ |
`rpcname` | T.Name | The function to call |
`...args` | T.Any[] | other arguments |
**Returns:** *PromiseT.Any*
**Returns:** *Promisevoid*
___
@@ -180,14 +200,20 @@ ___
**hook**(`name`: T.Name, `handler`: function): *[Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:20
Defined in Frontend.ts:37
Hooks a handler to a function name. Use [call](_frontend_.rpcsocket.md#call) to trigger it.
**Parameters:**
**name**: *T.Name*
The function name to listen on
**handler**: *function*
The handler to attach
▸ (...`args`: any[]): *any | Promiseany*
**Parameters:**
@@ -204,14 +230,16 @@ ___
**hookGenerator**(`fnName`: T.Name, `fnArgs`: T.Arg[]): *T.HookFunction*
Defined in Frontend.ts:79
Defined in Frontend.ts:137
Utility [HookFunction](../modules/_types_.md#hookfunction) generator
**Parameters:**
Name | Type |
------ | ------ |
`fnName` | T.Name |
`fnArgs` | T.Arg[] |
Name | Type | Description |
------ | ------ | ------ |
`fnName` | T.Name | The function name |
`fnArgs` | T.Arg[] | A string-list of parameters |
**Returns:** *T.HookFunction*
@@ -221,7 +249,9 @@ ___
**info**(): *Promiseany*
Defined in Frontend.ts:69
Defined in Frontend.ts:117
Get a list of available RPCs from the server
**Returns:** *Promiseany*
@@ -231,14 +261,20 @@ ___
**on**(`type`: "error" | "close", `f`: function): *[Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:28
Defined in Frontend.ts:54
Attach a listener to error or close events
**Parameters:**
**type**: *"error" | "close"*
'error' or 'close'
**f**: *function*
The listener to attach
▸ (`e?`: any): *void*
**Parameters:**
@@ -255,12 +291,14 @@ ___
**unhook**(`name`: T.Name): *[Socket](../interfaces/_interfaces_.socket.md)*
Defined in Frontend.ts:24
Defined in Frontend.ts:45
Removes a [hook](_frontend_.rpcsocket.md#hook) listener by name.
**Parameters:**
Name | Type |
------ | ------ |
`name` | T.Name |
Name | Type | Description |
------ | ------ | ------ |
`name` | T.Name | The function name |
**Returns:** *[Socket](../interfaces/_interfaces_.socket.md)*
+1 -1
View File
@@ -24,6 +24,6 @@
**destroy**(): *void*
Defined in Interfaces.ts:20
Defined in Interfaces.ts:26
**Returns:** *void*
-39
View File
@@ -1,39 +0,0 @@
[rpclibrary](../README.md) [Globals](../globals.md) ["Interfaces"](../modules/_interfaces_.md) [Exporter](_interfaces_.exporter.md)
# Interface: Exporter <**T**>
## Type parameters
**T**
## Hierarchy
* **Exporter**
## Index
### Properties
* [name](_interfaces_.exporter.md#name)
### Methods
* [exportRPCs](_interfaces_.exporter.md#exportrpcs)
## Properties
### name
**name**: *T.Name*
Defined in Interfaces.ts:5
## Methods
### exportRPCs
**exportRPCs**(): *T.RPCT[]*
Defined in Interfaces.ts:6
**Returns:** *T.RPCT[]*
+10 -8
View File
@@ -2,6 +2,8 @@
# Interface: Socket
Generic socket interface that can apply to bsock as well as RPCSocket
## Hierarchy
* [Destroyable](_interfaces_.destroyable.md)
@@ -34,7 +36,7 @@
**call**: *function*
Defined in Interfaces.ts:13
Defined in Interfaces.ts:19
#### Type declaration:
@@ -53,7 +55,7 @@ ___
**fire**: *function*
Defined in Interfaces.ts:14
Defined in Interfaces.ts:20
#### Type declaration:
@@ -72,7 +74,7 @@ ___
**hook**: *function*
Defined in Interfaces.ts:11
Defined in Interfaces.ts:17
#### Type declaration:
@@ -98,7 +100,7 @@ ___
**on**: *T.OnFunction*
Defined in Interfaces.ts:15
Defined in Interfaces.ts:21
___
@@ -106,7 +108,7 @@ ___
**port**: *number*
Defined in Interfaces.ts:10
Defined in Interfaces.ts:16
___
@@ -114,7 +116,7 @@ ___
**unhook**: *function*
Defined in Interfaces.ts:12
Defined in Interfaces.ts:18
#### Type declaration:
@@ -132,7 +134,7 @@ Name | Type |
**close**(): *void*
Defined in Interfaces.ts:16
Defined in Interfaces.ts:22
**Returns:** *void*
@@ -144,6 +146,6 @@ ___
*Inherited from [Destroyable](_interfaces_.destroyable.md).[destroy](_interfaces_.destroyable.md#destroy)*
Defined in Interfaces.ts:20
Defined in Interfaces.ts:26
**Returns:** *void*
+6 -4
View File
@@ -18,12 +18,14 @@
**stripAfterEquals**(`str`: string): *string*
Defined in Frontend.ts:9
Defined in Frontend.ts:12
Utility function to strip parameters like "a = 3" of their defaults
**Parameters:**
Name | Type |
------ | ------ |
`str` | string |
Name | Type | Description |
------ | ------ | ------ |
`str` | string | The parameter to modify |
**Returns:** *string*
+1 -1
View File
@@ -7,5 +7,5 @@
### Interfaces
* [Destroyable](../interfaces/_interfaces_.destroyable.md)
* [Exporter](../interfaces/_interfaces_.exporter.md)
* [RPCExporter](../interfaces/_interfaces_.rpcexporter.md)
* [Socket](../interfaces/_interfaces_.socket.md)
+23 -15
View File
@@ -18,13 +18,15 @@
**extractArgs**(`f`: Function): *T.Arg[]*
Defined in Utils.ts:102
Defined in Utils.ts:110
Extract a string list of parameters from a function
**Parameters:**
Name | Type |
------ | ------ |
`f` | Function |
Name | Type | Description |
------ | ------ | ------ |
`f` | Function | The source function |
**Returns:** *T.Arg[]*
@@ -34,16 +36,20 @@ ___
**hookGenerator**(`rpc`: T.HookRPCany): *function*
Defined in Utils.ts:81
Defined in Utils.ts:85
Utility function to generate [HookFunction](_types_.md#hookfunction) from a RPC
**Parameters:**
Name | Type |
------ | ------ |
`rpc` | T.HookRPCany |
Name | Type | Description |
------ | ------ | ------ |
`rpc` | T.HookRPCany | The RPC to transform |
**Returns:** *function*
A [HookFunction](_types_.md#hookfunction)
▸ (`socket?`: I.Socket): *[HookFunction](_types_.md#hookfunction)T*
**Parameters:**
@@ -58,13 +64,15 @@ ___
**makeSubResponse**(`uuid?`: undefined | string): *[SubscriptionResponse](_types_.md#subscriptionresponse)*
Defined in Utils.ts:107
Defined in Utils.ts:119
Simple utility function to create basic [SubscriptionResponse](_types_.md#subscriptionresponse)
**Parameters:**
Name | Type |
------ | ------ |
`uuid?` | undefined &#124; string |
Name | Type | Description |
------ | ------ | ------ |
`uuid?` | undefined &#124; string | optional uuid to use, otherwise defaults to uuid/v4 |
**Returns:** *[SubscriptionResponse](_types_.md#subscriptionresponse)*
@@ -72,11 +80,11 @@ ___
### rpcHooker
**rpcHooker**<**SubResT**>(`socket`: [Socket](../interfaces/_interfaces_.socket.md), `exporter`: [Exporter](../interfaces/_interfaces_.exporter.md)SubResT, `makeUnique`: boolean): *T.ExtendedRpcInfo[]*
**rpcHooker**<**SubResT**>(`socket`: [Socket](../interfaces/_interfaces_.socket.md), `exporter`: [RPCExporter](../interfaces/_interfaces_.rpcexporter.md)SubResT, `makeUnique`: boolean): *T.ExtendedRpcInfo[]*
Defined in Utils.ts:59
Utility function to apply the RPCs of an [Exporter](../interfaces/_interfaces_.exporter.md).
Utility function to apply the RPCs of an [RPCExporter](../interfaces/_interfaces_.rpcexporter.md).
**Type parameters:**
@@ -87,7 +95,7 @@ Utility function to apply the RPCs of an [Exporter](../interfaces/_interfaces_.e
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`socket` | [Socket](../interfaces/_interfaces_.socket.md) | - | The websocket (implementation: bsock) to hook on |
`exporter` | [Exporter](../interfaces/_interfaces_.exporter.md)SubResT | - | The exporter |
`exporter` | [RPCExporter](../interfaces/_interfaces_.rpcexporter.md)SubResT | - | The exporter |
`makeUnique` | boolean | true | @default true Attach a suffix to RPC names |
**Returns:** *T.ExtendedRpcInfo[]*