MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / collectRefs

Function collectRefs

packages/core/sdk/src/schema-refs.ts:91–119  ·  view source on GitHub ↗
(
  node: unknown,
  defs: ReadonlyMap<string, unknown>,
  found: Set<string> = new Set(),
)

Source from the content-addressed store, hash-verified

89 * e.g. "#/$defs/Address" → "Address", and if Address references City, both.
90 */
91export const collectRefs = (
92 node: unknown,
93 defs: ReadonlyMap<string, unknown>,
94 found: Set<string> = new Set(),
95): Set<string> => {
96 if (node == null || typeof node !== "object") return found;
97 const obj = node as Obj;
98
99 if (typeof obj.$ref === "string") {
100 const name = parseRefName(obj.$ref);
101 if (name && !found.has(name)) {
102 found.add(name);
103 const def = defs.get(name);
104 if (def) collectRefs(def, defs, found);
105 }
106 return found;
107 }
108
109 for (const v of Object.values(obj)) {
110 if (v && typeof v === "object") {
111 if (Array.isArray(v)) {
112 for (const item of v) collectRefs(item, defs, found);
113 } else {
114 collectRefs(v, defs, found);
115 }
116 }
117 }
118 return found;
119};
120
121export const collectReferencedDefinitions = (
122 roots: readonly unknown[],

Callers 1

Calls 3

parseRefNameFunction · 0.85
valuesMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected