@istar-ts/actions 0.15.0-beta.0 → 0.15.0-beta.1
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/index.cjs +53 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +54 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,9 @@ const OPERATION_KIND_LIST = [
|
|
|
17
17
|
"istar.updateProperties",
|
|
18
18
|
"istar.updateDisplay",
|
|
19
19
|
"istar.setLinkValue",
|
|
20
|
-
"istar.updateLinkDisplay"
|
|
20
|
+
"istar.updateLinkDisplay",
|
|
21
|
+
"istar.changeLinkKind",
|
|
22
|
+
"istar.setFileMetamodel"
|
|
21
23
|
];
|
|
22
24
|
const REQUEST_KIND_LIST = [
|
|
23
25
|
"requestModel",
|
|
@@ -274,6 +276,7 @@ function linkIssueDiagnostics(model) {
|
|
|
274
276
|
function createActionDispatcher(store, options = {}) {
|
|
275
277
|
const s = store;
|
|
276
278
|
const guards = options.guards ?? [];
|
|
279
|
+
const postGuards = options.postGuards ?? [];
|
|
277
280
|
const palette = options.palette ?? _istar_ts_core.DEFAULT_PALETTE;
|
|
278
281
|
const sourceModelName = options.sourceModelName ?? "";
|
|
279
282
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -319,8 +322,18 @@ function createActionDispatcher(store, options = {}) {
|
|
|
319
322
|
for (const guard of guards) for (const d of guard(operation, s.getModel()) ?? []) (d.severity === "error" ? errors : warnings).push(d);
|
|
320
323
|
if (errors.length > 0) throw new Rejection(errors);
|
|
321
324
|
};
|
|
325
|
+
const runPostGuards = (operation, before, warnings) => {
|
|
326
|
+
const errors = [];
|
|
327
|
+
for (const guard of postGuards) for (const d of guard(operation, s.getModel(), before) ?? []) (d.severity === "error" ? errors : warnings).push(d);
|
|
328
|
+
if (errors.length > 0) throw new Rejection(errors);
|
|
329
|
+
};
|
|
322
330
|
const apply = (operation, warnings) => {
|
|
323
331
|
runGuards(operation, warnings);
|
|
332
|
+
const before = s.getModel();
|
|
333
|
+
doApply(operation, warnings);
|
|
334
|
+
runPostGuards(operation, before, warnings);
|
|
335
|
+
};
|
|
336
|
+
const doApply = (operation, warnings) => {
|
|
324
337
|
const model = s.getModel();
|
|
325
338
|
const meta = metaOf(model);
|
|
326
339
|
switch (operation.kind) {
|
|
@@ -487,6 +500,45 @@ function createActionDispatcher(store, options = {}) {
|
|
|
487
500
|
s.updateLink(linkId, { label: value });
|
|
488
501
|
return;
|
|
489
502
|
}
|
|
503
|
+
case "istar.changeLinkKind": {
|
|
504
|
+
const { linkIds, elementTypeId: kind } = operation;
|
|
505
|
+
if (linkIds.length === 0) return;
|
|
506
|
+
const ids = new Set(linkIds);
|
|
507
|
+
const links = [...ids].map((id) => model.links.get(id) ?? reject(`unknown link "${id}"`, id, "unknown-element"));
|
|
508
|
+
const definition = meta.links.get(kind) ?? reject(`unknown link kind "${kind}" in ${meta.name}`, "", "unknown-kind");
|
|
509
|
+
const toChange = links.filter((link) => link.kind !== kind);
|
|
510
|
+
if (toChange.length === 0) return;
|
|
511
|
+
const remaining = new Map(model.links);
|
|
512
|
+
for (const id of ids) remaining.delete(id);
|
|
513
|
+
const without = withLinks(model, remaining);
|
|
514
|
+
const values = definition.info.possibleLabels;
|
|
515
|
+
for (const link of toChange) {
|
|
516
|
+
const check = (0, _istar_ts_core.canLink)(without, link.source, link.target, kind);
|
|
517
|
+
if (!check.ok) rejectCheck(check, {
|
|
518
|
+
source: link.source,
|
|
519
|
+
target: link.target
|
|
520
|
+
});
|
|
521
|
+
if (link.label != null && values && !values.includes(link.label)) reject(`"${link.label}" is not a value of a ${definition.label} link (${values.join(", ")})`, link.id, "invalid-value");
|
|
522
|
+
}
|
|
523
|
+
const next = new Map(model.links);
|
|
524
|
+
for (const link of toChange) next.set(link.id, {
|
|
525
|
+
...link,
|
|
526
|
+
kind
|
|
527
|
+
});
|
|
528
|
+
s.replace(withLinks(model, next));
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
case "istar.setFileMetamodel": {
|
|
532
|
+
let next;
|
|
533
|
+
try {
|
|
534
|
+
next = (0, _istar_ts_core.withFileMetamodel)(model, operation.block);
|
|
535
|
+
} catch (error) {
|
|
536
|
+
if (error instanceof _istar_ts_core.MetamodelError) reject(error.message, "", "invalid-metamodel");
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
s.replace(next);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
490
542
|
default: reject(`unknown operation "${operation.kind}"`, "", "unknown-action");
|
|
491
543
|
}
|
|
492
544
|
};
|