Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 6, 2023
1 parent 7d5bfe8 commit f4cb6cc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
```
6 changes: 6 additions & 0 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThingPersisted | null>} - The user profile or null if not found.
* @internal
*/
public static async getMeProfile(webId: string, fetch: any): Promise<ThingPersisted | null> {

Expand Down Expand Up @@ -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<NamedNode<string>>} A Promise that resolves with the typeIndex.
* @internal
*/
public static async getTypeIndex(webId: string, fetch: any, isPrivate: boolean): Promise<NamedNode<string>> {
const profileMe = await this.getMeProfile(webId, fetch)
Expand Down Expand Up @@ -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<SolidDataset | undefined>} 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<SolidDataset | undefined> {
try {
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -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`;
Expand Down

0 comments on commit f4cb6cc

Please sign in to comment.