@aztec/foundation 0.83.1 → 0.84.0
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/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/index.d.ts +0 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -2
- package/dest/log/index.d.ts +3 -4
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +3 -4
- package/dest/log/noir_debug_log_util.d.ts +14 -0
- package/dest/log/noir_debug_log_util.d.ts.map +1 -0
- package/dest/log/noir_debug_log_util.js +14 -0
- package/dest/transport/index.d.ts +0 -1
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/package.json +2 -4
- package/src/config/env_var.ts +1 -1
- package/src/index.ts +0 -2
- package/src/log/index.ts +3 -4
- package/src/log/noir_debug_log_util.ts +21 -0
- package/src/transport/index.ts +0 -1
- package/dest/log/debug.d.ts +0 -56
- package/dest/log/debug.d.ts.map +0 -1
- package/dest/log/debug.js +0 -75
- package/dest/log/log_history.d.ts +0 -31
- package/dest/log/log_history.d.ts.map +0 -1
- package/dest/log/log_history.js +0 -38
- package/dest/transport/browser/index.d.ts +0 -5
- package/dest/transport/browser/index.d.ts.map +0 -1
- package/dest/transport/browser/index.js +0 -4
- package/dest/transport/browser/message_port_socket.d.ts +0 -37
- package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
- package/dest/transport/browser/message_port_socket.js +0 -42
- package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
- package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_connector.js +0 -19
- package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
- package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_listener.js +0 -33
- package/dest/transport/browser/worker_connector.d.ts +0 -26
- package/dest/transport/browser/worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/worker_connector.js +0 -30
- package/dest/transport/browser/worker_listener.d.ts +0 -39
- package/dest/transport/browser/worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/worker_listener.js +0 -35
- package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
- package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
- package/dest/wasm/empty_wasi_sdk.js +0 -148
- package/dest/wasm/index.d.ts +0 -2
- package/dest/wasm/index.d.ts.map +0 -1
- package/dest/wasm/index.js +0 -1
- package/dest/wasm/wasm_module.d.ts +0 -136
- package/dest/wasm/wasm_module.d.ts.map +0 -1
- package/dest/wasm/wasm_module.js +0 -196
- package/dest/worker/browser/index.d.ts +0 -3
- package/dest/worker/browser/index.d.ts.map +0 -1
- package/dest/worker/browser/index.js +0 -2
- package/dest/worker/browser/start_web_module.d.ts +0 -7
- package/dest/worker/browser/start_web_module.d.ts.map +0 -1
- package/dest/worker/browser/start_web_module.js +0 -27
- package/dest/worker/browser/web_data_store.d.ts +0 -24
- package/dest/worker/browser/web_data_store.d.ts.map +0 -1
- package/dest/worker/browser/web_data_store.js +0 -29
- package/dest/worker/browser/web_worker.d.ts +0 -10
- package/dest/worker/browser/web_worker.d.ts.map +0 -1
- package/dest/worker/browser/web_worker.js +0 -25
- package/dest/worker/data_store.d.ts +0 -21
- package/dest/worker/data_store.d.ts.map +0 -1
- package/dest/worker/data_store.js +0 -3
- package/dest/worker/index.d.ts +0 -3
- package/dest/worker/index.d.ts.map +0 -1
- package/dest/worker/index.js +0 -1
- package/dest/worker/node/index.d.ts +0 -3
- package/dest/worker/node/index.d.ts.map +0 -1
- package/dest/worker/node/index.js +0 -2
- package/dest/worker/node/node_data_store.d.ts +0 -13
- package/dest/worker/node/node_data_store.d.ts.map +0 -1
- package/dest/worker/node/node_data_store.js +0 -20
- package/dest/worker/node/node_worker.d.ts +0 -6
- package/dest/worker/node/node_worker.d.ts.map +0 -1
- package/dest/worker/node/node_worker.js +0 -22
- package/dest/worker/node/start_node_module.d.ts +0 -7
- package/dest/worker/node/start_node_module.d.ts.map +0 -1
- package/dest/worker/node/start_node_module.js +0 -31
- package/dest/worker/wasm_worker.d.ts +0 -9
- package/dest/worker/wasm_worker.d.ts.map +0 -1
- package/dest/worker/wasm_worker.js +0 -3
- package/dest/worker/worker_pool.d.ts +0 -40
- package/dest/worker/worker_pool.d.ts.map +0 -1
- package/dest/worker/worker_pool.js +0 -51
- package/src/log/debug.ts +0 -104
- package/src/log/log_history.ts +0 -44
- package/src/transport/browser/index.ts +0 -4
- package/src/transport/browser/message_port_socket.ts +0 -48
- package/src/transport/browser/shared_worker_connector.ts +0 -21
- package/src/transport/browser/shared_worker_listener.ts +0 -53
- package/src/transport/browser/worker_connector.ts +0 -30
- package/src/transport/browser/worker_listener.ts +0 -54
- package/src/wasm/README.md +0 -6
- package/src/wasm/empty_wasi_sdk.ts +0 -166
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +0 -27
- package/src/wasm/index.ts +0 -1
- package/src/wasm/wasm_module.ts +0 -260
- package/src/worker/browser/index.ts +0 -2
- package/src/worker/browser/start_web_module.ts +0 -24
- package/src/worker/browser/web_data_store.ts +0 -38
- package/src/worker/browser/web_worker.ts +0 -25
- package/src/worker/data_store.ts +0 -19
- package/src/worker/index.ts +0 -2
- package/src/worker/node/index.ts +0 -2
- package/src/worker/node/node_data_store.ts +0 -27
- package/src/worker/node/node_worker.ts +0 -23
- package/src/worker/node/start_node_module.ts +0 -30
- package/src/worker/wasm_worker.ts +0 -7
- package/src/worker/worker_pool.ts +0 -73
package/src/log/debug.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
|
-
|
|
3
|
-
import type { LogFn } from './log_fn.js';
|
|
4
|
-
|
|
5
|
-
let preLogHook: ((...args: any[]) => void) | undefined;
|
|
6
|
-
let postLogHook: ((...args: any[]) => void) | undefined;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Process and handle the logging of messages through custom hooks and the given logger.
|
|
10
|
-
* This function checks if the logger's namespace is enabled, executes any preLogHook functions, logs the message using the provided logger, and then executes any postLogHook functions.
|
|
11
|
-
*
|
|
12
|
-
* @param logger - The debug logger instance to be used for logging.
|
|
13
|
-
* @param args - The arguments to be passed to the logger and any hook functions.
|
|
14
|
-
*/
|
|
15
|
-
function theFunctionThroughWhichAllLogsPass(logger: any, ...args: any[]) {
|
|
16
|
-
if (!debug.enabled(logger.namespace)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (preLogHook) {
|
|
20
|
-
preLogHook(logger.namespace, ...args);
|
|
21
|
-
}
|
|
22
|
-
logger(...args);
|
|
23
|
-
if (postLogHook) {
|
|
24
|
-
postLogHook(logger.namespace, ...args);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Return a logger, meant to be silent by default and verbose during debugging.
|
|
30
|
-
* @param name - The module name of the logger.
|
|
31
|
-
* @returns A callable log function.
|
|
32
|
-
*/
|
|
33
|
-
export function createDebugOnlyLogger(name: string): LogFn {
|
|
34
|
-
const logger = debug(name);
|
|
35
|
-
return (...args: any[]) => theFunctionThroughWhichAllLogsPass(logger, ...args);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Set a function to be called before each log message is handled by the debug logger.
|
|
40
|
-
* The hook function will receive the logger namespace and any arguments passed to the logger.
|
|
41
|
-
* This can be useful for adding additional context, filtering logs, or performing side-effects
|
|
42
|
-
* based on logged messages.
|
|
43
|
-
*
|
|
44
|
-
* @param fn - The function to be called before each log message.
|
|
45
|
-
*/
|
|
46
|
-
export function setPreDebugLogHook(fn: (...args: any[]) => void) {
|
|
47
|
-
preLogHook = fn;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Set a callback function to be executed after each log is written by the debug logger.
|
|
52
|
-
* This allows additional behavior or side effects to occur after a log has been written,
|
|
53
|
-
* such as sending logs to external services, formatting output, or triggering events.
|
|
54
|
-
*
|
|
55
|
-
* @param fn - The callback function to be executed after each log. It receives the same arguments as the original log function call.
|
|
56
|
-
*/
|
|
57
|
-
export function setPostDebugLogHook(fn: (...args: any[]) => void) {
|
|
58
|
-
postLogHook = fn;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Enable logs for the specified namespace(s) or wildcard pattern(s).
|
|
63
|
-
* This function activates the logging functionality for the given
|
|
64
|
-
* namespace(s) or pattern(s), allowing developers to selectively display
|
|
65
|
-
* debug logs that match the provided string(s).
|
|
66
|
-
*
|
|
67
|
-
* @param str - The namespace(s) or wildcard pattern(s) for which logs should be enabled.
|
|
68
|
-
*/
|
|
69
|
-
export function enableLogs(str: string) {
|
|
70
|
-
debug.enable(str);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Check if the logging is enabled for a given namespace.
|
|
75
|
-
* The input 'str' represents the namespace for which the log status is being checked.
|
|
76
|
-
* Returns true if the logging is enabled, otherwise false.
|
|
77
|
-
*
|
|
78
|
-
* @param str - The namespace string used to determine if logging is enabled.
|
|
79
|
-
* @returns A boolean indicating whether logging is enabled for the given namespace.
|
|
80
|
-
*/
|
|
81
|
-
export function isLogEnabled(str: string) {
|
|
82
|
-
return debug.enabled(str);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Format a debug string filling in `'{0}'` entries with their
|
|
87
|
-
* corresponding values from the args array, amd `'{}'` with the whole array.
|
|
88
|
-
*
|
|
89
|
-
* @param formatStr - str of form `'this is a string with some entries like {0} and {1}'`
|
|
90
|
-
* @param args - array of fields to fill in the string format entries with
|
|
91
|
-
* @returns formatted string
|
|
92
|
-
*/
|
|
93
|
-
interface Printable {
|
|
94
|
-
toString(): string;
|
|
95
|
-
}
|
|
96
|
-
export function applyStringFormatting(formatStr: string, args: Printable[]): string {
|
|
97
|
-
return formatStr
|
|
98
|
-
.replace(/{(\d+)}/g, (match, index) => {
|
|
99
|
-
return typeof args[index] === 'undefined' ? match : args[index].toString();
|
|
100
|
-
})
|
|
101
|
-
.replace(/{}/g, (_match, _index) => {
|
|
102
|
-
return args.toString();
|
|
103
|
-
});
|
|
104
|
-
}
|
package/src/log/log_history.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { setPreDebugLogHook } from './debug.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* LogHistory is a utility class that provides the ability to store and manage debug logs.
|
|
5
|
-
* It can be enabled to record logs along with their timestamps, retrieve a specified number
|
|
6
|
-
* of recent logs, or clear stored logs based on a given count. This can be useful for debugging
|
|
7
|
-
* purposes, monitoring application activities, and maintaining log history.
|
|
8
|
-
*/
|
|
9
|
-
export class LogHistory {
|
|
10
|
-
private logs: any[][] = [];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Enables the logging of debug messages with timestamps.
|
|
14
|
-
* Hooks into the pre-debug log and stores each log entry along with its timestamp in the logs array.
|
|
15
|
-
*/
|
|
16
|
-
public enable() {
|
|
17
|
-
setPreDebugLogHook((...args: any[]) => {
|
|
18
|
-
this.logs.push([new Date().toISOString(), ...args]);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves a specified number of logs from the end of the log history or all logs if no argument is provided.
|
|
24
|
-
* The logs are ordered chronologically, with the oldest logs at the beginning of the array.
|
|
25
|
-
*
|
|
26
|
-
* @param last - Optional number representing the amount of recent logs to return. Defaults to 0, which returns all logs.
|
|
27
|
-
* @returns An array of log arrays, each containing a timestamp and log arguments.
|
|
28
|
-
*/
|
|
29
|
-
public getLogs(last = 0) {
|
|
30
|
-
return last ? this.logs.slice(-last) : this.logs;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Clear a specified number of logs from the beginning of the logs array.
|
|
35
|
-
* If no count is provided, it will clear all logs.
|
|
36
|
-
*
|
|
37
|
-
* @param count - The number of logs to be removed (default: total logs length).
|
|
38
|
-
*/
|
|
39
|
-
public clear(count = this.logs.length) {
|
|
40
|
-
this.logs = this.logs.slice(count);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const logHistory = new LogHistory();
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Socket } from '../interface/socket.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* An implementation of a TransportSocket using MessagePorts.
|
|
5
|
-
*/
|
|
6
|
-
export class MessagePortSocket implements Socket {
|
|
7
|
-
constructor(private port: MessagePort) {}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Send a message to the connected MessagePort, optionally transferring ownership of certain objects.
|
|
11
|
-
* The 'msg' parameter can be any structured data type and will be sent to the other end of the MessagePort.
|
|
12
|
-
* The optional 'transfer' parameter is an array of Transferable objects whose ownership will be transferred,
|
|
13
|
-
* making them inaccessible on the sending side. This can improve performance for large data transfers.
|
|
14
|
-
*
|
|
15
|
-
* @param msg - The message to be sent through the MessagePort.
|
|
16
|
-
* @param transfer - An optional array of Transferable objects to transfer ownership.
|
|
17
|
-
* @returns A Promise that resolves when the message has been sent.
|
|
18
|
-
*/
|
|
19
|
-
send(msg: any, transfer: Transferable[] = []): Promise<void> {
|
|
20
|
-
this.port.postMessage(msg, transfer);
|
|
21
|
-
return Promise.resolve();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Register a callback function to handle incoming messages from the MessagePort.
|
|
26
|
-
* The provided callback will be invoked with the message data whenever a new message arrives.
|
|
27
|
-
* Note that only one callback can be registered at a time. Subsequent calls to this method
|
|
28
|
-
* will overwrite the previously registered callback.
|
|
29
|
-
*
|
|
30
|
-
* @param cb - The callback function to handle incoming messages.
|
|
31
|
-
*/
|
|
32
|
-
registerHandler(cb: (msg: any) => any): void {
|
|
33
|
-
this.port.onmessage = event => cb(event.data);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Close the MessagePort, unregister the message handler, and send an undefined message.
|
|
38
|
-
* The 'close' function is useful for gracefully shutting down a connection between two
|
|
39
|
-
* endpoints by sending an undefined message as an indication of disconnection before
|
|
40
|
-
* closing the port. After calling this method, the MessagePortSocket instance should not
|
|
41
|
-
* be used again.
|
|
42
|
-
*/
|
|
43
|
-
close() {
|
|
44
|
-
void this.send(undefined);
|
|
45
|
-
this.port.onmessage = null;
|
|
46
|
-
this.port.close();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Connector } from '../interface/connector.js';
|
|
2
|
-
import { MessagePortSocket } from './message_port_socket.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SharedWorkerConnector is an implementation of the Connector interface, specifically for SharedWorkers.
|
|
6
|
-
* It enables the creation of MessagePortSockets that communicate with a shared worker and allow
|
|
7
|
-
* multiple scripts to communicate with the worker using the same connection.
|
|
8
|
-
*/
|
|
9
|
-
export class SharedWorkerConnector implements Connector {
|
|
10
|
-
constructor(private worker: SharedWorker) {}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new MessagePortSocket instance using the SharedWorker's port.
|
|
14
|
-
* This method allows for easy creation of sockets to communicate with the SharedWorker.
|
|
15
|
-
*
|
|
16
|
-
* @returns A Promise that resolves to a new MessagePortSocket instance.
|
|
17
|
-
*/
|
|
18
|
-
createSocket() {
|
|
19
|
-
return Promise.resolve(new MessagePortSocket(this.worker.port));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
|
|
3
|
-
import type { Listener } from '../interface/listener.js';
|
|
4
|
-
import { MessagePortSocket } from './message_port_socket.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents the global scope of a Shared Worker.
|
|
8
|
-
* Provides functionality to handle incoming connections and manage communication with other scripts
|
|
9
|
-
* running in a shared context, enabling concurrent access and efficient resource sharing among those scripts.
|
|
10
|
-
*/
|
|
11
|
-
declare interface SharedWorkerGlobalScope {
|
|
12
|
-
/**
|
|
13
|
-
* Event handler for new connections to the Shared Worker.
|
|
14
|
-
*/
|
|
15
|
-
onconnect: (...args: any) => any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* SharedWorkerListener is an extension of the EventEmitter class that implements the Listener interface.
|
|
20
|
-
* It provides functionality to handle incoming messages from a shared worker and emit events for new sockets
|
|
21
|
-
* created in response to these incoming connections. This class is meant to be used in the context of managing
|
|
22
|
-
* MessagePort connections within the SharedWorkerGlobalScope.
|
|
23
|
-
*/
|
|
24
|
-
export class SharedWorkerListener extends EventEmitter implements Listener {
|
|
25
|
-
constructor(private worker: SharedWorkerGlobalScope) {
|
|
26
|
-
super();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Initializes the shared worker listener by assigning the 'handleMessageEvent' method as the event handler
|
|
31
|
-
* for the 'onconnect' event of the SharedWorkerGlobalScope. The 'handleMessageEvent' function will be called
|
|
32
|
-
* whenever a new connection is established with the shared worker.
|
|
33
|
-
*/
|
|
34
|
-
open() {
|
|
35
|
-
this.worker.onconnect = this.handleMessageEvent;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Closes the SharedWorkerListener by detaching the 'onconnect' event handler.
|
|
40
|
-
* This stops the listener from emitting new sockets on incoming connections.
|
|
41
|
-
*/
|
|
42
|
-
close() {
|
|
43
|
-
this.worker.onconnect = () => {};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private handleMessageEvent = (event: MessageEvent) => {
|
|
47
|
-
const [port] = event.ports;
|
|
48
|
-
if (!port) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.emit('new_socket', new MessagePortSocket(port));
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Connector } from '../interface/connector.js';
|
|
2
|
-
import { MessagePortSocket } from './message_port_socket.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* WorkerConnector is a class implementing the Connector interface for creating communication sockets
|
|
6
|
-
* with Web Workers. It allows to establish a connection with the worker and create MessagePortSockets
|
|
7
|
-
* using MessageChannels, enabling seamless communication between the main thread and worker threads.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const worker = new Worker('./myWorker.js');
|
|
11
|
-
* const connector = new WorkerConnector(worker);
|
|
12
|
-
* const socket = await connector.createSocket();
|
|
13
|
-
* socket.send('Hello, worker!');
|
|
14
|
-
*/
|
|
15
|
-
export class WorkerConnector implements Connector {
|
|
16
|
-
constructor(private worker: Worker) {}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new MessagePortSocket instance by establishing a connection between the Worker and the main thread.
|
|
20
|
-
* A MessageChannel is created, and one of its ports is sent to the Worker using postMessage.
|
|
21
|
-
* The other port is used to create a new MessagePortSocket which is then returned as a Promise.
|
|
22
|
-
*
|
|
23
|
-
* @returns A Promise that resolves to a new MessagePortSocket instance.
|
|
24
|
-
*/
|
|
25
|
-
createSocket() {
|
|
26
|
-
const channel = new MessageChannel();
|
|
27
|
-
this.worker.postMessage('', [channel.port2]);
|
|
28
|
-
return Promise.resolve(new MessagePortSocket(channel.port1));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
|
|
3
|
-
import type { Listener } from '../interface/listener.js';
|
|
4
|
-
import { MessagePortSocket } from './message_port_socket.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents a DedicatedWorkerGlobalScope, which is the global execution context for a dedicated worker.
|
|
8
|
-
* Provides properties and methods to manage the worker's lifecycle and communication with other threads or workers.
|
|
9
|
-
*/
|
|
10
|
-
declare interface DedicatedWorkerGlobalScope {
|
|
11
|
-
/**
|
|
12
|
-
* Handler for incoming messages from other threads or workers.
|
|
13
|
-
*/
|
|
14
|
-
onmessage: any;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* WorkerListener is a class that extends EventEmitter and implements the Listener interface.
|
|
19
|
-
* It listens for incoming connections on a dedicated worker global scope, and emits a 'new_socket' event
|
|
20
|
-
* with a MessagePortSocket instance for each new connection. This allows applications to communicate
|
|
21
|
-
* with other workers or main thread through the MessagePortSocket abstraction.
|
|
22
|
-
*
|
|
23
|
-
* The open() method starts listening for incoming connections, while the close() method stops it.
|
|
24
|
-
*/
|
|
25
|
-
export class WorkerListener extends EventEmitter implements Listener {
|
|
26
|
-
constructor(private worker: DedicatedWorkerGlobalScope) {
|
|
27
|
-
super();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Initializes the WorkerListener by setting the 'onmessage' event handler of the worker.
|
|
32
|
-
* The 'onmessage' event will be triggered when the worker receives a message, and it will then
|
|
33
|
-
* call the handleMessageEvent method to handle incoming connections.
|
|
34
|
-
*/
|
|
35
|
-
open() {
|
|
36
|
-
this.worker.onmessage = this.handleMessageEvent;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Close the worker listener by removing the 'onmessage' event handler.
|
|
41
|
-
* This method effectively stops the WorkerListener from reacting to new incoming messages.
|
|
42
|
-
*/
|
|
43
|
-
close() {
|
|
44
|
-
this.worker.onmessage = () => {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private handleMessageEvent = (event: MessageEvent) => {
|
|
48
|
-
const [port] = event.ports;
|
|
49
|
-
if (!port) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.emit('new_socket', new MessagePortSocket(port));
|
|
53
|
-
};
|
|
54
|
-
}
|
package/src/wasm/README.md
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createDebugOnlyLogger } from '../log/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dummy implementation of a necessary part of the wasi api:
|
|
5
|
-
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
6
|
-
* We don't use these functions, but the environment expects them.
|
|
7
|
-
* TODO find a way to update off of wasi 12.
|
|
8
|
-
*/
|
|
9
|
-
/* eslint-disable camelcase */
|
|
10
|
-
export const getEmptyWasiSdk = (debug = createDebugOnlyLogger('wasm:empty_wasi_sdk')) => ({
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves the current time from the system clock.
|
|
13
|
-
* This function is a dummy implementation of the WASI API's `clock_time_get` method,
|
|
14
|
-
* which is expected by the environment but not used in this context.
|
|
15
|
-
*
|
|
16
|
-
* No input parameters or return values are required, as the purpose of this function
|
|
17
|
-
* is solely to satisfy the environment expectations and provide debugging information.
|
|
18
|
-
*/
|
|
19
|
-
clock_time_get() {
|
|
20
|
-
debug('clock_time_get');
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* Dummy implementation of WASI's environ_get function.
|
|
24
|
-
* This function is used to obtain a snapshot of the current environment variables.
|
|
25
|
-
* In this dummy implementation, no actual actions are performed, but the debug logger logs 'environ_get' when called.
|
|
26
|
-
* Environment variables are not used in this context, so the real implementation is not required.
|
|
27
|
-
*
|
|
28
|
-
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#environ_get
|
|
29
|
-
*/
|
|
30
|
-
environ_get() {
|
|
31
|
-
debug('environ_get');
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Retrieves the environment variable sizes from the WebAssembly environment.
|
|
35
|
-
* This function is part of the WASI API and provides a dummy implementation to fulfill the expected APIs.
|
|
36
|
-
* It does not have any actual functionality, but serves as a placeholder in the environment.
|
|
37
|
-
*/
|
|
38
|
-
environ_sizes_get() {
|
|
39
|
-
debug('environ_sizes_get');
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Closes a file descriptor, releasing any resources associated with it.
|
|
43
|
-
* This function does not perform any actual closing operation, but exists to
|
|
44
|
-
* satisfy the requirements of the WebAssembly System Interface (WASI) API,
|
|
45
|
-
* which expects certain functions to be present for compatibility purposes.
|
|
46
|
-
*
|
|
47
|
-
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
48
|
-
*/
|
|
49
|
-
fd_close() {
|
|
50
|
-
debug('fd_close');
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* A dummy implementation of the 'fd_read' function from the WASI API.
|
|
54
|
-
* This function is required by the environment, but not used in this context.
|
|
55
|
-
* It would normally read data from a file descriptor into an array buffer,
|
|
56
|
-
* but here it simply logs the invocation for debugging purposes.
|
|
57
|
-
*/
|
|
58
|
-
fd_read() {
|
|
59
|
-
debug('fd_read');
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* Handles the file descriptor write operation.
|
|
63
|
-
* This dummy implementation of the WASI 'fd_write' function is part of the wasi API:
|
|
64
|
-
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
65
|
-
* The environment expects this function, but it is not used in the current implementation.
|
|
66
|
-
* It is used to write data from WebAssembly memory to a file descriptor.
|
|
67
|
-
*/
|
|
68
|
-
fd_write() {
|
|
69
|
-
debug('fd_write');
|
|
70
|
-
},
|
|
71
|
-
/**
|
|
72
|
-
* Perform a file seek operation on the given file descriptor to change its current position.
|
|
73
|
-
* The new position is calculated using the provided offset and whence values.
|
|
74
|
-
* Throws an error if the file descriptor is invalid or the operation cannot be performed.
|
|
75
|
-
*
|
|
76
|
-
* @param fd - The file descriptor of the file to perform the seek operation on.
|
|
77
|
-
* @param offset - The relative offset to apply, based on the whence value.
|
|
78
|
-
* @param whence - The reference point from which the offset should be calculated. One of SEEK_SET (start), SEEK_CUR (current), or SEEK_END (end).
|
|
79
|
-
* @returns The new position in the file after the seek operation has been performed.
|
|
80
|
-
*/
|
|
81
|
-
fd_seek() {
|
|
82
|
-
debug('fd_seek');
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* This function is a dummy implementation of the 'fd_fdstat_get' function in the WebAssembly System Interface (WASI) API.
|
|
86
|
-
* Although not actually used in this context, it is present due to the environment's expectation of its existence.
|
|
87
|
-
* The 'fd_fdstat_get' function is typically responsible for obtaining file descriptor status information.
|
|
88
|
-
*/
|
|
89
|
-
fd_fdstat_get() {
|
|
90
|
-
debug('fd_fdstat_get');
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* Sets the file descriptor flags for a given file descriptor.
|
|
94
|
-
* This function is a dummy implementation of the WASI API function 'fd_fdstat_set_flags'.
|
|
95
|
-
* It currently does not perform any operation but logs the function call with a debug instance.
|
|
96
|
-
* This is provided since the environment expects this function to be present.
|
|
97
|
-
*/
|
|
98
|
-
fd_fdstat_set_flags() {
|
|
99
|
-
debug('fd_fdstat_set_flags');
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* Handles the `fd_prestat_get` function call for the dummy WebAssembly System Interface (WASI) implementation.
|
|
103
|
-
* This function is expected by the WASI environment, although it is not used in this implementation.
|
|
104
|
-
* The `fd_prestat_get` function retrieves pre-opened file descriptor properties.
|
|
105
|
-
*
|
|
106
|
-
* @returns A constant integer value indicating successful completion of the function call.
|
|
107
|
-
*/
|
|
108
|
-
fd_prestat_get() {
|
|
109
|
-
debug('fd_prestat_get');
|
|
110
|
-
return 8;
|
|
111
|
-
},
|
|
112
|
-
/**
|
|
113
|
-
* Provides a dummy implementation for the `fd_prestat_dir_name` function, which is expected to be called by the WASI environment.
|
|
114
|
-
* This function is intended to retrieve the pre-opened directory's path associated with the given file descriptor. However, since it's a dummy implementation,
|
|
115
|
-
* it doesn't perform any actual operation and only logs the function call with the provided debug logger.
|
|
116
|
-
*
|
|
117
|
-
* @returns A constant number representing a dummy return value for the function call.
|
|
118
|
-
*/
|
|
119
|
-
fd_prestat_dir_name() {
|
|
120
|
-
debug('fd_prestat_dir_name');
|
|
121
|
-
return 28;
|
|
122
|
-
},
|
|
123
|
-
/**
|
|
124
|
-
* Handles the opening of a file path within the WASI environment.
|
|
125
|
-
* This function is a dummy implementation required for compatibility with
|
|
126
|
-
* the WebAssembly System Interface (WASI) API, but it does not perform any
|
|
127
|
-
* actual file opening operation. It is mainly used for debugging purposes.
|
|
128
|
-
*/
|
|
129
|
-
path_open() {
|
|
130
|
-
debug('path_open');
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* Retrieve file system information of the specified path.
|
|
134
|
-
* This function retrieves statistics, such as size and permissions, associated with the file or directory
|
|
135
|
-
* identified by the given path. In case of an error or non-existing path, appropriate debug logs will be generated.
|
|
136
|
-
*
|
|
137
|
-
* @returns An object containing file statistics like size, permissions, etc.
|
|
138
|
-
*/
|
|
139
|
-
path_filestat_get() {
|
|
140
|
-
debug('path_filestat_get');
|
|
141
|
-
},
|
|
142
|
-
/**
|
|
143
|
-
* Terminate the process normally, performing the regular cleanup for terminating programs.
|
|
144
|
-
* The input 'status' represents the exit code and is used to indicate success or failure
|
|
145
|
-
* of the program execution. A zero value typically indicates successful execution,
|
|
146
|
-
* while non-zero values are treated as errors by the operating system.
|
|
147
|
-
*
|
|
148
|
-
* @param status - The exit code representing the success or failure of the program execution.
|
|
149
|
-
* @returns The exit status code.
|
|
150
|
-
*/
|
|
151
|
-
proc_exit() {
|
|
152
|
-
debug('proc_exit');
|
|
153
|
-
return 52;
|
|
154
|
-
},
|
|
155
|
-
/**
|
|
156
|
-
* Generates a random number and returns it.
|
|
157
|
-
* This dummy implementation of 'random_get' method in the wasi API is expected by the environment.
|
|
158
|
-
* In this case, the function always returns 1 to maintain consistency with the environment's expectations.
|
|
159
|
-
*
|
|
160
|
-
* @returns A random number. In this implementation, always returns 1.
|
|
161
|
-
*/
|
|
162
|
-
random_get() {
|
|
163
|
-
debug('random_get');
|
|
164
|
-
return 1;
|
|
165
|
-
},
|
|
166
|
-
});
|
|
Binary file
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
(module
|
|
2
|
-
(func $gcd (param i32 i32) (result i32)
|
|
3
|
-
(local i32)
|
|
4
|
-
block ;; label = @1
|
|
5
|
-
block ;; label = @2
|
|
6
|
-
local.get 0
|
|
7
|
-
br_if 0 (;@2;)
|
|
8
|
-
local.get 1
|
|
9
|
-
local.set 2
|
|
10
|
-
br 1 (;@1;)
|
|
11
|
-
end
|
|
12
|
-
loop ;; label = @2
|
|
13
|
-
local.get 1
|
|
14
|
-
local.get 0
|
|
15
|
-
local.tee 2
|
|
16
|
-
i32.rem_u
|
|
17
|
-
local.set 0
|
|
18
|
-
local.get 2
|
|
19
|
-
local.set 1
|
|
20
|
-
local.get 0
|
|
21
|
-
br_if 0 (;@2;)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
local.get 2
|
|
25
|
-
)
|
|
26
|
-
(export "gcd" (func $gcd))
|
|
27
|
-
)
|
package/src/wasm/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { WasmModule, type IWasmModule } from './wasm_module.js';
|