@istar-ts/core 0.8.0 → 0.8.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/README.md CHANGED
@@ -225,6 +225,9 @@ const model = parsePistar(text, { metamodel: RATIONAL_AGENTS });
225
225
  need no extra argument. The association lives beside the model (`metamodelOf`), never in it:
226
226
  models keep their shape, and nothing reaches JSON or disk. A model rebuilt with an object
227
227
  spread loses it; `withMetamodel(model, metamodel)` restores it.
228
+ - **Predicates.** `isActor` / `isNode` answer for iStar 2.0 and take one argument, so they stay
229
+ safe as `filter` callbacks. For extended kinds use `isActorIn(metamodel)` / `isNodeIn(metamodel)`,
230
+ which return a predicate: `elements.filter(isActorIn(metamodelOf(model)))`.
228
231
  - **Types.** `ElementKind`, `LinkKind` and the other iStar 2.0 exports are unchanged.
229
232
  `IstarModel<EK, LK>`, `ModelStore<EK, LK>` and `Metamodel<EK, LK>` default to them, and
230
233
  `extendMetamodel` types the new kinds (`ElementKindOf<typeof RATIONAL_AGENTS>`).
package/dist/index.cjs CHANGED
@@ -415,13 +415,27 @@ function createEmptyModel(diagram = DEFAULT_DIAGRAM, options = {}) {
415
415
  function metamodelOf(model) {
416
416
  return metamodels.get(model) ?? ISTAR_2_0;
417
417
  }
418
- /** True for actor-category elements; pass the metamodel for extended actor kinds. */
419
- function isActor(element, metamodel = ISTAR_2_0) {
420
- return element !== void 0 && isActorKindIn(metamodel, element.kind);
418
+ /**
419
+ * True for iStar 2.0 actors (Actor, Agent, Role). One argument, so it is safe as an array
420
+ * callback (`elements.filter(isActor)`). For extended actor kinds use `isActorIn(metamodel)`.
421
+ */
422
+ function isActor(element) {
423
+ return element !== void 0 && isActorKindIn(ISTAR_2_0, element.kind);
424
+ }
425
+ /** True for iStar 2.0 intentional elements. For extended kinds use `isNodeIn(metamodel)`. */
426
+ function isNode(element) {
427
+ return element !== void 0 && !isActorKindIn(ISTAR_2_0, element.kind);
421
428
  }
422
- /** True for node-category elements; pass the metamodel for extended node kinds. */
423
- function isNode(element, metamodel = ISTAR_2_0) {
424
- return element !== void 0 && !isActorKindIn(metamodel, element.kind);
429
+ /**
430
+ * A predicate for actor-category elements of `metamodel`, extended actor kinds included:
431
+ * `elements.filter(isActorIn(metamodelOf(model)))`.
432
+ */
433
+ function isActorIn(metamodel) {
434
+ return (element) => element !== void 0 && isActorKindIn(metamodel, element.kind);
435
+ }
436
+ /** A predicate for node-category elements of `metamodel`, extended node kinds included. */
437
+ function isNodeIn(metamodel) {
438
+ return (element) => element !== void 0 && metamodel.elements.get(element.kind)?.category === "node";
425
439
  }
426
440
  /** Inner elements of an actor, in model order. */
427
441
  function childrenOf(model, actorId) {
@@ -690,13 +704,8 @@ const CHECKS = {
690
704
  "istar.ContributionLink": contributionLink,
691
705
  "istar.QualificationLink": qualificationLink
692
706
  };
693
- /**
694
- * Re-validates every link of a model, the way piStar does when loading a file: dependencies
695
- * first (each checked before its own links are added), then the remaining links in file
696
- * order, each against the graph built so far. Invalid links are reported, not removed.
697
- */
698
- function validateModel(model, options = {}) {
699
- const metamodel = options.metamodel ?? metamodelOf(model);
707
+ function validateModel(model, options) {
708
+ const metamodel = (typeof options === "object" && options !== null ? options.metamodel : void 0) ?? metamodelOf(model);
700
709
  const any = model;
701
710
  const issues = [];
702
711
  const accepted = /* @__PURE__ */ new Map();
@@ -1076,7 +1085,7 @@ function typed(model) {
1076
1085
  function metaOf(model) {
1077
1086
  return metamodelOf(model);
1078
1087
  }
1079
- function isActorIn(model, kind) {
1088
+ function isActorIn$1(model, kind) {
1080
1089
  return metaOf(model).elements.get(kind)?.category === "actor";
1081
1090
  }
1082
1091
  function derive(from, changes) {
@@ -1109,7 +1118,7 @@ function addElement(model, input, ctx = {}) {
1109
1118
  if (m.elements.has(id) || m.links.has(id)) throw new ModelOperationError(`id "${id}" is already in use`);
1110
1119
  if (input.parent !== void 0) {
1111
1120
  if (definition.category === "actor") throw new ModelOperationError("actors cannot be nested");
1112
- if (!isActorIn(m, requireElement(m, input.parent).kind)) throw new ModelOperationError(`parent "${input.parent}" is not an actor`);
1121
+ if (!isActorIn$1(m, requireElement(m, input.parent).kind)) throw new ModelOperationError(`parent "${input.parent}" is not an actor`);
1113
1122
  }
1114
1123
  const element = withoutUndefined({
1115
1124
  id,
@@ -1161,7 +1170,7 @@ function moveElement(model, id, x, y) {
1161
1170
  x,
1162
1171
  y
1163
1172
  });
1164
- if (isActorIn(m, current.kind)) {
1173
+ if (isActorIn$1(m, current.kind)) {
1165
1174
  for (const child of m.elements.values()) if (child.parent === id) elements.set(child.id, {
1166
1175
  ...child,
1167
1176
  x: child.x + dx,
@@ -1178,10 +1187,10 @@ function moveElement(model, id, x, y) {
1178
1187
  function nestElement(model, id, parent) {
1179
1188
  const m = any(model);
1180
1189
  const current = requireElement(m, id);
1181
- if (isActorIn(m, current.kind)) throw new ModelOperationError("actors cannot be nested");
1190
+ if (isActorIn$1(m, current.kind)) throw new ModelOperationError("actors cannot be nested");
1182
1191
  if (current.isDependum) throw new ModelOperationError("a dependum cannot be nested");
1183
1192
  if ((current.parent ?? null) === parent) return model;
1184
- if (parent !== null && !isActorIn(m, requireElement(m, parent).kind)) throw new ModelOperationError(`parent "${parent}" is not an actor`);
1193
+ if (parent !== null && !isActorIn$1(m, requireElement(m, parent).kind)) throw new ModelOperationError(`parent "${parent}" is not an actor`);
1185
1194
  const elements = new Map(m.elements);
1186
1195
  elements.delete(id);
1187
1196
  const { parent: _old, ...rest } = current;
@@ -1878,6 +1887,7 @@ exports.getSourceLayout = getSourceLayout;
1878
1887
  exports.inheritMetamodel = inheritMetamodel;
1879
1888
  exports.inheritSourceLayout = inheritSourceLayout;
1880
1889
  exports.isActor = isActor;
1890
+ exports.isActorIn = isActorIn;
1881
1891
  exports.isActorKind = isActorKind;
1882
1892
  exports.isActorKindIn = isActorKindIn;
1883
1893
  exports.isActorLinkKind = isActorLinkKind;
@@ -1886,6 +1896,7 @@ exports.isDependencyLinkKind = isDependencyLinkKind;
1886
1896
  exports.isElementKind = isElementKind;
1887
1897
  exports.isLinkKind = isLinkKind;
1888
1898
  exports.isNode = isNode;
1899
+ exports.isNodeIn = isNodeIn;
1889
1900
  exports.isNodeKind = isNodeKind;
1890
1901
  exports.isNodeKindIn = isNodeKindIn;
1891
1902
  exports.isNodeLinkKind = isNodeLinkKind;