This package has been deprecated

Author message:

Please use @liteflow/service

@mesg/service
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@mesg/service

Website - Docs - Forum - Chat - Blog

This library handles the connection with the MESG Engine, some authentication, and finally, the functions for your service to listen to tasks sent by the engine or emit events that your service needs to expose to the engine.

Contents

Installation

npm install @mesg/service

Service

const Service = require('@mesg/service')

const mesg = new Service()

Task

The service have to call mesg.listenTask to start listening for task to execute by passing an object containing the tasks' key and function.

mesg.listenTask({
  'TASK_1_KEY': (inputs) => {
    // Function of the task 1
    // Can directly throw error
    if (inputs.foo === undefined) {
      throw new Error('foo is undefined')
    }
    // Return an object
    return { foo: inputs.a + 'bar' }
  }, 
  'TASK_2_KEY': async (inputs) => {
    // Function of the task 2
    // Return an Promise containing an object
    const response = await fetch('...')
    return response.json()
  },
})

The task functions accept inputs as parameter and returns the outputs as object or Promise of object. The task function can throw an Error in case of error. The lib will catch it and send it to the MESG Engine.

Event

To emit an event, the service should call the mesg.emitEvent function with the event's key and event's data as parameters. This function returns a Promise.

mesg.emitEvent('EVENT_KEY', { foo: 'bar' })

Readme

Keywords

none

Package Sidebar

Install

npm i @mesg/service

Weekly Downloads

0

Version

0.1.1

License

ISC

Unpacked Size

26.1 kB

Total Files

8

Last publish

Collaborators

  • nicolasmahe
  • anthony-mesg
  • nicolas-mesg