New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wmfs/statebox

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wmfs/statebox - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [1.4.1](https://github.com/wmfs/statebox/compare/v1.4.0...v1.4.1) (2018-09-04)
### 🐛 Bug Fixes
* Beef up is object check to avoid trying work with a null ([fd60fa1](https://github.com/wmfs/statebox/commit/fd60fa1))
# [1.4.0](https://github.com/wmfs/statebox/compare/v1.3.2...v1.4.0) (2018-09-03)

@@ -2,0 +9,0 @@

2

lib/state-machines/index.js

@@ -49,3 +49,3 @@ 'use strict'

)
} else if (typeof root === 'object') {
} else if ((root != null) && (typeof root === 'object')) {
if (root.hasOwnProperty('StartAt')) {

@@ -52,0 +52,0 @@ if (topLevel) {

{
"name": "@wmfs/statebox",
"version": "1.4.0",
"version": "1.4.1",
"description": "Orchestrate Node functions using Amazon States Language",

@@ -5,0 +5,0 @@ "author": "West Midlands Fire Service",

@@ -30,16 +30,19 @@ # statebox

```javascript
const Statebox = require('statebox')
const statebox = new Statebox()
const Statebox = require('@wmfs/statebox')
const statebox = new Statebox({})
// STEP 1:
// Create some 'module' resources (i.e. Javascript
// classes with 'run' and optional 'init' methods)
// that state machines can then refer to...
// -------------------------------------------------
const main = async
statebox.createModuleResources(
{
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) {
run(event, context) {
context.sendTaskSuccess(event.number1 + event.number2)

@@ -52,116 +55,92 @@ }

// resource-instances to be configured...
init (resourceConfig, env, callback) {
callback(null)
}
run (event, context) {
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...
// ---------------------------------------
const info = statebox.createStateMachines(
{
'calculator': {
Comment: 'A simple calculator',
StartAt: 'OperatorChoice',
States: {
OperatorChoice: {
Type: 'Choice',
Choices: [
{
// 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
}]
},
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
function (err) {
// All good-to-go!
}
)
}, {}, // 'env': An environment/context/sandbox
)
// STEP 3:
// Start a new execution on a state machine
// ----------------------------------------
// 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
)
executionDescription = await statebox.startExecution(
{
numbers: {
number1: 3,
number2: 2
},
operator: '-'
}, // input
'calculator', // state machine name
{} // options
)
// Result object
// -------------
// {
// executionName: '01e1e288-9533-11e7-8fec-54d168e2e610',
// ctx: {
// numbers: {
// number1: 3,
// number2: 2
// },
// operator: '-'
// },
// currentStateName: 'OperatorChoice',
// stateMachineName: 'calculator',
// status: 'RUNNING',
// startDate: '2017-09-10T09:40:22.589Z'
// }
// STEP 4:
// Look at the results...
// ----------------------
const executionDescription2 = await statebox.waitUntilStoppedRunning(executionDescription.executionName)
console.log(executionDescription2)
// 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'
// }
}
// STEP 4:
// Look at the results...
// ----------------------
executionDescription = await statebox.describeExecution(
'01e1e288-9533-11e7-8fec-54d168e2e610'
)
// Result object
// -------------
// {
// executionName: '01e1e288-9533-11e7-8fec-54d168e2e610',
// ctx: {
// numbers': {
// number1: 3,
// number2: 2
// },
// operator: '-',
// result: 1 <--- The important bit :-)
// },
// currentStateName: 'Subtract',
// stateMachineName: 'calculator',
// status: 'SUCCEEDED',
// startDate: '2017-09-10T09:59:50.711Z'
// }
if (require.main === module) {
main();
}
```

@@ -168,0 +147,0 @@

Sorry, the diff of this file is not supported yet

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