ldkit 0.4.2 → 0.5.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 (51) hide show
  1. package/esm/library/decoder.js +5 -0
  2. package/esm/library/encoder.js +3 -3
  3. package/esm/library/engine/mod.js +2 -0
  4. package/esm/library/engine/query_engine.js +75 -0
  5. package/esm/library/engine/query_engine_proxy.js +35 -0
  6. package/esm/library/global.js +25 -0
  7. package/esm/library/namespaces/mod.js +1 -0
  8. package/esm/library/namespaces/rdfs.js +22 -0
  9. package/esm/library/rdf.js +78 -6
  10. package/esm/library/resource/query_builder.js +44 -37
  11. package/esm/library/resource/resource.js +19 -10
  12. package/esm/library/rxjs.js +2 -2
  13. package/esm/mod.js +1 -1
  14. package/package.json +2 -2
  15. package/script/library/decoder.js +5 -0
  16. package/script/library/encoder.js +2 -2
  17. package/script/library/engine/mod.js +7 -0
  18. package/script/library/engine/query_engine.js +79 -0
  19. package/script/library/engine/query_engine_proxy.js +39 -0
  20. package/script/library/global.js +32 -0
  21. package/script/library/namespaces/mod.js +3 -1
  22. package/script/library/namespaces/rdfs.js +24 -0
  23. package/script/library/rdf.js +84 -37
  24. package/script/library/resource/query_builder.js +41 -34
  25. package/script/library/resource/resource.js +19 -10
  26. package/script/library/rxjs.js +6 -3
  27. package/script/mod.js +4 -4
  28. package/types/library/decoder.d.ts +2 -3
  29. package/types/library/encoder.d.ts +2 -3
  30. package/types/library/engine/mod.d.ts +2 -0
  31. package/types/library/engine/query_engine.d.ts +10 -0
  32. package/types/library/engine/query_engine_proxy.d.ts +10 -0
  33. package/types/library/global.d.ts +5 -0
  34. package/types/library/namespaces/dcterms.d.ts +1 -1
  35. package/types/library/namespaces/mod.d.ts +1 -0
  36. package/types/library/namespaces/rdf.d.ts +4 -4
  37. package/types/library/namespaces/rdfs.d.ts +21 -0
  38. package/types/library/namespaces/schema.d.ts +5 -5
  39. package/types/library/namespaces/skos.d.ts +1 -1
  40. package/types/library/rdf.d.ts +47 -8
  41. package/types/library/resource/query_builder.d.ts +5 -5
  42. package/types/library/resource/query_helper.d.ts +6 -7
  43. package/types/library/resource/resource.d.ts +8 -8
  44. package/types/library/rxjs.d.ts +2 -2
  45. package/types/mod.d.ts +2 -1
  46. package/esm/library/context.js +0 -13
  47. package/esm/library/engine.js +0 -9
  48. package/script/library/context.js +0 -19
  49. package/script/library/engine.js +0 -16
  50. package/types/library/context.d.ts +0 -9
  51. package/types/library/engine.d.ts +0 -6
