socket-function 0.8.14 → 0.8.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SocketFunction.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SocketExposedInterface, CallContextType, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, NetworkLocation, CallerContext, SocketExposedInterfaceClass, CallType, FullCallType } from "./SocketFunctionTypes";
2
2
  import { exposeClass, registerClass, registerGlobalClientHook, registerGlobalHook, runClientHooks } from "./src/callManager";
3
3
  import { SocketServerConfig, startSocketServer } from "./src/webSocketServer";
4
- import { getCallFactoryFromNodeId, getCreateCallFactoryLocation, getNetworkLocationHash } from "./src/nodeCache";
4
+ import { getCallFactoryFromNodeId, getCreateCallFactoryLocation, getLocationFromNodeId, getNetworkLocationHash } from "./src/nodeCache";
5
5
  import { getCallProxy } from "./src/nodeProxy";
6
6
  import { Args } from "./src/types";
7
7
  import { setDefaultHTTPCall } from "./src/callHTTPHandler";
@@ -95,13 +95,13 @@ export class SocketFunction {
95
95
  return output as any;
96
96
  }
97
97
 
98
- /** Gets HTTP call link */
99
- public static async getHTTPCallLink(call: FullCallType): Promise<string> {
100
- let factory = await getCallFactoryFromNodeId(call.nodeId);
101
- if (!factory) {
102
- throw new Error(`Cannot find call factory for nodeId, and so do not know where call location is. NodeId ${call.nodeId}`);
98
+ /** NOTE: Only works if the call has been loaded from a url (we can't convert arbitrary nodeIds into urls,
99
+ * as we have no way of knowing how to contain a nodeId). */
100
+ public static getHTTPCallLink(call: FullCallType): string {
101
+ let location = getLocationFromNodeId(call.nodeId);
102
+ if (!location) {
103
+ throw new Error(`Cannot find call location for nodeId, and so do not know where call location is. NodeId ${call.nodeId}`);
103
104
  }
104
- let location = factory.location;
105
105
  let url = new URL(`https://${location.address}:${location.listeningPorts[0]}`);
106
106
  url.searchParams.set("classGuid", call.classGuid);
107
107
  url.searchParams.set("functionName", call.functionName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.8.14",
3
+ "version": "0.8.15",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
package/src/nodeCache.ts CHANGED
@@ -15,6 +15,8 @@ import { MaybePromise } from "./types";
15
15
  // nodeId =>
16
16
  const nodeCache = new Map<string, {
17
17
  callFactory: MaybePromise<CallFactory>;
18
+ // Just used for getCallFactoryFromNodeId
19
+ location: NetworkLocation | undefined;
18
20
  }>();
19
21
  const locationLookup = new Map<string, MaybePromise<string>>();
20
22
 
@@ -47,6 +49,7 @@ export function registerNodeClient(callFactory: CallFactory) {
47
49
  // TODO: Maybe even preserve the address in some cases, such as if it was a domain, and is now an ip?
48
50
  nodeCache.set(nodeId, {
49
51
  callFactory,
52
+ location: undefined,
50
53
  });
51
54
  }
52
55
 
@@ -64,6 +67,7 @@ export function getCreateCallFactoryLocation(location: NetworkLocation, tempNode
64
67
  if (tempNodeId !== undefined) {
65
68
  nodeCache.set(tempNodeId, {
66
69
  callFactory: callFactoryPromise,
70
+ location,
67
71
  });
68
72
  }
69
73
 
@@ -80,6 +84,7 @@ export function getCreateCallFactoryLocation(location: NetworkLocation, tempNode
80
84
  }
81
85
  nodeCache.set(nodeId, {
82
86
  callFactory,
87
+ location,
83
88
  });
84
89
  return nodeId;
85
90
  });
@@ -89,4 +94,8 @@ export function getCreateCallFactoryLocation(location: NetworkLocation, tempNode
89
94
  // TODO: Give a special error if the nodeId has been seen, but is only one-way (from HTTP requests).
90
95
  export async function getCallFactoryFromNodeId(nodeId: string): Promise<CallFactory | undefined> {
91
96
  return await nodeCache.get(nodeId)?.callFactory;
97
+ }
98
+ // NOTE: Only works if the nodeId has been loaded with getCreateCallFactoryLocation
99
+ export function getLocationFromNodeId(nodeId: string): NetworkLocation | undefined {
100
+ return nodeCache.get(nodeId)?.location;
92
101
  }
package/test/server.ts CHANGED
@@ -34,4 +34,12 @@ async function main() {
34
34
  const port = 2542;
35
35
 
36
36
  await SocketFunction.mount({ port });
37
+
38
+
39
+ {
40
+ let serverId = await SocketFunction.connect({ port, address: "letx.ca" });
41
+ let call = Test.nodes[serverId].add[getCallObj](1, 2);
42
+ console.log(call);
43
+ console.log(await SocketFunction.getHTTPCallLink(call));
44
+ }
37
45
  }