(
lines: string[],
node: Record<string, unknown>,
resolveType: (name: string) => string
)
| 3716 | } |
| 3717 | |
| 3718 | function emitClientGlobalApiRegistration( |
| 3719 | lines: string[], |
| 3720 | node: Record<string, unknown>, |
| 3721 | resolveType: (name: string) => string |
| 3722 | ): void { |
| 3723 | const groups = Object.entries(node).filter(([, value]) => typeof value === "object" && value !== null && !isRpcMethod(value)); |
| 3724 | |
| 3725 | for (const [groupName, groupNode] of groups) { |
| 3726 | const handlerName = `${toPascalCase(groupName)}Handler`; |
| 3727 | const groupExperimental = isNodeFullyExperimental(groupNode as Record<string, unknown>); |
| 3728 | const groupDeprecated = isNodeFullyDeprecated(groupNode as Record<string, unknown>); |
| 3729 | if (groupDeprecated) { |
| 3730 | lines.push(`# Deprecated: this API group is deprecated and will be removed in a future version.`); |
| 3731 | } |
| 3732 | if (groupExperimental) { |
| 3733 | pushPyExperimentalApiGroupComment(lines); |
| 3734 | } |
| 3735 | lines.push(`class ${handlerName}(Protocol):`); |
| 3736 | const methods = collectRpcMethods(groupNode as Record<string, unknown>); |
| 3737 | for (const method of methods) { |
| 3738 | // Client-global handler methods reuse the session handler shape; the |
| 3739 | // only difference is dispatch (no implicit session_id key). |
| 3740 | emitClientSessionHandlerMethod(lines, method, resolveType, groupExperimental, groupDeprecated); |
| 3741 | } |
| 3742 | lines.push(``); |
| 3743 | } |
| 3744 | |
| 3745 | lines.push(`@dataclass`); |
| 3746 | lines.push(`class ClientGlobalApiHandlers:`); |
| 3747 | if (groups.length === 0) { |
| 3748 | lines.push(` pass`); |
| 3749 | } else { |
| 3750 | for (const [groupName] of groups) { |
| 3751 | lines.push(` ${toSnakeCase(groupName)}: ${toPascalCase(groupName)}Handler | None = None`); |
| 3752 | } |
| 3753 | } |
| 3754 | lines.push(``); |
| 3755 | |
| 3756 | lines.push(`def register_client_global_api_handlers(`); |
| 3757 | lines.push(` client: "JsonRpcClient",`); |
| 3758 | lines.push(` handlers: ClientGlobalApiHandlers,`); |
| 3759 | lines.push(`) -> None:`); |
| 3760 | lines.push(` """Register client-global request handlers on a JSON-RPC connection.`); |
| 3761 | lines.push(``); |
| 3762 | lines.push(` Unlike client-session handlers these methods carry no implicit`); |
| 3763 | lines.push(` session_id dispatch key; a single set of handlers serves the entire`); |
| 3764 | lines.push(` connection.`); |
| 3765 | lines.push(` """`); |
| 3766 | if (groups.length === 0) { |
| 3767 | lines.push(` return`); |
| 3768 | } else { |
| 3769 | for (const [groupName, groupNode] of groups) { |
| 3770 | const methods = collectRpcMethods(groupNode as Record<string, unknown>); |
| 3771 | for (const method of methods) { |
| 3772 | emitClientGlobalRegistrationMethod(lines, groupName, method, resolveType); |
| 3773 | } |
| 3774 | } |
| 3775 | } |
no test coverage detected
searching dependent graphs…