File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,18 @@ export const defineWorkflow =
73
73
transitionByKey : ( key : ID ) => {
74
74
const transition = workflow . transitions . find ( ( t ) => t . key === key ) ;
75
75
if ( ! transition ) {
76
- throw new NotFoundException ( 'Transition does not exist' ) ;
76
+ throw new NotFoundException (
77
+ `${ workflow . name } workflow transition for key "${ key } " does not exist.` ,
78
+ ) ;
79
+ }
80
+ return transition ;
81
+ } ,
82
+ transitionByName : ( name : TransitionNames ) => {
83
+ const transition = workflow . transitions . find ( ( t ) => t . name === name ) ;
84
+ if ( ! transition ) {
85
+ throw new NotFoundException (
86
+ `${ workflow . name } workflow transition named "${ name } " does not exist` ,
87
+ ) ;
77
88
}
78
89
return transition ;
79
90
} ,
@@ -130,6 +141,9 @@ export interface Workflow<
130
141
/** type only */
131
142
readonly resolvedTransition : Omit < Transition , 'to' > & { to : State } ;
132
143
readonly transitionByKey : ( key : ID ) => Transition ;
144
+ readonly transitionByName : < Names extends TransitionNames > (
145
+ name : Names ,
146
+ ) => Transition ;
133
147
readonly pickNames : < Names extends TransitionNames > (
134
148
...keys : Array < Many < Names > >
135
149
) => ReadonlySet < Names > ;
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ export function WorkflowEventGranter<
15
15
W extends Workflow ,
16
16
EventClass extends W [ 'eventResource' ] ,
17
17
> ( workflow : ( ) => W ) {
18
- type State = Workflow [ 'state' ] ;
19
- type Names = Workflow [ 'transition' ] [ 'name' ] ;
18
+ type State = W [ 'state' ] ;
19
+ type Names = W [ 'transition' ] [ 'name' ] ;
20
20
21
21
abstract class WorkflowEventGranterClass extends ResourceGranter < EventClass > {
22
22
get read ( ) {
@@ -102,7 +102,7 @@ export class TransitionCondition<W extends Workflow>
102
102
return new TransitionCondition (
103
103
[ ...allowed ] . map ( ( name ) => ( {
104
104
name,
105
- key : [ workflow . transitions . find ( ( t ) => t . name === name ) ! . key ] ,
105
+ key : [ workflow . transitionByName ( name ) . key ] ,
106
106
} ) ) ,
107
107
) ;
108
108
}
You can’t perform that action at this time.
0 commit comments