@@ -2,7 +2,7 @@ import { NamedNode, st, sym } from 'rdflib'
22import { ScopedApp , TypeIndexLogic , TypeIndexScope } from '../types'
33import * as debug from "../util/debug"
44import { ns as namespace } from '../util/ns'
5- import { newThing , uniqueNodes } from "../util/utils"
5+ import { newThing } from "../util/utils"
66
77export function createTypeIndexLogic ( store , authn , profileLogic , utilityLogic ) : TypeIndexLogic {
88 const ns = namespace
@@ -155,29 +155,30 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
155155
156156 async function getScopedAppsFromIndex ( scope : TypeIndexScope , theClass : NamedNode | null ) : Promise < ScopedApp [ ] > {
157157 const index = scope . index
158+ const results : ScopedApp [ ] = [ ]
158159 const registrations = store . statementsMatching ( null , ns . solid ( 'instance' ) , null , index )
159160 . concat ( store . statementsMatching ( null , ns . solid ( 'instanceContainer' ) , null , index ) )
160161 . map ( st => st . subject )
161- const relevant = theClass ? registrations . filter ( reg => store . any ( reg , ns . solid ( 'forClass' ) , null , index ) ?. sameTerm ( theClass ) )
162- : registrations
163- const directInstances = relevant . map ( reg => store . each ( reg , ns . solid ( 'instance' ) , null , index ) . map ( one => sym ( one . value ) ) ) . flat ( )
164- let instances = uniqueNodes ( directInstances )
165-
166- const instanceContainers = relevant . map (
167- reg => store . each ( reg , ns . solid ( 'instanceContainer' ) , null , index ) . map ( one => sym ( one . value ) ) ) . flat ( )
168-
169- // instanceContainers may be deprocatable if no one has used them
170- const containers = uniqueNodes ( instanceContainers )
171- if ( containers . length > 0 ) { console . log ( '@@ getScopedAppsFromIndex containers ' , containers ) }
172- for ( let i = 0 ; i < containers . length ; i ++ ) {
173- const cont = containers [ i ]
174- await store . fetcher . load ( cont )
175- const contents = store . each ( cont , ns . ldp ( 'contains' ) , null , cont ) . map ( one => sym ( one . value ) )
176- instances = instances . concat ( contents )
162+ for ( const reg of registrations ) {
163+ const klass = store . any ( reg , ns . solid ( 'forClass' ) , null , index )
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+ }
176+ }
177+ }
177178 }
178- return instances . map ( instance => { return { instance , scope } } )
179+ return results
179180 }
180-
181+
181182 return {
182183 registerInTypeIndex,
183184 getRegistrations,
0 commit comments