Skip to content

Commit b3d216a

Browse files
committed
Removing unnecessary castings
1 parent 79a2776 commit b3d216a

5 files changed

Lines changed: 52 additions & 56 deletions

File tree

src/acl/acl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ export function comboToString (byCombo: ComboList): string {
295295
export function makeACLString (x: NamedNode, ac: AgentMapMap, aclDoc: NamedNode): string {
296296
const kb2 = graph()
297297
makeACLGraph(kb2, x, ac, aclDoc)
298-
// @@ TODO Remove casting
299298
return serialize(aclDoc, kb2, aclDoc.uri, 'text/turtle') || ''
300299
}
301300

@@ -327,7 +326,6 @@ export function putACLbyCombo (
327326
makeACLGraphbyCombo(kb2, x, byCombo, aclDoc, true)
328327

329328
// const str = makeACLString = function(x, ac, aclDoc)
330-
// @@ TODO Remove casting of kb.updater and kb.fetcher
331329
kb.updater.put(
332330
aclDoc,
333331
kb2.statementsMatching(undefined, undefined, undefined, aclDoc),
@@ -336,9 +334,9 @@ export function putACLbyCombo (
336334
if (!ok) {
337335
callbackFunction(ok, message)
338336
} else {
339-
;(kb as any).fetcher.unload(aclDoc)
337+
kb.fetcher.unload(aclDoc)
340338
makeACLGraphbyCombo(kb, x, byCombo, aclDoc, true)
341-
;(kb as any).fetcher.requested[aclDoc.uri] = 'done' // missing: save headers
339+
kb.fetcher.requested[aclDoc.uri] = 'done' // missing: save headers
342340
callbackFunction(ok)
343341
}
344342
}

src/authn/authn.ts

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* @packageDocumentation
2121
*/
2222
import SolidTls from 'solid-auth-tls'
23-
import * as $rdf from 'rdflib'
2423
import widgets from '../widgets'
2524
import solidAuthClient from 'solid-auth-client'
2625
import ns from '../ns.js'
@@ -30,6 +29,7 @@ import { alert } from '../log'
3029
import { AppDetails, AuthenticationContext } from './types'
3130
import { PaneDefinition } from 'pane-registry'
3231
import * as debug from '../debug'
32+
import { graph, namedNode, NamedNode, Namespace, serialize, st, Statement, sym, UpdateManager } from 'rdflib'
3333

3434
export { 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
*/
5858
export 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

312312
async 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
*/
454454
export 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
512512
function 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
*/
531531
export 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
*/
744744
export 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
*/
818818
function 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
*/
10011000
export 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)),

src/widgets/buttons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ export function propertyTriage (kb: IndexedFormula): any {
917917
no++
918918
}
919919
} // If nothing discovered, then could be either:
920-
var ps = kb.each(undefined, ns.rdf('type'), ns.rdf('Property')) as Array<Node>
920+
var ps = kb.each(undefined, ns.rdf('type'), ns.rdf('Property'))
921921
for (var i = 0; i < ps.length; i++) {
922922
p = ps[i].toNT()
923923
// log.debug('propertyTriage: unknown: ' + p)

test/unit/store.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ describe('kb (main global IndexedFormula instance)', () => {
1212

1313
describe('kb.fetcher', () => {
1414
it('exists', () => {
15-
expect((kb as any).fetcher).toBeInstanceOf(Object)
15+
expect(kb.fetcher).toBeInstanceOf(Object)
1616
})
1717
})
1818

1919
describe('kb.updater', () => {
2020
it('exists', () => {
21-
expect((kb as any).updater).toBeInstanceOf(Object)
21+
expect(kb.updater).toBeInstanceOf(Object)
2222
})
2323
})

test/unit/tabs.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ describe('tabWidget', () => {
3434
beforeAll(() => {
3535
const predicate = meeting('toolList')
3636
store.add(subject, predicate, new Collection([item1, item2]), subject.doc())
37-
// @@ TODO Remove need for casting lit (fix typings in rdflib)
38-
store.add(item1, rdfs('label'), (lit as any)('Item 1'), subject.doc())
37+
store.add(item1, rdfs('label'), lit('Item 1'), subject.doc())
3938

4039
tabWidgetElement = tabs.tabWidget({
4140
dom,

0 commit comments

Comments
 (0)