(
lines: string[],
apiName: string,
node: Record<string, unknown>,
isSession: boolean,
resolveType: (name: string) => string,
groupExperimental: boolean,
groupDeprecated: boolean = false,
classPrefix: string = ""
)
| 3375 | } |
| 3376 | |
| 3377 | function emitPyApiGroup( |
| 3378 | lines: string[], |
| 3379 | apiName: string, |
| 3380 | node: Record<string, unknown>, |
| 3381 | isSession: boolean, |
| 3382 | resolveType: (name: string) => string, |
| 3383 | groupExperimental: boolean, |
| 3384 | groupDeprecated: boolean = false, |
| 3385 | classPrefix: string = "" |
| 3386 | ): void { |
| 3387 | const subGroups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); |
| 3388 | |
| 3389 | // Emit sub-group classes first (Python needs definitions before use) |
| 3390 | for (const [subGroupName, subGroupNode] of subGroups) { |
| 3391 | const subApiName = apiName.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 3392 | const subGroupExperimental = isNodeFullyExperimental(subGroupNode as Record<string, unknown>); |
| 3393 | const subGroupDeprecated = isNodeFullyDeprecated(subGroupNode as Record<string, unknown>); |
| 3394 | emitPyApiGroup(lines, subApiName, subGroupNode as Record<string, unknown>, isSession, resolveType, subGroupExperimental, subGroupDeprecated, classPrefix); |
| 3395 | } |
| 3396 | |
| 3397 | // Emit this class |
| 3398 | if (groupDeprecated) { |
| 3399 | lines.push(`# Deprecated: this API group is deprecated and will be removed in a future version.`); |
| 3400 | } |
| 3401 | if (groupExperimental) { |
| 3402 | pushPyExperimentalApiGroupComment(lines); |
| 3403 | } |
| 3404 | lines.push(`class ${apiName}:`); |
| 3405 | if (isSession) { |
| 3406 | lines.push(` def __init__(self, client: "JsonRpcClient", session_id: str):`); |
| 3407 | lines.push(` self._client = client`); |
| 3408 | lines.push(` self._session_id = session_id`); |
| 3409 | for (const [subGroupName] of subGroups) { |
| 3410 | const subApiName = apiName.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 3411 | lines.push(` self.${toSnakeCase(subGroupName)} = ${subApiName}(client, session_id)`); |
| 3412 | } |
| 3413 | } else { |
| 3414 | lines.push(` def __init__(self, client: "JsonRpcClient"):`); |
| 3415 | lines.push(` self._client = client`); |
| 3416 | for (const [subGroupName] of subGroups) { |
| 3417 | const subApiName = apiName.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 3418 | lines.push(` self.${toSnakeCase(subGroupName)} = ${subApiName}(client)`); |
| 3419 | } |
| 3420 | } |
| 3421 | lines.push(``); |
| 3422 | |
| 3423 | for (const [key, value] of Object.entries(node)) { |
| 3424 | if (!isRpcMethod(value)) continue; |
| 3425 | emitMethod(lines, key, value, isSession, resolveType, groupExperimental, groupDeprecated); |
| 3426 | } |
| 3427 | lines.push(``); |
| 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)); |
no test coverage detected
searching dependent graphs…