-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget.js
33 lines (29 loc) · 906 Bytes
/
get.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
import Client from 'sparql-http-client'
/**
* @this {import('barnard59-core').Context}
* @param {Pick<import('sparql-http-client/StreamClient.js').Options<any>, 'user' | 'password'> & {
* endpoint: string,
* graph: string | import('@rdfjs/types').NamedNode | import('@rdfjs/types').DefaultGraph,
* }} options
*/
function get({ endpoint, graph, user, password }) {
const client = new Client({
factory: this.env,
storeUrl: endpoint,
user,
password,
})
/** @type {import('@rdfjs/types').Quad_Graph} */
let graphTerm
if (!graph) {
graphTerm = this.env.defaultGraph()
} else if (typeof graph === 'string') {
graphTerm = this.env.namedNode(graph)
} else if (this.env.defaultGraph().equals(graph)) {
graphTerm = this.env.defaultGraph()
} else {
graphTerm = this.env.namedNode(graph.value)
}
return client.store.get(graphTerm)
}
export default get