Browse Source

Before PioSocket dropin replacement

master
peter 3 years ago
parent
commit
f5fa51bef5
2 changed files with 9 additions and 8 deletions
  1. 7
    7
      demo.ts
  2. 2
    1
      test/Test.ts

+ 7
- 7
demo.ts View File

@@ -1,5 +1,6 @@
1 1
 import { RPCServer, RPCSocket } from './Index'
2 2
 import { RPCExporter } from './src/Interfaces'
3
+import { RPCInterface } from './src/Types'
3 4
 
4 5
 // TL;DR
5 6
 const echo = (text: string) => text
@@ -175,17 +176,16 @@ interface IMyImplementation {
175 176
     getCallback: (callback:Function) => string
176 177
 }
177 178
 
178
-type MyIfc = {
179
-    MyRPCGroup1: {
180
-        echo: IMyImplementation['echo']
181
-        add: IMyImplementation['add']
182
-        getAsync: IMyImplementation['getAsync']
183
-        getCallback: IMyImplementation['getCallback']
179
+type IfcGenerator<Name extends string, Interface, keys extends keyof Interface = keyof Interface> = {
180
+    [name in Name]: {
181
+        [key in keys] : Interface[key]
184 182
     }
185 183
 }
186 184
 
185
+type MyIfc = IfcGenerator<"MyRPCGroup1", IMyImplementation>
186
+
187 187
 class MyImplementation implements IMyImplementation, RPCExporter<MyIfc>{
188
-    //"X" as "X" syntax is required to satisfy the type system (as it assumed string)
188
+    //"X" as "X" syntax is required to satisfy the type system (as it assumes string)
189 189
     name = "MyRpcGroup11" as "MyRPCGroup1"
190 190
 
191 191
     //List the functions you declared in MyIfc

+ 2
- 1
test/Test.ts View File

@@ -38,7 +38,8 @@ function makeServer() {
38 38
             function triggerCallback(...messages: any[]): number { return subcallback.apply({}, messages) },
39 39
         ]
40 40
     }], {
41
-        connectionHandler: (socket) => { },
41
+        connectionHandler: (socket) => {
42
+        },
42 43
         closeHandler: (socket) => { },
43 44
         errorHandler: (socket, err) => { throw err }
44 45
     })

Loading…
Cancel
Save