Skip to content

Commit b15df38

Browse files
committed
working on new discovery
1 parent 23e59b8 commit b15df38

6 files changed

Lines changed: 111 additions & 122 deletions

File tree

.web_base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/solid/solid-ui/tree/main
1+
https://github.com/solidos/solid-ui/tree/main

src/chat/bookmarks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ function updatePromise (del, ins) {
8585
}) // promise
8686
}
8787

88-
// export findBookmarkDocument,
89-
9088
/* Bookmarking
9189
*/
9290
/** Find a user's bookmarks
@@ -96,7 +94,10 @@ export async function findBookmarkDocument (userContext) {
9694
const fileTail = 'bookmarks.ttl'
9795
const isPublic = true
9896

97+
console.log('@@ public bookmark userContext: before ', JSON.stringify(userContext))
9998
await findAppInstances(userContext, theClass, isPublic) // public -- only look for public links
99+
console.log('@@ public bookmark userContext: aftern ', JSON.stringify(userContext))
100+
100101
if (userContext.instances && userContext.instances.length > 0) {
101102
userContext.bookmarkDocument = userContext.instances[0]
102103
if (userContext.instances.length > 1) {

src/login/login.ts

Lines changed: 103 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ import { PaneDefinition } from 'pane-registry'
2626
import { BlankNode, NamedNode, st, Statement } from 'rdflib'
2727
// eslint-disable-next-line camelcase
2828
import { Quad_Object } from 'rdflib/lib/tf-types'
29-
import { AppDetails, AuthenticationContext, loadIndex, authn, authSession, CrossOriginForbiddenError, ensureTypeIndexes, FetchError, getSuggestedIssuers, NotFoundError, offlineTestID, SameOriginForbiddenError, solidLogicSingleton, UnauthorizedError } from 'solid-logic'
29+
import { AppDetails, AuthenticationContext, loadIndex, authn, authSession,
30+
CrossOriginForbiddenError, ensureTypeIndexes, FetchError, getSuggestedIssuers,
31+
discovery,
32+
NotFoundError, offlineTestID, SameOriginForbiddenError, solidLogicSingleton, UnauthorizedError } from 'solid-logic'
3033
import * as debug from '../debug'
3134
import { alert } from '../log'
3235
import * as ns from '../ns.js'
3336
import { Signup } from '../signup/signup.js'
3437
import { buttonStyle, commentStyle, textInputStyle } from '../style'
3538
import { utils } from '../utils/index'
3639
import * as widgets from '../widgets'
37-
40+
const { getScopedAppInstances, getAppInstances, registerInstanceInTypeIndex } = discovery
41+
const store = solidLogicSingleton.store
3842
/**
3943
* Resolves with the logged in user's WebID
4044
*
@@ -187,8 +191,9 @@ export async function findAppInstances (
187191
// console.log('found public & private app instance', context)
188192
return context
189193
}
190-
191194
// Loading preferences is more than loading profile
195+
196+
console.log('@@ 192 ', JSON.stringify(context))
192197
try {
193198
// console.log('calling logInLoad', isPublic)
194199
await (isPublic
@@ -205,30 +210,39 @@ export async function findAppInstances (
205210
} catch (err) {
206211
debug.error(err)
207212
}
213+
console.log('@@ 209 ', JSON.stringify(context))
214+
208215
const index = context.index as { [key: string]: Array<NamedNode> }
209216
const thisIndex = index[visibility]
217+
console.log('@@ ', visibility, ' thisIndex ', JSON.stringify(thisIndex))
218+
210219
const registrations = thisIndex
211220
.map(ix => solidLogicSingleton.store.each(undefined, ns.solid('forClass'), theClass, ix))
212221
.reduce((acc, curr) => acc.concat(curr), [])
213222
const instances = registrations
214223
.map(reg => solidLogicSingleton.store.each(reg as NamedNode, ns.solid('instance')))
215224
.reduce((acc, curr) => acc.concat(curr), [])
225+
console.log('@@ ', visibility, ' context.index ', JSON.stringify(context.index))
226+
216227
const containers = registrations
217228
.map(reg => solidLogicSingleton.store.each(reg as NamedNode, ns.solid('instanceContainer')))
218229
.reduce((acc, curr) => acc.concat(curr), [])
219-
230+
console.log('@@ ', visibility, ' instances ', JSON.stringify(instances))
220231
function unique (arr: NamedNode[]): NamedNode[] {
221232
return Array.from(new Set(arr))
222233
}
223234
context.instances = context.instances || []
224235
context.instances = unique(context.instances.concat(instances as NamedNode[]))
225-
236+
console.log('@@ ', visibility, ' context.index ', JSON.stringify(context.index))
237+
console.log('@@ ', visibility, ' instances 3 ', JSON.stringify(context.instances))
226238
context.containers = context.containers || []
227239
context.containers = unique(context.containers.concat(containers as NamedNode[]))
228240
if (!containers.length) {
229241
return context
230242
}
231243
// If the index gives containers, then look up all things within them
244+
console.log('@@ CONTAINERS ', JSON.stringify(containers))
245+
232246
try {
233247
await solidLogicSingleton.load(containers as NamedNode[])
234248
} catch (err) {
@@ -266,14 +280,15 @@ export async function registrationControl (
266280
box.innerHTML = '<p style="margin:2em;">(Log in to save a link to this)</p>'
267281
return context
268282
}
283+
const user = context.me
269284

270-
let context2 // @@ const
285+
let scopes // @@ const
271286
try {
272-
context2 = await ensureTypeIndexes(context)
287+
scopes = loadAllTypeIndexes(store, me)
273288
} catch (e) {
274289
let msg
275290
if (context.div && context.preferencesFileError) {
276-
msg = '(Preferences not available)'
291+
msg = '(Lists of stuff not available)'
277292
context.div.appendChild(dom.createElement('p')).textContent = msg
278293
} else if (context.div) {
279294
msg = `registrationControl: Type indexes not available: ${e}`
@@ -282,12 +297,12 @@ export async function registrationControl (
282297
debug.log(msg)
283298
}
284299

285-
box.innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>' // tbody will be inserted anyway
300+
box.innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
286301
box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;')
287302
const tbody = box.children[0].children[0]
288303
const form = new BlankNode() // @@ say for now
289304

290-
const registrationStatements = function (index) {
305+
function registrationStatements (index) {
291306
const registrations = solidLogicSingleton.getRegistrations(instance, theClass)
292307
const reg = registrations.length
293308
? registrations[0]
@@ -298,23 +313,33 @@ export async function registrationControl (
298313
]
299314
}
300315

301-
let index, statements
316+
function renderScope (scope) {
317+
const statements = registrationStatements(scope.index)
318+
const name = scope.agent.sameTerm(me) ? '' : label(scope.agent) + ' '
319+
widgets.buildCheckboxForm(
320+
context2.dom,
321+
solidLogicSingleton.store,
322+
`${name}${scope.label} link to this ${context2.noun}`,
323+
null,
324+
statements,
325+
form,
326+
scope.index
327+
)
328+
}
302329

330+
for const scope of scopes {
331+
const row = tbody.appendChild(dom.createElement('tr'))
332+
row.appendChild(renderScope(scope)) // @@ index
333+
}
334+
/*
303335
try {
304336
if (context2.index && context2.index.public && context2.index.public.length > 0) {
305337
index = context2.index.public[0]
338+
339+
306340
statements = registrationStatements(index)
307341
tbody.children[0].appendChild(
308-
widgets.buildCheckboxForm(
309-
context2.dom,
310-
solidLogicSingleton.store,
311-
`Public link to this ${context2.noun}`,
312-
null,
313-
statements,
314-
form,
315-
index
316-
)
317-
)
342+
318343
}
319344
320345
if (context2.index && context2.index.private && context2.index.private.length > 0) {
@@ -339,6 +364,7 @@ export async function registrationControl (
339364
}
340365
debug.log(msg)
341366
}
367+
*/
342368
return context2
343369
}
344370

