holos-wasm-node 0.16.0 → 0.18.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 +96 -6
- package/holos_wasm.d.ts +87 -5
- package/holos_wasm.js +178 -6
- package/holos_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,18 +30,49 @@ const holos = require('./pkg-node/holos_wasm.js');
|
|
|
30
30
|
const store = new holos.Store();
|
|
31
31
|
store.loadTurtle('<urn:a> <urn:p> "x" .', undefined);
|
|
32
32
|
|
|
33
|
-
store.query('ASK { ?s ?p ?o }', undefined);
|
|
34
|
-
store.query('SELECT ?s WHERE { ?s ?p ?o }', undefined);
|
|
33
|
+
store.query('ASK { ?s ?p ?o }', undefined); // true
|
|
34
|
+
store.query('SELECT ?s WHERE { ?s ?p ?o }', undefined); // [{ s: { termType: 'NamedNode',
|
|
35
|
+
// value: 'urn:a' } }]
|
|
35
36
|
store.query('CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }', undefined);
|
|
36
|
-
|
|
37
|
+
// ['<urn:a> <urn:p> "x"']
|
|
38
|
+
store.queryRdf('CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }', 'turtle', undefined);
|
|
39
|
+
// '<urn:a> <urn:p> "x" .
|
|
40
|
+
'
|
|
41
|
+
store.update('INSERT DATA { <urn:b> <urn:p> "y" }', undefined);
|
|
42
|
+
// { inserted: 1, deleted: 0, graphsCreated: 0, … }
|
|
43
|
+
store.dump('nquads'); // everything the store holds
|
|
37
44
|
```
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
| What you get back | From |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `true` / `false` | ASK |
|
|
49
|
+
| terms in rdf-js shape — `{termType, value}`, plus `language` and `datatype` on a literal | SELECT |
|
|
50
|
+
| N-Triples strings, one per triple, no trailing separator | CONSTRUCT, DESCRIBE |
|
|
51
|
+
| a document in the format you asked for | `queryRdf` |
|
|
52
|
+
| `{inserted, deleted, graphsCreated, graphsDropped}` | `update` |
|
|
53
|
+
|
|
54
|
+
**SELECT returns terms, not strings, since 0.17.0.** They used to be N-Triples strings,
|
|
55
|
+
which made every consumer parse term syntax to reach a value, and no RDF library in JS
|
|
56
|
+
accepts a bare term string as input. `{termType, value}` is what rdf-js specifies and what
|
|
57
|
+
oxigraph returns, so a term can go straight to n3 or be compared field by field. A blank
|
|
58
|
+
node's `value` is the bare label, without `_:` — and it is this engine's label, not the one
|
|
59
|
+
in whatever document was loaded, because a parser may rename blank nodes and this one does.
|
|
60
|
+
|
|
61
|
+
CONSTRUCT stays N-Triples strings deliberately: it is the one serialisation every RDF
|
|
62
|
+
library in JS parses without first agreeing on a term model, and a graph is usually wanted
|
|
63
|
+
as a graph. `queryRdf` is there when a *document* is wanted instead — a preview pane showing
|
|
64
|
+
Turtle, or a payload for something that parses RDF but does not speak these shapes.
|
|
65
|
+
|
|
42
66
|
An unbound variable is left *off* a SELECT row rather than set to `null`: RDF has no null,
|
|
43
67
|
and "no value here" is a different fact from "the value null".
|
|
44
68
|
|
|
69
|
+
`dump` is a document rather than a quad iterator, because crossing the boundary once with a
|
|
70
|
+
document beats crossing it once per quad and every JS RDF library can parse what comes back.
|
|
71
|
+
Use `nquads` or `trig` for a store with named graphs: Turtle and N-Triples have nowhere to
|
|
72
|
+
put a graph name, and the serialiser **refuses** such a quad rather than writing it into the
|
|
73
|
+
default graph. That is the right choice — flattening would move data between graphs while
|
|
74
|
+
reporting success — and the error names the formats that work.
|
|
75
|
+
|
|
45
76
|
## What this build cannot do
|
|
46
77
|
|
|
47
78
|
Each of these is a property of the host, not of the engine. None is a stripped-down
|
|
@@ -54,11 +85,70 @@ facilities.
|
|
|
54
85
|
| **No file paths** | `std::fs` compiles for wasm32 and fails at runtime. RDF arrives as a string the host has already read, so a load costs memory proportional to the document — a browser tab is not where a 60 GB dump goes. |
|
|
55
86
|
| **No spilling `ORDER BY`** | The external merge sort needs somewhere to put run files. A sort is bounded by memory here, and a large one exhausts the module rather than reaching for disk. |
|
|
56
87
|
| **No timeout, no memory ceiling** | Both are enforced by a watchdog thread sampling a clock, and this target has neither. `QueryOptions::guard` returns `None`, and this crate exposes no way to ask — so nobody can set a limit and believe it is being honoured. |
|
|
88
|
+
| **No network** | There is no HTTP client in here at all. `SERVICE` works, but only because the *host* fetches and hands the answer in — see below. |
|
|
57
89
|
| **One thread** | A load parses and interns in one serial loop rather than overlapping them. Same answer, same order, less throughput. |
|
|
58
90
|
|
|
59
91
|
Bringing the timeout back means a cooperative deadline checked in the row loop, with the
|
|
60
92
|
clock routed through the host. That is the one reduction above that is worth revisiting.
|
|
61
93
|
|
|
94
|
+
## `SERVICE`, without a network client
|
|
95
|
+
|
|
96
|
+
`store.query()` cannot answer a `SERVICE` clause. `store.queryFederated()` can, by asking the
|
|
97
|
+
host to do the fetching:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
for (let round = 0; round < 8; round += 1) {
|
|
101
|
+
const pass = store.queryFederated(query, undefined);
|
|
102
|
+
if (!pass.pending.length) return pass.result;
|
|
103
|
+
for (const { endpoint, query: ask } of pass.pending) {
|
|
104
|
+
// The host decides what may be called. Nothing in the wasm can reach the network.
|
|
105
|
+
const res = await fetch(endpoint, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: { 'Content-Type': 'application/sparql-query',
|
|
108
|
+
Accept: 'application/sparql-results+json' },
|
|
109
|
+
body: ask,
|
|
110
|
+
});
|
|
111
|
+
store.cacheService(endpoint, ask, await res.text());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
throw new Error('SERVICE did not settle');
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**A pass with anything `pending` has wrong results, and says so by having them.** The
|
|
118
|
+
unanswered `SERVICE` contributed no rows, so the join above it lost rows too. Discard `result`
|
|
119
|
+
whenever `pending` is non-empty rather than showing it.
|
|
120
|
+
|
|
121
|
+
### Why it is shaped like this
|
|
122
|
+
|
|
123
|
+
`spareval::DefaultServiceHandler::handle` is synchronous and `fetch` is not, and you cannot
|
|
124
|
+
await a Promise from synchronous wasm. Three ways round that, and they commit you to different
|
|
125
|
+
things:
|
|
126
|
+
|
|
127
|
+
| | Cost |
|
|
128
|
+
|---|---|
|
|
129
|
+
| synchronous `XMLHttpRequest` | deprecated, warns in every browser, blocks the tab, may stop working |
|
|
130
|
+
| a worker blocking on `Atomics.wait` | needs COOP/COEP cross-origin-isolation headers wherever the app is hosted, and breaks quietly if they are lost |
|
|
131
|
+
| **asking twice** | the query is evaluated more than once |
|
|
132
|
+
|
|
133
|
+
The third is what this does. It buys no deprecated API, no hosting requirement, and an
|
|
134
|
+
allow-list that lives in the host — which is the part that matters. `holos-engine`'s own
|
|
135
|
+
`service` module refuses remote `SERVICE` because on a *server* it is an SSRF primitive: a
|
|
136
|
+
query from a stranger makes the server fetch an address of the stranger's choosing. That
|
|
137
|
+
objection does not transfer here, and not because a browser is safer — because **this crate
|
|
138
|
+
cannot make a request at all**. There is nothing to point anywhere. The fetch is the host's, in
|
|
139
|
+
the user's own browser, with the user's own network position and CORS between them.
|
|
140
|
+
|
|
141
|
+
### More than two rounds is normal
|
|
142
|
+
|
|
143
|
+
A `SERVICE` whose pattern carries bindings from an earlier join only takes its final shape once
|
|
144
|
+
that join has rows, and the first pass gives it none — so an answer can reveal a request that
|
|
145
|
+
could not have been seen before. The same semi-naive iteration the rules engine uses. The cap
|
|
146
|
+
belongs to the host, because only the host knows how long it will wait.
|
|
147
|
+
|
|
148
|
+
The cache key is `(endpoint, query)` and the query is byte-exact: a reformatted query is a
|
|
149
|
+
different question and will be asked again. That is deliberate — matching a near-miss would
|
|
150
|
+
serve one endpoint's answer to another's question.
|
|
151
|
+
|
|
62
152
|
## Four things had to be cfg-ed for this target
|
|
63
153
|
|
|
64
154
|
The compile-time surface was almost nothing — one getrandom error. The work was runtime:
|
package/holos_wasm.d.ts
CHANGED
|
@@ -7,6 +7,29 @@
|
|
|
7
7
|
export class Store {
|
|
8
8
|
free(): void;
|
|
9
9
|
[Symbol.dispose](): void;
|
|
10
|
+
/**
|
|
11
|
+
* Give the store an endpoint's answer to one of `queryFederated`'s pending queries.
|
|
12
|
+
*
|
|
13
|
+
* `results` is SPARQL Results JSON, which is what an endpoint returns for
|
|
14
|
+
* `Accept: application/sparql-results+json`. `query` must be the string the pending entry
|
|
15
|
+
* carried, byte for byte: it is the cache key, so a reformatted query is a different
|
|
16
|
+
* question and will be asked again.
|
|
17
|
+
*/
|
|
18
|
+
cacheService(endpoint: string, query: string, results: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Everything the store holds, serialised in `format`.
|
|
21
|
+
*
|
|
22
|
+
* Use N-Quads or TriG for a store with named graphs. Turtle and N-Triples have nowhere
|
|
23
|
+
* to put a graph name, and the serialiser **refuses** such a quad rather than writing
|
|
24
|
+
* it into the default graph — measured, and the right behaviour: flattening would move
|
|
25
|
+
* data between graphs while reporting success. The error says which formats can carry
|
|
26
|
+
* it. A store with only a default graph serialises to any of the four.
|
|
27
|
+
*
|
|
28
|
+
* This is how a caller enumerates the store: there is no quad iterator on this binding,
|
|
29
|
+
* because crossing the boundary once with a document beats crossing it once per quad,
|
|
30
|
+
* and every JS RDF library can parse what comes back.
|
|
31
|
+
*/
|
|
32
|
+
dump(format: string): string;
|
|
10
33
|
/**
|
|
11
34
|
* Load Turtle, which is the common case.
|
|
12
35
|
*/
|
|
@@ -22,18 +45,77 @@ export class Store {
|
|
|
22
45
|
* A new, empty store.
|
|
23
46
|
*/
|
|
24
47
|
constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Run a query that may contain `SERVICE`, one pass at a time.
|
|
50
|
+
*
|
|
51
|
+
* Returns `{pending: [{endpoint, query}, …]}` when the engine asked for an endpoint this
|
|
52
|
+
* store has no answer for, and `{result: …}` -- shaped exactly as `query` returns -- when
|
|
53
|
+
* it did not. The host fetches each pending query, hands it back with `cacheService`, and
|
|
54
|
+
* calls this again:
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* for (let round = 0; round < 8; round += 1) {
|
|
58
|
+
* const pass = store.queryFederated(q, undefined);
|
|
59
|
+
* if (!pass.pending.length) return pass.result;
|
|
60
|
+
* for (const { endpoint, query } of pass.pending) {
|
|
61
|
+
* // The host decides what may be called. Nothing in the wasm can reach the network.
|
|
62
|
+
* store.cacheService(endpoint, query, await fetchSparqlJson(endpoint, query));
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* throw new Error('SERVICE did not settle');
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* **A pass with anything pending has wrong results, and says so by having them.** The
|
|
69
|
+
* unanswered `SERVICE` contributed no rows, so the join above it lost rows too. Discard
|
|
70
|
+
* `result` whenever `pending` is non-empty rather than showing it.
|
|
71
|
+
*
|
|
72
|
+
* More than two rounds are possible and not a fault: a `SERVICE` whose pattern carries
|
|
73
|
+
* bindings from an earlier join only takes its final shape once that join has rows, so an
|
|
74
|
+
* answer can reveal a request that could not have been seen before. The cap belongs to the
|
|
75
|
+
* host because only the host knows how long it is prepared to wait.
|
|
76
|
+
*
|
|
77
|
+
* A query with no `SERVICE` never consults the handler, so `pending` is empty and this is
|
|
78
|
+
* `query` with one more allocation.
|
|
79
|
+
*/
|
|
80
|
+
queryFederated(query: string, base?: string | null): any;
|
|
81
|
+
/**
|
|
82
|
+
* Run a CONSTRUCT or DESCRIBE and return the graph serialised in `format`.
|
|
83
|
+
*
|
|
84
|
+
* For when a caller wants a *document* rather than terms: a preview pane showing
|
|
85
|
+
* Turtle, or a payload to hand to something that parses RDF but does not speak this
|
|
86
|
+
* binding's shapes. `query` remains the way to get the triples themselves.
|
|
87
|
+
*
|
|
88
|
+
* A SELECT or ASK is refused rather than serialised, because neither produces a graph
|
|
89
|
+
* and "here is an empty document" would be the wrong way to say so.
|
|
90
|
+
*/
|
|
91
|
+
queryRdf(query: string, format: string, base?: string | null): string;
|
|
25
92
|
/**
|
|
26
93
|
* Run a SPARQL 1.2 query.
|
|
27
94
|
*
|
|
28
95
|
* Returns a boolean for ASK, an array of N-Triples strings for CONSTRUCT and DESCRIBE,
|
|
29
|
-
* and an array of objects keyed by variable name
|
|
30
|
-
*
|
|
31
|
-
*
|
|
96
|
+
* and for SELECT an array of objects keyed by variable name whose values are terms in
|
|
97
|
+
* RDF/JS shape — `{termType, value}`, plus `language` and `datatype` on a literal.
|
|
98
|
+
*
|
|
99
|
+
* **Terms rather than strings, since 0.17.0.** They were rendered as N-Triples strings,
|
|
100
|
+
* which made every consumer parse term syntax to get at a value, and no RDF library in
|
|
101
|
+
* JS accepts a bare term string as input. `{termType, value}` is what rdf-js specifies
|
|
102
|
+
* and what oxigraph returns, so a caller can hand these straight to n3 or compare them
|
|
103
|
+
* field by field. `queryRdf` is there for when a *document* is wanted instead.
|
|
32
104
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
105
|
+
* CONSTRUCT stays N-Triples strings, deliberately: it is one serialisation every RDF
|
|
106
|
+
* library in JS can parse without first agreeing on a term model, and a graph is
|
|
107
|
+
* usually wanted as a graph. A returned triple carries no trailing separator, matching
|
|
108
|
+
* the Python bindings; a caller reassembling a document adds one.
|
|
35
109
|
*/
|
|
36
110
|
query(query: string, base?: string | null): any;
|
|
111
|
+
/**
|
|
112
|
+
* Apply a SPARQL 1.1 Update, returning what changed:
|
|
113
|
+
* `{inserted, deleted, graphsCreated, graphsDropped}`.
|
|
114
|
+
*
|
|
115
|
+
* **All-or-nothing.** If any operation fails the store is left exactly as it was, so a
|
|
116
|
+
* refused write cannot leave half an update behind.
|
|
117
|
+
*/
|
|
118
|
+
update(update: string, base?: string | null): any;
|
|
37
119
|
/**
|
|
38
120
|
* Distinct terms in the dictionary.
|
|
39
121
|
*
|
package/holos_wasm.js
CHANGED
|
@@ -14,6 +14,26 @@ class Store {
|
|
|
14
14
|
const ptr = this.__destroy_into_raw();
|
|
15
15
|
wasm.__wbg_store_free(ptr, 0);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Give the store an endpoint's answer to one of `queryFederated`'s pending queries.
|
|
19
|
+
*
|
|
20
|
+
* `results` is SPARQL Results JSON, which is what an endpoint returns for
|
|
21
|
+
* `Accept: application/sparql-results+json`. `query` must be the string the pending entry
|
|
22
|
+
* carried, byte for byte: it is the cache key, so a reformatted query is a different
|
|
23
|
+
* question and will be asked again.
|
|
24
|
+
* @param {string} endpoint
|
|
25
|
+
* @param {string} query
|
|
26
|
+
* @param {string} results
|
|
27
|
+
*/
|
|
28
|
+
cacheService(endpoint, query, results) {
|
|
29
|
+
const ptr0 = passStringToWasm0(endpoint, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
30
|
+
const len0 = WASM_VECTOR_LEN;
|
|
31
|
+
const ptr1 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
32
|
+
const len1 = WASM_VECTOR_LEN;
|
|
33
|
+
const ptr2 = passStringToWasm0(results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
34
|
+
const len2 = WASM_VECTOR_LEN;
|
|
35
|
+
wasm.store_cacheService(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
36
|
+
}
|
|
17
37
|
/**
|
|
18
38
|
* Distinct terms in the dictionary.
|
|
19
39
|
*
|
|
@@ -25,6 +45,41 @@ class Store {
|
|
|
25
45
|
const ret = wasm.store_dictionarySize(this.__wbg_ptr);
|
|
26
46
|
return ret >>> 0;
|
|
27
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Everything the store holds, serialised in `format`.
|
|
50
|
+
*
|
|
51
|
+
* Use N-Quads or TriG for a store with named graphs. Turtle and N-Triples have nowhere
|
|
52
|
+
* to put a graph name, and the serialiser **refuses** such a quad rather than writing
|
|
53
|
+
* it into the default graph — measured, and the right behaviour: flattening would move
|
|
54
|
+
* data between graphs while reporting success. The error says which formats can carry
|
|
55
|
+
* it. A store with only a default graph serialises to any of the four.
|
|
56
|
+
*
|
|
57
|
+
* This is how a caller enumerates the store: there is no quad iterator on this binding,
|
|
58
|
+
* because crossing the boundary once with a document beats crossing it once per quad,
|
|
59
|
+
* and every JS RDF library can parse what comes back.
|
|
60
|
+
* @param {string} format
|
|
61
|
+
* @returns {string}
|
|
62
|
+
*/
|
|
63
|
+
dump(format) {
|
|
64
|
+
let deferred3_0;
|
|
65
|
+
let deferred3_1;
|
|
66
|
+
try {
|
|
67
|
+
const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
68
|
+
const len0 = WASM_VECTOR_LEN;
|
|
69
|
+
const ret = wasm.store_dump(this.__wbg_ptr, ptr0, len0);
|
|
70
|
+
var ptr2 = ret[0];
|
|
71
|
+
var len2 = ret[1];
|
|
72
|
+
if (ret[3]) {
|
|
73
|
+
ptr2 = 0; len2 = 0;
|
|
74
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
75
|
+
}
|
|
76
|
+
deferred3_0 = ptr2;
|
|
77
|
+
deferred3_1 = len2;
|
|
78
|
+
return getStringFromWasm0(ptr2, len2);
|
|
79
|
+
} finally {
|
|
80
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
28
83
|
/**
|
|
29
84
|
* Load Turtle, which is the common case.
|
|
30
85
|
* @param {string} text
|
|
@@ -74,16 +129,107 @@ class Store {
|
|
|
74
129
|
StoreFinalization.register(this, this.__wbg_ptr, this);
|
|
75
130
|
return this;
|
|
76
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Run a query that may contain `SERVICE`, one pass at a time.
|
|
134
|
+
*
|
|
135
|
+
* Returns `{pending: [{endpoint, query}, …]}` when the engine asked for an endpoint this
|
|
136
|
+
* store has no answer for, and `{result: …}` -- shaped exactly as `query` returns -- when
|
|
137
|
+
* it did not. The host fetches each pending query, hands it back with `cacheService`, and
|
|
138
|
+
* calls this again:
|
|
139
|
+
*
|
|
140
|
+
* ```js
|
|
141
|
+
* for (let round = 0; round < 8; round += 1) {
|
|
142
|
+
* const pass = store.queryFederated(q, undefined);
|
|
143
|
+
* if (!pass.pending.length) return pass.result;
|
|
144
|
+
* for (const { endpoint, query } of pass.pending) {
|
|
145
|
+
* // The host decides what may be called. Nothing in the wasm can reach the network.
|
|
146
|
+
* store.cacheService(endpoint, query, await fetchSparqlJson(endpoint, query));
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* throw new Error('SERVICE did not settle');
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* **A pass with anything pending has wrong results, and says so by having them.** The
|
|
153
|
+
* unanswered `SERVICE` contributed no rows, so the join above it lost rows too. Discard
|
|
154
|
+
* `result` whenever `pending` is non-empty rather than showing it.
|
|
155
|
+
*
|
|
156
|
+
* More than two rounds are possible and not a fault: a `SERVICE` whose pattern carries
|
|
157
|
+
* bindings from an earlier join only takes its final shape once that join has rows, so an
|
|
158
|
+
* answer can reveal a request that could not have been seen before. The cap belongs to the
|
|
159
|
+
* host because only the host knows how long it is prepared to wait.
|
|
160
|
+
*
|
|
161
|
+
* A query with no `SERVICE` never consults the handler, so `pending` is empty and this is
|
|
162
|
+
* `query` with one more allocation.
|
|
163
|
+
* @param {string} query
|
|
164
|
+
* @param {string | null} [base]
|
|
165
|
+
* @returns {any}
|
|
166
|
+
*/
|
|
167
|
+
queryFederated(query, base) {
|
|
168
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
169
|
+
const len0 = WASM_VECTOR_LEN;
|
|
170
|
+
var ptr1 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
171
|
+
var len1 = WASM_VECTOR_LEN;
|
|
172
|
+
const ret = wasm.store_queryFederated(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
173
|
+
if (ret[2]) {
|
|
174
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
175
|
+
}
|
|
176
|
+
return takeFromExternrefTable0(ret[0]);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Run a CONSTRUCT or DESCRIBE and return the graph serialised in `format`.
|
|
180
|
+
*
|
|
181
|
+
* For when a caller wants a *document* rather than terms: a preview pane showing
|
|
182
|
+
* Turtle, or a payload to hand to something that parses RDF but does not speak this
|
|
183
|
+
* binding's shapes. `query` remains the way to get the triples themselves.
|
|
184
|
+
*
|
|
185
|
+
* A SELECT or ASK is refused rather than serialised, because neither produces a graph
|
|
186
|
+
* and "here is an empty document" would be the wrong way to say so.
|
|
187
|
+
* @param {string} query
|
|
188
|
+
* @param {string} format
|
|
189
|
+
* @param {string | null} [base]
|
|
190
|
+
* @returns {string}
|
|
191
|
+
*/
|
|
192
|
+
queryRdf(query, format, base) {
|
|
193
|
+
let deferred5_0;
|
|
194
|
+
let deferred5_1;
|
|
195
|
+
try {
|
|
196
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
197
|
+
const len0 = WASM_VECTOR_LEN;
|
|
198
|
+
const ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
199
|
+
const len1 = WASM_VECTOR_LEN;
|
|
200
|
+
var ptr2 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
201
|
+
var len2 = WASM_VECTOR_LEN;
|
|
202
|
+
const ret = wasm.store_queryRdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
203
|
+
var ptr4 = ret[0];
|
|
204
|
+
var len4 = ret[1];
|
|
205
|
+
if (ret[3]) {
|
|
206
|
+
ptr4 = 0; len4 = 0;
|
|
207
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
208
|
+
}
|
|
209
|
+
deferred5_0 = ptr4;
|
|
210
|
+
deferred5_1 = len4;
|
|
211
|
+
return getStringFromWasm0(ptr4, len4);
|
|
212
|
+
} finally {
|
|
213
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
77
216
|
/**
|
|
78
217
|
* Run a SPARQL 1.2 query.
|
|
79
218
|
*
|
|
80
219
|
* Returns a boolean for ASK, an array of N-Triples strings for CONSTRUCT and DESCRIBE,
|
|
81
|
-
* and an array of objects keyed by variable name
|
|
82
|
-
*
|
|
83
|
-
*
|
|
220
|
+
* and for SELECT an array of objects keyed by variable name whose values are terms in
|
|
221
|
+
* RDF/JS shape — `{termType, value}`, plus `language` and `datatype` on a literal.
|
|
222
|
+
*
|
|
223
|
+
* **Terms rather than strings, since 0.17.0.** They were rendered as N-Triples strings,
|
|
224
|
+
* which made every consumer parse term syntax to get at a value, and no RDF library in
|
|
225
|
+
* JS accepts a bare term string as input. `{termType, value}` is what rdf-js specifies
|
|
226
|
+
* and what oxigraph returns, so a caller can hand these straight to n3 or compare them
|
|
227
|
+
* field by field. `queryRdf` is there for when a *document* is wanted instead.
|
|
84
228
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
229
|
+
* CONSTRUCT stays N-Triples strings, deliberately: it is one serialisation every RDF
|
|
230
|
+
* library in JS can parse without first agreeing on a term model, and a graph is
|
|
231
|
+
* usually wanted as a graph. A returned triple carries no trailing separator, matching
|
|
232
|
+
* the Python bindings; a caller reassembling a document adds one.
|
|
87
233
|
* @param {string} query
|
|
88
234
|
* @param {string | null} [base]
|
|
89
235
|
* @returns {any}
|
|
@@ -107,6 +253,27 @@ class Store {
|
|
|
107
253
|
const ret = wasm.store_size(this.__wbg_ptr);
|
|
108
254
|
return ret >>> 0;
|
|
109
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Apply a SPARQL 1.1 Update, returning what changed:
|
|
258
|
+
* `{inserted, deleted, graphsCreated, graphsDropped}`.
|
|
259
|
+
*
|
|
260
|
+
* **All-or-nothing.** If any operation fails the store is left exactly as it was, so a
|
|
261
|
+
* refused write cannot leave half an update behind.
|
|
262
|
+
* @param {string} update
|
|
263
|
+
* @param {string | null} [base]
|
|
264
|
+
* @returns {any}
|
|
265
|
+
*/
|
|
266
|
+
update(update, base) {
|
|
267
|
+
const ptr0 = passStringToWasm0(update, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
268
|
+
const len0 = WASM_VECTOR_LEN;
|
|
269
|
+
var ptr1 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
270
|
+
var len1 = WASM_VECTOR_LEN;
|
|
271
|
+
const ret = wasm.store_update(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
272
|
+
if (ret[2]) {
|
|
273
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
274
|
+
}
|
|
275
|
+
return takeFromExternrefTable0(ret[0]);
|
|
276
|
+
}
|
|
110
277
|
}
|
|
111
278
|
if (Symbol.dispose) Store.prototype[Symbol.dispose] = Store.prototype.free;
|
|
112
279
|
exports.Store = Store;
|
|
@@ -173,7 +340,12 @@ function __wbg_get_imports() {
|
|
|
173
340
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
174
341
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
175
342
|
},
|
|
176
|
-
__wbindgen_generic_0000000000000001: function(arg0
|
|
343
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
344
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
345
|
+
const ret = arg0;
|
|
346
|
+
return ret;
|
|
347
|
+
},
|
|
348
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
177
349
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
178
350
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
179
351
|
return ret;
|
package/holos_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "holos-wasm-node",
|
|
3
3
|
"description": "WebAssembly bindings for the HOLOS RDF 1.2 store and SPARQL 1.2 engine (CommonJS, for Node and require())",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|