comcom

0.2.5 • Public • Published

Complyify Commons for Javscript

Module containing common classes and helper functions for Javascript/Node.js applications.

Code Climate Test Coverage

Installation

npm install comcom --save

Building

This module is written in ES6 but can be compiled to ES5 with Babel for wider compatibility.

npm run compile

Ensure you run the compile command after running npm install which will load Babel and other development dependancies.

Getting Started

Simply import or require one or more classes from this module to make them available in your code.

ES6

import { SomeClass } from 'comcom';

ES5

var SomeClass = require('comcom').SomeClass;

API Reference

Classes

Configurable

A class that defines an object that must have a config object as a local property.

Constructor

var name = 'SomeName';
var type = 'SomeType';
var config = { configKey: 'someValue' };
var configurable = new Configurable(name, type, config);
Parameter Description Constraints
name user-friendly name for the configurable object, mostly for showing in logs must not be undefined, null, nor an empty string
type user-friendly type for the configurable object, mostly for show in logs must not be undefined, null, nor an empty string
config instance configuration object must be an object or undefined/null

Executable

A class designed to provide the scaffolding for an asynchronous job.

Constructor

var name = 'SomeName';
var config = { configKey: 'someValue' };
var log = bunyan.createLogger({name: 'myAppName'});
var executable = new Executable(name, config, log);
Parameter Description Constraints
name user-friendly name for the executable, mostly for showing in logs must not be undefined, null, nor an empty string
config instance configuration object must be an object or undefined/null
log a Bunyan logger object required

Methods

Method Description Returns
exec() Runs the executable by calling the implementing class' execImpl() method a promise that resolves to the eventual returned value of execImpl()

Named

A class that defines an object that must have name as a local property.

Constructor

var name = 'SomeName';
var named = new Named(name);
Parameter Description Constraints
name user-friendly name for the object, mostly for showing in logs must not be undefined, null, nor an empty string

NamedTyped

A class that defines an object that must have name and type as local properties.

Constructor

var name = 'SomeName';
var type = 'SomeType';
var namedTyped = new NamedTyped(name, type);
Parameter Description Constraints
name user-friendly name for the object, mostly for showing in logs must not be undefined, null, nor an empty string
type user-friendly type for the object, mostly for show in logs must not be undefined, null, nor an empty string

Service

A class designed to provide the scaffolding for a persistent service or daemon.

Usage

const NAME = 'SomeName';
const CONFIG = { configKey: 'someValue' };
const LOG = bunyan.createLogger({name: 'myAppName'});
let MyService = class extends Service {
  constructor() {
    super(NAME, CONFIG, LOG);
  }
}
let svc = new MyService();
svc.start();
Parameter Description Constraints
name user-friendly name for the service, mostly for showing in logs must not be undefined, null, nor an empty string
config instance configuration object must be an object or undefined/null
log a Bunyan logger object required

Methods

Method Description Returns
start() Starts the service by calling the implementing class' startImpl() method a promise that resolves when startup is complete
stop() Stops the service by calling the implementing class' stopImpl() method a promise that resolves when shutdown is complete
restart() Convenience method to call stop(), wait for completion, then call start() a promise that resolves upon completion of the restart
use() Register a service adapter or command/query/event handler undefined

License

This module is made available under the terms of the GNU Affero General Public License v3.0 (see LICENSE).

Readme

Keywords

none

Package Sidebar

Install

npm i comcom

Weekly Downloads

4

Version

0.2.5

License

AGPL-3.0

Last publish

Collaborators

  • sbruton