Skip to content

Commit cd54437

Browse files
committed
bookmarks-rdflib: simplify storage discovery
there is no need to distinguish documents and containers, since the module will handle the nuances anyway when creating or listing bookmarks
1 parent 69172aa commit cd54437

File tree

6 files changed

+44
-79
lines changed

6 files changed

+44
-79
lines changed
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import BookmarksModule from "../dist/index.js";
2-
import { Fetcher, graph, UpdateManager } from "rdflib";
1+
import BookmarksModule from '../dist/index.js';
2+
import {Fetcher, graph, UpdateManager} from "rdflib";
33

4-
const store = graph();
5-
const fetcher = new Fetcher(store);
6-
const updater = new UpdateManager(store);
7-
const bookmarks = new BookmarksModule({ store, fetcher, updater });
8-
9-
const storages = await bookmarks.discoverStorage("http://localhost:3000/alice/profile/card#me");
10-
const privateContainerUrl = storages.private.containerUrls[0];
11-
if (!privateContainerUrl) {
12-
throw new Error("there is no private container for bookmarks");
13-
}
4+
const store = graph()
5+
const fetcher = new Fetcher(store)
6+
const updater = new UpdateManager(store)
7+
const bookmarks = new BookmarksModule({store, fetcher, updater})
148

159
const uri = await bookmarks.createBookmark({
16-
storageUrl: privateContainerUrl,
10+
storageUrl: "http://localhost:3000/alice/bookmarks/",
1711
title: "My favorite website",
1812
url: "https://favorite.example"
19-
});
13+
})
2014

21-
console.log("new bookmark: " + uri);
15+
console.log("new bookmark: " + uri)
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import BookmarksModule from "../dist/index.js";
2-
import { Fetcher, graph, UpdateManager } from "rdflib";
1+
import BookmarksModule from '../dist/index.js';
2+
import {Fetcher, graph, UpdateManager} from "rdflib";
33

4-
const store = graph();
5-
const fetcher = new Fetcher(store);
6-
const updater = new UpdateManager(store);
7-
const bookmarks = new BookmarksModule({ store, fetcher, updater });
8-
9-
const storages = await bookmarks.discoverStorage("http://localhost:3000/alice/profile/card#me");
10-
const publicDocumentUrl = storages.public.documentUrls[0];
11-
if (!publicDocumentUrl) {
12-
throw new Error("there is no public document for bookmarks");
13-
}
4+
const store = graph()
5+
const fetcher = new Fetcher(store)
6+
const updater = new UpdateManager(store)
7+
const bookmarks = new BookmarksModule({store, fetcher, updater})
148

159
const uri = await bookmarks.createBookmark({
16-
storageUrl: publicDocumentUrl,
10+
storageUrl: "http://localhost:3000/alice/public/bookmarks",
1711
title: "My favorite website",
1812
url: "https://favorite.example"
19-
});
13+
})
2014

21-
console.log("new bookmark: " + uri);
15+
console.log("new bookmark: " + uri)

bookmarks/rdflib/src/e2e-tests/bookmarks.e2e.spec.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { setupModule } from "../test-support/setupModule.js";
22

33
describe("bookmarks", () => {
4-
54
it("can discover bookmark storages", async () => {
65
const bookmarks = setupModule();
7-
const result = await bookmarks.discoverStorage("http://localhost:3456/profile/card#me");
6+
const result = await bookmarks.discoverStorage(
7+
"http://localhost:3456/profile/card#me",
8+
);
89
expect(result).toEqual({
9-
private: {
10-
documentUrls: [],
11-
containerUrls: ["http://localhost:3456/bookmarks/"]
12-
},
13-
public: {
14-
documentUrls: ["http://localhost:3456/public/bookmarks"],
15-
containerUrls: []
16-
},
17-
})
10+
privateUrls: ["http://localhost:3456/bookmarks/"],
11+
publicUrls: ["http://localhost:3456/public/bookmarks"],
12+
});
1813
});
1914

2015
it("can create a new bookmark in a container", async () => {

bookmarks/rdflib/src/index.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ export interface CreateBookmarkCommand {
2020
url: string;
2121
}
2222

23-
/**
24-
* URLs of potential bookmark storages (documents and/or containers)
25-
*/
26-
export interface StorageLocations {
27-
/**
28-
* List of URLs pointing to documents containing bookmarks
29-
*/
30-
documentUrls: string[];
31-
/**
32-
* List of URLs pointing to containers containing bookmarks
33-
*/
34-
containerUrls: string[];
35-
}
36-
3723
/**
3824
* Object describing potential storage locations for bookmarks.
3925
*
@@ -42,11 +28,11 @@ export interface BookmarkStorage {
4228
/**
4329
* locations for personal use, not listed publicly
4430
*/
45-
private: StorageLocations;
31+
privateUrls: string[];
4632
/**
4733
* Locations that can be discovered by the public
4834
*/
49-
public: StorageLocations;
35+
publicUrls: string[];
5036
}
5137

5238
export interface BookmarksModule {

bookmarks/rdflib/src/module/BookmarksModuleRdfLib.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export class BookmarksModuleRdfLib implements BookmarksModule {
4343
BOOKM_BOOKMARK,
4444
);
4545
return {
46-
private: {
47-
documentUrls: urisOf(registrations.private.instances),
48-
containerUrls: urisOf(registrations.private.instanceContainers),
49-
},
50-
public: {
51-
documentUrls: urisOf(registrations.public.instances),
52-
containerUrls: urisOf(registrations.public.instanceContainers),
53-
},
46+
privateUrls: urisOf([
47+
...registrations.private.instances,
48+
...registrations.private.instanceContainers,
49+
]),
50+
publicUrls: urisOf([
51+
...registrations.public.instances,
52+
...registrations.public.instanceContainers,
53+
]),
5454
};
5555
}
5656

bookmarks/rdflib/src/module/_integration-tests/discover-storage.integration.spec.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,16 @@ describe("discover storage", () => {
9494
);
9595

9696
expect(result).toEqual({
97-
private: {
98-
containerUrls: ["https://pod.test/private/read-it-later/"],
99-
documentUrls: [
100-
"https://pod.test/alice/private/bookmarks.ttl",
101-
"https://pod.test/alice/private/more-bookmarks",
102-
],
103-
},
104-
public: {
105-
containerUrls: ["https://pod.test/alice/public/recommended-readings/"],
106-
documentUrls: [
107-
"https://pod.test/alice/public/bookmarks.ttl",
108-
"https://pod.test/alice/public/more-bookmarks",
109-
],
110-
},
97+
privateUrls: [
98+
"https://pod.test/alice/private/bookmarks.ttl",
99+
"https://pod.test/alice/private/more-bookmarks",
100+
"https://pod.test/private/read-it-later/",
101+
],
102+
publicUrls: [
103+
"https://pod.test/alice/public/bookmarks.ttl",
104+
"https://pod.test/alice/public/more-bookmarks",
105+
"https://pod.test/alice/public/recommended-readings/",
106+
],
111107
});
112108
});
113109
});

0 commit comments

Comments
 (0)