Package Exports
- larvitproduct
 
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (larvitproduct) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
larvitproduct
Generic product module for nodejs.
Product data structure:
{
    "uuid": "string",
    "created": date,
    "attributes": {
        "name": ["Conductor"],
        "price": [200],
        "available color": ["blue", "green"]
    }
}Installation
npm i --save larvitproductUsage
Add a new product
const	elasticsearch	= require('elasticsearch'),
    productLib	= require('larvitproduct'),
    product	= new productLib.Product();
productLib.dataWriter.elasticsearch	= new elasticsearch.Client({'host': '127.0.0.1:9200'});
productLib.dataWriter.esIndexName	= 'theIndexToUse';
product.attributes = {'name': 'Conductor', 'price': 200, 'available color': ['blue', 'green']};
product.save(function (err) {
    if (err) throw err;
});Get products
const	elasticsearch	= require('elasticsearch'),
    productLib	= require('larvitproduct'),
    products	= new productLib.Products();
productLib.dataWriter.elasticsearch	= new elasticsearch.Client({'host': '127.0.0.1:9200'});
productLib.dataWriter.esIndexName	= 'theIndexToUse';
products.get(function (err, productList) {
    // productList being an object with productUuid as key
});Highjack datawriter to fill up database before getting data from the queue
THIS MIGHT BE BROKEN
const	EventEmitter	= require('events').EventEmitter,
    eventEmitter	= new EventEmitter(),
    productLib	= require('larvitproduct'),
    oldReady	= productLib.dataWriter.ready,
    async	= require('async'); // npm i --save async
let	readyInProgress	= false,
    isReady	= false;
productLib.dataWriter.ready = function (cb) {
    const	tasks	= [];
    if (isReady === true) { cb(); return; }
    if (readyInProgress === true) {
        eventEmitter.on('ready', cb);
        return;
    }
    readyInProgress = true;
    // Do async stuff here that have to happend before the first message
    // from the queue is written to the database
    tasks.push(function (cb) {
        // do stuff
        cb();
    });
    // Run the original ready function
    tasks.push(oldReady);
    async.series(tasks, function () {
        isReady	= true;
        eventEmitter.emit('ready');
        cb();
    });
}