@amodx/ncs 0.0.1 → 0.0.2

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.
Files changed (181) hide show
  1. package/Components/Component.types.d.ts +78 -0
  2. package/Components/ComponentArray.d.ts +30 -0
  3. package/Components/ComponentArray.js +82 -0
  4. package/Components/ComponentCursor.d.ts +27 -0
  5. package/Components/ComponentCursor.js +72 -0
  6. package/Contexts/Context.types.d.ts +76 -0
  7. package/Contexts/ContextArray.d.ts +14 -0
  8. package/Contexts/ContextArray.js +47 -0
  9. package/Contexts/ContextCursor.d.ts +20 -0
  10. package/Contexts/ContextCursor.js +39 -0
  11. package/Data/SerializedData.types.d.ts +44 -0
  12. package/Data/deserializeComponent.d.ts +3 -0
  13. package/Data/deserializeComponent.js +3 -0
  14. package/Data/deserializeNode.d.ts +3 -0
  15. package/Data/deserializeNode.js +34 -0
  16. package/Data/serializeComponent.d.ts +7 -0
  17. package/Data/serializeComponent.js +36 -0
  18. package/Data/serializeNode.d.ts +13 -0
  19. package/Data/serializeNode.js +83 -0
  20. package/Functional.d.ts +12 -0
  21. package/Functional.js +31 -0
  22. package/Graphs/Graph.d.ts +19 -21
  23. package/Graphs/Graph.js +85 -74
  24. package/NCS.d.ts +79 -48
  25. package/NCS.js +108 -32
  26. package/Nodes/Node.types.d.ts +39 -0
  27. package/Nodes/Node.types.js +16 -0
  28. package/Nodes/NodeArray.d.ts +25 -0
  29. package/Nodes/NodeArray.js +96 -0
  30. package/Nodes/NodeComponents.d.ts +19 -0
  31. package/Nodes/NodeComponents.js +180 -0
  32. package/Nodes/NodeContext.d.ts +14 -0
  33. package/Nodes/NodeContext.js +107 -0
  34. package/Nodes/NodeCursor.d.ts +65 -0
  35. package/Nodes/NodeCursor.js +348 -0
  36. package/Nodes/NodeEvents.d.ts +10 -13
  37. package/Nodes/NodeEvents.js +51 -26
  38. package/Nodes/NodeId.d.ts +4 -13
  39. package/Nodes/NodeId.js +16 -48
  40. package/Nodes/NodeObservers.d.ts +35 -20
  41. package/Nodes/NodeObservers.js +162 -37
  42. package/Nodes/NodeTags.d.ts +17 -0
  43. package/Nodes/NodeTags.js +102 -0
  44. package/Pools/NCSPools.d.ts +27 -4
  45. package/Pools/NCSPools.js +14 -2
  46. package/Queries/Query.types.d.ts +8 -0
  47. package/Queries/QueryInstance.d.ts +6 -4
  48. package/Queries/QueryInstance.js +89 -44
  49. package/Queries/QueryPrototype.d.ts +1 -1
  50. package/Register/NCSRegister.d.ts +17 -9
  51. package/Register/NCSRegister.js +25 -2
  52. package/Register/registerComponent.d.ts +31 -25
  53. package/Register/registerComponent.js +88 -36
  54. package/Register/registerContext.d.ts +10 -13
  55. package/Register/registerContext.js +13 -18
  56. package/Register/registerSystem.d.ts +1 -1
  57. package/Register/registerSystem.js +1 -1
  58. package/Register/registerTag.d.ts +15 -17
  59. package/Register/registerTag.js +20 -23
  60. package/Schema/Functions/createBaseSchemaCursor.d.ts +18 -0
  61. package/Schema/Functions/createBaseSchemaCursor.js +34 -0
  62. package/Schema/Functions/createSchemaBinaryObjectCursorClass.d.ts +22 -0
  63. package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +134 -0
  64. package/Schema/Functions/createSchemaIndex.d.ts +3 -0
  65. package/Schema/Functions/createSchemaIndex.js +18 -0
  66. package/Schema/Functions/createSchemaObjectCursorClass.d.ts +18 -0
  67. package/Schema/Functions/createSchemaObjectCursorClass.js +66 -0
  68. package/Schema/Functions/createSchemaTypedArrayCursorClass.d.ts +17 -0
  69. package/Schema/Functions/createSchemaTypedArrayCursorClass.js +66 -0
  70. package/Schema/Property/Property.d.ts +11 -0
  71. package/Schema/Property/Property.js +16 -0
  72. package/Schema/Property/Property.types.d.ts +26 -0
  73. package/Schema/Property/Property.types.js +20 -0
  74. package/Schema/Schema.d.ts +28 -0
  75. package/Schema/Schema.js +223 -0
  76. package/Schema/Schema.types.d.ts +59 -0
  77. package/Schema/Schema.types.js +8 -0
  78. package/Schema/SchemaArray.d.ts +23 -0
  79. package/Schema/SchemaArray.js +87 -0
  80. package/Schema/SchemaArrayCursor.d.ts +19 -0
  81. package/Schema/SchemaArrayCursor.js +56 -0
  82. package/Schema/SchemaView.d.ts +24 -0
  83. package/Schema/SchemaView.js +141 -0
  84. package/Systems/{SystemData.d.ts → System.types.d.ts} +0 -4
  85. package/Systems/SystemInstance.d.ts +6 -4
  86. package/Systems/SystemInstance.js +14 -8
  87. package/Systems/SystemPrototype.d.ts +1 -1
  88. package/Systems/SystemPrototype.js +0 -1
  89. package/Tags/Tag.d.ts +1 -1
  90. package/Tags/Tag.js +1 -1
  91. package/Tags/{TagData.d.ts → Tag.types.d.ts} +0 -17
  92. package/Tags/TagArray.d.ts +18 -0
  93. package/Tags/TagArray.js +37 -0
  94. package/Tags/TagCursor.d.ts +20 -0
  95. package/Tags/TagCursor.js +45 -0
  96. package/Util/IdPalette.d.ts +13 -0
  97. package/Util/IdPalette.js +38 -0
  98. package/{Pools → Util}/ItemPool.d.ts +2 -3
  99. package/{Pools → Util}/ItemPool.js +2 -4
  100. package/Util/Observable.d.ts +28 -0
  101. package/Util/Observable.js +58 -0
  102. package/Util/Util.types.d.ts +4 -0
  103. package/index.d.ts +16 -6
  104. package/index.js +24 -6
  105. package/package.json +1 -1
  106. package/Components/ComponentData.d.ts +0 -112
  107. package/Components/ComponentInstance.d.ts +0 -36
  108. package/Components/ComponentInstance.js +0 -125
  109. package/Components/ComponentInstanceMap.d.ts +0 -7
  110. package/Components/ComponentInstanceMap.js +0 -15
  111. package/Components/ComponentObservers.d.ts +0 -8
  112. package/Components/ComponentObservers.js +0 -13
  113. package/Components/ComponentPipelines.d.ts +0 -16
  114. package/Components/ComponentPipelines.js +0 -33
  115. package/Components/ComponentPrototype.d.ts +0 -17
  116. package/Components/ComponentPrototype.js +0 -73
  117. package/Contexts/ContextData.d.ts +0 -59
  118. package/Contexts/ContextInstance.d.ts +0 -14
  119. package/Contexts/ContextInstance.js +0 -26
  120. package/Contexts/ContextInstanceAnchor.d.ts +0 -15
  121. package/Contexts/ContextInstanceAnchor.js +0 -33
  122. package/Contexts/ContextPrototype.d.ts +0 -9
  123. package/Contexts/ContextPrototype.js +0 -19
  124. package/Graphs/GraphEvents.d.ts +0 -9
  125. package/Graphs/GraphEvents.js +0 -35
  126. package/Graphs/GraphObservers.d.ts +0 -9
  127. package/Graphs/GraphObservers.js +0 -6
  128. package/Graphs/GraphUpdate.d.ts +0 -13
  129. package/Graphs/GraphUpdate.js +0 -38
  130. package/Maps/ItemGraphMap.d.ts +0 -11
  131. package/Maps/ItemGraphMap.js +0 -30
  132. package/Maps/ItemNodeMap.d.ts +0 -17
  133. package/Maps/ItemNodeMap.js +0 -41
  134. package/Nodes/Components/NodeComponentObservers.d.ts +0 -15
  135. package/Nodes/Components/NodeComponentObservers.js +0 -33
  136. package/Nodes/Components/NodeComponents.d.ts +0 -22
  137. package/Nodes/Components/NodeComponents.js +0 -107
  138. package/Nodes/Context/NodeContext.d.ts +0 -13
  139. package/Nodes/Context/NodeContext.js +0 -45
  140. package/Nodes/NodeData.d.ts +0 -40
  141. package/Nodes/NodeInstance.d.ts +0 -50
  142. package/Nodes/NodeInstance.js +0 -202
  143. package/Nodes/NodePipelines.d.ts +0 -16
  144. package/Nodes/NodePipelines.js +0 -33
  145. package/Nodes/Tags/NodeTagObservers.d.ts +0 -15
  146. package/Nodes/Tags/NodeTagObservers.js +0 -33
  147. package/Nodes/Tags/NodeTags.d.ts +0 -21
  148. package/Nodes/Tags/NodeTags.js +0 -95
  149. package/Queries/QueryData.d.ts +0 -8
  150. package/Register/ItemRegister.d.ts +0 -7
  151. package/Register/ItemRegister.js +0 -24
  152. package/Register/registerTrait.d.ts +0 -15
  153. package/Register/registerTrait.js +0 -39
  154. package/Tags/TagInstance.d.ts +0 -13
  155. package/Tags/TagInstance.js +0 -17
  156. package/Tags/TagInstanceMap.d.ts +0 -7
  157. package/Tags/TagInstanceMap.js +0 -15
  158. package/Tags/TagPrototype.d.ts +0 -16
  159. package/Tags/TagPrototype.js +0 -34
  160. package/Traits/TraitContaienrObservers.d.ts +0 -15
  161. package/Traits/TraitContaienrObservers.js +0 -33
  162. package/Traits/TraitContainer.d.ts +0 -22
  163. package/Traits/TraitContainer.js +0 -114
  164. package/Traits/TraitData.d.ts +0 -106
  165. package/Traits/TraitInstance.d.ts +0 -35
  166. package/Traits/TraitInstance.js +0 -115
  167. package/Traits/TraitInstanceMap.d.ts +0 -7
  168. package/Traits/TraitInstanceMap.js +0 -15
  169. package/Traits/TraitObservers.d.ts +0 -8
  170. package/Traits/TraitObservers.js +0 -13
  171. package/Traits/TraitPipelines.d.ts +0 -16
  172. package/Traits/TraitPipelines.js +0 -33
  173. package/Traits/TraitPrototype.d.ts +0 -16
  174. package/Traits/TraitPrototype.js +0 -74
  175. /package/Components/{ComponentData.js → Component.types.js} +0 -0
  176. /package/Contexts/{ContextData.js → Context.types.js} +0 -0
  177. /package/{Nodes/NodeData.js → Data/SerializedData.types.js} +0 -0
  178. /package/Queries/{QueryData.js → Query.types.js} +0 -0
  179. /package/Systems/{SystemData.js → System.types.js} +0 -0
  180. /package/Tags/{TagData.js → Tag.types.js} +0 -0
  181. /package/{Traits/TraitData.js → Util/Util.types.js} +0 -0
