hyperdb-wasm 0.0.27361-dev.wasm.g7817abf3 → 0.0.27367-dev.wasm.g50457039
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/dist/browser.d.ts +2 -0
- package/dist/browser.js +28 -11
- package/dist/browser_worker.js +5 -5
- package/dist/client.d.ts +2 -1
- package/dist/hyperdb-wasm.wasm.br +0 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.js +34 -12
- package/dist/node_worker.js +19 -5
- package/dist/protocol.d.ts +1 -0
- package/dist/raw.browser.js +13 -3
- package/dist/raw.node.js +17 -3
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface BrowserClientOptions {
|
|
|
14
14
|
/** OPFS-relative directory mounted as the durable filesystem root. */
|
|
15
15
|
readonly storagePath?: string;
|
|
16
16
|
readonly onSetupProgress?: (progress: SetupProgress) => void;
|
|
17
|
+
/** Receives engine output; omitted callbacks discard output, and callback exceptions are ignored */
|
|
18
|
+
readonly onLog?: (stream: 'stdout' | 'stderr', text: string) => void;
|
|
17
19
|
}
|
|
18
20
|
type BrowserEnvironment = {
|
|
19
21
|
readonly WebAssembly?: typeof WebAssembly;
|
package/dist/browser.js
CHANGED
|
@@ -52,7 +52,7 @@ function isWorkerEvent(message) {
|
|
|
52
52
|
case "fatal":
|
|
53
53
|
return hasKeys(message, ["type", "error"]) && typeof message.error === "string";
|
|
54
54
|
case "log":
|
|
55
|
-
return hasKeys(message, ["type", "text"]) && typeof message.text === "string";
|
|
55
|
+
return hasKeys(message, ["type", "stream", "text"]) && (message.stream === "stdout" || message.stream === "stderr") && typeof message.text === "string";
|
|
56
56
|
case "response":
|
|
57
57
|
return hasKeys(message, ["id", "type", "result"]) && Number.isSafeInteger(message.id) && isWasmResult(message.result);
|
|
58
58
|
default:
|
|
@@ -72,8 +72,9 @@ var init_client = __esm({
|
|
|
72
72
|
"use strict";
|
|
73
73
|
init_protocol();
|
|
74
74
|
HyperDBEngineClient = class {
|
|
75
|
-
constructor(transport, onSetupProgress) {
|
|
75
|
+
constructor(transport, onSetupProgress, onLog) {
|
|
76
76
|
this.onSetupProgress = onSetupProgress;
|
|
77
|
+
this.onLog = onLog;
|
|
77
78
|
this.transport = transport;
|
|
78
79
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
79
80
|
this.resolveReady = resolve;
|
|
@@ -86,6 +87,7 @@ var init_client = __esm({
|
|
|
86
87
|
];
|
|
87
88
|
}
|
|
88
89
|
onSetupProgress;
|
|
90
|
+
onLog;
|
|
89
91
|
transport;
|
|
90
92
|
pending = /* @__PURE__ */ new Map();
|
|
91
93
|
readyPromise;
|
|
@@ -167,6 +169,13 @@ var init_client = __esm({
|
|
|
167
169
|
this.onSetupProgress?.({ bytesLoaded: message.bytesLoaded, bytesTotal: message.bytesTotal });
|
|
168
170
|
return;
|
|
169
171
|
}
|
|
172
|
+
if (message.type === "log") {
|
|
173
|
+
try {
|
|
174
|
+
this.onLog?.(message.stream, message.text);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
170
179
|
if (message.type === "fatal") {
|
|
171
180
|
this.failAndTerminate(new Error(message.error || "engine aborted"));
|
|
172
181
|
return;
|
|
@@ -249,7 +258,8 @@ function createBrowserClient(options = {}) {
|
|
|
249
258
|
const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
|
|
250
259
|
return new HyperDBEngineClient(
|
|
251
260
|
new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl, options.storagePath), { type: "classic" })),
|
|
252
|
-
options.onSetupProgress
|
|
261
|
+
options.onSetupProgress,
|
|
262
|
+
options.onLog
|
|
253
263
|
);
|
|
254
264
|
}
|
|
255
265
|
var memory64Probe, threadsProbe, exceptionsProbe, tailCallsProbe, BrowserWorker;
|
|
@@ -755,12 +765,17 @@ var HyperDBConnection = class {
|
|
|
755
765
|
const result = {
|
|
756
766
|
[Symbol.asyncIterator]() {
|
|
757
767
|
return {
|
|
758
|
-
next() {
|
|
759
|
-
|
|
760
|
-
abortDelivered
|
|
761
|
-
|
|
768
|
+
async next() {
|
|
769
|
+
try {
|
|
770
|
+
if (operation.aborted && !abortDelivered) {
|
|
771
|
+
abortDelivered = true;
|
|
772
|
+
throw operation.abortReason;
|
|
773
|
+
}
|
|
774
|
+
return await operation.interrupt(generator.next());
|
|
775
|
+
} catch (error) {
|
|
776
|
+
await generator.return(void 0);
|
|
777
|
+
throw error;
|
|
762
778
|
}
|
|
763
|
-
return operation.interrupt(generator.next());
|
|
764
779
|
},
|
|
765
780
|
return(value) {
|
|
766
781
|
return generator.return(value);
|
|
@@ -804,12 +819,14 @@ var HyperDBConnection = class {
|
|
|
804
819
|
return queryPromise(result, stream.info);
|
|
805
820
|
}
|
|
806
821
|
query(sql, options = {}) {
|
|
807
|
-
const stream = this.
|
|
822
|
+
const stream = this.queryStreamIPC(sql, options);
|
|
808
823
|
const result = (async () => {
|
|
809
|
-
const reader = await stream;
|
|
824
|
+
const reader = await RecordBatchReader.from(stream);
|
|
825
|
+
await reader.open();
|
|
826
|
+
const schema = reader.schema;
|
|
810
827
|
const batches = [];
|
|
811
828
|
for await (const batch of reader) batches.push(batch);
|
|
812
|
-
return new Table(
|
|
829
|
+
return schema ? new Table(schema, batches) : new Table();
|
|
813
830
|
})();
|
|
814
831
|
return queryPromise(result, stream.info);
|
|
815
832
|
}
|
package/dist/browser_worker.js
CHANGED
|
@@ -483,11 +483,11 @@
|
|
|
483
483
|
try {
|
|
484
484
|
completeFetch(id, allocate(module, bytes), bytes.byteLength);
|
|
485
485
|
} catch (error) {
|
|
486
|
-
transport.postMessage({ type: "log", text: `fetch failed: ${errorText(error)}` });
|
|
486
|
+
transport.postMessage({ type: "log", stream: "stderr", text: `fetch failed: ${errorText(error)}` });
|
|
487
487
|
completeFetch(id, 0, -1);
|
|
488
488
|
}
|
|
489
489
|
}).catch(() => {
|
|
490
|
-
transport.postMessage({ type: "log", text: "fetch failed" });
|
|
490
|
+
transport.postMessage({ type: "log", stream: "stderr", text: "fetch failed" });
|
|
491
491
|
completeFetch(id, 0, -1);
|
|
492
492
|
});
|
|
493
493
|
};
|
|
@@ -498,7 +498,7 @@
|
|
|
498
498
|
if (!backend) return;
|
|
499
499
|
module.hyperdbWasmExternalDirectoryReleaseGeneration = (locator, generation) => {
|
|
500
500
|
void Promise.resolve().then(() => backend.releaseGeneration(locator, generation)).catch(() => {
|
|
501
|
-
transport.postMessage({ type: "log", text: "External directory generation cleanup failed; mount removal will retry" });
|
|
501
|
+
transport.postMessage({ type: "log", stream: "stderr", text: "External directory generation cleanup failed; mount removal will retry" });
|
|
502
502
|
});
|
|
503
503
|
};
|
|
504
504
|
const listComplete = module._hyperdb_wasm_external_directory_list_complete;
|
|
@@ -703,8 +703,8 @@
|
|
|
703
703
|
transport.onMessage((message) => {
|
|
704
704
|
if (isEngineRequest(message)) handle(message);
|
|
705
705
|
});
|
|
706
|
-
module.print = (text) => transport.postMessage({ type: "log", text });
|
|
707
|
-
module.printErr = (text) => transport.postMessage({ type: "log", text });
|
|
706
|
+
module.print = (text) => transport.postMessage({ type: "log", stream: "stdout", text });
|
|
707
|
+
module.printErr = (text) => transport.postMessage({ type: "log", stream: "stderr", text });
|
|
708
708
|
module.onRuntimeInitialized = () => {
|
|
709
709
|
if (failed) return;
|
|
710
710
|
try {
|
package/dist/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ConnectionSettings, HyperDBSettings, MountAccessMode } from './api
|
|
|
2
2
|
import type { MountSource, SetupProgress, WasmResult, WorkerTransport } from './protocol.js';
|
|
3
3
|
export declare class HyperDBEngineClient {
|
|
4
4
|
private readonly onSetupProgress?;
|
|
5
|
+
private readonly onLog?;
|
|
5
6
|
private readonly transport;
|
|
6
7
|
private readonly pending;
|
|
7
8
|
private readonly readyPromise;
|
|
@@ -11,7 +12,7 @@ export declare class HyperDBEngineClient {
|
|
|
11
12
|
private failed;
|
|
12
13
|
private termination;
|
|
13
14
|
private readonly unsubscribe;
|
|
14
|
-
constructor(transport: WorkerTransport, onSetupProgress?: ((progress: SetupProgress) => void) | undefined);
|
|
15
|
+
constructor(transport: WorkerTransport, onSetupProgress?: ((progress: SetupProgress) => void) | undefined, onLog?: ((stream: "stdout" | "stderr", text: string) => void) | undefined);
|
|
15
16
|
ready(): Promise<void>;
|
|
16
17
|
get failure(): Error | undefined;
|
|
17
18
|
initialize(settings: HyperDBSettings): Promise<WasmResult>;
|
|
Binary file
|
package/dist/node.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface NodeClientOptions {
|
|
|
21
21
|
readonly engineUrl?: string;
|
|
22
22
|
/** Host directory mounted as the durable root; callers must prevent concurrent database access from other engines */
|
|
23
23
|
readonly storagePath?: string;
|
|
24
|
+
/** Receives engine output; omitted callbacks discard output, and callback exceptions are ignored */
|
|
25
|
+
readonly onLog?: (stream: 'stdout' | 'stderr', text: string) => void;
|
|
24
26
|
}
|
|
25
27
|
export declare function resolveNodeEnginePath(engineUrl: URL): string;
|
|
26
28
|
export declare function createNodeClient(options?: NodeClientOptions): HyperDBEngineClient;
|
package/dist/node.js
CHANGED
|
@@ -52,7 +52,7 @@ function isWorkerEvent(message) {
|
|
|
52
52
|
case "fatal":
|
|
53
53
|
return hasKeys(message, ["type", "error"]) && typeof message.error === "string";
|
|
54
54
|
case "log":
|
|
55
|
-
return hasKeys(message, ["type", "text"]) && typeof message.text === "string";
|
|
55
|
+
return hasKeys(message, ["type", "stream", "text"]) && (message.stream === "stdout" || message.stream === "stderr") && typeof message.text === "string";
|
|
56
56
|
case "response":
|
|
57
57
|
return hasKeys(message, ["id", "type", "result"]) && Number.isSafeInteger(message.id) && isWasmResult(message.result);
|
|
58
58
|
default:
|
|
@@ -72,8 +72,9 @@ var init_client = __esm({
|
|
|
72
72
|
"use strict";
|
|
73
73
|
init_protocol();
|
|
74
74
|
HyperDBEngineClient = class {
|
|
75
|
-
constructor(transport, onSetupProgress) {
|
|
75
|
+
constructor(transport, onSetupProgress, onLog) {
|
|
76
76
|
this.onSetupProgress = onSetupProgress;
|
|
77
|
+
this.onLog = onLog;
|
|
77
78
|
this.transport = transport;
|
|
78
79
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
79
80
|
this.resolveReady = resolve;
|
|
@@ -86,6 +87,7 @@ var init_client = __esm({
|
|
|
86
87
|
];
|
|
87
88
|
}
|
|
88
89
|
onSetupProgress;
|
|
90
|
+
onLog;
|
|
89
91
|
transport;
|
|
90
92
|
pending = /* @__PURE__ */ new Map();
|
|
91
93
|
readyPromise;
|
|
@@ -167,6 +169,13 @@ var init_client = __esm({
|
|
|
167
169
|
this.onSetupProgress?.({ bytesLoaded: message.bytesLoaded, bytesTotal: message.bytesTotal });
|
|
168
170
|
return;
|
|
169
171
|
}
|
|
172
|
+
if (message.type === "log") {
|
|
173
|
+
try {
|
|
174
|
+
this.onLog?.(message.stream, message.text);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
170
179
|
if (message.type === "fatal") {
|
|
171
180
|
this.failAndTerminate(new Error(message.error || "engine aborted"));
|
|
172
181
|
return;
|
|
@@ -249,7 +258,8 @@ function createBrowserClient(options = {}) {
|
|
|
249
258
|
const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
|
|
250
259
|
return new HyperDBEngineClient(
|
|
251
260
|
new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl, options.storagePath), { type: "classic" })),
|
|
252
|
-
options.onSetupProgress
|
|
261
|
+
options.onSetupProgress,
|
|
262
|
+
options.onLog
|
|
253
263
|
);
|
|
254
264
|
}
|
|
255
265
|
var memory64Probe, threadsProbe, exceptionsProbe, tailCallsProbe, BrowserWorker;
|
|
@@ -755,12 +765,17 @@ var HyperDBConnection = class {
|
|
|
755
765
|
const result = {
|
|
756
766
|
[Symbol.asyncIterator]() {
|
|
757
767
|
return {
|
|
758
|
-
next() {
|
|
759
|
-
|
|
760
|
-
abortDelivered
|
|
761
|
-
|
|
768
|
+
async next() {
|
|
769
|
+
try {
|
|
770
|
+
if (operation.aborted && !abortDelivered) {
|
|
771
|
+
abortDelivered = true;
|
|
772
|
+
throw operation.abortReason;
|
|
773
|
+
}
|
|
774
|
+
return await operation.interrupt(generator.next());
|
|
775
|
+
} catch (error) {
|
|
776
|
+
await generator.return(void 0);
|
|
777
|
+
throw error;
|
|
762
778
|
}
|
|
763
|
-
return operation.interrupt(generator.next());
|
|
764
779
|
},
|
|
765
780
|
return(value) {
|
|
766
781
|
return generator.return(value);
|
|
@@ -804,12 +819,14 @@ var HyperDBConnection = class {
|
|
|
804
819
|
return queryPromise(result, stream.info);
|
|
805
820
|
}
|
|
806
821
|
query(sql, options = {}) {
|
|
807
|
-
const stream = this.
|
|
822
|
+
const stream = this.queryStreamIPC(sql, options);
|
|
808
823
|
const result = (async () => {
|
|
809
|
-
const reader = await stream;
|
|
824
|
+
const reader = await RecordBatchReader.from(stream);
|
|
825
|
+
await reader.open();
|
|
826
|
+
const schema = reader.schema;
|
|
810
827
|
const batches = [];
|
|
811
828
|
for await (const batch of reader) batches.push(batch);
|
|
812
|
-
return new Table(
|
|
829
|
+
return schema ? new Table(schema, batches) : new Table();
|
|
813
830
|
})();
|
|
814
831
|
return queryPromise(result, stream.info);
|
|
815
832
|
}
|
|
@@ -877,7 +894,12 @@ function resolveNodeEnginePath(engineUrl) {
|
|
|
877
894
|
function createNodeClient(options = {}) {
|
|
878
895
|
const workerUrl = options.workerUrl ?? new URL("./node_worker.js", import.meta.url);
|
|
879
896
|
const engineUrl = options.engineUrl ?? resolveNodeEnginePath(new URL("./hyperdb-wasm.cjs", import.meta.url));
|
|
880
|
-
|
|
897
|
+
const worker = new NativeWorker(workerUrl, {
|
|
898
|
+
workerData: { engineUrl, storagePath: options.storagePath },
|
|
899
|
+
stdout: true
|
|
900
|
+
});
|
|
901
|
+
worker.stdout.resume();
|
|
902
|
+
return new HyperDBEngineClient(new NodeWorker(worker), void 0, options.onLog);
|
|
881
903
|
}
|
|
882
904
|
|
|
883
905
|
// src/index.node.ts
|
package/dist/node_worker.js
CHANGED
|
@@ -477,11 +477,11 @@ function installHttpRuntime(module2, transport2) {
|
|
|
477
477
|
try {
|
|
478
478
|
completeFetch(id, allocate(module2, bytes), bytes.byteLength);
|
|
479
479
|
} catch (error) {
|
|
480
|
-
transport2.postMessage({ type: "log", text: `fetch failed: ${errorText(error)}` });
|
|
480
|
+
transport2.postMessage({ type: "log", stream: "stderr", text: `fetch failed: ${errorText(error)}` });
|
|
481
481
|
completeFetch(id, 0, -1);
|
|
482
482
|
}
|
|
483
483
|
}).catch(() => {
|
|
484
|
-
transport2.postMessage({ type: "log", text: "fetch failed" });
|
|
484
|
+
transport2.postMessage({ type: "log", stream: "stderr", text: "fetch failed" });
|
|
485
485
|
completeFetch(id, 0, -1);
|
|
486
486
|
});
|
|
487
487
|
};
|
|
@@ -492,7 +492,7 @@ function installExternalDirectoryRuntime(module2, transport2) {
|
|
|
492
492
|
if (!backend) return;
|
|
493
493
|
module2.hyperdbWasmExternalDirectoryReleaseGeneration = (locator, generation) => {
|
|
494
494
|
void Promise.resolve().then(() => backend.releaseGeneration(locator, generation)).catch(() => {
|
|
495
|
-
transport2.postMessage({ type: "log", text: "External directory generation cleanup failed; mount removal will retry" });
|
|
495
|
+
transport2.postMessage({ type: "log", stream: "stderr", text: "External directory generation cleanup failed; mount removal will retry" });
|
|
496
496
|
});
|
|
497
497
|
};
|
|
498
498
|
const listComplete = module2._hyperdb_wasm_external_directory_list_complete;
|
|
@@ -697,8 +697,8 @@ function configureWorker(module2, transport2, configureFilesystem = () => void 0
|
|
|
697
697
|
transport2.onMessage((message) => {
|
|
698
698
|
if (isEngineRequest(message)) handle(message);
|
|
699
699
|
});
|
|
700
|
-
module2.print = (text) => transport2.postMessage({ type: "log", text });
|
|
701
|
-
module2.printErr = (text) => transport2.postMessage({ type: "log", text });
|
|
700
|
+
module2.print = (text) => transport2.postMessage({ type: "log", stream: "stdout", text });
|
|
701
|
+
module2.printErr = (text) => transport2.postMessage({ type: "log", stream: "stderr", text });
|
|
702
702
|
module2.onRuntimeInitialized = () => {
|
|
703
703
|
if (failed) return;
|
|
704
704
|
try {
|
|
@@ -1107,6 +1107,17 @@ var enginePort = parentPort;
|
|
|
1107
1107
|
var options = workerData;
|
|
1108
1108
|
var engineUrl = options?.engineUrl ?? fileURLToPath(new URL("./hyperdb-wasm.cjs", import.meta.url));
|
|
1109
1109
|
var storagePath = resolve2(options?.storagePath ?? process.cwd());
|
|
1110
|
+
var storageInfo;
|
|
1111
|
+
try {
|
|
1112
|
+
storageInfo = statSync(storagePath);
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
1115
|
+
if (error.code === "ENOENT") throw new Error(`Node storagePath does not exist: ${storagePath}`, { cause: error });
|
|
1116
|
+
if (error.code === "ENOTDIR") throw new Error(`Node storagePath is not a directory: ${storagePath}`, { cause: error });
|
|
1117
|
+
}
|
|
1118
|
+
throw new Error(`Cannot access Node storagePath: ${storagePath}`, { cause: error });
|
|
1119
|
+
}
|
|
1120
|
+
if (!storageInfo.isDirectory()) throw new Error(`Node storagePath is not a directory: ${storagePath}`);
|
|
1110
1121
|
var transport = {
|
|
1111
1122
|
postMessage: (message, transfer = []) => enginePort.postMessage(message, [...transfer]),
|
|
1112
1123
|
onMessage: (listener) => enginePort.on("message", listener)
|
|
@@ -1117,6 +1128,9 @@ var compiledWasm = await WebAssembly.compileStreaming(new Response(decompressedW
|
|
|
1117
1128
|
headers: { "Content-Type": "application/wasm" }
|
|
1118
1129
|
}));
|
|
1119
1130
|
var moduleConfiguration = {
|
|
1131
|
+
// Emscripten captures these callbacks while loading; its Node fallback writes directly to host fds
|
|
1132
|
+
print: (text) => transport.postMessage({ type: "log", stream: "stdout", text }),
|
|
1133
|
+
printErr: (text) => transport.postMessage({ type: "log", stream: "stderr", text }),
|
|
1120
1134
|
instantiateWasm: (imports, receiveInstance) => {
|
|
1121
1135
|
void WebAssembly.instantiate(compiledWasm, imports).then((instance) => receiveInstance(instance, compiledWasm));
|
|
1122
1136
|
return {};
|
package/dist/protocol.d.ts
CHANGED
package/dist/raw.browser.js
CHANGED
|
@@ -37,7 +37,7 @@ function isWorkerEvent(message) {
|
|
|
37
37
|
case "fatal":
|
|
38
38
|
return hasKeys(message, ["type", "error"]) && typeof message.error === "string";
|
|
39
39
|
case "log":
|
|
40
|
-
return hasKeys(message, ["type", "text"]) && typeof message.text === "string";
|
|
40
|
+
return hasKeys(message, ["type", "stream", "text"]) && (message.stream === "stdout" || message.stream === "stderr") && typeof message.text === "string";
|
|
41
41
|
case "response":
|
|
42
42
|
return hasKeys(message, ["id", "type", "result"]) && Number.isSafeInteger(message.id) && isWasmResult(message.result);
|
|
43
43
|
default:
|
|
@@ -47,8 +47,9 @@ function isWorkerEvent(message) {
|
|
|
47
47
|
|
|
48
48
|
// src/client.ts
|
|
49
49
|
var HyperDBEngineClient = class {
|
|
50
|
-
constructor(transport, onSetupProgress) {
|
|
50
|
+
constructor(transport, onSetupProgress, onLog) {
|
|
51
51
|
this.onSetupProgress = onSetupProgress;
|
|
52
|
+
this.onLog = onLog;
|
|
52
53
|
this.transport = transport;
|
|
53
54
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
54
55
|
this.resolveReady = resolve;
|
|
@@ -61,6 +62,7 @@ var HyperDBEngineClient = class {
|
|
|
61
62
|
];
|
|
62
63
|
}
|
|
63
64
|
onSetupProgress;
|
|
65
|
+
onLog;
|
|
64
66
|
transport;
|
|
65
67
|
pending = /* @__PURE__ */ new Map();
|
|
66
68
|
readyPromise;
|
|
@@ -142,6 +144,13 @@ var HyperDBEngineClient = class {
|
|
|
142
144
|
this.onSetupProgress?.({ bytesLoaded: message.bytesLoaded, bytesTotal: message.bytesTotal });
|
|
143
145
|
return;
|
|
144
146
|
}
|
|
147
|
+
if (message.type === "log") {
|
|
148
|
+
try {
|
|
149
|
+
this.onLog?.(message.stream, message.text);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
145
154
|
if (message.type === "fatal") {
|
|
146
155
|
this.failAndTerminate(new Error(message.error || "engine aborted"));
|
|
147
156
|
return;
|
|
@@ -568,7 +577,8 @@ function createBrowserClient(options = {}) {
|
|
|
568
577
|
const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
|
|
569
578
|
return new HyperDBEngineClient(
|
|
570
579
|
new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl, options.storagePath), { type: "classic" })),
|
|
571
|
-
options.onSetupProgress
|
|
580
|
+
options.onSetupProgress,
|
|
581
|
+
options.onLog
|
|
572
582
|
);
|
|
573
583
|
}
|
|
574
584
|
export {
|
package/dist/raw.node.js
CHANGED
|
@@ -37,7 +37,7 @@ function isWorkerEvent(message) {
|
|
|
37
37
|
case "fatal":
|
|
38
38
|
return hasKeys(message, ["type", "error"]) && typeof message.error === "string";
|
|
39
39
|
case "log":
|
|
40
|
-
return hasKeys(message, ["type", "text"]) && typeof message.text === "string";
|
|
40
|
+
return hasKeys(message, ["type", "stream", "text"]) && (message.stream === "stdout" || message.stream === "stderr") && typeof message.text === "string";
|
|
41
41
|
case "response":
|
|
42
42
|
return hasKeys(message, ["id", "type", "result"]) && Number.isSafeInteger(message.id) && isWasmResult(message.result);
|
|
43
43
|
default:
|
|
@@ -47,8 +47,9 @@ function isWorkerEvent(message) {
|
|
|
47
47
|
|
|
48
48
|
// src/client.ts
|
|
49
49
|
var HyperDBEngineClient = class {
|
|
50
|
-
constructor(transport, onSetupProgress) {
|
|
50
|
+
constructor(transport, onSetupProgress, onLog) {
|
|
51
51
|
this.onSetupProgress = onSetupProgress;
|
|
52
|
+
this.onLog = onLog;
|
|
52
53
|
this.transport = transport;
|
|
53
54
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
54
55
|
this.resolveReady = resolve;
|
|
@@ -61,6 +62,7 @@ var HyperDBEngineClient = class {
|
|
|
61
62
|
];
|
|
62
63
|
}
|
|
63
64
|
onSetupProgress;
|
|
65
|
+
onLog;
|
|
64
66
|
transport;
|
|
65
67
|
pending = /* @__PURE__ */ new Map();
|
|
66
68
|
readyPromise;
|
|
@@ -142,6 +144,13 @@ var HyperDBEngineClient = class {
|
|
|
142
144
|
this.onSetupProgress?.({ bytesLoaded: message.bytesLoaded, bytesTotal: message.bytesTotal });
|
|
143
145
|
return;
|
|
144
146
|
}
|
|
147
|
+
if (message.type === "log") {
|
|
148
|
+
try {
|
|
149
|
+
this.onLog?.(message.stream, message.text);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
145
154
|
if (message.type === "fatal") {
|
|
146
155
|
this.failAndTerminate(new Error(message.error || "engine aborted"));
|
|
147
156
|
return;
|
|
@@ -526,7 +535,12 @@ function resolveNodeEnginePath(engineUrl) {
|
|
|
526
535
|
function createNodeClient(options = {}) {
|
|
527
536
|
const workerUrl = options.workerUrl ?? new URL("./node_worker.js", import.meta.url);
|
|
528
537
|
const engineUrl = options.engineUrl ?? resolveNodeEnginePath(new URL("./hyperdb-wasm.cjs", import.meta.url));
|
|
529
|
-
|
|
538
|
+
const worker = new NativeWorker(workerUrl, {
|
|
539
|
+
workerData: { engineUrl, storagePath: options.storagePath },
|
|
540
|
+
stdout: true
|
|
541
|
+
});
|
|
542
|
+
worker.stdout.resume();
|
|
543
|
+
return new HyperDBEngineClient(new NodeWorker(worker), void 0, options.onLog);
|
|
530
544
|
}
|
|
531
545
|
export {
|
|
532
546
|
HyperDBBindings,
|