@peter.naydenov/fsm-hub 2.0.5 → 2.1.0

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 CHANGED
@@ -1,12 +1,27 @@
1
1
  ## Release History
2
2
 
3
3
 
4
+ ### 2.1.0 ( 2024-02-04)
5
+ - [x] Dependency update. ask-for-promise@2.0.3;
6
+ - [x] Dependency update. @peter.naydenov/stack@3.0.0;
7
+ - [x] Dev dependency update. @peter.naydenov/fsm - v.5.2.0;
8
+ - [x] Dev dependencies updates. Chai@5.0.3;
9
+ - [x] Dev dependencies updates. C8@9.1.0;
10
+ - [x] Folder 'dist' was added to the project. Includes commonjs, umd and esm versions of the library;
11
+ - [x] Package.json: "exports" section was added. Allows you to use package as commonjs or es6 module without additional configuration;
12
+ - [x] Rollup was added to the project. Used to build the library versions;
13
+
14
+
4
15
 
5
16
  ### 2.0.5 ( 2023-10-21 )
6
17
  - [x] Dependency update. @peter.naydenov/fsm - v.5.1.2;
7
18
 
8
19
 
9
20
 
21
+ ### 2.0.4 ( 2022-11-17 )
22
+ - [x] Dependencies update. @peter.naydenov/fsm version 5.1.1;
23
+
24
+
10
25
 
11
26
  ### 2.0.3 ( 2023-10-21 )
12
27
  - [x] Dependency update. Ask-for-promise - v.1.4.0;
@@ -35,3 +50,9 @@
35
50
 
36
51
 
37
52
 
53
+
54
+
55
+
56
+
57
+
58
+
package/README.md CHANGED
@@ -203,35 +203,9 @@ const
203
203
 
204
204
 
205
205
 
206
- ## Release History
207
-
208
-
209
- ### 2.0.4 ( 2022-11-17 )
210
- - [x] Dependencies update. @peter.naydenov/fsm version 5.1.1;
211
-
212
-
213
- ### 2.0.2 ( 2022-11-17 )
214
- - [x] Works with `@peter.naydenov/fsm` version 5 and above;
215
-
216
-
217
-
218
- ### 2.0.0 ( 2022-11-16 )
219
- - [x] The library become a ES module;
220
-
221
-
222
-
223
- ### 1.0.5 ( 2022-05-27 )
224
- - [x] Just a dependency update;
225
-
226
- ### 1.0.4 ( 2021-04-02 )
227
- - [x] Fix: Duplicated update callback if logic contain a chainAction;
228
-
229
- ### 1.0.3 ( 2021-03-26 )
230
- - [x] Massive code refactoring;
231
- - [ ] Bug: Duplicated update callback if logic contain a chainAction;
232
-
233
-
206
+ ## Links
234
207
 
