@amodx/ncs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Components/Component.types.d.ts +78 -0
- package/Components/ComponentArray.d.ts +30 -0
- package/Components/ComponentArray.js +82 -0
- package/Components/ComponentCursor.d.ts +27 -0
- package/Components/ComponentCursor.js +72 -0
- package/Contexts/Context.types.d.ts +76 -0
- package/Contexts/ContextArray.d.ts +14 -0
- package/Contexts/ContextArray.js +47 -0
- package/Contexts/ContextCursor.d.ts +20 -0
- package/Contexts/ContextCursor.js +39 -0
- package/Data/SerializedData.types.d.ts +44 -0
- package/Data/deserializeComponent.d.ts +3 -0
- package/Data/deserializeComponent.js +3 -0
- package/Data/deserializeNode.d.ts +3 -0
- package/Data/deserializeNode.js +34 -0
- package/Data/serializeComponent.d.ts +7 -0
- package/Data/serializeComponent.js +36 -0
- package/Data/serializeNode.d.ts +13 -0
- package/Data/serializeNode.js +83 -0
- package/Functional.d.ts +12 -0
- package/Functional.js +31 -0
- package/Graphs/Graph.d.ts +19 -21
- package/Graphs/Graph.js +85 -74
- package/NCS.d.ts +79 -48
- package/NCS.js +108 -32
- package/Nodes/Node.types.d.ts +39 -0
- package/Nodes/Node.types.js +16 -0
- package/Nodes/NodeArray.d.ts +25 -0
- package/Nodes/NodeArray.js +96 -0
- package/Nodes/NodeComponents.d.ts +19 -0
- package/Nodes/NodeComponents.js +180 -0
- package/Nodes/NodeContext.d.ts +14 -0
- package/Nodes/NodeContext.js +107 -0
- package/Nodes/NodeCursor.d.ts +65 -0
- package/Nodes/NodeCursor.js +348 -0
- package/Nodes/NodeEvents.d.ts +10 -13
- package/Nodes/NodeEvents.js +51 -26
- package/Nodes/NodeId.d.ts +4 -13
- package/Nodes/NodeId.js +16 -48
- package/Nodes/NodeObservers.d.ts +35 -20
- package/Nodes/NodeObservers.js +162 -37
- package/Nodes/NodeTags.d.ts +17 -0
- package/Nodes/NodeTags.js +102 -0
- package/Pools/NCSPools.d.ts +27 -4
- package/Pools/NCSPools.js +14 -2
- package/Queries/Query.types.d.ts +8 -0
- package/Queries/QueryInstance.d.ts +6 -4
- package/Queries/QueryInstance.js +89 -44
- package/Queries/QueryPrototype.d.ts +1 -1
- package/Register/NCSRegister.d.ts +17 -9
- package/Register/NCSRegister.js +25 -2
- package/Register/registerComponent.d.ts +31 -25
- package/Register/registerComponent.js +88 -36
- package/Register/registerContext.d.ts +10 -13
- package/Register/registerContext.js +13 -18
- package/Register/registerSystem.d.ts +1 -1
- package/Register/registerSystem.js +1 -1
- package/Register/registerTag.d.ts +15 -17
- package/Register/registerTag.js +20 -23
- package/Schema/Functions/createBaseSchemaCursor.d.ts +18 -0
- package/Schema/Functions/createBaseSchemaCursor.js +34 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.d.ts +22 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +134 -0
- package/Schema/Functions/createSchemaIndex.d.ts +3 -0
- package/Schema/Functions/createSchemaIndex.js +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.d.ts +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.js +66 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.d.ts +17 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.js +66 -0
- package/Schema/Property/Property.d.ts +11 -0
- package/Schema/Property/Property.js +16 -0
- package/Schema/Property/Property.types.d.ts +26 -0
- package/Schema/Property/Property.types.js +20 -0
- package/Schema/Schema.d.ts +28 -0
- package/Schema/Schema.js +223 -0
- package/Schema/Schema.types.d.ts +59 -0
- package/Schema/Schema.types.js +8 -0
- package/Schema/SchemaArray.d.ts +23 -0
- package/Schema/SchemaArray.js +87 -0
- package/Schema/SchemaArrayCursor.d.ts +19 -0
- package/Schema/SchemaArrayCursor.js +56 -0
- package/Schema/SchemaView.d.ts +24 -0
- package/Schema/SchemaView.js +141 -0
- package/Systems/{SystemData.d.ts → System.types.d.ts} +0 -4
- package/Systems/SystemInstance.d.ts +6 -4
- package/Systems/SystemInstance.js +14 -8
- package/Systems/SystemPrototype.d.ts +1 -1
- package/Systems/SystemPrototype.js +0 -1
- package/Tags/Tag.d.ts +1 -1
- package/Tags/Tag.js +1 -1
- package/Tags/{TagData.d.ts → Tag.types.d.ts} +0 -17
- package/Tags/TagArray.d.ts +18 -0
- package/Tags/TagArray.js +37 -0
- package/Tags/TagCursor.d.ts +20 -0
- package/Tags/TagCursor.js +45 -0
- package/Util/IdPalette.d.ts +13 -0
- package/Util/IdPalette.js +38 -0
- package/{Pools → Util}/ItemPool.d.ts +2 -3
- package/{Pools → Util}/ItemPool.js +2 -4
- package/Util/Observable.d.ts +28 -0
- package/Util/Observable.js +58 -0
- package/Util/Util.types.d.ts +4 -0
- package/index.d.ts +16 -6
- package/index.js +24 -6
- package/package.json +1 -1
- package/Components/ComponentData.d.ts +0 -112
- package/Components/ComponentInstance.d.ts +0 -36
- package/Components/ComponentInstance.js +0 -125
- package/Components/ComponentInstanceMap.d.ts +0 -7
- package/Components/ComponentInstanceMap.js +0 -15
- package/Components/ComponentObservers.d.ts +0 -8
- package/Components/ComponentObservers.js +0 -13
- package/Components/ComponentPipelines.d.ts +0 -16
- package/Components/ComponentPipelines.js +0 -33
- package/Components/ComponentPrototype.d.ts +0 -17
- package/Components/ComponentPrototype.js +0 -73
- package/Contexts/ContextData.d.ts +0 -59
- package/Contexts/ContextInstance.d.ts +0 -14
- package/Contexts/ContextInstance.js +0 -26
- package/Contexts/ContextInstanceAnchor.d.ts +0 -15
- package/Contexts/ContextInstanceAnchor.js +0 -33
- package/Contexts/ContextPrototype.d.ts +0 -9
- package/Contexts/ContextPrototype.js +0 -19
- package/Graphs/GraphEvents.d.ts +0 -9
- package/Graphs/GraphEvents.js +0 -35
- package/Graphs/GraphObservers.d.ts +0 -9
- package/Graphs/GraphObservers.js +0 -6
- package/Graphs/GraphUpdate.d.ts +0 -13
- package/Graphs/GraphUpdate.js +0 -38
- package/Maps/ItemGraphMap.d.ts +0 -11
- package/Maps/ItemGraphMap.js +0 -30
- package/Maps/ItemNodeMap.d.ts +0 -17
- package/Maps/ItemNodeMap.js +0 -41
- package/Nodes/Components/NodeComponentObservers.d.ts +0 -15
- package/Nodes/Components/NodeComponentObservers.js +0 -33
- package/Nodes/Components/NodeComponents.d.ts +0 -22
- package/Nodes/Components/NodeComponents.js +0 -107
- package/Nodes/Context/NodeContext.d.ts +0 -13
- package/Nodes/Context/NodeContext.js +0 -45
- package/Nodes/NodeData.d.ts +0 -40
- package/Nodes/NodeInstance.d.ts +0 -50
- package/Nodes/NodeInstance.js +0 -202
- package/Nodes/NodePipelines.d.ts +0 -16
- package/Nodes/NodePipelines.js +0 -33
- package/Nodes/Tags/NodeTagObservers.d.ts +0 -15
- package/Nodes/Tags/NodeTagObservers.js +0 -33
- package/Nodes/Tags/NodeTags.d.ts +0 -21
- package/Nodes/Tags/NodeTags.js +0 -95
- package/Queries/QueryData.d.ts +0 -8
- package/Register/ItemRegister.d.ts +0 -7
- package/Register/ItemRegister.js +0 -24
- package/Register/registerTrait.d.ts +0 -15
- package/Register/registerTrait.js +0 -39
- package/Tags/TagInstance.d.ts +0 -13
- package/Tags/TagInstance.js +0 -17
- package/Tags/TagInstanceMap.d.ts +0 -7
- package/Tags/TagInstanceMap.js +0 -15
- package/Tags/TagPrototype.d.ts +0 -16
- package/Tags/TagPrototype.js +0 -34
- package/Traits/TraitContaienrObservers.d.ts +0 -15
- package/Traits/TraitContaienrObservers.js +0 -33
- package/Traits/TraitContainer.d.ts +0 -22
- package/Traits/TraitContainer.js +0 -114
- package/Traits/TraitData.d.ts +0 -106
- package/Traits/TraitInstance.d.ts +0 -35
- package/Traits/TraitInstance.js +0 -115
- package/Traits/TraitInstanceMap.d.ts +0 -7
- package/Traits/TraitInstanceMap.js +0 -15
- package/Traits/TraitObservers.d.ts +0 -8
- package/Traits/TraitObservers.js +0 -13
- package/Traits/TraitPipelines.d.ts +0 -16
- package/Traits/TraitPipelines.js +0 -33
- package/Traits/TraitPrototype.d.ts +0 -16
- package/Traits/TraitPrototype.js +0 -74
- /package/Components/{ComponentData.js → Component.types.js} +0 -0
- /package/Contexts/{ContextData.js → Context.types.js} +0 -0
- /package/{Nodes/NodeData.js → Data/SerializedData.types.js} +0 -0
- /package/Queries/{QueryData.js → Query.types.js} +0 -0
- /package/Systems/{SystemData.js → System.types.js} +0 -0
- /package/Tags/{TagData.js → Tag.types.js} +0 -0
- /package/{Traits/TraitData.js → Util/Util.types.js} +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { NodeId } from "../Nodes/NodeId";
|
|
2
|
+
import { createRemoteComponent, serializeComponent, } from "./serializeComponent";
|
|
3
|
+
export function serializeNodeData(data) {
|
|
4
|
+
return {
|
|
5
|
+
name: data[1],
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/** Serialize the node data as is for storage*/
|
|
9
|
+
export function serializeNode(node) {
|
|
10
|
+
const id = node.id;
|
|
11
|
+
let components = null;
|
|
12
|
+
if (node.hasComponents) {
|
|
13
|
+
components = [];
|
|
14
|
+
for (const comp of node.traverseComponents()) {
|
|
15
|
+
components.push(serializeComponent(comp));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
let tags = null;
|
|
19
|
+
if (node.hasTags) {
|
|
20
|
+
tags = [];
|
|
21
|
+
for (const tag of node.traverseTags()) {
|
|
22
|
+
tags.push(tag.type);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
let children = null;
|
|
26
|
+
if (node.childrenArray?.length) {
|
|
27
|
+
children = [];
|
|
28
|
+
for (const child of node.children()) {
|
|
29
|
+
children.push(serializeNode(child));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...(id ? { id: NodeId.ToHexString(id) } : {}),
|
|
34
|
+
name: node.name,
|
|
35
|
+
...(components ? { components } : {}),
|
|
36
|
+
...(tags ? { tags } : {}),
|
|
37
|
+
...(children ? { children } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Copy the node data as is */
|
|
41
|
+
export function copyNode(node) {
|
|
42
|
+
return [null, node.name, null, null, null];
|
|
43
|
+
}
|
|
44
|
+
/** Clone the node data and create new ids if needed. */
|
|
45
|
+
export function cloneNode(node) {
|
|
46
|
+
return {
|
|
47
|
+
name: node.name,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function createRemoteNode(node, includeChildren = false, includedComponents = []) {
|
|
51
|
+
let children = null;
|
|
52
|
+
if (includeChildren) {
|
|
53
|
+
children = [];
|
|
54
|
+
for (const child of node.children()) {
|
|
55
|
+
children.push(createRemoteNode(child, includeChildren, includedComponents));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
let components = null;
|
|
59
|
+
if (node.hasComponents) {
|
|
60
|
+
components = [];
|
|
61
|
+
for (const component of node.traverseComponents()) {
|
|
62
|
+
if (includedComponents.length) {
|
|
63
|
+
for (let i = 0; i < includedComponents.length; i++) {
|
|
64
|
+
if (includedComponents[i].type == component.type) {
|
|
65
|
+
components.push(createRemoteComponent(component));
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
components.push(createRemoteComponent(component));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let tags = null;
|
|
76
|
+
if (node.hasTags) {
|
|
77
|
+
tags = [];
|
|
78
|
+
for (const tag of node.traverseTags()) {
|
|
79
|
+
tags.push(tag.typeId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [node.id ? node.id : null, node.name, components, tags, children];
|
|
83
|
+
}
|
package/Functional.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CreateNodeData } from "./Nodes/Node.types";
|
|
2
|
+
import { CreateComponentData } from "./Components/Component.types";
|
|
3
|
+
import { RegisteredTag } from "./Register/registerTag";
|
|
4
|
+
export declare function Node(): CreateNodeData;
|
|
5
|
+
export declare function Node(components?: CreateComponentData[], tags?: number[] | null, ...children: CreateNodeData[]): CreateNodeData;
|
|
6
|
+
export declare function Node(data: string, components?: CreateComponentData[], ...children: CreateNodeData[]): CreateNodeData;
|
|
7
|
+
export declare function Node(data: {
|
|
8
|
+
id?: true;
|
|
9
|
+
name?: string;
|
|
10
|
+
tags?: number[];
|
|
11
|
+
}, components?: CreateComponentData[], ...children: CreateNodeData[]): CreateNodeData;
|
|
12
|
+
export declare function Tag(id: string, ...children: RegisteredTag[]): RegisteredTag;
|
package/Functional.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NCS } from "./NCS";
|
|
2
|
+
export function Node(dataOrComponents, maybeComponentsOrChildren, ...restChildren) {
|
|
3
|
+
if (!dataOrComponents) {
|
|
4
|
+
return NCS.createNode(null, "New Node", null, undefined, restChildren);
|
|
5
|
+
}
|
|
6
|
+
// Case A: dataOrComponents is an array => treat it as the components array
|
|
7
|
+
if (Array.isArray(dataOrComponents)) {
|
|
8
|
+
const components = dataOrComponents;
|
|
9
|
+
const children = restChildren ?? [];
|
|
10
|
+
return NCS.createNode(undefined, undefined, Array.isArray(maybeComponentsOrChildren)
|
|
11
|
+
? maybeComponentsOrChildren
|
|
12
|
+
: undefined, components, children);
|
|
13
|
+
}
|
|
14
|
+
// Case B: dataOrComponents is a string => treat it as the name
|
|
15
|
+
if (typeof dataOrComponents === "string") {
|
|
16
|
+
const name = dataOrComponents;
|
|
17
|
+
const components = (maybeComponentsOrChildren ??
|
|
18
|
+
[]);
|
|
19
|
+
return NCS.createNode(undefined, name, undefined, components, restChildren);
|
|
20
|
+
}
|
|
21
|
+
// Case C: dataOrComponents is the object form => { id?, name?, state?, tags? }
|
|
22
|
+
const components = (maybeComponentsOrChildren ?? []);
|
|
23
|
+
return NCS.createNode(dataOrComponents.id, dataOrComponents.name, dataOrComponents.tags, components, restChildren);
|
|
24
|
+
}
|
|
25
|
+
export function Tag(id, ...children) {
|
|
26
|
+
const tag = NCS.registerTag({ id });
|
|
27
|
+
children.forEach((_) => {
|
|
28
|
+
tag.tag.addChild(_.tag);
|
|
29
|
+
});
|
|
30
|
+
return tag;
|
|
31
|
+
}
|
package/Graphs/Graph.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export interface Graph {
|
|
10
|
-
}
|
|
1
|
+
import { CreateNodeData } from "../Nodes/Node.types";
|
|
2
|
+
import { NodeArray } from "../Nodes/NodeArray";
|
|
3
|
+
import { ComponentArray } from "../Components/ComponentArray";
|
|
4
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
5
|
+
import { ContextArray } from "../Contexts/ContextArray";
|
|
6
|
+
import { TagArray } from "../Tags/TagArray";
|
|
7
|
+
import { SystemInstance } from "../Systems/SystemInstance";
|
|
11
8
|
export declare class Graph {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
_systems: SystemInstance[];
|
|
10
|
+
_nodes: NodeArray;
|
|
11
|
+
_components: ComponentArray[];
|
|
12
|
+
_contexts: ContextArray;
|
|
13
|
+
_tags: TagArray[];
|
|
14
|
+
_updatingComponents: ComponentArray[];
|
|
15
|
+
root: NodeCursor;
|
|
16
|
+
constructor();
|
|
17
|
+
getNode(index: number, cursor?: NodeCursor): NodeCursor;
|
|
18
|
+
getNodeFromId(id: bigint | string, cursor?: NodeCursor): NodeCursor;
|
|
19
|
+
addNode(data: CreateNodeData, parent?: number, cursor?: NodeCursor): NodeCursor;
|
|
20
|
+
removeNode(index: number): boolean;
|
|
22
21
|
update(): void;
|
|
23
|
-
toJSON(): NodeData;
|
|
24
22
|
}
|
package/Graphs/Graph.js
CHANGED
|
@@ -1,90 +1,101 @@
|
|
|
1
|
-
import { NodeInstance } from "../Nodes/NodeInstance";
|
|
2
1
|
import { NodeId } from "../Nodes/NodeId";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import { NodeArray } from "../Nodes/NodeArray";
|
|
3
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
|
+
import { ContextArray } from "../Contexts/ContextArray";
|
|
5
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
6
|
+
const parentCursor = NodeCursor.Get();
|
|
7
|
+
const nodeCursor = NodeCursor.Get();
|
|
8
|
+
function createNode(graph, data, parent) {
|
|
9
|
+
const newNode = graph._nodes.addNode(typeof data[0] == "string" ? NodeId.FromString(data[0]) : data[0], parent, data[1]);
|
|
10
|
+
nodeCursor.graph = graph;
|
|
11
|
+
nodeCursor.setNode(graph, newNode);
|
|
12
|
+
if (data[2]?.length) {
|
|
13
|
+
for (let i = 0; i < data[2].length; i++) {
|
|
14
|
+
nodeCursor.components.add(data[2][i]);
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!high)
|
|
21
|
-
throw new Error(`Node with id ${id.idString} does not exist`);
|
|
22
|
-
const node = high.get(id.high);
|
|
23
|
-
if (!node)
|
|
24
|
-
throw new Error(`Node with id ${id.idString} does not exist`);
|
|
25
|
-
return node;
|
|
17
|
+
if (data[3]?.length) {
|
|
18
|
+
for (let i = 0; i < data[3].length; i++) {
|
|
19
|
+
nodeCursor.tags.add(data[3][i]);
|
|
20
|
+
}
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const root = new NodeInstance({}, data, this);
|
|
31
|
-
await root.addChildren(...data.children);
|
|
32
|
-
this.root = root;
|
|
22
|
+
if (parent >= 0) {
|
|
23
|
+
parentCursor.setNode(graph, parent);
|
|
24
|
+
parentCursor.addChild(nodeCursor);
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
parent.children.push(newNode);
|
|
38
|
-
let high = this._nodeMap.get(newNode.id.low);
|
|
39
|
-
if (!high) {
|
|
40
|
-
high = new Map();
|
|
41
|
-
this._nodeMap.set(newNode.id.low, high);
|
|
26
|
+
if (data[4]?.length) {
|
|
27
|
+
for (let i = 0; i < data[4].length; i++) {
|
|
28
|
+
createNode(graph, data[4][i], newNode);
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
}
|
|
31
|
+
nodeCursor.setNode(graph, newNode);
|
|
32
|
+
data[0] = null;
|
|
33
|
+
data[1] = "";
|
|
34
|
+
data[2] = null;
|
|
35
|
+
data[3] = null;
|
|
36
|
+
data[4] = null;
|
|
37
|
+
NCSPools.createNodeData.addItem(data);
|
|
38
|
+
return nodeCursor;
|
|
39
|
+
}
|
|
40
|
+
export class Graph {
|
|
41
|
+
_systems = [];
|
|
42
|
+
_nodes = new NodeArray();
|
|
43
|
+
_components = [];
|
|
44
|
+
_contexts = new ContextArray();
|
|
45
|
+
_tags = [];
|
|
46
|
+
_updatingComponents = [];
|
|
47
|
+
root = NodeCursor.Get();
|
|
48
|
+
constructor() {
|
|
49
|
+
const rootIndex = this._nodes.addNode(null, -1, "root");
|
|
50
|
+
this.root.setNode(this, rootIndex);
|
|
51
|
+
}
|
|
52
|
+
getNode(index, cursor = nodeCursor) {
|
|
53
|
+
const parentIndex = this._nodes._parents[index];
|
|
54
|
+
if (typeof parentIndex === "undefined")
|
|
55
|
+
throw new Error(`Node with index ${index} does not exist`);
|
|
56
|
+
cursor.setNode(this, index);
|
|
57
|
+
return cursor;
|
|
58
|
+
}
|
|
59
|
+
getNodeFromId(id, cursor = nodeCursor) {
|
|
60
|
+
if (typeof id == "string")
|
|
61
|
+
id = NodeId.FromString(id);
|
|
62
|
+
const nodeIndex = this._nodes._idMap.get(id);
|
|
63
|
+
if (typeof nodeIndex === "undefined")
|
|
64
|
+
throw new Error(`Node with id ${id} does not exist`);
|
|
65
|
+
cursor.setNode(this, nodeIndex);
|
|
66
|
+
return cursor;
|
|
67
|
+
}
|
|
68
|
+
addNode(data, parent = this.root.index, cursor = nodeCursor) {
|
|
69
|
+
const newNode = createNode(this, data, parent);
|
|
70
|
+
if (newNode.hasComponents) {
|
|
71
|
+
const components = newNode.components.components;
|
|
72
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
73
|
+
this._components[components[i]].init(components[i + 1]);
|
|
74
|
+
}
|
|
46
75
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
for (const child of data.children) {
|
|
54
|
-
await this.addNode(child, newNode);
|
|
76
|
+
for (const child of newNode.traverseChildren()) {
|
|
77
|
+
if (child.hasComponents) {
|
|
78
|
+
const components = child.components.components;
|
|
79
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
80
|
+
this._components[components[i]].init(components[i + 1]);
|
|
81
|
+
}
|
|
55
82
|
}
|
|
56
83
|
}
|
|
57
|
-
|
|
84
|
+
newNode.toRef(cursor);
|
|
85
|
+
return cursor;
|
|
58
86
|
}
|
|
59
|
-
removeNode(
|
|
60
|
-
const
|
|
61
|
-
if (!low)
|
|
62
|
-
return;
|
|
63
|
-
const node = low.get(id.high);
|
|
87
|
+
removeNode(index) {
|
|
88
|
+
const node = this._nodes.removeNode(index);
|
|
64
89
|
if (!node)
|
|
65
|
-
return;
|
|
66
|
-
|
|
67
|
-
node.dispose();
|
|
68
|
-
this._nodeMap.delete(id.low);
|
|
69
|
-
low.delete(id.high);
|
|
70
|
-
this.observers.nodeRemoved.notify(node);
|
|
71
|
-
this.observers.nodesUpdated.notify();
|
|
90
|
+
return false;
|
|
91
|
+
return true;
|
|
72
92
|
}
|
|
73
93
|
update() {
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
for (const component of updating) {
|
|
77
|
-
component.componentPrototype.data.update(component);
|
|
78
|
-
}
|
|
94
|
+
for (let i = 0; i < this._updatingComponents.length; i++) {
|
|
95
|
+
this._updatingComponents[i].update();
|
|
79
96
|
}
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
for (const system of updating) {
|
|
83
|
-
system.systemPrototype.update(system);
|
|
84
|
-
}
|
|
97
|
+
for (let i = 0; i < this._systems.length; i++) {
|
|
98
|
+
this._systems[i].update();
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
|
-
toJSON() {
|
|
88
|
-
return this.root.toJSON();
|
|
89
|
-
}
|
|
90
101
|
}
|
package/NCS.d.ts
CHANGED
|
@@ -1,54 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { NodeInstance } from "./Nodes/NodeInstance";
|
|
5
|
-
import { QueryData } from "./Queries/QueryData";
|
|
1
|
+
import { Graph } from "./Graphs/Graph";
|
|
2
|
+
import { CreateNodeData } from "./Nodes/Node.types";
|
|
3
|
+
import { QueryData } from "./Queries/Query.types";
|
|
6
4
|
import { QueryPrototype } from "./Queries/QueryPrototype";
|
|
7
|
-
import {
|
|
8
|
-
import { TraitData } from "./Traits/TraitData";
|
|
9
|
-
import { ContextData } from "./Contexts/ContextData";
|
|
10
|
-
import { TagData } from "./Tags/TagData";
|
|
5
|
+
import { CreateComponentData } from "./Components/Component.types";
|
|
11
6
|
import { registerContext } from "./Register/registerContext";
|
|
12
|
-
import { registerTrait } from "./Register/registerTrait";
|
|
13
7
|
import { registerTag } from "./Register/registerTag";
|
|
14
8
|
import { registerSystem } from "./Register/registerSystem";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
9
|
+
import { Schema } from "./Schema/Schema";
|
|
10
|
+
import { copyComponent, createRemoteComponent, serializeComponent, serializeComponentData } from "./Data/serializeComponent";
|
|
11
|
+
import { deserializeComponentData } from "./Data/deserializeComponent";
|
|
12
|
+
import { cloneNode, copyNode, createRemoteNode, serializeNode, serializeNodeData } from "./Data/serializeNode";
|
|
13
|
+
import { deserializeNodeData } from "./Data/deserializeNode";
|
|
14
|
+
import { ExtractSchemaClass, SchemaCreateData, SchemaProperty } from "./Schema/Schema.types";
|
|
15
|
+
export declare const NCS: {
|
|
16
|
+
/** Create a graph. */
|
|
17
|
+
createGraph(): Graph;
|
|
18
|
+
/** Create node data to add a node to a graph. */
|
|
19
|
+
createNode(id?: true | null, name?: string | null, tags?: number[] | null, components?: CreateComponentData[], children?: CreateNodeData[]): CreateNodeData;
|
|
20
|
+
/** Create a schema from an object. */
|
|
21
|
+
schemaFromObject<T extends Record<string, any>>(data: T): Schema<T>;
|
|
22
|
+
/** Create a schema for a component or context. */
|
|
23
|
+
schema<T extends Record<string, SchemaProperty<any>>>(schema: T, views?: SchemaCreateData[]): Schema<ExtractSchemaClass<T>>;
|
|
24
|
+
/** Create a property for a schema. */
|
|
25
|
+
property<T>(value: T, meta?: SchemaProperty<T>["meta"]): SchemaProperty<T>;
|
|
26
|
+
/** Cast and set the type for the Data and Shared properties of a component. */
|
|
27
|
+
data<T>(data?: any): T;
|
|
28
|
+
/** Create a query to work with nodes based on specific components and tags. */
|
|
29
|
+
createQuery(data: QueryData): QueryPrototype;
|
|
30
|
+
/** Register a system for use with NCS. */
|
|
31
|
+
registerSystem: typeof registerSystem;
|
|
32
|
+
/** Register a component for use with NCS. */
|
|
33
|
+
registerComponent: <Data extends unknown = any, Shared extends unknown = any, ComponentSchema extends object = any>(data: import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared>) => import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared> & {
|
|
34
|
+
getNodes(grpah: Graph): Generator<import(".").NodeCursor>;
|
|
35
|
+
getComponents(grpah: Graph): Generator<import(".").ComponentCursor<ComponentSchema, Data, Shared>, any, any>;
|
|
36
|
+
set(node: import(".").NodeCursor, componentSchema?: import("./Util/Util.types").Nullable<Partial<ComponentSchema>> | undefined, schemaCursor?: import("./Util/Util.types").Nullable<import("./Schema/Schema.types").SchemaCursor<ComponentSchema>> | undefined, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared>;
|
|
37
|
+
has(node: import(".").NodeCursor): boolean;
|
|
38
|
+
get(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
39
|
+
getRequired(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared>;
|
|
40
|
+
getChild(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
41
|
+
getRequiredChild(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared>;
|
|
42
|
+
getParent(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
43
|
+
getRequiredParent(node: import(".").NodeCursor, cursor?: import(".").ComponentCursor<ComponentSchema, Data, Shared> | undefined): import(".").ComponentCursor<ComponentSchema, Data, Shared>;
|
|
44
|
+
getAll(node: import(".").NodeCursor): import(".").ComponentCursor<ComponentSchema, Data, Shared>[] | null;
|
|
45
|
+
remove(node: import(".").NodeCursor): boolean;
|
|
46
|
+
removeAll(node: import(".").NodeCursor): boolean;
|
|
37
47
|
nodeData: {
|
|
38
|
-
get: (
|
|
39
|
-
set
|
|
40
|
-
getAll: (
|
|
41
|
-
remove: (
|
|
42
|
-
removeAll: (
|
|
48
|
+
get(node: import(".").SerializedNodeData): import(".").SerializedComponentData<ComponentSchema> | null;
|
|
49
|
+
set(node: import(".").SerializedNodeData, componentSchema?: Partial<ComponentSchema> | undefined): void;
|
|
50
|
+
getAll(node: import(".").SerializedNodeData): import(".").SerializedComponentData<ComponentSchema>[] | null;
|
|
51
|
+
remove(node: import(".").SerializedNodeData): import(".").SerializedComponentData<ComponentSchema> | null;
|
|
52
|
+
removeAll(node: import(".").SerializedNodeData): import(".").SerializedComponentData<ComponentSchema>[] | null;
|
|
43
53
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
type: string;
|
|
55
|
+
typeId: number;
|
|
56
|
+
data: import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared>;
|
|
57
|
+
default: import(".").ComponentCursor<ComponentSchema, Data, Shared>;
|
|
58
|
+
} & ((schema?: Partial<ComponentSchema> | null | undefined, schemaView?: string | null) => CreateComponentData<ComponentSchema>);
|
|
59
|
+
/** Register a context for use with NCS. */
|
|
60
|
+
registerContext: typeof registerContext;
|
|
61
|
+
/** Register a tag for use with NCS. */
|
|
62
|
+
registerTag: typeof registerTag;
|
|
63
|
+
/** Serialize a component for storage. */
|
|
64
|
+
serializeComponent: typeof serializeComponent;
|
|
65
|
+
/** Serialize component data for storage. */
|
|
66
|
+
serializeComponentData: typeof serializeComponentData;
|
|
67
|
+
/** Serialize a component to use in another context. */
|
|
68
|
+
createRemoteComponent: typeof createRemoteComponent;
|
|
69
|
+
/** Copy a component. */
|
|
70
|
+
copyComponent: typeof copyComponent;
|
|
71
|
+
/** Deserialize a component from storage into component data. */
|
|
72
|
+
deserializeComponentData: typeof deserializeComponentData;
|
|
73
|
+
/** Serialize a node for storage. */
|
|
74
|
+
serializeNode: typeof serializeNode;
|
|
75
|
+
/** Serialize node data for storage. */
|
|
76
|
+
serializeNodeData: typeof serializeNodeData;
|
|
77
|
+
/** Copy a node as is. */
|
|
78
|
+
copyNode: typeof copyNode;
|
|
79
|
+
/** Copy a node and change IDs. */
|
|
80
|
+
cloneNode: typeof cloneNode;
|
|
81
|
+
/** Serialize a node for use in another context. */
|
|
82
|
+
createRemoteNode: typeof createRemoteNode;
|
|
83
|
+
/** Deserialize a node from storage into node data. */
|
|
84
|
+
deserializeNodeData: typeof deserializeNodeData;
|
|
85
|
+
};
|
package/NCS.js
CHANGED
|
@@ -1,41 +1,117 @@
|
|
|
1
|
-
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
1
|
import { Graph } from "./Graphs/Graph";
|
|
3
2
|
import { NodeId } from "./Nodes/NodeId";
|
|
4
3
|
import { QueryPrototype } from "./Queries/QueryPrototype";
|
|
5
4
|
import { registerContext } from "./Register/registerContext";
|
|
6
5
|
import { registerComponent } from "./Register/registerComponent";
|
|
7
|
-
import { registerTrait } from "./Register/registerTrait";
|
|
8
6
|
import { registerTag } from "./Register/registerTag";
|
|
9
7
|
import { registerSystem } from "./Register/registerSystem";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
import { NCSPools } from "./Pools/NCSPools";
|
|
9
|
+
import { Schema } from "./Schema/Schema";
|
|
10
|
+
import { copyComponent, createRemoteComponent, serializeComponent, serializeComponentData, } from "./Data/serializeComponent";
|
|
11
|
+
import { deserializeComponentData } from "./Data/deserializeComponent";
|
|
12
|
+
import { cloneNode, copyNode, createRemoteNode, serializeNode, serializeNodeData, } from "./Data/serializeNode";
|
|
13
|
+
import { deserializeNodeData } from "./Data/deserializeNode";
|
|
14
|
+
import { SchemaProperty, } from "./Schema/Schema.types";
|
|
15
|
+
const traverseCreateSchema = (object, parent) => {
|
|
16
|
+
for (const key in object) {
|
|
17
|
+
parent.children ??= [];
|
|
18
|
+
const value = object[key];
|
|
19
|
+
if (value instanceof SchemaProperty) {
|
|
20
|
+
if (value.value instanceof SchemaProperty &&
|
|
21
|
+
typeof value.value.value == "object") {
|
|
22
|
+
const newParent = {
|
|
23
|
+
id: key,
|
|
24
|
+
meta: value.meta,
|
|
25
|
+
value: value.value,
|
|
26
|
+
children: [],
|
|
27
|
+
};
|
|
28
|
+
parent.children.push(newParent);
|
|
29
|
+
traverseCreateSchema(value.value.value, newParent);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
parent.children.push({
|
|
33
|
+
id: key,
|
|
34
|
+
meta: value.meta,
|
|
35
|
+
value: value.value,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
20
39
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
return parent;
|
|
41
|
+
};
|
|
42
|
+
export const NCS = {
|
|
43
|
+
/** Create a graph. */
|
|
44
|
+
createGraph() {
|
|
45
|
+
return new Graph();
|
|
46
|
+
},
|
|
47
|
+
/** Create node data to add a node to a graph. */
|
|
48
|
+
createNode(id, name, tags, components, children = []) {
|
|
49
|
+
const data = NCSPools.createNodeData.get() || [];
|
|
50
|
+
data[0] = id ? NodeId.Create() : null;
|
|
51
|
+
data[1] = name || "New Node";
|
|
52
|
+
data[2] = components || null;
|
|
53
|
+
data[3] = tags || null;
|
|
54
|
+
data[4] = children || null;
|
|
55
|
+
return data;
|
|
56
|
+
},
|
|
57
|
+
/** Create a schema from an object. */
|
|
58
|
+
schemaFromObject(data) {
|
|
59
|
+
return Schema.FromObject(data);
|
|
60
|
+
},
|
|
61
|
+
/** Create a schema for a component or context. */
|
|
62
|
+
schema(schema, views) {
|
|
63
|
+
const s = new Schema(traverseCreateSchema(schema, {
|
|
64
|
+
id: "root",
|
|
65
|
+
value: {},
|
|
66
|
+
children: [],
|
|
67
|
+
}).children);
|
|
68
|
+
if (views) {
|
|
69
|
+
for (const view of views) {
|
|
70
|
+
s.createView(view);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return s;
|
|
74
|
+
},
|
|
75
|
+
/** Create a property for a schema. */
|
|
76
|
+
property(value, meta = {}) {
|
|
77
|
+
return new SchemaProperty(value, meta);
|
|
78
|
+
},
|
|
79
|
+
/** Cast and set the type for the Data and Shared properties of a component. */
|
|
80
|
+
data(data = {}) {
|
|
81
|
+
return data;
|
|
82
|
+
},
|
|
83
|
+
/** Create a query to work with nodes based on specific components and tags. */
|
|
84
|
+
createQuery(data) {
|
|
31
85
|
return new QueryPrototype(data);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
86
|
+
},
|
|
87
|
+
/** Register a system for use with NCS. */
|
|
88
|
+
registerSystem,
|
|
89
|
+
/** Register a component for use with NCS. */
|
|
90
|
+
registerComponent,
|
|
91
|
+
/** Register a context for use with NCS. */
|
|
92
|
+
registerContext,
|
|
93
|
+
/** Register a tag for use with NCS. */
|
|
94
|
+
registerTag,
|
|
95
|
+
/** Serialize a component for storage. */
|
|
96
|
+
serializeComponent,
|
|
97
|
+
/** Serialize component data for storage. */
|
|
98
|
+
serializeComponentData,
|
|
99
|
+
/** Serialize a component to use in another context. */
|
|
100
|
+
createRemoteComponent,
|
|
101
|
+
/** Copy a component. */
|
|
102
|
+
copyComponent,
|
|
103
|
+
/** Deserialize a component from storage into component data. */
|
|
104
|
+
deserializeComponentData,
|
|
105
|
+
/** Serialize a node for storage. */
|
|
106
|
+
serializeNode,
|
|
107
|
+
/** Serialize node data for storage. */
|
|
108
|
+
serializeNodeData,
|
|
109
|
+
/** Copy a node as is. */
|
|
110
|
+
copyNode,
|
|
111
|
+
/** Copy a node and change IDs. */
|
|
112
|
+
cloneNode,
|
|
113
|
+
/** Serialize a node for use in another context. */
|
|
114
|
+
createRemoteNode,
|
|
115
|
+
/** Deserialize a node from storage into node data. */
|
|
116
|
+
deserializeNodeData,
|
|
117
|
+
};
|