flatsql 0.3.6 → 0.3.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatsql",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "SQL queries over raw FlatBuffer storage - zero conversion, real-time indexing, pure streaming",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,7 +13,12 @@
13
13
  "./wasm": {
14
14
  "types": "./wasm/index.d.ts",
15
15
  "import": "./wasm/index.js"
16
- }
16
+ },
17
+ "./wasi": {
18
+ "types": "./wasm/wasi.d.ts",
19
+ "import": "./wasm/wasi.js"
20
+ },
21
+ "./wasi.wasm": "./wasm/flatsql-wasi.wasm"
17
22
  },
18
23
  "files": [
19
24
  "dist",
Binary file
package/wasm/wasi.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface FlatSQLWASILoadOptions {
2
+ url?: string | URL;
3
+ path?: string;
4
+ as?: 'arrayBuffer' | 'uint8array';
5
+ }
6
+
7
+ export declare function getFlatSQLWASIURL(): URL;
8
+
9
+ export declare function loadFlatSQLWASI(
10
+ options?: FlatSQLWASILoadOptions
11
+ ): Promise<ArrayBuffer | Uint8Array>;
package/wasm/wasi.js ADDED
@@ -0,0 +1,51 @@
1
+ const DEFAULT_WASI_URL = new URL('./flatsql-wasi.wasm', import.meta.url);
2
+
3
+ /**
4
+ * Resolve the packaged FlatSQL WASI module URL.
5
+ */
6
+ export function getFlatSQLWASIURL() {
7
+ return DEFAULT_WASI_URL;
8
+ }
9
+
10
+ async function readViaFsPath(path) {
11
+ const fs = await import('node:fs/promises');
12
+ return new Uint8Array(await fs.readFile(path));
13
+ }
14
+
15
+ /**
16
+ * Load the packaged FlatSQL WASI module bytes.
17
+ *
18
+ * @param {{
19
+ * url?: string | URL,
20
+ * path?: string,
21
+ * as?: 'arrayBuffer' | 'uint8array'
22
+ * }} [options]
23
+ * @returns {Promise<ArrayBuffer | Uint8Array>}
24
+ */
25
+ export async function loadFlatSQLWASI(options = {}) {
26
+ const as = options.as === 'uint8array' ? 'uint8array' : 'arrayBuffer';
27
+
28
+ let bytes;
29
+ if (options.path) {
30
+ bytes = await readViaFsPath(options.path);
31
+ } else {
32
+ const wasmUrl = options.url ? new URL(options.url, import.meta.url) : DEFAULT_WASI_URL;
33
+
34
+ if (wasmUrl.protocol === 'file:') {
35
+ const { fileURLToPath } = await import('node:url');
36
+ bytes = await readViaFsPath(fileURLToPath(wasmUrl));
37
+ } else {
38
+ const response = await fetch(wasmUrl);
39
+ if (!response.ok) {
40
+ throw new Error(`Failed to load flatsql-wasi.wasm: ${response.status}`);
41
+ }
42
+ bytes = new Uint8Array(await response.arrayBuffer());
43
+ }
44
+ }
45
+
46
+ if (as === 'uint8array') {
47
+ return bytes;
48
+ }
49
+
50
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
51
+ }