@aztec/foundation 0.7.2 → 0.7.3
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/.tsbuildinfo +1 -0
- package/dest/abi/abi.d.ts +232 -0
- package/dest/abi/abi.d.ts.map +1 -0
- package/dest/abi/abi.js +37 -0
- package/dest/abi/abi_coder.d.ts +8 -0
- package/dest/abi/abi_coder.d.ts.map +1 -0
- package/dest/abi/abi_coder.js +24 -0
- package/dest/abi/decoder.d.ts +57 -0
- package/dest/abi/decoder.d.ts.map +1 -0
- package/dest/abi/decoder.js +149 -0
- package/dest/abi/decoder.test.d.ts +2 -0
- package/dest/abi/decoder.test.d.ts.map +1 -0
- package/dest/abi/decoder.test.js +70 -0
- package/dest/abi/encoder.d.ts +10 -0
- package/dest/abi/encoder.d.ts.map +1 -0
- package/dest/abi/encoder.js +89 -0
- package/dest/abi/encoder.test.d.ts +2 -0
- package/dest/abi/encoder.test.d.ts.map +1 -0
- package/dest/abi/encoder.test.js +74 -0
- package/dest/abi/function_selector.d.ts +73 -0
- package/dest/abi/function_selector.d.ts.map +1 -0
- package/dest/abi/function_selector.js +104 -0
- package/dest/abi/index.d.ts +6 -0
- package/dest/abi/index.d.ts.map +1 -0
- package/dest/abi/index.js +6 -0
- package/dest/async-map/async_map.test.d.ts +2 -0
- package/dest/async-map/async_map.test.d.ts.map +1 -0
- package/dest/async-map/async_map.test.js +9 -0
- package/dest/async-map/index.d.ts +13 -0
- package/dest/async-map/index.d.ts.map +1 -0
- package/dest/async-map/index.js +19 -0
- package/dest/aztec-address/index.d.ts +114 -0
- package/dest/aztec-address/index.d.ts.map +1 -0
- package/dest/aztec-address/index.js +148 -0
- package/dest/bigint-buffer/bigint-buffer.test.d.ts +2 -0
- package/dest/bigint-buffer/bigint-buffer.test.d.ts.map +1 -0
- package/dest/bigint-buffer/bigint-buffer.test.js +18 -0
- package/dest/bigint-buffer/index.d.ts +35 -0
- package/dest/bigint-buffer/index.d.ts.map +1 -0
- package/dest/bigint-buffer/index.js +68 -0
- package/dest/collection/array.d.ts +30 -0
- package/dest/collection/array.d.ts.map +1 -0
- package/dest/collection/array.js +47 -0
- package/dest/collection/index.d.ts +2 -0
- package/dest/collection/index.d.ts.map +1 -0
- package/dest/collection/index.js +2 -0
- package/dest/committable/committable.d.ts +28 -0
- package/dest/committable/committable.d.ts.map +1 -0
- package/dest/committable/committable.js +41 -0
- package/dest/committable/committable.test.d.ts +2 -0
- package/dest/committable/committable.test.d.ts.map +1 -0
- package/dest/committable/committable.test.js +26 -0
- package/dest/committable/index.d.ts +2 -0
- package/dest/committable/index.d.ts.map +1 -0
- package/dest/committable/index.js +2 -0
- package/dest/crypto/index.d.ts +4 -0
- package/dest/crypto/index.d.ts.map +1 -0
- package/dest/crypto/index.js +4 -0
- package/dest/crypto/keccak/index.d.ts +20 -0
- package/dest/crypto/keccak/index.d.ts.map +1 -0
- package/dest/crypto/keccak/index.js +31 -0
- package/dest/crypto/random/index.d.ts +3 -0
- package/dest/crypto/random/index.d.ts.map +1 -0
- package/dest/crypto/random/index.js +36 -0
- package/dest/crypto/random/index.test.d.ts +2 -0
- package/dest/crypto/random/index.test.d.ts.map +1 -0
- package/dest/crypto/random/index.test.js +13 -0
- package/dest/crypto/sha256/index.d.ts +11 -0
- package/dest/crypto/sha256/index.d.ts.map +1 -0
- package/dest/crypto/sha256/index.js +14 -0
- package/dest/crypto/sha256/index.test.d.ts +2 -0
- package/dest/crypto/sha256/index.test.d.ts.map +1 -0
- package/dest/crypto/sha256/index.test.js +11 -0
- package/dest/errors/index.d.ts +8 -0
- package/dest/errors/index.d.ts.map +1 -0
- package/dest/errors/index.js +8 -0
- package/dest/eth-address/eth_address.test.d.ts +2 -0
- package/dest/eth-address/eth_address.test.d.ts.map +1 -0
- package/dest/eth-address/eth_address.test.js +95 -0
- package/dest/eth-address/index.d.ts +144 -0
- package/dest/eth-address/index.d.ts.map +1 -0
- package/dest/eth-address/index.js +228 -0
- package/dest/fields/coordinate.d.ts +67 -0
- package/dest/fields/coordinate.d.ts.map +1 -0
- package/dest/fields/coordinate.js +95 -0
- package/dest/fields/coordinate.test.d.ts +2 -0
- package/dest/fields/coordinate.test.d.ts.map +1 -0
- package/dest/fields/coordinate.test.js +22 -0
- package/dest/fields/fields.d.ts +177 -0
- package/dest/fields/fields.d.ts.map +1 -0
- package/dest/fields/fields.js +219 -0
- package/dest/fields/grumpkin_scalar.d.ts +96 -0
- package/dest/fields/grumpkin_scalar.d.ts.map +1 -0
- package/dest/fields/grumpkin_scalar.js +125 -0
- package/dest/fields/grumpkin_scalar.test.d.ts +2 -0
- package/dest/fields/grumpkin_scalar.test.d.ts.map +1 -0
- package/dest/fields/grumpkin_scalar.test.js +45 -0
- package/dest/fields/index.d.ts +5 -0
- package/dest/fields/index.d.ts.map +1 -0
- package/dest/fields/index.js +5 -0
- package/dest/fields/point.d.ts +105 -0
- package/dest/fields/point.d.ts.map +1 -0
- package/dest/fields/point.js +125 -0
- package/dest/fifo/bounded_serial_queue.d.ts +56 -0
- package/dest/fifo/bounded_serial_queue.d.ts.map +1 -0
- package/dest/fifo/bounded_serial_queue.js +94 -0
- package/dest/fifo/index.d.ts +5 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +5 -0
- package/dest/fifo/memory_fifo.d.ts +55 -0
- package/dest/fifo/memory_fifo.d.ts.map +1 -0
- package/dest/fifo/memory_fifo.js +109 -0
- package/dest/fifo/semaphore.d.ts +23 -0
- package/dest/fifo/semaphore.d.ts.map +1 -0
- package/dest/fifo/semaphore.js +30 -0
- package/dest/fifo/serial_queue.d.ts +48 -0
- package/dest/fifo/serial_queue.d.ts.map +1 -0
- package/dest/fifo/serial_queue.js +74 -0
- package/dest/json-rpc/class_converter.d.ts +144 -0
- package/dest/json-rpc/class_converter.d.ts.map +1 -0
- package/dest/json-rpc/class_converter.js +100 -0
- package/dest/json-rpc/client/index.d.ts +2 -0
- package/dest/json-rpc/client/index.d.ts.map +1 -0
- package/dest/json-rpc/client/index.js +2 -0
- package/dest/json-rpc/client/json_rpc_client.d.ts +29 -0
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -0
- package/dest/json-rpc/client/json_rpc_client.js +104 -0
- package/dest/json-rpc/client/json_rpc_client.test.d.ts +2 -0
- package/dest/json-rpc/client/json_rpc_client.test.d.ts.map +1 -0
- package/dest/json-rpc/client/json_rpc_client.test.js +20 -0
- package/dest/json-rpc/convert.d.ts +28 -0
- package/dest/json-rpc/convert.d.ts.map +1 -0
- package/dest/json-rpc/convert.js +139 -0
- package/dest/json-rpc/convert.test.d.ts +2 -0
- package/dest/json-rpc/convert.test.d.ts.map +1 -0
- package/dest/json-rpc/convert.test.js +68 -0
- package/dest/json-rpc/fixtures/class_a.d.ts +11 -0
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_a.js +17 -0
- package/dest/json-rpc/fixtures/class_b.d.ts +11 -0
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_b.js +17 -0
- package/dest/json-rpc/fixtures/test_state.d.ts +47 -0
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/test_state.js +62 -0
- package/dest/json-rpc/index.d.ts +3 -0
- package/dest/json-rpc/index.d.ts.map +1 -0
- package/dest/json-rpc/index.js +3 -0
- package/dest/json-rpc/js_utils.d.ts +13 -0
- package/dest/json-rpc/js_utils.d.ts.map +1 -0
- package/dest/json-rpc/js_utils.js +18 -0
- package/dest/json-rpc/server/index.d.ts +3 -0
- package/dest/json-rpc/server/index.d.ts.map +1 -0
- package/dest/json-rpc/server/index.js +3 -0
- package/dest/json-rpc/server/json_proxy.d.ts +18 -0
- package/dest/json-rpc/server/json_proxy.d.ts.map +1 -0
- package/dest/json-rpc/server/json_proxy.js +36 -0
- package/dest/json-rpc/server/json_rpc_server.d.ts +34 -0
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -0
- package/dest/json-rpc/server/json_rpc_server.js +133 -0
- package/dest/json-rpc/server/json_rpc_server.test.d.ts +2 -0
- package/dest/json-rpc/server/json_rpc_server.test.d.ts.map +1 -0
- package/dest/json-rpc/server/json_rpc_server.test.js +22 -0
- package/dest/log/console.d.ts +11 -0
- package/dest/log/console.d.ts.map +1 -0
- package/dest/log/console.js +38 -0
- package/dest/log/debug.d.ts +43 -0
- package/dest/log/debug.d.ts.map +1 -0
- package/dest/log/debug.js +75 -0
- package/dest/log/index.d.ts +9 -0
- package/dest/log/index.d.ts.map +1 -0
- package/dest/log/index.js +5 -0
- package/dest/log/log_history.d.ts +31 -0
- package/dest/log/log_history.d.ts.map +1 -0
- package/dest/log/log_history.js +42 -0
- package/dest/log/log_history.test.d.ts +2 -0
- package/dest/log/log_history.test.d.ts.map +1 -0
- package/dest/log/log_history.test.js +78 -0
- package/dest/log/logger.d.ts +34 -0
- package/dest/log/logger.d.ts.map +1 -0
- package/dest/log/logger.js +78 -0
- package/dest/mutex/index.d.ts +53 -0
- package/dest/mutex/index.d.ts.map +1 -0
- package/dest/mutex/index.js +74 -0
- package/dest/mutex/mutex.test.d.ts +9 -0
- package/dest/mutex/mutex.test.d.ts.map +1 -0
- package/dest/mutex/mutex.test.js +58 -0
- package/dest/mutex/mutex_database.d.ts +10 -0
- package/dest/mutex/mutex_database.d.ts.map +1 -0
- package/dest/mutex/mutex_database.js +2 -0
- package/dest/retry/index.d.ts +44 -0
- package/dest/retry/index.d.ts.map +1 -0
- package/dest/retry/index.js +89 -0
- package/dest/running-promise/index.d.ts +35 -0
- package/dest/running-promise/index.d.ts.map +1 -0
- package/dest/running-promise/index.js +59 -0
- package/dest/serialize/buffer_reader.d.ts +188 -0
- package/dest/serialize/buffer_reader.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.js +229 -0
- package/dest/serialize/buffer_reader.test.d.ts +2 -0
- package/dest/serialize/buffer_reader.test.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.test.js +156 -0
- package/dest/serialize/deserializer.d.ts +134 -0
- package/dest/serialize/deserializer.d.ts.map +1 -0
- package/dest/serialize/deserializer.js +145 -0
- package/dest/serialize/free_funcs.d.ts +203 -0
- package/dest/serialize/free_funcs.d.ts.map +1 -0
- package/dest/serialize/free_funcs.js +250 -0
- package/dest/serialize/index.d.ts +6 -0
- package/dest/serialize/index.d.ts.map +1 -0
- package/dest/serialize/index.js +6 -0
- package/dest/serialize/serialize.test.d.ts +2 -0
- package/dest/serialize/serialize.test.d.ts.map +1 -0
- package/dest/serialize/serialize.test.js +68 -0
- package/dest/serialize/serializer.d.ts +89 -0
- package/dest/serialize/serializer.d.ts.map +1 -0
- package/dest/serialize/serializer.js +111 -0
- package/dest/serialize/types.d.ts +33 -0
- package/dest/serialize/types.d.ts.map +1 -0
- package/dest/serialize/types.js +22 -0
- package/dest/sleep/index.d.ts +52 -0
- package/dest/sleep/index.d.ts.map +1 -0
- package/dest/sleep/index.js +70 -0
- package/dest/timer/index.d.ts +3 -0
- package/dest/timer/index.d.ts.map +1 -0
- package/dest/timer/index.js +3 -0
- package/dest/timer/timeout.d.ts +41 -0
- package/dest/timer/timeout.d.ts.map +1 -0
- package/dest/timer/timeout.js +62 -0
- package/dest/timer/timer.d.ts +33 -0
- package/dest/timer/timer.d.ts.map +1 -0
- package/dest/timer/timer.js +38 -0
- package/dest/transport/browser/index.d.ts +5 -0
- package/dest/transport/browser/index.d.ts.map +1 -0
- package/dest/transport/browser/index.js +5 -0
- package/dest/transport/browser/message_port_socket.d.ts +37 -0
- package/dest/transport/browser/message_port_socket.d.ts.map +1 -0
- package/dest/transport/browser/message_port_socket.js +46 -0
- package/dest/transport/browser/shared_worker_connector.d.ts +19 -0
- package/dest/transport/browser/shared_worker_connector.d.ts.map +1 -0
- package/dest/transport/browser/shared_worker_connector.js +21 -0
- package/dest/transport/browser/shared_worker_listener.d.ts +38 -0
- package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -0
- package/dest/transport/browser/shared_worker_listener.js +37 -0
- package/dest/transport/browser/worker_connector.d.ts +26 -0
- package/dest/transport/browser/worker_connector.d.ts.map +1 -0
- package/dest/transport/browser/worker_connector.js +30 -0
- package/dest/transport/browser/worker_listener.d.ts +39 -0
- package/dest/transport/browser/worker_listener.d.ts.map +1 -0
- package/dest/transport/browser/worker_listener.js +39 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +25 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -0
- package/dest/transport/dispatch/create_dispatch_fn.js +18 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +102 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -0
- package/dest/transport/dispatch/create_dispatch_proxy.js +56 -0
- package/dest/transport/dispatch/messages.d.ts +52 -0
- package/dest/transport/dispatch/messages.d.ts.map +1 -0
- package/dest/transport/dispatch/messages.js +12 -0
- package/dest/transport/index.d.ts +12 -0
- package/dest/transport/index.d.ts.map +1 -0
- package/dest/transport/index.js +12 -0
- package/dest/transport/interface/connector.d.ts +8 -0
- package/dest/transport/interface/connector.d.ts.map +1 -0
- package/dest/transport/interface/connector.js +2 -0
- package/dest/transport/interface/listener.d.ts +13 -0
- package/dest/transport/interface/listener.d.ts.map +1 -0
- package/dest/transport/interface/listener.js +2 -0
- package/dest/transport/interface/socket.d.ts +13 -0
- package/dest/transport/interface/socket.d.ts.map +1 -0
- package/dest/transport/interface/socket.js +2 -0
- package/dest/transport/interface/transferable.d.ts +68 -0
- package/dest/transport/interface/transferable.d.ts.map +1 -0
- package/dest/transport/interface/transferable.js +63 -0
- package/dest/transport/node/index.d.ts +3 -0
- package/dest/transport/node/index.d.ts.map +1 -0
- package/dest/transport/node/index.js +3 -0
- package/dest/transport/node/node_connector.d.ts +28 -0
- package/dest/transport/node/node_connector.d.ts.map +1 -0
- package/dest/transport/node/node_connector.js +28 -0
- package/dest/transport/node/node_connector_socket.d.ts +42 -0
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -0
- package/dest/transport/node/node_connector_socket.js +48 -0
- package/dest/transport/node/node_listener.d.ts +26 -0
- package/dest/transport/node/node_listener.d.ts.map +1 -0
- package/dest/transport/node/node_listener.js +30 -0
- package/dest/transport/node/node_listener_socket.d.ts +37 -0
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -0
- package/dest/transport/node/node_listener_socket.js +44 -0
- package/dest/transport/transport_client.d.ts +61 -0
- package/dest/transport/transport_client.d.ts.map +1 -0
- package/dest/transport/transport_client.js +94 -0
- package/dest/transport/transport_server.d.ts +56 -0
- package/dest/transport/transport_server.d.ts.map +1 -0
- package/dest/transport/transport_server.js +101 -0
- package/dest/types/index.d.ts +7 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +2 -0
- package/dest/url/index.d.ts +9 -0
- package/dest/url/index.d.ts.map +1 -0
- package/dest/url/index.js +66 -0
- package/dest/wasm/empty_wasi_sdk.d.ts +130 -0
- package/dest/wasm/empty_wasi_sdk.d.ts.map +1 -0
- package/dest/wasm/empty_wasi_sdk.js +166 -0
- package/dest/wasm/index.d.ts +2 -0
- package/dest/wasm/index.d.ts.map +1 -0
- package/dest/wasm/index.js +2 -0
- package/dest/wasm/wasm_module.d.ts +135 -0
- package/dest/wasm/wasm_module.d.ts.map +1 -0
- package/dest/wasm/wasm_module.js +205 -0
- package/dest/wasm/wasm_module.test.d.ts +2 -0
- package/dest/wasm/wasm_module.test.d.ts.map +1 -0
- package/dest/wasm/wasm_module.test.js +24 -0
- package/dest/worker/browser/index.d.ts +3 -0
- package/dest/worker/browser/index.d.ts.map +1 -0
- package/dest/worker/browser/index.js +3 -0
- package/dest/worker/browser/start_web_module.d.ts +7 -0
- package/dest/worker/browser/start_web_module.d.ts.map +1 -0
- package/dest/worker/browser/start_web_module.js +22 -0
- package/dest/worker/browser/web_data_store.d.ts +23 -0
- package/dest/worker/browser/web_data_store.d.ts.map +1 -0
- package/dest/worker/browser/web_data_store.js +32 -0
- package/dest/worker/browser/web_worker.d.ts +10 -0
- package/dest/worker/browser/web_worker.d.ts.map +1 -0
- package/dest/worker/browser/web_worker.js +23 -0
- package/dest/worker/data_store.d.ts +20 -0
- package/dest/worker/data_store.d.ts.map +1 -0
- package/dest/worker/data_store.js +2 -0
- package/dest/worker/index.d.ts +3 -0
- package/dest/worker/index.d.ts.map +1 -0
- package/dest/worker/index.js +2 -0
- package/dest/worker/node/index.d.ts +3 -0
- package/dest/worker/node/index.d.ts.map +1 -0
- package/dest/worker/node/index.js +3 -0
- package/dest/worker/node/node_data_store.d.ts +12 -0
- package/dest/worker/node/node_data_store.d.ts.map +1 -0
- package/dest/worker/node/node_data_store.js +21 -0
- package/dest/worker/node/node_worker.d.ts +6 -0
- package/dest/worker/node/node_worker.d.ts.map +1 -0
- package/dest/worker/node/node_worker.js +20 -0
- package/dest/worker/node/start_node_module.d.ts +7 -0
- package/dest/worker/node/start_node_module.d.ts.map +1 -0
- package/dest/worker/node/start_node_module.js +26 -0
- package/dest/worker/wasm_worker.d.ts +9 -0
- package/dest/worker/wasm_worker.d.ts.map +1 -0
- package/dest/worker/wasm_worker.js +2 -0
- package/dest/worker/worker_pool.d.ts +40 -0
- package/dest/worker/worker_pool.d.ts.map +1 -0
- package/dest/worker/worker_pool.js +62 -0
- package/package.json +1 -1
- package/Dockerfile +0 -15
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import { Listener } from '../interface/listener.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a DedicatedWorkerGlobalScope, which is the global execution context for a dedicated worker.
|
|
6
|
+
* Provides properties and methods to manage the worker's lifecycle and communication with other threads or workers.
|
|
7
|
+
*/
|
|
8
|
+
declare interface DedicatedWorkerGlobalScope {
|
|
9
|
+
/**
|
|
10
|
+
* Handler for incoming messages from other threads or workers.
|
|
11
|
+
*/
|
|
12
|
+
onmessage: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* WorkerListener is a class that extends EventEmitter and implements the Listener interface.
|
|
16
|
+
* It listens for incoming connections on a dedicated worker global scope, and emits a 'new_socket' event
|
|
17
|
+
* with a MessagePortSocket instance for each new connection. This allows applications to communicate
|
|
18
|
+
* with other workers or main thread through the MessagePortSocket abstraction.
|
|
19
|
+
*
|
|
20
|
+
* The open() method starts listening for incoming connections, while the close() method stops it.
|
|
21
|
+
*/
|
|
22
|
+
export declare class WorkerListener extends EventEmitter implements Listener {
|
|
23
|
+
private worker;
|
|
24
|
+
constructor(worker: DedicatedWorkerGlobalScope);
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the WorkerListener by setting the 'onmessage' event handler of the worker.
|
|
27
|
+
* The 'onmessage' event will be triggered when the worker receives a message, and it will then
|
|
28
|
+
* call the handleMessageEvent method to handle incoming connections.
|
|
29
|
+
*/
|
|
30
|
+
open(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Close the worker listener by removing the 'onmessage' event handler.
|
|
33
|
+
* This method effectively stops the WorkerListener from reacting to new incoming messages.
|
|
34
|
+
*/
|
|
35
|
+
close(): void;
|
|
36
|
+
private handleMessageEvent;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=worker_listener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker_listener.d.ts","sourceRoot":"","sources":["../../../src/transport/browser/worker_listener.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD;;;GAGG;AACH,OAAO,WAAW,0BAA0B;IAC1C;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,YAAa,YAAW,QAAQ;IACtD,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,0BAA0B;IAItD;;;;OAIG;IACH,IAAI;IAIJ;;;OAGG;IACH,KAAK;IAIL,OAAO,CAAC,kBAAkB,CAMxB;CACH"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { MessagePortSocket } from './message_port_socket.js';
|
|
3
|
+
/**
|
|
4
|
+
* WorkerListener is a class that extends EventEmitter and implements the Listener interface.
|
|
5
|
+
* It listens for incoming connections on a dedicated worker global scope, and emits a 'new_socket' event
|
|
6
|
+
* with a MessagePortSocket instance for each new connection. This allows applications to communicate
|
|
7
|
+
* with other workers or main thread through the MessagePortSocket abstraction.
|
|
8
|
+
*
|
|
9
|
+
* The open() method starts listening for incoming connections, while the close() method stops it.
|
|
10
|
+
*/
|
|
11
|
+
export class WorkerListener extends EventEmitter {
|
|
12
|
+
constructor(worker) {
|
|
13
|
+
super();
|
|
14
|
+
this.worker = worker;
|
|
15
|
+
this.handleMessageEvent = (event) => {
|
|
16
|
+
const [port] = event.ports;
|
|
17
|
+
if (!port) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.emit('new_socket', new MessagePortSocket(port));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Initializes the WorkerListener by setting the 'onmessage' event handler of the worker.
|
|
25
|
+
* The 'onmessage' event will be triggered when the worker receives a message, and it will then
|
|
26
|
+
* call the handleMessageEvent method to handle incoming connections.
|
|
27
|
+
*/
|
|
28
|
+
open() {
|
|
29
|
+
this.worker.onmessage = this.handleMessageEvent;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Close the worker listener by removing the 'onmessage' event handler.
|
|
33
|
+
* This method effectively stops the WorkerListener from reacting to new incoming messages.
|
|
34
|
+
*/
|
|
35
|
+
close() {
|
|
36
|
+
this.worker.onmessage = () => { };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyX2xpc3RlbmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RyYW5zcG9ydC9icm93c2VyL3dvcmtlcl9saXN0ZW5lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLFlBQVksTUFBTSxRQUFRLENBQUM7QUFHbEMsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFhN0Q7Ozs7Ozs7R0FPRztBQUNILE1BQU0sT0FBTyxjQUFlLFNBQVEsWUFBWTtJQUM5QyxZQUFvQixNQUFrQztRQUNwRCxLQUFLLEVBQUUsQ0FBQztRQURVLFdBQU0sR0FBTixNQUFNLENBQTRCO1FBcUI5Qyx1QkFBa0IsR0FBRyxDQUFDLEtBQW1CLEVBQUUsRUFBRTtZQUNuRCxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsS0FBSyxDQUFDLEtBQUssQ0FBQztZQUMzQixJQUFJLENBQUMsSUFBSSxFQUFFO2dCQUNULE9BQU87YUFDUjtZQUNELElBQUksQ0FBQyxJQUFJLENBQUMsWUFBWSxFQUFFLElBQUksaUJBQWlCLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQztRQUN2RCxDQUFDLENBQUM7SUF6QkYsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxJQUFJO1FBQ0YsSUFBSSxDQUFDLE1BQU0sQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLGtCQUFrQixDQUFDO0lBQ2xELENBQUM7SUFFRDs7O09BR0c7SUFDSCxLQUFLO1FBQ0gsSUFBSSxDQUFDLE1BQU0sQ0FBQyxTQUFTLEdBQUcsR0FBRyxFQUFFLEdBQUUsQ0FBQyxDQUFDO0lBQ25DLENBQUM7Q0FTRiJ9
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a message object for dispatching function calls.
|
|
3
|
+
* Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
|
|
4
|
+
*/
|
|
5
|
+
export interface DispatchMsg {
|
|
6
|
+
/**
|
|
7
|
+
* Name of the target method to be called.
|
|
8
|
+
*/
|
|
9
|
+
fn: string;
|
|
10
|
+
/**
|
|
11
|
+
* An array of arguments to be passed to the target method.
|
|
12
|
+
*/
|
|
13
|
+
args: any[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a dispatch function that calls the target's specified method with provided arguments.
|
|
17
|
+
* The created dispatch function takes a DispatchMsg object as input, which contains the name of
|
|
18
|
+
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
19
|
+
*
|
|
20
|
+
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
21
|
+
* @param debug - Optional logging function for debugging purposes.
|
|
22
|
+
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createDispatchFn(targetFn: () => any, debug?: import("../../log/logger.js").DebugLogger): ({ fn, args }: DispatchMsg) => Promise<any>;
|
|
25
|
+
//# sourceMappingURL=create_dispatch_fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,KAAK,4CAAiD,kBAC9E,WAAW,kBAKxC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createDebugLogger } from '../../log/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a dispatch function that calls the target's specified method with provided arguments.
|
|
4
|
+
* The created dispatch function takes a DispatchMsg object as input, which contains the name of
|
|
5
|
+
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
6
|
+
*
|
|
7
|
+
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
8
|
+
* @param debug - Optional logging function for debugging purposes.
|
|
9
|
+
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
10
|
+
*/
|
|
11
|
+
export function createDispatchFn(targetFn, debug = createDebugLogger('aztec:foundation:dispatch')) {
|
|
12
|
+
return async ({ fn, args }) => {
|
|
13
|
+
const target = targetFn();
|
|
14
|
+
debug(`dispatching to ${target}: ${fn}`, args);
|
|
15
|
+
return await target[fn](...args);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlX2Rpc3BhdGNoX2ZuLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RyYW5zcG9ydC9kaXNwYXRjaC9jcmVhdGVfZGlzcGF0Y2hfZm4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFpQnZEOzs7Ozs7OztHQVFHO0FBQ0gsTUFBTSxVQUFVLGdCQUFnQixDQUFDLFFBQW1CLEVBQUUsS0FBSyxHQUFHLGlCQUFpQixDQUFDLDJCQUEyQixDQUFDO0lBQzFHLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBZSxFQUFFLEVBQUU7UUFDekMsTUFBTSxNQUFNLEdBQUcsUUFBUSxFQUFFLENBQUM7UUFDMUIsS0FBSyxDQUFDLGtCQUFrQixNQUFNLEtBQUssRUFBRSxFQUFFLEVBQUUsSUFBSSxDQUFDLENBQUM7UUFDL0MsT0FBTyxNQUFNLE1BQU0sQ0FBQyxFQUFFLENBQUMsQ0FBQyxHQUFHLElBQUksQ0FBQyxDQUFDO0lBQ25DLENBQUMsQ0FBQztBQUNKLENBQUMifQ==
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { TransferDescriptor } from '../interface/transferable.js';
|
|
2
|
+
import { TransportClient } from '../transport_client.js';
|
|
3
|
+
import { DispatchMsg } from './create_dispatch_fn.js';
|
|
4
|
+
/**
|
|
5
|
+
* FilterOutAttributes type filters out all non-method properties of an object, leaving only the attributes
|
|
6
|
+
* that are functions. This is useful for creating proxies or wrappers around objects while focusing only
|
|
7
|
+
* on their methods and ignoring other properties.
|
|
8
|
+
*/
|
|
9
|
+
type FilterOutAttributes<Base> = {
|
|
10
|
+
[Key in keyof Base]: Base[Key] extends (...any: any) => any ? Base[Key] : never;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Takes a function type `F` and returns a new function type with the same input parameters as `F`,
|
|
14
|
+
* but returning a Promise of the original return type of `F`. This is useful for converting sync
|
|
15
|
+
* functions or functions that take callbacks into a version that returns a Promise.
|
|
16
|
+
*/
|
|
17
|
+
type PromisifyFunction<F extends (...any: any) => any> = (...args: Parameters<F>) => Promise<ReturnType<F>>;
|
|
18
|
+
/**
|
|
19
|
+
* Transforms the provided object type by converting each of its function properties into their
|
|
20
|
+
* promise-returning counterparts. If a function property already returns a promise, it remains unchanged.
|
|
21
|
+
* This is useful when wrapping synchronous methods to return promises in order to standardize the API for
|
|
22
|
+
* asynchronous operations.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam Base - The type of the object whose function properties need to be converted into their
|
|
25
|
+
* promise-returning versions.
|
|
26
|
+
*/
|
|
27
|
+
type Promisify<Base extends {
|
|
28
|
+
[key: string]: (...any: any) => any;
|
|
29
|
+
}> = {
|
|
30
|
+
[Key in keyof Base]: ReturnType<Base[Key]> extends Promise<any> ? Base[Key] : PromisifyFunction<Base[Key]>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Type that transforms a tuple of types, replacing each type 'T' with either 'T' or a `TransferDescriptor<T>` if 'T' is `Transferable`.
|
|
34
|
+
* This is useful for handling arguments of functions that may accept both original and transferable representations of objects.
|
|
35
|
+
*/
|
|
36
|
+
type TransferTypes<Tuple extends [...args: any]> = {
|
|
37
|
+
[Index in keyof Tuple]: Tuple[Index] | (Tuple[Index] extends Transferable ? TransferDescriptor<Tuple[Index]> : never);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Annoying.
|
|
41
|
+
* @see https://github.com/microsoft/TypeScript/issues/29919
|
|
42
|
+
* There's a bug that means we can't map over the tuple or function parameter types to make them transferrable, if
|
|
43
|
+
* we use the Parameters builtin, and then try to map.
|
|
44
|
+
* So instead we inline the Parameters builtin and apply the TransferTypes to the parameters within the inline.
|
|
45
|
+
* Once the above is fixed we could in theory just do:
|
|
46
|
+
*
|
|
47
|
+
* type MakeFunctionTransferrable\<TFunction extends (...args: any) =\> any\> = (
|
|
48
|
+
* ...args: TransferTypes\<Parameters\<TFunction\>\>
|
|
49
|
+
* ) =\> ReturnType<TFunction>;
|
|
50
|
+
*/
|
|
51
|
+
type MakeFunctionTransferrable<TFunction extends (...args: any) => any> = (...args: TFunction extends (...args: infer P) => any ? TransferTypes<P> : never) => ReturnType<TFunction>;
|
|
52
|
+
/**
|
|
53
|
+
* Transferrable type represents a utility type that maps over the provided Base object's methods,
|
|
54
|
+
* transforming their argument types to support transferable objects. This is useful when dealing
|
|
55
|
+
* with operations across different environments or threads, such as Web Workers or Node.js processes,
|
|
56
|
+
* where certain objects need to be transferred instead of being serialized and deserialized.
|
|
57
|
+
*/
|
|
58
|
+
type Transferrable<Base extends {
|
|
59
|
+
[key: string]: (...any: any) => any;
|
|
60
|
+
}> = {
|
|
61
|
+
[Key in keyof Base]: MakeFunctionTransferrable<Base[Key]>;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Proxify is a mapped type that takes an object with functions as its properties and returns
|
|
65
|
+
* a new object with the same properties, but with each function transformed to return a Promise
|
|
66
|
+
* and accept Transferable types in place of their original parameters. This type is useful for
|
|
67
|
+
* creating proxies that communicate over different environments or threads while maintaining
|
|
68
|
+
* the original class's method signatures, allowing for type-safe interaction with remote instances.
|
|
69
|
+
*/
|
|
70
|
+
export type Proxify<T> = Promisify<Transferrable<FilterOutAttributes<T>>>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a proxy object for the provided class, wrapping each method in a request function.
|
|
73
|
+
* The resulting proxy object allows invoking methods of the original class, but their execution
|
|
74
|
+
* is delegated to the request function. This is useful when executing methods across different
|
|
75
|
+
* environments or threads, such as Web Workers or Node.js processes.
|
|
76
|
+
*
|
|
77
|
+
* @typeParam T - The type of the class to create a proxy for.
|
|
78
|
+
* @param class_ - The class constructor to create a proxy for.
|
|
79
|
+
* @param requestFn - A higher-order function that takes a method name and returns a function
|
|
80
|
+
* with the same signature as the original method, which wraps the actual
|
|
81
|
+
* invocation in a custom logic (e.g., sending a message to another thread).
|
|
82
|
+
* @returns An object whose methods match those of the original class, but whose execution is
|
|
83
|
+
* delegated to the provided request function.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createDispatchProxyFromFn<T>(class_: {
|
|
86
|
+
new (...args: any[]): T;
|
|
87
|
+
}, requestFn: (fn: string) => (...args: any[]) => Promise<any>): Proxify<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a proxy for the given class that transparently dispatches method calls over a transport client.
|
|
90
|
+
* The proxy allows calling methods on remote instances of the class through the provided transport client
|
|
91
|
+
* while maintaining the correct return types and handling promises. If the class inherits from EventEmitter,
|
|
92
|
+
* it also handles event emissions through the transport client.
|
|
93
|
+
*
|
|
94
|
+
* @param class_ - The constructor function of the class to create the proxy for.
|
|
95
|
+
* @param transportClient - The TransportClient instance used to handle communication between proxies.
|
|
96
|
+
* @returns A proxified version of the given class with methods dispatched over the transport client.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createDispatchProxy<T>(class_: {
|
|
99
|
+
new (...args: any[]): T;
|
|
100
|
+
}, transportClient: TransportClient<DispatchMsg>): Proxify<T>;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=create_dispatch_proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_dispatch_proxy.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_proxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAwB,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;GAIG;AACH,KAAK,mBAAmB,CAAC,IAAI,IAAI;KAC9B,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK;CAChF,CAAC;AAEF;;;;GAIG;AACH,KAAK,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5G;;;;;;;;GAQG;AACH,KAAK,SAAS,CAAC,IAAI,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,GAAG,CAAA;CAAE,IAAI;KACpE,GAAG,IAAI,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;CAC3G,CAAC;AAEF;;;GAGG;AACH,KAAK,aAAa,CAAC,KAAK,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI;KAChD,KAAK,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC;CACtH,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,KAAK,yBAAyB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,IAAI,CACxE,GAAG,IAAI,EAAE,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,KAAK,KAC5E,UAAU,CAAC,SAAS,CAAC,CAAC;AAE3B;;;;;GAKG;AACH,KAAK,aAAa,CAAC,IAAI,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,GAAG,CAAA;CAAE,IAAI;KACxE,GAAG,IAAI,MAAM,IAAI,GAAG,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,MAAM,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,EACnC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAC1D,OAAO,CAAC,CAAC,CAAC,CASZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,MAAM,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,EACnC,eAAe,EAAE,eAAe,CAAC,WAAW,CAAC,GAC5C,OAAO,CAAC,CAAC,CAAC,CAqBZ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { isTransferDescriptor } from '../interface/transferable.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a proxy object for the provided class, wrapping each method in a request function.
|
|
5
|
+
* The resulting proxy object allows invoking methods of the original class, but their execution
|
|
6
|
+
* is delegated to the request function. This is useful when executing methods across different
|
|
7
|
+
* environments or threads, such as Web Workers or Node.js processes.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - The type of the class to create a proxy for.
|
|
10
|
+
* @param class_ - The class constructor to create a proxy for.
|
|
11
|
+
* @param requestFn - A higher-order function that takes a method name and returns a function
|
|
12
|
+
* with the same signature as the original method, which wraps the actual
|
|
13
|
+
* invocation in a custom logic (e.g., sending a message to another thread).
|
|
14
|
+
* @returns An object whose methods match those of the original class, but whose execution is
|
|
15
|
+
* delegated to the provided request function.
|
|
16
|
+
*/
|
|
17
|
+
export function createDispatchProxyFromFn(class_, requestFn) {
|
|
18
|
+
const proxy = class_.prototype instanceof EventEmitter ? new EventEmitter() : {};
|
|
19
|
+
for (const fn of Object.getOwnPropertyNames(class_.prototype)) {
|
|
20
|
+
if (fn === 'constructor') {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
proxy[fn] = requestFn(fn);
|
|
24
|
+
}
|
|
25
|
+
return proxy;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a proxy for the given class that transparently dispatches method calls over a transport client.
|
|
29
|
+
* The proxy allows calling methods on remote instances of the class through the provided transport client
|
|
30
|
+
* while maintaining the correct return types and handling promises. If the class inherits from EventEmitter,
|
|
31
|
+
* it also handles event emissions through the transport client.
|
|
32
|
+
*
|
|
33
|
+
* @param class_ - The constructor function of the class to create the proxy for.
|
|
34
|
+
* @param transportClient - The TransportClient instance used to handle communication between proxies.
|
|
35
|
+
* @returns A proxified version of the given class with methods dispatched over the transport client.
|
|
36
|
+
*/
|
|
37
|
+
export function createDispatchProxy(class_, transportClient) {
|
|
38
|
+
// Create a proxy of class_ that passes along methods over our transportClient
|
|
39
|
+
const proxy = createDispatchProxyFromFn(class_, (fn) => (...args) => {
|
|
40
|
+
// Pass our proxied function name and arguments over our transport client
|
|
41
|
+
const transfer = args.reduce((acc, a) => (isTransferDescriptor(a) ? [...acc, ...a.transferables] : acc), []);
|
|
42
|
+
args = args.map(a => (isTransferDescriptor(a) ? a.send : a));
|
|
43
|
+
return transportClient.request({ fn, args }, transfer);
|
|
44
|
+
});
|
|
45
|
+
if (proxy instanceof EventEmitter) {
|
|
46
|
+
// Handle proxied 'emit' calls if our proxy object is an EventEmitter
|
|
47
|
+
transportClient.on('event_msg', ({ fn, args }) => {
|
|
48
|
+
if (fn === 'emit') {
|
|
49
|
+
const [eventName, ...restArgs] = args;
|
|
50
|
+
proxy.emit(eventName, ...restArgs);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return proxy;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlX2Rpc3BhdGNoX3Byb3h5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RyYW5zcG9ydC9kaXNwYXRjaC9jcmVhdGVfZGlzcGF0Y2hfcHJveHkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLFFBQVEsQ0FBQztBQUV0QyxPQUFPLEVBQXNCLG9CQUFvQixFQUFFLE1BQU0sOEJBQThCLENBQUM7QUE0RXhGOzs7Ozs7Ozs7Ozs7O0dBYUc7QUFDSCxNQUFNLFVBQVUseUJBQXlCLENBQ3ZDLE1BQW1DLEVBQ25DLFNBQTJEO0lBRTNELE1BQU0sS0FBSyxHQUFRLE1BQU0sQ0FBQyxTQUFTLFlBQVksWUFBWSxDQUFDLENBQUMsQ0FBQyxJQUFJLFlBQVksRUFBRSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUM7SUFDdEYsS0FBSyxNQUFNLEVBQUUsSUFBSSxNQUFNLENBQUMsbUJBQW1CLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQyxFQUFFO1FBQzdELElBQUksRUFBRSxLQUFLLGFBQWEsRUFBRTtZQUN4QixTQUFTO1NBQ1Y7UUFDRCxLQUFLLENBQUMsRUFBRSxDQUFDLEdBQUcsU0FBUyxDQUFDLEVBQUUsQ0FBQyxDQUFDO0tBQzNCO0lBQ0QsT0FBTyxLQUFLLENBQUM7QUFDZixDQUFDO0FBRUQ7Ozs7Ozs7OztHQVNHO0FBQ0gsTUFBTSxVQUFVLG1CQUFtQixDQUNqQyxNQUFtQyxFQUNuQyxlQUE2QztJQUU3Qyw4RUFBOEU7SUFDOUUsTUFBTSxLQUFLLEdBQUcseUJBQXlCLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBVSxFQUFFLEVBQUUsQ0FBQyxDQUFDLEdBQUcsSUFBVyxFQUFFLEVBQUU7UUFDakYseUVBQXlFO1FBQ3pFLE1BQU0sUUFBUSxHQUFtQixJQUFJLENBQUMsTUFBTSxDQUMxQyxDQUFDLEdBQUcsRUFBRSxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxHQUFHLEVBQUUsR0FBRyxDQUFDLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxFQUMxRSxFQUFvQixDQUNyQixDQUFDO1FBQ0YsSUFBSSxHQUFHLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLG9CQUFvQixDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzdELE9BQU8sZUFBZSxDQUFDLE9BQU8sQ0FBQyxFQUFFLEVBQUUsRUFBRSxJQUFJLEVBQUUsRUFBRSxRQUFRLENBQUMsQ0FBQztJQUN6RCxDQUFDLENBQUMsQ0FBQztJQUNILElBQUksS0FBSyxZQUFZLFlBQVksRUFBRTtRQUNqQyxxRUFBcUU7UUFDckUsZUFBZSxDQUFDLEVBQUUsQ0FBQyxXQUFXLEVBQUUsQ0FBQyxFQUFFLEVBQUUsRUFBRSxJQUFJLEVBQUUsRUFBRSxFQUFFO1lBQy9DLElBQUksRUFBRSxLQUFLLE1BQU0sRUFBRTtnQkFDakIsTUFBTSxDQUFDLFNBQVMsRUFBRSxHQUFHLFFBQVEsQ0FBQyxHQUFHLElBQUksQ0FBQztnQkFDdEMsS0FBSyxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsR0FBRyxRQUFRLENBQUMsQ0FBQzthQUNwQztRQUNILENBQUMsQ0FBQyxDQUFDO0tBQ0o7SUFDRCxPQUFPLEtBQUssQ0FBQztBQUNmLENBQUMifQ==
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a request message.
|
|
3
|
+
* Contains a unique identifier (msgId) and a payload object.
|
|
4
|
+
*/
|
|
5
|
+
export interface RequestMessage<Payload> {
|
|
6
|
+
/**
|
|
7
|
+
* A unique identifier for a message.
|
|
8
|
+
*/
|
|
9
|
+
msgId: number;
|
|
10
|
+
/**
|
|
11
|
+
* The data content carried within a message.
|
|
12
|
+
*/
|
|
13
|
+
payload: Payload;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Represents a structured response message.
|
|
17
|
+
* Contains an identifier to match with the corresponding request.
|
|
18
|
+
*/
|
|
19
|
+
export interface ResponseMessage<Payload> {
|
|
20
|
+
/**
|
|
21
|
+
* A unique identifier for the message.
|
|
22
|
+
*/
|
|
23
|
+
msgId: number;
|
|
24
|
+
/**
|
|
25
|
+
* The data content carried within the message.
|
|
26
|
+
*/
|
|
27
|
+
payload?: Payload;
|
|
28
|
+
/**
|
|
29
|
+
* An optional error description in case the response contains an error instead of a payload.
|
|
30
|
+
*/
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents an event-based message in a communication system.
|
|
35
|
+
* Contains a payload with the relevant data associated with a specific event occurrence.
|
|
36
|
+
*/
|
|
37
|
+
export interface EventMessage<Payload> {
|
|
38
|
+
/**
|
|
39
|
+
* The data content associated with a message.
|
|
40
|
+
*/
|
|
41
|
+
payload: Payload;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Determines if the given 'msg' is an EventMessage by checking if its 'msgId' property is undefined.
|
|
45
|
+
* Returns true if the input message is of type EventMessage, otherwise false. This utility function can be used
|
|
46
|
+
* to differentiate between instances of ResponseMessage and EventMessage that share a common Payload type.
|
|
47
|
+
*
|
|
48
|
+
* @param msg - The message object that can be either a ResponseMessage or EventMessage with a specific payload.
|
|
49
|
+
* @returns A boolean value indicating whether the input message is an EventMessage (true) or not (false).
|
|
50
|
+
*/
|
|
51
|
+
export declare function isEventMessage<Payload>(msg: ResponseMessage<Payload> | EventMessage<Payload>): msg is EventMessage<Payload>;
|
|
52
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/messages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO;IACrC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO;IACtC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO;IACnC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EACpC,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GACpD,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAE9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the given 'msg' is an EventMessage by checking if its 'msgId' property is undefined.
|
|
3
|
+
* Returns true if the input message is of type EventMessage, otherwise false. This utility function can be used
|
|
4
|
+
* to differentiate between instances of ResponseMessage and EventMessage that share a common Payload type.
|
|
5
|
+
*
|
|
6
|
+
* @param msg - The message object that can be either a ResponseMessage or EventMessage with a specific payload.
|
|
7
|
+
* @returns A boolean value indicating whether the input message is an EventMessage (true) or not (false).
|
|
8
|
+
*/
|
|
9
|
+
export function isEventMessage(msg) {
|
|
10
|
+
return msg.msgId === undefined;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHJhbnNwb3J0L2Rpc3BhdGNoL21lc3NhZ2VzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQTZDQTs7Ozs7OztHQU9HO0FBQ0gsTUFBTSxVQUFVLGNBQWMsQ0FDNUIsR0FBcUQ7SUFFckQsT0FBUSxHQUFnQyxDQUFDLEtBQUssS0FBSyxTQUFTLENBQUM7QUFDL0QsQ0FBQyJ9
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './dispatch/create_dispatch_fn.js';
|
|
2
|
+
export * from './dispatch/create_dispatch_proxy.js';
|
|
3
|
+
export * from './dispatch/messages.js';
|
|
4
|
+
export * from './interface/connector.js';
|
|
5
|
+
export * from './interface/listener.js';
|
|
6
|
+
export * from './interface/socket.js';
|
|
7
|
+
export * from './interface/transferable.js';
|
|
8
|
+
export * from './transport_client.js';
|
|
9
|
+
export * from './transport_server.js';
|
|
10
|
+
export * from './browser/index.js';
|
|
11
|
+
export * from './node/index.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './dispatch/create_dispatch_fn.js';
|
|
2
|
+
export * from './dispatch/create_dispatch_proxy.js';
|
|
3
|
+
export * from './dispatch/messages.js';
|
|
4
|
+
export * from './interface/connector.js';
|
|
5
|
+
export * from './interface/listener.js';
|
|
6
|
+
export * from './interface/socket.js';
|
|
7
|
+
export * from './interface/transferable.js';
|
|
8
|
+
export * from './transport_client.js';
|
|
9
|
+
export * from './transport_server.js';
|
|
10
|
+
export * from './browser/index.js';
|
|
11
|
+
export * from './node/index.js';
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJhbnNwb3J0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsa0NBQWtDLENBQUM7QUFDakQsY0FBYyxxQ0FBcUMsQ0FBQztBQUNwRCxjQUFjLHdCQUF3QixDQUFDO0FBQ3ZDLGNBQWMsMEJBQTBCLENBQUM7QUFDekMsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLHVCQUF1QixDQUFDO0FBQ3RDLGNBQWMsNkJBQTZCLENBQUM7QUFDNUMsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLHVCQUF1QixDQUFDO0FBQ3RDLGNBQWMsb0JBQW9CLENBQUM7QUFDbkMsY0FBYyxpQkFBaUIsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,SAAS;IAExB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACjC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import { Socket } from './socket.js';
|
|
4
|
+
/**
|
|
5
|
+
* Once opened, an implementation of a TransportListener will emit `new_socket` events as new clients connect.
|
|
6
|
+
* Possible implementations could include MessageChannels or WebSockets.
|
|
7
|
+
*/
|
|
8
|
+
export interface Listener extends EventEmitter {
|
|
9
|
+
open(): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
on(name: 'new_socket', cb: (client: Socket) => void): this;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=listener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/listener.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,YAAY;IAE5C,IAAI,IAAI,IAAI,CAAC;IAEb,KAAK,IAAI,IAAI,CAAC;IAEd,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents one end of a socket connection.
|
|
3
|
+
* A message sent via `send` will be handled by the corresponding Socket's handler function at the other end.
|
|
4
|
+
* Implementations could use e.g. MessagePorts for communication between browser workers,
|
|
5
|
+
* or WebSockets for communication between processes.
|
|
6
|
+
* If `registerHandler` callback receives `undefined` that signals the other end closed.
|
|
7
|
+
*/
|
|
8
|
+
export interface Socket {
|
|
9
|
+
send(msg: any, transfer?: Transferable[]): Promise<void>;
|
|
10
|
+
registerHandler(cb: (msg: any) => any): void;
|
|
11
|
+
close(): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/socket.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IAErB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI,CAAC;IAE7C,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
declare const $transferable: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a descriptor for transferable objects in multi-threaded environments.
|
|
4
|
+
* Provides a structure for marking certain objects as transferable and managing the ownership transfer
|
|
5
|
+
* between threads, particularly useful when working with Web Workers.
|
|
6
|
+
*/
|
|
7
|
+
export interface TransferDescriptor<T = any> {
|
|
8
|
+
/**
|
|
9
|
+
* A unique symbol indicating that an object is a TransferDescriptor.
|
|
10
|
+
*/
|
|
11
|
+
[$transferable]: true;
|
|
12
|
+
/**
|
|
13
|
+
* The transferable data to be sent between threads.
|
|
14
|
+
*/
|
|
15
|
+
send: T;
|
|
16
|
+
/**
|
|
17
|
+
* An array of objects that can be transferred between threads without serialization and deserialization.
|
|
18
|
+
*/
|
|
19
|
+
transferables: Transferable[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Determines whether a given object is a TransferDescriptor.
|
|
23
|
+
* A TransferDescriptor is an object with a [$transferable] property set to true and used for
|
|
24
|
+
* transferring ownership of transferable objects between threads.
|
|
25
|
+
* This function checks if the input object has the required properties to be considered
|
|
26
|
+
* a valid TransferDescriptor.
|
|
27
|
+
*
|
|
28
|
+
* @param thing - The object to be checked for being a TransferDescriptor.
|
|
29
|
+
* @returns True if the object is a TransferDescriptor, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTransferDescriptor(thing: any): thing is TransferDescriptor;
|
|
32
|
+
/**
|
|
33
|
+
* Mark a transferable object as such, so it will no be serialized and
|
|
34
|
+
* deserialized on messaging with the main thread, but to transfer
|
|
35
|
+
* ownership of it to the receiving thread.
|
|
36
|
+
*
|
|
37
|
+
* Only works with array buffers, message ports and few more special
|
|
38
|
+
* types of objects, but it's much faster than serializing and
|
|
39
|
+
* deserializing them.
|
|
40
|
+
*
|
|
41
|
+
* Note:
|
|
42
|
+
* The transferable object cannot be accessed by this thread again
|
|
43
|
+
* unless the receiving thread transfers it back again!
|
|
44
|
+
*
|
|
45
|
+
* @param transferable - Array buffer, message port or similar.
|
|
46
|
+
* @see https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast
|
|
47
|
+
*/
|
|
48
|
+
export declare function Transfer<T>(transferable: Transferable): TransferDescriptor<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Mark transferable objects within an arbitrary object or array as
|
|
51
|
+
* being a transferable object. They will then not be serialized
|
|
52
|
+
* and deserialized on messaging with the main thread, but ownership
|
|
53
|
+
* of them will be tranferred to the receiving thread.
|
|
54
|
+
*
|
|
55
|
+
* Only array buffers, message ports and few more special types of
|
|
56
|
+
* objects can be transferred, but it's much faster than serializing and
|
|
57
|
+
* deserializing them.
|
|
58
|
+
*
|
|
59
|
+
* Note:
|
|
60
|
+
* The transferable object cannot be accessed by this thread again
|
|
61
|
+
* unless the receiving thread transfers it back again!
|
|
62
|
+
*
|
|
63
|
+
* @param transferable - Array buffer, message port or similar.
|
|
64
|
+
* @see https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast
|
|
65
|
+
*/
|
|
66
|
+
export declare function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor<T>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=transferable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferable.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/transferable.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,aAAa,eAAgC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG;IACzC;;OAEG;IACH,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC;IACtB;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IACR;;OAEG;IACH,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B;AAuBD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAE5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const $transferable = Symbol('thread.transferable');
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the provided object is transferable.
|
|
4
|
+
* Transferable objects are instances of a certain set of classes,
|
|
5
|
+
* such as ArrayBuffer or MessagePort, which can be transferred between
|
|
6
|
+
* different execution contexts (e.g., workers) without incurring the
|
|
7
|
+
* overhead of serialization and deserialization.
|
|
8
|
+
*
|
|
9
|
+
* This function checks for the basic transferable criteria, but does not
|
|
10
|
+
* perform an exhaustive check for all possible transferable types. As new
|
|
11
|
+
* transferable types are added to JavaScript, they may be supported without
|
|
12
|
+
* needing to modify this function.
|
|
13
|
+
*
|
|
14
|
+
* @param thing - The object to check for transferability.
|
|
15
|
+
* @returns A boolean indicating whether the object is transferable.
|
|
16
|
+
*/
|
|
17
|
+
function isTransferable(thing) {
|
|
18
|
+
if (!thing || typeof thing !== 'object')
|
|
19
|
+
return false;
|
|
20
|
+
// Don't check too thoroughly, since the list of transferable things in JS might grow over time
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Determines whether a given object is a TransferDescriptor.
|
|
25
|
+
* A TransferDescriptor is an object with a [$transferable] property set to true and used for
|
|
26
|
+
* transferring ownership of transferable objects between threads.
|
|
27
|
+
* This function checks if the input object has the required properties to be considered
|
|
28
|
+
* a valid TransferDescriptor.
|
|
29
|
+
*
|
|
30
|
+
* @param thing - The object to be checked for being a TransferDescriptor.
|
|
31
|
+
* @returns True if the object is a TransferDescriptor, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export function isTransferDescriptor(thing) {
|
|
34
|
+
return thing && typeof thing === 'object' && thing[$transferable];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a TransferDescriptor for transferable objects within an arbitrary object or array, allowing
|
|
38
|
+
* them to be transferred between threads instead of being serialized and deserialized.
|
|
39
|
+
* This method is particularly useful when working with Web Workers and other multi-threaded environments.
|
|
40
|
+
* Transferable objects include ArrayBuffers, MessagePorts, and a few other special types.
|
|
41
|
+
* Note that after transferring, the original thread will lose access to the transferred object unless
|
|
42
|
+
* it's transferred back again.
|
|
43
|
+
*
|
|
44
|
+
* @param payload - The transferable object or an object containing transferable properties.
|
|
45
|
+
* @param transferables - Optional array of Transferable objects found in the payload. If not provided,
|
|
46
|
+
* the payload itself should be a Transferable object.
|
|
47
|
+
* @returns A TransferDescriptor<T> containing the payload and transferables, marked as transferable.
|
|
48
|
+
* @throws Error if payload is not transferable and transferables array is not provided.
|
|
49
|
+
* @see https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast
|
|
50
|
+
*/
|
|
51
|
+
export function Transfer(payload, transferables) {
|
|
52
|
+
if (!transferables) {
|
|
53
|
+
if (!isTransferable(payload))
|
|
54
|
+
throw Error();
|
|
55
|
+
transferables = [payload];
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
[$transferable]: true,
|
|
59
|
+
send: payload,
|
|
60
|
+
transferables,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNmZXJhYmxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RyYW5zcG9ydC9pbnRlcmZhY2UvdHJhbnNmZXJhYmxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sYUFBYSxHQUFHLE1BQU0sQ0FBQyxxQkFBcUIsQ0FBQyxDQUFDO0FBc0JwRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILFNBQVMsY0FBYyxDQUFDLEtBQVU7SUFDaEMsSUFBSSxDQUFDLEtBQUssSUFBSSxPQUFPLEtBQUssS0FBSyxRQUFRO1FBQUUsT0FBTyxLQUFLLENBQUM7SUFDdEQsK0ZBQStGO0lBQy9GLE9BQU8sSUFBSSxDQUFDO0FBQ2QsQ0FBQztBQUVEOzs7Ozs7Ozs7R0FTRztBQUNILE1BQU0sVUFBVSxvQkFBb0IsQ0FBQyxLQUFVO0lBQzdDLE9BQU8sS0FBSyxJQUFJLE9BQU8sS0FBSyxLQUFLLFFBQVEsSUFBSSxLQUFLLENBQUMsYUFBYSxDQUFDLENBQUM7QUFDcEUsQ0FBQztBQXVDRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILE1BQU0sVUFBVSxRQUFRLENBQUksT0FBVSxFQUFFLGFBQThCO0lBQ3BFLElBQUksQ0FBQyxhQUFhLEVBQUU7UUFDbEIsSUFBSSxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUM7WUFBRSxNQUFNLEtBQUssRUFBRSxDQUFDO1FBQzVDLGFBQWEsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0tBQzNCO0lBRUQsT0FBTztRQUNMLENBQUMsYUFBYSxDQUFDLEVBQUUsSUFBSTtRQUNyQixJQUFJLEVBQUUsT0FBTztRQUNiLGFBQWE7S0FDZCxDQUFDO0FBQ0osQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from './node_connector.js';
|
|
2
|
+
export * from './node_listener.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHJhbnNwb3J0L25vZGUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxxQkFBcUIsQ0FBQztBQUNwQyxjQUFjLG9CQUFvQixDQUFDIn0=
|