MCPcopy Index your code
hub / github.com/callstack/agent-device / formatSnapshotText

Function formatSnapshotText

src/utils/output.ts:66–109  ·  view source on GitHub ↗
(
  data: Record<string, unknown>,
  options: SnapshotTextOptions = {},
)

Source from the content-addressed store, hash-verified

64};
65
66export function formatSnapshotText(
67 data: Record<string, unknown>,
68 options: SnapshotTextOptions = {},
69): string {
70 const rawNodes = data.nodes;
71 const nodes = Array.isArray(rawNodes) ? (rawNodes as SnapshotNode[]) : [];
72 const backend = isSnapshotBackend(data.backend) ? data.backend : undefined;
73 const useMobilePresentation = usesMobileSnapshotPresentation(backend);
74 const helperPresentation = buildAndroidHelperPresentationInput(data, nodes, options);
75 const prefix = formatSnapshotMetaPrefix(data);
76 const notices = buildSnapshotNotices(data, nodes, options, helperPresentation);
77 const noticesBlock = notices.length > 0 ? `${notices.join('\n')}\n` : '';
78 const unchanged = options.raw ? null : readUnchangedSnapshot(data);
79 if (unchanged) {
80 return `${prefix}${noticesBlock}${formatUnchangedSnapshotText(unchanged)}\n`;
81 }
82 const visiblePresentation =
83 options.raw || !useMobilePresentation
84 ? null
85 : buildMobileSnapshotPresentation(helperPresentation.nodes);
86 const truncated = Boolean(data.truncated);
87 const displayedNodes = visiblePresentation?.nodes ?? nodes;
88 const visibility =
89 options.raw || !useMobilePresentation
90 ? null
91 : readSnapshotVisibility(
92 data,
93 visiblePresentation,
94 displayedNodes.length,
95 nodes.length,
96 helperPresentation.filteredCount,
97 );
98 const header = formatSnapshotHeader(nodes.length, visibility, truncated);
99 if (nodes.length === 0) {
100 return `${prefix}${header}\n${noticesBlock}`;
101 }
102 if (options.raw) {
103 return `${prefix}${header}\n${noticesBlock}${formatRawSnapshotLines(nodes)}\n`;
104 }
105 if (options.flatten) {
106 return `${prefix}${header}\n${noticesBlock}${formatFlattenedSnapshotLines(displayedNodes)}${formatSnapshotSummaryBlock(visiblePresentation)}\n`;
107 }
108 return `${prefix}${header}\n${noticesBlock}${formatStructuredSnapshotLines(displayedNodes)}${formatSnapshotSummaryBlock(visiblePresentation)}\n`;
109}
110
111function readUnchangedSnapshot(data: Record<string, unknown>): SnapshotUnchanged | null {
112 const raw = data.unchanged;

Callers 3

output.test.tsFile · 0.90
snapshotCliOutputFunction · 0.90

Calls 14

isSnapshotBackendFunction · 0.90
formatSnapshotMetaPrefixFunction · 0.85
buildSnapshotNoticesFunction · 0.85
readUnchangedSnapshotFunction · 0.85
readSnapshotVisibilityFunction · 0.85
formatSnapshotHeaderFunction · 0.85
formatRawSnapshotLinesFunction · 0.85

Tested by

no test coverage detected