-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLdpContainer.ts
More file actions
54 lines (51 loc) · 1.42 KB
/
LdpContainer.ts
File metadata and controls
54 lines (51 loc) · 1.42 KB
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
52
53
54
import { sym } from "rdflib";
import { labelFromUri, Thing } from "../thing";
import { Store } from "../Store";
import { debounceTime, filter, map, merge, Observable, startWith } from "rxjs";
export interface ContainerContent {
uri: string;
name: string;
}
export class LdpContainer extends Thing {
constructor(
readonly uri: string,
readonly store: Store,
readonly editable: boolean = false,
) {
super(uri, store, editable);
}
/**
* Resources that the LDP Container contains
*
* @returns Array of objects with uri and name
*/
contains(): ContainerContent[] {
const contains = this.store.statementsMatching(
sym(this.uri),
sym("http://www.w3.org/ns/ldp#contains"),
null,
sym(this.uri),
);
return contains.map((content) => ({
uri: content.object.value,
name: labelFromUri(content.object.value),
}));
}
/**
* Observe changes to the resources that the LDP Container contains
*
* @returns RxJS Observable that pushes a new contains() array when it changes
*/
observeContains(): Observable<ContainerContent[]> {
return merge(this.store.additions$, this.store.removals$).pipe(
filter(
(quad) =>
quad.graph.value == this.uri &&
quad.predicate.value == "http://www.w3.org/ns/ldp#contains",
),
debounceTime(250),
map(() => this.contains()),
startWith(this.contains()),
);
}
}