eventmodeler 0.4.7 → 0.6.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.
- package/dist/api/client-config.js +10 -0
- package/dist/api/generated/client/client.gen.js +235 -0
- package/dist/api/generated/client/index.js +6 -0
- package/dist/api/generated/client/types.gen.js +2 -0
- package/dist/api/generated/client/utils.gen.js +228 -0
- package/dist/api/generated/client.gen.js +4 -0
- package/dist/api/generated/core/auth.gen.js +14 -0
- package/dist/api/generated/core/bodySerializer.gen.js +57 -0
- package/dist/api/generated/core/params.gen.js +100 -0
- package/dist/api/generated/core/pathSerializer.gen.js +106 -0
- package/dist/api/generated/core/queryKeySerializer.gen.js +92 -0
- package/dist/api/generated/core/serverSentEvents.gen.js +133 -0
- package/dist/api/generated/core/types.gen.js +2 -0
- package/dist/api/generated/core/utils.gen.js +87 -0
- package/dist/api/generated/index.js +2 -0
- package/dist/api/generated/sdk.gen.js +4222 -0
- package/dist/api/generated/types.gen.js +2 -0
- package/dist/api/generated/zod.gen.js +7217 -0
- package/dist/commands/add.js +315 -0
- package/dist/commands/auth.js +14 -0
- package/dist/commands/create.js +192 -0
- package/dist/commands/design.js +108 -0
- package/dist/commands/guide.js +15 -0
- package/dist/commands/init.js +21 -0
- package/dist/commands/list-schemas.js +177 -0
- package/dist/commands/list.js +39 -0
- package/dist/commands/loop.js +101 -0
- package/dist/commands/map.js +40 -0
- package/dist/commands/mark.js +27 -0
- package/dist/commands/move.js +35 -0
- package/dist/commands/remove.js +170 -0
- package/dist/commands/rename.js +53 -0
- package/dist/commands/resize.js +30 -0
- package/dist/commands/search.js +14 -0
- package/dist/commands/set.js +199 -0
- package/dist/commands/show-schemas.js +259 -0
- package/dist/commands/show.js +56 -0
- package/dist/commands/summary.js +13 -0
- package/dist/commands/update.js +240 -0
- package/dist/index.js +46 -2379
- package/dist/lib/auth.js +1 -1
- package/dist/lib/config.js +0 -15
- package/dist/lib/excalidraw-schema.js +66 -0
- package/dist/lib/globals.js +8 -0
- package/dist/lib/model.js +11 -0
- package/dist/lib/project-config.js +20 -0
- package/dist/lib/resolve.js +59 -0
- package/dist/lib/scenario.js +15 -0
- package/dist/slices/add-scenario/index.js +2 -206
- package/dist/slices/guide/guides/codegen.js +1 -1
- package/dist/slices/guide/guides/connect-slices.js +12 -37
- package/dist/slices/guide/guides/create-slices.js +110 -140
- package/dist/slices/guide/guides/explore.js +37 -26
- package/dist/slices/guide/guides/information-flow.js +70 -82
- package/dist/slices/guide/guides/scenarios.js +82 -137
- package/dist/slices/guide/index.js +6 -6
- package/dist/slices/help/index.js +96 -0
- package/dist/slices/help/topics/build-codegen.js +109 -0
- package/dist/slices/help/topics/build-slice.js +147 -0
- package/dist/slices/help/topics/check-completeness.js +57 -0
- package/dist/slices/help/topics/connect-slices.js +99 -0
- package/dist/slices/help/topics/explore-model.js +112 -0
- package/dist/slices/help/topics/json-reference.js +188 -0
- package/dist/slices/help/topics/linked-copies.js +89 -0
- package/dist/slices/help/topics/manipulate-canvas.js +150 -0
- package/dist/slices/help/topics/write-scenarios.js +162 -0
- package/dist/slices/init/index.js +10 -4
- package/dist/slices/init/loop.js +60 -0
- package/dist/slices/login/index.js +2 -2
- package/dist/slices/logout/index.js +2 -2
- package/dist/slices/whoami/index.js +11 -36
- package/package.json +8 -3
- package/dist/api/index.d.ts +0 -285
- package/dist/api/index.js +0 -323
- package/dist/cloud/slices/index.d.ts +0 -276
- package/dist/cloud/slices/index.js +0 -406
- package/dist/eventmodeler.js +0 -5646
- package/dist/formatters.d.ts +0 -17
- package/dist/formatters.js +0 -482
- package/dist/index.d.ts +0 -2
- package/dist/lib/auth.d.ts +0 -24
- package/dist/lib/backend.d.ts +0 -43
- package/dist/lib/backend.js +0 -73
- package/dist/lib/chapter-utils.d.ts +0 -13
- package/dist/lib/chapter-utils.js +0 -71
- package/dist/lib/cloud-client.d.ts +0 -69
- package/dist/lib/cloud-client.js +0 -364
- package/dist/lib/config.d.ts +0 -30
- package/dist/lib/diff/merge-rules.d.ts +0 -45
- package/dist/lib/diff/merge-rules.js +0 -210
- package/dist/lib/diff/model-differ.d.ts +0 -8
- package/dist/lib/diff/model-differ.js +0 -568
- package/dist/lib/diff/three-way-merge.d.ts +0 -7
- package/dist/lib/diff/three-way-merge.js +0 -390
- package/dist/lib/diff/types.d.ts +0 -75
- package/dist/lib/diff/types.js +0 -1
- package/dist/lib/element-lookup.d.ts +0 -58
- package/dist/lib/element-lookup.js +0 -126
- package/dist/lib/file-loader.d.ts +0 -8
- package/dist/lib/file-loader.js +0 -108
- package/dist/lib/flow-utils.d.ts +0 -53
- package/dist/lib/flow-utils.js +0 -348
- package/dist/lib/format.d.ts +0 -10
- package/dist/lib/format.js +0 -23
- package/dist/lib/project-config.d.ts +0 -27
- package/dist/lib/slice-utils.d.ts +0 -59
- package/dist/lib/slice-utils.js +0 -140
- package/dist/local/slices/index.d.ts +0 -11
- package/dist/local/slices/index.js +0 -13
- package/dist/projection.d.ts +0 -3
- package/dist/projection.js +0 -828
- package/dist/slices/add-field/index.d.ts +0 -8
- package/dist/slices/add-field/index.js +0 -211
- package/dist/slices/add-scenario/index.d.ts +0 -27
- package/dist/slices/codegen-chapter-events/index.d.ts +0 -2
- package/dist/slices/codegen-chapter-events/index.js +0 -145
- package/dist/slices/codegen-slice/index.d.ts +0 -2
- package/dist/slices/codegen-slice/index.js +0 -448
- package/dist/slices/create-automation-slice/index.d.ts +0 -2
- package/dist/slices/create-automation-slice/index.js +0 -304
- package/dist/slices/create-flow/index.d.ts +0 -2
- package/dist/slices/create-flow/index.js +0 -183
- package/dist/slices/create-state-change-slice/index.d.ts +0 -2
- package/dist/slices/create-state-change-slice/index.js +0 -263
- package/dist/slices/create-state-view-slice/index.d.ts +0 -2
- package/dist/slices/create-state-view-slice/index.js +0 -128
- package/dist/slices/diff/index.d.ts +0 -11
- package/dist/slices/diff/index.js +0 -293
- package/dist/slices/export-eventmodel-to-json/index.d.ts +0 -2
- package/dist/slices/export-eventmodel-to-json/index.js +0 -355
- package/dist/slices/git/index.d.ts +0 -2
- package/dist/slices/git/index.js +0 -125
- package/dist/slices/guide/guides/codegen.d.ts +0 -5
- package/dist/slices/guide/guides/connect-slices.d.ts +0 -5
- package/dist/slices/guide/guides/create-slices.d.ts +0 -5
- package/dist/slices/guide/guides/explore.d.ts +0 -5
- package/dist/slices/guide/guides/information-flow.d.ts +0 -5
- package/dist/slices/guide/guides/scenarios.d.ts +0 -5
- package/dist/slices/guide/index.d.ts +0 -1
- package/dist/slices/import/index.d.ts +0 -8
- package/dist/slices/import/index.js +0 -63
- package/dist/slices/init/index.d.ts +0 -5
- package/dist/slices/list-chapters/index.d.ts +0 -3
- package/dist/slices/list-chapters/index.js +0 -21
- package/dist/slices/list-commands/index.d.ts +0 -3
- package/dist/slices/list-commands/index.js +0 -20
- package/dist/slices/list-events/index.d.ts +0 -3
- package/dist/slices/list-events/index.js +0 -98
- package/dist/slices/list-processors/index.d.ts +0 -3
- package/dist/slices/list-processors/index.js +0 -20
- package/dist/slices/list-readmodels/index.d.ts +0 -3
- package/dist/slices/list-readmodels/index.js +0 -21
- package/dist/slices/list-scenarios/index.d.ts +0 -3
- package/dist/slices/list-scenarios/index.js +0 -35
- package/dist/slices/list-screens/index.d.ts +0 -3
- package/dist/slices/list-screens/index.js +0 -47
- package/dist/slices/list-slices/index.d.ts +0 -3
- package/dist/slices/list-slices/index.js +0 -35
- package/dist/slices/login/index.d.ts +0 -1
- package/dist/slices/logout/index.d.ts +0 -1
- package/dist/slices/map-fields/index.d.ts +0 -2
- package/dist/slices/map-fields/index.js +0 -269
- package/dist/slices/mark-slice-status/index.d.ts +0 -2
- package/dist/slices/mark-slice-status/index.js +0 -31
- package/dist/slices/merge/index.d.ts +0 -19
- package/dist/slices/merge/index.js +0 -147
- package/dist/slices/open-app/index.d.ts +0 -1
- package/dist/slices/remove-field/index.d.ts +0 -8
- package/dist/slices/remove-field/index.js +0 -167
- package/dist/slices/remove-scenario/index.d.ts +0 -2
- package/dist/slices/remove-scenario/index.js +0 -77
- package/dist/slices/search/index.d.ts +0 -3
- package/dist/slices/search/index.js +0 -302
- package/dist/slices/show-actor/index.d.ts +0 -4
- package/dist/slices/show-actor/index.js +0 -115
- package/dist/slices/show-aggregate/index.d.ts +0 -3
- package/dist/slices/show-aggregate/index.js +0 -108
- package/dist/slices/show-aggregate-completeness/index.d.ts +0 -4
- package/dist/slices/show-aggregate-completeness/index.js +0 -181
- package/dist/slices/show-chapter/index.d.ts +0 -3
- package/dist/slices/show-chapter/index.js +0 -195
- package/dist/slices/show-command/index.d.ts +0 -3
- package/dist/slices/show-command/index.js +0 -133
- package/dist/slices/show-completeness/index.d.ts +0 -4
- package/dist/slices/show-completeness/index.js +0 -731
- package/dist/slices/show-event/index.d.ts +0 -3
- package/dist/slices/show-event/index.js +0 -118
- package/dist/slices/show-model-summary/index.d.ts +0 -3
- package/dist/slices/show-model-summary/index.js +0 -31
- package/dist/slices/show-processor/index.d.ts +0 -3
- package/dist/slices/show-processor/index.js +0 -111
- package/dist/slices/show-readmodel/index.d.ts +0 -3
- package/dist/slices/show-readmodel/index.js +0 -158
- package/dist/slices/show-scenario/index.d.ts +0 -3
- package/dist/slices/show-scenario/index.js +0 -196
- package/dist/slices/show-screen/index.d.ts +0 -3
- package/dist/slices/show-screen/index.js +0 -139
- package/dist/slices/show-slice/index.d.ts +0 -3
- package/dist/slices/show-slice/index.js +0 -696
- package/dist/slices/update-field/index.d.ts +0 -15
- package/dist/slices/update-field/index.js +0 -208
- package/dist/slices/whoami/index.d.ts +0 -2
- package/dist/types.d.ts +0 -195
- package/dist/types.js +0 -1
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
// Cloud slice implementations - thin wrappers that call backend CLI endpoints
|
|
2
|
-
// The backend does all the heavy lifting (name resolution, data denormalization)
|
|
3
|
-
import { getBackendUrl } from '../../lib/config.js';
|
|
4
|
-
import { getValidAccessToken } from '../../lib/auth.js';
|
|
5
|
-
// =============================================================================
|
|
6
|
-
// HTTP Client for CLI endpoints
|
|
7
|
-
// =============================================================================
|
|
8
|
-
/**
|
|
9
|
-
* Handle HTTP error responses with user-friendly messages.
|
|
10
|
-
* Tries to extract error detail from response body, falls back to status-based messages.
|
|
11
|
-
*/
|
|
12
|
-
async function handleHttpError(response, path) {
|
|
13
|
-
const text = await response.text().catch(() => '');
|
|
14
|
-
const errorDetail = extractErrorDetail(text);
|
|
15
|
-
switch (response.status) {
|
|
16
|
-
case 401:
|
|
17
|
-
throw new Error(`Authentication required. Run 'eventmodeler login' to authenticate.` +
|
|
18
|
-
(errorDetail ? `\n\nOriginal error: ${errorDetail}` : ''));
|
|
19
|
-
case 403:
|
|
20
|
-
throw new Error(`Permission denied. You may not have access to this model, or you need editor permission for this action.` +
|
|
21
|
-
(errorDetail ? `\n\nOriginal error: ${errorDetail}` : ''));
|
|
22
|
-
case 404:
|
|
23
|
-
throw new Error(errorDetail || `Not found: ${path}`);
|
|
24
|
-
default:
|
|
25
|
-
throw new Error(errorDetail || `HTTP ${response.status}: ${response.statusText}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const GENERIC_ERROR_MESSAGES = new Set([
|
|
29
|
-
'internal server error',
|
|
30
|
-
'bad request',
|
|
31
|
-
'unauthorized',
|
|
32
|
-
'forbidden',
|
|
33
|
-
'not found',
|
|
34
|
-
]);
|
|
35
|
-
function isGenericErrorMessage(value) {
|
|
36
|
-
return GENERIC_ERROR_MESSAGES.has(value.trim().toLowerCase());
|
|
37
|
-
}
|
|
38
|
-
function toStringValue(value) {
|
|
39
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
40
|
-
}
|
|
41
|
-
function collectCandidateMessages(node, out) {
|
|
42
|
-
if (!node || typeof node !== 'object')
|
|
43
|
-
return;
|
|
44
|
-
const obj = node;
|
|
45
|
-
// Prefer richer fields before generic "error".
|
|
46
|
-
for (const key of ['message', 'detail', 'reason', 'description', 'title', 'error']) {
|
|
47
|
-
const value = toStringValue(obj[key]);
|
|
48
|
-
if (value)
|
|
49
|
-
out.push(value);
|
|
50
|
-
}
|
|
51
|
-
const errors = obj.errors;
|
|
52
|
-
if (Array.isArray(errors)) {
|
|
53
|
-
for (const entry of errors) {
|
|
54
|
-
if (typeof entry === 'string') {
|
|
55
|
-
const value = entry.trim();
|
|
56
|
-
if (value)
|
|
57
|
-
out.push(value);
|
|
58
|
-
}
|
|
59
|
-
else if (entry && typeof entry === 'object') {
|
|
60
|
-
collectCandidateMessages(entry, out);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const cause = obj.cause;
|
|
65
|
-
if (cause && typeof cause === 'object') {
|
|
66
|
-
collectCandidateMessages(cause, out);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function extractErrorDetail(text) {
|
|
70
|
-
const body = text.trim();
|
|
71
|
-
if (!body)
|
|
72
|
-
return '';
|
|
73
|
-
try {
|
|
74
|
-
const parsed = JSON.parse(body);
|
|
75
|
-
if (typeof parsed === 'string') {
|
|
76
|
-
return parsed.trim();
|
|
77
|
-
}
|
|
78
|
-
const candidates = [];
|
|
79
|
-
collectCandidateMessages(parsed, candidates);
|
|
80
|
-
if (candidates.length > 0) {
|
|
81
|
-
const specific = candidates.find((value) => !isGenericErrorMessage(value));
|
|
82
|
-
return specific ?? candidates[0];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// Not JSON. Fall back to plain text below.
|
|
87
|
-
}
|
|
88
|
-
// Avoid dumping entire HTML pages from reverse proxies.
|
|
89
|
-
if (body.startsWith('<')) {
|
|
90
|
-
const title = body.match(/<title>([^<]+)<\/title>/i)?.[1]?.trim();
|
|
91
|
-
return title && !isGenericErrorMessage(title) ? title : '';
|
|
92
|
-
}
|
|
93
|
-
return body;
|
|
94
|
-
}
|
|
95
|
-
async function cliGet(path, params) {
|
|
96
|
-
const backendUrl = getBackendUrl();
|
|
97
|
-
const accessToken = await getValidAccessToken();
|
|
98
|
-
// Build query string manually using encodeURIComponent (uses %20 for spaces, not +)
|
|
99
|
-
const queryParts = Object.entries(params)
|
|
100
|
-
.filter(([_, value]) => value !== undefined)
|
|
101
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
102
|
-
const queryString = queryParts.length > 0 ? `?${queryParts.join('&')}` : '';
|
|
103
|
-
const fullUrl = `${backendUrl}${path}${queryString}`;
|
|
104
|
-
const response = await fetch(fullUrl, {
|
|
105
|
-
method: 'GET',
|
|
106
|
-
headers: {
|
|
107
|
-
Accept: 'application/json',
|
|
108
|
-
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
if (!response.ok) {
|
|
112
|
-
await handleHttpError(response, path);
|
|
113
|
-
}
|
|
114
|
-
const text = await response.text();
|
|
115
|
-
if (!text.trim()) {
|
|
116
|
-
throw new Error(`Empty response from ${path}`);
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
return JSON.parse(text);
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
-
const snippet = text.slice(0, 200);
|
|
124
|
-
throw new Error(`Invalid JSON from ${path}: ${message}. Body: ${snippet}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async function cliPost(path, body) {
|
|
128
|
-
const backendUrl = getBackendUrl();
|
|
129
|
-
const accessToken = await getValidAccessToken();
|
|
130
|
-
const response = await fetch(`${backendUrl}${path}`, {
|
|
131
|
-
method: 'POST',
|
|
132
|
-
headers: {
|
|
133
|
-
'Content-Type': 'application/json',
|
|
134
|
-
Accept: 'application/json',
|
|
135
|
-
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
136
|
-
},
|
|
137
|
-
body: JSON.stringify(body),
|
|
138
|
-
});
|
|
139
|
-
if (!response.ok) {
|
|
140
|
-
await handleHttpError(response, path);
|
|
141
|
-
}
|
|
142
|
-
const text = await response.text();
|
|
143
|
-
if (!text.trim()) {
|
|
144
|
-
throw new Error(`Empty response from ${path}`);
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
return JSON.parse(text);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
151
|
-
const snippet = text.slice(0, 200);
|
|
152
|
-
throw new Error(`Invalid JSON from ${path}: ${message}. Body: ${snippet}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// =============================================================================
|
|
156
|
-
// Query Functions (read-only, return denormalized data)
|
|
157
|
-
// =============================================================================
|
|
158
|
-
export async function listSlices(modelId, format = 'xml', chapterFilter) {
|
|
159
|
-
const params = { modelId };
|
|
160
|
-
if (chapterFilter)
|
|
161
|
-
params.chapter = chapterFilter;
|
|
162
|
-
return cliGetText('/cli/list-slices', params, format);
|
|
163
|
-
}
|
|
164
|
-
export async function listEvents(modelId, format = 'xml') {
|
|
165
|
-
return cliGetText('/cli/list-events', { modelId }, format);
|
|
166
|
-
}
|
|
167
|
-
export async function listCommands(modelId, format = 'xml') {
|
|
168
|
-
return cliGetText('/cli/list-commands', { modelId }, format);
|
|
169
|
-
}
|
|
170
|
-
export async function listChapters(modelId, format = 'xml') {
|
|
171
|
-
return cliGetText('/cli/list-chapters', { modelId }, format);
|
|
172
|
-
}
|
|
173
|
-
export async function listActors(modelId, format = 'xml') {
|
|
174
|
-
return cliGetText('/cli/list-actors', { modelId }, format);
|
|
175
|
-
}
|
|
176
|
-
export async function search(modelId, term) {
|
|
177
|
-
return cliGet('/cli/search', { modelId, term });
|
|
178
|
-
}
|
|
179
|
-
export async function getSummary(modelId) {
|
|
180
|
-
return cliGet('/cli/summary', { modelId });
|
|
181
|
-
}
|
|
182
|
-
export async function markSliceStatus(modelId, sliceName, status) {
|
|
183
|
-
return cliPost('/cli/mark-slice-status', { modelId, sliceName, status });
|
|
184
|
-
}
|
|
185
|
-
export async function addField(modelId, elementType, elementName, field) {
|
|
186
|
-
return cliPost('/cli/add-field', { modelId, elementType, elementName, field });
|
|
187
|
-
}
|
|
188
|
-
export async function removeField(modelId, elementType, elementName, fieldName) {
|
|
189
|
-
return cliPost('/cli/remove-field', { modelId, elementType, elementName, fieldName });
|
|
190
|
-
}
|
|
191
|
-
export async function updateField(modelId, elementType, elementName, fieldName, updates) {
|
|
192
|
-
return cliPost('/cli/update-field', { modelId, elementType, elementName, fieldName, updates });
|
|
193
|
-
}
|
|
194
|
-
export async function mapFields(modelId, sourceName, targetName, mappings) {
|
|
195
|
-
return cliPost('/cli/map-fields', { modelId, sourceName, targetName, mappings });
|
|
196
|
-
}
|
|
197
|
-
export async function createScenario(modelId, sliceName, scenario) {
|
|
198
|
-
return cliPost('/cli/create-scenario', { modelId, sliceName, scenario });
|
|
199
|
-
}
|
|
200
|
-
export async function removeScenario(modelId, scenarioName, sliceName) {
|
|
201
|
-
return cliPost('/cli/remove-scenario', { modelId, scenarioName, sliceName });
|
|
202
|
-
}
|
|
203
|
-
export async function createFlow(modelId, fromName, toName) {
|
|
204
|
-
return cliPost('/cli/create-flow', { modelId, fromName, toName });
|
|
205
|
-
}
|
|
206
|
-
export async function createStateChangeSlice(modelId, input) {
|
|
207
|
-
return cliPost('/cli/create-state-change-slice', { modelId, ...input });
|
|
208
|
-
}
|
|
209
|
-
export async function createAutomationSlice(modelId, input) {
|
|
210
|
-
return cliPost('/cli/create-automation-slice', { modelId, ...input });
|
|
211
|
-
}
|
|
212
|
-
export async function createStateViewSlice(modelId, input) {
|
|
213
|
-
return cliPost('/cli/create-state-view-slice', { modelId, ...input });
|
|
214
|
-
}
|
|
215
|
-
// =============================================================================
|
|
216
|
-
// View Functions (read-only, return formatted XML/JSON strings)
|
|
217
|
-
// =============================================================================
|
|
218
|
-
// Maps format to Accept header media type for content negotiation with the backend
|
|
219
|
-
function formatToMediaType(format) {
|
|
220
|
-
return format === 'xml' ? 'application/xml' : 'application/json';
|
|
221
|
-
}
|
|
222
|
-
// Helper for view queries that return text (XML or JSON string).
|
|
223
|
-
// Uses Accept header for content negotiation instead of a format query param.
|
|
224
|
-
async function cliGetText(path, params, format) {
|
|
225
|
-
const backendUrl = getBackendUrl();
|
|
226
|
-
const accessToken = await getValidAccessToken();
|
|
227
|
-
// Build query string manually using encodeURIComponent (uses %20 for spaces, not +)
|
|
228
|
-
// Some servers don't decode + as space in query parameters
|
|
229
|
-
const queryParts = Object.entries(params)
|
|
230
|
-
.filter(([_, value]) => value !== undefined)
|
|
231
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
232
|
-
const queryString = queryParts.length > 0 ? `?${queryParts.join('&')}` : '';
|
|
233
|
-
const fullUrl = `${backendUrl}${path}${queryString}`;
|
|
234
|
-
const response = await fetch(fullUrl, {
|
|
235
|
-
method: 'GET',
|
|
236
|
-
headers: {
|
|
237
|
-
Accept: formatToMediaType(format),
|
|
238
|
-
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
if (!response.ok) {
|
|
242
|
-
await handleHttpError(response, path);
|
|
243
|
-
}
|
|
244
|
-
const text = await response.text();
|
|
245
|
-
return text.trimEnd();
|
|
246
|
-
}
|
|
247
|
-
export async function showSlice(modelId, sliceName, format = 'xml') {
|
|
248
|
-
return cliGetText('/cli/show-slice', { modelId, name: sliceName }, format);
|
|
249
|
-
}
|
|
250
|
-
export async function showEvent(modelId, eventName, format = 'xml') {
|
|
251
|
-
return cliGetText('/cli/show-event', { modelId, name: eventName }, format);
|
|
252
|
-
}
|
|
253
|
-
export async function showCommand(modelId, commandName, format = 'xml') {
|
|
254
|
-
return cliGetText('/cli/show-command', { modelId, name: commandName }, format);
|
|
255
|
-
}
|
|
256
|
-
export async function showChapter(modelId, chapterName, format = 'xml') {
|
|
257
|
-
return cliGetText('/cli/show-chapter', { modelId, name: chapterName }, format);
|
|
258
|
-
}
|
|
259
|
-
export async function showActor(modelId, actorName, format = 'xml') {
|
|
260
|
-
return cliGetText('/cli/show-actor', { modelId, name: actorName }, format);
|
|
261
|
-
}
|
|
262
|
-
export async function exportJson(modelId) {
|
|
263
|
-
return cliGetText('/cli/export-json', { modelId });
|
|
264
|
-
}
|
|
265
|
-
export async function codegenSlice(modelId, sliceName) {
|
|
266
|
-
return cliGetText('/cli/codegen-slice', { modelId, name: sliceName });
|
|
267
|
-
}
|
|
268
|
-
function countFieldsDeep(fields) {
|
|
269
|
-
if (!fields || fields.length === 0) {
|
|
270
|
-
return 0;
|
|
271
|
-
}
|
|
272
|
-
return fields.reduce((count, field) => count + 1 + countFieldsDeep(field.subfields), 0);
|
|
273
|
-
}
|
|
274
|
-
function normalizeName(name) {
|
|
275
|
-
return (name ?? '').trim().toLowerCase();
|
|
276
|
-
}
|
|
277
|
-
export async function codegenEvents(modelId, chapterName) {
|
|
278
|
-
const slicesOutput = await listSlices(modelId, 'json', chapterName);
|
|
279
|
-
let slicesPayload;
|
|
280
|
-
try {
|
|
281
|
-
slicesPayload = JSON.parse(slicesOutput);
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
285
|
-
throw new Error(`Invalid JSON from /cli/list-slices: ${message}`);
|
|
286
|
-
}
|
|
287
|
-
const slices = (slicesPayload.slices ?? [])
|
|
288
|
-
.filter((slice) => typeof slice.id === 'string' && typeof slice.name === 'string');
|
|
289
|
-
if (slices.length === 0) {
|
|
290
|
-
return {
|
|
291
|
-
chapter: null,
|
|
292
|
-
sliceCount: 0,
|
|
293
|
-
eventCount: 0,
|
|
294
|
-
slices: [],
|
|
295
|
-
events: [],
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
const codegenOutputs = await Promise.all(slices.map(async (slice) => {
|
|
299
|
-
const raw = await codegenSlice(modelId, slice.name);
|
|
300
|
-
try {
|
|
301
|
-
return JSON.parse(raw);
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
305
|
-
throw new Error(`Invalid JSON from /cli/codegen-slice for "${slice.name}": ${message}`);
|
|
306
|
-
}
|
|
307
|
-
}));
|
|
308
|
-
const aggregatedSlices = [];
|
|
309
|
-
const eventsByName = new Map();
|
|
310
|
-
let chapter = null;
|
|
311
|
-
for (let i = 0; i < codegenOutputs.length; i++) {
|
|
312
|
-
const codegenOutput = codegenOutputs[i];
|
|
313
|
-
const fallbackSlice = slices[i];
|
|
314
|
-
const sliceName = codegenOutput.slice?.name ?? fallbackSlice.name;
|
|
315
|
-
aggregatedSlices.push({
|
|
316
|
-
id: codegenOutput.slice?.id ?? fallbackSlice.id,
|
|
317
|
-
name: sliceName,
|
|
318
|
-
sliceType: codegenOutput.sliceType ?? 'STATE_CHANGE',
|
|
319
|
-
});
|
|
320
|
-
if (chapterName && !chapter && codegenOutput.chapter) {
|
|
321
|
-
chapter = codegenOutput.chapter;
|
|
322
|
-
}
|
|
323
|
-
for (const event of codegenOutput.elements?.events ?? []) {
|
|
324
|
-
if (!event.name) {
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
const key = normalizeName(event.name);
|
|
328
|
-
if (!key) {
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
const existing = eventsByName.get(key);
|
|
332
|
-
if (!existing) {
|
|
333
|
-
eventsByName.set(key, {
|
|
334
|
-
id: event.id ?? '',
|
|
335
|
-
name: event.name,
|
|
336
|
-
fields: event.fields ?? [],
|
|
337
|
-
aggregate: event.aggregate,
|
|
338
|
-
sourceSlices: [sliceName],
|
|
339
|
-
});
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
if (!existing.sourceSlices.includes(sliceName)) {
|
|
343
|
-
existing.sourceSlices.push(sliceName);
|
|
344
|
-
}
|
|
345
|
-
if (!existing.aggregate && event.aggregate) {
|
|
346
|
-
existing.aggregate = event.aggregate;
|
|
347
|
-
}
|
|
348
|
-
if (countFieldsDeep(event.fields) > countFieldsDeep(existing.fields)) {
|
|
349
|
-
existing.fields = event.fields ?? [];
|
|
350
|
-
}
|
|
351
|
-
if (!existing.id && event.id) {
|
|
352
|
-
existing.id = event.id;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
const events = [...eventsByName.values()]
|
|
357
|
-
.map(event => ({ ...event, sourceSlices: [...event.sourceSlices].sort((a, b) => a.localeCompare(b)) }))
|
|
358
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
359
|
-
const sortedSlices = [...aggregatedSlices].sort((a, b) => a.name.localeCompare(b.name));
|
|
360
|
-
return {
|
|
361
|
-
chapter,
|
|
362
|
-
sliceCount: sortedSlices.length,
|
|
363
|
-
eventCount: events.length,
|
|
364
|
-
slices: sortedSlices,
|
|
365
|
-
events,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
export async function listAggregates(modelId, format = 'xml') {
|
|
369
|
-
return cliGetText('/cli/list-aggregates', { modelId }, format);
|
|
370
|
-
}
|
|
371
|
-
export async function listReadModels(modelId, format = 'xml') {
|
|
372
|
-
return cliGetText('/cli/list-readmodels', { modelId }, format);
|
|
373
|
-
}
|
|
374
|
-
export async function listScreens(modelId, format = 'xml') {
|
|
375
|
-
return cliGetText('/cli/list-screens', { modelId }, format);
|
|
376
|
-
}
|
|
377
|
-
export async function listProcessors(modelId, format = 'xml') {
|
|
378
|
-
return cliGetText('/cli/list-processors', { modelId }, format);
|
|
379
|
-
}
|
|
380
|
-
export async function showCompleteness(modelId, elementName, format = 'xml') {
|
|
381
|
-
return cliGetText('/cli/show-completeness', { modelId, name: elementName }, format);
|
|
382
|
-
}
|
|
383
|
-
export async function showModelCompleteness(modelId, format = 'xml') {
|
|
384
|
-
return cliGetText('/cli/show-model-completeness', { modelId }, format);
|
|
385
|
-
}
|
|
386
|
-
export async function showAggregateCompleteness(modelId, aggregateName, format = 'xml') {
|
|
387
|
-
return cliGetText('/cli/show-aggregate-completeness', { modelId, name: aggregateName }, format);
|
|
388
|
-
}
|
|
389
|
-
export async function showReadModel(modelId, name, format = 'xml') {
|
|
390
|
-
return cliGetText('/cli/show-readmodel', { modelId, name }, format);
|
|
391
|
-
}
|
|
392
|
-
export async function showScreen(modelId, name, format = 'xml') {
|
|
393
|
-
return cliGetText('/cli/show-screen', { modelId, name }, format);
|
|
394
|
-
}
|
|
395
|
-
export async function showProcessor(modelId, name, format = 'xml') {
|
|
396
|
-
return cliGetText('/cli/show-processor', { modelId, name }, format);
|
|
397
|
-
}
|
|
398
|
-
export async function showAggregate(modelId, name, format = 'xml') {
|
|
399
|
-
return cliGetText('/cli/show-aggregate', { modelId, name }, format);
|
|
400
|
-
}
|
|
401
|
-
export async function showScenario(modelId, name, format = 'xml') {
|
|
402
|
-
return cliGetText('/cli/show-scenario', { modelId, name }, format);
|
|
403
|
-
}
|
|
404
|
-
export async function listScenarios(modelId, format = 'xml') {
|
|
405
|
-
return cliGetText('/cli/list-scenarios', { modelId }, format);
|
|
406
|
-
}
|