@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.
Files changed (115) hide show
  1. package/Components/ComponentData.d.ts +112 -0
  2. package/Components/ComponentData.js +1 -0
  3. package/Components/ComponentInstance.d.ts +36 -0
  4. package/Components/ComponentInstance.js +125 -0
  5. package/Components/ComponentInstanceMap.d.ts +7 -0
  6. package/Components/ComponentInstanceMap.js +15 -0
  7. package/Components/ComponentObservers.d.ts +8 -0
  8. package/Components/ComponentObservers.js +13 -0
  9. package/Components/ComponentPipelines.d.ts +16 -0
  10. package/Components/ComponentPipelines.js +33 -0
  11. package/Components/ComponentPrototype.d.ts +17 -0
  12. package/Components/ComponentPrototype.js +73 -0
  13. package/Contexts/ContextData.d.ts +59 -0
  14. package/Contexts/ContextData.js +1 -0
  15. package/Contexts/ContextInstance.d.ts +14 -0
  16. package/Contexts/ContextInstance.js +26 -0
  17. package/Contexts/ContextInstanceAnchor.d.ts +15 -0
  18. package/Contexts/ContextInstanceAnchor.js +33 -0
  19. package/Contexts/ContextPrototype.d.ts +9 -0
  20. package/Contexts/ContextPrototype.js +19 -0
  21. package/Graphs/Graph.d.ts +24 -0
  22. package/Graphs/Graph.js +90 -0
  23. package/Graphs/GraphEvents.d.ts +9 -0
  24. package/Graphs/GraphEvents.js +35 -0
  25. package/Graphs/GraphObservers.d.ts +9 -0
  26. package/Graphs/GraphObservers.js +6 -0
  27. package/Graphs/GraphUpdate.d.ts +13 -0
  28. package/Graphs/GraphUpdate.js +38 -0
  29. package/Maps/ItemGraphMap.d.ts +11 -0
  30. package/Maps/ItemGraphMap.js +30 -0
  31. package/Maps/ItemNodeMap.d.ts +17 -0
  32. package/Maps/ItemNodeMap.js +41 -0
  33. package/NCS.d.ts +54 -0
  34. package/NCS.js +41 -0
  35. package/Nodes/Components/NodeComponentObservers.d.ts +15 -0
  36. package/Nodes/Components/NodeComponentObservers.js +33 -0
  37. package/Nodes/Components/NodeComponents.d.ts +22 -0
  38. package/Nodes/Components/NodeComponents.js +107 -0
  39. package/Nodes/Context/NodeContext.d.ts +13 -0
  40. package/Nodes/Context/NodeContext.js +45 -0
  41. package/Nodes/NodeData.d.ts +40 -0
  42. package/Nodes/NodeData.js +1 -0
  43. package/Nodes/NodeEvents.d.ts +25 -0
  44. package/Nodes/NodeEvents.js +62 -0
  45. package/Nodes/NodeId.d.ts +15 -0
  46. package/Nodes/NodeId.js +56 -0
  47. package/Nodes/NodeInstance.d.ts +50 -0
  48. package/Nodes/NodeInstance.js +202 -0
  49. package/Nodes/NodeObservers.d.ts +24 -0
  50. package/Nodes/NodeObservers.js +63 -0
  51. package/Nodes/NodePipelines.d.ts +16 -0
  52. package/Nodes/NodePipelines.js +33 -0
  53. package/Nodes/Tags/NodeTagObservers.d.ts +15 -0
  54. package/Nodes/Tags/NodeTagObservers.js +33 -0
  55. package/Nodes/Tags/NodeTags.d.ts +21 -0
  56. package/Nodes/Tags/NodeTags.js +95 -0
  57. package/Pools/ItemPool.d.ts +7 -0
  58. package/Pools/ItemPool.js +18 -0
  59. package/Pools/NCSPools.d.ts +7 -0
  60. package/Pools/NCSPools.js +5 -0
  61. package/Queries/QueryData.d.ts +8 -0
  62. package/Queries/QueryData.js +1 -0
  63. package/Queries/QueryInstance.d.ts +12 -0
  64. package/Queries/QueryInstance.js +78 -0
  65. package/Queries/QueryPrototype.d.ts +10 -0
  66. package/Queries/QueryPrototype.js +23 -0
  67. package/Register/ItemRegister.d.ts +7 -0
  68. package/Register/ItemRegister.js +24 -0
  69. package/Register/NCSRegister.d.ts +13 -0
  70. package/Register/NCSRegister.js +8 -0
  71. package/Register/registerComponent.d.ts +29 -0
  72. package/Register/registerComponent.js +54 -0
  73. package/Register/registerContext.d.ts +16 -0
  74. package/Register/registerContext.js +37 -0
  75. package/Register/registerSystem.d.ts +12 -0
  76. package/Register/registerSystem.js +12 -0
  77. package/Register/registerTag.d.ts +21 -0
  78. package/Register/registerTag.js +43 -0
  79. package/Register/registerTrait.d.ts +15 -0
  80. package/Register/registerTrait.js +39 -0
  81. package/Systems/SystemData.d.ts +20 -0
  82. package/Systems/SystemData.js +1 -0
  83. package/Systems/SystemInstance.d.ts +11 -0
  84. package/Systems/SystemInstance.js +19 -0
  85. package/Systems/SystemPrototype.d.ts +10 -0
  86. package/Systems/SystemPrototype.js +23 -0
  87. package/Tags/Tag.d.ts +14 -0
  88. package/Tags/Tag.js +51 -0
  89. package/Tags/TagData.d.ts +38 -0
  90. package/Tags/TagData.js +1 -0
  91. package/Tags/TagInstance.d.ts +13 -0
  92. package/Tags/TagInstance.js +17 -0
  93. package/Tags/TagInstanceMap.d.ts +7 -0
  94. package/Tags/TagInstanceMap.js +15 -0
  95. package/Tags/TagPrototype.d.ts +16 -0
  96. package/Tags/TagPrototype.js +34 -0
  97. package/Traits/TraitContaienrObservers.d.ts +15 -0
  98. package/Traits/TraitContaienrObservers.js +33 -0
  99. package/Traits/TraitContainer.d.ts +22 -0
  100. package/Traits/TraitContainer.js +114 -0
  101. package/Traits/TraitData.d.ts +106 -0
  102. package/Traits/TraitData.js +1 -0
  103. package/Traits/TraitInstance.d.ts +35 -0
  104. package/Traits/TraitInstance.js +115 -0
  105. package/Traits/TraitInstanceMap.d.ts +7 -0
  106. package/Traits/TraitInstanceMap.js +15 -0
  107. package/Traits/TraitObservers.d.ts +8 -0
  108. package/Traits/TraitObservers.js +13 -0
  109. package/Traits/TraitPipelines.d.ts +16 -0
  110. package/Traits/TraitPipelines.js +33 -0
  111. package/Traits/TraitPrototype.d.ts +16 -0
  112. package/Traits/TraitPrototype.js +74 -0
  113. package/index.d.ts +8 -0
  114. package/index.js +8 -0
  115. package/package.json +27 -0
