Comparing version 1.0.0 to 1.0.1
@@ -7,21 +7,6 @@ import { State } from "../states/State"; | ||
constructor(state: T); | ||
/** | ||
* We store and provide the state to allow method chaining. | ||
*/ | ||
getParentState(): T; | ||
/** | ||
* Method to validate some data, optional implementation. | ||
*/ | ||
validate(): null | Error; | ||
/** | ||
* When the field should be used as configuration to the parent (State). | ||
* If false the field is not configured, this means the State will | ||
* not provide any configuration of this field. | ||
*/ | ||
isConfigured(): boolean; | ||
/** | ||
* Once the instance receives configurations, we change the field | ||
* as configured. Call this once the field received setup interactions. | ||
*/ | ||
receiveConfiguration(): T; | ||
} |
@@ -8,11 +8,5 @@ "use strict"; | ||
} | ||
/** | ||
* We store and provide the state to allow method chaining. | ||
*/ | ||
Field.prototype.getParentState = function () { | ||
return this.state; | ||
}; | ||
/** | ||
* Method to validate some data, optional implementation. | ||
*/ | ||
Field.prototype.validate = function () { | ||
@@ -26,7 +20,2 @@ if (this.required && this.isConfigured() === false) { | ||
}; | ||
/** | ||
* When the field should be used as configuration to the parent (State). | ||
* If false the field is not configured, this means the State will | ||
* not provide any configuration of this field. | ||
*/ | ||
Field.prototype.isConfigured = function () { | ||
@@ -36,6 +25,2 @@ return this.configured; | ||
; | ||
/** | ||
* Once the instance receives configurations, we change the field | ||
* as configured. Call this once the field received setup interactions. | ||
*/ | ||
Field.prototype.receiveConfiguration = function () { | ||
@@ -42,0 +27,0 @@ this.configured = true; |
export * from './states/index'; | ||
export * from './fields/index'; | ||
export * from './generators/index'; | ||
export { StateMachine } from './StateMachine'; |
@@ -9,1 +9,3 @@ "use strict"; | ||
__export(require("./generators/index")); | ||
var StateMachine_1 = require("./StateMachine"); | ||
exports.StateMachine = StateMachine_1.StateMachine; |
@@ -18,2 +18,3 @@ import { State } from "./states"; | ||
addState(state: State): this; | ||
autoNextSetup(): void; | ||
validate(): Error[]; | ||
@@ -20,0 +21,0 @@ getComment(): string | null; |
@@ -34,2 +34,20 @@ "use strict"; | ||
}; | ||
StateMachine.prototype.autoNextSetup = function () { | ||
var previousState; | ||
this.states.forEach(function (state) { | ||
if (previousState) { | ||
var next = previousState.next; | ||
if (next && !next.isConfigured()) { | ||
next.to(state); | ||
} | ||
} | ||
previousState = state; | ||
}); | ||
if (previousState) { | ||
var next = (previousState).next; | ||
if (next && !next.isConfigured()) { | ||
next.end(); | ||
} | ||
} | ||
}; | ||
StateMachine.prototype.validate = function () { | ||
@@ -36,0 +54,0 @@ var errors = []; |
{ | ||
"name": "flowbject", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Flowbject is a library that allows you to describe state machines with objects.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
113
README.md
# Flowbject | ||
Flowbject is a library that allows you to describe state machines with objects. The concept is based on [Amazon-State-Language](https://states-language.net/spec.html). | ||
Flowbject allows you to build, validate and test your state-machine JSON in a more convenient way by interacting with Objects. This has many use-cases such as local state-flow validation, custom middlewares such as task identity resolvers, Tasks input/output mocking for flow-testing. | ||
## Motivation | ||
The concept is based on [Amazon-State-Language](https://states-language.net/spec.html). | ||
This package allows you to build, validate and test your state-machine JSON in a more convenient way by interacting with Objects. This has many use-cases such as local state-flow validation, custom middlewares such as task identity resolvers, Tasks input/output mocking for flow-testing. | ||
## Installation | ||
```bash | ||
npm install flowbject | ||
``` | ||
## Usage | ||
@@ -14,3 +19,3 @@ | ||
```typescript | ||
import * as fobject from '../src'; | ||
import * as fobject from 'flowbject'; | ||
@@ -33,6 +38,4 @@ | ||
.addState(saveImage) | ||
.autoNextSetup(); | ||
.autoNextSetup(); // setup the tasks next-field automatically | ||
const errors = stateMachine.validate(); | ||
const generator = new fobject.StepFunctionsGenerator(); | ||
@@ -67,97 +70,1 @@ | ||
``` | ||
### Choice build | ||
```typescript | ||
import * as fobject from '../src'; | ||
const stateMachine = new fobject.StateMachine(); | ||
const readImage = new fobject.Task('readImageFromS3') | ||
.setResource('arn::...'); | ||
const optimizePNG = new fobject.Task('optimizePNG') | ||
.setResource('arn::...'); | ||
const optimizeJPEG = new fobject.Task('optimizeJPEG') | ||
.setResource('arn::...'); | ||
const optimizationChoice = new fobject.Choice('optimizationChoice'); | ||
optimizationChoice.createComparatorRule(fobject.CHOICE_COMPARATOR_RULE.STRING_EQUALS) | ||
.setVariable('$.file.mime') | ||
.setValue('application/png') | ||
.next.to(optimizePNG); | ||
optimizationChoice.createComparatorRule(fobject.CHOICE_COMPARATOR_RULE.STRING_EQUALS) | ||
.setVariable('$.file.mime') | ||
.setValue('application/jpeg') | ||
.next.to(optimizeJPEG); | ||
const saveImage = new fobject.Task('saveToS3') | ||
.setResource('arn::...'); | ||
stateMachine | ||
.addState(readImage) | ||
.addState(optimizationChoice) | ||
.addState(optimizeJPEG.next.to(saveImage)) | ||
.addState(optimizePNG.next.to(saveImage)) | ||
.addState(saveImage).autoNextSetup(); | ||
const errors = stateMachine.validate(); | ||
const generator = new fobject.StepFunctionsGenerator(); | ||
const data = generator.generateStateMachine(stateMachine); | ||
console.log(JSON.stringify(data)); | ||
``` | ||
Output: | ||
```json | ||
{ | ||
"StartAt": "readImageFromS3", | ||
"States": { | ||
"readImageFromS3": { | ||
"Type": "Task", | ||
"Resource": "arn::...", | ||
"Next": "optimizationChoice" | ||
}, | ||
"optimizationChoice": { | ||
"Type": "Choice", | ||
"Choices": [ | ||
{ | ||
"StringEquals": "application/png", | ||
"Variable": "$.file.mime", | ||
"Next": "optimizePNG" | ||
}, | ||
{ | ||
"StringEquals": "application/jpeg", | ||
"Variable": "$.file.mime", | ||
"Next": "optimizeJPEG" | ||
} | ||
] | ||
}, | ||
"optimizeJPEG": { | ||
"Type": "Task", | ||
"Resource": "arn::...", | ||
"Next": "saveToS3" | ||
}, | ||
"optimizePNG": { | ||
"Type": "Task", | ||
"Resource": "arn::...", | ||
"Next": "saveToS3" | ||
}, | ||
"saveToS3": { | ||
"Type": "Task", | ||
"Resource": "arn::...", | ||
"End": true | ||
} | ||
} | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155777
3909
68