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

Function goVariantTargetedMatchSpec

scripts/codegen/go.ts:1434–1477  ·  view source on GitHub ↗
(
    variant: GoDiscriminatedUnionVariant,
    groupVariants: GoDiscriminatedUnionVariant[],
    discriminatorProp: string,
    ctx: GoCodegenCtx
)

Source from the content-addressed store, hash-verified

1432}
1433
1434function goVariantTargetedMatchSpec(
1435 variant: GoDiscriminatedUnionVariant,
1436 groupVariants: GoDiscriminatedUnionVariant[],
1437 discriminatorProp: string,
1438 ctx: GoCodegenCtx
1439): GoVariantMatchSpec {
1440 const termsByVariant = new Map<string, GoJSONMatchTerm[]>();
1441 const termCounts = new Map<string, number>();
1442
1443 for (const groupVariant of groupVariants) {
1444 const terms = goCollectRequiredJSONMatchTerms(groupVariant.schema, ctx, discriminatorProp);
1445 termsByVariant.set(groupVariant.typeName, terms);
1446 for (const term of terms) {
1447 const key = goJSONMatchTermKey(term);
1448 termCounts.set(key, (termCounts.get(key) ?? 0) + 1);
1449 }
1450 }
1451
1452 const variantTerms = termsByVariant.get(variant.typeName) ?? [];
1453 const uniqueTerms = variantTerms.filter((term) => (termCounts.get(goJSONMatchTermKey(term)) ?? 0) < groupVariants.length);
1454 const positiveTerms = removeRedundantGoJSONExistsTerms(uniqueTerms).sort(compareGoJSONMatchTerms);
1455
1456 const variantPositivePathKeys = new Set(positiveTerms.map((term) => goJSONMatchPathKey(term.path)));
1457 const peerPositivePathKeys = new Set<string>();
1458 const peerPositivePaths: string[][] = [];
1459 for (const groupVariant of groupVariants) {
1460 if (groupVariant.typeName === variant.typeName) continue;
1461 const groupTerms = termsByVariant.get(groupVariant.typeName) ?? [];
1462 const peerUniqueTerms = removeRedundantGoJSONExistsTerms(
1463 groupTerms.filter((term) => (termCounts.get(goJSONMatchTermKey(term)) ?? 0) < groupVariants.length)
1464 );
1465 for (const term of peerUniqueTerms) {
1466 const pathKey = goJSONMatchPathKey(term.path);
1467 if (variantPositivePathKeys.has(pathKey) || peerPositivePathKeys.has(pathKey)) continue;
1468 peerPositivePathKeys.add(pathKey);
1469 peerPositivePaths.push(term.path);
1470 }
1471 }
1472
1473 return {
1474 positiveTerms,
1475 negativeExistsPaths: peerPositivePaths.sort(compareGoJSONPaths),
1476 };
1477}
1478
1479function goJSONMatchTermParentPath(term: GoJSONMatchTerm): string[] {
1480 return term.path.slice(0, -1);

Callers 1

Calls 8

goJSONMatchTermKeyFunction · 0.85
goJSONMatchPathKeyFunction · 0.85
setMethod · 0.45
getMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…