-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathParsingQuery.js
40 lines (36 loc) · 1.36 KB
/
ParsingQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import chunks from 'stream-chunks/chunks.js'
import StreamQuery from './StreamQuery.js'
/**
* A query implementation that wraps the results of the {@link StreamQuery} into RDF/JS DatasetCore objects
* (CONSTRUCT/DESCRIBE) or an array of objects (SELECT).
*
* @extends StreamQuery
*/
class ParsingQuery extends StreamQuery {
/**
* Sends a request for a CONSTRUCT or DESCRIBE query
*
* @param {string} query CONSTRUCT or DESCRIBE query
* @param {Object} options
* @param {Headers} [options.headers] additional request headers
* @param {'get'|'postUrlencoded'|'postDirect'} [options.operation='get'] SPARQL Protocol operation
* @return {Promise<DatasetCore>}
*/
async construct (query, { headers, operation } = {}) {
const quads = await chunks(await super.construct(query, { headers, operation }))
return this.client.factory.dataset(quads)
}
/**
* Sends a request for a SELECT query
*
* @param {string} query SELECT query
* @param {Object} [options]
* @param {Headers} [options.headers] additional request headers
* @param {'get'|'postUrlencoded'|'postDirect'} [options.operation='get'] SPARQL Protocol operation
* @return {Promise<Array<Object.<string, Term>>>}
*/
async select (query, { headers, operation } = {}) {
return chunks(await super.select(query, { headers, operation }))
}
}
export default ParsingQuery