@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,112 @@
1
+ import { Property } from "@amodx/schemas";
2
+ import { ComponentInstance } from "./ComponentInstance";
3
+ import { TraitData } from "../Traits/TraitData";
4
+ /**
5
+ * Interface representing the meta data of a component.
6
+ */
7
+ export interface ComponentMetaData {
8
+ name: string;
9
+ [key: string]: any;
10
+ }
11
+ /**
12
+ * Interface representing the pool data of a component.
13
+ */
14
+ export interface ComponentPoolData {
15
+ maxSize: number;
16
+ [key: string]: any;
17
+ }
18
+ /**
19
+ * Interface representing the state data of a component.
20
+ */
21
+ export interface ComponentStateData {
22
+ [key: string]: any;
23
+ }
24
+ /**
25
+ * Type representing the data of a component.
26
+ *
27
+ * @template ComponentSchema - The ComponentSchema of the component.
28
+ */
29
+ export type ComponentData<ComponentSchema extends object = any> = {
30
+ /**
31
+ * The type of the component.
32
+ */
33
+ type: string;
34
+ /**
35
+ * The namespace of the component.
36
+ */
37
+ namespace?: string;
38
+ /**
39
+ * The state data of the component.
40
+ */
41
+ state: ComponentStateData;
42
+ /**
43
+ * The ComponentSchema of the component.
44
+ */
45
+ schema: ComponentSchema;
46
+ /**
47
+ * The traits associated with the component.
48
+ */
49
+ traits: TraitData[];
50
+ };
51
+ /**
52
+ * Type representing the data required to register a component.
53
+ *
54
+ * Used for serlization and creation.
55
+ * @template ComponentSchema - The schema of the component.
56
+ * @template Data - The runtime data of the component.
57
+ * @template Logic - The logic functions of the component.
58
+ * @template Shared - The shared data of all components of this type.
59
+ * @template Meta - The shared meta data of all components of this type.
60
+ */
61
+ export type ComponentRegisterData<ComponentSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> = {
62
+ /**
63
+ * The type of the component.
64
+ */
65
+ type: string;
66
+ /**
67
+ * The namespace of the component.
68
+ */
69
+ namespace?: string;
70
+ pool?: ComponentPoolData;
71
+ /**
72
+ * The schema used to create an editable version of the component.
73
+ * For the actual ComponentInstance the schema is created into an object.
74
+ */
75
+ schema?: Property<any, any>[];
76
+ /**
77
+ * The logic functions of the component.
78
+ */
79
+ logic?: Logic | ((component: ComponentInstance<ComponentSchema, Data, Logic, Shared>) => Logic);
80
+ /**
81
+ * The runtime data of the component.
82
+ */
83
+ data?: Data | ((component: ComponentInstance<ComponentSchema, Data, Logic, Shared>) => Data);
84
+ /**
85
+ * The shared data of all components.
86
+ */
87
+ shared?: Shared;
88
+ /**
89
+ * The shared meta data of all components.
90
+ */
91
+ meta?: ComponentMetaData;
92
+ /**
93
+ * Optional initialization function for the component.
94
+ *
95
+ * @param component - The instance of the component being initialized.
96
+ */
97
+ init?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
98
+ /**
99
+ * Optional update function for the component.
100
+ * The update function is usually called once per frame.
101
+ * It is up to the graph though when it gets called.
102
+ *
103
+ * @param component - The instance of the component being updated.
104
+ */
105
+ update?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
106
+ /**
107
+ * Optional disposal function for the component.
108
+ *
109
+ * @param component - The instance of the component being disposed.
110
+ */
111
+ dispose?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
112
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { ComponentData, ComponentStateData } from "./ComponentData";
2
+ import { ObjectSchemaInstance, QueryPath } from "@amodx/schemas";
3
+ import { SchemaNode } from "@amodx/schemas/Schemas/SchemaNode";
4
+ import { NodeInstance } from "../Nodes/NodeInstance";
5
+ import { ComponentObservers } from "./ComponentObservers";
6
+ import { ComponentPipelines } from "./ComponentPipelines";
7
+ import { TraintContainer } from "../Traits/TraitContainer";
8
+ import { ComponentPrototype } from "./ComponentPrototype";
9
+ export declare class ComponentInstance<ComponentSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}> {
10
+ get type(): string;
11
+ get shared(): Shared;
12
+ componentPrototype: ComponentPrototype<ComponentSchema, Data, Logic, Shared>;
13
+ schema: ObjectSchemaInstance<ComponentSchema>;
14
+ data: Data;
15
+ logic: Logic;
16
+ state: ComponentStateData;
17
+ private _traits?;
18
+ get traits(): TraintContainer;
19
+ get hasTraits(): boolean;
20
+ private _observers?;
21
+ get observers(): ComponentObservers;
22
+ get hasObservers(): boolean;
23
+ private _pipelines?;
24
+ get pipelines(): ComponentPipelines<ComponentSchema>;
25
+ get hasPipelines(): boolean;
26
+ node: NodeInstance;
27
+ addOnSchemaUpdate(path: QueryPath<ComponentSchema>, listener: (node: SchemaNode) => void): void;
28
+ removeOnSchemaUpdate(path: QueryPath<ComponentSchema>, listener: (node: SchemaNode) => void): void;
29
+ init(): Promise<void>;
30
+ private _disposed;
31
+ isDisposed(): boolean;
32
+ dispose(): Promise<void>;
33
+ getDependencies(): boolean;
34
+ copy(): ComponentData;
35
+ toJSON(): ComponentData;
36
+ }
@@ -0,0 +1,125 @@
1
+ import { ObjectPath } from "@amodx/schemas";
2
+ import { GraphUpdate } from "../Graphs/GraphUpdate";
3
+ import { ComponentObservers } from "./ComponentObservers";
4
+ import { ComponentPipelines } from "./ComponentPipelines";
5
+ import { TraintContainer } from "../Traits/TraitContainer";
6
+ export class ComponentInstance {
7
+ get type() {
8
+ return this.componentPrototype.data.type;
9
+ }
10
+ get shared() {
11
+ return this.componentPrototype.data.shared;
12
+ }
13
+ componentPrototype;
14
+ schema;
15
+ data;
16
+ logic;
17
+ state;
18
+ _traits;
19
+ get traits() {
20
+ if (!this._traits) {
21
+ this._traits = new TraintContainer(this);
22
+ }
23
+ return this._traits;
24
+ }
25
+ get hasTraits() {
26
+ return Boolean(this._traits);
27
+ }
28
+ _observers;
29
+ get observers() {
30
+ if (!this._observers) {
31
+ this._observers = new ComponentObservers();
32
+ }
33
+ return this._observers;
34
+ }
35
+ get hasObservers() {
36
+ return Boolean(this._observers);
37
+ }
38
+ _pipelines;
39
+ get pipelines() {
40
+ if (!this._pipelines) {
41
+ this._pipelines = new ComponentPipelines();
42
+ }
43
+ return this._pipelines;
44
+ }
45
+ get hasPipelines() {
46
+ return Boolean(this._pipelines);
47
+ }
48
+ node;
49
+ addOnSchemaUpdate(path, listener) {
50
+ this.schema
51
+ .getSchema()
52
+ .getNode(ObjectPath.Create(path))
53
+ ?.observers.updatedOrLoadedIn.subscribe(listener);
54
+ }
55
+ removeOnSchemaUpdate(path, listener) {
56
+ this.schema
57
+ .getSchema()
58
+ .getNode(ObjectPath.Create(path))
59
+ ?.observers.updatedOrLoadedIn.unsubscribe(listener);
60
+ }
61
+ async init() {
62
+ if (!this.componentPrototype.data.init)
63
+ return;
64
+ await this.componentPrototype.data.init(this);
65
+ if (this.componentPrototype.data.update) {
66
+ GraphUpdate.addComponentToUpdate(this);
67
+ }
68
+ }
69
+ _disposed = false;
70
+ isDisposed() {
71
+ return this._disposed;
72
+ }
73
+ async dispose() {
74
+ if (this.componentPrototype.data.update) {
75
+ GraphUpdate.removeComponentFromUpate(this);
76
+ }
77
+ this.hasPipelines &&
78
+ this.pipelines.isDisposedSet() &&
79
+ this.pipelines.disposed.pipe(this);
80
+ this.hasObservers &&
81
+ this.observers.isDisposedSet() &&
82
+ this.observers.disposed.notify();
83
+ if (this.componentPrototype.data.dispose)
84
+ await this.componentPrototype.data.dispose(this);
85
+ this._disposed = true;
86
+ if (this.hasTraits)
87
+ await this.traits.dispose();
88
+ this.componentPrototype.destory(this);
89
+ delete this._traits;
90
+ delete this._observers;
91
+ delete this._pipelines;
92
+ }
93
+ getDependencies() {
94
+ // return this.node.graph.dependencies;
95
+ return false;
96
+ }
97
+ copy() {
98
+ const data = {
99
+ schema: this.schema?.getSchema
100
+ ? this.schema.getSchema().store()
101
+ : {},
102
+ type: this.type,
103
+ state: this.state,
104
+ traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
105
+ };
106
+ return ((this.hasPipelines &&
107
+ this.pipelines.isCopySet() &&
108
+ this.pipelines.copy.pipe(data)) ||
109
+ data);
110
+ }
111
+ toJSON() {
112
+ const data = {
113
+ schema: this.schema?.getSchema
114
+ ? this.schema.getSchema().store()
115
+ : {},
116
+ type: this.type,
117
+ state: this.state,
118
+ traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
119
+ };
120
+ return ((this.hasPipelines &&
121
+ this.pipelines.isToJSONSet() &&
122
+ this.pipelines.toJSON.pipe(data)) ||
123
+ data);
124
+ }
125
+ }
@@ -0,0 +1,7 @@
1
+ import { ComponentInstance } from "./ComponentInstance";
2
+ import { ItemGraphMap } from "../Maps/ItemGraphMap";
3
+ export declare class ComponentInstanceMap {
4
+ private static types;
5
+ static registerComponent(type: string): ItemGraphMap<any>;
6
+ static getMap(type: string): ItemGraphMap<ComponentInstance<any, any, any, any>>;
7
+ }
@@ -0,0 +1,15 @@
1
+ import { ItemGraphMap } from "../Maps/ItemGraphMap";
2
+ export class ComponentInstanceMap {
3
+ static types = new Map();
4
+ static registerComponent(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
+ }
@@ -0,0 +1,8 @@
1
+ import { Observable } from "@amodx/core/Observers";
2
+ export interface ComponentObservers {
3
+ }
4
+ export declare class ComponentObservers {
5
+ private _disposed?;
6
+ get disposed(): Observable<void>;
7
+ isDisposedSet(): boolean;
8
+ }
@@ -0,0 +1,13 @@
1
+ import { Observable } from "@amodx/core/Observers";
2
+ export class ComponentObservers {
3
+ _disposed;
4
+ get disposed() {
5
+ if (!this._disposed) {
6
+ this._disposed = new Observable();
7
+ }
8
+ return this._disposed;
9
+ }
10
+ isDisposedSet() {
11
+ return !!this._disposed;
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ import { Pipeline } from "@amodx/core/Pipelines";
2
+ import { ComponentInstance } from "./ComponentInstance";
3
+ import { ComponentData } from "./ComponentData";
4
+ export interface ComponentPipelines {
5
+ }
6
+ export declare class ComponentPipelines<ComponentSchema extends object = {}> {
7
+ private _disposed?;
8
+ private _toJSON?;
9
+ private _copy?;
10
+ get disposed(): Pipeline<ComponentInstance<ComponentSchema>>;
11
+ get toJSON(): Pipeline<ComponentData<ComponentSchema>>;
12
+ get copy(): Pipeline<ComponentData<ComponentSchema>>;
13
+ isDisposedSet(): boolean;
14
+ isToJSONSet(): boolean;
15
+ isCopySet(): boolean;
16
+ }
@@ -0,0 +1,33 @@
1
+ import { Pipeline } from "@amodx/core/Pipelines";
2
+ export class ComponentPipelines {
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,17 @@
1
+ import { ObjectSchemaInstance, Schema } from "@amodx/schemas";
2
+ import { ComponentData, ComponentRegisterData } from "./ComponentData";
3
+ import { ComponentInstance } from "./ComponentInstance";
4
+ import { NodeInstance } from "../Nodes/NodeInstance";
5
+ import { ItemPool } from "../Pools/ItemPool";
6
+ export declare class ComponentPrototype<ComponentSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> {
7
+ data: ComponentRegisterData<ComponentSchema, Data, Logic, Shared>;
8
+ schemaController: Schema<ComponentSchema> | null;
9
+ baseContextSchema: ComponentSchema;
10
+ pool: ItemPool<ComponentInstance<ComponentSchema, Data, Logic, Shared>>;
11
+ constructor(data: ComponentRegisterData<ComponentSchema, Data, Logic, Shared>);
12
+ getSchema(overrides: Partial<ComponentSchema>): ObjectSchemaInstance<ComponentSchema>;
13
+ private getPooled;
14
+ private return;
15
+ create(node: NodeInstance, data: ComponentData): ComponentInstance<ComponentSchema, Data, Logic, Shared>;
16
+ destory(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): void;
17
+ }
@@ -0,0 +1,73 @@
1
+ import { Schema } from "@amodx/schemas";
2
+ import { ComponentInstance } from "./ComponentInstance";
3
+ import { ComponentInstanceMap } from "./ComponentInstanceMap";
4
+ import { ItemPool } from "../Pools/ItemPool";
5
+ export class ComponentPrototype {
6
+ data;
7
+ schemaController;
8
+ baseContextSchema;
9
+ pool = new ItemPool();
10
+ constructor(data) {
11
+ this.data = data;
12
+ this.schemaController =
13
+ Array.isArray(data.schema) && data.schema.length
14
+ ? Schema.Create(...data.schema)
15
+ : null;
16
+ this.baseContextSchema = (this.schemaController ? this.schemaController.createData() : {});
17
+ this.pool.maxSize = data.pool?.maxSize || 100;
18
+ }
19
+ getSchema(overrides) {
20
+ if (!this.schemaController)
21
+ return structuredClone(this.baseContextSchema);
22
+ return this.schemaController.instantiate(overrides);
23
+ }
24
+ getPooled() {
25
+ let comp = null;
26
+ if (this.data.pool?.maxSize) {
27
+ comp = this.pool.get();
28
+ }
29
+ return comp || new ComponentInstance();
30
+ }
31
+ return(component) {
32
+ if (this.data.pool?.maxSize) {
33
+ return this.pool.addItem(component);
34
+ }
35
+ return null;
36
+ }
37
+ create(node, data) {
38
+ const instance = this.getPooled();
39
+ instance.node = node;
40
+ instance.componentPrototype = this;
41
+ if (this.data.schema && !instance.schema) {
42
+ instance.schema = this.getSchema(data.schema);
43
+ }
44
+ if (this.data.schema && instance.schema?.getSchema) {
45
+ instance.schema.getSchema().loadIn(this.data.schema);
46
+ }
47
+ if (this.data.logic) {
48
+ instance.logic = this.data.logic
49
+ ? typeof this.data.logic == "function"
50
+ ? this.data.logic(instance)
51
+ : structuredClone(this.data.logic)
52
+ : {};
53
+ }
54
+ if (this.data.data) {
55
+ instance.data = this.data.data
56
+ ? typeof this.data.data == "function"
57
+ ? this.data.data(instance)
58
+ : structuredClone(this.data.data)
59
+ : {};
60
+ }
61
+ if (data.state) {
62
+ instance.state = structuredClone(data.state);
63
+ }
64
+ const map = ComponentInstanceMap.getMap(data.type);
65
+ map.addNode(node, instance);
66
+ return instance;
67
+ }
68
+ destory(component) {
69
+ const map = ComponentInstanceMap.getMap(component.type);
70
+ map.removeNode(component.node, component);
71
+ this.return(component);
72
+ }
73
+ }
@@ -0,0 +1,59 @@
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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,26 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,33 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,24 @@
1
+ import { NodeData } from "../Nodes/NodeData";
2
+ import { NodeInstance } from "../Nodes/NodeInstance";
3
+ import { NodeId } from "../Nodes/NodeId";
4
+ import { GraphEvents } from "./GraphEvents";
5
+ import { GraphObservers } from "./GraphObservers";
6
+ export interface GraphDependencies {
7
+ [key: string]: any;
8
+ }
9
+ export interface Graph {
10
+ }
11
+ export declare class Graph {
12
+ dependencies: GraphDependencies;
13
+ _nodeMap: Map<BigInt, Map<BigInt, NodeInstance>>;
14
+ events: GraphEvents;
15
+ observers: GraphObservers;
16
+ root: NodeInstance;
17
+ constructor(dependencies: GraphDependencies);
18
+ getNode(id: NodeId | string): NodeInstance;
19
+ loadInRoot(data: NodeData): Promise<void>;
20
+ addNode(data: NodeData, parent?: NodeInstance): Promise<NodeInstance>;
21
+ removeNode(id: NodeId): void;
22
+ update(): void;
23
+ toJSON(): NodeData;
24
+ }