Nitrogen Peroxide Monoxide

    moddle-context-serializer

    2.1.0 • Public • Published

    bpmn-moddle context serializer

    Make bpmn-moddle context serializable and mapped to behaviour functions

    Build StatusCoverage Status

    Documentation

    The tests are the documentation. Hence, please study test

    A basic example:

    import {default as Serializer, TypeResolver} from 'moddle-context-serializer';
    import * as bpmnElementsBehaviour from 'bpmn-elements';
    
    import EscalationEventDefinition from './mytypes/EscalationEventDefinition';
    
    import BpmnModdle from 'bpmn-moddle';
    
    export async function getSerializedContext(source) {
      const bpmnModdle = new BpmnModdle();
      const moddleContext = await bpmnModdle.fromXML(source);
      const typeResolver = TypeResolver(bpmnElementsBehaviour, extender);
      return Serializer(moddleContext, typeResolver);
    }
    
    function extender(behaviourMapping) {
      behaviourMapping['bpmn:EscalationEventDefinition'] = EscalationEventDefinition;
    }

    Backward compatibility

    In bpmn-moddle@5 the moddle context is served in the third argument of the callback. It has a sligthly different scheme but is still supported.

    Promisified example of how to retrieive the moddle context:

    import BpmnModdle from 'bpmn-moddle';
    
    function getModdleContext(source) {
      const bpmnModdle = new BpmnModdle();
    
      return new Promise((resolve, reject) => {
        bpmnModdle.fromXML(source, (err, definitions, moddleContext) => {
          if (err) return reject(err);
          resolve(moddleContext);
        });
      });
    }

    Install

    npm i moddle-context-serializer

    DownloadsWeekly Downloads

    761

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    63.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • paed01