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

heartisans-core

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heartisans-core

Core for heartisans.

latest
Source
npmnpm
Version
1.0.7
Version published
Weekly downloads
4
-75%
Maintainers
1
Weekly downloads
 
Created
Source

Heartisans Core

The following services are implemented

  • Config - System configuration that are read in on initialization and consolidated in order of priority
  • Setting - Service setting is a hash list that is store in Redis and can be change during runtime
  • Logger - Logging utility that will log to screen by default and also output records to logger module
  • Message - Messaging module with various communication methods
  • Mongoose - A MongoDb ORM
  • Bookshelf - A MySQL ORM
  • Redis - Redis client manager
const core = require('heartisans-core')

core.<module> // to get the service required

Config

*path can be mulit-level

// Usage

core.config.get('name') // = 'symptom_api'

core.config.getAll()
/*
 = {name: 'symptom_api', ...}
*/

get(path)

Get single config in path such as

getAll()

Get all configs

set(path. value)

Change config during runtime. However, this is not durable and will not survive a process restart.

Setting

*path is a single level and store in a hash on Redis

// Usage

core.setting.get('returnCount') // = 20

core.setting.getAll() /* = {returnCount: 20, ...} */

get(path)

Get single setting in path

getAll()

Get all settings

Logger

const logger = core.logger.create('test:module')

logger.error({err: err}, 'this is a message')
logger.warn({some: data}, 'this is a message')
logger.info('this is a message with no data')
logger.debug({err: err}, 'this is a message')
logger.trace('this is a message with no data')

create(namespace)

Create a logger instance for the module that you are currently working on, a string namespace must be supplied.

Message

Communicate between services / task queue


// Send a message / task to a service / work, no immediate reply
// send (to, subject, message, callback)
core.message.send('medical_history', 'newRecord', {data: 'newData'}, function(err) {
    // err if not successful
})

// Receive a message / task wait for one reply and stop
// receive (subject, callback)
core.message.send('newRecord', function(err, content, message, ack) {
    // err - if not successful
    // content - data replied (JSON)
    // message - the meta data
    // ack - callback to acknowledge that the message is received
})

// Receive a message / task wait for one reply and stop
// listen (subject, handler, callback)
core.message.listen('newRecord', function handler (err, content, message, ack) {
    // err - if not successful
    // content - data replied (JSON)
    // message - the meta data
    // ack - callback to acknowledge that the message is received
    
    ack()
}, function (err) {
    // err - if unable to register a listener
})

// Broadcast a message
// publish (subject, message, callback)
core.message.publish('pushToUser', {id: 10, message: 'Test...'}, function(err) {
    // err if not successful
})

// Subscribe to a broadcast
// subscribe (who, subject, handler, callback)
core.message.subscribe('medical_history', 'newRecord', function handler (err, content, message, ack) {
    // err - if not successful
    // content - data replied (JSON)
    // message - the meta data
    // ack - callback to acknowledge that the message is received
}, function (err) {
    // err - if unable to register a listener
})

// Send a request and expect a immediate response, default timeout 30sec
// request (to, subject, message, callback)
core.message.request('user', 'read', {id: 10}, function(err, user) {
    // err if not successful
})

// Receive a message / task wait for one reply and stop
// response (subject, handler, callback)
core.message.response('newRecord', function handler (err, content, message, res) {
    // err - if not successful
    // content - data replied (JSON)
    // message - the meta data
    // ack - callback to acknowledge that the message is received
    
    // example replies
    res(new Error('Stinks'))
    res(null, 'new name', {yucks: 'great'})
}, function (err) {
    // err - if unable to register a listener
})

send (to, subject, message, callback)

Queue a message / task to be process at a later time

receive (subject, callback)

Receive a single message / task; needs to acknowledge after processing

listen (subject, handler, callback)

Listen for message / task continuously; needs to acknowledge after processing

publish (subject, message, callback)

Publish a message to all subscriber of a subject

subscribe (who, subject, handler, callback)

Subscribe to a subject

request (to, subject, message, callback)

Send a request and expect a immediate response

response (subject, handler, callback)

Response to request

Redis

getClient()

Get a shared redis client

createClient()

Get a new Redis Client

Bookshelf

// just use like bookshelf
const bookshelf = core.bookshelf

mongoose

// just use like mongoose
const mongoose = core.mongoose

FAQs

Package last updated on 05 Feb 2017

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