@aztec/foundation 0.32.1 → 0.34.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.
Files changed (52) hide show
  1. package/dest/abi/abi.d.ts +38 -27
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +1 -1
  4. package/dest/abi/decoder.d.ts +1 -0
  5. package/dest/abi/decoder.d.ts.map +1 -1
  6. package/dest/abi/decoder.js +1 -1
  7. package/dest/abi/utils.d.ts +6 -6
  8. package/dest/array/array.d.ts +1 -1
  9. package/dest/array/array.d.ts.map +1 -1
  10. package/dest/array/array.js +3 -3
  11. package/dest/crypto/random/randomness_singleton.js +3 -3
  12. package/dest/fifo/bounded_serial_queue.d.ts +1 -1
  13. package/dest/fifo/bounded_serial_queue.d.ts.map +1 -1
  14. package/dest/fifo/memory_fifo.d.ts +1 -1
  15. package/dest/fifo/memory_fifo.d.ts.map +1 -1
  16. package/dest/json-rpc/client/json_rpc_client.d.ts +1 -1
  17. package/dest/json-rpc/client/json_rpc_client.js +8 -8
  18. package/dest/json-rpc/server/json_proxy.js +5 -5
  19. package/dest/json-rpc/server/json_rpc_server.d.ts +2 -2
  20. package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
  21. package/dest/log/logger.d.ts +2 -2
  22. package/dest/log/logger.d.ts.map +1 -1
  23. package/dest/log/logger.js +4 -5
  24. package/dest/retry/index.d.ts +1 -1
  25. package/dest/retry/index.d.ts.map +1 -1
  26. package/dest/retry/index.js +2 -2
  27. package/dest/sleep/index.d.ts +2 -1
  28. package/dest/sleep/index.d.ts.map +1 -1
  29. package/dest/sleep/index.js +4 -3
  30. package/dest/transport/dispatch/create_dispatch_fn.d.ts +2 -2
  31. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  32. package/dest/transport/dispatch/create_dispatch_fn.js +4 -4
  33. package/dest/transport/transport_client.js +4 -4
  34. package/dest/types/index.d.ts +4 -0
  35. package/dest/types/index.d.ts.map +1 -1
  36. package/dest/worker/worker_pool.js +4 -4
  37. package/package.json +14 -8
  38. package/src/abi/abi.ts +47 -28
  39. package/src/abi/decoder.ts +4 -3
  40. package/src/abi/encoder.ts +3 -3
  41. package/src/abi/utils.ts +6 -6
  42. package/src/array/array.ts +7 -2
  43. package/src/crypto/random/randomness_singleton.ts +2 -2
  44. package/src/json-rpc/client/json_rpc_client.ts +7 -7
  45. package/src/json-rpc/server/json_proxy.ts +4 -4
  46. package/src/log/logger.ts +4 -5
  47. package/src/retry/index.ts +1 -1
  48. package/src/sleep/index.ts +3 -2
  49. package/src/transport/dispatch/create_dispatch_fn.ts +3 -3
  50. package/src/transport/transport_client.ts +3 -3
  51. package/src/types/index.ts +6 -0
  52. package/src/worker/worker_pool.ts +3 -3
package/src/log/logger.ts CHANGED
@@ -4,8 +4,7 @@ import { isatty } from 'tty';
4
4
 
5
5
  import { type LogData, type LogFn } from './log_fn.js';
6
6
 
7
- // Matches a subset of Winston log levels
8
- const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const;
7
+ const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
9
8
  const DefaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : ('info' as const);
10
9
 
11
10
  /**
@@ -28,7 +27,7 @@ export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ er
28
27
  * Logger that supports multiple severity levels and can be called directly to issue a debug statement.
29
28
  * Intended as a drop-in replacement for the debug module.
30
29
  */
31
- export type DebugLogger = LogFn & Logger;
30
+ export type DebugLogger = Logger;
32
31
 
33
32
  /**
34
33
  * Creates a new DebugLogger for the current module, defaulting to the LOG_LEVEL env var.
@@ -50,7 +49,6 @@ export function createDebugLogger(name: string): DebugLogger {
50
49
  info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, data),
51
50
  verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, data),
52
51
  debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data),
53
- trace: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'trace', msg, data),
54
52
  };
55
53
  return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger);
56
54
  }
@@ -112,7 +110,8 @@ function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
112
110
  * @param msg - What to log.
113
111
  */
114
112
  function printLog(msg: string) {
115
- process.stderr.write(msg + '\n');
113
+ // eslint-disable-next-line no-console
114
+ isNode ? process.stderr.write(msg + '\n') : console.error(msg);
116
115
  }
117
116
 
