solid-logic 1.3.17-f7bdc345 → 1.3.17-fca5749b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/lib/acl/aclLogic.d.ts +12 -30
  2. package/lib/acl/aclLogic.d.ts.map +1 -1
  3. package/lib/acl/aclLogic.js +152 -119
  4. package/lib/acl/aclLogic.js.map +1 -1
  5. package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
  6. package/lib/authn/SolidAuthnLogic.js +2 -2
  7. package/lib/authn/SolidAuthnLogic.js.map +1 -1
  8. package/lib/chat/chatLogic.d.ts +16 -0
  9. package/lib/chat/chatLogic.d.ts.map +1 -0
  10. package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
  11. package/lib/chat/chatLogic.js.map +1 -0
  12. package/lib/inbox/inboxLogic.d.ts +7 -0
  13. package/lib/inbox/inboxLogic.d.ts.map +1 -0
  14. package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
  15. package/lib/inbox/inboxLogic.js.map +1 -0
  16. package/lib/index.d.ts +18 -9
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +76 -35
  19. package/lib/index.js.map +1 -1
  20. package/lib/logic/CustomError.d.ts +4 -0
  21. package/lib/logic/CustomError.d.ts.map +1 -1
  22. package/lib/logic/CustomError.js +17 -1
  23. package/lib/logic/CustomError.js.map +1 -1
  24. package/lib/logic/SolidLogic.d.ts +8 -31
  25. package/lib/logic/SolidLogic.d.ts.map +1 -1
  26. package/lib/logic/SolidLogic.js +16 -249
  27. package/lib/logic/SolidLogic.js.map +1 -1
  28. package/lib/logic/solidLogicSingleton.js +1 -1
  29. package/lib/logic/solidLogicSingleton.js.map +1 -1
  30. package/lib/logic/solidLogicSingletonNew.d.ts +67 -0
  31. package/lib/logic/solidLogicSingletonNew.d.ts.map +1 -0
  32. package/lib/logic/solidLogicSingletonNew.js +219 -0
  33. package/lib/logic/solidLogicSingletonNew.js.map +1 -0
  34. package/lib/profile/profileLogic.d.ts +11 -0
  35. package/lib/profile/profileLogic.d.ts.map +1 -0
  36. package/lib/profile/profileLogic.js +246 -0
  37. package/lib/profile/profileLogic.js.map +1 -0
  38. package/lib/typeIndex/typeIndexLogic.d.ts +18 -21
  39. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
  40. package/lib/typeIndex/typeIndexLogic.js +304 -296
  41. package/lib/typeIndex/typeIndexLogic.js.map +1 -1
  42. package/lib/types.d.ts +17 -0
  43. package/lib/types.d.ts.map +1 -1
  44. package/lib/util/containerLogic.d.ts +11 -0
  45. package/lib/util/containerLogic.d.ts.map +1 -0
  46. package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
  47. package/lib/util/containerLogic.js.map +1 -0
  48. package/lib/util/ns.d.ts +2 -0
  49. package/lib/util/ns.d.ts.map +1 -0
  50. package/lib/util/ns.js +34 -0
  51. package/lib/util/ns.js.map +1 -0
  52. package/lib/util/utilityLogic.d.ts +15 -0
  53. package/lib/util/utilityLogic.d.ts.map +1 -0
  54. package/lib/util/utilityLogic.js +272 -0
  55. package/lib/util/utilityLogic.js.map +1 -0
  56. package/lib/util/utils.d.ts +8 -0
  57. package/lib/util/utils.d.ts.map +1 -0
  58. package/lib/util/utils.js +48 -0
  59. package/lib/util/utils.js.map +1 -0
  60. package/package.json +1 -1
  61. package/src/acl/aclLogic.ts +136 -118
  62. package/src/authn/SolidAuthnLogic.ts +3 -2
  63. package/src/chat/chatLogic.ts +225 -0
  64. package/src/inbox/inboxLogic.ts +57 -0
  65. package/src/index.ts +121 -30
  66. package/src/logic/CustomError.ts +5 -1
  67. package/src/logic/SolidLogic.ts +30 -208
  68. package/src/logic/solidLogicSingleton.ts +1 -1
  69. package/src/logic/solidLogicSingletonNew.ts +210 -0
  70. package/src/profile/profileLogic.ts +125 -0
  71. package/src/typeIndex/typeIndexLogic.ts +175 -182
  72. package/src/types.ts +7 -3
  73. package/src/util/containerLogic.ts +54 -0
  74. package/src/util/ns.ts +5 -0
  75. package/src/util/utilityLogic.ts +155 -0
  76. package/src/util/utils.ts +52 -0
  77. package/test/aclLogic.test.ts +13 -4
  78. package/test/chatLogic.test.ts +70 -71
  79. package/test/container.test.ts +56 -0
  80. package/test/helpers/dataSetup.ts +134 -0
  81. package/test/helpers/setup.ts +4 -0
  82. package/test/inboxLogic.test.ts +39 -38
  83. package/test/logic.test.ts +10 -9
  84. package/test/profileLogic.test.ts +246 -0
  85. package/test/typeIndexLogic.test.ts +487 -30
  86. package/test/utilityLogic.test.ts +172 -126
  87. package/test/utils.test.ts +32 -0
  88. package/lib/chat/ChatLogic.d.ts +0 -26
  89. package/lib/chat/ChatLogic.d.ts.map +0 -1
  90. package/lib/chat/ChatLogic.js.map +0 -1
  91. package/lib/chat/determineChatContainer.d.ts +0 -3
  92. package/lib/chat/determineChatContainer.d.ts.map +0 -1
  93. package/lib/chat/determineChatContainer.js +0 -12
  94. package/lib/chat/determineChatContainer.js.map +0 -1
  95. package/lib/discovery/discoveryLogic.d.ts +0 -37
  96. package/lib/discovery/discoveryLogic.d.ts.map +0 -1
  97. package/lib/discovery/discoveryLogic.js +0 -502
  98. package/lib/discovery/discoveryLogic.js.map +0 -1
  99. package/lib/inbox/InboxLogic.d.ts +0 -18
  100. package/lib/inbox/InboxLogic.d.ts.map +0 -1
  101. package/lib/inbox/InboxLogic.js.map +0 -1
  102. package/lib/profile/ProfileLogic.d.ts +0 -13
  103. package/lib/profile/ProfileLogic.d.ts.map +0 -1
  104. package/lib/profile/ProfileLogic.js.map +0 -1
  105. package/lib/util/UtilityLogic.d.ts +0 -27
  106. package/lib/util/UtilityLogic.d.ts.map +0 -1
  107. package/lib/util/UtilityLogic.js +0 -216
  108. package/lib/util/UtilityLogic.js.map +0 -1
  109. package/lib/util/uri.d.ts +0 -3
  110. package/lib/util/uri.d.ts.map +0 -1
  111. package/lib/util/uri.js +0 -9
  112. package/lib/util/uri.js.map +0 -1
  113. package/src/chat/ChatLogic.ts +0 -244
  114. package/src/chat/determineChatContainer.ts +0 -14
  115. package/src/discovery/discoveryLogic.ts +0 -269
  116. package/src/inbox/InboxLogic.ts +0 -66
  117. package/src/profile/ProfileLogic.ts +0 -44
  118. package/src/util/UtilityLogic.ts +0 -144
  119. package/src/util/uri.ts +0 -5
  120. package/test/discoveryLogic.test.ts +0 -712
