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

bg-hive

v1.1.2

Published

Collection of highly abstracted and modular key-value stores, optimized to our different data types (e.g. articles, alerts, users, ...) with bg-object-cache used for caching.

Downloads

7

Readme

BG Hive

Collection of highly abstracted and modular key-value stores, optimized to our different data types (e.g. articles, alerts, users, ...) with bg-object-cache used for caching.

So.. why? With this you don't have to implement the same logic to retrieve the same data across different node services. For example, notification server uses this to retrieve instruments, beemail and alerting for articles, alerting and notification server for alerts and so on. Cache is shared module-wide, no instantiation needed.

So.. another api wrapper? Not really, this additionally enhances the returned data to accelerate access to specific, often-used values. E.g. Instrument quotations are conveniently available in a hashmap by quotationId, return expectation and breakout direction are copied and merged from sub-sub-sub-nodes of the chartpattern object to top level. This basically tries to hide our sometimes sadly ugly data models. Be aware that these optimizations are only for faster in-service usage and produces redundancy. Any enhancement and the final data model is mentioned above.

Usage

var userStore = require('bg-hive').user;

userStore.get(109369)
    .then(function(user) {})
    .catch(function(err) {});

There is an instantiated key-value cache for each data type called a 'Store'. Each store has his own retrieve method, which gets an object from our api over http if not already cached. This 'retrieve' method can be overwritten to bypass the http overhead, for example if a database connection is already available to perform a direct lookup.

var alertStore = require('bg-hive').alert;

alertStore.retrieve = function(id, callback) {
    db.list({ _id: new db.ObjectID(id)}, function(err, data) {
        if (err) { return callback(err); }
        else { callback(null, data); }
    });
}

alertStore.get('568150ee897d878801076ca2');
// if the alert is not cached yet, it will retrieve it with the direct db connection already available.

Attributes

Each store has a list of requested attributes for our api. This can be mutated to match any needs.

var articleStore = require('bg-hive').article;

articleStore.attributes = [
    'title',
    'teaser',
    'body',
    'author',
    'categories'
];

Supported Data Types

Returned data is directly taken from the response below the 'data' attribute, if not otherwise enhanced. The enhancements for each data type are mentioned in the corresponding type entry.

Alert

var alertStore = require('bg-hive').alert;

alertStore.get('568150ee897d878801076ca2')
    .then(function(alert) {})
    .catch(function(err) {});

Enhancements

Hooray, no enhancements needed!

Article

var articleStore = require('bg-hive').article;

articleStore.get(4598918)
    .then(function(article) {})
    .catch(function(err) {});

Enhancements

Hooray, no enhancements needed!

Beemail

Beemail is the first to have two stores, the simple 'data' store retrieves the template json object, the 'rendered' one returns the same json with the rendered HTML code added as string under 'html'.

var beemailDataStore = require('bg-hive').beemail.data;
var beemailRenderedStore = require('bg-hive').beemail.rendered;

beemailRenderedStore.get('56efd4113636583124ada5dd')
    .then(function(mail) {})
    .catch(function(err) {});

Enhancements

Hooray, no enhancements needed!

Chartpattern

var chartpatternStore = require('bg-hive').chartpattern;

chartpatternStore.get(109369)
    .then(function(chartpattern) {})
    .catch(function(err) {});

Enhancements

Return expectation and breakout direction are two important values, which are found separated across possibly multiple breakout entries. Breakout direction is the 'direction' attribute of the first entry in the breakout array. Default is 0. Return expectation is the highest 'quotePotential.distPercentBreakoutFrom' of all breakout entries. Default is 0.

Resulting Data Model

{ id: 8520152,
  patternType: 
   { id: 2,
     name: 'Trendkanal',
     desc: 'Ein Trendkanal grenzt die Schw...',
     direction: 0 },
  patternStatus: '10',
  instrument: { id: 118935, name: 'Activision, Inc.', refQuotation: null },
  exchangeId: 45,
  calculationTimestamp: 1313227559,
  beginX: 1299508200,
  endX: 1306935000,
  timeSort: 1308159000,
  patternLength: 137,
  resolution: 14400,
  timeHorizon: 0,
  confirmed: -1,
  instrumentSort: 'stock',
  closeTriggered: 1,
  closeTriggeredRegular: 1,
  ad: {},
  breakout: 
   [ { id: 2394205,
       patternId: 8520152,
       type: 1,
       timestamp: 1313227559,
       maxReturn: 0.02043188626101,
       value: 11.1835,
       candle: 1308159000,
       direction: -1,
       candlesTillBreakout: 137,
       quotePotential: [Object] },
     { id: 2394208,
       patternId: 8520152,
       type: 2,
       timestamp: 1313227559,
       maxReturn: 0.02043188626101,
       value: 11.1835,
       candle: 1308159000,
       direction: -1,
       candlesTillBreakout: 137,
       quotePotential: [Object] } (...) ],
  version: 0,
  points: null,
  lines: 
   [ { x1Date: 1298917800,
       x1Offset: 0,
       x2Date: 1307035800,
       x2Offset: 0,
       y1: 11.254,
       y2: 12.0795,
       type: 1 },
     { x1Date: 1298917800,
       x1Offset: 0,
       x2Date: 1307035800,
       x2Offset: 0,
       y1: 11.254,
       y2: 12.0795,
       type: 2 } (...) ],
  returnExpectation: 0.13586980819958,
  breakoutDirection: -1 }