118
117
  /**
@@ -63,7 +63,7 @@ export async function retry<Result>(
63
63
  if (s === undefined) {
64
64
  throw err;
65
65
  }
66
- log(`${name} failed. Will retry in ${s}s...`);
66
+ log.verbose(`${name} failed. Will retry in ${s}s...`);
67
67
  !failSilently && log.error(err);
68
68
  await sleep(s * 1000);
69
69
  continue;
@@ -67,8 +67,9 @@ export class InterruptibleSleep {
67
67
  * The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
68
68
  *
69
69
  * @param ms - The duration in milliseconds for which the sleep operation should last.
70
+ * @param returnValue - The return value of the promise.
70
71
  * @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
71
72
  */
72
- export function sleep(ms: number) {
73
- return new Promise(resolve => setTimeout(resolve, ms));
73
+ export function sleep<T>(ms: number, returnValue?: T): Promise<T | undefined> {
74
+ return new Promise(resolve => setTimeout(() => resolve(returnValue), ms));
74
75
  }
@@ -23,13 +23,13 @@ export interface DispatchMsg {
23
23
  * the method to be called ('fn') and an array of arguments to be passed to the method ('args').
24
24
  *
25
25
  * @param targetFn - A function that returns the target object containing the methods to be dispatched.
26
- * @param debug - Optional logging function for debugging purposes.
26
+ * @param log - Optional logging function for debugging purposes.
27
27
  * @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
28
28
  */
29
- export function createDispatchFn(targetFn: () => any, debug = createDebugLogger('aztec:foundation:dispatch')) {
29
+ export function createDispatchFn(targetFn: () => any, log = createDebugLogger('aztec:foundation:dispatch')) {
30
30
  return async ({ fn, args }: DispatchMsg) => {
31
31
  const target = targetFn();
32
- debug(format(`dispatching to ${target}: ${fn}`, args));
32
+ log.debug(format(`dispatching to ${target}: ${fn}`, args));
33
33
  return await target[fn](...args);
34
34
  };
35
35
  }
@@ -6,7 +6,7 @@ import { type EventMessage, type ResponseMessage, isEventMessage } from './dispa
6
6
  import { type Connector } from './interface/connector.js';
7
7
  import { type Socket } from './interface/socket.js';
8
8
 
9
- const debug = createDebugLogger('aztec:transport_client');
9
+ const log = createDebugLogger('aztec:transport_client');
10
10
 
11
11
  /**
12
12
  * Represents a pending request in the TransportClient.
@@ -92,7 +92,7 @@ export class TransportClient<Payload> extends EventEmitter {
92
92
  }
93
93
  const msgId = this.msgId++;
94
94
  const msg = { msgId, payload };
95
- debug(format(`->`, msg));
95
+ log.debug(format(`->`, msg));
96
96
  return new Promise<any>((resolve, reject) => {
97
97
  this.pendingRequests.push({ resolve, reject, msgId });
98
98
  this.socket!.send(msg, transfer).catch(reject);
@@ -112,7 +112,7 @@ export class TransportClient<Payload> extends EventEmitter {
112
112
  this.close();
113
113
  return;
114
114
  }
115
- debug(format(`<-`, msg));
115
+ log.debug(format(`<-`, msg));
116
116
  if (isEventMessage(msg)) {
117
117
  this.emit('event_msg', msg.payload);
118
118
  return;
@@ -4,5 +4,11 @@ export type FieldsOf<T> = {
4
4
  [P in keyof T as T[P] extends Function ? never : P]: T[P];
5
5
  };
6
6
 
7
+ /** Extracts methods of a type. */
8
+ export type FunctionsOf<T> = {
9
+ // eslint-disable-next-line @typescript-eslint/ban-types
10
+ [P in keyof T as T[P] extends Function ? P : never]: T[P];
11
+ };
12
+
7
13
  /** Marks a set of properties of a type as optional. */
8
14
  export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -1,7 +1,7 @@
1
1
  import { createDebugLogger } from '../log/index.js';
2
2
  import { type WasmWorker } from './wasm_worker.js';
3
3
 
4
- const debug = createDebugLogger('bb:worker_pool');
4
+ const log = createDebugLogger('bb:worker_pool');
5
5
 
6
6
  /**
7
7
  * Type of a worker factory.
@@ -53,7 +53,7 @@ export class WorkerPool {
53
53
  * @param maxMem - Max memory pages.
54
54
  */
55
55
  public async init(createWorker: CreateWorker, poolSize: number, maxMem = WorkerPool.MAX_PAGES) {
56
- debug(`creating ${poolSize} workers...`);
56
+ log.debug(`creating ${poolSize} workers...`);
57
57
  const start = new Date().getTime();
58
58
  this.workers = await Promise.all(
59
59
  Array(poolSize)
@@ -61,7 +61,7 @@ export class WorkerPool {
61
61
  .map((_, i) => createWorker(`${i}`, i === 0 ? Math.min(WorkerPool.MAX_PAGES, maxMem) : 768, maxMem)),
62
62
  );
63
63
 
64
- debug(`created workers: ${new Date().getTime() - start}ms`);
64
+ log.debug(`created workers: ${new Date().getTime() - start}ms`);
65
65
  }
66
66
 
67
67
  /**