diff --git a/docs/solid-typeindex-support.typeindexhelper.md b/docs/solid-typeindex-support.typeindexhelper.md index a22cd02..e1c0e31 100644 --- a/docs/solid-typeindex-support.typeindexhelper.md +++ b/docs/solid-typeindex-support.typeindexhelper.md @@ -17,5 +17,5 @@ export declare class TypeIndexHelper | Method | Modifiers | Description | | --- | --- | --- | | [getFromTypeIndex(webId, rdfClass, fetch, isPrivate)](./solid-typeindex-support.typeindexhelper.getfromtypeindex.md) | static | Retrieves all instances of the given RDF class from the user's typeIndexe. | -| [registerInTypeIndex(webId, typeRegistrationTitle, rdfClass, fetch, solidInstanceUrl, isPrivate)](./solid-typeindex-support.typeindexhelper.registerintypeindex.md) | static | Registers a typeRegistration in the user's typeIndexe. | +| [registerInTypeIndex(webId, typeRegistrationTitle, rdfClass, fetch, registeryUrl, isContainer, isPrivate)](./solid-typeindex-support.typeindexhelper.registerintypeindex.md) | static | Registers a typeRegistration in the user's typeIndexe. | diff --git a/docs/solid-typeindex-support.typeindexhelper.registerintypeindex.md b/docs/solid-typeindex-support.typeindexhelper.registerintypeindex.md index 30e0ed6..827ca4c 100644 --- a/docs/solid-typeindex-support.typeindexhelper.registerintypeindex.md +++ b/docs/solid-typeindex-support.typeindexhelper.registerintypeindex.md @@ -9,7 +9,7 @@ Registers a typeRegistration in the user's typeIndexe. **Signature:** ```typescript -static registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClass: string, fetch: any, solidInstanceUrl: string, isPrivate: boolean): Promise; +static registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClass: string, fetch: any, registeryUrl: string, isContainer: boolean, isPrivate: boolean): Promise; ``` ## Parameters @@ -20,7 +20,8 @@ static registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClas | typeRegistrationTitle | string | The title to use for the typeRegistration inside the typeIndex, | | rdfClass | string | The RDF class that this registration is for, as a Valid URL | | fetch | any | The authenticated fetch function | -| solidInstanceUrl | string | The URL of the solid:instance being registered | +| registeryUrl | string | The URL of the solid:instance or solid:instanceContainer being registered | +| isContainer | boolean | Whether to register a solid:instanceContainer or a solid:instance | | isPrivate | boolean | Whether to register in the private or public typeIndexe | **Returns:** diff --git a/etc/solid-typeindex-support.api.md b/etc/solid-typeindex-support.api.md index 3a8f4b4..f62d4b6 100644 --- a/etc/solid-typeindex-support.api.md +++ b/etc/solid-typeindex-support.api.md @@ -12,7 +12,7 @@ export class TypeIndexHelper { instanceContainers: string[]; instances: string[]; }>; - static registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClass: string, fetch: any, solidInstanceUrl: string, isPrivate: boolean): Promise; + static registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClass: string, fetch: any, registeryUrl: string, isContainer: boolean, isPrivate: boolean): Promise; } // (No @packageDocumentation comment for this package) diff --git a/package.json b/package.json index 73480a8..7365596 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rezasoltani/solid-typeindex-support", - "version": "0.0.3", + "version": "0.0.4", "description": "", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/TypeIndexHelper.ts b/src/TypeIndexHelper.ts index 1822917..c6fb61d 100644 --- a/src/TypeIndexHelper.ts +++ b/src/TypeIndexHelper.ts @@ -158,7 +158,7 @@ export class TypeIndexHelper { const all = getThingAll(instanceContainerDS); // all files under the instanceContainer - const urls = all.map(x => x.url) // all file urls + const urls = all.filter(x => x.url !== "").map(x => x.url) // all file urls return urls.filter(url => url !== instanceContainer) // remove the instanceContainer itself, only file urls needed; }) @@ -180,7 +180,8 @@ export class TypeIndexHelper { * @param typeRegistrationTitle - The title to use for the typeRegistration inside the typeIndex, * @param rdfClass - The RDF class that this registration is for, as a Valid URL * @param fetch - The authenticated fetch function - * @param solidInstanceUrl - The URL of the solid:instance being registered + * @param registeryUrl - The URL of the solid:instance or solid:instanceContainer being registered + * @param isContainer - Whether to register a solid:instanceContainer or a solid:instance * @param isPrivate - Whether to register in the private or public typeIndexe * @returns A Promise resolving to the updated typeIndexe dataset */ @@ -189,8 +190,9 @@ export class TypeIndexHelper { typeRegistrationTitle: string, rdfClass: string, fetch: any, - solidInstanceUrl: string, - isPrivate: boolean + registeryUrl: string, + isContainer: boolean, + isPrivate: boolean, ): Promise { const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate); @@ -202,7 +204,7 @@ export class TypeIndexHelper { createThing({ name: typeRegistrationTitle }) ) .addNamedNode(__forClass, namedNode(rdfClass)) - .addNamedNode(__solid_instance, namedNode(solidInstanceUrl)) + .addNamedNode(isContainer ? __solid_instance_container : __solid_instance, namedNode(registeryUrl)) .addUrl(RDF.type, __solidTypeRegistration) .build(); diff --git a/test/unit/TypeIndexHelper.test.ts b/test/unit/TypeIndexHelper.test.ts index 9ce1fd6..265d2c9 100644 --- a/test/unit/TypeIndexHelper.test.ts +++ b/test/unit/TypeIndexHelper.test.ts @@ -118,7 +118,8 @@ describe('getFromTypeIndex', () => { const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, BOOKMARK.Bookmark, session.fetch, isPrivate); - expect(result).toEqual([]); + expect(result.instances).toEqual([]); + expect(result.instanceContainers).toEqual([]); }); it('should return an array of instances', async () => { const isPrivate = true; @@ -128,7 +129,8 @@ describe('getFromTypeIndex', () => { const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, BOOKMARK.Bookmark, session.fetch, isPrivate); - expect(result.length).toBeGreaterThan(0); + expect(result.instances.length).toBeGreaterThan(0); + expect(result.instanceContainers.length).toBeGreaterThan(0); }); }); @@ -139,13 +141,14 @@ describe("registerInTypeIndex", () => { // }); test('Register in typeIndex - Private typeIndex', async () => { const isPrivate = true; + const isContainer = false; jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(privateTypeIndexPath)); jest.spyOn(inruptSOLIDClient, "getSolidDataset").mockResolvedValue(loadFixture("privateTypeIndexDS.json")); jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("privateTypeIndexDS.json")); jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("privateTypeIndexDS.json")); - const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isPrivate); + const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isContainer, isPrivate); expect(res).toEqual(loadFixture("privateTypeIndexDS.json")); expect(TypeIndexHelper.getTypeIndex).toHaveBeenCalledWith(session.info.webId, session.fetch, isPrivate); @@ -156,13 +159,14 @@ describe("registerInTypeIndex", () => { test('Register in typeIndex - Public typeIndex', async () => { const isPrivate = false; + const isContainer = false; jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(privateTypeIndexPath)); jest.spyOn(inruptSOLIDClient, "getSolidDataset").mockResolvedValue(loadFixture("publicTypeIndexDS.json")); jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("publicTypeIndexDS.json")); jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("publicTypeIndexDS.json")); - const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isPrivate); + const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isContainer, isPrivate); expect(res).toEqual(loadFixture("publicTypeIndexDS.json")); expect(TypeIndexHelper.getTypeIndex).toHaveBeenCalledWith(session.info.webId, session.fetch, isPrivate); @@ -220,7 +224,6 @@ describe("getTypeIndexPredicate", () => { it("returns __privateTypeIndex if isPrivate is true", () => { const isPrivate = true; const result = TypeIndexHelper.getTypeIndexPredicate(isPrivate); - console.log("🚀 ~ file: TypeIndexHelper.test.ts:223 ~ it ~ result:", result) expect(result).toBe(__privateTypeIndex); }); diff --git a/test/unit/fixtures/privateTypeIndex.ttl b/test/unit/fixtures/privateTypeIndex.ttl index f4e5563..fbfdb8f 100644 --- a/test/unit/fixtures/privateTypeIndex.ttl +++ b/test/unit/fixtures/privateTypeIndex.ttl @@ -7,14 +7,6 @@ <> a solid:TypeIndex, solid:UnlistedDocument. -:2bdc3da9-e0f0-48b5-b1aa-8123bb468a92 - a solid:TypeRegistration; - solid:forClass schem:WatchAction; - solid:instanceContainer mov: . -:5677e892-fad5-4039-8108-4f4ed2640b98 - a solid:TypeRegistration; - solid:forClass schem:Movie; - solid:instanceContainer mov: . :bookmarks_registery a solid:TypeRegistration; solid:forClass bookm:Bookmark;