( config: HooksConfig, eventName: string, matcherValue?: string, )
| 131 | * @returns Array of matching hook handler groups |
| 132 | */ |
| 133 | export function getMatchingHookGroups( |
| 134 | config: HooksConfig, |
| 135 | eventName: string, |
| 136 | matcherValue?: string, |
| 137 | ): HookMatcherGroup[] { |
| 138 | const groups = config[eventName as keyof HooksConfig]; |
| 139 | if (!groups) return []; |
| 140 | |
| 141 | return groups.filter((group) => { |
| 142 | // No matcher, empty matcher, or "*" = match all |
| 143 | if (!group.matcher || group.matcher === "" || group.matcher === "*") { |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | // If no matcher value provided (e.g., events without matcher support), match all |
| 148 | if (matcherValue === undefined) { |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | // Regex match |
| 153 | try { |
| 154 | const regex = new RegExp(group.matcher); |
| 155 | return regex.test(matcherValue); |
| 156 | } catch (error) { |
| 157 | logger.warn( |
| 158 | `Invalid hook matcher regex "${group.matcher}" for event ${eventName}:`, |
| 159 | error, |
| 160 | ); |
| 161 | return false; |
| 162 | } |
| 163 | }); |
| 164 | } |
no test coverage detected