Skip to content

Commit

Permalink
bookmarks-rdflib: simplify storage discovery
Browse files Browse the repository at this point in the history
there is no need to distinguish documents and containers, since the module will handle the nuances anyway when creating or listing bookmarks
  • Loading branch information
angelo-v committed Jul 25, 2024
1 parent 69172aa commit cd54437
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 79 deletions.
24 changes: 9 additions & 15 deletions bookmarks/rdflib/examples/create-bookmark-within-container.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import BookmarksModule from "../dist/index.js";
import { Fetcher, graph, UpdateManager } from "rdflib";
import BookmarksModule from '../dist/index.js';
import {Fetcher, graph, UpdateManager} from "rdflib";

const store = graph();
const fetcher = new Fetcher(store);
const updater = new UpdateManager(store);
const bookmarks = new BookmarksModule({ store, fetcher, updater });

const storages = await bookmarks.discoverStorage("http://localhost:3000/alice/profile/card#me");
const privateContainerUrl = storages.private.containerUrls[0];
if (!privateContainerUrl) {
throw new Error("there is no private container for bookmarks");
}
const store = graph()
const fetcher = new Fetcher(store)
const updater = new UpdateManager(store)
const bookmarks = new BookmarksModule({store, fetcher, updater})

const uri = await bookmarks.createBookmark({
storageUrl: privateContainerUrl,
storageUrl: "http://localhost:3000/alice/bookmarks/",
title: "My favorite website",
url: "https://favorite.example"
});
})

console.log("new bookmark: " + uri);
console.log("new bookmark: " + uri)
24 changes: 9 additions & 15 deletions bookmarks/rdflib/examples/create-bookmark-within-document.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import BookmarksModule from "../dist/index.js";
import { Fetcher, graph, UpdateManager } from "rdflib";
import BookmarksModule from '../dist/index.js';
import {Fetcher, graph, UpdateManager} from "rdflib";

const store = graph();
const fetcher = new Fetcher(store);
const updater = new UpdateManager(store);
const bookmarks = new BookmarksModule({ store, fetcher, updater });

const storages = await bookmarks.discoverStorage("http://localhost:3000/alice/profile/card#me");
const publicDocumentUrl = storages.public.documentUrls[0];
if (!publicDocumentUrl) {
throw new Error("there is no public document for bookmarks");
}
const store = graph()
const fetcher = new Fetcher(store)
const updater = new UpdateManager(store)
const bookmarks = new BookmarksModule({store, fetcher, updater})

const uri = await bookmarks.createBookmark({
storageUrl: publicDocumentUrl,
storageUrl: "http://localhost:3000/alice/public/bookmarks",
title: "My favorite website",
url: "https://favorite.example"
});
})

console.log("new bookmark: " + uri);
console.log("new bookmark: " + uri)
17 changes: 6 additions & 11 deletions bookmarks/rdflib/src/e2e-tests/bookmarks.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { setupModule } from "../test-support/setupModule.js";

describe("bookmarks", () => {

it("can discover bookmark storages", async () => {
const bookmarks = setupModule();
const result = await bookmarks.discoverStorage("http://localhost:3456/profile/card#me");
const result = await bookmarks.discoverStorage(
"http://localhost:3456/profile/card#me",
);
expect(result).toEqual({
private: {
documentUrls: [],
containerUrls: ["http://localhost:3456/bookmarks/"]
},
public: {
documentUrls: ["http://localhost:3456/public/bookmarks"],
containerUrls: []
},
})
privateUrls: ["http://localhost:3456/bookmarks/"],
publicUrls: ["http://localhost:3456/public/bookmarks"],
});
});

it("can create a new bookmark in a container", async () => {
Expand Down
18 changes: 2 additions & 16 deletions bookmarks/rdflib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ export interface CreateBookmarkCommand {
url: string;
}

/**
* URLs of potential bookmark storages (documents and/or containers)
*/
export interface StorageLocations {
/**
* List of URLs pointing to documents containing bookmarks
*/
documentUrls: string[];
/**
* List of URLs pointing to containers containing bookmarks
*/
containerUrls: string[];
}

/**
* Object describing potential storage locations for bookmarks.
*
Expand All @@ -42,11 +28,11 @@ export interface BookmarkStorage {
/**
* locations for personal use, not listed publicly
*/
private: StorageLocations;
privateUrls: string[];
/**
* Locations that can be discovered by the public
*/
public: StorageLocations;
publicUrls: string[];
}

export interface BookmarksModule {
Expand Down
16 changes: 8 additions & 8 deletions bookmarks/rdflib/src/module/BookmarksModuleRdfLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export class BookmarksModuleRdfLib implements BookmarksModule {
BOOKM_BOOKMARK,
);
return {
private: {
documentUrls: urisOf(registrations.private.instances),
containerUrls: urisOf(registrations.private.instanceContainers),
},
public: {
documentUrls: urisOf(registrations.public.instances),
containerUrls: urisOf(registrations.public.instanceContainers),
},
privateUrls: urisOf([
...registrations.private.instances,
...registrations.private.instanceContainers,
]),
publicUrls: urisOf([
...registrations.public.instances,
...registrations.public.instanceContainers,
]),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,16 @@ describe("discover storage", () => {
);

expect(result).toEqual({
private: {
containerUrls: ["https://pod.test/private/read-it-later/"],
documentUrls: [
"https://pod.test/alice/private/bookmarks.ttl",
"https://pod.test/alice/private/more-bookmarks",
],
},
public: {
containerUrls: ["https://pod.test/alice/public/recommended-readings/"],
documentUrls: [
"https://pod.test/alice/public/bookmarks.ttl",
"https://pod.test/alice/public/more-bookmarks",
],
},
privateUrls: [
"https://pod.test/alice/private/bookmarks.ttl",
"https://pod.test/alice/private/more-bookmarks",
"https://pod.test/private/read-it-later/",
],
publicUrls: [
"https://pod.test/alice/public/bookmarks.ttl",
"https://pod.test/alice/public/more-bookmarks",
"https://pod.test/alice/public/recommended-readings/",
],
});
});
});

0 comments on commit cd54437

Please sign in to comment.