Comment

var commentStore = require('bg-hive').comment;

commentStore.get(3344565)
    .then(function(comment) {})
    .catch(function(err) {});

Enhancements

Hooray, no enhancements needed!

Instrument

var instrumentStore = require('bg-hive').instrument;

instrumentStore.get(133962)
    .then(function(instrument) {})
    .catch(function(err) {});

Enhancements

Quotations are remapped and often-used fields from quoteSource and currency are merged into a new object. This applies to refQuotation and quotations, which is now a hashmap by quotationId, instead of an array. The original quotation is still available under '_origin'.

Resulting Data Model

{ id: 133962,
  name: 'DAX',
  assetClass: { id: 2, title: 'Index' },
  identifiers: { isin: 'DE0008469008', wkn: '846900' },
  refQuotation: 
   { id: 4,
     name: 'XETRA',
     type: 'last',
     precision: 2,
     currency: 'Pkt',
     _origin: { quoteSource: [Object], currency: [Object] } },
  quotations: 
   { '4': 
      { id: 4,
        name: 'XETRA',
        type: 'last',
        precision: 2,
        currency: 'Pkt',
        _origin: [Object] },
     '22': 
      { id: 22,
        name: 'Lang & Schwarz',
        type: 'last',
        precision: 2,
        currency: 'Pkt',
        _origin: [Object] },
     '57': 
      { id: 57,
        name: 'Deutsche Bank Indikation',
        type: 'last',
        precision: 2,
        currency: 'Pkt',
        _origin: [Object] }
      (...) } }

User

var userStore = require('bg-hive').user;

userStore.get(109369)
    .then(function(user) {})
    .catch(function(err) {});

Enhancements

The user devices are way too unstructured, therefore it will be rewired.

  • Devices are listed in arrays for each device type.
  • A 'target' field is added for each device, which is the resolved 'externalId' (email devices store the Email id as externalId, this will be resolved to the email address string).
  • Solvians is a special case, in that it can only be one solvians device without externalId, thus it is boolean. (solvians should really be a portal entry..)
  • Disabled devices are filtered out
  • Devices with invalid externalId are filtered out The original structure is available under devices._origin.

Resulting Data Model

{ id: 109369,
  domain: 'ad',
  title: 'Herr',
  firstname: 'Thomas',
  lastname: 'Lukacs',
  devices: 
   { portal: 
      [ { id: 181097,
          externalId: '26',
          type: 'portal',
          group: null,
          name: null,
          isEnabled: true,
          target: '26' } ],
     gcm: 
      [ { id: 168078,
          externalId: 'APA91bFGgoPFlpgt7rO38mc7AyW8DjhYda3eB73MPUz6GeUnOV8pk1qzFFSUgCenoI6IaZ1CK0MptRHU9ENMhNGmDhBRR-sZlKSwyWcAEcG3Xz_E_ERdVj0vdqJFVT6dPzOPdf3-cq33',
          type: 'gcm',
          group: 'phone',
          name: 'HTC HTC ONE X',
          isEnabled: true,
          target: 'APA91bFGgoPFlpgt7rO38mc7AyW8DjhYda3eB73MPUz6GeUnOV8pk1qzFFSUgCenoI6IaZ1CK0MptRHU9ENMhNGmDhBRR-sZlKSwyWcAEcG3Xz_E_ERdVj0vdqJFVT6dPzOPdf3-cq33' },
        { id: 167269,
          externalId: 'APA91bGApPnxjNIqeFgZqwaNh-Q5sPeaKQlXGIKXGzMyLJrSmBqyN7RXD6LRpuvok3d6lQjJORx5TY7PKSv6gP0zvWeaM4N55MXCxxC0Plj0tX1zNYk_Jjen-HvVmrZv05cd6KRCEmUW',
          type: 'gcm',
          group: 'phone',
          name: 'GOOGLE NEXUS 6P',
          isEnabled: true,
          target: 'APA91bGApPnxjNIqeFgZqwaNh-Q5sPeaKQlXGIKXGzMyLJrSmBqyN7RXD6LRpuvok3d6lQjJORx5TY7PKSv6gP0zvWeaM4N55MXCxxC0Plj0tX1zNYk_Jjen-HvVmrZv05cd6KRCEmUW' } ],
     email: 
      [ { id: 109572,
          externalId: '89502',
          type: 'email',
          group: null,
          name: null,
          isEnabled: true,
          target: '[email protected]' } ],
     solvians: true,
     _origin: 
      [ { id: 29,
          externalId: '1337',
          type: 'email',
          group: 'desktop',
          name: null,
          isEnabled: true },
        { id: 40416,
          externalId: '1',
          type: 'solvians',
          group: 'desktop',
          name: 'Helloooooo',
          isEnabled: true } (...) ] },
  Emails:
   [ { id: 89502, email: '[email protected]', active: true },
     { id: 46588, email: '[email protected]', active: true } ],
  rights: 
   [ 'advertisement.admin',
     'article.read' (...) ] }

Changelog

1.1.1

  • Fix: Beemail api returns rendered template in json

1.1.0

  • Feature: Added Beemail template stores
  • Improvement: Added user.device enhancement