# dmn-elements

[![Build](https://github.com/zerodep/dmn-elements/actions/workflows/build.yaml/badge.svg)](https://github.com/zerodep/dmn-elements/actions/workflows/build.yaml)[![Coverage Status](https://coveralls.io/repos/github/zerodep/dmn-elements/badge.svg?branch=main)](https://coveralls.io/github/zerodep/dmn-elements?branch=main)

Executable decision elements based on DMN 1.3, including the DMN 1.4 boxed expressions (conditional, filter, for, some, every) and the DMN 1.5 item definition type constraints through a shipped [dmn-moddle grammar extension](docs/API.md#dmn-14-boxed-expressions).

Walks the decision requirement graph (DRG) and evaluates decisions — decision tables and literal expressions — standing on maintained upstream pieces:

- [dmn-moddle](https://github.com/bpmn-io/dmn-moddle) parses DMN XML (host-side, dev dependency)
- [feelin](https://github.com/nikku/feelin) evaluates FEEL expressions and unary tests (peer dependency)

Sibling of [bpmn-elements](https://github.com/paed01/bpmn-elements), sharing its idiom: isomorphic, tree-shakeable, minimal runtime dependencies.

<!-- toc -->

- [Documentation](#documentation)
- [Debug](#debug)
- [DMN conformance](#dmn-conformance)
- [Ecosystem](#ecosystem)

<!-- /toc -->

## Documentation

- [API](docs/API.md) — `Definition`, environment settings, and extensions
- [Examples](docs/Examples.md) — runnable examples

## Debug

Element execution is logged through the pluggable `Logger` environment option — silent by default. To follow the execution tree, pass a [debug](https://www.npmjs.com/package/debug)-backed logger:

```javascript
import Debug from 'debug';
import { Context, Definition, Environment } from 'dmn-elements';

const environment = new Environment({
  Logger(scope) {
    return {
      debug: Debug(`dmn-elements:${scope}`),
      error: Debug(`dmn-elements:error:${scope}`),
      warn: Debug(`dmn-elements:warn:${scope}`),
    };
  },
});
```

Run with `DEBUG=dmn-elements:*`:

```
dmn-elements:dmn:definitions <membershipDefinitions> run decision <fee>
dmn-elements:dmn:definitions <fee> requires decision <category>
dmn-elements:dmn:definitions <category> requires input data <ageInput>
dmn-elements:dmn:inputdata <ageInput> evaluate
dmn-elements:dmn:decision <category> evaluate
dmn-elements:dmn:decisiontable <categoryTable> 1 of 2 rules matched: adultRule, resolving hit policy UNIQUE
dmn-elements:dmn:definitions <category> completed
dmn-elements:dmn:definitions <fee> bound <Category> from decision <category>
dmn-elements:dmn:decision <fee> evaluate
dmn-elements:dmn:decisiontable <feeTable> 1 of 2 rules matched: adultFeeRule, resolving hit policy UNIQUE
dmn-elements:dmn:definitions <fee> completed
```

FEEL evaluation warnings reported by feelin — an unknown variable or context key, an invocation of a missing function, invalid built-in arguments — are logged at `warn` level under the `feel` scope (`DEBUG=dmn-elements:warn:feel`). FEEL yields null in these cases without an error, so this is how a mistyped service or variable name surfaces.

## DMN conformance

Checked against the [DMN TCK](https://github.com/dmn-tck/tck) (October 2026):

- **Compliance level 2: 100%** (126/126 assertions)
- Compliance level 3: 88.6% (3000/3385)
- Overall: 89.0% (3126/3511)

All boxed expressions of DMN 1.3 evaluate — decision tables, literal expressions, contexts, invocations, relations, lists, and function definitions — as do the DMN 1.4 additions (conditional, filter, for, some, every; their TCK cases pass in full), plus decision services, business knowledge models, item definitions, and multi-model imports. The DMN 1.5 changes are covered too: item definition type constraints (no TCK case exercises them yet) and the simplified imported input data binding. The remaining gap is dominated by FEEL edge-case semantics owned by [feelin](https://github.com/nikku/feelin) (arithmetic corner cases, temporal edge cases, range equality).

The full per-case report lives in [scripts/tck/REPORT.md](scripts/tck/REPORT.md) — regenerate it with `npm run test:tck` (it tells you how to fetch the TCK test cases on first run).

# Ecosystem

- [bpmn-elements](https://github.com/paed01/bpmn-elements) — isomorphic BPMN 2.0 execution elements, the sibling this project mirrors
- [bpmn-engine](https://github.com/paed01/bpmn-engine) — BPMN 2.0 execution engine
- [bpmn-middleware](https://github.com/zerodep/bpmn-middleware) — Express middleware exposing the engine over HTTP. Holds example to combine `dmn-elements` with BPMN execution engine
