@peter.naydenov/fsm-hub 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Chaingelog.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Release History
2
+
3
+
4
+ ### 2.0.2 ( 2022-11-17 )
5
+ - [x] Works with `@peter.naydenov/fsm` version 5 and above;
6
+
7
+
8
+
9
+ ### 2.0.0 ( 2022-11-16 )
10
+ - [x] The library become a ES module;
11
+
12
+
13
+
14
+ ### 1.0.5 ( 2022-05-27 )
15
+ - [x] Just a dependency update;
16
+
17
+ ### 1.0.4 ( 2021-04-02 )
18
+ - [x] Fix: Duplicated update callback if logic contain a chainAction;
19
+
20
+ ### 1.0.3 ( 2021-03-26 )
21
+ - [x] Massive code refactoring;
22
+ - [ ] Bug: Duplicated update callback if logic contain a chainAction;
23
+
24
+
25
+
package/README.md CHANGED
@@ -205,6 +205,12 @@ const
205
205
 
206
206
  ## Release History
207
207
 
208
+
209
+ ### 2.0.2 ( 2022-11-17 )
210
+ - [x] Works with `@peter.naydenov/fsm` version 5 and above;
211
+
212
+
213
+
208
214
  ### 2.0.0 ( 2022-11-16 )
209
215
  - [x] The library become a ES module;
210
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peter.naydenov/fsm-hub",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "FSM orchestration and state-managment tool",
5
5
  "main": "src/main.js",
6
6
  "type": "module",
@@ -12,14 +12,14 @@
12
12
  "author": "Peter Naydenov",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@peter.naydenov/stack": "1.0.0",
15
+ "@peter.naydenov/stack": "2.0.0",
16
16
  "ask-for-promise": "1.3.1"
17
17
  },