@@ -48,9 +48,14 @@ class Decoder {
48
48
  decode() {
49
49
  const output = [];
50
50
  for (const [iri, properties] of this.graph) {
51
+ console.warn("IRI", iri);
51
52
  if (properties.has(rdf.type)) {
52
53
  const types = properties.get(rdf.type);
53
54
  for (const type of types) {
55
+ console.warn("TYPE", type.value);
56
+ if (type.value === ldkit.Resource) {
57
+ console.warn("FOUND", type);
58
+ }
54
59
  if (type.termType === "NamedNode" && type.value === ldkit.Resource) {
55
60
  output.push(this.decodeNode(iri, this.schema));
56
61
  }
@@ -1,4 +1,4 @@
1
- import { DataFactory, literal, toRdf, } from "./rdf.js";
1
+ import { DataFactory, toRdf } from "./rdf.js";
2
2
  import { rdf, xsd } from "./namespaces/mod.js";
3
3
  export const encode = (node, schema, context, variableInitCounter = 0) => {
4
4
  return Encoder.encode(node, schema, context, variableInitCounter);
@@ -87,7 +87,7 @@ class Encoder {
87
87
  ? value[language]
88
88
  : [value[language]];
89
89
  languageValue.forEach((singleValue) => {
90
- this.push(nodeId, propertyId, literal(singleValue, language.length > 0 ? language : undefined));
90
+ this.push(nodeId, propertyId, this.df.literal(singleValue, language.length > 0 ? language : undefined));
91
91
  });
92
92
  });
93
93
  return;
@@ -103,7 +103,7 @@ class Encoder {
103
103
  const propertyType = property["@type"] ? property["@type"] : xsd.string;
104
104
  if (typeof val === "string" && this.context.language) {
105
105
  if (propertyType === xsd.string || propertyType === rdf.langString) {
106
- this.push(nodeId, propertyId, literal(val, this.context.language));
106
+ this.push(nodeId, propertyId, this.df.literal(val, this.context.language));
107
107
  return;
108
108
  }
109
109
  }
@@ -0,0 +1,2 @@
1
+ export { QueryEngine } from "./query_engine.js";
2
+ export { QueryEngineProxy } from "./query_engine_proxy.js";
@@ -0,0 +1,75 @@
1
+ import { BindingsFactory, QuadFactory, } from "../rdf.js";
2
+ export class QueryEngine {
3
+ getSparqlEndpoint(context) {
4
+ if (!context) {
5
+ throw new Error("No context supplied to QueryEngine. You need to create a default context or pass one to a resource.");
6
+ }
7
+ if (!Array.isArray(context.sources) || context.sources.length < 1) {
8
+ throw new Error("Invalid context `sources` attribute defined. You need to provide a URL to a SPARQL endpoint to query.");
9
+ }
10
+ if (context.sources.length > 1) {
11
+ throw new Error("This query engine supports only one data source, multiple defined in `sources` property in context.");
12
+ }
13
+ const source = context.sources[0];
14
+ if (typeof source === "string") {
15
+ return source;
16
+ }
17
+ if ("value" in source && typeof source.value === "string") {
18
+ if ("type" in source) {
19
+ if (source.type === "sparql") {
20
+ return source.value;
21
+ }
22
+ }
23
+ else {
24
+ return source.value;
25
+ }
26
+ }
27
+ throw new Error("Invalid SPARQL source defined - please provide URL to a SPARQL endpoint to query.");
28
+ }
29
+ getFetch(context) {
30
+ return context && context.fetch ? context.fetch : fetch;
31
+ }
32
+ async query(query, context) {
33
+ const endpoint = this.getSparqlEndpoint(context);
34
+ const fetchFn = this.getFetch(context);
35
+ return await fetchFn(endpoint, {
36
+ method: "POST",
37
+ body: query,
38
+ headers: {
39
+ "content-type": "application/sparql-query",
40
+ "accept": "application/sparql-results+json",
41
+ },
42
+ });
43
+ }
44
+ async queryBindings(query, context) {
45
+ const result = await this.query(query, context);
46
+ const json = await result.json();
47
+ if (!Array.isArray(json?.results?.bindings)) {
48
+ throw new Error("Bindings SPARQL query result not found");
49
+ }
50
+ // Force richer type from RDF spec
51
+ const bindingsFactory = new BindingsFactory();
52
+ return Array.from(json.results.bindings, (i) => bindingsFactory.fromJson(i));
53
+ }
54
+ async queryBoolean(query, context) {
55
+ const result = await this.query(query, context);
56
+ const json = await result.json();
57
+ if ("boolean" in json) {
58
+ return Boolean(json.boolean);
59
+ }
60
+ throw new Error("Boolean SPARQL query result not found");
61
+ }
62
+ async queryQuads(query, context) {
63
+ const result = await this.query(query, context);
64
+ const json = await result.json();
65
+ if (!Array.isArray(json?.results?.bindings)) {
66
+ throw new Error("Quads SPARQL query result not found");
67
+ }
68
+ // Force richer type from RDF spec
69
+ const quadFactory = new QuadFactory();
70
+ return Array.from(json.results.bindings, (i) => quadFactory.fromJson(i));
71
+ }
72
+ async queryVoid(query, context) {
73
+ await this.query(query, context);
74
+ }
75
+ }
@@ -0,0 +1,35 @@
1
+ import { quadsToGraph } from "../rdf.js";
2
+ import { resolveContext, resolveEngine } from "../global.js";
3
+ import { from, map, of, switchMap } from "../rxjs.js";
4
+ export class QueryEngineProxy {
5
+ constructor(context, engine) {
6
+ Object.defineProperty(this, "context", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: void 0
11
+ });
12
+ Object.defineProperty(this, "engine", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ this.context = resolveContext(context);
19
+ this.engine = resolveEngine(engine);
20
+ }
21
+ queryBoolean(query) {
22
+ return from(this.engine.queryBoolean(query, this.context));
23
+ }
24
+ queryBindings(query) {
25
+ return from(this.engine.queryBindings(query, this.context)).pipe(switchMap((stream) => of(Array.from(stream))));
26
+ }
27
+ queryGraph(query) {
28
+ return from(this.engine.queryQuads(query, this.context)).pipe(switchMap((stream) => of(Array.from(stream))), map((quads) => {
29
+ return quadsToGraph(quads);
30
+ }));
31
+ }
32
+ queryVoid(query) {
33
+ return from(this.engine.queryVoid(query, this.context));
34
+ }
35
+ }
@@ -0,0 +1,25 @@
1
+ import { QueryEngine } from "./engine/mod.js";
2
+ let defaultContext = undefined;
3
+ let defaultEngine = undefined;
4
+ export const setDefaultContext = (context) => {
5
+ defaultContext = context;
6
+ };
7
+ export const resolveContext = (context) => {
8
+ if (!context && !defaultContext) {
9
+ throw new Error("No context found. Please create a default context or pass one to createResource function");
10
+ }
11
+ return context || defaultContext;
12
+ };
13
+ export const setDefaultEngine = (engine) => {
14
+ defaultEngine = engine;
15
+ };
16
+ export const resolveEngine = (engine) => {
17
+ if (!engine && !defaultEngine) {
18
+ setDefaultEngine(new QueryEngine());
19
+ // TODO: consider the consequences here, maybe log a warning?
20
+ /*throw new Error(
21
+ "No engine found. Please create a default engine or pass one to createResource function",
22
+ );*/
23
+ }
24
+ return engine || defaultEngine;
25
+ };
@@ -1,4 +1,5 @@
1
1
  export { default as rdf } from "./rdf.js";
2
+ export { default as rdfs } from "./rdfs.js";
2
3
  export { default as dcterms } from "./dcterms.js";
3
4
  export { default as ldkit } from "./ldkit.js";
4
5
  export { default as schema } from "./schema.js";
@@ -0,0 +1,22 @@
1
+ import { createNamespace } from "./namespace.js";
2
+ export default createNamespace({
3
+ iri: "http://www.w3.org/2000/01/rdf-schema#",
4
+ prefix: "rdfs:",
5
+ terms: [
6
+ "Class",
7
+ "Container",
8
+ "ContainerMembershipProperty",
9
+ "Datatype",
10
+ "Literal",
11
+ "Resource",
12
+ "comment",
13
+ "domain",
14
+ "isDefinedBy",
15
+ "label",
16
+ "member",
17
+ "range",
18
+ "seeAlso",
19
+ "subClassOf",
20
+ "subPropertyOf",
21
+ ],
22
+ });
@@ -1,11 +1,7 @@
1
1
  export { fromRdf, toRdf } from "rdf-literal";
2
- import * as DataFactory from "rdf-data-factory";
2
+ import { DataFactory } from "rdf-data-factory";
3
3
  export { DataFactory } from "rdf-data-factory";
4
- export const namedNode = (value) => new DataFactory.NamedNode(value);
5
- export const blankNode = (value) => new DataFactory.BlankNode(value);
6
- export const literal = (value, languageOrDatatype) => new DataFactory.Literal(value, languageOrDatatype);
7
- export const quad = (subject, predicate, object, graph) => new DataFactory.Quad(subject, predicate, object, graph || DataFactory.DefaultGraph.INSTANCE);
8
- export const variable = (value) => new DataFactory.Variable(value);
4
+ import { BindingsFactory as ComunicaBindingsFactory } from "@comunica/bindings-factory";
9
5
  export const quadsToGraph = (quads) => {
10
6
  const graph = new Map();
11
7
  for (const quad of quads) {
@@ -17,3 +13,79 @@ export const quadsToGraph = (quads) => {
17
13
  }
18
14
  return graph;
19
15
  };
16
+ export class TermFactory {
17
+ constructor(dataFactory = new DataFactory()) {
18
+ Object.defineProperty(this, "dataFactory", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.dataFactory = dataFactory;
25
+ }
26
+ fromJson(jsonTerm) {
27
+ if (jsonTerm.type === "uri") {
28
+ return this.dataFactory.namedNode(jsonTerm.value);
29
+ }
30
+ if (jsonTerm.type === "bnode") {
31
+ return this.dataFactory.blankNode(jsonTerm.value);
32
+ }
33
+ if ("xml:lang" in jsonTerm) {
34
+ return this.dataFactory.literal(jsonTerm.value, jsonTerm["xml:lang"]);
35
+ }
36
+ if ("datatype" in jsonTerm) {
37
+ return this.dataFactory.literal(jsonTerm.value, this.dataFactory.namedNode(jsonTerm.datatype));
38
+ }
39
+ return this.dataFactory.literal(jsonTerm.value);
40
+ }
41
+ }
42
+ export class BindingsFactory extends ComunicaBindingsFactory {
43
+ constructor(dataFactory = new DataFactory(), termFactory = new TermFactory()) {
44
+ super(dataFactory);
45
+ Object.defineProperty(this, "localDataFactory", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "termFactory", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ this.localDataFactory = dataFactory;
58
+ this.termFactory = termFactory;
59
+ }
60
+ fromJson(jsonBindings) {
61
+ const bindingsEntries = Object.entries(jsonBindings).map(([varName, jsonTerm]) => {
62
+ return [
63
+ this.localDataFactory.variable(varName),
64
+ this.termFactory.fromJson(jsonTerm),
65
+ ];
66
+ });
67
+ return this.bindings(bindingsEntries);
68
+ }
69
+ }
70
+ export class QuadFactory {
71
+ constructor(dataFactory = new DataFactory(), bindingsFactory = new BindingsFactory(dataFactory)) {
72
+ Object.defineProperty(this, "dataFactory", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ Object.defineProperty(this, "bindingsFactory", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: void 0
83
+ });
84
+ this.dataFactory = dataFactory;
85
+ this.bindingsFactory = bindingsFactory;
86
+ }
87
+ fromJson(jsonBindings) {
88
+ const bindings = this.bindingsFactory.fromJson(jsonBindings);
89
+ return this.dataFactory.quad(bindings.get("s"), bindings.get("p"), bindings.get("o"));
90
+ }
91
+ }
@@ -1,7 +1,7 @@
1
1
  import { getSchemaProperties } from "../schema/mod.js";
2
- import { $, CONSTRUCT, SELECT, INSERT, DELETE } from "../sparql.js";
3
- import { variable, namedNode, quad } from "../rdf.js";
4
- import { rdf, ldkit } from "../namespaces/mod.js";
2
+ import { $, CONSTRUCT, DELETE, INSERT, SELECT } from "../sparql.js";
3
+ import { DataFactory } from "../rdf.js";
4
+ import { ldkit, rdf } from "../namespaces/mod.js";
5
5
  import { encode } from "../encoder.js";
6
6
  import { QueryHelper } from "./query_helper.js";
7
7
  export class QueryBuilder {
@@ -24,28 +24,35 @@ export class QueryBuilder {
24
24
  writable: true,
25
25
  value: void 0
26
26
  });
27
+ Object.defineProperty(this, "df", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
27
33
  Object.defineProperty(this, "deleteQuery", {
28
34
  enumerable: true,
29
35
  configurable: true,
30
36
  writable: true,
31
37
  value: (iris) => {
32
- return DELETE `
33
- ?s ?p ?o
34
- `.WHERE `
35
- ?s ?p ?o .
36
- VALUES ?s { ${iris.map(namedNode)} }
38
+ return DELETE `
39
+ ?s ?p ?o
40
+ `.WHERE `
41
+ ?s ?p ?o .
42
+ VALUES ?s { ${iris.map(this.df.namedNode)} }
37
43
  `.build();
38
44
  }
39
45
  });
40
46
  this.schema = schema;
41
47
  this.schemaProperties = getSchemaProperties(this.schema);
42
48
  this.context = context;
49
+ this.df = new DataFactory();
43
50
  }
44
51
  getResourceSignature() {
45
- return quad(variable("iri"), namedNode(rdf.type), namedNode(ldkit.Resource));
52
+ return this.df.quad(this.df.variable("iri"), this.df.namedNode(rdf.type), this.df.namedNode(ldkit.Resource));
46
53
  }
47
54
  getTypesSignature() {
48
- return quad(variable("iri"), namedNode(rdf.type), variable("iri_type"));
55
+ return this.df.quad(this.df.variable("iri"), this.df.namedNode(rdf.type), this.df.variable("iri_type"));
49
56
  }
50
57
  entitiesToQuads(entities) {
51
58
  const quadArrays = entities.map((entity) => encode(entity, this.schema, this.context));
@@ -59,7 +66,7 @@ export class QueryBuilder {
59
66
  const properties = getSchemaProperties(s);
60
67
  if (varPrefix !== "iri" || !omitRootTypes) {
61
68
  rdfType.forEach((type) => {
62
- conditions.push(quad(variable(varPrefix), namedNode(rdf.type), namedNode(type)));
69
+ conditions.push(this.df.quad(this.df.variable(varPrefix), this.df.namedNode(rdf.type), this.df.namedNode(type)));
63
70
  });
64
71
  }
65
72
  Object.keys(properties).forEach((prop, index) => {
@@ -71,7 +78,7 @@ export class QueryBuilder {
71
78
  if (wrapOptional && isOptional) {
72
79
  conditions.push($ `\nOPTIONAL {`);
73
80
  }
74
- conditions.push(quad(variable(varPrefix), namedNode(property["@id"]), variable(`${varPrefix}_${index}`)));
81
+ conditions.push(this.df.quad(this.df.variable(varPrefix), this.df.namedNode(property["@id"]), this.df.variable(`${varPrefix}_${index}`)));
75
82
  if (typeof property["@context"] === "object") {
76
83
  populateConditionsRecursive(property["@context"], `${varPrefix}_${index}`);
77
84
  }
@@ -88,36 +95,36 @@ export class QueryBuilder {
88
95
  return SELECT `(count(?iri) as ?count)`.WHERE `${quads}`.build();
89
96
  }
90
97
  getQuery(where, limit = 1000) {
91
- const selectSubQuery = SELECT `
92
- ${variable("iri")}
93
- `.WHERE `
94
- ${this.getShape(false, true)}
95
- ${where}
98
+ const selectSubQuery = SELECT `
99
+ ${this.df.variable("iri")}
100
+ `.WHERE `
101
+ ${this.getShape(false, true)}
102
+ ${where}
96
103
  `.LIMIT(limit);
97
- const query = CONSTRUCT `
98
- ${this.getResourceSignature()}
99
- ${this.getTypesSignature()}
100
- ${this.getShape(true, false, true)}
101
- `.WHERE `
102
- ${this.getTypesSignature()}
103
- ${this.getShape(true, true, true)}
104
- {
105
- ${selectSubQuery}
106
- }
104
+ const query = CONSTRUCT `
105
+ ${this.getResourceSignature()}
106
+ ${this.getTypesSignature()}
107
+ ${this.getShape(true, false, true)}
108
+ `.WHERE `
109
+ ${this.getTypesSignature()}
110
+ ${this.getShape(true, true, true)}
111
+ {
112
+ ${selectSubQuery}
113
+ }
107
114
  `.build();
108
115
  return query;
109
116
  }
110
117
  getByIrisQuery(iris) {
111
- const query = CONSTRUCT `
112
- ${this.getResourceSignature()}
113
- ${this.getTypesSignature()}
114
- ${this.getShape(true, false, true)}
115
- `.WHERE `
116
- ${this.getTypesSignature()}
117
- ${this.getShape(true, true, true)}
118
- VALUES ?iri {
119
- ${iris.map(namedNode)}
120
- }
118
+ const query = CONSTRUCT `
119
+ ${this.getResourceSignature()}
120
+ ${this.getTypesSignature()}
121
+ ${this.getShape(true, false, true)}
122
+ `.WHERE `
123
+ ${this.getTypesSignature()}
124
+ ${this.getShape(true, true, true)}
125
+ VALUES ?iri {
126
+ ${iris.map(this.df.namedNode)}
127
+ }
121
128
  `.build();
122
129
  return query;
123
130
  }
@@ -1,12 +1,12 @@
1
- import { map, switchMap, tap, share, BehaviorSubject } from "../rxjs.js";
2
- import { bindingsQuery, quadsQuery, updateQuery } from "../engine.js";
3
- import { resolveContext } from "../context.js";
1
+ import { BehaviorSubject, map, share, switchMap, tap } from "../rxjs.js";
2
+ import { resolveContext } from "../global.js";
4
3
  import { expandSchema, } from "../schema/mod.js";
5
4
  import { decode } from "../decoder.js";
6
5
  import { QueryBuilder } from "./query_builder.js";
7
- export const createResource = (spec, context) => new Resource(spec, context);
6
+ import { QueryEngineProxy } from "../engine/query_engine_proxy.js";
7
+ export const createResource = (spec, context, engine) => new Resource(spec, context, engine);
8
8
  export class Resource {
9
- constructor(schema, context) {
9
+ constructor(schema, context, engine) {
10
10
  Object.defineProperty(this, "schema", {
11
11
  enumerable: true,
12
12
  configurable: true,
@@ -19,6 +19,12 @@ export class Resource {
19
19
  writable: true,
20
20
  value: void 0
21
21
  });
22
+ Object.defineProperty(this, "engine", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
22
28
  Object.defineProperty(this, "queryBuilder", {
23
29
  enumerable: true,
24
30
  configurable: true,
@@ -33,6 +39,7 @@ export class Resource {
33
39
  });
34
40
  this.schema = expandSchema(schema);
35
41
  this.context = resolveContext(context);
42
+ this.engine = new QueryEngineProxy(this.context, engine);
36
43
  this.queryBuilder = new QueryBuilder(this.schema, this.context);
37
44
  }
38
45
  decode(graph) {
@@ -41,7 +48,7 @@ export class Resource {
41
48
  count() {
42
49
  const q = this.queryBuilder.countQuery();
43
50
  console.log(q);
44
- return this.$trigger.pipe(switchMap(() => bindingsQuery(q, this.context)), map((bindings) => {
51
+ return this.$trigger.pipe(switchMap(() => this.engine.queryBindings(q)), map((bindings) => {
45
52
  console.warn("BINDINGS", bindings);
46
53
  return parseInt(bindings[0].get("count").value);
47
54
  }));
@@ -49,14 +56,16 @@ export class Resource {
49
56
  //exists(entity: Identity) {}
50
57
  query(sparqlConstructQuery) {
51
58
  console.log(sparqlConstructQuery);
52
- return quadsQuery(sparqlConstructQuery, this.context).pipe(map((graph) => {
59
+ return this.engine.queryGraph(sparqlConstructQuery).pipe(map((graph) => {
60
+ console.warn("GRAPH", graph);
53
61
  return this.decode(graph);
54
62
  }));
55
63
  }
56
64
  find(where, limit) {
57
65
  const q = this.queryBuilder.getQuery(where, limit);
58
66
  console.log(q);
59
- return this.$trigger.pipe(switchMap(() => quadsQuery(q, this.context)), map((graph) => {
67
+ return this.$trigger.pipe(switchMap(() => this.engine.queryGraph(q)), map((graph) => {
68
+ console.warn("GRAPH", graph);
60
69
  return this.decode(graph);
61
70
  }));
62
71
  }
@@ -66,13 +75,13 @@ export class Resource {
66
75
  findByIris(iris) {
67
76
  const q = this.queryBuilder.getByIrisQuery(iris);
68
77
  console.log(q);
69
- return this.$trigger.pipe(switchMap(() => quadsQuery(q, this.context)), map((graph) => {
78
+ return this.$trigger.pipe(switchMap(() => this.engine.queryGraph(q)), map((graph) => {
70
79
  return this.decode(graph);
71
80
  }));
72
81
  }
73
82
  updateQuery(query) {
74
83
  console.log(query);
75
- const result = updateQuery(query, this.context).pipe(tap(() => this.$trigger.next(null)), share());
84
+ const result = this.engine.queryVoid(query).pipe(tap(() => this.$trigger.next(null)), share());
76
85
  result.subscribe();
77
86
  return result;
78
87
  }
@@ -1,2 +1,2 @@
1
- export { from, BehaviorSubject, } from "rxjs";
2
- export { map, switchMap, tap, share, } from "rxjs/operators";
1
+ export { BehaviorSubject, firstValueFrom, from, lastValueFrom, of, } from "rxjs";
2
+ export { map, share, switchMap, tap, } from "rxjs/operators";
package/esm/mod.js CHANGED
@@ -1,3 +1,3 @@
1
+ export { setDefaultContext, setDefaultEngine } from "./library/global.js";
1
2
  export { createResource } from "./library/resource/mod.js";
2
3
  export { createNamespace } from "./library/namespaces/namespace.js";
3
- export { createContext, createDefaultContext, } from "./library/context.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.4.2",
6
+ "version": "0.5.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)",
@@ -41,7 +41,7 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/query-sparql": "2.4.3",
44
+ "@comunica/bindings-factory": "2.2.0",
45
45
  "@comunica/types": "2.4.0",
46
46
  "@tpluscode/rdf-string": "0.2.26",
47
47
  "@tpluscode/sparql-builder": "0.3.23",
@@ -51,9 +51,14 @@ class Decoder {
51
51
  decode() {
52
52
  const output = [];
53
53
  for (const [iri, properties] of this.graph) {
54
+ console.warn("IRI", iri);
54
55
  if (properties.has(mod_js_1.rdf.type)) {
55
56
  const types = properties.get(mod_js_1.rdf.type);
56
57
  for (const type of types) {
58
+ console.warn("TYPE", type.value);
59
+ if (type.value === mod_js_1.ldkit.Resource) {
60
+ console.warn("FOUND", type);
61
+ }
57
62
  if (type.termType === "NamedNode" && type.value === mod_js_1.ldkit.Resource) {
58
63
  output.push(this.decodeNode(iri, this.schema));
59
64
  }
@@ -91,7 +91,7 @@ class Encoder {
91
91
  ? value[language]
92
92
  : [value[language]];
93
93
  languageValue.forEach((singleValue) => {
94
- this.push(nodeId, propertyId, (0, rdf_js_1.literal)(singleValue, language.length > 0 ? language : undefined));
94
+ this.push(nodeId, propertyId, this.df.literal(singleValue, language.length > 0 ? language : undefined));
95
95
  });
96
96
  });
97
97
  return;
@@ -107,7 +107,7 @@ class Encoder {
107
107
  const propertyType = property["@type"] ? property["@type"] : mod_js_1.xsd.string;
108
108
  if (typeof val === "string" && this.context.language) {
109
109
  if (propertyType === mod_js_1.xsd.string || propertyType === mod_js_1.rdf.langString) {
110
- this.push(nodeId, propertyId, (0, rdf_js_1.literal)(val, this.context.language));
110
+ this.push(nodeId, propertyId, this.df.literal(val, this.context.language));
111
111
  return;
112
112
  }
113
113
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ 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; } });