Skip to content

Commit f7bdc34

Browse files
committed
streamlined the fetcher
1 parent 64c8b7a commit f7bdc34

3 files changed

Lines changed: 9 additions & 29 deletions

File tree

src/inbox/InboxLogic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class InboxLogic {
4444
return ourInbox;
4545
}
4646
async markAsRead(url: string, date: Date) {
47-
const downloaded = await this.util.underlyingFetch.fetch(url);
47+
const downloaded = await this.store.fetcher._fetch(url);
4848
if (downloaded.status !== 200) {
4949
throw new Error(`Not OK! ${url}`);
5050
}
@@ -56,7 +56,7 @@ export class InboxLogic {
5656
[ 'Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream' ]
5757
]
5858
};
59-
const uploaded = await this.util.underlyingFetch.fetch(archiveUrl, options);
59+
const uploaded = await this.store.fetcher._fetch(archiveUrl, options);
6060
if (uploaded.status.toString()[0] === '2') {
6161
await this.store.fetcher?._fetch(url, {
6262
method: 'DELETE'

src/logic/SolidLogic.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class SolidLogic {
3030

3131
store: LiveStore;
3232
me: string | undefined;
33-
underlyingFetch: { fetch: (url: string, options?: any) => any };
34-
3533
chat: ChatLogic;
3634
profile: ProfileLogic;
3735
authn: AuthnLogic;
@@ -51,12 +49,11 @@ export class SolidLogic {
5149
profileDocument: {},
5250
preferencesFile: {},
5351
};
54-
this.underlyingFetch = { fetch: fetch }; // Note global one not the one passed
5552
this.authn = new SolidAuthnLogic(session);
5653
debug.log('SolidAuthnLogic initialized')
5754
this.profile = new ProfileLogic(this.store, ns, this.authn);
5855
this.chat = new ChatLogic(this.store, ns, this.profile);
59-
this.util = new UtilityLogic(this.store, ns, this.underlyingFetch);
56+
this.util = new UtilityLogic(this.store, ns);
6057
}
6158

6259
findAclDocUrl(url: string) {
@@ -257,6 +254,6 @@ export class SolidLogic {
257254
}
258255

259256
async fetch(url: string, options?: any) {
260-
return this.underlyingFetch.fetch(url, options);
257+
return this.store.fetcher._fetch(url, options);
261258
}
262259
}

src/util/UtilityLogic.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ export const ACL_LINK = sym(
1111
export class UtilityLogic {
1212
store: LiveStore;
1313
ns: SolidNamespace;
14-
underlyingFetch: { fetch: (url: string, options?: any) => any };
1514

16-
constructor(store: LiveStore, ns: SolidNamespace, underlyingFetch: { fetch: (url: string, options?: any) => any }) {
15+
constructor(store: LiveStore, ns: SolidNamespace) {
1716
this.store = store;
1817
this.ns = ns;
19-
this.underlyingFetch = underlyingFetch;
2018
}
2119

2220
async findAclDocUrl(url: string) {
@@ -65,7 +63,7 @@ export class UtilityLogic {
6563
].join('\n')
6664
}
6765
const aclDocUrl = await this.findAclDocUrl(options.target);
68-
return this.underlyingFetch.fetch(aclDocUrl, {
66+
return this.store.fetcher._fetch(aclDocUrl, {
6967
method: 'PUT',
7068
body: str,
7169
headers: [
@@ -74,21 +72,6 @@ export class UtilityLogic {
7472
});
7573
}
7674

77-
async loadDoc(doc: NamedNode): Promise<void> {
78-
// Load a document into the knowledge base (fetcher.store)
79-
// withCredentials: Web arch should let us just load by turning off creds helps CORS
80-
// reload: Gets around a specific old Chrome bug caching/origin/cors
81-
// console.log('loading', profileDocument)
82-
if (!this.store.fetcher) {
83-
throw new Error("Cannot load doc, have no fetcher");
84-
}
85-
await this.store.fetcher.load(doc, {
86-
withCredentials: false, // @@ BUT this won't work when logged in an accessing private stuff!
87-
cache: "reload",
88-
});
89-
// console.log('loaded', profileDocument, this.store)
90-
}
91-
9275
isContainer(url: string) {
9376
return url.charAt(url.length-1) === "/";
9477
}
@@ -98,7 +81,7 @@ export class UtilityLogic {
9881
throw new Error(`Not a container URL ${url}`);
9982
}
10083
// Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64
101-
const result = await this.underlyingFetch.fetch(url, {
84+
const result = await this.store.fetcher._fetch(url, {
10285
method: "PUT",
10386
headers: {
10487
"Content-Type": "text/turtle",
@@ -134,13 +117,13 @@ export class UtilityLogic {
134117
try {
135118
if (this.isContainer(url)) {
136119
const aclDocUrl = await this.findAclDocUrl(url);
137-
await this.underlyingFetch.fetch(aclDocUrl, { method: "DELETE" });
120+
await this.store.fetcher._fetch(aclDocUrl, { method: "DELETE" });
138121
const containerMembers = await this.getContainerMembers(url);
139122
await Promise.all(
140123
containerMembers.map((url) => this.recursiveDelete(url))
141124
);
142125
}
143-
return this.underlyingFetch.fetch(url, { method: "DELETE" });
126+
return this.store.fetcher._fetch(url, { method: "DELETE" });
144127
} catch (e) {
145128
// console.log(`Please manually remove ${url} from your system under test.`, e);
146129
}

0 commit comments

Comments
 (0)