@wazootech/sparql-engine 0.0.0-stage → 0.5.8

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.
@@ -0,0 +1,416 @@
1
+ import { t as DataFactory$1 } from "./data-factory-76Dxrf0g.js";
2
+ import "./term-s9I2y-ck.js";
3
+ // src/term/numeric-format.ts
4
+ /**
5
+ * numeric-format.ts renders numeric values as lexical forms.
6
+ */
7
+ /**
8
+ * formatNumber renders a numeric value's Number string form. No datatype
9
+ * padding is applied: like Comunica, decimal results use plain JS string
10
+ * forms (6/3 -> "2", not "2.0"). Double and float results keep the Number
11
+ * string form; canonicalDouble (used by the XSD constructors and the
12
+ * aggregates) produces the canonical XPath exponent form instead. Infinity and
13
+ * NaN take their XML Schema spellings.
14
+ */
15
+ function formatNumber(value, _datatype) {
16
+ if (Number.isNaN(value)) return "NaN";
17
+ if (!Number.isFinite(value)) return value > 0 ? "INF" : "-INF";
18
+ return String(value);
19
+ }
20
+ /**
21
+ * canonicalDouble renders a number in the canonical XPath double lexical
22
+ * form: a mantissa with at least one decimal digit and an exponent with no
23
+ * leading plus ("3.0E0", "1.5E0", "1.0E21", "INF", "-INF").
24
+ */
25
+ function canonicalDouble(n) {
26
+ if (Number.isNaN(n)) return "NaN";
27
+ if (n === 0) return "0.0E0";
28
+ if (!Number.isFinite(n)) return n > 0 ? "INF" : "-INF";
29
+ const [mantissa, exponent] = n.toExponential().split("e");
30
+ return `${mantissa.includes(".") ? mantissa : `${mantissa}.0`}E${exponent.startsWith("+") ? exponent.slice(1) : exponent}`;
31
+ }
32
+ // src/term/sha1.ts
33
+ /**
34
+ * sha1Hex returns the SHA-1 digest of the UTF-8 encoding of the input as
35
+ * lowercase hexadecimal.
36
+ */
37
+ function sha1Hex(input) {
38
+ const bytes = new TextEncoder().encode(input);
39
+ const bitLength = bytes.length * 8;
40
+ const paddedLength = (bytes.length + 8 >> 6) + 1 << 6;
41
+ const padded = new Uint8Array(paddedLength);
42
+ padded.set(bytes);
43
+ padded[bytes.length] = 128;
44
+ const view = new DataView(padded.buffer);
45
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296), false);
46
+ view.setUint32(paddedLength - 4, bitLength >>> 0, false);
47
+ let h0 = 0x67452301;
48
+ let h1 = 0xefcdab89;
49
+ let h2 = 0x98badcfe;
50
+ let h3 = 271733878;
51
+ let h4 = 0xc3d2e1f0;
52
+ const rotateLeft = (value, bits) => (value << bits | value >>> 32 - bits) >>> 0;
53
+ for (let offset = 0; offset < paddedLength; offset += 64) {
54
+ const w = new Array(80);
55
+ for (let index = 0; index < 16; index++) w[index] = view.getUint32(offset + index * 4, false);
56
+ for (let index = 16; index < 80; index++) w[index] = rotateLeft(w[index - 3] ^ w[index - 8] ^ w[index - 14] ^ w[index - 16], 1);
57
+ let a = h0;
58
+ let b = h1;
59
+ let c = h2;
60
+ let d = h3;
61
+ let e = h4;
62
+ for (let index = 0; index < 80; index++) {
63
+ let f;
64
+ let k;
65
+ if (index < 20) {
66
+ f = b & c | ~b & d;
67
+ k = 0x5a827999;
68
+ } else if (index < 40) {
69
+ f = b ^ c ^ d;
70
+ k = 0x6ed9eba1;
71
+ } else if (index < 60) {
72
+ f = b & c | b & d | c & d;
73
+ k = 0x8f1bbcdc;
74
+ } else {
75
+ f = b ^ c ^ d;
76
+ k = 0xca62c1d6;
77
+ }
78
+ const temp = rotateLeft(a, 5) + f + e + k + w[index] >>> 0;
79
+ e = d;
80
+ d = c;
81
+ c = rotateLeft(b, 30);
82
+ b = a;
83
+ a = temp;
84
+ }
85
+ h0 = h0 + a >>> 0;
86
+ h1 = h1 + b >>> 0;
87
+ h2 = h2 + c >>> 0;
88
+ h3 = h3 + d >>> 0;
89
+ h4 = h4 + e >>> 0;
90
+ }
91
+ const wordHex = (word) => word.toString(16).padStart(8, "0");
92
+ return wordHex(h0) + wordHex(h1) + wordHex(h2) + wordHex(h3) + wordHex(h4);
93
+ }
94
+ // src/term/sha256-constants.ts
95
+ const SHA256_K = [
96
+ 0x428a2f98,
97
+ 0x71374491,
98
+ 0xb5c0fbcf,
99
+ 0xe9b5dba5,
100
+ 961987163,
101
+ 0x59f111f1,
102
+ 0x923f82a4,
103
+ 0xab1c5ed5,
104
+ 0xd807aa98,
105
+ 310598401,
106
+ 607225278,
107
+ 0x550c7dc3,
108
+ 0x72be5d74,
109
+ 0x80deb1fe,
110
+ 0x9bdc06a7,
111
+ 0xc19bf174,
112
+ 0xe49b69c1,
113
+ 0xefbe4786,
114
+ 0xfc19dc6,
115
+ 604807628,
116
+ 770255983,
117
+ 0x4a7484aa,
118
+ 0x5cb0a9dc,
119
+ 0x76f988da,
120
+ 0x983e5152,
121
+ 0xa831c66d,
122
+ 0xb00327c8,
123
+ 0xbf597fc7,
124
+ 0xc6e00bf3,
125
+ 0xd5a79147,
126
+ 0x6ca6351,
127
+ 338241895,
128
+ 666307205,
129
+ 773529912,
130
+ 0x4d2c6dfc,
131
+ 0x53380d13,
132
+ 0x650a7354,
133
+ 0x766a0abb,
134
+ 0x81c2c92e,
135
+ 0x92722c85,
136
+ 0xa2bfe8a1,
137
+ 0xa81a664b,
138
+ 0xc24b8b70,
139
+ 0xc76c51a3,
140
+ 0xd192e819,
141
+ 0xd6990624,
142
+ 0xf40e3585,
143
+ 275423344,
144
+ 430227734,
145
+ 506948616,
146
+ 659060556,
147
+ 883997877,
148
+ 958139571,
149
+ 0x4ed8aa4a,
150
+ 0x5b9cca4f,
151
+ 0x682e6ff3,
152
+ 0x748f82ee,
153
+ 0x78a5636f,
154
+ 0x84c87814,
155
+ 0x8cc70208,
156
+ 0x90befffa,
157
+ 0xa4506ceb,
158
+ 0xbef9a3f7,
159
+ 0xc67178f2
160
+ ];
161
+ // src/term/sha256.ts
162
+ /**
163
+ * sha256Hex returns the SHA-256 digest of the UTF-8 encoding of the input as
164
+ * lowercase hexadecimal.
165
+ */
166
+ function sha256Hex(input) {
167
+ const bytes = new TextEncoder().encode(input);
168
+ const bitLength = bytes.length * 8;
169
+ const paddedLength = (bytes.length + 8 >> 6) + 1 << 6;
170
+ const padded = new Uint8Array(paddedLength);
171
+ padded.set(bytes);
172
+ padded[bytes.length] = 128;
173
+ const view = new DataView(padded.buffer);
174
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296), false);
175
+ view.setUint32(paddedLength - 4, bitLength >>> 0, false);
176
+ let h0 = 0x6a09e667;
177
+ let h1 = 0xbb67ae85;
178
+ let h2 = 0x3c6ef372;
179
+ let h3 = 0xa54ff53a;
180
+ let h4 = 0x510e527f;
181
+ let h5 = 0x9b05688c;
182
+ let h6 = 528734635;
183
+ let h7 = 0x5be0cd19;
184
+ const rotateRight = (value, bits) => (value >>> bits | value << 32 - bits) >>> 0;
185
+ for (let offset = 0; offset < paddedLength; offset += 64) {
186
+ const w = new Array(64);
187
+ for (let index = 0; index < 16; index++) w[index] = view.getUint32(offset + index * 4, false);
188
+ for (let index = 16; index < 64; index++) {
189
+ const s0 = rotateRight(w[index - 15], 7) ^ rotateRight(w[index - 15], 18) ^ w[index - 15] >>> 3;
190
+ const s1 = rotateRight(w[index - 2], 17) ^ rotateRight(w[index - 2], 19) ^ w[index - 2] >>> 10;
191
+ w[index] = w[index - 16] + s0 + w[index - 7] + s1 >>> 0;
192
+ }
193
+ let a = h0;
194
+ let b = h1;
195
+ let c = h2;
196
+ let d = h3;
197
+ let e = h4;
198
+ let f = h5;
199
+ let g = h6;
200
+ let h = h7;
201
+ for (let index = 0; index < 64; index++) {
202
+ const s1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
203
+ const ch = e & f ^ ~e & g;
204
+ const temp1 = h + s1 + ch + SHA256_K[index] + w[index] >>> 0;
205
+ const temp2 = (rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
206
+ h = g;
207
+ g = f;
208
+ f = e;
209
+ e = d + temp1 >>> 0;
210
+ d = c;
211
+ c = b;
212
+ b = a;
213
+ a = temp1 + temp2 >>> 0;
214
+ }
215
+ h0 = h0 + a >>> 0;
216
+ h1 = h1 + b >>> 0;
217
+ h2 = h2 + c >>> 0;
218
+ h3 = h3 + d >>> 0;
219
+ h4 = h4 + e >>> 0;
220
+ h5 = h5 + f >>> 0;
221
+ h6 = h6 + g >>> 0;
222
+ h7 = h7 + h >>> 0;
223
+ }
224
+ const wordHex = (word) => word.toString(16).padStart(8, "0");
225
+ return wordHex(h0) + wordHex(h1) + wordHex(h2) + wordHex(h3) + wordHex(h4) + wordHex(h5) + wordHex(h6) + wordHex(h7);
226
+ }
227
+ // src/term/sha512-constants.ts
228
+ const SHA512_K = [
229
+ 4794697086780616226n,
230
+ 8158064640168781261n,
231
+ 13096744586834688815n,
232
+ 16840607885511220156n,
233
+ 4131703408338449720n,
234
+ 6480981068601479193n,
235
+ 10538285296894168987n,
236
+ 12329834152419229976n,
237
+ 15566598209576043074n,
238
+ 1334009975649890238n,
239
+ 2608012711638119052n,
240
+ 6128411473006802146n,
241
+ 8268148722764581231n,
242
+ 9286055187155687089n,
243
+ 11230858885718282805n,
244
+ 13951009754708518548n,
245
+ 16472876342353939154n,
246
+ 17275323862435702243n,
247
+ 1135362057144423861n,
248
+ 2597628984639134821n,
249
+ 3308224258029322869n,
250
+ 5365058923640841347n,
251
+ 6679025012923562964n,
252
+ 8573033837759648693n,
253
+ 10970295158949994411n,
254
+ 12119686244451234320n,
255
+ 12683024718118986047n,
256
+ 13788192230050041572n,
257
+ 14330467153632333762n,
258
+ 15395433587784984357n,
259
+ 489312712824947311n,
260
+ 1452737877330783856n,
261
+ 2861767655752347644n,
262
+ 3322285676063803686n,
263
+ 5560940570517711597n,
264
+ 5996557281743188959n,
265
+ 7280758554555802590n,
266
+ 8532644243296465576n,
267
+ 9350256976987008742n,
268
+ 10552545826968843579n,
269
+ 11727347734174303076n,
270
+ 12113106623233404929n,
271
+ 14000437183269869457n,
272
+ 14369950271660146224n,
273
+ 15101387698204529176n,
274
+ 15463397548674623760n,
275
+ 17586052441742319658n,
276
+ 1182934255886127544n,
277
+ 1847814050463011016n,
278
+ 2177327727835720531n,
279
+ 2830643537854262169n,
280
+ 3796741975233480872n,
281
+ 4115178125766777443n,
282
+ 5681478168544905931n,
283
+ 6601373596472566643n,
284
+ 7507060721942968483n,
285
+ 8399075790359081724n,
286
+ 8693463985226723168n,
287
+ 9568029438360202098n,
288
+ 10144078919501101548n,
289
+ 10430055236837252648n,
290
+ 11840083180663258601n,
291
+ 13761210420658862357n,
292
+ 14299343276471374635n,
293
+ 14566680578165727644n,
294
+ 15097957966210449927n,
295
+ 16922976911328602910n,
296
+ 17689382322260857208n,
297
+ 500013540394364858n,
298
+ 748580250866718886n,
299
+ 1242879168328830382n,
300
+ 1977374033974150939n,
301
+ 2944078676154940804n,
302
+ 3659926193048069267n,
303
+ 4368137639120453308n,
304
+ 4836135668995329356n,
305
+ 5532061633213252278n,
306
+ 6448918945643986474n,
307
+ 6902733635092675308n,
308
+ 7801388544844847127n
309
+ ];
310
+ // src/term/sha512.ts
311
+ const MASK64 = 18446744073709551615n;
312
+ const rotateRight64 = (value, bits) => (value >> bits | value << 64n - bits) & MASK64;
313
+ /**
314
+ * sha512Digest runs the SHA-512 compression over the input with the given
315
+ * initial hash values, returning the 8 state words (or a prefix of them for
316
+ * SHA-384).
317
+ */
318
+ function sha512Words(input, initial) {
319
+ const bytes = new TextEncoder().encode(input);
320
+ const bitLength = BigInt(bytes.length * 8);
321
+ const paddedLength = (bytes.length + 16 >> 7) + 1 << 7;
322
+ const padded = new Uint8Array(paddedLength);
323
+ padded.set(bytes);
324
+ padded[bytes.length] = 128;
325
+ const view = new DataView(padded.buffer);
326
+ view.setBigUint64(paddedLength - 16, bitLength >> 64n, false);
327
+ view.setBigUint64(paddedLength - 8, bitLength & MASK64, false);
328
+ let state = [...initial];
329
+ for (let offset = 0; offset < paddedLength; offset += 128) {
330
+ const w = new Array(80);
331
+ for (let index = 0; index < 16; index++) w[index] = view.getBigUint64(offset + index * 8, false);
332
+ for (let index = 16; index < 80; index++) {
333
+ const w15 = w[index - 15] ?? 0n;
334
+ const w2 = w[index - 2] ?? 0n;
335
+ const w16 = w[index - 16] ?? 0n;
336
+ const w7 = w[index - 7] ?? 0n;
337
+ const s0 = rotateRight64(w15, 1n) ^ rotateRight64(w15, 8n) ^ w15 >> 7n;
338
+ const s1 = rotateRight64(w2, 19n) ^ rotateRight64(w2, 61n) ^ w2 >> 6n;
339
+ w[index] = w16 + s0 + w7 + s1 & MASK64;
340
+ }
341
+ let a = state[0] ?? 0n;
342
+ let b = state[1] ?? 0n;
343
+ let c = state[2] ?? 0n;
344
+ let d = state[3] ?? 0n;
345
+ let e = state[4] ?? 0n;
346
+ let f = state[5] ?? 0n;
347
+ let g = state[6] ?? 0n;
348
+ let h = state[7] ?? 0n;
349
+ for (let index = 0; index < 80; index++) {
350
+ const s1 = rotateRight64(e, 14n) ^ rotateRight64(e, 18n) ^ rotateRight64(e, 41n);
351
+ const ch = e & f ^ ~e & g;
352
+ const k = SHA512_K[index] ?? 0n;
353
+ const wi = w[index] ?? 0n;
354
+ const temp1 = h + s1 + ch + k + wi & MASK64;
355
+ const temp2 = (rotateRight64(a, 28n) ^ rotateRight64(a, 34n) ^ rotateRight64(a, 39n)) + (a & b ^ a & c ^ b & c) & MASK64;
356
+ h = g;
357
+ g = f;
358
+ f = e;
359
+ e = d + temp1 & MASK64;
360
+ d = c;
361
+ c = b;
362
+ b = a;
363
+ a = temp1 + temp2 & MASK64;
364
+ }
365
+ state = [
366
+ a + (state[0] ?? 0n) & MASK64,
367
+ b + (state[1] ?? 0n) & MASK64,
368
+ c + (state[2] ?? 0n) & MASK64,
369
+ d + (state[3] ?? 0n) & MASK64,
370
+ e + (state[4] ?? 0n) & MASK64,
371
+ f + (state[5] ?? 0n) & MASK64,
372
+ g + (state[6] ?? 0n) & MASK64,
373
+ h + (state[7] ?? 0n) & MASK64
374
+ ];
375
+ }
376
+ return state;
377
+ }
378
+ const SHA512_IV = [
379
+ 7640891576956012808n,
380
+ 13503953896175478587n,
381
+ 4354685564936845355n,
382
+ 11912009170470909681n,
383
+ 5840696475078001361n,
384
+ 11170449401992604703n,
385
+ 2270897969802886507n,
386
+ 6620516959819538809n
387
+ ];
388
+ const SHA384_IV = [
389
+ 14680500436340154072n,
390
+ 7105036623409894663n,
391
+ 10473403895298186519n,
392
+ 1526699215303891257n,
393
+ 7436329637833083697n,
394
+ 10282925794625328401n,
395
+ 15784041429090275239n,
396
+ 5167115440072839076n
397
+ ];
398
+ const word64Hex = (word) => word.toString(16).padStart(16, "0");
399
+ /**
400
+ * sha384Hex returns the SHA-384 digest of the UTF-8 encoding of the input as
401
+ * lowercase hexadecimal.
402
+ */
403
+ function sha384Hex(input) {
404
+ return sha512Words(input, SHA384_IV).slice(0, 6).map(word64Hex).join("");
405
+ }
406
+ /**
407
+ * sha512Hex returns the SHA-512 digest of the UTF-8 encoding of the input as
408
+ * lowercase hexadecimal.
409
+ */
410
+ function sha512Hex(input) {
411
+ return sha512Words(input, SHA512_IV).map(word64Hex).join("");
412
+ }
413
+ // src/term/rdfjs-data-factory.ts
414
+ const DataFactory = DataFactory$1;
415
+ const dataFactory = DataFactory;
416
+ export { sha256Hex as a, formatNumber as c, sha512Hex as i, dataFactory as n, sha1Hex as o, sha384Hex as r, canonicalDouble as s, DataFactory as t };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Structural copies of the RDF/JS term interfaces (`@rdfjs/types`) the SPARQL
3
+ * AST is built from.
4
+ *
5
+ * The AST (`ast.ts`) must be analysable by the native compiler (scriptc, issue
6
+ * #221), which cannot represent types imported from an npm package whose
7
+ * implementation is not part of the compiled module graph (SC2013). These
8
+ * interfaces are member-for-member identical to `@rdfjs/types`' `Term`,
9
+ * `NamedNode`, `BlankNode`, `Literal`, `Variable`, `DefaultGraph`, `BaseQuad`
10
+ * and `Quad`, so values flow between the two worlds without conversion or
11
+ * casts: an RDF/JS term is assignable to the AST's `Term` and vice versa.
12
+ */
13
+ /** RdfNamedNode is an IRI term. */
14
+ interface RdfNamedNode {
15
+ termType: "NamedNode";
16
+ value: string;
17
+ equals(other: RdfTerm | null | undefined): boolean;
18
+ }
19
+ /** RdfBlankNode is a blank node term. */
20
+ interface RdfBlankNode {
21
+ termType: "BlankNode";
22
+ value: string;
23
+ equals(other: RdfTerm | null | undefined): boolean;
24
+ }
25
+ /** RdfLiteral is a literal term (plain, language-tagged, or typed). */
26
+ interface RdfLiteral {
27
+ termType: "Literal";
28
+ value: string;
29
+ language: string;
30
+ direction?: "ltr" | "rtl" | "" | null;
31
+ datatype: RdfNamedNode;
32
+ equals(other: RdfTerm | null | undefined): boolean;
33
+ }
34
+ /** RdfVariable is a query variable term. */
35
+ interface RdfVariable {
36
+ termType: "Variable";
37
+ value: string;
38
+ equals(other: RdfTerm | null | undefined): boolean;
39
+ }
40
+ /** RdfDefaultGraph is the default graph term. */
41
+ interface RdfDefaultGraph {
42
+ termType: "DefaultGraph";
43
+ value: "";
44
+ equals(other: RdfTerm | null | undefined): boolean;
45
+ }
46
+ /** RdfBaseQuad is a quad whose components are any terms. */
47
+ interface RdfBaseQuad {
48
+ termType: "Quad";
49
+ value: "";
50
+ subject: RdfTerm;
51
+ predicate: RdfTerm;
52
+ object: RdfTerm;
53
+ graph: RdfTerm;
54
+ equals(other: RdfTerm | null | undefined): boolean;
55
+ }
56
+ /** RdfQuad is a quad with the RDF/JS component restrictions. */
57
+ interface RdfQuad extends RdfBaseQuad {
58
+ subject: RdfNamedNode | RdfBlankNode | RdfQuad | RdfVariable;
59
+ predicate: RdfNamedNode | RdfVariable;
60
+ object: RdfNamedNode | RdfLiteral | RdfBlankNode | RdfQuad | RdfVariable;
61
+ graph: RdfDefaultGraph | RdfNamedNode | RdfBlankNode | RdfVariable;
62
+ }
63
+ /** RdfTerm is any RDF/JS term. */
64
+ type RdfTerm = RdfNamedNode | RdfBlankNode | RdfLiteral | RdfVariable | RdfDefaultGraph | RdfBaseQuad;
65
+ /** RdfQuadGraph is a term allowed in a quad's graph position. */
66
+ type RdfQuadGraph = RdfQuad["graph"];
67
+ /** RdfStream is the structural copy of RDF/JS `Stream` (event callback shape). */
68
+ interface RdfStream<T = RdfQuad> {
69
+ on(event: string | symbol, listener: (...args: unknown[]) => void): unknown;
70
+ read(): T | null;
71
+ }
72
+ /** RdfSource is the structural copy of RDF/JS `Source`: pattern matching. */
73
+ interface RdfSource<T = RdfQuad> {
74
+ match(subject?: RdfTerm | null, predicate?: RdfTerm | null, object?: RdfTerm | null, graph?: RdfTerm | null): RdfStream<T>;
75
+ }
76
+ /** RdfStore is the structural copy of RDF/JS `Store`: a source plus mutation. */
77
+ interface RdfStore<T extends RdfQuad = RdfQuad> extends RdfSource<T> {
78
+ addQuad(quad: T): unknown;
79
+ removeQuad(quad: T): unknown;
80
+ import(stream: RdfStream<T>): unknown;
81
+ removeMatches(subject?: RdfTerm | null, predicate?: RdfTerm | null, object?: RdfTerm | null, graph?: RdfTerm | null): unknown;
82
+ }
83
+ export { RdfQuadGraph as a, RdfStream as c, RdfQuad as i, RdfTerm as l, RdfLiteral as n, RdfSource as o, RdfNamedNode as r, RdfStore as s, RdfBaseQuad as t };