ldkit 0.6.0 → 0.6.1
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/esm/library/asynciterator.js +94 -0
- package/esm/library/engine/query_engine.js +14 -15
- package/esm/library/rdf.js +6 -6
- package/package.json +5 -2
- package/script/library/asynciterator.js +99 -4
- package/script/library/engine/query_engine.js +13 -14
- package/script/library/rdf.js +6 -6
- package/types/library/asynciterator.d.ts +28 -0
- package/types/library/engine/query_engine.d.ts +7 -2
- package/types/library/rdf.d.ts +14 -4
|
@@ -1 +1,95 @@
|
|
|
1
|
+
import { AsyncIterator } from "asynciterator";
|
|
1
2
|
export { ArrayIterator, MappingIterator, } from "asynciterator";
|
|
3
|
+
export class TreeIterator extends AsyncIterator {
|
|
4
|
+
constructor(tree) {
|
|
5
|
+
super();
|
|
6
|
+
Object.defineProperty(this, "_tree", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "_pointer", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
this._tree = tree;
|
|
19
|
+
this._pointer = this._buildPointerFromSource(tree);
|
|
20
|
+
this.readable = true;
|
|
21
|
+
}
|
|
22
|
+
read() {
|
|
23
|
+
if (this.closed) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
this._findNextCommonSegment();
|
|
27
|
+
this._findNextLeaf();
|
|
28
|
+
const p = this._pointer;
|
|
29
|
+
if (p.type === "leaf") {
|
|
30
|
+
p.index++;
|
|
31
|
+
if (p.index < p.items.length) {
|
|
32
|
+
return [...p.path, p.items[p.index]];
|
|
33
|
+
}
|
|
34
|
+
if (!p.parent) {
|
|
35
|
+
this.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (p.type === "node") {
|
|
39
|
+
this.close();
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
_buildPointerFromSource(tree, path = []) {
|
|
44
|
+
if (tree.constructor === Object && !Array.isArray(tree)) {
|
|
45
|
+
return {
|
|
46
|
+
tree,
|
|
47
|
+
parent: this._pointer,
|
|
48
|
+
type: "node",
|
|
49
|
+
items: Object.keys(tree),
|
|
50
|
+
path,
|
|
51
|
+
index: -1,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(tree)) {
|
|
55
|
+
return {
|
|
56
|
+
parent: this._pointer,
|
|
57
|
+
type: "leaf",
|
|
58
|
+
items: tree,
|
|
59
|
+
path,
|
|
60
|
+
index: -1,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error("Invalid tree specified, expecting arrays in plain objects.");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_findNextCommonSegment() {
|
|
68
|
+
while (this._pointer.parent !== null) {
|
|
69
|
+
const p = this._pointer;
|
|
70
|
+
if (p.type === "leaf" && p.index < p.items.length - 1) {
|
|
71
|
+
// Points to a leaf that is not yet exhausted
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (p.index >= p.items.length - 1 && this._pointer.parent) {
|
|
75
|
+
this._pointer = this._pointer.parent;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
_findNextLeaf() {
|
|
83
|
+
while (this._pointer.type !== "leaf") {
|
|
84
|
+
const p = this._pointer;
|
|
85
|
+
p.index++;
|
|
86
|
+
if (p.index >= p.items.length) {
|
|
87
|
+
// no other keys present, the tree is exhausted;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
const key = p.items[p.index];
|
|
91
|
+
const source = this._pointer.tree[key];
|
|
92
|
+
this._pointer = this._buildPointerFromSource(source, [...p.path, key]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BindingsFactory, QuadFactory, } from "../rdf.js";
|
|
2
|
-
import { ArrayIterator, MappingIterator } from "../asynciterator.js";
|
|
2
|
+
import { ArrayIterator, MappingIterator, TreeIterator, } from "../asynciterator.js";
|
|
3
3
|
export class QueryEngine {
|
|
4
4
|
getSparqlEndpoint(context) {
|
|
5
5
|
if (!context) {
|
|
@@ -30,24 +30,25 @@ export class QueryEngine {
|
|
|
30
30
|
getFetch(context) {
|
|
31
31
|
return context && context.fetch ? context.fetch : fetch;
|
|
32
32
|
}
|
|
33
|
-
async query(query, context) {
|
|
33
|
+
async query(query, responseType, context) {
|
|
34
34
|
const endpoint = this.getSparqlEndpoint(context);
|
|
35
35
|
const fetchFn = this.getFetch(context);
|
|
36
|
-
|
|
36
|
+
const response = await fetchFn(endpoint, {
|
|
37
37
|
method: "POST",
|
|
38
38
|
headers: {
|
|
39
|
-
"accept":
|
|
39
|
+
"accept": responseType,
|
|
40
40
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
41
41
|
},
|
|
42
42
|
body: new URLSearchParams({
|
|
43
43
|
query,
|
|
44
44
|
}),
|
|
45
45
|
});
|
|
46
|
+
const json = await response.json();
|
|
47
|
+
return json;
|
|
46
48
|
}
|
|
47
49
|
async queryBindings(query, context) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
if (!Array.isArray(json?.results?.bindings)) {
|
|
50
|
+
const json = await this.query(query, "application/sparql-results+json", context);
|
|
51
|
+
if (!Array.isArray(json.results?.bindings)) {
|
|
51
52
|
throw new Error("Bindings SPARQL query result not found");
|
|
52
53
|
}
|
|
53
54
|
const bindingsFactory = new BindingsFactory();
|
|
@@ -56,25 +57,23 @@ export class QueryEngine {
|
|
|
56
57
|
return new MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
|
|
57
58
|
}
|
|
58
59
|
async queryBoolean(query, context) {
|
|
59
|
-
const
|
|
60
|
-
const json = await result.json();
|
|
60
|
+
const json = await this.query(query, "application/sparql-results+json", context);
|
|
61
61
|
if ("boolean" in json) {
|
|
62
62
|
return Boolean(json.boolean);
|
|
63
63
|
}
|
|
64
64
|
throw new Error("Boolean SPARQL query result not found");
|
|
65
65
|
}
|
|
66
66
|
async queryQuads(query, context) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
if (!Array.isArray(json?.results?.bindings)) {
|
|
67
|
+
const json = await this.query(query, "application/rdf+json", context);
|
|
68
|
+
if (!(json?.constructor === Object)) {
|
|
70
69
|
throw new Error("Quads SPARQL query result not found");
|
|
71
70
|
}
|
|
72
71
|
const quadFactory = new QuadFactory();
|
|
73
|
-
const
|
|
72
|
+
const treeIterator = new TreeIterator(json);
|
|
74
73
|
// TODO: review the unknown type cast
|
|
75
|
-
return new MappingIterator(
|
|
74
|
+
return new MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
|
|
76
75
|
}
|
|
77
76
|
async queryVoid(query, context) {
|
|
78
|
-
await this.query(query, context);
|
|
77
|
+
await this.query(query, "application/sparql-results+json", context);
|
|
79
78
|
}
|
|
80
79
|
}
|
package/esm/library/rdf.js
CHANGED
|
@@ -68,24 +68,24 @@ export class BindingsFactory extends ComunicaBindingsFactory {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
export class QuadFactory {
|
|
71
|
-
constructor(dataFactory = new DataFactory(),
|
|
71
|
+
constructor(dataFactory = new DataFactory(), termFactory = new TermFactory()) {
|
|
72
72
|
Object.defineProperty(this, "dataFactory", {
|
|
73
73
|
enumerable: true,
|
|
74
74
|
configurable: true,
|
|
75
75
|
writable: true,
|
|
76
76
|
value: void 0
|
|
77
77
|
});
|
|
78
|
-
Object.defineProperty(this, "
|
|
78
|
+
Object.defineProperty(this, "termFactory", {
|
|
79
79
|
enumerable: true,
|
|
80
80
|
configurable: true,
|
|
81
81
|
writable: true,
|
|
82
82
|
value: void 0
|
|
83
83
|
});
|
|
84
84
|
this.dataFactory = dataFactory;
|
|
85
|
-
this.
|
|
85
|
+
this.termFactory = termFactory;
|
|
86
86
|
}
|
|
87
|
-
fromJson(
|
|
88
|
-
const
|
|
89
|
-
return this.dataFactory.quad(
|
|
87
|
+
fromJson(jsonRdf) {
|
|
88
|
+
const [s, p, o] = jsonRdf;
|
|
89
|
+
return this.dataFactory.quad(this.dataFactory.namedNode(s), this.dataFactory.namedNode(p), this.termFactory.fromJson(o));
|
|
90
90
|
}
|
|
91
91
|
}
|
package/package.json
CHANGED
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
"main": "./script/mod.js",
|
|
4
4
|
"types": "./types/mod.d.ts",
|
|
5
5
|
"name": "ldkit",
|
|
6
|
-
"version": "0.6.
|
|
6
|
+
"version": "0.6.1",
|
|
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)",
|
|
10
10
|
"keywords": [
|
|
11
|
-
"linked data,
|
|
11
|
+
"linked data",
|
|
12
|
+
"rdf",
|
|
13
|
+
"sparql",
|
|
14
|
+
"deno"
|
|
12
15
|
],
|
|
13
16
|
"license": "MIT",
|
|
14
17
|
"repository": {
|
|
@@ -1,6 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MappingIterator = exports.ArrayIterator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.TreeIterator = exports.MappingIterator = exports.ArrayIterator = void 0;
|
|
4
|
+
const asynciterator_1 = require("asynciterator");
|
|
5
|
+
var asynciterator_2 = require("asynciterator");
|
|
6
|
+
Object.defineProperty(exports, "ArrayIterator", { enumerable: true, get: function () { return asynciterator_2.ArrayIterator; } });
|
|
7
|
+
Object.defineProperty(exports, "MappingIterator", { enumerable: true, get: function () { return asynciterator_2.MappingIterator; } });
|
|
8
|
+
class TreeIterator extends asynciterator_1.AsyncIterator {
|
|
9
|
+
constructor(tree) {
|
|
10
|
+
super();
|
|
11
|
+
Object.defineProperty(this, "_tree", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "_pointer", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
this._tree = tree;
|
|
24
|
+
this._pointer = this._buildPointerFromSource(tree);
|
|
25
|
+
this.readable = true;
|
|
26
|
+
}
|
|
27
|
+
read() {
|
|
28
|
+
if (this.closed) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
this._findNextCommonSegment();
|
|
32
|
+
this._findNextLeaf();
|
|
33
|
+
const p = this._pointer;
|
|
34
|
+
if (p.type === "leaf") {
|
|
35
|
+
p.index++;
|
|
36
|
+
if (p.index < p.items.length) {
|
|
37
|
+
return [...p.path, p.items[p.index]];
|
|
38
|
+
}
|
|
39
|
+
if (!p.parent) {
|
|
40
|
+
this.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (p.type === "node") {
|
|
44
|
+
this.close();
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
_buildPointerFromSource(tree, path = []) {
|
|
49
|
+
if (tree.constructor === Object && !Array.isArray(tree)) {
|
|
50
|
+
return {
|
|
51
|
+
tree,
|
|
52
|
+
parent: this._pointer,
|
|
53
|
+
type: "node",
|
|
54
|
+
items: Object.keys(tree),
|
|
55
|
+
path,
|
|
56
|
+
index: -1,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(tree)) {
|
|
60
|
+
return {
|
|
61
|
+
parent: this._pointer,
|
|
62
|
+
type: "leaf",
|
|
63
|
+
items: tree,
|
|
64
|
+
path,
|
|
65
|
+
index: -1,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error("Invalid tree specified, expecting arrays in plain objects.");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
_findNextCommonSegment() {
|
|
73
|
+
while (this._pointer.parent !== null) {
|
|
74
|
+
const p = this._pointer;
|
|
75
|
+
if (p.type === "leaf" && p.index < p.items.length - 1) {
|
|
76
|
+
// Points to a leaf that is not yet exhausted
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (p.index >= p.items.length - 1 && this._pointer.parent) {
|
|
80
|
+
this._pointer = this._pointer.parent;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
_findNextLeaf() {
|
|
88
|
+
while (this._pointer.type !== "leaf") {
|
|
89
|
+
const p = this._pointer;
|
|
90
|
+
p.index++;
|
|
91
|
+
if (p.index >= p.items.length) {
|
|
92
|
+
// no other keys present, the tree is exhausted;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
const key = p.items[p.index];
|
|
96
|
+
const source = this._pointer.tree[key];
|
|
97
|
+
this._pointer = this._buildPointerFromSource(source, [...p.path, key]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TreeIterator = TreeIterator;
|
|
@@ -33,24 +33,25 @@ class QueryEngine {
|
|
|
33
33
|
getFetch(context) {
|
|
34
34
|
return context && context.fetch ? context.fetch : fetch;
|
|
35
35
|
}
|
|
36
|
-
async query(query, context) {
|
|
36
|
+
async query(query, responseType, context) {
|
|
37
37
|
const endpoint = this.getSparqlEndpoint(context);
|
|
38
38
|
const fetchFn = this.getFetch(context);
|
|
39
|
-
|
|
39
|
+
const response = await fetchFn(endpoint, {
|
|
40
40
|
method: "POST",
|
|
41
41
|
headers: {
|
|
42
|
-
"accept":
|
|
42
|
+
"accept": responseType,
|
|
43
43
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
44
44
|
},
|
|
45
45
|
body: new URLSearchParams({
|
|
46
46
|
query,
|
|
47
47
|
}),
|
|
48
48
|
});
|
|
49
|
+
const json = await response.json();
|
|
50
|
+
return json;
|
|
49
51
|
}
|
|
50
52
|
async queryBindings(query, context) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (!Array.isArray(json?.results?.bindings)) {
|
|
53
|
+
const json = await this.query(query, "application/sparql-results+json", context);
|
|
54
|
+
if (!Array.isArray(json.results?.bindings)) {
|
|
54
55
|
throw new Error("Bindings SPARQL query result not found");
|
|
55
56
|
}
|
|
56
57
|
const bindingsFactory = new rdf_js_1.BindingsFactory();
|
|
@@ -59,26 +60,24 @@ class QueryEngine {
|
|
|
59
60
|
return new asynciterator_js_1.MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
|
|
60
61
|
}
|
|
61
62
|
async queryBoolean(query, context) {
|
|
62
|
-
const
|
|
63
|
-
const json = await result.json();
|
|
63
|
+
const json = await this.query(query, "application/sparql-results+json", context);
|
|
64
64
|
if ("boolean" in json) {
|
|
65
65
|
return Boolean(json.boolean);
|
|
66
66
|
}
|
|
67
67
|
throw new Error("Boolean SPARQL query result not found");
|
|
68
68
|
}
|
|
69
69
|
async queryQuads(query, context) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
if (!Array.isArray(json?.results?.bindings)) {
|
|
70
|
+
const json = await this.query(query, "application/rdf+json", context);
|
|
71
|
+
if (!(json?.constructor === Object)) {
|
|
73
72
|
throw new Error("Quads SPARQL query result not found");
|
|
74
73
|
}
|
|
75
74
|
const quadFactory = new rdf_js_1.QuadFactory();
|
|
76
|
-
const
|
|
75
|
+
const treeIterator = new asynciterator_js_1.TreeIterator(json);
|
|
77
76
|
// TODO: review the unknown type cast
|
|
78
|
-
return new asynciterator_js_1.MappingIterator(
|
|
77
|
+
return new asynciterator_js_1.MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
|
|
79
78
|
}
|
|
80
79
|
async queryVoid(query, context) {
|
|
81
|
-
await this.query(query, context);
|
|
80
|
+
await this.query(query, "application/sparql-results+json", context);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
exports.QueryEngine = QueryEngine;
|
package/script/library/rdf.js
CHANGED
|
@@ -76,25 +76,25 @@ class BindingsFactory extends bindings_factory_1.BindingsFactory {
|
|
|
76
76
|
}
|
|
77
77
|
exports.BindingsFactory = BindingsFactory;
|
|
78
78
|
class QuadFactory {
|
|
79
|
-
constructor(dataFactory = new rdf_data_factory_1.DataFactory(),
|
|
79
|
+
constructor(dataFactory = new rdf_data_factory_1.DataFactory(), termFactory = new TermFactory()) {
|
|
80
80
|
Object.defineProperty(this, "dataFactory", {
|
|
81
81
|
enumerable: true,
|
|
82
82
|
configurable: true,
|
|
83
83
|
writable: true,
|
|
84
84
|
value: void 0
|
|
85
85
|
});
|
|
86
|
-
Object.defineProperty(this, "
|
|
86
|
+
Object.defineProperty(this, "termFactory", {
|
|
87
87
|
enumerable: true,
|
|
88
88
|
configurable: true,
|
|
89
89
|
writable: true,
|
|
90
90
|
value: void 0
|
|
91
91
|
});
|
|
92
92
|
this.dataFactory = dataFactory;
|
|
93
|
-
this.
|
|
93
|
+
this.termFactory = termFactory;
|
|
94
94
|
}
|
|
95
|
-
fromJson(
|
|
96
|
-
const
|
|
97
|
-
return this.dataFactory.quad(
|
|
95
|
+
fromJson(jsonRdf) {
|
|
96
|
+
const [s, p, o] = jsonRdf;
|
|
97
|
+
return this.dataFactory.quad(this.dataFactory.namedNode(s), this.dataFactory.namedNode(p), this.termFactory.fromJson(o));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
exports.QuadFactory = QuadFactory;
|
|
@@ -1 +1,29 @@
|
|
|
1
|
+
import { AsyncIterator } from "asynciterator";
|
|
1
2
|
export { ArrayIterator, type AsyncIterator, MappingIterator, } from "asynciterator";
|
|
3
|
+
declare type TreeNode<T> = {
|
|
4
|
+
[property: string]: T[] | TreeNode<T>;
|
|
5
|
+
};
|
|
6
|
+
export declare type Tree<T> = T[] | TreeNode<T>;
|
|
7
|
+
declare type Subtree<T> = {
|
|
8
|
+
type: "node";
|
|
9
|
+
tree: TreeNode<T>;
|
|
10
|
+
parent?: Subtree<T>;
|
|
11
|
+
items: string[];
|
|
12
|
+
path: string[];
|
|
13
|
+
index: number;
|
|
14
|
+
} | {
|
|
15
|
+
type: "leaf";
|
|
16
|
+
parent?: Subtree<T>;
|
|
17
|
+
items: T[];
|
|
18
|
+
path: string[];
|
|
19
|
+
index: number;
|
|
20
|
+
};
|
|
21
|
+
export declare class TreeIterator<T> extends AsyncIterator<[...string[], T]> {
|
|
22
|
+
private _tree;
|
|
23
|
+
private _pointer;
|
|
24
|
+
constructor(tree: Tree<T>);
|
|
25
|
+
read(): [...string[], T] | null;
|
|
26
|
+
protected _buildPointerFromSource(tree: Tree<T>, path?: string[]): Subtree<T>;
|
|
27
|
+
protected _findNextCommonSegment(): void;
|
|
28
|
+
protected _findNextLeaf(): void;
|
|
29
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { type Context, type IQueryEngine, type RDF } from "../rdf.js";
|
|
1
|
+
import { type Context, type IQueryEngine, type RDF, RDFJSON } from "../rdf.js";
|
|
2
|
+
declare type QueryResponseFormat = {
|
|
3
|
+
"application/sparql-results+json": RDFJSON.SparqlResultsJsonFormat;
|
|
4
|
+
"application/rdf+json": RDFJSON.RdfJsonFormat;
|
|
5
|
+
};
|
|
2
6
|
export declare class QueryEngine implements IQueryEngine {
|
|
3
7
|
protected getSparqlEndpoint(context?: Context): string;
|
|
4
8
|
protected getFetch(context?: Context): typeof fetch;
|
|
5
|
-
query(query: string, context?: Context): Promise<
|
|
9
|
+
query<ResponseType extends keyof QueryResponseFormat, ResponseFormat = QueryResponseFormat[ResponseType]>(query: string, responseType: ResponseType, context?: Context): Promise<ResponseFormat>;
|
|
6
10
|
queryBindings(query: string, context?: Context): Promise<RDF.ResultStream<RDF.Bindings>>;
|
|
7
11
|
queryBoolean(query: string, context?: Context): Promise<boolean>;
|
|
8
12
|
queryQuads(query: string, context?: Context): Promise<RDF.ResultStream<RDF.Quad>>;
|
|
9
13
|
queryVoid(query: string, context?: Context): Promise<void>;
|
|
10
14
|
}
|
|
15
|
+
export {};
|
package/types/library/rdf.d.ts
CHANGED
|
@@ -25,6 +25,16 @@ export declare namespace RDFJSON {
|
|
|
25
25
|
datatype?: string;
|
|
26
26
|
};
|
|
27
27
|
type Bindings = Record<string, Term>;
|
|
28
|
+
type SparqlResultsJsonFormat = {
|
|
29
|
+
head: {
|
|
30
|
+
vars?: string[];
|
|
31
|
+
};
|
|
32
|
+
results?: {
|
|
33
|
+
bindings: Bindings[];
|
|
34
|
+
};
|
|
35
|
+
boolean?: boolean;
|
|
36
|
+
};
|
|
37
|
+
type RdfJsonFormat = Record<Iri, Record<Iri, Term[]>>;
|
|
28
38
|
interface TermFactory {
|
|
29
39
|
fromJson(jsonTerm: Term): RDF.Term;
|
|
30
40
|
}
|
|
@@ -32,7 +42,7 @@ export declare namespace RDFJSON {
|
|
|
32
42
|
fromJson(jsonBindings: Bindings): RDF.Bindings;
|
|
33
43
|
}
|
|
34
44
|
interface QuadFactory {
|
|
35
|
-
fromJson(
|
|
45
|
+
fromJson(jsonRdf: [Iri, Iri, Term]): RDF.Quad;
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
export declare class TermFactory implements RDFJSON.TermFactory {
|
|
@@ -48,7 +58,7 @@ export declare class BindingsFactory extends ComunicaBindingsFactory implements
|
|
|
48
58
|
}
|
|
49
59
|
export declare class QuadFactory implements RDFJSON.QuadFactory {
|
|
50
60
|
protected readonly dataFactory: RDF.DataFactory;
|
|
51
|
-
protected readonly
|
|
52
|
-
constructor(dataFactory?: RDF.DataFactory,
|
|
53
|
-
fromJson(
|
|
61
|
+
protected readonly termFactory: RDFJSON.TermFactory;
|
|
62
|
+
constructor(dataFactory?: RDF.DataFactory, termFactory?: RDFJSON.TermFactory);
|
|
63
|
+
fromJson(jsonRdf: [Iri, Iri, RDFJSON.Term]): Quad;
|
|
54
64
|
}
|