hyperdb-wasm 0.0.27104-dev.wasm.g5798514d → 0.0.27106-dev.wasm.g22442c48
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/api.d.ts +7 -3
- package/dist/browser.js +5 -7
- package/dist/browser_worker.js +50 -34
- package/dist/client.d.ts +3 -3
- package/dist/hyperdb-wasm.cjs +1 -1
- package/dist/hyperdb-wasm.js +1 -1
- package/dist/hyperdb-wasm.wasm.br +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/node.js +5 -7
- package/dist/node_worker.js +50 -34
- package/dist/protocol.d.ts +3 -2
- package/dist/raw.browser.js +38 -34
- package/dist/raw.node.js +38 -34
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type { MountSource, WasmResult } from './protocol.js';
|
|
|
6
6
|
import type { HyperDBErrorSource } from './protocol.js';
|
|
7
7
|
export interface HyperDBClient {
|
|
8
8
|
ready(): Promise<void>;
|
|
9
|
-
initialize(settings:
|
|
10
|
-
connect(): Promise<WasmResult>;
|
|
9
|
+
initialize(settings: HyperDBSettings): Promise<WasmResult>;
|
|
10
|
+
connect(settings?: ConnectionSettings): Promise<WasmResult>;
|
|
11
11
|
disconnect(connection: number): Promise<WasmResult>;
|
|
12
12
|
startQuery(connection: number, sql: string): Promise<WasmResult>;
|
|
13
13
|
mount(source: MountSource, path: string, mode: MountAccessMode): Promise<WasmResult>;
|
|
@@ -35,6 +35,10 @@ export type HyperDBSettingValue = string | number | boolean | null | readonly Hy
|
|
|
35
35
|
readonly [key: string]: HyperDBSettingValue;
|
|
36
36
|
};
|
|
37
37
|
export type HyperDBSettings = Readonly<Record<string, HyperDBSettingValue>>;
|
|
38
|
+
export type ConnectionSettings = Readonly<Record<string, string>>;
|
|
39
|
+
export interface HyperDBConnectOptions {
|
|
40
|
+
readonly settings?: ConnectionSettings;
|
|
41
|
+
}
|
|
38
42
|
export interface HyperDBCreateOptions {
|
|
39
43
|
readonly settings?: HyperDBSettings;
|
|
40
44
|
}
|
|
@@ -92,7 +96,7 @@ export declare class HyperDB {
|
|
|
92
96
|
constructor(client: HyperDBClient);
|
|
93
97
|
static create(options?: BrowserCreateOptions): Promise<HyperDB>;
|
|
94
98
|
ready(): Promise<void>;
|
|
95
|
-
connect(): Promise<HyperDBConnection>;
|
|
99
|
+
connect(options?: HyperDBConnectOptions): Promise<HyperDBConnection>;
|
|
96
100
|
protected mountSource(source: MountSource, path: string, mode: MountAccessMode, cleanup?: () => void): Promise<MountedResource>;
|
|
97
101
|
terminate(): Promise<void>;
|
|
98
102
|
private ensureRunning;
|
package/dist/browser.js
CHANGED
|
@@ -100,8 +100,8 @@ var init_client = __esm({
|
|
|
100
100
|
initialize(settings) {
|
|
101
101
|
return this.request({ id: this.nextId++, type: "initialize", settings });
|
|
102
102
|
}
|
|
103
|
-
connect() {
|
|
104
|
-
return this.request({ id: this.nextId++, type: "connect" });
|
|
103
|
+
connect(settings = {}) {
|
|
104
|
+
return this.request({ id: this.nextId++, type: "connect", settings });
|
|
105
105
|
}
|
|
106
106
|
disconnect(connection) {
|
|
107
107
|
return this.request({ id: this.nextId++, type: "disconnect", connection });
|
|
@@ -380,9 +380,7 @@ function expectOk(result, operation) {
|
|
|
380
380
|
if (result.state !== "ok") throw readErrorFromResult(result, operation);
|
|
381
381
|
}
|
|
382
382
|
async function initializeHyperDB(client, settings) {
|
|
383
|
-
|
|
384
|
-
if (serialized === void 0) throw new Error("HyperDB settings must be JSON-serializable");
|
|
385
|
-
expectOk(await client.initialize(serialized), "initialize HyperDB settings");
|
|
383
|
+
expectOk(await client.initialize(settings ?? {}), "initialize HyperDB settings");
|
|
386
384
|
}
|
|
387
385
|
function yieldToEventLoop() {
|
|
388
386
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -566,9 +564,9 @@ var HyperDB = class _HyperDB {
|
|
|
566
564
|
this.ensureRunning();
|
|
567
565
|
return this.client.ready();
|
|
568
566
|
}
|
|
569
|
-
async connect() {
|
|
567
|
+
async connect(options = {}) {
|
|
570
568
|
this.ensureRunning();
|
|
571
|
-
const connection = readHandleFromResult(await this.client.connect(), "connect");
|
|
569
|
+
const connection = readHandleFromResult(await this.client.connect(options.settings), "connect");
|
|
572
570
|
const result = new HyperDBConnection(this.client, connection, () => this.connections.delete(result));
|
|
573
571
|
this.connections.add(result);
|
|
574
572
|
return result;
|
package/dist/browser_worker.js
CHANGED
|
@@ -73,19 +73,19 @@
|
|
|
73
73
|
mountedPaths = /* @__PURE__ */ new Set();
|
|
74
74
|
constructor(module) {
|
|
75
75
|
this.module = module;
|
|
76
|
-
this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string"]);
|
|
77
|
-
this.connect = module.cwrap("hyperdb_wasm_connect", "pointer", []);
|
|
78
|
-
this.disconnect = module.cwrap("hyperdb_wasm_disconnect", "pointer", ["number"]);
|
|
79
|
-
this.shutdown = module.cwrap("hyperdb_wasm_shutdown", "pointer", []);
|
|
80
|
-
this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number"]);
|
|
81
|
-
this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number"]);
|
|
82
|
-
this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string"]);
|
|
83
|
-
this.projectExternalFile = module.cwrap("hyperdb_wasm_project_external_file", "pointer", ["string", "string", "number"]);
|
|
84
|
-
this.projectExternalDirectory = module.cwrap("hyperdb_wasm_project_external_directory", "pointer", ["string", "string"]);
|
|
85
|
-
this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number"]);
|
|
86
|
-
this.pollQuery = module.cwrap("hyperdb_wasm_query_poll", "pointer", ["number"]);
|
|
87
|
-
this.cancelQuery = module.cwrap("hyperdb_wasm_query_cancel", "pointer", ["number"]);
|
|
88
|
-
this.finishQuery = module.cwrap("hyperdb_wasm_query_finish", "pointer", ["number"]);
|
|
76
|
+
this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string", "number"]);
|
|
77
|
+
this.connect = module.cwrap("hyperdb_wasm_connect", "pointer", ["string", "number"]);
|
|
78
|
+
this.disconnect = module.cwrap("hyperdb_wasm_disconnect", "pointer", ["number", "number"]);
|
|
79
|
+
this.shutdown = module.cwrap("hyperdb_wasm_shutdown", "pointer", ["number"]);
|
|
80
|
+
this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number", "number"]);
|
|
81
|
+
this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number", "number"]);
|
|
82
|
+
this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string", "number"]);
|
|
83
|
+
this.projectExternalFile = module.cwrap("hyperdb_wasm_project_external_file", "pointer", ["string", "string", "number", "number"]);
|
|
84
|
+
this.projectExternalDirectory = module.cwrap("hyperdb_wasm_project_external_directory", "pointer", ["string", "string", "number"]);
|
|
85
|
+
this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number", "number"]);
|
|
86
|
+
this.pollQuery = module.cwrap("hyperdb_wasm_query_poll", "pointer", ["number", "number"]);
|
|
87
|
+
this.cancelQuery = module.cwrap("hyperdb_wasm_query_cancel", "pointer", ["number", "number"]);
|
|
88
|
+
this.finishQuery = module.cwrap("hyperdb_wasm_query_finish", "pointer", ["number", "number"]);
|
|
89
89
|
this.resultState = module.cwrap("hyperdb_wasm_result_state", "number", ["number"]);
|
|
90
90
|
this.resultPayloadLength = module.cwrap("hyperdb_wasm_result_payload_len", "number", ["number"]);
|
|
91
91
|
this.free = module.cwrap("hyperdb_wasm_free", null, ["pointer"]);
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
}
|
|
111
111
|
if (request.type === "unmount" && (this.module.externalFileBackend || this.module.externalDirectoryBackend)) {
|
|
112
112
|
validateCString(request.path, "external registration path");
|
|
113
|
-
const pointer2 = safeInteger(this.removeExternalRegistration(request.path), "result pointer");
|
|
113
|
+
const pointer2 = safeInteger(this.removeExternalRegistration(request.path, request.id), "result pointer");
|
|
114
114
|
const result2 = this.decodeResult(pointer2);
|
|
115
115
|
if (result2.state === "ok" || result2.state === "error" && result2.error === "External registration was not found" && this.mountedPaths.has(request.path)) {
|
|
116
116
|
const cleanup = async () => {
|
|
@@ -146,29 +146,33 @@
|
|
|
146
146
|
invoke(request) {
|
|
147
147
|
switch (request.type) {
|
|
148
148
|
case "initialize":
|
|
149
|
-
|
|
149
|
+
const settings = JSON.stringify(request.settings);
|
|
150
|
+
validateCString(settings, "settings");
|
|
150
151
|
validateCStringContents(this.module.hyperdbWasmStoragePath ?? "", "storage path");
|
|
151
|
-
return this.initialize(
|
|
152
|
-
case "connect":
|
|
153
|
-
|
|
152
|
+
return this.initialize(settings, this.module.hyperdbWasmStoragePath ?? "", request.id);
|
|
153
|
+
case "connect": {
|
|
154
|
+
const connectionSettings = JSON.stringify(request.settings);
|
|
155
|
+
validateCString(connectionSettings, "connection settings");
|
|
156
|
+
return this.connect(connectionSettings, request.id);
|
|
157
|
+
}
|
|
154
158
|
case "disconnect":
|
|
155
|
-
return this.disconnect(request.connection);
|
|
159
|
+
return this.disconnect(request.connection, request.id);
|
|
156
160
|
case "shutdown":
|
|
157
|
-
return this.shutdown();
|
|
161
|
+
return this.shutdown(request.id);
|
|
158
162
|
case "mount":
|
|
159
163
|
throw new Error("mount request has no backend");
|
|
160
164
|
case "unmount":
|
|
161
165
|
validateCString(request.path, "external registration path");
|
|
162
|
-
return this.removeExternalRegistration(request.path);
|
|
166
|
+
return this.removeExternalRegistration(request.path, request.id);
|
|
163
167
|
case "startQuery":
|
|
164
168
|
validateCStringContents(request.sql, "SQL");
|
|
165
|
-
return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false));
|
|
169
|
+
return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false), request.id);
|
|
166
170
|
case "pollQuery":
|
|
167
|
-
return this.pollQuery(request.query);
|
|
171
|
+
return this.pollQuery(request.query, request.id);
|
|
168
172
|
case "cancelQuery":
|
|
169
|
-
return this.cancelQuery(request.query);
|
|
173
|
+
return this.cancelQuery(request.query, request.id);
|
|
170
174
|
case "finishQuery":
|
|
171
|
-
return this.finishQuery(request.query);
|
|
175
|
+
return this.finishQuery(request.query, request.id);
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
mountFile(request, locator, size, backend) {
|
|
@@ -178,13 +182,13 @@
|
|
|
178
182
|
let registered = false;
|
|
179
183
|
let rollbackError;
|
|
180
184
|
try {
|
|
181
|
-
const result = this.decodeResult(safeInteger(this.registerExternalFile(request.path, locator, size), "result pointer"));
|
|
185
|
+
const result = this.decodeResult(safeInteger(this.registerExternalFile(request.path, locator, size, request.id), "result pointer"));
|
|
182
186
|
if (result.state !== "ok") {
|
|
183
187
|
backend?.removed(locator);
|
|
184
188
|
return { response: { id: request.id, type: "response", result }, transfer: [] };
|
|
185
189
|
}
|
|
186
190
|
path = new TextDecoder("utf-8", { fatal: true }).decode(result.payload);
|
|
187
|
-
const projection = this.decodeResult(safeInteger(this.projectExternalFile(path, locator, size), "result pointer"));
|
|
191
|
+
const projection = this.decodeResult(safeInteger(this.projectExternalFile(path, locator, size, request.id), "result pointer"));
|
|
188
192
|
if (projection.state !== "ok") throw new Error(resultError(projection));
|
|
189
193
|
backend?.registered(path, locator);
|
|
190
194
|
registered = true;
|
|
@@ -193,7 +197,7 @@
|
|
|
193
197
|
} catch (error) {
|
|
194
198
|
if (path !== void 0) {
|
|
195
199
|
try {
|
|
196
|
-
const rollback = this.decodeResult(safeInteger(this.removeExternalRegistration(path), "result pointer"));
|
|
200
|
+
const rollback = this.decodeResult(safeInteger(this.removeExternalRegistration(path, request.id), "result pointer"));
|
|
197
201
|
if (rollback.state !== "ok") rollbackError = new Error(resultError(rollback));
|
|
198
202
|
} catch (failure) {
|
|
199
203
|
rollbackError = failure;
|
|
@@ -220,18 +224,18 @@
|
|
|
220
224
|
let preserveBackend = false;
|
|
221
225
|
try {
|
|
222
226
|
validateCString(registration.locator, "external directory locator");
|
|
223
|
-
const pointer = safeInteger(this.registerExternalDirectory(request.path, registration.locator, Number(request.mode === "readwrite")), "result pointer");
|
|
227
|
+
const pointer = safeInteger(this.registerExternalDirectory(request.path, registration.locator, Number(request.mode === "readwrite"), request.id), "result pointer");
|
|
224
228
|
const result = this.decodeResult(pointer);
|
|
225
229
|
if (result.state === "ok") {
|
|
226
230
|
const path = new TextDecoder("utf-8", { fatal: true }).decode(result.payload);
|
|
227
231
|
try {
|
|
228
|
-
const projectionPointer = this.projectExternalDirectory(path, registration.locator);
|
|
232
|
+
const projectionPointer = this.projectExternalDirectory(path, registration.locator, request.id);
|
|
229
233
|
const projection = this.decodeResult(safeInteger(projectionPointer, "result pointer"));
|
|
230
234
|
if (projection.state !== "ok") throw new Error(resultError(projection));
|
|
231
235
|
backend.registered(path, registration.locator);
|
|
232
236
|
this.mountedPaths.add(path);
|
|
233
237
|
} catch (error) {
|
|
234
|
-
const cleanupPointer = safeInteger(this.removeExternalRegistration(path), "result pointer");
|
|
238
|
+
const cleanupPointer = safeInteger(this.removeExternalRegistration(path, request.id), "result pointer");
|
|
235
239
|
const cleanup = this.decodeResult(cleanupPointer);
|
|
236
240
|
if (cleanup.state !== "ok") {
|
|
237
241
|
backend.registered(path, registration.locator);
|
|
@@ -256,8 +260,8 @@
|
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
262
|
decodeResult(pointer) {
|
|
259
|
-
if (pointer === 0) return { state: "error", error: "out of memory" };
|
|
260
263
|
try {
|
|
264
|
+
if (pointer === 0) return { state: "error", error: "out of memory" };
|
|
261
265
|
const rawState = safeInteger(this.resultState(pointer), "result state");
|
|
262
266
|
const state = resultStates[rawState];
|
|
263
267
|
if (!state) return { state: "error", error: `invalid result state ${rawState}` };
|
|
@@ -300,13 +304,25 @@
|
|
|
300
304
|
const expected = [...keys].sort();
|
|
301
305
|
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
302
306
|
}
|
|
307
|
+
function isConnectionSettings(value) {
|
|
308
|
+
return isRecord(value) && Object.values(value).every((setting) => typeof setting === "string");
|
|
309
|
+
}
|
|
310
|
+
function isHyperDBSettingValue(value) {
|
|
311
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
312
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
313
|
+
if (Array.isArray(value)) return value.every(isHyperDBSettingValue);
|
|
314
|
+
return isRecord(value) && Object.values(value).every(isHyperDBSettingValue);
|
|
315
|
+
}
|
|
316
|
+
function isHyperDBSettings(value) {
|
|
317
|
+
return isRecord(value) && Object.values(value).every(isHyperDBSettingValue);
|
|
318
|
+
}
|
|
303
319
|
function isEngineRequest(value) {
|
|
304
320
|
if (!isRecord(value) || !Number.isSafeInteger(value.id) || typeof value.type !== "string") return false;
|
|
305
321
|
switch (value.type) {
|
|
306
322
|
case "initialize":
|
|
307
|
-
return hasKeys(value, ["id", "type", "settings"]) &&
|
|
323
|
+
return hasKeys(value, ["id", "type", "settings"]) && isHyperDBSettings(value.settings);
|
|
308
324
|
case "connect":
|
|
309
|
-
return hasKeys(value, ["id", "type"]);
|
|
325
|
+
return hasKeys(value, ["id", "type", "settings"]) && isConnectionSettings(value.settings);
|
|
310
326
|
case "disconnect":
|
|
311
327
|
return hasKeys(value, ["id", "type", "connection"]) && Number.isSafeInteger(value.connection);
|
|
312
328
|
case "shutdown":
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MountAccessMode } from './api.js';
|
|
1
|
+
import type { ConnectionSettings, HyperDBSettings, MountAccessMode } from './api.js';
|
|
2
2
|
import type { MountSource, SetupProgress, WasmResult, WorkerTransport } from './protocol.js';
|
|
3
3
|
export declare class HyperDBEngineClient {
|
|
4
4
|
private readonly onSetupProgress?;
|
|
@@ -12,8 +12,8 @@ export declare class HyperDBEngineClient {
|
|
|
12
12
|
private readonly unsubscribe;
|
|
13
13
|
constructor(transport: WorkerTransport, onSetupProgress?: ((progress: SetupProgress) => void) | undefined);
|
|
14
14
|
ready(): Promise<void>;
|
|
15
|
-
initialize(settings:
|
|
16
|
-
connect(): Promise<WasmResult>;
|
|
15
|
+
initialize(settings: HyperDBSettings): Promise<WasmResult>;
|
|
16
|
+
connect(settings?: ConnectionSettings): Promise<WasmResult>;
|
|
17
17
|
disconnect(connection: number): Promise<WasmResult>;
|
|
18
18
|
shutdown(): Promise<WasmResult>;
|
|
19
19
|
startQuery(connection: number, sql: string, sqlTestMode?: boolean): Promise<WasmResult>;
|