@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
@@ -0,0 +1,78 @@
1
+ import { Schema } from "../Schema/Schema";
2
+ import { ComponentCursor } from "./ComponentCursor";
3
+ import { RecursivePartial } from "../Util/Util.types";
4
+ export type CreateComponentData<ComponentSchema extends object = any> = [
5
+ /**
6
+ * The type of the component.
7
+ */
8
+ type: string,
9
+ /**
10
+ * The ComponentSchema of the component.
11
+ */
12
+ schema: RecursivePartial<ComponentSchema> | any | null,
13
+ /**
14
+ * The schema view id of the component.
15
+ */
16
+ schemaViewId: string | null,
17
+ /**
18
+ * Wether or not if the component is remote.
19
+ */
20
+ remote: true | null
21
+ ];
22
+ /**
23
+ * Interface representing the meta data of a component.
24
+ */
25
+ export interface ComponentMetaData {
26
+ name: string;
27
+ [key: string]: any;
28
+ }
29
+ /**
30
+ * Type representing the data required to register a component.
31
+ *
32
+ * Used for serlization and creation.
33
+ * @template ComponentSchema - The schema of the component.
34
+ * @template Data - The runtime data of the component.
35
+ * @template Logic - The logic functions of the component.
36
+ * @template Shared - The shared data of all components of this type.
37
+ * @template Meta - The shared meta data of all components of this type.
38
+ */
39
+ export type ComponentRegisterData<ComponentSchema extends object = any, Data extends any = any, Shared extends any = any> = {
40
+ /**
41
+ * The type of the component.
42
+ */
43
+ type: string;
44
+ /**
45
+ * The schema used to create an editable version of the component.
46
+ * For the actual ComponentInstance the schema is created into an object.
47
+ */
48
+ schema?: Schema<ComponentSchema>;
49
+ data?: Data;
50
+ /**
51
+ * The shared data of all components.
52
+ */
53
+ shared?: Shared;
54
+ /**
55
+ * The shared meta data of all components.
56
+ */
57
+ meta?: ComponentMetaData;
58
+ /**
59
+ * Optional initialization function for the component.
60
+ *
61
+ * @param component - The instance of the component being initialized.
62
+ */
63
+ init?(component: ComponentCursor<ComponentSchema, Data, Shared>): void;
64
+ /**
65
+ * Optional update function for the component.
66
+ * The update function is usually called once per frame.
67
+ * It is up to the graph though when it gets called.
68
+ *
69
+ * @param component - The instance of the component being updated.
70
+ */
71
+ update?(component: ComponentCursor<ComponentSchema, Data, Shared>): void;
72
+ /**
73
+ * Optional disposal function for the component.
74
+ *
75
+ * @param component - The instance of the component being disposed.
76
+ */
77
+ dispose?(component: ComponentCursor<ComponentSchema, Data, Shared>): void;
78
+ };
@@ -0,0 +1,30 @@
1
+ import { Observable } from "../Util/Observable";
2
+ import { SchemaArray } from "../Schema/SchemaArray";
3
+ import { ComponentRegisterData } from "./Component.types";
4
+ import { Graph } from "../Graphs/Graph";
5
+ type ComponentObserverData = [type: number, index: number];
6
+ declare class ComponentArrayObservers {
7
+ componentAdded: Observable<ComponentObserverData>;
8
+ componentRemoved: Observable<ComponentObserverData>;
9
+ nodeAdded: Observable<number>;
10
+ nodeRemoved: Observable<number>;
11
+ }
12
+ export declare class ComponentArray {
13
+ graph: Graph;
14
+ numberTypeId: number;
15
+ _freeSlots: number[];
16
+ _node: number[];
17
+ _disposed: boolean[];
18
+ _data: any[];
19
+ schemaArray: SchemaArray;
20
+ proto: ComponentRegisterData;
21
+ observers: ComponentArrayObservers;
22
+ private _nodeCursor;
23
+ private _componentCursor;
24
+ constructor(graph: Graph, numberTypeId: number);
25
+ addComponent(node: number, schema: any | null, schemaView: string | null): number;
26
+ removeComponent(index: number): number | null;
27
+ update(): void;
28
+ init(index: number): boolean;
29
+ }
30
+ export {};
@@ -0,0 +1,82 @@
1
+ import { Observable } from "../Util/Observable";
2
+ import { NCSRegister } from "../Register/NCSRegister";
3
+ import { NodeCursor } from "../Nodes/NodeCursor";
4
+ import { ComponentCursor } from "./ComponentCursor";
5
+ const componentObserverData = [0, 0];
6
+ class ComponentArrayObservers {
7
+ componentAdded = new Observable();
8
+ componentRemoved = new Observable();
9
+ nodeAdded = new Observable();
10
+ nodeRemoved = new Observable();
11
+ }
12
+ export class ComponentArray {
13
+ graph;
14
+ numberTypeId;
15
+ _freeSlots = [];
16
+ _node = [];
17
+ _disposed = [];
18
+ _data = [];
19
+ schemaArray;
20
+ proto;
21
+ observers = new ComponentArrayObservers();
22
+ _nodeCursor;
23
+ _componentCursor;
24
+ constructor(graph, numberTypeId) {
25
+ this.graph = graph;
26
+ this.numberTypeId = numberTypeId;
27
+ const proto = NCSRegister.components.get(NCSRegister.components.idPalette.getStringId(numberTypeId));
28
+ if (proto.schema)
29
+ this.schemaArray = proto.schema.array;
30
+ this.proto = proto;
31
+ this._nodeCursor = NodeCursor.Get();
32
+ this._componentCursor = ComponentCursor.Get();
33
+ }
34
+ addComponent(node, schema, schemaView) {
35
+ let slot = this._freeSlots.length
36
+ ? this._freeSlots.shift()
37
+ : this._node.length;
38
+ this._node[slot] = node;
39
+ this._disposed[slot] = false;
40
+ if (this.schemaArray)
41
+ this.schemaArray.setData(slot, schema, schemaView);
42
+ componentObserverData[0] = this.numberTypeId;
43
+ componentObserverData[1] = slot;
44
+ this.observers.componentAdded.notify(componentObserverData);
45
+ return slot;
46
+ }
47
+ removeComponent(index) {
48
+ if (this._node[index] === undefined)
49
+ return null;
50
+ componentObserverData[0] = this.numberTypeId;
51
+ componentObserverData[1] = index;
52
+ this.observers.componentRemoved.notify(componentObserverData);
53
+ this.observers.nodeRemoved.notify(this._node[index]);
54
+ this._freeSlots.push(index);
55
+ const nodeIndex = this._node[index];
56
+ this._disposed[index] = true;
57
+ this._data[index] = undefined;
58
+ this._node[index] = -1;
59
+ if (this.schemaArray)
60
+ this.schemaArray.removeData(index);
61
+ return nodeIndex;
62
+ }
63
+ update() {
64
+ const update = this.proto.update;
65
+ if (!update)
66
+ return;
67
+ for (let i = 0; i < this._disposed.length; i++) {
68
+ if (this._disposed[i])
69
+ continue;
70
+ this._componentCursor.setInstance(this._nodeCursor.setNode(this.graph, this._node[i]), this.numberTypeId, i);
71
+ update(this._componentCursor);
72
+ }
73
+ }
74
+ init(index) {
75
+ const init = this.proto.init;
76
+ if (!init)
77
+ return false;
78
+ this._componentCursor.setInstance(this._nodeCursor.setNode(this.graph, this._node[index]), this.numberTypeId, index);
79
+ init(this._componentCursor);
80
+ return false;
81
+ }
82
+ }
@@ -0,0 +1,27 @@
1
+ import { ComponentRegisterData } from "./Component.types";
2
+ import { SchemaCursor } from "../Schema/Schema.types";
3
+ import { NodeCursor } from "../Nodes/NodeCursor";
4
+ import { ComponentArray } from "./ComponentArray";
5
+ export declare class ComponentCursor<ComponentSchema extends object = {}, Data extends any = any, Shared extends any = any> {
6
+ static Get(): ComponentCursor<{}, any, any>;
7
+ static Retrun(cursor: ComponentCursor): boolean;
8
+ get index(): number;
9
+ get type(): string;
10
+ get shared(): Shared;
11
+ schema: SchemaCursor<ComponentSchema>;
12
+ get data(): Data;
13
+ set data(data: Data);
14
+ node: NodeCursor;
15
+ arrays: ComponentArray;
16
+ __proto: ComponentRegisterData<ComponentSchema, Data, Shared>;
17
+ get typeId(): number;
18
+ private _index;
19
+ private _type;
20
+ private constructor();
21
+ setInstance(node: NodeCursor, type: number, index: number): this;
22
+ get isDisposed(): boolean;
23
+ dispose(): void;
24
+ returnCursor(): boolean;
25
+ cloneCursor(cursor?: ComponentCursor, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
26
+ update(): void;
27
+ }
@@ -0,0 +1,72 @@
1
+ import { NCSRegister } from "../Register/NCSRegister";
2
+ import { NodeCursor } from "../Nodes/NodeCursor";
3
+ import { NCSPools } from "../Pools/NCSPools";
4
+ export class ComponentCursor {
5
+ static Get() {
6
+ const cursor = NCSPools.componentCursor.get();
7
+ if (!cursor)
8
+ return new ComponentCursor();
9
+ return cursor;
10
+ }
11
+ static Retrun(cursor) {
12
+ return NCSPools.componentCursor.addItem(cursor);
13
+ }
14
+ get index() {
15
+ return this._index;
16
+ }
17
+ get type() {
18
+ return NCSRegister.components.idPalette.getStringId(this._type);
19
+ }
20
+ get shared() {
21
+ return this.__proto.shared;
22
+ }
23
+ schema;
24
+ get data() {
25
+ return this.arrays._data[this._index];
26
+ }
27
+ set data(data) {
28
+ this.arrays._data[this._index] = data;
29
+ }
30
+ node;
31
+ arrays;
32
+ __proto;
33
+ get typeId() {
34
+ return this._type;
35
+ }
36
+ _index = 0;
37
+ _type = 0;
38
+ constructor() { }
39
+ setInstance(node, type, index) {
40
+ this._index = index;
41
+ this._type = type;
42
+ this.node = node;
43
+ this.__proto = NCSRegister.components.items[this._type];
44
+ this.arrays = node.graph._components[type];
45
+ if (this.arrays?.schemaArray?._data[index] !== undefined) {
46
+ this.schema = this.arrays.schemaArray.createViewCursor(index);
47
+ this.schema.setInstance(index);
48
+ }
49
+ return this;
50
+ }
51
+ get isDisposed() {
52
+ return this.arrays._disposed[this._index];
53
+ }
54
+ dispose() {
55
+ if (this.__proto.dispose)
56
+ this.__proto.dispose(this);
57
+ this.arrays.removeComponent(this._index);
58
+ }
59
+ returnCursor() {
60
+ return ComponentCursor.Retrun(this);
61
+ }
62
+ cloneCursor(cursor, nodeCursor) {
63
+ const newCursor = cursor || ComponentCursor.Get();
64
+ const newNodeCursor = nodeCursor || NodeCursor.Get();
65
+ newNodeCursor.setNode(this.node.graph, this.node.index);
66
+ newCursor.setInstance(newNodeCursor, this.typeId, this._index);
67
+ return newCursor;
68
+ }
69
+ update() {
70
+ this.__proto.update && this.__proto.update(this);
71
+ }
72
+ }
@@ -0,0 +1,76 @@
1
+ import { RecursivePartial } from "../Util/Util.types";
2
+ import { Schema } from "../Schema/Schema";
3
+ /**
4
+ * Interface representing the meta data of a context.
5
+ */
6
+ export interface ContextMetaData {
7
+ name: string;
8
+ [key: string]: any;
9
+ }
10
+ /**
11
+ * Interface representing the state data of a context.
12
+ */
13
+ export interface ContextStateData {
14
+ [key: string]: any;
15
+ }
16
+ /**
17
+ * Type representing the data of a context.
18
+ *
19
+ */
20
+ export type SerializedContextData<Schema extends Record<string, any> = {}> = {
21
+ /**
22
+ * The type of the context.
23
+ */
24
+ type: string;
25
+ /**
26
+ * The schema of the context.
27
+ */
28
+ schema: Schema;
29
+ /**
30
+ * The schema view id of the component.
31
+ */
32
+ schemaViewId: string | null;
33
+ };
34
+ export type CreateContextData<Schema extends Record<string, any> = {}, Data extends Record<string, any> = {}> = [
35
+ /**
36
+ * The type of the context.
37
+ */
38
+ type: string,
39
+ /**
40
+ * The schema of the context.
41
+ */
42
+ schema: RecursivePartial<Schema> | null,
43
+ /**
44
+ * The schema view id of the component.
45
+ */
46
+ schemaViewId: string | null,
47
+ /**
48
+ * The runtime data of the context.
49
+ */
50
+ data: Data | null
51
+ ];
52
+ /**
53
+ * Type representing the data required to register a context.
54
+ *
55
+ * Used for serlization and creation.
56
+ * @template Data - The runtime data of the context.
57
+ */
58
+ export type ContextRegisterData<ContextSchema extends Record<string, any> = {}, Data extends Record<string, any> = {}> = {
59
+ /**
60
+ * The type of the context.
61
+ */
62
+ type: string;
63
+ /**
64
+ * The schema used to create an editable version of the component.
65
+ * For the actual ComponentInstance the schema is created into an object.
66
+ */
67
+ schema?: Schema<ContextSchema>;
68
+ /**
69
+ * The runtime data of the context.
70
+ */
71
+ data?: Data;
72
+ /**
73
+ * The shared meta data of all contexts.
74
+ */
75
+ meta?: ContextMetaData;
76
+ };
@@ -0,0 +1,14 @@
1
+ import { ContextStateData } from "./Context.types";
2
+ import { SchemaArray } from "../Schema/SchemaArray";
3
+ export declare class ContextArray {
4
+ _freeSlots: number[];
5
+ _type: number[];
6
+ _node: number[][];
7
+ _state: ContextStateData[];
8
+ _disposed: boolean[];
9
+ _data: any[];
10
+ schemaArray: SchemaArray[];
11
+ numberTypeId: number;
12
+ addContext(type: number, node: number[], state: ContextStateData, schema: any | null, data?: any | null): number;
13
+ removeContext(index: number): number[] | null;
14
+ }
@@ -0,0 +1,47 @@
1
+ import { NCSRegister } from "../Register/NCSRegister";
2
+ export class ContextArray {
3
+ _freeSlots = [];
4
+ _type = [];
5
+ _node = [];
6
+ _state = [];
7
+ _disposed = [];
8
+ _data = [];
9
+ schemaArray;
10
+ numberTypeId;
11
+ addContext(type, node, state, schema, data = null) {
12
+ let slot = this._freeSlots.length
13
+ ? this._freeSlots.shift()
14
+ : this._node.length;
15
+ const contextSchema = NCSRegister.contexts.get(type).schema;
16
+ if (contextSchema) {
17
+ let schemaArray = this.schemaArray[type];
18
+ if (!schemaArray) {
19
+ schemaArray = contextSchema.array;
20
+ this.schemaArray[type] = schemaArray;
21
+ }
22
+ schemaArray.setData(slot, schema);
23
+ }
24
+ this._type[slot] = type;
25
+ this._node[slot] = node;
26
+ this._state[slot] = state;
27
+ this._disposed[slot] = false;
28
+ data && (this._data[slot] = data);
29
+ return slot;
30
+ }
31
+ removeContext(index) {
32
+ if (this._node[index] === undefined)
33
+ return null;
34
+ this._freeSlots.push(index);
35
+ const data = this._node[index];
36
+ this._node[index] = [];
37
+ this._state[index] = -1;
38
+ this._disposed[index] = true;
39
+ let schemaArray = this.schemaArray[this._type[index]];
40
+ this._type[index] = -1;
41
+ if (schemaArray) {
42
+ schemaArray.removeData(index);
43
+ }
44
+ this._data[index] = undefined;
45
+ return data;
46
+ }
47
+ }
@@ -0,0 +1,24 @@
1
+ import { ContextRegisterData } from "./Context.types";
2
+ import { ContextArray } from "./ContextArray";
3
+ import { NodeCursor } from "../Nodes/NodeCursor";
4
+ import { SchemaCursor } from "../Schema/Schema.types";
5
+ import { Graph } from "../Graphs/Graph";
6
+ export declare class ContextCursor<ContextSchema extends {} = {}, Data extends {} = {}> {
7
+ static Get(): ContextCursor<{}, {}>;
8
+ static Retrun(cursor: ContextCursor): boolean;
9
+ proto: ContextRegisterData<ContextSchema, Data>;
10
+ _index: number;
11
+ _type: number;
12
+ get index(): number;
13
+ get data(): Data;
14
+ set data(data: Data);
15
+ schema: SchemaCursor<ContextSchema>;
16
+ get nodes(): number[];
17
+ get type(): string;
18
+ private _graph;
19
+ get graph(): Graph;
20
+ arrays: ContextArray;
21
+ private constructor();
22
+ setContext(node: NodeCursor, index: number): void;
23
+ dispose(): void;
24
+ }
@@ -0,0 +1,47 @@
1
+ import { NCSRegister } from "../Register/NCSRegister";
2
+ import { NCSPools } from "../Pools/NCSPools";
3
+ export class ContextCursor {
4
+ static Get() {
5
+ const cursor = NCSPools.contextCursor.get();
6
+ if (!cursor)
7
+ return new ContextCursor();
8
+ return cursor;
9
+ }
10
+ static Retrun(cursor) {
11
+ return NCSPools.contextCursor.addItem(cursor);
12
+ }
13
+ proto;
14
+ _index = 0;
15
+ _type = 0;
16
+ get index() {
17
+ return this._index;
18
+ }
19
+ get data() {
20
+ return this.arrays._data[this._index];
21
+ }
22
+ set data(data) {
23
+ this.arrays._data[this._index] = data;
24
+ }
25
+ schema;
26
+ get nodes() {
27
+ return this.arrays._node[this._index];
28
+ }
29
+ get type() {
30
+ return NCSRegister.contexts.idPalette.getStringId(this.arrays._type[this._index]);
31
+ }
32
+ _graph;
33
+ get graph() {
34
+ return this._graph;
35
+ }
36
+ arrays;
37
+ constructor() { }
38
+ setContext(node, index) {
39
+ this._index = index;
40
+ this.arrays = node.graph._contexts;
41
+ this._graph = node.graph;
42
+ this._type = this.arrays._type[index];
43
+ }
44
+ dispose() {
45
+ this.arrays.removeContext(this._index);
46
+ }
47
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Type representing the data of a component.
3
+ *
4
+ * @template ComponentSchema - The ComponentSchema of the component.
5
+ */
6
+ export type SerializedComponentData<ComponentSchema extends object = any> = {
7
+ /**
8
+ * The type of the component.
9
+ */
10
+ type: string;
11
+ /**
12
+ * The ComponentSchema of the component.
13
+ */
14
+ schema?: ComponentSchema;
15
+ schemaViewId?: string;
16
+ };
17
+ /**
18
+ * Type representing the data of a node.
19
+ *
20
+ * Used for serlization and creation.
21
+ */
22
+ export type SerializedNodeData = {
23
+ /**
24
+ * The unique 128 bit identifier of the node.
25
+ *
26
+ */
27
+ id?: string;
28
+ /**
29
+ * The name of the node.
30
+ */
31
+ name: string;
32
+ /**
33
+ * The components of the node.
34
+ */
35
+ components?: SerializedComponentData[];
36
+ /**
37
+ * The tags of the node.
38
+ */
39
+ tags?: string[];
40
+ /**
41
+ * The children nodes of the node.
42
+ */
43
+ children?: SerializedNodeData[];
44
+ };
@@ -0,0 +1,3 @@
1
+ import { CreateComponentData } from "../Components/Component.types";
2
+ import { SerializedComponentData } from "./SerializedData.types";
3
+ export declare function deserializeComponentData(data: SerializedComponentData): CreateComponentData;
@@ -0,0 +1,3 @@
1
+ export function deserializeComponentData(data) {
2
+ return [data.type, data.schema || null, data.schemaViewId || null, null];
3
+ }
@@ -0,0 +1,3 @@
1
+ import { CreateNodeData } from "../Nodes/Node.types";
2
+ import { SerializedNodeData } from "./SerializedData.types";
3
+ export declare function deserializeNodeData(data: SerializedNodeData): CreateNodeData;
@@ -0,0 +1,34 @@
1
+ import { NodeId } from "../Nodes/NodeId";
2
+ import { deserializeComponentData } from "./deserializeComponent";
3
+ import { NCSRegister } from "../Register/NCSRegister";
4
+ export function deserializeNodeData(data) {
5
+ let components = null;
6
+ if (data.components) {
7
+ components = [];
8
+ for (let i = 0; i < data.components.length; i++) {
9
+ const comp = data.components[i];
10
+ components.push(deserializeComponentData(comp));
11
+ }
12
+ }
13
+ let tags = null;
14
+ if (data.tags) {
15
+ tags = [];
16
+ for (let i = 0; i < data.tags.length; i++) {
17
+ tags.push(NCSRegister.tags.idPalette.getNumberId(data.tags[i]));
18
+ }
19
+ }
20
+ let children = null;
21
+ if (data.children) {
22
+ children = [];
23
+ for (let i = 0; i < data.children.length; i++) {
24
+ children.push(deserializeNodeData(data.children[i]));
25
+ }
26
+ }
27
+ return [
28
+ data.id ? NodeId.FromString(data.id) : null,
29
+ data.name,
30
+ components,
31
+ tags,
32
+ children,
33
+ ];
34
+ }
@@ -0,0 +1,7 @@
1
+ import { CreateComponentData } from "../Components/Component.types";
2
+ import { ComponentCursor } from "../Components/ComponentCursor";
3
+ import { SerializedComponentData } from "./SerializedData.types";
4
+ export declare function serializeComponentData(data: CreateComponentData): SerializedComponentData;
5
+ export declare function serializeComponent(component: ComponentCursor): SerializedComponentData;
6
+ export declare function copyComponent(component: ComponentCursor): CreateComponentData;
7
+ export declare function createRemoteComponent(component: ComponentCursor): CreateComponentData;
@@ -0,0 +1,36 @@
1
+ import { NCSRegister } from "../Register/NCSRegister";
2
+ export function serializeComponentData(data) {
3
+ const component = NCSRegister.components.get(data[0]);
4
+ return {
5
+ type: component.type,
6
+ ...(data[1] ? { schema: data[1] } : {}),
7
+ ...(data[2] && data[2] !== "default" ? { schemaViewId: data[2] } : {}),
8
+ };
9
+ }
10
+ export function serializeComponent(component) {
11
+ return {
12
+ type: component.type,
13
+ ...(component.schema ? { schema: component.schema.toJSON() } : {}),
14
+ ...(component.schema?.__view && component.schema?.__view.id !== "default"
15
+ ? { schemaViewId: component.schema.__view.id }
16
+ : {}),
17
+ };
18
+ }
19
+ export function copyComponent(component) {
20
+ return [
21
+ component.type,
22
+ component.schema ? component.schema.toJSON() : null,
23
+ component.schema ? component.schema.__view.id : null,
24
+ null,
25
+ ];
26
+ }
27
+ export function createRemoteComponent(component) {
28
+ return [
29
+ component.type,
30
+ component.schema
31
+ ? component.schema.__view.toRemote(component.schema)
32
+ : null,
33
+ component.schema ? component.schema.__view.id : null,
34
+ true,
35
+ ];
36
+ }
@@ -0,0 +1,13 @@
1
+ import { CreateNodeData } from "../Nodes/Node.types";
2
+ import { NodeCursor } from "../Nodes/NodeCursor";
3
+ import { SerializedNodeData } from "./SerializedData.types";
4
+ export declare function serializeNodeData(data: CreateNodeData): SerializedNodeData;
5
+ /** Serialize the node data as is for storage*/
6
+ export declare function serializeNode(node: NodeCursor): SerializedNodeData;
7
+ /** Copy the node data as is */
8
+ export declare function copyNode(node: NodeCursor): CreateNodeData;
9
+ /** Clone the node data and create new ids if needed. */
10
+ export declare function cloneNode(node: NodeCursor): SerializedNodeData;
11
+ export declare function createRemoteNode(node: NodeCursor, includeChildren?: boolean, includedComponents?: {
12
+ type: string;
13
+ }[]): CreateNodeData;