@@ -0,0 +1,95 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ export declare class ItemPool<Item> {
2
+ maxSize: number;
3
+ items: Item[];
4
+ constructor(maxSize?: number);
5
+ addItem(item: Item): false | undefined;
6
+ get(): NonNullable<Item> | null;
7
+ }
@@ -0,0 +1,18 @@
1
+ export class ItemPool {
2
+ maxSize;
3
+ items = [];
4
+ constructor(maxSize = 100) {
5
+ this.maxSize = maxSize;
6
+ }
7
+ addItem(item) {
8
+ if (this.items.length > this.maxSize)
9
+ return false;
10
+ this.items.push(item);
11
+ }
12
+ get() {
13
+ const item = this.items.shift();
14
+ if (!item)
15
+ return null;
16
+ return item;
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ import { ItemPool } from "./ItemPool";
2
+ import { Observable } from "@amodx/core/Observers";
3
+ import { Pipeline } from "@amodx/core/Pipelines";
4
+ export declare class NCSPools {
5
+ static observers: ItemPool<Observable<void>>;
6
+ static pipelines: ItemPool<Pipeline<{}>>;
7
+ }
@@ -0,0 +1,5 @@
1
+ import { ItemPool } from "./ItemPool";
2
+ export class NCSPools {
3
+ static observers = new ItemPool();
4
+ static pipelines = new ItemPool();
5
+ }
@@ -0,0 +1,8 @@
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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Graph } from "../Graphs/Graph";
2
+ import { QueryData } from "./QueryData";
3
+ import { NodeInstance } from "../Nodes/NodeInstance";
4
+ export declare class QueryInstance {
5
+ graph: Graph;
6
+ data: QueryData;
7
+ nodes: Set<NodeInstance>;
8
+ constructor(graph: Graph, data: QueryData);
9
+ evulate(node: NodeInstance): boolean;
10
+ init(): void;
11
+ dispose(): void;
12
+ }
@@ -0,0 +1,78 @@
1
+ import { ComponentInstanceMap } from "../Components/ComponentInstanceMap";
2
+ import { TagInstanceMap } from "../Tags/TagInstanceMap";
3
+ import { NCSRegister } from "../Register/NCSRegister";
4
+ export class QueryInstance {
5
+ graph;
6
+ data;
7
+ nodes = new Set();
8
+ constructor(graph, data) {
9
+ this.graph = graph;
10
+ this.data = data;
11
+ }
12
+ evulate(node) {
13
+ for (const comp of this.data.inclueComponents) {
14
+ if (!(node.hasComponents && node.components.get(comp.type))) {
15
+ return false;
16
+ }
17
+ }
18
+ for (const tag of this.data.includeTags) {
19
+ if (!(node.hasTags && node.tags.get(tag.id))) {
20
+ return false;
21
+ }
22
+ }
23
+ for (const comp of this.data.excludeComponents) {
24
+ if (node.hasComponents && node.components.get(comp.type)) {
25
+ return false;
26
+ }
27
+ }
28
+ for (const tag of this.data.excludeTags) {
29
+ if (node.hasTags && node.tags.get(tag.id)) {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
35
+ init() {
36
+ const onupdate = (node) => {
37
+ if (!this.evulate(node)) {
38
+ this.nodes.delete(node);
39
+ return;
40
+ }
41
+ this.nodes.add(node);
42
+ };
43
+ for (const comp of this.data.inclueComponents) {
44
+ const map = ComponentInstanceMap.getMap(comp.type).getMap(this.graph);
45
+ map.observers.nodeAdded.subscribe(this, onupdate);
46
+ map.observers.nodeRemoved.subscribe(this, onupdate);
47
+ }
48
+ for (const tagId of this.data.includeTags) {
49
+ const tagPrototype = NCSRegister.tags.get(tagId.id, tagId.namespace || "main");
50
+ const tagMap = TagInstanceMap.getMap(tagId.id).getMap(this.graph);
51
+ tagMap.observers.nodeAdded.subscribe(this, onupdate);
52
+ tagMap.observers.nodeRemoved.subscribe(this, onupdate);
53
+ for (const child of tagPrototype.tag.traverseChildren()) {
54
+ const chidMap = TagInstanceMap.getMap(child.id).getMap(this.graph);
55
+ chidMap.observers.nodeAdded.subscribe(this, onupdate);
56
+ chidMap.observers.nodeRemoved.subscribe(this, onupdate);
57
+ }
58
+ }
59
+ }
60
+ dispose() {
61
+ for (const comp of this.data.inclueComponents) {
62
+ const map = ComponentInstanceMap.getMap(comp.type).getMap(this.graph);
63
+ map.observers.nodeAdded.unsubscribe(this);
64
+ map.observers.nodeRemoved.unsubscribe(this);
65
+ }
66
+ for (const tagId of this.data.includeTags) {
67
+ const tagPrototype = NCSRegister.tags.get(tagId.id, tagId.namespace || "main");
68
+ const tagMap = TagInstanceMap.getMap(tagId.id).getMap(this.graph);
69
+ tagMap.observers.nodeAdded.unsubscribe(this);
70
+ tagMap.observers.nodeRemoved.unsubscribe(this);
71
+ for (const child of tagPrototype.tag.traverseChildren()) {
72
+ const chidMap = TagInstanceMap.getMap(child.id).getMap(this.graph);
73
+ chidMap.observers.nodeAdded.unsubscribe(this);
74
+ chidMap.observers.nodeRemoved.unsubscribe(this);
75
+ }
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,10 @@
1
+ import { Graph } from "../Graphs/Graph";
2
+ import { QueryData } from "./QueryData";
3
+ import { QueryInstance } from "./QueryInstance";
4
+ export declare class QueryPrototype {
5
+ data: QueryData;
6
+ queries: Map<Graph, QueryInstance>;
7
+ constructor(data: QueryData);
8
+ add(graph: Graph): QueryInstance;
9
+ remove(graph: Graph): boolean;
10
+ }
@@ -0,0 +1,23 @@
1
+ import { QueryInstance } from "./QueryInstance";
2
+ export class QueryPrototype {
3
+ data;
4
+ queries = new Map();
5
+ constructor(data) {
6
+ this.data = data;
7
+ }
8
+ add(graph) {
9
+ if (this.queries.has(graph))
10
+ return this.queries.get(graph);
11
+ const newQuery = new QueryInstance(graph, this.data);
12
+ this.queries.set(graph, newQuery);
13
+ newQuery.init();
14
+ return newQuery;
15
+ }
16
+ remove(graph) {
17
+ const query = this.queries.get(graph);
18
+ if (!query)
19
+ return false;
20
+ query.dispose();
21
+ return true;
22
+ }
23
+ }
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,13 @@
1
+ import { ContextPrototype } from "../Contexts/ContextPrototype";
2
+ import { ComponentPrototype } from "../Components/ComponentPrototype";
3
+ import { TraitPrototype } from "../Traits/TraitPrototype";
4
+ import { ItemRegister } from "./ItemRegister";
5
+ import { SystemPrototype } from "../Systems/SystemPrototype";
6
+ import { TagPrototype } from "../Tags/TagPrototype";
7
+ export declare class NCSRegister {
8
+ static components: ItemRegister<ComponentPrototype<any, any, any, any>>;
9
+ static traits: ItemRegister<TraitPrototype<any, any, any, any>>;
10
+ static contexts: ItemRegister<ContextPrototype<any, any>>;
11
+ static tags: ItemRegister<TagPrototype>;
12
+ static systems: ItemRegister<SystemPrototype>;
13
+ }
@@ -0,0 +1,8 @@
1
+ import { ItemRegister } from "./ItemRegister";
2
+ export class NCSRegister {
3
+ static components = new ItemRegister("Components");
4
+ static traits = new ItemRegister("Traits");
5
+ static contexts = new ItemRegister("Context");
6
+ static tags = new ItemRegister("Tags");
7
+ static systems = new ItemRegister("Systems");
8
+ }
@@ -0,0 +1,29 @@
1
+ import { ComponentData, ComponentRegisterData, ComponentStateData } from "../Components/ComponentData";
2
+ import { ComponentInstance } from "../Components/ComponentInstance";
3
+ import { Graph } from "../Graphs/Graph";
4
+ import { NodeInstance } from "../Nodes/NodeInstance";
5
+ import { TraitData } from "../Traits/TraitData";
6
+ import { NodeData } from "../Nodes/NodeData";
7
+ import { ComponentPrototype } from "../Components/ComponentPrototype";
8
+ type RegisteredComponent<ComponentSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}> = (ComponentRegisterData<ComponentSchema, Data, Logic, Shared> & {
9
+ getNodes: (grpah: Graph) => Set<NodeInstance>;
10
+ getComponents: (grpah: Graph) => Set<ComponentInstance<ComponentSchema, Data, Logic, Shared>>;
11
+ set: (node: NodeInstance, componentSchema?: Partial<ComponentSchema>, traits?: TraitData[], state?: ComponentStateData) => Promise<ComponentInstance<ComponentSchema, Data, Logic, Shared>>;
12
+ get: (node: NodeInstance) => ComponentInstance<ComponentSchema, Data, Logic, Shared> | null;
13
+ getChild: (node: NodeInstance) => ComponentInstance<ComponentSchema, Data, Logic, Shared> | null;
14
+ getParent: (node: NodeInstance) => ComponentInstance<ComponentSchema, Data, Logic, Shared> | null;
15
+ getAll: (node: NodeInstance) => ComponentInstance<ComponentSchema, Data, Logic, Shared>[] | null;
16
+ remove: (node: NodeInstance) => Promise<ComponentInstance<ComponentSchema, Data, Logic, Shared> | null>;
17
+ removeAll: (node: NodeInstance) => Promise<ComponentInstance<ComponentSchema, Data, Logic, Shared>[] | null>;
18
+ nodeData: {
19
+ get: (node: NodeData) => ComponentData<ComponentSchema> | null;
20
+ set: (node: NodeData, componentSchema?: Partial<ComponentSchema>, traits?: TraitData[], state?: ComponentStateData) => void;
21
+ getAll: (node: NodeData) => ComponentData<ComponentSchema>[] | null;
22
+ remove: (node: NodeData) => ComponentData<ComponentSchema> | null;
23
+ removeAll: (node: NodeData) => ComponentData<ComponentSchema>[] | null;
24
+ };
25
+ prototype: ComponentPrototype<ComponentSchema, Data, Logic, Shared>;
26
+ default: ComponentInstance<ComponentSchema, Data, Logic, Shared>;
27
+ }) & ((schema?: Partial<ComponentSchema> | null | undefined, state?: Partial<ComponentStateData> | null | undefined, ...traits: TraitData[]) => ComponentData<ComponentSchema>);
28
+ export declare const registerComponent: <ComponentSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}>(data: ComponentRegisterData<ComponentSchema, Data, Logic, Shared>) => RegisteredComponent<ComponentSchema, Data, Logic, Shared>;
29
+ export {};
@@ -0,0 +1,54 @@
1
+ import { ComponentInstanceMap } from "../Components/ComponentInstanceMap";
2
+ import { NCS } from "../NCS";
3
+ import { NCSRegister } from "./NCSRegister";
4
+ import { ComponentPrototype } from "../Components/ComponentPrototype";
5
+ export const registerComponent = (data) => {
6
+ const prototype = new ComponentPrototype(data);
7
+ NCSRegister.components.register(data.type, data.namespace || "main", prototype);
8
+ const componentMap = ComponentInstanceMap.registerComponent(data.type);
9
+ const createComponent = (schema, state, ...traits) => {
10
+ return NCS.Pipelines.OnComponentDataCreate.pipe({
11
+ type: data.type,
12
+ state: state || {},
13
+ traits: traits || [],
14
+ schema: {
15
+ ...structuredClone(prototype.baseContextSchema),
16
+ ...(schema || {}),
17
+ },
18
+ });
19
+ };
20
+ return Object.assign(createComponent, data, {
21
+ prototype,
22
+ set: (node, schema, state, ...traits) => node.components.add(createComponent(schema
23
+ ? schema
24
+ : data.schema
25
+ ? structuredClone(prototype.baseContextSchema)
26
+ : {}, state, ...traits)),
27
+ getNodes: (graph) => componentMap.getNodes(graph),
28
+ getComponents: (graph) => componentMap.getItems(graph),
29
+ get: (node) => node.components.get(data.type),
30
+ getChild: (node) => node.components.getChild(data.type),
31
+ getParent: (node) => node.components.getParent(data.type),
32
+ getAll: (node) => node.components.getAll(data.type),
33
+ removeAll: (node) => node.components.removeAll(data.type),
34
+ remove: (node) => node.components.remove(data.type),
35
+ nodeData: {
36
+ get: (node) => node.components?.find((_) => _.type == data.type) || null,
37
+ getAll: (node) => node.components?.filter((_) => _.type == data.type),
38
+ remove: (node) => node.components?.splice(node.components?.findIndex((_) => _.type == data.type))[0] || null,
39
+ removeAll(node) {
40
+ const all = this.getAll(node);
41
+ node.components = node.components?.filter((_) => _.type != data.type);
42
+ return all?.length ? all : null;
43
+ },
44
+ set: (node, schema, state, ...traits) => {
45
+ node.components ??= [];
46
+ node.components.push(createComponent(schema
47
+ ? schema
48
+ : data.schema
49
+ ? structuredClone(prototype.baseContextSchema)
50
+ : {}, state, ...traits));
51
+ },
52
+ },
53
+ });
54
+ };
@@ -0,0 +1,16 @@
1
+ import { ContextData, ContextRegisterData } from "../Contexts/ContextData";
2
+ import { NodeInstance } from "../Nodes/NodeInstance";
3
+ import { ContextInstance } from "../Contexts/ContextInstance";
4
+ import { ObjectSchemaInstance } from "@amodx/schemas";
5
+ import { ContextPrototype } from "../Contexts/ContextPrototype";
6
+ type RegisteredContext<ContextSchema extends {} = {}, Data extends object = {}> = (ContextRegisterData<ContextSchema, Data> & {
7
+ set: (parent: NodeInstance, schema?: ContextSchema, data?: Data) => Promise<void>;
8
+ get: (parent: NodeInstance) => ContextInstance<ContextSchema, Data> | null;
9
+ getRequired: (parent: NodeInstance) => ContextInstance<ContextSchema, Data>;
10
+ remove: (parent: NodeInstance) => Promise<ContextInstance<ContextSchema, Data> | null>;
11
+ prototype: ContextPrototype<ContextSchema, Data>;
12
+ default: ContextInstance<Data>;
13
+ schemaController: ObjectSchemaInstance<ContextSchema>;
14
+ }) & (() => ContextData);
15
+ export declare function registerContext<ContextSchema extends {} = {}, Data extends object = {}>(data: ContextRegisterData<ContextSchema, Data>): RegisteredContext<ContextSchema, Data>;
16
+ export {};
@@ -0,0 +1,37 @@
1
+ import { NCS } from "../NCS";
2
+ import { NCSRegister } from "./NCSRegister";
3
+ import { ContextPrototype } from "../Contexts/ContextPrototype";
4
+ export function registerContext(data) {
5
+ const prototype = new ContextPrototype(data);
6
+ NCSRegister.contexts.register(data.type, data.namespace || "main", prototype);
7
+ const createContext = (schema) => {
8
+ return NCS.Pipelines.OnContextDataCreate.pipe({
9
+ type: data.type,
10
+ schema: {
11
+ ...structuredClone(prototype.baseContextSchema),
12
+ ...(schema || {}),
13
+ },
14
+ });
15
+ };
16
+ return Object.assign(createContext, data, {
17
+ prototype,
18
+ set: (parent, schema, data) => {
19
+ const newContext = parent.context.add(createContext(schema));
20
+ if (data) {
21
+ newContext.data = data;
22
+ }
23
+ },
24
+ get: (parent) => {
25
+ return parent.context.get(data.type);
26
+ },
27
+ getRequired: (parent) => {
28
+ const found = parent.context.get(data.type);
29
+ if (!found)
30
+ throw new Error(`Could not find required context type: ${data.type}`);
31
+ return found;
32
+ },
33
+ remove: (parent) => {
34
+ return parent.context.remove(data.type);
35
+ },
36
+ });
37
+ }
@@ -0,0 +1,12 @@
1
+ import { SystemPrototype } from "../Systems/SystemPrototype";
2
+ import { SystemRegisterData } from "../Systems/SystemData";
3
+ import { Graph } from "../Graphs/Graph";
4
+ import { SystemInstance } from "../Systems/SystemInstance";
5
+ type RegisteredSystem = SystemRegisterData & {
6
+ set: (graph: Graph) => void;
7
+ get: (graph: Graph) => SystemInstance | null;
8
+ remove: (graph: Graph) => SystemInstance | null;
9
+ prototype: SystemPrototype;
10
+ };
11
+ export declare function registerSystem(data: SystemRegisterData): RegisteredSystem;
12
+ export {};
@@ -0,0 +1,12 @@
1
+ import { NCSRegister } from "./NCSRegister";
2
+ import { SystemPrototype } from "../Systems/SystemPrototype";
3
+ export function registerSystem(data) {
4
+ const prototype = new SystemPrototype(data);
5
+ NCSRegister.systems.register(data.type, data.namespace || "main", prototype);
6
+ return Object.assign(data, {
7
+ prototype,
8
+ set: (graph) => prototype.add(graph),
9
+ get: (graph) => prototype.systems.get(graph) || null,
10
+ remove: (graph) => prototype.remove(graph),
11
+ });
12
+ }
@@ -0,0 +1,21 @@
1
+ import { TagData, TagRegisterData } from "../Tags/TagData";
2
+ import { NodeInstance } from "../Nodes/NodeInstance";
3
+ import { TagInstance } from "../Tags/TagInstance";
4
+ import { Tag } from "../Tags/Tag";
5
+ import { TagPrototype } from "../Tags/TagPrototype";
6
+ import { Graph } from "../Graphs/Graph";
7
+ type RegisteredTag = (TagRegisterData & {
8
+ tag: Tag;
9
+ prototype: TagPrototype;
10
+ set: (parent: NodeInstance) => TagInstance;
11
+ get: (parent: NodeInstance) => TagInstance | null;
12
+ getChild: (parent: NodeInstance) => TagInstance | null;
13
+ getAllChildlren: (parent: NodeInstance) => TagInstance[] | null;
14
+ getParent: (parent: NodeInstance) => TagInstance | null;
15
+ getAllParents: (parent: NodeInstance) => TagInstance[] | null;
16
+ remove: (parent: NodeInstance) => TagInstance | null;
17
+ getNodes: (grpah: Graph) => Set<NodeInstance>;
18
+ getTags: (grpah: Graph) => Set<TagInstance>;
19
+ }) & (() => TagData);
20
+ export declare function registerTag(data: TagRegisterData): RegisteredTag;
21
+ export {};
@@ -0,0 +1,43 @@
1
+ import { NCS } from "../NCS";
2
+ import { NCSRegister } from "./NCSRegister";
3
+ import { Tag } from "../Tags/Tag";
4
+ import { TagPrototype } from "../Tags/TagPrototype";
5
+ import { TagInstanceMap } from "../Tags/TagInstanceMap";
6
+ export function registerTag(data) {
7
+ const tag = new Tag(null, data);
8
+ const prototype = new TagPrototype(data, tag);
9
+ NCSRegister.tags.register(data.id, data.namespace || "main", prototype);
10
+ const map = TagInstanceMap.getMap(tag.id);
11
+ const createTag = () => {
12
+ return NCS.Pipelines.OnTagDataCreate.pipe({
13
+ id: data.id,
14
+ });
15
+ };
16
+ return Object.assign(createTag, data, {
17
+ tag,
18
+ prototype,
19
+ getNodes: (graph) => map.getNodes(graph),
20
+ getTags: (graph) => map.getItems(graph),
21
+ getChild: (parent) => {
22
+ return parent.tags.getChild(data.id);
23
+ },
24
+ getAllChildlren: (parent) => {
25
+ return parent.tags.getAllChildlren(data.id);
26
+ },
27
+ getParent: (parent) => {
28
+ return parent.tags.getParent(data.id);
29
+ },
30
+ getAllParents: (parent) => {
31
+ return parent.tags.getAllParents(data.id);
32
+ },
33
+ set: (parent) => {
34
+ return parent.tags.add(createTag());
35
+ },
36
+ get: (parent) => {
37
+ return parent.tags.get(data.id);
38
+ },
39
+ remove: (parent) => {
40
+ return parent.tags.remove(data.id);
41
+ },
42
+ });
43
+ }
@@ -0,0 +1,15 @@
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 {};
@@ -0,0 +1,39 @@
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
+ }
@@ -0,0 +1,20 @@
1
+ import { QueryPrototype } from "../Queries/QueryPrototype";
2
+ import { SystemInstance } from "./SystemInstance";
3
+ export type SystemRegisterData = {
4
+ /**
5
+ * The name of the system.
6
+ */
7
+ type: string;
8
+ /**
9
+ * The namespace of the system.
10
+ */
11
+ namespace?: string;
12
+ /**
13
+ * The queries of the system.
14
+ */
15
+ queries: QueryPrototype[];
16
+ /**
17
+ * The update function of the system.
18
+ */
19
+ update(system: SystemInstance): void;
20
+ };
@@ -0,0 +1 @@
1
+ export {};