18
18
  "devDependencies": {
19
- "@peter.naydenov/fsm": "4.0.1",
20
- "c8": "^7.12.0",
21
- "chai": "4.3.7",
22
- "mocha": "10.1.0"
19
+ "@peter.naydenov/fsm": "5.0.0",
20
+ "c8": "^8.0.1",
21
+ "chai": "4.3.8",
22
+ "mocha": "10.2.0"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
package/src/main.js CHANGED
@@ -11,8 +11,8 @@ function FsmHub ( machine, transformerLib ) {
11
11
  hub.fsm = {} // Fsm's placeholder
12
12
  hub.fnCallbacks = {} // Callback functions place
13
13
  hub.debug = machine.debug || false
14
- hub.cache = stack ( 'FIFO' )
15
- hub.cacheInternal = stack ( 'FIFO' )
14
+ hub.cache = stack ({ type : 'FIFO' })
15
+ hub.cacheInternal = stack ({ type: 'FIFO' })
16
16
  hub.wait = []
17
17
  hub.lock = false
18
18
  hub.haveInternalRequest = false
package/test/01-basics.js CHANGED
@@ -45,13 +45,13 @@ it ( 'Hub structure', () => {
45
45
 
46
46
  it ( 'Add a fsm', () => {
47
47
  const
48
- mini = {
48
+ miniMachine = {
49
49
  init : 'none'
50
- , table : [
50
+ , behavior : [
51
51
  [ 'none', 'activate', 'active', 'switchOn']
52
52
  ]
53
53
  };
54
- const machine = new Fsm ( mini );
54
+ const machine = new Fsm ( miniMachine );
55
55
  const
56
56
  hubDescription = {
57
57
  reactivity : [
@@ -111,7 +111,7 @@ it ( 'Add a fsm', () => {
111
111
  const
112
112
  mini = {
113
113
  init : 'none'
114
- , table : [
114
+ , behavior : [
115
115
  [ 'none', 'activate', 'active', 'switchOn']
116
116
  ]
117
117
  };
@@ -142,14 +142,14 @@ it ( 'Use hub-transformer', done => {
142
142
  const
143
143
  miniOne = {
144
144
  init : 'none'
145
- , table : [
145
+ , behavior : [
146
146
  [ 'none', 'activate', 'active', 'switchOn']
147
147
  ]
148
148
  };
149
149
 
150
150
  // Setup fsm transition libraries
151
151
  const transitionOne = {
152
- switchOn ( task, dependencies, stateObj, data ) {
152
+ switchOn ( {task}, data ) {
153
153
  task.done ({
154
154
  success : true
155
155
  , response : data
@@ -194,7 +194,7 @@ it ( 'Use hub-transformer', done => {
194
194
  , state
195
195
  , answer
196
196
  } = transitionResult;
197
-
197
+ console.log ( second, state, answer )
198
198
  expect ( second ).to.be.equal ( 'second' )
199
199
  expect ( state ).to.be.equal ( 'active' )
200
200
  expect ( answer ).to.be.equal ( 'try' )
@@ -270,7 +270,7 @@ it ( 'Try to add FSM name that is already registered', () => {
270
270
  const
271
271
  miniOne = {
272
272
  init : 'none'
273
- , table : [
273
+ , behavior : [
274
274
  [ 'none', 'activate', 'active', 'switchOn']
275
275
  ]
276
276
  };
@@ -339,17 +339,17 @@ it ( 'Not registered fsm subscriber', done => {
339
339
  const
340
340
  miniOne = {
341
341
  init : 'none'
342
- , table : [
342
+ , behavior : [
343
343
  [ 'none', 'activate', 'active', 'switchOn']
344
344
  ]
345
345
  };
346
346
 
347
347
  // Setup fsm transition libraries
348
348
  const transitionOne = {
349
- switchOn ( task, dependencies, stateObj, dt ) {
349
+ switchOn ( {task}, data ) {
350
350
  task.done ({
351
351
  success : true
352
- , response : dt
352
+ , response : data
353
353
  })
354
354
  }
355
355
  };
@@ -403,17 +403,17 @@ it ( 'Transformer is not a function', () => {
403
403
  const
404
404
  miniOne = {
405
405
  init : 'none'
406
- , table : [
406
+ , behavior : [
407
407
  [ 'none', 'activate', 'active', 'switchOn']
408
408
  ]
409
409
  };
410
410
 
411
411
  // Setup fsm transition libraries
412
412
  const transitionOne = {
413
- switchOn ( task, dependencies, stateObj, dt ) {
413
+ switchOn ( {task}, data ) {
414
414
  task.done ({
415
415
  success : true
416
- , response : dt
416
+ , response : data
417
417
  })
418
418
  }
419
419
  };
@@ -461,7 +461,7 @@ it ( 'Callback-function with data argument', done => {
461
461
  const
462
462
  miniOne = {
463
463
  init : 'none'
464
- , table : [
464
+ , behavior : [
465
465
  [ 'none', 'activate', 'active', 'switchOn']
466
466
  , [ 'active', 'stop', 'none', 'switchOff']
467
467
  ]
@@ -469,16 +469,16 @@ it ( 'Callback-function with data argument', done => {
469
469
 
470
470
  // Setup fsm transition libraries
471
471
  const transitionOne = {
472
- switchOn ( task, dependencies, stateObj, dt ) {
472
+ switchOn ( {task}, data ) {
473
473
  task.done ({
474
474
  success : true
475
- , response : dt
475
+ , response : data
476
476
  })
477
477
  }
478
- , switchOff ( task, dependencies, stateObj, dt ) {
478
+ , switchOff ( {task}, data ) {
479
479
  task.done ({
480
480
  success : true
481
- , response : dt
481
+ , response : data
482
482
  })
483
483
  }
484
484
  };
@@ -510,12 +510,12 @@ it ( 'Callback-function with data argument', done => {
510
510
  const hub = new FsmHub ( machine, transformerLib );
511
511
  function showme ( data ) {
512
512
  expect ( data.try ).to.equal ( 'simple-active-try' )
513
- expect ( two.state == 'active' )
513
+ expect ( two.getState () == 'active' )
514
514
  one.update ( 'stop' )
515
515
  } // showme func.
516
516
 
517
517
  function final ( data ) {
518
- expect ( two.state ).to.be.equal ( 'none' )
518
+ expect ( two.getState() ).to.be.equal ( 'none' )
519
519
  done ()
520
520
  } // final func.
521
521
 
@@ -8,7 +8,7 @@ describe ( 'Fsm Hub', () => {
8
8
 
9
9
  /**
10
10
  * Description:
11
- * Create a 3 fsm systems - human, spy, and recorder
11
+ * Create a 3 fsm systems - human, spy, and recorder
12
12
  * - Human: Can receive good and bad news and change his mood according the news;
13
13
  * - Spy: Spy on human and sends to recorder the messages that make him unhappy;
14
14
  * - Recorder: Storage for bad news. When messages are 3 will stop with the recording and will call function "TimeForChange"
@@ -17,7 +17,7 @@ describe ( 'Fsm Hub', () => {
17
17
  const
18
18
  recorderDescription = { // Description of the recorder
19
19
  init : 'empty'
20
- , table : [
20
+ , behavior : [
21
21
  [ 'empty' , 'write' , 'used' , 'add_a_warning' ]
22
22
  , [ 'used' , 'write' , 'used' , 'add_a_warning', [ 'isFull?', false ] ]
23
23
  , [ 'used' , 'isFull?' , 'full' , 'check_if_full' ]
@@ -28,7 +28,7 @@ describe ( 'Fsm Hub', () => {
28
28
  }
29
29
  , humanDescription = { // Very weak description of human emotions. Just for testing purposes
30
30
  init : 'happy'
31
- , table : [
31
+ , behavior : [
32
32
  [ 'happy' , 'goodNews', 'happy' , 'feel_happy' ]
33
33
  , [ 'happy' , 'badNews' , 'unhappy' , 'feel_bad' ]
34
34
  , [ 'unhappy' , 'badNews' , 'unhappy' , 'feel_bad' ]
@@ -37,7 +37,7 @@ describe ( 'Fsm Hub', () => {
37
37
  }
38
38
  , spyDescription = {
39
39
  init: 'positive'
40
- , table : [
40
+ , behavior : [
41
41
  [ 'positive', 'bad' , 'negative' , 'onBad' ]
42
42
  , [ 'negative', 'good' , 'positive' , 'onGood' ]
43
43
  , [ 'negative', 'bad' , 'negative' , 'onBad' ]
@@ -48,7 +48,7 @@ describe ( 'Fsm Hub', () => {
48
48
  [ 'human' , 'unhappy' , 'spy' , 'bad' ]
49
49
  , [ 'spy' , 'negative' , 'recorder' , 'write' ]
50
50
  , [ 'recorder' , 'full' , 'timeForChange' ]
51
- , [ 'recorder' , 'full' , 'test' ]
51
+ , [ 'recorder' , 'full' , 'test' ]
52
52
  ]
53
53
  , transformers : {
54
54
  'human/spy' : 'emotion2spy'
@@ -59,13 +59,13 @@ describe ( 'Fsm Hub', () => {
59
59
  // Define libs
60
60
  const
61
61
  humanLib = {
62
- feel_happy (task,dependencies, stateData, data ) {
62
+ feel_happy ({task}, data ) {
63
63
  task.done ({
64
64
  success : true
65
65
  , response : data
66
66
  })
67
67
  }
68
- , feel_bad ( task, dependencies, stateData, data ) {
68
+ , feel_bad ( {task}, data ) {
69
69
  task.done ({
70
70
  success : true
71
71
  , response: data
@@ -73,13 +73,13 @@ describe ( 'Fsm Hub', () => {
73
73
  }
74
74
  }
75
75
  , spyLib = {
76
- onBad ( task, dependencies, stateData, data ) {
76
+ onBad ( {task}, data ) {
77
77
  task.done ({
78
78
  success : true
79
79
  , response : data
80
80
  })
81
81
  }
82
- , onGood ( task, dependencies, stateData, data ) {
82
+ , onGood ( {task}, data ) {
83
83
  task.done ({
84
84
  success : true
85
85
  , response : data
@@ -87,17 +87,17 @@ describe ( 'Fsm Hub', () => {
87
87
  }
88
88
  }
89
89
  , recorderLib = {
90
- add_a_warning ( task, dependencies, stateData, data ) {
91
- const { reasons } = stateData;
92
- if ( !reasons.includes(data.response) ) stateData.reasons.push ( data.response )
90
+ add_a_warning ( { task, extractList }, data ) {
91
+ const [ reasons ] = extractList (['reasons']);
92
+ if ( !reasons.includes(data.response) ) reasons.push ( data.response )
93
93
  task.done ({
94
94
  success : true
95
- , stateData
95
+ , stateData : { reasons }
96
96
  , response : data
97
97
  })
98
98
  }
99
- , check_if_full ( task, dependencies, stateData, data ) {
100
- const { reasons } = stateData;
99
+ , check_if_full ( {task, extractList}, data ) {
100
+ const [ reasons ] = extractList (['reasons']);
101
101
  if ( reasons.length >= 3 ) task.done ({ success : true, response: data })
102
102
  else task.done ({ success : false, response: data })
103
103
  }
@@ -127,7 +127,7 @@ describe ( 'Fsm Hub', () => {
127
127
  expect ( result ).to.be.equal ( 'DONE' )
128
128
  expect ( theHub.cache.isEmpty () ).to.be.true
129
129
  expect ( theHub.cacheInternal.isEmpty () ).to.be.true
130
- let rec = recorder.exportState ().stateData.reasons
130
+ let [ rec ] = recorder.extractList (['reasons'], { as: 'std'})
131
131
 
132
132
  expect ( rec ).to.be.an ( 'array' )
133
133
  expect ( rec ).to.have.length ( 3 )