MCPcopy
hub / github.com/AndrewWalsh/openapi-devtools / parameterise

Function parameterise

src/lib/store-helpers/parameterise.ts:19–49  ·  view source on GitHub ↗
({
  store,
  index,
  path,
  host,
}: Params)

Source from the content-addressed store, hash-verified

17};
18
19export default function parameterise({
20 store,
21 index,
22 path,
23 host,
24}: Params): Returns | null {
25 const removedPaths: Array<string> = [];
26 const matchedLeaves: Array<Leaf> = [];
27 const router = store[host];
28 if (!router) return null;
29 const matchedRoute = router.lookup(path);
30 if (!matchedRoute) return null;
31 const nextPath = getNextPath(index, path, matchedRoute);
32 const foundPathnames = findPathnamesInRouter(router.ctx, nextPath);
33 for (const found of foundPathnames) {
34 matchedLeaves.push(found.leaf);
35 removedPaths.push(found.pathname);
36 remove(router.ctx, found.pathname);
37 pruneRouter(router.ctx.rootNode, pathToArray(found.pathname));
38 }
39 const mergedLeaf = matchedLeaves.reduce(mergeLeaves);
40 mergedLeaf.pathname = nextPath;
41 removedPaths.forEach((path) => unset(store[host].ctx.staticRoutesMap, path));
42 unset(store[host].ctx.staticRoutesMap, nextPath);
43 router.insert(nextPath, { data: mergedLeaf });
44 return {
45 removedPaths,
46 insertedPath: nextPath,
47 insertedLeaf: mergedLeaf,
48 };
49}

Callers 2

parameteriseMethod · 0.90
ControlDynamicFunction · 0.85

Calls 6

pathToArrayFunction · 0.90
getNextPathFunction · 0.85
findPathnamesInRouterFunction · 0.85
removeFunction · 0.85
pruneRouterFunction · 0.85
insertMethod · 0.80

Tested by

no test coverage detected