@@ -361,67 +387,67 @@ export async function registrationList (context0: AuthenticationContext, options
361387
return context0
362388
}
363389

364-
return ensureTypeIndexes(context0).then(context => {
365-
box.innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
366-
box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;')
367-
const table = box.firstChild as HTMLElement
368-
369-
let ix: Array<NamedNode> = []
370-
let sts: Statement[] = []
371-
const vs = ['private', 'public']
372-
vs.forEach(function (visibility) {
373-
if (context.index && context.index[visibility].length > 0 && options[visibility]) {
374-
ix = ix.concat(context.index[visibility][0])
375-
sts = sts.concat(
376-
solidLogicSingleton.store.statementsMatching(
377-
undefined,
378-
ns.solid('instance'),
379-
undefined,
380-
context.index[visibility][0]
381-
)
390+
const scopes = loadAllTypeIndexes(store, me) // includes community indexes
391+
392+
box.innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
393+
box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;')
394+
const table = box.firstChild as HTMLElement
395+
396+
let ix: Array<NamedNode> = []
397+
let sts: Statement[] = []
398+
scopes.forEach(function (scope) {
399+
if (context.index && context.index[visibility].length > 0 && options[visibility]) {
400+
ix = ix.concat(context.index[visibility][0])
401+
sts = sts.concat(
402+
solidLogicSingleton.store.statementsMatching(
403+
undefined,
404+
ns.solid('instance'),
405+
undefined,
406+
scope.index
382407
)
383-
}
384-
})
408+
)
409+
}
410+
})
385411

386-
for (let i = 0; i < sts.length; i++) {
387-
const statement: Statement = sts[i]
388-
if (options.type) { // now check terms:forClass
389-
if (!solidLogicSingleton.store.holds(statement.subject, ns.solid('forClass'), options.type, statement.why)) {
390-
continue // skip irrelevant ones
391-
}
412+
for (let i = 0; i < sts.length; i++) {
413+
const statement: Statement = sts[i]
414+
if (options.type) { // now check terms:forClass
415+
if (!solidLogicSingleton.store.holds(statement.subject, ns.solid('forClass'), options.type, statement.why)) {
416+
continue // skip irrelevant ones
392417
}
393-
// const cla = statement.subject
394-
const inst = statement.object
395-
table.appendChild(widgets.personTR(dom, ns.solid('instance'), inst, {
396-
deleteFunction: function (_x) {
397-
if (!solidLogicSingleton.store.updater) {
398-
throw new Error('Cannot delete this, store has no updater')
399-
}
400-
solidLogicSingleton.store.updater.update([statement], [], function (uri, ok, errorBody) {
401-
if (ok) {
402-
debug.log(`Removed from index: ${statement.subject}`)
403-
} else {
404-
debug.log(`Error: Cannot delete ${statement}: ${errorBody}`)
405-
}
406-
})
407-
}
408-
}))
409-
} // registrationList
410-
411-
/*
412-
//const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
413-
if (containers.length) {
414-
fetcher.load(containers).then(function(xhrs){
415-
for (const i=0; i<containers.length; i++) {
416-
const cont = containers[i];
417-
instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
418-
}
419-
});
418+
}
419+
// const cla = statement.subject
420+
const inst = statement.object
421+
table.appendChild(widgets.personTR(dom, ns.solid('instance'), inst, {
422+
deleteFunction: function (_x) {
423+
if (!solidLogicSingleton.store.updater) {
424+
throw new Error('Cannot delete this, store has no updater')
420425
}
421-
*/
426+
solidLogicSingleton.store.updater.update([statement], [], function (uri, ok, errorBody) {
427+
if (ok) {
428+
debug.log(`Removed from index: ${statement.subject}`)
429+
} else {
430+
debug.log(`Error: Cannot delete ${statement}: ${errorBody}`)
431+
}
432+
})
433+
}
434+
}))
435+
} // registrationList
436+
437+
/*
438+
//const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
439+
if (containers.length) {
440+
fetcher.load(containers).then(function(xhrs){
441+
for (const i=0; i<containers.length; i++) {
442+
const cont = containers[i];
443+
instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
444+
}
445+
});
446+
}
447+
*/
448+
449+
return context
422450

423-
return context
424-
})
425451
}
426452

