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

@basementuniverse/jsonpad-realtime-sdk

v1.2.1

Published

JSONPad Realtime SDK for Node and browser

Downloads

160

Readme

JSONPad Realtime SDK

This package allows you to connect to JSONPad Realtime and get realtime updates when your lists or items change.

Installation

npm install @basementuniverse/jsonpad-realtime-sdk

Usage

Create an instance of the JSONPad Realtime SDK and pass in your API token:

Node (JS):

const JSONPadRealtime = require('@basementuniverse/jsonpad-realtime-sdk').default;

const jsonpadRealtime = new JSONPadRealtime('your-api-token');

Node (TS):

import JSONPadRealtime from '@basementuniverse/jsonpad-realtime-sdk';

const jsonpadRealtime = new JSONPadRealtime('your-api-token');

Browser:

<script src="https://cdn.jsdelivr.net/npm/@basementuniverse/[email protected]/build/jsonpad-realtime-sdk.js"></script>
<script>

const jsonpadRealtime = new JSONPadRealtime.default('your-api-token');

</script>

Next, start listening for events on your lists or items:

jsonpadRealtime.listen(
  [
    'list-created',
    'list-updated',
    'list-deleted',
    'item-created',
    'item-updated',
    'item-restored',
    'item-deleted',
  ]
);

Attach event listeners to the JSONPad Realtime SDK instance:

jsonpadRealtime.addEventListener('list-created', e => {
  console.log(`A list called ${e.detail.model.name} was created!`);
});

If you want to stop listening for events and disconnect from the server, you can call the close method:

jsonpadRealtime.close();

listen() method

The listen() method takes an array of event types to listen for. You can pass in any of the following event types:

  • list-created
  • list-updated
  • list-deleted
  • item-created
  • item-updated
  • item-restored
  • item-deleted

You can also optionally pass in an array of list ids or path names, and item ids or aliases to listen for. For example:

jsonpadRealtime.listen(
  [
    'list-updated',
    'item-updated',
  ],
  [
    '86059de7-9b16-4469-a630-23c8f69944b6',
    'a2c706a6-5212-4e8a-92ad-bce1beea153f',
    'my-list',
  ],
  [
    'e0bc4797-303a-49ff-b7b4-18781cc2460e',
    '06ad5a22-c002-4c67-92bc-83ec85014461',
    'my-item',
  ]
);

This will listen for list-updated events on the lists with ids 86059de7-9b16-4469-a630-23c8f69944b6 and a2c706a6-5212-4e8a-92ad-bce1beea153f, and the list with the path name my-list (provided those lists belong to the user who owns the token being used to authenticate).

It will also listen for item-updated events on the items with ids e0bc4797-303a-49ff-b7b4-18781cc2460e and 06ad5a22-c002-4c67-92bc-83ec85014461, and the item with the alias my-item (again, provided those items belong to the user who owns the token being used to authenticate).

You can include * in the list ids and item ids arrays to listen for all lists or items. For example:

jsonpadRealtime.listen(
  [
    'list-updated',
    'item-updated',
  ],
  ['*'],
  ['*']
);

This will listen for any list being updated, and any item being updated.

Event types

  • list-created: A list was created.
  • list-updated: A list was updated.
  • list-deleted: A list was deleted.
  • item-created: An item was created.
  • item-updated: An item was updated.
  • item-restored: An item was restored.
  • item-deleted: An item was deleted.

Event object

The event object passed to the event listener has the following properties:

{
  type: string;
  details: {
    listId: string;
    itemId: string;
    model: any; // This will be a List or Item, depending on the event type
  };
}