@@ -34,9 +34,9 @@ export class SolidLogic {
3434 this . fetcher = fetcher
3535 }
3636
37- async findAclDocUrl ( url : string | NamedNode ) {
37+ async findAclDocUrl ( url : string ) {
3838 const doc = this . store . sym ( url )
39- await this . store . fetcher . load ( doc )
39+ await this . load ( doc )
4040 const docNode = this . store . any ( doc , ACL_LINK )
4141 if ( ! docNode ) {
4242 throw new Error ( `No ACL link discovered for ${ url } ` )
@@ -49,15 +49,18 @@ export class SolidLogic {
4949 // withCredentials: Web arch should let us just load by turning off creds helps CORS
5050 // reload: Gets around a specific old Chrome bug caching/origin/cors
5151 // console.log('loading', profileDocument)
52+ if ( ! this . store . fetcher ) {
53+ throw new Error ( 'Cannot load doc, have no fetcher' )
54+ }
5255 await this . store . fetcher
5356 . load ( profileDocument , { withCredentials : false , cache : 'reload' } )
5457 // console.log('loaded', profileDocument, this.store)
5558 }
5659
5760 async loadProfile ( me : NamedNode ) : Promise < NamedNode > {
5861 // console.log('loadProfile', me)
59- if ( this . cache . profileDocument [ me ] ) {
60- return this . cache . profileDocument [ me ]
62+ if ( this . cache . profileDocument [ me . value ] ) {
63+ return this . cache . profileDocument [ me . value ]
6164 }
6265 let profileDocument
6366 try {
@@ -72,8 +75,8 @@ export class SolidLogic {
7275
7376 async loadPreferences ( me : NamedNode ) : Promise < NamedNode > {
7477 // console.log('loadPreferences', me)
75- if ( this . cache . preferencesFile [ me ] ) {
76- return this . cache . preferencesFile [ me ]
78+ if ( this . cache . preferencesFile [ me . value ] ) {
79+ return this . cache . preferencesFile [ me . value ]
7780 }
7881 const preferencesFile = this . store . any ( me , ns . space ( 'preferencesFile' ) )
7982 // console.log('this.store.any()', this.store.any())
@@ -82,17 +85,23 @@ export class SolidLogic {
8285 * Returns True if we are in a webapp at an origin, and the file origin is different
8386 */
8487 function differentOrigin ( ) : boolean {
85- return `${ window . location . origin } /` !== preferencesFile . site ( ) . uri
88+ if ( ! preferencesFile ) {
89+ return true
90+ }
91+ return `${ window . location . origin } /` !== new URL ( preferencesFile . value ) . origin
8692 }
8793
8894 if ( ! preferencesFile ) {
8995 throw new Error ( `Can't find a preference file pointer in profile ${ me . doc ( ) } ` )
9096 }
9197
98+ if ( ! this . store . fetcher ) {
99+ throw new Error ( 'Cannot load doc, have no fetcher' )
100+ }
92101 // //// Load preference file
93102 try {
94103 await this . store . fetcher
95- . load ( preferencesFile , { withCredentials : true } )
104+ . load ( preferencesFile as NamedNode , { withCredentials : true } )
96105 } catch ( err ) {
97106 // Really important to look at why
98107 const status = err . status
@@ -109,21 +118,21 @@ export class SolidLogic {
109118 throw new SameOriginForbiddenError ( )
110119 }
111120 if ( status === 404 ) {
112- throw new NotFoundError ( preferencesFile )
121+ throw new NotFoundError ( preferencesFile . value )
113122 }
114123 throw new FetchError ( err . status , err . message )
115124 }
116- return preferencesFile
125+ return preferencesFile as NamedNode
117126 }
118127
119128 getTypeIndex ( me : NamedNode | string , preferencesFile : NamedNode | string , isPublic : boolean ) : NamedNode [ ] {
120129 // console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
121130 return this . store . each (
122- me ,
131+ me as NamedNode ,
123132 ( isPublic ? ns . solid ( 'publicTypeIndex' ) : ns . solid ( 'privateTypeIndex' ) ) ,
124133 undefined ,
125- preferencesFile
126- )
134+ preferencesFile as NamedNode
135+ ) as NamedNode [ ]
127136 }
128137
129138 getContainerElements ( cont : NamedNode ) {
@@ -138,7 +147,10 @@ export class SolidLogic {
138147 } )
139148 }
140149
141- load ( doc : NamedNode | string ) {
150+ load ( doc : NamedNode | NamedNode [ ] | string ) {
151+ if ( ! this . store . fetcher ) {
152+ throw new Error ( 'Cannot load doc(s), have no fetcher' )
153+ }
142154 return this . store . fetcher . load ( doc )
143155 }
144156
@@ -156,7 +168,7 @@ export class SolidLogic {
156168 if ( publicProfile ) {
157169 publicIndexes = this . getTypeIndex ( me , publicProfile , true )
158170 try {
159- await this . load ( publicIndexes )
171+ await this . load ( publicIndexes as NamedNode [ ] )
160172 } catch ( err ) {
161173 onWarning ( new Error ( `loadIndex: loading public type index(es) ${ err } ` ) )
162174 }
@@ -186,6 +198,9 @@ export class SolidLogic {
186198 }
187199
188200 async createEmptyRdfDoc ( doc : NamedNode , comment : string ) {
201+ if ( ! this . store . fetcher ) {
202+ throw new Error ( 'Cannot create empty rdf doc, have no fetcher' )
203+ }
189204 await this . store . fetcher . webOperation ( 'PUT' , doc . uri , {
190205 data : `# ${ new Date ( ) } ${ comment }
191206` ,
@@ -199,6 +214,9 @@ export class SolidLogic {
199214 ins : Array < Statement > = [ ]
200215 ) : Promise < void > {
201216 return new Promise ( ( resolve , reject ) => {
217+ if ( ! this . store . updater ) {
218+ throw new Error ( 'Cannot updatePromise, have no updater' )
219+ }
202220 this . store . updater . update ( del , ins , function ( _uri , ok , errorBody ) {
203221 if ( ! ok ) {
204222 reject ( new Error ( errorBody ) )
@@ -214,19 +232,19 @@ export class SolidLogic {
214232 }
215233
216234 async getContainerMembers ( containerUrl ) {
217- await this . store . fetcher . load ( this . store . sym ( containerUrl ) ) ;
235+ await this . load ( this . store . sym ( containerUrl ) ) ;
218236 return this . store . statementsMatching ( this . store . sym ( containerUrl ) , this . store . sym ( 'http://www.w3.org/ns/ldp#contains' ) ) . map ( ( st : Statement ) => st . object . value ) ;
219237 }
220238
221239 async recursiveDelete ( url : string ) {
222240 try {
223241 if ( this . isContainer ( url ) ) {
224242 const aclDocUrl = await this . findAclDocUrl ( url ) ;
225- await this . store . fetcher . fetch ( aclDocUrl , { method : 'DELETE' } ) ;
243+ await this . fetcher . fetch ( aclDocUrl , { method : 'DELETE' } ) ;
226244 const containerMembers = await this . getContainerMembers ( url ) ;
227245 await Promise . all ( containerMembers . map ( url => this . recursiveDelete ( url ) ) ) ;
228246 }
229- return this . store . fetcher . fetch ( url , { method : 'DELETE' } ) ;
247+ return this . fetcher . fetch ( url , { method : 'DELETE' } ) ;
230248 } catch ( e ) {
231249 // console.log(`Please manually remove ${url} from your system under test.`, e);
232250 }
0 commit comments