ldkit 1.1.0 → 2.1.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 +15 -5
- package/esm/library/decoder.js +20 -30
- package/esm/library/encoder.js +33 -17
- package/esm/library/engine/mod.js +2 -2
- package/esm/library/engine/query_engine.js +40 -0
- package/esm/library/engine/query_engine_proxy.js +8 -8
- package/esm/library/engine/types.js +1 -0
- package/esm/library/lens/lens.js +416 -27
- package/esm/library/lens/mod.js +1 -1
- package/esm/library/lens/query_builder.js +86 -52
- package/esm/library/lens/search_helper.js +142 -0
- package/esm/library/lens/update_helper.js +157 -0
- package/esm/library/namespace.js +36 -0
- package/esm/library/options.js +50 -0
- package/esm/library/schema/data_types.js +3 -38
- package/esm/library/schema/search.js +1 -0
- package/esm/library/schema/utils.js +31 -6
- package/esm/library/sparql/mod.js +2 -1
- package/esm/library/sparql/sparql_expression_builders.js +18 -0
- package/esm/library/sparql/sparql_query_builders.js +65 -0
- package/esm/library/sparql/sparql_shared_builders.js +1 -0
- package/esm/library/sparql/sparql_tag.js +27 -1
- package/esm/library/sparql/sparql_update_builders.js +70 -0
- package/esm/library/sparql/stringify.js +3 -4
- package/esm/mod.js +4 -4
- package/esm/{library/namespaces → namespaces}/dbo.js +7 -2
- package/esm/{library/namespaces → namespaces}/dc.js +7 -2
- package/esm/{library/namespaces → namespaces}/dcterms.js +7 -2
- package/esm/{library/namespaces → namespaces}/foaf.js +7 -2
- package/esm/{library/namespaces → namespaces}/gr.js +7 -2
- package/esm/namespaces/ldkit.js +11 -0
- package/esm/namespaces/owl.js +91 -0
- package/{script/library → esm}/namespaces/rdf.js +7 -4
- package/{script/library → esm}/namespaces/rdfs.js +7 -4
- package/esm/{library/namespaces → namespaces}/schema.js +7 -2
- package/esm/{library/namespaces → namespaces}/sioc.js +7 -2
- package/{script/library → esm}/namespaces/skos.js +7 -4
- package/{script/library → esm}/namespaces/xsd.js +7 -4
- package/esm/namespaces.js +30 -1
- package/esm/rdf.js +14 -1
- package/esm/sparql.js +13 -0
- package/package.json +8 -8
- package/script/library/decoder.js +25 -38
- package/script/library/encoder.js +38 -24
- package/script/library/engine/mod.js +16 -5
- package/script/library/engine/query_engine.js +40 -0
- package/script/library/engine/query_engine_proxy.js +7 -7
- package/script/library/engine/types.js +2 -0
- package/script/library/lens/lens.js +417 -29
- package/script/library/lens/mod.js +15 -4
- package/script/library/lens/query_builder.js +87 -56
- package/script/library/lens/search_helper.js +146 -0
- package/script/library/lens/update_helper.js +161 -0
- package/script/library/namespace.js +40 -0
- package/script/library/options.js +56 -0
- package/script/library/schema/data_types.js +3 -41
- package/script/library/schema/search.js +2 -0
- package/script/library/schema/utils.js +33 -11
- package/script/library/sparql/mod.js +17 -3
- package/script/library/sparql/sparql_expression_builders.js +22 -0
- package/script/library/sparql/sparql_query_builders.js +65 -0
- package/script/library/sparql/sparql_shared_builders.js +3 -1
- package/script/library/sparql/sparql_tag.js +30 -7
- package/script/library/sparql/sparql_update_builders.js +70 -0
- package/script/library/sparql/stringify.js +4 -8
- package/script/mod.js +20 -11
- package/script/{library/namespaces → namespaces}/dbo.js +8 -2
- package/script/{library/namespaces → namespaces}/dc.js +8 -2
- package/script/{library/namespaces → namespaces}/dcterms.js +8 -2
- package/script/{library/namespaces → namespaces}/foaf.js +8 -2
- package/script/{library/namespaces → namespaces}/gr.js +8 -2
- package/script/namespaces/ldkit.js +14 -0
- package/script/namespaces/owl.js +94 -0
- package/{esm/library → script}/namespaces/rdf.js +10 -2
- package/{esm/library → script}/namespaces/rdfs.js +10 -2
- package/script/{library/namespaces → namespaces}/schema.js +8 -2
- package/script/{library/namespaces → namespaces}/sioc.js +8 -2
- package/{esm/library → script}/namespaces/skos.js +10 -2
- package/{esm/library → script}/namespaces/xsd.js +10 -2
- package/script/namespaces.js +44 -1
- package/script/rdf.js +20 -15
- package/script/sparql.js +13 -0
- package/types/library/decoder.d.ts +4 -3
- package/types/library/encoder.d.ts +5 -3
- package/types/library/engine/mod.d.ts +2 -2
- package/types/library/engine/query_engine.d.ts +50 -9
- package/types/library/engine/query_engine_proxy.d.ts +4 -3
- package/types/library/engine/types.d.ts +23 -0
- package/types/library/lens/lens.d.ts +401 -24
- package/types/library/lens/mod.d.ts +1 -1
- package/types/library/lens/query_builder.d.ts +11 -11
- package/types/library/lens/search_helper.d.ts +21 -0
- package/types/library/lens/types.d.ts +5 -2
- package/types/library/lens/update_helper.d.ts +23 -0
- package/types/library/namespace.d.ts +41 -0
- package/types/library/options.d.ts +70 -0
- package/types/library/rdf.d.ts +8 -15
- package/types/library/schema/data_types.d.ts +44 -37
- package/types/library/schema/interface.d.ts +75 -20
- package/types/library/schema/mod.d.ts +4 -2
- package/types/library/schema/schema.d.ts +23 -16
- package/types/library/schema/search.d.ts +20 -0
- package/types/library/schema/utils.d.ts +3 -3
- package/types/library/sparql/mod.d.ts +2 -1
- package/types/library/sparql/sparql_expression_builders.d.ts +19 -0
- package/types/library/sparql/sparql_query_builders.d.ts +68 -3
- package/types/library/sparql/sparql_shared_builders.d.ts +1 -0
- package/types/library/sparql/sparql_tag.d.ts +29 -1
- package/types/library/sparql/sparql_update_builders.d.ts +68 -0
- package/types/mod.d.ts +5 -6
- package/types/namespaces/dbo.d.ts +10 -0
- package/types/namespaces/dc.d.ts +10 -0
- package/types/namespaces/dcterms.d.ts +10 -0
- package/types/namespaces/foaf.d.ts +10 -0
- package/types/namespaces/gr.d.ts +10 -0
- package/types/namespaces/ldkit.d.ts +10 -0
- package/types/namespaces/owl.d.ts +10 -0
- package/types/namespaces/rdf.d.ts +10 -0
- package/types/namespaces/rdfs.d.ts +10 -0
- package/types/namespaces/schema.d.ts +10 -0
- package/types/namespaces/sioc.d.ts +10 -0
- package/types/namespaces/skos.d.ts +10 -0
- package/types/namespaces/xsd.d.ts +10 -0
- package/types/namespaces.d.ts +30 -1
- package/types/rdf.d.ts +14 -1
- package/types/sparql.d.ts +13 -0
- package/esm/library/global.js +0 -25
- package/esm/library/lens/query_helper.js +0 -102
- package/esm/library/namespaces/ldkit.js +0 -6
- package/esm/library/namespaces/mod.js +0 -13
- package/esm/library/namespaces/namespace.js +0 -11
- package/script/library/global.js +0 -32
- package/script/library/lens/query_helper.js +0 -106
- package/script/library/namespaces/ldkit.js +0 -8
- package/script/library/namespaces/mod.js +0 -32
- package/script/library/namespaces/namespace.js +0 -15
- package/types/library/global.d.ts +0 -5
- package/types/library/lens/query_helper.d.ts +0 -19
- package/types/library/namespaces/dbo.d.ts +0 -3649
- package/types/library/namespaces/dc.d.ts +0 -21
- package/types/library/namespaces/dcterms.d.ts +0 -104
- package/types/library/namespaces/foaf.d.ts +0 -69
- package/types/library/namespaces/gr.d.ts +0 -175
- package/types/library/namespaces/ldkit.d.ts +0 -7
- package/types/library/namespaces/mod.d.ts +0 -13
- package/types/library/namespaces/namespace.d.ts +0 -15
- package/types/library/namespaces/rdf.d.ts +0 -28
- package/types/library/namespaces/rdfs.d.ts +0 -21
- package/types/library/namespaces/schema.d.ts +0 -2697
- package/types/library/namespaces/sioc.d.ts +0 -105
- package/types/library/namespaces/skos.d.ts +0 -38
- package/types/library/namespaces/xsd.d.ts +0 -56
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ import * as ldkit from "https://deno.land/x/ldkit/mod.ts";
|
|
|
40
40
|
### Create data schema and set up RDF source
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
import { type
|
|
43
|
+
import { createLens, type Options } from "ldkit";
|
|
44
44
|
import { dbo, rdfs, xsd } from "ldkit/namespaces";
|
|
45
45
|
|
|
46
46
|
// Create a schema
|
|
@@ -54,14 +54,14 @@ const PersonSchema = {
|
|
|
54
54
|
},
|
|
55
55
|
} as const;
|
|
56
56
|
|
|
57
|
-
// Create
|
|
58
|
-
const
|
|
57
|
+
// Create options for query engine
|
|
58
|
+
const options: Options = {
|
|
59
59
|
sources: ["https://dbpedia.org/sparql"], // SPARQL endpoint
|
|
60
60
|
language: "en", // Preferred language
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
// Create a resource using the data schema and
|
|
64
|
-
const Persons = createLens(PersonSchema,
|
|
63
|
+
// Create a resource using the data schema and options above
|
|
64
|
+
const Persons = createLens(PersonSchema, options);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
### List all available data
|
|
@@ -110,6 +110,16 @@ Persons.delete("http://dbpedia.org/resource/Alan_Turing");
|
|
|
110
110
|
|
|
111
111
|
More complex examples can be found in [documentation](https://ldkit.io/docs).
|
|
112
112
|
|
|
113
|
+
## Specification Compliance
|
|
114
|
+
|
|
115
|
+
LDkit complies with the following specifications:
|
|
116
|
+
|
|
117
|
+
- [RDF/JS: Data model specification](https://rdf.js.org/data-model-spec/)
|
|
118
|
+
- [RDF/JS: Query specification](https://rdf.js.org/query-spec/)
|
|
119
|
+
- [SPARQL 1.1 Query Language](https://www.w3.org/TR/sparql11-query/)
|
|
120
|
+
- [SPARQL 1.1 Update](https://www.w3.org/TR/2013/REC-sparql11-update-20130321/)
|
|
121
|
+
- [SPARQL 1.1 Protocol](https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/)
|
|
122
|
+
|
|
113
123
|
## License
|
|
114
124
|
|
|
115
125
|
[MIT License](./LICENSE.md)
|
package/esm/library/decoder.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { fromRdf } from "./rdf.js";
|
|
2
|
-
import ldkit from "
|
|
3
|
-
import rdf from "
|
|
2
|
+
import { ldkit } from "../namespaces/ldkit.js";
|
|
3
|
+
import { rdf } from "../namespaces/rdf.js";
|
|
4
|
+
export const decode = (graph, schema, options) => {
|
|
5
|
+
return Decoder.decode(graph, schema, options);
|
|
6
|
+
};
|
|
4
7
|
class Decoder {
|
|
5
|
-
constructor(graph, schema,
|
|
8
|
+
constructor(graph, schema, options) {
|
|
6
9
|
Object.defineProperty(this, "graph", {
|
|
7
10
|
enumerable: true,
|
|
8
11
|
configurable: true,
|
|
@@ -15,7 +18,7 @@ class Decoder {
|
|
|
15
18
|
writable: true,
|
|
16
19
|
value: void 0
|
|
17
20
|
});
|
|
18
|
-
Object.defineProperty(this, "
|
|
21
|
+
Object.defineProperty(this, "options", {
|
|
19
22
|
enumerable: true,
|
|
20
23
|
configurable: true,
|
|
21
24
|
writable: true,
|
|
@@ -29,10 +32,10 @@ class Decoder {
|
|
|
29
32
|
});
|
|
30
33
|
this.graph = graph;
|
|
31
34
|
this.schema = schema;
|
|
32
|
-
this.
|
|
35
|
+
this.options = options;
|
|
33
36
|
}
|
|
34
|
-
static decode(graph, schema,
|
|
35
|
-
return new Decoder(graph, schema,
|
|
37
|
+
static decode(graph, schema, options) {
|
|
38
|
+
return new Decoder(graph, schema, options).decode();
|
|
36
39
|
}
|
|
37
40
|
getCachedNode(nodeIri, schema) {
|
|
38
41
|
if (!this.cache.has(schema)) {
|
|
@@ -75,7 +78,6 @@ class Decoder {
|
|
|
75
78
|
if (!node) {
|
|
76
79
|
throw new Error(`Error decoding graph, <${nodeIri}> node not found.`);
|
|
77
80
|
}
|
|
78
|
-
output.$type = this.decodeNodeType(node);
|
|
79
81
|
Object.keys(schema).forEach((key) => {
|
|
80
82
|
if (key === "@type") {
|
|
81
83
|
return;
|
|
@@ -88,20 +90,11 @@ class Decoder {
|
|
|
88
90
|
this.setCachedNode(nodeIri, schema, output);
|
|
89
91
|
return output;
|
|
90
92
|
}
|
|
91
|
-
decodeNodeType(node) {
|
|
92
|
-
const typeTerms = node.get(rdf.type);
|
|
93
|
-
if (!typeTerms) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
return typeTerms.reduce((acc, term) => {
|
|
97
|
-
if (term.value !== ldkit.Resource) {
|
|
98
|
-
acc.push(term.value);
|
|
99
|
-
}
|
|
100
|
-
return acc;
|
|
101
|
-
}, []);
|
|
102
|
-
}
|
|
103
93
|
decodeNodeProperty(nodeIri, node, propertyKey, property) {
|
|
104
|
-
const
|
|
94
|
+
const allTerms = node.get(property["@id"]);
|
|
95
|
+
const terms = property["@id"] !== rdf.type
|
|
96
|
+
? allTerms
|
|
97
|
+
: allTerms?.filter((term) => term.value !== ldkit.Resource);
|
|
105
98
|
if (!terms) {
|
|
106
99
|
if (!property["@optional"]) {
|
|
107
100
|
// No data, required property
|
|
@@ -109,7 +102,7 @@ class Decoder {
|
|
|
109
102
|
}
|
|
110
103
|
else {
|
|
111
104
|
// No data, optional property
|
|
112
|
-
return property["@array"] ? [] :
|
|
105
|
+
return property["@array"] ? [] : null;
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
if (property["@multilang"]) {
|
|
@@ -141,13 +134,13 @@ class Decoder {
|
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
if (property["@array"]) {
|
|
144
|
-
if (property["@
|
|
137
|
+
if (property["@schema"]) {
|
|
145
138
|
// Collection of resources specified by sub schema
|
|
146
139
|
return terms.map((term) => {
|
|
147
140
|
if (term.termType !== "NamedNode" && term.termType !== "BlankNode") {
|
|
148
141
|
throw new Error(`Property "${propertyKey}" data type mismatch - expected a node, but received ${term.termType} instead on resource <${nodeIri}>`);
|
|
149
142
|
}
|
|
150
|
-
return this.decodeNode(term.value, property["@
|
|
143
|
+
return this.decodeNode(term.value, property["@schema"]);
|
|
151
144
|
});
|
|
152
145
|
}
|
|
153
146
|
else {
|
|
@@ -161,15 +154,15 @@ class Decoder {
|
|
|
161
154
|
}
|
|
162
155
|
}
|
|
163
156
|
// Single return value expected from this point on
|
|
164
|
-
if (property["@
|
|
157
|
+
if (property["@schema"]) {
|
|
165
158
|
for (const term of terms) {
|
|
166
159
|
if (term.termType === "NamedNode" || term.termType === "BlankNode") {
|
|
167
|
-
return this.decodeNode(term.value, property["@
|
|
160
|
+
return this.decodeNode(term.value, property["@schema"]);
|
|
168
161
|
}
|
|
169
162
|
}
|
|
170
163
|
throw new Error(`Property "${propertyKey}" data type mismatch - expected a named node for context on resource <${nodeIri}>`);
|
|
171
164
|
}
|
|
172
|
-
const preferredLanguage = this.
|
|
165
|
+
const preferredLanguage = this.options.language;
|
|
173
166
|
if (preferredLanguage) {
|
|
174
167
|
// Try to find a term that corresponds to the preferred language
|
|
175
168
|
for (const term of terms) {
|
|
@@ -199,6 +192,3 @@ class Decoder {
|
|
|
199
192
|
}
|
|
200
193
|
}
|
|
201
194
|
}
|
|
202
|
-
export const decode = (graph, schema, context) => {
|
|
203
|
-
return Decoder.decode(graph, schema, context);
|
|
204
|
-
};
|
package/esm/library/encoder.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import { DataFactory, toRdf } from "./rdf.js";
|
|
2
|
-
import xsd from "
|
|
3
|
-
import rdf from "
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { xsd } from "../namespaces/xsd.js";
|
|
3
|
+
import { rdf } from "../namespaces/rdf.js";
|
|
4
|
+
import { ldkit } from "../namespaces/ldkit.js";
|
|
5
|
+
export const encode = (node, schema, options, includeType = true, variableInitCounter = 0) => {
|
|
6
|
+
return Encoder.encode(node, schema, options, includeType, variableInitCounter);
|
|
7
|
+
};
|
|
8
|
+
export const encodeValue = (value, datatype, df) => {
|
|
9
|
+
if (datatype === ldkit.IRI) {
|
|
10
|
+
return df.namedNode(value);
|
|
11
|
+
}
|
|
12
|
+
return toRdf(value, {
|
|
13
|
+
datatype: df.namedNode(datatype),
|
|
14
|
+
});
|
|
6
15
|
};
|
|
7
16
|
class Encoder {
|
|
8
|
-
constructor(
|
|
9
|
-
Object.defineProperty(this, "
|
|
17
|
+
constructor(options, includeType, variableInitCounter) {
|
|
18
|
+
Object.defineProperty(this, "options", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "includeType", {
|
|
10
25
|
enumerable: true,
|
|
11
26
|
configurable: true,
|
|
12
27
|
writable: true,
|
|
@@ -32,11 +47,12 @@ class Encoder {
|
|
|
32
47
|
writable: true,
|
|
33
48
|
value: []
|
|
34
49
|
});
|
|
35
|
-
this.
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.includeType = includeType;
|
|
36
52
|
this.variableCounter = variableInitCounter;
|
|
37
53
|
}
|
|
38
|
-
static encode(node, schema,
|
|
39
|
-
return new Encoder(
|
|
54
|
+
static encode(node, schema, options, includeType, variableInitCounter) {
|
|
55
|
+
return new Encoder(options, includeType, variableInitCounter).encode(node, schema);
|
|
40
56
|
}
|
|
41
57
|
encode(node, schema) {
|
|
42
58
|
const nodeId = this.getNodeId(node);
|
|
@@ -58,7 +74,9 @@ class Encoder {
|
|
|
58
74
|
return node.$type ? [node.$type] : [];
|
|
59
75
|
}
|
|
60
76
|
encodeNode(node, schema, nodeId) {
|
|
61
|
-
this.
|
|
77
|
+
if (this.includeType) {
|
|
78
|
+
this.encodeNodeType(node, schema["@type"], nodeId);
|
|
79
|
+
}
|
|
62
80
|
Object.keys(schema).forEach((key) => {
|
|
63
81
|
if (key === "@type") {
|
|
64
82
|
return;
|
|
@@ -96,22 +114,20 @@ class Encoder {
|
|
|
96
114
|
}
|
|
97
115
|
const values = Array.isArray(value) ? value : [value];
|
|
98
116
|
values.forEach((val) => {
|
|
99
|
-
if (property["@
|
|
117
|
+
if (property["@schema"]) {
|
|
100
118
|
const subNodeId = this.getNodeId(val);
|
|
101
|
-
this.encodeNode(val, property["@
|
|
119
|
+
this.encodeNode(val, property["@schema"], subNodeId);
|
|
102
120
|
this.push(nodeId, propertyId, subNodeId);
|
|
103
121
|
return;
|
|
104
122
|
}
|
|
105
123
|
const propertyType = property["@type"] ? property["@type"] : xsd.string;
|
|
106
|
-
if (typeof val === "string" && this.
|
|
124
|
+
if (typeof val === "string" && this.options.language) {
|
|
107
125
|
if (propertyType === xsd.string || propertyType === rdf.langString) {
|
|
108
|
-
this.push(nodeId, propertyId, this.df.literal(val, this.
|
|
126
|
+
this.push(nodeId, propertyId, this.df.literal(val, this.options.language));
|
|
109
127
|
return;
|
|
110
128
|
}
|
|
111
129
|
}
|
|
112
|
-
const rdfValue =
|
|
113
|
-
datatype: this.df.namedNode(propertyType),
|
|
114
|
-
});
|
|
130
|
+
const rdfValue = encodeValue(val, propertyType, this.df);
|
|
115
131
|
this.push(nodeId, propertyId, rdfValue);
|
|
116
132
|
});
|
|
117
133
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./query_engine.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { getResponseTypes, resolve, } from "./query_resolvers.js";
|
|
2
|
+
/**
|
|
3
|
+
* A query engine that can query a SPARQL endpoint.
|
|
4
|
+
*
|
|
5
|
+
* Implements {@link IQueryEngine} interface.
|
|
6
|
+
*
|
|
7
|
+
* This engine is used by default if no other engine is configured.
|
|
8
|
+
* See {@link Options} for more details.
|
|
9
|
+
*
|
|
10
|
+
* If you need to query other data sources, or multiple SPARQL endpoints,
|
|
11
|
+
* you can use [Comunica](https://comunica.dev) instead, extend this engine,
|
|
12
|
+
* or implement your own.
|
|
13
|
+
*/
|
|
2
14
|
export class QueryEngine {
|
|
3
15
|
getSparqlEndpoint(context) {
|
|
4
16
|
if (!context) {
|
|
@@ -52,15 +64,43 @@ export class QueryEngine {
|
|
|
52
64
|
}
|
|
53
65
|
return resolve(type, response);
|
|
54
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Executes a SPARQL SELECT query and returns a stream of bindings.
|
|
69
|
+
*
|
|
70
|
+
* @param query SPARQL query string
|
|
71
|
+
* @param context Engine context
|
|
72
|
+
* @returns Stream of bindings
|
|
73
|
+
*/
|
|
55
74
|
queryBindings(query, context) {
|
|
56
75
|
return this.queryAndResolve("bindings", query, context);
|
|
57
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Executes a SPARQL ASK query and returns a boolean result.
|
|
79
|
+
*
|
|
80
|
+
* @param query SPARQL query string
|
|
81
|
+
* @param context Engine context
|
|
82
|
+
* @returns Boolean result
|
|
83
|
+
*/
|
|
58
84
|
queryBoolean(query, context) {
|
|
59
85
|
return this.queryAndResolve("boolean", query, context);
|
|
60
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Executes a SPARQL CONSTRUCT query and returns a stream of quads.
|
|
89
|
+
*
|
|
90
|
+
* @param query SPARQL query string
|
|
91
|
+
* @param context Engine context
|
|
92
|
+
* @returns Stream of quads
|
|
93
|
+
*/
|
|
61
94
|
queryQuads(query, context) {
|
|
62
95
|
return this.queryAndResolve("quads", query, context);
|
|
63
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Executes a SPARQL UPDATE query and returns nothing.
|
|
99
|
+
*
|
|
100
|
+
* @param query SPARQL query string
|
|
101
|
+
* @param context Engine context
|
|
102
|
+
* @returns Nothing
|
|
103
|
+
*/
|
|
64
104
|
async queryVoid(query, context) {
|
|
65
105
|
await this.query(query, "application/sparql-results+json", context);
|
|
66
106
|
}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { quadsToGraph } from "../rdf.js";
|
|
2
|
-
import { resolveContext, resolveEngine } from "../global.js";
|
|
1
|
+
import { N3, quadsToGraph } from "../rdf.js";
|
|
3
2
|
export class QueryEngineProxy {
|
|
4
|
-
constructor(
|
|
5
|
-
Object.defineProperty(this, "
|
|
3
|
+
constructor(engine, context) {
|
|
4
|
+
Object.defineProperty(this, "engine", {
|
|
6
5
|
enumerable: true,
|
|
7
6
|
configurable: true,
|
|
8
7
|
writable: true,
|
|
9
8
|
value: void 0
|
|
10
9
|
});
|
|
11
|
-
Object.defineProperty(this, "
|
|
10
|
+
Object.defineProperty(this, "context", {
|
|
12
11
|
enumerable: true,
|
|
13
12
|
configurable: true,
|
|
14
13
|
writable: true,
|
|
15
14
|
value: void 0
|
|
16
15
|
});
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
16
|
+
this.engine = engine;
|
|
17
|
+
this.context = context;
|
|
19
18
|
}
|
|
20
19
|
queryBoolean(query) {
|
|
21
20
|
return this.engine.queryBoolean(query, this.context);
|
|
@@ -27,7 +26,8 @@ export class QueryEngineProxy {
|
|
|
27
26
|
async queryGraph(query) {
|
|
28
27
|
const quadStream = await this.engine.queryQuads(query, this.context);
|
|
29
28
|
const quads = await (quadStream.toArray());
|
|
30
|
-
|
|
29
|
+
const store = new N3.Store(quads);
|
|
30
|
+
return quadsToGraph(store);
|
|
31
31
|
}
|
|
32
32
|
queryVoid(query) {
|
|
33
33
|
return this.engine.queryVoid(query, this.context);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|