Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | 1526x 1526x 1526x 22x 1504x 1504x 1504x 1526x 9x 1526x 9x 1526x 9x 1526x 9x 1526x 1526x 1526x 1524x 2x 1526x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 110x 23x 106x 106x 106x 106x 1526x 1526x 1526x 1526x 1526x 1526x 1526x 1526x 2x 106x 38x 106x 14x 106x 106x 106x 106x 106x 58x 106x 48x 106x 40x 106x 106x 106x 106x | import { applyMergedStateToDocument } from './roundTrip/applyMergedState';
import { parseXmlDocument } from './xmlParser';
import { buildElementIdRenameMap, buildProcessIdRenameMap, remapProcessScopedItems } from './roundTrip/processMatching';
import { buildIdMap, collectNamespaceDeclarations } from './roundTrip/structuralIndexing';
import { didStructuralElementChildOrderChange } from './roundTrip/structuralMerge';
import {
getStableCollectionKey,
mergeElementState,
mergePreservedExtensionElements,
mergeSerializedCollectionState,
mergeSerializedOverlayValue,
mergeSerializedProcessExtensionStates,
mergeSerializedValue,
} from './roundTrip/stateMerging';
import { serializeXmlDocument } from './roundTrip/xmlSerialization';
import {
cloneFlowableState,
type FlowableDocumentState,
} from './types';
import { ensureActivitiNamespace, extractFlowableDocumentState } from './roundTrip/extractDocumentState';
import { findDirectChild, getElementsByLocalName } from './roundTrip/xmlUtils';
export { extractFlowableDocumentState } from './roundTrip/extractDocumentState';
export type FlowableMergeOrigin = 'designer' | 'source';
export interface FlowableMergeOptions {
origin?: FlowableMergeOrigin;
}
function mergeSerializedElementOverlayState(
context: {
mergedState: FlowableDocumentState;
originalState: FlowableDocumentState;
serializedState: FlowableDocumentState;
originalElementsById: ReturnType<typeof buildIdMap>;
serializedElementsById: ReturnType<typeof buildIdMap>;
},
originalElementId: string,
nextId: string,
preserveMissingExtensionContainers: boolean,
): void {
const mergedElementState = context.mergedState.elements[nextId];
const serializedElementState = context.serializedState.elements[nextId];
if (!mergedElementState || !serializedElementState) {
return;
}
const originalElement = context.originalElementsById.get(originalElementId);
const serializedElement = context.serializedElementsById.get(nextId);
const serializedStructuralOrderChanged = Boolean(
originalElement
&& serializedElement
&& didStructuralElementChildOrderChange(originalElement, serializedElement),
);
mergedElementState.documentation = mergeSerializedOverlayValue(
context.originalState.elements[originalElementId]?.documentation || '',
serializedElementState.documentation,
mergedElementState.documentation,
serializedStructuralOrderChanged,
(value) => value === '',
);
mergedElementState.conditionExpression = mergeSerializedOverlayValue(
context.originalState.elements[originalElementId]?.conditionExpression || '',
serializedElementState.conditionExpression,
mergedElementState.conditionExpression,
serializedStructuralOrderChanged,
(value) => value === '',
);
mergedElementState.script = mergeSerializedOverlayValue(
context.originalState.elements[originalElementId]?.script || '',
serializedElementState.script,
mergedElementState.script,
serializedStructuralOrderChanged,
(value) => value === '',
);
mergedElementState.multiInstance = mergeSerializedOverlayValue(
context.originalState.elements[originalElementId]?.multiInstance || null,
serializedElementState.multiInstance,
mergedElementState.multiInstance,
serializedStructuralOrderChanged,
(value) => value === null,
);
mergedElementState.timerDefinition = mergeSerializedValue(
context.originalState.elements[originalElementId]?.timerDefinition || null,
serializedElementState.timerDefinition,
mergedElementState.timerDefinition,
);
mergedElementState.preservedExtensionElements = mergePreservedExtensionElements(
mergedElementState.preservedExtensionElements,
serializedElementState.preservedExtensionElements,
Boolean(serializedElement && findDirectChild(serializedElement, 'extensionElements')),
preserveMissingExtensionContainers,
);
}
function remapElementReferenceId(referenceId: string, elementIdRenameMap: Map<string, string>): string {
if (!referenceId) {
return referenceId;
}
return elementIdRenameMap.get(referenceId) || referenceId;
}
function remapElementStateReferences(
elementState: FlowableDocumentState['elements'][string],
elementIdRenameMap: Map<string, string>,
): FlowableDocumentState['elements'][string] {
return {
...elementState,
compensateActivityRef: remapElementReferenceId(elementState.compensateActivityRef, elementIdRenameMap),
};
}
export function mergeFlowableDocumentXml(
serializedXml: string,
originalXml: string,
incomingState: FlowableDocumentState,
options: FlowableMergeOptions = {},
): string {
const preserveMissingExtensionContainers = options.origin !== 'source';
const serializedState = extractFlowableDocumentState(serializedXml);
const originalDocument = parseXmlDocument(originalXml);
const serializedDocument = parseXmlDocument(serializedXml);
const originalDefinitions = originalDocument.documentElement;
const serializedDefinitions = serializedDocument.documentElement;
Iif (!originalDefinitions || !serializedDefinitions) {
return serializedXml;
}
const originalState = extractFlowableDocumentState(originalXml);
const mergedState = cloneFlowableState(originalState);
const serializedNamespaces = collectNamespaceDeclarations(serializedDefinitions);
const processIdRenameMap = buildProcessIdRenameMap(originalDocument, serializedDocument);
const elementIdRenameMap = buildElementIdRenameMap(originalDocument, serializedDocument);
const originalElementsById = buildIdMap(originalDocument);
const serializedElementsById = buildIdMap(serializedDocument);
const serializedProcessIdsWithExtensionElements = new Set(
getElementsByLocalName(serializedDocument, 'process')
.filter((processElement) => Boolean(findDirectChild(processElement, 'extensionElements')))
.map((processElement) => processElement.getAttribute('id') || ''),
);
mergedState.namespaces = {
...originalState.namespaces,
...serializedNamespaces,
...incomingState.namespaces,
};
Eif (incomingState.targetNamespace !== undefined) {
mergedState.targetNamespace = incomingState.targetNamespace;
}
for (const [incomingId, incomingElementState] of Object.entries(incomingState.elements)) {
const nextId = elementIdRenameMap.get(incomingId) || incomingId;
const originalElementId = originalState.elements[nextId] ? nextId : incomingId;
const remappedIncomingElementState = nextId === incomingId
? incomingElementState
: {
...incomingElementState,
id: nextId,
};
const mergedElementState = mergeElementState(
originalState.elements[originalElementId],
remapElementStateReferences(remappedIncomingElementState, elementIdRenameMap),
);
Eif (mergedElementState) {
mergedState.elements[nextId] = mergedElementState;
mergeSerializedElementOverlayState(
{ mergedState, originalState, serializedState, originalElementsById, serializedElementsById },
originalElementId,
nextId,
preserveMissingExtensionContainers,
);
if (nextId !== originalElementId) {
delete mergedState.elements[originalElementId];
}
}
}
mergedState.signalDefinitions = mergeSerializedCollectionState(
originalState.signalDefinitions,
serializedState.signalDefinitions,
incomingState.signalDefinitions,
(signal) => signal.id,
);
mergedState.messageDefinitions = mergeSerializedCollectionState(
originalState.messageDefinitions,
serializedState.messageDefinitions,
incomingState.messageDefinitions,
(message) => message.id,
);
const remappedIncomingEventListeners = remapProcessScopedItems(incomingState.eventListeners, processIdRenameMap);
const remappedIncomingLocalizations = remapProcessScopedItems(incomingState.localizations, processIdRenameMap);
const remappedIncomingDataObjects = remapProcessScopedItems(incomingState.dataObjects, processIdRenameMap);
const remappedIncomingProcessExtensionElements = remapProcessScopedItems(
incomingState.processExtensionElements,
processIdRenameMap,
);
mergedState.eventListeners = mergeSerializedCollectionState(
originalState.eventListeners,
serializedState.eventListeners,
remappedIncomingEventListeners,
(eventListener) => `${eventListener.processId || ''}:${getStableCollectionKey(eventListener, eventListener.id)}`,
);
mergedState.localizations = mergeSerializedCollectionState(
originalState.localizations,
serializedState.localizations,
remappedIncomingLocalizations,
(localization) => `${localization.processId || ''}:${getStableCollectionKey(localization, localization.id)}`,
);
mergedState.dataObjects = mergeSerializedCollectionState(
originalState.dataObjects,
serializedState.dataObjects,
remappedIncomingDataObjects,
(dataObject) => `${dataObject.processId || ''}:${getStableCollectionKey(dataObject, dataObject.id)}`,
);
mergedState.processExtensionElements = mergeSerializedProcessExtensionStates(
originalState.processExtensionElements,
serializedState.processExtensionElements,
remappedIncomingProcessExtensionElements,
serializedProcessIdsWithExtensionElements,
preserveMissingExtensionContainers,
);
ensureActivitiNamespace(mergedState);
applyMergedStateToDocument({
originalDocument,
serializedDocument,
originalDefinitions,
serializedDefinitions,
originalState,
mergedState,
preserveUnmatchedLexicalNodes: options.origin !== 'source',
});
return serializeXmlDocument(originalDocument);
}
|