-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathput.js
30 lines (26 loc) · 856 Bytes
/
put.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
import Client from 'sparql-http-client'
import SinkToWritable from './lib/SinkToWritable.js'
import { toTerm } from './lib/graph.js'
/**
* @this {import('barnard59-core').Context}
* @param {Pick<import('sparql-http-client/StreamClient.js').Options<any>, 'user' | 'password'> & {
* endpoint: string,
* graph: string | import('clownface').GraphPointer<import('@rdfjs/types').NamedNode> | import('@rdfjs/types').NamedNode,
* }} options
* @returns {import('readable-stream').Writable}
*/
function put({ endpoint, graph, user, password }) {
if (!graph) {
throw new Error('graph is required')
}
const client = new Client({
factory: this.env,
storeUrl: endpoint,
user,
password,
})
return new SinkToWritable(readable => client.store.put(readable, {
graph: toTerm(this.env, graph),
}), this)
}
export default put