55 RegisteredHookFunction ,
66 RegisterHookFunctionParams ,
77 AnyOnFailureHookFunction ,
8+ AnyOnSuccessHookFunction ,
89} from "./types.js" ;
910
1011export class StandardLifecycleHooksManager implements LifecycleHooksManager {
@@ -19,6 +20,11 @@ export class StandardLifecycleHooksManager implements LifecycleHooksManager {
1920 private taskFailureHooks : Map < string , RegisteredHookFunction < AnyOnFailureHookFunction > > =
2021 new Map ( ) ;
2122
23+ private globalSuccessHooks : Map < string , RegisteredHookFunction < AnyOnSuccessHookFunction > > =
24+ new Map ( ) ;
25+ private taskSuccessHooks : Map < string , RegisteredHookFunction < AnyOnSuccessHookFunction > > =
26+ new Map ( ) ;
27+
2228 registerGlobalStartHook ( hook : RegisterHookFunctionParams < AnyOnStartHookFunction > ) : void {
2329 const id = generateHookId ( hook ) ;
2430
@@ -114,6 +120,37 @@ export class StandardLifecycleHooksManager implements LifecycleHooksManager {
114120 getGlobalFailureHooks ( ) : RegisteredHookFunction < AnyOnFailureHookFunction > [ ] {
115121 return Array . from ( this . globalFailureHooks . values ( ) ) ;
116122 }
123+
124+ registerGlobalSuccessHook ( hook : RegisterHookFunctionParams < AnyOnSuccessHookFunction > ) : void {
125+ const id = generateHookId ( hook ) ;
126+
127+ this . globalSuccessHooks . set ( id , {
128+ id,
129+ name : hook . id ?? hook . fn . name ? ( hook . fn . name === "" ? undefined : hook . fn . name ) : undefined ,
130+ fn : hook . fn ,
131+ } ) ;
132+ }
133+
134+ registerTaskSuccessHook (
135+ taskId : string ,
136+ hook : RegisterHookFunctionParams < AnyOnSuccessHookFunction >
137+ ) : void {
138+ const id = generateHookId ( hook ) ;
139+
140+ this . taskSuccessHooks . set ( taskId , {
141+ id,
142+ name : hook . id ?? hook . fn . name ? ( hook . fn . name === "" ? undefined : hook . fn . name ) : undefined ,
143+ fn : hook . fn ,
144+ } ) ;
145+ }
146+
147+ getTaskSuccessHook ( taskId : string ) : AnyOnSuccessHookFunction | undefined {
148+ return this . taskSuccessHooks . get ( taskId ) ?. fn ;
149+ }
150+
151+ getGlobalSuccessHooks ( ) : RegisteredHookFunction < AnyOnSuccessHookFunction > [ ] {
152+ return Array . from ( this . globalSuccessHooks . values ( ) ) ;
153+ }
117154}
118155
119156export class NoopLifecycleHooksManager implements LifecycleHooksManager {
@@ -173,6 +210,25 @@ export class NoopLifecycleHooksManager implements LifecycleHooksManager {
173210 getGlobalFailureHooks ( ) : RegisteredHookFunction < AnyOnFailureHookFunction > [ ] {
174211 return [ ] ;
175212 }
213+
214+ registerGlobalSuccessHook ( hook : RegisterHookFunctionParams < AnyOnSuccessHookFunction > ) : void {
215+ // Noop
216+ }
217+
218+ registerTaskSuccessHook (
219+ taskId : string ,
220+ hook : RegisterHookFunctionParams < AnyOnSuccessHookFunction >
221+ ) : void {
222+ // Noop
223+ }
224+
225+ getTaskSuccessHook ( taskId : string ) : AnyOnSuccessHookFunction | undefined {
226+ return undefined ;
227+ }
228+
229+ getGlobalSuccessHooks ( ) : RegisteredHookFunction < AnyOnSuccessHookFunction > [ ] {
230+ return [ ] ;
231+ }
176232}
177233
178234function generateHookId ( hook : RegisterHookFunctionParams < any > ) : string {
0 commit comments