Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sources = [];
const typeResolver = TypeResolver({
...elements,
...(options.elements || {})
}, defaultTypeResolver);
function defaultTypeResolver(elementTypes) {
if (options.typeResolver) return options.typeResolver(elementTypes);
elementTypes['bpmn:DataObject'] = ProcessOutputDataObject;
}
const pendingSources = [];
if (options.source) pendingSources.push(serializeSource(options.source));
if (options.moddleContext) pendingSources.push(serializeModdleContext(options.moddleContext));
let environment = elements.Environment(options);
const emitter = new EventEmitter();
const engine = Object.assign(emitter, {
execute,
logger,
getDefinitionById,
getDefinitions,
getState,
recover,
resume,
stop,
waitFor,
});
const broker = Broker(engine);
broker.assertExchange('event', 'topic', {autoDelete: false});
function recover(savedState, recoverOptions) {
if (!savedState) return engine;
logger.debug(`<${name}> recover`);
if (!name) name = savedState.name;
if (recoverOptions) environment = elements.Environment(recoverOptions);
if (savedState.environment) environment = environment.recover(savedState.environment);
if (!savedState.definitions) return engine;
loadedDefinitions = savedState.definitions.map((dState) => {
const source = deserialize(JSON.parse(dState.source), typeResolver);
logger.debug(`<${name}> recover ${dState.type} <${dState.id}>`);
const definition = loadDefinition(source);
definition.recover(dState);
return definition;
});
return engine;