(className: string, node: Record<string, unknown>, classes: string[])
| 1760 | } |
| 1761 | |
| 1762 | function emitServerApiClass(className: string, node: Record<string, unknown>, classes: string[]): string[] { |
| 1763 | const parts: string[] = []; |
| 1764 | const lines: string[] = []; |
| 1765 | const displayName = className.replace(/^Server/, "").replace(/Api$/, ""); |
| 1766 | const subGroups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); |
| 1767 | |
| 1768 | lines.push(`/// <summary>Provides server-scoped ${displayName} APIs.</summary>`); |
| 1769 | const groupExperimental = isNodeFullyExperimental(node); |
| 1770 | const groupDeprecated = isNodeFullyDeprecated(node); |
| 1771 | if (groupExperimental) { |
| 1772 | pushExperimentalAttribute(lines); |
| 1773 | } |
| 1774 | if (groupDeprecated) { |
| 1775 | pushObsoleteAttributes(lines); |
| 1776 | } |
| 1777 | lines.push(`public sealed class ${className}`); |
| 1778 | lines.push(`{`); |
| 1779 | lines.push(` private readonly JsonRpc _rpc;`); |
| 1780 | lines.push(""); |
| 1781 | lines.push(` internal ${className}(JsonRpc rpc)`); |
| 1782 | lines.push(` {`); |
| 1783 | lines.push(` _rpc = rpc;`); |
| 1784 | lines.push(` }`); |
| 1785 | |
| 1786 | for (const [key, value] of Object.entries(node)) { |
| 1787 | if (!isRpcMethod(value)) continue; |
| 1788 | emitServerInstanceMethod(key, value, lines, classes, " ", groupExperimental, groupDeprecated); |
| 1789 | } |
| 1790 | |
| 1791 | for (const [subGroupName] of subGroups) { |
| 1792 | const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 1793 | const propertyName = toPascalCase(subGroupName); |
| 1794 | lines.push(""); |
| 1795 | lines.push(` /// <summary>${propertyName} APIs.</summary>`); |
| 1796 | lines.push( |
| 1797 | ` public ${subClassName} ${propertyName} =>`, |
| 1798 | ` field ??`, |
| 1799 | ` Interlocked.CompareExchange(ref field, new(_rpc), null) ??`, |
| 1800 | ` field;` |
| 1801 | ); |
| 1802 | } |
| 1803 | |
| 1804 | lines.push(`}`); |
| 1805 | parts.push(lines.join("\n")); |
| 1806 | |
| 1807 | for (const [subGroupName, subGroupNode] of subGroups) { |
| 1808 | const subClassName = className.replace(/Api$/, "") + toPascalCase(subGroupName) + "Api"; |
| 1809 | parts.push(...emitServerApiClass(subClassName, subGroupNode as Record<string, unknown>, classes)); |
| 1810 | } |
| 1811 | |
| 1812 | return parts; |
| 1813 | } |
| 1814 | |
| 1815 | function emitServerInstanceMethod( |
| 1816 | name: string, |
no test coverage detected
searching dependent graphs…