( appState: AppState, sessionId: string, event?: HookEvent, )
| 343 | * @returns Function hook matchers for the event |
| 344 | */ |
| 345 | export function getSessionFunctionHooks( |
| 346 | appState: AppState, |
| 347 | sessionId: string, |
| 348 | event?: HookEvent, |
| 349 | ): Map<HookEvent, FunctionHookMatcher[]> { |
| 350 | const store = appState.sessionHooks.get(sessionId) |
| 351 | if (!store) { |
| 352 | return new Map() |
| 353 | } |
| 354 | |
| 355 | const result = new Map<HookEvent, FunctionHookMatcher[]>() |
| 356 | |
| 357 | const extractFunctionHooks = ( |
| 358 | sessionMatchers: SessionHookMatcher[], |
| 359 | ): FunctionHookMatcher[] => { |
| 360 | return sessionMatchers |
| 361 | .map(sm => ({ |
| 362 | matcher: sm.matcher, |
| 363 | hooks: sm.hooks |
| 364 | .map(h => h.hook) |
| 365 | .filter((h): h is FunctionHook => h.type === 'function'), |
| 366 | })) |
| 367 | .filter(m => m.hooks.length > 0) |
| 368 | } |
| 369 | |
| 370 | if (event) { |
| 371 | const sessionMatchers = store.hooks[event] |
| 372 | if (sessionMatchers) { |
| 373 | const functionMatchers = extractFunctionHooks(sessionMatchers) |
| 374 | if (functionMatchers.length > 0) { |
| 375 | result.set(event, functionMatchers) |
| 376 | } |
| 377 | } |
| 378 | return result |
| 379 | } |
| 380 | |
| 381 | for (const evt of HOOK_EVENTS) { |
| 382 | const sessionMatchers = store.hooks[evt] |
| 383 | if (sessionMatchers) { |
| 384 | const functionMatchers = extractFunctionHooks(sessionMatchers) |
| 385 | if (functionMatchers.length > 0) { |
| 386 | result.set(evt, functionMatchers) |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return result |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Get the full hook entry (including callbacks) for a specific session hook |
no test coverage detected