@@ -9,63 +9,44 @@ import { createProfileLogic } from "../profile/profileLogic";
99import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic" ;
1010import { createContainerLogic } from "../util/containerLogic" ;
1111import { createUtilityLogic } from "../util/utilityLogic" ;
12- import { AuthnLogic } from "../types" ;
12+ import { AuthnLogic , SolidLogic } from "../types" ;
1313import * as debug from "../util/debug" ;
1414/*
1515** It is important to distinquish `fetch`, a function provided by the browser
1616** and `Fetcher`, a helper object for the rdflib Store which turns it
1717** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
1818** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
1919*/
20- export class SolidLogic {
20+ export function createSolidLogic ( specialFetch : { fetch : ( url : any , requestInit : any ) => any } , session : Session ) : SolidLogic {
2121
22- store : LiveStore ;
23- me : string | undefined ;
24- authn : AuthnLogic ;
22+ debug . log ( "SolidLogic: Unique instance created. There should only be one of these." )
23+ const store : LiveStore = rdf . graph ( ) as LiveStore
24+ rdf . fetcher ( store , { fetch : specialFetch . fetch } ) ; // Attach a web I/O module, store.fetcher
25+ store . updater = new rdf . UpdateManager ( store ) ; // Add real-time live updates store.updater
26+ store . features = [ ] // disable automatic node merging on store load
2527
26- readonly acl
27- readonly profile
28- readonly inbox
29- readonly typeIndex
30- readonly chat
31- private readonly containerLogic
32- private readonly utilityLogic
28+ const authn : AuthnLogic = new SolidAuthnLogic ( session )
29+
30+ const acl = createAclLogic ( store )
31+ const containerLogic = createContainerLogic ( store )
32+ const utilityLogic = createUtilityLogic ( store , acl , containerLogic )
33+ const profile = createProfileLogic ( store , authn , utilityLogic )
34+ const chat = createChatLogic ( store , profile )
35+ const inbox = createInboxLogic ( store , profile , utilityLogic , containerLogic , acl )
36+ const typeIndex = createTypeIndexLogic ( store , authn , profile , utilityLogic )
37+ debug . log ( 'SolidAuthnLogic initialized' )
3338
34-
35- constructor ( specialFetch : { fetch : ( url : any , requestInit : any ) => any } , session : Session ) {
36- // would xpect to be able to do it this way: but get TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation status: 999
37- // this.store = new rdf.LiveStore({})
38- // this.store.fetcher._fetch = fetch
39- debug . log ( "SolidLogic: Unique instance created. There should only be one of these." )
40- this . store = rdf . graph ( ) as LiveStore ; // Make a Quad store
41- rdf . fetcher ( this . store , { fetch : specialFetch . fetch } ) ; // Attach a web I/O module, store.fetcher
42- this . store . updater = new rdf . UpdateManager ( this . store ) ; // Add real-time live updates store.updater
43- this . store . features = [ ] // disable automatic node merging on store load
44-
45- this . authn = new SolidAuthnLogic ( session )
46-
47- debug . log ( 'SolidAuthnLogic initialized' )
48-
49- this . acl = createAclLogic ( this . store )
50- this . containerLogic = createContainerLogic ( this . store )
51- this . utilityLogic = createUtilityLogic ( this . store , this . acl , this . containerLogic )
52- this . profile = createProfileLogic ( this . store , this . authn , this . utilityLogic )
53- this . chat = createChatLogic ( this . store , this . profile )
54- this . inbox = createInboxLogic ( this . store , this . profile , this . utilityLogic , this . containerLogic , this . acl )
55- this . typeIndex = createTypeIndexLogic ( this . store , this . authn , this . profile , this . utilityLogic )
56- }
57-
58- load ( doc : NamedNode | NamedNode [ ] | string ) {
59- return this . store . fetcher . load ( doc ) ;
39+ function load ( doc : NamedNode | NamedNode [ ] | string ) {
40+ return store . fetcher . load ( doc ) ;
6041 }
6142
6243 // @@@@ use the one in rdflib.js when it is available and delete this
63- updatePromise (
44+ function updatePromise (
6445 del : Array < Statement > ,
6546 ins : Array < Statement > = [ ]
6647 ) : Promise < void > {
6748 return new Promise ( ( resolve , reject ) => {
68- this . store . updater . update ( del , ins , function ( _uri , ok , errorBody ) {
49+ store . updater . update ( del , ins , function ( _uri , ok , errorBody ) {
6950 if ( ! ok ) {
7051 reject ( new Error ( errorBody ) ) ;
7152 } else {
@@ -75,7 +56,20 @@ export class SolidLogic {
7556 } ) ; // promise
7657 }
7758
78- clearStore ( ) {
79- this . store . statements . slice ( ) . forEach ( this . store . remove . bind ( this . store ) ) ;
59+ function clearStore ( ) {
60+ store . statements . slice ( ) . forEach ( store . remove . bind ( store ) ) ;
61+ }
62+
63+ return {
64+ store,
65+ authn,
66+ acl,
67+ inbox,
68+ chat,
69+ profile,
70+ typeIndex,
71+ load,
72+ updatePromise,
73+ clearStore
8074 }
8175}
0 commit comments