(
node: Record<string, unknown>,
indent: string,
isSession: boolean,
parentExperimental = false,
parentDeprecated = false,
visibilityFilter?: "public" | "internal",
)
| 730 | } |
| 731 | |
| 732 | function emitGroup( |
| 733 | node: Record<string, unknown>, |
| 734 | indent: string, |
| 735 | isSession: boolean, |
| 736 | parentExperimental = false, |
| 737 | parentDeprecated = false, |
| 738 | visibilityFilter?: "public" | "internal", |
| 739 | ): string[] { |
| 740 | const lines: string[] = []; |
| 741 | for (const [key, value] of Object.entries(node)) { |
| 742 | if (isRpcMethod(value)) { |
| 743 | const isInternalMethod = (value as RpcMethod).visibility === "internal"; |
| 744 | if (visibilityFilter === "public" && isInternalMethod) continue; |
| 745 | if (visibilityFilter === "internal" && !isInternalMethod) continue; |
| 746 | const { rpcMethod, params } = value; |
| 747 | const resultType = tsResultType(value); |
| 748 | const paramsType = paramsTypeName(value); |
| 749 | const effectiveParams = getMethodParamsSchema(value); |
| 750 | |
| 751 | const paramEntries = effectiveParams?.properties |
| 752 | ? Object.entries(effectiveParams.properties).filter(([k]) => k !== "sessionId") |
| 753 | : []; |
| 754 | const hasParams = hasSchemaPayload(effectiveParams); |
| 755 | const hasNonSessionParams = paramEntries.length > 0; |
| 756 | |
| 757 | const sigParams: string[] = []; |
| 758 | let bodyArg: string; |
| 759 | |
| 760 | if (isSession) { |
| 761 | if (hasNonSessionParams) { |
| 762 | const optMark = isParamsOptional(value) ? "?" : ""; |
| 763 | // sessionId is already stripped from the generated type definition, |
| 764 | // so no need for Omit<..., "sessionId"> |
| 765 | sigParams.push(`params${optMark}: ${paramsType}`); |
| 766 | bodyArg = "{ sessionId, ...params }"; |
| 767 | } else { |
| 768 | bodyArg = "{ sessionId }"; |
| 769 | } |
| 770 | } else { |
| 771 | if (hasParams) { |
| 772 | const optMark = isParamsOptional(value) ? "?" : ""; |
| 773 | sigParams.push(`params${optMark}: ${paramsType}`); |
| 774 | bodyArg = "params"; |
| 775 | } else { |
| 776 | bodyArg = "{}"; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | pushTsRpcMethodJsDoc(lines, indent, value, { |
| 781 | paramsName: sigParams.length > 0 ? "params" : undefined, |
| 782 | paramsDescription: rpcParamsDescription(value, effectiveParams), |
| 783 | includeDeprecated: (value as RpcMethod).deprecated && !parentDeprecated, |
| 784 | includeExperimental: (value as RpcMethod).stability === "experimental" && !parentExperimental, |
| 785 | }); |
| 786 | lines.push(`${indent}${key}: async (${sigParams.join(", ")}): Promise<${resultType}> =>`); |
| 787 | lines.push(`${indent} connection.sendRequest("${rpcMethod}", ${bodyArg}),`); |
| 788 | } else if (typeof value === "object" && value !== null) { |
| 789 | const groupExperimental = isNodeFullyExperimental(value as Record<string, unknown>); |
no test coverage detected
searching dependent graphs…