(
lines: string[],
groupName: string,
method: RpcMethod,
resolveType: (name: string) => string
)
| 3777 | } |
| 3778 | |
| 3779 | function emitClientGlobalRegistrationMethod( |
| 3780 | lines: string[], |
| 3781 | groupName: string, |
| 3782 | method: RpcMethod, |
| 3783 | resolveType: (name: string) => string |
| 3784 | ): void { |
| 3785 | const rpcSegments = method.rpcMethod.split("."); |
| 3786 | const handlerVariableName = `handle_${rpcSegments.map(toSnakeCase).join("_")}`; |
| 3787 | const paramsType = resolveType(pythonParamsTypeName(method)); |
| 3788 | const resultSchema = getMethodResultSchema(method); |
| 3789 | const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined; |
| 3790 | const hasResult = !isVoidSchema(resultSchema) && !nullableInner; |
| 3791 | const handlerField = toSnakeCase(groupName); |
| 3792 | const handlerMethod = clientSessionHandlerMethodName(method.rpcMethod); |
| 3793 | |
| 3794 | lines.push(` async def ${handlerVariableName}(params: dict) -> dict | None:`); |
| 3795 | lines.push(` request = ${paramsType}.from_dict(params)`); |
| 3796 | lines.push(` handler = handlers.${handlerField}`); |
| 3797 | lines.push(` if handler is None: raise RuntimeError("No ${handlerField} client-global handler registered")`); |
| 3798 | if (hasResult) { |
| 3799 | lines.push(` result = await handler.${handlerMethod}(request)`); |
| 3800 | if (isObjectSchema(resultSchema)) { |
| 3801 | lines.push(` return result.to_dict()`); |
| 3802 | } else { |
| 3803 | lines.push(` return result.value if hasattr(result, 'value') else result`); |
| 3804 | } |
| 3805 | } else if (nullableInner) { |
| 3806 | lines.push(` result = await handler.${handlerMethod}(request)`); |
| 3807 | const resolvedInner = resolveSchema(nullableInner, rpcDefinitions) ?? nullableInner; |
| 3808 | if (isObjectSchema(resolvedInner) || nullableInner.$ref) { |
| 3809 | lines.push(` return result.to_dict() if result is not None else None`); |
| 3810 | } else { |
| 3811 | lines.push(` return result`); |
| 3812 | } |
| 3813 | } else { |
| 3814 | lines.push(` await handler.${handlerMethod}(request)`); |
| 3815 | lines.push(` return None`); |
| 3816 | } |
| 3817 | lines.push(` client.set_request_handler("${method.rpcMethod}", ${handlerVariableName})`); |
| 3818 | } |
| 3819 | |
| 3820 | async function generate(sessionSchemaPath?: string, apiSchemaPath?: string): Promise<void> { |
| 3821 | await generateSessionEvents(sessionSchemaPath); |
no test coverage detected
searching dependent graphs…