208
+ - [Release History](https://github.com/PeterNaydenov/fsm-hub/blob/master/Chaingelog.md)
235
209
 
236
210
 
237
211
 
@@ -0,0 +1 @@
1
+ "use strict";var e=require("ask-for-promise"),n=require("@peter.naydenov/stack");const r={_setTransitions:function(e,n){return function({reactivity:r,transformers:t},s={}){let a={},c={},o={},i={};return r.forEach(((r,t)=>{if(!(r instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const s=r.length,[a,u,l,f]=r;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))})),t&&Object.keys(t).forEach((e=>{const n=t[e],r=s[n];r&&(a[e]=r)})),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,r){e.debug&&console.log(n,r)}},_callback:function(n,r){return function(t,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach((e=>{if(!n.fsm[e])return void n._debugger(r.MISSING_FSM,i);const t=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(t,d);h.push(_)})),u){let t=e();h.push(t.promise),u.forEach((e=>{const t=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof t?t(d):n._debugger(r.MISSING_FN,e)})),t.done()}Promise.all(h).then((()=>t.done()))}else t.done()}},addFsm:function(n,r){return function(t){Object.keys(t).forEach((s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let r=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&r)return void(n.lock=!1);let[t,s,a]=r?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(t,s,a)}function c(r,t,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete((e=>a(!1))),void n._callback(c,r,t,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[r,t,s]]);let c=e();return c.onComplete((e=>a(!0))),n.haveInternalRequest=!0,void n._callback(c,r,t,s)}n.cache.push([[r,t,s]])}n.fsm[s]?n._debugger(r.REGISTERED_FSM_NAME,s):(n.fsm[s]=t[s],n.fsm[s].on("update",((e,n)=>c(s,e,n))))}))}},addFunctions:function(e,n){return function(r){Object.keys(r).forEach((t=>{e.fnCallbacks[t]?e._debugger(n.REGISTERED_FUNCTION_NAME,t):e.fnCallbacks[t]=r[t]}))}}},t={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};module.exports=function(s,a){const c=this,o=Object.keys(r);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach((e=>{c[e]=r[e](c,t)}));const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f};
@@ -0,0 +1 @@
1
+ import e from"ask-for-promise";import n from"@peter.naydenov/stack";const t={_setTransitions:function(e,n){return function({reactivity:t,transformers:r},s={}){let a={},c={},o={},i={};return t.forEach(((t,r)=>{if(!(t instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const s=t.length,[a,u,l,f]=t;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))})),r&&Object.keys(r).forEach((e=>{const n=r[e],t=s[n];t&&(a[e]=t)})),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,t){e.debug&&console.log(n,t)}},_callback:function(n,t){return function(r,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach((e=>{if(!n.fsm[e])return void n._debugger(t.MISSING_FSM,i);const r=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(r,d);h.push(_)})),u){let r=e();h.push(r.promise),u.forEach((e=>{const r=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof r?r(d):n._debugger(t.MISSING_FN,e)})),r.done()}Promise.all(h).then((()=>r.done()))}else r.done()}},addFsm:function(n,t){return function(r){Object.keys(r).forEach((s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let t=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&t)return void(n.lock=!1);let[r,s,a]=t?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(r,s,a)}function c(t,r,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete((e=>a(!1))),void n._callback(c,t,r,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[t,r,s]]);let c=e();return c.onComplete((e=>a(!0))),n.haveInternalRequest=!0,void n._callback(c,t,r,s)}n.cache.push([[t,r,s]])}n.fsm[s]?n._debugger(t.REGISTERED_FSM_NAME,s):(n.fsm[s]=r[s],n.fsm[s].on("update",((e,n)=>c(s,e,n))))}))}},addFunctions:function(e,n){return function(t){Object.keys(t).forEach((r=>{e.fnCallbacks[r]?e._debugger(n.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=t[r]}))}}},r={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function s(s,a){const c=this,o=Object.keys(t);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach((e=>{c[e]=t[e](c,r)}));const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f}export{s as default};
@@ -0,0 +1 @@
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).fsmHub=n()}(this,(function(){"use strict";function e(e){let r,o=!1;return e?(r=function(e){let r=e.map((e=>n())),o=r.map((e=>e.promise));return r.promises=o,r.onComplete=t(Promise.all(o)),r}(e),o=!0):r=n(),r.timeout=function(e,n){let r;return r=e?Promise.all(n.promises):n.promise,function(e,o){let s,i=new Promise(((n,t)=>{s=setTimeout((()=>{n(o),Promise.resolve(r)}),e)}));return r.then((()=>clearTimeout(s))),n.onComplete=t(Promise.race([r,i])),n}}(o,r),r}function n(){let e,n;const r=new Promise(((t,r)=>{e=t,n=r}));return{promise:r,done:e,cancel:n,onComplete:t(r)}}function t(e){return function(n){e.then((e=>n(e)))}}e.sequence=function(n,...t){const r=e(),o=[],s=function*(e){for(const n of e)yield n}(n);return function e(n,...t){n.done?r.done(o):n.value(...t).then((n=>{o.push(n),e(s.next(),...t,n)}))}(s.next(),...t),r},e.all=function(n,...t){const r=e(),o=[],s=n.map(((e,n)=>"function"==typeof e?e(...t).then((e=>o[n]=e)):e.then((e=>o[n]=e))));return Promise.all(s).then((()=>r.done(o))),r};const r={_setTransitions:function(e,n){return function({reactivity:t,transformers:r},o={}){let s={},i={},c={},l={};return t.forEach(((t,r)=>{if(!(t instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const o=t.length,[s,a,u,f]=t;if(!(4==o||3==o))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const p=`${s}/${a}`;if(4==o){i[p]||(i[p]=[]),i[p].push(u);c[`${p}/${u}`]=f}3==o&&(l[p]||(l[p]=[]),l[p].push(u))})),r&&Object.keys(r).forEach((e=>{const n=r[e],t=o[n];t&&(s[e]=t)})),{transformers:s,subscribers:i,callbacks:l,actions:c}}},_debugger:function(e){return function(n,t){e.debug&&console.log(n,t)}},_callback:function(n,t){return function(r,o,s,i){const c=`${o}/${s}`,l=n.subscribers[c]||!1,a=n.callbacks[c]||!1,u=n.fnCallbacks,f=n.actions,p=[];let h;if(l||a){if(l&&l.forEach((e=>{if(!n.fsm[e])return void n._debugger(t.MISSING_FSM,l);const r=f[`${c}/${e}`],a=`${o}/${e}`,u=n.transformers[a];h="function"==typeof u?u(s,i):i,h||(h={},h.___internalFlag=!0);const m=n.fsm[e].update(r,h);p.push(m)})),a){let r=e();p.push(r.promise),a.forEach((e=>{const r=u[e],c=`${o}/${e}`,l=n.transformers[c];h="function"==typeof l?l(s,i):i,h.answer&&h.answer.hasOwnProperty("___internalFlag")&&(h.answer=void 0),"function"==typeof r?r(h):n._debugger(t.MISSING_FN,e)})),r.done()}Promise.all(p).then((()=>r.done()))}else r.done()}},addFsm:function(n,t){return function(r){Object.keys(r).forEach((o=>{function s(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let t=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&t)return void(n.lock=!1);let[r,o,s]=t?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),i(r,o,s)}function i(t,r,o){let i;if(!n.lock)return n.lock=!0,i=e(),i.onComplete((e=>s(!1))),void n._callback(i,t,r,o);if(o){if(n.haveInternalRequest)return void n.cacheInternal.push([[t,r,o]]);let i=e();return i.onComplete((e=>s(!0))),n.haveInternalRequest=!0,void n._callback(i,t,r,o)}n.cache.push([[t,r,o]])}n.fsm[o]?n._debugger(t.REGISTERED_FSM_NAME,o):(n.fsm[o]=r[o],n.fsm[o].on("update",((e,n)=>i(o,e,n))))}))}},addFunctions:function(e,n){return function(t){Object.keys(t).forEach((r=>{e.fnCallbacks[r]?e._debugger(n.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=t[r]}))}}},o={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function s(e={}){let n=[],{type:t,limit:r,onLimit:o}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),s="LIFO"===t.toUpperCase(),i=!1;function c(e=1,t=0){let r=[];return t>0&&Array.from({length:t}).map((()=>n.pop())),1==e?n.pop():(Array.from({length:e}).map((()=>{let e=n.pop();null!=e&&r.push(e)})),r)}function l(e=1,t=0){let r=[],o=n.length-t;return e>1&&Array.from({length:e}).map((()=>{null!=n[o-1]&&r.push(n[o-1]),o--})),1==e?n[n.length-1]:r}function a(){}return a.prototype={pull:c,pullReverse:function(e=1,n=0){let t=c(e,n);return t instanceof Array?t.reverse():t},peek:l,peekReverse:function(e=1,n=0){const t=l(e,n);return t instanceof Array?t.reverse():t},getSize:()=>n.length,isEmpty:()=>0==n.length,reset:()=>(n=[],!0),debug:()=>[...n]},a.prototype.push=s?function(e){const t=e instanceof Array,s=t?e.length:1;let l=!1;if("full"!==o||!i){if(r&&t&&s>r&&(e=e.slice(0,-s+r)),r){const s=(t?e.length:1)+n.length;s>=r&&"full"===o&&(e=e.slice(0,-(s-r))),s>=r&&"update"===o&&(l=c(s-r))}return n=e instanceof Array?n.concat(e):n.concat([e]),i=!!r&&n.length===r,l||void 0}}:function(e){const t=e instanceof Array,s=t?e.length:1;let l=!1;if("full"!==o||!i){if(r&&t&&s>r&&(e=e.slice(s-r)),r){const s=(t?e.length:1)+n.length;s>=r&&"full"===o&&(e=e.slice(0,-(s-r))),s>=r&&"update"===o&&(l=c(s-r))}return n=t?e.reduce(((e,n)=>[n,...e]),n):[e].reduce(((e,n)=>[n,...e]),n),i=!!r&&n.length===r,l||void 0}},new a}return function(n,t){const i=this,c=Object.keys(r);i.fsm={},i.fnCallbacks={},i.debug=n.debug||!1,i.cache=s({type:"FIFO"}),i.cacheInternal=s({type:"FIFO"}),i.wait=[],i.lock=!1,i.haveInternalRequest=!1,i.reactivityTask=!1,i.askForPromise=e,c.forEach((e=>{i[e]=r[e](i,o)}));const{transformers:l,subscribers:a,actions:u,callbacks:f}=i._setTransitions(n,t);i.transformers=l,i.subscribers=a,i.actions=u,i.callbacks=f}}));
package/package.json CHANGED
@@ -1,35 +1,44 @@
1
1
  {
2
2
  "name": "@peter.naydenov/fsm-hub",
3
- "version": "2.0.5",
4
3
  "description": "FSM orchestration and state-managment tool",
5
- "main": "src/main.js",
4
+ "version": "2.1.0",
5
+ "license": "MIT",
6
+ "author": "Peter Naydenov",
7
+ "main": "./dist/fsm-hub.umd.js",
6
8
  "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/fsm-hub.esm.mjs",
12
+ "require": "./dist/fsm-hub.cjs",
13
+ "default": "./dist/fsm-hub.umd.js"
14
+ },
15
+ "./package.json": "./package.json",
16
+ "./dist/*": "./dist/*",
17
+ "./src/*": "./src/*"
18
+ },
7
19
  "scripts": {
8
20
  "test": "mocha test",
9
21
  "cover": "c8 mocha test",
10
- "build": "vite build"
22
+ "build": "rollup -c"
11
23
  },
