chore(deps): update to bpmn-moddle v7.0.1

Adds awaitable import and export apis.

Related to https://github.com/bpmn-io/bpmn-js/issues/812
This commit is contained in:
Oguz 2020-04-16 07:49:59 +02:00 committed by Nico Rehwaldt
parent 6bff933d92
commit 506321eafd
6 changed files with 76 additions and 46 deletions

View File

@ -104,26 +104,26 @@ BaseViewer.prototype.importXML = function(xml, bpmnDiagram, done) {
// allow xml manipulation // allow xml manipulation
xml = this._emit('import.parse.start', { xml: xml }) || xml; xml = this._emit('import.parse.start', { xml: xml }) || xml;
this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) { this._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
var definitions = result.rootElement;
var references = result.references;
var parseWarnings = result.warnings;
var elementsById = result.elementsById;
var context = {
elementsById: elementsById,
references: references,
warnings: parseWarnings
};
// hook in post parse listeners + // hook in post parse listeners +
// allow definitions manipulation // allow definitions manipulation
definitions = self._emit('import.parse.complete', { definitions = self._emit('import.parse.complete', {
error: err, error: null,
definitions: definitions, definitions: definitions,
context: context context: context
}) || definitions; }) || definitions;
var parseWarnings = context.warnings;
if (err) {
err = checkValidationError(err);
self._emit('import.done', { error: err, warnings: parseWarnings });
return done(err, parseWarnings);
}
self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) { self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
var allWarnings = [].concat(parseWarnings, importWarnings || []); var allWarnings = [].concat(parseWarnings, importWarnings || []);
@ -131,6 +131,17 @@ BaseViewer.prototype.importXML = function(xml, bpmnDiagram, done) {
done(err, allWarnings); done(err, allWarnings);
}); });
}).catch(function(err) {
self._emit('import.parse.complete', {
error: err
});
err = checkValidationError(err);
self._emit('import.done', { error: err, warnings: err.warnings });
return done(err, err.warnings);
}); });
}; };
@ -263,23 +274,27 @@ BaseViewer.prototype.saveXML = function(options, done) {
definitions: definitions definitions: definitions
}) || definitions; }) || definitions;
this._moddle.toXML(definitions, options, function(err, xml) { this._moddle.toXML(definitions, options).then(function(result) {
var xml = result.xml;
try { try {
xml = self._emit('saveXML.serialized', { xml = self._emit('saveXML.serialized', {
error: err, error: null,
xml: xml xml: xml
}) || xml; }) || xml;
self._emit('saveXML.done', { self._emit('saveXML.done', {
error: err, error: null,
xml: xml xml: xml
}); });
} catch (e) { } catch (e) {
console.error('error in saveXML life-cycle listener', e); console.error('error in saveXML life-cycle listener', e);
} }
done(err, xml); done(null, xml);
}).catch(function(err) {
done(err);
}); });
}; };
@ -650,4 +665,4 @@ function addProjectLogo(container) {
}); });
} }
/* </project-logo> */ /* </project-logo> */

14
package-lock.json generated
View File

