2020 * @packageDocumentation
2121 */
2222import SolidTls from 'solid-auth-tls'
23- import * as $rdf from 'rdflib'
2423import widgets from '../widgets'
2524import solidAuthClient from 'solid-auth-client'
2625import ns from '../ns.js'
@@ -30,6 +29,7 @@ import { alert } from '../log'
3029import { AppDetails , AuthenticationContext } from './types'
3130import { PaneDefinition } from 'pane-registry'
3231import * as debug from '../debug'
32+ import { graph , namedNode , NamedNode , Namespace , serialize , st , Statement , sym , UpdateManager } from 'rdflib'
3333
3434export { solidAuthClient }
3535
@@ -38,7 +38,7 @@ export { solidAuthClient }
3838/**
3939 * Look for and load the User who has control over it
4040 */
41- export function findOriginOwner ( doc : $rdf . NamedNode | string ) : string | boolean {
41+ export function findOriginOwner ( doc : NamedNode | string ) : string | boolean {
4242 const uri = ( typeof doc === 'string' ) ? doc : doc . uri
4343 const i = uri . indexOf ( '://' )
4444 if ( i < 0 ) return false
@@ -56,14 +56,14 @@ export function findOriginOwner (doc: $rdf.NamedNode | string): string | boolean
5656 * @returns Returns the WebID, after setting it
5757 */
5858export function saveUser (
59- webId : $rdf . NamedNode | string | null ,
59+ webId : NamedNode | string | null ,
6060 context ?: AuthenticationContext
61- ) : $rdf . NamedNode | null {
61+ ) : NamedNode | null {
6262 // @@ TODO Remove the need for having context as output argument
6363 let webIdUri : string
6464 if ( webId ) {
6565 webIdUri = ( typeof webId === 'string' ) ? webId : webId . uri
66- const me = $rdf . namedNode ( webIdUri )
66+ const me = namedNode ( webIdUri )
6767 if ( context ) {
6868 context . me = me
6969 }
@@ -76,7 +76,7 @@ export function saveUser (
7676 * Wrapper around [[offlineTestID]]
7777 * @returns {NamedNode|null }
7878 */
79- export function defaultTestUser ( ) : $rdf . NamedNode | null {
79+ export function defaultTestUser ( ) : NamedNode | null {
8080 // Check for offline override
8181 const offlineId = offlineTestID ( )
8282
@@ -92,13 +92,13 @@ export function defaultTestUser (): $rdf.NamedNode | null {
9292 *
9393 * @returns Named Node or null
9494 */
95- export function currentUser ( ) : $rdf . NamedNode | null {
95+ export function currentUser ( ) : NamedNode | null {
9696 const str = localStorage [ 'solid-auth-client' ]
9797 if ( str ) {
9898 const da = JSON . parse ( str )
9999 if ( da . session && da . session . webId ) {
100100 // @@ TODO check has not expired
101- return $rdf . sym ( da . session . webId )
101+ return sym ( da . session . webId )
102102 }
103103 }
104104 return offlineTestID ( ) // null unless testing
@@ -122,7 +122,7 @@ export function logIn (context: AuthenticationContext): Promise<AuthenticationCo
122122 checkUser ( ) . then ( webId => {
123123 // Already logged in?
124124 if ( webId ) {
125- context . me = $rdf . sym ( webId as string )
125+ context . me = sym ( webId as string )
126126 debug . log ( `logIn: Already logged in as ${ context . me } ` )
127127 return resolve ( context )
128128 }
@@ -311,7 +311,7 @@ async function loadOneTypeIndex (context: AuthenticationContext, isPublic: boole
311311
312312async function loadIndex (
313313 context : AuthenticationContext ,
314- predicate : $rdf . NamedNode ,
314+ predicate : NamedNode ,
315315 isPublic : boolean
316316) : Promise < AuthenticationContext > {
317317 // Loading preferences is more than loading profile
@@ -398,14 +398,14 @@ async function ensureOneTypeIndex (context: AuthenticationContext, isPublic: boo
398398 context . index [ visibility ] = context . index [ visibility ] || [ ]
399399 let newIndex
400400 if ( context . index [ visibility ] . length === 0 ) {
401- newIndex = $rdf . sym ( `${ relevant . dir ( ) . uri + visibility } TypeIndex.ttl` )
401+ newIndex = sym ( `${ relevant . dir ( ) . uri + visibility } TypeIndex.ttl` )
402402 debug . log ( `Linking to new fresh type index ${ newIndex } ` )
403403 if ( ! confirm ( `OK to create a new empty index file at ${ newIndex } , overwriting anything that is now there?` ) ) {
404404 throw new Error ( 'cancelled by user' )
405405 }
406406 debug . log ( `Linking to new fresh type index ${ newIndex } ` )
407407 const addMe = [
408- $rdf . st ( context . me , ns . solid ( `${ visibility } TypeIndex` ) , newIndex , relevant )
408+ st ( context . me , ns . solid ( `${ visibility } TypeIndex` ) , newIndex , relevant )
409409 ]
410410 try {
411411 await updatePromise ( kb . updater , [ ] , addMe )
@@ -453,7 +453,7 @@ async function ensureOneTypeIndex (context: AuthenticationContext, isPublic: boo
453453 */
454454export async function findAppInstances (
455455 context : AuthenticationContext ,
456- theClass : $rdf . NamedNode ,
456+ theClass : NamedNode ,
457457 isPublic : boolean
458458) : Promise < AuthenticationContext > {
459459 const fetcher = kb . fetcher
@@ -469,7 +469,7 @@ export async function findAppInstances (
469469 await loadOneTypeIndex ( context , isPublic )
470470 } catch ( err ) {
471471 }
472- const index = context . index as { [ key : string ] : Array < $rdf . NamedNode > }
472+ const index = context . index as { [ key : string ] : Array < NamedNode > }
473473 const thisIndex = index [ visibility ]
474474 const registrations = thisIndex
475475 . map ( ix => kb . each ( undefined , ns . solid ( 'forClass' ) , theClass , ix ) )
@@ -510,9 +510,9 @@ export async function findAppInstances (
510510
511511// @@@@ use the one in rdflib.js when it is available and delete this
512512function updatePromise (
513- updater : $rdf . UpdateManager ,
514- del : Array < $rdf . Statement > ,
515- ins : Array < $rdf . Statement > = [ ]
513+ updater : UpdateManager ,
514+ del : Array < Statement > ,
515+ ins : Array < Statement > = [ ]
516516) : Promise < void > {
517517 return new Promise ( function ( resolve , reject ) {
518518 updater . update ( del , ins , function ( uri , ok , errorBody ) {
@@ -530,8 +530,8 @@ function updatePromise (
530530 */
531531export async function registerInTypeIndex (
532532 context : AuthenticationContext ,
533- instance : $rdf . NamedNode ,
534- theClass : $rdf . NamedNode ,
533+ instance : NamedNode ,
534+ theClass : NamedNode ,
535535 isPublic : boolean
536536) : Promise < AuthenticationContext > {
537537 await ensureOneTypeIndex ( context , isPublic )
@@ -546,9 +546,9 @@ export async function registerInTypeIndex (
546546 const registration = widgets . newThing ( index )
547547 const ins = [
548548 // See https://github.com/solid/solid/blob/master/proposals/data-discovery.md
549- $rdf . st ( registration , ns . rdf ( 'type' ) , ns . solid ( 'TypeRegistration' ) , index ) ,
550- $rdf . st ( registration , ns . solid ( 'forClass' ) , theClass , index ) ,
551- $rdf . st ( registration , ns . solid ( 'instance' ) , instance , index )
549+ st ( registration , ns . rdf ( 'type' ) , ns . solid ( 'TypeRegistration' ) , index ) ,
550+ st ( registration , ns . solid ( 'forClass' ) , theClass , index ) ,
551+ st ( registration , ns . solid ( 'instance' ) , instance , index )
552552 ]
553553 try {
554554 await updatePromise ( kb . updater , [ ] , ins )
@@ -591,8 +591,8 @@ export function registrationControl (
591591 ? registrations [ 0 ]
592592 : widgets . newThing ( index )
593593 return [
594- $rdf . st ( reg , ns . solid ( 'instance' ) , instance , index ) ,
595- $rdf . st ( reg , ns . solid ( 'forClass' ) , theClass , index )
594+ st ( reg , ns . solid ( 'instance' ) , instance , index ) ,
595+ st ( reg , ns . solid ( 'forClass' ) , theClass , index )
596596 ]
597597 }
598598
@@ -670,7 +670,7 @@ export function registrationList (context: AuthenticationContext, options: {
670670 box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;' )
671671 const table = box . firstChild as HTMLElement
672672
673- let ix : Array < $rdf . NamedNode > = [ ]
673+ let ix : Array < NamedNode > = [ ]
674674 let sts = [ ]
675675 const vs = [ 'private' , 'public' ]
676676 vs . forEach ( function ( visibility ) {
@@ -688,7 +688,7 @@ export function registrationList (context: AuthenticationContext, options: {
688688 } )
689689
690690 for ( let i = 0 ; i < sts . length ; i ++ ) {
691- const statement : $rdf . Statement = sts [ i ]
691+ const statement : Statement = sts [ i ]
692692 // const cla = statement.subject
693693 const inst = statement . object
694694 // if (false) {
@@ -743,12 +743,12 @@ export function registrationList (context: AuthenticationContext, options: {
743743 */
744744export function setACLUserPublic (
745745 docURI : string ,
746- me : $rdf . NamedNode ,
746+ me : NamedNode ,
747747 options : {
748748 defaultForNew ?: boolean ,
749749 public ?: [ ]
750750 }
751- ) : Promise < $rdf . NamedNode > {
751+ ) : Promise < NamedNode > {
752752 const aclDoc = kb . any (
753753 kb . sym ( docURI ) ,
754754 kb . sym ( 'http://www.iana.org/assignments/link-relations/acl' )
@@ -786,7 +786,7 @@ export function setACLUserPublic (
786786 * @param docURI
787787 * @returns
788788 */
789- function fetchACLRel ( docURI : string ) : Promise < $rdf . NamedNode > {
789+ function fetchACLRel ( docURI : string ) : Promise < NamedNode > {
790790 const fetcher = kb . fetcher
791791
792792 return fetcher . load ( docURI ) . then ( result => {
@@ -817,16 +817,16 @@ function fetchACLRel (docURI: string): Promise<$rdf.NamedNode> {
817817 */
818818function genACLText (
819819 docURI : string ,
820- me : $rdf . NamedNode ,
820+ me : NamedNode ,
821821 aclURI : string ,
822822 options : {
823823 defaultForNew ?: boolean ,
824824 public ?: [ ]
825825 } = { }
826- ) : string {
826+ ) : string | undefined {
827827 const optPublic = options . public || [ ]
828- const g = $rdf . graph ( )
829- const auth = $rdf . Namespace ( 'http://www.w3.org/ns/auth/acl#' )
828+ const g = graph ( )
829+ const auth = Namespace ( 'http://www.w3.org/ns/auth/acl#' )
830830 let a = g . sym ( `${ aclURI } #a1` )
831831 const acl = g . sym ( aclURI )
832832 const doc = g . sym ( docURI )
@@ -850,24 +850,23 @@ function genACLText (
850850 g . add ( a , auth ( 'mode' ) , auth ( optPublic [ p ] ) , acl ) // Like 'Read' etc
851851 }
852852 }
853- // @@ TODO Remove casting of $rdf
854- return ( $rdf as any ) . serialize ( acl , g , aclURI , 'text/turtle' )
853+ return serialize ( acl , g , aclURI )
855854}
856855
857856/**
858- * Returns `$rdf. sym($SolidTestEnvironment.username)` if
857+ * Returns `sym($SolidTestEnvironment.username)` if
859858 * `$SolidTestEnvironment.username` is defined as a global
860859 * @returns {NamedNode|null }
861860 */
862- export function offlineTestID ( ) : $rdf . NamedNode | null {
861+ export function offlineTestID ( ) : NamedNode | null {
863862 const { $SolidTestEnvironment } : any = window
864863 if (
865864 typeof $SolidTestEnvironment !== 'undefined' &&
866865 $SolidTestEnvironment . username
867866 ) {
868867 // Test setup
869868 debug . log ( 'Assuming the user is ' + $SolidTestEnvironment . username )
870- return $rdf . sym ( $SolidTestEnvironment . username )
869+ return sym ( $SolidTestEnvironment . username )
871870 }
872871
873872 if (
@@ -882,7 +881,7 @@ export function offlineTestID (): $rdf.NamedNode | null {
882881 /* me = kb.any(subject, ns.acl('owner')); // when testing on plane with no WebID
883882 */
884883 debug . log ( 'Assuming user is ' + id )
885- return $rdf . sym ( id )
884+ return sym ( id )
886885 }
887886 return null
888887}
@@ -999,8 +998,8 @@ function checkCurrentUser () {
999998 * @returns Resolves with webId uri, if no callback provided
1000999 */
10011000export function checkUser < T > (
1002- setUserCallback ?: ( me : $rdf . NamedNode | null ) => T
1003- ) : Promise < $rdf . NamedNode | T > {
1001+ setUserCallback ?: ( me : NamedNode | null ) => T
1002+ ) : Promise < NamedNode | T > {
10041003 // Check to see if already logged in / have the WebID
10051004 const me = defaultTestUser ( )
10061005 if ( me ) {
@@ -1058,7 +1057,7 @@ export function loginStatusBox (
10581057
10591058 const uri = newidURI . uri || newidURI
10601059 // UI.preferences.set('me', uri)
1061- me = $rdf . sym ( uri )
1060+ me = sym ( uri )
10621061 box . refresh ( )
10631062 if ( listener ) listener ( me . uri )
10641063 }
@@ -1107,7 +1106,7 @@ export function loginStatusBox (
11071106 solidAuthClient . currentSession ( ) . then (
11081107 session => {
11091108 if ( session && session . webId ) {
1110- me = $rdf . sym ( session . webId )
1109+ me = sym ( session . webId )
11111110 } else {
11121111 me = null
11131112 }
@@ -1130,7 +1129,7 @@ export function loginStatusBox (
11301129 if ( solidAuthClient . trackSession ) {
11311130 solidAuthClient . trackSession ( session => {
11321131 if ( session && session . webId ) {
1133- me = $rdf . sym ( session . webId )
1132+ me = sym ( session . webId )
11341133 } else {
11351134 me = null
11361135 }
@@ -1387,7 +1386,7 @@ export function newAppInstance (
13871386 callback : ( workspace : string | null , newBase : string ) => void
13881387) : HTMLElement {
13891388 const gotWS = function ( ws , base ) {
1390- // $rdf. log.debug("newAppInstance: Selected workspace = " + (ws? ws.uri : 'none'))
1389+ // log.debug("newAppInstance: Selected workspace = " + (ws? ws.uri : 'none'))
13911390 callback ( ws , base )
13921391 }
13931392 const div = dom . createElement ( 'div' )
@@ -1406,7 +1405,7 @@ export function newAppInstance (
14061405 * Retrieves whether the currently logged in user is a power user
14071406 * and/or a developer
14081407 */
1409- export async function getUserRoles ( ) : Promise < Array < $rdf . NamedNode > > {
1408+ export async function getUserRoles ( ) : Promise < Array < NamedNode > > {
14101409 try {
14111410 const {
14121411 me,
@@ -1431,7 +1430,7 @@ export async function filterAvailablePanes (panes: Array<PaneDefinition>): Promi
14311430 return panes . filter ( pane => isMatchingAudience ( pane , userRoles ) )
14321431}
14331432
1434- function isMatchingAudience ( pane : PaneDefinition , userRoles : Array < $rdf . NamedNode > ) : boolean {
1433+ function isMatchingAudience ( pane : PaneDefinition , userRoles : Array < NamedNode > ) : boolean {
14351434 const audience = pane . audience || [ ]
14361435 return audience . reduce (
14371436 ( isMatch , audienceRole ) => isMatch && ! ! userRoles . find ( role => role . equals ( audienceRole ) ) ,
0 commit comments