* Build a namespace tree from a list of methods. `groupOf(method)` returns the * dotted group path (e.g. "mcp.config" for "mcp.config.list" / "workspaces" * for "workspaces.listFiles"); the last segment of `rpcMethod` is the leaf * method name.
( rootTypeName: string, methods: RpcMethod[], stripPrefix: string, )
| 1666 | * method name. |
| 1667 | */ |
| 1668 | function buildNamespaceTree( |
| 1669 | rootTypeName: string, |
| 1670 | methods: RpcMethod[], |
| 1671 | stripPrefix: string, |
| 1672 | ): NamespaceNode { |
| 1673 | const root = newNamespaceNode("", rootTypeName); |
| 1674 | for (const method of methods) { |
| 1675 | const trimmed = stripPrefix && method.rpcMethod.startsWith(stripPrefix) |
| 1676 | ? method.rpcMethod.slice(stripPrefix.length) |
| 1677 | : method.rpcMethod; |
| 1678 | const segments = trimmed.split("."); |
| 1679 | const groupSegments = segments.slice(0, -1); |
| 1680 | let node = root; |
| 1681 | for (const seg of groupSegments) { |
| 1682 | let child = node.children.get(seg); |
| 1683 | if (!child) { |
| 1684 | const childTypeName = `${node.typeName}${toPascalCase(seg)}`; |
| 1685 | child = newNamespaceNode(seg, childTypeName); |
| 1686 | node.children.set(seg, child); |
| 1687 | } |
| 1688 | node = child; |
| 1689 | } |
| 1690 | node.methods.push(method); |
| 1691 | } |
| 1692 | return root; |
| 1693 | } |
| 1694 | |
| 1695 | /** |
| 1696 | * Determine if a method has typed params. Returns `{ hasParams, typeName }`. |
no test coverage detected
searching dependent graphs…