From 715b39e91d19fb6b8e0db5a6d673cf0427b7afc3 Mon Sep 17 00:00:00 2001 From: Reza Soltani Date: Mon, 27 Nov 2023 23:05:42 +0330 Subject: [PATCH] refactor --- bookmarks/vanilla/src/constants.ts | 13 +++++++------ .../vanilla/src/utils/TypeIndexHelper.ts | 19 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bookmarks/vanilla/src/constants.ts b/bookmarks/vanilla/src/constants.ts index 48cae7ac..429f1d6f 100644 --- a/bookmarks/vanilla/src/constants.ts +++ b/bookmarks/vanilla/src/constants.ts @@ -1,7 +1,8 @@ -export const FOR_CLASS = "http://www.w3.org/ns/solid/terms#forClass" -export const BOOKMARK = 'http://www.w3.org/2002/01/bookmark#Bookmark' +export const __FOR_CLASS = "http://www.w3.org/ns/solid/terms#forClass" +export const __BOOKMARK = 'http://www.w3.org/2002/01/bookmark#Bookmark' -export const SOLID = { - INSTANCE: "http://www.w3.org/ns/solid/terms#instance", - INSTANCE_CONTAINER: "http://www.w3.org/ns/solid/terms#instanceContainer", -} \ No newline at end of file +export const __PRIVATE_TYPEINDEX = "http://www.w3.org/ns/solid/terms#privateTypeIndex" +export const __PUBLIC_TYPEINDEX = "http://www.w3.org/ns/solid/terms#publicTypeIndex" + +export const __SOLID_INSTANCE = "http://www.w3.org/ns/solid/terms#instance" +export const __SOLID_INSTANCE_CONTAINER = "http://www.w3.org/ns/solid/terms#instanceContainer" diff --git a/bookmarks/vanilla/src/utils/TypeIndexHelper.ts b/bookmarks/vanilla/src/utils/TypeIndexHelper.ts index eab71797..fa753b1d 100644 --- a/bookmarks/vanilla/src/utils/TypeIndexHelper.ts +++ b/bookmarks/vanilla/src/utils/TypeIndexHelper.ts @@ -8,7 +8,8 @@ import { getThingAll } from "@inrupt/solid-client"; import { BOOKMARK } from "@inrupt/vocab-common-rdf"; -import { FOR_CLASS, SOLID } from "../constants"; +import { __FOR_CLASS, __PRIVATE_TYPEINDEX, __PUBLIC_TYPEINDEX, __SOLID_INSTANCE, __SOLID_INSTANCE_CONTAINER } from "../constants"; +// import { FOR_CLASS, SOLID } from "../constants"; export class TypeIndexHelper { constructor() { } @@ -23,15 +24,12 @@ export class TypeIndexHelper { } public static async getTypeIndex({ session, isPrivate }: { session: Session, isPrivate: boolean }) { - if (!session.info.webId) return - const profileDS = await getSolidDataset(session.info.webId, { fetch: session.fetch }) - const me = getThing(profileDS, session.info.webId); + const me = await this.getProfile(session) if (me) { - const predicate = isPrivate ? "privateTypeIndex" : "publicTypeIndex" - - const typeIndex = getNamedNode(me, `http://www.w3.org/ns/solid/terms#${predicate}`) + // TODO: me doc exists + const typeIndex = getNamedNode(me, isPrivate ? __PRIVATE_TYPEINDEX : __PUBLIC_TYPEINDEX) return typeIndex } else { @@ -55,12 +53,12 @@ export class TypeIndexHelper { const instanceContainers: string[] = [] all.forEach(x => { - const forClass = getNamedNode(x, FOR_CLASS) + const forClass = getNamedNode(x, __FOR_CLASS) if (forClass?.value === BOOKMARK.Bookmark) { - const instance = getNamedNode(x, SOLID.INSTANCE)?.value - const instanceContainer = getNamedNode(x, SOLID.INSTANCE_CONTAINER)?.value + const instance = getNamedNode(x, __SOLID_INSTANCE)?.value + const instanceContainer = getNamedNode(x, __SOLID_INSTANCE_CONTAINER)?.value instance && instances?.push(instance) instanceContainer && instanceContainers?.push(instanceContainer) @@ -71,6 +69,7 @@ export class TypeIndexHelper { instances, instanceContainers } + console.log("🚀 ~ file: TypeIndexHelper.ts:75 ~ TypeIndexHelper ~ getFromTypeIndex ~ bookmarkRegisteries:", bookmarkRegisteries) return bookmarkRegisteries } } \ No newline at end of file