Skip to content

Commit

Permalink
use TypeIndexHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Nov 27, 2023
1 parent 715b39e commit 70b5b84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion bookmarks/vanilla/src/modules/Bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
RDFS
} from "@inrupt/vocab-common-rdf";
import { namedNode } from '@rdfjs/data-model';
import { TypeIndexHelper } from "../utils/TypeIndexHelper";


export type ICreateBookmark = {
Expand Down Expand Up @@ -56,11 +57,24 @@ export class Bookmark {
* @returns string
*/
public static async getIndexUrl(session: Session) {
const bookmarkRegisteries = await TypeIndexHelper.getFromTypeIndex(session)
if (bookmarkRegisteries) {
// inrupt getSolidDataset takes a full url to turtle file like https://example.com/bookmarks/index.ttl
const { instanceContainers, instances } = bookmarkRegisteries

if (!!instances) {
return instances[0]
}

// TODO: return all instances
} else {
// TODO: create registeries
}
const pods = await getPodUrlAll(session.info.webId!, {
fetch: session.fetch,
});
const bookmarksContainerUri = `${pods[0]}bookmarks/`;
return `${bookmarksContainerUri}index.ttl`;
return `${bookmarksContainerUri}index.ttl`; // defaultIndexUrl
}

/**
Expand Down Expand Up @@ -132,6 +146,7 @@ export class Bookmark {
* @returns IBookmark
*/
public static async create(payload: ICreateBookmark, session: Session) {
// TODO: check typeIndex

const { title, link, creator, topic } = payload

Expand Down Expand Up @@ -166,6 +181,8 @@ export class Bookmark {
* @returns IBookmark
*/
public static async update(url: string, payload: IUpdateBookmark, session: Session) {
// TODO: check typeIndex

const indexUrl = await this.getIndexUrl(session);
const ds = await getSolidDataset(indexUrl, { fetch: session.fetch });
let thing = getThing(ds, url)
Expand Down
4 changes: 2 additions & 2 deletions bookmarks/vanilla/src/utils/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
BOOKMARK
} from "@inrupt/vocab-common-rdf";
import { __FOR_CLASS, __PRIVATE_TYPEINDEX, __PUBLIC_TYPEINDEX, __SOLID_INSTANCE, __SOLID_INSTANCE_CONTAINER } from "../constants";
// import { FOR_CLASS, SOLID } from "../constants";

export class TypeIndexHelper {
constructor() { }
Expand Down Expand Up @@ -43,6 +42,7 @@ export class TypeIndexHelper {

public static async getFromTypeIndex(session: Session) {
const typeIndex = await this.getTypeIndex({ session, isPrivate: true })

if (!typeIndex) return // TODO validate

const ds = await getSolidDataset(typeIndex?.value, { fetch: session.fetch })
Expand All @@ -69,7 +69,7 @@ export class TypeIndexHelper {
instances,
instanceContainers
}
console.log("🚀 ~ file: TypeIndexHelper.ts:75 ~ TypeIndexHelper ~ getFromTypeIndex ~ bookmarkRegisteries:", bookmarkRegisteries)

return bookmarkRegisteries
}
}

0 comments on commit 70b5b84

Please sign in to comment.