npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solid-data-modules/bookmarks-vanilla

v0.0.7

Published

See [Docs](https://solid-contrib.github.io/data-modules/bookmarks-vanilla/index.html) for more information about this module. # How to use this module

Downloads

15

Readme

Bookmarks Data Module using vanilla JavaScript

See Docs for more information about this module.

How to use this module

install it as a dependency to you application

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

import the module

import { Bookmark } from "@solid-data-modules/bookmarks-vanilla"

use it to work with bookmarks

const result: IBookmark[] = await Bookmark.getAll(session.fetch, session.info.webId, "<defaultRegisteryUrl>");

the getAll method will return an array of IBookmark, in case there are no bookmarks it will return an empty array.

const result: IBookmark | undefined  = await Bookmark.get("url", session.fetch);

the get method will return an IBookmark, in case there is no bookmark it will return undefined.

const result: boolean  = await Bookmark.delete("url", session.fetch);

the delete method will return a boolean indicating if the bookmark was deleted.

const result: boolean  = await Bookmark.create(payload: ICreateBookmark, session.fetch, session.info.webId, "<defaultRegisteryUrl>");

the create method will return a boolean indicating if the bookmark was created.

const result: IBookmark | undefined = await Bookmark.update("url", payload: IUpdateBookmark, session.fetch);

the update method will return an IBookmark, in case there is no bookmark it will return undefined.

  • url indicates the primary key of the bookmark, (IRI in the RDF)
  • defaultRegisteryUrl indicates the default registry url in case you want to specify, and it's optional, and obviously it has to be a valid URL, the default value is /bookmarks/index.ttl
  • payload is an object containing the fields of the bookmark
  • you need to pass the authenticated fetch and a webId to the methods, these values is obtained from the auth.ts in the demo app.
  • session object can be obtained from:
    • useSession hook inside React Components, after handleIncomingRedirect hook is called.
    • getDefaultSession function inside vanilla js, after handleIncomingRedirect hook is called.

Types

type ICreateBookmark = {
    title: string
    topic?: string
    link: string
    creator?: string,
}

type IUpdateBookmark = {
    title: string
    topic?: string
    link: string
    creator?: string,
}

type IBookmark = ICreateBookmark & {
    url: string
    created?: string
    updated?: string
}

Development

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

Demo app

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

npm run build
cd demo
npm install
npm run dev

Explanation of the demo app

The login is handled by src/utils/auth.ts.

Once its completed the auth proccess it will redirect to the redirect url, and from there it will use Bookmark static methods to CRUD the bookmarks in Bookmarks component

methods

the Bookmark.getAll takes an authenticated fetch to use for fetching the data as well as a webId of the logedin user. also it takes the defaultRegisteryUrl in case you want to store the bookmarks in specific directory.

the Bookmark.get and Bookmark.delete methods take the url of the bookmark as the primary key and an authenticated fetch.

the Bookmark.create takes an object with fields: label, topic and link, creator, created and updated as the payload with an authenticated fetch and a webId. also it takes the defaultRegisteryUrl in case you want to store the bookmarks in specific directory.

the Bookmark.update takes the url of the bookmark as primary key, then as a payload, it takes an object with fields: label, topic and link, creator, created and updated with an authenticated fetch.

the Bookmark.delete takes the url of the bookmark as primary key, with an authenticated fetch.

Schema: label: any string value should be fine (required) link: link should be a valid URL e.g. starts with http or https (required) topic: topic can be both a string or a link to a topic e.g. "tipoc title" | "http://example.com/topic" (optional) creator: a URL to the creator e.g. WebID (optional) created: DateTime string e.g. "2023-10-21T14:16:16Z" (optional) updated: DateTime string e.g. "2023-10-21T14:16:16Z" (optional)

example payload

{
    "label": "label",
    "topic": "http://example.com/topic", // it also works with strings "topic title"
    "link": "http://example.com",
    "creator": "https://michielbdejong.solidcommunity.net/profile/card#me",
    "created": "2023-10-21T14:16:16Z",
    "updated": "2023-10-21T14:16:16Z"
}

typeIndex Support

The Bookmak.getRegisteryUrls is the entrypoint for the data module and typeIndex. it checkes if typeIndex has a solid:instance or solid:instanceContainer registerd and returns the url of them as an array of strings. also it takes the defaultRegisteryUrl in case you want to store the bookmarks in specific directory.

see Solid Typeindex Support for more information on typeindex support