ldkit 0.7.0 → 1.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.
@@ -1,5 +1,4 @@
1
- import { BindingsFactory, QuadFactory, } from "../rdf.js";
2
- import { ArrayIterator, MappingIterator, TreeIterator, } from "../asynciterator.js";
1
+ import { getResponseTypes, resolve, } from "./query_resolvers.js";
3
2
  export class QueryEngine {
4
3
  getSparqlEndpoint(context) {
5
4
  if (!context) {
@@ -30,10 +29,10 @@ export class QueryEngine {
30
29
  getFetch(context) {
31
30
  return context && context.fetch ? context.fetch : fetch;
32
31
  }
33
- async query(query, responseType, context) {
32
+ query(query, responseType, context) {
34
33
  const endpoint = this.getSparqlEndpoint(context);
35
34
  const fetchFn = this.getFetch(context);
36
- const response = await fetchFn(endpoint, {
35
+ return fetchFn(endpoint, {
37
36
  method: "POST",
38
37
  headers: {
39
38
  "accept": responseType,
@@ -43,35 +42,24 @@ export class QueryEngine {
43
42
  query,
44
43
  }),
45
44
  });
46
- const json = await response.json();
47
- return json;
48
45
  }
49
- async queryBindings(query, context) {
50
- const json = await this.query(query, "application/sparql-results+json", context);
51
- if (!Array.isArray(json.results?.bindings)) {
52
- throw new Error("Bindings SPARQL query result not found");
46
+ async queryAndResolve(type, query, context) {
47
+ const responseType = getResponseTypes(type).join(", ");
48
+ const response = await this.query(query, responseType, context);
49
+ if (!response.ok) {
50
+ await response.body?.cancel();
51
+ throw new Error(`Invalid query response status '${response.status} ${response.statusText}'`);
53
52
  }
54
- const bindingsFactory = new BindingsFactory();
55
- const bindingsIterator = new ArrayIterator(json.results.bindings);
56
- // TODO: review the unknown type cast
57
- return new MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
53
+ return resolve(type, response);
58
54
  }
59
- async queryBoolean(query, context) {
60
- const json = await this.query(query, "application/sparql-results+json", context);
61
- if ("boolean" in json) {
62
- return Boolean(json.boolean);
63
- }
64
- throw new Error("Boolean SPARQL query result not found");
55
+ queryBindings(query, context) {
56
+ return this.queryAndResolve("bindings", query, context);
65
57
  }
66
- async queryQuads(query, context) {
67
- const json = await this.query(query, "application/rdf+json", context);
68
- if (!(json?.constructor === Object)) {
69
- throw new Error("Quads SPARQL query result not found");
70
- }
71
- const quadFactory = new QuadFactory();
72
- const treeIterator = new TreeIterator(json);
73
- // TODO: review the unknown type cast
74
- return new MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
58
+ queryBoolean(query, context) {
59
+ return this.queryAndResolve("boolean", query, context);
60
+ }
61
+ queryQuads(query, context) {
62
+ return this.queryAndResolve("quads", query, context);
75
63
  }
76
64
  async queryVoid(query, context) {
77
65
  await this.query(query, "application/sparql-results+json", context);
@@ -0,0 +1,72 @@
1
+ import { BindingsFactory, N3, QuadFactory } from "../rdf.js";
2
+ import { ArrayIterator, MappingIterator, TreeIterator, } from "../asynciterator.js";
3
+ class QueryResolver {
4
+ }
5
+ class BooleanJsonResolver extends QueryResolver {
6
+ async resolve(response) {
7
+ const json = await response.json();
8
+ if ("boolean" in json) {
9
+ return Boolean(json.boolean);
10
+ }
11
+ throw new Error("Boolean SPARQL query result not found");
12
+ }
13
+ }
14
+ class BindingsJsonResolver extends QueryResolver {
15
+ async resolve(response) {
16
+ const json = await response.json();
17
+ if (!Array.isArray(json.results?.bindings)) {
18
+ throw new Error("Bindings SPARQL query result not found");
19
+ }
20
+ const bindingsFactory = new BindingsFactory();
21
+ const bindingsIterator = new ArrayIterator(json.results.bindings);
22
+ // TODO: review the unknown type cast
23
+ return new MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
24
+ }
25
+ }
26
+ class QuadsJsonResolver extends QueryResolver {
27
+ async resolve(response) {
28
+ const json = await response.json();
29
+ if (!(json?.constructor === Object)) {
30
+ throw new Error("Quads SPARQL query result not found");
31
+ }
32
+ const quadFactory = new QuadFactory();
33
+ const treeIterator = new TreeIterator(json);
34
+ // TODO: review the unknown type cast
35
+ return new MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
36
+ }
37
+ }
38
+ class QuadsTurtleResolver extends QueryResolver {
39
+ async resolve(response) {
40
+ const text = await response.text();
41
+ const quads = new N3.Parser({ format: "turtle" }).parse(text);
42
+ return new ArrayIterator(quads);
43
+ }
44
+ }
45
+ const resolvers = {
46
+ "boolean": {
47
+ "application/sparql-results+json": new BooleanJsonResolver(),
48
+ },
49
+ "bindings": {
50
+ "application/sparql-results+json": new BindingsJsonResolver(),
51
+ },
52
+ "quads": {
53
+ "application/rdf+json": new QuadsJsonResolver(),
54
+ "text/turtle": new QuadsTurtleResolver(),
55
+ },
56
+ };
57
+ export const getResponseTypes = (resolverType) => Object.keys(resolvers[resolverType]);
58
+ export const resolve = (resolverType, response) => {
59
+ const contentType = response.headers.get("Content-type");
60
+ if (!contentType) {
61
+ throw new Error(`Content-type header was not found in response`);
62
+ }
63
+ const separatorPosition = contentType.indexOf(";");
64
+ const mime = separatorPosition > 0
65
+ ? contentType.substring(0, separatorPosition)
66
+ : contentType;
67
+ const resolver = resolvers[resolverType][mime];
68
+ if (!resolver) {
69
+ throw new Error(`No resolver exists for response type '${mime}'`);
70
+ }
71
+ return resolver.resolve(response);
72
+ };
@@ -1,6 +1,7 @@
1
1
  export { fromRdf, toRdf } from "rdf-literal";
2
- import { DataFactory, DefaultGraph, } from "rdf-data-factory";
2
+ import { DataFactory, DefaultGraph } from "rdf-data-factory";
3
3
  export { DataFactory, DefaultGraph };
4
+ export * as N3 from "n3";
4
5
  export const quadsToGraph = (quads) => {
5
6
  const graph = new Map();
6
7
  for (const quad of quads) {
@@ -29,8 +30,8 @@ export class TermFactory {
29
30
  if (jsonTerm.type === "bnode") {
30
31
  return this.dataFactory.blankNode(jsonTerm.value);
31
32
  }
32
- if ("xml:lang" in jsonTerm) {
33
- return this.dataFactory.literal(jsonTerm.value, jsonTerm["xml:lang"]);
33
+ if ("lang" in jsonTerm) {
34
+ return this.dataFactory.literal(jsonTerm.value, jsonTerm["lang"]);
34
35
  }
35
36
  if ("datatype" in jsonTerm) {
36
37
  return this.dataFactory.literal(jsonTerm.value, this.dataFactory.namedNode(jsonTerm.datatype));
package/esm/mod.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { setDefaultContext, setDefaultEngine } from "./library/global.js";
2
2
  export { createLens, createResource } from "./library/lens/mod.js";
3
3
  export { createNamespace } from "./library/namespaces/namespace.js";
4
+ export { QueryEngine } from "./library/engine/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": "0.7.0",
6
+ "version": "1.1.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)",
@@ -23,31 +23,53 @@
23
23
  },
24
24
  "exports": {
25
25
  ".": {
26
- "import": "./esm/mod.js",
27
- "require": "./script/mod.js",
28
- "types": "./types/mod.d.ts"
26
+ "import": {
27
+ "types": "./types/mod.d.ts",
28
+ "default": "./esm/mod.js"
29
+ },
30
+ "require": {
31
+ "types": "./types/mod.d.ts",
32
+ "default": "./script/mod.js"
33
+ }
29
34
  },
30
35
  "./namespaces": {
31
- "import": "./esm/namespaces.js",
32
- "require": "./script/namespaces.js",
33
- "types": "./types/namespaces.d.ts"
36
+ "import": {
37
+ "types": "./types/namespaces.d.ts",
38
+ "default": "./esm/namespaces.js"
39
+ },
40
+ "require": {
41
+ "types": "./types/namespaces.d.ts",
42
+ "default": "./script/namespaces.js"
43
+ }
34
44
  },
35
45
  "./rdf": {
36
- "import": "./esm/rdf.js",
37
- "require": "./script/rdf.js",
38
- "types": "./types/rdf.d.ts"
46
+ "import": {
47
+ "types": "./types/rdf.d.ts",
48
+ "default": "./esm/rdf.js"
49
+ },
50
+ "require": {
51
+ "types": "./types/rdf.d.ts",
52
+ "default": "./script/rdf.js"
53
+ }
39
54
  },
40
55
  "./sparql": {
41
- "import": "./esm/sparql.js",
42
- "require": "./script/sparql.js",
43
- "types": "./types/sparql.d.ts"
56
+ "import": {
57
+ "types": "./types/sparql.d.ts",
58
+ "default": "./esm/sparql.js"
59
+ },
60
+ "require": {
61
+ "types": "./types/sparql.d.ts",
62
+ "default": "./script/sparql.js"
63
+ }
44
64
  }
45
65
  },
46
66
  "dependencies": {
47
- "@comunica/types": "2.4.0",
48
- "asynciterator": "3.7.0",
67
+ "@comunica/types": "2.6.8",
68
+ "@types/n3": "*",
69
+ "asynciterator": "3.8.0",
70
+ "n3": "1.17.2",
49
71
  "rdf-data-factory": "1.1.1",
50
72
  "rdf-js": "4.0.2",
51
- "rdf-literal": "1.3.0"
73
+ "rdf-literal": "1.3.1"
52
74
  }
53
75
  }
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryEngine = void 0;
4
- const rdf_js_1 = require("../rdf.js");
5
- const asynciterator_js_1 = require("../asynciterator.js");
4
+ const query_resolvers_js_1 = require("./query_resolvers.js");
6
5
  class QueryEngine {
7
6
  getSparqlEndpoint(context) {
8
7
  if (!context) {
@@ -33,10 +32,10 @@ class QueryEngine {
33
32
  getFetch(context) {
34
33
  return context && context.fetch ? context.fetch : fetch;
35
34
  }
36
- async query(query, responseType, context) {
35
+ query(query, responseType, context) {
37
36
  const endpoint = this.getSparqlEndpoint(context);
38
37
  const fetchFn = this.getFetch(context);
39
- const response = await fetchFn(endpoint, {
38
+ return fetchFn(endpoint, {
40
39
  method: "POST",
41
40
  headers: {
42
41
  "accept": responseType,
@@ -46,35 +45,24 @@ class QueryEngine {
46
45
  query,
47
46
  }),
48
47
  });
49
- const json = await response.json();
50
- return json;
51
48
  }
52
- async queryBindings(query, context) {
53
- const json = await this.query(query, "application/sparql-results+json", context);
54
- if (!Array.isArray(json.results?.bindings)) {
55
- throw new Error("Bindings SPARQL query result not found");
49
+ async queryAndResolve(type, query, context) {
50
+ const responseType = (0, query_resolvers_js_1.getResponseTypes)(type).join(", ");
51
+ const response = await this.query(query, responseType, context);
52
+ if (!response.ok) {
53
+ await response.body?.cancel();
54
+ throw new Error(`Invalid query response status '${response.status} ${response.statusText}'`);
56
55
  }
57
- const bindingsFactory = new rdf_js_1.BindingsFactory();
58
- const bindingsIterator = new asynciterator_js_1.ArrayIterator(json.results.bindings);
59
- // TODO: review the unknown type cast
60
- return new asynciterator_js_1.MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
56
+ return (0, query_resolvers_js_1.resolve)(type, response);
61
57
  }
62
- async queryBoolean(query, context) {
63
- const json = await this.query(query, "application/sparql-results+json", context);
64
- if ("boolean" in json) {
65
- return Boolean(json.boolean);
66
- }
67
- throw new Error("Boolean SPARQL query result not found");
58
+ queryBindings(query, context) {
59
+ return this.queryAndResolve("bindings", query, context);
68
60
  }
69
- async queryQuads(query, context) {
70
- const json = await this.query(query, "application/rdf+json", context);
71
- if (!(json?.constructor === Object)) {
72
- throw new Error("Quads SPARQL query result not found");
73
- }
74
- const quadFactory = new rdf_js_1.QuadFactory();
75
- const treeIterator = new asynciterator_js_1.TreeIterator(json);
76
- // TODO: review the unknown type cast
77
- return new asynciterator_js_1.MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
61
+ queryBoolean(query, context) {
62
+ return this.queryAndResolve("boolean", query, context);
63
+ }
64
+ queryQuads(query, context) {
65
+ return this.queryAndResolve("quads", query, context);
78
66
  }
79
67
  async queryVoid(query, context) {
80
68
  await this.query(query, "application/sparql-results+json", context);
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolve = exports.getResponseTypes = void 0;
4
+ const rdf_js_1 = require("../rdf.js");
5
+ const asynciterator_js_1 = require("../asynciterator.js");
6
+ class QueryResolver {
7
+ }
8
+ class BooleanJsonResolver extends QueryResolver {
9
+ async resolve(response) {
10
+ const json = await response.json();
11
+ if ("boolean" in json) {
12
+ return Boolean(json.boolean);
13
+ }
14
+ throw new Error("Boolean SPARQL query result not found");
15
+ }
16
+ }
17
+ class BindingsJsonResolver extends QueryResolver {
18
+ async resolve(response) {
19
+ const json = await response.json();
20
+ if (!Array.isArray(json.results?.bindings)) {
21
+ throw new Error("Bindings SPARQL query result not found");
22
+ }
23
+ const bindingsFactory = new rdf_js_1.BindingsFactory();
24
+ const bindingsIterator = new asynciterator_js_1.ArrayIterator(json.results.bindings);
25
+ // TODO: review the unknown type cast
26
+ return new asynciterator_js_1.MappingIterator(bindingsIterator, (i) => bindingsFactory.fromJson(i));
27
+ }
28
+ }
29
+ class QuadsJsonResolver extends QueryResolver {
30
+ async resolve(response) {
31
+ const json = await response.json();
32
+ if (!(json?.constructor === Object)) {
33
+ throw new Error("Quads SPARQL query result not found");
34
+ }
35
+ const quadFactory = new rdf_js_1.QuadFactory();
36
+ const treeIterator = new asynciterator_js_1.TreeIterator(json);
37
+ // TODO: review the unknown type cast
38
+ return new asynciterator_js_1.MappingIterator(treeIterator, (i) => quadFactory.fromJson(i));
39
+ }
40
+ }
41
+ class QuadsTurtleResolver extends QueryResolver {
42
+ async resolve(response) {
43
+ const text = await response.text();
44
+ const quads = new rdf_js_1.N3.Parser({ format: "turtle" }).parse(text);
45
+ return new asynciterator_js_1.ArrayIterator(quads);
46
+ }
47
+ }
48
+ const resolvers = {
49
+ "boolean": {
50
+ "application/sparql-results+json": new BooleanJsonResolver(),
51
+ },
52
+ "bindings": {
53
+ "application/sparql-results+json": new BindingsJsonResolver(),
54
+ },
55
+ "quads": {
56
+ "application/rdf+json": new QuadsJsonResolver(),
57
+ "text/turtle": new QuadsTurtleResolver(),
58
+ },
59
+ };
60
+ const getResponseTypes = (resolverType) => Object.keys(resolvers[resolverType]);
61
+ exports.getResponseTypes = getResponseTypes;
62
+ const resolve = (resolverType, response) => {
63
+ const contentType = response.headers.get("Content-type");
64
+ if (!contentType) {
65
+ throw new Error(`Content-type header was not found in response`);
66
+ }
67
+ const separatorPosition = contentType.indexOf(";");
68
+ const mime = separatorPosition > 0
69
+ ? contentType.substring(0, separatorPosition)
70
+ : contentType;
71
+ const resolver = resolvers[resolverType][mime];
72
+ if (!resolver) {
73
+ throw new Error(`No resolver exists for response type '${mime}'`);
74
+ }
75
+ return resolver.resolve(response);
76
+ };
77
+ exports.resolve = resolve;
@@ -1,12 +1,36 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuadFactory = exports.BindingsFactory = exports.ReadOnlyBindings = exports.TermFactory = exports.quadsToGraph = exports.DefaultGraph = exports.DataFactory = exports.toRdf = exports.fromRdf = void 0;
26
+ exports.QuadFactory = exports.BindingsFactory = exports.ReadOnlyBindings = exports.TermFactory = exports.quadsToGraph = exports.N3 = exports.DefaultGraph = exports.DataFactory = exports.toRdf = exports.fromRdf = void 0;
4
27
  var rdf_literal_1 = require("rdf-literal");
5
28
  Object.defineProperty(exports, "fromRdf", { enumerable: true, get: function () { return rdf_literal_1.fromRdf; } });
6
29
  Object.defineProperty(exports, "toRdf", { enumerable: true, get: function () { return rdf_literal_1.toRdf; } });
7
30
  const rdf_data_factory_1 = require("rdf-data-factory");
8
31
  Object.defineProperty(exports, "DataFactory", { enumerable: true, get: function () { return rdf_data_factory_1.DataFactory; } });
9
32
  Object.defineProperty(exports, "DefaultGraph", { enumerable: true, get: function () { return rdf_data_factory_1.DefaultGraph; } });
33
+ exports.N3 = __importStar(require("n3"));
10
34
  const quadsToGraph = (quads) => {
11
35
  const graph = new Map();
12
36
  for (const quad of quads) {
@@ -36,8 +60,8 @@ class TermFactory {
36
60
  if (jsonTerm.type === "bnode") {
37
61
  return this.dataFactory.blankNode(jsonTerm.value);
38
62
  }
39
- if ("xml:lang" in jsonTerm) {
40
- return this.dataFactory.literal(jsonTerm.value, jsonTerm["xml:lang"]);
63
+ if ("lang" in jsonTerm) {
64
+ return this.dataFactory.literal(jsonTerm.value, jsonTerm["lang"]);
41
65
  }
42
66
  if ("datatype" in jsonTerm) {
43
67
  return this.dataFactory.literal(jsonTerm.value, this.dataFactory.namedNode(jsonTerm.datatype));
package/script/mod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNamespace = exports.createResource = exports.createLens = exports.setDefaultEngine = exports.setDefaultContext = void 0;
3
+ exports.QueryEngine = exports.createNamespace = exports.createResource = exports.createLens = exports.setDefaultEngine = exports.setDefaultContext = void 0;
4
4
  var global_js_1 = require("./library/global.js");
5
5
  Object.defineProperty(exports, "setDefaultContext", { enumerable: true, get: function () { return global_js_1.setDefaultContext; } });
6
6
  Object.defineProperty(exports, "setDefaultEngine", { enumerable: true, get: function () { return global_js_1.setDefaultEngine; } });
@@ -9,3 +9,5 @@ Object.defineProperty(exports, "createLens", { enumerable: true, get: function (
9
9
  Object.defineProperty(exports, "createResource", { enumerable: true, get: function () { return mod_js_1.createResource; } });
10
10
  var namespace_js_1 = require("./library/namespaces/namespace.js");
11
11
  Object.defineProperty(exports, "createNamespace", { enumerable: true, get: function () { return namespace_js_1.createNamespace; } });
12
+ var mod_js_2 = require("./library/engine/mod.js");
13
+ Object.defineProperty(exports, "QueryEngine", { enumerable: true, get: function () { return mod_js_2.QueryEngine; } });
@@ -1,10 +1,10 @@
1
1
  import { AsyncIterator } from "asynciterator";
2
2
  export { ArrayIterator, type AsyncIterator, MappingIterator, } from "asynciterator";
3
- declare type TreeNode<T> = {
3
+ type TreeNode<T> = {
4
4
  [property: string]: T[] | TreeNode<T>;
5
5
  };
6
- export declare type Tree<T> = T[] | TreeNode<T>;
7
- declare type Subtree<T> = {
6
+ export type Tree<T> = T[] | TreeNode<T>;
7
+ type Subtree<T> = {
8
8
  type: "node";
9
9
  tree: TreeNode<T>;
10
10
  parent?: Subtree<T>;
@@ -1,5 +1,5 @@
1
1
  import { type Context, Graph } from "./rdf.js";
2
2
  import type { Schema } from "./schema/mod.js";
3
- declare type DecodedNode = Record<string, unknown>;
3
+ type DecodedNode = Record<string, unknown>;
4
4
  export declare const decode: (graph: Graph, schema: Schema, context: Context) => DecodedNode[];
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  import { type Context, type RDF } from "./rdf.js";
2
2
  import type { Schema } from "./schema/mod.js";
3
- declare type DecodedNode = Record<string, unknown>;
3
+ type DecodedNode = Record<string, unknown>;
4
4
  export declare const encode: (node: DecodedNode, schema: Schema, context: Context, variableInitCounter?: number) => RDF.Quad[];
5
5
  export {};
@@ -1,15 +1,16 @@
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
- };
1
+ import { type Context, type IQueryEngine, type RDF } from "../rdf.js";
2
+ import { type ResolverType } from "./query_resolvers.js";
6
3
  export declare class QueryEngine implements IQueryEngine {
7
4
  protected getSparqlEndpoint(context?: Context): string;
8
5
  protected getFetch(context?: Context): typeof fetch;
9
- query<ResponseType extends keyof QueryResponseFormat, ResponseFormat = QueryResponseFormat[ResponseType]>(query: string, responseType: ResponseType, context?: Context): Promise<ResponseFormat>;
6
+ query(query: string, responseType: string, context?: Context): Promise<Response>;
7
+ queryAndResolve<T extends ResolverType>(type: T, query: string, context?: Context): Promise<{
8
+ boolean: boolean;
9
+ bindings: RDF.ResultStream<RDF.Bindings>;
10
+ quads: RDF.ResultStream<RDF.Quad>;
11
+ }[T]>;
10
12
  queryBindings(query: string, context?: Context): Promise<RDF.ResultStream<RDF.Bindings>>;
11
13
  queryBoolean(query: string, context?: Context): Promise<boolean>;
12
14
  queryQuads(query: string, context?: Context): Promise<RDF.ResultStream<RDF.Quad>>;
13
15
  queryVoid(query: string, context?: Context): Promise<void>;
14
16
  }
15
- export {};
@@ -0,0 +1,10 @@
1
+ import { type RDF } from "../rdf.js";
2
+ type ResolveFormat = {
3
+ "boolean": boolean;
4
+ "bindings": RDF.ResultStream<RDF.Bindings>;
5
+ "quads": RDF.ResultStream<RDF.Quad>;
6
+ };
7
+ export type ResolverType = keyof ResolveFormat;
8
+ export declare const getResponseTypes: (resolverType: ResolverType) => string[];
9
+ export declare const resolve: <T extends keyof ResolveFormat>(resolverType: T, response: Response) => Promise<ResolveFormat[T]>;
10
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { SchemaInterfaceIdentity } from "../schema/mod.js";
2
- export declare type Entity<T extends unknown = Record<string, unknown>> = DeepPartial<T> & SchemaInterfaceIdentity;
3
- export declare type DeepPartial<T> = T extends Record<string, unknown> ? {
2
+ export type Entity<T extends unknown = Record<string, unknown>> = DeepPartial<T> & SchemaInterfaceIdentity;
3
+ export type DeepPartial<T> = T extends Record<string, unknown> ? {
4
4
  [P in keyof T]?: DeepPartial<T[P]>;
5
5
  } : T;
@@ -2,11 +2,12 @@ declare const _default: {
2
2
  number: "dbo:number";
3
3
  symbol: "dbo:symbol";
4
4
  tree: "dbo:tree";
5
- value: "dbo:value";
6
- type: "dbo:type";
7
5
  closed: "dbo:closed";
8
6
  map: "dbo:map";
9
7
  range: "dbo:range";
8
+ format: "dbo:format";
9
+ value: "dbo:value";
10
+ type: "dbo:type";
10
11
  prefix: "dbo:prefix";
11
12
  length: "dbo:length";
12
13
  Name: "dbo:Name";
@@ -1742,7 +1743,6 @@ declare const _default: {
1742
1743
  footedness: "dbo:footedness";
1743
1744
  forces: "dbo:forces";
1744
1745
  foresterDistrict: "dbo:foresterDistrict";
1745
- format: "dbo:format";
1746
1746
  formationDate: "dbo:formationDate";
1747
1747
  formationYear: "dbo:formationYear";
1748
1748
  formerBandMember: "dbo:formerBandMember";
@@ -1,11 +1,11 @@
1
1
  declare const _default: {
2
2
  subject: "dc:subject";
3
+ format: "dc:format";
3
4
  type: "dc:type";
4
5
  date: "dc:date";
5
6
  language: "dc:language";
6
7
  description: "dc:description";
7
8
  creator: "dc:creator";
8
- format: "dc:format";
9
9
  publisher: "dc:publisher";
10
10
  relation: "dc:relation";
11
11
  source: "dc:source";
@@ -1,5 +1,6 @@
1
1
  declare const _default: {
2
2
  subject: "dcterms:subject";
3
+ format: "dcterms:format";
3
4
  type: "dcterms:type";
4
5
  date: "dcterms:date";
5
6
  language: "dcterms:language";
@@ -9,7 +10,6 @@ declare const _default: {
9
10
  abstract: "dcterms:abstract";
10
11
  created: "dcterms:created";
11
12
  creator: "dcterms:creator";
12
- format: "dcterms:format";
13
13
  isPartOf: "dcterms:isPartOf";
14
14
  license: "dcterms:license";
15
15
  publisher: "dcterms:publisher";
@@ -1,11 +1,11 @@
1
- declare type NamespacePrototype = {
1
+ type NamespacePrototype = {
2
2
  iri: string;
3
3
  prefix: string;
4
4
  terms: readonly string[];
5
5
  };
6
- declare type NamespacePrefix<Namespace extends NamespacePrototype> = Namespace["prefix"];
7
- declare type NamespaceIri<Namespace extends NamespacePrototype> = Namespace["iri"];
8
- declare type NamespaceObject<Namespace extends NamespacePrototype> = {
6
+ type NamespacePrefix<Namespace extends NamespacePrototype> = Namespace["prefix"];
7
+ type NamespaceIri<Namespace extends NamespacePrototype> = Namespace["iri"];
8
+ type NamespaceObject<Namespace extends NamespacePrototype> = {
9
9
  [Term in Namespace["terms"][number]]: `${NamespacePrefix<Namespace>}${Term}`;
10
10
  };
11
11
  export declare const createNamespace: <N extends NamespacePrototype, I = NamespaceIri<N>, P = NamespacePrefix<N>, O = NamespaceObject<N>>(namespaceSpec: N) => O & {
@@ -1,8 +1,10 @@
1
1
  declare const _default: {
2
2
  object: "schema:object";
3
+ map: "schema:map";
4
+ application: "schema:application";
5
+ text: "schema:text";
3
6
  value: "schema:value";
4
7
  query: "schema:query";
5
- map: "schema:map";
6
8
  duration: "schema:duration";
7
9
  language: "schema:language";
8
10
  Property: "schema:Property";
@@ -1560,7 +1562,6 @@ declare const _default: {
1560
1562
  antagonist: "schema:antagonist";
1561
1563
  applicableLocation: "schema:applicableLocation";
1562
1564
  applicantLocationRequirements: "schema:applicantLocationRequirements";
1563
- application: "schema:application";
1564
1565
  applicationCategory: "schema:applicationCategory";
1565
1566
  applicationContact: "schema:applicationContact";
1566
1567
  applicationDeadline: "schema:applicationDeadline";
@@ -2577,7 +2578,6 @@ declare const _default: {
2577
2578
  termDuration: "schema:termDuration";
2578
2579
  termsOfService: "schema:termsOfService";
2579
2580
  termsPerYear: "schema:termsPerYear";
2580
- text: "schema:text";
2581
2581
  textValue: "schema:textValue";
2582
2582
  thumbnailUrl: "schema:thumbnailUrl";
2583
2583
  tickerSymbol: "schema:tickerSymbol";
@@ -1,4 +1,5 @@
1
1
  declare const _default: {
2
+ example: "skos:example";
2
3
  definition: "skos:definition";
3
4
  member: "skos:member";
4
5
  note: "skos:note";
@@ -15,7 +16,6 @@ declare const _default: {
15
16
  closeMatch: "skos:closeMatch";
16
17
  editorialNote: "skos:editorialNote";
17
18
  exactMatch: "skos:exactMatch";
18
- example: "skos:example";
19
19
  hasTopConcept: "skos:hasTopConcept";
20
20
  hiddenLabel: "skos:hiddenLabel";
21
21
  historyNote: "skos:historyNote";
@@ -3,22 +3,23 @@ export type { RDF };
3
3
  export { fromRdf, toRdf } from "rdf-literal";
4
4
  import { DataFactory, DefaultGraph } from "rdf-data-factory";
5
5
  export { DataFactory, DefaultGraph };
6
+ export * as N3 from "n3";
6
7
  import type { IDataSource, IQueryContextCommon } from "@comunica/types";
7
- export declare type LDkitContext = {
8
+ export type LDkitContext = {
8
9
  graph?: string;
9
10
  language?: string;
10
11
  };
11
- export declare type Context = LDkitContext & RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
12
- export declare type IQueryEngine = RDF.StringSparqlQueryable<RDF.SparqlResultSupport, Context>;
13
- export declare type Iri = string;
14
- export declare type Node = Map<Iri, RDF.Term[]>;
15
- export declare type Graph = Map<Iri, Node>;
12
+ export type Context = LDkitContext & RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
13
+ export type IQueryEngine = RDF.StringSparqlQueryable<RDF.SparqlResultSupport, Context>;
14
+ export type Iri = string;
15
+ export type Node = Map<Iri, RDF.Term[]>;
16
+ export type Graph = Map<Iri, Node>;
16
17
  export declare const quadsToGraph: (quads: RDF.Quad[]) => Graph;
17
18
  export declare namespace RDFJSON {
18
19
  type Term = {
19
20
  type: "uri" | "literal" | "bnode";
20
21
  value: string;
21
- "xml:lang"?: string;
22
+ lang?: string;
22
23
  datatype?: string;
23
24
  };
24
25
  type Bindings = Record<string, Term>;
@@ -34,6 +34,6 @@ declare const SupportedDataTypesPrototype: {
34
34
  "xsd:hexBinary": string;
35
35
  "rdf:langString": string;
36
36
  };
37
- export declare type SupportedDataTypes = typeof SupportedDataTypesPrototype;
38
- export declare type SupportedNativeTypes = SupportedDataTypes[keyof SupportedDataTypes];
37
+ export type SupportedDataTypes = typeof SupportedDataTypesPrototype;
38
+ export type SupportedNativeTypes = SupportedDataTypes[keyof SupportedDataTypes];
39
39
  export {};
@@ -1,32 +1,32 @@
1
1
  import type { SupportedDataTypes } from "./data_types.js";
2
2
  import type { PropertyPrototype, SchemaPrototype } from "./schema.js";
3
- declare type IsOptional<Property extends PropertyPrototype> = Property extends {
3
+ type IsOptional<Property extends PropertyPrototype> = Property extends {
4
4
  "@optional": true;
5
5
  } ? true : false;
6
- declare type IsArray<Property extends PropertyPrototype> = Property extends {
6
+ type IsArray<Property extends PropertyPrototype> = Property extends {
7
7
  "@array": true;
8
8
  } ? true : false;
9
- declare type IsMultilang<Property extends PropertyPrototype> = Property extends {
9
+ type IsMultilang<Property extends PropertyPrototype> = Property extends {
10
10
  "@multilang": true;
11
11
  } ? true : false;
12
- declare type ValidPropertyDefinition = PropertyPrototype | string;
13
- declare type ConvertPropertyType<T extends PropertyPrototype> = T extends {
12
+ type ValidPropertyDefinition = PropertyPrototype | string;
13
+ type ConvertPropertyType<T extends PropertyPrototype> = T extends {
14
14
  "@context": SchemaPrototype;
15
15
  } ? SchemaInterface<T["@context"]> : T extends {
16
16
  "@type": unknown;
17
17
  } ? T["@type"] extends keyof SupportedDataTypes ? SupportedDataTypes[T["@type"]] : never : string;
18
- declare type ConvertPropertyOptional<T extends PropertyPrototype> = IsOptional<T> extends true ? ConvertPropertyType<T> | undefined : ConvertPropertyType<T>;
19
- declare type ConvertPropertyArray<T extends PropertyPrototype> = IsArray<T> extends true ? ConvertPropertyType<T>[] : ConvertPropertyOptional<T>;
20
- declare type ConvertPropertyMultilang<T extends PropertyPrototype> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
21
- declare type ConvertPropertyObject<T extends PropertyPrototype> = ConvertPropertyMultilang<T>;
22
- declare type ConvertProperty<T extends ValidPropertyDefinition> = T extends PropertyPrototype ? ConvertPropertyObject<T> : string;
23
- export declare type SchemaInterfaceIdentity = {
18
+ type ConvertPropertyOptional<T extends PropertyPrototype> = IsOptional<T> extends true ? ConvertPropertyType<T> | undefined : ConvertPropertyType<T>;
19
+ type ConvertPropertyArray<T extends PropertyPrototype> = IsArray<T> extends true ? ConvertPropertyType<T>[] : ConvertPropertyOptional<T>;
20
+ type ConvertPropertyMultilang<T extends PropertyPrototype> = IsMultilang<T> extends true ? IsArray<T> extends true ? Record<string, ConvertPropertyType<T>[]> : Record<string, ConvertPropertyType<T>> : ConvertPropertyArray<T>;
21
+ type ConvertPropertyObject<T extends PropertyPrototype> = ConvertPropertyMultilang<T>;
22
+ type ConvertProperty<T extends ValidPropertyDefinition> = T extends PropertyPrototype ? ConvertPropertyObject<T> : string;
23
+ export type SchemaInterfaceIdentity = {
24
24
  $id: string;
25
25
  };
26
- export declare type SchemaInterfaceType = {
26
+ export type SchemaInterfaceType = {
27
27
  $type: string[];
28
28
  };
29
- export declare type SchemaInterface<T extends SchemaPrototype> = {
29
+ export type SchemaInterface<T extends SchemaPrototype> = {
30
30
  [X in Exclude<keyof T, "@type">]: T[X] extends ValidPropertyDefinition ? ConvertProperty<T[X]> : never;
31
31
  } & SchemaInterfaceIdentity & SchemaInterfaceType;
32
32
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { SupportedDataTypes } from "./data_types.js";
2
- declare type PropertyType = keyof SupportedDataTypes;
3
- export declare type PropertyPrototype = {
2
+ type PropertyType = keyof SupportedDataTypes;
3
+ export type PropertyPrototype = {
4
4
  "@id": string;
5
5
  "@type"?: PropertyType;
6
6
  "@context"?: SchemaPrototype;
@@ -8,14 +8,14 @@ export declare type PropertyPrototype = {
8
8
  "@array"?: true;
9
9
  "@multilang"?: true;
10
10
  };
11
- export declare type SchemaPrototypeProperties = {
11
+ export type SchemaPrototypeProperties = {
12
12
  [key: string]: PropertyPrototype | string | readonly string[];
13
13
  };
14
- export declare type SchemaPrototypeType = {
14
+ export type SchemaPrototypeType = {
15
15
  "@type": string | readonly string[];
16
16
  };
17
- export declare type SchemaPrototype = SchemaPrototypeProperties & SchemaPrototypeType;
18
- export declare type Property = {
17
+ export type SchemaPrototype = SchemaPrototypeProperties & SchemaPrototypeType;
18
+ export type Property = {
19
19
  "@id": string;
20
20
  "@type"?: PropertyType;
21
21
  "@context"?: Schema;
@@ -23,7 +23,7 @@ export declare type Property = {
23
23
  "@array"?: true;
24
24
  "@multilang"?: true;
25
25
  };
26
- export declare type Schema = {
26
+ export type Schema = {
27
27
  [key: string]: Property | string[];
28
28
  "@type": string[];
29
29
  };
@@ -1,7 +1,7 @@
1
1
  import { SparqlBuilder } from "./sparql_shared_builders.js";
2
2
  import { type RDF } from "../rdf.js";
3
3
  import { type SparqlValue } from "./sparql_tag.js";
4
- declare type Builders<T extends keyof SparqlQueryBuilder> = Pick<SparqlQueryBuilder, T>;
4
+ type Builders<T extends keyof SparqlQueryBuilder> = Pick<SparqlQueryBuilder, T>;
5
5
  declare class SparqlQueryBuilder extends SparqlBuilder {
6
6
  OFFSET(number: number): Builders<"build">;
7
7
  LIMIT(number: number): Builders<"build" | "OFFSET">;
@@ -1,6 +1,6 @@
1
1
  import { DataFactory, RDF } from "../rdf.js";
2
2
  import { type SparqlValue } from "./sparql_tag.js";
3
- declare type Wrap = (keyword: string, value: string) => string;
3
+ type Wrap = (keyword: string, value: string) => string;
4
4
  export declare const braces: Wrap;
5
5
  export declare const parentheses: Wrap;
6
6
  export declare abstract class SparqlBuilder {
@@ -1,3 +1,3 @@
1
1
  import { type RDF } from "../rdf.js";
2
- export declare type SparqlValue = RDF.Term | string | number | boolean | Date | Iterable<SparqlValue> | null | undefined;
2
+ export type SparqlValue = RDF.Term | string | number | boolean | Date | Iterable<SparqlValue> | null | undefined;
3
3
  export declare const sparql: (strings: TemplateStringsArray, ...values: SparqlValue[]) => string;
@@ -1,7 +1,7 @@
1
1
  import { SparqlBuilder } from "./sparql_shared_builders.js";
2
2
  import { type RDF } from "../rdf.js";
3
3
  import { type SparqlValue } from "./sparql_tag.js";
4
- declare type Builders<T extends keyof SparqlUpdateBuilder> = Pick<SparqlUpdateBuilder, T>;
4
+ type Builders<T extends keyof SparqlUpdateBuilder> = Pick<SparqlUpdateBuilder, T>;
5
5
  declare class SparqlUpdateBuilder extends SparqlBuilder {
6
6
  WHERE(strings: TemplateStringsArray, ...values: SparqlValue[]): Builders<"build">;
7
7
  USING_NAMED(stringOrNamedNode: string | RDF.NamedNode<string>): Builders<"USING_NAMED" | "WHERE">;
package/types/mod.d.ts CHANGED
@@ -3,3 +3,4 @@ export { setDefaultContext, setDefaultEngine } from "./library/global.js";
3
3
  export { type SchemaInterface } from "./library/schema/mod.js";
4
4
  export { createLens, createResource, type Lens } from "./library/lens/mod.js";
5
5
  export { createNamespace } from "./library/namespaces/namespace.js";
6
+ export { QueryEngine } from "./library/engine/mod.js";