ldkit 1.1.0 → 2.0.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 +5 -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 +414 -25
- package/esm/library/lens/mod.js +1 -1
- package/esm/library/lens/query_builder.js +81 -50
- 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 +2 -2
- 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 +415 -27
- package/script/library/lens/mod.js +15 -4
- package/script/library/lens/query_builder.js +82 -54
- 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 +400 -23
- package/types/library/lens/mod.d.ts +1 -1
- package/types/library/lens/query_builder.d.ts +10 -10
- 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 +72 -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/esm/rdf.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* RDF utilities
|
|
3
|
+
*
|
|
4
|
+
* This module contains a re-export of external RDF libraries that are used
|
|
5
|
+
* in LDkit and may be used in tandem with LDkit in Linked Data applications as well.
|
|
6
|
+
*
|
|
7
|
+
* Included packages:
|
|
8
|
+
* - [@rdfjs/types](https://github.com/rdfjs/types) [RDF/JS](https://rdf.js.org/) authoritative TypeScript typings
|
|
9
|
+
* - [n3](https://rdf.js.org/N3.js/) RDF parser and serializer
|
|
10
|
+
* - [rdf-data-factory](https://github.com/rubensworks/rdf-data-factory.js) A TypeScript/JavaScript implementation of the RDF/JS data factory
|
|
11
|
+
* - [rdf-literal](https://github.com/rubensworks/rdf-literal.js) Translates between RDF literals and JavaScript primitives
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
export { DataFactory, DefaultGraph, fromRdf, N3, toRdf, } from "./library/rdf.js";
|
package/esm/sparql.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPARQL builders that provide a fluent interface for building SPARQL queries
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { SELECT } from "ldkit/sparql";
|
|
7
|
+
*
|
|
8
|
+
* const query = SELECT`?s ?p ?o`.WHERE`?s ?p ?o`.LIMIT(10).build();
|
|
9
|
+
* console.log(query); // SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10;
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
1
14
|
export * from "./library/sparql/mod.js";
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "./script/mod.js",
|
|
4
4
|
"types": "./types/mod.d.ts",
|
|
5
5
|
"name": "ldkit",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "2.0.0",
|
|
7
7
|
"description": "LDkit, a Linked Data query toolkit for TypeScript developers",
|
|
8
8
|
"homepage": "https://ldkit.io",
|
|
9
9
|
"author": "Karel Klima <karelklima@gmail.com> (https://karelklima.com)",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@comunica/types": "2.6.8",
|
|
68
|
+
"@rdfjs/types": "*",
|
|
68
69
|
"@types/n3": "*",
|
|
69
70
|
"asynciterator": "3.8.0",
|
|
70
71
|
"n3": "1.17.2",
|
|
71
72
|
"rdf-data-factory": "1.1.1",
|
|
72
|
-
"rdf-js": "4.0.2",
|
|
73
73
|
"rdf-literal": "1.3.1"
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.decode = void 0;
|
|
7
4
|
const rdf_js_1 = require("./rdf.js");
|
|
8
|
-
const ldkit_js_1 =
|
|
9
|
-
const rdf_js_2 =
|
|
5
|
+
const ldkit_js_1 = require("../namespaces/ldkit.js");
|
|
6
|
+
const rdf_js_2 = require("../namespaces/rdf.js");
|
|
7
|
+
const decode = (graph, schema, options) => {
|
|
8
|
+
return Decoder.decode(graph, schema, options);
|
|
9
|
+
};
|
|
10
|
+
exports.decode = decode;
|
|
10
11
|
class Decoder {
|
|
11
|
-
constructor(graph, schema,
|
|
12
|
+
constructor(graph, schema, options) {
|
|
12
13
|
Object.defineProperty(this, "graph", {
|
|
13
14
|
enumerable: true,
|
|
14
15
|
configurable: true,
|
|
@@ -21,7 +22,7 @@ class Decoder {
|
|
|
21
22
|
writable: true,
|
|
22
23
|
value: void 0
|
|
23
24
|
});
|
|
24
|
-
Object.defineProperty(this, "
|
|
25
|
+
Object.defineProperty(this, "options", {
|
|
25
26
|
enumerable: true,
|
|
26
27
|
configurable: true,
|
|
27
28
|
writable: true,
|
|
@@ -35,10 +36,10 @@ class Decoder {
|
|
|
35
36
|
});
|
|
36
37
|
this.graph = graph;
|
|
37
38
|
this.schema = schema;
|
|
38
|
-
this.
|
|
39
|
+
this.options = options;
|
|
39
40
|
}
|
|
40
|
-
static decode(graph, schema,
|
|
41
|
-
return new Decoder(graph, schema,
|
|
41
|
+
static decode(graph, schema, options) {
|
|
42
|
+
return new Decoder(graph, schema, options).decode();
|
|
42
43
|
}
|
|
43
44
|
getCachedNode(nodeIri, schema) {
|
|
44
45
|
if (!this.cache.has(schema)) {
|
|
@@ -55,17 +56,17 @@ class Decoder {
|
|
|
55
56
|
decode() {
|
|
56
57
|
const output = [];
|
|
57
58
|
for (const [iri, properties] of this.graph) {
|
|
58
|
-
if (properties.has(rdf_js_2.
|
|
59
|
-
const types = properties.get(rdf_js_2.
|
|
59
|
+
if (properties.has(rdf_js_2.rdf.type)) {
|
|
60
|
+
const types = properties.get(rdf_js_2.rdf.type);
|
|
60
61
|
for (const type of types) {
|
|
61
|
-
if (type.termType === "NamedNode" && type.value === ldkit_js_1.
|
|
62
|
+
if (type.termType === "NamedNode" && type.value === ldkit_js_1.ldkit.Resource) {
|
|
62
63
|
output.push(this.decodeNode(iri, this.schema));
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
if (this.graph.size > 0 && output.length < 1) {
|
|
68
|
-
throw new Error(`Unable to decode graph - no resources with type <${ldkit_js_1.
|
|
69
|
+
throw new Error(`Unable to decode graph - no resources with type <${ldkit_js_1.ldkit.Resource}> found`);
|
|
69
70
|
}
|
|
70
71
|
return output;
|
|
71
72
|
}
|
|
@@ -81,7 +82,6 @@ class Decoder {
|
|
|
81
82
|
if (!node) {
|
|
82
83
|
throw new Error(`Error decoding graph, <${nodeIri}> node not found.`);
|
|
83
84
|
}
|
|
84
|
-
output.$type = this.decodeNodeType(node);
|
|
85
85
|
Object.keys(schema).forEach((key) => {
|
|
86
86
|
if (key === "@type") {
|
|
87
87
|
return;
|
|
@@ -94,20 +94,11 @@ class Decoder {
|
|
|
94
94
|
this.setCachedNode(nodeIri, schema, output);
|
|
95
95
|
return output;
|
|
96
96
|
}
|
|
97
|
-
decodeNodeType(node) {
|
|
98
|
-
const typeTerms = node.get(rdf_js_2.default.type);
|
|
99
|
-
if (!typeTerms) {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
return typeTerms.reduce((acc, term) => {
|
|
103
|
-
if (term.value !== ldkit_js_1.default.Resource) {
|
|
104
|
-
acc.push(term.value);
|
|
105
|
-
}
|
|
106
|
-
return acc;
|
|
107
|
-
}, []);
|
|
108
|
-
}
|
|
109
97
|
decodeNodeProperty(nodeIri, node, propertyKey, property) {
|
|
110
|
-
const
|
|
98
|
+
const allTerms = node.get(property["@id"]);
|
|
99
|
+
const terms = property["@id"] !== rdf_js_2.rdf.type
|
|
100
|
+
? allTerms
|
|
101
|
+
: allTerms?.filter((term) => term.value !== ldkit_js_1.ldkit.Resource);
|
|
111
102
|
if (!terms) {
|
|
112
103
|
if (!property["@optional"]) {
|
|
113
104
|
// No data, required property
|
|
@@ -115,7 +106,7 @@ class Decoder {
|
|
|
115
106
|
}
|
|
116
107
|
else {
|
|
117
108
|
// No data, optional property
|
|
118
|
-
return property["@array"] ? [] :
|
|
109
|
+
return property["@array"] ? [] : null;
|
|
119
110
|
}
|
|
120
111
|
}
|
|
121
112
|
if (property["@multilang"]) {
|
|
@@ -147,13 +138,13 @@ class Decoder {
|
|
|
147
138
|
}
|
|
148
139
|
}
|
|
149
140
|
if (property["@array"]) {
|
|
150
|
-
if (property["@
|
|
141
|
+
if (property["@schema"]) {
|
|
151
142
|
// Collection of resources specified by sub schema
|
|
152
143
|
return terms.map((term) => {
|
|
153
144
|
if (term.termType !== "NamedNode" && term.termType !== "BlankNode") {
|
|
154
145
|
throw new Error(`Property "${propertyKey}" data type mismatch - expected a node, but received ${term.termType} instead on resource <${nodeIri}>`);
|
|
155
146
|
}
|
|
156
|
-
return this.decodeNode(term.value, property["@
|
|
147
|
+
return this.decodeNode(term.value, property["@schema"]);
|
|
157
148
|
});
|
|
158
149
|
}
|
|
159
150
|
else {
|
|
@@ -167,15 +158,15 @@ class Decoder {
|
|
|
167
158
|
}
|
|
168
159
|
}
|
|
169
160
|
// Single return value expected from this point on
|
|
170
|
-
if (property["@
|
|
161
|
+
if (property["@schema"]) {
|
|
171
162
|
for (const term of terms) {
|
|
172
163
|
if (term.termType === "NamedNode" || term.termType === "BlankNode") {
|
|
173
|
-
return this.decodeNode(term.value, property["@
|
|
164
|
+
return this.decodeNode(term.value, property["@schema"]);
|
|
174
165
|
}
|
|
175
166
|
}
|
|
176
167
|
throw new Error(`Property "${propertyKey}" data type mismatch - expected a named node for context on resource <${nodeIri}>`);
|
|
177
168
|
}
|
|
178
|
-
const preferredLanguage = this.
|
|
169
|
+
const preferredLanguage = this.options.language;
|
|
179
170
|
if (preferredLanguage) {
|
|
180
171
|
// Try to find a term that corresponds to the preferred language
|
|
181
172
|
for (const term of terms) {
|
|
@@ -205,7 +196,3 @@ class Decoder {
|
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
198
|
}
|
|
208
|
-
const decode = (graph, schema, context) => {
|
|
209
|
-
return Decoder.decode(graph, schema, context);
|
|
210
|
-
};
|
|
211
|
-
exports.decode = decode;
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.encode = void 0;
|
|
3
|
+
exports.encodeValue = exports.encode = void 0;
|
|
7
4
|
const rdf_js_1 = require("./rdf.js");
|
|
8
|
-
const xsd_js_1 =
|
|
9
|
-
const rdf_js_2 =
|
|
10
|
-
const
|
|
11
|
-
|
|
5
|
+
const xsd_js_1 = require("../namespaces/xsd.js");
|
|
6
|
+
const rdf_js_2 = require("../namespaces/rdf.js");
|
|
7
|
+
const ldkit_js_1 = require("../namespaces/ldkit.js");
|
|
8
|
+
const encode = (node, schema, options, includeType = true, variableInitCounter = 0) => {
|
|
9
|
+
return Encoder.encode(node, schema, options, includeType, variableInitCounter);
|
|
12
10
|
};
|
|
13
11
|
exports.encode = encode;
|
|
12
|
+
const encodeValue = (value, datatype, df) => {
|
|
13
|
+
if (datatype === ldkit_js_1.ldkit.IRI) {
|
|
14
|
+
return df.namedNode(value);
|
|
15
|
+
}
|
|
16
|
+
return (0, rdf_js_1.toRdf)(value, {
|
|
17
|
+
datatype: df.namedNode(datatype),
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
exports.encodeValue = encodeValue;
|
|
14
21
|
class Encoder {
|
|
15
|
-
constructor(
|
|
16
|
-
Object.defineProperty(this, "
|
|
22
|
+
constructor(options, includeType, variableInitCounter) {
|
|
23
|
+
Object.defineProperty(this, "options", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "includeType", {
|
|
17
30
|
enumerable: true,
|
|
18
31
|
configurable: true,
|
|
19
32
|
writable: true,
|
|
@@ -39,11 +52,12 @@ class Encoder {
|
|
|
39
52
|
writable: true,
|
|
40
53
|
value: []
|
|
41
54
|
});
|
|
42
|
-
this.
|
|
55
|
+
this.options = options;
|
|
56
|
+
this.includeType = includeType;
|
|
43
57
|
this.variableCounter = variableInitCounter;
|
|
44
58
|
}
|
|
45
|
-
static encode(node, schema,
|
|
46
|
-
return new Encoder(
|
|
59
|
+
static encode(node, schema, options, includeType, variableInitCounter) {
|
|
60
|
+
return new Encoder(options, includeType, variableInitCounter).encode(node, schema);
|
|
47
61
|
}
|
|
48
62
|
encode(node, schema) {
|
|
49
63
|
const nodeId = this.getNodeId(node);
|
|
@@ -65,7 +79,9 @@ class Encoder {
|
|
|
65
79
|
return node.$type ? [node.$type] : [];
|
|
66
80
|
}
|
|
67
81
|
encodeNode(node, schema, nodeId) {
|
|
68
|
-
this.
|
|
82
|
+
if (this.includeType) {
|
|
83
|
+
this.encodeNodeType(node, schema["@type"], nodeId);
|
|
84
|
+
}
|
|
69
85
|
Object.keys(schema).forEach((key) => {
|
|
70
86
|
if (key === "@type") {
|
|
71
87
|
return;
|
|
@@ -76,7 +92,7 @@ class Encoder {
|
|
|
76
92
|
encodeNodeType(node, requiredTypes, nodeId) {
|
|
77
93
|
const finalTypes = new Set([...this.getNodeTypes(node), ...requiredTypes]);
|
|
78
94
|
finalTypes.forEach((type) => {
|
|
79
|
-
this.push(nodeId, this.df.namedNode(rdf_js_2.
|
|
95
|
+
this.push(nodeId, this.df.namedNode(rdf_js_2.rdf.type), this.df.namedNode(type));
|
|
80
96
|
});
|
|
81
97
|
}
|
|
82
98
|
encodeNodeProperty(value, property, nodeId) {
|
|
@@ -103,22 +119,20 @@ class Encoder {
|
|
|
103
119
|
}
|
|
104
120
|
const values = Array.isArray(value) ? value : [value];
|
|
105
121
|
values.forEach((val) => {
|
|
106
|
-
if (property["@
|
|
122
|
+
if (property["@schema"]) {
|
|
107
123
|
const subNodeId = this.getNodeId(val);
|
|
108
|
-
this.encodeNode(val, property["@
|
|
124
|
+
this.encodeNode(val, property["@schema"], subNodeId);
|
|
109
125
|
this.push(nodeId, propertyId, subNodeId);
|
|
110
126
|
return;
|
|
111
127
|
}
|
|
112
|
-
const propertyType = property["@type"] ? property["@type"] : xsd_js_1.
|
|
113
|
-
if (typeof val === "string" && this.
|
|
114
|
-
if (propertyType === xsd_js_1.
|
|
115
|
-
this.push(nodeId, propertyId, this.df.literal(val, this.
|
|
128
|
+
const propertyType = property["@type"] ? property["@type"] : xsd_js_1.xsd.string;
|
|
129
|
+
if (typeof val === "string" && this.options.language) {
|
|
130
|
+
if (propertyType === xsd_js_1.xsd.string || propertyType === rdf_js_2.rdf.langString) {
|
|
131
|
+
this.push(nodeId, propertyId, this.df.literal(val, this.options.language));
|
|
116
132
|
return;
|
|
117
133
|
}
|
|
118
134
|
}
|
|
119
|
-
const rdfValue = (0,
|
|
120
|
-
datatype: this.df.namedNode(propertyType),
|
|
121
|
-
});
|
|
135
|
+
const rdfValue = (0, exports.encodeValue)(val, propertyType, this.df);
|
|
122
136
|
this.push(nodeId, propertyId, rdfValue);
|
|
123
137
|
});
|
|
124
138
|
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "QueryEngine", { enumerable: true, get: function () { return query_engine_js_1.QueryEngine; } });
|
|
6
|
-
var query_engine_proxy_js_1 = require("./query_engine_proxy.js");
|
|
7
|
-
Object.defineProperty(exports, "QueryEngineProxy", { enumerable: true, get: function () { return query_engine_proxy_js_1.QueryEngineProxy; } });
|
|
17
|
+
__exportStar(require("./query_engine.js"), exports);
|
|
18
|
+
__exportStar(require("./types.js"), exports);
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryEngine = void 0;
|
|
4
4
|
const query_resolvers_js_1 = require("./query_resolvers.js");
|
|
5
|
+
/**
|
|
6
|
+
* A query engine that can query a SPARQL endpoint.
|
|
7
|
+
*
|
|
8
|
+
* Implements {@link IQueryEngine} interface.
|
|
9
|
+
*
|
|
10
|
+
* This engine is used by default if no other engine is configured.
|
|
11
|
+
* See {@link Options} for more details.
|
|
12
|
+
*
|
|
13
|
+
* If you need to query other data sources, or multiple SPARQL endpoints,
|
|
14
|
+
* you can use [Comunica](https://comunica.dev) instead, extend this engine,
|
|
15
|
+
* or implement your own.
|
|
16
|
+
*/
|
|
5
17
|
class QueryEngine {
|
|
6
18
|
getSparqlEndpoint(context) {
|
|
7
19
|
if (!context) {
|
|
@@ -55,15 +67,43 @@ class QueryEngine {
|
|
|
55
67
|
}
|
|
56
68
|
return (0, query_resolvers_js_1.resolve)(type, response);
|
|
57
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Executes a SPARQL SELECT query and returns a stream of bindings.
|
|
72
|
+
*
|
|
73
|
+
* @param query SPARQL query string
|
|
74
|
+
* @param context Engine context
|
|
75
|
+
* @returns Stream of bindings
|
|
76
|
+
*/
|
|
58
77
|
queryBindings(query, context) {
|
|
59
78
|
return this.queryAndResolve("bindings", query, context);
|
|
60
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Executes a SPARQL ASK query and returns a boolean result.
|
|
82
|
+
*
|
|
83
|
+
* @param query SPARQL query string
|
|
84
|
+
* @param context Engine context
|
|
85
|
+
* @returns Boolean result
|
|
86
|
+
*/
|
|
61
87
|
queryBoolean(query, context) {
|
|
62
88
|
return this.queryAndResolve("boolean", query, context);
|
|
63
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Executes a SPARQL CONSTRUCT query and returns a stream of quads.
|
|
92
|
+
*
|
|
93
|
+
* @param query SPARQL query string
|
|
94
|
+
* @param context Engine context
|
|
95
|
+
* @returns Stream of quads
|
|
96
|
+
*/
|
|
64
97
|
queryQuads(query, context) {
|
|
65
98
|
return this.queryAndResolve("quads", query, context);
|
|
66
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Executes a SPARQL UPDATE query and returns nothing.
|
|
102
|
+
*
|
|
103
|
+
* @param query SPARQL query string
|
|
104
|
+
* @param context Engine context
|
|
105
|
+
* @returns Nothing
|
|
106
|
+
*/
|
|
67
107
|
async queryVoid(query, context) {
|
|
68
108
|
await this.query(query, "application/sparql-results+json", context);
|
|
69
109
|
}
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryEngineProxy = void 0;
|
|
4
4
|
const rdf_js_1 = require("../rdf.js");
|
|
5
|
-
const global_js_1 = require("../global.js");
|
|
6
5
|
class QueryEngineProxy {
|
|
7
|
-
constructor(
|
|
8
|
-
Object.defineProperty(this, "
|
|
6
|
+
constructor(engine, context) {
|
|
7
|
+
Object.defineProperty(this, "engine", {
|
|
9
8
|
enumerable: true,
|
|
10
9
|
configurable: true,
|
|
11
10
|
writable: true,
|
|
12
11
|
value: void 0
|
|
13
12
|
});
|
|
14
|
-
Object.defineProperty(this, "
|
|
13
|
+
Object.defineProperty(this, "context", {
|
|
15
14
|
enumerable: true,
|
|
16
15
|
configurable: true,
|
|
17
16
|
writable: true,
|
|
18
17
|
value: void 0
|
|
19
18
|
});
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
19
|
+
this.engine = engine;
|
|
20
|
+
this.context = context;
|
|
22
21
|
}
|
|
23
22
|
queryBoolean(query) {
|
|
24
23
|
return this.engine.queryBoolean(query, this.context);
|
|
@@ -30,7 +29,8 @@ class QueryEngineProxy {
|
|
|
30
29
|
async queryGraph(query) {
|
|
31
30
|
const quadStream = await this.engine.queryQuads(query, this.context);
|
|
32
31
|
const quads = await (quadStream.toArray());
|
|
33
|
-
|
|
32
|
+
const store = new rdf_js_1.N3.Store(quads);
|
|
33
|
+
return (0, rdf_js_1.quadsToGraph)(store);
|
|
34
34
|
}
|
|
35
35
|
queryVoid(query) {
|
|
36
36
|
return this.engine.queryVoid(query, this.context);
|