Skip to main content

Crate bpmnkit

Crate bpmnkit 

Source
Expand description

§bpmnkit

BPMN Kit for Rust: one dependency for BPMN, DMN, FEEL and Camunda forms. Each bpmnkit-* crate is re-exported as a module behind a cargo feature of the same name.

The crates are the Rust twin of the @bpmnkit/* TypeScript packages. The TypeScript implementation is the oracle: both are held to the same conformance cases, so results match.

§Install

cargo add bpmnkit                      # feel, bpmn, dmn, form
cargo add bpmnkit --features full      # everything
cargo add bpmnkit --no-default-features --features feel

§Features

FeatureModuleCrateDefaultWhat it does
feelbpmnkit::feelbpmnkit-feelyesFEEL lexer, parser and evaluator with exact decimals
bpmnbpmnkit::bpmnbpmnkit-bpmnyesBPMN 2.0 model, parser and lossless serializer (Zeebe extensions)
dmnbpmnkit::dmnbpmnkit-dmnyesDMN 1.3 model, parser, serializer and decision evaluation
formbpmnkit::formbpmnkit-formyesCamunda form JSON model, parser and serializer
xmlbpmnkit::xmlbpmnkit-xmlLossless XML reader and writer the BPMN and DMN parsers share
specbpmnkit::specbpmnkit-specShared data: element tables, FEEL built-ins, lint rules, connector templates
compatbpmnkit::compatbpmnkit-compatCamunda 8 version compatibility checks and Camunda 7 to 8 migration
lintbpmnkit::lintbpmnkit-lintBPMN lint and optimize passes, bpmnlint config, DMN and form lint
layoutbpmnkit::layoutbpmnkit-layoutAuto layout of BPMN and DMN diagrams
builderbpmnkit::builderbpmnkit-builderFluent BPMN process builders, DMN decision-table and DRD builders
textbpmnkit::textbpmnkit-textCompact JSON, the process line format and connector lines
renderbpmnkit::renderbpmnkit-renderBPMN to SVG (same bytes as exportSvg), auto layout for models without DI
render-pngbpmnkit::renderbpmnkit-rendersvg_to_png / bpmn_to_png with an embedded font (not in full)
render-system-fontsbpmnkit::renderbpmnkit-renderPNG text may also use the machine’s fonts (not in full)
diffbpmnkit::diffbpmnkit-diffSemantic diff with field-level changes, layout-only moves and a semantic hash
diff-htmlbpmnkit::diffbpmnkit-diffSelf-contained HTML diff viewer and the diff-over-diagram SVG (implies diff, render)
viewerbpmnkit::viewerbpmnkit-viewerOne self-contained HTML viewer page per diagram (same bytes as viewer-lite toHtml), or its head/body/scripts parts
fullAll of the above except the PNG features

A feature turns on the crates it needs; for example text also builds bpmn, dmn and layout, but only the modules you name are re-exported.

For a size-bound build (such as WebAssembly), depend on bpmnkit-feel or bpmnkit-dmn directly with default-features = false to leave out the IANA time zone table and the full regex engine.

§Example

use bpmnkit::dmn::{evaluate_decision_table, parse_dmn};
use bpmnkit::feel::{evaluate, Context, Value};

// FEEL
let mut vars = Context::new();
vars.insert("score", Value::from(70));
assert_eq!(evaluate("score >= 50", &vars).unwrap(), Value::from(true));

// DMN: a decision table evaluated with the same FEEL context
let xml = r#"<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" id="d" name="D" namespace="urn:x">
  <decision id="grade" name="Grade">
    <decisionTable id="t" hitPolicy="FIRST">
      <input id="i"><inputExpression id="ie" typeRef="number"><text>score</text></inputExpression></input>
      <output id="o" name="grade" typeRef="string"/>
      <rule id="r1"><inputEntry id="e1"><text>&gt;= 50</text></inputEntry><outputEntry id="o1"><text>"pass"</text></outputEntry></rule>
      <rule id="r2"><inputEntry id="e2"><text>-</text></inputEntry><outputEntry id="o2"><text>"fail"</text></outputEntry></rule>
    </decisionTable>
  </decision>
</definitions>"#;
let definitions = parse_dmn(xml).unwrap();
let outcome = evaluate_decision_table(&definitions.decisions[0], &vars).unwrap();
assert_eq!(outcome.result, Value::from("pass"));

// BPMN: parse and write back losslessly
let process = bpmnkit::bpmn::parse_bpmn(r#"<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" id="Defs_1" targetNamespace="http://bpmn.io/schema/bpmn">
  <bpmn:process id="p" isExecutable="true">
    <bpmn:startEvent id="s"/>
  </bpmn:process>
</bpmn:definitions>"#).unwrap();
assert_eq!(process.processes[0].id, "p");
let _xml = bpmnkit::bpmn::serialize_bpmn(&process);

Re-exports§

pub use bpmnkit_ascii as ascii;
pub use bpmnkit_bpmn as bpmn;
pub use bpmnkit_builder as builder;
pub use bpmnkit_compat as compat;
pub use bpmnkit_diff as diff;
pub use bpmnkit_dmn as dmn;
pub use bpmnkit_feel as feel;
pub use bpmnkit_form as form;
pub use bpmnkit_layout as layout;
pub use bpmnkit_lint as lint;
pub use bpmnkit_render as render;
pub use bpmnkit_spec as spec;
pub use bpmnkit_text as text;
pub use bpmnkit_viewer as viewer;
pub use bpmnkit_xml as xml;

Modules§

prelude
The names most programs import: use bpmnkit::prelude::*;.
quick
Text in, picture out: process text (or compact JSON) to SVG or PNG in one call.

Enums§

DocKind
What detect found.
Document
A parsed document of any supported kind.
Error
Any failure from a bpmnkit-* crate, or from load itself.

Functions§

detect
Looks at input and says which format it is. Cheap: no full parse, so a Bpmn answer does not promise the XML is valid.
load
detect + parse. Process text and compact JSON are expanded (and laid out) into a BPMN or DMN document. Expansion does not apply the Camunda 8 deploy gate, so a draft still loads; run the lint crate to find what Zeebe would refuse.