@stravigor/machine 0.4.6 → 0.4.7
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 +1 -1
- package/src/errors.ts +5 -3
- package/src/machine.ts +2 -2
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -5,11 +5,13 @@ export class TransitionError extends StravError {
|
|
|
5
5
|
constructor(
|
|
6
6
|
public readonly transition: string,
|
|
7
7
|
public readonly currentState: string,
|
|
8
|
-
public readonly allowedFrom
|
|
8
|
+
public readonly allowedFrom?: string[]
|
|
9
9
|
) {
|
|
10
10
|
super(
|
|
11
|
-
|
|
12
|
-
`
|
|
11
|
+
allowedFrom
|
|
12
|
+
? `Cannot apply transition "${transition}" from state "${currentState}". ` +
|
|
13
|
+
`Allowed from: [${allowedFrom.join(', ')}]`
|
|
14
|
+
: `Transition "${transition}" is not defined.`
|
|
13
15
|
)
|
|
14
16
|
}
|
|
15
17
|
}
|
package/src/machine.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function defineMachine<TState extends string, TTransition extends string>
|
|
|
65
65
|
const result = guard(entity)
|
|
66
66
|
// Support both sync and async guards
|
|
67
67
|
if (typeof (result as any)?.then === 'function') {
|
|
68
|
-
return
|
|
68
|
+
return result as Promise<boolean>
|
|
69
69
|
}
|
|
70
70
|
return result as boolean
|
|
71
71
|
},
|
|
@@ -90,7 +90,7 @@ export function defineMachine<TState extends string, TTransition extends string>
|
|
|
90
90
|
const currentState = entity[definition.field] as TState
|
|
91
91
|
const transitionDef = definition.transitions[transition]
|
|
92
92
|
if (!transitionDef) {
|
|
93
|
-
throw new TransitionError(transition, currentState
|
|
93
|
+
throw new TransitionError(transition, currentState)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const allowed = fromMap.get(transition)!
|