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

pusudb-connector

v2.1.1

Published

Create a connector for the pusudb-framework.

Downloads

9

Readme

pusudb-connector

Create a connector for the pusudb-framework.

Framework: https://www.npmjs.com/package/pusudb

Define the configuration and open the connection. When a key is subscribed, then each event will be fired according the meta. Check the pusudb docs for the metas.

Installing

npm install pusudb-connector --save

Use

Options

  • key of the pusudb-connector-instance
  • db is the db-name where the pusudb stores the data
  • url of the pusudb
  • login-object of the pusudb-use-auth-jwt
  • subscribeWhenOpen if true, then the key will be subscribed when the connection is open

const Connector = require('pusudb-connector')

// Create instance
let connectComponent = new Connector({ key : 'sensor:rapport', 
                                       db : 'component', 
                                       url : '192.168.178.20:3000/api', 
                                       login : null, // or { email : '', password: '' } when login required, check props in pusudb-configuration
                                       subscribeWhenOpen : true,
                                       heartbeat : 30000 // default or set the same value like in pusudb
})

// Create connection 
connectComponent.open()

// Fired when the connection is open
connectComponent.on('open', function(){

    // subscribe the defined key in the defined db
    //connectComponent.subscribeWildcard()

    // unsubscribe the defined key in the defined db
    //connectComponent.unsubscribeWildcard()

    // get all entries by key
    connectComponent.stream(function(err, data){
        console.log(data)
        /*
            {
            "err": null, // error message
            "db": "db", // db name
            "meta": "update", // or others
            "data": [{key : '', value : ''}, ...] // see pusudb-api doc
            }
        */
    })
})


// Fired when the db entry has changed by put
connectComponent.on('put', function(data){

    console.log('put message:', data)
    /*
        {
        "err": null, // error message
        "db": "db", // db name
        "meta": "update", // or others
        "data": { key : '', value : 'all values'} // see pusudb-api doc
        }
    */
})

// Fired when the db entry has changed by update
connectComponent.on('update', function(data){

    console.log('update message:', data)
    /*
        {
        "err": null, // error message
        "db": "db", // db name
        "meta": "update", // or others
        "data": { key : '', value : 'only the specific updated value'} // see pusudb-api doc
        }
    */
})

// Fired when the db entry has changed by delete
connectComponent.on('del', function(data){

    console.log('delete message:', data)
    /*
        {
        "err": null, // error message
        "db": "db", // db name
        "meta": "del", // or others
        "data": 'key' // see pusudb-api doc
        }
    */
})


// Fired when the db entry has changed by batch
connectComponent.on('batch', function(data){

    console.log('batch message:', data)
    /*
        {
        "err": null, // error message
        "db": "db", // db name
        "meta": "update", // or others
        "data": [{ key : '', value : 'all values'},...] // see pusudb-api doc
        }
    */
})

// Fired when the db entry has changed by batch
connectComponent.on('publish', function(data){

    console.log('publish message:', data)
    /*
        {
        "err": null, // error message
        "db": "db", // db name
        "meta": "update", // or others
        "data": [{ key : '', value : 'all values'},...] // see pusudb-api doc
        }
    */
})

// Fired when the websocket is closed. It will try to reconnet every 10s.
// Change interval connectComponent.reconnectInterval = ...ms
connectComponent.on('close', function(e){
    console.error(e)
})

// Fired when an error occurred
connectComponent.on('error', function(err){
    console.error(err)
})


connectComponent.ws.on('ping', /* heartbeat function like this one from package ws */)

/********************************************************/
// QUERY API

// webscoket Push data direct to the defined db in cfg
connectComponent.push_('update' /*or 'publish', 'put', ... see pusudb-metas*/, { key : data.key, value : data.value})
// http Pull data direct from the defined db in cfg,
connectComponent.pull_('stream' /*or 'publish', 'put', ... see pusudb-metas*/, { gte : 'bla:', lte: 'bla:~'}, function(err, data){
    // handle err or json-data
})


// http Get query arguments = db, meta, params, callback
connectComponent.get_('db', 'stream' /*or 'publish', 'put', ... see pusudb-metas*/, 'gte=componentA&lte=componentA~', function(err, body){
    try{
        body = JSON.parse(body)
    }
    catch(e){
        console.error(e)
    }     
})

// Post query arguments = db, meta, json-data
connectComponent.post_('db', 'put', json, function(err, data){

})

// Websocket query arguments = db, meta, json-data
connectComponent.send_('db', 'get', json )

Authors

  • Yannick Grund - Initial work - yamigr

License

This project is licensed under the MIT License