ldkit 2.1.0 → 2.1.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.
|
@@ -41,7 +41,7 @@ export class QueryEngine {
|
|
|
41
41
|
getFetch(context) {
|
|
42
42
|
return context && context.fetch ? context.fetch : fetch;
|
|
43
43
|
}
|
|
44
|
-
query(
|
|
44
|
+
query(body, responseType, context) {
|
|
45
45
|
const endpoint = this.getSparqlEndpoint(context);
|
|
46
46
|
const fetchFn = this.getFetch(context);
|
|
47
47
|
return fetchFn(endpoint, {
|
|
@@ -50,14 +50,12 @@ export class QueryEngine {
|
|
|
50
50
|
"accept": responseType,
|
|
51
51
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
52
52
|
},
|
|
53
|
-
body: new URLSearchParams(
|
|
54
|
-
query,
|
|
55
|
-
}),
|
|
53
|
+
body: new URLSearchParams(body),
|
|
56
54
|
});
|
|
57
55
|
}
|
|
58
56
|
async queryAndResolve(type, query, context) {
|
|
59
57
|
const responseType = getResponseTypes(type).join(", ");
|
|
60
|
-
const response = await this.query(query, responseType, context);
|
|
58
|
+
const response = await this.query({ query }, responseType, context);
|
|
61
59
|
if (!response.ok) {
|
|
62
60
|
await response.body?.cancel();
|
|
63
61
|
throw new Error(`Invalid query response status '${response.status} ${response.statusText}'`);
|
|
@@ -102,6 +100,6 @@ export class QueryEngine {
|
|
|
102
100
|
* @returns Nothing
|
|
103
101
|
*/
|
|
104
102
|
async queryVoid(query, context) {
|
|
105
|
-
await this.query(query, "application/sparql-results+json", context);
|
|
103
|
+
await this.query({ update: query }, "application/sparql-results+json", context);
|
|
106
104
|
}
|
|
107
105
|
}
|
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": "2.1.
|
|
6
|
+
"version": "2.1.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)",
|
|
@@ -44,7 +44,7 @@ class QueryEngine {
|
|
|
44
44
|
getFetch(context) {
|
|
45
45
|
return context && context.fetch ? context.fetch : fetch;
|
|
46
46
|
}
|
|
47
|
-
query(
|
|
47
|
+
query(body, responseType, context) {
|
|
48
48
|
const endpoint = this.getSparqlEndpoint(context);
|
|
49
49
|
const fetchFn = this.getFetch(context);
|
|
50
50
|
return fetchFn(endpoint, {
|
|
@@ -53,14 +53,12 @@ class QueryEngine {
|
|
|
53
53
|
"accept": responseType,
|
|
54
54
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
55
55
|
},
|
|
56
|
-
body: new URLSearchParams(
|
|
57
|
-
query,
|
|
58
|
-
}),
|
|
56
|
+
body: new URLSearchParams(body),
|
|
59
57
|
});
|
|
60
58
|
}
|
|
61
59
|
async queryAndResolve(type, query, context) {
|
|
62
60
|
const responseType = (0, query_resolvers_js_1.getResponseTypes)(type).join(", ");
|
|
63
|
-
const response = await this.query(query, responseType, context);
|
|
61
|
+
const response = await this.query({ query }, responseType, context);
|
|
64
62
|
if (!response.ok) {
|
|
65
63
|
await response.body?.cancel();
|
|
66
64
|
throw new Error(`Invalid query response status '${response.status} ${response.statusText}'`);
|
|
@@ -105,7 +103,7 @@ class QueryEngine {
|
|
|
105
103
|
* @returns Nothing
|
|
106
104
|
*/
|
|
107
105
|
async queryVoid(query, context) {
|
|
108
|
-
await this.query(query, "application/sparql-results+json", context);
|
|
106
|
+
await this.query({ update: query }, "application/sparql-results+json", context);
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
exports.QueryEngine = QueryEngine;
|
|
@@ -16,7 +16,11 @@ import { type ResolverType } from "./query_resolvers.js";
|
|
|
16
16
|
export declare class QueryEngine implements IQueryEngine {
|
|
17
17
|
protected getSparqlEndpoint(context?: QueryContext): string;
|
|
18
18
|
protected getFetch(context?: QueryContext): typeof fetch;
|
|
19
|
-
protected query(
|
|
19
|
+
protected query(body: {
|
|
20
|
+
query: string;
|
|
21
|
+
} | {
|
|
22
|
+
update: string;
|
|
23
|
+
}, responseType: string, context?: QueryContext): Promise<Response>;
|
|
20
24
|
protected queryAndResolve<T extends ResolverType>(type: T, query: string, context?: QueryContext): Promise<{
|
|
21
25
|
boolean: boolean;
|
|
22
26
|
bindings: RDF.ResultStream<RDF.Bindings>;
|