solid-logic 1.3.17-a27c1702 → 1.3.17-cd4cd566

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 (49) hide show
  1. package/lib/acl/aclLogic.d.ts +2 -11
  2. package/lib/acl/aclLogic.d.ts.map +1 -1
  3. package/lib/acl/aclLogic.js.map +1 -1
  4. package/lib/chat/chatLogic.d.ts +2 -15
  5. package/lib/chat/chatLogic.d.ts.map +1 -1
  6. package/lib/chat/chatLogic.js +8 -7
  7. package/lib/chat/chatLogic.js.map +1 -1
  8. package/lib/inbox/inboxLogic.d.ts +2 -6
  9. package/lib/inbox/inboxLogic.d.ts.map +1 -1
  10. package/lib/inbox/inboxLogic.js.map +1 -1
  11. package/lib/index.d.ts +4 -18
  12. package/lib/index.d.ts.map +1 -1
  13. package/lib/index.js +2 -86
  14. package/lib/index.js.map +1 -1
  15. package/lib/logic/SolidLogic.d.ts +4 -20
  16. package/lib/logic/SolidLogic.d.ts.map +1 -1
  17. package/lib/logic/SolidLogic.js +37 -32
  18. package/lib/logic/SolidLogic.js.map +1 -1
  19. package/lib/logic/solidLogicSingleton.d.ts +1 -2
  20. package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
  21. package/lib/logic/solidLogicSingleton.js +1 -1
  22. package/lib/logic/solidLogicSingleton.js.map +1 -1
  23. package/lib/profile/profileLogic.d.ts +2 -12
  24. package/lib/profile/profileLogic.d.ts.map +1 -1
  25. package/lib/profile/profileLogic.js +1 -23
  26. package/lib/profile/profileLogic.js.map +1 -1
  27. package/lib/typeIndex/typeIndexLogic.d.ts +2 -31
  28. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
  29. package/lib/typeIndex/typeIndexLogic.js +12 -359
  30. package/lib/typeIndex/typeIndexLogic.js.map +1 -1
  31. package/lib/types.d.ts +65 -1
  32. package/lib/types.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/acl/aclLogic.ts +5 -4
  35. package/src/chat/chatLogic.ts +7 -7
  36. package/src/inbox/inboxLogic.ts +2 -1
  37. package/src/index.ts +3 -146
  38. package/src/logic/SolidLogic.ts +36 -42
  39. package/src/logic/solidLogicSingleton.ts +2 -2
  40. package/src/profile/profileLogic.ts +4 -12
  41. package/src/typeIndex/typeIndexLogic.ts +6 -277
  42. package/src/types.ts +76 -1
  43. package/test/typeIndexLogic.test.ts +484 -54
  44. package/lib/logic/solidLogicSingletonNew.d.ts +0 -80
  45. package/lib/logic/solidLogicSingletonNew.d.ts.map +0 -1
  46. package/lib/logic/solidLogicSingletonNew.js +0 -238
  47. package/lib/logic/solidLogicSingletonNew.js.map +0 -1
  48. package/src/logic/solidLogicSingletonNew.ts +0 -239
  49. package/test/typeIndexLogicPart2.test.ts +0 -485
