Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mesg/application

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mesg/application

[Website](https://mesg.com/) - [Docs](https://docs.mesg.com/) - [Forum](https://forum.mesg.com/) - [Chat](https://discordapp.com/invite/SaZ5HcE) - [Blog](https://blog.mesg.com)

  • 0.1.0-alpha-1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

@mesg/application

Website - Docs - Forum - Chat - Blog

This library lets you connect to the MESG engine to listen for any event or result that you might be interested too. It also allows you to execute a task, either synchronously or asynchronously.

Contents

Installation

npm install @mesg/application

Application

Require mesg-js as an application:

const Application = require('@mesg/application')

const mesg = new Application()

MESG Engine endpoint

By default, the library connects to the MESG Engine from the endpoint localhost:50052.

Resolve SID

Instead of hard-coding instanceHash in your application's env, your application can resolve dynamically using the service's SID.

const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')

const result = await mesg.executeTaskAndWaitResult({
  instanceHash,
  .....
})

Listen events

Listen events from a service.

const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')

mesg.listenEvent({
  filter: {
    instanceHash: instanceHash,
    key: 'EVENT_KEY' // optional
  }
})
.on('data', (event) => {
  console.log('an event received:', event.key, mesg.decodeData(event.data))
})

Listen results

Listen results from a service.

const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')

mesg.listenResult({
  filter: {
    instanceHash: instanceHash,
    taskKey: 'TASK_KEY_FILTER', // optional
    tags: ['TAG_FILTER'] // optional
  }
})
.on('data', (result) => {
  if (result.error) {
    console.error('an error has occurred:', result.error)
    return
  }
  console.log('a result received:', mesg.decodeData(result.outputs))
})

Execute task

Execute task on a service.

const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')

const execution = await mesg.executeTask({
  instanceHash: instanceHash,
  taskKey: 'TASK_KEY',
  inputs: mesg.encodeData({ key: 'INPUT_DATA' }),
  tags: ['ASSOCIATE_TAG'] // optional
})
console.log('task in progress with execution:', execution.hash)

Execute task and wait result

Execute task on a service and wait for its result. This can be considered as a shortcut for using both executeTask() and listenResult() at same time.

const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')

const result = await mesg.executeTaskAndWaitResult({
  instanceHash: instanceHash,
  taskKey: 'TASK_KEY',
  inputs: mesg.encodeData({ key: 'INPUT_DATA' }),
  tags: ['ASSOCIATE_TAG'] // optional
})
if (result.error) {
  console.error('an error has occurred:', result.error)
  throw new Error(result.error)
}
console.log('a result received:', mesg.decodeData(result.outputs))

FAQs

Package last updated on 26 Nov 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc