Skip to content

Commit

Permalink
add jsDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 6, 2023
1 parent 50d1344 commit 7d5bfe8
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import { NamedNode } from '@rdfjs/types'

export class TypeIndexHelper {

/**
* Retrieves the profile of the logged-in user.
*
* @param {string} webId - The WebID of the user.
* @param {any} fetch - The authenticated fetch function to use for HTTP requests.
* @return {Promise<ThingPersisted | null>} - The user profile or null if not found.
*/
public static async getMeProfile(webId: string, fetch: any): Promise<ThingPersisted | null> {

const profileDS = await getSolidDataset(webId, { fetch: fetch });
Expand All @@ -44,11 +51,12 @@ export class TypeIndexHelper {
}

/**
* Retrieves the typeIndex for a given session and isPrivate flag.
* Retrieves the typeIndex for a given webId.
*
* @param {Session} session - The session object.
* @param {boolean} isPrivate - A flag indicating whether the typeIndex is private.
* @return {Promise<NamedNode<string>>} A promise that resolves to the named node representing the typeIndex.
* @param {string} webId - The WebID of the user.
* @param {any} fetch - The authenticated fetch function to use for HTTP requests.
* @param {boolean} isPrivate - Indicates whether the typeIndex is private or not.
* @return {Promise<NamedNode<string>>} A Promise that resolves with the typeIndex.
*/
public static async getTypeIndex(webId: string, fetch: any, isPrivate: boolean): Promise<NamedNode<string>> {
const profileMe = await this.getMeProfile(webId, fetch)
Expand Down Expand Up @@ -90,13 +98,13 @@ export class TypeIndexHelper {
}
}


/**
* Retrieves an array of strings representing instances from the typeIndex.
* Retrieves a list of instances from the typeIndex.
*
* @param {Session} session - The session object.
* @param {boolean} isPrivate - A boolean indicating if the instances are private.
* @return {Promise<string[]>} A promise that resolves to an array of strings representing instances.
* @param {string} webId - The WebID of the user.
* @param {any} fetch - The authenticated fetch function to use for HTTP requests.
* @param {true} isPrivate - Indicates if the instances are private.
* @return {Promise<string[]>} - A promise that resolves to an array of instance URLs.
*/
public static async getFromTypeIndex(webId: string, fetch: any, isPrivate: true): Promise<string[]> {
const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate);
Expand Down Expand Up @@ -139,12 +147,13 @@ export class TypeIndexHelper {
}

/**
* Registers the indexUrl in the typeIndex.
* Registers the given webId in the typeIndex.
*
* @param {Session} session - The session object.
* @param {string} webId - The WebID of the user.
* @param {any} fetch - The authenticated fetch function to use for HTTP requests.
* @param {string} indexUrl - The URL of the typeIndex.
* @param {boolean} isPrivate - Indicates whether the typeIndex is private.
* @return {Promise<SolidDataset>} A promise that resolves to the updated typeIndex.
* @param {boolean} isPrivate - Flag indicating if the typeIndex is private.
* @return {Promise<SolidDataset>} The updated typeIndex dataset.
*/
public static async registerInTypeIndex(webId: string, fetch: any, indexUrl: string, isPrivate: boolean): Promise<SolidDataset> {
const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate);
Expand All @@ -162,6 +171,13 @@ export class TypeIndexHelper {
return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { fetch: fetch });
}

/**
* Creates a typeIndex using the provided fetch function and typeIndex URL.
*
* @param {any} fetch - The authenticated fetch function to use for HTTP requests.
* @param {string} typeIndexUrl - The URL of the typeIndex.
* @return {Promise<SolidDataset | undefined>} A promise that resolves to the created typeIndex SolidDataset, or undefined if there was an error.
*/
public static async createTypeIndex(fetch: any, typeIndexUrl: string): Promise<SolidDataset | undefined> {
try {
await fetch(typeIndexUrl, {
Expand All @@ -178,14 +194,33 @@ export class TypeIndexHelper {
}
}

/**
* Returns the name of the typeIndex file based on the given isPrivate flag.
*
* @param {boolean} isPrivate - Indicates whether the typeIndex file is private or public.
* @return {"privateTypeIndex" | "publicTypeIndex"} - The name of the typeIndex file.
*/
public static getTypeIndexFileName(isPrivate: boolean): "privateTypeIndex" | "publicTypeIndex" {
return isPrivate ? "privateTypeIndex" : "publicTypeIndex";
}

/**
* Returns the typeIndex predicate based on the given isPrivate flag.
*
* @param {boolean} isPrivate - A flag indicating whether the typeIndex should be private.
* @return {string} The typeIndex predicate.
*/
public static getTypeIndexPredicate(isPrivate: boolean): string {
return isPrivate ? __privateTypeIndex : __publicTypeIndex;
}

/**
* Returns the URL for the typeIndex file based on the given webId and typeIndexFileName.
*
* @param {string} webId - The webId used to construct the URL.
* @param {string} typeIndexFileName - The name of the typeIndex file.
* @return {string} The URL for the typeIndex file.
*/
public static getTypeIndexURL(webId: string, typeIndexFileName: string): string {
return `${webId.split("/profile")[0]}/settings/${typeIndexFileName}.ttl`;
}
Expand Down

0 comments on commit 7d5bfe8

Please sign in to comment.