( pattern: string, rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>, )
| 168 | * existing rule by racing to the top of the list. |
| 169 | */ |
| 170 | export const positionForNewPattern = ( |
| 171 | pattern: string, |
| 172 | rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>, |
| 173 | ): string => { |
| 174 | const committed = [...rows].sort(comparePolicyRow); |
| 175 | const newScore = patternSpecificity(pattern); |
| 176 | let idx = committed.findIndex((r) => patternSpecificity(r.pattern) <= newScore); |
| 177 | if (idx === -1) idx = committed.length; // below every more-specific rule |
| 178 | const prev = idx === 0 ? null : committed[idx - 1]!.position; |
| 179 | const next = idx === committed.length ? null : committed[idx]!.position; |
| 180 | return generateKeyBetween(prev, next); |
| 181 | }; |
| 182 | |
| 183 | const actionRestrictionRank = (action: ToolPolicyAction): number => |
| 184 | Match.value(action).pipe( |
no test coverage detected