diff --git a/README.md b/README.md index e69de29..eb1d1a8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,48 @@ +# solid-typeindex-support + +## Development + +```bash +git clone https://github.com/pondersource/solid-typeindex-support +npm install +npm run test +``` + +`TypeIndexHelper` This class provides methods for working with Solid Type Index, which is a way of storing and retrieving information about the types of data a user has in their personal online data store (POD). + +## Methods: +The `TypeIndexHelper` class has several methods, such as: +- `getMeProfile`: This method returns the user’s profile document from their WebID. +- `getTypeIndex`: This method returns the user’s typeIndex document URL as a `namedNode` from their profile document. +- `getFromTypeIndex`: This method returns an array of URLs that match a given type from the user’s typeIndex document. +- `registerInTypeIndex`: This method adds a new entry to the user’s typeIndex document for a given type and URL. +- `createTypeIndex`: This method creates a new typeIndex document for the user if they don’t have one. +- `getTypeIndexFileName`: This function returns the file name of the typeIndex document, which is settings.ttl. +- `getTypeIndexPredicate`: This function returns the predicate that links the user’s profile document to their typeIndex document. +- `getTypeIndexURL`: This function returns the full URL of the user’s typeIndex document by appending the file name to their POD root URL. + +## Dependencies: +`@inrupt/solid-client`: This module provides methods for interacting with the Solid Pod. +`@inrupt/vocab-common-rdf`: This module provides methods for working with RDF data. +`@rdfjs/data-model`: This module provides methods for working with RDF data. + + +## Usage + +```bash +mpm install solid-typeindex-support +``` + +```typescript +import { TypeIndexHelper } from "solid-typeindex-support"; +``` + +```typescript +const webId = "https://fake-pod.net/profile/card#me"; +const indexUrl = "https://fake-pod.net/settings/privateTypeIndex.ttl"; +const isPrivate = true; + +const registeries: string[] = await TypeIndexHelper.getFromTypeIndex(webId, session.fetch, isPrivate); + +const result: SolidDataset = await TypeIndexHelper.registerInTypeIndex(webId, session.fetch, indexUrl, isPrivate); +``` \ No newline at end of file diff --git a/src/TypeIndexHelper.ts b/src/TypeIndexHelper.ts index 4e755ca..fef7b44 100644 --- a/src/TypeIndexHelper.ts +++ b/src/TypeIndexHelper.ts @@ -26,6 +26,7 @@ export class TypeIndexHelper { * @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. + * @internal */ public static async getMeProfile(webId: string, fetch: any): Promise { @@ -57,6 +58,7 @@ export class TypeIndexHelper { * @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. + * @internal */ public static async getTypeIndex(webId: string, fetch: any, isPrivate: boolean): Promise> { const profileMe = await this.getMeProfile(webId, fetch) @@ -177,6 +179,7 @@ export class TypeIndexHelper { * @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. + * @internal */ public static async createTypeIndex(fetch: any, typeIndexUrl: string): Promise { try { @@ -199,6 +202,7 @@ export class TypeIndexHelper { * * @param {boolean} isPrivate - Indicates whether the typeIndex file is private or public. * @return {"privateTypeIndex" | "publicTypeIndex"} - The name of the typeIndex file. + * @internal */ public static getTypeIndexFileName(isPrivate: boolean): "privateTypeIndex" | "publicTypeIndex" { return isPrivate ? "privateTypeIndex" : "publicTypeIndex"; @@ -209,6 +213,7 @@ export class TypeIndexHelper { * * @param {boolean} isPrivate - A flag indicating whether the typeIndex should be private. * @return {string} The typeIndex predicate. + * @internal */ public static getTypeIndexPredicate(isPrivate: boolean): string { return isPrivate ? __privateTypeIndex : __publicTypeIndex; @@ -220,6 +225,7 @@ export class TypeIndexHelper { * @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. + * @internal */ public static getTypeIndexURL(webId: string, typeIndexFileName: string): string { return `${webId.split("/profile")[0]}/settings/${typeIndexFileName}.ttl`;