package/src/index.ts CHANGED
@@ -1,52 +1,143 @@
1
1
  // Make these variables directly accessible as it is what you need most of the time
2
2
  // This also makes these variable globaly accesible in mashlib
3
3
  import { solidLogicSingleton } from './logic/solidLogicSingleton'
4
+
4
5
  const authn = solidLogicSingleton.authn
5
6
  const authSession = solidLogicSingleton.authn.authSession
6
7
  const store = solidLogicSingleton.store
7
8
 
8
- const chat = solidLogicSingleton.chat
9
- const profile = solidLogicSingleton.profile
9
+ const aclLogic = solidLogicSingleton.aclLogic
10
+ const utilityLogic = solidLogicSingleton.utilityLogic
11
+ const containerLogic = solidLogicSingleton.containerLogic
12
+ const profileLogic = solidLogicSingleton.profileLogic
13
+ const inboxLogic = solidLogicSingleton.inboxLogic
14
+ const typeIndexLogic = solidLogicSingleton.typeIndexLogic
15
+ const chatLogic = solidLogicSingleton.chatLogic
10
16
 
11
- export {
17
+ const {
18
+ findAclDocUrl,
12
19
  setACLUserPublic,
13
- genACLText
14
- } from './acl/aclLogic'
20
+ genACLText,
21
+ } = aclLogic
15
22
 
