(className: string, node: Record<string, unknown>, classes: string[])
| 2116 | } |
| 2117 | |
| 2118 | function emitSessionApiClass(className: string, node: Record<string, unknown>, classes: string[]): string[] { |
| 2119 | const parts: string[] = []; |
| 2120 | const displayName = className.replace(/Api$/, ""); |
| 2121 | const groupExperimental = isNodeFullyExperimental(node); |
| 2122 | const groupDeprecated = isNodeFullyDeprecated(node); |
| 2123 | const experimentalAttr = groupExperimental ? `${experimentalAttribute()}\n` : ""; |
| 2124 | const deprecatedAttr = groupDeprecated ? `${obsoleteAttributeBlock()}\n` : ""; |
| 2125 | const subGroups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); |
| 2126 | |
| 2127 | const lines = [`/// <summary>Provides session-scoped ${displayName} APIs.</summary>`, `${experimentalAttr}${deprecatedAttr}public sealed class ${className}`, `{`, ` private readonly CopilotSession _session;`, ""]; |
| 2128 | lines.push(` internal ${className}(CopilotSession session)`, ` {`, ` _session = session;`); |
| 2129 | lines.push(` }`); |
| 2130 | |
| 2131 | for (const [key, value] of Object.entries(node)) { |
| 2132 | if (!isRpcMethod(value)) continue; |
| 2133 | emitSessionMethod(key, value, lines, classes, " ", groupExperimental, groupDeprecated); |
| 2134 | } |
| 2135 | |
| 2136 | for (const [subGroupName] of subGroups) { |
| 2137 | const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 2138 | const propertyName = toPascalCase(subGroupName); |
| 2139 | lines.push(""); |
| 2140 | lines.push(` /// <summary>${propertyName} APIs.</summary>`); |
| 2141 | lines.push( |
| 2142 | ` public ${subClassName} ${propertyName} =>`, |
| 2143 | ` field ??`, |
| 2144 | ` Interlocked.CompareExchange(ref field, new(_session), null) ??`, |
| 2145 | ` field;` |
| 2146 | ); |
| 2147 | } |
| 2148 | |
| 2149 | lines.push(`}`); |
| 2150 | parts.push(lines.join("\n")); |
| 2151 | |
| 2152 | for (const [subGroupName, subGroupNode] of subGroups) { |
| 2153 | const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 2154 | parts.push(...emitSessionApiClass(subClassName, subGroupNode as Record<string, unknown>, classes)); |
| 2155 | } |
| 2156 | |
| 2157 | return parts; |
| 2158 | } |
| 2159 | |
| 2160 | function collectClientGroups(node: Record<string, unknown>): Array<{ groupName: string; groupNode: Record<string, unknown>; methods: RpcMethod[] }> { |
| 2161 | const groups: Array<{ groupName: string; groupNode: Record<string, unknown>; methods: RpcMethod[] }> = []; |
no test coverage detected
searching dependent graphs…