(lines: string[], clientSchema: Record<string, unknown>, resolveType: (name: string) => string, unionInfos: Map<string, GoDiscriminatedUnionInfo>)
| 4255 | } |
| 4256 | |
| 4257 | function emitClientSessionApiRegistration(lines: string[], clientSchema: Record<string, unknown>, resolveType: (name: string) => string, unionInfos: Map<string, GoDiscriminatedUnionInfo>): void { |
| 4258 | const groups = collectClientGroups(clientSchema); |
| 4259 | |
| 4260 | for (const { groupName, groupNode, methods } of groups) { |
| 4261 | const interfaceName = clientHandlerInterfaceName(groupName); |
| 4262 | const groupExperimental = isNodeFullyExperimental(groupNode); |
| 4263 | const groupDeprecated = isNodeFullyDeprecated(groupNode); |
| 4264 | if (groupDeprecated) { |
| 4265 | pushGoComment(lines, `Deprecated: ${interfaceName} contains deprecated APIs that will be removed in a future version.`); |
| 4266 | } |
| 4267 | if (groupExperimental) { |
| 4268 | pushGoExperimentalApiComment(lines, interfaceName); |
| 4269 | } |
| 4270 | lines.push(`type ${interfaceName} interface {`); |
| 4271 | for (const method of methods) { |
| 4272 | const resultSchema = getMethodResultSchema(method); |
| 4273 | pushGoRpcMethodComment( |
| 4274 | lines, |
| 4275 | clientHandlerMethodName(method.rpcMethod), |
| 4276 | method, |
| 4277 | resultSchema, |
| 4278 | goRpcParamsDescription(method, getMethodParamsSchema(method)), |
| 4279 | "\t", |
| 4280 | "handles" |
| 4281 | ); |
| 4282 | if (method.deprecated && !groupDeprecated) { |
| 4283 | pushGoComment(lines, `Deprecated: ${clientHandlerMethodName(method.rpcMethod)} is deprecated and will be removed in a future version.`, "\t"); |
| 4284 | } |
| 4285 | if (method.stability === "experimental" && !groupExperimental) { |
| 4286 | pushGoExperimentalMethodComment(lines, clientHandlerMethodName(method.rpcMethod), "\t"); |
| 4287 | } |
| 4288 | const paramsType = resolveType(goParamsTypeName(method)); |
| 4289 | const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined; |
| 4290 | let returnType: string; |
| 4291 | if (isOpaqueJson(resultSchema)) { |
| 4292 | returnType = "any"; |
| 4293 | } else { |
| 4294 | const resultType = nullableInner |
| 4295 | ? resolveType(goNullableResultTypeName(method, nullableInner)) |
| 4296 | : resolveType(goResultTypeName(method)); |
| 4297 | returnType = unionInfos.has(resultType) ? resultType : `*${resultType}`; |
| 4298 | } |
| 4299 | lines.push(`\t${clientHandlerMethodName(method.rpcMethod)}(request *${paramsType}) (${returnType}, error)`); |
| 4300 | } |
| 4301 | lines.push(`}`); |
| 4302 | lines.push(``); |
| 4303 | } |
| 4304 | |
| 4305 | lines.push(`// ClientSessionAPIHandlers provides all client session API handler groups for a session.`); |
| 4306 | lines.push(`type ClientSessionAPIHandlers struct {`); |
| 4307 | for (const { groupName } of groups) { |
| 4308 | lines.push(`\t${toGoFieldName(groupName)} ${clientHandlerInterfaceName(groupName)}`); |
| 4309 | } |
| 4310 | lines.push(`}`); |
| 4311 | lines.push(``); |
| 4312 | |
| 4313 | lines.push(`func clientSessionHandlerError(err error) *jsonrpc2.Error {`); |
| 4314 | lines.push(`\tif err == nil {`); |
no test coverage detected
searching dependent graphs…