(lines: string[], node: Record<string, unknown>, isSession: boolean, resolveType: (name: string) => string, classPrefix: string = "")
| 3428 | } |
| 3429 | |
| 3430 | function emitRpcWrapper(lines: string[], node: Record<string, unknown>, isSession: boolean, resolveType: (name: string) => string, classPrefix: string = ""): void { |
| 3431 | const groups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); |
| 3432 | const topLevelMethods = Object.entries(node).filter(([, v]) => isRpcMethod(v)); |
| 3433 | |
| 3434 | const wrapperName = classPrefix + (isSession ? "SessionRpc" : "ServerRpc"); |
| 3435 | |
| 3436 | // Emit API classes for groups (recursively handles sub-groups) |
| 3437 | for (const [groupName, groupNode] of groups) { |
| 3438 | const prefix = classPrefix + (isSession ? "" : "Server"); |
| 3439 | const apiName = prefix + toPascalCase(groupName) + "Api"; |
| 3440 | const groupExperimental = isNodeFullyExperimental(groupNode as Record<string, unknown>); |
| 3441 | const groupDeprecated = isNodeFullyDeprecated(groupNode as Record<string, unknown>); |
| 3442 | emitPyApiGroup(lines, apiName, groupNode as Record<string, unknown>, isSession, resolveType, groupExperimental, groupDeprecated, classPrefix); |
| 3443 | } |
| 3444 | |
| 3445 | // Emit wrapper class |
| 3446 | if (isSession) { |
| 3447 | lines.push(`class ${wrapperName}:`); |
| 3448 | lines.push(classPrefix === "_Internal" |
| 3449 | ? ` """Internal SDK session-scoped RPC methods. Not part of the public API."""` |
| 3450 | : ` """Typed session-scoped RPC methods."""`); |
| 3451 | lines.push(` def __init__(self, client: "JsonRpcClient", session_id: str):`); |
| 3452 | lines.push(` self._client = client`); |
| 3453 | lines.push(` self._session_id = session_id`); |
| 3454 | for (const [groupName] of groups) { |
| 3455 | lines.push(` self.${toSnakeCase(groupName)} = ${classPrefix}${toPascalCase(groupName)}Api(client, session_id)`); |
| 3456 | } |
| 3457 | } else { |
| 3458 | lines.push(`class ${wrapperName}:`); |
| 3459 | lines.push(classPrefix === "_Internal" |
| 3460 | ? ` """Internal SDK server-scoped RPC methods. Not part of the public API."""` |
| 3461 | : ` """Typed server-scoped RPC methods."""`); |
| 3462 | lines.push(` def __init__(self, client: "JsonRpcClient"):`); |
| 3463 | lines.push(` self._client = client`); |
| 3464 | for (const [groupName] of groups) { |
| 3465 | lines.push(` self.${toSnakeCase(groupName)} = ${classPrefix}Server${toPascalCase(groupName)}Api(client)`); |
| 3466 | } |
| 3467 | } |
| 3468 | lines.push(``); |
| 3469 | |
| 3470 | // Top-level methods |
| 3471 | for (const [key, value] of topLevelMethods) { |
| 3472 | if (!isRpcMethod(value)) continue; |
| 3473 | emitMethod(lines, key, value, isSession, resolveType, false); |
| 3474 | } |
| 3475 | lines.push(``); |
| 3476 | } |
| 3477 | |
| 3478 | function emitMethod(lines: string[], name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, groupExperimental = false, groupDeprecated = false): void { |
| 3479 | const isInternal = method.visibility === "internal"; |
no test coverage detected
searching dependent graphs…