MCPcopy Index your code
hub / github.com/github/copilot-sdk / emitApiGroup

Function emitApiGroup

scripts/codegen/go.ts:4006–4049  ·  view source on GitHub ↗
(
    lines: string[],
    apiName: string,
    node: Record<string, unknown>,
    isSession: boolean,
    serviceName: string,
    resolveType: (name: string) => string,
    fields: Map<string, Map<string, GoExtractedField>>,
    unionInfos: Map<string, GoDiscriminatedUnionInfo>,
    groupExperimental: boolean,
    groupDeprecated: boolean = false
)

Source from the content-addressed store, hash-verified

4004}
4005
4006function emitApiGroup(
4007 lines: string[],
4008 apiName: string,
4009 node: Record<string, unknown>,
4010 isSession: boolean,
4011 serviceName: string,
4012 resolveType: (name: string) => string,
4013 fields: Map<string, Map<string, GoExtractedField>>,
4014 unionInfos: Map<string, GoDiscriminatedUnionInfo>,
4015 groupExperimental: boolean,
4016 groupDeprecated: boolean = false
4017): void {
4018 const subGroups = sortByPascalName(Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)));
4019 const methods = sortByPascalName(Object.entries(node).filter(([, v]) => isRpcMethod(v)));
4020
4021 if (groupDeprecated) {
4022 pushGoComment(lines, `Deprecated: ${apiName} contains deprecated APIs that will be removed in a future version.`);
4023 }
4024 if (groupExperimental) {
4025 pushGoExperimentalApiComment(lines, apiName);
4026 }
4027 lines.push(`type ${apiName} ${serviceName}`);
4028 lines.push(``);
4029
4030 for (const [key, value] of methods) {
4031 if (!isRpcMethod(value)) continue;
4032 emitMethod(lines, apiName, key, value, isSession, resolveType, fields, unionInfos, groupExperimental, false, groupDeprecated);
4033 }
4034
4035 for (const [subGroupName, subGroupNode] of subGroups) {
4036 const subApiName = apiName.replace(/API$/, "") + toGoFieldName(subGroupName) + "API";
4037 const subGroupExperimental = isNodeFullyExperimental(subGroupNode as Record<string, unknown>);
4038 const subGroupDeprecated = isNodeFullyDeprecated(subGroupNode as Record<string, unknown>);
4039 emitApiGroup(lines, subApiName, subGroupNode as Record<string, unknown>, isSession, serviceName, resolveType, fields, unionInfos, subGroupExperimental, subGroupDeprecated);
4040
4041 if (subGroupExperimental) {
4042 pushGoExperimentalSubApiComment(lines, toGoFieldName(subGroupName));
4043 }
4044 lines.push(`func (s *${apiName}) ${toGoFieldName(subGroupName)}() *${subApiName} {`);
4045 lines.push(`\treturn (*${subApiName})(s)`);
4046 lines.push(`}`);
4047 lines.push(``);
4048 }
4049}
4050
4051function emitRpcWrapper(lines: string[], node: Record<string, unknown>, isSession: boolean, resolveType: (name: string) => string, fields: Map<string, Map<string, GoExtractedField>>, unionInfos: Map<string, GoDiscriminatedUnionInfo>, classPrefix: string = ""): void {
4052 const groups = sortByPascalName(Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)));

Callers 1

emitRpcWrapperFunction · 0.85

Calls 10

sortByPascalNameFunction · 0.85
pushGoCommentFunction · 0.85
toGoFieldNameFunction · 0.85
isNodeFullyExperimentalFunction · 0.85
isNodeFullyDeprecatedFunction · 0.85
isRpcMethodFunction · 0.70
emitMethodFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…