ldkit 2.0.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.
package/README.md CHANGED
@@ -110,6 +110,16 @@ Persons.delete("http://dbpedia.org/resource/Alan_Turing");
110
110
 
111
111
  More complex examples can be found in [documentation](https://ldkit.io/docs).
112
112
 
113
+ ## Specification Compliance
114
+
115
+ LDkit complies with the following specifications:
116
+
117
+ - [RDF/JS: Data model specification](https://rdf.js.org/data-model-spec/)
118
+ - [RDF/JS: Query specification](https://rdf.js.org/query-spec/)
119
+ - [SPARQL 1.1 Query Language](https://www.w3.org/TR/sparql11-query/)
120
+ - [SPARQL 1.1 Update](https://www.w3.org/TR/2013/REC-sparql11-update-20130321/)
121
+ - [SPARQL 1.1 Protocol](https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/)
122
+
113
123
  ## License
114
124
 
115
125
  [MIT License](./LICENSE.md)
@@ -41,7 +41,7 @@ export class QueryEngine {
41
41
  getFetch(context) {
42
42
  return context && context.fetch ? context.fetch : fetch;
43
43
  }
44
- query(query, responseType, context) {
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
  }
@@ -125,8 +125,8 @@ export class Lens {
125
125
  *
126
126
  * @returns total number of entities corresponding to the data schema
127
127
  */
128
- async count() {
129
- const q = this.queryBuilder.countQuery();
128
+ async count(max) {
129
+ const q = this.queryBuilder.countQuery(max);
130
130
  this.log(q);
131
131
  const bindings = await this.engine.queryBindings(q);
132
132
  return parseInt(bindings[0].get("count").value);
@@ -110,9 +110,12 @@ export class QueryBuilder {
110
110
  populateConditionsRecursive(this.schema, mainVar, searchSchema);
111
111
  return conditions;
112
112
  }
113
- countQuery() {
113
+ countQuery(max) {
114
114
  const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes);
115
- return SELECT `(count(?iri) as ?count)`.WHERE `${quads}`.build();
115
+ const innerQuery = max === undefined
116
+ ? quads
117
+ : SELECT `?iri`.WHERE `${quads}`.LIMIT(max);
118
+ return SELECT `(count(?iri) as ?count)`.WHERE `${innerQuery}`.build();
116
119
  }
117
120
  getQuery(where, limit, offset) {
118
121
  const selectSubQuery = SELECT.DISTINCT `
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.0.0",
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)",
@@ -64,12 +64,12 @@
64
64
  }
65
65
  },
66
66
  "dependencies": {
67
- "@comunica/types": "2.6.8",
68
- "@rdfjs/types": "*",
69
- "@types/n3": "*",
70
- "asynciterator": "3.8.0",
71
- "n3": "1.17.2",
72
- "rdf-data-factory": "1.1.1",
73
- "rdf-literal": "1.3.1"
67
+ "@comunica/types": "^4.1.0",
68
+ "@rdfjs/types": "^2.0.0",
69
+ "@types/n3": "^1.21.1",
70
+ "asynciterator": "^3.9.0",
71
+ "n3": "^1.23.1",
72
+ "rdf-data-factory": "^2.0.2",
73
+ "rdf-literal": "^2.0.0"
74
74
  }
75
75
  }
@@ -44,7 +44,7 @@ class QueryEngine {
44
44
  getFetch(context) {
45
45
  return context && context.fetch ? context.fetch : fetch;
46
46
  }
47
- query(query, responseType, context) {
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;
@@ -129,8 +129,8 @@ class Lens {
129
129
  *
130
130
  * @returns total number of entities corresponding to the data schema
131
131
  */
132
- async count() {
133
- const q = this.queryBuilder.countQuery();
132
+ async count(max) {
133
+ const q = this.queryBuilder.countQuery(max);
134
134
  this.log(q);
135
135
  const bindings = await this.engine.queryBindings(q);
136
136
  return parseInt(bindings[0].get("count").value);
@@ -113,9 +113,12 @@ class QueryBuilder {
113
113
  populateConditionsRecursive(this.schema, mainVar, searchSchema);
114
114
  return conditions;
115
115
  }
116
- countQuery() {
116
+ countQuery(max) {
117
117
  const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes);
118
- return (0, mod_js_2.SELECT) `(count(?iri) as ?count)`.WHERE `${quads}`.build();
118
+ const innerQuery = max === undefined
119
+ ? quads
120
+ : (0, mod_js_2.SELECT) `?iri`.WHERE `${quads}`.LIMIT(max);
121
+ return (0, mod_js_2.SELECT) `(count(?iri) as ?count)`.WHERE `${innerQuery}`.build();
119
122
  }
120
123
  getQuery(where, limit, offset) {
121
124
  const selectSubQuery = mod_js_2.SELECT.DISTINCT `
@@ -3,5 +3,5 @@ import { DataFactory, type RDF } from "./rdf.js";
3
3
  import type { ExpandedSchema } from "./schema/mod.js";
4
4
  type DecodedNode = Record<string, unknown>;
5
5
  export declare const encode: (node: DecodedNode, schema: ExpandedSchema, options: Options, includeType?: boolean, variableInitCounter?: number) => RDF.Quad[];
6
- export declare const encodeValue: (value: unknown, datatype: string, df: DataFactory) => any;
6
+ export declare const encodeValue: (value: unknown, datatype: string, df: DataFactory) => RDF.Literal | import("rdf-data-factory").NamedNode<string>;
7
7
  export {};
@@ -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(query: string, responseType: string, context?: QueryContext): Promise<Response>;
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>;
@@ -1,4 +1,4 @@
1
- import type { IDataSource, IQueryContextCommon } from "@comunica/types";
1
+ import type { IQueryContextCommon, QuerySourceUnidentified } from "@comunica/types";
2
2
  import { RDF } from "../rdf.js";
3
3
  /**
4
4
  * A set of context entries that can be passed to a query engine,
@@ -16,7 +16,7 @@ import { RDF } from "../rdf.js";
16
16
  * await engine.queryBoolean("ASK { ?s ?p ?o }", context);
17
17
  * ```
18
18
  */
19
- export type QueryContext = RDF.QueryStringContext & RDF.QuerySourceContext<IDataSource> & IQueryContextCommon;
19
+ export type QueryContext = RDF.QueryStringContext & RDF.QuerySourceContext<QuerySourceUnidentified> & IQueryContextCommon;
20
20
  /**
21
21
  * Interface of a query engine compatible with LDkit
22
22
  */
@@ -92,7 +92,7 @@ export declare class Lens<T extends Schema> {
92
92
  *
93
93
  * @returns total number of entities corresponding to the data schema
94
94
  */
95
- count(): Promise<number>;
95
+ count(max?: number): Promise<number>;
96
96
  /**
97
97
  * Find entities with a custom SPARQL query.
98
98
  *
@@ -10,7 +10,7 @@ export declare class QueryBuilder {
10
10
  private getResourceSignature;
11
11
  private entitiesToQuads;
12
12
  private getShape;
13
- countQuery(): string;
13
+ countQuery(max?: number): string;
14
14
  getQuery(where: string | RDF.Quad[] | undefined, limit: number, offset: number): string;
15
15
  getSearchQuery(where: SearchSchema, limit: number, offset: number): string;
16
16
  getByIrisQuery(iris: IRI[], where?: SearchSchema): string;
@@ -45,8 +45,7 @@ export declare function resolveOptions(options?: Options): {
45
45
  queryFormat?: import("@rdfjs/types").QueryFormat | undefined;
46
46
  baseIRI?: string | undefined;
47
47
  queryTimestamp?: Date | undefined;
48
- sources?: [import("@comunica/types").IDataSource, ...import("@comunica/types").IDataSource[]] | undefined;
49
- source?: string | import("@rdfjs/types").Source<import("@rdfjs/types").Quad> | import("@comunica/types").IDataSourceExpanded | undefined;
48
+ sources?: [import("@comunica/types").QuerySourceUnidentified, ...import("@comunica/types").QuerySourceUnidentified[]] | undefined;
50
49
  destination?: import("@comunica/types").IDataDestination | undefined;
51
50
  initialBindings?: import("@rdfjs/types").Bindings | undefined;
52
51
  log?: import("@comunica/types").Logger | undefined;
@@ -58,8 +57,8 @@ export declare function resolveOptions(options?: Options): {
58
57
  httpTimeout?: number | undefined;
59
58
  httpBodyTimeout?: boolean | undefined;
60
59
  httpRetryCount?: number | undefined;
61
- httpRetryDelay?: number | undefined;
62
- httpRetryOnServerError?: boolean | undefined;
60
+ httpRetryDelayFallback?: number | undefined;
61
+ httpRetryDelayLimit?: number | undefined;
63
62
  fetch?: typeof fetch | undefined;
64
63
  readOnly?: boolean | undefined;
65
64
  extensionFunctionCreator?: ((functionNamedNode: import("@rdfjs/types").NamedNode<string>) => ((args: import("@rdfjs/types").Term[]) => Promise<import("@rdfjs/types").Term>) | undefined) | undefined;
@@ -67,6 +66,5 @@ export declare function resolveOptions(options?: Options): {
67
66
  extensionFunctions?: Record<string, (args: import("@rdfjs/types").Term[]) => Promise<import("@rdfjs/types").Term>> | undefined;
68
67
  explain?: import("@comunica/types").QueryExplainMode | undefined;
69
68
  recoverBrokenLinks?: boolean | undefined;
70
- localizeBlankNodes?: boolean | undefined;
71
69
  };
72
70
  export declare function resolveQueryContext(options: Options): QueryContext;