@strav/machine 0.3.32 → 0.3.33
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/package.json +3 -3
- package/src/machine.ts +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strav/machine",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "State machine for the Strav framework",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"tsconfig.json"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@strav/kernel": "0.3.
|
|
18
|
-
"@strav/database": "0.3.
|
|
17
|
+
"@strav/kernel": "0.3.33",
|
|
18
|
+
"@strav/database": "0.3.33"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "bun test tests/",
|
package/src/machine.ts
CHANGED
|
@@ -122,12 +122,24 @@ export function defineMachine<TState extends string, TTransition extends string>
|
|
|
122
122
|
await effect(entity, meta)
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// Emit event
|
|
125
|
+
// Emit user-defined per-transition event (zero-cost when no listener).
|
|
126
126
|
const eventName = definition.events?.[transition]
|
|
127
127
|
if (eventName && Emitter.listenerCount(eventName) > 0) {
|
|
128
128
|
Emitter.emit(eventName, { entity, ...meta }).catch(() => {})
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// Emit a generic state-transition event so a single audit hook can
|
|
132
|
+
// observe every transition across every machine without each
|
|
133
|
+
// definition wiring an `events.*` entry. Zero-cost when no
|
|
134
|
+
// listener is registered.
|
|
135
|
+
if (Emitter.listenerCount('machine:transition') > 0) {
|
|
136
|
+
Emitter.emit('machine:transition', {
|
|
137
|
+
entity,
|
|
138
|
+
field: definition.field,
|
|
139
|
+
...meta,
|
|
140
|
+
}).catch(() => {})
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
return meta
|
|
132
144
|
},
|
|
133
145
|
}
|