lazy-sparql-result-reader 1.0.0 → 1.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ioannis Nezis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ <h1 align="center">
2
+ lazy-sparql-result-reader
3
+ </h1>
4
+
5
+ <div align="center">
6
+ <a href="https://www.npmjs.com/package/lazy-sparql-result-reader">
7
+ <img alt="npm" src="https://img.shields.io/npm/v/lazy-sparql-result-reader" />
8
+ </a>
9
+ <a href="https://crates.io/crates/lazy-sparql-result-reader">
10
+ <img alt="crates.io" src="https://img.shields.io/crates/v/lazy-sparql-result-reader.svg" />
11
+ </a>
12
+ </div>
13
+
14
+ A fast SPARQL results parser for JavaScript and TypeScript, compiled from Rust via WebAssembly.
15
+ It reads streamed SPARQL query results and calls a callback for each parsed batch of bindings.
16
+
17
+ ---
18
+
19
+ ## Features
20
+
21
+ - Processes streaming SPARQL results efficiently.
22
+ - Calls a JavaScript callback for each batch of parsed bindings.
23
+ - Written in Rust for speed and reliability.
24
+ - Fully compatible with TypeScript.
25
+
26
+ ---
27
+
28
+
29
+ ## Usage Example
30
+
31
+ ### 1. Install dependencies
32
+
33
+ ```bash
34
+ npm install lazy-sparql-result-reader vite @vitejs/plugin-wasm
35
+ ```
36
+
37
+ ### 2. Configure Vite for WASM
38
+
39
+ Create or update vite.config.ts:
40
+
41
+ ```bash
42
+ import { defineConfig } from 'vite';
43
+ import wasm from '@vitejs/plugin-wasm';
44
+
45
+ export default defineConfig({
46
+ plugins: [wasm()],
47
+ });
48
+ ```
49
+
50
+ This allows Vite to correctly load WebAssembly modules.
51
+
52
+ ### 3. Use the parser in your app
53
+
54
+ ```ts
55
+ import init, { read } from "lazy-sparql-result-reader?init";
56
+
57
+ // Initialize the WASM module
58
+ await init();
59
+
60
+ fetch("https://qlever.dev/api/wikidata", {
61
+ method: 'POST',
62
+ headers: {
63
+ "Accept": "application/sparql-results+json",
64
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
65
+ },
66
+ body: new URLSearchParams({
67
+ query: "SELECT * {?s ?p ?o} LIMIT 1000",
68
+ })
69
+ })
70
+ .then(async response => {
71
+ if (!response.ok) {
72
+ throw new Error(`SPARQL request failed: ${response.status}`);
73
+ }
74
+ const stream = response.body; // ReadableStream of the SPARQL JSON results
75
+ if (!stream) throw new Error("Response has no body stream");
76
+ // Parse the streamed results with the WASM parser
77
+ await read(stream, 100, (bindings) => {
78
+ console.log("Received batch of bindings:", bindings);
79
+ });
80
+ })
81
+ .catch((err) => {
82
+ console.error("Error fetching or parsing SPARQL results:", err);
83
+ });
84
+ ```
85
+
86
+ ## Notes
87
+
88
+ - The **first callback invocation** contains the **SPARQL head**, i.e., the variable names in the result set.
89
+ - Subsequent callback invocations contain batches of bindings as they are parsed.
90
+ - `batch_size` controls how many bindings are buffered before each callback.
91
+ - Ensure your environment supports **ReadableStream** (modern browsers or Node.js >= 18).
92
+
93
+ This setup allows your JS/TS application to process **streaming SPARQL results** efficiently,
94
+ with immediate access to the head and incremental batches of bindings.
95
+
96
+ ## License
97
+
98
+ This project is licensed under the **MIT** License.
99
+
100
+ You are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, under the conditions of the MIT License.
101
+
102
+ For full details, see the [LICENSE](./LICENSE) file.
@@ -16,7 +16,6 @@ export interface InitOutput {
16
16
  readonly __wbindgen_exn_store: (a: number) => void;
17
17
  readonly __externref_table_alloc: () => number;
18
18
  readonly __wbindgen_externrefs: WebAssembly.Table;
19
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
20
19
  readonly __wbindgen_start: () => void;
21
20
  }
22
21
 
