eventmodeler 0.1.0

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.
Files changed (37) hide show
  1. package/dist/formatters.d.ts +17 -0
  2. package/dist/formatters.js +482 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +186 -0
  5. package/dist/lib/file-loader.d.ts +5 -0
  6. package/dist/lib/file-loader.js +53 -0
  7. package/dist/projection.d.ts +3 -0
  8. package/dist/projection.js +781 -0
  9. package/dist/slices/export-eventmodel-to-json/index.d.ts +2 -0
  10. package/dist/slices/export-eventmodel-to-json/index.js +296 -0
  11. package/dist/slices/list-chapters/index.d.ts +2 -0
  12. package/dist/slices/list-chapters/index.js +22 -0
  13. package/dist/slices/list-commands/index.d.ts +2 -0
  14. package/dist/slices/list-commands/index.js +21 -0
  15. package/dist/slices/list-events/index.d.ts +2 -0
  16. package/dist/slices/list-events/index.js +21 -0
  17. package/dist/slices/list-slices/index.d.ts +2 -0
  18. package/dist/slices/list-slices/index.js +21 -0
  19. package/dist/slices/mark-slice-status/index.d.ts +2 -0
  20. package/dist/slices/mark-slice-status/index.js +38 -0
  21. package/dist/slices/open-app/index.d.ts +1 -0
  22. package/dist/slices/open-app/index.js +36 -0
  23. package/dist/slices/search/index.d.ts +2 -0
  24. package/dist/slices/search/index.js +175 -0
  25. package/dist/slices/show-chapter/index.d.ts +2 -0
  26. package/dist/slices/show-chapter/index.js +43 -0
  27. package/dist/slices/show-command/index.d.ts +2 -0
  28. package/dist/slices/show-command/index.js +78 -0
  29. package/dist/slices/show-event/index.d.ts +2 -0
  30. package/dist/slices/show-event/index.js +75 -0
  31. package/dist/slices/show-model-summary/index.d.ts +2 -0
  32. package/dist/slices/show-model-summary/index.js +20 -0
  33. package/dist/slices/show-slice/index.d.ts +2 -0
  34. package/dist/slices/show-slice/index.js +239 -0
  35. package/dist/types.d.ts +161 -0
  36. package/dist/types.js +1 -0
  37. package/package.json +40 -0
