@solid-data-modules/bookmarks-soukai
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Bookmarks Data Module for Soukai

See Docs for more information about this module.

Development

Make sure you have node v. 20.10.0 installed.

git clone https://github.com/solid-contrib/data-modules
cd data-modules
cd bookmarks/soukai
npm install
npm run test

Demo app

Assuming you just ran the 'development' steps above and are now in the bookmarks/soukai folder.

npm run build
cd demo
npm install
npm run dev

Explanation of the demo app

First of all, the login and booting is handled by src/utils.js.

Once up and running, the demo app instantiates the BookmarkFactory inside a React useEffect callback. After that, it simply calls factory.getAll() to retrieve all bookmarks that are discoverable through the private type index on the Solid pod of the currently authenticated user. The setBookmarks(bookmarks) call hands the fetched items over to React.

The factory.get and factory.remove functions take the url of a bookmark as the primary key.

And factory.create takes an object with three string fields: label, topic and link.

And finally there is factory.update which takes the url as a primary key, and then an object with the same three string fields as the second argument.

Boot Engine

bootSolidModels();
bootModels({ Bookmark: Bookmark });

get Factory instance (it's a singleton)

const factory = await BookmarkFactory.getInstance(
    {
        webId: userSession?.info.webId,
        fetch: userSession?.fetch,
        isPrivate: true,
    },
    "bookmarks/" // you can optionally pass a path to override typeRegistration
);

use factory instance to CRUD over bookmarks

const bookmarks = await bookmarkFactory.getAll();
const bookmark  = await bookmarkFactory.get("<pk>");
const bookmark  = await bookmarkFactory.create({ label: "example", link: "https://example.com", hasTopic: "Topic" });
const bookmark  = await bookmarkFactory.remove("<pk>");
const bookmark  = await bookmarkFactory.update("<pk>", { label: "example", link: "https://example.com", hasTopic: "Topic"  });

Package Sidebar

Install

npm i @solid-data-modules/bookmarks-soukai

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

4.31 kB

Total Files

2

Last publish

Collaborators

  • soltanireza54
  • michielbdejong
  • aveltens