@stravigor/machine 0.4.6 → 0.4.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stravigor/machine",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "description": "State machine for the Strav framework",
6
6
  "license": "MIT",
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: string[]
8
+ public readonly allowedFrom?: string[]
9
9
  ) {
10
10
  super(
11
- `Cannot apply transition "${transition}" from state "${currentState}". ` +
12
- `Allowed from: [${allowedFrom.join(', ')}]`
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 (result as Promise<boolean>).catch(() => false)
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)!