Is it possible to make a custom bpmnlint rule that calls an async function? I have integrated bpmnlint and bpmn-js-lint into my react project. In doing so, I’m writing a custom bpmnlint that needs to make an api call to verify that the data associated with a task on the diagram is correct. However, creating an async rule that calls await causes the console to print this error:
export ‘default’ (imported as ‘rule_11’) was not found in 'bpmnlint-plugin-rules/rules/test-rule'
In my project, I have a directory called bpmnlint-plugin-rules/rules where all my custom rules are located and here is what my rule looks like:
/** bpmnlint-plugin-rules/rules/test-rule.js */
module.exports = () => {
const check = async (node, reporter) => {
if (is(node, 'bpmn:Task') && node.name) {
const data = await someApiCall();
// do some comparisons with data and node.$attrs
reporter.report(node.id, 'some message');
}
};
return { check };
};
Thanks for updating your post to provide further details!
In bpmnlint evaluating a rule, i.e. check is always synchronous. This is to make sure that rules can be evaluated blazing fast, on the fly, as a user edits a diagram.
What is possible is to define a rule itself. This allows you to load and cache data required for validation before rule evaluation:
module.exports = async function(node, reporter) {
const data = await someApiCall();
function check(node, reporter) {
if (is(node, 'bpmn:Task') && node.name) {
// do some comparisons with data and node.$attrs
reporter.report(node.id, 'some message');
}
};
return { check };
}
Does that help you? If not I’d be interested in some additional details what you are going to lint (and why check-time checks are required for that.
I’m sorry if it’s not allowed to bump old topics, but otherwise, I would have to create exactly the same again.
I’ve stumbled upon this question, and would like to run a async check in a bpmnlint rule to validate Javascript code that is embedded in a script task.
I’m looping over all ServiceTask to extract the body of inputParameters with type Script and language Javascript to verify if the Javascript looks valid.