rete-graph 0.1.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 +79 -0
- package/dist/index.js +1436 -0
- package/dist/rete-graph.js +1492 -0
- package/dist/rete-graph.min.js +22 -0
- package/dist/rete_wasm_bg.wasm +0 -0
- package/index.d.ts +65 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# rete-graph — JavaScript client for `.rete` files
|
|
2
|
+
|
|
3
|
+
Query **local and remote `.rete` graph files with SPARQL** from JavaScript —
|
|
4
|
+
in the browser and in Node. A `.rete` file is a single, immutable,
|
|
5
|
+
range-queryable RDF graph file ([rete](https://github.com/caviri/rete)): host
|
|
6
|
+
it on any HTTP server that supports `Range` requests and query it in place —
|
|
7
|
+
the client fetches only the byte ranges a query touches, never the whole
|
|
8
|
+
file. This package wraps the same WebAssembly engine that powers the
|
|
9
|
+
[rete playground](https://caviri.github.io/rete/playground.html).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install rete-graph
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { open, build } from "rete-graph";
|
|
19
|
+
|
|
20
|
+
const g = await open(new Uint8Array(await (await fetch("data.rete")).arrayBuffer()));
|
|
21
|
+
for (const row of g.query("SELECT ?s ?label WHERE { ?s rdfs:label ?label } LIMIT 5")) {
|
|
22
|
+
console.log(row.s.value, row.label.toJS());
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Or just a `<script>` tag (p5.js-style)
|
|
27
|
+
|
|
28
|
+
One self-contained file, engine included — via any npm CDN:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/rete-graph@0.1.0/dist/rete-graph.min.js"></script>
|
|
32
|
+
<script>
|
|
33
|
+
(async () => {
|
|
34
|
+
const g = await rete.open(await rete.build("<urn:a> <urn:knows> <urn:b> ."));
|
|
35
|
+
console.log(g.query("ASK { <urn:a> ?p ?o }")); // true
|
|
36
|
+
})();
|
|
37
|
+
</script>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`dist/rete-graph.js` is the unminified twin.
|
|
41
|
+
|
|
42
|
+
## Remote graphs (HTTP Range)
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const g = await open("https://data.graphplaza.com/boe/boe.rete"); // 447k triples
|
|
46
|
+
g.query("SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 5");
|
|
47
|
+
g.stats(); // { fileLength, bytes, requests } — a LIMIT query fetches KBs–MBs, not the file
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Remote opens use synchronous XHR range reads, so they work:
|
|
51
|
+
|
|
52
|
+
- **in Node** (≥18) — out of the box, via a built-in sync-fetch bridge;
|
|
53
|
+
- **in browser web workers** — where sync binary XHR is allowed (this is how
|
|
54
|
+
the playground runs its queries).
|
|
55
|
+
|
|
56
|
+
On a browser **main thread**, open bytes instead, or move the graph into a
|
|
57
|
+
worker. The host serving the file must send CORS headers and honor `Range`.
|
|
58
|
+
|
|
59
|
+
## API sketch
|
|
60
|
+
|
|
61
|
+
`query()` returns `{var: Term}` rows for SELECT, a boolean for ASK, and
|
|
62
|
+
`[s, p, o]` Term triples for CONSTRUCT/DESCRIBE. A `Term` carries `.kind` /
|
|
63
|
+
`.value` / `.datatype` / `.lang`, plus `.toJS()` (number/boolean/BigInt for
|
|
64
|
+
common XSD types) and `.n3`. Also: `queryRaw`, `query(q, {reason: true})`
|
|
65
|
+
(OWL 2 QL entailment), `prefixSearch`, `textSearch`, `schema`, `graphNames`,
|
|
66
|
+
`info`, and on remote graphs `stats()` / `contentHash()`.
|
|
67
|
+
|
|
68
|
+
## Building from source
|
|
69
|
+
|
|
70
|
+
The package builds its wasm engine fresh from the repo's crates:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
# from clients/js (needs Rust + wasm-pack; repo convention is Docker)
|
|
74
|
+
bash build-wasm.sh # crates/rete-wasm -> vendor/pkg
|
|
75
|
+
npm install && npm test
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Releases are published to npm by `.github/workflows/js-client-publish.yml`
|
|
79
|
+
on a `js-v*` tag. Docs: <https://caviri.github.io/rete/javascript.html>.
|