dal-engine-core-js-lib-dev 0.0.3 → 0.0.4

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
@@ -42,18 +42,6 @@ class UnknownBehaviorError extends DALEngineError {
42
42
  }
43
43
  }
44
44
 
45
- let ENGINE_TYPES = {
46
- BEHAVIOR: 1,
47
- INVARIANT: 2,
48
- PARTICIPANT: 3,
49
- PRIMITIVE: 4,
50
- BEHAVIORAL_CONTROL_GRAPH: 5,
51
- GRAPH_NODE: 6,
52
- };
53
- ENGINE_TYPES = Object.freeze(ENGINE_TYPES);
54
-
55
- var ENGINE_TYPES$1 = ENGINE_TYPES;
56
-
57
45
  class MissingAttributes extends DALEngineError {
58
46
  constructor (type, attribute) {
59
47
  let msg;
@@ -66,6 +54,18 @@ class MissingAttributes extends DALEngineError {
66
54
  }
67
55
  }
68
56
 
57
+ let ENGINE_TYPES = {
58
+ BEHAVIOR: 1,
59
+ INVARIANT: 2,
60
+ PARTICIPANT: 3,
61
+ PRIMITIVE: 4,
62
+ BEHAVIORAL_CONTROL_GRAPH: 5,
63
+ GRAPH_NODE: 6,
64
+ };
65
+ ENGINE_TYPES = Object.freeze(ENGINE_TYPES);
66
+
67
+ var ENGINE_TYPES$1 = ENGINE_TYPES;
68
+
69
69
  /**
70
70
  * Class representing a Invariant in the design.
71
71
  */
@@ -389,6 +389,7 @@ class GraphNode extends Base {
389
389
  this.type = ENGINE_TYPES$1.GRAPH_NODE;
390
390
  this._behavior = null;
391
391
  this._goToBehaviorIds = [];
392
+ this._isAtomic = false;
392
393
  if (typeof args === "object" && args !== null) {
393
394
  if (Object.hasOwn(args, "uid")) {
394
395
  this._loadNodeFromJSON(args);
@@ -448,6 +449,10 @@ class GraphNode extends Base {
448
449
  this._goToBehaviorIds.push(...behaviorIds);
449
450
  }
450
451
 
452
+ /**
453
+ * Remove the behavior from the list of transitions.
454
+ * @param {String} behaviorId
455
+ */
451
456
  removeGoToBehavior (behaviorId) {
452
457
  const goToIndex = this._goToBehaviorIds.indexOf(behaviorId);
453
458
  if (goToIndex > -1) {
@@ -455,6 +460,22 @@ class GraphNode extends Base {
455
460
  }
456
461
  }
457
462
 
463
+ /**
464
+ * Raises a flag to indicate if the behavior is atomic or not.
465
+ * @param {Boolean} isAtomic Flag indicates if the behavior is atomic.
466
+ */
467
+ setAtomic (isAtomic) {
468
+ this._isAtomic = isAtomic;
469
+ }
470
+
471
+ /**
472
+ * Returns whether the behavior is atomic or not.
473
+ * @returns {Boolean}
474
+ */
475
+ isAtomic () {
476
+ return this._isAtomic;
477
+ }
478
+
458
479
  /**
459
480
  * Checks if the provided behavior name is a valid
460
481
  * transition from this node.
@@ -509,14 +530,16 @@ class BehavioralControlGraph extends Base {
509
530
 
510
531
  /**
511
532
  * Adds a node to the graph.
512
- * @param {Behavior} behavior
533
+ * @param {Behavior} behaviorId
513
534
  * @param {Array} goToBehaviorsIds
535
+ * @param {Boolean} isAtomic
514
536
  * @returns
515
537
  */
516
- _addNode (behavior, goToBehaviorsIds) {
538
+ _addNode (behaviorId, goToBehaviorsIds, isAtomic) {
517
539
  const node = new GraphNode({
518
- behavior: behavior,
519
- goToBehaviorsIds: goToBehaviorsIds,
540
+ behavior: new Behavior({name: behaviorId}),
541
+ goToBehaviorsIds: goToBehaviorsIds?goToBehaviorsIds:[],
542
+ isAtomic: isAtomic?isAtomic:false,
520
543
  });
521
544
  this.nodes.push(node);
522
545
  return node;
@@ -605,6 +628,7 @@ class BehavioralControlGraph extends Base {
605
628
  class DALEngine {
606
629
  constructor (args) {
607
630
  this.graph = new BehavioralControlGraph();
631
+ this.atomicGraphs = [];
608
632
  this.loadArgs(args);
609
633
  }
610
634
 
@@ -684,12 +708,11 @@ class DALEngine {
684
708
  * Adds a node to the graph with the given behaviorId and goToBehaviors.
685
709
  * @param {String} behaviorId
686
710
  * @param {Array} goToBehaviorsIds
711
+ * @param {Boolean} isAtomic
687
712
  * @returns {GraphNode}
688
713
  */
689
- addNode (behaviorId, goToBehaviorsIds) {
690
- const behavior = this.createBehavior({name: behaviorId});
691
- const goToIds = goToBehaviorsIds?goToBehaviorsIds:[];
692
- return this.graph._addNode(behavior, goToIds);
714
+ addNode (behaviorId, goToBehaviorsIds, isAtomic) {
715
+ return this.graph._addNode(behaviorId, goToBehaviorsIds, isAtomic);
693
716
  }
694
717
 
695
718
  /**
@@ -714,7 +737,6 @@ class DALEngine {
714
737
  this.graph._setCurrentBehavior(behaviorId);
715
738
  }
716
739
 
717
-
718
740
  /**
719
741
  * Transitions the graph to the given behavior if it
720
742
  * is a valid transition from the current behavior.
package/dist/index.esm.js CHANGED
@@ -40,18 +40,6 @@ class UnknownBehaviorError extends DALEngineError {
40
40
  }
41
41
  }
42
42
 
43
- let ENGINE_TYPES$1 = {
44
- BEHAVIOR: 1,
45
- INVARIANT: 2,
46
- PARTICIPANT: 3,
47
- PRIMITIVE: 4,
48
- BEHAVIORAL_CONTROL_GRAPH: 5,
49
- GRAPH_NODE: 6,
50
- };
51
- ENGINE_TYPES$1 = Object.freeze(ENGINE_TYPES$1);
52
-
53
- var ENGINE_TYPES = ENGINE_TYPES$1;
54
-
55
43
  class MissingAttributes extends DALEngineError {
56
44
  constructor (type, attribute) {
57
45
  let msg;
@@ -64,6 +52,18 @@ class MissingAttributes extends DALEngineError {
64
52
  }
65
53
  }
66
54
 
55
+ let ENGINE_TYPES$1 = {
56
+ BEHAVIOR: 1,
57
+ INVARIANT: 2,
58
+ PARTICIPANT: 3,
59
+ PRIMITIVE: 4,
60
+ BEHAVIORAL_CONTROL_GRAPH: 5,
61
+ GRAPH_NODE: 6,
62
+ };
63
+ ENGINE_TYPES$1 = Object.freeze(ENGINE_TYPES$1);
64
+
65
+ var ENGINE_TYPES = ENGINE_TYPES$1;
66
+
67
67
  /**
68
68
  * Class representing a Invariant in the design.
69
69
  */
@@ -387,6 +387,7 @@ class GraphNode extends Base {
387
387
  this.type = ENGINE_TYPES.GRAPH_NODE;
388
388
  this._behavior = null;
389
389
  this._goToBehaviorIds = [];
390
+ this._isAtomic = false;
390
391
  if (typeof args === "object" && args !== null) {
391
392
  if (Object.hasOwn(args, "uid")) {
392
393
  this._loadNodeFromJSON(args);
@@ -446,6 +447,10 @@ class GraphNode extends Base {
446
447
  this._goToBehaviorIds.push(...behaviorIds);
447
448
  }
448
449
 
450
+ /**
451
+ * Remove the behavior from the list of transitions.
452
+ * @param {String} behaviorId
453
+ */
449
454
  removeGoToBehavior (behaviorId) {
450
455
  const goToIndex = this._goToBehaviorIds.indexOf(behaviorId);
451
456
  if (goToIndex > -1) {
@@ -453,6 +458,22 @@ class GraphNode extends Base {
453
458
  }
454
459
  }
455
460
 
461
+ /**
462
+ * Raises a flag to indicate if the behavior is atomic or not.
463
+ * @param {Boolean} isAtomic Flag indicates if the behavior is atomic.
464
+ */
465
+ setAtomic (isAtomic) {
466
+ this._isAtomic = isAtomic;
467
+ }
468
+
469
+ /**
470
+ * Returns whether the behavior is atomic or not.
471
+ * @returns {Boolean}
472
+ */
473
+ isAtomic () {
474
+ return this._isAtomic;
475
+ }
476
+
456
477
  /**
457
478
  * Checks if the provided behavior name is a valid
458
479
  * transition from this node.
@@ -507,14 +528,16 @@ class BehavioralControlGraph extends Base {
507
528
 
508
529
  /**
509
530
  * Adds a node to the graph.
510
- * @param {Behavior} behavior
531
+ * @param {Behavior} behaviorId
511
532
  * @param {Array} goToBehaviorsIds
533
+ * @param {Boolean} isAtomic
512
534
  * @returns
513
535
  */
514
- _addNode (behavior, goToBehaviorsIds) {
536
+ _addNode (behaviorId, goToBehaviorsIds, isAtomic) {
515
537
  const node = new GraphNode({
516
- behavior: behavior,
517
- goToBehaviorsIds: goToBehaviorsIds,
538
+ behavior: new Behavior({name: behaviorId}),
539
+ goToBehaviorsIds: goToBehaviorsIds?goToBehaviorsIds:[],
540
+ isAtomic: isAtomic?isAtomic:false,
518
541
  });
519
542
  this.nodes.push(node);
520
543
  return node;
@@ -603,6 +626,7 @@ class BehavioralControlGraph extends Base {
603
626
  class DALEngine {
604
627
  constructor (args) {
605
628
  this.graph = new BehavioralControlGraph();
629
+ this.atomicGraphs = [];
606
630
  this.loadArgs(args);
607
631
  }
608
632
 
@@ -682,12 +706,11 @@ class DALEngine {
682
706
  * Adds a node to the graph with the given behaviorId and goToBehaviors.
683
707
  * @param {String} behaviorId
684
708
  * @param {Array} goToBehaviorsIds
709
+ * @param {Boolean} isAtomic
685
710
  * @returns {GraphNode}
686
711
  */
687
- addNode (behaviorId, goToBehaviorsIds) {
688
- const behavior = this.createBehavior({name: behaviorId});
689
- const goToIds = goToBehaviorsIds?goToBehaviorsIds:[];
690
- return this.graph._addNode(behavior, goToIds);
712
+ addNode (behaviorId, goToBehaviorsIds, isAtomic) {
713
+ return this.graph._addNode(behaviorId, goToBehaviorsIds, isAtomic);
691
714
  }
692
715
 
693
716
  /**
@@ -712,7 +735,6 @@ class DALEngine {
712
735
  this.graph._setCurrentBehavior(behaviorId);
713
736
  }
714
737
 
715
-
716
738
  /**
717
739
  * Transitions the graph to the given behavior if it
718
740
  * is a valid transition from the current behavior.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dal-engine-core-js-lib-dev",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.esm.js",
6
6
  "type": "module",
@@ -1,6 +1,7 @@
1
1
  import Base from "../Base";
2
2
  import InvalidTransitionError from "../Errors/InvalidTransitionError";
3
3
  import UnknownBehaviorError from "../Errors/UnknownBehaviorError";
4
+ import Behavior from "../Members/Behavior";
4
5
  import ENGINE_TYPES from "../TYPES";
5
6
  import GraphNode from "./GraphNode";
6
7
 
@@ -42,14 +43,16 @@ class BehavioralControlGraph extends Base {
42
43
 
43
44
  /**
44
45
  * Adds a node to the graph.
45
- * @param {Behavior} behavior
46
+ * @param {Behavior} behaviorId
46
47
  * @param {Array} goToBehaviorsIds
48
+ * @param {Boolean} isAtomic
47
49
  * @returns
48
50
  */
49
- _addNode (behavior, goToBehaviorsIds) {
51
+ _addNode (behaviorId, goToBehaviorsIds, isAtomic) {
50
52
  const node = new GraphNode({
51
- behavior: behavior,
52
- goToBehaviorsIds: goToBehaviorsIds,
53
+ behavior: new Behavior({name: behaviorId}),
54
+ goToBehaviorsIds: goToBehaviorsIds?goToBehaviorsIds:[],
55
+ isAtomic: isAtomic?isAtomic:false,
53
56
  });
54
57
  this.nodes.push(node);
55
58
  return node;
@@ -15,6 +15,7 @@ class GraphNode extends Base {
15
15
  this.type = ENGINE_TYPES.GRAPH_NODE;
16
16
  this._behavior = null;
17
17
  this._goToBehaviorIds = [];
18
+ this._isAtomic = false;
18
19
  if (typeof args === "object" && args !== null) {
19
20
  if (Object.hasOwn(args, "uid")) {
20
21
  this._loadNodeFromJSON(args);
@@ -75,6 +76,10 @@ class GraphNode extends Base {
75
76
  this._goToBehaviorIds.push(...behaviorIds);
76
77
  }
77
78
 
79
+ /**
80
+ * Remove the behavior from the list of transitions.
81
+ * @param {String} behaviorId
82
+ */
78
83
  removeGoToBehavior (behaviorId) {
79
84
  const goToIndex = this._goToBehaviorIds.indexOf(behaviorId);
80
85
  if (goToIndex > -1) {
@@ -82,6 +87,22 @@ class GraphNode extends Base {
82
87
  }
83
88
  }
84
89
 
90
+ /**
91
+ * Raises a flag to indicate if the behavior is atomic or not.
92
+ * @param {Boolean} isAtomic Flag indicates if the behavior is atomic.
93
+ */
94
+ setAtomic (isAtomic) {
95
+ this._isAtomic = isAtomic;
96
+ }
97
+
98
+ /**
99
+ * Returns whether the behavior is atomic or not.
100
+ * @returns {Boolean}
101
+ */
102
+ isAtomic () {
103
+ return this._isAtomic;
104
+ }
105
+
85
106
  /**
86
107
  * Checks if the provided behavior name is a valid
87
108
  * transition from this node.
@@ -0,0 +1,35 @@
1
+ import BehavioralControlGraph from "./BehavioralControlGraph";
2
+
3
+ /**
4
+ * Class representing a collection of atomic graphs.
5
+ *
6
+ * These graphs together represent the design. I chose to separate
7
+ * them into their graphs because as the design grows larger, it will
8
+ * be easier to manage the design if it is separated into smaller graphs.
9
+ * It is also easier to visualize in the UI in managable way.
10
+ */
11
+ export class Graphs {
12
+
13
+ constructor () {
14
+ this._graphs = {};
15
+ }
16
+
17
+ /**
18
+ * Adds a graph to the collection of graphs.
19
+ * @param {String} graphId ID of the graph.
20
+ * @returns {BehavioralControlGraph} The graph that was added.
21
+ */
22
+ addGraph (graphId) {
23
+ this._graphs[graphId] = new BehavioralControlGraph();
24
+ return this._graphs[graphId];
25
+ }
26
+
27
+ /**
28
+ * Returns the graph with the given graphId.
29
+ * @param {String} graphId ID of the graph to return.
30
+ * @returns {BehavioralControlGraph} The graph with the given graphId.
31
+ */
32
+ getGraph (graphId) {
33
+ return this._graphs[graphId];
34
+ }
35
+ }
package/src/DALEngine.js CHANGED
@@ -20,6 +20,7 @@ import Participant from "./Members/Participant";
20
20
  export class DALEngine {
21
21
  constructor (args) {
22
22
  this.graph = new BehavioralControlGraph();
23
+ this.atomicGraphs = [];
23
24
  this.loadArgs(args);
24
25
  }
25
26
 
@@ -99,12 +100,11 @@ export class DALEngine {
99
100
  * Adds a node to the graph with the given behaviorId and goToBehaviors.
100
101
  * @param {String} behaviorId
101
102
  * @param {Array} goToBehaviorsIds
103
+ * @param {Boolean} isAtomic
102
104
  * @returns {GraphNode}
103
105
  */
104
- addNode (behaviorId, goToBehaviorsIds) {
105
- const behavior = this.createBehavior({name: behaviorId});
106
- const goToIds = goToBehaviorsIds?goToBehaviorsIds:[];
107
- return this.graph._addNode(behavior, goToIds);
106
+ addNode (behaviorId, goToBehaviorsIds, isAtomic) {
107
+ return this.graph._addNode(behaviorId, goToBehaviorsIds, isAtomic);
108
108
  }
109
109
 
110
110
  /**
@@ -129,7 +129,6 @@ export class DALEngine {
129
129
  this.graph._setCurrentBehavior(behaviorId);
130
130
  }
131
131
 
132
-
133
132
  /**
134
133
  * Transitions the graph to the given behavior if it
135
134
  * is a valid transition from the current behavior.