-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
81 lines (73 loc) · 2.63 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html><html><head><meta charset="UTF-8" />
<script src="./dist/solid-rest-browser.js"></script>
<script src="../solid-auth-client/dist-lib/solid-auth-client.bundle.js">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js">
</script>
</head><body>
<p><b>Testing Local Storage via rdflib.js</b></p><div id="results"></div>
<script>
let store = $rdf.graph()
// let fetcher = $rdf.fetcher(store,{fetch:appfetch})
let fetcher = $rdf.fetcher(store)
let docRoot = "app://ls"
let foldername = "/test-folder/";
let filename = "test-file.ttl";
let folder = docRoot + foldername;
let file = folder + filename;
let DOC = $rdf.Namespace(file);
const LDP = $rdf.Namespace("http://www.w3.org/ns/ldp#");
async function run(){
let results;
/* CREATE A CONTAINER
*/
results = await fetcher.createContainer( docRoot+"/",foldername )
if(results.status===201)
show(`Created Local Storage Container <${docRoot+foldername}>`);
/* CREATE A RESOURCE
*/
store.add( DOC("#test"), DOC("#message"), "hello world", DOC("") );
results = await fetcher.putBack( DOC("") );
if(results.status===201)
show(`Created Local Storage Resource <${DOC("").uri}>`);
/* LOAD AND QUERY A CONTAINER
*/
store.removeMatches();
await fetcher.load( folder );
let files = store.each( $rdf.sym(folder), LDP("contains"));
if(files.length!=1 && !files[0].value.match(file)) {
console.log("Bad query of Container");
console.log(files);
}
else
show(`Loaded & queried Local Storage Container : ${files.length} file`);
/* LOAD AND QUERY A RESOURCE
*/
store.removeMatches();
await fetcher.load( DOC("") );
results = store.any( DOC("#test"), DOC("#message"), null );
if(results)
show(`Loaded & queried Local Storage Resource : ${results.value}`);
/* DELETE A RESOURCE & CONTAINER
*/
await fetcher.delete( DOC("") );
await fetcher.delete( folder );
store.removeMatches();
await fetcher.load( docRoot + "/");
files = store.each( $rdf.sym(folder), LDP("contains")) || [];
if(files.length!=0) {
console.log("Expected Container to be empty, it wasn't!");
console.log(files);
}
else
show(`Deleted Local Storage Resource & Container`);
show(`Local Storage for this app is now empty`);
show("---\nAll done, thanks!");
}
run();
function show(msg){
let par = document.createElement('p')
par.appendChild(document.createTextNode(msg));
document.getElementById("results").appendChild(par);
}
</script></body></html>