@aztec/foundation 0.0.1-commit.993d52e → 0.0.1-commit.9a89641
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/bigint-buffer/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- package/dest/bigint-buffer/index.js +6 -1
- package/dest/branded-types/block_number.d.ts +3 -3
- package/dest/branded-types/block_number.d.ts.map +1 -1
- package/dest/branded-types/block_number.js +15 -4
- package/dest/branded-types/buffer32_hash.d.ts +27 -0
- package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
- package/dest/branded-types/buffer32_hash.js +12 -0
- package/dest/branded-types/checkpoint_number.d.ts +9 -3
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
- package/dest/branded-types/checkpoint_number.js +11 -0
- package/dest/branded-types/epoch.d.ts +2 -2
- package/dest/branded-types/epoch.d.ts.map +1 -1
- package/dest/branded-types/index.d.ts +2 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +1 -0
- package/dest/branded-types/index_within_checkpoint.d.ts +2 -2
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -1
- package/dest/branded-types/slot.d.ts +5 -2
- package/dest/branded-types/slot.d.ts.map +1 -1
- package/dest/branded-types/slot.js +3 -0
- package/dest/buffer/buffer16.d.ts +3 -1
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer32.d.ts +28 -61
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +29 -63
- package/dest/buffer/index.d.ts +2 -1
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/buffer/utils.d.ts +3 -0
- package/dest/buffer/utils.d.ts.map +1 -0
- package/dest/buffer/utils.js +7 -0
- package/dest/collection/array.d.ts +11 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +33 -0
- package/dest/collection/index.d.ts +3 -1
- package/dest/collection/index.d.ts.map +1 -1
- package/dest/collection/index.js +2 -0
- package/dest/collection/lru_map.d.ts +41 -0
- package/dest/collection/lru_map.d.ts.map +1 -0
- package/dest/collection/lru_map.js +119 -0
- package/dest/collection/lru_set.d.ts +35 -0
- package/dest/collection/lru_set.d.ts.map +1 -0
- package/dest/collection/lru_set.js +95 -0
- package/dest/committable/committable.js +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +67 -37
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +72 -71
- package/dest/config/network_config.d.ts +13 -45
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +2 -0
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +3 -3
- package/dest/config/secret_value.d.ts +2 -2
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/crypto/aes128/index.d.ts +2 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +11 -2
- package/dest/crypto/bls/bn254_keystore.d.ts +10 -177
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +22 -34
- package/dest/crypto/keys/index.d.ts +3 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +30 -6
- package/dest/crypto/poseidon/index.d.ts +1 -1
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +40 -33
- package/dest/crypto/schnorr/index.d.ts +8 -7
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +6 -6
- package/dest/crypto/schnorr/signature.d.ts +9 -29
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +20 -36
- package/dest/curves/bls12/field.d.ts +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -1
- package/dest/curves/bls12/field.js +0 -5
- package/dest/curves/bls12/point.d.ts +2 -2
- package/dest/curves/bls12/point.d.ts.map +1 -1
- package/dest/curves/bn254/field.d.ts +23 -19
- package/dest/curves/bn254/field.d.ts.map +1 -1
- package/dest/curves/bn254/field.js +23 -17
- package/dest/curves/grumpkin/point.d.ts +14 -28
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/curves/grumpkin/point.js +29 -43
- package/dest/eth-address/index.d.ts +2 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +0 -3
- package/dest/eth-signature/eth_signature.d.ts +2 -2
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/fifo/fifo_frame_reader.d.ts +41 -0
- package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
- package/dest/fifo/fifo_frame_reader.js +91 -0
- package/dest/fifo/index.d.ts +2 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +1 -0
- package/dest/fifo_set/fifo_set.d.ts +15 -0
- package/dest/fifo_set/fifo_set.d.ts.map +1 -0
- package/dest/fifo_set/fifo_set.js +39 -0
- package/dest/fifo_set/index.d.ts +2 -0
- package/dest/fifo_set/index.d.ts.map +1 -0
- package/dest/fifo_set/index.js +1 -0
- package/dest/jest/setup.js +24 -0
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +4 -3
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +5 -4
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +5 -3
- package/dest/json-rpc/fixtures/test_state.d.ts +4 -8
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.js +57 -17
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +32 -14
- package/dest/log/aws-logger-config.d.ts +8 -0
- package/dest/log/aws-logger-config.d.ts.map +1 -0
- package/dest/log/aws-logger-config.js +55 -0
- package/dest/log/pino-logger.d.ts +1 -1
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +29 -8
- package/dest/noir/noir_package_config.d.ts +19 -104
- package/dest/noir/noir_package_config.d.ts.map +1 -1
- package/dest/noir/noir_package_config.js +1 -1
- package/dest/promise/running-promise.d.ts +5 -4
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +7 -3
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.js +1 -0
- package/dest/retry/index.d.ts +31 -3
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +44 -2
- package/dest/schemas/api.d.ts +12 -10
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/api.js +7 -1
- package/dest/schemas/parse.d.ts +4 -4
- package/dest/schemas/parse.d.ts.map +1 -1
- package/dest/schemas/parse.js +6 -5
- package/dest/schemas/schemas.d.ts +15 -15
- package/dest/schemas/types.d.ts +3 -3
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/utils.d.ts +7 -11
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +2 -18
- package/dest/serialize/buffer_reader.d.ts +1 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +5 -0
- package/dest/serialize/buffer_sink.d.ts +134 -0
- package/dest/serialize/buffer_sink.d.ts.map +1 -0
- package/dest/serialize/buffer_sink.js +297 -0
- package/dest/serialize/index.d.ts +2 -1
- package/dest/serialize/index.d.ts.map +1 -1
- package/dest/serialize/index.js +1 -0
- package/dest/serialize/serialize.d.ts +1 -32
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +0 -21
- package/dest/sleep/index.d.ts +2 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +10 -1
- package/dest/string/index.d.ts +3 -1
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +13 -1
- package/dest/testing/files/index.d.ts +3 -4
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +3 -4
- package/dest/timer/date.d.ts +3 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +4 -0
- package/dest/timer/index.d.ts +2 -2
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +3 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +26 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/index.d.ts +1 -2
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/trees/balanced_merkle_tree_root.d.ts +2 -3
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree_root.js +2 -3
- package/dest/trees/hasher.d.ts +3 -2
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +5 -5
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
- package/dest/trees/membership_witness.d.ts +2 -6
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +0 -9
- package/dest/trees/merkle_tree_calculator.d.ts +4 -2
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -5
- package/dest/trees/sibling_path.d.ts +13 -14
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +23 -28
- package/dest/trees/unbalanced_merkle_tree_root.d.ts +2 -3
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_root.js +2 -3
- package/dest/types/index.d.ts +23 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +15 -0
- package/package.json +6 -4
- package/src/bigint-buffer/index.ts +6 -1
- package/src/branded-types/block_number.ts +20 -2
- package/src/branded-types/buffer32_hash.ts +38 -0
- package/src/branded-types/checkpoint_number.ts +16 -1
- package/src/branded-types/epoch.ts +1 -1
- package/src/branded-types/index.ts +1 -0
- package/src/branded-types/index_within_checkpoint.ts +1 -1
- package/src/branded-types/slot.ts +6 -1
- package/src/buffer/buffer16.ts +3 -0
- package/src/buffer/buffer32.ts +39 -68
- package/src/buffer/index.ts +1 -0
- package/src/buffer/utils.ts +8 -0
- package/src/collection/array.ts +34 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/lru_map.ts +143 -0
- package/src/collection/lru_set.ts +115 -0
- package/src/committable/committable.ts +1 -1
- package/src/config/env_var.ts +63 -25
- package/src/config/index.ts +143 -122
- package/src/config/network_config.ts +2 -0
- package/src/config/network_name.ts +6 -6
- package/src/config/secret_value.ts +1 -1
- package/src/crypto/aes128/index.ts +11 -2
- package/src/crypto/bls/bn254_keystore.ts +33 -43
- package/src/crypto/keys/index.ts +20 -4
- package/src/crypto/poseidon/index.ts +42 -34
- package/src/crypto/schnorr/index.ts +9 -8
- package/src/crypto/schnorr/signature.ts +17 -46
- package/src/curves/bls12/field.ts +0 -7
- package/src/curves/bn254/field.ts +35 -34
- package/src/curves/grumpkin/point.ts +23 -40
- package/src/eth-address/index.ts +0 -4
- package/src/fifo/fifo_frame_reader.ts +113 -0
- package/src/fifo/index.ts +1 -0
- package/src/fifo_set/fifo_set.ts +52 -0
- package/src/fifo_set/index.ts +1 -0
- package/src/jest/setup.mjs +27 -0
- package/src/json-rpc/client/fetch.ts +4 -3
- package/src/json-rpc/client/safe_json_rpc_client.ts +5 -4
- package/src/json-rpc/client/undici.ts +5 -3
- package/src/json-rpc/fixtures/test_state.ts +10 -10
- package/src/json-rpc/server/safe_json_rpc_server.ts +36 -14
- package/src/log/aws-logger-config.ts +32 -0
- package/src/log/pino-logger.ts +33 -6
- package/src/noir/noir_package_config.ts +32 -20
- package/src/promise/running-promise.ts +8 -5
- package/src/queue/batch_queue.ts +1 -0
- package/src/retry/index.ts +66 -4
- package/src/schemas/api.ts +25 -25
- package/src/schemas/parse.ts +9 -6
- package/src/schemas/schemas.ts +4 -4
- package/src/schemas/types.ts +2 -2
- package/src/schemas/utils.ts +4 -38
- package/src/serialize/buffer_reader.ts +5 -0
- package/src/serialize/buffer_sink.ts +350 -0
- package/src/serialize/index.ts +1 -0
- package/src/serialize/serialize.ts +0 -50
- package/src/sleep/index.ts +10 -1
- package/src/string/index.ts +15 -1
- package/src/testing/files/index.ts +3 -4
- package/src/timer/date.ts +6 -0
- package/src/timer/index.ts +1 -1
- package/src/timer/timeout.ts +31 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
- package/src/transport/index.ts +0 -1
- package/src/trees/balanced_merkle_tree_root.ts +2 -5
- package/src/trees/hasher.ts +6 -3
- package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
- package/src/trees/membership_witness.ts +0 -8
- package/src/trees/merkle_tree_calculator.ts +4 -10
- package/src/trees/sibling_path.ts +24 -30
- package/src/trees/unbalanced_merkle_tree_root.ts +2 -5
- package/src/types/index.ts +47 -0
- package/dest/crypto/serialize.d.ts +0 -51
- package/dest/crypto/serialize.d.ts.map +0 -1
- package/dest/crypto/serialize.js +0 -68
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
- package/src/crypto/serialize.ts +0 -85
- package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as net from 'node:net';
|
|
4
|
+
import type { Readable } from 'node:stream';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Events emitted by FifoFrameReader.
|
|
8
|
+
*
|
|
9
|
+
* - `frame`: A complete frame payload (without the 4-byte length header).
|
|
10
|
+
* - `error`: An unrecoverable error (invalid frame length, stream error).
|
|
11
|
+
* - `end`: The underlying stream has ended.
|
|
12
|
+
*/
|
|
13
|
+
export interface FifoFrameReaderEvents {
|
|
14
|
+
frame: [payload: Buffer];
|
|
15
|
+
error: [error: Error];
|
|
16
|
+
end: [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reads length-delimited frames from a readable stream (typically a named FIFO pipe).
|
|
21
|
+
*
|
|
22
|
+
* Wire format: `[4-byte big-endian payload length][payload bytes]`
|
|
23
|
+
*
|
|
24
|
+
* Emits a `frame` event for each complete frame with the raw payload buffer.
|
|
25
|
+
* Callers are responsible for deserializing the payload (e.g., via msgpack).
|
|
26
|
+
*
|
|
27
|
+
* On encountering an invalid payload length (0 or >maxPayloadSize), emits `error`
|
|
28
|
+
* and destroys the stream.
|
|
29
|
+
*/
|
|
30
|
+
export class FifoFrameReader extends EventEmitter<FifoFrameReaderEvents> {
|
|
31
|
+
private stream: Readable | null = null;
|
|
32
|
+
private pendingBuf: Buffer = Buffer.alloc(0);
|
|
33
|
+
private running = false;
|
|
34
|
+
|
|
35
|
+
constructor(private readonly maxPayloadSize = 10 * 1024 * 1024) {
|
|
36
|
+
super();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Open a FIFO at the given path and start reading frames. */
|
|
40
|
+
start(fifoPath: string): void {
|
|
41
|
+
// Read the FIFO through a libuv pipe handle (net.Socket) rather than fs.createReadStream.
|
|
42
|
+
// An fs read stream services the pipe with a blocking threadpool read that destroy() cannot
|
|
43
|
+
// cancel: if a writer never closes, that read stays parked and keeps the host process alive
|
|
44
|
+
// (manifesting as Jest "did not exit"). Opening O_NONBLOCK and wrapping the fd in a pipe
|
|
45
|
+
// handle makes reads epoll-based, so stop()'s destroy() releases the handle immediately,
|
|
46
|
+
// regardless of whether the writer is still attached.
|
|
47
|
+
const fd = fs.openSync(fifoPath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
|
|
48
|
+
let socket: net.Socket;
|
|
49
|
+
try {
|
|
50
|
+
socket = new net.Socket({ fd, readable: true, writable: false });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
fs.closeSync(fd);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
this.startFromStream(socket);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Start reading frames from an existing readable stream. */
|
|
59
|
+
startFromStream(stream: Readable): void {
|
|
60
|
+
if (this.running) {
|
|
61
|
+
throw new Error('FifoFrameReader is already running');
|
|
62
|
+
}
|
|
63
|
+
this.running = true;
|
|
64
|
+
this.pendingBuf = Buffer.alloc(0);
|
|
65
|
+
this.stream = stream;
|
|
66
|
+
|
|
67
|
+
stream.on('data', (chunk: Buffer | string) => {
|
|
68
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
69
|
+
this.pendingBuf = this.pendingBuf.length > 0 ? Buffer.concat([this.pendingBuf, buf]) : buf;
|
|
70
|
+
this.drainFrames();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
stream.on('error', (err: Error) => {
|
|
74
|
+
if (this.running) {
|
|
75
|
+
this.emit('error', err);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
stream.on('end', () => {
|
|
80
|
+
this.emit('end');
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Stop reading and destroy the underlying stream. */
|
|
85
|
+
stop(): void {
|
|
86
|
+
this.running = false;
|
|
87
|
+
if (this.stream) {
|
|
88
|
+
this.stream.destroy();
|
|
89
|
+
this.stream = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Parse complete frames out of the pending buffer. */
|
|
94
|
+
private drainFrames(): void {
|
|
95
|
+
while (this.pendingBuf.length >= 4) {
|
|
96
|
+
const payloadLen = this.pendingBuf.readUInt32BE(0);
|
|
97
|
+
if (payloadLen === 0 || payloadLen > this.maxPayloadSize) {
|
|
98
|
+
this.emit('error', new Error(`Invalid payload length: ${payloadLen}`));
|
|
99
|
+
this.stop();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const frameLen = 4 + payloadLen;
|
|
104
|
+
if (this.pendingBuf.length < frameLen) {
|
|
105
|
+
break; // Wait for more data
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const payload = this.pendingBuf.subarray(4, frameLen);
|
|
109
|
+
this.pendingBuf = this.pendingBuf.subarray(frameLen);
|
|
110
|
+
this.emit('frame', Buffer.from(payload));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FifoFrameReader } from './fifo_frame_reader.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** A Set capped to a fixed number of entries, evicting the oldest inserted value when full. */
|
|
2
|
+
export class FifoSet<T> extends Set<T> {
|
|
3
|
+
private _limit: number | undefined;
|
|
4
|
+
|
|
5
|
+
private constructor(values?: Iterable<T>) {
|
|
6
|
+
super(values);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Creates a bounded set with a positive integer limit. */
|
|
10
|
+
static withLimit<T>(limit: number, values?: Iterable<T>): FifoSet<T> {
|
|
11
|
+
if (!Number.isSafeInteger(limit) || limit <= 0) {
|
|
12
|
+
throw new TypeError(`FifoSet limit must be a positive safe integer: ${limit}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const set = new FifoSet(values);
|
|
16
|
+
set._limit = limit;
|
|
17
|
+
set.compact();
|
|
18
|
+
|
|
19
|
+
return set;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override add(value: T): this {
|
|
23
|
+
super.add(value);
|
|
24
|
+
this.compact();
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Maximum number of entries retained by this set. */
|
|
29
|
+
public get limit(): number {
|
|
30
|
+
return this._limit ?? Infinity;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Evicts oldest entries until the set is within its limit. */
|
|
34
|
+
public compact(): void {
|
|
35
|
+
while (this.size > this.limit) {
|
|
36
|
+
const head = this.values().next();
|
|
37
|
+
if (head.done) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.delete(head.value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Adds a value only if it is absent, returning whether the set changed. */
|
|
45
|
+
public addIfAbsent(value: T): boolean {
|
|
46
|
+
if (this.has(value)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
this.add(value);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fifo_set.js';
|
package/src/jest/setup.mjs
CHANGED
|
@@ -10,3 +10,30 @@ import pretty from 'pino-pretty';
|
|
|
10
10
|
if (!parseBooleanEnv(process.env.LOG_JSON)) {
|
|
11
11
|
overwriteLoggingStream(pretty(pinoPrettyOpts));
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
// Prevent timers from keeping the process alive after tests complete.
|
|
15
|
+
// Libraries like viem create internal polling loops (via setTimeout) that
|
|
16
|
+
// reschedule themselves indefinitely. In test environments we never want a
|
|
17
|
+
// timer to be the reason the process can't exit. We also unref stdout/stderr
|
|
18
|
+
// which, when they are pipes (as in Jest workers), remain ref'd by default.
|
|
19
|
+
{
|
|
20
|
+
const origSetTimeout = globalThis.setTimeout;
|
|
21
|
+
const origSetInterval = globalThis.setInterval;
|
|
22
|
+
globalThis.setTimeout = function unrefSetTimeout(...args) {
|
|
23
|
+
const id = origSetTimeout.apply(this, args);
|
|
24
|
+
id?.unref?.();
|
|
25
|
+
return id;
|
|
26
|
+
};
|
|
27
|
+
// Preserve .unref, .__promisify__ etc. that may exist on the original
|
|
28
|
+
Object.setPrototypeOf(globalThis.setTimeout, origSetTimeout);
|
|
29
|
+
|
|
30
|
+
globalThis.setInterval = function unrefSetInterval(...args) {
|
|
31
|
+
const id = origSetInterval.apply(this, args);
|
|
32
|
+
id?.unref?.();
|
|
33
|
+
return id;
|
|
34
|
+
};
|
|
35
|
+
Object.setPrototypeOf(globalThis.setInterval, origSetInterval);
|
|
36
|
+
|
|
37
|
+
if (process.stdout?._handle?.unref) process.stdout._handle.unref();
|
|
38
|
+
if (process.stderr?._handle?.unref) process.stderr._handle.unref();
|
|
39
|
+
}
|
|
@@ -43,17 +43,18 @@ export async function defaultFetch(
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
let responseJson;
|
|
46
|
+
const responseText = await resp.text();
|
|
46
47
|
try {
|
|
47
|
-
responseJson =
|
|
48
|
+
responseJson = JSON.parse(responseText);
|
|
48
49
|
} catch {
|
|
49
50
|
if (!resp.ok) {
|
|
50
51
|
throw new Error(resp.statusText);
|
|
51
52
|
}
|
|
52
|
-
throw new Error(`Failed to parse body as JSON: ${
|
|
53
|
+
throw new Error(`Failed to parse body as JSON: ${responseText}`);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
if (!resp.ok) {
|
|
56
|
-
const errorMessage = `Error ${resp.status} from server ${host}: ${responseJson
|
|
57
|
+
const errorMessage = `Error ${resp.status} from server ${host}: ${responseJson?.error?.message ?? JSON.stringify(responseJson)}`;
|
|
57
58
|
if (noRetry || (resp.status >= 400 && resp.status < 500)) {
|
|
58
59
|
throw new NoRetryError(errorMessage);
|
|
59
60
|
} else {
|
|
@@ -2,7 +2,7 @@ import { format } from 'util';
|
|
|
2
2
|
|
|
3
3
|
import { type Logger, createLogger } from '../../log/pino-logger.js';
|
|
4
4
|
import { type PromiseWithResolvers, promiseWithResolvers } from '../../promise/utils.js';
|
|
5
|
-
import { type ApiSchema, type ApiSchemaFor, schemaHasMethod } from '../../schemas/api.js';
|
|
5
|
+
import { type ApiSchema, type ApiSchemaFor, getSchemaReturnType, schemaHasMethod } from '../../schemas/api.js';
|
|
6
6
|
import { jsonStringify } from '../convert.js';
|
|
7
7
|
import { type JsonRpcFetch, defaultFetch } from './fetch.js';
|
|
8
8
|
|
|
@@ -14,8 +14,9 @@ const DEFAULT_BATCH_WINDOW_MS = 0;
|
|
|
14
14
|
// the maximum size of a batched request
|
|
15
15
|
const DEFAULT_MAX_BATCH_SIZE = 100;
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
|
|
17
|
+
// 1 mb, matching the JSON-RPC server's default maxBodySizeBytes so the client never assembles a batch the
|
|
18
|
+
// server rejects for exceeding the body limit
|
|
19
|
+
const DEFAULT_MAX_REQUESTY_BODY_SIZE = 1 * 1024 * 1024;
|
|
19
20
|
|
|
20
21
|
export type SafeJsonRpcClientOptions = {
|
|
21
22
|
namespaceMethods?: string | false;
|
|
@@ -236,7 +237,7 @@ export function createSafeJsonRpcClient<T extends object>(
|
|
|
236
237
|
if ([null, undefined, 'null', 'undefined'].includes(response.result)) {
|
|
237
238
|
return;
|
|
238
239
|
}
|
|
239
|
-
return (schema as ApiSchema)[methodName]
|
|
240
|
+
return getSchemaReturnType((schema as ApiSchema)[methodName]).parseAsync(response.result);
|
|
240
241
|
};
|
|
241
242
|
|
|
242
243
|
const clientId = nextClientId++;
|
|
@@ -44,18 +44,20 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
44
44
|
let responseJson: any;
|
|
45
45
|
const responseOk = resp.statusCode >= 200 && resp.statusCode <= 299;
|
|
46
46
|
const contentEncoding = resp.headers['content-encoding'];
|
|
47
|
+
let responseText: string;
|
|
47
48
|
try {
|
|
48
49
|
if (contentEncoding === 'gzip') {
|
|
49
50
|
const jsonBuffer = await gunzip(await resp.body.arrayBuffer());
|
|
50
|
-
|
|
51
|
+
responseText = jsonBuffer.toString('utf-8');
|
|
51
52
|
} else {
|
|
52
|
-
|
|
53
|
+
responseText = await resp.body.text();
|
|
53
54
|
}
|
|
55
|
+
responseJson = JSON.parse(responseText);
|
|
54
56
|
} catch {
|
|
55
57
|
if (!responseOk) {
|
|
56
58
|
throw new Error('HTTP ' + resp.statusCode);
|
|
57
59
|
}
|
|
58
|
-
throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${
|
|
60
|
+
throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${responseText!}`);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
if (!responseOk) {
|
|
@@ -130,14 +130,14 @@ export class TestState implements TestStateApi {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
export const TestStateSchema: ApiSchemaFor<TestStateApi> = {
|
|
133
|
-
getNote: z.function(
|
|
134
|
-
getNotes: z.function(
|
|
135
|
-
getNotes2: z.function(
|
|
136
|
-
getNotes3: z.function(
|
|
137
|
-
clear: z.function(
|
|
138
|
-
addNotes: z.function(
|
|
139
|
-
fail: z.function(
|
|
140
|
-
count: z.function(
|
|
141
|
-
getStatus: z.function(
|
|
142
|
-
getTuple: z.function(
|
|
133
|
+
getNote: z.function({ input: z.tuple([z.number()]), output: TestNote.schema.optional() }),
|
|
134
|
+
getNotes: z.function({ input: z.tuple([optional(schemas.Integer)]), output: z.array(TestNote.schema) }),
|
|
135
|
+
getNotes2: z.function({ input: z.tuple([optional(schemas.BigInt)]), output: z.array(TestNote.schema) }),
|
|
136
|
+
getNotes3: z.function({ input: z.tuple([optional(schemas.Integer)]), output: z.array(TestNote.schema) }),
|
|
137
|
+
clear: z.function({ input: z.tuple([]), output: z.void() }),
|
|
138
|
+
addNotes: z.function({ input: z.tuple([z.array(TestNote.schema)]), output: z.array(TestNote.schema) }),
|
|
139
|
+
fail: z.function({ input: z.tuple([]), output: z.void() }),
|
|
140
|
+
count: z.function({ input: z.tuple([]), output: z.number() }),
|
|
141
|
+
getStatus: z.function({ input: z.tuple([]), output: z.object({ status: z.string(), count: schemas.BigInt }) }),
|
|
142
|
+
getTuple: z.function({ input: z.tuple([]), output: z.tuple([z.string(), optional(z.string()), z.number()]) }),
|
|
143
143
|
};
|
|
@@ -10,7 +10,13 @@ import { ZodError } from 'zod';
|
|
|
10
10
|
|
|
11
11
|
import { type Logger, createLogger } from '../../log/index.js';
|
|
12
12
|
import { promiseWithResolvers } from '../../promise/utils.js';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
type ApiSchema,
|
|
15
|
+
type ApiSchemaFor,
|
|
16
|
+
getSchemaParameters,
|
|
17
|
+
parseWithOptionals,
|
|
18
|
+
schemaHasMethod,
|
|
19
|
+
} from '../../schemas/index.js';
|
|
14
20
|
import { jsonStringify } from '../convert.js';
|
|
15
21
|
import { assert } from '../js_utils.js';
|
|
16
22
|
|
|
@@ -53,8 +59,10 @@ export class SafeJsonRpcServer {
|
|
|
53
59
|
config: Partial<SafeJsonRpcServerConfig> = {},
|
|
54
60
|
/** Health check function */
|
|
55
61
|
private readonly healthCheck: StatusCheckFn = () => true,
|
|
56
|
-
/** Additional middlewares */
|
|
62
|
+
/** Additional Koa middlewares */
|
|
57
63
|
private extraMiddlewares: Application.Middleware[] = [],
|
|
64
|
+
/** Additional per-request diagnostics middlewares */
|
|
65
|
+
private diagnosticsMiddleware?: DiagnosticsMiddleware,
|
|
58
66
|
/** Logger */
|
|
59
67
|
private log = createLogger('json-rpc:server'),
|
|
60
68
|
) {
|
|
@@ -155,7 +163,7 @@ export class SafeJsonRpcServer {
|
|
|
155
163
|
};
|
|
156
164
|
return;
|
|
157
165
|
}
|
|
158
|
-
const resp = await this.processBatch(ctx.request.body);
|
|
166
|
+
const resp = await this.processBatch(ctx.request.body, ctx.request.headers);
|
|
159
167
|
if (Array.isArray(resp)) {
|
|
160
168
|
ctx.status = 200;
|
|
161
169
|
ctx.body = resp;
|
|
@@ -164,7 +172,7 @@ export class SafeJsonRpcServer {
|
|
|
164
172
|
ctx.body = resp;
|
|
165
173
|
}
|
|
166
174
|
} else {
|
|
167
|
-
const resp = await this.processRequest(ctx.request.body);
|
|
175
|
+
const resp = await this.processRequest(ctx.request.body, ctx.request.headers);
|
|
168
176
|
if ('error' in resp) {
|
|
169
177
|
ctx.status = this.config.http200OnError ? 200 : 400;
|
|
170
178
|
}
|
|
@@ -176,11 +184,11 @@ export class SafeJsonRpcServer {
|
|
|
176
184
|
return router;
|
|
177
185
|
}
|
|
178
186
|
|
|
179
|
-
private async processBatch(requests: any[]) {
|
|
187
|
+
private async processBatch(requests: any[], headers: http.IncomingHttpHeaders = {}) {
|
|
180
188
|
if (requests.length === 0) {
|
|
181
189
|
return { jsonrpc: '2.0', error: { code: -32600, message: 'Invalid Request' }, id: null };
|
|
182
190
|
}
|
|
183
|
-
const results = await Promise.allSettled(requests.map(req => this.processRequest(req)));
|
|
191
|
+
const results = await Promise.allSettled(requests.map(req => this.processRequest(req, headers)));
|
|
184
192
|
return results.map(res => {
|
|
185
193
|
if (res.status === 'fulfilled') {
|
|
186
194
|
return res.value;
|
|
@@ -191,7 +199,7 @@ export class SafeJsonRpcServer {
|
|
|
191
199
|
});
|
|
192
200
|
}
|
|
193
201
|
|
|
194
|
-
private async processRequest(request: any) {
|
|
202
|
+
private async processRequest(request: any, headers: http.IncomingHttpHeaders = {}) {
|
|
195
203
|
if (!request || typeof request !== 'object') {
|
|
196
204
|
return { jsonrpc: '2.0', error: { code: -32600, message: 'Invalid Request' }, id: null };
|
|
197
205
|
}
|
|
@@ -206,8 +214,21 @@ export class SafeJsonRpcServer {
|
|
|
206
214
|
return { jsonrpc, id, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
207
215
|
} else {
|
|
208
216
|
try {
|
|
209
|
-
|
|
210
|
-
|
|
217
|
+
let result: any;
|
|
218
|
+
|
|
219
|
+
if (this.diagnosticsMiddleware) {
|
|
220
|
+
await this.diagnosticsMiddleware({ id: id ?? null, method, params, headers }, async () => {
|
|
221
|
+
result = await this.proxy.call(method, params);
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
result = await this.proxy.call(method, params);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Coerce an undefined return value to null so the response always carries a `result` key.
|
|
228
|
+
// JSON.stringify drops undefined-valued keys, which would otherwise produce a JSON-RPC
|
|
229
|
+
// response with neither `result` nor `error` — a spec violation that leaves callers unable
|
|
230
|
+
// to distinguish "not found" from a malformed response.
|
|
231
|
+
return { jsonrpc, id, result: result ?? null };
|
|
211
232
|
} catch (err: any) {
|
|
212
233
|
if (err && err instanceof ZodError) {
|
|
213
234
|
const message = err.issues.map(e => `${e.message} (${e.path.join('.')})`).join('. ') || 'Validation error';
|
|
@@ -309,7 +330,7 @@ export class SafeJsonProxy<T extends object = any> implements Proxy {
|
|
|
309
330
|
assert(schemaHasMethod(this.schema, methodName), `Method ${methodName} not found in schema`);
|
|
310
331
|
const method = this.handler[methodName as keyof T];
|
|
311
332
|
assert(typeof method === 'function', `Method ${methodName} is not a function`);
|
|
312
|
-
const args = await parseWithOptionals(jsonParams, this.schema[methodName]
|
|
333
|
+
const args = await parseWithOptionals(jsonParams, getSchemaParameters(this.schema[methodName]));
|
|
313
334
|
const ret = await method.apply(this.handler, args);
|
|
314
335
|
this.log.debug(format('response', methodName, ret));
|
|
315
336
|
return ret;
|
|
@@ -377,6 +398,7 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo
|
|
|
377
398
|
export type SafeJsonRpcServerOptions = Partial<
|
|
378
399
|
SafeJsonRpcServerConfig & {
|
|
379
400
|
healthCheck: StatusCheckFn;
|
|
401
|
+
diagnostic: DiagnosticsMiddleware;
|
|
380
402
|
log: Logger;
|
|
381
403
|
middlewares: Application.Middleware[];
|
|
382
404
|
}
|
|
@@ -391,10 +413,10 @@ export function createNamespacedSafeJsonRpcServer(
|
|
|
391
413
|
handlers: NamespacedApiHandlers,
|
|
392
414
|
options: Omit<SafeJsonRpcServerOptions, 'healthcheck'> = {},
|
|
393
415
|
): SafeJsonRpcServer {
|
|
394
|
-
const { middlewares, log } = options;
|
|
416
|
+
const { diagnostic, middlewares, log } = options;
|
|
395
417
|
const proxy = new NamespacedSafeJsonProxy(handlers);
|
|
396
418
|
const healthCheck = makeAggregateHealthcheck(handlers, log);
|
|
397
|
-
return new SafeJsonRpcServer(proxy, options, healthCheck, middlewares, log);
|
|
419
|
+
return new SafeJsonRpcServer(proxy, options, healthCheck, middlewares, diagnostic, log);
|
|
398
420
|
}
|
|
399
421
|
|
|
400
422
|
export function createSafeJsonRpcServer<T extends object = any>(
|
|
@@ -402,9 +424,9 @@ export function createSafeJsonRpcServer<T extends object = any>(
|
|
|
402
424
|
schema: ApiSchemaFor<T>,
|
|
403
425
|
options: SafeJsonRpcServerOptions = {},
|
|
404
426
|
) {
|
|
405
|
-
const { log, healthCheck, middlewares: extraMiddlewares } = options;
|
|
427
|
+
const { diagnostic, log, healthCheck, middlewares: extraMiddlewares } = options;
|
|
406
428
|
const proxy = new SafeJsonProxy(handler, schema);
|
|
407
|
-
return new SafeJsonRpcServer(proxy, options, healthCheck, extraMiddlewares, log);
|
|
429
|
+
return new SafeJsonRpcServer(proxy, options, healthCheck, extraMiddlewares, diagnostic, log);
|
|
408
430
|
}
|
|
409
431
|
|
|
410
432
|
/**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { pino } from 'pino';
|
|
2
|
+
|
|
3
|
+
function getSeverity(label: string): { severityText: string; severityNumber: number } {
|
|
4
|
+
switch (label) {
|
|
5
|
+
case 'trace':
|
|
6
|
+
return { severityText: 'TRACE', severityNumber: 1 };
|
|
7
|
+
case 'debug':
|
|
8
|
+
return { severityText: 'DEBUG', severityNumber: 5 };
|
|
9
|
+
case 'verbose':
|
|
10
|
+
return { severityText: 'VERBOSE', severityNumber: 7 };
|
|
11
|
+
case 'info':
|
|
12
|
+
return { severityText: 'INFO', severityNumber: 9 };
|
|
13
|
+
case 'warn':
|
|
14
|
+
return { severityText: 'WARN', severityNumber: 13 };
|
|
15
|
+
case 'error':
|
|
16
|
+
return { severityText: 'ERROR', severityNumber: 17 };
|
|
17
|
+
case 'fatal':
|
|
18
|
+
return { severityText: 'FATAL', severityNumber: 21 };
|
|
19
|
+
default:
|
|
20
|
+
return { severityText: 'UNSPECIFIED', severityNumber: 0 };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Pino configuration that adds OpenTelemetry severity fields understood by CloudWatch Logs. */
|
|
25
|
+
export const AWSCloudLoggerConfig = {
|
|
26
|
+
messageKey: 'msg',
|
|
27
|
+
formatters: {
|
|
28
|
+
level(label: string, level: number): object {
|
|
29
|
+
return { level, ...getSeverity(label) };
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
} satisfies pino.LoggerOptions;
|
package/src/log/pino-logger.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { inspect } from 'util';
|
|
|
7
7
|
import { compactArray } from '../collection/array.js';
|
|
8
8
|
import type { EnvVar } from '../config/index.js';
|
|
9
9
|
import { parseBooleanEnv } from '../config/parse-env.js';
|
|
10
|
+
import { AWSCloudLoggerConfig } from './aws-logger-config.js';
|
|
10
11
|
import { convertBigintsToStrings } from './bigint-utils.js';
|
|
11
12
|
import { GoogleCloudLoggerConfig } from './gcloud-logger-config.js';
|
|
12
13
|
import { getLogLevelFromFilters, parseLogLevelEnvVar } from './log-filters.js';
|
|
@@ -21,6 +22,8 @@ export type LoggerBindings = {
|
|
|
21
22
|
instanceId?: string;
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
const MAX_MODULE_NAME_LENGTH = 256;
|
|
26
|
+
|
|
24
27
|
// Allow global hooks for providing default bindings.
|
|
25
28
|
// Used by withLoggerBindings in pino-logger-server to propagate bindings via AsyncLocalStorage.
|
|
26
29
|
type LogBindingsHandler = () => LoggerBindings | undefined;
|
|
@@ -48,7 +51,7 @@ function getBindingsFromHandlers(): LoggerBindings | undefined {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
export function createLogger(module: string, bindings?: LoggerBindings): Logger {
|
|
51
|
-
module = module.replace(/^aztec:/, '');
|
|
54
|
+
module = module.slice(0, MAX_MODULE_NAME_LENGTH).replace(/^aztec:/, '');
|
|
52
55
|
|
|
53
56
|
const resolvedBindings = { ...getBindingsFromHandlers(), ...bindings };
|
|
54
57
|
const actor = resolvedBindings?.actor;
|
|
@@ -132,8 +135,17 @@ export const [logLevel, logFilters] = parseLogLevelEnvVar(process.env.LOG_LEVEL,
|
|
|
132
135
|
// Define custom logging levels for pino.
|
|
133
136
|
const customLevels = { verbose: 25 };
|
|
134
137
|
|
|
135
|
-
// Global pino options, tweaked for
|
|
138
|
+
// Global pino options, tweaked for the active cloud logging backend.
|
|
136
139
|
const useGcloudLogging = parseBooleanEnv(process.env['USE_GCLOUD_LOGGING' satisfies EnvVar]);
|
|
140
|
+
const useAwsLogging = parseBooleanEnv(process.env['USE_AWS_LOGGING' satisfies EnvVar]);
|
|
141
|
+
const loggingConfig = useGcloudLogging
|
|
142
|
+
? GoogleCloudLoggerConfig
|
|
143
|
+
: useAwsLogging
|
|
144
|
+
? AWSCloudLoggerConfig
|
|
145
|
+
: {
|
|
146
|
+
formatters: {},
|
|
147
|
+
messageKey: 'msg',
|
|
148
|
+
};
|
|
137
149
|
|
|
138
150
|
const redactedPaths = [
|
|
139
151
|
'validatorPrivateKeys',
|
|
@@ -154,7 +166,7 @@ const redactedPaths = [
|
|
|
154
166
|
|
|
155
167
|
const pinoOpts: pino.LoggerOptions<keyof typeof customLevels> = {
|
|
156
168
|
customLevels,
|
|
157
|
-
messageKey:
|
|
169
|
+
messageKey: loggingConfig.messageKey,
|
|
158
170
|
useOnlyCustomLevels: false,
|
|
159
171
|
level: logLevel,
|
|
160
172
|
redact: {
|
|
@@ -168,8 +180,8 @@ const pinoOpts: pino.LoggerOptions<keyof typeof customLevels> = {
|
|
|
168
180
|
},
|
|
169
181
|
formatters: {
|
|
170
182
|
log: obj => convertBigintsToStrings(obj) as Record<string, unknown>,
|
|
183
|
+
...loggingConfig.formatters,
|
|
171
184
|
},
|
|
172
|
-
...(useGcloudLogging ? GoogleCloudLoggerConfig : {}),
|
|
173
185
|
};
|
|
174
186
|
|
|
175
187
|
export const levels = {
|
|
@@ -239,7 +251,7 @@ const pinoPrettyBaseOpts = {
|
|
|
239
251
|
destination: 2,
|
|
240
252
|
sync: true,
|
|
241
253
|
colorize: useColor,
|
|
242
|
-
ignore: 'module,actor,instanceId,pid,hostname,trace_id,span_id,trace_flags,severity',
|
|
254
|
+
ignore: 'module,actor,instanceId,pid,hostname,trace_id,span_id,trace_flags,severity,severityText,severityNumber',
|
|
243
255
|
customLevels: 'fatal:60,error:50,warn:40,info:30,verbose:25,debug:20,trace:10',
|
|
244
256
|
customColors: 'fatal:bgRed,error:red,warn:yellow,info:green,verbose:magenta,debug:blue,trace:gray',
|
|
245
257
|
minimumLevel: 'trace' as const,
|
|
@@ -375,5 +387,20 @@ export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ er
|
|
|
375
387
|
* @returns A string with both the log message and the error message.
|
|
376
388
|
*/
|
|
377
389
|
function formatErr(msg: string, err?: unknown): string {
|
|
378
|
-
|
|
390
|
+
if (!err) {
|
|
391
|
+
return msg;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
try {
|
|
395
|
+
return `${msg}: ${inspect(err)}`;
|
|
396
|
+
} catch {
|
|
397
|
+
// inspect can crash on error objects with broken property descriptors
|
|
398
|
+
try {
|
|
399
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
400
|
+
return `${msg}: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`;
|
|
401
|
+
} catch {
|
|
402
|
+
// if even String(err) fails, return the original message with a note about the error
|
|
403
|
+
return `${msg}: [unserializable error]`;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
379
406
|
}
|
|
@@ -10,26 +10,6 @@ const noirLocalDependencySchema = z.object({
|
|
|
10
10
|
path: z.string(),
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
const noirPackageConfigSchema = z.object({
|
|
14
|
-
package: z.object({
|
|
15
|
-
name: z.string().default(''),
|
|
16
|
-
type: z.enum(['lib', 'contract', 'bin']).default('bin'),
|
|
17
|
-
entry: z.string().optional(),
|
|
18
|
-
description: z.string().optional(),
|
|
19
|
-
authors: z.array(z.string()).optional(),
|
|
20
|
-
// eslint-disable-next-line camelcase
|
|
21
|
-
compiler_version: z.string().optional(),
|
|
22
|
-
backend: z.string().optional(),
|
|
23
|
-
license: z.string().optional(),
|
|
24
|
-
}),
|
|
25
|
-
dependencies: z.record(z.union([noirGitDependencySchema, noirLocalDependencySchema])).default({}),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Noir package configuration.
|
|
30
|
-
*/
|
|
31
|
-
export type NoirPackageConfig = z.infer<typeof noirPackageConfigSchema>;
|
|
32
|
-
|
|
33
13
|
/**
|
|
34
14
|
* A remote package dependency.
|
|
35
15
|
*/
|
|
@@ -45,6 +25,38 @@ export type NoirLocalDependencyConfig = z.infer<typeof noirLocalDependencySchema
|
|
|
45
25
|
*/
|
|
46
26
|
export type NoirDependencyConfig = NoirGitDependencyConfig | NoirLocalDependencyConfig;
|
|
47
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Noir package configuration.
|
|
30
|
+
*/
|
|
31
|
+
export type NoirPackageConfig = {
|
|
32
|
+
package: {
|
|
33
|
+
name: string;
|
|
34
|
+
type: 'lib' | 'contract' | 'bin';
|
|
35
|
+
entry?: string | undefined;
|
|
36
|
+
description?: string | undefined;
|
|
37
|
+
authors?: string[] | undefined;
|
|
38
|
+
compiler_version?: string | undefined;
|
|
39
|
+
backend?: string | undefined;
|
|
40
|
+
license?: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
dependencies: Record<string, NoirDependencyConfig>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const noirPackageConfigSchema: z.ZodType<NoirPackageConfig> = z.object({
|
|
46
|
+
package: z.object({
|
|
47
|
+
name: z.string().default(''),
|
|
48
|
+
type: z.enum(['lib', 'contract', 'bin']).default('bin'),
|
|
49
|
+
entry: z.string().optional(),
|
|
50
|
+
description: z.string().optional(),
|
|
51
|
+
authors: z.array(z.string()).optional(),
|
|
52
|
+
// eslint-disable-next-line camelcase
|
|
53
|
+
compiler_version: z.string().optional(),
|
|
54
|
+
backend: z.string().optional(),
|
|
55
|
+
license: z.string().optional(),
|
|
56
|
+
}),
|
|
57
|
+
dependencies: z.record(z.string(), z.union([noirGitDependencySchema, noirLocalDependencySchema])).default({}),
|
|
58
|
+
});
|
|
59
|
+
|
|
48
60
|
/**
|
|
49
61
|
* Checks that an object is a package configuration.
|
|
50
62
|
* @param config - Config to check
|