Created
November 22, 2019 21:46
-
-
Save unsay/523e187c5f2f3276b16ea68fc833f2c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Archiver = Decryptor = Unzipper = bcp = Copier = Intell = Cleanup = {} | |
| const guards = { | |
| isArchived: (context, event) => context._archive != undefined && fs.existsSync(context._archive), | |
| isMoved: (context, event) => context._moved != undefined && fs.existsSync(context._moved), | |
| achExtracted: (context, event) => (context._origin.includes(context.bankDirectories.incomingACH)), | |
| cardExtracted: (context, event) => (context._origin.includes(context.bankDirectories.incomingCard)), | |
| isTransformed: (context, event) => context._transformed != undefined, | |
| fileIsZipped: (context, event) => path.extname(context.working) === '.zip', | |
| fileIsEncrypted: (context, event) => path.extname(context.working) === '.gpg', | |
| hasError: (context, event) => context.error != undefined | |
| } | |
| const etl = Machine({ | |
| id: 'etl', | |
| initial: 'pending', | |
| strict: true, | |
| context: { | |
| working: undefined, | |
| error: undefined, | |
| console: '', | |
| _origin: undefined, | |
| _copied: undefined, | |
| _archive: undefined, | |
| _decrypted: undefined, | |
| _unzipped: undefined, | |
| _transformed: undefined, | |
| }, | |
| states: { | |
| 'pending': { | |
| on: { | |
| 'START': { | |
| target: 'archiving' | |
| } | |
| } | |
| }, | |
| 'archiving': { | |
| invoke: { | |
| id: 'archiver', | |
| src: Archiver, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'archived', | |
| actions: assign({ | |
| _origin: (context, event) => context.working, | |
| _archive: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| // working parameter is unchanged | |
| }) | |
| } | |
| } | |
| }, | |
| 'archived': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'copying', cond: 'isArchived' } | |
| ] | |
| } | |
| }, | |
| 'copying': { | |
| invoke: { | |
| id: 'copier', | |
| src: Copier, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'copied', | |
| actions: assign({ | |
| _copied: (context, event) => event.data.result, | |
| working: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'copied': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'decrypting', cond: 'fileIsEncrypted' }, | |
| { target: 'unzipping', cond: 'fileIsZipped' } | |
| ] | |
| } | |
| }, | |
| 'decrypting': { | |
| invoke: { | |
| id: 'decryptor', | |
| src: Decryptor, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'extracted', | |
| actions: assign({ | |
| _decrypted: (context, event) => event.data.result, | |
| working: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'unzipping': { | |
| invoke: { | |
| id: 'unzipper', | |
| src: Unzipper, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'extracted', | |
| actions: assign({ | |
| _unzipped: (context, event) => event.data.result, | |
| working: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'extracted': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'loading', cond: 'cardExtracted' }, | |
| { target: 'transforming', cond: 'achExtracted' } | |
| ] | |
| } | |
| }, | |
| 'transforming': { | |
| invoke: { | |
| id: 'transfomer', | |
| src: Intell, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'transformed', | |
| actions: assign({ | |
| _transformed: (context, event) => event.data.result, | |
| working: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'transformed': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'loading', cond: 'isTransformed' } | |
| ] | |
| } | |
| }, | |
| 'loading': { | |
| invoke: { | |
| id: 'loader', | |
| src: bcp, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'loaded', | |
| actions: assign({ | |
| _loaded: (context, event) => event.data.result, | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'loaded': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'cleanup' } | |
| ] | |
| } | |
| }, | |
| 'cleanup': { | |
| invoke: { | |
| id: 'cleanup', | |
| src: Cleanup, | |
| data: (context) => context, | |
| onDone: { | |
| target: 'cleaned', | |
| actions: assign({ | |
| error: (context, event) => event.data.error | |
| }) | |
| } | |
| } | |
| }, | |
| 'cleaned': { | |
| on: { | |
| '': [ | |
| { target: 'error', cond: 'hasError' }, | |
| { target: 'complete' } | |
| ] | |
| } | |
| }, | |
| 'complete': { | |
| type: 'final' | |
| }, | |
| 'error': { | |
| type: 'final' | |
| } | |
| } | |
| },{ guards }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment