@wmfs/statebox
Orchestrate Node functions using Amazon States Language
Last updated 25 days ago by wmfsbot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @wmfs/statebox 
SYNC missed versions from official npm registry.

Statebox Logo

Tymly Package npm (scoped) CircleCI codecov CodeFactor Dependabot badge Commitizen friendly JavaScript Style Guide license

Orchestrate Node functions using Amazon States Language

Useful links

Install

$ npm install @wmfs/statebox --save

Usage

const Statebox = require('@wmfs/statebox')
const statebox = new Statebox({})

const main = async

function() {

  // STEP 1:
  // Create some 'module' resources (i.e. Javascript
  // classes with 'run' and optional 'init' methods)
  // that state machines can then refer to...
  // -------------------------------------------------
  await statebox.ready
  statebox.createModuleResources({
    // Simple module to add two numbers together
    add: class Add {
      run(event, context) {
        context.sendTaskSuccess(event.number1 + event.number2)
      }
    },
    // Simple module to subtract one number from another
    subtract: class Subtract {
      // Init methods are optional, but all allow
      // resource-instances to be configured...
      init(resourceConfig, env, callback) {
        callback(null)
      }
      run(event, context) {
        context.sendTaskSuccess(event.number1 - event.number2)
      }
    }
  })

  // STEP 2:
  // Next create a new 'calculator' state
  // machine using Amazon States Language...
  // ---------------------------------------
  await statebox.createStateMachines({
      'calculator': {
        Comment: 'A simple calculator',
        StartAt: 'OperatorChoice',
        States: {
          OperatorChoice: {
            Type: 'Choice',
            Choices: [{
              Variable: '$.operator',
              StringEquals: '+',
              Next: 'Add'
            }, {
              Variable: '$.operator',
              StringEquals: '-',
              Next: 'Subtract'
            }]
          },
          Add: {
            Type: 'Task',
            InputPath: '$.numbers',
            Resource: 'module:add', // See createModuleResources()
            ResultPath: '$.result',
            End: true
          },
          Subtract: {
            Type: 'Task',
            InputPath: '$.numbers',
            Resource: 'module:subtract',
            ResultPath: '$.result',
            End: true
          }
        }
      }
    }, {}, // 'env': An environment/context/sandbox
  )

  // STEP 3:
  // Start a new execution on a state machine
  // ----------------------------------------
  const executionDescription = await statebox.startExecution({
      numbers: {
        number1: 3,
        number2: 2
      },
      operator: '-'
    }, // input
    'calculator', // state machine name
    {} // options
  )

  // STEP 4:
  // Look at the results...
  // ----------------------
  console.log(executionDescription)
  //  Result object
  //  -------------
  // {
  //   executionName: '...',
  //   ctx: {
  //     numbers': {
  //       number1: 3,
  //       number2: 2
  //     },
  //     operator: '-',
  //     result: 1 <--- The important bit :-)
  //   },
  //   currentStateName:'Subtract',
  //   currentResource:'module:subtract',
  //   stateMachineName:'calculator',
  //   startDate: '2018-09-03T21:58:04.287Z'
  // }
}

if (require.main === module) {
  main();
}

Testing

$ npm test

License

MIT

Current Tags

  • 1.65.0                                ...           latest (25 days ago)

97 Versions

  • 1.65.0                                ...           25 days ago
  • 1.64.2                                ...           a month ago
  • 1.64.1                                ...           2 months ago
  • 1.64.0                                ...           2 months ago
  • 1.63.0                                ...           2 months ago
  • 1.62.0                                ...           2 months ago
  • 1.61.1                                ...           3 months ago
  • 1.61.0                                ...           3 months ago
  • 1.60.0                                ...           4 months ago
  • 1.59.0                                ...           4 months ago
  • 1.58.0                                ...           4 months ago
  • 1.57.0                                ...           5 months ago
  • 1.56.0                                ...           5 months ago
  • 1.55.0                                ...           5 months ago
  • 1.54.4                                ...           7 months ago
  • 1.54.3                                ...           7 months ago
  • 1.54.2                                ...           7 months ago
  • 1.54.1                                ...           7 months ago
  • 1.54.0                                ...           9 months ago
  • 1.53.0                                ...           9 months ago
  • 1.52.0                                ...           a year ago
  • 1.51.0                                ...           a year ago
  • 1.50.0                                ...           a year ago
  • 1.49.0                                ...           a year ago
  • 1.48.1                                ...           a year ago
  • 1.48.0                                ...           a year ago
  • 1.47.3                                ...           a year ago
  • 1.47.2                                ...           a year ago
  • 1.47.1                                ...           a year ago
  • 1.47.0                                ...           a year ago
  • 1.46.0                                ...           a year ago
  • 1.45.0                                ...           a year ago
  • 1.44.2                                ...           a year ago
  • 1.44.1                                ...           a year ago
  • 1.44.0                                ...           a year ago
  • 1.43.0                                ...           a year ago
  • 1.42.0                                ...           a year ago
  • 1.41.0                                ...           a year ago
  • 1.40.0                                ...           a year ago
  • 1.39.1                                ...           a year ago
  • 1.39.0                                ...           a year ago
  • 1.38.0                                ...           a year ago
  • 1.37.3                                ...           a year ago
  • 1.37.2                                ...           2 years ago
  • 1.37.1                                ...           2 years ago
  • 1.37.0                                ...           2 years ago
  • 1.36.0                                ...           2 years ago
  • 1.35.0                                ...           2 years ago
  • 1.34.3                                ...           2 years ago
  • 1.34.2                                ...           2 years ago
  • 1.34.1                                ...           2 years ago
  • 1.34.0                                ...           2 years ago
  • 1.33.0                                ...           2 years ago
  • 1.32.0                                ...           2 years ago
  • 1.31.0                                ...           2 years ago
  • 1.30.0                                ...           2 years ago
  • 1.29.0                                ...           2 years ago
  • 1.28.0                                ...           2 years ago
  • 1.27.0                                ...           2 years ago
  • 1.26.0                                ...           2 years ago
  • 1.25.0                                ...           2 years ago
  • 1.24.0                                ...           2 years ago
  • 1.23.1                                ...           2 years ago
  • 1.23.0                                ...           2 years ago
  • 1.22.0                                ...           2 years ago
  • 1.21.0                                ...           2 years ago
  • 1.20.0                                ...           2 years ago
  • 1.19.0                                ...           2 years ago
  • 1.18.0                                ...           2 years ago
  • 1.17.0                                ...           2 years ago
  • 1.16.0                                ...           2 years ago
  • 1.15.0                                ...           2 years ago
  • 1.14.0                                ...           2 years ago
  • 1.13.0                                ...           2 years ago
  • 1.12.0                                ...           2 years ago
  • 1.11.0                                ...           2 years ago
  • 1.10.0                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.8.0                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 19
Dependencies (8)
Dev Dependencies (15)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |