@netwerk-digitaal-erfgoed/network-of-terms-query 6.2.14 → 6.2.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netwerk-digitaal-erfgoed/network-of-terms-query",
3
- "version": "6.2.14",
3
+ "version": "6.2.15",
4
4
  "description": "Engine for querying sources in the Network of Terms",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/netwerk-digitaal-erfgoed/network-of-terms#readme",
@@ -30,9 +30,9 @@
30
30
  "main": "./dist/index.js",
31
31
  "types": "./dist/index.d.ts",
32
32
  "dependencies": {
33
- "@comunica/query-sparql": "^5.1.2",
34
- "@comunica/types": "^5.1.0",
35
- "@comunica/utils-bindings-factory": "^5.1.0",
33
+ "@comunica/query-sparql": "^5.1.3",
34
+ "@comunica/types": "^5.1.3",
35
+ "@comunica/utils-bindings-factory": "^5.1.3",
36
36
  "@hapi/hoek": "^11.0.7",
37
37
  "@opentelemetry/api": "^1.9.0",
38
38
  "@opentelemetry/exporter-metrics-otlp-proto": "0.208.0",
@@ -51,7 +51,7 @@
51
51
  "tslib": "^2.3.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@comunica/query-sparql-file": "^5.1.2",
54
+ "@comunica/query-sparql-file": "^5.1.3",
55
55
  "asynciterator": "^3.9.0"
56
56
  }
57
57
  }
package/src/query.ts CHANGED
@@ -13,50 +13,6 @@ import { DataFactory } from 'rdf-data-factory';
13
13
  import { sourceQueriesHistogram } from './instrumentation.js';
14
14
  import { config } from './config.js';
15
15
 
16
- /**
17
- * Check if a query requires string substitution instead of initialBindings.
18
- * Workaround for Comunica v5 traqula bug that crashes with:
19
- * - SERVICE clauses
20
- * - VALUES combination
21
- */
22
- function requiresStringSubstitution(query: string): boolean {
23
- const hasService = /\bSERVICE\b/i.test(query);
24
- const hasValues = /\bVALUES\b/i.test(query);
25
- return hasService || hasValues;
26
- }
27
-
28
- /**
29
- * Substitute bindings directly into a SPARQL query string.
30
- * This is a workaround for Comunica v5's initialBindings bug with SERVICE clauses.
31
- */
32
- function substituteBindings(
33
- query: string,
34
- bindings: Record<string, RDF.Term>,
35
- ): string {
36
- let result = query;
37
- for (const [name, term] of Object.entries(bindings)) {
38
- const pattern = new RegExp(`\\?${name}\\b`, 'g');
39
- if (term.termType === 'NamedNode') {
40
- result = result.replace(pattern, `<${term.value}>`);
41
- } else if (term.termType === 'Literal') {
42
- const literal = term as RDF.Literal;
43
- const datatype = literal.datatype?.value;
44
- if (
45
- datatype &&
46
- datatype !== 'http://www.w3.org/2001/XMLSchema#string' &&
47
- datatype !== 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString'
48
- ) {
49
- result = result.replace(pattern, `"${term.value}"^^<${datatype}>`);
50
- } else if (literal.language) {
51
- result = result.replace(pattern, `"${term.value}"@${literal.language}`);
52
- } else {
53
- result = result.replace(pattern, `"${term.value}"`);
54
- }
55
- }
56
- }
57
- return result;
58
- }
59
-
60
16
  export type TermsResult = Terms | TimeoutError | ServerError;
61
17
 
62
18
  export class TermsResponse {
@@ -231,18 +187,8 @@ export class QueryTermsService {
231
187
  const logger = new LoggerPino({ logger: this.logger });
232
188
  // Extract HTTP credentials if the distribution URL contains any.
233
189
  const url = new URL(distribution.endpoint.toString());
234
-
235
- // Workaround for https://github.com/comunica/comunica/issues/1655, so use
236
- // string substitution instead of initialBindings for:
237
- // - SERVICE clauses crash with initialBindings
238
- // - VALUES crashes in some combinations
239
- const useStringSubstitution = requiresStringSubstitution(query);
240
- const finalQuery = useStringSubstitution
241
- ? substituteBindings(query, bindings)
242
- : query;
243
-
244
- this.logger.info(`Querying "${url}" with "${finalQuery}"...`);
245
- const quadStream = await this.engine.queryQuads(finalQuery, {
190
+ this.logger.info(`Querying "${url}" with "${query}"...`);
191
+ const quadStream = await this.engine.queryQuads(query, {
246
192
  log: logger,
247
193
  httpAuth:
248
194
  url.username === '' ? undefined : url.username + ':' + url.password,
@@ -254,10 +200,7 @@ export class QueryTermsService {
254
200
  value: url.origin + url.pathname,
255
201
  },
256
202
  ],
257
- // Only pass initialBindings when NOT using string substitution
258
- ...(useStringSubstitution
259
- ? {}
260
- : { initialBindings: bindingsFactory.fromRecord(bindings) }),
203
+ initialBindings: bindingsFactory.fromRecord(bindings),
261
204
  });
262
205
 
263
206
  return new Promise((resolve) => {
package/vite.config.ts CHANGED
@@ -16,11 +16,11 @@ export default defineConfig(() => ({
16
16
  provider: 'v8' as const,
17
17
  thresholds: {
18
18
  autoUpdate: true,
19
- lines: 57.57,
20
- functions: 41.02,
21
- branches: 91.52,
22
- statements: 57.57,
19
+ lines: 58.88,
20
+ functions: 40.78,
21
+ branches: 94.64,
22
+ statements: 58.88,
23
23
  },
24
24
  },
25
25
  },
26
- }));
26
+ }));