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

@starbase/channels

v0.4.2

Published

Starbase Channels

Downloads

20

Readme

Channels

Starbase Channels

Starbase Channels adds a unix-like directory structure to the Starbase Database and handles the creation and removal of parent and child documents based on channel paths. This allows for documents (channels) with sub-documents, which in turn can have child documents of their own. Channels is great for building APIs based on a path structure.

Adding Starbase Channels to your Project

On the Web

<script src="/path/to/database.min.js"></script>
<script src="/path/to/channels.min.js"></script>

On the Web via jsdelivr CDN

<script src="https://cdn.jsdelivr.net/npm/@starbase/database/database.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@starbase/channels/channels.min.js"></script>

In NodeJS

npm install @starbase/channels @starbase/database

Using Channels

Create a channels database in the browser using channels.min.js and database.min.js:

var database = Database('testdb');
var db = Channels(database);

Create a database in NodeJS using @starbase/channels and @starbase/database:

var Database = require('@starbase/database');
var Channels = require('@starbase/channels');
var database = Database('/path/to/testdb');
var db = Channels(database);

API Methods

db.path(channelPath)

The path method returns the CRUD operations for the specified channel path

var root = db.path('/');

By default, the db object will point to the root path '/'

db.onEvent(handler)

listen for and react to write and delete events

db.onEvent(e => {

  // an object with the event information that occured
  console.log(e);

});

NOTE: onEvent is only available as a method on base channels object.

db.path(path).channel()

Return the current channel path in use

db.path('/users/mike').channel();

Response

"/users/mike"

db.path(path).put(value)

Put data into a document at the path specified and create all parent channels.

db.path('/users/mike').put({"name":"Mike"}).then(result => {
  console.log(result);
});

NOTE: If the parent channel (in this case "/users") does not exist, this operation will create it. The PUT operation creates all corresponding parents for a child document.

Response

{
    "event": "write",
    "path": "/users/mike",
    "channel": "/users",
    "key": "mike",
    "timestamp": 1543119035522
}

db.path(path).get()

Get data from the document at the path specified.

db.path('/users/mike').get().then(result => {
  console.log(result);
});

Response

{
    "path": "/users/mike",
    "channel": "/users",
    "key": "mike",
    "data": {
        "name": "Mike"
    }
}

db.path(path).del()

Delete the document, data, and all children from the path specified.

db.path('/users').del().then(result => {
  console.log(result);
});

NOTE: This operation will DELETE ALL CHILD KEYS below it.

Response

{
    "event": "delete",
    "paths": [
        "/users",
        "/users/mike"
    ],
    "timestamp": 1543119519439
}

db.path(path).list(query)

List the child keys at a specific path

db.path('/users').list().then(result => {  
  console.log(result);
});

Response

{
    "data": [
        {
            "path": "/users/dracula",
            "channel": "/users",
            "key": "dracula"
        },
        {
            "path": "/users/ghost",
            "channel": "/users",
            "key": "ghost"
        },
        {
            "path": "/users/mike",
            "channel": "/users",
            "key": "mike"
        }
    ]
}

List keys with values, ranges, and limits

db.path('/users').list({

  // Range in reverse lexicographical order
  "reverse": true,
  
  // Limit results to 2
  "limit":2,
  
  // Return results as objects containing the key and value
  "values": true,
  
  // key must be greater than 'alien'
  "gt": "alien",
  
  // key must be less than 'werewolf'
  "lt": "werewolf"

}).then(result => {  
  console.log(result);
});

Response

{
    "data": [
        {
            "path": "/users/mike",
            "channel": "/users",
            "key": "mike",
            "data": {
                "name": "Mike"
            }
        },
        {
            "path": "/users/ghost",
            "channel": "/users",
            "key": "ghost",
            "data": {
                "name": "ghost"
            }
        }
    ]
}

More Information

The use of slashes in paths and chaining path methods

The slash in paths denotes the separation of parent channels from child channels. The path method can be chained to achieve the same effect as specifying the complete path.

These two reference objects point to the same location:

var comments = db.path('/users/mike/posts/1/comments');
var comments = db.path('users/mike').path('posts').path('1/comments');

Starbase Channels API Library

Documentation for using the API client library is coming soon.

Using Starbase Database with Starbase Channels

Starbase Database is great for storing data based on single keys. Starbase Channels expands on that idea and allows for keys to have sub-keys. Parent documents to contain child documents. Starbase Channels combined with the Starbase Rules Engine can provide an API gateway solution.