Skip to content

Commit d631865

Browse files
authored
Merge pull request #53 from SolidOS/returnClass
Return class with typeindex data
2 parents 53bd247 + d73984d commit d631865

5 files changed

Lines changed: 43 additions & 289 deletions

File tree

src/inbox/inboxLogic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { InboxLogic } from "../types";
33
import { getArchiveUrl } from "../util/utils";
44

55
export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic): InboxLogic {
6-
6+
77
async function createInboxFor(peerWebId: string, nick: string) {
88
const myWebId: NamedNode = await profileLogic.loadMe();
99
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
1010
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
1111
await containerLogic.createContainer(ourInbox);
12-
const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
12+
// const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
1313
await utilityLogic.setSinglePeerAccess({
1414
ownerWebId: myWebId.value,
1515
peerWebId,
@@ -55,4 +55,4 @@ export function createInboxLogic(store, profileLogic, utilityLogic, containerLog
5555
getNewMessages,
5656
markAsRead
5757
}
58-
}
58+
}

src/profile/profileLogic.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
1111
/**
1212
* loads the preference without throwing errors - if it can create it it does so.
1313
* remark: it still throws error if it cannot load profile.
14-
* @param user
14+
* @param user
1515
* @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it
1616
*/
1717
async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {
@@ -25,7 +25,7 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
2525
/**
2626
* loads the preference without returning different errors if it cannot create or load it.
2727
* remark: it also throws error if it cannot load profile.
28-
* @param user
28+
* @param user
2929
* @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it
3030
*/
3131
async function loadPreferences (user: NamedNode): Promise <NamedNode> {
@@ -48,9 +48,8 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
4848
throw err
4949
}
5050

51-
let response
5251
try {
53-
response = await store.fetcher.load(preferencesFile as NamedNode)
52+
await store.fetcher.load(preferencesFile as NamedNode)
5453
} catch (err) { // Maybe a permission problem or origin problem
5554
const msg = `Unable to load preference of user ${user}: ${err}`
5655
debug.warn(msg)
@@ -123,4 +122,3 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
123122
silencedLoadPreferences
124123
}
125124
}
126-

src/typeIndex/typeIndexLogic.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NamedNode, st, sym } from 'rdflib'
22
import { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'
33
import * as debug from "../util/debug"
44
import { ns as namespace } from '../util/ns'
5-
import { newThing, uniqueNodes } from "../util/utils"
5+
import { newThing } from "../util/utils"
66

77
export 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,

src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface SolidNamespace {
3333
}
3434

3535
export type TypeIndexScope = { label: string, index: NamedNode, agent: NamedNode }
36-
export type ScopedApp = { instance: NamedNode, scope: TypeIndexScope }
36+
export type ScopedApp = { instance: NamedNode, type: NamedNode, scope: TypeIndexScope }
3737

3838
export interface NewPaneOptions {
3939
me?: NamedNode;
@@ -119,4 +119,3 @@ export interface SolidLogic {
119119
updatePromise: (del: Array<Statement>, ins: Array<Statement>) => Promise<void>,
120120
clearStore: () => void
121121
}
122-

0 commit comments

Comments
 (0)