(
lines: string[],
node: Record<string, unknown>,
resolveType: (name: string) => string
)
| 3584 | } |
| 3585 | |
| 3586 | function emitClientSessionApiRegistration( |
| 3587 | lines: string[], |
| 3588 | node: Record<string, unknown>, |
| 3589 | resolveType: (name: string) => string |
| 3590 | ): void { |
| 3591 | const groups = Object.entries(node).filter(([, value]) => typeof value === "object" && value !== null && !isRpcMethod(value)); |
| 3592 | |
| 3593 | for (const [groupName, groupNode] of groups) { |
| 3594 | const handlerName = `${toPascalCase(groupName)}Handler`; |
| 3595 | const groupExperimental = isNodeFullyExperimental(groupNode as Record<string, unknown>); |
| 3596 | const groupDeprecated = isNodeFullyDeprecated(groupNode as Record<string, unknown>); |
| 3597 | if (groupDeprecated) { |
| 3598 | lines.push(`# Deprecated: this API group is deprecated and will be removed in a future version.`); |
| 3599 | } |
| 3600 | if (groupExperimental) { |
| 3601 | pushPyExperimentalApiGroupComment(lines); |
| 3602 | } |
| 3603 | lines.push(`class ${handlerName}(Protocol):`); |
| 3604 | const methods = collectRpcMethods(groupNode as Record<string, unknown>); |
| 3605 | for (const method of methods) { |
| 3606 | emitClientSessionHandlerMethod(lines, method, resolveType, groupExperimental, groupDeprecated); |
| 3607 | } |
| 3608 | lines.push(``); |
| 3609 | } |
| 3610 | |
| 3611 | lines.push(`@dataclass`); |
| 3612 | lines.push(`class ClientSessionApiHandlers:`); |
| 3613 | if (groups.length === 0) { |
| 3614 | lines.push(` pass`); |
| 3615 | } else { |
| 3616 | for (const [groupName] of groups) { |
| 3617 | lines.push(` ${toSnakeCase(groupName)}: ${toPascalCase(groupName)}Handler | None = None`); |
| 3618 | } |
| 3619 | } |
| 3620 | lines.push(``); |
| 3621 | |
| 3622 | lines.push(`def register_client_session_api_handlers(`); |
| 3623 | lines.push(` client: "JsonRpcClient",`); |
| 3624 | lines.push(` get_handlers: Callable[[str], ClientSessionApiHandlers],`); |
| 3625 | lines.push(`) -> None:`); |
| 3626 | lines.push(` """Register client-session request handlers on a JSON-RPC connection."""`); |
| 3627 | if (groups.length === 0) { |
| 3628 | lines.push(` return`); |
| 3629 | } else { |
| 3630 | for (const [groupName, groupNode] of groups) { |
| 3631 | const methods = collectRpcMethods(groupNode as Record<string, unknown>); |
| 3632 | for (const method of methods) { |
| 3633 | emitClientSessionRegistrationMethod( |
| 3634 | lines, |
| 3635 | groupName, |
| 3636 | method, |
| 3637 | resolveType |
| 3638 | ); |
| 3639 | } |
| 3640 | } |
| 3641 | } |
| 3642 | lines.push(``); |
| 3643 | } |
no test coverage detected
searching dependent graphs…