16
- export {
17
- ensureTypeIndexes,
18
- loadTypeIndexes,
23
+ const {
19
24
  registerInTypeIndex,
20
- loadIndex
21
- } from './typeIndex/typeIndexLogic'
22
-
23
- // Generate by
24
- // grep export src/discovery/discoveryLogic.ts | sed -e 's/export //g' | sed -e 's/async //g'| sed -e 's/function //g' | sed -e 's/ .*/,/g' | sort
25
- export {
25
+ getRegistrations,
26
+ //NEW function for discovery
27
+ loadTypeIndexesFor,
28
+ loadCommunityTypeIndexes,
29
+ loadAllTypeIndexes,
30
+ getScopedAppInstances,
31
+ getAppInstances,
32
+ suggestPublicTypeIndex,
33
+ suggestPrivateTypeIndex,
26
34
  deleteTypeIndexRegistration,
35
+ getScopedAppsFromIndex
36
+ } = typeIndexLogic
37
+
38
+ const {
39
+ setAcl,
40
+ addToPrivateTypeIndex,
41
+ findChat,
42
+ createChatThing,
43
+ getChat,
44
+ sendInvite,
45
+ mintNew
46
+ } = chatLogic
47
+
48
+ const { createInboxFor, getNewMessages, markAsRead } = inboxLogic
49
+ const {
50
+ recursiveDelete,
51
+ setSinglePeerAccess,
52
+ createEmptyRdfDoc,
53
+ //NEW function for discovery
27
54
  followOrCreateLink,
28
- getAppInstances,
29
- getScopedAppInstances,
30
- getScopedAppsFromIndex,
31
- loadAllTypeIndexes,
32
- loadCommunityTypeIndexes,
33
55
  loadOrCreateIfNotExists,
56
+ } = utilityLogic
57
+
58
+ const {
59
+ loadMe,
60
+ getPodRoot,
61
+ getMainInbox,
62
+ findStorage,
63
+ //NEW content from discovery
34
64
  loadPreferences,
35
65
  loadProfile,
36
- loadTypeIndexesFor,
37
- registerInstanceInTypeIndex,
38
- suggestPreferencesFile,
39
- suggestPrivateTypeIndex,
40
- suggestPublicTypeIndex,
41
- uniqueNodes
42
- } from './discovery/discoveryLogic'
66
+ //NEW function for discovery
67
+ silencedLoadPreferences
68
+ } = profileLogic
43
69
 
44
- export { SolidLogic } from './logic/SolidLogic'
70
+ const {
71
+ isContainer,
72
+ createContainer,
73
+ getContainerElements,
74
+ getContainerMembers
75
+ } = containerLogic
76
+
77
+ export { ACL_LINK } from './acl/aclLogic'
45
78
  export { offlineTestID, appContext } from './authn/authUtil'
46
- export { ACL_LINK } from './util/UtilityLogic'
47
79
  export { getSuggestedIssuers } from './issuer/issuerLogic'
80
+ export { SolidLogic } from './logic/SolidLogic'
48
81
  export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
49
82
  // solidLogicSingleton is exported entirely because it is used in solid-panes
50
83
  export { solidLogicSingleton } from './logic/solidLogicSingleton'
51
- export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
52
- export { authn, authSession, store, chat, profile }
84
+ export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
85
+
86
+ export {
87
+ store,
88
+ authn,
89
+ authSession,
90
+ aclLogic,
91
+ utilityLogic,
92
+ containerLogic,
93
+ profileLogic,
94
+ inboxLogic,
95
+ typeIndexLogic,
96
+ chatLogic,
97
+ //aclLogic
98
+ findAclDocUrl,
99
+ setACLUserPublic,
100
+ genACLText,
101
+ //typeIndexLogic
102
+ registerInTypeIndex,
103
+ getRegistrations,
104
+ loadTypeIndexesFor,
105
+ loadCommunityTypeIndexes,
106
+ loadAllTypeIndexes,
107
+ getScopedAppInstances,
108
+ getAppInstances,
109
+ suggestPublicTypeIndex,
110
+ suggestPrivateTypeIndex,
111
+ deleteTypeIndexRegistration,
112
+ getScopedAppsFromIndex,
113
+ setAcl,
114
+ addToPrivateTypeIndex,
115
+ findChat,
116
+ createChatThing,
117
+ getChat,
118
+ sendInvite,
119
+ //inboxLogic
120
+ mintNew,
121
+ createInboxFor,
122
+ getNewMessages,
123
+ markAsRead,
124
+ //utilityLogic
125
+ recursiveDelete,
126
+ setSinglePeerAccess,
127
+ createEmptyRdfDoc,
128
+ followOrCreateLink,
129
+ loadOrCreateIfNotExists,
130
+ //profileLogic
131
+ loadMe,
132
+ getPodRoot,
133
+ getMainInbox,
134
+ findStorage,
135
+ loadPreferences,
136
+ loadProfile,
137
+ silencedLoadPreferences,
138
+ //containerLogic
139
+ isContainer,
140
+ createContainer,
141
+ getContainerElements,
142
+ getContainerMembers
143
+ }
@@ -6,7 +6,7 @@ class CustomError extends Error {
6
6
  this.name = new.target.name; // stack traces display correctly now
7
7
  }
8
8
  }
9
-
9
+
10
10
  export class UnauthorizedError extends CustomError {}
11
11
 
12
12
  export class CrossOriginForbiddenError extends CustomError {}
@@ -15,6 +15,10 @@ export class SameOriginForbiddenError extends CustomError {}
15
15
 
16
16
  export class NotFoundError extends CustomError {}
17
17
 
