hyperdb-wasm 0.0.26281-dev.wasm.g39d82636 → 0.0.26284-dev.wasm.gf1f9d795
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 +14 -2
- package/dist/browser.js +259 -2
- package/dist/browser_worker.js +21 -0
- package/dist/client.d.ts +2 -0
- 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 -0
- package/dist/index.node.d.ts +1 -0
- package/dist/node.js +93 -3
- package/dist/node_worker.js +21 -0
- package/dist/protocol.d.ts +12 -0
- package/dist/raw.browser.js +26 -2
- package/dist/raw.node.js +26 -2
- package/dist/wasm_bindings.d.ts +3 -0
- package/examples/node.mjs +20 -7
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Table } from 'apache-arrow';
|
|
2
|
-
import type { AsyncRecordBatchStreamReader,
|
|
1
|
+
import { DataType, Table } from 'apache-arrow';
|
|
2
|
+
import type { AsyncRecordBatchStreamReader, TypeMap } from 'apache-arrow';
|
|
3
3
|
import type { HyperDBEngineClient } from './client.js';
|
|
4
4
|
import type { BrowserClientOptions } from './browser.js';
|
|
5
5
|
import type { WasmResult } from './protocol.js';
|
|
@@ -8,11 +8,18 @@ export interface HyperDBClient {
|
|
|
8
8
|
connect(): Promise<WasmResult>;
|
|
9
9
|
disconnect(connection: number): Promise<WasmResult>;
|
|
10
10
|
startQuery(connection: number, sql: string): Promise<WasmResult>;
|
|
11
|
+
appendArrowIPC(connection: number, chunk: Uint8Array): Promise<WasmResult>;
|
|
12
|
+
finishArrowIPC(connection: number, name: string, schema: string | null, create: boolean): Promise<WasmResult>;
|
|
11
13
|
pollQuery(query: number): Promise<WasmResult>;
|
|
12
14
|
cancelQuery(query: number): Promise<WasmResult>;
|
|
13
15
|
releaseQuery(query: number): Promise<WasmResult>;
|
|
14
16
|
terminate(): Promise<void>;
|
|
15
17
|
}
|
|
18
|
+
export interface ArrowInsertOptions {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly schema?: string;
|
|
21
|
+
readonly create?: boolean;
|
|
22
|
+
}
|
|
16
23
|
export declare class HyperDB {
|
|
17
24
|
private readonly client;
|
|
18
25
|
private terminated;
|
|
@@ -31,6 +38,8 @@ export declare class HyperDBConnection {
|
|
|
31
38
|
private readonly onClose;
|
|
32
39
|
private closed;
|
|
33
40
|
private active;
|
|
41
|
+
private arrowInsertOptions;
|
|
42
|
+
private appendingArrow;
|
|
34
43
|
private closing;
|
|
35
44
|
constructor(client: HyperDBClient, connection: number, onClose?: () => void);
|
|
36
45
|
close(): Promise<void>;
|
|
@@ -42,6 +51,9 @@ export declare class HyperDBConnection {
|
|
|
42
51
|
query<T extends TypeMap = {
|
|
43
52
|
[key: string]: DataType;
|
|
44
53
|
}>(sql: string): Promise<Table<T>>;
|
|
54
|
+
insertArrowTable(table: Table, options: ArrowInsertOptions): Promise<void>;
|
|
55
|
+
insertArrowFromIPCStream(chunk: Uint8Array, options: ArrowInsertOptions): Promise<void>;
|
|
56
|
+
finishArrowIPCStream(options?: ArrowInsertOptions): Promise<void>;
|
|
45
57
|
private ensureAvailable;
|
|
46
58
|
private release;
|
|
47
59
|
closeForTermination(): Promise<void>;
|
package/dist/browser.js
CHANGED
|
@@ -98,6 +98,13 @@ var init_client = __esm({
|
|
|
98
98
|
startQuery(connection, sql) {
|
|
99
99
|
return this.request({ id: this.nextId++, type: "startQuery", connection, sql });
|
|
100
100
|
}
|
|
101
|
+
appendArrowIPC(connection, chunk) {
|
|
102
|
+
const payload = chunk.slice();
|
|
103
|
+
return this.request({ id: this.nextId++, type: "appendArrowIPC", connection, chunk: payload }, [payload.buffer]);
|
|
104
|
+
}
|
|
105
|
+
finishArrowIPC(connection, name, schema, create) {
|
|
106
|
+
return this.request({ id: this.nextId++, type: "finishArrowIPC", connection, name, schema, create });
|
|
107
|
+
}
|
|
101
108
|
pollQuery(query) {
|
|
102
109
|
return this.request({ id: this.nextId++, type: "pollQuery", query });
|
|
103
110
|
}
|
|
@@ -111,12 +118,12 @@ var init_client = __esm({
|
|
|
111
118
|
this.fail(new Error("engine worker terminated"));
|
|
112
119
|
await this.transport.terminate();
|
|
113
120
|
}
|
|
114
|
-
request(request) {
|
|
121
|
+
request(request, transfer = []) {
|
|
115
122
|
if (this.failed) return Promise.reject(this.failed);
|
|
116
123
|
return new Promise((resolve, reject) => {
|
|
117
124
|
this.pending.set(request.id, { resolve, reject });
|
|
118
125
|
try {
|
|
119
|
-
this.transport.postMessage(request);
|
|
126
|
+
this.transport.postMessage(request, transfer);
|
|
120
127
|
} catch (error) {
|
|
121
128
|
this.pending.delete(request.id);
|
|
122
129
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -3858,6 +3865,11 @@ Timestamp_[_o] = ((proto) => {
|
|
|
3858
3865
|
proto.ArrayType = BigInt64Array;
|
|
3859
3866
|
return proto[Symbol.toStringTag] = "Timestamp";
|
|
3860
3867
|
})(Timestamp_.prototype);
|
|
3868
|
+
var TimestampMillisecond = class extends Timestamp_ {
|
|
3869
|
+
constructor(timezone) {
|
|
3870
|
+
super(TimeUnit.MILLISECOND, timezone);
|
|
3871
|
+
}
|
|
3872
|
+
};
|
|
3861
3873
|
var Interval_ = class extends DataType {
|
|
3862
3874
|
constructor(unit) {
|
|
3863
3875
|
super(Type2.Interval);
|
|
@@ -6397,6 +6409,63 @@ var MemoizedVector = class _MemoizedVector extends Vector {
|
|
|
6397
6409
|
});
|
|
6398
6410
|
}
|
|
6399
6411
|
};
|
|
6412
|
+
function makeVector(init) {
|
|
6413
|
+
if (init) {
|
|
6414
|
+
if (init instanceof Data) {
|
|
6415
|
+
return new Vector([init]);
|
|
6416
|
+
}
|
|
6417
|
+
if (init instanceof Vector) {
|
|
6418
|
+
return new Vector(init.data);
|
|
6419
|
+
}
|
|
6420
|
+
if (init.type instanceof DataType) {
|
|
6421
|
+
return new Vector([makeData(init)]);
|
|
6422
|
+
}
|
|
6423
|
+
if (Array.isArray(init)) {
|
|
6424
|
+
return new Vector(init.flatMap((v) => unwrapInputs(v)));
|
|
6425
|
+
}
|
|
6426
|
+
if (ArrayBuffer.isView(init)) {
|
|
6427
|
+
if (init instanceof DataView) {
|
|
6428
|
+
init = new Uint8Array(init.buffer);
|
|
6429
|
+
}
|
|
6430
|
+
const props = { offset: 0, length: init.length, nullCount: -1, data: init };
|
|
6431
|
+
if (init instanceof Int8Array) {
|
|
6432
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int8() }))]);
|
|
6433
|
+
}
|
|
6434
|
+
if (init instanceof Int16Array) {
|
|
6435
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int16() }))]);
|
|
6436
|
+
}
|
|
6437
|
+
if (init instanceof Int32Array) {
|
|
6438
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int32() }))]);
|
|
6439
|
+
}
|
|
6440
|
+
if (init instanceof BigInt64Array) {
|
|
6441
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int64() }))]);
|
|
6442
|
+
}
|
|
6443
|
+
if (init instanceof Uint8Array || init instanceof Uint8ClampedArray) {
|
|
6444
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint8() }))]);
|
|
6445
|
+
}
|
|
6446
|
+
if (init instanceof Uint16Array) {
|
|
6447
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint16() }))]);
|
|
6448
|
+
}
|
|
6449
|
+
if (init instanceof Uint32Array) {
|
|
6450
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint32() }))]);
|
|
6451
|
+
}
|
|
6452
|
+
if (init instanceof BigUint64Array) {
|
|
6453
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint64() }))]);
|
|
6454
|
+
}
|
|
6455
|
+
if (init instanceof Float32Array) {
|
|
6456
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Float32() }))]);
|
|
6457
|
+
}
|
|
6458
|
+
if (init instanceof Float64Array) {
|
|
6459
|
+
return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Float64() }))]);
|
|
6460
|
+
}
|
|
6461
|
+
throw new Error("Unrecognized input");
|
|
6462
|
+
}
|
|
6463
|
+
}
|
|
6464
|
+
throw new Error("Unrecognized input");
|
|
6465
|
+
}
|
|
6466
|
+
function unwrapInputs(x) {
|
|
6467
|
+
return x instanceof Data ? [x] : x instanceof Vector ? x.data : makeVector(x).data;
|
|
6468
|
+
}
|
|
6400
6469
|
|
|
6401
6470
|
// ../node_modules/apache-arrow/builder/valid.mjs
|
|
6402
6471
|
function createIsValidFunction(nullValues) {
|
|
@@ -8872,6 +8941,106 @@ function makeBuilder(options) {
|
|
|
8872
8941
|
}
|
|
8873
8942
|
return builder;
|
|
8874
8943
|
}
|
|
8944
|
+
function vectorFromArray(init, type) {
|
|
8945
|
+
if (init instanceof Data || init instanceof Vector || init.type instanceof DataType || ArrayBuffer.isView(init)) {
|
|
8946
|
+
return makeVector(init);
|
|
8947
|
+
}
|
|
8948
|
+
const options = { type: type !== null && type !== void 0 ? type : inferType(init), nullValues: [null] };
|
|
8949
|
+
const chunks = [...builderThroughIterable(options)(init)];
|
|
8950
|
+
const vector = chunks.length === 1 ? chunks[0] : chunks.reduce((a, b) => a.concat(b));
|
|
8951
|
+
if (DataType.isDictionary(vector.type)) {
|
|
8952
|
+
return vector.memoize();
|
|
8953
|
+
}
|
|
8954
|
+
return vector;
|
|
8955
|
+
}
|
|
8956
|
+
function inferType(value) {
|
|
8957
|
+
if (value.length === 0) {
|
|
8958
|
+
return new Null2();
|
|
8959
|
+
}
|
|
8960
|
+
let nullsCount = 0;
|
|
8961
|
+
let arraysCount = 0;
|
|
8962
|
+
let objectsCount = 0;
|
|
8963
|
+
let numbersCount = 0;
|
|
8964
|
+
let stringsCount = 0;
|
|
8965
|
+
let bigintsCount = 0;
|
|
8966
|
+
let booleansCount = 0;
|
|
8967
|
+
let datesCount = 0;
|
|
8968
|
+
for (const val of value) {
|
|
8969
|
+
if (val == null) {
|
|
8970
|
+
++nullsCount;
|
|
8971
|
+
continue;
|
|
8972
|
+
}
|
|
8973
|
+
switch (typeof val) {
|
|
8974
|
+
case "bigint":
|
|
8975
|
+
++bigintsCount;
|
|
8976
|
+
continue;
|
|
8977
|
+
case "boolean":
|
|
8978
|
+
++booleansCount;
|
|
8979
|
+
continue;
|
|
8980
|
+
case "number":
|
|
8981
|
+
++numbersCount;
|
|
8982
|
+
continue;
|
|
8983
|
+
case "string":
|
|
8984
|
+
++stringsCount;
|
|
8985
|
+
continue;
|
|
8986
|
+
case "object":
|
|
8987
|
+
if (Array.isArray(val)) {
|
|
8988
|
+
++arraysCount;
|
|
8989
|
+
} else if (Object.prototype.toString.call(val) === "[object Date]") {
|
|
8990
|
+
++datesCount;
|
|
8991
|
+
} else {
|
|
8992
|
+
++objectsCount;
|
|
8993
|
+
}
|
|
8994
|
+
continue;
|
|
8995
|
+
}
|
|
8996
|
+
throw new TypeError("Unable to infer Vector type from input values, explicit type declaration expected.");
|
|
8997
|
+
}
|
|
8998
|
+
if (numbersCount + nullsCount === value.length) {
|
|
8999
|
+
return new Float64();
|
|
9000
|
+
} else if (stringsCount + nullsCount === value.length) {
|
|
9001
|
+
return new Dictionary(new Utf82(), new Int32());
|
|
9002
|
+
} else if (bigintsCount + nullsCount === value.length) {
|
|
9003
|
+
return new Int64();
|
|
9004
|
+
} else if (booleansCount + nullsCount === value.length) {
|
|
9005
|
+
return new Bool2();
|
|
9006
|
+
} else if (datesCount + nullsCount === value.length) {
|
|
9007
|
+
return new TimestampMillisecond();
|
|
9008
|
+
} else if (arraysCount + nullsCount === value.length) {
|
|
9009
|
+
const array = value;
|
|
9010
|
+
const childType = inferType(array[array.findIndex((ary) => ary != null)]);
|
|
9011
|
+
if (array.every((ary) => ary == null || compareTypes(childType, inferType(ary)))) {
|
|
9012
|
+
return new List2(new Field2("", childType, true));
|
|
9013
|
+
}
|
|
9014
|
+
} else if (objectsCount + nullsCount === value.length) {
|
|
9015
|
+
const fields = /* @__PURE__ */ new Map();
|
|
9016
|
+
for (const row of value) {
|
|
9017
|
+
for (const key of Object.keys(row)) {
|
|
9018
|
+
if (!fields.has(key) && row[key] != null) {
|
|
9019
|
+
fields.set(key, new Field2(key, inferType([row[key]]), true));
|
|
9020
|
+
}
|
|
9021
|
+
}
|
|
9022
|
+
}
|
|
9023
|
+
return new Struct([...fields.values()]);
|
|
9024
|
+
}
|
|
9025
|
+
throw new TypeError("Unable to infer Vector type from input values, explicit type declaration expected.");
|
|
9026
|
+
}
|
|
9027
|
+
function builderThroughIterable(options) {
|
|
9028
|
+
const { ["queueingStrategy"]: queueingStrategy = "count" } = options;
|
|
9029
|
+
const { ["highWaterMark"]: highWaterMark = queueingStrategy !== "bytes" ? Number.POSITIVE_INFINITY : Math.pow(2, 14) } = options;
|
|
9030
|
+
const sizeProperty = queueingStrategy !== "bytes" ? "length" : "byteLength";
|
|
9031
|
+
return function* (source) {
|
|
9032
|
+
let numChunks = 0;
|
|
9033
|
+
const builder = makeBuilder(options);
|
|
9034
|
+
for (const value of source) {
|
|
9035
|
+
if (builder.append(value)[sizeProperty] >= highWaterMark) {
|
|
9036
|
+
++numChunks && (yield builder.toVector());
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
if (builder.finish().length > 0 || numChunks === 0) {
|
|
9040
|
+
yield builder.toVector();
|
|
9041
|
+
}
|
|
9042
|
+
};
|
|
9043
|
+
}
|
|
8875
9044
|
|
|
8876
9045
|
// ../node_modules/apache-arrow/util/recordbatch.mjs
|
|
8877
9046
|
function distributeVectorsIntoRecordBatches(schema, vecs) {
|
|
@@ -11858,6 +12027,11 @@ function recordBatchWriterThroughDOMStream(writableStrategy, readableStrategy) {
|
|
|
11858
12027
|
}
|
|
11859
12028
|
}
|
|
11860
12029
|
|
|
12030
|
+
// ../node_modules/apache-arrow/ipc/serialization.mjs
|
|
12031
|
+
function tableToIPC(table, type = "stream") {
|
|
12032
|
+
return (type === "stream" ? RecordBatchStreamWriter : RecordBatchFileWriter).writeAll(table).toUint8Array(true);
|
|
12033
|
+
}
|
|
12034
|
+
|
|
11861
12035
|
// ../node_modules/apache-arrow/Arrow.mjs
|
|
11862
12036
|
var util = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bn_exports), int_exports), bit_exports), math_exports), buffer_exports), vector_exports), pretty_exports), {
|
|
11863
12037
|
compareSchemas,
|
|
@@ -11876,6 +12050,31 @@ RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
|
|
|
11876
12050
|
RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
|
|
11877
12051
|
|
|
11878
12052
|
// api.ts
|
|
12053
|
+
function normalizeArrowInsertOptions(options) {
|
|
12054
|
+
if (!options.name) throw new Error("Arrow insert table name must not be empty");
|
|
12055
|
+
return { name: options.name, schema: options.schema ?? null, create: options.create ?? true };
|
|
12056
|
+
}
|
|
12057
|
+
function equalArrowInsertOptions(left, right) {
|
|
12058
|
+
return left.name === right.name && left.schema === right.schema && left.create === right.create;
|
|
12059
|
+
}
|
|
12060
|
+
function materializeDictionaryColumns(table) {
|
|
12061
|
+
const dictionaryColumns = table.schema.fields.map((field, index) => DataType.isDictionary(field.type) ? index : -1).filter((index) => index !== -1);
|
|
12062
|
+
if (dictionaryColumns.length === 0) return table;
|
|
12063
|
+
const fields = table.schema.fields.map((field) => DataType.isDictionary(field.type) ? field.clone({ type: field.type.dictionary }) : field);
|
|
12064
|
+
const batches = table.batches.map((batch) => {
|
|
12065
|
+
let result = batch;
|
|
12066
|
+
for (const index of dictionaryColumns) {
|
|
12067
|
+
const column = result.getChildAt(index);
|
|
12068
|
+
const sourceField = table.schema.fields[index];
|
|
12069
|
+
if (!column || !sourceField) throw new Error(`Arrow table is missing column ${index}`);
|
|
12070
|
+
const type = sourceField.type;
|
|
12071
|
+
const materialized = vectorFromArray([...column], type.dictionary);
|
|
12072
|
+
result = result.setChildAt(index, materialized);
|
|
12073
|
+
}
|
|
12074
|
+
return result;
|
|
12075
|
+
});
|
|
12076
|
+
return new Table(new Schema2(fields, table.schema.metadata, null, table.schema.metadataVersion), batches);
|
|
12077
|
+
}
|
|
11879
12078
|
function readHandleFromResult(result, operation) {
|
|
11880
12079
|
if (result.state !== "ok") throw readErrorFromResult(result, operation);
|
|
11881
12080
|
if (result.payload.byteLength !== 4) throw new Error(`${operation} returned an invalid handle`);
|
|
@@ -11947,10 +12146,13 @@ var HyperDBConnection = class {
|
|
|
11947
12146
|
onClose;
|
|
11948
12147
|
closed = false;
|
|
11949
12148
|
active = false;
|
|
12149
|
+
arrowInsertOptions;
|
|
12150
|
+
appendingArrow = false;
|
|
11950
12151
|
closing;
|
|
11951
12152
|
async close() {
|
|
11952
12153
|
if (this.closed) return;
|
|
11953
12154
|
if (this.active) throw new Error("connection has an active query");
|
|
12155
|
+
if (this.arrowInsertOptions) throw new Error("connection has an unfinished Arrow IPC stream");
|
|
11954
12156
|
if (!this.closing) {
|
|
11955
12157
|
this.closing = (async () => {
|
|
11956
12158
|
try {
|
|
@@ -12051,6 +12253,60 @@ var HyperDBConnection = class {
|
|
|
12051
12253
|
for await (const batch of reader) batches.push(batch);
|
|
12052
12254
|
return new Table(reader.schema, batches);
|
|
12053
12255
|
}
|
|
12256
|
+
async insertArrowTable(table, options) {
|
|
12257
|
+
await this.insertArrowFromIPCStream(tableToIPC(materializeDictionaryColumns(table), "stream"), options);
|
|
12258
|
+
await this.finishArrowIPCStream();
|
|
12259
|
+
}
|
|
12260
|
+
async insertArrowFromIPCStream(chunk, options) {
|
|
12261
|
+
if (this.closed) throw new Error("connection is closed");
|
|
12262
|
+
if (this.closing) throw new Error("connection is closing");
|
|
12263
|
+
if (this.active) throw new Error("connection has an active query");
|
|
12264
|
+
if (this.appendingArrow) throw new Error("connection is appending Arrow IPC");
|
|
12265
|
+
const normalized = normalizeArrowInsertOptions(options);
|
|
12266
|
+
if (this.arrowInsertOptions && !equalArrowInsertOptions(this.arrowInsertOptions, normalized)) {
|
|
12267
|
+
throw new Error("Arrow insert options must match the pending stream");
|
|
12268
|
+
}
|
|
12269
|
+
this.appendingArrow = true;
|
|
12270
|
+
try {
|
|
12271
|
+
expectOk(await this.client.appendArrowIPC(this.connection, chunk), "append Arrow IPC");
|
|
12272
|
+
this.arrowInsertOptions = normalized;
|
|
12273
|
+
} finally {
|
|
12274
|
+
this.appendingArrow = false;
|
|
12275
|
+
}
|
|
12276
|
+
}
|
|
12277
|
+
async finishArrowIPCStream(options) {
|
|
12278
|
+
if (this.closed) throw new Error("connection is closed");
|
|
12279
|
+
if (this.closing) throw new Error("connection is closing");
|
|
12280
|
+
if (this.active) throw new Error("connection has an active query");
|
|
12281
|
+
if (this.appendingArrow) throw new Error("connection is appending Arrow IPC");
|
|
12282
|
+
const normalized = options ? normalizeArrowInsertOptions(options) : this.arrowInsertOptions;
|
|
12283
|
+
if (!normalized) throw new Error("connection has no Arrow IPC input");
|
|
12284
|
+
if (this.arrowInsertOptions && !equalArrowInsertOptions(this.arrowInsertOptions, normalized)) {
|
|
12285
|
+
throw new Error("Arrow insert options must match the pending stream");
|
|
12286
|
+
}
|
|
12287
|
+
this.active = true;
|
|
12288
|
+
let query;
|
|
12289
|
+
try {
|
|
12290
|
+
query = readHandleFromResult(await this.client.finishArrowIPC(this.connection, normalized.name, normalized.schema, normalized.create), "finish Arrow IPC");
|
|
12291
|
+
this.arrowInsertOptions = void 0;
|
|
12292
|
+
for (; ; ) {
|
|
12293
|
+
let result = await this.client.pollQuery(query);
|
|
12294
|
+
while (result.state === "pending") {
|
|
12295
|
+
await yieldToEventLoop();
|
|
12296
|
+
result = await this.client.pollQuery(query);
|
|
12297
|
+
}
|
|
12298
|
+
if (result.state === "done") return;
|
|
12299
|
+
if (result.state === "chunk") continue;
|
|
12300
|
+
throw readErrorFromResult(result, "finish Arrow IPC");
|
|
12301
|
+
}
|
|
12302
|
+
} finally {
|
|
12303
|
+
try {
|
|
12304
|
+
if (query !== void 0) await this.release(query);
|
|
12305
|
+
} finally {
|
|
12306
|
+
this.active = false;
|
|
12307
|
+
}
|
|
12308
|
+
}
|
|
12309
|
+
}
|
|
12054
12310
|
ensureAvailable() {
|
|
12055
12311
|
if (this.closed) throw new Error("connection is closed");
|
|
12056
12312
|
if (this.closing) throw new Error("connection is closing");
|
|
@@ -12071,6 +12327,7 @@ var HyperDBConnection = class {
|
|
|
12071
12327
|
}
|
|
12072
12328
|
async closeForTermination() {
|
|
12073
12329
|
if (this.active) throw new Error("cannot terminate while a connection has an active query");
|
|
12330
|
+
if (this.arrowInsertOptions) throw new Error("cannot terminate while a connection has an unfinished Arrow IPC stream");
|
|
12074
12331
|
await this.close();
|
|
12075
12332
|
}
|
|
12076
12333
|
};
|
package/dist/browser_worker.js
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
connect;
|
|
13
13
|
disconnect;
|
|
14
14
|
startQuery;
|
|
15
|
+
appendArrowIPC;
|
|
16
|
+
finishArrowIPC;
|
|
15
17
|
pollQuery;
|
|
16
18
|
cancelQuery;
|
|
17
19
|
releaseQuery;
|
|
@@ -23,6 +25,8 @@
|
|
|
23
25
|
this.connect = module.cwrap("hyperdb_wasm_connect", "pointer", []);
|
|
24
26
|
this.disconnect = module.cwrap("hyperdb_wasm_disconnect", "pointer", ["number"]);
|
|
25
27
|
this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string"]);
|
|
28
|
+
this.appendArrowIPC = module.cwrap("hyperdb_wasm_arrow_insert_append", "pointer", ["number", "number", "number"]);
|
|
29
|
+
this.finishArrowIPC = module.cwrap("hyperdb_wasm_arrow_insert_finish", "pointer", ["number", "string", "string", "number"]);
|
|
26
30
|
this.pollQuery = module.cwrap("hyperdb_wasm_query_poll", "pointer", ["number"]);
|
|
27
31
|
this.cancelQuery = module.cwrap("hyperdb_wasm_query_cancel", "pointer", ["number"]);
|
|
28
32
|
this.releaseQuery = module.cwrap("hyperdb_wasm_query_release", "pointer", ["number"]);
|
|
@@ -44,6 +48,19 @@
|
|
|
44
48
|
return this.disconnect(request.connection);
|
|
45
49
|
case "startQuery":
|
|
46
50
|
return this.startQuery(request.connection, request.sql);
|
|
51
|
+
case "appendArrowIPC": {
|
|
52
|
+
const pointer = safeInteger(this.module._malloc(request.chunk.byteLength || 1), "allocation pointer");
|
|
53
|
+
if (pointer === 0) throw new Error("wasm allocation failed");
|
|
54
|
+
try {
|
|
55
|
+
if (pointer + request.chunk.byteLength > this.module.HEAPU8.byteLength) throw new Error("allocation exceeds the wasm heap");
|
|
56
|
+
this.module.HEAPU8.set(request.chunk, pointer);
|
|
57
|
+
return this.appendArrowIPC(request.connection, pointer, request.chunk.byteLength);
|
|
58
|
+
} finally {
|
|
59
|
+
this.free(pointer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
case "finishArrowIPC":
|
|
63
|
+
return this.finishArrowIPC(request.connection, request.name, request.schema ?? "", Number(request.create));
|
|
47
64
|
case "pollQuery":
|
|
48
65
|
return this.pollQuery(request.query);
|
|
49
66
|
case "cancelQuery":
|
|
@@ -102,6 +119,10 @@
|
|
|
102
119
|
return hasKeys(value, ["id", "type", "connection"]) && Number.isSafeInteger(value.connection);
|
|
103
120
|
case "startQuery":
|
|
104
121
|
return hasKeys(value, ["id", "type", "connection", "sql"]) && Number.isSafeInteger(value.connection) && typeof value.sql === "string";
|
|
122
|
+
case "appendArrowIPC":
|
|
123
|
+
return hasKeys(value, ["id", "type", "connection", "chunk"]) && Number.isSafeInteger(value.connection) && value.chunk instanceof Uint8Array;
|
|
124
|
+
case "finishArrowIPC":
|
|
125
|
+
return hasKeys(value, ["id", "type", "connection", "name", "schema", "create"]) && Number.isSafeInteger(value.connection) && typeof value.name === "string" && (typeof value.schema === "string" || value.schema === null) && typeof value.create === "boolean";
|
|
105
126
|
case "pollQuery":
|
|
106
127
|
case "cancelQuery":
|
|
107
128
|
case "releaseQuery":
|
package/dist/client.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare class HyperDBEngineClient {
|
|
|
13
13
|
connect(): Promise<WasmResult>;
|
|
14
14
|
disconnect(connection: number): Promise<WasmResult>;
|
|
15
15
|
startQuery(connection: number, sql: string): Promise<WasmResult>;
|
|
16
|
+
appendArrowIPC(connection: number, chunk: Uint8Array): Promise<WasmResult>;
|
|
17
|
+
finishArrowIPC(connection: number, name: string, schema: string | null, create: boolean): Promise<WasmResult>;
|
|
16
18
|
pollQuery(query: number): Promise<WasmResult>;
|
|
17
19
|
cancelQuery(query: number): Promise<WasmResult>;
|
|
18
20
|
releaseQuery(query: number): Promise<WasmResult>;
|