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

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,14 @@ 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\
471
+ to behavior "${transitionName}".`;
472
+ super(msg);
473
+ }
474
+ }
475
+
468
476
  class GraphNode extends Base {
469
477
  /**
470
478
  * Class representing a behavioral control graph node. Each node has a
@@ -537,8 +545,13 @@ class GraphNode extends Base {
537
545
  /**
538
546
  * Adds a behavior to the transitions from this node.
539
547
  * @param {String} behaviorId ID of behavior.
548
+ * @throws {TransitionAlreadyExistsError} Raised when a transition to the
549
+ * provided behavior already exists.
540
550
  */
541
551
  addGoToBehavior (behaviorId) {
552
+ if (this._goToBehaviorIds.includes(behaviorId)) {
553
+ throw new TransitionAlreadyExistsError(this.behaviorName, behaviorId);
554
+ }
542
555
  this._goToBehaviorIds.push(behaviorId);
543
556
  }
544
557
 
@@ -922,7 +935,6 @@ class DALEngine {
922
935
  this.graphs = new Graphs();
923
936
  this.graph = this.graphs.getActiveGraph();
924
937
  this._loadArgs(args);
925
- console.log("Initialized DAL Engine with graphs: ", this.graphs);
926
938
  }
927
939
 
928
940
  /**
@@ -1095,6 +1107,8 @@ class DALEngine {
1095
1107
  * a valid behavior in the graph.
1096
1108
  */
1097
1109
  removeNode (behaviorId) {
1110
+ // TODO: Move this to graph class, this class shouldn't
1111
+ // modifiy the graph structure directly.
1098
1112
  const node = this.graph.findNode(behaviorId);
1099
1113
  const nodeIndex = this.graph.nodes.indexOf(node);
1100
1114
  const removedNode = this.graph.nodes.splice(nodeIndex, 1);
package/dist/index.esm.js CHANGED
@@ -463,6 +463,14 @@ 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\
469
+ to behavior "${transitionName}".`;
470
+ super(msg);
471
+ }
472
+ }
473
+
466
474
  class GraphNode extends Base {
467
475
  /**
468
476
  * Class representing a behavioral control graph node. Each node has a
@@ -535,8 +543,13 @@ class GraphNode extends Base {
535
543
  /**
536
544
  * Adds a behavior to the transitions from this node.
537
545
  * @param {String} behaviorId ID of behavior.
546
+ * @throws {TransitionAlreadyExistsError} Raised when a transition to the
547
+ * provided behavior already exists.
538
548
  */
539
549
  addGoToBehavior (behaviorId) {
550
+ if (this._goToBehaviorIds.includes(behaviorId)) {
551
+ throw new TransitionAlreadyExistsError(this.behaviorName, behaviorId);
552
+ }
540
553
  this._goToBehaviorIds.push(behaviorId);
541
554
  }
542
555
 
@@ -920,7 +933,6 @@ class DALEngine {
920
933
  this.graphs = new Graphs();
921
934
  this.graph = this.graphs.getActiveGraph();
922
935
  this._loadArgs(args);
923
- console.log("Initialized DAL Engine with graphs: ", this.graphs);
924
936
  }
925
937
 
926
938
  /**
@@ -1093,6 +1105,8 @@ class DALEngine {
1093
1105
  * a valid behavior in the graph.
1094
1106
  */
1095
1107
  removeNode (behaviorId) {
1108
+ // TODO: Move this to graph class, this class shouldn't
1109
+ // modifiy the graph structure directly.
1096
1110
  const node = this.graph.findNode(behaviorId);
1097
1111
  const nodeIndex = this.graph.nodes.indexOf(node);
1098
1112
  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.6",
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.behaviorName, 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,11 @@
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\
6
+ to behavior "${transitionName}".`;
7
+ super(msg);
8
+ }
9
+ }
10
+
11
+ 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"});