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.
Files changed (152) hide show
  1. package/README.md +5 -5
  2. package/esm/library/decoder.js +20 -30
  3. package/esm/library/encoder.js +33 -17
  4. package/esm/library/engine/mod.js +2 -2
  5. package/esm/library/engine/query_engine.js +40 -0
  6. package/esm/library/engine/query_engine_proxy.js +8 -8
  7. package/esm/library/engine/types.js +1 -0
  8. package/esm/library/lens/lens.js +414 -25
  9. package/esm/library/lens/mod.js +1 -1
  10. package/esm/library/lens/query_builder.js +81 -50
  11. package/esm/library/lens/search_helper.js +142 -0
  12. package/esm/library/lens/update_helper.js +157 -0
  13. package/esm/library/namespace.js +36 -0
  14. package/esm/library/options.js +50 -0
  15. package/esm/library/schema/data_types.js +3 -38
  16. package/esm/library/schema/search.js +1 -0
  17. package/esm/library/schema/utils.js +31 -6
  18. package/esm/library/sparql/mod.js +2 -1
  19. package/esm/library/sparql/sparql_expression_builders.js +18 -0
  20. package/esm/library/sparql/sparql_query_builders.js +65 -0
  21. package/esm/library/sparql/sparql_shared_builders.js +1 -0
  22. package/esm/library/sparql/sparql_tag.js +27 -1
  23. package/esm/library/sparql/sparql_update_builders.js +70 -0
  24. package/esm/library/sparql/stringify.js +3 -4
  25. package/esm/mod.js +4 -4
  26. package/esm/{library/namespaces → namespaces}/dbo.js +7 -2
  27. package/esm/{library/namespaces → namespaces}/dc.js +7 -2
  28. package/esm/{library/namespaces → namespaces}/dcterms.js +7 -2
  29. package/esm/{library/namespaces → namespaces}/foaf.js +7 -2
  30. package/esm/{library/namespaces → namespaces}/gr.js +7 -2
  31. package/esm/namespaces/ldkit.js +11 -0
  32. package/esm/namespaces/owl.js +91 -0
  33. package/{script/library → esm}/namespaces/rdf.js +7 -4
  34. package/{script/library → esm}/namespaces/rdfs.js +7 -4
  35. package/esm/{library/namespaces → namespaces}/schema.js +7 -2
  36. package/esm/{library/namespaces → namespaces}/sioc.js +7 -2
  37. package/{script/library → esm}/namespaces/skos.js +7 -4
  38. package/{script/library → esm}/namespaces/xsd.js +7 -4
  39. package/esm/namespaces.js +30 -1
  40. package/esm/rdf.js +14 -1
  41. package/esm/sparql.js +13 -0
  42. package/package.json +2 -2
  43. package/script/library/decoder.js +25 -38
  44. package/script/library/encoder.js +38 -24
  45. package/script/library/engine/mod.js +16 -5
  46. package/script/library/engine/query_engine.js +40 -0
  47. package/script/library/engine/query_engine_proxy.js +7 -7
  48. package/script/library/engine/types.js +2 -0
  49. package/script/library/lens/lens.js +415 -27
  50. package/script/library/lens/mod.js +15 -4
  51. package/script/library/lens/query_builder.js +82 -54
  52. package/script/library/lens/search_helper.js +146 -0
  53. package/script/library/lens/update_helper.js +161 -0
  54. package/script/library/namespace.js +40 -0
  55. package/script/library/options.js +56 -0
  56. package/script/library/schema/data_types.js +3 -41
  57. package/script/library/schema/search.js +2 -0
  58. package/script/library/schema/utils.js +33 -11
  59. package/script/library/sparql/mod.js +17 -3
  60. package/script/library/sparql/sparql_expression_builders.js +22 -0
  61. package/script/library/sparql/sparql_query_builders.js +65 -0
  62. package/script/library/sparql/sparql_shared_builders.js +3 -1
  63. package/script/library/sparql/sparql_tag.js +30 -7
  64. package/script/library/sparql/sparql_update_builders.js +70 -0
  65. package/script/library/sparql/stringify.js +4 -8
  66. package/script/mod.js +20 -11
  67. package/script/{library/namespaces → namespaces}/dbo.js +8 -2
  68. package/script/{library/namespaces → namespaces}/dc.js +8 -2
  69. package/script/{library/namespaces → namespaces}/dcterms.js +8 -2
  70. package/script/{library/namespaces → namespaces}/foaf.js +8 -2
  71. package/script/{library/namespaces → namespaces}/gr.js +8 -2
  72. package/script/namespaces/ldkit.js +14 -0
  73. package/script/namespaces/owl.js +94 -0
  74. package/{esm/library → script}/namespaces/rdf.js +10 -2
  75. package/{esm/library → script}/namespaces/rdfs.js +10 -2
  76. package/script/{library/namespaces → namespaces}/schema.js +8 -2
  77. package/script/{library/namespaces → namespaces}/sioc.js +8 -2
  78. package/{esm/library → script}/namespaces/skos.js +10 -2
  79. package/{esm/library → script}/namespaces/xsd.js +10 -2
  80. package/script/namespaces.js +44 -1
  81. package/script/rdf.js +20 -15
  82. package/script/sparql.js +13 -0
  83. package/types/library/decoder.d.ts +4 -3
  84. package/types/library/encoder.d.ts +5 -3
  85. package/types/library/engine/mod.d.ts +2 -2
  86. package/types/library/engine/query_engine.d.ts +50 -9
  87. package/types/library/engine/query_engine_proxy.d.ts +4 -3
  88. package/types/library/engine/types.d.ts +23 -0
  89. package/types/library/lens/lens.d.ts +400 -23
  90. package/types/library/lens/mod.d.ts +1 -1
  91. package/types/library/lens/query_builder.d.ts +10 -10
  92. package/types/library/lens/search_helper.d.ts +21 -0
  93. package/types/library/lens/types.d.ts +5 -2
  94. package/types/library/lens/update_helper.d.ts +23 -0
  95. package/types/library/namespace.d.ts +41 -0
  96. package/types/library/options.d.ts +72 -0
  97. package/types/library/rdf.d.ts +8 -15
  98. package/types/library/schema/data_types.d.ts +44 -37
  99. package/types/library/schema/interface.d.ts +75 -20
  100. package/types/library/schema/mod.d.ts +4 -2
  101. package/types/library/schema/schema.d.ts +23 -16
  102. package/types/library/schema/search.d.ts +20 -0
  103. package/types/library/schema/utils.d.ts +3 -3
  104. package/types/library/sparql/mod.d.ts +2 -1
  105. package/types/library/sparql/sparql_expression_builders.d.ts +19 -0
  106. package/types/library/sparql/sparql_query_builders.d.ts +68 -3
  107. package/types/library/sparql/sparql_shared_builders.d.ts +1 -0
  108. package/types/library/sparql/sparql_tag.d.ts +29 -1
  109. package/types/library/sparql/sparql_update_builders.d.ts +68 -0
  110. package/types/mod.d.ts +5 -6
  111. package/types/namespaces/dbo.d.ts +10 -0
  112. package/types/namespaces/dc.d.ts +10 -0
  113. package/types/namespaces/dcterms.d.ts +10 -0
  114. package/types/namespaces/foaf.d.ts +10 -0
  115. package/types/namespaces/gr.d.ts +10 -0
  116. package/types/namespaces/ldkit.d.ts +10 -0
  117. package/types/namespaces/owl.d.ts +10 -0
  118. package/types/namespaces/rdf.d.ts +10 -0
  119. package/types/namespaces/rdfs.d.ts +10 -0
  120. package/types/namespaces/schema.d.ts +10 -0
  121. package/types/namespaces/sioc.d.ts +10 -0
  122. package/types/namespaces/skos.d.ts +10 -0
  123. package/types/namespaces/xsd.d.ts +10 -0
  124. package/types/namespaces.d.ts +30 -1
  125. package/types/rdf.d.ts +14 -1
  126. package/types/sparql.d.ts +13 -0
  127. package/esm/library/global.js +0 -25
  128. package/esm/library/lens/query_helper.js +0 -102
  129. package/esm/library/namespaces/ldkit.js +0 -6
  130. package/esm/library/namespaces/mod.js +0 -13
  131. package/esm/library/namespaces/namespace.js +0 -11
  132. package/script/library/global.js +0 -32
  133. package/script/library/lens/query_helper.js +0 -106
  134. package/script/library/namespaces/ldkit.js +0 -8
  135. package/script/library/namespaces/mod.js +0 -32
  136. package/script/library/namespaces/namespace.js +0 -15
  137. package/types/library/global.d.ts +0 -5
  138. package/types/library/lens/query_helper.d.ts +0 -19
  139. package/types/library/namespaces/dbo.d.ts +0 -3649
  140. package/types/library/namespaces/dc.d.ts +0 -21
  141. package/types/library/namespaces/dcterms.d.ts +0 -104
  142. package/types/library/namespaces/foaf.d.ts +0 -69
  143. package/types/library/namespaces/gr.d.ts +0 -175
  144. package/types/library/namespaces/ldkit.d.ts +0 -7
  145. package/types/library/namespaces/mod.d.ts +0 -13
  146. package/types/library/namespaces/namespace.d.ts +0 -15
  147. package/types/library/namespaces/rdf.d.ts +0 -28
  148. package/types/library/namespaces/rdfs.d.ts +0 -21
  149. package/types/library/namespaces/schema.d.ts +0 -2697
  150. package/types/library/namespaces/sioc.d.ts +0 -105
  151. package/types/library/namespaces/skos.d.ts +0 -38
  152. package/types/library/namespaces/xsd.d.ts +0 -56