12
- "author": "Peter Naydenov",
13
- "license": "MIT",
14
24
  "dependencies": {
15
- "@peter.naydenov/stack": "2.0.0",
16
- "ask-for-promise": "1.5.0"
25
+ "@peter.naydenov/stack": "3.0.0",
26
+ "ask-for-promise": "2.0.3"
17
27
  },
18
28
  "devDependencies": {
19
- "@peter.naydenov/fsm": "5.1.2",
20
- "c8": "^8.0.1",
21
- "chai": "4.3.10",
22
- "mocha": "10.2.0"
29
+ "@peter.naydenov/fsm": "5.2.0",
30
+ "@rollup/plugin-commonjs": "^25.0.7",
31
+ "@rollup/plugin-node-resolve": "^15.2.3",
32
+ "@rollup/plugin-terser": "^0.4.4",
33
+ "c8": "^9.1.0",
34
+ "chai": "5.0.3",
35
+ "mocha": "10.2.0",
36
+ "rollup": "^4.9.6"
23
37
  },
24
38
  "repository": {
25
39
  "type": "git",
26
40
  "url": "https://github.com/PeterNaydenov/fsm-hub.git"
27
41
  },
28
- "keywords": [
29
- "fsm",
30
- "state-managment",
31
- "orchestration"
32
- ],
33
42
  "c8": {
34
43
  "include": [
35
44
  "src/**/*.js"
@@ -42,5 +51,10 @@
42
51
  "lcov",
43
52
  "text-summary"
44
53
  ]
45
- }
54
+ },
55
+ "keywords": [
56
+ "fsm",
57
+ "state-managment",
58
+ "orchestration"
59
+ ]
46
60
  }
