Skip to content

Commit d73984d

Browse files
committed
respond to comments in PR
1 parent 3dc29cf commit d73984d

2 files changed

Lines changed: 26 additions & 290 deletions

File tree

src/typeIndex/typeIndexLogic.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -159,44 +159,24 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
159159
const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
160160
.concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
161161
.map(st => st.subject)
162-
const relevant = theClass ? registrations.filter(reg => store.any(reg, ns.solid('forClass'), null, index)?.sameTerm(theClass))
163-
: registrations
164-
165-
for (const reg of relevant) {
162+
for (const reg of registrations) {
166163
const klass = store.any(reg, ns.solid('forClass'), null, index)
167-
const instances = store.each(reg, ns.solid('instance'), null, index)
168-
for (const instance of instances) {
169-
results.push({ instance, type: klass, scope })
170-
}
171-
const containers = store.each(reg, ns.solid('instanceContainer'), null, index)
172-
for (const cont of containers) {
173-
await store.fetcher.load(cont)
174-
const contents = store.each(cont, ns.ldp('contains'), null, cont).map(one => sym(one.value))
175-
for (const instance of contents) {
176-
results.push({ instance: sym(instance.value), type: klass, scope })
164+
if (!theClass || klass.sameTerm(theClass)) {
165+
const instances = store.each(reg, ns.solid('instance'), null, index)
166+
for (const instance of instances) {
167+
results.push({ instance, type: klass, scope })
168+
}
169+
const containers = store.each(reg, ns.solid('instanceContainer'), null, index)
170+
for (const cont of containers) {
171+
await store.fetcher.load(cont)
172+
const contents = store.each(cont, ns.ldp('contains'), null, cont).map(one => sym(one.value))
173+
for (const instance of contents) {
174+
results.push({ instance: sym(instance.value), type: klass, scope })
175+
}
177176
}
178177
}
179178
}
180179
return results
181-
/*
182-
const directInstances = relevant.map(reg => store.each(reg, ns.solid('instance'), null, index)).flat()
183-
// const directInstances = relevant.map(reg => store.each(reg, ns.solid('instance'), null, index).map(one => sym(one.value))).flat()
184-
let instances = uniqueNodes(directInstances)
185-
186-
const instanceContainers = relevant.map(
187-
reg => store.each(reg, ns.solid('instanceContainer'), null, index).map(one => sym(one.value))).flat()
188-
189-
// instanceContainers may be deprocatable if no one has used them
190-
const containers = uniqueNodes(instanceContainers)
191-
if (containers.length > 0) { console.log('@@ getScopedAppsFromIndex containers ', containers) }
192-
for (let i = 0; i < containers.length; i++) {
193-
const cont = containers[i]
194-
await store.fetcher.load(cont)
195-
const contents = store.each(cont, ns.ldp('contains'), null, cont).map(one => sym(one.value))
196-
instances = instances.concat(contents)
197-
}
198-
return instances.map(instance => { return { instance, scope } })
199-
*/
200180
}
201181

202182
return {

test/typeIndexLogic.test.ts

Lines changed: 13 additions & 257 deletions
Original file line numberDiff line numberDiff line change
@@ -173,217 +173,15 @@ describe("TypeIndex logic NEW", () => {
173173
})
174174
})
175175

176-
const AliceAndClubScopes =
177-
[
178-
{
179-
"instance": {
180-
"classOrder": 5,
181-
"termType": "NamedNode",
182-
"value": "https://alice.example.com/publicStuff/actionItems.ttl#this",
183-
},
184-
"scope": {
185-
"agent": {
186-
"classOrder": 5,
187-
"termType": "NamedNode",
188-
"value": "https://alice.example.com/profile/card.ttl#me",
189-
},
190-
"index": {
191-
"classOrder": 5,
192-
"termType": "NamedNode",
193-
"value": "https://alice.example.com/profile/public-type-index.ttl",
194-
},
195-
"label": "public",
196-
},
197-
},
198-
{
199-
"instance": {
200-
"classOrder": 5,
201-
"termType": "NamedNode",
202-
"value": "https://alice.example.com/project4/issues.ttl#this",
203-
},
204-
"scope": {
205-
"agent": {
206-
"classOrder": 5,
207-
"termType": "NamedNode",
208-
"value": "https://alice.example.com/profile/card.ttl#me",
209-
},
210-
"index": {
211-
"classOrder": 5,
212-
"termType": "NamedNode",
213-
"value": "https://alice.example.com/profile/public-type-index.ttl",
214-
},
215-
"label": "public",
216-
},
217-
},
218-
{
219-
"instance": {
220-
"classOrder": 5,
221-
"termType": "NamedNode",
222-
"value": "https://alice.example.com/privateStuff/ToDo.ttl#this",
223-
},
224-
"scope": {
225-
"agent": {
226-
"classOrder": 5,
227-
"termType": "NamedNode",
228-
"value": "https://alice.example.com/profile/card.ttl#me",
229-
},
230-
"index": {
231-
"classOrder": 5,
232-
"termType": "NamedNode",
233-
"value": "https://alice.example.com/settings/private-type-index.ttl",
234-
},
235-
"label": "private",
236-
},
237-
},
238-
{
239-
"instance": {
240-
"classOrder": 5,
241-
"termType": "NamedNode",
242-
"value": "https://alice.example.com/privateStuff/Goals.ttl#this",
243-
},
244-
"scope": {
245-
"agent": {
246-
"classOrder": 5,
247-
"termType": "NamedNode",
248-
"value": "https://alice.example.com/profile/card.ttl#me",
249-
},
250-
"index": {
251-
"classOrder": 5,
252-
"termType": "NamedNode",
253-
"value": "https://alice.example.com/settings/private-type-index.ttl",
254-
},
255-
"label": "private",
256-
},
257-
},
258-
{
259-
"instance": {
260-
"classOrder": 5,
261-
"termType": "NamedNode",
262-
"value": "https://alice.example.com/privateStuff/workingOn.ttl#this",
263-
},
264-
"scope": {
265-
"agent": {
266-
"classOrder": 5,
267-
"termType": "NamedNode",
268-
"value": "https://alice.example.com/profile/card.ttl#me",
269-
},
270-
"index": {
271-
"classOrder": 5,
272-
"termType": "NamedNode",
273-
"value": "https://alice.example.com/settings/private-type-index.ttl",
274-
},
275-
"label": "private",
276-
},
277-
},
278-
{
279-
"instance": {
280-
"classOrder": 5,
281-
"termType": "NamedNode",
282-
"value": "https://club.example.com/publicStuff/actionItems.ttl#this",
283-
},
284-
"scope": {
285-
"agent": {
286-
"classOrder": 5,
287-
"termType": "NamedNode",
288-
"value": "https://club.example.com/profile/card.ttl#it",
289-
},
290-
"index": {
291-
"classOrder": 5,
292-
"termType": "NamedNode",
293-
"value": "https://club.example.com/profile/public-type-index.ttl",
294-
},
295-
"label": "public",
296-
},
297-
},
298-
{
299-
"instance": {
300-
"classOrder": 5,
301-
"termType": "NamedNode",
302-
"value": "https://club.example.com/project4/clubIssues.ttl#this",
303-
},
304-
"scope": {
305-
"agent": {
306-
"classOrder": 5,
307-
"termType": "NamedNode",
308-
"value": "https://club.example.com/profile/card.ttl#it",
309-
},
310-
"index": {
311-
"classOrder": 5,
312-
"termType": "NamedNode",
313-
"value": "https://club.example.com/profile/public-type-index.ttl",
314-
},
315-
"label": "public",
316-
},
317-
},
318-
{
319-
"instance": {
320-
"classOrder": 5,
321-
"termType": "NamedNode",
322-
"value": "https://club.example.com/privateStuff/ToDo.ttl#this",
323-
},
324-
"scope": {
325-
"agent": {
326-
"classOrder": 5,
327-
"termType": "NamedNode",
328-
"value": "https://club.example.com/profile/card.ttl#it",
329-
},
330-
"index": {
331-
"classOrder": 5,
332-
"termType": "NamedNode",
333-
"value": "https://club.example.com/settings/private-type-index.ttl",
334-
},
335-
"label": "private",
336-
},
337-
},
338-
{
339-
"instance": {
340-
"classOrder": 5,
341-
"termType": "NamedNode",
342-
"value": "https://club.example.com/privateStuff/Goals.ttl#this",
343-
},
344-
"scope": {
345-
"agent": {
346-
"classOrder": 5,
347-
"termType": "NamedNode",
348-
"value": "https://club.example.com/profile/card.ttl#it",
349-
},
350-
"index": {
351-
"classOrder": 5,
352-
"termType": "NamedNode",
353-
"value": "https://club.example.com/settings/private-type-index.ttl",
354-
},
355-
"label": "private",
356-
},
357-
},
358-
{
359-
"instance": {
360-
"classOrder": 5,
361-
"termType": "NamedNode",
362-
"value": "https://club.example.com/privateStuff/tasks.ttl#this",
363-
},
364-
"scope": {
365-
"agent": {
366-
"classOrder": 5,
367-
"termType": "NamedNode",
368-
"value": "https://club.example.com/profile/card.ttl#it",
369-
},
370-
"index": {
371-
"classOrder": 5,
372-
"termType": "NamedNode",
373-
"value": "https://club.example.com/settings/private-type-index.ttl",
374-
},
375-
"label": "private",
376-
},
377-
},
378-
]
176+
const AliceAndClubScopes = [{"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/publicStuff/actionItems.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/card.ttl#me"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/public-type-index.ttl"}, "label": "public"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/project4/issues.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/card.ttl#me"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/public-type-index.ttl"}, "label": "public"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/ToDo.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/card.ttl#me"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/Goals.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/card.ttl#me"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/workingOn.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/profile/card.ttl#me"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/publicStuff/actionItems.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/card.ttl#it"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/public-type-index.ttl"}, "label": "public"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/project4/clubIssues.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/card.ttl#it"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/public-type-index.ttl"}, "label": "public"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/ToDo.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/card.ttl#it"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/Goals.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/card.ttl#it"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}, {"instance": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/tasks.ttl#this"}, "scope": {"agent": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/profile/card.ttl#it"}, "index": {"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/settings/private-type-index.ttl"}, "label": "private"}, "type": {"classOrder": 5, "termType": "NamedNode", "value": "http://www.w3.org/2005/01/wf/flow#Tracker"}}]
379177

380178
describe('getScopedAppInstances', () => {
381179
it('exists', () => {
382180
expect(typeIndexLogic.getScopedAppInstances).toBeInstanceOf(Function)
383181
})
384182
it('pulls in users scopes and also community ones', async () => {
385183
const result = await typeIndexLogic.getScopedAppInstances(Tracker, alice)
386-
// expect(result).toEqual(AliceAndClubScopes)
184+
expect(result).toEqual(AliceAndClubScopes) // @@ AliceAndClubScopes
387185
})
388186
it('creates new preferenceFile and typeIndex files where they dont exist', async () => {
389187
const result = await typeIndexLogic.getScopedAppInstances(Tracker, bob)
@@ -412,66 +210,24 @@ describe("TypeIndex logic NEW", () => {
412210
})
413211

414212
const TRACKERS =
415-
[
416-
{
417-
"classOrder": 5,
418-
"termType": "NamedNode",
419-
"value": "https://alice.example.com/publicStuff/actionItems.ttl#this",
420-
},
421-
{
422-
"classOrder": 5,
423-
"termType": "NamedNode",
424-
"value": "https://alice.example.com/project4/issues.ttl#this",
425-
},
426-
{
427-
"classOrder": 5,
428-
"termType": "NamedNode",
429-
"value": "https://alice.example.com/privateStuff/ToDo.ttl#this",
430-
},
431-
{
432-
"classOrder": 5,
433-
"termType": "NamedNode",
434-
"value": "https://alice.example.com/privateStuff/Goals.ttl#this",
435-
},
436-
{
437-
"classOrder": 5,
438-
"termType": "NamedNode",
439-
"value": "https://alice.example.com/privateStuff/workingOn.ttl#this",
440-
},
441-
{
442-
"classOrder": 5,
443-
"termType": "NamedNode",
444-
"value": "https://club.example.com/publicStuff/actionItems.ttl#this",
445-
},
446-
{
447-
"classOrder": 5,
448-
"termType": "NamedNode",
449-
"value": "https://club.example.com/project4/clubIssues.ttl#this",
450-
},
451-
{
452-
"classOrder": 5,
453-
"termType": "NamedNode",
454-
"value": "https://club.example.com/privateStuff/ToDo.ttl#this",
455-
},
456-
{
457-
"classOrder": 5,
458-
"termType": "NamedNode",
459-
"value": "https://club.example.com/privateStuff/Goals.ttl#this",
460-
},
461-
{
462-
"classOrder": 5,
463-
"termType": "NamedNode",
464-
"value": "https://club.example.com/privateStuff/tasks.ttl#this",
465-
},
466-
]
213+
[{"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/publicStuff/actionItems.ttl#this"},
214+
{"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/project4/issues.ttl#this"},
215+
{"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/ToDo.ttl#this"},
216+
{"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/Goals.ttl#this"},
217+
{"classOrder": 5, "termType": "NamedNode", "value": "https://alice.example.com/privateStuff/workingOn.ttl#this"},
218+
{"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/publicStuff/actionItems.ttl#this"},
219+
{"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/project4/clubIssues.ttl#this"},
220+
{"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/ToDo.ttl#this"},
221+
{"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/Goals.ttl#this"},
222+
{"classOrder": 5, "termType": "NamedNode", "value": "https://club.example.com/privateStuff/tasks.ttl#this"} ]
467223

468224
describe('getAppInstances', () => {
469225
it('exists', () => {
470226
expect(typeIndexLogic.getAppInstances).toBeInstanceOf(Function)
471227
})
472228
it('finds trackers', async () => {
473229
const result = await typeIndexLogic.getAppInstances(Tracker)
474-
// expect(result).toEqual(TRACKERS)
230+
expect(result).toEqual(TRACKERS) // TRACKERS @@
475231
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
476232
})
477233
it('finds images in containers', async () => {

0 commit comments

Comments
 (0)