LocalMachinepacks.interpretMachineModule()

Interpret a machine from a Node.js module string into a JSON string.

Functions will be escaped as strings.

Usage

Hover over inputs/exits for more info.

var LocalMachinepacks = require('machinepack-localmachinepacks');


// Interpret a machine from a Node.js module string into a JSON string.

LocalMachinepacks.interpretMachineModule({

module: 'module.exports = {inputs: {atest: {example: "whatever" } }, exits: { error: {}, success: {example: {stuff: [{andMore: "stuff" }] } } }, fn: function(inputs, exits) { return exits.success(); }};',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Machine definition is semantically invalid: No exits were provided

noExits: function () {

 

},

// Timed out attempting to interpret machine module.

tookTooLong: function () {

 

},

// OK.

success: function (jsonString) {

 

},

});

Inputs

module required

The machine definition as a Node.js module (a string of JavaScript code).

'module.exports = {inputs: {atest: {example: "whatever"    }  },  exits: {    error: {}, success: {example: {stuff: [{andMore: "stuff"        }]      }    }  },  fn: function(inputs, exits) {    return exits.success();  }};'

Exits

error

An unexpected error occurred.

noExits

Machine definition is semantically invalid: No exits were provided

tookTooLong

Timed out attempting to interpret machine module.

success

OK.

'((machine definition as a json string))'