solid-logic 1.3.17-9d25ceb7 → 1.3.17-a849582e

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 (114) 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 +151 -116
  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/discovery/discoveryLogic.d.ts +8 -8
  13. package/lib/discovery/discoveryLogic.d.ts.map +1 -1
  14. package/lib/discovery/discoveryLogic.js +65 -72
  15. package/lib/discovery/discoveryLogic.js.map +1 -1
  16. package/lib/inbox/inboxLogic.d.ts +7 -0
  17. package/lib/inbox/inboxLogic.d.ts.map +1 -0
  18. package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
  19. package/lib/inbox/inboxLogic.js.map +1 -0
  20. package/lib/index.d.ts +10 -13
  21. package/lib/index.d.ts.map +1 -1
  22. package/lib/index.js +76 -32
  23. package/lib/index.js.map +1 -1
  24. package/lib/logic/CustomError.d.ts +4 -0
  25. package/lib/logic/CustomError.d.ts.map +1 -1
  26. package/lib/logic/CustomError.js +17 -1
  27. package/lib/logic/CustomError.js.map +1 -1
  28. package/lib/logic/solidLogicSingleton.d.ts +35 -3
  29. package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
  30. package/lib/logic/solidLogicSingleton.js +87 -8
  31. package/lib/logic/solidLogicSingleton.js.map +1 -1
  32. package/lib/profile/profileLogic.d.ts +13 -0
  33. package/lib/profile/profileLogic.d.ts.map +1 -0
  34. package/lib/profile/profileLogic.js +268 -0
  35. package/lib/profile/profileLogic.js.map +1 -0
  36. package/lib/typeIndex/typeIndexLogic.d.ts +31 -21
  37. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
  38. package/lib/typeIndex/typeIndexLogic.js +650 -295
  39. package/lib/typeIndex/typeIndexLogic.js.map +1 -1
  40. package/lib/types.d.ts +17 -0
  41. package/lib/types.d.ts.map +1 -1
  42. package/lib/util/containerLogic.d.ts +11 -0
  43. package/lib/util/containerLogic.d.ts.map +1 -0
  44. package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
  45. package/lib/util/containerLogic.js.map +1 -0
  46. package/lib/util/utilityLogic.d.ts +15 -0
  47. package/lib/util/utilityLogic.d.ts.map +1 -0
  48. package/lib/util/utilityLogic.js +272 -0
  49. package/lib/util/utilityLogic.js.map +1 -0
  50. package/lib/util/utils.d.ts +8 -0
  51. package/lib/util/utils.d.ts.map +1 -0
  52. package/lib/util/utils.js +48 -0
  53. package/lib/util/utils.js.map +1 -0
  54. package/package.json +3 -1
  55. package/src/acl/aclLogic.ts +135 -119
  56. package/src/authn/SolidAuthnLogic.ts +3 -2
  57. package/src/chat/chatLogic.ts +225 -0
  58. package/src/discovery/discoveryLogic.ts +66 -87
  59. package/src/inbox/inboxLogic.ts +57 -0
  60. package/src/index.ts +74 -21
  61. package/src/logic/CustomError.ts +5 -1
  62. package/src/logic/solidLogicSingleton.ts +160 -7
  63. package/src/profile/profileLogic.ts +134 -0
  64. package/src/typeIndex/typeIndexLogic.ts +417 -153
  65. package/src/types.ts +7 -3
  66. package/src/util/containerLogic.ts +54 -0
  67. package/src/util/ns.js +5 -0
  68. package/src/util/utilityLogic.ts +155 -0
  69. package/src/util/utils.ts +52 -0
  70. package/test/aclLogic.test.ts +13 -4
  71. package/test/chatLogic.test.ts +70 -71
  72. package/test/container.test.ts +56 -0
  73. package/test/discoveryLogic.test.ts +14 -14
  74. package/test/helpers/dataSetup.ts +134 -0
  75. package/test/helpers/setup.ts +4 -0
  76. package/test/inboxLogic.test.ts +39 -38
  77. package/test/logic.test.ts +11 -9
  78. package/test/profileLogic.test.ts +246 -0
  79. package/test/typeIndexLogic.test.ts +49 -22
  80. package/test/typeIndexLogicPart2.test.ts +485 -0
  81. package/test/utilityLogic.test.ts +172 -126
  82. package/test/utils.test.ts +32 -0
  83. package/lib/chat/ChatLogic.d.ts +0 -26
  84. package/lib/chat/ChatLogic.d.ts.map +0 -1
  85. package/lib/chat/ChatLogic.js.map +0 -1
  86. package/lib/chat/determineChatContainer.d.ts +0 -3
  87. package/lib/chat/determineChatContainer.d.ts.map +0 -1
  88. package/lib/chat/determineChatContainer.js +0 -12
  89. package/lib/chat/determineChatContainer.js.map +0 -1
  90. package/lib/inbox/InboxLogic.d.ts +0 -18
  91. package/lib/inbox/InboxLogic.d.ts.map +0 -1
  92. package/lib/inbox/InboxLogic.js.map +0 -1
  93. package/lib/logic/SolidLogic.d.ts +0 -48
  94. package/lib/logic/SolidLogic.d.ts.map +0 -1
  95. package/lib/logic/SolidLogic.js +0 -321
  96. package/lib/logic/SolidLogic.js.map +0 -1
  97. package/lib/profile/ProfileLogic.d.ts +0 -13
  98. package/lib/profile/ProfileLogic.d.ts.map +0 -1
  99. package/lib/profile/ProfileLogic.js.map +0 -1
  100. package/lib/util/UtilityLogic.d.ts +0 -33
  101. package/lib/util/UtilityLogic.d.ts.map +0 -1
  102. package/lib/util/UtilityLogic.js +0 -240
  103. package/lib/util/UtilityLogic.js.map +0 -1
  104. package/lib/util/uri.d.ts +0 -3
  105. package/lib/util/uri.d.ts.map +0 -1
  106. package/lib/util/uri.js +0 -9
  107. package/lib/util/uri.js.map +0 -1
  108. package/src/chat/ChatLogic.ts +0 -244
  109. package/src/chat/determineChatContainer.ts +0 -14
  110. package/src/inbox/InboxLogic.ts +0 -66
  111. package/src/logic/SolidLogic.ts +0 -262
  112. package/src/profile/ProfileLogic.ts +0 -44
  113. package/src/util/UtilityLogic.ts +0 -161
  114. package/src/util/uri.ts +0 -5
