* Generate handler interfaces and a registration function for client session API groups. * * Client session API methods have `sessionId` on the wire (injected by the * runtime's proxy layer). The generated registration function accepts a * `getHandler` callback that resolves a sessionId to a han
(clientSchema: Record<string, unknown>)
| 846 | * Param types include sessionId — handler code can simply ignore it. |
| 847 | */ |
| 848 | function emitClientSessionApiRegistration(clientSchema: Record<string, unknown>): string[] { |
| 849 | const lines: string[] = []; |
| 850 | const groups = collectClientGroups(clientSchema); |
| 851 | |
| 852 | // Emit a handler interface per group |
| 853 | for (const [groupName, methods] of groups) { |
| 854 | const interfaceName = toPascalCase(groupName) + "Handler"; |
| 855 | const groupDeprecated = isNodeFullyDeprecated(clientSchema[groupName] as Record<string, unknown>); |
| 856 | const groupExperimental = isNodeFullyExperimental(clientSchema[groupName] as Record<string, unknown>); |
| 857 | if (groupDeprecated) { |
| 858 | lines.push(`/** @deprecated Handler for \`${groupName}\` client session API methods. */`); |
| 859 | } else if (groupExperimental) { |
| 860 | lines.push(`/** Handler for \`${groupName}\` client session API methods. */`); |
| 861 | lines.push(TS_EXPERIMENTAL_JSDOC); |
| 862 | } else { |
| 863 | lines.push(`/** Handler for \`${groupName}\` client session API methods. */`); |
| 864 | } |
| 865 | lines.push(`export interface ${interfaceName} {`); |
| 866 | for (const method of methods) { |
| 867 | const name = handlerMethodName(method.rpcMethod); |
| 868 | const hasParams = hasSchemaPayload(getMethodParamsSchema(method)); |
| 869 | const pType = hasParams ? paramsTypeName(method) : ""; |
| 870 | const rType = tsResultType(method); |
| 871 | |
| 872 | pushTsRpcMethodJsDoc(lines, " ", method, { |
| 873 | summaryFallback: `Handles \`${method.rpcMethod}\`.`, |
| 874 | paramsName: hasParams ? "params" : undefined, |
| 875 | paramsDescription: rpcParamsDescription(method, getMethodParamsSchema(method)), |
| 876 | includeDeprecated: method.deprecated && !groupDeprecated, |
| 877 | includeExperimental: method.stability === "experimental" && !groupExperimental, |
| 878 | }); |
| 879 | if (hasParams) { |
| 880 | lines.push(` ${name}(params: ${pType}): Promise<${rType}>;`); |
| 881 | } else { |
| 882 | lines.push(` ${name}(): Promise<${rType}>;`); |
| 883 | } |
| 884 | } |
| 885 | lines.push(`}`); |
| 886 | lines.push(""); |
| 887 | } |
| 888 | |
| 889 | // Emit combined ClientSessionApiHandlers type |
| 890 | lines.push(`/** All client session API handler groups. */`); |
| 891 | lines.push(`export interface ClientSessionApiHandlers {`); |
| 892 | for (const [groupName] of groups) { |
| 893 | const interfaceName = toPascalCase(groupName) + "Handler"; |
| 894 | lines.push(` ${groupName}?: ${interfaceName};`); |
| 895 | } |
| 896 | lines.push(`}`); |
| 897 | lines.push(""); |
| 898 | |
| 899 | // Emit registration function |
| 900 | lines.push(`/**`); |
| 901 | lines.push(` * Register client session API handlers on a JSON-RPC connection.`); |
| 902 | lines.push(` * The server calls these methods to delegate work to the client.`); |
| 903 | lines.push(` * Each incoming call includes a \`sessionId\` in the params; the registration`); |
| 904 | lines.push(` * function uses \`getHandlers\` to resolve the session's handlers.`); |
| 905 | lines.push(` */`); |
no test coverage detected
searching dependent graphs…