@@ -1,40 +0,0 @@
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
- };
@@ -1,50 +0,0 @@
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
- }
@@ -1,202 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,95 +0,0 @@
1
- import { NodeTagObservers } from "./NodeTagObservers";
2
- import { NCSRegister } from "../../Register/NCSRegister";
3
- export class NodeTags {
4
- node;
5
- _observers;
6
- get observers() {
7
- if (!this._observers) {
8
- this._observers = new NodeTagObservers();
9
- }
10
- return this._observers;
11
- }
12
- get hasObservers() {
13
- return Boolean(this._observers);
14
- }
15
- tags = [];
16
- constructor(node) {
17
- this.node = node;
18
- }
19
- dispose() {
20
- for (const tag of this.tags) {
21
- tag.dispose();
22
- }
23
- }
24
- add(tag) {
25
- const tagType = NCSRegister.tags.get(tag.id, tag.namespace || "main");
26
- const newTag = tagType.create(this.node, tag);
27
- this.tags.push(newTag);
28
- this.hasObservers &&
29
- this.observers.isTagsAddedSet() &&
30
- this.hasObservers &&
31
- this.observers.tagsAdded.notify(newTag);
32
- return newTag;
33
- }
34
- addTags(...components) {
35
- for (const comp of components) {
36
- this.add(comp);
37
- }
38
- this.hasObservers &&
39
- this.observers.isTagsUpdatedSet() &&
40
- this.observers.tagsUpdated.notify();
41
- }
42
- remove(type) {
43
- const index = this.tags.findIndex((_) => _.id == type);
44
- const tag = this.tags[index];
45
- if (tag) {
46
- const child = this.tags.splice(index, 1)[0];
47
- this.hasObservers &&
48
- this.observers.isTagsRemovedSet() &&
49
- this.observers.tagsRemoved.notify(child);
50
- this.hasObservers &&
51
- this.observers.isTagsUpdatedSet() &&
52
- this.observers.tagsUpdated.notify();
53
- tag.dispose();
54
- return true;
55
- }
56
- return false;
57
- }
58
- get(type) {
59
- return this.tags.find((_) => _.id == type) || null;
60
- }
61
- getChild(type) {
62
- for (const child of this.node.traverseChildren()) {
63
- const found = child.tags.get(type);
64
- if (found)
65
- return found;
66
- }
67
- return null;
68
- }
69
- getAllChildlren(type) {
70
- const tags = [];
71
- for (const child of this.node.traverseChildren()) {
72
- const found = child.tags.get(type);
73
- if (found)
74
- tags.push(found);
75
- }
76
- return tags;
77
- }
78
- getParent(type) {
79
- for (const parent of this.node.traverseParents()) {
80
- const found = parent.tags.get(type);
81
- if (found)
82
- return found;
83
- }
84
- return null;
85
- }
86
- getAllParents(type) {
87
- const tags = [];
88
- for (const child of this.node.traverseParents()) {
89
- const found = child.tags.get(type);
90
- if (found)
91
- tags.push(found);
92
- }
93
- return tags;
94
- }
95
- }
@@ -1,8 +0,0 @@
1
- import { ComponentRegisterData } from "../Components/ComponentData";
2
- import { TagRegisterData } from "../Tags/TagData";
3
- export type QueryData = {
4
- inclueComponents: ComponentRegisterData[];
5
- includeTags: TagRegisterData[];
6
- excludeComponents: ComponentRegisterData[];
7
- excludeTags: TagRegisterData[];
8
- };
@@ -1,7 +0,0 @@
1
- export declare class ItemRegister<Item extends any> {
2
- itemtype: string;
3
- namespaces: Map<string, Map<string, Item>>;
4
- constructor(itemtype: string);
5
- get(id: string, namespace: string): Item;
6
- register(id: string, namespace: string, item: Item): void;
7
- }
@@ -1,24 +0,0 @@
1
- export class ItemRegister {
2
- itemtype;
3
- namespaces = new Map([["main", new Map()]]);
4
- constructor(itemtype) {
5
- this.itemtype = itemtype;
6
- }
7
- get(id, namespace) {
8
- const namespaceMap = this.namespaces.get(namespace);
9
- if (!namespaceMap)
10
- throw new Error(`[${this.itemtype}]: Namespace with id ${id} does not exist`);
11
- const item = namespaceMap.get(id);
12
- if (!item)
13
- throw new Error(`[${this.itemtype}]: Entry with id ${id} does not exist`);
14
- return item;
15
- }
16
- register(id, namespace, item) {
17
- let itemMap = this.namespaces.get(namespace);
18
- if (!itemMap) {
19
- itemMap = new Map();
20
- this.namespaces.set(namespace, itemMap);
21
- }
22
- itemMap.set(id, item);
23
- }
24
- }
@@ -1,15 +0,0 @@
1
- import { ComponentInstance } from "../Components/ComponentInstance";
2
- import { TraitData, TraitRegisterData, TraitStateData } from "../Traits/TraitData";
3
- import { TraitInstance } from "../Traits/TraitInstance";
4
- import { TraitPrototype } from "../Traits/TraitPrototype";
5
- type RegisteredTrait<TraitSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}> = (TraitRegisterData<TraitSchema, Data, Logic, Shared> & {
6
- set: (parent: ComponentInstance | TraitInstance, ComponentSchema?: Partial<TraitSchema>, traits?: TraitData[], state?: TraitStateData) => Promise<void>;
7
- get: (parent: ComponentInstance | TraitInstance) => TraitInstance<TraitSchema, Data, Logic, Shared> | null;
8
- getAll: (parent: ComponentInstance | TraitInstance) => TraitInstance<TraitSchema, Data, Logic, Shared>[] | null;
9
- remove: (parent: ComponentInstance | TraitInstance) => Promise<TraitInstance<TraitSchema, Data, Logic, Shared> | null>;
10
- removeAll: (parent: ComponentInstance | TraitInstance) => Promise<TraitInstance<TraitSchema, Data, Logic, Shared>[] | null>;
11
- prototype: TraitPrototype<TraitSchema, Data, Logic, Shared>;
12
- default: TraitInstance<TraitSchema, Data, Logic, Shared>;
13
- }) & ((schema?: Partial<TraitSchema> | null | undefined, state?: TraitStateData | null | undefined, ...traits: TraitData[]) => TraitData<TraitSchema>);
14
- export declare function registerTrait<TraitSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}>(data: TraitRegisterData<TraitSchema, Data, Logic, Shared>): RegisteredTrait;
15
- export {};
@@ -1,39 +0,0 @@
1
- import { NCS } from "../NCS";
2
- import { NCSRegister } from "./NCSRegister";
3
- import { TraitPrototype } from "../Traits/TraitPrototype";
4
- export function registerTrait(data) {
5
- const prototype = new TraitPrototype(data);
6
- NCSRegister.traits.register(data.type, data.namespace || "main", prototype);
7
- const createTrait = (schema, state, ...traits) => {
8
- return NCS.Pipelines.OnTraitDataCreate.pipe({
9
- type: data.type,
10
- state: state || {},
11
- traits: traits || [],
12
- schema: {
13
- ...structuredClone(prototype.baseContextSchema),
14
- ...(schema || {}),
15
- },
16
- });
17
- };
18
- return Object.assign(createTrait, data, {
19
- set: (parent, schema, state, ...traits) => {
20
- return parent.traits.addTraits(createTrait(schema
21
- ? schema
22
- : data.schema
23
- ? structuredClone(prototype.baseContextSchema)
24
- : {}, state, ...traits));
25
- },
26
- get: (parent) => {
27
- return parent.traits.get(data.type);
28
- },
29
- getAll: (parent) => {
30
- return parent.traits.getAll(data.type);
31
- },
32
- removeAll: (parent) => {
33
- return parent.traits.removeAll(data.type);
34
- },
35
- remove: (parent) => {
36
- return parent.traits.remove(data.type);
37
- },
38
- });
39
- }
@@ -1,13 +0,0 @@
1
- import { NodeInstance } from "../Nodes/NodeInstance";
2
- import { Tag } from "./Tag";
3
- import { TagData } from "./TagData";
4
- import { TagPrototype } from "./TagPrototype";
5
- export declare class TagInstance {
6
- get id(): string;
7
- tagPrototype: TagPrototype;
8
- node: NodeInstance;
9
- tag: Tag;
10
- constructor();
11
- dispose(): void;
12
- toJSON(): TagData;
13
- }
@@ -1,17 +0,0 @@
1
- export class TagInstance {
2
- get id() {
3
- return this.tag.id;
4
- }
5
- tagPrototype;
6
- node;
7
- tag;
8
- constructor() { }
9
- dispose() {
10
- this.tagPrototype.destory(this);
11
- }
12
- toJSON() {
13
- return {
14
- id: this.id,
15
- };
16
- }
17
- }
@@ -1,7 +0,0 @@
1
- import { ItemGraphMap } from "../Maps/ItemGraphMap";
2
- import { TagInstance } from "./TagInstance";
3
- export declare class TagInstanceMap {
4
- private static types;
5
- static registerTag(type: string): ItemGraphMap<TagInstance>;
6
- static getMap(type: string): ItemGraphMap<TagInstance>;
7
- }
@@ -1,15 +0,0 @@
1
- import { ItemGraphMap } from "../Maps/ItemGraphMap";
2
- export class TagInstanceMap {
3
- static types = new Map();
4
- static registerTag(type) {
5
- const map = new ItemGraphMap();
6
- this.types.set(type, map);
7
- return map;
8
- }
9
- static getMap(type) {
10
- const map = this.types.get(type);
11
- if (!map)
12
- throw new Error(`Map for component ${type} does not exist`);
13
- return map;
14
- }
15
- }
@@ -1,16 +0,0 @@
1
- import { TagData } from "./TagData";
2
- import { TagInstance } from "./TagInstance";
3
- import { NodeInstance } from "../Nodes/NodeInstance";
4
- import { ItemPool } from "../Pools/ItemPool";
5
- import { TagRegisterData } from "./TagData";
6
- import { Tag } from "./Tag";
7
- export declare class TagPrototype {
8
- data: TagRegisterData;
9
- tag: Tag;
10
- pool: ItemPool<TagInstance>;
11
- constructor(data: TagRegisterData, tag: Tag);
12
- private getPooled;
13
- private return;
14
- create(node: NodeInstance, data: TagData): TagInstance;
15
- destory(tag: TagInstance): void;
16
- }