quiverdb 0.5.0 → 0.6.0
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 +10 -10
- package/dist/composites.d.ts +9 -0
- package/dist/composites.d.ts.map +1 -0
- package/dist/composites.js +69 -0
- package/dist/composites.js.map +1 -0
- package/dist/create.d.ts +9 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +104 -0
- package/dist/create.js.map +1 -0
- package/dist/csv.d.ts +11 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +67 -0
- package/dist/csv.js.map +1 -0
- package/dist/database.d.ts +13 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +42 -0
- package/dist/database.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/ffi-helpers.d.ts +57 -0
- package/dist/ffi-helpers.d.ts.map +1 -0
- package/dist/ffi-helpers.js +136 -0
- package/dist/ffi-helpers.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection.d.ts +10 -0
- package/dist/introspection.d.ts.map +1 -0
- package/dist/introspection.js +27 -0
- package/dist/introspection.js.map +1 -0
- package/dist/loader.d.ts +7 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +165 -0
- package/dist/loader.js.map +1 -0
- package/dist/lua-runner.d.ts +11 -0
- package/dist/lua-runner.d.ts.map +1 -0
- package/dist/lua-runner.js +43 -0
- package/dist/lua-runner.js.map +1 -0
- package/dist/metadata.d.ts +28 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +100 -0
- package/dist/metadata.js.map +1 -0
- package/dist/query.d.ts +9 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +90 -0
- package/dist/query.js.map +1 -0
- package/dist/read.d.ts +25 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +220 -0
- package/dist/read.js.map +1 -0
- package/dist/time-series.d.ts +12 -0
- package/dist/time-series.d.ts.map +1 -0
- package/dist/time-series.js +155 -0
- package/dist/time-series.js.map +1 -0
- package/dist/transaction.d.ts +10 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +22 -0
- package/dist/transaction.js.map +1 -0
- package/{src/types.ts → dist/types.d.ts} +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +19 -16
- package/src/create.ts +0 -128
- package/src/database.ts +0 -68
- package/src/errors.ts +0 -24
- package/src/ffi-helpers.ts +0 -48
- package/src/index.ts +0 -8
- package/src/loader.ts +0 -286
- package/src/query.ts +0 -164
- package/src/read.ts +0 -231
- package/src/transaction.ts +0 -35
- package/tsconfig.json +0 -13
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# quiverdb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SQLite wrapper binding for Quiver via koffi FFI. Works with Node.js, Deno, and Bun.
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
- Bun >= 1.0
|
|
8
|
-
- `libquiver.dll` and `libquiver_c.dll` in system PATH
|
|
7
|
+
- Node.js >= 20, Deno >= 2.0, or Bun >= 1.0
|
|
8
|
+
- `libquiver.dll` and `libquiver_c.dll` (or `.so`/`.dylib`) in system PATH
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
|
|
13
|
+
npm install quiverdb
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
The native Quiver
|
|
16
|
+
The native Quiver libraries must be compiled separately and available in your system PATH. See the Quiver project build instructions for details.
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Native Library Setup
|
|
19
19
|
|
|
20
|
-
This binding loads the Quiver C API library (`libquiver_c
|
|
20
|
+
This binding loads the Quiver C API library (`libquiver_c`) at runtime via koffi. The core library (`libquiver`) is a dependency that must also be loadable.
|
|
21
21
|
|
|
22
|
-
Options for making the
|
|
22
|
+
Options for making the libraries available:
|
|
23
23
|
|
|
24
24
|
1. Add the `build/bin/` directory to your system PATH
|
|
25
|
-
2. Copy both
|
|
26
|
-
3. Place both
|
|
25
|
+
2. Copy both libraries to a directory already in PATH
|
|
26
|
+
3. Place both libraries alongside your application entry point
|
|
27
27
|
|
|
28
28
|
## Quick Start
|
|
29
29
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module "./database.js" {
|
|
2
|
+
interface Database {
|
|
3
|
+
readScalarsById(collection: string, id: number): Record<string, number | string | null>;
|
|
4
|
+
readVectorsById(collection: string, id: number): Record<string, number[] | string[]>;
|
|
5
|
+
readSetsById(collection: string, id: number): Record<string, number[] | string[]>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=composites.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composites.d.ts","sourceRoot":"","sources":["../src/composites.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;QACxF,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACrF,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;KACnF;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Database } from "./database.js";
|
|
2
|
+
Database.prototype.readScalarsById = function (collection, id) {
|
|
3
|
+
const attributes = this.listScalarAttributes(collection);
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const attr of attributes) {
|
|
6
|
+
switch (attr.dataType) {
|
|
7
|
+
case 0: // INTEGER
|
|
8
|
+
result[attr.name] = this.readScalarIntegerById(collection, attr.name, id);
|
|
9
|
+
break;
|
|
10
|
+
case 1: // FLOAT
|
|
11
|
+
result[attr.name] = this.readScalarFloatById(collection, attr.name, id);
|
|
12
|
+
break;
|
|
13
|
+
case 2: // STRING
|
|
14
|
+
case 3: // DATE_TIME
|
|
15
|
+
result[attr.name] = this.readScalarStringById(collection, attr.name, id);
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
throw new Error(`Unknown data type ${attr.dataType} for attribute '${attr.name}'`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
Database.prototype.readVectorsById = function (collection, id) {
|
|
24
|
+
const groups = this.listVectorGroups(collection);
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const group of groups) {
|
|
27
|
+
for (const col of group.valueColumns) {
|
|
28
|
+
switch (col.dataType) {
|
|
29
|
+
case 0: // INTEGER
|
|
30
|
+
result[col.name] = this.readVectorIntegersById(collection, col.name, id);
|
|
31
|
+
break;
|
|
32
|
+
case 1: // FLOAT
|
|
33
|
+
result[col.name] = this.readVectorFloatsById(collection, col.name, id);
|
|
34
|
+
break;
|
|
35
|
+
case 2: // STRING
|
|
36
|
+
case 3: // DATE_TIME
|
|
37
|
+
result[col.name] = this.readVectorStringsById(collection, col.name, id);
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(`Unknown data type ${col.dataType} for column '${col.name}'`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Database.prototype.readSetsById = function (collection, id) {
|
|
47
|
+
const groups = this.listSetGroups(collection);
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const group of groups) {
|
|
50
|
+
for (const col of group.valueColumns) {
|
|
51
|
+
switch (col.dataType) {
|
|
52
|
+
case 0: // INTEGER
|
|
53
|
+
result[col.name] = this.readSetIntegersById(collection, col.name, id);
|
|
54
|
+
break;
|
|
55
|
+
case 1: // FLOAT
|
|
56
|
+
result[col.name] = this.readSetFloatsById(collection, col.name, id);
|
|
57
|
+
break;
|
|
58
|
+
case 2: // STRING
|
|
59
|
+
case 3: // DATE_TIME
|
|
60
|
+
result[col.name] = this.readSetStringsById(collection, col.name, id);
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unknown data type ${col.dataType} for column '${col.name}'`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=composites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composites.js","sourceRoot":"","sources":["../src/composites.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAUzC,QAAQ,CAAC,SAAS,CAAC,eAAe,GAAG,UAEnC,UAAkB,EAClB,EAAU;IAEV,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,MAAM,GAA2C,EAAE,CAAC;IAE1D,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtB,KAAK,CAAC,EAAE,UAAU;gBAChB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC1E,MAAM;YACR,KAAK,CAAC,EAAE,QAAQ;gBACd,MAAM,CAAC,I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ACR;oBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAC,QAAQ,gBAAgB,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ElementData } from "./types.js";
|
|
2
|
+
declare module "./database.js" {
|
|
3
|
+
interface Database {
|
|
4
|
+
createElement(collection: string, data: ElementData): number;
|
|
5
|
+
updateElement(collection: string, id: number, data: ElementData): void;
|
|
6
|
+
deleteElement(collection: string, id: number): void;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,YAAY,CAAC;AAErD,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;QAC7D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;QACvE,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;KACrD;CACF"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Database } from "./database.js";
|
|
2
|
+
import { check, QuiverError } from "./errors.js";
|
|
3
|
+
import { allocPtrOut, readPtrOut } from "./ffi-helpers.js";
|
|
4
|
+
import { getSymbols } from "./loader.js";
|
|
5
|
+
function setElementArray(lib, elemPtr, name, values) {
|
|
6
|
+
if (values.length === 0) {
|
|
7
|
+
check(lib.quiver_element_set_array_integer(elemPtr, name, null, 0));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const first = values[0];
|
|
11
|
+
if (typeof first === "bigint") {
|
|
12
|
+
const arr = BigInt64Array.from(values, (v) => BigInt(v));
|
|
13
|
+
check(lib.quiver_element_set_array_integer(elemPtr, name, arr, values.length));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (typeof first === "number") {
|
|
17
|
+
const allIntegers = values.every((v) => Number.isInteger(v));
|
|
18
|
+
if (allIntegers) {
|
|
19
|
+
const arr = BigInt64Array.from(values, (v) => BigInt(v));
|
|
20
|
+
check(lib.quiver_element_set_array_integer(elemPtr, name, arr, values.length));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const arr = Float64Array.from(values);
|
|
24
|
+
check(lib.quiver_element_set_array_float(elemPtr, name, arr, values.length));
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (typeof first === "string") {
|
|
29
|
+
check(lib.quiver_element_set_array_string(elemPtr, name, values, values.length));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
throw new QuiverError(`Unsupported array element type for '${name}': ${typeof first}`);
|
|
33
|
+
}
|
|
34
|
+
function setElementField(lib, elemPtr, name, value) {
|
|
35
|
+
if (value === null) {
|
|
36
|
+
check(lib.quiver_element_set_null(elemPtr, name));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "bigint") {
|
|
40
|
+
check(lib.quiver_element_set_integer(elemPtr, name, value));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === "number") {
|
|
44
|
+
if (Number.isInteger(value)) {
|
|
45
|
+
check(lib.quiver_element_set_integer(elemPtr, name, value));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
check(lib.quiver_element_set_float(elemPtr, name, value));
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "string") {
|
|
53
|
+
check(lib.quiver_element_set_string(elemPtr, name, value));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
setElementArray(lib, elemPtr, name, value);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
throw new QuiverError(`Unsupported value type for '${name}': ${typeof value}`);
|
|
61
|
+
}
|
|
62
|
+
Database.prototype.createElement = function (collection, data) {
|
|
63
|
+
const lib = getSymbols();
|
|
64
|
+
const handle = this._handle;
|
|
65
|
+
const outElem = allocPtrOut();
|
|
66
|
+
check(lib.quiver_element_create(outElem));
|
|
67
|
+
const elemPtr = readPtrOut(outElem);
|
|
68
|
+
try {
|
|
69
|
+
for (const [key, value] of Object.entries(data)) {
|
|
70
|
+
if (value === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
setElementField(lib, elemPtr, key, value);
|
|
73
|
+
}
|
|
74
|
+
const outId = new BigInt64Array(1);
|
|
75
|
+
check(lib.quiver_database_create_element(handle, collection, elemPtr, outId));
|
|
76
|
+
return Number(outId[0]);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
lib.quiver_element_destroy(elemPtr);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
Database.prototype.updateElement = function (collection, id, data) {
|
|
83
|
+
const lib = getSymbols();
|
|
84
|
+
const handle = this._handle;
|
|
85
|
+
const outElem = allocPtrOut();
|
|
86
|
+
check(lib.quiver_element_create(outElem));
|
|
87
|
+
const elemPtr = readPtrOut(outElem);
|
|
88
|
+
try {
|
|
89
|
+
for (const [key, value] of Object.entries(data)) {
|
|
90
|
+
if (value === undefined)
|
|
91
|
+
continue;
|
|
92
|
+
setElementField(lib, elemPtr, key, value);
|
|
93
|
+
}
|
|
94
|
+
check(lib.quiver_database_update_element(handle, collection, id, elemPtr));
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
lib.quiver_element_destroy(elemPtr);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
Database.prototype.deleteElement = function (collection, id) {
|
|
101
|
+
const lib = getSymbols();
|
|
102
|
+
check(lib.quiver_database_delete_element(this._handle, collection, id));
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAazC,SAAS,eAAe,CAAC,GAAY,EAAE,OAAgB,EAAE,IAAY,EAAE,MAAiB;IACtF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAExB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,MAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC/E,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAI,MAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CA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QAAQ,CAAC,SAAS,CAAC,aAAa,GAAG,UAA0B,UAAkB,EAAE,EAAU;IACzF,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,KAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC"}
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface CsvOptions {
|
|
2
|
+
dateTimeFormat?: string;
|
|
3
|
+
enumLabels?: Record<string, Record<string, Record<string, number>>>;
|
|
4
|
+
}
|
|
5
|
+
declare module "./database.js" {
|
|
6
|
+
interface Database {
|
|
7
|
+
exportCsv(collection: string, group: string, filePath: string, options?: CsvOptions): void;
|
|
8
|
+
importCsv(collection: string, group: string, filePath: string, options?: CsvOptions): void;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CACrE;AAED,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;QAC3F,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;KAC5F;CACF"}
|
package/dist/csv.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import koffi from "koffi";
|
|
2
|
+
import { Database } from "./database.js";
|
|
3
|
+
import { check } from "./errors.js";
|
|
4
|
+
import { allocNativeInt64, allocNativeString, allocNativeStringArray, nativeAddress } from "./ffi-helpers.js";
|
|
5
|
+
import { getSymbols } from "./loader.js";
|
|
6
|
+
/**
|
|
7
|
+
* Build the 56-byte quiver_csv_options_t struct as a Buffer.
|
|
8
|
+
* Returns [structBuffer, keepalive] where keepalive prevents GC of native allocations.
|
|
9
|
+
*/
|
|
10
|
+
function buildCsvOptionsBuffer(options) {
|
|
11
|
+
const buf = Buffer.alloc(56);
|
|
12
|
+
const keepalive = [];
|
|
13
|
+
const dtfStr = allocNativeString(options?.dateTimeFormat ?? "");
|
|
14
|
+
keepalive.push(dtfStr);
|
|
15
|
+
buf.writeBigUInt64LE(nativeAddress(dtfStr), 0);
|
|
16
|
+
if (!options?.enumLabels || Object.keys(options.enumLabels).length === 0) {
|
|
17
|
+
return [buf, keepalive];
|
|
18
|
+
}
|
|
19
|
+
const groupAttrNames = [];
|
|
20
|
+
const groupLocaleNames = [];
|
|
21
|
+
const groupEntryCounts = [];
|
|
22
|
+
const allLabels = [];
|
|
23
|
+
const allValues = [];
|
|
24
|
+
for (const [attrName, locales] of Object.entries(options.enumLabels)) {
|
|
25
|
+
for (const [localeName, entries] of Object.entries(locales)) {
|
|
26
|
+
groupAttrNames.push(attrName);
|
|
27
|
+
groupLocaleNames.push(localeName);
|
|
28
|
+
groupEntryCounts.push(Object.keys(entries).length);
|
|
29
|
+
for (const [label, value] of Object.entries(entries)) {
|
|
30
|
+
allLabels.push(label);
|
|
31
|
+
allValues.push(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const groupCount = groupAttrNames.length;
|
|
36
|
+
const { table: attrTable, keepalive: attrPtrs } = allocNativeStringArray(groupAttrNames);
|
|
37
|
+
keepalive.push(attrTable, ...attrPtrs);
|
|
38
|
+
const { table: localeTable, keepalive: localePtrs } = allocNativeStringArray(groupLocaleNames);
|
|
39
|
+
keepalive.push(localeTable, ...localePtrs);
|
|
40
|
+
const entryCounts = koffi.alloc("uint64_t", groupCount);
|
|
41
|
+
for (let i = 0; i < groupCount; i++) {
|
|
42
|
+
koffi.encode(entryCounts, i * 8, "uint64_t", BigInt(groupEntryCounts[i]));
|
|
43
|
+
}
|
|
44
|
+
keepalive.push(entryCounts);
|
|
45
|
+
const { table: labelsTable, keepalive: labelPtrs } = allocNativeStringArray(allLabels);
|
|
46
|
+
keepalive.push(labelsTable, ...labelPtrs);
|
|
47
|
+
const valuesArr = allocNativeInt64(allValues);
|
|
48
|
+
keepalive.push(valuesArr);
|
|
49
|
+
buf.writeBigUInt64LE(nativeAddress(attrTable), 8);
|
|
50
|
+
buf.writeBigUInt64LE(nativeAddress(localeTable), 16);
|
|
51
|
+
buf.writeBigUInt64LE(nativeAddress(entryCounts), 24);
|
|
52
|
+
buf.writeBigUInt64LE(nativeAddress(labelsTable), 32);
|
|
53
|
+
buf.writeBigUInt64LE(nativeAddress(valuesArr), 40);
|
|
54
|
+
buf.writeBigUInt64LE(BigInt(groupCount), 48);
|
|
55
|
+
return [buf, keepalive];
|
|
56
|
+
}
|
|
57
|
+
Database.prototype.exportCsv = function (collection, group, filePath, options) {
|
|
58
|
+
const lib = getSymbols();
|
|
59
|
+
const [optsBuf, _keepalive] = buildCsvOptionsBuffer(options);
|
|
60
|
+
check(lib.quiver_database_export_csv(this._handle, collection, group, filePath, optsBuf));
|
|
61
|
+
};
|
|
62
|
+
Database.prototype.importCsv = function (collection, group, filePath, options) {
|
|
63
|
+
const lib = getSymbols();
|
|
64
|
+
const [optsBuf, _keepalive] = buildCsvOptionsBuffer(options);
|
|
65
|
+
check(lib.quiver_database_import_csv(this._handle, collection, group, filePath, optsBuf));
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=csv.js.map
|
package/dist/csv.js.map
ADDED
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C5F,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,CAAC,SAAS,GAAG,UAE7B,UAAkB,EAClB,KAAa,EACb,QAAgB,EAChB,OAAoB;IAEpB,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC7D,KAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NativePointer } from "./loader.js";
|
|
2
|
+
export declare class Database {
|
|
3
|
+
private _ptr;
|
|
4
|
+
private _closed;
|
|
5
|
+
private constructor();
|
|
6
|
+
static fromSchema(dbPath: string, schemaPath: string): Database;
|
|
7
|
+
static fromMigrations(dbPath: string, migrationsPath: string): Database;
|
|
8
|
+
close(): void;
|
|
9
|
+
private ensureOpen;
|
|
10
|
+
/** @internal */
|
|
11
|
+
get _handle(): NativePointer;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjD,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAIP,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,QAAQ;IAU/D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,QAAQ;IAUvE,KAAK,IAAI,IAAI;IAOb,OAAO,CAAC,UAAU;IAMlB,gBAAgB;IAChB,IAAI,OAAO,IAAI,aAAa,CAG3B;CACF"}
|
package/dist/database.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { check, QuiverError } from "./errors.js";
|
|
2
|
+
import { allocPtrOut, makeDefaultOptions, readPtrOut } from "./ffi-helpers.js";
|
|
3
|
+
import { getSymbols } from "./loader.js";
|
|
4
|
+
export class Database {
|
|
5
|
+
_ptr;
|
|
6
|
+
_closed = false;
|
|
7
|
+
constructor(nativePtr) {
|
|
8
|
+
this._ptr = nativePtr;
|
|
9
|
+
}
|
|
10
|
+
static fromSchema(dbPath, schemaPath) {
|
|
11
|
+
const lib = getSymbols();
|
|
12
|
+
const options = makeDefaultOptions();
|
|
13
|
+
const outDb = allocPtrOut();
|
|
14
|
+
check(lib.quiver_database_from_schema(dbPath, schemaPath, options, outDb));
|
|
15
|
+
return new Database(readPtrOut(outDb));
|
|
16
|
+
}
|
|
17
|
+
static fromMigrations(dbPath, migrationsPath) {
|
|
18
|
+
const lib = getSymbols();
|
|
19
|
+
const options = makeDefaultOptions();
|
|
20
|
+
const outDb = allocPtrOut();
|
|
21
|
+
check(lib.quiver_database_from_migrations(dbPath, migrationsPath, options, outDb));
|
|
22
|
+
return new Database(readPtrOut(outDb));
|
|
23
|
+
}
|
|
24
|
+
close() {
|
|
25
|
+
if (this._closed)
|
|
26
|
+
return;
|
|
27
|
+
const lib = getSymbols();
|
|
28
|
+
check(lib.quiver_database_close(this._ptr));
|
|
29
|
+
this._closed = true;
|
|
30
|
+
}
|
|
31
|
+
ensureOpen() {
|
|
32
|
+
if (this._closed) {
|
|
33
|
+
throw new QuiverError("Database is closed");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** @internal */
|
|
37
|
+
get _handle() {
|
|
38
|
+
this.ensureOpen();
|
|
39
|
+
return this._ptr;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,WAAW,CAAC,oBAAoB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,IAAI,OAAO;QACT,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CASvC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getSymbols } from "./loader.js";
|
|
2
|
+
export class QuiverError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "QuiverError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function check(err) {
|
|
9
|
+
if (err !== 0) {
|
|
10
|
+
const lib = getSymbols();
|
|
11
|
+
const detail = lib.quiver_get_last_error();
|
|
12
|
+
if (detail) {
|
|
13
|
+
throw new QuiverError(detail);
|
|
14
|
+
}
|
|
15
|
+
throw new QuiverError("Unknown error");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAC3C,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NativePointer } from "./loader.js";
|
|
2
|
+
/**
|
|
3
|
+
* Construct the 8-byte quiver_database_options_t struct as a Buffer.
|
|
4
|
+
* Layout: offset 0 = int32 read_only (default 0), offset 4 = int32 console_level (default 1 = QUIVER_LOG_INFO).
|
|
5
|
+
*/
|
|
6
|
+
export declare function makeDefaultOptions(): Buffer;
|
|
7
|
+
/** Allocate an 8-byte buffer for a pointer out-parameter. */
|
|
8
|
+
export declare function allocPtrOut(): Buffer;
|
|
9
|
+
/** Read a pointer from an out-parameter buffer. */
|
|
10
|
+
export declare function readPtrOut(buf: Buffer): NativePointer;
|
|
11
|
+
/** Allocate and read a uint64 out-parameter. */
|
|
12
|
+
export declare function allocUint64Out(): Buffer;
|
|
13
|
+
/** Read a uint64 value from an out-parameter buffer. */
|
|
14
|
+
export declare function readUint64Out(buf: Buffer): number;
|
|
15
|
+
/**
|
|
16
|
+
* Read a null-terminated C string from a pointer stored in a Buffer.
|
|
17
|
+
* koffi.decode(externalPtr, "str") segfaults with external pointers,
|
|
18
|
+
* so we decode from the original Buffer that holds the char* pointer.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decodeStringFromBuf(buf: Buffer): string;
|
|
21
|
+
/** Read an array of int64 values from a native pointer, returning JS numbers. */
|
|
22
|
+
export declare function decodeInt64Array(ptr: NativePointer, count: number): number[];
|
|
23
|
+
/** Read an array of float64 values from a native pointer. */
|
|
24
|
+
export declare function decodeFloat64Array(ptr: NativePointer, count: number): number[];
|
|
25
|
+
/** Read an array of uint64 values from a native pointer, returning JS numbers. */
|
|
26
|
+
export declare function decodeUint64Array(ptr: NativePointer, count: number): number[];
|
|
27
|
+
/** Read an array of pointers from a native pointer using offset-based reading. */
|
|
28
|
+
export declare function decodePtrArray(ptr: NativePointer, count: number): NativePointer[];
|
|
29
|
+
/** Read an array of C strings from a char** pointer. */
|
|
30
|
+
export declare function decodeStringArray(ptr: NativePointer, count: number): string[];
|
|
31
|
+
/** Encode a JS string as a null-terminated C string buffer. */
|
|
32
|
+
export declare function toCString(str: string): Buffer;
|
|
33
|
+
/**
|
|
34
|
+
* Allocate native memory for a typed array and write values into it.
|
|
35
|
+
* Returns [nativePtr, address] where nativePtr must be kept alive to prevent GC.
|
|
36
|
+
*/
|
|
37
|
+
export declare function allocNativeInt64(values: number[]): NativePointer;
|
|
38
|
+
export declare function allocNativeFloat64(values: number[]): NativePointer;
|
|
39
|
+
/**
|
|
40
|
+
* Build a native pointer table from an array of native pointers.
|
|
41
|
+
* The returned pointer contains an array of void* addresses.
|
|
42
|
+
*/
|
|
43
|
+
export declare function allocNativePtrTable(ptrs: NativePointer[]): NativePointer;
|
|
44
|
+
/**
|
|
45
|
+
* Allocate a native string (null-terminated) and return its external pointer.
|
|
46
|
+
*/
|
|
47
|
+
export declare function allocNativeString(str: string): NativePointer;
|
|
48
|
+
/**
|
|
49
|
+
* Build a native string pointer table (const char* const*) from an array of strings.
|
|
50
|
+
*/
|
|
51
|
+
export declare function allocNativeStringArray(strings: string[]): {
|
|
52
|
+
table: NativePointer;
|
|
53
|
+
keepalive: NativePointer[];
|
|
54
|
+
};
|
|
55
|
+
/** Get the native address of an external pointer as BigInt. */
|
|
56
|
+
export declare function nativeAddress(ptr: NativePointer): bigint;
|
|
57
|
+
//# sourceMappingURL=ffi-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffi-helpers.d.ts","sourceRoot":"","sources":["../src/ffi-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAK3C;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,mDAAmD;AACnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAErD;AAED,gDAAgD;AAChD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wDAAwD;AACxD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ5E;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAG9E;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ7E;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAOjF;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAG7E;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAMhE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAMlE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,aAAa,CAMxE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAO5D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG;IAAE,KAAK,EAAE,aAAa,CAAC;IAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CAAE,CAI9G;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import koffi from "koffi";
|
|
2
|
+
/**
|
|
3
|
+
* Construct the 8-byte quiver_database_options_t struct as a Buffer.
|
|
4
|
+
* Layout: offset 0 = int32 read_only (default 0), offset 4 = int32 console_level (default 1 = QUIVER_LOG_INFO).
|
|
5
|
+
*/
|
|
6
|
+
export function makeDefaultOptions() {
|
|
7
|
+
const buf = Buffer.alloc(8);
|
|
8
|
+
buf.writeInt32LE(0, 0); // read_only = false
|
|
9
|
+
buf.writeInt32LE(1, 4); // console_level = QUIVER_LOG_INFO
|
|
10
|
+
return buf;
|
|
11
|
+
}
|
|
12
|
+
/** Allocate an 8-byte buffer for a pointer out-parameter. */
|
|
13
|
+
export function allocPtrOut() {
|
|
14
|
+
return Buffer.alloc(8);
|
|
15
|
+
}
|
|
16
|
+
/** Read a pointer from an out-parameter buffer. */
|
|
17
|
+
export function readPtrOut(buf) {
|
|
18
|
+
return koffi.decode(buf, "void *");
|
|
19
|
+
}
|
|
20
|
+
/** Allocate and read a uint64 out-parameter. */
|
|
21
|
+
export function allocUint64Out() {
|
|
22
|
+
return Buffer.alloc(8);
|
|
23
|
+
}
|
|
24
|
+
/** Read a uint64 value from an out-parameter buffer. */
|
|
25
|
+
export function readUint64Out(buf) {
|
|
26
|
+
return Number(buf.readBigUInt64LE());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read a null-terminated C string from a pointer stored in a Buffer.
|
|
30
|
+
* koffi.decode(externalPtr, "str") segfaults with external pointers,
|
|
31
|
+
* so we decode from the original Buffer that holds the char* pointer.
|
|
32
|
+
*/
|
|
33
|
+
export function decodeStringFromBuf(buf) {
|
|
34
|
+
return koffi.decode(buf, koffi.array("str", 1))[0];
|
|
35
|
+
}
|
|
36
|
+
/** Read an array of int64 values from a native pointer, returning JS numbers. */
|
|
37
|
+
export function decodeInt64Array(ptr, count) {
|
|
38
|
+
if (count === 0)
|
|
39
|
+
return [];
|
|
40
|
+
const bigInts = koffi.decode(ptr, koffi.array("int64_t", count));
|
|
41
|
+
const result = new Array(count);
|
|
42
|
+
for (let i = 0; i < count; i++) {
|
|
43
|
+
result[i] = Number(bigInts[i]);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/** Read an array of float64 values from a native pointer. */
|
|
48
|
+
export function decodeFloat64Array(ptr, count) {
|
|
49
|
+
if (count === 0)
|
|
50
|
+
return [];
|
|
51
|
+
return Array.from(koffi.decode(ptr, koffi.array("double", count)));
|
|
52
|
+
}
|
|
53
|
+
/** Read an array of uint64 values from a native pointer, returning JS numbers. */
|
|
54
|
+
export function decodeUint64Array(ptr, count) {
|
|
55
|
+
if (count === 0)
|
|
56
|
+
return [];
|
|
57
|
+
const bigInts = koffi.decode(ptr, koffi.array("uint64_t", count));
|
|
58
|
+
const result = new Array(count);
|
|
59
|
+
for (let i = 0; i < count; i++) {
|
|
60
|
+
result[i] = Number(bigInts[i]);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
/** Read an array of pointers from a native pointer using offset-based reading. */
|
|
65
|
+
export function decodePtrArray(ptr, count) {
|
|
66
|
+
if (count === 0)
|
|
67
|
+
return [];
|
|
68
|
+
const result = new Array(count);
|
|
69
|
+
for (let i = 0; i < count; i++) {
|
|
70
|
+
result[i] = koffi.decode(ptr, i * 8, "void *");
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/** Read an array of C strings from a char** pointer. */
|
|
75
|
+
export function decodeStringArray(ptr, count) {
|
|
76
|
+
if (count === 0)
|
|
77
|
+
return [];
|
|
78
|
+
return koffi.decode(ptr, koffi.array("str", count));
|
|
79
|
+
}
|
|
80
|
+
/** Encode a JS string as a null-terminated C string buffer. */
|
|
81
|
+
export function toCString(str) {
|
|
82
|
+
return Buffer.from(`${str}\0`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Allocate native memory for a typed array and write values into it.
|
|
86
|
+
* Returns [nativePtr, address] where nativePtr must be kept alive to prevent GC.
|
|
87
|
+
*/
|
|
88
|
+
export function allocNativeInt64(values) {
|
|
89
|
+
const p = koffi.alloc("int64_t", values.length);
|
|
90
|
+
for (let i = 0; i < values.length; i++) {
|
|
91
|
+
koffi.encode(p, i * 8, "int64_t", BigInt(values[i]));
|
|
92
|
+
}
|
|
93
|
+
return p;
|
|
94
|
+
}
|
|
95
|
+
export function allocNativeFloat64(values) {
|
|
96
|
+
const p = koffi.alloc("double", values.length);
|
|
97
|
+
for (let i = 0; i < values.length; i++) {
|
|
98
|
+
koffi.encode(p, i * 8, "double", values[i]);
|
|
99
|
+
}
|
|
100
|
+
return p;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Build a native pointer table from an array of native pointers.
|
|
104
|
+
* The returned pointer contains an array of void* addresses.
|
|
105
|
+
*/
|
|
106
|
+
export function allocNativePtrTable(ptrs) {
|
|
107
|
+
const p = koffi.alloc("void *", ptrs.length);
|
|
108
|
+
for (let i = 0; i < ptrs.length; i++) {
|
|
109
|
+
koffi.encode(p, i * 8, "void *", ptrs[i]);
|
|
110
|
+
}
|
|
111
|
+
return p;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Allocate a native string (null-terminated) and return its external pointer.
|
|
115
|
+
*/
|
|
116
|
+
export function allocNativeString(str) {
|
|
117
|
+
const buf = Buffer.from(`${str}\0`);
|
|
118
|
+
const p = koffi.alloc("char", buf.length);
|
|
119
|
+
for (let i = 0; i < buf.length; i++) {
|
|
120
|
+
koffi.encode(p, i, "char", buf[i]);
|
|
121
|
+
}
|
|
122
|
+
return p;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Build a native string pointer table (const char* const*) from an array of strings.
|
|
126
|
+
*/
|
|
127
|
+
export function allocNativeStringArray(strings) {
|
|
128
|
+
const strPtrs = strings.map((s) => allocNativeString(s));
|
|
129
|
+
const table = allocNativePtrTable(strPtrs);
|
|
130
|
+
return { table, keepalive: strPtrs };
|
|
131
|
+
}
|
|
132
|
+
/** Get the native address of an external pointer as BigInt. */
|
|
133
|
+
export function nativeAddress(ptr) {
|
|
134
|
+
return koffi.address(ptr);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=ffi-helpers.js.map
|