dal-engine-core-js-lib-dev 0.0.5 → 0.0.7

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 CHANGED
@@ -465,6 +465,13 @@ class Behavior extends Base {
465
465
  }
466
466
  }
467
467
 
468
+ class TransitionAlreadyExistsError extends DALEngineError {
469
+ constructor (behaviorName, transitionName) {
470
+ let msg = `Node with behavior named "${behaviorName}" already has a transition to behavior "${transitionName}".`;
471
+ super(msg);
472
+ }
473
+ }
474
+
468
475
  class GraphNode extends Base {
469
476
  /**
470
477
  * Class representing a behavioral control graph node. Each node has a
@@ -537,8 +544,13 @@ class GraphNode extends Base {
537
544
  /**
538
545
  * Adds a behavior to the transitions from this node.
539
546
  * @param {String} behaviorId ID of behavior.
547
+ * @throws {TransitionAlreadyExistsError} Raised when a transition to the
548
+ * provided behavior already exists.
540
549
  */
541
550
  addGoToBehavior (behaviorId) {
551
+ if (this._goToBehaviorIds.includes(behaviorId)) {
552
+ throw new TransitionAlreadyExistsError(this._behavior.name, behaviorId);
553
+ }
542
554
  this._goToBehaviorIds.push(behaviorId);
543
555
  }
544
556
 
@@ -922,7 +934,6 @@ class DALEngine {
922
934
  this.graphs = new Graphs();
923
935
  this.graph = this.graphs.getActiveGraph();
924
936
  this._loadArgs(args);
925
- console.log("Initialized DAL Engine with graphs: ", this.graphs);
926
937
  }
927
938
 
928
939
  /**
@@ -1095,6 +1106,8 @@ class DALEngine {
1095
1106
  * a valid behavior in the graph.
1096
1107
  */
1097
1108
  removeNode (behaviorId) {
1109
+ // TODO: Move this to graph class, this class shouldn't
1110
+ // modifiy the graph structure directly.
1098
1111
  const node = this.graph.findNode(behaviorId);
1099
1112
  const nodeIndex = this.graph.nodes.indexOf(node);
1100
1113
  const removedNode = this.graph.nodes.splice(nodeIndex, 1);
package/dist/index.esm.js CHANGED
@@ -463,6 +463,13 @@ class Behavior extends Base {
463
463
  }
464
464
  }
465
465
 
466
+ class TransitionAlreadyExistsError extends DALEngineError {
467
+ constructor (behaviorName, transitionName) {
468
+ let msg = `Node with behavior named "${behaviorName}" already has a transition to behavior "${transitionName}".`;
469
+ super(msg);
470
+ }
471
+ }
472
+
466
473
  class GraphNode extends Base {
467
474
  /**
468
475
  * Class representing a behavioral control graph node. Each node has a
@@ -535,8 +542,13 @@ class GraphNode extends Base {
535
542
  /**
536
543
  * Adds a behavior to the transitions from this node.
537
544
  * @param {String} behaviorId ID of behavior.
545
+ * @throws {TransitionAlreadyExistsError} Raised when a transition to the
546
+ * provided behavior already exists.
538
547
  */
539
548
  addGoToBehavior (behaviorId) {
549
+ if (this._goToBehaviorIds.includes(behaviorId)) {
550
+ throw new TransitionAlreadyExistsError(this._behavior.name, behaviorId);
551
+ }
540
552
  this._goToBehaviorIds.push(behaviorId);
541
553
  }
542
554
 
@@ -920,7 +932,6 @@ class DALEngine {
920
932
  this.graphs = new Graphs();
921
933
  this.graph = this.graphs.getActiveGraph();
922
934
  this._loadArgs(args);
923
- console.log("Initialized DAL Engine with graphs: ", this.graphs);
924
935
  }
925
936
 
926
937
  /**
@@ -1093,6 +1104,8 @@ class DALEngine {
1093
1104
  * a valid behavior in the graph.
1094
1105
  */
1095
1106
  removeNode (behaviorId) {
1107
+ // TODO: Move this to graph class, this class shouldn't
1108
+ // modifiy the graph structure directly.
1096
1109
  const node = this.graph.findNode(behaviorId);
1097
1110
  const nodeIndex = this.graph.nodes.indexOf(node);
1098
1111
  const removedNode = this.graph.nodes.splice(nodeIndex, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dal-engine-core-js-lib-dev",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.esm.js",
6
6
  "type": "module",
@@ -1,5 +1,6 @@
1
1
  import Base from "../Base";
2
2
  import MissingAttributes from "../Errors/MissingAttributes";
3
+ import TransitionAlreadyExistsError from "../Errors/TransitionAlreadyExistsError";
3
4
  import isLoadedFromFile from "../helpers/isLoadedFromFile";
4
5
  import Behavior from "../Members/Behavior";
5
6
  import ENGINE_TYPES from "../TYPES";
@@ -77,8 +78,13 @@ class GraphNode extends Base {
77
78
  /**
78
79
  * Adds a behavior to the transitions from this node.
79
80
  * @param {String} behaviorId ID of behavior.
81
+ * @throws {TransitionAlreadyExistsError} Raised when a transition to the
82
+ * provided behavior already exists.
80
83
  */
81
84
  addGoToBehavior (behaviorId) {
85
+ if (this._goToBehaviorIds.includes(behaviorId)) {
86
+ throw new TransitionAlreadyExistsError(this._behavior.name, behaviorId);
87
+ }
82
88
  this._goToBehaviorIds.push(behaviorId);
83
89
  }
84
90
 
package/src/DALEngine.js CHANGED
@@ -30,7 +30,6 @@ export class DALEngine {
30
30
  this.graphs = new Graphs();
31
31
  this.graph = this.graphs.getActiveGraph();
32
32
  this._loadArgs(args);
33
- console.log("Initialized DAL Engine with graphs: ", this.graphs);
34
33
  }
35
34
 
36
35
  /**
@@ -203,6 +202,8 @@ export class DALEngine {
203
202
  * a valid behavior in the graph.
204
203
  */
205
204
  removeNode (behaviorId) {
205
+ // TODO: Move this to graph class, this class shouldn't
206
+ // modifiy the graph structure directly.
206
207
  const node = this.graph.findNode(behaviorId);
207
208
  const nodeIndex = this.graph.nodes.indexOf(node);
208
209
  const removedNode = this.graph.nodes.splice(nodeIndex, 1);
@@ -0,0 +1,10 @@
1
+ import DALEngineError from "./DALEngineError";
2
+
3
+ class TransitionAlreadyExistsError extends DALEngineError {
4
+ constructor (behaviorName, transitionName) {
5
+ let msg = `Node with behavior named "${behaviorName}" already has a transition to behavior "${transitionName}".`;
6
+ super(msg);
7
+ }
8
+ }
9
+
10
+ export default TransitionAlreadyExistsError;
@@ -7,6 +7,7 @@ import {DALEngine} from "../src/DALEngine.js";
7
7
  import BehaviorAlreadyExistsError from "../src/Errors/BehaviorAlreadyExistsError.js";
8
8
  import InvalidTransitionError from "../src/Errors/InvalidTransitionError.js";
9
9
  import MissingAttributes from "../src/Errors/MissingAttributes.js";
10
+ import TransitionAlreadyExistsError from "../src/Errors/TransitionAlreadyExistsError.js";
10
11
  import UnknownBehaviorError from "../src/Errors/UnknownBehaviorError.js";
11
12
  import ENGINE_TYPES from "../src/TYPES.js";
12
13
 
@@ -128,6 +129,16 @@ describe("DALEngine", () => {
128
129
  expect(lastInvariant).toBe(invariant);
129
130
  });
130
131
 
132
+ it ("add duplicate transition and check error is raised", () => {
133
+ const d = new DALEngine({name: "Library Manager"});
134
+ const node1 = d.addNode("AcceptBookFromUser", []);
135
+ const node2 = d.addNode("AddBookToBasket", []);
136
+ node1.addGoToBehavior("AddBookToBasket");
137
+ expect(() => {
138
+ node1.addGoToBehavior("AddBookToBasket");
139
+ }).toThrow(TransitionAlreadyExistsError);
140
+ });
141
+
131
142
  it("serialize to file and deseralize from file", async () => {
132
143
  let d = new DALEngine({name: "Library Manager"});
133
144
  const book = d.createParticipant({name: "book"});