@@ -308,26 +308,6 @@ function __wbg_get_imports() {
308
308
  const ret = arg0.call(arg1);
309
309
  return ret;
310
310
  }, arguments) };
311
- imports.wbg.__wbg_debug_9ad80675faf0c9cf = function(arg0, arg1, arg2, arg3) {
312
- console.debug(arg0, arg1, arg2, arg3);
313
- };
314
- imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
315
- let deferred0_0;
316
- let deferred0_1;
317
- try {
318
- deferred0_0 = arg0;
319
- deferred0_1 = arg1;
320
- console.error(getStringFromWasm0(arg0, arg1));
321
- } finally {
322
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
323
- }
324
- };
325
- imports.wbg.__wbg_error_7bc7d576a6aaf855 = function(arg0) {
326
- console.error(arg0);
327
- };
328
- imports.wbg.__wbg_error_ad1ecdacd1bb600d = function(arg0, arg1, arg2, arg3) {
329
- console.error(arg0, arg1, arg2, arg3);
330
- };
331
311
  imports.wbg.__wbg_getReader_b6676f6d8b326942 = function(arg0) {
332
312
  const ret = arg0.getReader();
333
313
  return ret;
@@ -336,16 +316,10 @@ function __wbg_get_imports() {
336
316
  const ret = Reflect.get(arg0, arg1);
337
317
  return ret;
338
318
  }, arguments) };
339
- imports.wbg.__wbg_info_b7fa8ce2e59d29c6 = function(arg0, arg1, arg2, arg3) {
340
- console.info(arg0, arg1, arg2, arg3);
341
- };
342
319
  imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
343
320
  const ret = arg0.length;
344
321
  return ret;
345
322
  };
346
- imports.wbg.__wbg_log_f614673762e98966 = function(arg0, arg1, arg2, arg3) {
347
- console.log(arg0, arg1, arg2, arg3);
348
- };
349
323
  imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
350
324
  const ret = new Object();
351
325
  return ret;
@@ -358,10 +332,6 @@ function __wbg_get_imports() {
358
332
  const ret = new Uint8Array(arg0);
359
333
  return ret;
360
334
  };
361
- imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
362
- const ret = new Error();
363
- return ret;
364
- };
365
335
  imports.wbg.__wbg_new_b546ae120718850e = function() {
366
336
  const ret = new Map();
367
337
  return ret;
@@ -416,13 +386,6 @@ function __wbg_get_imports() {
416
386
  const ret = arg0.set(arg1, arg2);
417
387
  return ret;
418
388
  };
419
- imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
420
- const ret = arg1.stack;
421
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
422
- const len1 = WASM_VECTOR_LEN;
423
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
424
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
425
- };
426
389
  imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
427
390
  const ret = typeof global === 'undefined' ? null : global;
428
391
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
@@ -447,16 +410,13 @@ function __wbg_get_imports() {
447
410
  const ret = arg0.then(arg1);
448
411
  return ret;
449
412
  };
450
- imports.wbg.__wbg_warn_165ef4f6bcfc05e7 = function(arg0, arg1, arg2, arg3) {
451
- console.warn(arg0, arg1, arg2, arg3);
452
- };
453
413
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
454
414
  // Cast intrinsic for `Ref(String) -> Externref`.
455
415
  const ret = getStringFromWasm0(arg0, arg1);
456
416
  return ret;
457
417
  };
458
- imports.wbg.__wbindgen_cast_27d8f2a9ce018ee0 = function(arg0, arg1) {
459
- // Cast intrinsic for `Closure(Closure { dtor_idx: 43, function: Function { arguments: [Externref], shim_idx: 44, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
418
+ imports.wbg.__wbindgen_cast_c6111fef16576abb = function(arg0, arg1) {
419
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 40, function: Function { arguments: [Externref], shim_idx: 41, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
460
420
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h9431bfc0c26898f5, wasm_bindgen__convert__closures_____invoke__h53040b977ccf16ad);
461
421
  return ret;
462
422
  };
Binary file
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "lazy-sparql-result-reader",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "description": "A lazy sparql result reader",
5
+ "version": "1.1.1",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/IoannisNezis/Lazy-SPARQL-result-reader"
10
+ },
5
11
  "files": [
6
12
  "lazy_sparql_result_reader_bg.wasm",
7
13
  "lazy_sparql_result_reader.js",