Report files and version control

A report is one JSON document. That's convenient to load, but every change touches the same big file. @prismbi/prismbi/files stores it as a folder of small, stable files instead, so reviews show exactly what changed and branches merge cleanly.

report.json                          name, version, report filters, page and bookmark order
pages/overview/page.json             page settings and visual order
pages/overview/visuals/cols.json     one file per visual
pages/overview/visuals/year.json
bookmarks/bikes-only.json            one file per bookmark

API #

import { splitReport, joinReport, diffReports, formatDiff, stableStringify } from '@prismbi/prismbi/files';

const files = splitReport(report.toJSON());   // { 'report.json': '…', 'pages/overview/page.json': '…', … }
const def = joinReport(files);                // back to a ReportDefinition (migrated to the current schema)
console.log(formatDiff(diffReports(before, after)));
- page "Overview" › visual "year"
~ page "Overview" › visual "Sales by category" › format.dataLabels.show: true → false
+ page "Details" › visual "kpi"
↕ page order: ["overview","details"] → ["details","overview"]

Command line #

The package installs a prismbi command (npx @prismbi/prismbi runs it without installing):

npx @prismbi/prismbi split report.json reports/sales      # write the folder
npx @prismbi/prismbi join reports/sales report.json       # rebuild one file (stdout without a file name)
npx @prismbi/prismbi diff old.json reports/sales          # either side may be a JSON file or a split folder

diff exits with code 1 when there are changes and 0 when there are none, so it fits in CI checks and pre-commit hooks.

Try it #

▶ Run in playground
import { splitReport, diffReports, formatDiff } from '@prismbi/prismbi/files';

const before = { name: 'Sales', pages: [{ id: 'p1', name: 'Overview', visuals: [{ id: 'v1', type: 'card', fields: { value: 'Total Sales' } }] }] };
const after = { ...before, pages: [{ ...before.pages[0], visuals: [{ ...before.pages[0].visuals[0], type: 'kpi' }] }] };
return { files: Object.keys(splitReport(before)), diff: formatDiff(diffReports(before, after)) };

On the docs site (npm run docs), ▶ Run in playground opens it in an editor next to its output.