MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / migratePolicyPattern

Function migratePolicyPattern

packages/core/sdk/src/migration-spec.ts:146–161  ·  view source on GitHub ↗
(
  pattern: string,
  slugMap: ReadonlyMap<string, string>,
  staticNamespaces: readonly string[] = DEFAULT_STATIC_NAMESPACES,
)

Source from the content-addressed store, hash-verified

144 | { readonly kind: "dead"; readonly slug: string };
145
146export 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.

Callers 2

planMigrationFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected