socket-function 0.9.3 → 0.9.5

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.
Files changed (45) hide show
  1. package/.eslintrc.js +50 -50
  2. package/SocketFunction.ts +280 -280
  3. package/SocketFunctionTypes.ts +90 -90
  4. package/hot/HotReloadController.ts +105 -105
  5. package/mobx/UrlParam.ts +39 -39
  6. package/mobx/observer.tsx +49 -49
  7. package/mobx/promiseToObservable.tsx +41 -41
  8. package/package.json +1 -1
  9. package/require/CSSShim.ts +19 -19
  10. package/require/RequireController.ts +252 -252
  11. package/require/buffer.js +2368 -2368
  12. package/require/compileFlags.ts +44 -44
  13. package/require/require.html +13 -13
  14. package/require/require.js +464 -462
  15. package/spec.txt +115 -115
  16. package/src/CallFactory.ts +389 -389
  17. package/src/JSONLACKS/JSONLACKS.generated.js +17 -17
  18. package/src/JSONLACKS/JSONLACKS.pegjs +247 -247
  19. package/src/JSONLACKS/JSONLACKS.ts +441 -429
  20. package/src/args.ts +21 -21
  21. package/src/batching.ts +177 -170
  22. package/src/caching.ts +359 -318
  23. package/src/callHTTPHandler.ts +203 -203
  24. package/src/callManager.ts +134 -134
  25. package/src/certStore.ts +29 -29
  26. package/src/fixLargeNetworkCalls.ts +8 -8
  27. package/src/formatting/colors.ts +78 -78
  28. package/src/formatting/format.ts +160 -160
  29. package/src/formatting/logColors.ts +17 -17
  30. package/src/misc.ts +315 -302
  31. package/src/nodeCache.ts +92 -92
  32. package/src/nodeProxy.ts +54 -54
  33. package/src/profiling/getOwnTime.ts +107 -142
  34. package/src/profiling/measure.ts +289 -273
  35. package/src/profiling/stats.ts +212 -212
  36. package/src/profiling/tcpLagProxy.ts +63 -63
  37. package/src/storagePath.ts +10 -10
  38. package/src/tlsParsing.ts +96 -96
  39. package/src/types.ts +8 -8
  40. package/src/webSocketServer.ts +254 -250
  41. package/test/client.css +2 -2
  42. package/test/client.ts +46 -46
  43. package/test/server.ts +43 -43
  44. package/test/shared.ts +52 -52
  45. package/tsconfig.json +26 -26
