From 7d5bfe89ec3eff0d4dd860d153c94188d63f82ac Mon Sep 17 00:00:00 2001 From: Reza Soltani Date: Wed, 6 Dec 2023 17:02:41 +0330 Subject: [PATCH] add jsDocs --- src/TypeIndexHelper.ts | 61 +++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/src/TypeIndexHelper.ts b/src/TypeIndexHelper.ts index 6690c46..4e755ca 100644 --- a/src/TypeIndexHelper.ts +++ b/src/TypeIndexHelper.ts @@ -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} - The user profile or null if not found. + */ public static async getMeProfile(webId: string, fetch: any): Promise { const profileDS = await getSolidDataset(webId, { fetch: fetch }); @@ -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>} 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>} A Promise that resolves with the typeIndex. */ public static async getTypeIndex(webId: string, fetch: any, isPrivate: boolean): Promise> { const profileMe = await this.getMeProfile(webId, fetch) @@ -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} 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} - A promise that resolves to an array of instance URLs. */ public static async getFromTypeIndex(webId: string, fetch: any, isPrivate: true): Promise { const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate); @@ -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} A promise that resolves to the updated typeIndex. + * @param {boolean} isPrivate - Flag indicating if the typeIndex is private. + * @return {Promise} The updated typeIndex dataset. */ public static async registerInTypeIndex(webId: string, fetch: any, indexUrl: string, isPrivate: boolean): Promise { const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate); @@ -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} 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 { try { await fetch(typeIndexUrl, { @@ -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`; }