@@ -0,0 +1,17 @@
1
+ import type { EventModel, Slice, CommandSticky, EventSticky, ReadModelSticky, Screen, Processor, Scenario, Flow } from './types.js';
2
+ export declare function getSliceComponents(model: EventModel, slice: Slice): {
3
+ commands: CommandSticky[];
4
+ events: EventSticky[];
5
+ readModels: ReadModelSticky[];
6
+ screens: Screen[];
7
+ processors: Processor[];
8
+ };
9
+ export declare function getSliceScenarios(model: EventModel, sliceId: string): Scenario[];
10
+ export declare function getRelevantFlows(model: EventModel, componentIds: Set<string>): Flow[];
11
+ export declare function formatSliceXml(model: EventModel, slice: Slice): string;
12
+ export declare function formatSlicesTable(slices: Slice[]): string;
13
+ export declare function formatEventsTable(events: EventSticky[]): string;
14
+ export declare function formatCommandsTable(commands: CommandSticky[]): string;
15
+ export declare function formatModelSummary(model: EventModel): string;
16
+ export declare function formatEventXml(model: EventModel, event: EventSticky): string;
17
+ export declare function formatCommandXml(model: EventModel, command: CommandSticky): string;
@@ -0,0 +1,482 @@
1
+ // Helper to escape XML special characters
2
+ function escapeXml(str) {
3
+ return str
4
+ .replace(/&/g, '&amp;')
5
+ .replace(/</g, '&lt;')
6
+ .replace(/>/g, '&gt;')
7
+ .replace(/"/g, '&quot;')
8
+ .replace(/'/g, '&apos;');
9
+ }
10
+ // Helper to format field values for display
11
+ function formatFieldValues(values) {
12
+ if (!values || Object.keys(values).length === 0)
13
+ return '';
14
+ return Object.entries(values)
15
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
16
+ .join(', ');
17
+ }
18
+ // Format a single field as XML
19
+ function formatFieldXml(field, indent, sourceInfo) {
20
+ const attrs = [
21
+ `name="${escapeXml(field.name)}"`,
22
+ `type="${field.fieldType}"`,
23
+ ];
24
+ if (field.isList)
25
+ attrs.push('list="true"');
26
+ if (field.isGenerated)
27
+ attrs.push('generated="true"');
28
+ if (field.isOptional)
29
+ attrs.push('optional="true"');
30
+ if (field.isUserInput)
31
+ attrs.push('user-input="true"');
32
+ if (sourceInfo)
33
+ attrs.push(`source="${escapeXml(sourceInfo)}"`);
34
+ if (field.subfields && field.subfields.length > 0) {
35
+ let xml = `${indent}<field ${attrs.join(' ')}>\n`;
36
+ for (const subfield of field.subfields) {
37
+ xml += formatFieldXml(subfield, indent + ' ');
38
+ }
39
+ xml += `${indent}</field>\n`;
40
+ return xml;
41
+ }
42
+ return `${indent}<field ${attrs.join(' ')}/>\n`;
43
+ }
44
+ // Get all components that belong to a slice (by position intersection)
45
+ export function getSliceComponents(model, slice) {
46
+ const sliceBounds = {
47
+ left: slice.position.x,
48
+ right: slice.position.x + slice.size.width,
49
+ top: slice.position.y,
50
+ bottom: slice.position.y + slice.size.height,
51
+ };
52
+ function isInSlice(pos, width, height) {
53
+ const centerX = pos.x + width / 2;
54
+ const centerY = pos.y + height / 2;
55
+ return (centerX >= sliceBounds.left &&
56
+ centerX <= sliceBounds.right &&
57
+ centerY >= sliceBounds.top &&
58
+ centerY <= sliceBounds.bottom);
59
+ }
60
+ const commands = [];
61
+ const events = [];
62
+ const readModels = [];
63
+ const screens = [];
64
+ const processors = [];
65
+ for (const cmd of model.commands.values()) {
66
+ if (isInSlice(cmd.position, cmd.width, cmd.height)) {
67
+ commands.push(cmd);
68
+ }
69
+ }
70
+ for (const evt of model.events.values()) {
71
+ if (isInSlice(evt.position, evt.width, evt.height)) {
72
+ events.push(evt);
73
+ }
74
+ }
75
+ for (const rm of model.readModels.values()) {
76
+ if (isInSlice(rm.position, rm.width, rm.height)) {
77
+ readModels.push(rm);
78
+ }
79
+ }
80
+ for (const scr of model.screens.values()) {
81
+ if (isInSlice(scr.position, scr.width, scr.height)) {
82
+ screens.push(scr);
83
+ }
84
+ }
85
+ for (const proc of model.processors.values()) {
86
+ if (isInSlice(proc.position, proc.width, proc.height)) {
87
+ processors.push(proc);
88
+ }
89
+ }
90
+ return { commands, events, readModels, screens, processors };
91
+ }
92
+ // Get scenarios for a slice
93
+ export function getSliceScenarios(model, sliceId) {
94
+ const scenarios = [];
95
+ for (const scenario of model.scenarios.values()) {
96
+ if (scenario.sliceId === sliceId) {
97
+ scenarios.push(scenario);
98
+ }
99
+ }
100
+ return scenarios;
101
+ }
102
+ // Get flows relevant to a set of components
103
+ export function getRelevantFlows(model, componentIds) {
104
+ const flows = [];
105
+ for (const flow of model.flows.values()) {
106
+ if (componentIds.has(flow.sourceId) || componentIds.has(flow.targetId)) {
107
+ flows.push(flow);
108
+ }
109
+ }
110
+ return flows;
111
+ }
112
+ // Build information flow chains for a slice
113
+ function buildInformationFlows(model, components, flows) {
114
+ const componentIds = new Set();
115
+ components.commands.forEach(c => componentIds.add(c.id));
116
+ components.events.forEach(e => componentIds.add(e.id));
117
+ components.readModels.forEach(rm => componentIds.add(rm.id));
118
+ components.screens.forEach(s => componentIds.add(s.id));
119
+ components.processors.forEach(p => componentIds.add(p.id));
120
+ // Build adjacency for flows within the slice
121
+ const internalFlows = flows.filter(f => componentIds.has(f.sourceId) && componentIds.has(f.targetId));
122
+ // Get component name by ID
123
+ function getName(id) {
124
+ const cmd = model.commands.get(id);
125
+ if (cmd)
126
+ return cmd.name;
127
+ const evt = model.events.get(id);
128
+ if (evt)
129
+ return evt.name;
130
+ const rm = model.readModels.get(id);
131
+ if (rm)
132
+ return rm.name;
133
+ const scr = model.screens.get(id);
134
+ if (scr)
135
+ return scr.name;
136
+ const proc = model.processors.get(id);
137
+ if (proc)
138
+ return proc.name;
139
+ return id;
140
+ }
141
+ // Simple representation of flows
142
+ const flowStrings = [];
143
+ for (const flow of internalFlows) {
144
+ flowStrings.push(`${getName(flow.sourceId)} → ${getName(flow.targetId)}`);
145
+ }
146
+ return flowStrings;
147
+ }
148
+ // Format a slice as XML
149
+ export function formatSliceXml(model, slice) {
150
+ const components = getSliceComponents(model, slice);
151
+ const scenarios = getSliceScenarios(model, slice.id);
152
+ const componentIds = new Set();
153
+ components.commands.forEach(c => componentIds.add(c.id));
154
+ components.events.forEach(e => componentIds.add(e.id));
155
+ components.readModels.forEach(rm => componentIds.add(rm.id));
156
+ components.screens.forEach(s => componentIds.add(s.id));
157
+ components.processors.forEach(p => componentIds.add(p.id));
158
+ const flows = getRelevantFlows(model, componentIds);
159
+ const infoFlows = buildInformationFlows(model, components, flows);
160
+ let xml = `<slice name="${escapeXml(slice.name)}" status="${slice.status}">\n`;
161
+ // Components section
162
+ xml += ' <components>\n';
163
+ // Screens
164
+ for (const screen of components.screens) {
165
+ xml += ` <screen name="${escapeXml(screen.name)}">\n`;
166
+ if (screen.fields.length > 0) {
167
+ xml += ' <fields>\n';
168
+ for (const field of screen.fields) {
169
+ const sourceInfo = field.isUserInput ? 'user-input' : undefined;
170
+ xml += formatFieldXml(field, ' ', sourceInfo);
171
+ }
172
+ xml += ' </fields>\n';
173
+ }
174
+ xml += ' </screen>\n';
175
+ }
176
+ // Commands
177
+ for (const command of components.commands) {
178
+ xml += ` <command name="${escapeXml(command.name)}">\n`;
179
+ if (command.fields.length > 0) {
180
+ xml += ' <fields>\n';
181
+ for (const field of command.fields) {
182
+ // Try to find source from incoming flows
183
+ const incomingFlow = flows.find(f => f.targetId === command.id);
184
+ let sourceInfo;
185
+ if (incomingFlow) {
186
+ const sourceScreen = model.screens.get(incomingFlow.sourceId);
187
+ const sourceProcessor = model.processors.get(incomingFlow.sourceId);
188
+ if (sourceScreen) {
189
+ const sourceField = sourceScreen.fields.find(f => f.name === field.name);
190
+ if (sourceField) {
191
+ sourceInfo = `${sourceScreen.name}.${field.name}`;
192
+ }
193
+ }
194
+ else if (sourceProcessor) {
195
+ const sourceField = sourceProcessor.fields.find(f => f.name === field.name);
196
+ if (sourceField) {
197
+ sourceInfo = `${sourceProcessor.name}.${field.name}`;
198
+ }
199
+ }
200
+ }
201
+ xml += formatFieldXml(field, ' ', sourceInfo);
202
+ }
203
+ xml += ' </fields>\n';
204
+ }
205
+ xml += ' </command>\n';
206
+ }
207
+ // Events
208
+ for (const event of components.events) {
209
+ xml += ` <event name="${escapeXml(event.name)}">\n`;
210
+ if (event.fields.length > 0) {
211
+ xml += ' <fields>\n';
212
+ for (const field of event.fields) {
213
+ // Try to find source from incoming flows
214
+ const incomingFlow = flows.find(f => f.targetId === event.id);
215
+ let sourceInfo;
216
+ if (field.isGenerated) {
217
+ sourceInfo = 'generated';
218
+ }
219
+ else if (incomingFlow) {
220
+ const sourceCommand = model.commands.get(incomingFlow.sourceId);
221
+ if (sourceCommand) {
222
+ const sourceField = sourceCommand.fields.find(f => f.name === field.name);
223
+ if (sourceField) {
224
+ sourceInfo = `${sourceCommand.name}.${field.name}`;
225
+ }
226
+ }
227
+ }
228
+ xml += formatFieldXml(field, ' ', sourceInfo);
229
+ }
230
+ xml += ' </fields>\n';
231
+ }
232
+ xml += ' </event>\n';
233
+ }
234
+ // Read Models
235
+ for (const readModel of components.readModels) {
236
+ xml += ` <read-model name="${escapeXml(readModel.name)}">\n`;
237
+ if (readModel.fields.length > 0) {
238
+ xml += ' <fields>\n';
239
+ for (const field of readModel.fields) {
240
+ xml += formatFieldXml(field, ' ');
241
+ }
242
+ xml += ' </fields>\n';
243
+ }
244
+ xml += ' </read-model>\n';
245
+ }
246
+ // Processors
247
+ for (const processor of components.processors) {
248
+ xml += ` <processor name="${escapeXml(processor.name)}">\n`;
249
+ if (processor.fields.length > 0) {
250
+ xml += ' <fields>\n';
251
+ for (const field of processor.fields) {
252
+ xml += formatFieldXml(field, ' ');
253
+ }
254
+ xml += ' </fields>\n';
255
+ }
256
+ xml += ' </processor>\n';
257
+ }
258
+ xml += ' </components>\n';
259
+ // Information flow section
260
+ if (infoFlows.length > 0) {
261
+ xml += ' <information-flow>\n';
262
+ for (const flow of infoFlows) {
263
+ xml += ` ${escapeXml(flow)}\n`;
264
+ }
265
+ xml += ' </information-flow>\n';
266
+ }
267
+ // Scenarios section
268
+ if (scenarios.length > 0) {
269
+ xml += ' <scenarios>\n';
270
+ for (const scenario of scenarios) {
271
+ xml += ` <scenario name="${escapeXml(scenario.name)}">\n`;
272
+ if (scenario.description) {
273
+ xml += ` <description>${escapeXml(scenario.description)}</description>\n`;
274
+ }
275
+ // Given events
276
+ if (scenario.givenEvents.length > 0) {
277
+ xml += ' <given>\n';
278
+ for (const givenEvent of scenario.givenEvents) {
279
+ const evt = model.events.get(givenEvent.eventStickyId);
280
+ const evtName = evt?.name ?? 'UnknownEvent';
281
+ const fieldValuesStr = formatFieldValues(givenEvent.fieldValues);
282
+ if (fieldValuesStr) {
283
+ xml += ` <event type="${escapeXml(evtName)}">${escapeXml(fieldValuesStr)}</event>\n`;
284
+ }
285
+ else {
286
+ xml += ` <event type="${escapeXml(evtName)}"/>\n`;
287
+ }
288
+ }
289
+ xml += ' </given>\n';
290
+ }
291
+ // When command
292
+ if (scenario.whenCommand) {
293
+ const cmd = model.commands.get(scenario.whenCommand.commandStickyId);
294
+ const cmdName = cmd?.name ?? 'UnknownCommand';
295
+ const fieldValuesStr = formatFieldValues(scenario.whenCommand.fieldValues);
296
+ if (fieldValuesStr) {
297
+ xml += ` <when>\n <command type="${escapeXml(cmdName)}">${escapeXml(fieldValuesStr)}</command>\n </when>\n`;
298
+ }
299
+ else {
300
+ xml += ` <when>\n <command type="${escapeXml(cmdName)}"/>\n </when>\n`;
301
+ }
302
+ }
303
+ // Then
304
+ xml += ' <then>\n';
305
+ if (scenario.then.type === 'error') {
306
+ xml += ` <error`;
307
+ if (scenario.then.errorType) {
308
+ xml += ` type="${escapeXml(scenario.then.errorType)}"`;
309
+ }
310
+ xml += `>${escapeXml(scenario.then.errorMessage ?? '')}</error>\n`;
311
+ }
312
+ else if (scenario.then.type === 'events' && scenario.then.expectedEvents) {
313
+ for (const expectedEvent of scenario.then.expectedEvents) {
314
+ const evt = model.events.get(expectedEvent.eventStickyId);
315
+ const evtName = evt?.name ?? 'UnknownEvent';
316
+ const fieldValuesStr = formatFieldValues(expectedEvent.fieldValues);
317
+ if (fieldValuesStr) {
318
+ xml += ` <event type="${escapeXml(evtName)}">${escapeXml(fieldValuesStr)}</event>\n`;
319
+ }
320
+ else {
321
+ xml += ` <event type="${escapeXml(evtName)}"/>\n`;
322
+ }
323
+ }
324
+ }
325
+ else if (scenario.then.type === 'readModelAssertion' && scenario.then.readModelAssertion) {
326
+ const assertion = scenario.then.readModelAssertion;
327
+ const rm = model.readModels.get(assertion.readModelStickyId);
328
+ const rmName = rm?.name ?? 'UnknownReadModel';
329
+ xml += ` <read-model-assertion type="${escapeXml(rmName)}">\n`;
330
+ xml += ` <expected>${escapeXml(formatFieldValues(assertion.expectedFieldValues))}</expected>\n`;
331
+ xml += ' </read-model-assertion>\n';
332
+ }
333
+ xml += ' </then>\n';
334
+ xml += ' </scenario>\n';
335
+ }
336
+ xml += ' </scenarios>\n';
337
+ }
338
+ xml += '</slice>';
339
+ return xml;
340
+ }
341
+ // Format slices list as table
342
+ export function formatSlicesTable(slices) {
343
+ if (slices.length === 0) {
344
+ return 'No slices found.';
345
+ }
346
+ // Sort by position (left to right)
347
+ const sorted = [...slices].sort((a, b) => a.position.x - b.position.x);
348
+ // Calculate column widths
349
+ const nameWidth = Math.max(4, ...sorted.map(s => s.name.length));
350
+ const statusWidth = 11; // 'in-progress' is longest
351
+ let output = '';
352
+ output += `${'NAME'.padEnd(nameWidth)} ${'STATUS'.padEnd(statusWidth)}\n`;
353
+ output += `${'-'.repeat(nameWidth)} ${'-'.repeat(statusWidth)}\n`;
354
+ for (const slice of sorted) {
355
+ const statusDisplay = slice.status === 'in-progress' ? 'in-progress' : slice.status;
356
+ output += `${slice.name.padEnd(nameWidth)} ${statusDisplay.padEnd(statusWidth)}\n`;
357
+ }
358
+ return output;
359
+ }
360
+ // Format events list as table
361
+ export function formatEventsTable(events) {
362
+ if (events.length === 0) {
363
+ return 'No events found.';
364
+ }
365
+ const sorted = [...events].sort((a, b) => a.name.localeCompare(b.name));
366
+ const nameWidth = Math.max(4, ...sorted.map(e => e.name.length));
367
+ const fieldsWidth = 6;
368
+ let output = '';
369
+ output += `${'NAME'.padEnd(nameWidth)} ${'FIELDS'.padEnd(fieldsWidth)}\n`;
370
+ output += `${'-'.repeat(nameWidth)} ${'-'.repeat(fieldsWidth)}\n`;
371
+ for (const evt of sorted) {
372
+ output += `${evt.name.padEnd(nameWidth)} ${String(evt.fields.length).padEnd(fieldsWidth)}\n`;
373
+ }
374
+ return output;
375
+ }
376
+ // Format commands list as table
377
+ export function formatCommandsTable(commands) {
378
+ if (commands.length === 0) {
379
+ return 'No commands found.';
380
+ }
381
+ const sorted = [...commands].sort((a, b) => a.name.localeCompare(b.name));
382
+ const nameWidth = Math.max(4, ...sorted.map(c => c.name.length));
383
+ const fieldsWidth = 6;
384
+ let output = '';
385
+ output += `${'NAME'.padEnd(nameWidth)} ${'FIELDS'.padEnd(fieldsWidth)}\n`;
386
+ output += `${'-'.repeat(nameWidth)} ${'-'.repeat(fieldsWidth)}\n`;
387
+ for (const cmd of sorted) {
388
+ output += `${cmd.name.padEnd(nameWidth)} ${String(cmd.fields.length).padEnd(fieldsWidth)}\n`;
389
+ }
390
+ return output;
391
+ }
392
+ // Format model summary
393
+ export function formatModelSummary(model) {
394
+ let output = `Event Model: ${model.name}\n`;
395
+ output += `${'='.repeat(model.name.length + 13)}\n\n`;
396
+ output += `Slices: ${model.slices.size}\n`;
397
+ output += `Commands: ${model.commands.size}\n`;
398
+ output += `Events: ${model.events.size}\n`;
399
+ output += `Read Models: ${model.readModels.size}\n`;
400
+ output += `Screens: ${model.screens.size}\n`;
401
+ output += `Processors: ${model.processors.size}\n`;
402
+ output += `Scenarios: ${model.scenarios.size}\n`;
403
+ output += `Flows: ${model.flows.size}\n`;
404
+ return output;
405
+ }
406
+ // Format entity details as XML
407
+ export function formatEventXml(model, event) {
408
+ let xml = `<event name="${escapeXml(event.name)}">\n`;
409
+ if (event.fields.length > 0) {
410
+ xml += ' <fields>\n';
411
+ for (const field of event.fields) {
412
+ xml += formatFieldXml(field, ' ');
413
+ }
414
+ xml += ' </fields>\n';
415
+ }
416
+ // Find incoming flows (what produces this event)
417
+ const incomingFlows = [...model.flows.values()].filter(f => f.targetId === event.id);
418
+ // Find outgoing flows (what consumes this event)
419
+ const outgoingFlows = [...model.flows.values()].filter(f => f.sourceId === event.id);
420
+ if (incomingFlows.length > 0) {
421
+ xml += ' <produced-by>\n';
422
+ for (const flow of incomingFlows) {
423
+ const source = model.commands.get(flow.sourceId);
424
+ if (source) {
425
+ xml += ` <command name="${escapeXml(source.name)}"/>\n`;
426
+ }
427
+ }
428
+ xml += ' </produced-by>\n';
429
+ }
430
+ if (outgoingFlows.length > 0) {
431
+ xml += ' <consumed-by>\n';
432
+ for (const flow of outgoingFlows) {
433
+ const target = model.readModels.get(flow.targetId);
434
+ if (target) {
435
+ xml += ` <read-model name="${escapeXml(target.name)}"/>\n`;
436
+ }
437
+ }
438
+ xml += ' </consumed-by>\n';
439
+ }
440
+ xml += '</event>';
441
+ return xml;
442
+ }
443
+ export function formatCommandXml(model, command) {
444
+ let xml = `<command name="${escapeXml(command.name)}">\n`;
445
+ if (command.fields.length > 0) {
446
+ xml += ' <fields>\n';
447
+ for (const field of command.fields) {
448
+ xml += formatFieldXml(field, ' ');
449
+ }
450
+ xml += ' </fields>\n';
451
+ }
452
+ // Find incoming flows (what triggers this command)
453
+ const incomingFlows = [...model.flows.values()].filter(f => f.targetId === command.id);
454
+ // Find outgoing flows (what events this command produces)
455
+ const outgoingFlows = [...model.flows.values()].filter(f => f.sourceId === command.id);
456
+ if (incomingFlows.length > 0) {
457
+ xml += ' <triggered-by>\n';
458
+ for (const flow of incomingFlows) {
459
+ const sourceScreen = model.screens.get(flow.sourceId);
460
+ const sourceProcessor = model.processors.get(flow.sourceId);
461
+ if (sourceScreen) {
462
+ xml += ` <screen name="${escapeXml(sourceScreen.name)}"/>\n`;
463
+ }
464
+ else if (sourceProcessor) {
465
+ xml += ` <processor name="${escapeXml(sourceProcessor.name)}"/>\n`;
466
+ }
467
+ }
468
+ xml += ' </triggered-by>\n';
469
+ }
470
+ if (outgoingFlows.length > 0) {
471
+ xml += ' <produces>\n';
472
+ for (const flow of outgoingFlows) {
473
+ const target = model.events.get(flow.targetId);
474
+ if (target) {
475
+ xml += ` <event name="${escapeXml(target.name)}"/>\n`;
476
+ }
477
+ }
478
+ xml += ' </produces>\n';
479
+ }
480
+ xml += '</command>';
481
+ return xml;
482
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ import * as fs from 'node:fs';
3
+ import { findEventModelFile, loadModel } from './lib/file-loader.js';
4
+ // Import slices
5
+ import { listSlices } from './slices/list-slices/index.js';
6
+ import { listEvents } from './slices/list-events/index.js';
7
+ import { listCommands } from './slices/list-commands/index.js';
8
+ import { showSlice } from './slices/show-slice/index.js';
9
+ import { showEvent } from './slices/show-event/index.js';
10
+ import { showCommand } from './slices/show-command/index.js';
11
+ import { markSliceStatus } from './slices/mark-slice-status/index.js';
12
+ import { showModelSummary } from './slices/show-model-summary/index.js';
13
+ import { exportEventmodelToJson } from './slices/export-eventmodel-to-json/index.js';
14
+ import { openApp } from './slices/open-app/index.js';
15
+ import { search } from './slices/search/index.js';
16
+ import { listChapters } from './slices/list-chapters/index.js';
17
+ import { showChapter } from './slices/show-chapter/index.js';
18
+ const args = process.argv.slice(2);
19
+ function printHelp() {
20
+ console.log(`
21
+ eventmodeler - CLI tool for interacting with Event Model files
22
+
23
+ USAGE:
24
+ eventmodeler Open the Event Modeling app in browser
25
+ eventmodeler <command> [options] Run a CLI command
26
+
27
+ COMMANDS:
28
+ list slices List all slices with their status
29
+ list events List all events
30
+ list commands List all commands
31
+ list chapters List all chapters
32
+
33
+ show slice <name> Show detailed XML view of a slice
34
+ show event <name> Show detailed XML view of an event
35
+ show command <name> Show detailed XML view of a command
36
+ show chapter <name> Show chapter with its slices
37
+
38
+ search <term> Search for entities by name
39
+
40
+ mark <slice-name> <status> Mark a slice's status
41
+ Status: created | in-progress | blocked | done
42
+
43
+ summary Show model summary statistics
44
+
45
+ export json Export entire model as JSON
46
+
47
+ OPTIONS:
48
+ -f, --file <path> Path to .eventmodeler file (default: auto-detect)
49
+ -h, --help Show this help message
50
+
51
+ EXAMPLES:
52
+ eventmodeler list slices
53
+ eventmodeler show slice "Place Order"
54
+ eventmodeler mark "Place Order" done
55
+ eventmodeler summary -f ./my-model.eventmodeler
56
+ `);
57
+ }
58
+ async function main() {
59
+ let fileArg = null;
60
+ const filteredArgs = [];
61
+ for (let i = 0; i < args.length; i++) {
62
+ if (args[i] === '-f' || args[i] === '--file') {
63
+ fileArg = args[++i];
64
+ }
65
+ else if (args[i] === '-h' || args[i] === '--help') {
66
+ printHelp();
67
+ process.exit(0);
68
+ }
69
+ else {
70
+ filteredArgs.push(args[i]);
71
+ }
72
+ }
73
+ const command = filteredArgs[0];
74
+ const subcommand = filteredArgs[1];
75
+ const target = filteredArgs[2];
76
+ if (!command) {
77
+ openApp();
78
+ return;
79
+ }
80
+ const filePath = fileArg ?? await findEventModelFile();
81
+ if (!filePath) {
82
+ console.error('Error: No .eventmodeler file found in current directory.');
83
+ console.error('Use -f <path> to specify a file or run in a directory with an .eventmodeler file.');
84
+ process.exit(1);
85
+ }
86
+ if (!fs.existsSync(filePath)) {
87
+ console.error(`Error: File not found: ${filePath}`);
88
+ process.exit(1);
89
+ }
90
+ const model = loadModel(filePath);
91
+ switch (command) {
92
+ case 'list':
93
+ switch (subcommand) {
94
+ case 'slices':
95
+ listSlices(model);
96
+ break;
97
+ case 'events':
98
+ listEvents(model);
99
+ break;
100
+ case 'commands':
101
+ listCommands(model);
102
+ break;
103
+ case 'chapters':
104
+ listChapters(model);
105
+ break;
106
+ default:
107
+ console.error(`Unknown list target: ${subcommand}`);
108
+ console.error('Valid targets: slices, events, commands, chapters');
109
+ process.exit(1);
110
+ }
111
+ break;
112
+ case 'show':
113
+ switch (subcommand) {
114
+ case 'slice':
115
+ if (!target) {
116
+ console.error('Usage: eventmodeler show slice <name>');
117
+ process.exit(1);
118
+ }
119
+ showSlice(model, target);
120
+ break;
121
+ case 'event':
122
+ if (!target) {
123
+ console.error('Usage: eventmodeler show event <name>');
124
+ process.exit(1);
125
+ }
126
+ showEvent(model, target);
127
+ break;
128
+ case 'command':
129
+ if (!target) {
130
+ console.error('Usage: eventmodeler show command <name>');
131
+ process.exit(1);
132
+ }
133
+ showCommand(model, target);
134
+ break;
135
+ case 'chapter':
136
+ if (!target) {
137
+ console.error('Usage: eventmodeler show chapter <name>');
138
+ process.exit(1);
139
+ }
140
+ showChapter(model, target);
141
+ break;
142
+ default:
143
+ console.error(`Unknown show target: ${subcommand}`);
144
+ console.error('Valid targets: slice, event, command, chapter');
145
+ process.exit(1);
146
+ }
147
+ break;
148
+ case 'search':
149
+ if (!subcommand) {
150
+ console.error('Usage: eventmodeler search <term>');
151
+ process.exit(1);
152
+ }
153
+ search(model, subcommand);
154
+ break;
155
+ case 'mark':
156
+ if (!subcommand || !target) {
157
+ console.error('Usage: eventmodeler mark <slice-name> <status>');
158
+ console.error('Valid statuses: created, in-progress, blocked, done');
159
+ process.exit(1);
160
+ }
161
+ markSliceStatus(model, filePath, subcommand, target);
162
+ break;
163
+ case 'summary':
164
+ showModelSummary(model);
165
+ break;
166
+ case 'export':
167
+ switch (subcommand) {
168
+ case 'json':
169
+ exportEventmodelToJson(model);
170
+ break;
171
+ default:
172
+ console.error(`Unknown export format: ${subcommand}`);
173
+ console.error('Valid formats: json');
174
+ process.exit(1);
175
+ }
176
+ break;
177
+ default:
178
+ console.error(`Unknown command: ${command}`);
179
+ printHelp();
180
+ process.exit(1);
181
+ }
182
+ }
183
+ main().catch((err) => {
184
+ console.error('Error:', err.message);
185
+ process.exit(1);
186
+ });