@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.
- 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 +24 -0
- package/Contexts/ContextCursor.js +47 -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 +115 -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 +183 -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 +13 -14
- package/Nodes/NodeEvents.js +58 -28
- 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 +16 -16
- 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
package/Register/NCSRegister.js
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IdPalette } from "../Util/IdPalette";
|
|
2
|
+
class ItemRegister {
|
|
3
|
+
itemtype;
|
|
4
|
+
items = [];
|
|
5
|
+
idPalette = new IdPalette();
|
|
6
|
+
constructor(itemtype) {
|
|
7
|
+
this.itemtype = itemtype;
|
|
8
|
+
}
|
|
9
|
+
get(id) {
|
|
10
|
+
const item = typeof id == "string"
|
|
11
|
+
? this.items[this.idPalette.getNumberId(id)]
|
|
12
|
+
: this.items[id];
|
|
13
|
+
if (!item)
|
|
14
|
+
throw new Error(`[${this.itemtype}]: Entry with id ${id} does not exist`);
|
|
15
|
+
return item;
|
|
16
|
+
}
|
|
17
|
+
has(id) {
|
|
18
|
+
return this.idPalette.isRegistered(id);
|
|
19
|
+
}
|
|
20
|
+
register(id, item) {
|
|
21
|
+
const itemId = this.idPalette.register(id);
|
|
22
|
+
this.items[itemId] = item;
|
|
23
|
+
return itemId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
2
26
|
export class NCSRegister {
|
|
3
27
|
static components = new ItemRegister("Components");
|
|
4
|
-
static traits = new ItemRegister("Traits");
|
|
5
28
|
static contexts = new ItemRegister("Context");
|
|
6
29
|
static tags = new ItemRegister("Tags");
|
|
7
30
|
static systems = new ItemRegister("Systems");
|
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentInstance } from "../Components/ComponentInstance";
|
|
1
|
+
import { ComponentRegisterData, CreateComponentData } from "../Components/Component.types";
|
|
3
2
|
import { Graph } from "../Graphs/Graph";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
import { SerializedNodeData, SerializedComponentData } from "../Data/SerializedData.types";
|
|
4
|
+
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
5
|
+
import { SchemaCursor } from "../Schema/Schema.types";
|
|
6
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
7
|
+
import { Nullable } from "Util/Util.types";
|
|
8
|
+
type RegisteredComponent<ComponentSchema extends object = any, Data extends any = any, Shared extends any = any> = (ComponentRegisterData<ComponentSchema, Data, Shared> & {
|
|
9
|
+
getNodes(grpah: Graph): Generator<NodeCursor>;
|
|
10
|
+
getComponents(grpah: Graph): Generator<ComponentCursor<ComponentSchema, Data, Shared>>;
|
|
11
|
+
set(node: NodeCursor, componentSchema?: Nullable<Partial<ComponentSchema>>, schemaCursor?: Nullable<SchemaCursor<ComponentSchema>>, cursor?: ComponentCursor<ComponentSchema, Data, Shared>): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
12
|
+
has(node: NodeCursor): boolean;
|
|
13
|
+
get(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
14
|
+
getRequired(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
15
|
+
getChild(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
16
|
+
getRequiredChild(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
17
|
+
getParent(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
18
|
+
getRequiredParent(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared>, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
19
|
+
getAll(node: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>[] | null;
|
|
20
|
+
remove(node: NodeCursor): boolean;
|
|
21
|
+
removeAll(node: NodeCursor): boolean;
|
|
18
22
|
nodeData: {
|
|
19
|
-
get
|
|
20
|
-
set
|
|
21
|
-
getAll
|
|
22
|
-
remove
|
|
23
|
-
removeAll
|
|
23
|
+
get(node: SerializedNodeData): SerializedComponentData<ComponentSchema> | null;
|
|
24
|
+
set(node: SerializedNodeData, componentSchema?: Partial<ComponentSchema>): void;
|
|
25
|
+
getAll(node: SerializedNodeData): SerializedComponentData<ComponentSchema>[] | null;
|
|
26
|
+
remove(node: SerializedNodeData): SerializedComponentData<ComponentSchema> | null;
|
|
27
|
+
removeAll(node: SerializedNodeData): SerializedComponentData<ComponentSchema>[] | null;
|
|
24
28
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
type: string;
|
|
30
|
+
typeId: number;
|
|
31
|
+
data: ComponentRegisterData<ComponentSchema, Data, Shared>;
|
|
32
|
+
default: ComponentCursor<ComponentSchema, Data, Shared>;
|
|
33
|
+
}) & ((schema?: Partial<ComponentSchema> | null | undefined, schemaView?: string | null) => CreateComponentData<ComponentSchema>);
|
|
34
|
+
export declare const registerComponent: <Data extends unknown = any, Shared extends unknown = any, ComponentSchema extends object = any>(data: ComponentRegisterData<ComponentSchema, Data, Shared>) => RegisteredComponent<ComponentSchema, Data, Shared>;
|
|
29
35
|
export {};
|
|
@@ -1,37 +1,90 @@
|
|
|
1
|
-
import { ComponentInstanceMap } from "../Components/ComponentInstanceMap";
|
|
2
|
-
import { NCS } from "../NCS";
|
|
3
1
|
import { NCSRegister } from "./NCSRegister";
|
|
4
|
-
import {
|
|
2
|
+
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
3
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
5
5
|
export const registerComponent = (data) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
schema: {
|
|
15
|
-
...structuredClone(prototype.baseContextSchema),
|
|
16
|
-
...(schema || {}),
|
|
17
|
-
},
|
|
18
|
-
});
|
|
6
|
+
const typeId = NCSRegister.components.register(data.type, data);
|
|
7
|
+
data.shared = data.shared || {};
|
|
8
|
+
const createComponent = (schema, schemaView) => {
|
|
9
|
+
const createData = NCSPools.createComponentData.get() || [];
|
|
10
|
+
createData[0] = data.type;
|
|
11
|
+
createData[1] = schema || {};
|
|
12
|
+
createData[2] = schemaView || "default";
|
|
13
|
+
return createData;
|
|
19
14
|
};
|
|
20
15
|
return Object.assign(createComponent, data, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
data,
|
|
17
|
+
type: data.type,
|
|
18
|
+
typeId,
|
|
19
|
+
*getNodes(graph, nodeCursor = NodeCursor.Get()) {
|
|
20
|
+
const array = graph._components[typeId];
|
|
21
|
+
if (!array)
|
|
22
|
+
return false;
|
|
23
|
+
for (let i = 0; i < array._disposed.length; i++) {
|
|
24
|
+
nodeCursor.setNode(graph, array._node[i]);
|
|
25
|
+
yield nodeCursor;
|
|
26
|
+
}
|
|
27
|
+
NodeCursor.Retrun(nodeCursor);
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
*getComponents(graph, cursor = ComponentCursor.Get(), nodeCursor = NodeCursor.Get()) {
|
|
31
|
+
const array = graph._components[typeId];
|
|
32
|
+
if (!array)
|
|
33
|
+
return false;
|
|
34
|
+
for (let i = 0; i < array._disposed.length; i++) {
|
|
35
|
+
nodeCursor.setNode(graph, array._node[i]);
|
|
36
|
+
cursor.setInstance(nodeCursor, typeId, i);
|
|
37
|
+
yield cursor;
|
|
38
|
+
}
|
|
39
|
+
ComponentCursor.Retrun(cursor);
|
|
40
|
+
NodeCursor.Retrun(nodeCursor);
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
set(node, schema, schemaView, cursor = ComponentCursor.Get()) {
|
|
44
|
+
const newComponent = node.components.add(createComponent(schema, schemaView));
|
|
45
|
+
cursor.setInstance(node, typeId, newComponent);
|
|
46
|
+
node.graph._components[typeId].init(newComponent);
|
|
47
|
+
return cursor;
|
|
48
|
+
},
|
|
49
|
+
has(node) {
|
|
50
|
+
return node.components.has(data.type);
|
|
51
|
+
},
|
|
52
|
+
get(node, cursor, nodeCursor) {
|
|
53
|
+
return node.components.get(data.type, cursor, nodeCursor);
|
|
54
|
+
},
|
|
55
|
+
getRequired(node, cursor, nodeCursor) {
|
|
56
|
+
const found = node.components.get(data.type, cursor, nodeCursor);
|
|
57
|
+
if (!found)
|
|
58
|
+
throw new Error(`Node [${node.name}] does not have required component [${data.type}].`);
|
|
59
|
+
return found;
|
|
60
|
+
},
|
|
61
|
+
getChild(node, cursor, nodeCursor) {
|
|
62
|
+
return node.components.getChild(data.type, cursor, nodeCursor);
|
|
63
|
+
},
|
|
64
|
+
getRequiredChild(node, cursor, nodeCursor) {
|
|
65
|
+
const comp = node.components.getChild(data.type, cursor, nodeCursor);
|
|
66
|
+
if (!comp)
|
|
67
|
+
throw new Error(`Node [${node.name}] does not have a child with required component [${data.type}].`);
|
|
68
|
+
return comp;
|
|
69
|
+
},
|
|
70
|
+
getParent(node, cursor, nodeCursor) {
|
|
71
|
+
return node.components.getParent(data.type, cursor, nodeCursor);
|
|
72
|
+
},
|
|
73
|
+
getRequiredParent(node, cursor, nodeCursor) {
|
|
74
|
+
const comp = node.components.getParent(data.type, cursor, nodeCursor);
|
|
75
|
+
if (!comp)
|
|
76
|
+
throw new Error(`Node [${node.name}] does not have a parent with required component [${data.type}].`);
|
|
77
|
+
return comp;
|
|
78
|
+
},
|
|
79
|
+
getAll(node) {
|
|
80
|
+
return node.components.getAll(data.type);
|
|
81
|
+
},
|
|
82
|
+
removeAll(node) {
|
|
83
|
+
return node.components.removeAll(data.type);
|
|
84
|
+
},
|
|
85
|
+
remove(node) {
|
|
86
|
+
return node.components.remove(data.type);
|
|
87
|
+
},
|
|
35
88
|
nodeData: {
|
|
36
89
|
get: (node) => node.components?.find((_) => _.type == data.type) || null,
|
|
37
90
|
getAll: (node) => node.components?.filter((_) => _.type == data.type),
|
|
@@ -41,13 +94,12 @@ export const registerComponent = (data) => {
|
|
|
41
94
|
node.components = node.components?.filter((_) => _.type != data.type);
|
|
42
95
|
return all?.length ? all : null;
|
|
43
96
|
},
|
|
44
|
-
set: (node, schema
|
|
97
|
+
set: (node, schema) => {
|
|
45
98
|
node.components ??= [];
|
|
46
|
-
node.components.push(
|
|
47
|
-
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
: {}, state, ...traits));
|
|
99
|
+
node.components.push({
|
|
100
|
+
type: data.type,
|
|
101
|
+
schema: {},
|
|
102
|
+
});
|
|
51
103
|
},
|
|
52
104
|
},
|
|
53
105
|
});
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ObjectSchemaInstance } from "@amodx/schemas";
|
|
5
|
-
import { ContextPrototype } from "../Contexts/ContextPrototype";
|
|
1
|
+
import { ContextRegisterData, CreateContextData } from "../Contexts/Context.types";
|
|
2
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
3
|
+
import { ContextCursor } from "../Contexts/ContextCursor";
|
|
6
4
|
type RegisteredContext<ContextSchema extends {} = {}, Data extends object = {}> = (ContextRegisterData<ContextSchema, Data> & {
|
|
7
|
-
set: (parent:
|
|
8
|
-
get: (parent:
|
|
9
|
-
getRequired: (parent:
|
|
10
|
-
remove: (parent:
|
|
11
|
-
|
|
12
|
-
default:
|
|
13
|
-
|
|
14
|
-
}) & (() => ContextData);
|
|
5
|
+
set: (parent: NodeCursor, schema?: ContextSchema | null, schemaView?: string | null, data?: Data | null) => ContextCursor<ContextSchema, Data>;
|
|
6
|
+
get: (parent: NodeCursor) => ContextCursor<ContextSchema, Data> | null;
|
|
7
|
+
getRequired: (parent: NodeCursor) => ContextCursor<ContextSchema, Data>;
|
|
8
|
+
remove: (parent: NodeCursor) => ContextCursor<ContextSchema, Data> | null;
|
|
9
|
+
data: ContextRegisterData<ContextSchema, Data>;
|
|
10
|
+
default: ContextCursor<ContextSchema, Data>;
|
|
11
|
+
}) & ((schema?: ContextSchema, schemaViewId?: string, data?: Data) => CreateContextData);
|
|
15
12
|
export declare function registerContext<ContextSchema extends {} = {}, Data extends object = {}>(data: ContextRegisterData<ContextSchema, Data>): RegisteredContext<ContextSchema, Data>;
|
|
16
13
|
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { NCS } from "../NCS";
|
|
2
1
|
import { NCSRegister } from "./NCSRegister";
|
|
3
|
-
import {
|
|
2
|
+
import { ContextCursor } from "../Contexts/ContextCursor";
|
|
3
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
4
4
|
export function registerContext(data) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
});
|
|
5
|
+
NCSRegister.contexts.register(data.type, data);
|
|
6
|
+
const createContext = (schema, schemaViewId, contextData) => {
|
|
7
|
+
const createData = NCSPools.createContextData.get() || [];
|
|
8
|
+
createData[0] = data.type;
|
|
9
|
+
createData[1] = schema || {};
|
|
10
|
+
createData[2] = schemaViewId || "default";
|
|
11
|
+
createData[3] = contextData || null;
|
|
12
|
+
return createData;
|
|
15
13
|
};
|
|
16
14
|
return Object.assign(createContext, data, {
|
|
17
|
-
|
|
18
|
-
set: (parent, schema, data) => {
|
|
19
|
-
const newContext = parent.context.add(createContext(schema));
|
|
15
|
+
data,
|
|
16
|
+
set: (parent, schema, schemaViewId, data, cursor = ContextCursor.Get()) => {
|
|
17
|
+
const newContext = parent.context.add(createContext(schema, schemaViewId, data));
|
|
20
18
|
if (data) {
|
|
21
|
-
newContext
|
|
19
|
+
parent.graph._contexts._data[newContext] = data;
|
|
22
20
|
}
|
|
21
|
+
cursor.setContext(parent, newContext);
|
|
22
|
+
return cursor;
|
|
23
23
|
},
|
|
24
24
|
get: (parent) => {
|
|
25
25
|
return parent.context.get(data.type);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SystemPrototype } from "../Systems/SystemPrototype";
|
|
2
|
-
import { SystemRegisterData } from "../Systems/
|
|
2
|
+
import { SystemRegisterData } from "../Systems/System.types";
|
|
3
3
|
import { Graph } from "../Graphs/Graph";
|
|
4
4
|
import { SystemInstance } from "../Systems/SystemInstance";
|
|
5
5
|
type RegisteredSystem = SystemRegisterData & {
|
|
@@ -2,7 +2,7 @@ import { NCSRegister } from "./NCSRegister";
|
|
|
2
2
|
import { SystemPrototype } from "../Systems/SystemPrototype";
|
|
3
3
|
export function registerSystem(data) {
|
|
4
4
|
const prototype = new SystemPrototype(data);
|
|
5
|
-
NCSRegister.systems.register(data.type,
|
|
5
|
+
NCSRegister.systems.register(data.type, prototype);
|
|
6
6
|
return Object.assign(data, {
|
|
7
7
|
prototype,
|
|
8
8
|
set: (graph) => prototype.add(graph),
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { TagRegisterData } from "../Tags/Tag.types";
|
|
2
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
3
|
+
import { TagCursor } from "../Tags/TagCursor";
|
|
4
4
|
import { Tag } from "../Tags/Tag";
|
|
5
|
-
import { TagPrototype } from "../Tags/TagPrototype";
|
|
6
5
|
import { Graph } from "../Graphs/Graph";
|
|
7
|
-
type RegisteredTag = (TagRegisterData & {
|
|
6
|
+
export type RegisteredTag = (TagRegisterData & {
|
|
8
7
|
tag: Tag;
|
|
9
|
-
|
|
10
|
-
set
|
|
11
|
-
get
|
|
12
|
-
getChild
|
|
13
|
-
getAllChildlren
|
|
14
|
-
getParent
|
|
15
|
-
getAllParents
|
|
16
|
-
remove
|
|
17
|
-
getNodes
|
|
18
|
-
getTags
|
|
19
|
-
}) & (() =>
|
|
8
|
+
data: TagRegisterData;
|
|
9
|
+
set(parent: NodeCursor, cursor?: TagCursor): TagCursor;
|
|
10
|
+
get(parent: NodeCursor, cursor?: TagCursor): TagCursor | null;
|
|
11
|
+
getChild(parent: NodeCursor, cursor?: TagCursor): TagCursor | null;
|
|
12
|
+
getAllChildlren(parent: NodeCursor): TagCursor[] | null;
|
|
13
|
+
getParent(parent: NodeCursor, cursor?: TagCursor): TagCursor | null;
|
|
14
|
+
getAllParents(parent: NodeCursor): TagCursor[] | null;
|
|
15
|
+
remove(parent: NodeCursor): boolean;
|
|
16
|
+
getNodes(grpah: Graph): Generator<NodeCursor>;
|
|
17
|
+
getTags(grpah: Graph): Generator<TagCursor>;
|
|
18
|
+
}) & (() => number);
|
|
20
19
|
export declare function registerTag(data: TagRegisterData): RegisteredTag;
|
|
21
|
-
export {};
|
package/Register/registerTag.js
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
import { NCS } from "../NCS";
|
|
2
1
|
import { NCSRegister } from "./NCSRegister";
|
|
2
|
+
import { TagCursor } from "../Tags/TagCursor";
|
|
3
3
|
import { Tag } from "../Tags/Tag";
|
|
4
|
-
import { TagPrototype } from "../Tags/TagPrototype";
|
|
5
|
-
import { TagInstanceMap } from "../Tags/TagInstanceMap";
|
|
6
4
|
export function registerTag(data) {
|
|
7
5
|
const tag = new Tag(null, data);
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const map = TagInstanceMap.getMap(tag.id);
|
|
6
|
+
const typeId = NCSRegister.tags.register(data.id, tag);
|
|
7
|
+
// const map = TagInstanceMap.registerTag(tag.id);
|
|
11
8
|
const createTag = () => {
|
|
12
|
-
return
|
|
13
|
-
id: data.id,
|
|
14
|
-
});
|
|
9
|
+
return typeId;
|
|
15
10
|
};
|
|
16
11
|
return Object.assign(createTag, data, {
|
|
17
12
|
tag,
|
|
18
|
-
|
|
19
|
-
getNodes: (graph) => map.getNodes(graph),
|
|
20
|
-
getTags: (graph) => map.getItems(graph),
|
|
21
|
-
getChild
|
|
22
|
-
return parent.tags.getChild(data.id);
|
|
13
|
+
data,
|
|
14
|
+
// getNodes: (graph: Graph) => map.getNodes(graph),
|
|
15
|
+
// getTags: (graph: Graph) => map.getItems(graph),
|
|
16
|
+
getChild(parent, cursor) {
|
|
17
|
+
return parent.tags.getChild(data.id, cursor);
|
|
23
18
|
},
|
|
24
|
-
getAllChildlren
|
|
19
|
+
getAllChildlren(parent) {
|
|
25
20
|
return parent.tags.getAllChildlren(data.id);
|
|
26
21
|
},
|
|
27
|
-
getParent
|
|
28
|
-
return parent.tags.getParent(data.id);
|
|
22
|
+
getParent(parent, cursor) {
|
|
23
|
+
return parent.tags.getParent(data.id, cursor);
|
|
29
24
|
},
|
|
30
|
-
getAllParents
|
|
25
|
+
getAllParents(parent) {
|
|
31
26
|
return parent.tags.getAllParents(data.id);
|
|
32
27
|
},
|
|
33
|
-
set
|
|
34
|
-
|
|
28
|
+
set(parent, cursor = TagCursor.Get()) {
|
|
29
|
+
const newTag = parent.tags.add(createTag());
|
|
30
|
+
cursor.setTag(parent, typeId, newTag);
|
|
31
|
+
return cursor;
|
|
35
32
|
},
|
|
36
|
-
get
|
|
37
|
-
return parent.tags.get(data.id);
|
|
33
|
+
get(parent, cursor) {
|
|
34
|
+
return parent.tags.get(data.id, cursor);
|
|
38
35
|
},
|
|
39
|
-
remove
|
|
36
|
+
remove(parent) {
|
|
40
37
|
return parent.tags.remove(data.id);
|
|
41
38
|
},
|
|
42
39
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SchemaArrayCursor } from "../SchemaArrayCursor";
|
|
2
|
+
import { SchemaView } from "../SchemaView";
|
|
3
|
+
import { SchemaArray } from "../SchemaArray";
|
|
4
|
+
export declare function createBaseSchemaCursor(): {
|
|
5
|
+
new (__view: SchemaView<any>): {
|
|
6
|
+
__cursor: SchemaArrayCursor;
|
|
7
|
+
__cursors: never[];
|
|
8
|
+
__view: SchemaView<any>;
|
|
9
|
+
__array: SchemaArray;
|
|
10
|
+
__index: number;
|
|
11
|
+
setInstance(index: number): void;
|
|
12
|
+
getInstance(): number;
|
|
13
|
+
getCursor(): SchemaArrayCursor;
|
|
14
|
+
getSchemaIndex(): import("../Schema.types").SchemaCursorIndex<any>;
|
|
15
|
+
clone(): any;
|
|
16
|
+
toJSON(): any;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SchemaArrayCursor } from "../SchemaArrayCursor";
|
|
2
|
+
export function createBaseSchemaCursor() {
|
|
3
|
+
class SchemaCursor {
|
|
4
|
+
__view;
|
|
5
|
+
__cursor;
|
|
6
|
+
__cursors = [];
|
|
7
|
+
constructor(__view) {
|
|
8
|
+
this.__view = __view;
|
|
9
|
+
this.__cursor = new SchemaArrayCursor(this.__view.schema.array);
|
|
10
|
+
}
|
|
11
|
+
__array;
|
|
12
|
+
__index;
|
|
13
|
+
setInstance(index) {
|
|
14
|
+
this.__cursor.setIndex(index);
|
|
15
|
+
}
|
|
16
|
+
getInstance() {
|
|
17
|
+
return this.__cursor._index;
|
|
18
|
+
}
|
|
19
|
+
getCursor() {
|
|
20
|
+
return this.__cursor;
|
|
21
|
+
}
|
|
22
|
+
getSchemaIndex() {
|
|
23
|
+
return this.__view.schema.index;
|
|
24
|
+
}
|
|
25
|
+
clone() {
|
|
26
|
+
const newCursor = new SchemaCursor(this.__view);
|
|
27
|
+
return newCursor;
|
|
28
|
+
}
|
|
29
|
+
toJSON() {
|
|
30
|
+
return this.__view.toJSON(this);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return SchemaCursor;
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BinaryObjectSchemaView } from "../Schema.types";
|
|
2
|
+
import { Schema } from "../Schema";
|
|
3
|
+
import { PropertyMetaData } from "../Property/Property.types";
|
|
4
|
+
import { SchemaView } from "../SchemaView";
|
|
5
|
+
import { SchemaArrayCursor } from "../SchemaArrayCursor";
|
|
6
|
+
export declare function setBinaryObjectData(current: BinaryObjectSchemaView, meta: PropertyMetaData, index: number, value: number): void;
|
|
7
|
+
export declare function getBinaryObjectData(current: BinaryObjectSchemaView, meta: PropertyMetaData, index: number): any;
|
|
8
|
+
export declare function createSchemaBinaryObjectCursorClass(schema: Schema): {
|
|
9
|
+
new (__view: SchemaView<any>): {
|
|
10
|
+
__cursor: SchemaArrayCursor;
|
|
11
|
+
__cursors: never[];
|
|
12
|
+
__view: SchemaView<any>;
|
|
13
|
+
__array: import("../SchemaArray").SchemaArray;
|
|
14
|
+
__index: number;
|
|
15
|
+
setInstance(index: number): void;
|
|
16
|
+
getInstance(): number;
|
|
17
|
+
getCursor(): SchemaArrayCursor;
|
|
18
|
+
getSchemaIndex(): import("../Schema.types").SchemaCursorIndex<any>;
|
|
19
|
+
clone(): any;
|
|
20
|
+
toJSON(): any;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createBaseSchemaCursor } from "./createBaseSchemaCursor";
|
|
2
|
+
const valueSetMap = {
|
|
3
|
+
i8(dataView, index, value) {
|
|
4
|
+
dataView.setInt8(index, value);
|
|
5
|
+
},
|
|
6
|
+
ui8(dataView, index, value) {
|
|
7
|
+
dataView.setUint8(index, value);
|
|
8
|
+
},
|
|
9
|
+
i16(dataView, index, value) {
|
|
10
|
+
dataView.setInt16(index, value);
|
|
11
|
+
},
|
|
12
|
+
ui16(dataView, index, value) {
|
|
13
|
+
dataView.setUint16(index, value);
|
|
14
|
+
},
|
|
15
|
+
i32(dataView, index, value) {
|
|
16
|
+
dataView.setInt32(index, value);
|
|
17
|
+
},
|
|
18
|
+
ui32(dataView, index, value) {
|
|
19
|
+
dataView.setUint32(index, value);
|
|
20
|
+
},
|
|
21
|
+
f32(dataView, index, value) {
|
|
22
|
+
dataView.setFloat32(index, value);
|
|
23
|
+
},
|
|
24
|
+
f64(dataView, index, value) {
|
|
25
|
+
dataView.setFloat64(index, value);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const valueGetMap = {
|
|
29
|
+
i8(dataView, index) {
|
|
30
|
+
return dataView.getInt8(index);
|
|
31
|
+
},
|
|
32
|
+
ui8(dataView, index) {
|
|
33
|
+
return dataView.getUint8(index);
|
|
34
|
+
},
|
|
35
|
+
i16(dataView, index) {
|
|
36
|
+
return dataView.getInt16(index);
|
|
37
|
+
},
|
|
38
|
+
ui16(dataView, index) {
|
|
39
|
+
return dataView.getUint16(index);
|
|
40
|
+
},
|
|
41
|
+
i32(dataView, index) {
|
|
42
|
+
return dataView.getInt32(index);
|
|
43
|
+
},
|
|
44
|
+
ui32(dataView, index) {
|
|
45
|
+
return dataView.getUint32(index);
|
|
46
|
+
},
|
|
47
|
+
f32(dataView, index) {
|
|
48
|
+
return dataView.getFloat32(index);
|
|
49
|
+
},
|
|
50
|
+
f64(dataView, index) {
|
|
51
|
+
return dataView.getFloat64(index);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export function setBinaryObjectData(current, meta, index, value) {
|
|
55
|
+
if (!meta.binary)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (typeof meta.binary == "object")
|
|
58
|
+
return meta.binary.set(current.view, meta, index, value);
|
|
59
|
+
return valueSetMap[meta.binary](current.view, index, value);
|
|
60
|
+
}
|
|
61
|
+
export function getBinaryObjectData(current, meta, index) {
|
|
62
|
+
if (!meta.binary)
|
|
63
|
+
return undefined;
|
|
64
|
+
if (typeof meta.binary == "object")
|
|
65
|
+
return meta.binary.get(current.view, meta, index);
|
|
66
|
+
return valueGetMap[meta.binary](current.view, index);
|
|
67
|
+
}
|
|
68
|
+
function traverse(parent, properties) {
|
|
69
|
+
for (let i = 0; i < properties.length; i++) {
|
|
70
|
+
const property = properties[i];
|
|
71
|
+
const index = property.index;
|
|
72
|
+
if (!property.children) {
|
|
73
|
+
Object.defineProperty(parent.prototype, property.id, {
|
|
74
|
+
get() {
|
|
75
|
+
if (this.__cursor.hasProxy(index)) {
|
|
76
|
+
return this.__cursor.fetchProxyData(index);
|
|
77
|
+
}
|
|
78
|
+
return getBinaryObjectData(this.__cursor.data, this.__view.meta[index], this.__view.byteOffset[index]);
|
|
79
|
+
},
|
|
80
|
+
set(value) {
|
|
81
|
+
let obs = this.__cursor.getObserver(index);
|
|
82
|
+
let proxy = this.__cursor.hasProxy(index);
|
|
83
|
+
if (obs) {
|
|
84
|
+
const oldVale = proxy
|
|
85
|
+
? this.__cursor.fetchProxyData(index)
|
|
86
|
+
: getBinaryObjectData(this.__cursor.data, this.__view.meta[index], this.__view.byteOffset[index]);
|
|
87
|
+
if (oldVale != value) {
|
|
88
|
+
setBinaryObjectData(this.__cursor.data, this.__view.meta[index], this.__view.byteOffset[index], value);
|
|
89
|
+
if (proxy) {
|
|
90
|
+
this.__cursor.setProxyData(index, value);
|
|
91
|
+
}
|
|
92
|
+
obs.notify(value);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
setBinaryObjectData(this.__cursor.data, this.__view.meta[index], this.__view.byteOffset[index], value);
|
|
97
|
+
if (proxy) {
|
|
98
|
+
this.__cursor.setProxyData(index, value);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
class SchemaCursorProperty {
|
|
105
|
+
__cursor;
|
|
106
|
+
__cursors;
|
|
107
|
+
__view;
|
|
108
|
+
constructor(__cursor, __cursors, __view) {
|
|
109
|
+
this.__cursor = __cursor;
|
|
110
|
+
this.__cursors = __cursors;
|
|
111
|
+
this.__view = __view;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
traverse(SchemaCursorProperty, property.children);
|
|
115
|
+
Object.defineProperty(parent.prototype, property.id, {
|
|
116
|
+
get() {
|
|
117
|
+
let v = this.__cursors[index];
|
|
118
|
+
if (!v) {
|
|
119
|
+
v = new SchemaCursorProperty(this.__cursor, this.__cursors, this.__view);
|
|
120
|
+
this.__cursors[index] = v;
|
|
121
|
+
}
|
|
122
|
+
return v;
|
|
123
|
+
},
|
|
124
|
+
set(value) {
|
|
125
|
+
// (this as SchemaClassBase).__data.current[index] = value;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function createSchemaBinaryObjectCursorClass(schema) {
|
|
131
|
+
const SchemaCursor = createBaseSchemaCursor();
|
|
132
|
+
traverse(SchemaCursor, schema.root.children);
|
|
133
|
+
return SchemaCursor;
|
|
134
|
+
}
|