Creating outgoing and incoming xml elements using bpmn-moddle

Hello,

I am generating a BPMN xml using bpmn-moddle. I am unable to generate the outgoing and incoming elements for StartEvent, EndEvent and CallActivity. Please help.

Here is what I have so far.

const startEvent = moddle.create('bpmn:StartEvent', {
          id: 'StartEvent_1',
          name: 'Start process event',
        })
        const seqFlow1 = moddle.create('bpmn:SequenceFlow', {
          id: `Flow_${startEvent.get('id')}_${payload.steps[0].id}`,
          sourceRef: startEvent,
          targetRef: callActivity,
        })
        const outgoingStart = moddle.create('bpmn:FlowNode', { outgoing: [seqFlow1] })
        startEvent.get('eventDefinitions').push(outgoingStart) // TODO not correct
        bpmnProcess.get('flowElements').push(seqFlow1)
        bpmnProcess.get('flowElements').push(startEvent)

This is generating an xml like this.

<bpmn2:process id='FirstCut_Gen' name='Process Name' isExecutable='true'>
    <bpmn2:sequenceFlow id='Flow_StartEvent_1_Step1' sourceRef='StartEvent_1' targetRef='Step1' />
    <bpmn2:startEvent id='StartEvent_1' name='Start process event'>
      <bpmn2:flowNode>
        <bpmn2:outgoing>Flow_StartEvent_1_Step1</bpmn2:outgoing>
      </bpmn2:flowNode>
    </bpmn2:startEvent>

Notice the flowNode within the startEvent, this should not be there, only the outgoing is expected.Similar trouble I am having for CallActivity outgoing and incoming elements.I found an example: bpmn-moddle/read.js at master · bpmn-io/bpmn-moddle · GitHub. But not sure how to use that.

Any help in this direction would be great. Thanks.