( pattern: string, rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>, )
| 211 | * existing rule by racing to the top of the list. |
| 212 | */ |
| 213 | export const positionForNewPattern = ( |
| 214 | pattern: string, |
| 215 | rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>, |
| 216 | ): string => { |
| 217 | const committed = [...rows].sort(comparePolicyRow); |
| 218 | const newScore = patternSpecificity(pattern); |
| 219 | let idx = committed.findIndex((r) => patternSpecificity(r.pattern) <= newScore); |
| 220 | if (idx === -1) idx = committed.length; // below every more-specific rule |
| 221 | const prev = idx === 0 ? null : committed[idx - 1]!.position; |
| 222 | const next = idx === committed.length ? null : committed[idx]!.position; |
| 223 | return generateKeyBetween(prev, next); |
| 224 | }; |
| 225 | |
| 226 | const actionRestrictionRank = (action: ToolPolicyAction): number => |
| 227 | Match.value(action).pipe( |
no test coverage detected