Skip to content

Commit f02a2f1

Browse files
committed
chnaged SolidLogic from class to function
1 parent c374879 commit f02a2f1

4 files changed

Lines changed: 52 additions & 47 deletions

File tree

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const store = solidLogicSingleton.store
99
export { ACL_LINK } from './acl/aclLogic'
1010
export { offlineTestID, appContext } from './authn/authUtil'
1111
export { getSuggestedIssuers } from './issuer/issuerLogic'
12-
export { SolidLogic } from './logic/SolidLogic'
13-
export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
12+
export { AppDetails, SolidNamespace, AuthenticationContext, SolidLogic } from './types'
1413
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
1514

1615
export {

src/logic/SolidLogic.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,44 @@ import { createProfileLogic } from "../profile/profileLogic";
99
import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic";
1010
import { createContainerLogic } from "../util/containerLogic";
1111
import { createUtilityLogic } from "../util/utilityLogic";
12-
import { AuthnLogic } from "../types";
12+
import { AuthnLogic, SolidLogic } from "../types";
1313
import * 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
}

src/logic/solidLogicSingleton.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as debug from "../util/debug"
22
import { authSession } from "../authSession/authSession"
3-
import { SolidLogic } from "./SolidLogic"
3+
import { createSolidLogic } from "./SolidLogic"
44

55
const _fetch = async (url, requestInit) => {
66
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
@@ -13,7 +13,7 @@ const _fetch = async (url, requestInit) => {
1313
}
1414

1515
//this const makes solidLogicSingleton global accessible in mashlib
16-
const solidLogicSingleton = new SolidLogic({ fetch: _fetch }, authSession)
16+
const solidLogicSingleton = createSolidLogic({ fetch: _fetch }, authSession)
1717

1818
debug.log('Unique quadstore initialized.')
1919

src/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Session } from "@inrupt/solid-client-authn-browser"
2-
import { NamedNode } from "rdflib"
2+
import { LiveStore, NamedNode, Statement } from "rdflib"
33

44
export type AppDetails = {
55
noun: string
@@ -105,6 +105,18 @@ export interface TypeIndexLogic {
105105
registerInTypeIndex: (instance: NamedNode, index: NamedNode, theClass: NamedNode) => Promise<NamedNode | null>,
106106
deleteTypeIndexRegistration: (item: any) => Promise<void>
107107
getScopedAppsFromIndex: (scope: TypeIndexScope, theClass: NamedNode | null) => Promise<ScopedApp[]>
108+
}
108109

110+
export interface SolidLogic {
111+
store: LiveStore,
112+
authn: AuthnLogic,
113+
acl: AclLogic,
114+
profile: ProfileLogic,
115+
inbox: InboxLogic,
116+
typeIndex: TypeIndexLogic,
117+
chat: ChatLogic,
118+
load: (doc: NamedNode | NamedNode[] | string) => void,
119+
updatePromise: (del: Array<Statement>, ins: Array<Statement>) => Promise<void>,
120+
clearStore: () => void
109121
}
110122

0 commit comments

Comments
 (0)