18
+ export class NotEditableError extends CustomError { }
19
+
20
+ export class WebOperationError extends CustomError {}
21
+
18
22
  export class FetchError extends CustomError {
19
23
  status: number;
20
24
 
@@ -1,222 +1,64 @@
1
1
  import { Session } from "@inrupt/solid-client-authn-browser";
2
2
  import * as rdf from "rdflib";
3
- import { NamedNode, Statement, LiveStore } from "rdflib";
4
- import solidNamespace from "solid-namespace";
3
+ import { LiveStore, NamedNode, Statement } from "rdflib";
4
+ import { createAclLogic } from "../acl/aclLogic";
5
5
  import { SolidAuthnLogic } from "../authn/SolidAuthnLogic";
6
- import { ChatLogic } from "../chat/ChatLogic";
7
- import { ProfileLogic } from "../profile/ProfileLogic";
8
- import { AuthnLogic, SolidNamespace } from "../types";
6
+ import { createChatLogic } from "../chat/chatLogic";
7
+ import { createInboxLogic } from "../inbox/inboxLogic";
8
+ import { createProfileLogic } from "../profile/profileLogic";
9
+ import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic";
10
+ import { createContainerLogic } from "../util/containerLogic";
11
+ import { createUtilityLogic } from "../util/utilityLogic";
12
+ import { AuthnLogic } from "../types";
9
13
  import * as debug from "../util/debug";
10
- import { UtilityLogic } from "../util/UtilityLogic";
11
- import { CrossOriginForbiddenError, FetchError, NotFoundError, SameOriginForbiddenError, UnauthorizedError } from "./CustomError";
12
14
  /*
13
15
  ** It is important to distinquish `fetch`, a function provided by the browser
14
16
  ** and `Fetcher`, a helper object for the rdflib Store which turns it
15
17
  ** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
16
18
  ** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
17
19
  */
18
-
19
- const ns: SolidNamespace = solidNamespace(rdf);
20
-
21
20
  export class SolidLogic {
22
- cache: {
23
- profileDocument: {
24
- [WebID: string]: NamedNode;
25
- };
26
- preferencesFile: {
27
- [WebID: string]: NamedNode;
28
- };
29
- };
30
21
 
31
22
  store: LiveStore;
32
23
  me: string | undefined;
33
- chat: ChatLogic;
34
- profile: ProfileLogic;
35
24
  authn: AuthnLogic;
36
- util: UtilityLogic;
25
+
26
+ aclLogic
27
+ utilityLogic
28
+ containerLogic
29
+ profileLogic
30
+ inboxLogic
31
+ typeIndexLogic
32
+ chatLogic
33
+
37
34
 
38
35
  constructor(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: Session) {
39
36
  // would xpect to be able to do it this way: but get TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation status: 999
40
37
  // this.store = new rdf.LiveStore({})
41
38
  // this.store.fetcher._fetch = fetch
42
- console.log("SolidLogic: Unique instance created. There should only be one of these.")
39
+ debug.log("SolidLogic: Unique instance created. There should only be one of these.")
43
40
  this.store = rdf.graph() as LiveStore; // Make a Quad store
44
41
  rdf.fetcher(this.store, { fetch: specialFetch.fetch}); // Attach a web I/O module, store.fetcher
45
42
  this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
46
-
47
43
  this.store.features = [] // disable automatic node merging on store load
48
- this.cache = {
49
- profileDocument: {},
50
- preferencesFile: {},
51
- };
52
- this.authn = new SolidAuthnLogic(session);
53
- debug.log('SolidAuthnLogic initialized')
54
- this.profile = new ProfileLogic(this.store, ns, this.authn);
55
- this.chat = new ChatLogic(this.store, ns, this.profile);
56
- this.util = new UtilityLogic(this.store, ns);
57
- }
58
-
59
- findAclDocUrl(url: string) {
60
- return this.util.findAclDocUrl(url);
61
- }
44
+
45
+ this.authn = new SolidAuthnLogic(session)
62
46
 
63
- async loadProfile(me: NamedNode): Promise<NamedNode> {
64
- /*
65
- // console.log('loadProfile cache ', this.cache)
66
- if (this.cache.profileDocument[me.value]) {
67
- return this.cache.profileDocument[me.value];
68
- } @@ just use the cache in the store
69
- */
70
- console.log('loadProfile me ', me)
71
- const profileDocument = me.doc()
72
- try {
73
- await this.store.fetcher.load(profileDocument);
74
- return profileDocument;
75
- } catch (err) {
76
- const message = `Cannot load profile ${profileDocument} : ${err}`;
77
- throw new Error(message);
78
- }
79
- }
80
-
81
- async loadPreferences(me: NamedNode): Promise<NamedNode> {
82
- console.log('loadPreferences cache ', this.cache)
83
- if (this.cache.preferencesFile[me.value]) {
84
- return this.cache.preferencesFile[me.value];
85
- }
86
- await this.loadProfile(me) // Load pointer to pref file
87
- const preferencesFile = this.store.any(me, ns.space('preferencesFile'), null, me.doc());
88
-
89
- // console.log('this.store.any()', this.store.any())
90
- /**
91
- * Are we working cross-origin?
92
- * Returns True if we are in a webapp at an origin, and the file origin is different
93
- */
94
- function differentOrigin(): boolean {
95
- if (!preferencesFile) {
96
- return true;
97
- }
98
- return (
99
- `${window.location.origin}/` !== new URL(preferencesFile.value).origin
100
- );
101
- }
102
-
103
- if (!preferencesFile) {
104
- throw new Error(
105
- `Can't find a preference file pointer in profile ${me.doc()}`
106
- );
107
- }
108
-
109
- // //// Load preference file
110
- try {
111
- await this.store.fetcher.load(preferencesFile as NamedNode, {
112
- withCredentials: true,
113
- });
114
- } catch (err) {
115
- // Really important to look at why
116
- const status = err.status;
117
- debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
118
- if (status === 401) {
119
- throw new UnauthorizedError();
120
- }
121
- if (status === 403) {
122
- if (differentOrigin()) {
123
- throw new CrossOriginForbiddenError();
124
- }
125
- throw new SameOriginForbiddenError();
126
- }
127
- if (status === 404) {
128
- throw new NotFoundError(preferencesFile.value);
129
- }
130
- throw new FetchError(err.status, err.message);
131
- }
132
- return preferencesFile as NamedNode;
133
- }
134
-
135
- getTypeIndex(
136
- me: NamedNode | string,
137
- preferencesFile: NamedNode | string,
138
- isPublic: boolean
139
- ): NamedNode[] {
140
- // console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
141
- return this.store.each(
142
- me as NamedNode,
143
- isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
144
- undefined,
145
- preferencesFile as NamedNode
146
- ) as NamedNode[];
147
- }
47
+ debug.log('SolidAuthnLogic initialized')
148
48
 
149
- getRegistrations(instance, theClass) {
150
- return this.store
151
- .each(undefined, ns.solid("instance"), instance)
152
- .filter((r) => {
153
- return this.store.holds(r, ns.solid("forClass"), theClass);
154
- });
49
+ this.aclLogic = createAclLogic(this.store)
50
+ this.containerLogic = createContainerLogic(this.store)
51
+ this.utilityLogic = createUtilityLogic(this.store, this.aclLogic, this.containerLogic)
52
+ this.profileLogic = createProfileLogic(this.store, this.authn, this.utilityLogic)
53
+ this.chatLogic = createChatLogic(this.store, this.profileLogic)
54
+ this.inboxLogic = createInboxLogic(this.store, this.profileLogic, this.utilityLogic, this.containerLogic, this.aclLogic)
55
+ this.typeIndexLogic = createTypeIndexLogic(this.store, this.authn, this.profileLogic, this.utilityLogic)
155
56
  }
156
57
 
157
58
  load(doc: NamedNode | NamedNode[] | string) {
158
59
  return this.store.fetcher.load(doc);
159
60
  }
160
61
 
161
- async loadIndexes(
162
- me: NamedNode | string,
163
- publicProfile: NamedNode | string | null,
164
- preferencesFile: NamedNode | string | null,
165
- onWarning = async (_err: Error) => {
166
- return undefined;
167
- }
168
- ): Promise<{
169
- private: any;
170
- public: any;
171
- }> {
172
- let privateIndexes: any[] = [];
173
- let publicIndexes: any[] = [];
174
- if (publicProfile) {
175
- publicIndexes = this.getTypeIndex(me, publicProfile, true);
176
- try {
177
- await this.load(publicIndexes as NamedNode[]);
178
- } catch (err) {
179
- onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
180
- }
181
- }
182
- if (preferencesFile) {
183
- privateIndexes = this.getTypeIndex(me, preferencesFile, false);
184
- // console.log({ privateIndexes })
185
- if (privateIndexes.length === 0) {
186
- await onWarning(
187
- new Error(
188
- `Your preference file ${preferencesFile} does not point to a private type index.`
189
- )
190
- );
191
- } else {
192
- try {
193
- await this.load(privateIndexes);
194
- } catch (err) {
195
- onWarning(
196
- new Error(`loadIndex: loading private type index(es) ${err}`)
197
- );
198
- }
199
- }
200
- // } else {
201
- // debug.log(
202
- // 'We know your preference file is not available, so we are not bothering with private type indexes.'
203
- // )
204
- }
205
-
206
- return {
207
- private: privateIndexes,
208
- public: publicIndexes,
209
- };
210
- }
211
-
212
- async createEmptyRdfDoc(doc: NamedNode, comment: string) {
213
- await this.store.fetcher.webOperation("PUT", doc.uri, {
214
- data: `# ${new Date()} ${comment}
215
- `,
216
- contentType: "text/turtle",
217
- });
218
- }
219
-
220
62
  // @@@@ use the one in rdflib.js when it is available and delete this
221
63
  updatePromise(
222
64
  del: Array<Statement>,
@@ -233,27 +75,7 @@ export class SolidLogic {
233
75
  }); // promise
234
76
  }
235
77
 
236
- isContainer(url: string) {
237
- return this.util.isContainer(url);
238
- }
239
-
240
- getContainerElements(containerNode: NamedNode): NamedNode[] {
241
- return this.util.getContainerElements(containerNode);
242
- }
243
-
244
- getContainerMembers(containerUrl: string): Promise<string[]> {
245
- return this.util.getContainerMembers(containerUrl);
246
- }
247
-
248
- async recursiveDelete(url: string) {
249
- return this.util.recursiveDelete(url);
250
- }
251
-
252
78
  clearStore() {
253
- return this.util.clearStore();
254
- }
255
-
256
- async fetch(url: string, options?: any) {
257
- return this.store.fetcher._fetch(url, options);
79
+ this.store.statements.slice().forEach(this.store.remove.bind(this.store));
258
80
  }
259
81
  }