package/spec.txt CHANGED
@@ -1,115 +1,115 @@
1
- spec.txt
2
-
3
- - Add the ability to specify the certs yourself (so you can specify your identity with a real cert)
4
- - Then use real certificates on the server
5
- - Fix multiple clients on the same machines
6
- - Maybe we need to exchange link information
7
- - The login emails SHOULD redirect, if the close doesn't works
8
- (due to copying the link instead of clicking it)
9
-
10
- - Other stuff
11
- - JSON buffer serialize, which generates an object, that allows for rehydration of buffers
12
- - Also... static classes (maybe even static resources), so structures can be sent
13
- - Consider forcing everything to use real certs everywhere, and make generating and updating
14
- certs very easy.
15
- - ALTHOUGH, maybe this should just be a downstream user of socket-function thing, and not
16
- a requirement of socket-function?
17
- - This will be something where machines ask a server for an identity, and then the owner
18
- allows it (giving them a subdomain), verifying their ip, etc.
19
- - MAYBE we just automatically allow it? This works if we never use the root domain for anything,
20
- and only use subdomains?
21
- - Although, of course, sometimes we WILL want to group by domain, so it is more than just
22
- identity, so having a way for the owner to authenticate it might be nice as well...
23
- - Once they are given an identity, they are allowed to request their certs are updated,
24
- and to get the new certs (it probably won't happen automatically, so that we can create
25
- many nodes and let them die, without having to try to track which still need certs to be updated)
26
- - ALSO, remember, for domains, use the domain as the nodeId, not the public key, that way it
27
- is more consistent.
28
-
29
-
30
- - https://letx.ca:2542/?classGuid=RequireController-e2f811f3-14b8-4759-b0d6-73f14516cf1d&functionName=requireHTML&args=[%22./test/test%22]
31
-
32
- ================== SocketFunction ==================
33
-
34
- - Uses proxies, so that functions can be called before we know the shape of interface
35
- - Headers
36
- - Support enabling "Access-Control-Allow-Credentials"/Request.credentials=include, with a hardcoded list of domains
37
- - Support Access-Control-Allow-Origin, with a hardcoded list of domains
38
- - Always set
39
- - response.setHeader("Cross-Origin-Opener-Policy", "same-origin");
40
- - response.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
41
- - response.setHeader("Cross-Origin-Resource-Policy", "same-site");
42
- - Remember to set headers for OPTIONS, but then NOOP
43
-
44
- // NOTE: It is not possible to expose different services over different ports in the same process.
45
- // Just run different processes if you want different services.
46
- SocketFunction.expose(ExampleController);
47
- // Global hooks are useful for authentication
48
- SocketFunction.addGlobalHook<ExampleContext>(null as SocketFunctionHook);
49
- // Mount only after exposing controllers and setting up hooks
50
- SocketFunction.mount({ port: 40981 });
51
-
52
-
53
- // callerId is set before each function (and part of the hook context)
54
- let callerId = ExampleController[socket].callerId;
55
- let result = await ExampleController[socket].nodes[callerId].exampleFunction("hi");
56
-
57
-
58
- // An object with context information is available in each call (so arguments don't have to be modified)
59
- // - register will have a second generic argument that is context, so this will be typed
60
- ExampleController[socket].callContext
61
-
62
-
63
-
64
- // Clientside may also wish to expose controllers, possibly the same, or different.
65
- SocketFunction.expose(ExampleControllerClient);
66
- // We might also want global clientside hooks (for authentication)
67
- SocketFunction.addGlobalClientHook<ExampleContext>(null as SocketFunctionHook);
68
- let serverId = await SocketFunctions.connect({ host: "example.com", port: 40981 });
69
- // Cached, so it can be put in a helper function and called every time a call is made
70
- let serverId = SocketFunctions.connectSync({ host: "example.com", port: 40981 });
71
- ExampleController[socket].nodes[serverId].exampleFunction("hi server");
72
- // If you have multiple servers each with many endpoints, you can make helper functions like this:
73
- function exampleControllers() {
74
- let serverId = SocketFunctions.connectSync({ host: "example.com", port: 40981 });
75
- return {
76
- ExampleController: ExampleController[socket].nodes[serverId],
77
- ... etc, with all controllers mapped like this:
78
- }
79
- }
80
-
81
-
82
- export class ExampleController {
83
- // Uses both types AND shape configuration, to prevent functions from accidentally being exposed
84
- // on the public internet...
85
- // - Type checking is done to ensure no functions are exposed that aren't in your type
86
- [socket] = SocketFunction.register<ExampleController, ExampleContext>("ExampleController-2a4b1bd1-d00f-4812-be32-c4466f3c354a", {
87
- exampleFunction: {
88
- // Hooks wrap the call, allowing them to cancel it, change arguments, change the output, run it
89
- // on another thread, check permission, etc, etc
90
- // - Hooks are asynchronously, so they can even trigger other calls, etc
91
- // - Context is passed to hooks
92
- hooks: [] as SocketFunctionHook[],
93
- // Client hooks run before a call, on the client. They have a different context,
94
- // because they won't have information such as caller ip, but they can wrap calls
95
- // in mostly the similar way
96
- clientHooks: [] as SocketFunctionClientHook[]
97
- },
98
- });
99
-
100
- async exampleFunction(arg1: string) {
101
-
102
- }
103
- }
104
-
105
- // ALSO, a shim can be created to avoid exposing your source code to API users (such as webpage).
106
- // - If you want, you can have your implementation import your config shape from the client file,
107
- // that way you only need to write it once.
108
- import type * as Base from "./ExampleController";
109
- export class ExampleController {
110
- [socket] = SocketFunction.register<Base.ExampleController, ExampleContext>("ExampleController-2a4b1bd1-d00f-4812-be32-c4466f3c354a", {
111
- exampleFunction: {
112
- clientHooks: [] as SocketFunctionClientHook[]
113
- },
114
- });
115
- }
1
+ spec.txt
2
+
3
+ - Add the ability to specify the certs yourself (so you can specify your identity with a real cert)
4
+ - Then use real certificates on the server
5
+ - Fix multiple clients on the same machines
6
+ - Maybe we need to exchange link information
7
+ - The login emails SHOULD redirect, if the close doesn't works
8
+ (due to copying the link instead of clicking it)
9
+
10
+ - Other stuff
11
+ - JSON buffer serialize, which generates an object, that allows for rehydration of buffers
12
+ - Also... static classes (maybe even static resources), so structures can be sent
13
+ - Consider forcing everything to use real certs everywhere, and make generating and updating
14
+ certs very easy.
15
+ - ALTHOUGH, maybe this should just be a downstream user of socket-function thing, and not
16
+ a requirement of socket-function?
17
+ - This will be something where machines ask a server for an identity, and then the owner
18
+ allows it (giving them a subdomain), verifying their ip, etc.
19
+ - MAYBE we just automatically allow it? This works if we never use the root domain for anything,
20
+ and only use subdomains?
21
+ - Although, of course, sometimes we WILL want to group by domain, so it is more than just
22
+ identity, so having a way for the owner to authenticate it might be nice as well...
23
+ - Once they are given an identity, they are allowed to request their certs are updated,
24
+ and to get the new certs (it probably won't happen automatically, so that we can create
25
+ many nodes and let them die, without having to try to track which still need certs to be updated)
26
+ - ALSO, remember, for domains, use the domain as the nodeId, not the public key, that way it
27
+ is more consistent.
28
+
29
+
30
+ - https://letx.ca:2542/?classGuid=RequireController-e2f811f3-14b8-4759-b0d6-73f14516cf1d&functionName=requireHTML&args=[%22./test/test%22]
31
+
32
+ ================== SocketFunction ==================
33
+
34
+ - Uses proxies, so that functions can be called before we know the shape of interface
35
+ - Headers
36
+ - Support enabling "Access-Control-Allow-Credentials"/Request.credentials=include, with a hardcoded list of domains
37
+ - Support Access-Control-Allow-Origin, with a hardcoded list of domains
38
+ - Always set
39
+ - response.setHeader("Cross-Origin-Opener-Policy", "same-origin");
40
+ - response.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
41
+ - response.setHeader("Cross-Origin-Resource-Policy", "same-site");
42
+ - Remember to set headers for OPTIONS, but then NOOP
43
+
44
+ // NOTE: It is not possible to expose different services over different ports in the same process.
45
+ // Just run different processes if you want different services.
46
+ SocketFunction.expose(ExampleController);
47
+ // Global hooks are useful for authentication
48
+ SocketFunction.addGlobalHook<ExampleContext>(null as SocketFunctionHook);
49
+ // Mount only after exposing controllers and setting up hooks
50
+ SocketFunction.mount({ port: 40981 });
51
+
52
+
53
+ // callerId is set before each function (and part of the hook context)
54
+ let callerId = ExampleController[socket].callerId;
55
+ let result = await ExampleController[socket].nodes[callerId].exampleFunction("hi");
56
+
57
+
58
+ // An object with context information is available in each call (so arguments don't have to be modified)
59
+ // - register will have a second generic argument that is context, so this will be typed
60
+ ExampleController[socket].callContext
61
+
62
+
63
+
64
+ // Clientside may also wish to expose controllers, possibly the same, or different.
65
+ SocketFunction.expose(ExampleControllerClient);
66
+ // We might also want global clientside hooks (for authentication)
67
+ SocketFunction.addGlobalClientHook<ExampleContext>(null as SocketFunctionHook);
68
+ let serverId = await SocketFunctions.connect({ host: "example.com", port: 40981 });
69
+ // Cached, so it can be put in a helper function and called every time a call is made
70
+ let serverId = SocketFunctions.connectSync({ host: "example.com", port: 40981 });
71
+ ExampleController[socket].nodes[serverId].exampleFunction("hi server");
72
+ // If you have multiple servers each with many endpoints, you can make helper functions like this:
73
+ function exampleControllers() {
74
+ let serverId = SocketFunctions.connectSync({ host: "example.com", port: 40981 });
75
+ return {
76
+ ExampleController: ExampleController[socket].nodes[serverId],
77
+ ... etc, with all controllers mapped like this:
78
+ }
79
+ }
80
+
81
+
82
+ export class ExampleController {
83
+ // Uses both types AND shape configuration, to prevent functions from accidentally being exposed
84
+ // on the public internet...
85
+ // - Type checking is done to ensure no functions are exposed that aren't in your type
86
+ [socket] = SocketFunction.register<ExampleController, ExampleContext>("ExampleController-2a4b1bd1-d00f-4812-be32-c4466f3c354a", {
87
+ exampleFunction: {
88
+ // Hooks wrap the call, allowing them to cancel it, change arguments, change the output, run it
89
+ // on another thread, check permission, etc, etc
90
+ // - Hooks are asynchronously, so they can even trigger other calls, etc
91
+ // - Context is passed to hooks
92
+ hooks: [] as SocketFunctionHook[],
93
+ // Client hooks run before a call, on the client. They have a different context,
94
+ // because they won't have information such as caller ip, but they can wrap calls
95
+ // in mostly the similar way
96
+ clientHooks: [] as SocketFunctionClientHook[]
97
+ },
98
+ });
99
+
100
+ async exampleFunction(arg1: string) {
101
+
102
+ }
103
+ }
104
+
105
+ // ALSO, a shim can be created to avoid exposing your source code to API users (such as webpage).
106
+ // - If you want, you can have your implementation import your config shape from the client file,
107
+ // that way you only need to write it once.
108
+ import type * as Base from "./ExampleController";
109
+ export class ExampleController {
110
+ [socket] = SocketFunction.register<Base.ExampleController, ExampleContext>("ExampleController-2a4b1bd1-d00f-4812-be32-c4466f3c354a", {
111
+ exampleFunction: {
112
+ clientHooks: [] as SocketFunctionClientHook[]
113
+ },
114
+ });
115
+ }