* Generate handler interfaces and a registration function for client *global* * API groups. * * Unlike client-session APIs, these methods carry no implicit `sessionId` * dispatch key. The SDK consumer registers a single process-wide handler set * via `registerClientGlobalApiHandlers`; the runti
(clientSchema: Record<string, unknown>)
| 945 | * runtime session triggered it. |
| 946 | */ |
| 947 | function emitClientGlobalApiRegistration(clientSchema: Record<string, unknown>): string[] { |
| 948 | const lines: string[] = []; |
| 949 | const groups = collectClientGroups(clientSchema); |
| 950 | |
| 951 | for (const [groupName, methods] of groups) { |
| 952 | const interfaceName = toPascalCase(groupName) + "Handler"; |
| 953 | const groupDeprecated = isNodeFullyDeprecated(clientSchema[groupName] as Record<string, unknown>); |
| 954 | const groupExperimental = isNodeFullyExperimental(clientSchema[groupName] as Record<string, unknown>); |
| 955 | if (groupDeprecated) { |
| 956 | lines.push(`/** @deprecated Handler for \`${groupName}\` client global API methods. */`); |
| 957 | } else if (groupExperimental) { |
| 958 | lines.push(`/** Handler for \`${groupName}\` client global API methods. */`); |
| 959 | lines.push(TS_EXPERIMENTAL_JSDOC); |
| 960 | } else { |
| 961 | lines.push(`/** Handler for \`${groupName}\` client global API methods. */`); |
| 962 | } |
| 963 | lines.push(`export interface ${interfaceName} {`); |
| 964 | for (const method of methods) { |
| 965 | const name = handlerMethodName(method.rpcMethod); |
| 966 | const hasParams = hasSchemaPayload(getMethodParamsSchema(method)); |
| 967 | const pType = hasParams ? paramsTypeName(method) : ""; |
| 968 | const rType = tsResultType(method); |
| 969 | |
| 970 | pushTsRpcMethodJsDoc(lines, " ", method, { |
| 971 | summaryFallback: `Handles \`${method.rpcMethod}\`.`, |
| 972 | paramsName: hasParams ? "params" : undefined, |
| 973 | paramsDescription: rpcParamsDescription(method, getMethodParamsSchema(method)), |
| 974 | includeDeprecated: method.deprecated && !groupDeprecated, |
| 975 | includeExperimental: method.stability === "experimental" && !groupExperimental, |
| 976 | }); |
| 977 | if (hasParams) { |
| 978 | lines.push(` ${name}(params: ${pType}): Promise<${rType}>;`); |
| 979 | } else { |
| 980 | lines.push(` ${name}(): Promise<${rType}>;`); |
| 981 | } |
| 982 | } |
| 983 | lines.push(`}`); |
| 984 | lines.push(""); |
| 985 | } |
| 986 | |
| 987 | lines.push(`/** All client global API handler groups. */`); |
| 988 | lines.push(`export interface ClientGlobalApiHandlers {`); |
| 989 | for (const [groupName] of groups) { |
| 990 | const interfaceName = toPascalCase(groupName) + "Handler"; |
| 991 | lines.push(` ${groupName}?: ${interfaceName};`); |
| 992 | } |
| 993 | lines.push(`}`); |
| 994 | lines.push(""); |
| 995 | |
| 996 | lines.push(`/**`); |
| 997 | lines.push(` * Register client global API handlers on a JSON-RPC connection.`); |
| 998 | lines.push(` * The server calls these methods to delegate work to the client.`); |
| 999 | lines.push(` * Unlike session-scoped client APIs, these methods carry no implicit`); |
| 1000 | lines.push(` * \`sessionId\` dispatch key — a single set of handlers serves the entire`); |
| 1001 | lines.push(` * connection.`); |
| 1002 | lines.push(` */`); |
| 1003 | lines.push(`export function registerClientGlobalApiHandlers(`); |
| 1004 | lines.push(` connection: MessageConnection,`); |
no test coverage detected
searching dependent graphs…