@@ -1,273 +1,11 @@
1
- import * as rdf from "rdflib"
2
- import { NamedNode, st, Statement, sym } from 'rdflib'
3
- import { AuthenticationContext, ScopedApp, TypeIndexScope } from '../types'
1
+ import { NamedNode, st, sym } from 'rdflib'
2
+ import { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'
4
3
  import * as debug from "../util/debug"
5
- import {ns as namespace } from '../util/ns'
4
+ import { ns as namespace } from '../util/ns'
6
5
  import { newThing, uniqueNodes } from "../util/utils"
7
6
 
8
- export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
7
+ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {
9
8
  const ns = namespace
10
-
11
- function updatePromise(
12
- del: Array<Statement>,
13
- ins: Array<Statement> = []
14
- ): Promise<void> {
15
- return new Promise((resolve, reject) => {
16
- store.updater.update(del, ins, function (_uri, ok, errorBody) {
17
- if (!ok) {
18
- reject(new Error(errorBody));
19
- } else {
20
- resolve();
21
- }
22
- }); // callback
23
- }); // promise
24
- }
25
- /**
26
- * Resolves with the same context, outputting
27
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
28
- */
29
- async function ensureTypeIndexes(context: AuthenticationContext, agent?: NamedNode): Promise<AuthenticationContext> {
30
- if (!context.me) {
31
- throw new Error(`ensureTypeIndexes: @@ no user`)
32
- }
33
- await ensureOneTypeIndex(context, true, agent)
34
- await ensureOneTypeIndex(context, false, agent)
35
- return context
36
- }
37
-
38
- async function loadTypeIndexes(context: AuthenticationContext) {
39
- try {
40
- await profileLogic.silencedLoadPreferences(context.me as NamedNode)
41
- } catch (error) {
42
- debug.warn(error.message) as undefined
43
- }
44
- try {
45
- const indexes = await loadIndexes(
46
- context.me as NamedNode,
47
- context.publicProfile || null,
48
- context.preferencesFile || null,
49
- // async (err: Error) => widgets.complain(context, err.message)
50
- // async (err: Error) => debug.warn(err.message) as undefined
51
- )
52
- context.index = context.index || {}
53
- context.index.private = indexes.private || context.index.private
54
- context.index.public = indexes.public || context.index.public
55
- return context
56
- } catch (error) {
57
- async (error: Error) => debug.warn(error.message) as undefined
58
- }
59
- }
60
-
61
- /**
62
- * Register a new app in a type index
63
- * used in chat in bookmark.js (solid-ui)
64
- */
65
- async function registerInTypeIndex(
66
- context: AuthenticationContext,
67
- instance: NamedNode,
68
- theClass: NamedNode,
69
- isPublic: boolean,
70
- agent?: NamedNode // Defaults to current user
71
- ): Promise<AuthenticationContext> {
72
- await ensureOneTypeIndex(context, isPublic, agent)
73
- if (!context.index) {
74
- throw new Error('registerInTypeIndex: No type index found')
75
- }
76
- const indexes = isPublic ? context.index.public : context.index.private
77
- if (!indexes.length) {
78
- throw new Error('registerInTypeIndex: What no type index?')
79
- }
80
- const index = indexes[0]
81
- const registration = newThing(index)
82
- const ins = [
83
- // See https://github.com/solidos/solid/blob/main/proposals/data-discovery.md
84
- st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
85
- st(registration, ns.solid('forClass'), theClass, index),
86
- st(registration, ns.solid('instance'), instance, index)
87
- ]
88
- try {
89
- await updatePromise([], ins)
90
- } catch (e) {
91
- debug.log(e)
92
- alert(e)
93
- }
94
- return context
95
- }
96
-
97
- /**
98
- * Resolves with the same context, outputting
99
- * output: index.public, index.private
100
- * @@ This is a very bizare function
101
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
102
- */
103
- async function loadIndex(
104
- context: AuthenticationContext,
105
- isPublic: boolean
106
- ): Promise<AuthenticationContext> {
107
- const indexes = await loadIndexes(
108
- context.me as NamedNode,
109
- (isPublic ? context.publicProfile || null : null),
110
- (isPublic ? null : context.preferencesFile || null),
111
- // async (err: Error) => widgets.complain(context, err.message)
112
- async (err: Error) => debug.error(err.message) as undefined
113
- )
114
- context.index = context.index || {}
115
- context.index.private = indexes.private.concat(context.index.private || []) // otherwise concat will wrongly add 'undefined' as a private index
116
- context.index.public = indexes.public.concat(context.index.public || []) // otherwise concat will wrongly add 'undefined' as a public index
117
- return context
118
- }
119
-
120
- /**
121
- * Load or create ONE type index
122
- * Find one or make one or fail
123
- * Many reasons for failing including script not having permission etc
124
- *
125
- * Adds its output to the context
126
- * @see https://github.com/solidos/solid/blob/main/proposals/data-discovery.md#discoverability
127
- */
128
- async function ensureOneTypeIndex(context: AuthenticationContext, isPublic: boolean, agent?: NamedNode): Promise<AuthenticationContext | void> {
129
-
130
- const context2 = await profileLogic.ensureLoadedPreferences(context)
131
- if (!context2.publicProfile) throw new Error(`@@ type index: no publicProfile`)
132
- if (!context2.preferencesFile) throw new Error(`@@ type index: no preferencesFile for profile ${context2.publicProfile}`)
133
- const relevant = isPublic ? context2.publicProfile : context2.preferencesFile
134
-
135
- try {
136
- await loadIndex(context2, isPublic)
137
- const pp = isPublic ? 'public' : 'private'
138
- if (context2.index && context2.index[pp] && context2.index[pp].length > 0) {
139
- debug.log(`ensureOneTypeIndex: Type index exists already ${context2.index[pp]}`)
140
- return context2
141
- }
142
- await makeIndexIfNecessary(context2, isPublic, store, ns)
143
- } catch (error) {
144
- await makeIndexIfNecessary(context2, isPublic, store, ns)
145
- // widgets.complain(context2, 'calling loadIndex:' + error)
146
- }
147
- }
148
-
149
- async function putIndex(newIndex, context) {
150
- try {
151
- await utilityLogic.createEmptyRdfDoc(newIndex, 'Blank initial Type index')
152
- return context
153
- } catch (e) {
154
- const msg = `Error creating new index ${e}`
155
- // widgets.complain(context, msg)
156
- debug.warn(msg)
157
- }
158
- } // putIndex
159
-
160
- async function makeIndexIfNecessary(context, isPublic, store, ns) {
161
- const relevant = isPublic ? context.publicProfile : context.preferencesFile
162
- if (!relevant) alert('@@@@ relevent null')
163
- const visibility = isPublic ? 'public' : 'private'
164
-
165
- context.index = context.index || {}
166
- context.index[visibility] = context.index[visibility] || []
167
- let newIndex
168
- if (context.index[visibility].length === 0) {
169
- if (!store.updater.editable(relevant)) {
170
- debug.log(`Not adding new type index as ${relevant} is not editable`)
171
- return
172
- }
173
- newIndex = rdf.sym(`${relevant.dir().uri + visibility}TypeIndex.ttl`)
174
- debug.log(`Linking to new fresh type index ${newIndex}`)
175
- if (!confirm(`OK to create a new empty index file at ${newIndex}, overwriting anything that is now there?`)) {
176
- throw new Error('cancelled by user')
177
- }
178
- debug.log(`Linking to new fresh type index ${newIndex}`)
179
- const addMe = [
180
- st(context.me, ns.solid(`${visibility}TypeIndex`), newIndex, relevant)
181
- ]
182
- try {
183
- await updatePromise([], addMe)
184
- } catch (err) {
185
- const msg = `Error saving type index link saving back ${newIndex}: ${err}`
186
- //widgets.complain(context, msg)
187
- debug.warn(msg)
188
- return context
189
- }
190
-
191
- debug.log(`Creating new fresh type index file${newIndex}`)
192
- await putIndex(newIndex, context)
193
- context.index[visibility].push(newIndex) // @@ wait
194
- } else {
195
- // officially exists
196
- const ixs = context.index[visibility]
197
- try {
198
- await store.fetcher.load(ixs)
199
- } catch (err) {
200
- const msg = `ensureOneTypeIndex: loading indexes ${err}`
201
- debug.warn(msg)
202
- // widgets.complain(context, `ensureOneTypeIndex: loading indexes ${err}`)
203
- }
204
- }
205
- } // makeIndexIfNecessary
206
-
207
- async function loadIndexes(
208
- me: NamedNode | string,
209
- publicProfile: NamedNode | string | null,
210
- preferencesFile: NamedNode | string | null,
211
- onWarning = async (_err: Error) => {
212
- return undefined;
213
- }
214
- ): Promise<{
215
- private: any;
216
- public: any;
217
- }> {
218
- let privateIndexes: any[] = [];
219
- let publicIndexes: any[] = [];
220
- if (publicProfile) {
221
- publicIndexes = getTypeIndex(me, publicProfile, true);
222
- try {
223
- await store.fetcher.load(publicIndexes as NamedNode[]);
224
- } catch (err) {
225
- onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
226
- }
227
- }
228
- if (preferencesFile) {
229
- privateIndexes = getTypeIndex(me, preferencesFile, false);
230
- // console.log({ privateIndexes })
231
- if (privateIndexes.length === 0) {
232
- await onWarning(
233
- new Error(
234
- `Your preference file ${preferencesFile} does not point to a private type index.`
235
- )
236
- );
237
- } else {
238
- try {
239
- await store.fetcher.load(privateIndexes);
240
- } catch (err) {
241
- onWarning(
242
- new Error(`loadIndex: loading private type index(es) ${err}`)
243
- );
244
- }
245
- }
246
- // } else {
247
- // debug.log(
248
- // 'We know your preference file is not available, so we are not bothering with private type indexes.'
249
- // )
250
- }
251
-
252
- return {
253
- private: privateIndexes,
254
- public: publicIndexes,
255
- };
256
- }
257
-
258
- function getTypeIndex(
259
- me: NamedNode | string,
260
- preferencesFile: NamedNode | string,
261
- isPublic: boolean
262
- ): NamedNode[] {
263
- // console.log('getTypeIndex', store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
264
- return store.each(
265
- me as NamedNode,
266
- isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
267
- undefined,
268
- preferencesFile as NamedNode
269
- ) as NamedNode[];
270
- }
271
9
 
272
10
  function getRegistrations(instance, theClass) {
273
11
  return store
@@ -385,7 +123,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
385
123
  * used in chat in bookmark.js (solid-ui)
386
124
  * Returns the registration object if successful else null
387
125
  */
388
- async function registerInstanceInTypeIndex(
126
+ async function registerInTypeIndex(
389
127
  instance: NamedNode,
390
128
  index: NamedNode,
391
129
  theClass: NamedNode,
@@ -415,7 +153,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
415
153
  await store.updater.update(statements, [])
416
154
  }
417
155
 
418
- async function getScopedAppsFromIndex(scope, theClass: NamedNode | null) {
156
+ async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {
419
157
  const index = scope.index
420
158
  const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
421
159
  .concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
@@ -441,15 +179,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
441
179
  }
442
180
 
443
181
  return {
444
- ensureTypeIndexes,
445
- loadTypeIndexes,
446
182
  registerInTypeIndex,
447
- loadIndex,
448
- ensureOneTypeIndex,
449
- putIndex,
450
- makeIndexIfNecessary,
451
- loadIndexes,
452
- getTypeIndex,
453
183
  getRegistrations,
454
184
  loadTypeIndexesFor,
455
185
  loadCommunityTypeIndexes,
@@ -458,7 +188,6 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic) {
458
188
  getAppInstances,
459
189
  suggestPublicTypeIndex,
460
190
  suggestPrivateTypeIndex,
461
- registerInstanceInTypeIndex,
462
191
  deleteTypeIndexRegistration,
463
192
  getScopedAppsFromIndex
464
193
  }
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Session } from "@inrupt/solid-client-authn-browser"
2
- import { NamedNode } from "rdflib"
2
+ import { LiveStore, NamedNode, Statement } from "rdflib"
3
3
 
4
4
  export type AppDetails = {
5
5
  noun: string
@@ -45,3 +45,78 @@ export interface CreatedPaneOptions {
45
45
  newInstance: NamedNode;
46
46
  }
47
47
 
48
+ export interface ChatLogic {
49
+ setAcl: (chatContainer: NamedNode, me: NamedNode, invitee: NamedNode) => Promise<void>,
50
+ addToPrivateTypeIndex: (chatThing, me) => void | Promise<void>,
51
+ findChat: (invitee: NamedNode) => Promise<Chat>,
52
+ createChatThing: (chatContainer: NamedNode, me: NamedNode) => Promise<NamedNode>,
53
+ mintNew: (newPaneOptions: NewPaneOptions) => Promise<CreatedPaneOptions>,
54
+ getChat: (invitee: NamedNode, boolean) => Promise<NamedNode | null>,
55
+ sendInvite: (invitee: NamedNode, chatThing: NamedNode) => void
56
+ }
57
+
58
+ export interface Chat {
59
+ me: NamedNode,
60
+ chatContainer: NamedNode,
61
+ exists: boolean
62
+ }
63
+
64
+ export interface ProfileLogic {
65
+ silencedLoadPreferences: (user: NamedNode) => Promise<NamedNode | undefined>,
66
+ loadPreferences: (user: NamedNode) => Promise<NamedNode>,
67
+ loadProfile: (user: NamedNode) => Promise<NamedNode>,
68
+ loadMe: () => Promise<NamedNode>,
69
+ getPodRoot: (user: NamedNode) => NamedNode,
70
+ getMainInbox: (user: NamedNode) => Promise<NamedNode>,
71
+ findStorage: (me: NamedNode) => Node | null
72
+ }
73
+
74
+ export interface AclLogic {
75
+ findAclDocUrl: (url: string) => Promise<any>,
76
+ setACLUserPublic: (docURI: string, me: NamedNode,
77
+ options: {
78
+ defaultForNew?: boolean,
79
+ public?: []
80
+ }
81
+ ) => Promise<NamedNode>,
82
+ genACLText: (docURI: string, me: NamedNode, aclURI: string,
83
+ options: {
84
+ defaultForNew?: boolean,
85
+ public?: []
86
+ }
87
+ ) => string | undefined
88
+ }
89
+
90
+ export interface InboxLogic {
91
+ createInboxFor: (peerWebId: string, nick: string) => Promise<string>,
92
+ getNewMessages: (user?: NamedNode) => Promise<string[]>,
93
+ markAsRead: (url: string, date: Date) => void
94
+ }
95
+
96
+ export interface TypeIndexLogic {
97
+ getRegistrations: (instance, theClass) => Promise<NamedNode>,
98
+ loadTypeIndexesFor: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
99
+ loadCommunityTypeIndexes: (user: NamedNode) => Promise<TypeIndexScope[][]>,
100
+ loadAllTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
101
+ getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise<ScopedApp[]>,
102
+ getAppInstances: (klass: NamedNode) => Promise<NamedNode[]>,
103
+ suggestPublicTypeIndex: (me: NamedNode) => NamedNode,
104
+ suggestPrivateTypeIndex: (preferencesFile: NamedNode) => NamedNode,
105
+ registerInTypeIndex: (instance: NamedNode, index: NamedNode, theClass: NamedNode) => Promise<NamedNode | null>,
106
+ deleteTypeIndexRegistration: (item: any) => Promise<void>
107
+ getScopedAppsFromIndex: (scope: TypeIndexScope, theClass: NamedNode | null) => Promise<ScopedApp[]>
108
+ }
109
+
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
121
+ }
122
+