@amodx/ncs 0.0.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/Components/ComponentData.d.ts +112 -0
- package/Components/ComponentData.js +1 -0
- package/Components/ComponentInstance.d.ts +36 -0
- package/Components/ComponentInstance.js +125 -0
- package/Components/ComponentInstanceMap.d.ts +7 -0
- package/Components/ComponentInstanceMap.js +15 -0
- package/Components/ComponentObservers.d.ts +8 -0
- package/Components/ComponentObservers.js +13 -0
- package/Components/ComponentPipelines.d.ts +16 -0
- package/Components/ComponentPipelines.js +33 -0
- package/Components/ComponentPrototype.d.ts +17 -0
- package/Components/ComponentPrototype.js +73 -0
- package/Contexts/ContextData.d.ts +59 -0
- package/Contexts/ContextData.js +1 -0
- package/Contexts/ContextInstance.d.ts +14 -0
- package/Contexts/ContextInstance.js +26 -0
- package/Contexts/ContextInstanceAnchor.d.ts +15 -0
- package/Contexts/ContextInstanceAnchor.js +33 -0
- package/Contexts/ContextPrototype.d.ts +9 -0
- package/Contexts/ContextPrototype.js +19 -0
- package/Graphs/Graph.d.ts +24 -0
- package/Graphs/Graph.js +90 -0
- package/Graphs/GraphEvents.d.ts +9 -0
- package/Graphs/GraphEvents.js +35 -0
- package/Graphs/GraphObservers.d.ts +9 -0
- package/Graphs/GraphObservers.js +6 -0
- package/Graphs/GraphUpdate.d.ts +13 -0
- package/Graphs/GraphUpdate.js +38 -0
- package/Maps/ItemGraphMap.d.ts +11 -0
- package/Maps/ItemGraphMap.js +30 -0
- package/Maps/ItemNodeMap.d.ts +17 -0
- package/Maps/ItemNodeMap.js +41 -0
- package/NCS.d.ts +54 -0
- package/NCS.js +41 -0
- package/Nodes/Components/NodeComponentObservers.d.ts +15 -0
- package/Nodes/Components/NodeComponentObservers.js +33 -0
- package/Nodes/Components/NodeComponents.d.ts +22 -0
- package/Nodes/Components/NodeComponents.js +107 -0
- package/Nodes/Context/NodeContext.d.ts +13 -0
- package/Nodes/Context/NodeContext.js +45 -0
- package/Nodes/NodeData.d.ts +40 -0
- package/Nodes/NodeData.js +1 -0
- package/Nodes/NodeEvents.d.ts +25 -0
- package/Nodes/NodeEvents.js +62 -0
- package/Nodes/NodeId.d.ts +15 -0
- package/Nodes/NodeId.js +56 -0
- package/Nodes/NodeInstance.d.ts +50 -0
- package/Nodes/NodeInstance.js +202 -0
- package/Nodes/NodeObservers.d.ts +24 -0
- package/Nodes/NodeObservers.js +63 -0
- package/Nodes/NodePipelines.d.ts +16 -0
- package/Nodes/NodePipelines.js +33 -0
- package/Nodes/Tags/NodeTagObservers.d.ts +15 -0
- package/Nodes/Tags/NodeTagObservers.js +33 -0
- package/Nodes/Tags/NodeTags.d.ts +21 -0
- package/Nodes/Tags/NodeTags.js +95 -0
- package/Pools/ItemPool.d.ts +7 -0
- package/Pools/ItemPool.js +18 -0
- package/Pools/NCSPools.d.ts +7 -0
- package/Pools/NCSPools.js +5 -0
- package/Queries/QueryData.d.ts +8 -0
- package/Queries/QueryData.js +1 -0
- package/Queries/QueryInstance.d.ts +12 -0
- package/Queries/QueryInstance.js +78 -0
- package/Queries/QueryPrototype.d.ts +10 -0
- package/Queries/QueryPrototype.js +23 -0
- package/Register/ItemRegister.d.ts +7 -0
- package/Register/ItemRegister.js +24 -0
- package/Register/NCSRegister.d.ts +13 -0
- package/Register/NCSRegister.js +8 -0
- package/Register/registerComponent.d.ts +29 -0
- package/Register/registerComponent.js +54 -0
- package/Register/registerContext.d.ts +16 -0
- package/Register/registerContext.js +37 -0
- package/Register/registerSystem.d.ts +12 -0
- package/Register/registerSystem.js +12 -0
- package/Register/registerTag.d.ts +21 -0
- package/Register/registerTag.js +43 -0
- package/Register/registerTrait.d.ts +15 -0
- package/Register/registerTrait.js +39 -0
- package/Systems/SystemData.d.ts +20 -0
- package/Systems/SystemData.js +1 -0
- package/Systems/SystemInstance.d.ts +11 -0
- package/Systems/SystemInstance.js +19 -0
- package/Systems/SystemPrototype.d.ts +10 -0
- package/Systems/SystemPrototype.js +23 -0
- package/Tags/Tag.d.ts +14 -0
- package/Tags/Tag.js +51 -0
- package/Tags/TagData.d.ts +38 -0
- package/Tags/TagData.js +1 -0
- package/Tags/TagInstance.d.ts +13 -0
- package/Tags/TagInstance.js +17 -0
- package/Tags/TagInstanceMap.d.ts +7 -0
- package/Tags/TagInstanceMap.js +15 -0
- package/Tags/TagPrototype.d.ts +16 -0
- package/Tags/TagPrototype.js +34 -0
- package/Traits/TraitContaienrObservers.d.ts +15 -0
- package/Traits/TraitContaienrObservers.js +33 -0
- package/Traits/TraitContainer.d.ts +22 -0
- package/Traits/TraitContainer.js +114 -0
- package/Traits/TraitData.d.ts +106 -0
- package/Traits/TraitData.js +1 -0
- package/Traits/TraitInstance.d.ts +35 -0
- package/Traits/TraitInstance.js +115 -0
- package/Traits/TraitInstanceMap.d.ts +7 -0
- package/Traits/TraitInstanceMap.js +15 -0
- package/Traits/TraitObservers.d.ts +8 -0
- package/Traits/TraitObservers.js +13 -0
- package/Traits/TraitPipelines.d.ts +16 -0
- package/Traits/TraitPipelines.js +33 -0
- package/Traits/TraitPrototype.d.ts +16 -0
- package/Traits/TraitPrototype.js +74 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/package.json +27 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TagData } from "../Tags/TagData";
|
|
2
|
+
import { ComponentData } from "../Components/ComponentData";
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing the state data of a node.
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeStateData {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Type representing the data of a node.
|
|
11
|
+
*
|
|
12
|
+
* Used for serlization and creation.
|
|
13
|
+
*/
|
|
14
|
+
export type NodeData = {
|
|
15
|
+
/**
|
|
16
|
+
* The unique 128 bit identifier of the node.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* The name of the node.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* The state data of the node.
|
|
26
|
+
*/
|
|
27
|
+
state: NodeStateData;
|
|
28
|
+
/**
|
|
29
|
+
* The components of the node.
|
|
30
|
+
*/
|
|
31
|
+
components?: ComponentData[];
|
|
32
|
+
/**
|
|
33
|
+
* The tags of the node.
|
|
34
|
+
*/
|
|
35
|
+
tags?: TagData[];
|
|
36
|
+
/**
|
|
37
|
+
* The children nodes of the node.
|
|
38
|
+
*/
|
|
39
|
+
children: NodeData[];
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
import { NodeInstance } from "./NodeInstance";
|
|
3
|
+
export declare class NodeEventCursor {
|
|
4
|
+
id: string;
|
|
5
|
+
node: NodeInstance;
|
|
6
|
+
data: any;
|
|
7
|
+
}
|
|
8
|
+
declare class NodeEventsObservers {
|
|
9
|
+
eventTypeAdded: Observable<string>;
|
|
10
|
+
eventDispatched: Observable<NodeEventCursor>;
|
|
11
|
+
}
|
|
12
|
+
export declare class NodeEvents {
|
|
13
|
+
node: NodeInstance;
|
|
14
|
+
observers: NodeEventsObservers;
|
|
15
|
+
private cursor;
|
|
16
|
+
private events;
|
|
17
|
+
constructor(node: NodeInstance);
|
|
18
|
+
hasListener(id: string): boolean;
|
|
19
|
+
clearListeners(id: string): false | undefined;
|
|
20
|
+
addListener<Data>(id: string, run: (data: Data) => void): void;
|
|
21
|
+
removeListener(id: string, run: Function): boolean;
|
|
22
|
+
dispatch<Data>(id: string, data: Data): boolean;
|
|
23
|
+
dispatchDeep<Data>(id: string, data: Data): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
export class NodeEventCursor {
|
|
3
|
+
id;
|
|
4
|
+
node;
|
|
5
|
+
data;
|
|
6
|
+
}
|
|
7
|
+
class NodeEventsObservers {
|
|
8
|
+
eventTypeAdded = new Observable();
|
|
9
|
+
eventDispatched = new Observable();
|
|
10
|
+
}
|
|
11
|
+
export class NodeEvents {
|
|
12
|
+
node;
|
|
13
|
+
observers = new NodeEventsObservers();
|
|
14
|
+
cursor = new NodeEventCursor();
|
|
15
|
+
events = new Map();
|
|
16
|
+
constructor(node) {
|
|
17
|
+
this.node = node;
|
|
18
|
+
}
|
|
19
|
+
hasListener(id) {
|
|
20
|
+
return this.events.has(id);
|
|
21
|
+
}
|
|
22
|
+
clearListeners(id) {
|
|
23
|
+
let observer = this.events.get(id);
|
|
24
|
+
if (!observer)
|
|
25
|
+
return false;
|
|
26
|
+
observer.clear();
|
|
27
|
+
}
|
|
28
|
+
addListener(id, run) {
|
|
29
|
+
let observer = this.events.get(id);
|
|
30
|
+
if (!observer) {
|
|
31
|
+
observer = new Observable();
|
|
32
|
+
this.events.set(id, observer);
|
|
33
|
+
this.observers.eventTypeAdded.notify(id);
|
|
34
|
+
}
|
|
35
|
+
observer.subscribe(run);
|
|
36
|
+
}
|
|
37
|
+
removeListener(id, run) {
|
|
38
|
+
let observer = this.events.get(id);
|
|
39
|
+
if (!observer)
|
|
40
|
+
return false;
|
|
41
|
+
observer.unsubscribe(run);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
dispatch(id, data) {
|
|
45
|
+
let observer = this.events.get(id);
|
|
46
|
+
if (!observer)
|
|
47
|
+
return false;
|
|
48
|
+
observer.notify(data);
|
|
49
|
+
this.cursor.id = id;
|
|
50
|
+
this.cursor.data = data;
|
|
51
|
+
this.observers.eventDispatched.notify(this.cursor);
|
|
52
|
+
if (this.node.graph.events.hasListener(id)) {
|
|
53
|
+
this.node.graph.events.dispatch(id, this.cursor);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
dispatchDeep(id, data) {
|
|
58
|
+
for (const child of this.node.traverseChildren()) {
|
|
59
|
+
child.events.dispatch(id, data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class NodeId {
|
|
2
|
+
high: bigint;
|
|
3
|
+
low: bigint;
|
|
4
|
+
private _idString;
|
|
5
|
+
get idString(): string;
|
|
6
|
+
set idString(id: string);
|
|
7
|
+
private constructor();
|
|
8
|
+
static Compare(id: NodeId, id2: NodeId): boolean;
|
|
9
|
+
static Create(id?: string): NodeId;
|
|
10
|
+
static FromString(id: string): {
|
|
11
|
+
high: bigint;
|
|
12
|
+
low: bigint;
|
|
13
|
+
};
|
|
14
|
+
static ToHexString(id: NodeId): string;
|
|
15
|
+
}
|
package/Nodes/NodeId.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class NodeId {
|
|
2
|
+
high;
|
|
3
|
+
low;
|
|
4
|
+
_idString = "";
|
|
5
|
+
get idString() {
|
|
6
|
+
if (!this._idString)
|
|
7
|
+
this._idString = NodeId.ToHexString(this);
|
|
8
|
+
return this._idString;
|
|
9
|
+
}
|
|
10
|
+
set idString(id) {
|
|
11
|
+
this._idString = id;
|
|
12
|
+
}
|
|
13
|
+
constructor(low, high) {
|
|
14
|
+
this.low = low;
|
|
15
|
+
this.high = high;
|
|
16
|
+
}
|
|
17
|
+
static Compare(id, id2) {
|
|
18
|
+
return id.low == id2.low && id.high == id2.high;
|
|
19
|
+
}
|
|
20
|
+
static Create(id) {
|
|
21
|
+
if (id) {
|
|
22
|
+
const { high, low } = NodeId.FromString(id);
|
|
23
|
+
return new NodeId(low, high);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const array = new Uint8Array(16);
|
|
27
|
+
crypto.getRandomValues(array);
|
|
28
|
+
const high = (BigInt(array[0]) << 56n) |
|
|
29
|
+
(BigInt(array[1]) << 48n) |
|
|
30
|
+
(BigInt(array[2]) << 40n) |
|
|
31
|
+
(BigInt(array[3]) << 32n) |
|
|
32
|
+
(BigInt(array[4]) << 24n) |
|
|
33
|
+
(BigInt(array[5]) << 16n) |
|
|
34
|
+
(BigInt(array[6]) << 8n) |
|
|
35
|
+
BigInt(array[7]);
|
|
36
|
+
const low = (BigInt(array[8]) << 56n) |
|
|
37
|
+
(BigInt(array[9]) << 48n) |
|
|
38
|
+
(BigInt(array[10]) << 40n) |
|
|
39
|
+
(BigInt(array[11]) << 32n) |
|
|
40
|
+
(BigInt(array[12]) << 24n) |
|
|
41
|
+
(BigInt(array[13]) << 16n) |
|
|
42
|
+
(BigInt(array[14]) << 8n) |
|
|
43
|
+
BigInt(array[15]);
|
|
44
|
+
return new NodeId(low, high);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static FromString(id) {
|
|
48
|
+
const high = BigInt("0x" + id.slice(0, 16));
|
|
49
|
+
const low = BigInt("0x" + id.slice(16, 32));
|
|
50
|
+
return { high, low };
|
|
51
|
+
}
|
|
52
|
+
static ToHexString(id) {
|
|
53
|
+
return (id.high.toString(16).padStart(16, "0") +
|
|
54
|
+
id.low.toString(16).padStart(16, "0"));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Graph } from "../Graphs/Graph";
|
|
2
|
+
import { NodeId } from "./NodeId";
|
|
3
|
+
import { NodeData, NodeStateData } from "./NodeData";
|
|
4
|
+
import { NodeEvents } from "./NodeEvents";
|
|
5
|
+
import { NodeObservers } from "./NodeObservers";
|
|
6
|
+
import { NodePipelines } from "./NodePipelines";
|
|
7
|
+
import { NodeContext } from "./Context/NodeContext";
|
|
8
|
+
import { NodeComponents } from "./Components/NodeComponents";
|
|
9
|
+
import { NodeTags } from "./Tags/NodeTags";
|
|
10
|
+
export interface NodeInstance {
|
|
11
|
+
}
|
|
12
|
+
export declare class NodeInstance {
|
|
13
|
+
parent: NodeInstance;
|
|
14
|
+
graph: Graph;
|
|
15
|
+
get id(): NodeId;
|
|
16
|
+
name: string;
|
|
17
|
+
state: NodeStateData;
|
|
18
|
+
private _events?;
|
|
19
|
+
get events(): NodeEvents;
|
|
20
|
+
get hasEvents(): boolean;
|
|
21
|
+
private _context?;
|
|
22
|
+
get context(): NodeContext;
|
|
23
|
+
get hasContexts(): boolean;
|
|
24
|
+
private _observers?;
|
|
25
|
+
get observers(): NodeObservers;
|
|
26
|
+
get hasObservers(): boolean;
|
|
27
|
+
private _pipelines?;
|
|
28
|
+
get pipelines(): NodePipelines;
|
|
29
|
+
get hasPipelines(): boolean;
|
|
30
|
+
private _components?;
|
|
31
|
+
get components(): NodeComponents;
|
|
32
|
+
get hasComponents(): boolean;
|
|
33
|
+
private _tags?;
|
|
34
|
+
get tags(): NodeTags;
|
|
35
|
+
get hasTags(): boolean;
|
|
36
|
+
children: NodeInstance[];
|
|
37
|
+
private nodeId;
|
|
38
|
+
constructor(parent: NodeInstance, data: NodeData, graph: Graph);
|
|
39
|
+
traverseChildren(): Generator<NodeInstance>;
|
|
40
|
+
traverseParents(): Generator<NodeInstance>;
|
|
41
|
+
private _disposed;
|
|
42
|
+
isDisposed(): boolean;
|
|
43
|
+
dispose(): Promise<void>;
|
|
44
|
+
addChildren(...nodes: NodeData[]): Promise<void>;
|
|
45
|
+
parentTo(node: NodeInstance): void;
|
|
46
|
+
addChild(node: NodeInstance): void;
|
|
47
|
+
removeChild(id: NodeId): NodeInstance | null;
|
|
48
|
+
copy(): NodeData;
|
|
49
|
+
toJSON(): NodeData;
|
|
50
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { NodeId } from "./NodeId";
|
|
2
|
+
import { NodeEvents } from "./NodeEvents";
|
|
3
|
+
import { NodeObservers } from "./NodeObservers";
|
|
4
|
+
import { NodePipelines } from "./NodePipelines";
|
|
5
|
+
import { NodeContext } from "./Context/NodeContext";
|
|
6
|
+
import { NodeComponents } from "./Components/NodeComponents";
|
|
7
|
+
import { NodeTags } from "./Tags/NodeTags";
|
|
8
|
+
export class NodeInstance {
|
|
9
|
+
parent;
|
|
10
|
+
graph;
|
|
11
|
+
get id() {
|
|
12
|
+
return this.nodeId;
|
|
13
|
+
}
|
|
14
|
+
name;
|
|
15
|
+
state;
|
|
16
|
+
_events;
|
|
17
|
+
get events() {
|
|
18
|
+
if (!this._events) {
|
|
19
|
+
this._events = new NodeEvents(this);
|
|
20
|
+
}
|
|
21
|
+
return this._events;
|
|
22
|
+
}
|
|
23
|
+
get hasEvents() {
|
|
24
|
+
return Boolean(this._context);
|
|
25
|
+
}
|
|
26
|
+
_context;
|
|
27
|
+
get context() {
|
|
28
|
+
if (!this._context) {
|
|
29
|
+
this._context = new NodeContext(this);
|
|
30
|
+
}
|
|
31
|
+
return this._context;
|
|
32
|
+
}
|
|
33
|
+
get hasContexts() {
|
|
34
|
+
return Boolean(this._context);
|
|
35
|
+
}
|
|
36
|
+
_observers;
|
|
37
|
+
get observers() {
|
|
38
|
+
if (!this._observers) {
|
|
39
|
+
this._observers = new NodeObservers();
|
|
40
|
+
}
|
|
41
|
+
return this._observers;
|
|
42
|
+
}
|
|
43
|
+
get hasObservers() {
|
|
44
|
+
return Boolean(this._observers);
|
|
45
|
+
}
|
|
46
|
+
_pipelines;
|
|
47
|
+
get pipelines() {
|
|
48
|
+
if (!this._pipelines) {
|
|
49
|
+
this._pipelines = new NodePipelines();
|
|
50
|
+
}
|
|
51
|
+
return this._pipelines;
|
|
52
|
+
}
|
|
53
|
+
get hasPipelines() {
|
|
54
|
+
return Boolean(this._pipelines);
|
|
55
|
+
}
|
|
56
|
+
_components;
|
|
57
|
+
get components() {
|
|
58
|
+
if (!this._components) {
|
|
59
|
+
this._components = new NodeComponents(this);
|
|
60
|
+
}
|
|
61
|
+
return this._components;
|
|
62
|
+
}
|
|
63
|
+
get hasComponents() {
|
|
64
|
+
return Boolean(this._components);
|
|
65
|
+
}
|
|
66
|
+
_tags;
|
|
67
|
+
get tags() {
|
|
68
|
+
if (!this._tags) {
|
|
69
|
+
this._tags = new NodeTags(this);
|
|
70
|
+
}
|
|
71
|
+
return this._tags;
|
|
72
|
+
}
|
|
73
|
+
get hasTags() {
|
|
74
|
+
return Boolean(this._tags);
|
|
75
|
+
}
|
|
76
|
+
children = [];
|
|
77
|
+
nodeId;
|
|
78
|
+
constructor(parent, data, graph) {
|
|
79
|
+
this.parent = parent;
|
|
80
|
+
this.graph = graph;
|
|
81
|
+
this.name = data.name;
|
|
82
|
+
this.state = data.state;
|
|
83
|
+
this.nodeId = NodeId.Create(data.id);
|
|
84
|
+
}
|
|
85
|
+
*traverseChildren() {
|
|
86
|
+
const children = [...this.children];
|
|
87
|
+
while (children.length) {
|
|
88
|
+
const child = children.shift();
|
|
89
|
+
yield child;
|
|
90
|
+
if (child.children.length)
|
|
91
|
+
children.push(...child.children);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
*traverseParents() {
|
|
95
|
+
let parent = this.parent;
|
|
96
|
+
while (parent) {
|
|
97
|
+
yield parent;
|
|
98
|
+
parent = parent.parent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_disposed = false;
|
|
102
|
+
isDisposed() {
|
|
103
|
+
return this._disposed;
|
|
104
|
+
}
|
|
105
|
+
async dispose() {
|
|
106
|
+
if (this._disposed)
|
|
107
|
+
return;
|
|
108
|
+
this._disposed = true;
|
|
109
|
+
this.graph.removeNode(this.id);
|
|
110
|
+
this.parent?.removeChild(this.id);
|
|
111
|
+
this.hasComponents && (await this.components.dispose());
|
|
112
|
+
this.hasTags && (await this.tags.dispose());
|
|
113
|
+
for (const child of this.children) {
|
|
114
|
+
await child.dispose();
|
|
115
|
+
}
|
|
116
|
+
this.hasPipelines &&
|
|
117
|
+
this.pipelines.isDisposedSet() &&
|
|
118
|
+
this.pipelines.disposed.pipe(this);
|
|
119
|
+
this.hasObservers &&
|
|
120
|
+
this.observers.isDisposedSet() &&
|
|
121
|
+
this.observers.disposed.notify();
|
|
122
|
+
delete this._observers;
|
|
123
|
+
delete this._pipelines;
|
|
124
|
+
delete this._events;
|
|
125
|
+
delete this._context;
|
|
126
|
+
delete this._tags;
|
|
127
|
+
}
|
|
128
|
+
async addChildren(...nodes) {
|
|
129
|
+
for (const node of nodes) {
|
|
130
|
+
const newNode = await this.graph.addNode(node, this);
|
|
131
|
+
this.addChild(newNode);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
parentTo(node) {
|
|
135
|
+
if (this.children.find((_) => NodeId.Compare(_.id, node.id)))
|
|
136
|
+
return;
|
|
137
|
+
this.parent?.removeChild(this.id);
|
|
138
|
+
node.addChild(this);
|
|
139
|
+
this.parent = node;
|
|
140
|
+
this.hasObservers &&
|
|
141
|
+
this.observers.isParentedSet() &&
|
|
142
|
+
node.observers.parented.notify();
|
|
143
|
+
}
|
|
144
|
+
addChild(node) {
|
|
145
|
+
if (this.children.find((_) => NodeId.Compare(_.id, node.id)))
|
|
146
|
+
return;
|
|
147
|
+
node.parent = this;
|
|
148
|
+
this.children.push(node);
|
|
149
|
+
this.hasObservers &&
|
|
150
|
+
this.observers.isChildAddedSet() &&
|
|
151
|
+
this.observers.childAdded.notify(node);
|
|
152
|
+
node.hasObservers &&
|
|
153
|
+
node.observers.isParentedSet() &&
|
|
154
|
+
node.observers.parented.notify();
|
|
155
|
+
}
|
|
156
|
+
removeChild(id) {
|
|
157
|
+
const index = this.children.findIndex((_) => _ && NodeId.Compare(id, _.id));
|
|
158
|
+
if (index !== -1) {
|
|
159
|
+
const child = this.children.splice(index, 1)[0];
|
|
160
|
+
this.hasObservers &&
|
|
161
|
+
this.observers.isChildRemovedSet() &&
|
|
162
|
+
this.observers.childRemoved.notify(child);
|
|
163
|
+
this.hasObservers &&
|
|
164
|
+
this.observers.isRemovedFromParentSet() &&
|
|
165
|
+
child.observers.removedFromParent.notify();
|
|
166
|
+
return child;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
copy() {
|
|
171
|
+
const data = {
|
|
172
|
+
id: NodeId.Create().idString,
|
|
173
|
+
name: this.name,
|
|
174
|
+
state: this.state,
|
|
175
|
+
children: this.children.map((_) => _.copy()),
|
|
176
|
+
tags: (this.hasTags && this.tags.tags.map((_) => _.toJSON())) || undefined,
|
|
177
|
+
components: (this.hasComponents &&
|
|
178
|
+
this.components.components.map((_) => _.copy())) ||
|
|
179
|
+
undefined,
|
|
180
|
+
};
|
|
181
|
+
return ((this.hasPipelines &&
|
|
182
|
+
this.pipelines.isCopySet() &&
|
|
183
|
+
this.pipelines.copy.pipe(data)) ||
|
|
184
|
+
data);
|
|
185
|
+
}
|
|
186
|
+
toJSON() {
|
|
187
|
+
const data = {
|
|
188
|
+
id: NodeId.Create().idString,
|
|
189
|
+
name: this.name,
|
|
190
|
+
state: this.state,
|
|
191
|
+
children: this.children.map((_) => _.copy()),
|
|
192
|
+
tags: (this.hasTags && this.tags.tags.map((_) => _.toJSON())) || undefined,
|
|
193
|
+
components: (this.hasComponents &&
|
|
194
|
+
this.components.components.map((_) => _.copy())) ||
|
|
195
|
+
undefined,
|
|
196
|
+
};
|
|
197
|
+
return ((this.hasPipelines &&
|
|
198
|
+
this.pipelines.isToJSONSet() &&
|
|
199
|
+
this.pipelines.toJSON.pipe(data)) ||
|
|
200
|
+
data);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
import { NodeInstance } from "./NodeInstance";
|
|
3
|
+
export interface NodeObservers {
|
|
4
|
+
}
|
|
5
|
+
export declare class NodeObservers {
|
|
6
|
+
private _disposed?;
|
|
7
|
+
private _parented?;
|
|
8
|
+
private _removedFromParent?;
|
|
9
|
+
private _childAdded?;
|
|
10
|
+
private _childRemoved?;
|
|
11
|
+
private _childrenUpdated?;
|
|
12
|
+
get disposed(): Observable<void>;
|
|
13
|
+
get parented(): Observable<void>;
|
|
14
|
+
get removedFromParent(): Observable<void>;
|
|
15
|
+
get childAdded(): Observable<NodeInstance>;
|
|
16
|
+
get childRemoved(): Observable<NodeInstance>;
|
|
17
|
+
get childrenUpdated(): Observable<void>;
|
|
18
|
+
isDisposedSet(): boolean;
|
|
19
|
+
isParentedSet(): boolean;
|
|
20
|
+
isRemovedFromParentSet(): boolean;
|
|
21
|
+
isChildAddedSet(): boolean;
|
|
22
|
+
isChildRemovedSet(): boolean;
|
|
23
|
+
isChildrenUpdatedSet(): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
export class NodeObservers {
|
|
3
|
+
_disposed;
|
|
4
|
+
_parented;
|
|
5
|
+
_removedFromParent;
|
|
6
|
+
_childAdded;
|
|
7
|
+
_childRemoved;
|
|
8
|
+
_childrenUpdated;
|
|
9
|
+
get disposed() {
|
|
10
|
+
if (!this._disposed) {
|
|
11
|
+
this._disposed = new Observable();
|
|
12
|
+
}
|
|
13
|
+
return this._disposed;
|
|
14
|
+
}
|
|
15
|
+
get parented() {
|
|
16
|
+
if (!this._parented) {
|
|
17
|
+
this._parented = new Observable();
|
|
18
|
+
}
|
|
19
|
+
return this._parented;
|
|
20
|
+
}
|
|
21
|
+
get removedFromParent() {
|
|
22
|
+
if (!this._removedFromParent) {
|
|
23
|
+
this._removedFromParent = new Observable();
|
|
24
|
+
}
|
|
25
|
+
return this._removedFromParent;
|
|
26
|
+
}
|
|
27
|
+
get childAdded() {
|
|
28
|
+
if (!this._childAdded) {
|
|
29
|
+
this._childAdded = new Observable();
|
|
30
|
+
}
|
|
31
|
+
return this._childAdded;
|
|
32
|
+
}
|
|
33
|
+
get childRemoved() {
|
|
34
|
+
if (!this._childRemoved) {
|
|
35
|
+
this._childRemoved = new Observable();
|
|
36
|
+
}
|
|
37
|
+
return this._childRemoved;
|
|
38
|
+
}
|
|
39
|
+
get childrenUpdated() {
|
|
40
|
+
if (!this._childrenUpdated) {
|
|
41
|
+
this._childrenUpdated = new Observable();
|
|
42
|
+
}
|
|
43
|
+
return this._childrenUpdated;
|
|
44
|
+
}
|
|
45
|
+
isDisposedSet() {
|
|
46
|
+
return !!this._disposed;
|
|
47
|
+
}
|
|
48
|
+
isParentedSet() {
|
|
49
|
+
return !!this._parented;
|
|
50
|
+
}
|
|
51
|
+
isRemovedFromParentSet() {
|
|
52
|
+
return !!this._removedFromParent;
|
|
53
|
+
}
|
|
54
|
+
isChildAddedSet() {
|
|
55
|
+
return !!this._childAdded;
|
|
56
|
+
}
|
|
57
|
+
isChildRemovedSet() {
|
|
58
|
+
return !!this._childRemoved;
|
|
59
|
+
}
|
|
60
|
+
isChildrenUpdatedSet() {
|
|
61
|
+
return !!this._childrenUpdated;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
|
+
import { NodeInstance } from "./NodeInstance";
|
|
3
|
+
import { NodeData } from "./NodeData";
|
|
4
|
+
export interface NodePipelines {
|
|
5
|
+
}
|
|
6
|
+
export declare class NodePipelines {
|
|
7
|
+
private _disposed?;
|
|
8
|
+
private _toJSON?;
|
|
9
|
+
private _copy?;
|
|
10
|
+
get disposed(): Pipeline<NodeInstance>;
|
|
11
|
+
get toJSON(): Pipeline<NodeData>;
|
|
12
|
+
get copy(): Pipeline<NodeData>;
|
|
13
|
+
isDisposedSet(): boolean;
|
|
14
|
+
isToJSONSet(): boolean;
|
|
15
|
+
isCopySet(): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
|
+
export class NodePipelines {
|
|
3
|
+
_disposed;
|
|
4
|
+
_toJSON;
|
|
5
|
+
_copy;
|
|
6
|
+
get disposed() {
|
|
7
|
+
if (!this._disposed) {
|
|
8
|
+
this._disposed = new Pipeline();
|
|
9
|
+
}
|
|
10
|
+
return this._disposed;
|
|
11
|
+
}
|
|
12
|
+
get toJSON() {
|
|
13
|
+
if (!this._toJSON) {
|
|
14
|
+
this._toJSON = new Pipeline();
|
|
15
|
+
}
|
|
16
|
+
return this._toJSON;
|
|
17
|
+
}
|
|
18
|
+
get copy() {
|
|
19
|
+
if (!this._copy) {
|
|
20
|
+
this._copy = new Pipeline();
|
|
21
|
+
}
|
|
22
|
+
return this._copy;
|
|
23
|
+
}
|
|
24
|
+
isDisposedSet() {
|
|
25
|
+
return !!this._disposed;
|
|
26
|
+
}
|
|
27
|
+
isToJSONSet() {
|
|
28
|
+
return !!this._toJSON;
|
|
29
|
+
}
|
|
30
|
+
isCopySet() {
|
|
31
|
+
return !!this._copy;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
import { TagInstance } from "../../Tags/TagInstance";
|
|
3
|
+
export interface NodeTagObservers {
|
|
4
|
+
}
|
|
5
|
+
export declare class NodeTagObservers {
|
|
6
|
+
private _tagAdded?;
|
|
7
|
+
private _tagRemoved?;
|
|
8
|
+
private _tagsUpdated?;
|
|
9
|
+
get tagsAdded(): Observable<TagInstance>;
|
|
10
|
+
get tagsRemoved(): Observable<TagInstance>;
|
|
11
|
+
get tagsUpdated(): Observable<void>;
|
|
12
|
+
isTagsAddedSet(): boolean;
|
|
13
|
+
isTagsRemovedSet(): boolean;
|
|
14
|
+
isTagsUpdatedSet(): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Observable } from "@amodx/core/Observers";
|
|
2
|
+
export class NodeTagObservers {
|
|
3
|
+
_tagAdded;
|
|
4
|
+
_tagRemoved;
|
|
5
|
+
_tagsUpdated;
|
|
6
|
+
get tagsAdded() {
|
|
7
|
+
if (!this._tagAdded) {
|
|
8
|
+
this._tagAdded = new Observable();
|
|
9
|
+
}
|
|
10
|
+
return this._tagAdded;
|
|
11
|
+
}
|
|
12
|
+
get tagsRemoved() {
|
|
13
|
+
if (!this._tagRemoved) {
|
|
14
|
+
this._tagRemoved = new Observable();
|
|
15
|
+
}
|
|
16
|
+
return this._tagRemoved;
|
|
17
|
+
}
|
|
18
|
+
get tagsUpdated() {
|
|
19
|
+
if (!this._tagsUpdated) {
|
|
20
|
+
this._tagsUpdated = new Observable();
|
|
21
|
+
}
|
|
22
|
+
return this._tagsUpdated;
|
|
23
|
+
}
|
|
24
|
+
isTagsAddedSet() {
|
|
25
|
+
return !!this._tagAdded;
|
|
26
|
+
}
|
|
27
|
+
isTagsRemovedSet() {
|
|
28
|
+
return !!this._tagRemoved;
|
|
29
|
+
}
|
|
30
|
+
isTagsUpdatedSet() {
|
|
31
|
+
return !!this._tagsUpdated;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NodeInstance } from "../NodeInstance";
|
|
2
|
+
import { NodeTagObservers } from "./NodeTagObservers";
|
|
3
|
+
import { TagInstance } from "../../Tags/TagInstance";
|
|
4
|
+
import { TagData } from "../../Tags/TagData";
|
|
5
|
+
export declare class NodeTags {
|
|
6
|
+
node: NodeInstance;
|
|
7
|
+
private _observers?;
|
|
8
|
+
get observers(): NodeTagObservers;
|
|
9
|
+
get hasObservers(): boolean;
|
|
10
|
+
tags: TagInstance[];
|
|
11
|
+
constructor(node: NodeInstance);
|
|
12
|
+
dispose(): void;
|
|
13
|
+
add(tag: TagData): TagInstance;
|
|
14
|
+
addTags(...components: TagData[]): void;
|
|
15
|
+
remove(type: string): boolean;
|
|
16
|
+
get(type: string): TagInstance | null;
|
|
17
|
+
getChild(type: string): TagInstance | null;
|
|
18
|
+
getAllChildlren(type: string): TagInstance[];
|
|
19
|
+
getParent(type: string): TagInstance | null;
|
|
20
|
+
getAllParents(type: string): TagInstance[];
|
|
21
|
+
}
|