scoundrel-remote-eval 1.0.8 → 1.0.10

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 (50) hide show
  1. package/build/client/connections/web-socket/index.d.ts +34 -0
  2. package/build/client/connections/web-socket/index.d.ts.map +1 -0
  3. package/build/client/connections/web-socket/index.js +68 -0
  4. package/build/client/index.d.ts +186 -0
  5. package/build/client/index.d.ts.map +1 -0
  6. package/build/client/index.js +452 -0
  7. package/build/client/reference-proxy.d.ts +7 -0
  8. package/build/client/reference-proxy.d.ts.map +1 -0
  9. package/build/client/reference-proxy.js +41 -0
  10. package/build/client/reference.d.ts +50 -0
  11. package/build/client/reference.d.ts.map +1 -0
  12. package/build/client/reference.js +63 -0
  13. package/build/index.d.ts +2 -0
  14. package/build/index.d.ts.map +1 -0
  15. package/build/index.js +1 -0
  16. package/build/logger.d.ts +39 -0
  17. package/build/logger.d.ts.map +1 -0
  18. package/build/logger.js +64 -0
  19. package/build/python-web-socket-runner.d.ts +27 -0
  20. package/build/python-web-socket-runner.d.ts.map +1 -0
  21. package/build/python-web-socket-runner.js +94 -0
  22. package/build/server/connections/web-socket/client.d.ts +26 -0
  23. package/build/server/connections/web-socket/client.d.ts.map +1 -0
  24. package/build/server/connections/web-socket/client.js +39 -0
  25. package/build/server/connections/web-socket/index.d.ts +19 -0
  26. package/build/server/connections/web-socket/index.d.ts.map +1 -0
  27. package/build/server/connections/web-socket/index.js +29 -0
  28. package/build/server/index.d.ts +27 -0
  29. package/build/server/index.d.ts.map +1 -0
  30. package/build/server/index.js +34 -0
  31. package/build/utils/single-event-emitter.d.ts +46 -0
  32. package/build/utils/single-event-emitter.d.ts.map +1 -0
  33. package/build/utils/single-event-emitter.js +86 -0
  34. package/package.json +9 -3
  35. package/eslint.config.js +0 -18
  36. package/spec/reference-with-proxy-spec.js +0 -101
  37. package/spec/support/jasmine.json +0 -13
  38. package/spec/web-socket-javascript-spec.js +0 -66
  39. package/spec/web-socket-python-spec.js +0 -57
  40. package/src/client/connections/web-socket/index.js +0 -88
  41. package/src/client/index.js +0 -469
  42. package/src/client/reference-proxy.js +0 -53
  43. package/src/client/reference.js +0 -69
  44. package/src/index.js +0 -0
  45. package/src/logger.js +0 -70
  46. package/src/python-web-socket-runner.js +0 -116
  47. package/src/server/connections/web-socket/client.js +0 -46
  48. package/src/server/connections/web-socket/index.js +0 -34
  49. package/src/server/index.js +0 -33
  50. package/tsconfig.json +0 -13