@@ -0,0 +1,41 @@
1
+ import resolve from '@rollup/plugin-node-resolve'
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import terser from '@rollup/plugin-terser';
4
+
5
+
6
+ export default [
7
+ // browser-friendly UMD build
8
+ {
9
+ input: 'src/main.js',
10
+ output: {
11
+ name: 'fsmHub',
12
+ file: 'dist/fsm-hub.umd.js',
13
+ format: 'umd',
14
+ globals : {
15
+ 'ask-for-promise' : 'askForPromise',
16
+ '@peter.naydenov/stack' : 'stack'
17
+ }
18
+ },
19
+ plugins: [
20
+ resolve(), // so Rollup can find `ms`
21
+ commonjs() // so Rollup can convert `ms` to an ES module
22
+ , terser()
23
+ ]
24
+ },
25
+
26
+ // CommonJS (for Node) and ES module (for bundlers) build.
27
+ // (We could have three entries in the configuration array
28
+ // instead of two, but it's quicker to generate multiple
29
+ // builds from a single configuration where possible, using
30
+ // an array for the `output` option, where we can specify
31
+ // `file` and `format` for each target)
32
+ {
33
+ input: 'src/main.js',
34
+ external: [ 'ask-for-promise', '@peter.naydenov/stack' ],
35
+ output: [
36
+ { file: 'dist/fsm-hub.cjs' , format: 'cjs' },
37
+ { file: 'dist/fsm-hub.esm.mjs', format: 'es' }
38
+ ],
39
+ plugins: [ terser() ]
40
+ }
41
+ ];