@istar-ts/actions 0.15.0-beta.0 → 0.15.0-beta.2
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 +97 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -4
- package/dist/index.d.ts +58 -4
- package/dist/index.js +98 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
1
|
+
import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.d.ts
|
|
3
3
|
/** GLSP's custom arguments: a flat map of primitives. */
|
|
4
4
|
export type Args = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -216,8 +216,35 @@ export interface UpdateLinkDisplayOperation extends Operation {
|
|
|
216
216
|
readonly linkId: string;
|
|
217
217
|
readonly patch: Readonly<Record<string, unknown>>;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Changes the kind of a set of links: each listed link's id, source, target, order in the file,
|
|
221
|
+
* name, value, custom properties and display are kept; other links are untouched. One undo step
|
|
222
|
+
* for the whole set, all or nothing. A link whose kind is already `elementTypeId` is a no-op;
|
|
223
|
+
* an empty `linkIds` is a no-op too. Rejected (model untouched) if `canLink` refuses any listed
|
|
224
|
+
* link's new kind for its unchanged source and target (e.g. a mixed-refinement rule), or if the
|
|
225
|
+
* link keeps a `value` the new kind's `possibleLabels` disallows.
|
|
226
|
+
*/
|
|
227
|
+
export interface ChangeLinkKindOperation<LK extends string = LinkKind> extends Operation {
|
|
228
|
+
readonly kind: "istar.changeLinkKind";
|
|
229
|
+
readonly linkIds: readonly string[];
|
|
230
|
+
/** The links' new kind, e.g. `istar.OrRefinementLink`. */
|
|
231
|
+
readonly elementTypeId: LK;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Sets (or, with `null` or an empty block, removes) the model file's own `"metamodel"` block:
|
|
235
|
+
* custom element kinds, groupers, link kinds with their rules and line style (`withFileMetamodel`
|
|
236
|
+
* in `@istar-ts/core`). One undo step; undo restores the previous block exactly. Rejected (model
|
|
237
|
+
* untouched) if the block is malformed, collides with the host's kinds, or drops a kind an
|
|
238
|
+
* element or link still uses. A host's dialect-specific checks (e.g. goal-controller's own
|
|
239
|
+
* validation of the block) run as an `ActionGuard` on this operation's kind, so their refusal
|
|
240
|
+
* also comes back as diagnostics.
|
|
241
|
+
*/
|
|
242
|
+
export interface SetFileMetamodelOperation extends Operation {
|
|
243
|
+
readonly kind: "istar.setFileMetamodel";
|
|
244
|
+
readonly block: FileMetamodel | null;
|
|
245
|
+
}
|
|
219
246
|
/** Every operation, keyed by `kind`. */
|
|
220
|
-
export type IstarOperation<EK extends string = ElementKind, LK extends string = LinkKind> = CreateNodeOperation<EK> | CreateEdgeOperation<EK, LK> | DeleteElementOperation | ChangeBoundsOperation | ChangeContainerOperation | ReconnectEdgeOperation | ApplyLabelEditOperation | CompoundOperation<EK, LK> | AddLegOperation | RemoveLegOperation | SetCollapsedOperation | UpdateDiagramOperation | UpdatePropertiesOperation | UpdateDisplayOperation | SetLinkValueOperation | UpdateLinkDisplayOperation;
|
|
247
|
+
export type IstarOperation<EK extends string = ElementKind, LK extends string = LinkKind> = CreateNodeOperation<EK> | CreateEdgeOperation<EK, LK> | DeleteElementOperation | ChangeBoundsOperation | ChangeContainerOperation | ReconnectEdgeOperation | ApplyLabelEditOperation | CompoundOperation<EK, LK> | AddLegOperation | RemoveLegOperation | SetCollapsedOperation | UpdateDiagramOperation | UpdatePropertiesOperation | UpdateDisplayOperation | SetLinkValueOperation | UpdateLinkDisplayOperation | ChangeLinkKindOperation<LK> | SetFileMetamodelOperation;
|
|
221
248
|
export interface RequestModelAction extends RequestAction {
|
|
222
249
|
readonly kind: "requestModel";
|
|
223
250
|
readonly options?: Args;
|
|
@@ -477,10 +504,28 @@ export interface ActionDispatcher<EK extends string = ElementKind, LK extends st
|
|
|
477
504
|
* the operation; others are returned with the result.
|
|
478
505
|
*/
|
|
479
506
|
export type ActionGuard<EK extends string = ElementKind, LK extends string = LinkKind> = (operation: IstarOperation<EK, LK>, model: IstarModel<EK, LK>) => readonly GoalDiagnostic[] | void;
|
|
507
|
+
/**
|
|
508
|
+
* A host's rule, run after each operation is applied (and after each operation of a compound
|
|
509
|
+
* one, plus once more on the compound's own result), inside the operation's transaction. Sees
|
|
510
|
+
* the model as the operation leaves it (`modelAfter`) and as it was before (`modelBefore`), so
|
|
511
|
+
* it can check things a pre-guard can't without re-applying the operation itself (goal-controller's
|
|
512
|
+
* edgeV2 engine check is the motivating case). Diagnostics of severity `error` roll the
|
|
513
|
+
* transaction back: the model is untouched and there is no undo entry. Others are returned with
|
|
514
|
+
* the result, merged with pre-guards' warnings.
|
|
515
|
+
*/
|
|
516
|
+
export type ActionPostGuard<EK extends string = ElementKind, LK extends string = LinkKind> = (operation: IstarOperation<EK, LK>, modelAfter: IstarModel<EK, LK>, modelBefore: IstarModel<EK, LK>) => readonly GoalDiagnostic[] | void;
|
|
480
517
|
export interface ActionDispatcherOptions<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
481
518
|
readonly guards?: readonly ActionGuard<EK, LK>[];
|
|
482
|
-
/**
|
|
483
|
-
readonly
|
|
519
|
+
/** Run after each operation is applied; see `ActionPostGuard`. */
|
|
520
|
+
readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
|
|
521
|
+
/**
|
|
522
|
+
* What `RequestContextActions` offers: a fixed description, or a function evaluated on each
|
|
523
|
+
* request (so a host can track a registry or extensions that change after this dispatcher was
|
|
524
|
+
* created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
|
|
525
|
+
* the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
|
|
526
|
+
* (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
|
|
527
|
+
*/
|
|
528
|
+
readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
|
|
484
529
|
/**
|
|
485
530
|
* Property schemas an operation must not break: an operation that adds an issue
|
|
486
531
|
* (`validateModelProperties`) is rejected. Their issues are also markers.
|
|
@@ -527,6 +572,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
|
|
|
527
572
|
* lacks are left out.
|
|
528
573
|
*/
|
|
529
574
|
export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
|
|
575
|
+
/**
|
|
576
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
577
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
578
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
579
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
580
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
581
|
+
* was given.
|
|
582
|
+
*/
|
|
583
|
+
export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
|
|
530
584
|
//#endregion
|
|
531
585
|
//#region src/host.d.ts
|
|
532
586
|
/** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
1
|
+
import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.d.ts
|
|
3
3
|
/** GLSP's custom arguments: a flat map of primitives. */
|
|
4
4
|
export type Args = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -216,8 +216,35 @@ export interface UpdateLinkDisplayOperation extends Operation {
|
|
|
216
216
|
readonly linkId: string;
|
|
217
217
|
readonly patch: Readonly<Record<string, unknown>>;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Changes the kind of a set of links: each listed link's id, source, target, order in the file,
|
|
221
|
+
* name, value, custom properties and display are kept; other links are untouched. One undo step
|
|
222
|
+
* for the whole set, all or nothing. A link whose kind is already `elementTypeId` is a no-op;
|
|
223
|
+
* an empty `linkIds` is a no-op too. Rejected (model untouched) if `canLink` refuses any listed
|
|
224
|
+
* link's new kind for its unchanged source and target (e.g. a mixed-refinement rule), or if the
|
|
225
|
+
* link keeps a `value` the new kind's `possibleLabels` disallows.
|
|
226
|
+
*/
|
|
227
|
+
export interface ChangeLinkKindOperation<LK extends string = LinkKind> extends Operation {
|
|
228
|
+
readonly kind: "istar.changeLinkKind";
|
|
229
|
+
readonly linkIds: readonly string[];
|
|
230
|
+
/** The links' new kind, e.g. `istar.OrRefinementLink`. */
|
|
231
|
+
readonly elementTypeId: LK;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Sets (or, with `null` or an empty block, removes) the model file's own `"metamodel"` block:
|
|
235
|
+
* custom element kinds, groupers, link kinds with their rules and line style (`withFileMetamodel`
|
|
236
|
+
* in `@istar-ts/core`). One undo step; undo restores the previous block exactly. Rejected (model
|
|
237
|
+
* untouched) if the block is malformed, collides with the host's kinds, or drops a kind an
|
|
238
|
+
* element or link still uses. A host's dialect-specific checks (e.g. goal-controller's own
|
|
239
|
+
* validation of the block) run as an `ActionGuard` on this operation's kind, so their refusal
|
|
240
|
+
* also comes back as diagnostics.
|
|
241
|
+
*/
|
|
242
|
+
export interface SetFileMetamodelOperation extends Operation {
|
|
243
|
+
readonly kind: "istar.setFileMetamodel";
|
|
244
|
+
readonly block: FileMetamodel | null;
|
|
245
|
+
}
|
|
219
246
|
/** Every operation, keyed by `kind`. */
|
|
220
|
-
export type IstarOperation<EK extends string = ElementKind, LK extends string = LinkKind> = CreateNodeOperation<EK> | CreateEdgeOperation<EK, LK> | DeleteElementOperation | ChangeBoundsOperation | ChangeContainerOperation | ReconnectEdgeOperation | ApplyLabelEditOperation | CompoundOperation<EK, LK> | AddLegOperation | RemoveLegOperation | SetCollapsedOperation | UpdateDiagramOperation | UpdatePropertiesOperation | UpdateDisplayOperation | SetLinkValueOperation | UpdateLinkDisplayOperation;
|
|
247
|
+
export type IstarOperation<EK extends string = ElementKind, LK extends string = LinkKind> = CreateNodeOperation<EK> | CreateEdgeOperation<EK, LK> | DeleteElementOperation | ChangeBoundsOperation | ChangeContainerOperation | ReconnectEdgeOperation | ApplyLabelEditOperation | CompoundOperation<EK, LK> | AddLegOperation | RemoveLegOperation | SetCollapsedOperation | UpdateDiagramOperation | UpdatePropertiesOperation | UpdateDisplayOperation | SetLinkValueOperation | UpdateLinkDisplayOperation | ChangeLinkKindOperation<LK> | SetFileMetamodelOperation;
|
|
221
248
|
export interface RequestModelAction extends RequestAction {
|
|
222
249
|
readonly kind: "requestModel";
|
|
223
250
|
readonly options?: Args;
|
|
@@ -477,10 +504,28 @@ export interface ActionDispatcher<EK extends string = ElementKind, LK extends st
|
|
|
477
504
|
* the operation; others are returned with the result.
|
|
478
505
|
*/
|
|
479
506
|
export type ActionGuard<EK extends string = ElementKind, LK extends string = LinkKind> = (operation: IstarOperation<EK, LK>, model: IstarModel<EK, LK>) => readonly GoalDiagnostic[] | void;
|
|
507
|
+
/**
|
|
508
|
+
* A host's rule, run after each operation is applied (and after each operation of a compound
|
|
509
|
+
* one, plus once more on the compound's own result), inside the operation's transaction. Sees
|
|
510
|
+
* the model as the operation leaves it (`modelAfter`) and as it was before (`modelBefore`), so
|
|
511
|
+
* it can check things a pre-guard can't without re-applying the operation itself (goal-controller's
|
|
512
|
+
* edgeV2 engine check is the motivating case). Diagnostics of severity `error` roll the
|
|
513
|
+
* transaction back: the model is untouched and there is no undo entry. Others are returned with
|
|
514
|
+
* the result, merged with pre-guards' warnings.
|
|
515
|
+
*/
|
|
516
|
+
export type ActionPostGuard<EK extends string = ElementKind, LK extends string = LinkKind> = (operation: IstarOperation<EK, LK>, modelAfter: IstarModel<EK, LK>, modelBefore: IstarModel<EK, LK>) => readonly GoalDiagnostic[] | void;
|
|
480
517
|
export interface ActionDispatcherOptions<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
481
518
|
readonly guards?: readonly ActionGuard<EK, LK>[];
|
|
482
|
-
/**
|
|
483
|
-
readonly
|
|
519
|
+
/** Run after each operation is applied; see `ActionPostGuard`. */
|
|
520
|
+
readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
|
|
521
|
+
/**
|
|
522
|
+
* What `RequestContextActions` offers: a fixed description, or a function evaluated on each
|
|
523
|
+
* request (so a host can track a registry or extensions that change after this dispatcher was
|
|
524
|
+
* created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
|
|
525
|
+
* the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
|
|
526
|
+
* (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
|
|
527
|
+
*/
|
|
528
|
+
readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
|
|
484
529
|
/**
|
|
485
530
|
* Property schemas an operation must not break: an operation that adds an issue
|
|
486
531
|
* (`validateModelProperties`) is rejected. Their issues are also markers.
|
|
@@ -527,6 +572,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
|
|
|
527
572
|
* lacks are left out.
|
|
528
573
|
*/
|
|
529
574
|
export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
|
|
575
|
+
/**
|
|
576
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
577
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
578
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
579
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
580
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
581
|
+
* was given.
|
|
582
|
+
*/
|
|
583
|
+
export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
|
|
530
584
|
//#endregion
|
|
531
585
|
//#region src/host.d.ts
|
|
532
586
|
/** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIAGNOSTIC_SEVERITIES, FILE_METAMODEL_KEY, LINK_SELECTOR, MetamodelError, ModelOperationError, canLink, connectResultToDiagnostic, createEmptyModel, dependencyEnds, effectiveLinkKind, elementBehavesLike, inheritMetamodel, inheritSourceLayout, linkBehavesLike, metamodelOf, parsePistar, toPistarObject, validateModel, validateModelProperties, withFileMetamodel } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.ts
|
|
3
3
|
const OPERATION_KIND_LIST = [
|
|
4
4
|
"createNode",
|
|
@@ -16,7 +16,9 @@ const OPERATION_KIND_LIST = [
|
|
|
16
16
|
"istar.updateProperties",
|
|
17
17
|
"istar.updateDisplay",
|
|
18
18
|
"istar.setLinkValue",
|
|
19
|
-
"istar.updateLinkDisplay"
|
|
19
|
+
"istar.updateLinkDisplay",
|
|
20
|
+
"istar.changeLinkKind",
|
|
21
|
+
"istar.setFileMetamodel"
|
|
20
22
|
];
|
|
21
23
|
const REQUEST_KIND_LIST = [
|
|
22
24
|
"requestModel",
|
|
@@ -183,6 +185,36 @@ function contextActionsFor(palette, metamodel) {
|
|
|
183
185
|
groups: palette.groups
|
|
184
186
|
};
|
|
185
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
190
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
191
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
192
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
193
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
194
|
+
* was given.
|
|
195
|
+
*/
|
|
196
|
+
function paletteFromMetamodel(metamodel) {
|
|
197
|
+
const elements = {};
|
|
198
|
+
let order = 0;
|
|
199
|
+
for (const definition of metamodel.elements.values()) elements[definition.kind] = definition.role !== void 0 ? false : {
|
|
200
|
+
label: definition.label,
|
|
201
|
+
order: order++,
|
|
202
|
+
section: definition.category === "actor" ? "actors" : "elements",
|
|
203
|
+
...definition.category === "actor" ? { group: "actors" } : {}
|
|
204
|
+
};
|
|
205
|
+
const links = {};
|
|
206
|
+
order = 0;
|
|
207
|
+
for (const definition of metamodel.links.values()) links[definition.kind] = definition.role !== void 0 ? false : [{
|
|
208
|
+
label: definition.label,
|
|
209
|
+
order: order++,
|
|
210
|
+
section: "elements"
|
|
211
|
+
}];
|
|
212
|
+
return {
|
|
213
|
+
elements,
|
|
214
|
+
links,
|
|
215
|
+
groups: { actors: { label: "Actor" } }
|
|
216
|
+
};
|
|
217
|
+
}
|
|
186
218
|
//#endregion
|
|
187
219
|
//#region src/markers.ts
|
|
188
220
|
/** A `GoalDiagnostic` as a GLSP marker: `kind` is its severity, `label` its message. */
|
|
@@ -273,7 +305,12 @@ function linkIssueDiagnostics(model) {
|
|
|
273
305
|
function createActionDispatcher(store, options = {}) {
|
|
274
306
|
const s = store;
|
|
275
307
|
const guards = options.guards ?? [];
|
|
276
|
-
const
|
|
308
|
+
const postGuards = options.postGuards ?? [];
|
|
309
|
+
const resolvePalette = (meta) => {
|
|
310
|
+
const option = options.palette;
|
|
311
|
+
if (typeof option === "function") return option();
|
|
312
|
+
return option ?? paletteFromMetamodel(meta);
|
|
313
|
+
};
|
|
277
314
|
const sourceModelName = options.sourceModelName ?? "";
|
|
278
315
|
const listeners = /* @__PURE__ */ new Set();
|
|
279
316
|
let saved = s.getModel();
|
|
@@ -318,8 +355,18 @@ function createActionDispatcher(store, options = {}) {
|
|
|
318
355
|
for (const guard of guards) for (const d of guard(operation, s.getModel()) ?? []) (d.severity === "error" ? errors : warnings).push(d);
|
|
319
356
|
if (errors.length > 0) throw new Rejection(errors);
|
|
320
357
|
};
|
|
358
|
+
const runPostGuards = (operation, before, warnings) => {
|
|
359
|
+
const errors = [];
|
|
360
|
+
for (const guard of postGuards) for (const d of guard(operation, s.getModel(), before) ?? []) (d.severity === "error" ? errors : warnings).push(d);
|
|
361
|
+
if (errors.length > 0) throw new Rejection(errors);
|
|
362
|
+
};
|
|
321
363
|
const apply = (operation, warnings) => {
|
|
322
364
|
runGuards(operation, warnings);
|
|
365
|
+
const before = s.getModel();
|
|
366
|
+
doApply(operation, warnings);
|
|
367
|
+
runPostGuards(operation, before, warnings);
|
|
368
|
+
};
|
|
369
|
+
const doApply = (operation, warnings) => {
|
|
323
370
|
const model = s.getModel();
|
|
324
371
|
const meta = metaOf(model);
|
|
325
372
|
switch (operation.kind) {
|
|
@@ -486,6 +533,45 @@ function createActionDispatcher(store, options = {}) {
|
|
|
486
533
|
s.updateLink(linkId, { label: value });
|
|
487
534
|
return;
|
|
488
535
|
}
|
|
536
|
+
case "istar.changeLinkKind": {
|
|
537
|
+
const { linkIds, elementTypeId: kind } = operation;
|
|
538
|
+
if (linkIds.length === 0) return;
|
|
539
|
+
const ids = new Set(linkIds);
|
|
540
|
+
const links = [...ids].map((id) => model.links.get(id) ?? reject(`unknown link "${id}"`, id, "unknown-element"));
|
|
541
|
+
const definition = meta.links.get(kind) ?? reject(`unknown link kind "${kind}" in ${meta.name}`, "", "unknown-kind");
|
|
542
|
+
const toChange = links.filter((link) => link.kind !== kind);
|
|
543
|
+
if (toChange.length === 0) return;
|
|
544
|
+
const remaining = new Map(model.links);
|
|
545
|
+
for (const id of ids) remaining.delete(id);
|
|
546
|
+
const without = withLinks(model, remaining);
|
|
547
|
+
const values = definition.info.possibleLabels;
|
|
548
|
+
for (const link of toChange) {
|
|
549
|
+
const check = canLink(without, link.source, link.target, kind);
|
|
550
|
+
if (!check.ok) rejectCheck(check, {
|
|
551
|
+
source: link.source,
|
|
552
|
+
target: link.target
|
|
553
|
+
});
|
|
554
|
+
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");
|
|
555
|
+
}
|
|
556
|
+
const next = new Map(model.links);
|
|
557
|
+
for (const link of toChange) next.set(link.id, {
|
|
558
|
+
...link,
|
|
559
|
+
kind
|
|
560
|
+
});
|
|
561
|
+
s.replace(withLinks(model, next));
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
case "istar.setFileMetamodel": {
|
|
565
|
+
let next;
|
|
566
|
+
try {
|
|
567
|
+
next = withFileMetamodel(model, operation.block);
|
|
568
|
+
} catch (error) {
|
|
569
|
+
if (error instanceof MetamodelError) reject(error.message, "", "invalid-metamodel");
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
s.replace(next);
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
489
575
|
default: reject(`unknown operation "${operation.kind}"`, "", "unknown-action");
|
|
490
576
|
}
|
|
491
577
|
};
|
|
@@ -646,11 +732,14 @@ function createActionDispatcher(store, options = {}) {
|
|
|
646
732
|
...typeHintsFor(metaOf(model))
|
|
647
733
|
};
|
|
648
734
|
case "requestCheckEdge": return checkEdge(action);
|
|
649
|
-
case "requestContextActions":
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
735
|
+
case "requestContextActions": {
|
|
736
|
+
const meta = metaOf(model);
|
|
737
|
+
return {
|
|
738
|
+
kind: "setContextActions",
|
|
739
|
+
responseId: action.requestId,
|
|
740
|
+
...contextActionsFor(resolvePalette(meta), meta)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
654
743
|
case "requestMarkers": return markers(action);
|
|
655
744
|
default: return;
|
|
656
745
|
}
|
|
@@ -1098,6 +1187,6 @@ function createRemoteDispatcher(port) {
|
|
|
1098
1187
|
/** Version of the action protocol this package speaks. */
|
|
1099
1188
|
const ACTIONS_PROTOCOL_VERSION = "0.0.0";
|
|
1100
1189
|
//#endregion
|
|
1101
|
-
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, readOnlyDispatcher, typeHintsFor };
|
|
1190
|
+
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, paletteFromMetamodel, readOnlyDispatcher, typeHintsFor };
|
|
1102
1191
|
|
|
1103
1192
|
//# sourceMappingURL=index.js.map
|