-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (39 loc) · 1.23 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
import rdf from 'rdf-ext'
import promiseToEvent from 'rdf-utils-stream/promiseToEvent.js'
class Store {
constructor ({ dataset, factory = rdf } = {}) {
this.factory = factory
this.dataset = this.factory.dataset(dataset)
}
async _import (stream, { truncate } = {}) {
const other = await rdf.dataset().import(stream)
if (truncate) {
this.dataset = other
} else {
this.dataset.addAll(other)
}
}
async _remove (stream) {
const other = await rdf.dataset().import(stream)
this.dataset = this.dataset.difference(other)
}
async _removeMatches (subject, predicate, object, graph) {
this.dataset.deleteMatches(subject, predicate, object, graph)
}
deleteGraph (graph) {
return this.removeMatches(null, null, null, graph)
}
import (stream, { truncate } = {}) {
return promiseToEvent(this._import(stream, { truncate }))
}
match (subject, predicate, object, graph) {
return this.dataset.match(subject, predicate, object, graph).toStream()
}
remove (stream) {
return promiseToEvent(this._remove(stream))
}
removeMatches (subject, predicate, object, graph) {
return promiseToEvent(this._removeMatches(subject, predicate, object, graph))
}
}
export default Store