@ -1107,13 +1107,13 @@
"dev": true "dev": true
}, },
"bpmn-moddle": { "bpmn-moddle": {
"version": "6.0.6", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/bpmn-moddle/-/bpmn-moddle-6.0.6.tgz", "resolved": "https://registry.npmjs.org/bpmn-moddle/-/bpmn-moddle-7.0.1.tgz",
"integrity": "sha512-GbriI2Jt+qiLCaZV/oo9B7PM1fzBz+Mt0ls1irAXEUZek9VMaM71lL0KiN2wCHMcvEVqCMQLMdR9hTW42ji/iQ==", "integrity": "sha512-Y9zLrDi39L+I2IdYR+9cdef8asyhhQsJdDghhfvUicflZ7ayzopt8hpdzhkwGai1KMVGc8izn/BUB9kK8F12Og==",
"requires": { "requires": {
"min-dash": "^3.0.0", "min-dash": "^3.0.0",
"moddle": "^5.0.1", "moddle": "^5.0.1",
"moddle-xml": "^8.0.7" "moddle-xml": "^9.0.1"
} }
}, },
"brace-expansion": { "brace-expansion": {
@ -5837,9 +5837,9 @@
} }
}, },
"moddle-xml": { "moddle-xml": {
"version": "8.0.7", "version": "9.0.1",
"resolved": "https://registry.npmjs.org/moddle-xml/-/moddle-xml-8.0.7.tgz", "resolved": "https://registry.npmjs.org/moddle-xml/-/moddle-xml-9.0.1.tgz",
"integrity": "sha512-ynoIED3UwDuvhwpLzSjBX2qXAAgXeMvkjU0xlG2Q9eZGHakNOFJ6TYHEnEOSuaxUrGe3k5c2rZ8jMM7nvlpU7g==", "integrity": "sha512-AXT3C1XGxo2h2ckk9hz62MY/spDobyhR+A2o30it0ZAO/NFDWpzYm+y/WeC52XrWi/MzUrVz8JVtfJu+W2DESA==",
"requires": { "requires": {
"min-dash": "^3.0.0", "min-dash": "^3.0.0",
"moddle": "^5.0.1", "moddle": "^5.0.1",

View File

@ -81,7 +81,7 @@
"webpack": "^4.35.3" "webpack": "^4.35.3"
}, },
"dependencies": { "dependencies": {
"bpmn-moddle": "^6.0.6", "bpmn-moddle": "^7.0.1",
"css.escape": "^1.5.1", "css.escape": "^1.5.1",
"diagram-js": "^6.6.1", "diagram-js": "^6.6.1",
"diagram-js-direct-editing": "^1.6.1", "diagram-js-direct-editing": "^1.6.1",

View File

@ -3,9 +3,9 @@ import BpmnModdle from 'bpmn-moddle';
describe('bpmn-moddle', function() { describe('bpmn-moddle', function() {
function parse(xml, done) { function parse(xml) {
var moddle = new BpmnModdle(); var moddle = new BpmnModdle();
moddle.fromXML(xml, 'bpmn:Definitions', done); return moddle.fromXML(xml, 'bpmn:Definitions');
} }
@ -22,11 +22,9 @@ describe('bpmn-moddle', function() {
'</bpmn2:definitions>'; '</bpmn2:definitions>';
// when // when
parse(xml, function(err, definitions) { parse(xml).then(function(result) {
if (err) { var definitions = result.rootElement;
return done(err);
}
// then // then
expect(definitions.id).to.equal('simple'); expect(definitions.id).to.equal('simple');
@ -36,6 +34,8 @@ describe('bpmn-moddle', function() {
expect(definitions.rootElements[0].id).to.equal('Process_1'); expect(definitions.rootElements[0].id).to.equal('Process_1');
done(); done();
}).catch(function(err) {
done(err);
}); });
}); });
@ -47,18 +47,17 @@ describe('bpmn-moddle', function() {
var start = new Date().getTime(); var start = new Date().getTime();
// when // when
parse(xml, function(err) { parse(xml).then(function() {
// then
// parsing a XML document should not take too long // parsing a XML document should not take too long
expect((new Date().getTime() - start)).to.be.below(1000); expect((new Date().getTime() - start)).to.be.below(1000);
done();
}).catch(function(err) {
done(err); done(err);
}); });
// then
// everything should be a.o.k
}); });
}); });
}); });

View File

@ -35,7 +35,9 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, function(err, definitions, context, moddle) { createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
// when // when
walker.handleDefinitions(definitions); walker.handleDefinitions(definitions);
@ -46,6 +48,9 @@ describe('import - BpmnTreeWalker', function() {
expect(errorSpy.notCalled).to.be.true; expect(errorSpy.notCalled).to.be.true;
done(); done();
}).catch(function(err) {
done(err);
}); });
}); });
@ -63,7 +68,10 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, function(err, definitions, context, moddle) { createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
var subProcess = findElementWithId(definitions, 'SubProcess_1'); var subProcess = findElementWithId(definitions, 'SubProcess_1');
var plane = definitions.diagrams[0].plane, var plane = definitions.diagrams[0].plane,
@ -83,6 +91,9 @@ describe('import - BpmnTreeWalker', function() {
expect(errorSpy.notCalled).to.be.true; expect(errorSpy.notCalled).to.be.true;
done(); done();
}).catch(function(err) {
done(err);
}); });
}); });
@ -100,7 +111,9 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, function(err, definitions, context, moddle) { createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
var element = findElementWithId(definitions, 'SubProcess_1'); var element = findElementWithId(definitions, 'SubProcess_1');
@ -116,6 +129,9 @@ describe('import - BpmnTreeWalker', function() {
expect(errorSpy.calledOnce).to.be.true; expect(errorSpy.calledOnce).to.be.true;
done(); done();
}).catch(function(err) {
done(err);
}); });
}); });
@ -127,9 +143,7 @@ describe('import - BpmnTreeWalker', function() {
function createModdle(xml, done) { function createModdle(xml, done) {
var moddle = new BpmnModdle(); var moddle = new BpmnModdle();
moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) { return moddle.fromXML(xml, 'bpmn:Definitions');
done(err, definitions, context, moddle);
});
} }
function createWalker(listeners) { function createWalker(listeners) {
@ -174,4 +188,4 @@ function findElementWithId(definitions, id) {
return findElement(rootElement) || foundElement; return findElement(rootElement) || foundElement;
} }
}, null); }, null);
} }

View File

@ -50,7 +50,9 @@ describe('import - Importer', function() {
var moddle = new BpmnModdle(); var moddle = new BpmnModdle();
moddle.fromXML(xml, function(err, definitions) { moddle.fromXML(xml).then(function(result) {
var definitions = result.rootElement;
var selectedDiagram = find(definitions.diagrams, function(element) { var selectedDiagram = find(definitions.diagrams, function(element) {
return element.id === diagramId; return element.id === diagramId;
@ -711,4 +713,4 @@ function expectChildren(diagram, parent, children) {
expect(existingChildrenGfx).to.eql(expectedChildrenGfx); expect(existingChildrenGfx).to.eql(expectedChildrenGfx);
}); });
} }