(labels: string[])
| 66 | // (`labels.{key} == "v"` or `labels.{key} in [...]`). Ported verbatim from |
| 67 | // the legacy Pinia database store. |
| 68 | export function getLabelFilter(labels: string[]): string[] { |
| 69 | const labelMap = new Map<string, string[]>(); |
| 70 | for (const label of labels) { |
| 71 | const sections = label.split(":"); |
| 72 | if (sections.length !== 2) { |
| 73 | continue; |
| 74 | } |
| 75 | const [key, rawValue] = sections; |
| 76 | const values = rawValue.split(","); |
| 77 | if (!labelMap.has(key)) { |
| 78 | labelMap.set(key, []); |
| 79 | } |
| 80 | labelMap.get(key)?.push(...values); |
| 81 | } |
| 82 | return [...labelMap.entries()].reduce((result, [key, values]) => { |
| 83 | switch (values.length) { |
| 84 | case 0: |
| 85 | return result; |
| 86 | case 1: |
| 87 | result.push(`labels.${key} == "${values[0]}"`); |
| 88 | return result; |
| 89 | default: |
| 90 | result.push( |
| 91 | `labels.${key} in [${values.map((v) => `"${v}"`).join(", ")}]` |
| 92 | ); |
| 93 | return result; |
| 94 | } |
| 95 | }, [] as string[]); |
| 96 | } |
| 97 | |
| 98 | // Builds the CEL filter string for `listDatabases` from a structured |
| 99 | // `DatabaseFilter`. Mirrors the legacy Pinia `getListDatabaseFilter` so the |
no test coverage detected