holos-wasm 0.17.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 +59 -0
- package/holos_wasm.d.ts +42 -0
- package/holos_wasm_bg.js +66 -0
- package/holos_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,11 +85,70 @@ facilities.
|
|
|
85
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. |
|
|
86
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. |
|
|
87
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. |
|
|
88
89
|
| **One thread** | A load parses and interns in one serial loop rather than overlapping them. Same answer, same order, less throughput. |
|
|
89
90
|
|
|
90
91
|
Bringing the timeout back means a cooperative deadline checked in the row loop, with the
|
|
91
92
|
clock routed through the host. That is the one reduction above that is worth revisiting.
|
|
92
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
|
+
|
|
93
152
|
## Four things had to be cfg-ed for this target
|
|
94
153
|
|
|
95
154
|
The compile-time surface was almost nothing — one getrandom error. The work was runtime:
|
package/holos_wasm.d.ts
CHANGED
|
@@ -7,6 +7,15 @@
|
|
|
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;
|
|
10
19
|
/**
|
|
11
20
|
* Everything the store holds, serialised in `format`.
|
|
12
21
|
*
|
|
@@ -36,6 +45,39 @@ export class Store {
|
|
|
36
45
|
* A new, empty store.
|
|
37
46
|
*/
|
|
38
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;
|
|
39
81
|
/**
|
|
40
82
|
* Run a CONSTRUCT or DESCRIBE and return the graph serialised in `format`.
|
|
41
83
|
*
|
package/holos_wasm_bg.js
CHANGED
|
@@ -12,6 +12,26 @@ export class Store {
|
|
|
12
12
|
const ptr = this.__destroy_into_raw();
|
|
13
13
|
wasm.__wbg_store_free(ptr, 0);
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Give the store an endpoint's answer to one of `queryFederated`'s pending queries.
|
|
17
|
+
*
|
|
18
|
+
* `results` is SPARQL Results JSON, which is what an endpoint returns for
|
|
19
|
+
* `Accept: application/sparql-results+json`. `query` must be the string the pending entry
|
|
20
|
+
* carried, byte for byte: it is the cache key, so a reformatted query is a different
|
|
21
|
+
* question and will be asked again.
|
|
22
|
+
* @param {string} endpoint
|
|
23
|
+
* @param {string} query
|
|
24
|
+
* @param {string} results
|
|
25
|
+
*/
|
|
26
|
+
cacheService(endpoint, query, results) {
|
|
27
|
+
const ptr0 = passStringToWasm0(endpoint, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
28
|
+
const len0 = WASM_VECTOR_LEN;
|
|
29
|
+
const ptr1 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
30
|
+
const len1 = WASM_VECTOR_LEN;
|
|
31
|
+
const ptr2 = passStringToWasm0(results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
32
|
+
const len2 = WASM_VECTOR_LEN;
|
|
33
|
+
wasm.store_cacheService(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
34
|
+
}
|
|
15
35
|
/**
|
|
16
36
|
* Distinct terms in the dictionary.
|
|
17
37
|
*
|
|
@@ -107,6 +127,52 @@ export class Store {
|
|
|
107
127
|
StoreFinalization.register(this, this.__wbg_ptr, this);
|
|
108
128
|
return this;
|
|
109
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Run a query that may contain `SERVICE`, one pass at a time.
|
|
132
|
+
*
|
|
133
|
+
* Returns `{pending: [{endpoint, query}, …]}` when the engine asked for an endpoint this
|
|
134
|
+
* store has no answer for, and `{result: …}` -- shaped exactly as `query` returns -- when
|
|
135
|
+
* it did not. The host fetches each pending query, hands it back with `cacheService`, and
|
|
136
|
+
* calls this again:
|
|
137
|
+
*
|
|
138
|
+
* ```js
|
|
139
|
+
* for (let round = 0; round < 8; round += 1) {
|
|
140
|
+
* const pass = store.queryFederated(q, undefined);
|
|
141
|
+
* if (!pass.pending.length) return pass.result;
|
|
142
|
+
* for (const { endpoint, query } of pass.pending) {
|
|
143
|
+
* // The host decides what may be called. Nothing in the wasm can reach the network.
|
|
144
|
+
* store.cacheService(endpoint, query, await fetchSparqlJson(endpoint, query));
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* throw new Error('SERVICE did not settle');
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* **A pass with anything pending has wrong results, and says so by having them.** The
|
|
151
|
+
* unanswered `SERVICE` contributed no rows, so the join above it lost rows too. Discard
|
|
152
|
+
* `result` whenever `pending` is non-empty rather than showing it.
|
|
153
|
+
*
|
|
154
|
+
* More than two rounds are possible and not a fault: a `SERVICE` whose pattern carries
|
|
155
|
+
* bindings from an earlier join only takes its final shape once that join has rows, so an
|
|
156
|
+
* answer can reveal a request that could not have been seen before. The cap belongs to the
|
|
157
|
+
* host because only the host knows how long it is prepared to wait.
|
|
158
|
+
*
|
|
159
|
+
* A query with no `SERVICE` never consults the handler, so `pending` is empty and this is
|
|
160
|
+
* `query` with one more allocation.
|
|
161
|
+
* @param {string} query
|
|
162
|
+
* @param {string | null} [base]
|
|
163
|
+
* @returns {any}
|
|
164
|
+
*/
|
|
165
|
+
queryFederated(query, base) {
|
|
166
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
167
|
+
const len0 = WASM_VECTOR_LEN;
|
|
168
|
+
var ptr1 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
169
|
+
var len1 = WASM_VECTOR_LEN;
|
|
170
|
+
const ret = wasm.store_queryFederated(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
171
|
+
if (ret[2]) {
|
|
172
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
173
|
+
}
|
|
174
|
+
return takeFromExternrefTable0(ret[0]);
|
|
175
|
+
}
|
|
110
176
|
/**
|
|
111
177
|
* Run a CONSTRUCT or DESCRIBE and return the graph serialised in `format`.
|
|
112
178
|
*
|
package/holos_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "holos-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly bindings for the HOLOS RDF 1.2 store and SPARQL 1.2 engine (ESM, for bundlers)",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.18.0",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|