@@ -5,7 +5,7 @@ import { SolidLogic } from "./SolidLogic"
5
5
  const _fetch = async (url, requestInit) => {
6
6
  const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
7
7
  if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
8
- // In fact ftech should respect crentials omit itself
8
+ // In fact fetch should respect credentials omit itself
9
9
  return authSession.fetch(url, requestInit)
10
10
  } else {
11
11
  return window.fetch(url, requestInit)
@@ -0,0 +1,210 @@
1
+ import * as rdf from "rdflib"
2
+ import { SolidAuthnLogic } from "../authn/SolidAuthnLogic"
3
+ import { authSession } from "../authSession/authSession"
4
+ import { createContainerLogic } from "../util/containerLogic"
5
+ import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic"
6
+ import * as debug from "../util/debug"
7
+ import { createUtilityLogic } from "../util/utilityLogic"
8
+ import { createProfileLogic } from "../profile/profileLogic"
9
+ import { createInboxLogic } from "../inbox/inboxLogic"
10
+ import { createChatLogic } from "../chat/chatLogic"
11
+ import { createAclLogic } from "../acl/aclLogic"
12
+
13
+ export function solidLogicSingleton() {
14
+
15
+ const _fetch = async (url, requestInit) => {
16
+ const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
17
+ if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
18
+ // In fact fetch should respect credentials omit itself
19
+ return authSession.fetch(url, requestInit)
20
+ } else {
21
+ return window.fetch(url, requestInit)
22
+ }
23
+ }
24
+
25
+ debug.log("SolidLogicSingleton: Unique instance created. There should only be one of these.")
26
+
27
+ const store = rdf.graph() as rdf.LiveStore; // Make a Quad store
28
+ rdf.fetcher(store, { fetch: _fetch }); // Attach a web I/O module, store.fetcher
29
+ store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
30
+ store.features = [] // disable automatic node merging on store load
31
+
32
+ debug.log('SolidAuthnLogic initialized')
33
+ const authn = new SolidAuthnLogic(authSession)
34
+
35
+ const aclLogic = createAclLogic(store)
36
+ const {
37
+ findAclDocUrl,
38
+ setACLUserPublic,
39
+ genACLText
40
+ } = aclLogic
41
+
42
+ const containerLogic = createContainerLogic(store)
43
+ const {
44
+ isContainer,
45
+ createContainer,
46
+ getContainerElements,
47
+ getContainerMembers
48
+ } = containerLogic
49
+
50
+ const utilityLogic = createUtilityLogic(store, aclLogic, containerLogic)
51
+ const {
52
+ recursiveDelete,
53
+ setSinglePeerAccess,
54
+ createEmptyRdfDoc,
55
+ followOrCreateLink,
56
+ loadOrCreateIfNotExists
57
+ } = utilityLogic
58
+
59
+ const profileLogic = createProfileLogic(store, authn, utilityLogic)
60
+ const {
61
+ loadMe,
62
+ getPodRoot,
63
+ getMainInbox,
64
+ findStorage,
65
+ loadPreferences,
66
+ loadProfile,
67
+ silencedLoadPreferences
68
+ } = profileLogic
69
+
70
+ const chatLogic = createChatLogic(store, profileLogic)
71
+ const {
72
+ setAcl,
73
+ addToPrivateTypeIndex,
74
+ findChat,
75
+ createChatThing,
76
+ getChat,
77
+ sendInvite,
78
+ mintNew
79
+ } = chatLogic
80
+
81
+ const inboxLogic = createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic)
82
+ const {
83
+ createInboxFor,
84
+ getNewMessages,
85
+ markAsRead
86
+ } = inboxLogic
87
+
88
+ const typeIndexLogic = createTypeIndexLogic(store, authn, profileLogic, utilityLogic)
89
+ const {
90
+ registerInTypeIndex,
91
+ getRegistrations,
92
+ loadTypeIndexesFor,
93
+ loadCommunityTypeIndexes,
94
+ loadAllTypeIndexes,
95
+ getScopedAppInstances,
96
+ getAppInstances,
97
+ suggestPublicTypeIndex,
98
+ suggestPrivateTypeIndex,
99
+ deleteTypeIndexRegistration,
100
+ getScopedAppsFromIndex
101
+ } = typeIndexLogic
102
+
103
+ return {
104
+ store,
105
+ authn,
106
+ authSession,
107
+ //unilityLogic
108
+ recursiveDelete,
109
+ setSinglePeerAccess,
110
+ createEmptyRdfDoc,
111
+ followOrCreateLink,
112
+ loadOrCreateIfNotExists,
113
+ //containerLogic
114
+ isContainer,
115
+ createContainer,
116
+ getContainerElements,
117
+ getContainerMembers,
118
+ //typeIndexLogic
119
+ registerInTypeIndex,
120
+ getRegistrations,
121
+ loadTypeIndexesFor,
122
+ loadCommunityTypeIndexes,
123
+ loadAllTypeIndexes,
124
+ getScopedAppInstances,
125
+ getAppInstances,
126
+ suggestPublicTypeIndex,
127
+ suggestPrivateTypeIndex,
128
+ deleteTypeIndexRegistration,
129
+ getScopedAppsFromIndex,
130
+ //profileLogic
131
+ loadMe,
132
+ getPodRoot,
133
+ getMainInbox,
134
+ findStorage,
135
+ loadPreferences,
136
+ loadProfile,
137
+ silencedLoadPreferences,
138
+ //inboxLogic
139
+ createInboxFor,
140
+ getNewMessages,
141
+ markAsRead,
142
+ //chatLogic
143
+ setAcl,
144
+ addToPrivateTypeIndex,
145
+ findChat,
146
+ createChatThing,
147
+ getChat,
148
+ sendInvite,
149
+ mintNew,
150
+ //aclLogic
151
+ findAclDocUrl,
152
+ setACLUserPublic,
153
+ genACLText
154
+ }
155
+ }
156
+
157
+ /*export {
158
+ store,
159
+ authn,
160
+ authSession,
161
+ //unilityLogic
162
+ recursiveDelete,
163
+ setSinglePeerAccess,
164
+ createEmptyRdfDoc,
165
+ followOrCreateLink,
166
+ loadOrCreateIfNotExists,
167
+ //containerLogic
168
+ isContainer,
169
+ createContainer,
170
+ getContainerElements,
171
+ getContainerMembers,
172
+ //typeIndexLogic
173
+ ensureTypeIndexes,
174
+ registerInTypeIndex,
175
+ getRegistrations,
176
+ loadTypeIndexesFor,
177
+ loadCommunityTypeIndexes,
178
+ loadAllTypeIndexes,
179
+ getScopedAppInstances,
180
+ getAppInstances,
181
+ suggestPublicTypeIndex,
182
+ suggestPrivateTypeIndex,
183
+ deleteTypeIndexRegistration,
184
+ getScopedAppsFromIndex,
185
+ //profileLogic
186
+ loadMe,
187
+ getPodRoot,
188
+ getMainInbox,
189
+ findStorage,
190
+ loadPreferences,
191
+ loadProfile,
192
+ silencedLoadPreferences,
193
+ //inboxLogic
194
+ createInboxFor,
195
+ getNewMessages,
196
+ markAsRead,
197
+ //chatLogic
198
+ setAcl,
199
+ addToPrivateTypeIndex,
200
+ findChat,
201
+ createChatThing,
202
+ getChat,
203
+ sendInvite,
204
+ mintNew,
205
+ //aclLogic
206
+ findAclDocUrl,
207
+ setACLUserPublic,
208
+ genACLText
209
+ }
210
+ */