scoundrel-remote-eval 1.0.7 → 1.0.9

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/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 +180 -0
  5. package/build/client/index.d.ts.map +1 -0
  6. package/build/client/index.js +413 -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 +45 -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 +20 -0
  29. package/build/server/index.d.ts.map +1 -0
  30. package/build/server/index.js +26 -0
  31. package/package.json +17 -4
  32. package/spec/reference-with-proxy-spec.js +0 -87
  33. package/spec/support/jasmine.json +0 -13
  34. package/spec/web-socket-javascript-spec.js +0 -64
  35. package/spec/web-socket-python-spec.js +0 -55
  36. package/src/client/connections/web-socket/index.js +0 -51
  37. package/src/client/index.js +0 -423
  38. package/src/client/reference-proxy.js +0 -29
  39. package/src/client/reference.js +0 -67
  40. package/src/index.js +0 -0
  41. package/src/logger.js +0 -56
  42. package/src/python-web-socket-runner.js +0 -87
  43. package/src/server/connections/web-socket/client.js +0 -28
  44. package/src/server/connections/web-socket/index.js +0 -22
  45. package/src/server/index.js +0 -21
@@ -1,29 +0,0 @@
1
- const proxyMethodSpawner = (reference, prop) => (...args) => reference.callMethodWithReference(prop, ...args)
2
-
3
- const proxyObjectHandler = {
4
- get(reference, prop) {
5
- if (typeof reference == "function") reference = reference()
6
-
7
- if (prop == "__serialize") {
8
- const method = reference.serialize
9
- const boundMethod = method.bind(reference)
10
-
11
- return boundMethod
12
- }
13
-
14
- return proxyMethodSpawner(reference, prop)
15
- },
16
-
17
- set(receiver, prop, newValue) {
18
- throw new Error("set property isn't supported yet")
19
-
20
- if (typeof receiver == "function") receiver = receiver()
21
- if (!(prop in receiver)) throw new PropertyNotFoundError(`Property not found: ${prop}`)
22
-
23
- return Reflect.set(receiver, prop, newValue)
24
- }
25
- }
26
-
27
- const referenceProxy = (wrappedObject) => new Proxy(wrappedObject, proxyObjectHandler)
28
-
29
- export default referenceProxy
@@ -1,67 +0,0 @@
1
- export default class Reference {
2
- /**
3
- * Creates a new Reference
4
- *
5
- * @param {any} client The client instance
6
- * @param {string} id The reference ID
7
- */
8
- constructor(client, id) {
9
- this.client = client
10
- this.id = id
11
-
12
- if (!id) throw new Error(`Invalid ID given: ${id}`)
13
- }
14
-
15
- /**
16
- * Calls a method on the reference
17
- *
18
- * @param {string} methodName
19
- * @param {...any} args
20
- * @returns {Promise<any>}
21
- */
22
- async callMethod(methodName, ...args) {
23
- return await this.client.callMethodOnReference(this.id, methodName, ...args)
24
- }
25
-
26
- /**
27
- * Calls a method on the reference using another reference as argument
28
- *
29
- * @param {string} methodName
30
- * @param {...any} args
31
- * @returns {Promise<any>}
32
- */
33
- async callMethodWithReference(methodName, ...args) {
34
- return await this.client.callMethodOnReferenceWithReference(this.id, methodName, ...args)
35
- }
36
-
37
- /**
38
- * Reads an attribute from the reference
39
- *
40
- * @param {string} attributeName
41
- * @param {...any} args
42
- * @returns {Promise<any>}
43
- */
44
- async readAttribute(attributeName, ...args) {
45
- return await this.client.readAttributeOnReference(this.id, attributeName, ...args)
46
- }
47
-
48
- /**
49
- * Reads an attribute from the reference using another reference as argument
50
- *
51
- * @param {string} attributeName
52
- * @param {...any} args
53
- * @returns {Promise<any>}
54
- */
55
- async readAttributeWithReference(attributeName, ...args) {
56
- return await this.client.readAttributeOnReferenceWithReference(this.id, attributeName, ...args)
57
- }
58
-
59
- /**
60
- * Serializes the reference and returns the result directly
61
- *
62
- * @returns {Promise<any>}
63
- */
64
- async serialize() {
65
- return await this.client.serializeReference(this.id)
66
- }
67
- }
package/src/index.js DELETED
File without changes
package/src/logger.js DELETED
@@ -1,56 +0,0 @@
1
- export default class Logger {
2
- /**
3
- * Creates a new Logger instance
4
- *
5
- * @param {string} scopeName The name of the scope for the logger
6
- */
7
- constructor(scopeName) {
8
- this.debug = false
9
- this.scopeName = scopeName
10
- }
11
-
12
- /**
13
- * Enables or disables debug logging
14
- *
15
- * @param {boolean} newValue
16
- */
17
- setDebug(newValue) {
18
- this.debug = newValue
19
- }
20
-
21
- /**
22
- * Logs an error message to the console if debug is enabled
23
- *
24
- * @param {...any} args
25
- */
26
- error(...args) {
27
- return this._sendToConsole("error", ...args)
28
- }
29
-
30
- /**
31
- * Logs a message to the console if debug is enabled
32
- *
33
- * @param {...any} args
34
- */
35
- log(...args) {
36
- return this._sendToConsole("log", ...args)
37
- }
38
-
39
- _sendToConsole(logType, ...args) {
40
- if (!this.debug) {
41
- return
42
- }
43
-
44
- if (args.length == 1 && typeof args[0] == "function") {
45
- const callbackArgs = args[0]()
46
-
47
- if (Array.isArray(callbackArgs)) {
48
- console[logType](this.scopeName, ...callbackArgs)
49
- } else {
50
- console[logType](this.scopeName, callbackArgs)
51
- }
52
- } else {
53
- console[logType](this.scopeName, ...args)
54
- }
55
- }
56
- }
@@ -1,87 +0,0 @@
1
- import {exec, spawn} from "child_process"
2
- import Logger from "./logger.js"
3
- import {realpath} from "node:fs/promises"
4
-
5
- const logger = new Logger("Scoundrel PythonWebSocketRunner")
6
-
7
- // logger.setDebug(true)
8
-
9
- export default class PythonWebSocketRunner {
10
- constructor() {
11
- process.on("exit", this.onProcessExit)
12
- }
13
-
14
- runAndWaitForPid() {
15
- return new Promise((resolve, reject) => {
16
- this.waitForPidResolve = resolve
17
- this.waitForPidReject = reject
18
- this.run()
19
- })
20
- }
21
-
22
- async run() {
23
- const filePath = `${process.cwd()}/../python/server/web-socket.py`
24
- const fileRealPath = await realpath(filePath)
25
- const child = spawn("python3", [fileRealPath])
26
-
27
- child.on("exit", this.onChildExit)
28
- child.stdout.on("data", this.onChildStdout)
29
- child.stderr.on("data", this.onChildStderr)
30
- }
31
-
32
- onProcessExit = () => {
33
- if (this.pid) {
34
- this.close()
35
- logger.log(() => `onProcessExit: Killing Python process with PID ${this.pid}`)
36
- }
37
- }
38
-
39
- onChildExit = (code, signal) => {
40
- logger.log(() => `Child process exited with code ${code} and signal ${signal}`)
41
-
42
- if (this.waitForPidRejectError) {
43
- this.waitForPidReject(this.waitForPidRejectError)
44
- this.waitForPidResolve = null
45
- this.waitForPidReject = null
46
- this.waitForPidRejectError = null
47
- } else if (this.waitForPidReject) {
48
- this.waitForPidReject(new Error(`Python process exited before PID was received (code: ${code}, signal: ${signal})`))
49
- this.waitForPidResolve = null
50
- this.waitForPidReject = null
51
- this.waitForPidRejectError = null
52
- }
53
- }
54
-
55
- onChildStderr = (data) => {
56
- logger.error(() => `stderr: ${data}`)
57
-
58
- if (this.waitForPidReject) {
59
- this.waitForPidRejectError = new Error(`Python process stderr before PID was received: ${data}`)
60
- }
61
- }
62
-
63
- onChildStdout = (data) => {
64
- logger.log(() => `stdout: ${data}`)
65
-
66
- const match = (`${data}`).match(/^Started with PID (\d+) on (.+):(.+)\n$/)
67
-
68
- if (match) {
69
- this.pid = match[1]
70
-
71
- logger.log(() => `Registered PID ${this.pid}`)
72
-
73
- if (this.waitForPidResolve) {
74
- this.waitForPidResolve()
75
- this.waitForPidResolve = null
76
- this.waitForPidReject = null
77
- this.waitForPidRejectError = null
78
- }
79
- }
80
- }
81
-
82
- close() {
83
- if (this.pid) {
84
- exec(`kill ${this.pid}`)
85
- }
86
- }
87
- }
@@ -1,28 +0,0 @@
1
- export default class WebSocketClient {
2
- constructor(ws) {
3
- this.ws = ws
4
-
5
- ws.on("error", this.onError)
6
- ws.on("message", this.onMessage)
7
- }
8
-
9
- onCommand(callback) {
10
- this.onCommandCallback = callback
11
- }
12
-
13
- onError = (error) => {
14
- console.error("WebSocketClient error", error)
15
- }
16
-
17
- onMessage = (rawData) => {
18
- const data = JSON.parse(rawData)
19
-
20
- if (!this.onCommandCallback) throw new Error("Command callback hasn't been set")
21
-
22
- this.onCommandCallback(data)
23
- }
24
-
25
- async send(data) {
26
- await this.ws.send(JSON.stringify(data))
27
- }
28
- }
@@ -1,22 +0,0 @@
1
- import WebSocketClient from "./client.js"
2
-
3
- export default class WebSocket {
4
- constructor(webSocketServer) {
5
- this.wss = webSocketServer
6
- this.wss.on("connection", this.onConnection)
7
- }
8
-
9
- close() { this.wss.close() }
10
-
11
- onConnection = (ws) => {
12
- if (!this.onNewClientCallback) throw new Error("'onNewClient' hasn't been called")
13
-
14
- this.onNewClientCallback(new WebSocketClient(ws))
15
- }
16
-
17
- onNewClient(callback) {
18
- if (!callback) throw new Error("No callback was given")
19
-
20
- this.onNewClientCallback = callback
21
- }
22
- }
@@ -1,21 +0,0 @@
1
- import Client from "../client/index.js"
2
- import EventEmitter from "events"
3
-
4
- export default class ScoundrelServer {
5
- constructor(backend) {
6
- this.backend = backend
7
- this.backend.onNewClient(this.onNewClient)
8
- this.clients = []
9
- this.events = new EventEmitter()
10
- }
11
-
12
- close() { this.backend.close() }
13
- getClients() { return this.clients }
14
-
15
- onNewClient = (clientBackend) => {
16
- const client = new Client(clientBackend)
17
-
18
- this.clients.push(client)
19
- this.events.emit("newClient", client)
20
- }
21
- }