( pattern: string, slugMap: ReadonlyMap<string, string>, staticNamespaces: readonly string[] = DEFAULT_STATIC_NAMESPACES, )
| 144 | | { readonly kind: "dead"; readonly slug: string }; |
| 145 | |
| 146 | export const migratePolicyPattern = ( |
| 147 | pattern: string, |
| 148 | slugMap: ReadonlyMap<string, string>, |
| 149 | staticNamespaces: readonly string[] = DEFAULT_STATIC_NAMESPACES, |
| 150 | ): PolicyTransformResult => { |
| 151 | if (pattern === "*") return { kind: "ok", pattern: "*" }; |
| 152 | const firstDot = pattern.indexOf("."); |
| 153 | const slug = firstDot === -1 ? pattern : pattern.slice(0, firstDot); |
| 154 | if (staticNamespaces.includes(slug)) return { kind: "static", pattern }; |
| 155 | const newSlug = slugMap.get(slug); |
| 156 | if (newSlug === undefined) return { kind: "dead", slug }; |
| 157 | const rest = firstDot === -1 ? "" : pattern.slice(firstDot + 1); |
| 158 | if (rest === "") return { kind: "ok", pattern: newSlug }; |
| 159 | if (rest === "*") return { kind: "ok", pattern: `${newSlug}.*` }; |
| 160 | return { kind: "ok", pattern: `${newSlug}.*.*.${rest}` }; |
| 161 | }; |
| 162 | |
| 163 | // --------------------------------------------------------------------------- |
| 164 | // Plugin runtime metadata migration. |
no test coverage detected