package/esm/rdf.js CHANGED
@@ -1 +1,14 @@
1
- export * from "./library/rdf.js";
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": "1.1.0",
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 = __importDefault(require("./namespaces/ldkit.js"));
9
- const rdf_js_2 = __importDefault(require("./namespaces/rdf.js"));
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, context) {
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, "context", {
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.context = context;
39
+ this.options = options;
39
40
  }
40
- static decode(graph, schema, context) {
41
- return new Decoder(graph, schema, context).decode();
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.default.type)) {
59
- const types = properties.get(rdf_js_2.default.type);
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.default.Resource) {
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.default.Resource}> found`);
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 terms = node.get(property["@id"]);
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"] ? [] : undefined;
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["@context"]) {
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["@context"]);
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["@context"]) {
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["@context"]);
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.context.language;
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 = __importDefault(require("./namespaces/xsd.js"));
9
- const rdf_js_2 = __importDefault(require("./namespaces/rdf.js"));
10
- const encode = (node, schema, context, variableInitCounter = 0) => {
11
- return Encoder.encode(node, schema, context, variableInitCounter);
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(context, variableInitCounter) {
16
- Object.defineProperty(this, "context", {
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.context = context;
55
+ this.options = options;
56
+ this.includeType = includeType;
43
57
  this.variableCounter = variableInitCounter;
44
58
  }
45
- static encode(node, schema, context, variableInitCounter) {
46
- return new Encoder(context, variableInitCounter).encode(node, schema);
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.encodeNodeType(node, schema["@type"], nodeId);
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.default.type), this.df.namedNode(type));
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["@context"]) {
122
+ if (property["@schema"]) {
107
123
  const subNodeId = this.getNodeId(val);
108
- this.encodeNode(val, property["@context"], subNodeId);
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.default.string;
113
- if (typeof val === "string" && this.context.language) {
114
- if (propertyType === xsd_js_1.default.string || propertyType === rdf_js_2.default.langString) {
115
- this.push(nodeId, propertyId, this.df.literal(val, this.context.language));
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, rdf_js_1.toRdf)(val, {
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
- exports.QueryEngineProxy = exports.QueryEngine = void 0;
4
- var query_engine_js_1 = require("./query_engine.js");
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(context, engine) {
8
- Object.defineProperty(this, "context", {
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, "engine", {
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.context = (0, global_js_1.resolveContext)(context);
21
- this.engine = (0, global_js_1.resolveEngine)(engine);
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
- return (0, rdf_js_1.quadsToGraph)(quads);
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);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });