npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@curium.rocks/maestro

v0.150.0

Published

Connects emitters to chroniclers and transceivers along with managing state of emitters

Downloads

189

Readme

Meastro

Quality Gate Status Coverage Security Rating npm

Manager of emitters and chroniclers. Intended to run as a service and house multiple emitters.

How to install

npm install --save @curium.rocks/maestro

API Documentation

You can view the API documentation here.

How to use

Create your configuration

The below example shows a full configuration, load, and save handlers can be provided to dynamically fetch the latest config on save/load calls.

/***
 * Create a logger facade wrapper winston
 * @param {string} serviceName 
 * @return {LoggerFacade}
 */
function getLoggerFacade(serviceName: string): LoggerFacade {
    const logger = winston.createLogger({
        level: 'info',
        format: winston.format.json(),
        defaultMeta: { service: serviceName },
        transports: [
          new winston.transports.Console()
        ],
      });
    return {
        info: logger.info.bind(logger),
        debug: logger.debug.bind(logger),
        trace: logger.silly.bind(logger),
        warn: logger.warn.bind(logger),
        error: logger.error.bind(logger),
        critical: logger.error.bind(logger)
    }
}

/**
 * Get the configuraiton obj, in this case it's mostly static for demo purposes,
 * but this could fetch from a file, fill properties in from a DB etc.
 * @param {string} logDir log directory for json chronicler
 * @param {string} logName log name for json chronicler
 * @return {IMaestroConfig} 
 */
function getConfig(logDir?: string, logName?: string) : IMaestroConfig {
    return {
        id: 'meastro-id',
        name: 'meastro-name',
        description: 'meastro description',
        formatSettings: {
            encrypted: false,
            type: 'N/A'
        },
        connections: [{
            emitters: [
                'ping-pong-1'
            ],
            chroniclers: [
                'json-chronicler-1'
            ]
        }],
        factories: {
            emitter: [{
                factoryType: PingPongEmitter.TYPE,
                factoryPath: 'PingPongEmitterFactory',
                packageName: '@curium.rocks/ping-pong-emitter',
            }],
            chronicler: [{
                factoryType: JsonChronicler.TYPE,
                factoryPath: 'JsonChroniclerFactory',
                packageName: '@curium.rocks/json-chronicler'
            }]
        },
        emitters: [{
            config: {
                type: PingPongEmitter.TYPE,
                id: 'ping-pong-1',
                name: 'My Ping Pong Emitter 1',
                description: "A ping pong emitter",
                emitterProperties: {
                    interval: 250
                }
            }
        }],
        chroniclers: [{
            config: {
                type: JsonChronicler.TYPE,
                id: 'json-chronicler-1',
                name: 'Chronicler 1',
                description: "A json chronicler",
                chroniclerProperties: {
                    logDirectory: logDir || './logs',
                    logName: logName || 'maestro',
                    rotationSettings: {
                        seconds: 300
                    }
                }
            }
        }]
    }
}

const maestroOptions = {
    config: getConfig(),
    logger: getLoggerFacade('maestro'),
    loadHandler: () => {
        return Promise.resolve(getConfig());
    }
}

Create the maestro

Once you have your configuration, you can create the maestro:

const maestro = new Maestro(maestroOptions);

Start the maestro

The meastro doesn't start automatically and you must call start, this refreshes it's configuration and starts any emitters as well.

await maestro.start();

Stop and cleanup on SIG INT

You can add a hook to clean up gracefully on SIG INT like so:

process.on('SIGINT', async () =>  {
    await maestro.disposeAsync();
})

Complete Example

import { IMaestro, LoggerFacade, ProviderSingleton } from "@curium.rocks/data-emitter-base";
import { JsonChronicler } from "@curium.rocks/json-chronicler";
import { PingPongEmitter } from "@curium.rocks/ping-pong-emitter";
import { IMaestroConfig, Maestro } from "@curium.rocks/maestro";
import winston from "winston";

/**
 * Create a logger facade wrapper winston
 * @param {string} serviceName 
 * @return {LoggerFacade}
 */
function getLoggerFacade(serviceName: string): LoggerFacade {
    const logger = winston.createLogger({
        level: 'info',
        format: winston.format.json(),
        defaultMeta: { service: serviceName },
        transports: [
          new winston.transports.Console()
        ],
      });
    return {
        info: logger.info.bind(logger),
        debug: logger.debug.bind(logger),
        trace: logger.silly.bind(logger),
        warn: logger.warn.bind(logger),
        error: logger.error.bind(logger),
        critical: logger.error.bind(logger)
    }
}

/**
 * Get the configuraiton obj, in this case it's mostly static for demo purposes,
 * but this could fetch from a file, fill properties in from a DB etc.
 * @param {string} logDir log directory for json chronicler
 * @param {string} logName log name for json chronicler
 * @return {IMaestroConfig} 
 */
function getConfig(logDir?: string, logName?: string) : IMaestroConfig {
    return {
        id: 'meastro-id',
        name: 'meastro-name',
        description: 'meastro description',
        formatSettings: {
            encrypted: false,
            type: 'N/A'
        },
        connections: [{
            emitters: [
                'ping-pong-1'
            ],
            chroniclers: [
                'json-chronicler-1'
            ]
        }],
        factories: {
            emitter: [{
                factoryType: PingPongEmitter.TYPE,
                factoryPath: 'PingPongEmitterFactory',
                packageName: '@curium.rocks/ping-pong-emitter',
            }],
            chronicler: [{
                factoryType: JsonChronicler.TYPE,
                factoryPath: 'JsonChroniclerFactory',
                packageName: '@curium.rocks/json-chronicler'
            }]
        },
        emitters: [{
            config: {
                type: PingPongEmitter.TYPE,
                id: 'ping-pong-1',
                name: 'My Ping Pong Emitter 1',
                description: "A ping pong emitter",
                emitterProperties: {
                    interval: 250
                }
            }
        }],
        chroniclers: [{
            config: {
                type: JsonChronicler.TYPE,
                id: 'json-chronicler-1',
                name: 'Chronicler 1',
                description: "A json chronicler",
                chroniclerProperties: {
                    logDirectory: logDir || './logs',
                    logName: logName || 'maestro',
                    rotationSettings: {
                        seconds: 300
                    }
                }
            }
        }]
    }
}

const maestroOptions = {
    config: getConfig(),
    logger: getLoggerFacade('maestro'),
    loadHandler: () => {
        return Promise.resolve(getConfig());
    }
}
ProviderSingleton.getInstance().setLoggerFacade(maestroOptions.logger);
const maestro:IMaestro = new Maestro(maestroOptions);
maestro.start();

process.on('SIGINT', async () => {
    await maestro.disposeAsync();
});

Docs

For more information generate the docs using npm run doc, documentation for each version is also attached as an artifact of the build in CI.