1- import { NamedNode , Namespace , LiveStore , sym , st } from "rdflib" ;
1+ import { NamedNode , LiveStore , sym , st } from 'rdflib'
2+ import * as $rdf from 'rdflib'
23import { solidLogicSingleton } from "../logic/solidLogicSingleton"
34import { newThing } from "../util/uri"
4- const { authn } = solidLogicSingleton
5+ import solidNamespace from 'solid-namespace'
6+
7+ const { authn } = solidLogicSingleton
58const { currentUser } = authn
9+ const ns = solidNamespace ( $rdf )
610
7- type TypeIndexScope = { label : string , index : NamedNode , agent : NamedNode } ;
11+ type TypeIndexScope = { label : string , index : NamedNode , agent : NamedNode }
812type ScopedApp = { instance : NamedNode , scope : TypeIndexScope }
913
10- const ns = {
11- dct : Namespace ( 'http://purl.org/dc/terms/' ) ,
12- ldp : Namespace ( 'http://www.w3.org/ns/ldp#' ) ,
13- meeting : Namespace ( 'http://www.w3.org/ns/pim/meeting#' ) ,
14- rdf : Namespace ( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' ) ,
15- schema : Namespace ( 'http://schema.org/' ) ,
16- solid : Namespace ( 'http://www.w3.org/ns/solid/terms#' ) ,
17- space : Namespace ( 'http://www.w3.org/ns/pim/space#' ) ,
18- stat : Namespace ( 'http://www.w3.org/ns/posix/stat#' ) ,
19- vcard : Namespace ( 'http://www.w3.org/2006/vcard/ns#' ) ,
20- wf : Namespace ( 'http://www.w3.org/2005/01/wf/flow#' ) ,
21- xsd : Namespace ( 'http://www.w3.org/2001/XMLSchema#' )
22-
23- }
24-
25- /** Create a resource if it really does not exist
26- * Be absolutely sure something does not exist before creating a new empty file
14+ /**
15+ * Create a resource if it really does not exist
16+ * Be absolutely sure something does not exist before creating a new empty file
2717 * as otherwise existing could be deleted.
2818 * @param doc {NamedNode} - The resource
2919 */
@@ -64,9 +54,10 @@ export function suggestPublicTypeIndex (me:NamedNode) {
6454export function suggestPrivateTypeIndex ( preferencesFile :NamedNode ) {
6555 return sym ( preferencesFile . doc ( ) . dir ( ) ?. uri + 'privateTypeIndex.ttl' )
6656}
57+
6758/* Follow link from this doc to another thing, or else make a new link
6859**
69- ** return: null no ld one and failed to make a new one
60+ ** return: null no ld one and failed to make a new one
7061*/
7162export async function followOrCreateLink ( store : LiveStore , subject : NamedNode , predicate : NamedNode ,
7263 object : NamedNode , doc :NamedNode ) :Promise < NamedNode | null > {
@@ -119,7 +110,7 @@ export async function loadPreferences (store: LiveStore, user: NamedNode): Promi
119110 }
120111 try {
121112 await store . fetcher . load ( preferencesFile as NamedNode )
122- } catch ( err ) { // Mabeb a permission propblem or origin problem
113+ } catch ( err ) { // Maybe a permission propblem or origin problem
123114 return undefined
124115 }
125116 return preferencesFile as NamedNode
@@ -150,7 +141,7 @@ export async function loadTypeIndexesFor (store: LiveStore, user:NamedNode): Pro
150141
151142 const privateTypeIndex = store . any ( user , ns . solid ( 'privateTypeIndex' ) , undefined , profile ) ||
152143
153- await followOrCreateLink ( store , user , ns . solid ( 'privateTypeIndex' ) as NamedNode , suggestedPrivateTypeIndex , preferencesFile ) ;
144+ await followOrCreateLink ( store , user , ns . solid ( 'privateTypeIndex' ) as NamedNode , suggestedPrivateTypeIndex , preferencesFile ) ;
154145
155146 privateScopes = privateTypeIndex ? [ { label : 'private' , index : privateTypeIndex as NamedNode , agent : user } ] : [ ]
156147 } else {
@@ -187,7 +178,6 @@ export async function loadAllTypeIndexes (store:LiveStore, user:NamedNode) {
187178}
188179
189180// Utility: remove duplicates from Array of NamedNodes
190-
191181export function uniqueNodes ( arr : NamedNode [ ] ) : NamedNode [ ] {
192182 const uris = arr . map ( x => x . uri )
193183 const set = new Set ( uris )
@@ -210,7 +200,6 @@ export async function getScopedAppsFromIndex (store, scope, theClass: NamedNode
210200 reg => store . each ( reg as NamedNode , ns . solid ( 'instanceContainer' ) , null , index ) ) . flat ( )
211201
212202 // instanceContainers may be deprocatable if no one has used them
213-
214203 const containers = uniqueNodes ( instanceContainers )
215204 if ( containers . length > 0 ) { console . log ( '@@ getScopedAppsFromIndex containers ' , containers ) }
216205 for ( let i = 0 ; i < containers . length ; i ++ ) {
@@ -222,7 +211,6 @@ export async function getScopedAppsFromIndex (store, scope, theClass: NamedNode
222211 return instances . map ( instance => { return { instance, scope} } )
223212}
224213
225-
226214export async function getScopedAppInstances ( store :LiveStore , klass : NamedNode , user : NamedNode ) :Promise < ScopedApp [ ] > {
227215 const scopes = await loadAllTypeIndexes ( store , user )
228216 let scopedApps = [ ]
@@ -232,6 +220,7 @@ export async function getScopedAppInstances (store:LiveStore, klass: NamedNode,
232220 }
233221 return scopedApps
234222}
223+
235224// This is the function signature which used to be in solid-ui/logic
236225// Recommended to use getScopedAppInstances instead as it provides more information.
237226//
@@ -241,7 +230,8 @@ export async function getAppInstances (store:LiveStore, klass: NamedNode): Promi
241230 const scopedAppInstances = await getScopedAppInstances ( store , klass , user )
242231 return scopedAppInstances . map ( scoped => scoped . instance )
243232}
244- /**
233+
234+ /*
245235 * Register a new app in a type index
246236 * used in chat in bookmark.js (solid-ui)
247237 * Returns the registration object if successful else null
@@ -276,5 +266,4 @@ export async function deleteTypeIndexRegistration (store: LiveStore, item) {
276266 const statements = store . statementsMatching ( reg , null , null , item . scope . index )
277267 await store . updater . update ( statements , [ ] )
278268}
279-
280269// ENDS
0 commit comments