Skip to content

Commit 79bf9b2

Browse files
committed
implement copilot comments
1 parent 3dbd0c3 commit 79bf9b2

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/typeIndex/typeIndexLogic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
8686
return scopes
8787
}
8888

89-
async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[][]> {
89+
async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {
9090
let preferencesFile
9191
try {
9292
preferencesFile = await profileLogic.silencedLoadPreferences(user)
@@ -116,7 +116,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
116116
}
117117

118118
async function loadAllTypeIndexes(user: NamedNode) {
119-
return (await loadTypeIndexesFor(user)).concat((await loadCommunityTypeIndexes(user)).flat())
119+
return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))
120120
}
121121

122122
async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {
@@ -145,7 +145,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
145145
if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri
146146
const docUri = doc.uri
147147
if (!docUri || !isAbsoluteHttpUri(docUri)) {
148-
debug.log(`docDirUri: missing doc uri for ${node?.uri}`)
148+
debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)
149149
return null
150150
}
151151
const withoutFragment = docUri.split('#')[0]
@@ -159,14 +159,14 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
159159

160160
function suggestPublicTypeIndex(me: NamedNode) {
161161
const dirUri = docDirUri(me)
162-
if (!dirUri || !isAbsoluteHttpUri(dirUri)) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)
162+
if (!dirUri) throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${me.uri}`)
163163
return sym(dirUri + 'publicTypeIndex.ttl')
164164
}
165165
// Note this one is based off the pref file not the profile
166166

167167
function suggestPrivateTypeIndex(preferencesFile: NamedNode) {
168168
const dirUri = docDirUri(preferencesFile)
169-
if (!dirUri || !isAbsoluteHttpUri(dirUri)) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)
169+
if (!dirUri) throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${preferencesFile.uri}`)
170170
return sym(dirUri + 'privateTypeIndex.ttl')
171171
}
172172

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface InboxLogic {
9696
export interface TypeIndexLogic {
9797
getRegistrations: (instance, theClass) => Node[],
9898
loadTypeIndexesFor: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
99-
loadCommunityTypeIndexes: (user: NamedNode) => Promise<TypeIndexScope[][]>,
99+
loadCommunityTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
100100
loadAllTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
101101
getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise<ScopedApp[]>,
102102
getAppInstances: (klass: NamedNode) => Promise<NamedNode[]>,

test/typeIndexLogic.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ describe('TypeIndex logic NEW', () => {
170170
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
171171
expect(result).toEqual(ClubScopes)
172172
})
173+
it('skips malformed non-NamedNode community entries', async () => {
174+
web[AlicePreferencesFile.uri] = `
175+
${alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
176+
solid:community ${club};
177+
solid:community "not-a-webid" .
178+
`
179+
180+
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
181+
expect(result).toEqual(ClubScopes)
182+
})
183+
it('continues when one community fails to load', async () => {
184+
const brokenCommunity = sym('https://broken.example.com/profile/card.ttl#it')
185+
web[AlicePreferencesFile.uri] = `
186+
${alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
187+
solid:community ${brokenCommunity};
188+
solid:community ${club} .
189+
`
190+
191+
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
192+
expect(result).toEqual(ClubScopes)
193+
})
173194
})
174195

175196
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'}}]

0 commit comments

Comments
 (0)