@alwatr/fsm 2.0.4 → 3.0.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/CHANGELOG.md +135 -73
- package/README.md +93 -2
- package/dist/base.d.ts +48 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/fsm.d.ts +15 -0
- package/dist/fsm.d.ts.map +1 -0
- package/dist/main.cjs +3 -0
- package/dist/main.cjs.map +7 -0
- package/{index.js → dist/main.d.ts} +1 -1
- package/dist/main.d.ts.map +1 -0
- package/dist/main.mjs +3 -0
- package/dist/main.mjs.map +7 -0
- package/{type.d.ts → dist/type.d.ts} +1 -1
- package/dist/type.d.ts.map +1 -0
- package/package.json +47 -18
- package/base.d.ts +0 -47
- package/base.d.ts.map +0 -1
- package/base.js +0 -92
- package/base.js.map +0 -1
- package/fsm.d.ts +0 -15
- package/fsm.d.ts.map +0 -1
- package/fsm.js +0 -19
- package/fsm.js.map +0 -1
- package/index.d.ts +0 -4
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/type.d.ts.map +0 -1
- package/type.js +0 -2
- package/type.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,38 +3,100 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## 3.0.0 (2024-09-15)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* **fsm:** FiniteStateMachineBase state property renamed to message data structure
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* update all repo files from alwatr ([b85a3a6](https://github.com/Alwatr/flux/commit/b85a3a62a8c19f395cf33d72329b9c0f301cddfc)) by @AliMD
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* all new repo path and packages dependencies ([21a6afa](https://github.com/Alwatr/flux/commit/21a6afa0badafe4051617d9a9e3bbfbaabd0c4ad)) by @
|
|
19
|
+
* cleanup old signal and fsm v1 ([bde0bea](https://github.com/Alwatr/flux/commit/bde0bea06a6750bebad49a127b75b57fd5e55ddd)) by @
|
|
20
|
+
* **fsm:** compatible with new logger api ([77db656](https://github.com/Alwatr/flux/commit/77db656d8b261da29376cf6dba7b9d4c35deeae8)) by @
|
|
21
|
+
* **fsm:** import issue ([9674f34](https://github.com/Alwatr/flux/commit/9674f34a7c63137fb9597d2b465b4fb123c963c1)) by @
|
|
22
|
+
* ts refrence path ([c2baa44](https://github.com/Alwatr/flux/commit/c2baa44999c72a0015481fc8fea25439329c3f37)) by @
|
|
23
|
+
|
|
24
|
+
### Code Refactoring
|
|
25
|
+
|
|
26
|
+
* **fsm:** rename main ([60a52bd](https://github.com/Alwatr/flux/commit/60a52bdc1e5ae3126226a9518d81f3c8dbf238dc)) by @AliMD
|
|
27
|
+
* **fsm:** Update FiniteStateMachineBase class ([27a29ca](https://github.com/Alwatr/flux/commit/27a29ca45fb2c7998760ce2177a386c7085011f9)) by @AliMD
|
|
28
|
+
* **fsm:** Update FiniteStateMachineBase class to use class property for state and transition methods ([647a921](https://github.com/Alwatr/flux/commit/647a921dab405b5545aecdb66f5d1d44490795d4)) by @AliMD
|
|
29
|
+
* **fsm:** Update FiniteStateMachineBase state property to message ([be1ca78](https://github.com/Alwatr/flux/commit/be1ca7897b8ada4b44576c2eaf9f38f3c2903668)) by @AliMD
|
|
30
|
+
* **fsm:** Update import statement for type.ts ([6091385](https://github.com/Alwatr/flux/commit/6091385ae7a4c4d92aa74effe6446c8e3a7606e9)) by @AliMD
|
|
31
|
+
* Remove unused dependencies from @alwatr/fsm package ([da58900](https://github.com/Alwatr/flux/commit/da5890009c9ddea4f45949eef5a372dd3784ea7a)) by @AliMD
|
|
32
|
+
* Rename fetch-state-machine.ts base class name ([ab88730](https://github.com/Alwatr/flux/commit/ab88730b46b2db0baeaca09e3de8e51c55b1e361)) by @AliMD
|
|
33
|
+
* Update @alwatr/fsm package and add @alwatr/observable package ([d78b177](https://github.com/Alwatr/flux/commit/d78b1774978632d66c6831c8a46626f524746e81)) by @AliMD
|
|
34
|
+
* Update @alwatr/polyfill-has-own dependency to version ^1.0.9 in fsm package.json ([f1c82a6](https://github.com/Alwatr/flux/commit/f1c82a6d330c3f1bfbf435a00a52e92f0541b024)) by @AliMD
|
|
35
|
+
* Update all package URLs to point to the flux repository ([e7e56d2](https://github.com/Alwatr/flux/commit/e7e56d252d4a0e1b4b1fa20c06e8b61b1b7242ae)) by @AliMD
|
|
36
|
+
* Update AlwatrContext constructor to use AlwatrObservableConfig ([a8c75c6](https://github.com/Alwatr/flux/commit/a8c75c6f937419e628a0b11b053e0028c731bcaf)) by @AliMD
|
|
37
|
+
* Update package dependencies and references ([888f698](https://github.com/Alwatr/flux/commit/888f6987553a410e561da9fe21c0655f8f935db0)) by @AliMD
|
|
38
|
+
|
|
39
|
+
### Miscellaneous Chores
|
|
40
|
+
|
|
41
|
+
* **deps-dev:** bump the development-dependencies group with 11 updates ([60f3075](https://github.com/Alwatr/flux/commit/60f3075872d3a4a9da979c589b5aa6b84065d48b)) by @
|
|
42
|
+
* **deps-dev:** bump the development-dependencies group with 14 updates ([c6ae70e](https://github.com/Alwatr/flux/commit/c6ae70e1534469fd36386f0828a52985001e2ef6)) by @
|
|
43
|
+
* **deps-dev:** bump the development-dependencies group with 8 updates ([c853aa2](https://github.com/Alwatr/flux/commit/c853aa2730b5c256049414e302a3d2d0c58ef61e)) by @
|
|
44
|
+
* **deps:** bump the alwatr-dependencies group with 3 updates ([f2a109d](https://github.com/Alwatr/flux/commit/f2a109d9b1775b67303d9407e20a5591cc69e4a7)) by @
|
|
45
|
+
* **deps:** bump the alwatr-dependencies group with 3 updates ([e5105eb](https://github.com/Alwatr/flux/commit/e5105eb0bbc450566b1ae6aee9241d541377bf94)) by @
|
|
46
|
+
* **deps:** bump the alwatr-dependencies group with 4 updates ([0019b83](https://github.com/Alwatr/flux/commit/0019b83ed56643b634972d8a15651ef2eaa2d735)) by @
|
|
47
|
+
* **deps:** bump the alwatr-dependencies group with 4 updates ([eb7fdfa](https://github.com/Alwatr/flux/commit/eb7fdfa545b5c1e040839a427326937acdcd8cb3)) by @
|
|
48
|
+
* **deps:** bump the alwatr-dependencies group with 4 updates ([4069863](https://github.com/Alwatr/flux/commit/40698638f3825b118d8c24fa115403f3f3b564a7)) by @
|
|
49
|
+
* **deps:** fix and update ([ab83ec7](https://github.com/Alwatr/flux/commit/ab83ec789d43245a8ff109e151b054a1fecb8e2a)) by @
|
|
50
|
+
* **deps:** update ([d7e2ef1](https://github.com/Alwatr/flux/commit/d7e2ef1a9de62fff6bfb2fd32af7dcfb4fcb048d)) by @njfamirm
|
|
51
|
+
* **deps:** upgrade ([7e60a62](https://github.com/Alwatr/flux/commit/7e60a6237f8b07b72dd9afd6bbaa140b187fe882)) by @
|
|
52
|
+
* **deps:** workspace dependencies ([627938e](https://github.com/Alwatr/flux/commit/627938e38e75a5e425388c3d56837feffd6716a2)) by @
|
|
53
|
+
* **fsm:** rename fsm2 ([f10fea0](https://github.com/Alwatr/flux/commit/f10fea017f75c3a26a26319b14284e8ee4bc605d)) by @
|
|
54
|
+
* rename core to packages ([9158c8e](https://github.com/Alwatr/flux/commit/9158c8e4c679d96c9b54e91ea6faa49364d47494)) by @
|
|
55
|
+
* update changelogs ([a965ecd](https://github.com/Alwatr/flux/commit/a965ecd095cb621b4a7748d2e048f4a82b0aa872)) by @
|
|
56
|
+
* **yarn:** pnp mode ([02bd406](https://github.com/Alwatr/flux/commit/02bd4064e381c483e31a8acbe7c72e7aed3e62b3)) by @
|
|
57
|
+
|
|
58
|
+
### Dependencies update
|
|
59
|
+
|
|
60
|
+
* bump the alwatr-dependencies group with 6 updates ([4470fd8](https://github.com/Alwatr/flux/commit/4470fd8be49e1a73c17bdd5a09127b9f3a67b3bb)) by @dependabot[bot]
|
|
61
|
+
* update ([0128365](https://github.com/Alwatr/flux/commit/01283652b0798243aaac9643c5024e7856af169c)) by @AliMD
|
|
62
|
+
* update ([e8f8281](https://github.com/Alwatr/flux/commit/e8f8281beb24988466c6e29f724a963118870933)) by @AliMD
|
|
63
|
+
|
|
64
|
+
## [2.0.5](https://github.com/Alwatr/flux/compare/@alwatr/fsm@2.0.4...@alwatr/fsm@2.0.5) (2023-12-19)
|
|
65
|
+
|
|
66
|
+
**Note:** Version bump only for package @alwatr/fsm
|
|
67
|
+
|
|
68
|
+
## [2.0.4](https://github.com/Alwatr/flux/compare/@alwatr/fsm@2.0.2...@alwatr/fsm@2.0.4) (2023-12-19)
|
|
7
69
|
|
|
8
70
|
**Note:** Version bump only for package @alwatr/fsm
|
|
9
71
|
|
|
10
|
-
## [2.0.3](https://github.com/Alwatr/
|
|
72
|
+
## [2.0.3](https://github.com/Alwatr/flux/compare/@alwatr/fsm@2.0.2...@alwatr/fsm@2.0.3) (2023-11-09)
|
|
11
73
|
|
|
12
74
|
**Note:** Version bump only for package @alwatr/fsm
|
|
13
75
|
|
|
14
|
-
## [2.0.2](https://github.com/
|
|
76
|
+
## [2.0.2](https://github.com/Alwatr/flux/compare/@alwatr/fsm@2.0.1...@alwatr/fsm@2.0.2) (2023-11-01)
|
|
15
77
|
|
|
16
78
|
**Note:** Version bump only for package @alwatr/fsm
|
|
17
79
|
|
|
18
|
-
## [2.0.1](https://github.com/
|
|
80
|
+
## [2.0.1](https://github.com/Alwatr/flux/compare/@alwatr/fsm@2.0.0...@alwatr/fsm@2.0.1) (2023-10-23)
|
|
19
81
|
|
|
20
82
|
### Bug Fixes
|
|
21
83
|
|
|
22
|
-
- **fsm:** compatible with new logger api ([77db656](https://github.com/
|
|
84
|
+
- **fsm:** compatible with new logger api ([77db656](https://github.com/Alwatr/flux/commit/77db656d8b261da29376cf6dba7b9d4c35deeae8)) by @
|
|
23
85
|
|
|
24
86
|
# 2.0.0 (2023-09-19)
|
|
25
87
|
|
|
26
88
|
### Bug Fixes
|
|
27
89
|
|
|
28
|
-
- all new repo path and packages dependencies ([21a6afa](https://github.com/
|
|
29
|
-
- cleanup old signal and fsm v1 ([bde0bea](https://github.com/
|
|
30
|
-
- **fsm:** import issue ([9674f34](https://github.com/
|
|
31
|
-
- ts refrence path ([c2baa44](https://github.com/
|
|
90
|
+
- all new repo path and packages dependencies ([21a6afa](https://github.com/Alwatr/flux/commit/21a6afa0badafe4051617d9a9e3bbfbaabd0c4ad)) by @AliMD
|
|
91
|
+
- cleanup old signal and fsm v1 ([bde0bea](https://github.com/Alwatr/flux/commit/bde0bea06a6750bebad49a127b75b57fd5e55ddd)) by @AliMD
|
|
92
|
+
- **fsm:** import issue ([9674f34](https://github.com/Alwatr/flux/commit/9674f34a7c63137fb9597d2b465b4fb123c963c1)) by @AliMD
|
|
93
|
+
- ts refrence path ([c2baa44](https://github.com/Alwatr/flux/commit/c2baa44999c72a0015481fc8fea25439329c3f37)) by @AliMD
|
|
32
94
|
|
|
33
|
-
## [1.1.2](https://github.com/
|
|
95
|
+
## [1.1.2](https://github.com/Alwatr/flux/compare/@alwatr/fsm@1.1.1...@alwatr/fsm@1.1.2) (2023-09-12)
|
|
34
96
|
|
|
35
97
|
**Note:** Version bump only for package @alwatr/fsm
|
|
36
98
|
|
|
37
|
-
## [1.1.1](https://github.com/
|
|
99
|
+
## [1.1.1](https://github.com/Alwatr/flux/compare/@alwatr/fsm@1.1.0...@alwatr/fsm@1.1.1) (2023-09-12)
|
|
38
100
|
|
|
39
101
|
**Note:** Version bump only for package @alwatr/fsm
|
|
40
102
|
|
|
@@ -48,96 +110,96 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
48
110
|
|
|
49
111
|
### Bug Fixes
|
|
50
112
|
|
|
51
|
-
- **fms:** import path ([f6770a0](https://github.com/
|
|
52
|
-
- **fsm:** action maybe async ([50efffa](https://github.com/
|
|
53
|
-
- **fsm:** autoSignalUnsubscribe type ([f7db30b](https://github.com/
|
|
54
|
-
- **fsm:** call render states function in there own this ([a950478](https://github.com/
|
|
55
|
-
- **fsm:** fix order of `initFsmInstance` args ([3b60138](https://github.com/
|
|
56
|
-
- **fsm:** initial exec actions ([e7dd5c8](https://github.com/
|
|
57
|
-
- **fsm:** last reported bugs in set state ([e7435c8](https://github.com/
|
|
58
|
-
- **fsm:** review reset process ([af6e81c](https://github.com/
|
|
59
|
-
- **fsm:** run init entry actions ([777ae45](https://github.com/
|
|
60
|
-
- new logger api ([9d83a7d](https://github.com/
|
|
113
|
+
- **fms:** import path ([f6770a0](https://github.com/Alwatr/flux/commit/f6770a07fdf6855ccd63a85822d44d5ef9c72dee))
|
|
114
|
+
- **fsm:** action maybe async ([50efffa](https://github.com/Alwatr/flux/commit/50efffa34a2ea5a3515561d7425da0c109631f36))
|
|
115
|
+
- **fsm:** autoSignalUnsubscribe type ([f7db30b](https://github.com/Alwatr/flux/commit/f7db30bf5a90ff3d163f036b313a412a5149ff2b))
|
|
116
|
+
- **fsm:** call render states function in there own this ([a950478](https://github.com/Alwatr/flux/commit/a95047811366e375785b2cd8fb176b1176638cab))
|
|
117
|
+
- **fsm:** fix order of `initFsmInstance` args ([3b60138](https://github.com/Alwatr/flux/commit/3b60138ecebcbcb4d732e4d1a3e79f5b8661ae47))
|
|
118
|
+
- **fsm:** initial exec actions ([e7dd5c8](https://github.com/Alwatr/flux/commit/e7dd5c8aaf9760c9856e4392cc899020f7e796d9))
|
|
119
|
+
- **fsm:** last reported bugs in set state ([e7435c8](https://github.com/Alwatr/flux/commit/e7435c870a054b0ec3e4004f13c6db7610610be0))
|
|
120
|
+
- **fsm:** review reset process ([af6e81c](https://github.com/Alwatr/flux/commit/af6e81c068b467d8b3aa96f2431e13ac479f018c))
|
|
121
|
+
- **fsm:** run init entry actions ([777ae45](https://github.com/Alwatr/flux/commit/777ae459f2b77f79696daf3a0ca355d6d78e57d3))
|
|
122
|
+
- new logger api ([9d83a7d](https://github.com/Alwatr/flux/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
61
123
|
|
|
62
124
|
### Features
|
|
63
125
|
|
|
64
|
-
- **fsm:** add `signalRecord` to config ([1a35291](https://github.com/
|
|
65
|
-
- **fsm:** add unsubscribe ([85ed3c3](https://github.com/
|
|
66
|
-
- **fsm:** callback in provider signals ([772818b](https://github.com/
|
|
67
|
-
- **fsm:** custom signal callback ([47c22e9](https://github.com/
|
|
68
|
-
- **fsm:** destroy and expire api ([e1a1c15](https://github.com/
|
|
69
|
-
- **fsm:** new types ([2866e3b](https://github.com/
|
|
70
|
-
- **fsm:** rewrite state machine ([7f24695](https://github.com/
|
|
71
|
-
- **fsm:** subscribe ([2af4f44](https://github.com/
|
|
126
|
+
- **fsm:** add `signalRecord` to config ([1a35291](https://github.com/Alwatr/flux/commit/1a352915fba978da141513517655d1e07350c3ec))
|
|
127
|
+
- **fsm:** add unsubscribe ([85ed3c3](https://github.com/Alwatr/flux/commit/85ed3c3439e1f40c2760f6011df112242f10be06))
|
|
128
|
+
- **fsm:** callback in provider signals ([772818b](https://github.com/Alwatr/flux/commit/772818baa7953b6fbb4d4128fcee76733f42cc2d))
|
|
129
|
+
- **fsm:** custom signal callback ([47c22e9](https://github.com/Alwatr/flux/commit/47c22e92a8a8085148b44b316d649b695ff8071a))
|
|
130
|
+
- **fsm:** destroy and expire api ([e1a1c15](https://github.com/Alwatr/flux/commit/e1a1c150d81f4428718bd18f039235c7fce9caf2))
|
|
131
|
+
- **fsm:** new types ([2866e3b](https://github.com/Alwatr/flux/commit/2866e3bd5ff56fd2b5bddcaed3673a5868bae4bb))
|
|
132
|
+
- **fsm:** rewrite state machine ([7f24695](https://github.com/Alwatr/flux/commit/7f246959e5a80b21c1c4b21e895e75f8fbe56798))
|
|
133
|
+
- **fsm:** subscribe ([2af4f44](https://github.com/Alwatr/flux/commit/2af4f44f0e8a2dee39cde10dcaa3281075632e6a))
|
|
72
134
|
|
|
73
135
|
# 0.30.0 (2023-03-06)
|
|
74
136
|
|
|
75
137
|
### Bug Fixes
|
|
76
138
|
|
|
77
|
-
- **fsm:** every signal mather ([0dc504d](https://github.com/
|
|
78
|
-
- **fsm:** remove additional import ([231337b](https://github.com/
|
|
79
|
-
- **fsm:** update context in transition bug ([28a21d0](https://github.com/
|
|
139
|
+
- **fsm:** every signal mather ([0dc504d](https://github.com/Alwatr/flux/commit/0dc504dacbb1ec68f154244619d644ff8e43cc04))
|
|
140
|
+
- **fsm:** remove additional import ([231337b](https://github.com/Alwatr/flux/commit/231337b95ee7b046fe35429f50931ddf85be291f))
|
|
141
|
+
- **fsm:** update context in transition bug ([28a21d0](https://github.com/Alwatr/flux/commit/28a21d00d903b6189d814303c72ba6e784852f33))
|
|
80
142
|
|
|
81
143
|
### Features
|
|
82
144
|
|
|
83
|
-
- Alwatr Finite State Machines ([d5900b4](https://github.com/
|
|
84
|
-
- **fsm:** $all and $self state ([69adf41](https://github.com/
|
|
85
|
-
- **fsm:** enhance types ([3b13046](https://github.com/
|
|
86
|
-
- **fsm:** make simple state machine ([ff9ae1c](https://github.com/
|
|
87
|
-
- **fsm:** new state context type with {to, from, by} ([11423e6](https://github.com/
|
|
88
|
-
- **fsm:** rewrite with signal power ([01a1651](https://github.com/
|
|
89
|
-
- **fsm:** share state events ([de42522](https://github.com/
|
|
90
|
-
- **fsm:** transition with partial context set ([823377e](https://github.com/
|
|
145
|
+
- Alwatr Finite State Machines ([d5900b4](https://github.com/Alwatr/flux/commit/d5900b4ee8685b120188888871405853f5a69417))
|
|
146
|
+
- **fsm:** $all and $self state ([69adf41](https://github.com/Alwatr/flux/commit/69adf41064ca0f55497484c50e298ebc26c42dcc))
|
|
147
|
+
- **fsm:** enhance types ([3b13046](https://github.com/Alwatr/flux/commit/3b130463a102f59c38603b0de470be5c87ee88c9))
|
|
148
|
+
- **fsm:** make simple state machine ([ff9ae1c](https://github.com/Alwatr/flux/commit/ff9ae1ca04156e8b811899ff0f62480e1c37af72))
|
|
149
|
+
- **fsm:** new state context type with {to, from, by} ([11423e6](https://github.com/Alwatr/flux/commit/11423e6a89159b92e82cfd1e774ad37983581090))
|
|
150
|
+
- **fsm:** rewrite with signal power ([01a1651](https://github.com/Alwatr/flux/commit/01a1651e231a817d5eebb54cf84d51d620bfd6e8))
|
|
151
|
+
- **fsm:** share state events ([de42522](https://github.com/Alwatr/flux/commit/de42522a97fdf6be8bee73d91a35820e2a5e6efb))
|
|
152
|
+
- **fsm:** transition with partial context set ([823377e](https://github.com/Alwatr/flux/commit/823377e65028ea3e713f060ae678776c609c1661))
|
|
91
153
|
|
|
92
|
-
# [1.0.0](https://github.com/
|
|
154
|
+
# [1.0.0](https://github.com/Alwatr/flux/compare/v0.32.0...v1.0.0) (2023-06-14)
|
|
93
155
|
|
|
94
156
|
**Note:** Version bump only for package @alwatr/fsm
|
|
95
157
|
|
|
96
|
-
# [0.32.0](https://github.com/
|
|
158
|
+
# [0.32.0](https://github.com/Alwatr/flux/compare/v0.31.0...v0.32.0) (2023-05-27)
|
|
97
159
|
|
|
98
160
|
**Note:** Version bump only for package @alwatr/fsm
|
|
99
161
|
|
|
100
|
-
# [0.31.0](https://github.com/
|
|
162
|
+
# [0.31.0](https://github.com/Alwatr/flux/compare/v0.30.0...v0.31.0) (2023-05-08)
|
|
101
163
|
|
|
102
164
|
### Bug Fixes
|
|
103
165
|
|
|
104
|
-
- **fms:** import path ([f6770a0](https://github.com/
|
|
105
|
-
- **fsm:** action maybe async ([50efffa](https://github.com/
|
|
106
|
-
- **fsm:** autoSignalUnsubscribe type ([f7db30b](https://github.com/
|
|
107
|
-
- **fsm:** call render states function in there own this ([a950478](https://github.com/
|
|
108
|
-
- **fsm:** fix order of `initFsmInstance` args ([3b60138](https://github.com/
|
|
109
|
-
- **fsm:** initial exec actions ([e7dd5c8](https://github.com/
|
|
110
|
-
- **fsm:** last reported bugs in set state ([e7435c8](https://github.com/
|
|
111
|
-
- **fsm:** review reset process ([af6e81c](https://github.com/
|
|
112
|
-
- **fsm:** run init entry actions ([777ae45](https://github.com/
|
|
113
|
-
- new logger api ([9d83a7d](https://github.com/
|
|
166
|
+
- **fms:** import path ([f6770a0](https://github.com/Alwatr/flux/commit/f6770a07fdf6855ccd63a85822d44d5ef9c72dee))
|
|
167
|
+
- **fsm:** action maybe async ([50efffa](https://github.com/Alwatr/flux/commit/50efffa34a2ea5a3515561d7425da0c109631f36))
|
|
168
|
+
- **fsm:** autoSignalUnsubscribe type ([f7db30b](https://github.com/Alwatr/flux/commit/f7db30bf5a90ff3d163f036b313a412a5149ff2b))
|
|
169
|
+
- **fsm:** call render states function in there own this ([a950478](https://github.com/Alwatr/flux/commit/a95047811366e375785b2cd8fb176b1176638cab))
|
|
170
|
+
- **fsm:** fix order of `initFsmInstance` args ([3b60138](https://github.com/Alwatr/flux/commit/3b60138ecebcbcb4d732e4d1a3e79f5b8661ae47))
|
|
171
|
+
- **fsm:** initial exec actions ([e7dd5c8](https://github.com/Alwatr/flux/commit/e7dd5c8aaf9760c9856e4392cc899020f7e796d9))
|
|
172
|
+
- **fsm:** last reported bugs in set state ([e7435c8](https://github.com/Alwatr/flux/commit/e7435c870a054b0ec3e4004f13c6db7610610be0))
|
|
173
|
+
- **fsm:** review reset process ([af6e81c](https://github.com/Alwatr/flux/commit/af6e81c068b467d8b3aa96f2431e13ac479f018c))
|
|
174
|
+
- **fsm:** run init entry actions ([777ae45](https://github.com/Alwatr/flux/commit/777ae459f2b77f79696daf3a0ca355d6d78e57d3))
|
|
175
|
+
- new logger api ([9d83a7d](https://github.com/Alwatr/flux/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
114
176
|
|
|
115
177
|
### Features
|
|
116
178
|
|
|
117
|
-
- **fsm:** add `signalRecord` to config ([1a35291](https://github.com/
|
|
118
|
-
- **fsm:** add unsubscribe ([85ed3c3](https://github.com/
|
|
119
|
-
- **fsm:** callback in provider signals ([772818b](https://github.com/
|
|
120
|
-
- **fsm:** custom signal callback ([47c22e9](https://github.com/
|
|
121
|
-
- **fsm:** destroy and expire api ([e1a1c15](https://github.com/
|
|
122
|
-
- **fsm:** new types ([2866e3b](https://github.com/
|
|
123
|
-
- **fsm:** rewrite state machine ([7f24695](https://github.com/
|
|
124
|
-
- **fsm:** subscribe ([2af4f44](https://github.com/
|
|
179
|
+
- **fsm:** add `signalRecord` to config ([1a35291](https://github.com/Alwatr/flux/commit/1a352915fba978da141513517655d1e07350c3ec))
|
|
180
|
+
- **fsm:** add unsubscribe ([85ed3c3](https://github.com/Alwatr/flux/commit/85ed3c3439e1f40c2760f6011df112242f10be06))
|
|
181
|
+
- **fsm:** callback in provider signals ([772818b](https://github.com/Alwatr/flux/commit/772818baa7953b6fbb4d4128fcee76733f42cc2d))
|
|
182
|
+
- **fsm:** custom signal callback ([47c22e9](https://github.com/Alwatr/flux/commit/47c22e92a8a8085148b44b316d649b695ff8071a))
|
|
183
|
+
- **fsm:** destroy and expire api ([e1a1c15](https://github.com/Alwatr/flux/commit/e1a1c150d81f4428718bd18f039235c7fce9caf2))
|
|
184
|
+
- **fsm:** new types ([2866e3b](https://github.com/Alwatr/flux/commit/2866e3bd5ff56fd2b5bddcaed3673a5868bae4bb))
|
|
185
|
+
- **fsm:** rewrite state machine ([7f24695](https://github.com/Alwatr/flux/commit/7f246959e5a80b21c1c4b21e895e75f8fbe56798))
|
|
186
|
+
- **fsm:** subscribe ([2af4f44](https://github.com/Alwatr/flux/commit/2af4f44f0e8a2dee39cde10dcaa3281075632e6a))
|
|
125
187
|
|
|
126
|
-
# [0.30.0](https://github.com/
|
|
188
|
+
# [0.30.0](https://github.com/Alwatr/flux/compare/v0.29.0...v0.30.0) (2023-03-06)
|
|
127
189
|
|
|
128
190
|
### Bug Fixes
|
|
129
191
|
|
|
130
|
-
- **fsm:** every signal mather ([0dc504d](https://github.com/
|
|
131
|
-
- **fsm:** remove additional import ([231337b](https://github.com/
|
|
132
|
-
- **fsm:** update context in transition bug ([28a21d0](https://github.com/
|
|
192
|
+
- **fsm:** every signal mather ([0dc504d](https://github.com/Alwatr/flux/commit/0dc504dacbb1ec68f154244619d644ff8e43cc04))
|
|
193
|
+
- **fsm:** remove additional import ([231337b](https://github.com/Alwatr/flux/commit/231337b95ee7b046fe35429f50931ddf85be291f))
|
|
194
|
+
- **fsm:** update context in transition bug ([28a21d0](https://github.com/Alwatr/flux/commit/28a21d00d903b6189d814303c72ba6e784852f33))
|
|
133
195
|
|
|
134
196
|
### Features
|
|
135
197
|
|
|
136
|
-
- Alwatr Finite State Machines ([d5900b4](https://github.com/
|
|
137
|
-
- **fsm:** $all and $self state ([69adf41](https://github.com/
|
|
138
|
-
- **fsm:** enhance types ([3b13046](https://github.com/
|
|
139
|
-
- **fsm:** make simple state machine ([ff9ae1c](https://github.com/
|
|
140
|
-
- **fsm:** new state context type with {to, from, by} ([11423e6](https://github.com/
|
|
141
|
-
- **fsm:** rewrite with signal power ([01a1651](https://github.com/
|
|
142
|
-
- **fsm:** share state events ([de42522](https://github.com/
|
|
143
|
-
- **fsm:** transition with partial context set ([823377e](https://github.com/
|
|
198
|
+
- Alwatr Finite State Machines ([d5900b4](https://github.com/Alwatr/flux/commit/d5900b4ee8685b120188888871405853f5a69417))
|
|
199
|
+
- **fsm:** $all and $self state ([69adf41](https://github.com/Alwatr/flux/commit/69adf41064ca0f55497484c50e298ebc26c42dcc))
|
|
200
|
+
- **fsm:** enhance types ([3b13046](https://github.com/Alwatr/flux/commit/3b130463a102f59c38603b0de470be5c87ee88c9))
|
|
201
|
+
- **fsm:** make simple state machine ([ff9ae1c](https://github.com/Alwatr/flux/commit/ff9ae1ca04156e8b811899ff0f62480e1c37af72))
|
|
202
|
+
- **fsm:** new state context type with {to, from, by} ([11423e6](https://github.com/Alwatr/flux/commit/11423e6a89159b92e82cfd1e774ad37983581090))
|
|
203
|
+
- **fsm:** rewrite with signal power ([01a1651](https://github.com/Alwatr/flux/commit/01a1651e231a817d5eebb54cf84d51d620bfd6e8))
|
|
204
|
+
- **fsm:** share state events ([de42522](https://github.com/Alwatr/flux/commit/de42522a97fdf6be8bee73d91a35820e2a5e6efb))
|
|
205
|
+
- **fsm:** transition with partial context set ([823377e](https://github.com/Alwatr/flux/commit/823377e65028ea3e713f060ae678776c609c1661))
|
package/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alwatr/fsm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A robust TypeScript library for implementing Flux (Finite) State Machines, enabling clear and organized management of application state and transitions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* **Clear State Management:** Model your application's behavior with well-defined states and transitions.
|
|
8
|
+
* **TypeScript Support:** Written in TypeScript with full type definitions for improved code quality and developer experience.
|
|
9
|
+
* **Flexible Actions:** Attach custom actions to state transitions and events.
|
|
10
|
+
* **Observable Integration:** Built-in integration with `@alwatr/observable` for reactive state updates.
|
|
11
|
+
* **Built-in Logging:** Integrated logging for debugging and monitoring state machine behavior.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @alwatr/fsm
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import {FluxStateMachineBase} from '@alwatr/fsm';
|
|
23
|
+
|
|
24
|
+
// Define your states and events
|
|
25
|
+
type MyState = 'idle' | 'loading' | 'success' | 'error';
|
|
26
|
+
type MyEvent = 'fetch' | 'success' | 'error';
|
|
27
|
+
|
|
28
|
+
class MyStateMachine extends FluxStateMachineBase<MyState, MyEvent> {
|
|
29
|
+
constructor() {
|
|
30
|
+
super({
|
|
31
|
+
name: 'my-state-machine',
|
|
32
|
+
initialState: 'idle',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Define state transitions
|
|
36
|
+
this.stateRecord_ = {
|
|
37
|
+
idle: {
|
|
38
|
+
fetch: 'loading',
|
|
39
|
+
},
|
|
40
|
+
loading: {
|
|
41
|
+
success: 'success',
|
|
42
|
+
error: 'error',
|
|
43
|
+
},
|
|
44
|
+
success: {}, // Terminal state
|
|
45
|
+
error: {}, // Terminal state
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Define actions (optional)
|
|
49
|
+
this.actionRecord_ = {
|
|
50
|
+
'_on_fetch': this.handleFetch,
|
|
51
|
+
'_on_success': this.handleSuccess,
|
|
52
|
+
'_on_error': this.handleError,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ... (Implement your action methods: handleFetch, handleSuccess, handleError)
|
|
57
|
+
|
|
58
|
+
// Trigger a state transition
|
|
59
|
+
fetchData() {
|
|
60
|
+
this.transition_('fetch');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
### `FluxStateMachineBase<S extends string, E extends string>`
|
|
68
|
+
|
|
69
|
+
* **`constructor(config: {name: string; loggerPrefix?: string; initialState: S})`:**
|
|
70
|
+
* `config.name`: The name of the state machine (used for logging).
|
|
71
|
+
* `config.loggerPrefix`: Optional prefix for log messages.
|
|
72
|
+
* `config.initialState`: The initial state of the machine.
|
|
73
|
+
|
|
74
|
+
* **`stateRecord_: StateRecord<S, E>`:** Defines the states and their possible transitions based on events.
|
|
75
|
+
|
|
76
|
+
* **`actionRecord_: ActionRecord<S, E>`:** Binds action names to class methods for execution during transitions.
|
|
77
|
+
|
|
78
|
+
* **`transition_(event: E)`:** Triggers a state transition based on the provided event.
|
|
79
|
+
|
|
80
|
+
* **`shouldTransition_(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean>`:** (Optional) Allows you to define custom conditions for transitions.
|
|
81
|
+
|
|
82
|
+
* **`postTransition__(eventDetail: StateEventDetail<S, E>)`:** Executes actions associated with state transitions and events.
|
|
83
|
+
|
|
84
|
+
* **`execAction__(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>)`:** Executes a specific action if defined in the `actionRecord_`.
|
|
85
|
+
|
|
86
|
+
* **`resetToInitialState_()`:** Resets the machine to its initial state without notifying subscribers.
|
|
87
|
+
|
|
88
|
+
## Contributing
|
|
89
|
+
|
|
90
|
+
Contributions are welcome! Please read the contributing guidelines before submitting a pull request.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AlwatrObservable, type AlwatrObservableConfig } from '@alwatr/observable';
|
|
2
|
+
import '@alwatr/polyfill-has-own';
|
|
3
|
+
import type { ActionRecord, StateEventDetail, StateRecord } from './type.js';
|
|
4
|
+
import type { MaybePromise } from '@alwatr/type-helper';
|
|
5
|
+
export interface AlwatrFluxStateMachineConfig<S extends string> extends AlwatrObservableConfig {
|
|
6
|
+
initialState: S;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Flux (Finite) State Machine Base Class
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class AlwatrFluxStateMachineBase<S extends string, E extends string> extends AlwatrObservable<{
|
|
12
|
+
state: S;
|
|
13
|
+
}> {
|
|
14
|
+
/**
|
|
15
|
+
* States and transitions config.
|
|
16
|
+
*/
|
|
17
|
+
protected stateRecord_: StateRecord<S, E>;
|
|
18
|
+
/**
|
|
19
|
+
* Bind actions name to class methods
|
|
20
|
+
*/
|
|
21
|
+
protected actionRecord_: ActionRecord<S, E>;
|
|
22
|
+
protected initialState_: S;
|
|
23
|
+
protected message_: {
|
|
24
|
+
state: S;
|
|
25
|
+
};
|
|
26
|
+
constructor(config: AlwatrFluxStateMachineConfig<S>);
|
|
27
|
+
/**
|
|
28
|
+
* Reset machine to initial state without notify.
|
|
29
|
+
*/
|
|
30
|
+
protected resetToInitialState_(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Transition condition.
|
|
33
|
+
*/
|
|
34
|
+
protected shouldTransition_(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Transition flux state machine instance to new state.
|
|
37
|
+
*/
|
|
38
|
+
protected transition_(event: E): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Execute all actions for current state.
|
|
41
|
+
*/
|
|
42
|
+
private postTransition__;
|
|
43
|
+
/**
|
|
44
|
+
* Execute action name if defined in _actionRecord.
|
|
45
|
+
*/
|
|
46
|
+
private execAction__;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAE,KAAK,sBAAsB,EAAC,MAAM,oBAAoB,CAAC;AACjF,OAAO,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAa,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AAEvF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAItD,MAAM,WAAW,4BAA4B,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,sBAAsB;IAC5F,YAAY,EAAE,CAAC,CAAC;CACjB;AAGD;;GAEG;AACH,8BAAsB,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,gBAAgB,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAC,CAAC;IACvH;;OAEG;IACH,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAM;IAE/C;;OAEG;IACH,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAM;IAEjD,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IAE3B,UAAmB,QAAQ,EAAE;QAAC,KAAK,EAAE,CAAC,CAAA;KAAC,CAAC;gBAE5B,MAAM,EAAE,4BAA4B,CAAC,CAAC,CAAC;IAMnD;;OAEG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAKtC;;OAEG;IACH,SAAS,CAAC,iBAAiB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC;IAKxF;;OAEG;cACa,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBpD;;OAEG;YACW,gBAAgB;IAqB9B;;OAEG;IACH,OAAO,CAAC,YAAY;CAOrB"}
|
package/dist/fsm.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AlwatrFluxStateMachineBase } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flux (Finite) State Machine Base Class
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class AlwatrFluxStateMachine<S extends string, E extends string> extends AlwatrFluxStateMachineBase<S, E> {
|
|
6
|
+
/**
|
|
7
|
+
* Current state.
|
|
8
|
+
*/
|
|
9
|
+
get state(): S;
|
|
10
|
+
/**
|
|
11
|
+
* Transition flux state machine instance to new state.
|
|
12
|
+
*/
|
|
13
|
+
transition(event: E): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=fsm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsm.d.ts","sourceRoot":"","sources":["../src/fsm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAErD;;GAEG;AACH,8BAAsB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC;IACvH;;OAEG;IACH,IAAI,KAAK,IAAI,CAAC,CAEb;IAED;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;CAG3B"}
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @alwatr/fsm v3.0.0 */
|
|
2
|
+
"use strict";var a=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var g=(r,o)=>{for(var t in o)a(r,t,{get:o[t],enumerable:!0})},S=(r,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of l(o))!m.call(r,e)&&e!==t&&a(r,e,{get:()=>o[e],enumerable:!(i=h(o,e))||i.enumerable});return r};var p=r=>S(a({},"__esModule",{value:!0}),r);var f={};g(f,{AlwatrFluxStateMachine:()=>n,AlwatrFluxStateMachineBase:()=>s});module.exports=p(f);var d=require("@alwatr/logger"),c=require("@alwatr/observable"),u=require("@alwatr/polyfill-has-own");(0,d.definePackage)("@alwatr/fsm","3.0.0");var s=class extends c.AlwatrObservable{constructor(t){t.loggerPrefix??(t.loggerPrefix="flux-state-machine");super(t);this.stateRecord_={};this.actionRecord_={};this.message_={state:this.initialState_=t.initialState}}resetToInitialState_(){this.logger_.logMethod?.("resetToInitialState_"),this.message_={state:this.initialState_}}shouldTransition_(t){return this.logger_.logMethodFull?.("shouldTransition_",t,!0),!0}async transition_(t){let i=this.message_.state,e=this.stateRecord_[i]?.[t]??this.stateRecord_._all?.[t];if(this.logger_.logMethodArgs?.("transition_",{fromState:i,event:t,toState:e}),e==null){this.logger_.incident?.("transition","invalid_target_state",{fromState:i,event:t});return}let _={from:i,event:t,to:e};await this.shouldTransition_(_)===!0&&(this.notify_({state:e}),this.e(_))}async e(t){this.logger_.logMethodArgs?.("_transitioned",t),await this.t(`_on_${t.event}`,t),t.from!==t.to&&(await this.t("_on_state_exit",t),await this.t(`_on_${t.from}_exit`,t),await this.t("_on_state_enter",t),await this.t(`_on_${t.to}_enter`,t)),Object.hasOwn(this,`_on_${t.from}_${t.event}`)?this.t(`_on_${t.from}_${t.event}`,t):this.t(`_on_all_${t.event}`,t)}t(t,i){let e=this.actionRecord_[t];if(typeof e=="function")return this.logger_.logMethodArgs?.("_$execAction",t),e.call(this,i)}};var n=class extends s{get state(){return this.message_.state}transition(o){this.transition_(o)}};0&&(module.exports={AlwatrFluxStateMachine,AlwatrFluxStateMachineBase});
|
|
3
|
+
//# sourceMappingURL=main.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/main.ts", "../src/base.ts", "../src/fsm.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './base.js';\nexport * from './fsm.js';\nexport * from './type.js';\n", "import {definePackage} from '@alwatr/logger';\nimport {AlwatrObservable, type AlwatrObservableConfig} from '@alwatr/observable';\nimport '@alwatr/polyfill-has-own';\n\nimport type {ActionName, ActionRecord, StateEventDetail, StateRecord} from './type.js';\nimport type {} from '@alwatr/nano-build';\nimport type {MaybePromise} from '@alwatr/type-helper';\n\ndefinePackage('@alwatr/fsm', __package_version__);\n\nexport interface AlwatrFluxStateMachineConfig<S extends string> extends AlwatrObservableConfig {\n initialState: S;\n}\n\n\n/**\n * Flux (Finite) State Machine Base Class\n */\nexport abstract class AlwatrFluxStateMachineBase<S extends string, E extends string> extends AlwatrObservable<{state: S}> {\n /**\n * States and transitions config.\n */\n protected stateRecord_: StateRecord<S, E> = {};\n\n /**\n * Bind actions name to class methods\n */\n protected actionRecord_: ActionRecord<S, E> = {};\n\n protected initialState_: S;\n\n protected override message_: {state: S};\n\n constructor(config: AlwatrFluxStateMachineConfig<S>) {\n config.loggerPrefix ??= 'flux-state-machine';\n super(config);\n this.message_ = {state: this.initialState_ = config.initialState};\n }\n\n /**\n * Reset machine to initial state without notify.\n */\n protected resetToInitialState_(): void {\n this.logger_.logMethod?.('resetToInitialState_');\n this.message_ = {state: this.initialState_};\n }\n\n /**\n * Transition condition.\n */\n protected shouldTransition_(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean> {\n this.logger_.logMethodFull?.('shouldTransition_', _eventDetail, true);\n return true;\n }\n\n /**\n * Transition flux state machine instance to new state.\n */\n protected async transition_(event: E): Promise<void> {\n const fromState = this.message_.state;\n const toState = this.stateRecord_[fromState]?.[event] ?? this.stateRecord_._all?.[event];\n\n this.logger_.logMethodArgs?.('transition_', {fromState, event, toState});\n\n if (toState == null) {\n this.logger_.incident?.('transition', 'invalid_target_state', {\n fromState,\n event,\n });\n return;\n }\n\n const eventDetail: StateEventDetail<S, E> = {from: fromState, event, to: toState};\n\n if ((await this.shouldTransition_(eventDetail)) !== true) return;\n\n this.notify_({state: toState});\n\n this.postTransition__(eventDetail);\n }\n\n /**\n * Execute all actions for current state.\n */\n private async postTransition__(eventDetail: StateEventDetail<S, E>): Promise<void> {\n this.logger_.logMethodArgs?.('_transitioned', eventDetail);\n\n await this.execAction__(`_on_${eventDetail.event}`, eventDetail);\n\n if (eventDetail.from !== eventDetail.to) {\n await this.execAction__(`_on_state_exit`, eventDetail);\n await this.execAction__(`_on_${eventDetail.from}_exit`, eventDetail);\n await this.execAction__(`_on_state_enter`, eventDetail);\n await this.execAction__(`_on_${eventDetail.to}_enter`, eventDetail);\n }\n\n if (Object.hasOwn(this, `_on_${eventDetail.from}_${eventDetail.event}`)) {\n this.execAction__(`_on_${eventDetail.from}_${eventDetail.event}`, eventDetail);\n }\n else {\n // The action `all_eventName` is executed only if the action `fromState_eventName` is not defined.\n this.execAction__(`_on_all_${eventDetail.event}`, eventDetail);\n }\n }\n\n /**\n * Execute action name if defined in _actionRecord.\n */\n private execAction__(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>): MaybePromise<void> {\n const actionFn = this.actionRecord_[name];\n if (typeof actionFn === 'function') {\n this.logger_.logMethodArgs?.('_$execAction', name);\n return actionFn.call(this, eventDetail);\n }\n }\n}\n", "import {AlwatrFluxStateMachineBase} from './base.js';\n\n/**\n * Flux (Finite) State Machine Base Class\n */\nexport abstract class AlwatrFluxStateMachine<S extends string, E extends string> extends AlwatrFluxStateMachineBase<S, E> {\n /**\n * Current state.\n */\n get state(): S {\n return this.message_.state;\n }\n\n /**\n * Transition flux state machine instance to new state.\n */\n transition(event: E): void {\n this.transition_(event);\n }\n}\n"],
|
|
5
|
+
"mappings": ";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,+BAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA4B,0BAC5BC,EAA4D,8BAC5DC,EAAO,uCAMP,iBAAc,cAAe,OAAmB,EAUzC,IAAeC,EAAf,cAAsF,kBAA6B,CAexH,YAAYC,EAAyC,CACnDA,EAAO,eAAPA,EAAO,aAAiB,sBACxB,MAAMA,CAAM,EAbd,KAAU,aAAkC,CAAC,EAK7C,KAAU,cAAoC,CAAC,EAS7C,KAAK,SAAW,CAAC,MAAO,KAAK,cAAgBA,EAAO,YAAY,CAClE,CAKU,sBAA6B,CACrC,KAAK,QAAQ,YAAY,sBAAsB,EAC/C,KAAK,SAAW,CAAC,MAAO,KAAK,aAAa,CAC5C,CAKU,kBAAkBC,EAA6D,CACvF,YAAK,QAAQ,gBAAgB,oBAAqBA,EAAc,EAAI,EAC7D,EACT,CAKA,MAAgB,YAAYC,EAAyB,CACnD,IAAMC,EAAY,KAAK,SAAS,MAC1BC,EAAU,KAAK,aAAaD,CAAS,IAAID,CAAK,GAAK,KAAK,aAAa,OAAOA,CAAK,EAIvF,GAFA,KAAK,QAAQ,gBAAgB,cAAe,CAAC,UAAAC,EAAW,MAAAD,EAAO,QAAAE,CAAO,CAAC,EAEnEA,GAAW,KAAM,CACnB,KAAK,QAAQ,WAAW,aAAc,uBAAwB,CAC5D,UAAAD,EACA,MAAAD,CACF,CAAC,EACD,MACF,CAEA,IAAMG,EAAsC,CAAC,KAAMF,EAAW,MAAAD,EAAO,GAAIE,CAAO,EAE3E,MAAM,KAAK,kBAAkBC,CAAW,IAAO,KAEpD,KAAK,QAAQ,CAAC,MAAOD,CAAO,CAAC,EAE7B,KAAKE,EAAiBD,CAAW,EACnC,CAKA,MAAcC,EAAiBD,EAAoD,CACjF,KAAK,QAAQ,gBAAgB,gBAAiBA,CAAW,EAEzD,MAAM,KAAKE,EAAa,OAAOF,EAAY,KAAK,GAAIA,CAAW,EAE3DA,EAAY,OAASA,EAAY,KACnC,MAAM,KAAKE,EAAa,iBAAkBF,CAAW,EACrD,MAAM,KAAKE,EAAa,OAAOF,EAAY,IAAI,QAASA,CAAW,EACnE,MAAM,KAAKE,EAAa,kBAAmBF,CAAW,EACtD,MAAM,KAAKE,EAAa,OAAOF,EAAY,EAAE,SAAUA,CAAW,GAGhE,OAAO,OAAO,KAAM,OAAOA,EAAY,IAAI,IAAIA,EAAY,KAAK,EAAE,EACpE,KAAKE,EAAa,OAAOF,EAAY,IAAI,IAAIA,EAAY,KAAK,GAAIA,CAAW,EAI7E,KAAKE,EAAa,WAAWF,EAAY,KAAK,GAAIA,CAAW,CAEjE,CAKQE,EAAaC,EAAwBH,EAAyD,CACpG,IAAMI,EAAW,KAAK,cAAcD,CAAI,EACxC,GAAI,OAAOC,GAAa,WACtB,YAAK,QAAQ,gBAAgB,eAAgBD,CAAI,EAC1CC,EAAS,KAAK,KAAMJ,CAAW,CAE1C,CACF,EC9GO,IAAeK,EAAf,cAAkFC,CAAiC,CAIxH,IAAI,OAAW,CACb,OAAO,KAAK,SAAS,KACvB,CAKA,WAAWC,EAAgB,CACzB,KAAK,YAAYA,CAAK,CACxB,CACF",
|
|
6
|
+
"names": ["main_exports", "__export", "AlwatrFluxStateMachine", "AlwatrFluxStateMachineBase", "__toCommonJS", "import_logger", "import_observable", "import_polyfill_has_own", "AlwatrFluxStateMachineBase", "config", "_eventDetail", "event", "fromState", "toState", "eventDetail", "postTransition__", "execAction__", "name", "actionFn", "AlwatrFluxStateMachine", "AlwatrFluxStateMachineBase", "event"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @alwatr/fsm v3.0.0 */
|
|
2
|
+
import{definePackage as _}from"@alwatr/logger";import{AlwatrObservable as d}from"@alwatr/observable";import"@alwatr/polyfill-has-own";_("@alwatr/fsm","3.0.0");var r=class extends d{constructor(t){t.loggerPrefix??(t.loggerPrefix="flux-state-machine");super(t);this.stateRecord_={};this.actionRecord_={};this.message_={state:this.initialState_=t.initialState}}resetToInitialState_(){this.logger_.logMethod?.("resetToInitialState_"),this.message_={state:this.initialState_}}shouldTransition_(t){return this.logger_.logMethodFull?.("shouldTransition_",t,!0),!0}async transition_(t){let o=this.message_.state,e=this.stateRecord_[o]?.[t]??this.stateRecord_._all?.[t];if(this.logger_.logMethodArgs?.("transition_",{fromState:o,event:t,toState:e}),e==null){this.logger_.incident?.("transition","invalid_target_state",{fromState:o,event:t});return}let s={from:o,event:t,to:e};await this.shouldTransition_(s)===!0&&(this.notify_({state:e}),this.e(s))}async e(t){this.logger_.logMethodArgs?.("_transitioned",t),await this.t(`_on_${t.event}`,t),t.from!==t.to&&(await this.t("_on_state_exit",t),await this.t(`_on_${t.from}_exit`,t),await this.t("_on_state_enter",t),await this.t(`_on_${t.to}_enter`,t)),Object.hasOwn(this,`_on_${t.from}_${t.event}`)?this.t(`_on_${t.from}_${t.event}`,t):this.t(`_on_all_${t.event}`,t)}t(t,o){let e=this.actionRecord_[t];if(typeof e=="function")return this.logger_.logMethodArgs?.("_$execAction",t),e.call(this,o)}};var a=class extends r{get state(){return this.message_.state}transition(i){this.transition_(i)}};export{a as AlwatrFluxStateMachine,r as AlwatrFluxStateMachineBase};
|
|
3
|
+
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/base.ts", "../src/fsm.ts"],
|
|
4
|
+
"sourcesContent": ["import {definePackage} from '@alwatr/logger';\nimport {AlwatrObservable, type AlwatrObservableConfig} from '@alwatr/observable';\nimport '@alwatr/polyfill-has-own';\n\nimport type {ActionName, ActionRecord, StateEventDetail, StateRecord} from './type.js';\nimport type {} from '@alwatr/nano-build';\nimport type {MaybePromise} from '@alwatr/type-helper';\n\ndefinePackage('@alwatr/fsm', __package_version__);\n\nexport interface AlwatrFluxStateMachineConfig<S extends string> extends AlwatrObservableConfig {\n initialState: S;\n}\n\n\n/**\n * Flux (Finite) State Machine Base Class\n */\nexport abstract class AlwatrFluxStateMachineBase<S extends string, E extends string> extends AlwatrObservable<{state: S}> {\n /**\n * States and transitions config.\n */\n protected stateRecord_: StateRecord<S, E> = {};\n\n /**\n * Bind actions name to class methods\n */\n protected actionRecord_: ActionRecord<S, E> = {};\n\n protected initialState_: S;\n\n protected override message_: {state: S};\n\n constructor(config: AlwatrFluxStateMachineConfig<S>) {\n config.loggerPrefix ??= 'flux-state-machine';\n super(config);\n this.message_ = {state: this.initialState_ = config.initialState};\n }\n\n /**\n * Reset machine to initial state without notify.\n */\n protected resetToInitialState_(): void {\n this.logger_.logMethod?.('resetToInitialState_');\n this.message_ = {state: this.initialState_};\n }\n\n /**\n * Transition condition.\n */\n protected shouldTransition_(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean> {\n this.logger_.logMethodFull?.('shouldTransition_', _eventDetail, true);\n return true;\n }\n\n /**\n * Transition flux state machine instance to new state.\n */\n protected async transition_(event: E): Promise<void> {\n const fromState = this.message_.state;\n const toState = this.stateRecord_[fromState]?.[event] ?? this.stateRecord_._all?.[event];\n\n this.logger_.logMethodArgs?.('transition_', {fromState, event, toState});\n\n if (toState == null) {\n this.logger_.incident?.('transition', 'invalid_target_state', {\n fromState,\n event,\n });\n return;\n }\n\n const eventDetail: StateEventDetail<S, E> = {from: fromState, event, to: toState};\n\n if ((await this.shouldTransition_(eventDetail)) !== true) return;\n\n this.notify_({state: toState});\n\n this.postTransition__(eventDetail);\n }\n\n /**\n * Execute all actions for current state.\n */\n private async postTransition__(eventDetail: StateEventDetail<S, E>): Promise<void> {\n this.logger_.logMethodArgs?.('_transitioned', eventDetail);\n\n await this.execAction__(`_on_${eventDetail.event}`, eventDetail);\n\n if (eventDetail.from !== eventDetail.to) {\n await this.execAction__(`_on_state_exit`, eventDetail);\n await this.execAction__(`_on_${eventDetail.from}_exit`, eventDetail);\n await this.execAction__(`_on_state_enter`, eventDetail);\n await this.execAction__(`_on_${eventDetail.to}_enter`, eventDetail);\n }\n\n if (Object.hasOwn(this, `_on_${eventDetail.from}_${eventDetail.event}`)) {\n this.execAction__(`_on_${eventDetail.from}_${eventDetail.event}`, eventDetail);\n }\n else {\n // The action `all_eventName` is executed only if the action `fromState_eventName` is not defined.\n this.execAction__(`_on_all_${eventDetail.event}`, eventDetail);\n }\n }\n\n /**\n * Execute action name if defined in _actionRecord.\n */\n private execAction__(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>): MaybePromise<void> {\n const actionFn = this.actionRecord_[name];\n if (typeof actionFn === 'function') {\n this.logger_.logMethodArgs?.('_$execAction', name);\n return actionFn.call(this, eventDetail);\n }\n }\n}\n", "import {AlwatrFluxStateMachineBase} from './base.js';\n\n/**\n * Flux (Finite) State Machine Base Class\n */\nexport abstract class AlwatrFluxStateMachine<S extends string, E extends string> extends AlwatrFluxStateMachineBase<S, E> {\n /**\n * Current state.\n */\n get state(): S {\n return this.message_.state;\n }\n\n /**\n * Transition flux state machine instance to new state.\n */\n transition(event: E): void {\n this.transition_(event);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAQ,iBAAAA,MAAoB,iBAC5B,OAAQ,oBAAAC,MAAoD,qBAC5D,MAAO,2BAMPD,EAAc,cAAe,OAAmB,EAUzC,IAAeE,EAAf,cAAsFD,CAA6B,CAexH,YAAYE,EAAyC,CACnDA,EAAO,eAAPA,EAAO,aAAiB,sBACxB,MAAMA,CAAM,EAbd,KAAU,aAAkC,CAAC,EAK7C,KAAU,cAAoC,CAAC,EAS7C,KAAK,SAAW,CAAC,MAAO,KAAK,cAAgBA,EAAO,YAAY,CAClE,CAKU,sBAA6B,CACrC,KAAK,QAAQ,YAAY,sBAAsB,EAC/C,KAAK,SAAW,CAAC,MAAO,KAAK,aAAa,CAC5C,CAKU,kBAAkBC,EAA6D,CACvF,YAAK,QAAQ,gBAAgB,oBAAqBA,EAAc,EAAI,EAC7D,EACT,CAKA,MAAgB,YAAYC,EAAyB,CACnD,IAAMC,EAAY,KAAK,SAAS,MAC1BC,EAAU,KAAK,aAAaD,CAAS,IAAID,CAAK,GAAK,KAAK,aAAa,OAAOA,CAAK,EAIvF,GAFA,KAAK,QAAQ,gBAAgB,cAAe,CAAC,UAAAC,EAAW,MAAAD,EAAO,QAAAE,CAAO,CAAC,EAEnEA,GAAW,KAAM,CACnB,KAAK,QAAQ,WAAW,aAAc,uBAAwB,CAC5D,UAAAD,EACA,MAAAD,CACF,CAAC,EACD,MACF,CAEA,IAAMG,EAAsC,CAAC,KAAMF,EAAW,MAAAD,EAAO,GAAIE,CAAO,EAE3E,MAAM,KAAK,kBAAkBC,CAAW,IAAO,KAEpD,KAAK,QAAQ,CAAC,MAAOD,CAAO,CAAC,EAE7B,KAAKE,EAAiBD,CAAW,EACnC,CAKA,MAAcC,EAAiBD,EAAoD,CACjF,KAAK,QAAQ,gBAAgB,gBAAiBA,CAAW,EAEzD,MAAM,KAAKE,EAAa,OAAOF,EAAY,KAAK,GAAIA,CAAW,EAE3DA,EAAY,OAASA,EAAY,KACnC,MAAM,KAAKE,EAAa,iBAAkBF,CAAW,EACrD,MAAM,KAAKE,EAAa,OAAOF,EAAY,IAAI,QAASA,CAAW,EACnE,MAAM,KAAKE,EAAa,kBAAmBF,CAAW,EACtD,MAAM,KAAKE,EAAa,OAAOF,EAAY,EAAE,SAAUA,CAAW,GAGhE,OAAO,OAAO,KAAM,OAAOA,EAAY,IAAI,IAAIA,EAAY,KAAK,EAAE,EACpE,KAAKE,EAAa,OAAOF,EAAY,IAAI,IAAIA,EAAY,KAAK,GAAIA,CAAW,EAI7E,KAAKE,EAAa,WAAWF,EAAY,KAAK,GAAIA,CAAW,CAEjE,CAKQE,EAAaC,EAAwBH,EAAyD,CACpG,IAAMI,EAAW,KAAK,cAAcD,CAAI,EACxC,GAAI,OAAOC,GAAa,WACtB,YAAK,QAAQ,gBAAgB,eAAgBD,CAAI,EAC1CC,EAAS,KAAK,KAAMJ,CAAW,CAE1C,CACF,EC9GO,IAAeK,EAAf,cAAkFC,CAAiC,CAIxH,IAAI,OAAW,CACb,OAAO,KAAK,SAAS,KACvB,CAKA,WAAWC,EAAgB,CACzB,KAAK,YAAYA,CAAK,CACxB,CACF",
|
|
6
|
+
"names": ["definePackage", "AlwatrObservable", "AlwatrFluxStateMachineBase", "config", "_eventDetail", "event", "fromState", "toState", "eventDetail", "postTransition__", "execAction__", "name", "actionFn", "AlwatrFluxStateMachine", "AlwatrFluxStateMachineBase", "event"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;IACT,EAAE,EAAE,CAAC,CAAC;CACP;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;AAEtH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IACrD,OAAO,CAAC,EAAE,GACV,gBAAgB,GAChB,iBAAiB,GACjB,OAAO,CAAC,OAAO,GACf,OAAO,CAAC,QAAQ,GAChB,OAAO,CAAC,IAAI,CAAC,EAAE,GACf,WAAW,CAAC,EAAE,CAAC;AAEnB,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,46 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/fsm",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "A robust TypeScript library for implementing Flux (Finite) State Machines, enabling clear and organized management of application state and transitions.",
|
|
5
|
+
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"state",
|
|
8
|
+
"flux",
|
|
7
9
|
"finite",
|
|
8
10
|
"machine",
|
|
9
|
-
"lit",
|
|
10
|
-
"lit-element",
|
|
11
|
-
"lit-html",
|
|
12
11
|
"typescript",
|
|
13
12
|
"esm",
|
|
14
13
|
"alwatr"
|
|
15
14
|
],
|
|
16
|
-
"main": "index.js",
|
|
17
15
|
"type": "module",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"main": "./dist/main.cjs",
|
|
17
|
+
"module": "./dist/main.mjs",
|
|
18
|
+
"types": "./dist/main.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/main.d.ts",
|
|
22
|
+
"import": "./dist/main.mjs",
|
|
23
|
+
"require": "./dist/main.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
20
26
|
"license": "MIT",
|
|
21
27
|
"files": [
|
|
22
|
-
"**/*.{
|
|
28
|
+
"**/*.{js,mjs,cjs,map,d.ts,html,md}",
|
|
29
|
+
"!demo/**/*"
|
|
23
30
|
],
|
|
24
31
|
"publishConfig": {
|
|
25
32
|
"access": "public"
|
|
26
33
|
},
|
|
27
34
|
"repository": {
|
|
28
35
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/Alwatr/
|
|
36
|
+
"url": "https://github.com/Alwatr/flux",
|
|
30
37
|
"directory": "packages/fsm"
|
|
31
38
|
},
|
|
32
|
-
"homepage": "https://github.com/Alwatr/
|
|
39
|
+
"homepage": "https://github.com/Alwatr/flux/tree/next/packages/fsm#readme",
|
|
33
40
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/Alwatr/
|
|
41
|
+
"url": "https://github.com/Alwatr/flux/issues"
|
|
42
|
+
},
|
|
43
|
+
"prettier": "@alwatr/prettier-config",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"b": "yarn run build",
|
|
46
|
+
"t": "yarn run test",
|
|
47
|
+
"w": "yarn run watch",
|
|
48
|
+
"c": "yarn run clean",
|
|
49
|
+
"cb": "yarn run clean && yarn run build",
|
|
50
|
+
"d": "yarn run build:es && yarn node --enable-source-maps --trace-warnings",
|
|
51
|
+
"build": "yarn run build:ts & yarn run build:es",
|
|
52
|
+
"build:es": "nano-build --preset=module",
|
|
53
|
+
"build:ts": "tsc --build",
|
|
54
|
+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --enable-source-maps --experimental-vm-modules\" jest",
|
|
55
|
+
"watch": "yarn run watch:ts & yarn run watch:es",
|
|
56
|
+
"watch:es": "yarn run build:es --watch",
|
|
57
|
+
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput",
|
|
58
|
+
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
35
59
|
},
|
|
36
60
|
"dependencies": {
|
|
37
|
-
"@alwatr/logger": "^2.
|
|
38
|
-
"@alwatr/
|
|
39
|
-
"@alwatr/
|
|
40
|
-
"tslib": "^2.6.2"
|
|
61
|
+
"@alwatr/logger": "^3.2.13",
|
|
62
|
+
"@alwatr/observable": "^3.0.0",
|
|
63
|
+
"@alwatr/polyfill-has-own": "^1.0.9"
|
|
41
64
|
},
|
|
42
65
|
"devDependencies": {
|
|
43
|
-
"@
|
|
66
|
+
"@alwatr/nano-build": "^1.3.9",
|
|
67
|
+
"@alwatr/prettier-config": "^1.0.4",
|
|
68
|
+
"@alwatr/tsconfig-base": "^1.2.0",
|
|
69
|
+
"@alwatr/type-helper": "^1.2.6",
|
|
70
|
+
"@types/node": "^22.5.5",
|
|
71
|
+
"jest": "^29.7.0",
|
|
72
|
+
"typescript": "^5.6.2"
|
|
44
73
|
},
|
|
45
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "6c8830345d35da730c386adb047ca2cdcb3c36f0"
|
|
46
75
|
}
|
package/base.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { AlwatrObservable } from '@alwatr/signal';
|
|
2
|
-
import type { ActionName, ActionRecord, StateEventDetail, StateRecord } from './type.js';
|
|
3
|
-
import type { MaybePromise } from '@alwatr/type';
|
|
4
|
-
/**
|
|
5
|
-
* Finite State Machine Base Class
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class FiniteStateMachineBase<S extends string, E extends string> extends AlwatrObservable<S> {
|
|
8
|
-
/**
|
|
9
|
-
* Current state
|
|
10
|
-
*/
|
|
11
|
-
protected get _state(): S;
|
|
12
|
-
/**
|
|
13
|
-
* States and transitions config.
|
|
14
|
-
*/
|
|
15
|
-
protected _stateRecord: StateRecord<S, E>;
|
|
16
|
-
/**
|
|
17
|
-
* Bind actions name to class methods
|
|
18
|
-
*/
|
|
19
|
-
protected _actionRecord: ActionRecord<S, E>;
|
|
20
|
-
protected _initialState: S;
|
|
21
|
-
constructor(config: {
|
|
22
|
-
name: string;
|
|
23
|
-
loggerPrefix?: string;
|
|
24
|
-
initialState: S;
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Transition condition.
|
|
28
|
-
*/
|
|
29
|
-
protected _shouldTransition(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Transition finite state machine instance to new state.
|
|
32
|
-
*/
|
|
33
|
-
protected _transition(event: E): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Execute all actions for current state.
|
|
36
|
-
*/
|
|
37
|
-
protected _transitioned(eventDetail: StateEventDetail<S, E>): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Execute action name if defined in _actionRecord.
|
|
40
|
-
*/
|
|
41
|
-
protected _$execAction(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>): MaybePromise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Reset machine to initial state.
|
|
44
|
-
*/
|
|
45
|
-
protected _reset(): void;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=base.d.ts.map
|
package/base.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["src/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAC,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AACvF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAI/C;;GAEG;AACH,8BAAsB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC1G;;OAEG;IACH,SAAS,KAAK,MAAM,IAAI,CAAC,CAExB;IAED;;OAEG;IACH,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAM;IAE/C;;OAEG;IACH,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAM;IAEjD,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;gBAEf,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,CAAC,CAAA;KAAC;IAO1E;;OAEG;IACH,SAAS,CAAC,iBAAiB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC;IAKxF;;OAEG;cACa,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBpD;;OAEG;cACa,aAAa,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBjF;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;IAQvG;;OAEG;IACH,SAAS,CAAC,MAAM,IAAI,IAAI;CAGzB"}
|
package/base.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { definePackage } from '@alwatr/logger';
|
|
3
|
-
import { AlwatrObservable } from '@alwatr/signal';
|
|
4
|
-
definePackage('fsm', '2.x');
|
|
5
|
-
/**
|
|
6
|
-
* Finite State Machine Base Class
|
|
7
|
-
*/
|
|
8
|
-
export class FiniteStateMachineBase extends AlwatrObservable {
|
|
9
|
-
/**
|
|
10
|
-
* Current state
|
|
11
|
-
*/
|
|
12
|
-
get _state() {
|
|
13
|
-
return this._getData();
|
|
14
|
-
}
|
|
15
|
-
constructor(config) {
|
|
16
|
-
config.loggerPrefix ?? (config.loggerPrefix = 'fsm');
|
|
17
|
-
super(config);
|
|
18
|
-
/**
|
|
19
|
-
* States and transitions config.
|
|
20
|
-
*/
|
|
21
|
-
this._stateRecord = {};
|
|
22
|
-
/**
|
|
23
|
-
* Bind actions name to class methods
|
|
24
|
-
*/
|
|
25
|
-
this._actionRecord = {};
|
|
26
|
-
this._initialState = config.initialState;
|
|
27
|
-
this._reset();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Transition condition.
|
|
31
|
-
*/
|
|
32
|
-
_shouldTransition(_eventDetail) {
|
|
33
|
-
this._logger.logMethodFull?.('_shouldTransition', _eventDetail, true);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Transition finite state machine instance to new state.
|
|
38
|
-
*/
|
|
39
|
-
async _transition(event) {
|
|
40
|
-
const fromState = this._state;
|
|
41
|
-
const toState = this._stateRecord[fromState]?.[event] ?? this._stateRecord._all?.[event];
|
|
42
|
-
this._logger.logMethodArgs?.('_transition', { fromState, event, toState });
|
|
43
|
-
if (toState == null) {
|
|
44
|
-
this._logger.incident?.('transition', 'invalid_target_state', {
|
|
45
|
-
fromState,
|
|
46
|
-
event,
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const eventDetail = { from: fromState, event, to: toState };
|
|
51
|
-
if ((await this._shouldTransition(eventDetail)) !== true)
|
|
52
|
-
return;
|
|
53
|
-
this._notify(toState);
|
|
54
|
-
this._transitioned(eventDetail);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Execute all actions for current state.
|
|
58
|
-
*/
|
|
59
|
-
async _transitioned(eventDetail) {
|
|
60
|
-
this._logger.logMethodArgs?.('_transitioned', eventDetail);
|
|
61
|
-
await this._$execAction(`_on_${eventDetail.event}`, eventDetail);
|
|
62
|
-
if (eventDetail.from !== eventDetail.to) {
|
|
63
|
-
await this._$execAction(`_on_state_exit`, eventDetail);
|
|
64
|
-
await this._$execAction(`_on_${eventDetail.from}_exit`, eventDetail);
|
|
65
|
-
await this._$execAction(`_on_state_enter`, eventDetail);
|
|
66
|
-
await this._$execAction(`_on_${eventDetail.to}_enter`, eventDetail);
|
|
67
|
-
}
|
|
68
|
-
if (`_on_${eventDetail.from}_${eventDetail.event}` in this) {
|
|
69
|
-
this._$execAction(`_on_${eventDetail.from}_${eventDetail.event}`, eventDetail);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this._$execAction(`_on_all_${eventDetail.event}`, eventDetail);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Execute action name if defined in _actionRecord.
|
|
77
|
-
*/
|
|
78
|
-
_$execAction(name, eventDetail) {
|
|
79
|
-
const actionFn = this._actionRecord[name];
|
|
80
|
-
if (typeof actionFn === 'function') {
|
|
81
|
-
this._logger.logMethodArgs?.('_$execAction', name);
|
|
82
|
-
return this._actionRecord[name]?.call(this, eventDetail);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Reset machine to initial state.
|
|
87
|
-
*/
|
|
88
|
-
_reset() {
|
|
89
|
-
this._$data = this._initialState;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=base.js.map
|
package/base.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["src/base.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAKhD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,OAAgB,sBAA2D,SAAQ,gBAAmB;IAC1G;;OAEG;IACH,IAAc,MAAM;QAClB,OAAO,IAAI,CAAC,QAAQ,EAAG,CAAC;IAC1B,CAAC;IAcD,YAAY,MAA8D;QACxE,MAAM,CAAC,YAAY,KAAnB,MAAM,CAAC,YAAY,GAAK,KAAK,EAAC;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;QAdhB;;WAEG;QACO,iBAAY,GAAsB,EAAE,CAAC;QAE/C;;WAEG;QACO,kBAAa,GAAuB,EAAE,CAAC;QAO/C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED;;OAEG;IACO,iBAAiB,CAAC,YAAoC;QAC9D,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,mBAAmB,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,WAAW,CAAC,KAAQ;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;QAEzF,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,aAAa,EAAE,EAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC;QAEzE,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,YAAY,EAAE,sBAAsB,EAAE;gBAC5D,SAAS;gBACT,KAAK;aACN,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GAA2B,EAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAC,CAAC;QAElF,IAAI,CAAC,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI;YAAE,OAAO;QAEjE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEtB,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,aAAa,CAAC,WAAmC;QAC/D,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAE3D,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC,KAAK,EAAE,EAAE,WAAW,CAAC,CAAC;QAEjE,IAAI,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;YACvD,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC,IAAI,OAAO,EAAE,WAAW,CAAC,CAAC;YACrE,MAAM,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;YACxD,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,OAAO,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;YAC3D,IAAI,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,EAAE,WAAW,CAAC,CAAC;QACjF,CAAC;aACI,CAAC;YACJ,IAAI,CAAC,YAAY,CAAC,WAAW,WAAW,CAAC,KAAK,EAAE,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED;;OAEG;IACO,YAAY,CAAC,IAAsB,EAAE,WAAmC;QAChF,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;OAEG;IACO,MAAM;QACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;IACnC,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {definePackage} from '@alwatr/logger';\nimport {AlwatrObservable} from '@alwatr/signal';\n\nimport type {ActionName, ActionRecord, StateEventDetail, StateRecord} from './type.js';\nimport type {MaybePromise} from '@alwatr/type';\n\ndefinePackage('fsm', '2.x');\n\n/**\n * Finite State Machine Base Class\n */\nexport abstract class FiniteStateMachineBase<S extends string, E extends string> extends AlwatrObservable<S> {\n /**\n * Current state\n */\n protected get _state(): S {\n return this._getData()!;\n }\n\n /**\n * States and transitions config.\n */\n protected _stateRecord: StateRecord<S, E> = {};\n\n /**\n * Bind actions name to class methods\n */\n protected _actionRecord: ActionRecord<S, E> = {};\n\n protected _initialState: S;\n\n constructor(config: {name: string; loggerPrefix?: string; initialState: S}) {\n config.loggerPrefix ??= 'fsm';\n super(config);\n this._initialState = config.initialState;\n this._reset();\n }\n\n /**\n * Transition condition.\n */\n protected _shouldTransition(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean> {\n this._logger.logMethodFull?.('_shouldTransition', _eventDetail, true);\n return true;\n }\n\n /**\n * Transition finite state machine instance to new state.\n */\n protected async _transition(event: E): Promise<void> {\n const fromState = this._state;\n const toState = this._stateRecord[fromState]?.[event] ?? this._stateRecord._all?.[event];\n\n this._logger.logMethodArgs?.('_transition', {fromState, event, toState});\n\n if (toState == null) {\n this._logger.incident?.('transition', 'invalid_target_state', {\n fromState,\n event,\n });\n return;\n }\n\n const eventDetail: StateEventDetail<S, E> = {from: fromState, event, to: toState};\n\n if ((await this._shouldTransition(eventDetail)) !== true) return;\n\n this._notify(toState);\n\n this._transitioned(eventDetail);\n }\n\n /**\n * Execute all actions for current state.\n */\n protected async _transitioned(eventDetail: StateEventDetail<S, E>): Promise<void> {\n this._logger.logMethodArgs?.('_transitioned', eventDetail);\n\n await this._$execAction(`_on_${eventDetail.event}`, eventDetail);\n\n if (eventDetail.from !== eventDetail.to) {\n await this._$execAction(`_on_state_exit`, eventDetail);\n await this._$execAction(`_on_${eventDetail.from}_exit`, eventDetail);\n await this._$execAction(`_on_state_enter`, eventDetail);\n await this._$execAction(`_on_${eventDetail.to}_enter`, eventDetail);\n }\n\n if (`_on_${eventDetail.from}_${eventDetail.event}` in this) {\n this._$execAction(`_on_${eventDetail.from}_${eventDetail.event}`, eventDetail);\n }\n else {\n this._$execAction(`_on_all_${eventDetail.event}`, eventDetail);\n }\n }\n\n /**\n * Execute action name if defined in _actionRecord.\n */\n protected _$execAction(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>): MaybePromise<void> {\n const actionFn = this._actionRecord[name];\n if (typeof actionFn === 'function') {\n this._logger.logMethodArgs?.('_$execAction', name);\n return this._actionRecord[name]?.call(this, eventDetail);\n }\n }\n\n /**\n * Reset machine to initial state.\n */\n protected _reset(): void {\n this._$data = this._initialState;\n }\n}\n"]}
|
package/fsm.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FiniteStateMachineBase } from './base.js';
|
|
2
|
-
/**
|
|
3
|
-
* Finite State Machine Base Class
|
|
4
|
-
*/
|
|
5
|
-
export declare abstract class FiniteStateMachine<S extends string, E extends string> extends FiniteStateMachineBase<S, E> {
|
|
6
|
-
/**
|
|
7
|
-
* Current state.
|
|
8
|
-
*/
|
|
9
|
-
get state(): S;
|
|
10
|
-
/**
|
|
11
|
-
* Transition finite state machine instance to new state.
|
|
12
|
-
*/
|
|
13
|
-
transition(event: E): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=fsm.d.ts.map
|
package/fsm.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fsm.d.ts","sourceRoot":"","sources":["src/fsm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,WAAW,CAAC;AAEjD;;GAEG;AACH,8BAAsB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/G;;OAEG;IACH,IAAI,KAAK,IAAI,CAAC,CAEb;IAED;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;CAG3B"}
|
package/fsm.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FiniteStateMachineBase } from './base.js';
|
|
2
|
-
/**
|
|
3
|
-
* Finite State Machine Base Class
|
|
4
|
-
*/
|
|
5
|
-
export class FiniteStateMachine extends FiniteStateMachineBase {
|
|
6
|
-
/**
|
|
7
|
-
* Current state.
|
|
8
|
-
*/
|
|
9
|
-
get state() {
|
|
10
|
-
return super._state;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Transition finite state machine instance to new state.
|
|
14
|
-
*/
|
|
15
|
-
transition(event) {
|
|
16
|
-
super._transition(event);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=fsm.js.map
|
package/fsm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fsm.js","sourceRoot":"","sources":["src/fsm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAgB,kBAAuD,SAAQ,sBAA4B;IAC/G;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAQ;QACjB,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import {FiniteStateMachineBase} from './base.js';\n\n/**\n * Finite State Machine Base Class\n */\nexport abstract class FiniteStateMachine<S extends string, E extends string> extends FiniteStateMachineBase<S, E> {\n /**\n * Current state.\n */\n get state(): S {\n return super._state;\n }\n\n /**\n * Transition finite state machine instance to new state.\n */\n transition(event: E): void {\n super._transition(event);\n }\n}\n"]}
|
package/index.d.ts
DELETED
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC","sourcesContent":["export * from './base.js';\nexport * from './fsm.js';\nexport * from './type.js';\n"]}
|
package/type.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;IACT,EAAE,EAAE,CAAC,CAAC;CACP;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;AAEtH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IACrD,OAAO,CAAC,EAAE,GACV,gBAAgB,GAChB,iBAAiB,GACjB,OAAO,CAAC,OAAO,GACf,OAAO,CAAC,QAAQ,GAChB,OAAO,CAAC,IAAI,CAAC,EAAE,GACf,WAAW,CAAC,EAAE,CAAC;AAEnB,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/type.js
DELETED
package/type.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import type {MaybePromise} from '@alwatr/type';\n\nexport interface StateEventDetail<S, E> {\n from: S;\n event: E;\n to: S;\n}\n\nexport type StateRecord<S extends string, E extends string> = Partial<Record<S | '_all', Partial<Record<E, S>>>>;\n\nexport type Action<S extends string, E extends string> = (eventDetail?: StateEventDetail<S, E>) => MaybePromise<void>;\n\nexport type ActionName<S extends string, E extends string> =\n | `_on_${E}`\n | `_on_state_exit`\n | `_on_state_enter`\n | `_on_${S}_exit`\n | `_on_${S}_enter`\n | `_on_${S}_${E}`\n | `_on_all_${E}`;\n\nexport type ActionRecord<S extends string, E extends string> = Partial<Record<ActionName<S, E>, Action<S, E>>>;\n"]}
|