@netwerk-digitaal-erfgoed/network-of-terms-query 6.2.8 → 6.2.10
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/CHANGELOG.md +9 -0
- package/{build → dist}/catalog.d.ts.map +1 -1
- package/{build → dist}/catalog.js +6 -7
- package/dist/config.d.ts.map +1 -0
- package/{build → dist}/config.js +0 -1
- package/{build → dist}/distributions.d.ts.map +1 -1
- package/{build → dist}/distributions.js +0 -1
- package/{build → dist}/helpers/logger-pino.d.ts.map +1 -1
- package/{build → dist}/helpers/logger-pino.js +0 -1
- package/{build → dist}/helpers/logger.js +0 -1
- package/{build → dist}/index.d.ts.map +1 -1
- package/{build → dist}/index.js +0 -1
- package/{build → dist}/instrumentation.js +0 -1
- package/{build → dist}/literal.d.ts +1 -1
- package/{build → dist}/literal.d.ts.map +1 -1
- package/{build → dist}/literal.js +7 -7
- package/{build → dist}/lookup/lookup.d.ts.map +1 -1
- package/{build → dist}/lookup/lookup.js +6 -4
- package/dist/query.d.ts.map +1 -0
- package/{build → dist}/query.js +58 -8
- package/{build → dist}/search/query-mode.js +2 -3
- package/{build → dist}/terms.d.ts +1 -1
- package/{build → dist}/terms.js +2 -3
- package/{build/server-test.d.ts → dist/test-utils.d.ts} +1 -1
- package/dist/test-utils.d.ts.map +1 -0
- package/{build/server-test.js → dist/test-utils.js} +2 -3
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/eslint.config.mjs +22 -0
- package/package.json +37 -41
- package/src/catalog.ts +157 -0
- package/src/config.ts +24 -0
- package/src/distributions.ts +94 -0
- package/src/helpers/logger-pino.ts +45 -0
- package/src/helpers/logger.ts +52 -0
- package/src/index.ts +12 -0
- package/src/instrumentation.ts +51 -0
- package/src/literal.ts +42 -0
- package/src/lookup/lookup.ts +147 -0
- package/src/query.ts +302 -0
- package/src/search/query-mode.ts +54 -0
- package/src/terms.ts +141 -0
- package/src/test-utils.ts +207 -0
- package/test/fixtures/terms.ttl +46 -0
- package/test/query.test.ts +68 -0
- package/test/search/query-mode.test.ts +71 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.test.json +27 -0
- package/vite.config.ts +26 -0
- package/build/catalog.js.map +0 -1
- package/build/config.d.ts.map +0 -1
- package/build/config.js.map +0 -1
- package/build/distributions.js.map +0 -1
- package/build/helpers/logger-pino.js.map +0 -1
- package/build/helpers/logger.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/instrumentation.js.map +0 -1
- package/build/literal.js.map +0 -1
- package/build/lookup/lookup.js.map +0 -1
- package/build/query.d.ts.map +0 -1
- package/build/query.js.map +0 -1
- package/build/search/query-mode.js.map +0 -1
- package/build/server-test.d.ts.map +0 -1
- package/build/server-test.js.map +0 -1
- package/build/terms.js.map +0 -1
- /package/{build → dist}/catalog.d.ts +0 -0
- /package/{build → dist}/config.d.ts +0 -0
- /package/{build → dist}/distributions.d.ts +0 -0
- /package/{build → dist}/helpers/logger-pino.d.ts +0 -0
- /package/{build → dist}/helpers/logger.d.ts +0 -0
- /package/{build → dist}/helpers/logger.d.ts.map +0 -0
- /package/{build → dist}/index.d.ts +0 -0
- /package/{build → dist}/instrumentation.d.ts +0 -0
- /package/{build → dist}/instrumentation.d.ts.map +0 -0
- /package/{build → dist}/lookup/lookup.d.ts +0 -0
- /package/{build → dist}/query.d.ts +0 -0
- /package/{build → dist}/search/query-mode.d.ts +0 -0
- /package/{build → dist}/search/query-mode.d.ts.map +0 -0
- /package/{build → dist}/terms.d.ts.map +0 -0
package/CHANGELOG.md
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,qBAAa,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I, accepting distribution IRIs too for BC.
|
|
10
10
|
*/
|
|
11
11
|
getDatasetByIri(iri) {
|
|
12
|
-
return (this.datasets.find(dataset => dataset.iri.toString() === iri.toString()) ?? this.getDatasetByDistributionIri(iri));
|
|
12
|
+
return (this.datasets.find((dataset) => dataset.iri.toString() === iri.toString()) ?? this.getDatasetByDistributionIri(iri));
|
|
13
13
|
}
|
|
14
14
|
getDatasetsSortedByName(languageCode) {
|
|
15
15
|
return [...this.datasets].sort((a, b) => a.name[languageCode].localeCompare(b.name[languageCode]));
|
|
16
16
|
}
|
|
17
17
|
getDatasetByDistributionIri(iri) {
|
|
18
|
-
return this.datasets.find(dataset => dataset.getDistributionByIri(iri) !== undefined);
|
|
18
|
+
return this.datasets.find((dataset) => dataset.getDistributionByIri(iri) !== undefined);
|
|
19
19
|
}
|
|
20
20
|
getDatasetByTermIri(iri) {
|
|
21
21
|
for (const [prefix, datasetIri] of this.prefixToDataset) {
|
|
@@ -29,7 +29,7 @@ export class Catalog {
|
|
|
29
29
|
return this.datasets.reduce((acc, dataset) => {
|
|
30
30
|
return [
|
|
31
31
|
...acc,
|
|
32
|
-
...dataset.distributions.filter(distribution => distribution.hasFeature(featureType)),
|
|
32
|
+
...dataset.distributions.filter((distribution) => distribution.hasFeature(featureType)),
|
|
33
33
|
];
|
|
34
34
|
}, []);
|
|
35
35
|
}
|
|
@@ -52,7 +52,7 @@ export class Catalog {
|
|
|
52
52
|
return new Map([
|
|
53
53
|
...this.datasets
|
|
54
54
|
.reduce((acc, dataset) => {
|
|
55
|
-
dataset.termsPrefixes.forEach(prefix => {
|
|
55
|
+
dataset.termsPrefixes.forEach((prefix) => {
|
|
56
56
|
acc.set(prefix.toString(), dataset.iri);
|
|
57
57
|
});
|
|
58
58
|
return acc;
|
|
@@ -85,10 +85,10 @@ export class Dataset {
|
|
|
85
85
|
this.alternateName = alternateName;
|
|
86
86
|
}
|
|
87
87
|
getSparqlDistribution() {
|
|
88
|
-
return this.distributions.find(distribution => distribution instanceof SparqlDistribution);
|
|
88
|
+
return this.distributions.find((distribution) => distribution instanceof SparqlDistribution);
|
|
89
89
|
}
|
|
90
90
|
getDistributionByIri(iri) {
|
|
91
|
-
return this.distributions.find(distribution => distribution.iri.toString() === iri.toString());
|
|
91
|
+
return this.distributions.find((distribution) => distribution.iri.toString() === iri.toString());
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
export class Organization {
|
|
@@ -130,4 +130,3 @@ export var FeatureType;
|
|
|
130
130
|
(function (FeatureType) {
|
|
131
131
|
FeatureType["RECONCILIATION"] = "https://reconciliation-api.github.io/specs/latest/";
|
|
132
132
|
})(FeatureType || (FeatureType = {}));
|
|
133
|
-
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,cAAc,EAAE,MAAM,YAAY,CAAC;AAgBvD,UAAU,GAAG;IACX,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,GAAG,CAErC,CAAC"}
|
package/{build → dist}/config.js
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distributions.d.ts","sourceRoot":"","sources":["../src/distributions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"distributions.d.ts","sourceRoot":"","sources":["../src/distributions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAqB,aAAa,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAI5C,UAAU,gBAAgB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,MAAM,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,OAAO,EAAE,GAAG,EAAE,CAAC;CAChB;AAiBD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,QAAQ,CAAc;gBAElB,OAAO,EAAE;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,WAAW,CAAC;KACxB;IAMK,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAsBpD,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiBnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-pino.d.ts","sourceRoot":"","sources":["../../src/helpers/logger-pino.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"logger-pino.d.ts","sourceRoot":"","sources":["../../src/helpers/logger-pino.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AAED,qBAAa,UAAW,SAAQ,MAAM;IACpC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;gBAElB,OAAO,EAAE,kBAAkB;IAMvC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKxC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKxC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKxC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKvC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKxC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;CAGxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,eAAO,MAAM,QAAQ,kEAA0B,CAAC"}
|
package/{build → dist}/index.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as RDF from '@rdfjs/types';
|
|
2
|
-
export declare function filterLiteralsByLanguage(literals: RDF.Literal[], languages: string[]): RDF.Literal[];
|
|
2
|
+
export declare function filterLiteralsByLanguage(literals: RDF.Literal[], languages: string[]): RDF.Literal[] | import("rdf-data-factory").Literal[];
|
|
3
3
|
/**
|
|
4
4
|
* Return value from {@link Literal} in the given languages.
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAKpC,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,EACvB,SAAS,EAAE,MAAM,EAAE,wDAapB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,EACvB,SAAS,GAAE,MAAM,EAAW,YAW7B"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DataFactory } from 'rdf-data-factory';
|
|
2
|
+
const dataFactory = new DataFactory();
|
|
2
3
|
export function filterLiteralsByLanguage(literals, languages) {
|
|
3
|
-
const preferredLanguageLiterals = literals.filter(literal => languages.includes(literal.language));
|
|
4
|
+
const preferredLanguageLiterals = literals.filter((literal) => languages.includes(literal.language));
|
|
4
5
|
if (preferredLanguageLiterals.length > 0) {
|
|
5
6
|
return preferredLanguageLiterals;
|
|
6
7
|
}
|
|
7
8
|
// If literal has no language tag, we assume it is in the Network of Terms’ default language, Dutch.
|
|
8
9
|
return literals
|
|
9
|
-
.filter(literal => literal.language === '')
|
|
10
|
-
.map(literal =>
|
|
10
|
+
.filter((literal) => literal.language === '')
|
|
11
|
+
.map((literal) => dataFactory.literal(literal.value, 'nl'));
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Return value from {@link Literal} in the given languages.
|
|
@@ -18,9 +19,8 @@ export function filterLiteralsByLanguage(literals, languages) {
|
|
|
18
19
|
export function literalValues(literals, languages = ['nl']) {
|
|
19
20
|
const languageLiterals = filterLiteralsByLanguage(literals, languages);
|
|
20
21
|
if (languageLiterals.length > 0) {
|
|
21
|
-
return languageLiterals.map(literal => literal.value);
|
|
22
|
+
return languageLiterals.map((literal) => literal.value);
|
|
22
23
|
}
|
|
23
24
|
// Fall back to English for sources that provide no Dutch labels.
|
|
24
|
-
return filterLiteralsByLanguage(literals, ['en']).map(literal => literal.value);
|
|
25
|
+
return filterLiteralsByLanguage(literals, ['en']).map((literal) => literal.value);
|
|
25
26
|
}
|
|
26
|
-
//# sourceMappingURL=literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/lookup/lookup.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/lookup/lookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAW,YAAY,EAAO,MAAM,eAAe,CAAC;AACpE,OAAO,EAEL,iBAAiB,EACjB,WAAW,EAIX,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,YAAY,CAAC;IAErB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,mBAAmB,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,GAAG,YAAY,GAAG,WAAW,CAAC;AAE7E,qBAAa,mBAAmB;IAGlB,QAAQ,CAAC,GAAG,EAAE,MAAM;IAFhC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEJ,GAAG,EAAE,MAAM;CAGjC;AAED,qBAAa,aAAa;IAGZ,QAAQ,CAAC,GAAG,EAAE,MAAM;IAFhC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEJ,GAAG,EAAE,MAAM;CAGjC;AAED,qBAAa,aAAa;IAEtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;gBADZ,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,iBAAiB;IAG5B,MAAM,CACjB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAqFhC"}
|
|
@@ -60,10 +60,13 @@ export class LookupService {
|
|
|
60
60
|
}
|
|
61
61
|
return acc;
|
|
62
62
|
}, new Map());
|
|
63
|
-
return iris.map(iri => {
|
|
63
|
+
return iris.map((iri) => {
|
|
64
64
|
const dataset = irisToDataset.get(iri.toString());
|
|
65
65
|
if (dataset === undefined) {
|
|
66
|
-
clientQueriesCounter.add(1, {
|
|
66
|
+
clientQueriesCounter.add(1, {
|
|
67
|
+
type: 'lookup',
|
|
68
|
+
error: 'SourceNotFound',
|
|
69
|
+
});
|
|
67
70
|
return {
|
|
68
71
|
uri: iri,
|
|
69
72
|
distribution: new SourceNotFoundError(iri),
|
|
@@ -86,7 +89,6 @@ function result(result, iri) {
|
|
|
86
89
|
if (result instanceof Error) {
|
|
87
90
|
return result;
|
|
88
91
|
}
|
|
89
|
-
return (result.terms.find(term => term.id.value === iri.toString()) ??
|
|
92
|
+
return (result.terms.find((term) => term.id.value === iri.toString()) ??
|
|
90
93
|
new NotFoundError(iri));
|
|
91
94
|
}
|
|
92
|
-
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,MAAM,CAAC;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K,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,EAAE,MAAM,CAAC;KACf,GAAG;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;KAAE;IAarE,MAAM,CACV,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC;IAyBnB,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM;IAWjE,GAAG,CACP,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAM,GACtC,OAAO,CAAC,aAAa,CAAC;CAuG1B"}
|
package/{build → dist}/query.js
RENAMED
|
@@ -10,6 +10,46 @@ import { BindingsFactory } from '@comunica/utils-bindings-factory';
|
|
|
10
10
|
import { DataFactory } from 'rdf-data-factory';
|
|
11
11
|
import { sourceQueriesHistogram } from './instrumentation.js';
|
|
12
12
|
import { config } from './config.js';
|
|
13
|
+
/**
|
|
14
|
+
* Check if a query requires string substitution instead of initialBindings.
|
|
15
|
+
* Workaround for Comunica v5 traqula bug that crashes with:
|
|
16
|
+
* - SERVICE clauses
|
|
17
|
+
* - VALUES combination
|
|
18
|
+
*/
|
|
19
|
+
function requiresStringSubstitution(query) {
|
|
20
|
+
const hasService = /\bSERVICE\b/i.test(query);
|
|
21
|
+
const hasValues = /\bVALUES\b/i.test(query);
|
|
22
|
+
return hasService || hasValues;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Substitute bindings directly into a SPARQL query string.
|
|
26
|
+
* This is a workaround for Comunica v5's initialBindings bug with SERVICE clauses.
|
|
27
|
+
*/
|
|
28
|
+
function substituteBindings(query, bindings) {
|
|
29
|
+
let result = query;
|
|
30
|
+
for (const [name, term] of Object.entries(bindings)) {
|
|
31
|
+
const pattern = new RegExp(`\\?${name}\\b`, 'g');
|
|
32
|
+
if (term.termType === 'NamedNode') {
|
|
33
|
+
result = result.replace(pattern, `<${term.value}>`);
|
|
34
|
+
}
|
|
35
|
+
else if (term.termType === 'Literal') {
|
|
36
|
+
const literal = term;
|
|
37
|
+
const datatype = literal.datatype?.value;
|
|
38
|
+
if (datatype &&
|
|
39
|
+
datatype !== 'http://www.w3.org/2001/XMLSchema#string' &&
|
|
40
|
+
datatype !== 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString') {
|
|
41
|
+
result = result.replace(pattern, `"${term.value}"^^<${datatype}>`);
|
|
42
|
+
}
|
|
43
|
+
else if (literal.language) {
|
|
44
|
+
result = result.replace(pattern, `"${term.value}"@${literal.language}`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
result = result.replace(pattern, `"${term.value}"`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
13
53
|
export class TermsResponse {
|
|
14
54
|
result;
|
|
15
55
|
responseTimeMs;
|
|
@@ -80,7 +120,7 @@ export class QueryTermsService {
|
|
|
80
120
|
queryWithLimit, distribution, timeoutMs, bindingsWithLimit);
|
|
81
121
|
}
|
|
82
122
|
async lookup(iris, distribution, timeoutMs) {
|
|
83
|
-
return this.run(distribution.lookupQuery.replace('?uris', iris.map(iri => `<${iri}>`).join(' ')), distribution, timeoutMs);
|
|
123
|
+
return this.run(distribution.lookupQuery.replace('?uris', iris.map((iri) => `<${iri}>`).join(' ')), distribution, timeoutMs);
|
|
84
124
|
}
|
|
85
125
|
async run(query, distribution, timeoutMs, bindings = {}) {
|
|
86
126
|
Joi.attempt(timeoutMs, Joi.number()
|
|
@@ -92,10 +132,18 @@ export class QueryTermsService {
|
|
|
92
132
|
const logger = new LoggerPino({ logger: this.logger });
|
|
93
133
|
// Extract HTTP credentials if the distribution URL contains any.
|
|
94
134
|
const url = new URL(distribution.endpoint.toString());
|
|
95
|
-
|
|
96
|
-
|
|
135
|
+
// Workaround for https://github.com/comunica/comunica/issues/1655, so use
|
|
136
|
+
// string substitution instead of initialBindings for:
|
|
137
|
+
// - SERVICE clauses crash with initialBindings
|
|
138
|
+
// - VALUES crashes in some combinations
|
|
139
|
+
const useStringSubstitution = requiresStringSubstitution(query);
|
|
140
|
+
const finalQuery = useStringSubstitution
|
|
141
|
+
? substituteBindings(query, bindings)
|
|
142
|
+
: query;
|
|
143
|
+
this.logger.info(`Querying "${url}" with "${finalQuery}"...`);
|
|
144
|
+
const quadStream = await this.engine.queryQuads(finalQuery, {
|
|
97
145
|
log: logger,
|
|
98
|
-
httpAuth: url.username === '' ?
|
|
146
|
+
httpAuth: url.username === '' ? undefined : url.username + ':' + url.password,
|
|
99
147
|
httpTimeout: timeoutMs,
|
|
100
148
|
noCache: true,
|
|
101
149
|
sources: [
|
|
@@ -104,11 +152,14 @@ export class QueryTermsService {
|
|
|
104
152
|
value: url.origin + url.pathname,
|
|
105
153
|
},
|
|
106
154
|
],
|
|
107
|
-
initialBindings
|
|
155
|
+
// Only pass initialBindings when NOT using string substitution
|
|
156
|
+
...(useStringSubstitution
|
|
157
|
+
? {}
|
|
158
|
+
: { initialBindings: bindingsFactory.fromRecord(bindings) }),
|
|
108
159
|
});
|
|
109
|
-
return new Promise(resolve => {
|
|
160
|
+
return new Promise((resolve) => {
|
|
110
161
|
const termsTransformer = new TermsTransformer();
|
|
111
|
-
quadStream.on('error', error => {
|
|
162
|
+
quadStream.on('error', (error) => {
|
|
112
163
|
const elapsed = Math.round(timer.elapsed());
|
|
113
164
|
this.logger.error(`An error occurred when querying "${distribution.endpoint}": ${error} with %o`, error);
|
|
114
165
|
if (error.message.startsWith('Fetch timed out')) {
|
|
@@ -164,4 +215,3 @@ const alphabeticallyByLabels = (a, b) => {
|
|
|
164
215
|
const dataFactory = new DataFactory();
|
|
165
216
|
const bindingsFactory = new BindingsFactory(dataFactory);
|
|
166
217
|
const obfuscateHttpCredentials = (message) => message.replace(/(https?):\/\/.+:.+@/, '$1://***@');
|
|
167
|
-
//# sourceMappingURL=query.js.map
|
|
@@ -24,8 +24,8 @@ const split = (query) => query.split(/\s+/);
|
|
|
24
24
|
/**
|
|
25
25
|
* Quote parts that are not boolean operators.
|
|
26
26
|
*/
|
|
27
|
-
const quote = (queryParts) => queryParts.map(part => (isBooleanOperator(part) ? part : `'${part}'`));
|
|
28
|
-
const filterStopWords = (queryParts) => queryParts.filter(part => part !== '&');
|
|
27
|
+
const quote = (queryParts) => queryParts.map((part) => (isBooleanOperator(part) ? part : `'${part}'`));
|
|
28
|
+
const filterStopWords = (queryParts) => queryParts.filter((part) => part !== '&');
|
|
29
29
|
/**
|
|
30
30
|
* Join query parts with boolean AND if they are not yet connected with a boolean.
|
|
31
31
|
*/
|
|
@@ -37,4 +37,3 @@ const join = (queryParts) => queryParts.reduce((previousValue, currentValue, cur
|
|
|
37
37
|
return `${previousValue} ${currentValue}`;
|
|
38
38
|
});
|
|
39
39
|
const isBooleanOperator = (maybeBool) => maybeBool.toLowerCase() === 'and' || maybeBool.toLowerCase() === 'or';
|
|
40
|
-
//# sourceMappingURL=query-mode.js.map
|
package/{build → dist}/terms.js
RENAMED
|
@@ -94,7 +94,7 @@ export class TermsTransformer {
|
|
|
94
94
|
const propertyValue = currentTerm[propertyName]; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
95
95
|
if (Array.isArray(propertyValue)) {
|
|
96
96
|
// Prevent duplicate prefLabel values due to duplicate quads.
|
|
97
|
-
if (!propertyValue.find(value => value.equals(quad.object))) {
|
|
97
|
+
if (!propertyValue.find((value) => value.equals(quad.object))) {
|
|
98
98
|
propertyValue.push(quad.object);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -104,7 +104,7 @@ export class TermsTransformer {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
asArray() {
|
|
107
|
-
return [...this.termsIris].map(iri => {
|
|
107
|
+
return [...this.termsIris].map((iri) => {
|
|
108
108
|
const term = this.termsMap.get(iri);
|
|
109
109
|
return new Term(term.id, term.type, term.prefLabels, term.altLabels, term.hiddenLabels, term.scopeNotes, term.seeAlso, this.mapRelatedTerms(term.broaderTerms).sort(alphabeticallyByPrefLabel), this.mapRelatedTerms(term.narrowerTerms).sort(alphabeticallyByPrefLabel), this.mapRelatedTerms(term.relatedTerms).sort(alphabeticallyByPrefLabel), this.mapRelatedTerms(term.exactMatches).sort(alphabeticallyByPrefLabel), term.inScheme, term.score);
|
|
110
110
|
});
|
|
@@ -126,4 +126,3 @@ const alphabeticallyByPrefLabel = (a, b) => {
|
|
|
126
126
|
const prefLabelB = b.prefLabels[0]?.value ?? '';
|
|
127
127
|
return prefLabelA.localeCompare(prefLabelB);
|
|
128
128
|
};
|
|
129
|
-
//# sourceMappingURL=terms.js.map
|
|
@@ -2,4 +2,4 @@ import { Catalog } from './index.js';
|
|
|
2
2
|
export declare const teardown: () => Promise<void>;
|
|
3
3
|
export declare const testCatalog: (port: number) => Catalog;
|
|
4
4
|
export declare function startDistributionSparqlEndpoint(port: number): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=
|
|
5
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAMR,MAAM,YAAY,CAAC;AAapB,eAAO,MAAM,QAAQ,qBAEpB,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,YAyKpC,CAAC;AAEL,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
|
@@ -93,14 +93,13 @@ export const testCatalog = (port) => new Catalog([
|
|
|
93
93
|
], ['http://data.beeldengeluid.nl/gtaa/'], 'https://example.com/gtaa', ['nl'], [
|
|
94
94
|
new Organization('https://www.beeldengeluid.nl/', { nl: 'Nederlands Instituut voor Beeld en Geluid' }, { nl: 'Beeld en Geluid' }),
|
|
95
95
|
], [
|
|
96
|
-
new SparqlDistribution('https://data.beeldengeluid.nl/id/datadownload/0026', 'https://username:password@gtaa.apis.beeldengeluid.nl/sparql', 'CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }', 'CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }'),
|
|
96
|
+
new SparqlDistribution('https://data.beeldengeluid.nl/id/datadownload/0026', 'https://username:password@gtaa.apis.beeldengeluid.nl/sparql', 'CONSTRUCT { ?s ?p ?o } WHERE { ?s skos:inScheme ?datasetUri ; ?p ?o }', 'CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }'),
|
|
97
97
|
]),
|
|
98
98
|
]);
|
|
99
99
|
export async function startDistributionSparqlEndpoint(port) {
|
|
100
100
|
servers = await setup({
|
|
101
|
-
command: `npx comunica-sparql-file-http ${dirname(fileURLToPath(import.meta.url))}/../test/fixtures/terms.ttl -p ${port}`,
|
|
101
|
+
command: `npx --no comunica-sparql-file-http ${dirname(fileURLToPath(import.meta.url))}/../test/fixtures/terms.ttl -p ${port}`,
|
|
102
102
|
port,
|
|
103
103
|
launchTimeout: 20000,
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
//# sourceMappingURL=server-test.js.map
|