ldkit 2.4.0 → 2.5.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 +25 -0
- package/esm/library/lens/lens.d.ts +16 -1
- package/esm/library/lens/lens.d.ts.map +1 -1
- package/esm/library/lens/lens.js +18 -2
- package/esm/library/lens/query_builder.d.ts +1 -1
- package/esm/library/lens/query_builder.d.ts.map +1 -1
- package/esm/library/lens/query_builder.js +4 -3
- package/package.json +10 -10
- package/script/library/lens/lens.d.ts +16 -1
- package/script/library/lens/lens.d.ts.map +1 -1
- package/script/library/lens/lens.js +18 -2
- package/script/library/lens/query_builder.d.ts +1 -1
- package/script/library/lens/query_builder.d.ts.map +1 -1
- package/script/library/lens/query_builder.js +4 -3
package/README.md
CHANGED
|
@@ -110,6 +110,12 @@ 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
|
+
## Minimum software requirements
|
|
114
|
+
|
|
115
|
+
- TypeScript v5.5 or newer
|
|
116
|
+
- Node.js v20.19.3 or newer
|
|
117
|
+
- Deno v2.1 or newer
|
|
118
|
+
|
|
113
119
|
## Specification Compliance
|
|
114
120
|
|
|
115
121
|
LDkit complies with the following specifications:
|
|
@@ -120,6 +126,25 @@ LDkit complies with the following specifications:
|
|
|
120
126
|
- [SPARQL 1.1 Update](https://www.w3.org/TR/2013/REC-sparql11-update-20130321/)
|
|
121
127
|
- [SPARQL 1.1 Protocol](https://www.w3.org/TR/2013/REC-sparql11-protocol-20130321/)
|
|
122
128
|
|
|
129
|
+
## Citation
|
|
130
|
+
|
|
131
|
+
If you are using LDkit in a scientific publication, we would appreciate a
|
|
132
|
+
citation of our work.
|
|
133
|
+
|
|
134
|
+
```bibtex
|
|
135
|
+
@inproceedings{klima2023ldkit,
|
|
136
|
+
title = {LDkit: Linked Data Object Graph Mapping Toolkit for Web Applications},
|
|
137
|
+
author = {Kl{\'\i}ma, Karel and Taelman, Ruben and Ne{\v{c}}ask{\`y}, Martin},
|
|
138
|
+
booktitle = {International Semantic Web Conference},
|
|
139
|
+
pages = {194--210},
|
|
140
|
+
year = {2023},
|
|
141
|
+
month = oct,
|
|
142
|
+
publisher = {Springer Nature Switzerland},
|
|
143
|
+
isbn = {978-3-031-47243-5},
|
|
144
|
+
url = {https://doi.org/10.1007/978-3-031-47243-5_11}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
123
148
|
## License
|
|
124
149
|
|
|
125
150
|
[MIT License](./LICENSE.md)
|
|
@@ -71,6 +71,7 @@ export declare class Lens<T extends Schema> {
|
|
|
71
71
|
private log;
|
|
72
72
|
/**
|
|
73
73
|
* Returns the total number of entities corresponding to the data schema.
|
|
74
|
+
* Optionally, you can specify search criteria and a maximum number of results to count.
|
|
74
75
|
*
|
|
75
76
|
* @example
|
|
76
77
|
* ```typescript
|
|
@@ -88,11 +89,25 @@ export declare class Lens<T extends Schema> {
|
|
|
88
89
|
*
|
|
89
90
|
* // Count all persons
|
|
90
91
|
* const count = await Persons.count(); // number
|
|
92
|
+
*
|
|
93
|
+
* // Count all persons with name that starts with "Ada"
|
|
94
|
+
* const adaCount = await Persons.count({
|
|
95
|
+
* where: {
|
|
96
|
+
* name: { $strStarts: "Ada" },
|
|
97
|
+
* },
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Count all persons, but limit the result to 100
|
|
101
|
+
* const limitedCount = await Persons.count({ max: 100 });
|
|
91
102
|
* ```
|
|
92
103
|
*
|
|
104
|
+
* @param options Search criteria and maximum number of results to count
|
|
93
105
|
* @returns total number of entities corresponding to the data schema
|
|
94
106
|
*/
|
|
95
|
-
count(
|
|
107
|
+
count(options?: {
|
|
108
|
+
where?: SchemaSearchInterface<T>;
|
|
109
|
+
max?: number;
|
|
110
|
+
}): Promise<number>;
|
|
96
111
|
/**
|
|
97
112
|
* Find entities with a custom SPARQL query.
|
|
98
113
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lens.d.ts","sourceRoot":"","sources":["../../../src/library/lens/lens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,GAAG,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EACL,KAAK,OAAO,EAGb,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,OAAO,GAChB,IAAI,CAAC,CAAC,CAAC,CAET;AAED;;;;GAIG;AACH,qBAAa,IAAI,CAAC,CAAC,SAAS,MAAM;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO;IAQxC,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,GAAG;IAIX
|
|
1
|
+
{"version":3,"file":"lens.d.ts","sourceRoot":"","sources":["../../../src/library/lens/lens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,GAAG,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EACL,KAAK,OAAO,EAGb,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,QAAQ,EACb,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;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,UAAU,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAIhD"}
|
package/esm/library/lens/lens.js
CHANGED
|
@@ -104,6 +104,7 @@ export class Lens {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Returns the total number of entities corresponding to the data schema.
|
|
107
|
+
* Optionally, you can specify search criteria and a maximum number of results to count.
|
|
107
108
|
*
|
|
108
109
|
* @example
|
|
109
110
|
* ```typescript
|
|
@@ -121,12 +122,27 @@ export class Lens {
|
|
|
121
122
|
*
|
|
122
123
|
* // Count all persons
|
|
123
124
|
* const count = await Persons.count(); // number
|
|
125
|
+
*
|
|
126
|
+
* // Count all persons with name that starts with "Ada"
|
|
127
|
+
* const adaCount = await Persons.count({
|
|
128
|
+
* where: {
|
|
129
|
+
* name: { $strStarts: "Ada" },
|
|
130
|
+
* },
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* // Count all persons, but limit the result to 100
|
|
134
|
+
* const limitedCount = await Persons.count({ max: 100 });
|
|
124
135
|
* ```
|
|
125
136
|
*
|
|
137
|
+
* @param options Search criteria and maximum number of results to count
|
|
126
138
|
* @returns total number of entities corresponding to the data schema
|
|
127
139
|
*/
|
|
128
|
-
async count(
|
|
129
|
-
const
|
|
140
|
+
async count(options = {}) {
|
|
141
|
+
const { where, max } = {
|
|
142
|
+
where: {},
|
|
143
|
+
...options,
|
|
144
|
+
};
|
|
145
|
+
const q = this.queryBuilder.countQuery(where, max);
|
|
130
146
|
this.log(q);
|
|
131
147
|
const bindings = await this.engine.queryBindings(q);
|
|
132
148
|
return parseInt(bindings[0].get("count").value);
|
|
@@ -10,7 +10,7 @@ export declare class QueryBuilder {
|
|
|
10
10
|
private getResourceSignature;
|
|
11
11
|
private entitiesToQuads;
|
|
12
12
|
private getShape;
|
|
13
|
-
countQuery(max?: number): string;
|
|
13
|
+
countQuery(where: SearchSchema, 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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query_builder.d.ts","sourceRoot":"","sources":["../../../src/library/lens/query_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAe,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAM5D,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAYzC,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;gBAEzB,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO;IAMpD,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,QAAQ;IA4FhB,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"query_builder.d.ts","sourceRoot":"","sources":["../../../src/library/lens/query_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAe,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAM5D,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAYzC,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;gBAEzB,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO;IAMpD,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,QAAQ;IA4FhB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,MAAM;IAY5C,QAAQ,CACN,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,GAAG,SAAS,EACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;IAsBhB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAyBjE,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,YAAY;IAchD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;IAK9B,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE;IAIjC,WAAW,SAAU,GAAG,EAAE,YAOxB;IAEF,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE;IAIjC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;CAU/B"}
|
|
@@ -110,12 +110,13 @@ export class QueryBuilder {
|
|
|
110
110
|
populateConditionsRecursive(this.schema, mainVar, searchSchema);
|
|
111
111
|
return conditions;
|
|
112
112
|
}
|
|
113
|
-
countQuery(max) {
|
|
114
|
-
const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes);
|
|
113
|
+
countQuery(where, max) {
|
|
114
|
+
const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes, where);
|
|
115
115
|
const innerQuery = max === undefined
|
|
116
116
|
? quads
|
|
117
117
|
: SELECT `?iri`.WHERE `${quads}`.LIMIT(max);
|
|
118
|
-
return SELECT `(
|
|
118
|
+
return SELECT `(COUNT(DISTINCT ?iri) as ?count)`.WHERE `${innerQuery}`
|
|
119
|
+
.build();
|
|
119
120
|
}
|
|
120
121
|
getQuery(where, limit, offset) {
|
|
121
122
|
const selectSubQuery = SELECT.DISTINCT `
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "LDkit, a Linked Data query toolkit for TypeScript developers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linked data",
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
"ldkit": "./esm/cli.js"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@comunica/types": "^4
|
|
47
|
-
"@rdfjs/types": "^2
|
|
46
|
+
"@comunica/types": "^4",
|
|
47
|
+
"@rdfjs/types": "^2",
|
|
48
48
|
"@shexjs/parser": "1.0.0-alpha.28",
|
|
49
|
-
"@types/n3": "^1
|
|
50
|
-
"asynciterator": "^3
|
|
49
|
+
"@types/n3": "^1",
|
|
50
|
+
"asynciterator": "^3",
|
|
51
51
|
"commander": "^13.1.0",
|
|
52
52
|
"jsonld-context-parser": "^3",
|
|
53
|
-
"n3": "^1
|
|
54
|
-
"rdf-data-factory": "^2
|
|
55
|
-
"rdf-literal": "^2
|
|
56
|
-
"rdf-string": "^2
|
|
57
|
-
"readable-from-web": "^
|
|
53
|
+
"n3": "^1",
|
|
54
|
+
"rdf-data-factory": "^2",
|
|
55
|
+
"rdf-literal": "^2",
|
|
56
|
+
"rdf-string": "^2",
|
|
57
|
+
"readable-from-web": "^1"
|
|
58
58
|
},
|
|
59
59
|
"_generatedBy": "dnt@dev"
|
|
60
60
|
}
|
|
@@ -71,6 +71,7 @@ export declare class Lens<T extends Schema> {
|
|
|
71
71
|
private log;
|
|
72
72
|
/**
|
|
73
73
|
* Returns the total number of entities corresponding to the data schema.
|
|
74
|
+
* Optionally, you can specify search criteria and a maximum number of results to count.
|
|
74
75
|
*
|
|
75
76
|
* @example
|
|
76
77
|
* ```typescript
|
|
@@ -88,11 +89,25 @@ export declare class Lens<T extends Schema> {
|
|
|
88
89
|
*
|
|
89
90
|
* // Count all persons
|
|
90
91
|
* const count = await Persons.count(); // number
|
|
92
|
+
*
|
|
93
|
+
* // Count all persons with name that starts with "Ada"
|
|
94
|
+
* const adaCount = await Persons.count({
|
|
95
|
+
* where: {
|
|
96
|
+
* name: { $strStarts: "Ada" },
|
|
97
|
+
* },
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Count all persons, but limit the result to 100
|
|
101
|
+
* const limitedCount = await Persons.count({ max: 100 });
|
|
91
102
|
* ```
|
|
92
103
|
*
|
|
104
|
+
* @param options Search criteria and maximum number of results to count
|
|
93
105
|
* @returns total number of entities corresponding to the data schema
|
|
94
106
|
*/
|
|
95
|
-
count(
|
|
107
|
+
count(options?: {
|
|
108
|
+
where?: SchemaSearchInterface<T>;
|
|
109
|
+
max?: number;
|
|
110
|
+
}): Promise<number>;
|
|
96
111
|
/**
|
|
97
112
|
* Find entities with a custom SPARQL query.
|
|
98
113
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lens.d.ts","sourceRoot":"","sources":["../../../src/library/lens/lens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,GAAG,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EACL,KAAK,OAAO,EAGb,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGhD;;;;;;;;;;;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;;;;;;;;;;;;;;OA4BG;IACG,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAOnE,OAAO,CAAC,WAAW;IAKnB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,UAAU,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,GAAG,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,MAAM,CAAC,GAAG,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,UAAU,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAIhD"}
|
|
@@ -108,6 +108,7 @@ class Lens {
|
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Returns the total number of entities corresponding to the data schema.
|
|
111
|
+
* Optionally, you can specify search criteria and a maximum number of results to count.
|
|
111
112
|
*
|
|
112
113
|
* @example
|
|
113
114
|
* ```typescript
|
|
@@ -125,12 +126,27 @@ class Lens {
|
|
|
125
126
|
*
|
|
126
127
|
* // Count all persons
|
|
127
128
|
* const count = await Persons.count(); // number
|
|
129
|
+
*
|
|
130
|
+
* // Count all persons with name that starts with "Ada"
|
|
131
|
+
* const adaCount = await Persons.count({
|
|
132
|
+
* where: {
|
|
133
|
+
* name: { $strStarts: "Ada" },
|
|
134
|
+
* },
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Count all persons, but limit the result to 100
|
|
138
|
+
* const limitedCount = await Persons.count({ max: 100 });
|
|
128
139
|
* ```
|
|
129
140
|
*
|
|
141
|
+
* @param options Search criteria and maximum number of results to count
|
|
130
142
|
* @returns total number of entities corresponding to the data schema
|
|
131
143
|
*/
|
|
132
|
-
async count(
|
|
133
|
-
const
|
|
144
|
+
async count(options = {}) {
|
|
145
|
+
const { where, max } = {
|
|
146
|
+
where: {},
|
|
147
|
+
...options,
|
|
148
|
+
};
|
|
149
|
+
const q = this.queryBuilder.countQuery(where, max);
|
|
134
150
|
this.log(q);
|
|
135
151
|
const bindings = await this.engine.queryBindings(q);
|
|
136
152
|
return parseInt(bindings[0].get("count").value);
|
|
@@ -10,7 +10,7 @@ export declare class QueryBuilder {
|
|
|
10
10
|
private getResourceSignature;
|
|
11
11
|
private entitiesToQuads;
|
|
12
12
|
private getShape;
|
|
13
|
-
countQuery(max?: number): string;
|
|
13
|
+
countQuery(where: SearchSchema, 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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query_builder.d.ts","sourceRoot":"","sources":["../../../src/library/lens/query_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAe,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAA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C,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAyBjE,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,YAAY;IAchD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;IAK9B,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE;IAIjC,WAAW,SAAU,GAAG,EAAE,YAOxB;IAEF,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE;IAIjC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;CAU/B"}
|
|
@@ -113,12 +113,13 @@ class QueryBuilder {
|
|
|
113
113
|
populateConditionsRecursive(this.schema, mainVar, searchSchema);
|
|
114
114
|
return conditions;
|
|
115
115
|
}
|
|
116
|
-
countQuery(max) {
|
|
117
|
-
const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes);
|
|
116
|
+
countQuery(where, max) {
|
|
117
|
+
const quads = this.getShape(Flags.ExcludeOptional | Flags.IncludeTypes, where);
|
|
118
118
|
const innerQuery = max === undefined
|
|
119
119
|
? quads
|
|
120
120
|
: (0, mod_js_2.SELECT) `?iri`.WHERE `${quads}`.LIMIT(max);
|
|
121
|
-
return (0, mod_js_2.SELECT) `(
|
|
121
|
+
return (0, mod_js_2.SELECT) `(COUNT(DISTINCT ?iri) as ?count)`.WHERE `${innerQuery}`
|
|
122
|
+
.build();
|
|
122
123
|
}
|
|
123
124
|
getQuery(where, limit, offset) {
|
|
124
125
|
const selectSubQuery = mod_js_2.SELECT.DISTINCT `
|