@amodx/ncs 0.0.1 → 0.0.21

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 +24 -0
  10. package/Contexts/ContextCursor.js +47 -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 +115 -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 +183 -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 +13 -14
  37. package/Nodes/NodeEvents.js +58 -28
  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 +16 -16
  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,59 +0,0 @@
1
- /**
2
- * Interface representing the meta data of a context.
3
- */
4
- export interface ContextMetaData {
5
- name: string;
6
- [key: string]: any;
7
- }
8
- /**
9
- * Interface representing the state data of a context.
10
- */
11
- export interface ContextStateData {
12
- [key: string]: any;
13
- }
14
- /**
15
- * Type representing the data of a context.
16
- *
17
- */
18
- export type ContextData<Schema extends Record<string, any> = {}> = {
19
- /**
20
- * The type of the context.
21
- */
22
- type: string;
23
- /**
24
- * The namespace of the context.
25
- */
26
- namespace?: string;
27
- /**
28
- * The schema of the context.
29
- */
30
- schema: Schema;
31
- };
32
- /**
33
- * Type representing the data required to register a context.
34
- *
35
- * Used for serlization and creation.
36
- * @template Data - The runtime data of the context.
37
- */
38
- export type ContextRegisterData<Schema extends Record<string, any> = {}, Data extends Record<string, any> = {}> = {
39
- /**
40
- * The type of the context.
41
- */
42
- type: string;
43
- /**
44
- * The namespace of the context.
45
- */
46
- namespace?: string;
47
- /**
48
- * The schema of the context.
49
- */
50
- schema?: Schema;
51
- /**
52
- * The runtime data of the context.
53
- */
54
- data?: Data;
55
- /**
56
- * The shared meta data of all contexts.
57
- */
58
- meta?: ContextMetaData;
59
- };
@@ -1,14 +0,0 @@
1
- import { ContextData } from "./ContextData";
2
- import { NodeInstance } from "../Nodes/NodeInstance";
3
- import { ObjectSchemaInstance, QueryPath } from "@amodx/schemas";
4
- import { SchemaNode } from "@amodx/schemas/Schemas/SchemaNode";
5
- import { ContextPrototype } from "./ContextPrototype";
6
- export declare class ContextInstance<ContextSchema extends {} = {}, Data extends {} = {}> {
7
- node: NodeInstance;
8
- type: string;
9
- data: Data;
10
- schema: ObjectSchemaInstance<ContextSchema>;
11
- constructor(node: NodeInstance, contextPrototypeData: ContextPrototype<ContextSchema, Data>, data: ContextData);
12
- addOnSchemaUpdate(path: QueryPath<ContextSchema>, listener: (node: SchemaNode) => void): void;
13
- removeOnSchemaUpdate(path: QueryPath<ContextSchema>, listener: (node: SchemaNode) => void): void;
14
- }
@@ -1,26 +0,0 @@
1
- import { ObjectPath } from "@amodx/schemas";
2
- export class ContextInstance {
3
- node;
4
- type;
5
- data;
6
- schema;
7
- constructor(node, contextPrototypeData, data) {
8
- this.node = node;
9
- this.schema = contextPrototypeData.getSchema(data.schema);
10
- this.type = contextPrototypeData.data.type;
11
- contextPrototypeData.data.data &&
12
- (this.data = contextPrototypeData.data.data);
13
- }
14
- addOnSchemaUpdate(path, listener) {
15
- this.schema
16
- .getSchema()
17
- .getNode(ObjectPath.Create(path))
18
- ?.observers.updatedOrLoadedIn.subscribe(listener);
19
- }
20
- removeOnSchemaUpdate(path, listener) {
21
- this.schema
22
- .getSchema()
23
- .getNode(ObjectPath.Create(path))
24
- ?.observers.updatedOrLoadedIn.unsubscribe(listener);
25
- }
26
- }
@@ -1,15 +0,0 @@
1
- import { NodeInstance } from "../Nodes/NodeInstance";
2
- import { ContextInstance } from "./ContextInstance";
3
- import { QueryPath } from "@amodx/schemas";
4
- import { SchemaNode } from "@amodx/schemas/Schemas/SchemaNode";
5
- export declare class ContextAnchorInstance<ContextSchema extends {} = {}, Data extends {} = {}> {
6
- node: NodeInstance;
7
- private context;
8
- get type(): string;
9
- get schema(): import("@amodx/schemas").ObjectSchemaInstance<Data>;
10
- get data(): {};
11
- constructor(node: NodeInstance, context: ContextInstance<Data>);
12
- getContext(): ContextInstance<Data, {}>;
13
- addOnSchemaUpdate(path: QueryPath<ContextSchema>, listener: (node: SchemaNode) => void): void;
14
- removeOnSchemaUpdate(path: QueryPath<ContextSchema>, listener: (node: SchemaNode) => void): void;
15
- }
@@ -1,33 +0,0 @@
1
- import { ObjectPath } from "@amodx/schemas";
2
- export class ContextAnchorInstance {
3
- node;
4
- context;
5
- get type() {
6
- return this.context.type;
7
- }
8
- get schema() {
9
- return this.context.schema;
10
- }
11
- get data() {
12
- return this.context.data;
13
- }
14
- constructor(node, context) {
15
- this.node = node;
16
- this.context = context;
17
- }
18
- getContext() {
19
- return this.context;
20
- }
21
- addOnSchemaUpdate(path, listener) {
22
- this.schema
23
- .getSchema()
24
- .getNode(ObjectPath.Create(path))
25
- ?.observers.updatedOrLoadedIn.subscribe(listener);
26
- }
27
- removeOnSchemaUpdate(path, listener) {
28
- this.schema
29
- .getSchema()
30
- .getNode(ObjectPath.Create(path))
31
- ?.observers.updatedOrLoadedIn.unsubscribe(listener);
32
- }
33
- }
@@ -1,9 +0,0 @@
1
- import { ObjectSchemaInstance, Schema } from "@amodx/schemas";
2
- import { ContextRegisterData } from "./ContextData";
3
- export declare class ContextPrototype<ComponentSchema extends object = {}, Data extends object = {}> {
4
- data: ContextRegisterData<ComponentSchema, Data>;
5
- schemaController: Schema<ComponentSchema> | null;
6
- baseContextSchema: ComponentSchema;
7
- constructor(data: ContextRegisterData<ComponentSchema, Data>);
8
- getSchema(overrides: Partial<ComponentSchema>): ObjectSchemaInstance<ComponentSchema>;
9
- }
@@ -1,19 +0,0 @@
1
- import { Schema } from "@amodx/schemas";
2
- export class ContextPrototype {
3
- data;
4
- schemaController;
5
- baseContextSchema;
6
- constructor(data) {
7
- this.data = data;
8
- this.schemaController =
9
- Array.isArray(data.schema) && data.schema.length
10
- ? Schema.Create(...data.schema)
11
- : null;
12
- this.baseContextSchema = (this.schemaController ? this.schemaController.createData() : {});
13
- }
14
- getSchema(overrides) {
15
- if (!this.schemaController)
16
- return structuredClone(this.baseContextSchema);
17
- return this.schemaController.instantiate(overrides);
18
- }
19
- }
@@ -1,9 +0,0 @@
1
- import { NodeEventCursor } from "../Nodes/NodeEvents";
2
- export declare class GraphEvents {
3
- private events;
4
- hasListener(id: string): boolean;
5
- clearListeners(id: string): false | undefined;
6
- addListener(id: string, run: (data: NodeEventCursor) => void): void;
7
- removeListener(id: string, run: Function): boolean;
8
- dispatch<Data>(id: string, data: NodeEventCursor): boolean;
9
- }
@@ -1,35 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- export class GraphEvents {
3
- events = new Map();
4
- hasListener(id) {
5
- return this.events.has(id);
6
- }
7
- clearListeners(id) {
8
- let observer = this.events.get(id);
9
- if (!observer)
10
- return false;
11
- observer.clear();
12
- }
13
- addListener(id, run) {
14
- let observer = this.events.get(id);
15
- if (!observer) {
16
- observer = new Observable();
17
- this.events.set(id, observer);
18
- }
19
- observer.subscribe(run);
20
- }
21
- removeListener(id, run) {
22
- let observer = this.events.get(id);
23
- if (!observer)
24
- return false;
25
- observer.unsubscribe(run);
26
- return true;
27
- }
28
- dispatch(id, data) {
29
- let observer = this.events.get(id);
30
- if (!observer)
31
- return false;
32
- observer.notify(data);
33
- return true;
34
- }
35
- }
@@ -1,9 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- import { NodeInstance } from "../Nodes/NodeInstance";
3
- export interface GraphObservers {
4
- }
5
- export declare class GraphObservers {
6
- nodeAdded: Observable<NodeInstance>;
7
- nodeRemoved: Observable<NodeInstance>;
8
- nodesUpdated: Observable<void>;
9
- }
@@ -1,6 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- export class GraphObservers {
3
- nodeAdded = new Observable();
4
- nodeRemoved = new Observable();
5
- nodesUpdated = new Observable();
6
- }
@@ -1,13 +0,0 @@
1
- import { SystemInstance } from "../Systems/SystemInstance";
2
- import { ComponentInstance } from "../Components/ComponentInstance";
3
- import { Graph } from "./Graph";
4
- export declare class GraphUpdate {
5
- private static updatingComponents;
6
- static addComponentToUpdate(component: ComponentInstance<any, any, any, any>): void;
7
- static removeComponentFromUpate(component: ComponentInstance<any, any, any, any>): void;
8
- static getUpdatingComponents(graph: Graph): Set<ComponentInstance<{}, {}, {}, {}>>;
9
- private static updatingSystems;
10
- static addSystemToUpdate(system: SystemInstance): void;
11
- static removeSystemFromUpdate(system: SystemInstance): void;
12
- static getUpdatingSystems(graph: Graph): Set<SystemInstance>;
13
- }
@@ -1,38 +0,0 @@
1
- export class GraphUpdate {
2
- static updatingComponents = new Map();
3
- static addComponentToUpdate(component) {
4
- let updating = this.updatingComponents.get(component.node.graph);
5
- if (!updating) {
6
- updating = new Set();
7
- this.updatingComponents.set(component.node.graph, updating);
8
- }
9
- updating.add(component);
10
- }
11
- static removeComponentFromUpate(component) {
12
- let updating = this.updatingComponents.get(component.node.graph);
13
- if (!updating)
14
- return;
15
- updating.delete(component);
16
- }
17
- static getUpdatingComponents(graph) {
18
- return this.updatingComponents.get(graph);
19
- }
20
- static updatingSystems = new Map();
21
- static addSystemToUpdate(system) {
22
- let updating = this.updatingSystems.get(system.graph);
23
- if (!updating) {
24
- updating = new Set();
25
- this.updatingSystems.set(system.graph, updating);
26
- }
27
- updating.add(system);
28
- }
29
- static removeSystemFromUpdate(system) {
30
- let updating = this.updatingSystems.get(system.graph);
31
- if (!updating)
32
- return;
33
- updating.delete(system);
34
- }
35
- static getUpdatingSystems(graph) {
36
- return this.updatingSystems.get(graph);
37
- }
38
- }
@@ -1,11 +0,0 @@
1
- import { NodeInstance } from "../Nodes/NodeInstance";
2
- import { Graph } from "../Graphs/Graph";
3
- import { ItemNodeMap } from "../Maps/ItemNodeMap";
4
- export declare class ItemGraphMap<MappedItem> {
5
- private graphs;
6
- getMap(graph: Graph): ItemNodeMap<MappedItem>;
7
- addNode(node: NodeInstance, item: MappedItem): void;
8
- removeNode(node: NodeInstance, item: MappedItem): void;
9
- getNodes(graph: Graph): Set<NodeInstance>;
10
- getItems(graph: Graph): Set<MappedItem>;
11
- }
@@ -1,30 +0,0 @@
1
- import { ItemNodeMap } from "../Maps/ItemNodeMap";
2
- export class ItemGraphMap {
3
- graphs = new Map();
4
- getMap(graph) {
5
- let graphMap = this.graphs.get(graph);
6
- if (!graphMap) {
7
- graphMap = new ItemNodeMap();
8
- this.graphs.set(graph, graphMap);
9
- }
10
- return graphMap;
11
- }
12
- addNode(node, item) {
13
- const graphMap = this.getMap(node.graph);
14
- graphMap.addNode(node, item);
15
- }
16
- removeNode(node, item) {
17
- if (!this.graphs.has(node.graph))
18
- return;
19
- const graphMap = this.getMap(node.graph);
20
- graphMap.addNode(node, item);
21
- }
22
- getNodes(graph) {
23
- const graphMap = this.getMap(graph);
24
- return graphMap.getNodes();
25
- }
26
- getItems(graph) {
27
- const graphMap = this.getMap(graph);
28
- return graphMap.getItems();
29
- }
30
- }
@@ -1,17 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- import { NodeInstance } from "../Nodes/NodeInstance";
3
- declare class NodeGraphMapObservers {
4
- nodeAdded: Observable<NodeInstance>;
5
- nodeRemoved: Observable<NodeInstance>;
6
- }
7
- export declare class ItemNodeMap<MappedItem> {
8
- private nodes;
9
- private items;
10
- private nodeMap;
11
- observers: NodeGraphMapObservers;
12
- addNode(node: NodeInstance, mappedItem: MappedItem): void;
13
- removeNode(node: NodeInstance, mappedItem: MappedItem): void;
14
- getNodes(): Set<NodeInstance>;
15
- getItems(): Set<MappedItem>;
16
- }
17
- export {};
@@ -1,41 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- class NodeGraphMapObservers {
3
- nodeAdded = new Observable();
4
- nodeRemoved = new Observable();
5
- }
6
- export class ItemNodeMap {
7
- nodes = new Set();
8
- items = new Set();
9
- nodeMap = new Map();
10
- observers = new NodeGraphMapObservers();
11
- addNode(node, mappedItem) {
12
- this.nodes.add(node);
13
- this.items.add(mappedItem);
14
- let mapped = this.nodeMap.get(node);
15
- if (!mapped) {
16
- mapped = [];
17
- this.nodeMap.set(node, mapped);
18
- }
19
- mapped.push(mappedItem);
20
- this.observers.nodeAdded.notify(node);
21
- }
22
- removeNode(node, mappedItem) {
23
- this.nodes.delete(node);
24
- this.items.delete(mappedItem);
25
- let mapped = this.nodeMap.get(node);
26
- if (!mapped)
27
- return;
28
- mapped = mapped.filter((_) => _ != mappedItem);
29
- if (!mapped.length) {
30
- this.nodeMap.delete(node);
31
- this.nodes.delete(node);
32
- this.observers.nodeRemoved.notify(node);
33
- }
34
- }
35
- getNodes() {
36
- return this.nodes;
37
- }
38
- getItems() {
39
- return this.items;
40
- }
41
- }
@@ -1,15 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- import { ComponentInstance } from "../../Components/ComponentInstance";
3
- export interface NodeComponentObservers {
4
- }
5
- export declare class NodeComponentObservers {
6
- private _componentAdded?;
7
- private _componentRemoved?;
8
- private _componentsUpdated?;
9
- get componentAdded(): Observable<ComponentInstance<any>>;
10
- get componentRemoved(): Observable<ComponentInstance<any>>;
11
- get componentsUpdated(): Observable<void>;
12
- isComponentAddedSet(): boolean;
13
- isComponentRemovedSet(): boolean;
14
- isComponentsUpdatedSet(): boolean;
15
- }
@@ -1,33 +0,0 @@
1
- import { Observable } from "@amodx/core/Observers";
2
- export class NodeComponentObservers {
3
- _componentAdded;
4
- _componentRemoved;
5
- _componentsUpdated;
6
- get componentAdded() {
7
- if (!this._componentAdded) {
8
- this._componentAdded = new Observable();
9
- }
10
- return this._componentAdded;
11
- }
12
- get componentRemoved() {
13
- if (!this._componentRemoved) {
14
- this._componentRemoved = new Observable();
15
- }
16
- return this._componentRemoved;
17
- }
18
- get componentsUpdated() {
19
- if (!this._componentsUpdated) {
20
- this._componentsUpdated = new Observable();
21
- }
22
- return this._componentsUpdated;
23
- }
24
- isComponentAddedSet() {
25
- return !!this._componentAdded;
26
- }
27
- isComponentRemovedSet() {
28
- return !!this._componentRemoved;
29
- }
30
- isComponentsUpdatedSet() {
31
- return !!this._componentsUpdated;
32
- }
33
- }
@@ -1,22 +0,0 @@
1
- import { NodeInstance } from "../NodeInstance";
2
- import { ComponentData } from "../../Components/ComponentData";
3
- import { ComponentInstance } from "../../Components/ComponentInstance";
4
- import { NodeComponentObservers } from "./NodeComponentObservers";
5
- export declare class NodeComponents {
6
- node: NodeInstance;
7
- private _observers?;
8
- get observers(): NodeComponentObservers;
9
- get hasObservers(): boolean;
10
- components: ComponentInstance[];
11
- constructor(node: NodeInstance);
12
- dispose(): Promise<void>;
13
- add(comp: ComponentData, init?: boolean): Promise<ComponentInstance<any, any, any, any>>;
14
- addComponents(...components: ComponentData[]): Promise<void>;
15
- removeByIndex(index: number): Promise<boolean>;
16
- remove(type: string): Promise<boolean>;
17
- get(type: string): ComponentInstance<any, any, any, any> | null;
18
- getAll(type: string): ComponentInstance<any, any, any, any>[];
19
- removeAll(type: string): Promise<ComponentInstance<any, any, any, any>[]>;
20
- getChild(type: string): ComponentInstance<any, any, any, any> | null;
21
- getParent(type: string): ComponentInstance<any, any, any, any> | null;
22
- }
@@ -1,107 +0,0 @@
1
- import { NodeComponentObservers } from "./NodeComponentObservers";
2
- import { NCSRegister } from "../../Register/NCSRegister";
3
- export class NodeComponents {
4
- node;
5
- _observers;
6
- get observers() {
7
- if (!this._observers) {
8
- this._observers = new NodeComponentObservers();
9
- }
10
- return this._observers;
11
- }
12
- get hasObservers() {
13
- return Boolean(this._observers);
14
- }
15
- components = [];
16
- constructor(node) {
17
- this.node = node;
18
- }
19
- async dispose() {
20
- for (const comp of this.components) {
21
- await comp.dispose();
22
- }
23
- }
24
- async add(comp, init = true) {
25
- const compType = NCSRegister.components.get(comp.type, comp.namespace || "main");
26
- const newComponent = compType.create(this.node, comp);
27
- this.components.push(newComponent);
28
- if (init)
29
- await newComponent.init();
30
- if (comp.traits.length) {
31
- await newComponent.traits.addTraits(...comp.traits);
32
- }
33
- this.hasObservers &&
34
- this.observers.isComponentAddedSet() &&
35
- this.hasObservers &&
36
- this.observers.componentAdded.notify(newComponent);
37
- return newComponent;
38
- }
39
- async addComponents(...components) {
40
- const newComponents = [];
41
- for (const comp of components) {
42
- newComponents.push(await this.add(comp, false));
43
- }
44
- for (const comp of newComponents) {
45
- await comp.init();
46
- }
47
- this.hasObservers &&
48
- this.observers.isComponentsUpdatedSet() &&
49
- this.observers.componentsUpdated.notify();
50
- }
51
- async removeByIndex(index) {
52
- const component = this.components[index];
53
- if (component) {
54
- const child = this.components.splice(index, 1)[0];
55
- this.hasObservers &&
56
- this.observers.isComponentRemovedSet() &&
57
- this.observers.componentRemoved.notify(child);
58
- this.hasObservers &&
59
- this.observers.isComponentsUpdatedSet() &&
60
- this.observers.componentsUpdated.notify();
61
- await component.dispose();
62
- return true;
63
- }
64
- return false;
65
- }
66
- remove(type) {
67
- return this.removeByIndex(this.components.findIndex((_) => _.type == type));
68
- }
69
- get(type) {
70
- return this.components.find((_) => _.type == type) || null;
71
- }
72
- getAll(type) {
73
- return this.components.filter((_) => _.type == type);
74
- }
75
- async removeAll(type) {
76
- const filtered = this.getAll(type);
77
- this.components = this.components.filter((_) => _.type != type);
78
- for (const comp of filtered) {
79
- await comp.dispose();
80
- }
81
- for (const comp of filtered) {
82
- this.hasObservers &&
83
- this.observers.isComponentRemovedSet() &&
84
- this.observers.componentRemoved.notify(comp);
85
- }
86
- this.hasObservers &&
87
- this.observers.isComponentsUpdatedSet() &&
88
- this.observers.componentsUpdated.notify();
89
- return filtered;
90
- }
91
- getChild(type) {
92
- for (const child of this.node.traverseChildren()) {
93
- const found = child.components.get(type);
94
- if (found)
95
- return found;
96
- }
97
- return null;
98
- }
99
- getParent(type) {
100
- for (const parent of this.node.traverseParents()) {
101
- const found = parent.components.get(type);
102
- if (found)
103
- return found;
104
- }
105
- return null;
106
- }
107
- }
@@ -1,13 +0,0 @@
1
- import { ContextInstance } from "../../Contexts/ContextInstance";
2
- import { NodeInstance } from "../NodeInstance";
3
- import { ContextAnchorInstance } from "../../Contexts/ContextInstanceAnchor";
4
- import { ContextData } from "../../Contexts/ContextData";
5
- export declare class NodeContext {
6
- node: NodeInstance;
7
- contexts: Map<string, ContextInstance<{}, {}>>;
8
- anchors: Map<string, ContextAnchorInstance<{}, {}>>;
9
- constructor(node: NodeInstance);
10
- add(context: ContextData): ContextInstance<{}, {}> | ContextInstance<any, any>;
11
- remove(type: string): ContextInstance<{}, {}> | undefined;
12
- get(type: string): ContextInstance | ContextAnchorInstance | null;
13
- }
@@ -1,45 +0,0 @@
1
- import { ContextInstance } from "../../Contexts/ContextInstance";
2
- import { ContextAnchorInstance } from "../../Contexts/ContextInstanceAnchor";
3
- import { NCSRegister } from "../../Register/NCSRegister";
4
- export class NodeContext {
5
- node;
6
- contexts = new Map();
7
- anchors = new Map();
8
- constructor(node) {
9
- this.node = node;
10
- }
11
- add(context) {
12
- if (this.contexts.has(context.type)) {
13
- return this.contexts.get(context.type);
14
- }
15
- const newContext = new ContextInstance(this.node, NCSRegister.contexts.get(context.type, context.namespace || "main"), context);
16
- this.contexts.set(context.type, newContext);
17
- return newContext;
18
- }
19
- remove(type) {
20
- const context = this.contexts.get(type);
21
- if (!context)
22
- return;
23
- this.contexts.delete(type);
24
- return context;
25
- }
26
- get(type) {
27
- if (this.contexts.has(type))
28
- return this.contexts.get(type);
29
- if (this.anchors.has(type))
30
- return this.anchors.get(type);
31
- for (const parent of this.node.traverseParents()) {
32
- if (parent.hasContexts) {
33
- const found = parent.context.get(type);
34
- if (found) {
35
- const newAnchor = found instanceof ContextInstance
36
- ? new ContextAnchorInstance(this.node, found)
37
- : new ContextAnchorInstance(this.node, found.getContext());
38
- this.anchors.set(type, newAnchor);
39
- return newAnchor;
40
- }
41
- }
42
- }
43
- return null;
44
- }
45
- }