Skip to content

Commit aaf3e9a

Browse files
committed
remove skip
1 parent e1042e7 commit aaf3e9a

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

src/discovery/discoveryLogic.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NamedNode, Namespace, LiveStore, sym, st } from "rdflib";
22
// import * as debug from '../util/debug'
33
// import { getContainerMembers } from '../util/UtilityLogic'
44
import { solidLogicSingleton } from "../logic/solidLogicSingleton"
5+
import { newThing } from "../util/uri"
56

67
const { authn } = solidLogicSingleton
78
const { currentUser } = authn
@@ -278,5 +279,33 @@ export async function getAppInstances (store:LiveStore, klass: NamedNode): Promi
278279
const scopedAppInstances = await getScopedAppInstances(store, klass, user)
279280
return scopedAppInstances.map(scoped => scoped.instance)
280281
}
281-
282+
/**
283+
* Register a new app in a type index
284+
* used in chat in bookmark.js (solid-ui)
285+
* Returns the registration object if successful else null
286+
*/
287+
export async function registerInstanceInTypeIndex (
288+
store:LiveStore,
289+
instance: NamedNode,
290+
index: NamedNode,
291+
theClass: NamedNode,
292+
// agent: NamedNode
293+
): Promise<NamedNode | null> {
294+
const registration = newThing(index)
295+
const ins = [
296+
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
297+
st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
298+
st(registration, ns.solid('forClass'), theClass, index),
299+
st(registration, ns.solid('instance'), instance, index)
300+
]
301+
try {
302+
console.log('patching index', ins)
303+
await store.updater.update([], ins)
304+
} catch (err) {
305+
const msg = `Unable to register ${instance} in index ${index}: ${err}`
306+
console.warn(msg)
307+
return null
308+
}
309+
return registration
310+
}
282311
// ENDS

test/discoveryLogic.test.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { solidLogicSingleton } from "../src/logic/solidLogicSingleton"
88
import fetchMock from "jest-fetch-mock";
99

1010
import { loadOrCreateIfNotExists, makePreferencesFileURI, followOrCreateLink, loadCommunityTypeIndexes,
11-
getAppInstances, getScopedAppInstances, loadTypeIndexesFor, loadPreferences,
11+
getAppInstances, getScopedAppInstances, loadTypeIndexesFor, loadPreferences, registerInstanceInTypeIndex,
1212
uniqueNodes, loadProfile } from '../src/discovery/discoveryLogic.ts'
1313

1414
const { getContainerMembers, authn, store } = solidLogicSingleton
@@ -244,11 +244,11 @@ describe('uniqueNodes', () => {
244244
expect(requests).toEqual([])
245245

246246
})
247-
it.skip('creates empty file if did not exist', async () => {
248-
const result = await loadOrCreateIfNotExists(store, Bob.doc())
249-
// console.log('@@@@@ test requests', requests)
247+
it('creates empty file if did not exist', async () => {
248+
const newFile = sym(Bob.doc().uri + /refhoijhoegg/)
249+
const result = await loadOrCreateIfNotExists(store, newFile)
250250
expect(requests[0].method).toEqual('PUT')
251-
expect(requests[0].url).toEqual(Bob.doc().uri)
251+
expect(requests[0].url).toEqual(newFile.uri)
252252
})
253253
})
254254

@@ -697,16 +697,33 @@ const TRACKERS =
697697
it('exists', () => {
698698
expect(getAppInstances).toBeInstanceOf(Function)
699699
})
700-
it('finds trackers', async () => { // needs auth mock
700+
it('finds trackers', async () => {
701701
const result = await getAppInstances(store, Tracker)
702702
expect(result).toEqual(TRACKERS)
703703
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
704704
})
705-
it('finds images in containers', async () => { // needs auth mock
705+
it('finds images in containers', async () => {
706706
const result = await getAppInstances(store, Image)
707707
expect(result.length).toEqual(3)
708708
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
709709
expect(result.map(x => x.uri).join()).toEqual("https://alice.example.com/profile/Photos/photo1.png,https://alice.example.com/profile/Photos/photo2.png,https://alice.example.com/profile/Photos/photo3.png")
710710
})
711711
})
712+
713+
describe('registerInstanceInTypeIndex', () => {
714+
it('exists', () => {
715+
expect(registerInstanceInTypeIndex).toBeInstanceOf(Function)
716+
})
717+
it('adds a registration', async () => {
718+
const instance = sym(Alice.doc().uri + 'trackers/myToDo.ttl#this')
719+
const index = AlicePublicTypeIndex
720+
const result = await registerInstanceInTypeIndex(store, instance, index, klass)
721+
expect(result.doc()).toEqual(index)
722+
expect(store.any(result, ns.solid('forClass'), null, index)).toEqual(klass)
723+
expect(store.any(result, ns.solid('instance'), null, index)).toEqual(instance)
724+
expect(store.holds(result, ns.rdf('type'), ns.solid('TypeRegistration'), index)).toEqual(true)
725+
expect(requests[0].url).toEqual(index.uri)
726+
})
727+
})
728+
712729
})

0 commit comments

Comments
 (0)