forked from SolidOS/solid-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolidLogic.js
More file actions
64 lines (64 loc) · 2.63 KB
/
solidLogic.js
File metadata and controls
64 lines (64 loc) · 2.63 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
55
56
57
58
59
60
61
62
63
64
import * as rdf from 'rdflib';
import { createAclLogic } from '../acl/aclLogic';
import { SolidAuthnLogic } from '../authn/SolidAuthnLogic';
import { createChatLogic } from '../chat/chatLogic';
import { createInboxLogic } from '../inbox/inboxLogic';
import { createProfileLogic } from '../profile/profileLogic';
import { createTypeIndexLogic } from '../typeIndex/typeIndexLogic';
import { createContainerLogic } from '../util/containerLogic';
import { createUtilityLogic } from '../util/utilityLogic';
import * as debug from '../util/debug';
/*
** It is important to distinquish `fetch`, a function provided by the browser
** and `Fetcher`, a helper object for the rdflib Store which turns it
** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
*/
export function createSolidLogic(specialFetch, session) {
debug.log('SolidLogic: Unique instance created. There should only be one of these.');
const store = rdf.graph();
rdf.fetcher(store, { fetch: specialFetch.fetch }); // Attach a web I/O module, store.fetcher
store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
store.features = []; // disable automatic node merging on store load
const authn = new SolidAuthnLogic(session);
const acl = createAclLogic(store);
const containerLogic = createContainerLogic(store);
const utilityLogic = createUtilityLogic(store, acl, containerLogic);
const profile = createProfileLogic(store, authn, utilityLogic);
const chat = createChatLogic(store, profile);
const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl);
const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic);
debug.log('SolidAuthnLogic initialized');
function load(doc) {
return store.fetcher.load(doc);
}
// @@@@ use the one in rdflib.js when it is available and delete this
function updatePromise(del, ins = []) {
return new Promise((resolve, reject) => {
store.updater.update(del, ins, function (_uri, ok, errorBody) {
if (!ok) {
reject(new Error(errorBody));
}
else {
resolve();
}
}); // callback
}); // promise
}
function clearStore() {
store.statements.slice().forEach(store.remove.bind(store));
}
return {
store,
authn,
acl,
inbox,
chat,
profile,
typeIndex,
load,
updatePromise,
clearStore
};
}
//# sourceMappingURL=solidLogic.js.map