427453
function getDefaultSignInButtonStyle (): string {

src/widgets/forms.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,16 @@ field[ns.ui('Choice').uri] = function (
802802
let object = kb.any(subject, property)
803803
function addSubForm () {
804804
object = kb.any(subject, property)
805-
fieldFunction(dom, subForm)(
805+
const subFormElement = fieldFunction(dom, subForm)(
806806
dom,
807-
rhs,
807+
null,
808808
already,
809809
object,
810810
subForm,
811811
follow ? object.doc() : dataDoc,
812812
callbackFunction
813813
)
814+
rhs.appendChild(subFormElement)
814815
}
815816
const possible2 = sortByLabel(possible)
816817
if (kb.any(form, ui('canMintNew'))) {
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`findBookmarkDocument complains if you have multiple bookmark docs 1`] = `"More than one bookmark file! <http://example.com/bookmarks2.ttl>,<http://example.com/bookmarks3.ttl>"`;
4-
5-
exports[`findBookmarkDocument complains if you have multiple bookmark docs 2`] = `"More than one bookmark file! <http://example.com/bookmarks2.ttl>,<http://example.com/bookmarks3.ttl>"`;
3+
exports[`findBookmarkDocument complains if you have multiple bookmark docs 1`] = `"More than one bookmark file! <http://example.com/bookmarks2.ttl>,<http://example.com/bookmarks3.ttl>,<http://example.com/bookmarks1.ttl>"`;

test/unit/chat/bookmarks.test.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -98,44 +98,7 @@ describe('findBookmarkDocument', () => {
9898
expect((window.alert as any).mock.calls.length).toEqual(1)
9999
expect((window.alert as any).mock.calls[0][0]).toMatchSnapshot()
100100
})
101-
it('complains if you have multiple bookmark docs', async () => {
102-
const privReg = new NamedNode('http://example.com/privType.ttl#reg1')
103-
const pubReg1 = new NamedNode('http://example.com/pubType.ttl#reg1')
104-
const pubReg2 = new NamedNode('http://example.com/pubType.ttl#reg2')
105-
const bookmarksDoc1 = new NamedNode('http://example.com/bookmarks1.ttl')
106-
const bookmarksDoc2 = new NamedNode('http://example.com/bookmarks2.ttl')
107-
const bookmarksDoc3 = new NamedNode('http://example.com/bookmarks3.ttl')
108-
const context = {
109-
me: new NamedNode('http://example.com/profile/card#me'),
110-
publicProfile: new NamedNode('http://example.com/profile/card'),
111-
preferencesFile: new NamedNode('http://example.com/prefs.ttl'),
112-
privateTypeIndex: new NamedNode('http://example.com/privType.ttl'),
113-
publicTypeIndex: new NamedNode('http://example.com/pubType.ttl')
114-
}
115101

116-
window.alert = jest.fn()
117-
store.add(context.me, ns.space('preferencesFile'), context.preferencesFile, context.publicProfile)
118-
// announce private index in settings:
119-
store.add(context.me, ns.solid('privateTypeIndex'), context.privateTypeIndex, context.preferencesFile)
120-
// announce public index in profile:
121-
store.add(context.me, ns.solid('publicTypeIndex'), context.publicTypeIndex, context.publicProfile)
122-
123-
store.add(privReg, ns.rdf('type'), ns.solid('TypeRegistration'), context.privateTypeIndex)
124-
store.add(privReg, ns.solid('forClass'), BOOK('Bookmark'), context.privateTypeIndex)
125-
store.add(privReg, ns.solid('instance'), bookmarksDoc1, context.privateTypeIndex)
126-
127-
store.add(pubReg1, ns.rdf('type'), ns.solid('TypeRegistration'), context.publicTypeIndex)
128-
store.add(pubReg1, ns.solid('forClass'), BOOK('Bookmark'), context.publicTypeIndex)
129-
store.add(pubReg1, ns.solid('instance'), bookmarksDoc2, context.publicTypeIndex)
130-
131-
store.add(pubReg2, ns.rdf('type'), ns.solid('TypeRegistration'), context.publicTypeIndex)
132-
store.add(pubReg2, ns.solid('forClass'), BOOK('Bookmark'), context.publicTypeIndex)
133-
store.add(pubReg2, ns.solid('instance'), bookmarksDoc3, context.publicTypeIndex)
134-
135-
await findBookmarkDocument(context)
136-
expect((window.alert as any).mock.calls.length).toEqual(1)
137-
expect((window.alert as any).mock.calls[0][0]).toMatchSnapshot()
138-
})
139102
it('does not complains if you have one bookmark docs', async () => {
140103
const privReg = new NamedNode('http://example.com/privType.ttl#reg1')
141104
const pubReg1 = new NamedNode('http://example.com/pubType.ttl#reg1')

0 commit comments

Comments
 (0)