@@ -1,11 +1,9 @@
1
+ import { NamedNode, LiveStore, sym, st } from 'rdflib'
1
2
  import * as $rdf from 'rdflib'
2
- import { LiveStore, NamedNode, st, sym } from 'rdflib'
3
+ import { newThing } from "../util/utils"
3
4
  import solidNamespace from 'solid-namespace'
4
- import { solidLogicSingleton } from '../logic/solidLogicSingleton'
5
- import { newThing } from '../util/uri'
5
+ import { authn } from '../logic/solidLogicSingleton'
6
6
 
7
- const { authn } = solidLogicSingleton
8
- const { currentUser } = authn
9
7
  const ns = solidNamespace($rdf)
10
8
 
11
9
  type TypeIndexScope = { label: string, index: NamedNode, agent: NamedNode }
@@ -18,30 +16,24 @@ type ScopedApp = { instance: NamedNode, scope: TypeIndexScope }
18
16
  * @param doc {NamedNode} - The resource
19
17
  */
20
18
  export async function loadOrCreateIfNotExists (store: LiveStore, doc: NamedNode) {
21
- let response
22
- // console.log('@@ loadOrCreateIfNotExists doc ', doc)
23
- try {
24
- response = await store.fetcher.load(doc)
25
- } catch (err) {
26
- if (err.response.status === 404) {
27
- // console.log('createIfNotExists doc does NOT exist, will create: ' + doc)
28
- try {
29
- store.fetcher.webOperation('PUT', doc, {data: '', contentType: 'text/turtle'})
30
- } catch (err) {
31
- const msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err
32
- // console.log(msg)
33
- throw new Error(msg)
19
+ let response
20
+ try {
21
+ response = await store.fetcher.load(doc)
22
+ } catch (err) {
23
+ if (err.response.status === 404) {
24
+ try {
25
+ store.fetcher.webOperation('PUT', doc, {data: '', contentType: 'text/turtle'})
26
+ } catch (err) {
27
+ const msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err
28
+ throw new Error(msg)
29
+ }
30
+ delete store.fetcher.requested[doc.uri] // delete cached 404 error
31
+ } else {
32
+ const msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err
33
+ throw new Error(msg) // @@ add nested errors
34
34
  }
35
- delete store.fetcher.requested[doc.uri] // delete cached 404 error
36
- // console.log('createIfNotExists doc created ok ' + doc)
37
- } else {
38
- const msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err
39
- // console.log(msg)
40
- throw new Error(msg) // @@ add nested errors
41
- }
42
- }
43
- // console.log('createIfNotExists doc exists, all good ' + doc)
44
- return response
35
+ }
36
+ return response
45
37
  }
46
38
 
47
39
  export function suggestPreferencesFile (me:NamedNode) {
@@ -65,16 +57,13 @@ export function suggestPrivateTypeIndex (preferencesFile:NamedNode) {
65
57
  **
66
58
  ** return: null no ld one and failed to make a new one
67
59
  */
68
- export async function followOrCreateLink(store: LiveStore, subject: NamedNode, predicate: NamedNode,
69
- object: NamedNode, doc:NamedNode):Promise<NamedNode | null> {
60
+ export async function followOrCreateLink (store: LiveStore, subject: NamedNode, predicate: NamedNode,
61
+ object: NamedNode, doc:NamedNode):Promise<NamedNode | null> {
70
62
  await store.fetcher.load(doc)
71
63
  const result = store.any(subject, predicate, null, doc)
72
- // console.log('@@ followOrCreateLink result ', result)
73
64
 
74
65
  if (result) return result as NamedNode
75
66
  if (!store.updater.editable(doc)) {
76
- // console.log(`followOrCreateLink: Can't modify ${doc} so can't make new link to ${object}.`)
77
- // console.log('followOrCreateLink @@ connectedStatements', store.connectedStatements(subject))
78
67
  return null
79
68
  }
80
69
  try {
@@ -84,57 +73,48 @@ export async function followOrCreateLink(store: LiveStore, subject: NamedNode, p
84
73
  return null
85
74
  }
86
75
 
87
- // console.log(`Success making link in ${doc} to ${object}` )
88
-
89
76
  try {
90
77
  await loadOrCreateIfNotExists(store, object)
91
78
  // store.fetcher.webOperation('PUT', object, { data: '', contentType: 'text/turtle'})
92
79
  } catch (err) {
93
80
  console.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)
94
81
  }
95
- // console.log(`followOrCreateLink: Success loading or saving new linked document: ${object}.`)
96
82
  return object
97
83
  }
98
84
 
99
- export async function loadProfile(store: LiveStore, user: NamedNode) {
100
- // console.log(' @@ loadProfile: user', user)
85
+ export async function loadProfile (store: LiveStore, user: NamedNode) {
101
86
  if (!user) {
102
87
  throw new Error(`loadProfile: no user given.`)
103
88
  }
104
- // try {
89
+ try {
105
90
  await store.fetcher.load(user.doc())
106
- // } catch (err) {
107
- // throw new Error(`Unable to load profile of user ${user}: ${err}`)
108
- //}
91
+ } catch (err) {
92
+ throw new Error(`Unable to load profile of user ${user}: ${err}`)
93
+ }
109
94
  return user.doc()
110
95
  }
111
96
 
112
- export async function loadPreferences(store: LiveStore, user: NamedNode): Promise <NamedNode | undefined > {
113
- // console.log('loadPreferences @@ user', user)
97
+ export async function loadPreferences (store: LiveStore, user: NamedNode): Promise <NamedNode | undefined > {
114
98
  await loadProfile(store as LiveStore, user)
115
99
 
116
100
  const possiblePreferencesFile = suggestPreferencesFile(user)
117
101
 
118
102
  const preferencesFile = await followOrCreateLink(store, user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())
119
103
 
120
- // console.log('loadPreferences @@ pref file', preferencesFile)
121
104
  if (!preferencesFile) {
122
105
  const message = `User ${user} has no pointer in profile to preferences file.`
123
106
  console.warn(message)
124
- // throw new Error()
125
107
  return undefined
126
108
  }
127
109
  try {
128
110
  await store.fetcher.load(preferencesFile as NamedNode)
129
111
  } catch (err) { // Maybe a permission propblem or origin problem
130
112
  return undefined
131
- // throw new Error(`Unable to load preferences file ${preferencesFile} of user <${user}>: ${err}`)
132
113
  }
133
114
  return preferencesFile as NamedNode
134
115
  }
135
116
 
136
- export async function loadTypeIndexesFor(store: LiveStore, user:NamedNode): Promise<Array<TypeIndexScope>> {
137
- // console.log('@@ loadTypeIndexesFor user', user)
117
+ export async function loadTypeIndexesFor (store: LiveStore, user:NamedNode): Promise<Array<TypeIndexScope>> {
138
118
  if (!user) throw new Error(`loadTypeIndexesFor: No user given`)
139
119
  const profile = await loadProfile(store, user)
140
120
 
@@ -142,9 +122,6 @@ export async function loadTypeIndexesFor(store: LiveStore, user:NamedNode): Prom
142
122
 
143
123
  const publicTypeIndex = await followOrCreateLink(store, user, ns.solid('publicTypeIndex') as NamedNode, suggestion, profile)
144
124
 
145
- // const publicTypeIndex = store.any(user, ns.solid('publicTypeIndex'), undefined, profile)
146
- // console.log('@@ loadTypeIndexesFor publicTypeIndex', publicTypeIndex)
147
-
148
125
  const publicScopes = publicTypeIndex ? [ { label: 'public', index: publicTypeIndex as NamedNode, agent: user } ] : []
149
126
 
150
127
  let preferencesFile
@@ -171,7 +148,6 @@ export async function loadTypeIndexesFor(store: LiveStore, user:NamedNode): Prom
171
148
  const scopes = publicScopes.concat(privateScopes)
172
149
  if (scopes.length === 0) return scopes
173
150
  const files = scopes.map(scope => scope.index)
174
- // console.log('@@ loadTypeIndexesFor files ', files)
175
151
  try {
176
152
  await store.fetcher.load(files)
177
153
  } catch (err) {
@@ -183,14 +159,13 @@ export async function loadTypeIndexesFor(store: LiveStore, user:NamedNode): Prom
183
159
  export async function loadCommunityTypeIndexes (store:LiveStore, user:NamedNode): Promise<TypeIndexScope[][]> {
184
160
  const preferencesFile = await loadPreferences(store, user)
185
161
  if (preferencesFile) { // For now, pick up communities as simple links from the preferences file.
186
- const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode)
187
- // console.log('loadCommunityTypeIndexes communities: ',communities)
162
+ const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(
163
+ store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)
164
+ )
188
165
  let result = []
189
166
  for (const org of communities) {
190
167
  result = result.concat(await loadTypeIndexesFor(store, org as NamedNode) as any)
191
168
  }
192
- // const communityTypeIndexesPromises = communities.map(async community => await loadTypeIndexesFor(store, community as NamedNode))
193
- // const result1 = Promise.all(communityTypeIndexesPromises)
194
169
  return result
195
170
  }
196
171
  return [] // No communities
@@ -209,38 +184,36 @@ export function uniqueNodes (arr: NamedNode[]): NamedNode[] {
209
184
  return arr2 // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
210
185
  }
211
186
 
212
- export async function getScopedAppsfromIndex (store, scope, theClass: NamedNode) {
213
- // console.log(`getScopedAppsfromIndex agent ${scope.agent} index: ${scope.index}` )
187
+ export async function getScopedAppsFromIndex (store, scope, theClass: NamedNode | null) {
214
188
  const index = scope.index
215
- const registrations = store.each(undefined, ns.solid('forClass'), theClass, index)
216
- // console.log(' registrations', registrations )
217
-
218
- const directInstances = registrations.map(reg => store.each(reg as NamedNode, ns.solid('instance'), null, index)).flat()
219
- // console.log(' directInstances', directInstances )
189
+ const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
190
+ .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
191
+ .map(st => st.subject)
192
+ const relevant = theClass ? registrations.filter(reg => store.any(reg, ns.solid('forClass'), null, index).sameTerm(theClass))
193
+ : registrations
194
+ const directInstances = relevant.map(reg => store.each(reg as NamedNode, ns.solid('instance'), null, index)).flat()
220
195
  let instances = uniqueNodes(directInstances)
221
196
 
222
- const instanceContainers = registrations.map(
223
- reg => store.each(reg as NamedNode, ns.solid('instanceContainer'), null, index)
224
- ).flat()
197
+ const instanceContainers = relevant.map(
198
+ reg => store.each(reg as NamedNode, ns.solid('instanceContainer'), null, index)).flat()
225
199
 
226
200
  // instanceContainers may be deprocatable if no one has used them
227
201
  const containers = uniqueNodes(instanceContainers)
202
+ if (containers.length > 0) { console.log('@@ getScopedAppsFromIndex containers ', containers)}
228
203
  for (let i = 0; i < containers.length; i++) {
229
204
  const cont = containers[i]
230
205
  await store.fetcher.load(cont)
231
206
  const contents = store.each(cont, ns.ldp('contains'), null, cont)
232
- // if (contents.length) console.log('getScopedAppsfromIndex @@ instanceContainer contents:', contents)
233
207
  instances = instances.concat(contents)
234
208
  }
235
209
  return instances.map(instance => { return {instance, scope}})
236
210
  }
237
211
 
238
212
  export async function getScopedAppInstances (store:LiveStore, klass: NamedNode, user: NamedNode):Promise<ScopedApp[]> {
239
- // console.log('getScopedAppInstances @@ ' + user)
240
213
  const scopes = await loadAllTypeIndexes(store, user)
241
214
  let scopedApps = []
242
215
  for (const scope of scopes) {
243
- const scopedApps0 = await getScopedAppsfromIndex(store, scope, klass) as any
216
+ const scopedApps0 = await getScopedAppsFromIndex(store, scope, klass) as any
244
217
  scopedApps = scopedApps.concat(scopedApps0)
245
218
  }
246
219
  return scopedApps
@@ -250,7 +223,7 @@ export async function getScopedAppInstances (store:LiveStore, klass: NamedNode,
250
223
  // Recommended to use getScopedAppInstances instead as it provides more information.
251
224
  //
252
225
  export async function getAppInstances (store:LiveStore, klass: NamedNode): Promise<NamedNode[]> {
253
- const user = currentUser()
226
+ const user = authn.currentUser()
254
227
  if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')
255
228
  const scopedAppInstances = await getScopedAppInstances(store, klass, user)
256
229
  return scopedAppInstances.map(scoped => scoped.instance)
@@ -268,21 +241,27 @@ export async function registerInstanceInTypeIndex (
268
241
  theClass: NamedNode,
269
242
  // agent: NamedNode
270
243
  ): Promise<NamedNode | null> {
271
- const registration = newThing(index)
272
- const ins = [
273
- // See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
274
- st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
275
- st(registration, ns.solid('forClass'), theClass, index),
276
- st(registration, ns.solid('instance'), instance, index)
277
- ]
278
- try {
279
- console.log('patching index', ins)
280
- await store.updater.update([], ins)
281
- } catch (err) {
282
- const msg = `Unable to register ${instance} in index ${index}: ${err}`
283
- console.warn(msg)
284
- return null
285
- }
286
- return registration
244
+ const registration = newThing(index)
245
+ const ins = [
246
+ // See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
247
+ st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
248
+ st(registration, ns.solid('forClass'), theClass, index),
249
+ st(registration, ns.solid('instance'), instance, index)
250
+ ]
251
+ try {
252
+ await store.updater.update([], ins)
253
+ } catch (err) {
254
+ const msg = `Unable to register ${instance} in index ${index}: ${err}`
255
+ console.warn(msg)
256
+ return null
257
+ }
258
+ return registration
259
+ }
260
+
261
+ export async function deleteTypeIndexRegistration (store: LiveStore, item) {
262
+ const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode
263
+ if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)
264
+ const statements = store.statementsMatching(reg, null, null, item.scope.index)
265
+ await store.updater.update(statements, [])
287
266
  }
288
267
  // ENDS
@@ -0,0 +1,57 @@
1
+ import { NamedNode } from "rdflib";
2
+ import { getArchiveUrl } from "../util/utils";
3
+
4
+ export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic) {
5
+
6
+ async function createInboxFor(peerWebId: string, nick: string) {
7
+ const myWebId: NamedNode = await profileLogic.loadMe();
8
+ const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
9
+ const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
10
+ await containerLogic.createContainer(ourInbox);
11
+ const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
12
+ await utilityLogic.setSinglePeerAccess({
13
+ ownerWebId: myWebId.value,
14
+ peerWebId,
15
+ accessToModes: 'acl:Append',
16
+ target: ourInbox
17
+ });
18
+ return ourInbox;
19
+ }
20
+
21
+ async function getNewMessages(
22
+ user?: NamedNode
23
+ ): Promise<string[]> {
24
+ if (!user) {
25
+ user = await profileLogic.loadMe();
26
+ }
27
+ const inbox = await profileLogic.getMainInbox(user);
28
+ const urls = await containerLogic.getContainerMembers(inbox.value);
29
+ return urls.filter(url => !containerLogic.isContainer(url));
30
+ }
31
+
32
+ async function markAsRead(url: string, date: Date) {
33
+ const downloaded = await store.fetcher._fetch(url);
34
+ if (downloaded.status !== 200) {
35
+ throw new Error(`Not OK! ${url}`);
36
+ }
37
+ const archiveUrl = getArchiveUrl(url, date);
38
+ const options = {
39
+ method: 'PUT',
40
+ body: await downloaded.text(),
41
+ headers: [
42
+ ['Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream']
43
+ ]
44
+ };
45
+ const uploaded = await store.fetcher._fetch(archiveUrl, options);
46
+ if (uploaded.status.toString()[0] === '2') {
47
+ await store.fetcher._fetch(url, {
48
+ method: 'DELETE'
49
+ });
50
+ }
51
+ }
52
+ return {
53
+ createInboxFor,
54
+ getNewMessages,
55
+ markAsRead
56
+ }
57
+ }
package/src/index.ts CHANGED
@@ -1,39 +1,92 @@
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
- import { solidLogicSingleton } from './logic/solidLogicSingleton'
4
- const authn = solidLogicSingleton.authn
5
- const authSession = solidLogicSingleton.authn.authSession
6
- const store = solidLogicSingleton.store
3
+ //import { solidLogicSingleton } from './logic/solidLogicSingleton'
4
+ //const authn = solidLogicSingleton.authn
5
+ //const authSession = solidLogicSingleton.authn.authSession
6
+ //const store = solidLogicSingleton.store
7
7
 
8
- const chat = solidLogicSingleton.chat
9
- const profile = solidLogicSingleton.profile
8
+ export {
9
+ ACL_LINK
10
+ } from './acl/aclLogic'
10
11
 
11
12
  export {
13
+ findAclDocUrl,
12
14
  setACLUserPublic,
13
- genACLText
14
- } from './acl/aclLogic'
15
+ genACLText,
16
+ } from './logic/solidLogicSingleton'
15
17
 
16
18
  export {
17
19
  ensureTypeIndexes,
18
20
  loadTypeIndexes,
19
21
  registerInTypeIndex,
20
- loadIndex
21
- } from './typeIndex/typeIndexLogic'
22
-
23
- export {
24
- loadProfile,
25
- loadPreferences,
22
+ loadIndex,
23
+ ensureOneTypeIndex,
24
+ putIndex,
25
+ makeIndexIfNecessary,
26
+ loadIndexes,
27
+ getTypeIndex,
28
+ getRegistrations,
29
+ //NEW function for discovery
26
30
  loadTypeIndexesFor,
27
31
  loadCommunityTypeIndexes,
28
- loadAllTypeIndexes
29
- } from './discovery/discoveryLogic'
32
+ loadAllTypeIndexes,
33
+ getScopedAppInstances,
34
+ getAppInstances,
35
+ suggestPublicTypeIndex,
36
+ suggestPrivateTypeIndex,
37
+ registerInstanceInTypeIndex,
38
+ deleteTypeIndexRegistration,
39
+ getScopedAppsFromIndex
40
+ } from './logic/solidLogicSingleton'
41
+
42
+ export {
43
+ setAcl,
44
+ addToPrivateTypeIndex,
45
+ findChat,
46
+ createChatThing,
47
+ getChat,
48
+ sendInvite,
49
+ mintNew
50
+ } from './logic/solidLogicSingleton'
30
51
 
31
- export { SolidLogic } from './logic/SolidLogic'
32
52
  export { offlineTestID, appContext } from './authn/authUtil'
33
- export { ACL_LINK } from './util/UtilityLogic'
53
+ export { createInboxFor, getNewMessages, markAsRead } from './logic/solidLogicSingleton'
54
+ export {
55
+ recursiveDelete,
56
+ setSinglePeerAccess,
57
+ createEmptyRdfDoc,
58
+ //NEW function for discovery
59
+ followOrCreateLink,
60
+ loadOrCreateIfNotExists,
61
+ } from './logic/solidLogicSingleton'
62
+
63
+ export {
64
+ ensureLoadedPreferences,
65
+ loadMe,
66
+ getPodRoot,
67
+ getMainInbox,
68
+ findStorage,
69
+ //NEW content from discovery
70
+ loadPreferences,
71
+ loadProfile,
72
+ //NEW function for discovery
73
+ silencedLoadPreferences
74
+ } from './logic/solidLogicSingleton'
75
+
34
76
  export { getSuggestedIssuers } from './issuer/issuerLogic'
77
+
78
+ export {
79
+ isContainer,
80
+ createContainer,
81
+ getContainerElements,
82
+ getContainerMembers
83
+ } from './logic/solidLogicSingleton'
84
+
85
+ export { authn, authSession, store } from './logic/solidLogicSingleton'
86
+
87
+ //export { SolidLogic } from './logic/SolidLogic'
35
88
  export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
36
89
  // solidLogicSingleton is exported entirely because it is used in solid-panes
37
- export { solidLogicSingleton } from './logic/solidLogicSingleton'
38
- export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
39
- export { authn, authSession, store, chat, profile }
90
+ //export { solidLogicSingleton } from './logic/solidLogicSingleton'
91
+ export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
92
+
@@ -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,20 +1,173 @@
1
- import * as debug from "../util/debug"
1
+ import * as rdf from "rdflib"
2
+ import { SolidAuthnLogic } from "../authn/SolidAuthnLogic"
2
3
  import { authSession } from "../authSession/authSession"
3
- import { SolidLogic } from "./SolidLogic"
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"
4
12
 
5
13
  const _fetch = async (url, requestInit) => {
6
14
  const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
7
15
  if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
8
- // In fact ftech should respect crentials omit itself
16
+ // In fact fetch should respect credentials omit itself
9
17
  return authSession.fetch(url, requestInit)
10
18
  } else {
11
19
  return window.fetch(url, requestInit)
12
20
  }
13
21
  }
14
22
 
15
- //this const makes solidLogicSingleton global accessible in mashlib
16
- const solidLogicSingleton = new SolidLogic({ fetch: _fetch }, authSession)
23
+ debug.log("SolidLogicSingleton: Unique instance created. There should only be one of these.")
24
+
25
+ const store = rdf.graph() as rdf.LiveStore; // Make a Quad store
26
+ rdf.fetcher(store, { fetch: _fetch}); // Attach a web I/O module, store.fetcher
27
+ store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
28
+ store.features = [] // disable automatic node merging on store load
29
+
30
+ debug.log('SolidAuthnLogic initialized')
31
+ const authn = new SolidAuthnLogic(authSession)
32
+
33
+ const aclLogic = createAclLogic(store)
34
+ const {
35
+ findAclDocUrl,
36
+ setACLUserPublic,
37
+ genACLText
38
+ } = aclLogic
39
+
40
+ const containerLogic = createContainerLogic(store)
41
+ const {
42
+ isContainer,
43
+ createContainer,
44
+ getContainerElements,
45
+ getContainerMembers
46
+ } = containerLogic
17
47
 
18
- debug.log('Unique quadstore initialized.')
48
+ const utilityLogic = createUtilityLogic(store, aclLogic, containerLogic)
49
+ const {
50
+ recursiveDelete,
51
+ setSinglePeerAccess,
52
+ createEmptyRdfDoc,
53
+ followOrCreateLink,
54
+ loadOrCreateIfNotExists
55
+ } = utilityLogic
56
+
57
+ const profileLogic = createProfileLogic(store, authn, utilityLogic)
58
+ const {
59
+ ensureLoadedPreferences,
60
+ loadMe,
61
+ getPodRoot,
62
+ getMainInbox,
63
+ findStorage,
64
+ loadPreferences,
65
+ loadProfile,
66
+ silencedLoadPreferences
67
+ } = profileLogic
68
+
69
+ const chatLogic = createChatLogic(store, profileLogic)
70
+ const {
71
+ setAcl,
72
+ addToPrivateTypeIndex,
73
+ findChat,
74
+ createChatThing,
75
+ getChat,
76
+ sendInvite,
77
+ mintNew
78
+ } = chatLogic
79
+
80
+ const inboxLogic = createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic)
81
+ const {
82
+ createInboxFor,
83
+ getNewMessages,
84
+ markAsRead
85
+ } = inboxLogic
86
+
87
+ const typeIndexLogic = createTypeIndexLogic(store, authn, profileLogic, utilityLogic)
88
+ const {
89
+ ensureTypeIndexes,
90
+ loadTypeIndexes,
91
+ registerInTypeIndex,
92
+ loadIndex,
93
+ ensureOneTypeIndex,
94
+ putIndex,
95
+ makeIndexIfNecessary,
96
+ loadIndexes,
97
+ getTypeIndex,
98
+ getRegistrations,
99
+ loadTypeIndexesFor,
100
+ loadCommunityTypeIndexes,
101
+ loadAllTypeIndexes,
102
+ getScopedAppInstances,
103
+ getAppInstances,
104
+ suggestPublicTypeIndex,
105
+ suggestPrivateTypeIndex,
106
+ registerInstanceInTypeIndex,
107
+ deleteTypeIndexRegistration,
108
+ getScopedAppsFromIndex
109
+ } = typeIndexLogic
110
+
111
+ export {
112
+ store,
113
+ authn,
114
+ authSession,
115
+ //unilityLogic
116
+ recursiveDelete,
117
+ setSinglePeerAccess,
118
+ createEmptyRdfDoc,
119
+ followOrCreateLink,
120
+ loadOrCreateIfNotExists,
121
+ //containerLogic
122
+ isContainer,
123
+ createContainer,
124
+ getContainerElements,
125
+ getContainerMembers,
126
+ //typeIndexLogic
127
+ ensureTypeIndexes,
128
+ loadTypeIndexes,
129
+ registerInTypeIndex,
130
+ loadIndex,
131
+ ensureOneTypeIndex,
132
+ putIndex,
133
+ makeIndexIfNecessary,
134
+ loadIndexes,
135
+ getTypeIndex,
136
+ getRegistrations,
137
+ loadTypeIndexesFor,
138
+ loadCommunityTypeIndexes,
139
+ loadAllTypeIndexes,
140
+ getScopedAppInstances,
141
+ getAppInstances,
142
+ suggestPublicTypeIndex,
143
+ suggestPrivateTypeIndex,
144
+ registerInstanceInTypeIndex,
145
+ deleteTypeIndexRegistration,
146
+ getScopedAppsFromIndex,
147
+ //profileLogic
148
+ ensureLoadedPreferences,
149
+ loadMe,
150
+ getPodRoot,
151
+ getMainInbox,
152
+ findStorage,
153
+ loadPreferences,
154
+ loadProfile,
155
+ silencedLoadPreferences,
156
+ //inboxLogic
157
+ createInboxFor,
158
+ getNewMessages,
159
+ markAsRead,
160
+ //chatLogic
161
+ setAcl,
162
+ addToPrivateTypeIndex,
163
+ findChat,
164
+ createChatThing,
165
+ getChat,
166
+ sendInvite,
167
+ mintNew,
168
+ //aclLogic
169
+ findAclDocUrl,
170
+ setACLUserPublic,
171
+ genACLText
172
+ }
19
173
 
20
- export { solidLogicSingleton }