@aztec/wsdb 0.0.1-commit.031e54b → 0.0.1-commit.189eedb3
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/README.md +3 -4
- package/dest/bin.d.ts +3 -0
- package/dest/bin.d.ts.map +1 -0
- package/dest/bin.js +15 -0
- package/dest/generated/api_types.d.ts +58 -58
- package/dest/generated/api_types.d.ts.map +1 -1
- package/dest/generated/api_types.js +198 -205
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +52 -5
- package/package.json +9 -6
package/dest/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncApi, type IpcErrorFactory } from './generated/async.js';
|
|
2
2
|
export * from './generated/api_types.js';
|
|
3
3
|
export { AsyncApi } from './generated/async.js';
|
|
4
|
+
export { SyncApi } from './generated/sync.js';
|
|
4
5
|
export type WsdbTransport = 'uds' | 'shm';
|
|
5
6
|
export interface WsdbServiceOptions {
|
|
6
7
|
binaryPath?: string;
|
|
@@ -18,5 +19,6 @@ export declare class WsdbService extends AsyncApi {
|
|
|
18
19
|
private constructor();
|
|
19
20
|
static spawn(options?: WsdbServiceOptions): Promise<WsdbService>;
|
|
20
21
|
getIpcPath(): string;
|
|
22
|
+
sendProcessSignal(signal: NodeJS.Signals): void;
|
|
21
23
|
}
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGtE,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGtE,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAmLD,qBAAa,WAAY,SAAQ,QAAQ;IACnB,OAAO,CAAC,cAAc;IAA1C,OAAO;WAIM,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAK1E,UAAU,IAAI,MAAM;IAIpB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI;CAGhD"}
|
package/dest/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import { closeSync, existsSync, openSync, unlinkSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { threadId } from 'node:worker_threads';
|
|
@@ -8,6 +8,7 @@ import { AsyncApi } from './generated/async.js';
|
|
|
8
8
|
import { findWsdbBinary } from './platform.js';
|
|
9
9
|
export * from './generated/api_types.js';
|
|
10
10
|
export { AsyncApi } from './generated/async.js';
|
|
11
|
+
export { SyncApi } from './generated/sync.js';
|
|
11
12
|
let instanceCounter = 0;
|
|
12
13
|
const DEFAULT_CONNECT_TIMEOUT_MS = 30_000;
|
|
13
14
|
class SpawnedBackend {
|
|
@@ -16,12 +17,28 @@ class SpawnedBackend {
|
|
|
16
17
|
ipcPath;
|
|
17
18
|
transport;
|
|
18
19
|
exitPromise;
|
|
19
|
-
|
|
20
|
+
logPath;
|
|
21
|
+
destroying = false;
|
|
22
|
+
exitError;
|
|
23
|
+
constructor(child, client, ipcPath, transport, exitPromise, logPath) {
|
|
20
24
|
this.child = child;
|
|
21
25
|
this.client = client;
|
|
22
26
|
this.ipcPath = ipcPath;
|
|
23
27
|
this.transport = transport;
|
|
24
28
|
this.exitPromise = exitPromise;
|
|
29
|
+
this.logPath = logPath;
|
|
30
|
+
// Detect unexpected server death. Over SHM there is no connection to break,
|
|
31
|
+
// so without this an in-flight call waits forever for a reply that will
|
|
32
|
+
// never arrive. Reject in-flight calls and point at the log file.
|
|
33
|
+
this.child.on('exit', (code, signal) => {
|
|
34
|
+
if (this.destroying) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.exitError = new Error('aztec-wsdb exited unexpectedly (code=' + code + ', signal=' + signal + ')' +
|
|
38
|
+
(this.logPath ? '; see logs: ' + this.logPath : ''));
|
|
39
|
+
console.error(this.exitError.message);
|
|
40
|
+
void this.client.destroy();
|
|
41
|
+
});
|
|
25
42
|
}
|
|
26
43
|
static async spawn(options = {}) {
|
|
27
44
|
const binaryPath = findWsdbBinary(options.binaryPath);
|
|
@@ -36,11 +53,25 @@ class SpawnedBackend {
|
|
|
36
53
|
if (transport === 'uds' && existsSync(ipcPath)) {
|
|
37
54
|
unlinkSync(ipcPath);
|
|
38
55
|
}
|
|
56
|
+
// Without a live logger, capture the child's stdout/stderr to a temp file
|
|
57
|
+
// (a plain fd, not a pipe — a pipe would keep the libuv loop referenced and
|
|
58
|
+
// break clean process exit). The path is surfaced if the child dies, so its
|
|
59
|
+
// errors are recoverable instead of vanishing into an ignored stream.
|
|
60
|
+
const logPath = options.logger ? undefined : join(tmpdir(), instanceId + '.log');
|
|
61
|
+
const logFd = logPath !== undefined ? openSync(logPath, 'a') : undefined;
|
|
39
62
|
const ipcPathArgs = ["msgpack", "run", "--input", "{path}"].map((arg) => arg === '{path}' ? ipcPath : arg);
|
|
40
63
|
const child = spawn(binaryPath, [...ipcPathArgs, ...(options.extraArgs ?? [])], {
|
|
41
|
-
stdio: [
|
|
64
|
+
stdio: [
|
|
65
|
+
'ignore',
|
|
66
|
+
options.logger ? 'pipe' : logFd,
|
|
67
|
+
options.logger ? 'pipe' : logFd,
|
|
68
|
+
],
|
|
42
69
|
env: { ...process.env, ...(options.env ?? {}) },
|
|
43
70
|
});
|
|
71
|
+
if (logFd !== undefined) {
|
|
72
|
+
// The child holds its own dup of the fd; the parent's copy isn't needed.
|
|
73
|
+
closeSync(logFd);
|
|
74
|
+
}
|
|
44
75
|
if (options.logger) {
|
|
45
76
|
child.stdout?.on('data', (data) => options.logger?.('[aztec-wsdb stdout] ' + data.toString().trimEnd()));
|
|
46
77
|
child.stderr?.on('data', (data) => options.logger?.('[aztec-wsdb stderr] ' + data.toString().trimEnd()));
|
|
@@ -55,15 +86,26 @@ class SpawnedBackend {
|
|
|
55
86
|
});
|
|
56
87
|
});
|
|
57
88
|
const client = await Promise.race([connectClient(child, ipcPath, transport, options), childReadyFailure]);
|
|
58
|
-
return new SpawnedBackend(child, client, ipcPath, transport, exitPromise);
|
|
89
|
+
return new SpawnedBackend(child, client, ipcPath, transport, exitPromise, logPath);
|
|
59
90
|
}
|
|
60
91
|
getIpcPath() {
|
|
61
92
|
return this.ipcPath;
|
|
62
93
|
}
|
|
63
94
|
call(input) {
|
|
95
|
+
if (this.exitError) {
|
|
96
|
+
return Promise.reject(this.exitError);
|
|
97
|
+
}
|
|
64
98
|
return this.client.call(input);
|
|
65
99
|
}
|
|
100
|
+
sendProcessSignal(signal) {
|
|
101
|
+
if (this.child.exitCode === null) {
|
|
102
|
+
this.child.kill(signal);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
66
105
|
async destroy() {
|
|
106
|
+
// Mark intentional teardown so the exit handler doesn't report it as an
|
|
107
|
+
// unexpected death.
|
|
108
|
+
this.destroying = true;
|
|
67
109
|
await this.client.destroy();
|
|
68
110
|
if (this.child.exitCode === null) {
|
|
69
111
|
this.child.kill('SIGTERM');
|
|
@@ -89,7 +131,9 @@ async function connectClient(child, ipcPath, transport, options) {
|
|
|
89
131
|
}
|
|
90
132
|
if (transport === 'shm') {
|
|
91
133
|
return createNapiShmAsyncClient(ipcPath.replace(/\.shm$/, ''), {
|
|
92
|
-
clientId:
|
|
134
|
+
// Pass clientId through as-is: when unset, the client self-allocates a
|
|
135
|
+
// free producer slot (don't default to 0, which aliases every client).
|
|
136
|
+
clientId: options.clientId,
|
|
93
137
|
customAddonPath: options.napiPath,
|
|
94
138
|
});
|
|
95
139
|
}
|
|
@@ -132,4 +176,7 @@ export class WsdbService extends AsyncApi {
|
|
|
132
176
|
getIpcPath() {
|
|
133
177
|
return this.spawnedBackend.getIpcPath();
|
|
134
178
|
}
|
|
179
|
+
sendProcessSignal(signal) {
|
|
180
|
+
this.spawnedBackend.sendProcessSignal(signal);
|
|
181
|
+
}
|
|
135
182
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wsdb",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.189eedb3",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"aztec-wsdb": "./dest/bin.js"
|
|
7
|
+
},
|
|
5
8
|
"exports": {
|
|
6
9
|
".": {
|
|
7
10
|
"types": "./dest/index.d.ts",
|
|
@@ -18,15 +21,15 @@
|
|
|
18
21
|
"prepare_arch_packages": "./scripts/prepare_arch_packages.sh"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"@aztec/ipc-runtime": "0.0.1-commit.
|
|
24
|
+
"@aztec/ipc-runtime": "0.0.1-commit.189eedb3",
|
|
22
25
|
"msgpackr": "^1.11.2",
|
|
23
26
|
"tslib": "^2.4.0"
|
|
24
27
|
},
|
|
25
28
|
"optionalDependencies": {
|
|
26
|
-
"@aztec/wsdb-linux-x64": "0.0.1-commit.
|
|
27
|
-
"@aztec/wsdb-darwin-x64": "0.0.1-commit.
|
|
28
|
-
"@aztec/wsdb-linux-arm64": "0.0.1-commit.
|
|
29
|
-
"@aztec/wsdb-darwin-arm64": "0.0.1-commit.
|
|
29
|
+
"@aztec/wsdb-linux-x64": "0.0.1-commit.189eedb3",
|
|
30
|
+
"@aztec/wsdb-darwin-x64": "0.0.1-commit.189eedb3",
|
|
31
|
+
"@aztec/wsdb-linux-arm64": "0.0.1-commit.189eedb3",
|
|
32
|
+
"@aztec/wsdb-darwin-arm64": "0.0.1-commit.189eedb3"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
35
|
"@types/node": "^22.15.17",
|