bpmn-moddle
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -8,7 +8,2 @@ 'use strict'; | ||
function createModel(packages) { | ||
return new Moddle(packages); | ||
} | ||
/** | ||
@@ -15,0 +10,0 @@ * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files. |
{ | ||
"name": "bpmn-moddle", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A moddle wrapper for BPMN 2.0", | ||
@@ -41,3 +41,3 @@ "scripts": { | ||
"load-grunt-tasks": "^0.3.0", | ||
"xsd-schema-validator": "^0.0.3" | ||
"xsd-schema-validator": "^0.1.0" | ||
}, | ||
@@ -47,5 +47,5 @@ "dependencies": { | ||
"sax": "^0.6.0", | ||
"moddle": "^0.4.0", | ||
"moddle-xml": "^0.4.1" | ||
"moddle": "^0.5.0", | ||
"moddle-xml": "^0.5.0" | ||
} | ||
} |
# bpmn-moddle | ||
bpmn-moddle allows you to read and write BPMN 2.0 diagram files in NodeJS and the browser. It uses the [BPMN 2.0 meta-model](http://www.omg.org/spec/BPMN/2.0/) to validate the input and produce correct BPMN 2.0 XML. | ||
[![Build Status](https://travis-ci.org/bpmn-io/bpmn-moddle.svg)](https://travis-ci.org/bpmn-io/bpmn-moddle) | ||
The library is built on top of [moddle](https://github.com/bpmn-io/moddle) / [moddle-xml](https://github.com/bpmn-io/moddle-xml). | ||
Read and write BPMN 2.0 diagram files in NodeJS and the browser. | ||
__bpmn-moddle__ uses the [BPMN 2.0 meta-model](http://www.omg.org/spec/BPMN/2.0/) to validate the input and produce correct BPMN 2.0 XML. The library is built on top of [moddle](https://github.com/bpmn-io/moddle) and [moddle-xml](https://github.com/bpmn-io/moddle-xml). | ||
## Usage | ||
The library is provided as an [npm package](https://www.npmjs.org/package/bpmn-moddle). Bundle it for the web via [browserify](browserify.org). | ||
Get the library via [npm package](https://www.npmjs.org/package/bpmn-moddle). Bundle it for the web using [browserify](http://browserify.org) or [webpack](https://webpack.github.io). | ||
@@ -26,3 +28,3 @@ ```javascript | ||
// update id attribute | ||
definitions.attr('id', 'NEW ID'); | ||
definitions.set('id', 'NEW ID'); | ||
@@ -51,3 +53,3 @@ // add a root element | ||
You need [grunt](gruntjs.com) to build the project. | ||
You need [grunt](http://gruntjs.com) to build the project. | ||
@@ -54,0 +56,0 @@ To run the test suite that includes XSD schema validation you must have a Java JDK installed and properly exposed through the `JAVA_HOME` variable. |
@@ -11,3 +11,2 @@ { | ||
"type": "BPMNPlane", | ||
"association": "A_plane_diagram", | ||
"redefines": "di:Diagram#rootElement" | ||
@@ -18,3 +17,2 @@ }, | ||
"type": "BPMNLabelStyle", | ||
"association": "A_labelStyle_diagram", | ||
"isMany": true | ||
@@ -32,3 +30,2 @@ } | ||
"name": "bpmnElement", | ||
"association": "A_bpmnElement_plane", | ||
"isAttr": true, | ||
@@ -49,3 +46,2 @@ "isReference": true, | ||
"name": "bpmnElement", | ||
"association": "A_bpmnElement_shape", | ||
"isAttr": true, | ||
@@ -73,4 +69,3 @@ "isReference": true, | ||
"name": "label", | ||
"type": "BPMNLabel", | ||
"association": "A_label_shape" | ||
"type": "BPMNLabel" | ||
}, | ||
@@ -90,3 +85,2 @@ { | ||
"type": "BPMNShape", | ||
"association": "A_choreographyActivityShape_participantBandShape", | ||
"isAttr": true, | ||
@@ -105,8 +99,6 @@ "isReference": true | ||
"name": "label", | ||
"type": "BPMNLabel", | ||
"association": "A_label_edge" | ||
"type": "BPMNLabel" | ||
}, | ||
{ | ||
"name": "bpmnElement", | ||
"association": "A_bpmnElement_edge", | ||
"isAttr": true, | ||
@@ -119,3 +111,2 @@ "isReference": true, | ||
"name": "sourceElement", | ||
"association": "A_sourceElement_sourceEdge", | ||
"isAttr": true, | ||
@@ -128,3 +119,2 @@ "isReference": true, | ||
"name": "targetElement", | ||
"association": "A_targetElement_targetEdge", | ||
"isAttr": true, | ||
@@ -152,3 +142,2 @@ "isReference": true, | ||
"type": "BPMNLabelStyle", | ||
"association": "A_labelStyle_label", | ||
"isAttr": true, | ||
@@ -155,0 +144,0 @@ "isReference": true, |
@@ -10,6 +10,9 @@ { | ||
{ | ||
"name": "extension", | ||
"type": "Extension" | ||
}, | ||
{ | ||
"name": "owningDiagram", | ||
"type": "Diagram", | ||
"isReadOnly": true, | ||
"association": "A_rootElement_owningDiagram", | ||
"isVirtual": true, | ||
@@ -22,3 +25,2 @@ "isReference": true | ||
"isReadOnly": true, | ||
"association": "A_ownedElement_owningElement", | ||
"isVirtual": true, | ||
@@ -30,3 +32,2 @@ "isReference": true | ||
"isReadOnly": true, | ||
"association": "A_modelElement_diagramElement", | ||
"isVirtual": true, | ||
@@ -40,3 +41,2 @@ "isReference": true, | ||
"isReadOnly": true, | ||
"association": "A_style_diagramElement", | ||
"isVirtual": true, | ||
@@ -49,3 +49,2 @@ "isReference": true | ||
"isReadOnly": true, | ||
"association": "A_ownedElement_owningElement", | ||
"isVirtual": true, | ||
@@ -74,3 +73,2 @@ "isMany": true | ||
"isReadOnly": true, | ||
"association": "A_source_sourceEdge", | ||
"isVirtual": true, | ||
@@ -83,3 +81,2 @@ "isReference": true | ||
"isReadOnly": true, | ||
"association": "A_target_targetEdge", | ||
"isVirtual": true, | ||
@@ -105,3 +102,2 @@ "isReference": true | ||
"isReadOnly": true, | ||
"association": "A_rootElement_owningDiagram", | ||
"isVirtual": true | ||
@@ -128,3 +124,2 @@ }, | ||
"isReadOnly": true, | ||
"association": "A_ownedStyle_owningDiagram", | ||
"isVirtual": true, | ||
@@ -159,3 +154,2 @@ "isMany": true | ||
"subsettedProperty": "DiagramElement-ownedElement", | ||
"association": "A_planeElement_plane", | ||
"isMany": true | ||
@@ -177,3 +171,2 @@ } | ||
"subsettedProperty": "DiagramElement-ownedElement", | ||
"association": "A_ownedLabel_owningEdge", | ||
"isVirtual": true, | ||
@@ -196,3 +189,2 @@ "isMany": true | ||
"subsettedProperty": "DiagramElement-ownedElement", | ||
"association": "A_ownedLabel_owningShape", | ||
"isVirtual": true, | ||
@@ -219,6 +211,19 @@ "isMany": true | ||
"isAbstract": true | ||
}, | ||
{ | ||
"name": "Extension", | ||
"properties": [ | ||
{ | ||
"name": "values", | ||
"type": "Element", | ||
"isMany": true | ||
} | ||
] | ||
} | ||
], | ||
"associations": [], | ||
"prefix": "di" | ||
"prefix": "di", | ||
"xml": { | ||
"tagAlias": "lowerCase" | ||
} | ||
} |
@@ -109,2 +109,11 @@ var _ = require('lodash'), | ||
function cleanAssociations() { | ||
preSerialize(function(str) { | ||
// remove "association": "Something" lines | ||
return str.replace(/,\n\s+"association": "[^"]+"/g, ''); | ||
}); | ||
} | ||
function parse(file, postParse, done) { | ||
@@ -139,2 +148,4 @@ | ||
this.cleanIDs = cleanIDs; | ||
this.cleanAssociations = cleanAssociations; | ||
this.exportTo = exportTo; | ||
@@ -141,0 +152,0 @@ } |
@@ -22,2 +22,3 @@ 'use strict'; | ||
builder.cleanIDs(); | ||
builder.cleanAssociations(); | ||
@@ -28,3 +29,4 @@ // remove associations | ||
pkg.xml = { | ||
alias: 'lowerCase' | ||
tagAlias: 'lowerCase', | ||
typePrefix: 't' | ||
}; | ||
@@ -84,6 +86,2 @@ | ||
builder.alter('ConditionalEventDefinition#condition', { | ||
serialize: 'xsi:type' | ||
}); | ||
builder.alter('TextAnnotation#text', function(desc) { | ||
@@ -93,3 +91,20 @@ delete desc.isAttr; | ||
builder.alter('Expression', { | ||
isAbstract: true | ||
}); | ||
// serialize Expression as xsi:type | ||
pkg.types.forEach(function(t) { | ||
(t.properties || []).forEach(function(p) { | ||
if (p.type === 'Expression') { | ||
p.serialize = 'xsi:type'; | ||
} | ||
}) | ||
}); | ||
builder.alter('Lane#childLaneSet', { | ||
serialize: 'xsi:type' | ||
}); | ||
// make some references strings rather than references | ||
@@ -158,2 +173,7 @@ // (this way we are able to import it properly) | ||
builder.alter('FormalExpression#body', { | ||
"type": "String", | ||
"isBody": true | ||
}); | ||
builder.exportTo('resources/bpmn/json/bpmn.json'); | ||
@@ -172,2 +192,3 @@ }, done); | ||
builder.cleanIDs(); | ||
builder.cleanAssociations(); | ||
@@ -194,6 +215,30 @@ // remove associations | ||
builder.cleanIDs(); | ||
builder.cleanAssociations(); | ||
pkg.xml = { | ||
tagAlias: 'lowerCase' | ||
}; | ||
// remove associations | ||
pkg.associations = []; | ||
pkg.types.push({ | ||
"name": "Extension", | ||
"properties": [ | ||
{ | ||
"name": "values", | ||
"type": "Element", | ||
"isMany": true | ||
} | ||
] | ||
}); | ||
builder.alter('DiagramElement', function(data) { | ||
data.properties.unshift({ | ||
"name": "extension", | ||
"type": "Extension" | ||
}); | ||
}); | ||
builder.alter('Edge#waypoint', { | ||
@@ -216,2 +261,3 @@ serialize: 'xsi:type' | ||
builder.cleanIDs(); | ||
builder.cleanAssociations(); | ||
@@ -218,0 +264,0 @@ // remove associations |
@@ -304,2 +304,76 @@ 'use strict'; | ||
it('Lane#childLaneSet', function(done) { | ||
// when | ||
fromFile('test/fixtures/bpmn/lane-childLaneSets.part.bpmn', 'bpmn:Lane', function(err, result) { | ||
// then | ||
expect(result).to.jsonEqual({ | ||
$type: 'bpmn:Lane', | ||
id: 'Lane_1', | ||
name: 'Lane', | ||
childLaneSet: { | ||
$type: 'bpmn:LaneSet', | ||
id: 'LaneSet_2', | ||
lanes: [ | ||
{ | ||
$type: 'bpmn:Lane', | ||
id: 'Lane_2', | ||
name: 'Nested Lane' | ||
} | ||
] | ||
} | ||
}); | ||
done(err); | ||
}); | ||
}); | ||
it('SequenceFlow#conditionExpression', function(done) { | ||
// when | ||
fromFile('test/fixtures/bpmn/sequenceFlow-conditionExpression.part.bpmn', 'bpmn:SequenceFlow', function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// then | ||
expect(result).to.jsonEqual({ | ||
$type: 'bpmn:SequenceFlow', | ||
id: 'SequenceFlow_1', | ||
conditionExpression: { | ||
$type: 'bpmn:FormalExpression', | ||
body: '${foo > bar}' | ||
} | ||
}); | ||
done(err); | ||
}); | ||
}); | ||
it('MultiInstanceLoopCharacteristics#completionCondition', function(done) { | ||
// when | ||
fromFile('test/fixtures/bpmn/multiInstanceLoopCharacteristics-completionCondition.part.bpmn', 'bpmn:MultiInstanceLoopCharacteristics', function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// then | ||
expect(result).to.jsonEqual({ | ||
$type: 'bpmn:MultiInstanceLoopCharacteristics', | ||
completionCondition: { | ||
$type: 'bpmn:FormalExpression', | ||
body: '${foo > bar}' | ||
} | ||
}); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
@@ -310,2 +384,59 @@ | ||
it('Extensions', function(done) { | ||
// when | ||
fromFile('test/fixtures/bpmn/di/bpmnDiagram-extension.part.bpmn', 'bpmndi:BPMNDiagram', function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
var expected = { | ||
$type: 'bpmndi:BPMNDiagram', | ||
id: 'BPMNDiagram_1', | ||
plane: { | ||
$type: 'bpmndi:BPMNPlane', | ||
id: 'BPMNPlane_1', | ||
extension: { | ||
$type: 'di:Extension', | ||
values: [ | ||
{ | ||
$type: 'vendor:baz', | ||
baz: 'BAZ' | ||
} | ||
] | ||
}, | ||
planeElement: [ | ||
{ | ||
$type: 'bpmndi:BPMNShape', | ||
id: 'BPMNShape_1', | ||
extension: { | ||
$type: 'di:Extension', | ||
values: [ | ||
{ | ||
$type: 'vendor:bar', | ||
$body: 'BAR' | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
$type: 'bpmndi:BPMNEdge', | ||
id: 'BPMNEdge_1', | ||
extension: { | ||
$type: 'di:Extension' | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
// then | ||
expect(result).to.jsonEqual(expected); | ||
done(err); | ||
}); | ||
}); | ||
it('BPMNShape#bounds (non-ns-attributes)', function(done) { | ||
@@ -316,3 +447,3 @@ | ||
// when | ||
fromFile('test/fixtures/bpmn/di/bpmnshape.part.bpmn', 'bpmndi:BPMNShape', function(err, result) { | ||
fromFile('test/fixtures/bpmn/di/bpmnShape.part.bpmn', 'bpmndi:BPMNShape', function(err, result) { | ||
@@ -328,3 +459,2 @@ var expected = { | ||
expect(result).to.jsonEqual(expected); | ||
expect(result.bounds).to.exist; | ||
@@ -341,3 +471,3 @@ done(err); | ||
// when | ||
fromFile('test/fixtures/bpmn/di/bpmnedge-waypoint.part.bpmn', 'bpmndi:BPMNEdge', function(err, result) { | ||
fromFile('test/fixtures/bpmn/di/bpmnEdge-waypoint.part.bpmn', 'bpmndi:BPMNEdge', function(err, result) { | ||
@@ -364,3 +494,3 @@ // then | ||
// when | ||
fromFile('test/fixtures/bpmn/di/bpmnedge.part.bpmn', 'bpmndi:BPMNEdge', function(err, result) { | ||
fromFile('test/fixtures/bpmn/di/bpmnEdge.part.bpmn', 'bpmndi:BPMNEdge', function(err, result) { | ||
@@ -389,3 +519,3 @@ var expected = { | ||
// when | ||
fromFile('test/fixtures/bpmn/di/bpmndiagram.part.bpmn', 'bpmndi:BPMNDiagram', function(err, result) { | ||
fromFile('test/fixtures/bpmn/di/bpmnDiagram.part.bpmn', 'bpmndi:BPMNDiagram', function(err, result) { | ||
@@ -493,2 +623,48 @@ var expected = { | ||
describe('should import extensions', function() { | ||
it('as attributes', function(done) { | ||
// given | ||
var xml = '<bpmn:sequenceFlow xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/bpmnModel" ' + | ||
'xmlns:foo="http://foobar" foo:bar="BAR" />'; | ||
// when | ||
read(xml, 'bpmn:SequenceFlow', function(err, result, context) { | ||
// then | ||
expect(result.$attrs['foo:bar']).to.eql("BAR"); | ||
done(err); | ||
}); | ||
}); | ||
it('as elements', function(done) { | ||
// when | ||
fromFile('test/fixtures/bpmn/extension-elements.bpmn', 'bpmn:Definitions', function(err, result) { | ||
expect(result).to.jsonEqual({ | ||
$type: 'bpmn:Definitions', | ||
id: 'test', | ||
targetNamespace: 'http://bpmn.io/schema/bpmn', | ||
extensionElements: { | ||
$type : 'bpmn:ExtensionElements', | ||
values : [ | ||
{ $type: 'vendor:info', key: 'bgcolor', value: '#ffffff' }, | ||
{ $type: 'vendor:info', key: 'role', value: '[]' } | ||
] | ||
} | ||
}); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
describe('should read xml documents', function() { | ||
@@ -495,0 +671,0 @@ |
@@ -21,2 +21,3 @@ 'use strict'; | ||
this.timeout(15000); | ||
@@ -78,2 +79,24 @@ it('home-made bpmn model', function(done) { | ||
it('di extensions', function(done) { | ||
// given | ||
fromFile('test/fixtures/bpmn/di-extension.bpmn', function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// when | ||
toXML(result, { format: true }, function(err, xml) { | ||
expect(xml).to.contain('<vendor:baz baz="BAZ" />'); | ||
expect(xml).to.contain('<vendor:bar>BAR</vendor:bar>'); | ||
expect(xml).to.contain('<di:extension />'); | ||
validate(err, xml, done); | ||
}); | ||
}); | ||
}); | ||
it('complex process / extensionElements', function(done) { | ||
@@ -112,3 +135,21 @@ | ||
it('xsi:type', function(done) { | ||
// given | ||
fromFile('test/fixtures/bpmn/xsi-type.bpmn', function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// when | ||
toXML(result, { format: true }, function(err, xml) { | ||
validate(err, xml, done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -77,2 +77,33 @@ var _ = require('lodash'); | ||
it('SequenceFlow#conditionExpression', function(done) { | ||
// given | ||
var sequenceFlow = moddle.create('bpmn:SequenceFlow', { | ||
id: 'SequenceFlow_1' | ||
}); | ||
sequenceFlow.conditionExpression = moddle.create('bpmn:FormalExpression', { body: '${ foo < bar }' }); | ||
var expectedXML = | ||
'<bpmn:sequenceFlow xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' + | ||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + | ||
'id="SequenceFlow_1">\n' + | ||
' <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[${ foo < bar }]]></bpmn:conditionExpression>\n' + | ||
'</bpmn:sequenceFlow>\n'; | ||
// when | ||
write(sequenceFlow, { format: true }, function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// then | ||
expect(result).to.eql(expectedXML); | ||
done(err); | ||
}); | ||
}); | ||
it('BaseElement#documentation', function(done) { | ||
@@ -99,4 +130,2 @@ | ||
console.log(err); | ||
// then | ||
@@ -273,2 +302,77 @@ expect(result).to.eql(expectedXML); | ||
describe('should export extensions', function() { | ||
it('as attributes', function(done) { | ||
// given | ||
var definitions = moddle.create('bpmn:Definitions'); | ||
definitions.set('xmlns:foo', 'http://foobar'); | ||
definitions.set('foo:bar', 'BAR'); | ||
// or alternatively directly assign it to definitions.$attrs | ||
var expectedXML = | ||
'<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' + | ||
'xmlns:foo="http://foobar" foo:bar="BAR" />'; | ||
// when | ||
write(definitions, function(err, result) { | ||
// then | ||
expect(result).to.eql(expectedXML); | ||
done(err); | ||
}); | ||
}); | ||
it('as elements', function(done) { | ||
// given | ||
var vendorBgColor = moddle.createAny('vendor:info', 'http://vendor', { | ||
key: 'bgcolor', | ||
value: '#ffffff' | ||
}); | ||
var vendorRole = moddle.createAny('vendor:info', 'http://vendor', { | ||
key: 'role', | ||
value: '[]' | ||
}); | ||
var extensionElements = moddle.create('bpmn:ExtensionElements', { | ||
values: [ vendorBgColor, vendorRole ] | ||
}); | ||
var definitions = moddle.create('bpmn:Definitions', { extensionElements: extensionElements }); | ||
var expectedXML = | ||
'<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' + | ||
'xmlns:vendor="http://vendor">' + | ||
'<bpmn:extensionElements>' + | ||
'<vendor:info key="bgcolor" value="#ffffff" />' + | ||
'<vendor:info key="role" value="[]" />' + | ||
'</bpmn:extensionElements>' + | ||
'</bpmn:definitions>'; | ||
// when | ||
write(definitions, function(err, result) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// then | ||
expect(result).to.eql(expectedXML); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var BPMN_XSD = 'resources/bpmn/xsd/BPMN20.xsd'; | ||
var BPMN_XSD = 'test/fixtures/xsd/BPMN20.xsd'; | ||
@@ -8,0 +8,0 @@ var Helper = require('./helper'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
873470
72
5040
71
+ Addedmoddle@0.5.1(transitive)
+ Addedmoddle-xml@0.5.1(transitive)
- Removedmoddle@0.4.0(transitive)
- Removedmoddle-xml@0.4.1(transitive)
Updatedmoddle@^0.5.0
Updatedmoddle-xml@^0.5.0