@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/dist/index.d.cts CHANGED
@@ -122,7 +122,9 @@ export interface ModelIssue<LK extends string = LinkKind> {
122
122
  * first (each checked before its own links are added), then the remaining links in file
123
123
  * order, each against the graph built so far. Invalid links are reported, not removed.
124
124
  */
125
- export declare function validateModel<EK extends string = ElementKind, LK extends string = LinkKind>(model: IstarModel<EK, LK>, options?: CanLinkOptions<EK, LK>): ModelIssue<LK>[];
125
+ export declare function validateModel<EK extends string, LK extends string>(model: IstarModel<EK, LK>, options: CanLinkOptions<EK, LK>): ModelIssue<LK>[];
126
+ export declare function validateModel<EK extends string, LK extends string>(model: IstarModel<EK, LK>): ModelIssue<LK>[];
127
+ export declare function validateModel(model: IstarModel): ModelIssue[];
126
128
  //#endregion
127
129
  //#region src/metamodels.d.ts
128
130
  export type ElementCategory = "actor" | "node";
@@ -390,10 +392,20 @@ export declare function createEmptyModel(diagram?: Diagram): IstarModel;
390
392
  * iStar 2.0. Constraints, operations and serialization use it unless given another one.
391
393
  */
392
394
  export declare function metamodelOf<EK extends string, LK extends string>(model: IstarModel<EK, LK>): Metamodel<EK, LK>;
393
- /** True for actor-category elements; pass the metamodel for extended actor kinds. */
394
- export declare function isActor(element: IstarElement<string> | undefined, metamodel?: AnyMetamodel): element is IstarActor;
395
- /** True for node-category elements; pass the metamodel for extended node kinds. */
396
- export declare function isNode(element: IstarElement<string> | undefined, metamodel?: AnyMetamodel): element is IstarNode;
395
+ /**
396
+ * True for iStar 2.0 actors (Actor, Agent, Role). One argument, so it is safe as an array
397
+ * callback (`elements.filter(isActor)`). For extended actor kinds use `isActorIn(metamodel)`.
398
+ */
399
+ export declare function isActor(element: IstarElement<string> | undefined): element is IstarActor;
400
+ /** True for iStar 2.0 intentional elements. For extended kinds use `isNodeIn(metamodel)`. */
401
+ export declare function isNode(element: IstarElement<string> | undefined): element is IstarNode;
402
+ /**
403
+ * A predicate for actor-category elements of `metamodel`, extended actor kinds included:
404
+ * `elements.filter(isActorIn(metamodelOf(model)))`.
405
+ */
406
+ export declare function isActorIn(metamodel: AnyMetamodel): (element: IstarElement<string> | undefined) => boolean;
407
+ /** A predicate for node-category elements of `metamodel`, extended node kinds included. */
408
+ export declare function isNodeIn(metamodel: AnyMetamodel): (element: IstarElement<string> | undefined) => boolean;
397
409
  /** Inner elements of an actor, in model order. */
398
410
  export declare function childrenOf<EK extends string, LK extends string>(model: IstarModel<EK, LK>, actorId: string): IstarElement<EK>[];
399
411
  /** Links that have the element as source or target. */
package/dist/index.d.ts CHANGED
@@ -122,7 +122,9 @@ export interface ModelIssue<LK extends string = LinkKind> {
122
122
  * first (each checked before its own links are added), then the remaining links in file
123
123
  * order, each against the graph built so far. Invalid links are reported, not removed.
124
124
  */
125
- export declare function validateModel<EK extends string = ElementKind, LK extends string = LinkKind>(model: IstarModel<EK, LK>, options?: CanLinkOptions<EK, LK>): ModelIssue<LK>[];
125
+ export declare function validateModel<EK extends string, LK extends string>(model: IstarModel<EK, LK>, options: CanLinkOptions<EK, LK>): ModelIssue<LK>[];
126
+ export declare function validateModel<EK extends string, LK extends string>(model: IstarModel<EK, LK>): ModelIssue<LK>[];
127
+ export declare function validateModel(model: IstarModel): ModelIssue[];
126
128
  //#endregion
127
129
  //#region src/metamodels.d.ts
128
130
  export type ElementCategory = "actor" | "node";
@@ -390,10 +392,20 @@ export declare function createEmptyModel(diagram?: Diagram): IstarModel;
390
392
  * iStar 2.0. Constraints, operations and serialization use it unless given another one.
391
393
  */
392
394
  export declare function metamodelOf<EK extends string, LK extends string>(model: IstarModel<EK, LK>): Metamodel<EK, LK>;
393
- /** True for actor-category elements; pass the metamodel for extended actor kinds. */
394
- export declare function isActor(element: IstarElement<string> | undefined, metamodel?: AnyMetamodel): element is IstarActor;
395
- /** True for node-category elements; pass the metamodel for extended node kinds. */
396
- export declare function isNode(element: IstarElement<string> | undefined, metamodel?: AnyMetamodel): element is IstarNode;
395
+ /**
396
+ * True for iStar 2.0 actors (Actor, Agent, Role). One argument, so it is safe as an array
397
+ * callback (`elements.filter(isActor)`). For extended actor kinds use `isActorIn(metamodel)`.
398
+ */
399
+ export declare function isActor(element: IstarElement<string> | undefined): element is IstarActor;
400
+ /** True for iStar 2.0 intentional elements. For extended kinds use `isNodeIn(metamodel)`. */
401
+ export declare function isNode(element: IstarElement<string> | undefined): element is IstarNode;
402
+ /**
403
+ * A predicate for actor-category elements of `metamodel`, extended actor kinds included:
404
+ * `elements.filter(isActorIn(metamodelOf(model)))`.
405
+ */
406
+ export declare function isActorIn(metamodel: AnyMetamodel): (element: IstarElement<string> | undefined) => boolean;
407
+ /** A predicate for node-category elements of `metamodel`, extended node kinds included. */
408
+ export declare function isNodeIn(metamodel: AnyMetamodel): (element: IstarElement<string> | undefined) => boolean;
397
409
  /** Inner elements of an actor, in model order. */
398
410
  export declare function childrenOf<EK extends string, LK extends string>(model: IstarModel<EK, LK>, actorId: string): IstarElement<EK>[];
399
411
  /** Links that have the element as source or target. */
package/dist/index.js CHANGED
@@ -414,13 +414,27 @@ function createEmptyModel(diagram = DEFAULT_DIAGRAM, options = {}) {
414
414
  function metamodelOf(model) {
415
415
  return metamodels.get(model) ?? ISTAR_2_0;
416
416
  }
417
- /** True for actor-category elements; pass the metamodel for extended actor kinds. */
418
- function isActor(element, metamodel = ISTAR_2_0) {
419
- return element !== void 0 && isActorKindIn(metamodel, element.kind);
417
+ /**
418
+ * True for iStar 2.0 actors (Actor, Agent, Role). One argument, so it is safe as an array
419
+ * callback (`elements.filter(isActor)`). For extended actor kinds use `isActorIn(metamodel)`.
420
+ */
421
+ function isActor(element) {
422
+ return element !== void 0 && isActorKindIn(ISTAR_2_0, element.kind);
423
+ }
424
+ /** True for iStar 2.0 intentional elements. For extended kinds use `isNodeIn(metamodel)`. */
425
+ function isNode(element) {
426
+ return element !== void 0 && !isActorKindIn(ISTAR_2_0, element.kind);
420
427
  }
421
- /** True for node-category elements; pass the metamodel for extended node kinds. */
422
- function isNode(element, metamodel = ISTAR_2_0) {
423
- return element !== void 0 && !isActorKindIn(metamodel, element.kind);
428
+ /**
429
+ * A predicate for actor-category elements of `metamodel`, extended actor kinds included:
430
+ * `elements.filter(isActorIn(metamodelOf(model)))`.
431
+ */
432
+ function isActorIn(metamodel) {
433
+ return (element) => element !== void 0 && isActorKindIn(metamodel, element.kind);
434
+ }
435
+ /** A predicate for node-category elements of `metamodel`, extended node kinds included. */
436
+ function isNodeIn(metamodel) {
437
+ return (element) => element !== void 0 && metamodel.elements.get(element.kind)?.category === "node";
424
438
  }
425
439
  /** Inner elements of an actor, in model order. */
426
440
  function childrenOf(model, actorId) {
@@ -689,13 +703,8 @@ const CHECKS = {
689
703
  "istar.ContributionLink": contributionLink,
690
704
  "istar.QualificationLink": qualificationLink
691
705
  };
692
- /**
693
- * Re-validates every link of a model, the way piStar does when loading a file: dependencies
694
- * first (each checked before its own links are added), then the remaining links in file
695
- * order, each against the graph built so far. Invalid links are reported, not removed.
696
- */
697
- function validateModel(model, options = {}) {
698
- const metamodel = options.metamodel ?? metamodelOf(model);
706
+ function validateModel(model, options) {
707
+ const metamodel = (typeof options === "object" && options !== null ? options.metamodel : void 0) ?? metamodelOf(model);
699
708
  const any = model;
700
709
  const issues = [];
701
710
  const accepted = /* @__PURE__ */ new Map();
@@ -1075,7 +1084,7 @@ function typed(model) {
1075
1084
  function metaOf(model) {
1076
1085
  return metamodelOf(model);
1077
1086
  }
1078
- function isActorIn(model, kind) {
1087
+ function isActorIn$1(model, kind) {
1079
1088
  return metaOf(model).elements.get(kind)?.category === "actor";
1080
1089
  }
1081
1090
  function derive(from, changes) {
@@ -1108,7 +1117,7 @@ function addElement(model, input, ctx = {}) {
1108
1117
  if (m.elements.has(id) || m.links.has(id)) throw new ModelOperationError(`id "${id}" is already in use`);
1109
1118
  if (input.parent !== void 0) {
1110
1119
  if (definition.category === "actor") throw new ModelOperationError("actors cannot be nested");
1111
- if (!isActorIn(m, requireElement(m, input.parent).kind)) throw new ModelOperationError(`parent "${input.parent}" is not an actor`);
1120
+ if (!isActorIn$1(m, requireElement(m, input.parent).kind)) throw new ModelOperationError(`parent "${input.parent}" is not an actor`);
1112
1121
  }
1113
1122
  const element = withoutUndefined({
1114
1123
  id,
@@ -1160,7 +1169,7 @@ function moveElement(model, id, x, y) {
1160
1169
  x,
1161
1170
  y
1162
1171
  });
1163
- if (isActorIn(m, current.kind)) {
1172
+ if (isActorIn$1(m, current.kind)) {
1164
1173
  for (const child of m.elements.values()) if (child.parent === id) elements.set(child.id, {
1165
1174
  ...child,
1166
1175
  x: child.x + dx,
@@ -1177,10 +1186,10 @@ function moveElement(model, id, x, y) {
1177
1186
  function nestElement(model, id, parent) {
1178
1187
  const m = any(model);
1179
1188
  const current = requireElement(m, id);
1180
- if (isActorIn(m, current.kind)) throw new ModelOperationError("actors cannot be nested");
1189
+ if (isActorIn$1(m, current.kind)) throw new ModelOperationError("actors cannot be nested");
1181
1190
  if (current.isDependum) throw new ModelOperationError("a dependum cannot be nested");
1182
1191
  if ((current.parent ?? null) === parent) return model;
1183
- if (parent !== null && !isActorIn(m, requireElement(m, parent).kind)) throw new ModelOperationError(`parent "${parent}" is not an actor`);
1192
+ if (parent !== null && !isActorIn$1(m, requireElement(m, parent).kind)) throw new ModelOperationError(`parent "${parent}" is not an actor`);
1184
1193
  const elements = new Map(m.elements);
1185
1194
  elements.delete(id);
1186
1195
  const { parent: _old, ...rest } = current;
@@ -1832,6 +1841,6 @@ function validateModelProperties(model, schemas) {
1832
1841
  return issues;
1833
1842
  }
1834
1843
  //#endregion
1835
- export { ACTOR_KINDS, ACTOR_LINK_KINDS, CONTRIBUTION_LABELS, DEFAULT_DIAGRAM, DEFAULT_ELEMENT_SIZE, DEPENDENCY_LINK_KINDS, ELEMENT_KINDS, ISTAR_2_0, ISTAR_PREFIX, ISTAR_VERSION, LINK_KINDS, LINK_KIND_INFO, METAMODEL_VERSION, MetamodelError, ModelOperationError, NODE_KINDS, NODE_KIND_INFO, NODE_LINK_KINDS, PISTAR_TOOL, PistarParseError, PistarWriteError, addDependency, addElement, boolean, canLink, childrenOf, connect, createEmptyModel, createModelStore, defaultIdGenerator, defineMetamodelExtension, defineProperties, dependencyEnds, dependencyLinksOf, disconnect, effectiveElementKind, effectiveLinkKind, elementBehavesLike, elementKindDefinition, enumOf, extendMetamodel, getSourceLayout, inheritMetamodel, inheritSourceLayout, isActor, isActorKind, isActorKindIn, isActorLinkKind, isContributionLabel, isDependencyLinkKind, isElementKind, isLinkKind, isNode, isNodeKind, isNodeKindIn, isNodeLinkKind, linkKindDefinition, linksOf, metamodelOf, moveElement, nestElement, number, parsePistar, prop, removeElement, removeElements, shortKindName, string, toPistar, toPistarObject, updateDiagram, updateElement, updateLink, validateModel, validateModelProperties, withMetamodel };
1844
+ export { ACTOR_KINDS, ACTOR_LINK_KINDS, CONTRIBUTION_LABELS, DEFAULT_DIAGRAM, DEFAULT_ELEMENT_SIZE, DEPENDENCY_LINK_KINDS, ELEMENT_KINDS, ISTAR_2_0, ISTAR_PREFIX, ISTAR_VERSION, LINK_KINDS, LINK_KIND_INFO, METAMODEL_VERSION, MetamodelError, ModelOperationError, NODE_KINDS, NODE_KIND_INFO, NODE_LINK_KINDS, PISTAR_TOOL, PistarParseError, PistarWriteError, addDependency, addElement, boolean, canLink, childrenOf, connect, createEmptyModel, createModelStore, defaultIdGenerator, defineMetamodelExtension, defineProperties, dependencyEnds, dependencyLinksOf, disconnect, effectiveElementKind, effectiveLinkKind, elementBehavesLike, elementKindDefinition, enumOf, extendMetamodel, getSourceLayout, inheritMetamodel, inheritSourceLayout, isActor, isActorIn, isActorKind, isActorKindIn, isActorLinkKind, isContributionLabel, isDependencyLinkKind, isElementKind, isLinkKind, isNode, isNodeIn, isNodeKind, isNodeKindIn, isNodeLinkKind, linkKindDefinition, linksOf, metamodelOf, moveElement, nestElement, number, parsePistar, prop, removeElement, removeElements, shortKindName, string, toPistar, toPistarObject, updateDiagram, updateElement, updateLink, validateModel, validateModelProperties, withMetamodel };
1836
1845
 
1837
1846
  //# sourceMappingURL=index.js.map