eventmodeler 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
import { appendEvent } from '../../lib/file-loader.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves an entity ID to its canonical original.
|
|
4
|
+
* If the entity is a linked copy, returns the original's ID.
|
|
5
|
+
* Otherwise returns the entity ID unchanged.
|
|
6
|
+
*/
|
|
7
|
+
function resolveToOriginal(model, entityId) {
|
|
8
|
+
const event = model.events.get(entityId);
|
|
9
|
+
if (event?.originalNodeId)
|
|
10
|
+
return event.originalNodeId;
|
|
11
|
+
const readModel = model.readModels.get(entityId);
|
|
12
|
+
if (readModel?.originalNodeId)
|
|
13
|
+
return readModel.originalNodeId;
|
|
14
|
+
const screen = model.screens.get(entityId);
|
|
15
|
+
if (screen?.originalNodeId)
|
|
16
|
+
return screen.originalNodeId;
|
|
17
|
+
return entityId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks if an entity is a linked copy (has originalNodeId set).
|
|
21
|
+
*/
|
|
22
|
+
function isLinkedCopy(model, entityId) {
|
|
23
|
+
const event = model.events.get(entityId);
|
|
24
|
+
if (event?.originalNodeId)
|
|
25
|
+
return true;
|
|
26
|
+
const readModel = model.readModels.get(entityId);
|
|
27
|
+
if (readModel?.originalNodeId)
|
|
28
|
+
return true;
|
|
29
|
+
const screen = model.screens.get(entityId);
|
|
30
|
+
if (screen?.originalNodeId)
|
|
31
|
+
return true;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
2
34
|
function flattenFields(fields, prefix = '') {
|
|
3
35
|
const result = [];
|
|
4
36
|
for (const field of fields) {
|
|
@@ -64,7 +96,8 @@ export function mapFields(model, filePath, flowIdentifier, input) {
|
|
|
64
96
|
if (arrowMatch) {
|
|
65
97
|
const sourceName = arrowMatch[1].trim().toLowerCase();
|
|
66
98
|
const targetName = arrowMatch[2].trim().toLowerCase();
|
|
67
|
-
// Find matching flow
|
|
99
|
+
// Find matching flow, preferring flows that don't involve linked copies
|
|
100
|
+
let fallbackFlow = undefined;
|
|
68
101
|
for (const f of model.flows.values()) {
|
|
69
102
|
let sourceEntityName = '';
|
|
70
103
|
let targetEntityName = '';
|
|
@@ -104,16 +137,32 @@ export function mapFields(model, filePath, flowIdentifier, input) {
|
|
|
104
137
|
const sourceMatches = sourceEntityName === sourceName || sourceEntityName.includes(sourceName);
|
|
105
138
|
const targetMatches = targetEntityName === targetName || targetEntityName.includes(targetName);
|
|
106
139
|
if (sourceMatches && targetMatches) {
|
|
107
|
-
|
|
108
|
-
|
|
140
|
+
// Prefer flows that don't involve linked copies
|
|
141
|
+
const involvesLinkedCopy = isLinkedCopy(model, f.sourceId) || isLinkedCopy(model, f.targetId);
|
|
142
|
+
if (!involvesLinkedCopy) {
|
|
143
|
+
flow = f;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
else if (!fallbackFlow) {
|
|
147
|
+
// Keep as fallback in case no non-copy flow is found
|
|
148
|
+
fallbackFlow = f;
|
|
149
|
+
}
|
|
109
150
|
}
|
|
110
151
|
}
|
|
152
|
+
// Use fallback if no non-copy flow was found
|
|
153
|
+
if (!flow && fallbackFlow) {
|
|
154
|
+
flow = fallbackFlow;
|
|
155
|
+
}
|
|
111
156
|
}
|
|
112
157
|
}
|
|
113
158
|
if (!flow) {
|
|
114
159
|
console.error(`Error: Flow not found: ${flowIdentifier}`);
|
|
115
160
|
console.error('Available flows:');
|
|
116
161
|
for (const f of model.flows.values()) {
|
|
162
|
+
// Skip flows where source or target is a linked copy (UI-only elements)
|
|
163
|
+
if (isLinkedCopy(model, f.sourceId) || isLinkedCopy(model, f.targetId)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
117
166
|
const source = getEntityName(model, f.sourceId);
|
|
118
167
|
const target = getEntityName(model, f.targetId);
|
|
119
168
|
console.error(` - ${source}→${target} (${f.id})`);
|
|
@@ -197,19 +246,21 @@ function getEntityName(model, entityId) {
|
|
|
197
246
|
return entityId;
|
|
198
247
|
}
|
|
199
248
|
function getEntityFields(model, entityId) {
|
|
200
|
-
|
|
249
|
+
// Resolve linked copies to their originals to get canonical fields
|
|
250
|
+
const resolvedId = resolveToOriginal(model, entityId);
|
|
251
|
+
const event = model.events.get(resolvedId);
|
|
201
252
|
if (event)
|
|
202
253
|
return event.fields;
|
|
203
|
-
const readModel = model.readModels.get(
|
|
254
|
+
const readModel = model.readModels.get(resolvedId);
|
|
204
255
|
if (readModel)
|
|
205
256
|
return readModel.fields;
|
|
206
|
-
const command = model.commands.get(
|
|
257
|
+
const command = model.commands.get(resolvedId);
|
|
207
258
|
if (command)
|
|
208
259
|
return command.fields;
|
|
209
|
-
const screen = model.screens.get(
|
|
260
|
+
const screen = model.screens.get(resolvedId);
|
|
210
261
|
if (screen)
|
|
211
262
|
return screen.fields;
|
|
212
|
-
const processor = model.processors.get(
|
|
263
|
+
const processor = model.processors.get(resolvedId);
|
|
213
264
|
if (processor)
|
|
214
265
|
return processor.fields;
|
|
215
266
|
return [];
|