@@ -0,0 +1,34 @@
1
+ export default class WebSocket {
2
+ /**
3
+ * Creates a new WebSocket connection handler
4
+ * @param {WebSocket} ws The WebSocket instance
5
+ */
6
+ constructor(ws: WebSocket);
7
+ ws: WebSocket;
8
+ commands: {};
9
+ commandsCount: number;
10
+ close(): Promise<void>;
11
+ /**
12
+ * @param {(data: any) => void} callback
13
+ */
14
+ onCommand(callback: (data: any) => void): void;
15
+ onCommandCallback: (data: any) => void;
16
+ /**
17
+ * @param {Event} event
18
+ */
19
+ onSocketError: (event: Event) => void;
20
+ /**
21
+ * @param {MessageEvent} event
22
+ */
23
+ onSocketMessage: (event: MessageEvent) => void;
24
+ /**
25
+ * @param {Event} event
26
+ */
27
+ onSocketOpen: (event: Event) => void;
28
+ /**
29
+ * @param {Record<string, any>} data
30
+ */
31
+ send(data: Record<string, any>): void;
32
+ waitForOpened: () => Promise<any>;
33
+ }
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/connections/web-socket/index.js"],"names":[],"mappings":"AAQA;IACE;;;OAGG;IACH,gBAFW,SAAS,EAgBnB;IAbC,cAAY;IAWZ,aAAkB;IAClB,sBAAsB;IAGxB,uBAEC;IAED;;OAEG;IACH,oBAFW,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,QAI7B;IADC,0BAHgB,GAAG,KAAK,IAAI,CAGK;IAGnC;;OAEG;IACH,gBAAiB,OAFN,KAEW,UAErB;IAED;;OAEG;IACH,kBAAmB,OAFR,YAEa,UAUvB;IAED;;OAEG;IACH,eAAgB,OAFL,KAEU,UAEpB;IAED;;OAEG;IACH,WAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAQ7B;IAED,kCAME;CACH"}
@@ -0,0 +1,68 @@
1
+ // @ts-check
2
+ import Logger from "../../../logger.js";
3
+ const logger = new Logger("Scoundrel WebSocket");
4
+ // logger.setDebug(true)
5
+ export default class WebSocket {
6
+ /**
7
+ * Creates a new WebSocket connection handler
8
+ * @param {WebSocket} ws The WebSocket instance
9
+ */
10
+ constructor(ws) {
11
+ /**
12
+ * @param {Event} event
13
+ */
14
+ this.onSocketError = (event) => {
15
+ logger.error(() => ["onSocketError", event]);
16
+ };
17
+ /**
18
+ * @param {MessageEvent} event
19
+ */
20
+ this.onSocketMessage = (event) => {
21
+ const data = JSON.parse(event.data);
22
+ logger.log(() => ["Client::Connections::WebSocket onSocketMessage", data]);
23
+ if (!this.onCommandCallback) {
24
+ throw new Error("No onCommand callback set, ignoring message");
25
+ }
26
+ this.onCommandCallback(data);
27
+ };
28
+ /**
29
+ * @param {Event} event
30
+ */
31
+ this.onSocketOpen = (event) => {
32
+ logger.log(() => ["onSocketOpen", event]);
33
+ };
34
+ this.waitForOpened = () => new Promise((resolve, reject) => {
35
+ // @ts-ignore
36
+ this.ws.addEventListener("open", resolve);
37
+ // @ts-ignore
38
+ this.ws.addEventListener("error", reject);
39
+ });
40
+ this.ws = ws;
41
+ // @ts-ignore
42
+ this.ws.addEventListener("error", this.onSocketError);
43
+ // @ts-ignore
44
+ this.ws.addEventListener("open", this.onSocketOpen);
45
+ // @ts-ignore
46
+ this.ws.addEventListener("message", this.onSocketMessage);
47
+ this.commands = {};
48
+ this.commandsCount = 0;
49
+ }
50
+ async close() {
51
+ await this.ws.close();
52
+ }
53
+ /**
54
+ * @param {(data: any) => void} callback
55
+ */
56
+ onCommand(callback) {
57
+ this.onCommandCallback = callback;
58
+ }
59
+ /**
60
+ * @param {Record<string, any>} data
61
+ */
62
+ send(data) {
63
+ const sendData = JSON.stringify(data);
64
+ logger.log(() => ["Sending", sendData]);
65
+ // @ts-ignore
66
+ this.ws.send(sendData);
67
+ }
68
+ }
@@ -0,0 +1,186 @@
1
+ export default class Client {
2
+ /**
3
+ * Creates a new Scoundrel Client
4
+ *
5
+ * @param {any} backend The backend connection (e.g., WebSocket)
6
+ * @param {{enableServerControl?: boolean}} [options]
7
+ */
8
+ constructor(backend: any, options?: {
9
+ enableServerControl?: boolean;
10
+ });
11
+ backend: any;
12
+ /** @type {Record<number, any>} */
13
+ outgoingCommands: Record<number, any>;
14
+ incomingCommands: {};
15
+ outgoingCommandsCount: number;
16
+ /** @type {Record<string, any>} */
17
+ _classes: Record<string, any>;
18
+ /** @type {Record<string, any>} */
19
+ _objects: Record<string, any>;
20
+ /** @type {Record<string, Reference>} */
21
+ references: Record<string, Reference>;
22
+ /** @type {Record<number, any>} */
23
+ objects: Record<number, any>;
24
+ objectsCount: number;
25
+ /** @type {boolean} */
26
+ serverControlEnabled: boolean;
27
+ /**
28
+ * Closes the client connection
29
+ */
30
+ close(): Promise<void>;
31
+ /**
32
+ * Calls a method on a reference and returns the result directly
33
+ *
34
+ * @param {number} referenceId
35
+ * @param {string} methodName
36
+ * @param {...any} args
37
+ * @returns {Promise<any>}
38
+ */
39
+ callMethodOnReference(referenceId: number, methodName: string, ...args: any[]): Promise<any>;
40
+ /**
41
+ * Calls a method on a reference and returns a new reference
42
+ *
43
+ * @param {number} referenceId
44
+ * @param {string} methodName
45
+ * @param {...any} args
46
+ * @returns {Promise<Reference>}
47
+ */
48
+ callMethodOnReferenceWithReference(referenceId: number, methodName: string, ...args: any[]): Promise<Reference>;
49
+ /**
50
+ * Evaluates a string and returns a new reference
51
+ *
52
+ * @param {string} evalString
53
+ * @returns {Promise<Reference>}
54
+ */
55
+ evalWithReference(evalString: string): Promise<Reference>;
56
+ /**
57
+ * Imports a module and returns a reference to it
58
+ *
59
+ * @param {string} importName
60
+ * @returns {Promise<Reference>}
61
+ */
62
+ import(importName: string): Promise<Reference>;
63
+ /**
64
+ * Gets a registered object by name
65
+ *
66
+ * @param {string} objectName
67
+ * @returns {Promise<Reference>}
68
+ */
69
+ getObject(objectName: string): Promise<Reference>;
70
+ /**
71
+ * Spawns a new reference to an object
72
+ *
73
+ * @param {string} className
74
+ * @param {...any} args
75
+ * @returns {Promise<Reference>}
76
+ */
77
+ newObjectWithReference(className: string, ...args: any[]): Promise<Reference>;
78
+ /**
79
+ * Checks if the input is a plain object
80
+ * @param {any} input
81
+ * @returns {boolean}
82
+ */
83
+ isPlainObject(input: any): boolean;
84
+ /**
85
+ * Handles an incoming command from the backend
86
+ * @param {object} args
87
+ * @param {string} args.command
88
+ * @param {number} args.command_id
89
+ * @param {any} args.data
90
+ * @param {string} [args.error]
91
+ * @param {string} [args.errorStack]
92
+ */
93
+ onCommand: ({ command, command_id: commandID, data, error, errorStack, ...restArgs }: {
94
+ command: string;
95
+ command_id: number;
96
+ data: any;
97
+ error?: string;
98
+ errorStack?: string;
99
+ }) => void;
100
+ /**
101
+ * Parases an argument for sending to the server
102
+ *
103
+ * @param {any} arg
104
+ * @returns {any}
105
+ */
106
+ parseArg(arg: any): any;
107
+ /**
108
+ * Reads an attribute on a reference and returns a new reference
109
+ *
110
+ * @param {number} referenceId
111
+ * @param {string} attributeName
112
+ * @returns {Promise<Reference>}
113
+ */
114
+ readAttributeOnReferenceWithReference(referenceId: number, attributeName: string): Promise<Reference>;
115
+ /**
116
+ * Reads an attribute on a reference and returns the result directly
117
+ *
118
+ * @param {number} referenceId
119
+ * @param {string} attributeName
120
+ * @returns {Promise<any>}
121
+ */
122
+ readAttributeOnReference(referenceId: number, attributeName: string): Promise<any>;
123
+ /**
124
+ * Registers a class by name
125
+ *
126
+ * @param {string} className
127
+ * @param {any} classInstance
128
+ */
129
+ registerClass(className: string, classInstance: any): void;
130
+ /**
131
+ * Gets a registered class by name
132
+ *
133
+ * @param {string} className
134
+ * @returns {any}
135
+ */
136
+ getClass(className: string): any;
137
+ /**
138
+ * Registers an object by name
139
+ *
140
+ * @param {string} objectName
141
+ * @param {any} objectInstance
142
+ */
143
+ registerObject(objectName: string, objectInstance: any): void;
144
+ /**
145
+ * Gets a registered object by name
146
+ *
147
+ * @param {string} objectName
148
+ * @returns {any}
149
+ */
150
+ _getRegisteredObject(objectName: string): any;
151
+ /**
152
+ * Responds to a command from the backend
153
+ * @param {number} commandId
154
+ * @param {any} data
155
+ */
156
+ respondToCommand(commandId: number, data: any): void;
157
+ /**
158
+ * Sends a command to the backend and returns a promise that resolves with the response
159
+ * @param {string} command
160
+ * @param {any} data
161
+ * @returns {Promise<any>}
162
+ */
163
+ sendCommand(command: string, data: any): Promise<any>;
164
+ /**
165
+ * Sends data to the backend
166
+ * @param {any} data
167
+ */
168
+ send(data: any): void;
169
+ /**
170
+ * Serializes a reference and returns the result directly
171
+ *
172
+ * @param {number} referenceId
173
+ * @returns {Promise<any>}
174
+ */
175
+ serializeReference(referenceId: number): Promise<any>;
176
+ /**
177
+ * Spawns a new reference to an object
178
+ *
179
+ * @param {string} id
180
+ * @returns {Reference}
181
+ */
182
+ spawnReference(id: string): Reference;
183
+ enableServerControl(): void;
184
+ }
185
+ import Reference from "./reference.js";
186
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.js"],"names":[],"mappings":"AASA;IACE;;;;;OAKG;IACH,qBAHW,GAAG,YACH;QAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;KAAC,EA2BzC;IAxBC,aAAsB;IAGtB,kCAAkC;IAClC,kBADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACJ;IAC1B,qBAA0B;IAC1B,8BAA8B;IAE9B,kCAAkC;IAClC,UADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACZ;IAElB,kCAAkC;IAClC,UADW,MAAM,CAAC,MAAM,EAAE,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