lazy-sparql-result-reader 1.0.0 → 1.0.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,99 @@
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
+ </div>
10
+
11
+ A fast SPARQL results parser for JavaScript and TypeScript, compiled from Rust via WebAssembly.
12
+ It reads streamed SPARQL query results and calls a callback for each parsed batch of bindings.
13
+
14
+ ---
15
+
16
+ ## Features
17
+
18
+ - Processes streaming SPARQL results efficiently.
19
+ - Calls a JavaScript callback for each batch of parsed bindings.
20
+ - Written in Rust for speed and reliability.
21
+ - Fully compatible with TypeScript.
22
+
23
+ ---
24
+
25
+
26
+ ## Usage Example
27
+
28
+ ### 1. Install dependencies
29
+
30
+ ```bash
31
+ npm install lazy-sparql-result-reader vite @vitejs/plugin-wasm
32
+ ```
33
+
34
+ ### 2. Configure Vite for WASM
35
+
36
+ Create or update vite.config.ts:
37
+
38
+ ```bash
39
+ import { defineConfig } from 'vite';
40
+ import wasm from '@vitejs/plugin-wasm';
41
+
42
+ export default defineConfig({
43
+ plugins: [wasm()],
44
+ });
45
+ ```
46
+
47
+ This allows Vite to correctly load WebAssembly modules.
48
+
49
+ ### 3. Use the parser in your app
50
+
51
+ ```ts
52
+ import init, { read } from "lazy-sparql-result-reader?init";
53
+
54
+ // Initialize the WASM module
55
+ await init();
56
+
57
+ fetch("https://qlever.dev/api/wikidata", {
58
+ method: 'POST',
59
+ headers: {
60
+ "Accept": "application/sparql-results+json",
61
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
62
+ },
63
+ body: new URLSearchParams({
64
+ query: "SELECT * {?s ?p ?o} LIMIT 1000",
65
+ })
66
+ })
67
+ .then(async response => {
68
+ if (!response.ok) {
69
+ throw new Error(`SPARQL request failed: ${response.status}`);
70
+ }
71
+ const stream = response.body; // ReadableStream of the SPARQL JSON results
72
+ if (!stream) throw new Error("Response has no body stream");
73
+ // Parse the streamed results with the WASM parser
74
+ await read(stream, 100, (bindings) => {
75
+ console.log("Received batch of bindings:", bindings);
76
+ });
77
+ })
78
+ .catch((err) => {
79
+ console.error("Error fetching or parsing SPARQL results:", err);
80
+ });
81
+ ```
82
+
83
+ ## Notes
84
+
85
+ - The **first callback invocation** contains the **SPARQL head**, i.e., the variable names in the result set.
86
+ - Subsequent callback invocations contain batches of bindings as they are parsed.
87
+ - `batch_size` controls how many bindings are buffered before each callback.
88
+ - Ensure your environment supports **ReadableStream** (modern browsers or Node.js >= 18).
89
+
90
+ This setup allows your JS/TS application to process **streaming SPARQL results** efficiently,
91
+ with immediate access to the head and incremental batches of bindings.
92
+
93
+ ## License
94
+
95
+ This project is licensed under the **MIT** License.
96
+
97
+ 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.
98
+
99
+ For full details, see the [LICENSE](./LICENSE) file.
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.0.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",