MCPcopy Create free account
hub / github.com/hey-api/hey-api / buildGraph

Function buildGraph

packages/shared/src/openApi/shared/utils/graph.ts:222–373  ·  view source on GitHub ↗
(
  root: unknown,
  logger: Logger,
)

Source from the content-addressed store, hash-verified

220 * - dependencies: Map from normalized JSON Pointer string to Set of referenced normalized JSON Pointers
221 */
222export function buildGraph(
223 root: unknown,
224 logger: Logger,
225): {
226 graph: Graph;
227} {
228 const eventBuildGraph = logger.timeEvent('build-graph');
229 const graph: Graph = {
230 nodeDependencies: new Map(),
231 nodes: new Map(),
232 subtreeDependencies: new Map(),
233 transitiveDependencies: new Map(),
234 };
235
236 const walk = ({
237 key,
238 node,
239 parentPointer,
240 pointer,
241 }: {
242 key: string | number | null;
243 node: unknown;
244 parentPointer: string | null;
245 pointer: string;
246 }) => {
247 if (typeof node !== 'object' || node === null) {
248 return;
249 }
250
251 let deprecated: boolean | undefined;
252 let tags: Set<string> | undefined;
253
254 if (typeof node === 'object' && node !== null) {
255 // Check for deprecated property
256 if ('deprecated' in node && typeof node.deprecated === 'boolean') {
257 deprecated = Boolean(node.deprecated);
258 }
259 // If this node has a $ref, record the dependency
260 if ('$ref' in node && typeof node.$ref === 'string') {
261 const refPointer = normalizeJsonPointer(node.$ref);
262 if (!graph.nodeDependencies.has(pointer)) {
263 graph.nodeDependencies.set(pointer, new Set());
264 }
265 graph.nodeDependencies.get(pointer)!.add(refPointer);
266 }
267 // Check for tags property (should be an array of strings)
268 if ('tags' in node && Array.isArray(node.tags)) {
269 tags = new Set(node.tags.filter((tag) => typeof tag === 'string'));
270 }
271 }
272
273 graph.nodes.set(pointer, { deprecated, key, node, parentPointer, tags });
274
275 if (Array.isArray(node)) {
276 node.forEach((item, index) =>
277 walk({
278 key: index,
279 node: item,

Callers 8

graph.test.tsFile · 0.90
readWriteTransformFunction · 0.90
parseV3_0_XFunction · 0.90
parseV2_0_XFunction · 0.90
parseV3_1_XFunction · 0.90
walk.test.tsFile · 0.90
createClientFunction · 0.90
createClientFunction · 0.90

Calls 9

propagateScopesFunction · 0.85
annotateChildScopesFunction · 0.85
timeEventMethod · 0.80
pushMethod · 0.80
sliceMethod · 0.80
walkFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected