Skip to content

Programmatic API

diff(fromXml, toXml, options?)

The main entry point. Returns a DiffResult.

typescript
import { diff } from '@veridtools/dmn-diff'

const result = diff(fromXml, toXml, {
  fromFile: 'before.dmn',  // optional — shows up in meta and renderer output
  toFile:   'after.dmn',
})

Renderers

typescript
import { renderSemantic, renderRows, renderJson, renderXml } from '@veridtools/dmn-diff'

renderSemantic(result)         // human-readable prose
renderRows(result)             // table with +/- rows
renderJson(result)             // JSON.stringify of DiffResult
renderXml(fromXml, toXml)     // raw line diff (takes XML strings, not DiffResult)

Filtering changes

typescript
// Breaking changes only
const breaking = result.changes.filter(
  (c) => c.type === 'modified' && c.fieldChanges.some((f) => f.severity === 'breaking')
)

// Changes scoped to a specific decision
const decisionChanges = result.changes.filter((c) => c.path.includes('decision[d1]'))

// All added elements
const added = result.changes.filter((c) => c.type === 'added')

Working with AddedChange

typescript
import type { AddedChange } from '@veridtools/dmn-diff'

for (const c of result.changes) {
  if (c.type === 'added') {
    // c.element contains the full parsed DMN element
    console.log(c.elementType, c.id, c.element['@name'])
  }
}

Working with ModifiedChange

typescript
import type { ModifiedChange } from '@veridtools/dmn-diff'

for (const c of result.changes) {
  if (c.type === 'modified') {
    for (const fc of c.fieldChanges) {
      console.log(`${c.name} (${c.id}).${fc.field}: ${fc.from} → ${fc.to} [${fc.severity}]`)
    }
  }
}

Released under the MIT License.