JSPM

  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q77205F
  • License ISC

Generic product database for use in webshops or other places

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

Build Status Dependencies

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 larvitproduct

Usage

Add a new product

const	productLib	= require('larvitproduct'),
    product	= new productLib.Product();

product.attributes = {'name': 'Conductor', 'price': 200, 'available color': ['blue', 'green']};

product.save(function (err) {
    if (err) throw err;
});

Get products

const	productLib	= require('larvitproduct'),
    products	= new productLib.Products();

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();
    });
}