New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dabatoric

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dabatoric

NodeJS plain object data-base (Redis, Mongo) manipulation over object validation schemes

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

dabatoric

Overview

Provides a way to manipulate plain Object data in some data-bases:

  • mongodb
  • redis
  • ... (more to come)

Documentation

A pre-generated version of the documentation is located in ./artifacts/jsdoc/dabatoric/<VERSION>/index.html. Primarily check the globals namespace and the class DataModels.

WoW

Install with:

npm install dabatoric --save

The index of the modules exports functions:

  • init the mongo controller with initMongoController
  • init the redis controller with initRedisController

Mongo

Mongo instances save documents in collections. So, you insert:

{
    'a': 2,
    'b': 3,
    'id': 'ab'
}

... under the collection data-a with the query

{
    'id': 'ab'
}

Redis

For Redis, the term collection is mapped to a hash. So, if you insert:

{
    'a': 2,
    'b': 3,
    'id': 'ab'
}

... under the collection data-a with the query

'ab'

... you will get a hash named data-a with a key ab and the stringified object as the value.

For both instances, you need to define:

  • MongoDB/RedisDB URI
  • ObjectValidationScheme - user defined scheme as described (documentation)
  • Array<DataModelIdentifier> - array of identifiers as described (documentation)
  • Array<CollectionName> - strings to be used as Regular Expression as to validate a name of a collection on each action (documentation)

Example:

    const dabatoric = require('dabatoric'))
    let redisController = dabatoric.initRedisController(
        'redis://localhost:6379',
        {
            'content': {
                'videos': path to a user-defined object validation sheme,
                'images': path to a user-defined object validation sheme
            }
        },
        [
            'content.videos',
            'content.images',
        ],
        [
            'content\\-.*'
        ]
    );

And you have access to some DB actions:

  • find
    redisController.find([{
        'collection': 'content-images',
        'model': 'content.images',
        'query': '...'
    }, {
        'collection': 'content-images',
        'model': 'content.images',
        'query': '...'
    }], (results) => {
        ...
    });
  • insert only if the document does not exist
    redisController.insert([{
        'collection': 'content-images',
        'model': 'content.images',
        'query': '...',
        'data': { ... }
    }], (results) => {
        ...
    });
  • upsert; insert (if new) or modify (if existing); works with partial data if the document exists
    redisController.upsert([{
        'collection': 'content-images',
        'model': 'content.images',
        'query': '...',
        'data': { ... }
    }], (results) => {
        ...
    });
  • remove
    redisController.remove([{
        'collection': 'content-images',
        'model': 'content.images',
        'query': '...'
    }], (results) => {
        ...
    });

For all of those, the first parameter is a array of objects that describe the action:

  • collection to reference the collection (hash for Redis)
  • model to reference the model (as defined during the initialization)
  • query to identify the document:
    • for MongoDB is a query object
    • for RedisDB is a string that is a key in a hash (collection)
  • data - insert and upsert require data

No more than ten actions can be performed in one go. Each action is checked against the corresponding data-model. Callback result is always an array of individual results - check individual docs.

Additionally, you have:

  • getConnectionClient()
  • getDataModels()
  • closeConnection()
  • isReady()

There are some examples in the tests:

  • ./src/test/tests/data_base_controllers/mongo_test
  • ./src/test/tests/data_base_controllers/redis_test

Logging

The module has the capability to log to:

  • the terminal
  • the Linux system log

Terminal

The terminal logging is to be enabled with a environmental variable:

DBTRC_TERM_F=OK

Syslog

The Linux system log logging is to be enabled with a environmental variable:

DBTRC_SYSLOG_F=OK

To enable this, open /etc/rsyslog.conf and enable UDP on port 514. This is usually just commented and needs uncommenting:

# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514")

... and restart the service with ./etc/init.d/rsyslog restart. The logs should appear in /var/log/syslog. This was tested on Ubuntu 16.04.

Source

The source is located on bitbucket

Tests

To run the tests, run (in the root of the project):

npm test

You need to have installed (and running) both Redis and Mongo locally on default URIS.

Besides unit, functionality and regression tests, a static analysis is performed with the help of plato module. This creates a folder ./artifacts/plato_analysis/. There, the file index.html is to be opened in a browser.

Keywords

mongo

FAQs

Package last updated on 05 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts