@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
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
2
|
+
export class SchemaArray {
|
|
3
|
+
schema;
|
|
4
|
+
_data = [];
|
|
5
|
+
_dataViews = [];
|
|
6
|
+
_observers = [];
|
|
7
|
+
_proxyObjects = [];
|
|
8
|
+
_proxyKeys = [];
|
|
9
|
+
constructor(schema) {
|
|
10
|
+
this.schema = schema;
|
|
11
|
+
for (let i = 0; i < schema._data.length; i++) {
|
|
12
|
+
this._observers[i] = [];
|
|
13
|
+
this._proxyObjects[i] = [];
|
|
14
|
+
this._proxyKeys[i] = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
createViewCursor(index) {
|
|
18
|
+
const data = this._data[index];
|
|
19
|
+
if (data === undefined)
|
|
20
|
+
return null;
|
|
21
|
+
const viewId = this._dataViews[index];
|
|
22
|
+
const view = this.schema.views[viewId];
|
|
23
|
+
if (!view)
|
|
24
|
+
return null;
|
|
25
|
+
return view.createCursor();
|
|
26
|
+
}
|
|
27
|
+
setData(index, data, view) {
|
|
28
|
+
this._data[index] = data;
|
|
29
|
+
this._dataViews[index] = this.schema.viewIdPalettew.getNumberId(view || "default");
|
|
30
|
+
}
|
|
31
|
+
getViewAt(index) {
|
|
32
|
+
if (this._data[index] === undefined)
|
|
33
|
+
return null;
|
|
34
|
+
return this.schema.getView(this.schema.viewIdPalettew.getStringId(this._dataViews[index]));
|
|
35
|
+
}
|
|
36
|
+
removeData(index) {
|
|
37
|
+
if (this._data[index] === undefined)
|
|
38
|
+
return false;
|
|
39
|
+
const view = this.getViewAt(index);
|
|
40
|
+
view.returnData(this._data[index]);
|
|
41
|
+
this._data[index] = undefined;
|
|
42
|
+
this._dataViews[index] = -1;
|
|
43
|
+
for (let i = 0; i < this.schema._data.length; i++) {
|
|
44
|
+
if (this._observers[i][index]) {
|
|
45
|
+
this._observers[i][index].clear();
|
|
46
|
+
NCSPools.observers.addItem(this._observers[i][index]);
|
|
47
|
+
this._observers[i][index] = undefined;
|
|
48
|
+
}
|
|
49
|
+
this._proxyObjects[i][index] = undefined;
|
|
50
|
+
this._proxyKeys[i][index] = undefined;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
getObserver(propertyIndex, arrayIndex) {
|
|
55
|
+
if (!this._observers[propertyIndex][arrayIndex])
|
|
56
|
+
return null;
|
|
57
|
+
let observer = this._observers[propertyIndex][arrayIndex];
|
|
58
|
+
if (!observer)
|
|
59
|
+
return null;
|
|
60
|
+
return observer;
|
|
61
|
+
}
|
|
62
|
+
setObserver(propertyIndex, arrayIndex, value) {
|
|
63
|
+
if (!value) {
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
this._observers[propertyIndex][arrayIndex] = undefined;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this._observers[propertyIndex][arrayIndex] = value;
|
|
69
|
+
}
|
|
70
|
+
hasProxy(propertyIndex, arrayIndex) {
|
|
71
|
+
return this._proxyObjects[propertyIndex][arrayIndex] !== undefined;
|
|
72
|
+
}
|
|
73
|
+
fetchProxyData(propertyIndex, arrayIndex) {
|
|
74
|
+
return this._proxyObjects[propertyIndex][arrayIndex][this._proxyKeys[propertyIndex][arrayIndex]];
|
|
75
|
+
}
|
|
76
|
+
setProxyData(propertyIndex, arrayIndex, value) {
|
|
77
|
+
this._proxyObjects[propertyIndex][arrayIndex][this._proxyKeys[propertyIndex][arrayIndex]] = value;
|
|
78
|
+
}
|
|
79
|
+
removeProxy(propertyIndex, arrayIndex) {
|
|
80
|
+
this._proxyObjects[propertyIndex][arrayIndex] = undefined;
|
|
81
|
+
this._proxyKeys[propertyIndex][arrayIndex] = undefined;
|
|
82
|
+
}
|
|
83
|
+
setProxy(propertyIndex, arrayIndex, object, key) {
|
|
84
|
+
this._proxyObjects[propertyIndex][arrayIndex] = object;
|
|
85
|
+
this._proxyKeys[propertyIndex][arrayIndex] = key;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Observable } from "../Util/Observable";
|
|
2
|
+
import { SchemaArray } from "./SchemaArray";
|
|
3
|
+
export declare class SchemaArrayCursor {
|
|
4
|
+
schemaArray: SchemaArray;
|
|
5
|
+
constructor(schemaArray: SchemaArray);
|
|
6
|
+
get data(): any;
|
|
7
|
+
set data(value: any);
|
|
8
|
+
_index: number;
|
|
9
|
+
setIndex(index: number): void;
|
|
10
|
+
getObserver(propertyIndex: number): Observable<any> | null;
|
|
11
|
+
getOrCreateObserver(propertyIndex: number): Observable<any>;
|
|
12
|
+
removeObserver(propertyIndex: number): boolean;
|
|
13
|
+
setObserver(propertyIndex: number, value: Observable | null): void;
|
|
14
|
+
hasProxy(propertyIndex: number): boolean;
|
|
15
|
+
fetchProxyData(propertyIndex: number): any;
|
|
16
|
+
setProxyData(propertyIndex: number, value: any): void;
|
|
17
|
+
removeProxy(propertyIndex: number): void;
|
|
18
|
+
setProxy<T extends Record<string | number, any> = {}>(propertyIndex: number, object: T, key: keyof T): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
2
|
+
import { Observable } from "../Util/Observable";
|
|
3
|
+
export class SchemaArrayCursor {
|
|
4
|
+
schemaArray;
|
|
5
|
+
constructor(schemaArray) {
|
|
6
|
+
this.schemaArray = schemaArray;
|
|
7
|
+
}
|
|
8
|
+
get data() {
|
|
9
|
+
return this.schemaArray._data[this._index];
|
|
10
|
+
}
|
|
11
|
+
set data(value) {
|
|
12
|
+
this.schemaArray._data[this._index] = value;
|
|
13
|
+
}
|
|
14
|
+
_index = 0;
|
|
15
|
+
setIndex(index) {
|
|
16
|
+
this._index = index;
|
|
17
|
+
}
|
|
18
|
+
getObserver(propertyIndex) {
|
|
19
|
+
return this.schemaArray.getObserver(propertyIndex, this._index);
|
|
20
|
+
}
|
|
21
|
+
getOrCreateObserver(propertyIndex) {
|
|
22
|
+
let observer = this.schemaArray.getObserver(propertyIndex, this._index);
|
|
23
|
+
if (!observer) {
|
|
24
|
+
observer = NCSPools.observers.get() || new Observable();
|
|
25
|
+
this.schemaArray.setObserver(propertyIndex, this._index, observer);
|
|
26
|
+
}
|
|
27
|
+
return observer;
|
|
28
|
+
}
|
|
29
|
+
removeObserver(propertyIndex) {
|
|
30
|
+
let observer = this.schemaArray.getObserver(propertyIndex, this._index);
|
|
31
|
+
if (!observer)
|
|
32
|
+
return false;
|
|
33
|
+
observer.clear();
|
|
34
|
+
NCSPools.observers.addItem(observer);
|
|
35
|
+
this.schemaArray.setObserver(propertyIndex, this._index, null);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
setObserver(propertyIndex, value) {
|
|
39
|
+
return this.schemaArray.setObserver(propertyIndex, this._index, value);
|
|
40
|
+
}
|
|
41
|
+
hasProxy(propertyIndex) {
|
|
42
|
+
return this.schemaArray.hasProxy(propertyIndex, this._index);
|
|
43
|
+
}
|
|
44
|
+
fetchProxyData(propertyIndex) {
|
|
45
|
+
return this.schemaArray.fetchProxyData(propertyIndex, this._index);
|
|
46
|
+
}
|
|
47
|
+
setProxyData(propertyIndex, value) {
|
|
48
|
+
return this.schemaArray.setProxyData(propertyIndex, this._index, value);
|
|
49
|
+
}
|
|
50
|
+
removeProxy(propertyIndex) {
|
|
51
|
+
return this.schemaArray.removeProxy(propertyIndex, this._index);
|
|
52
|
+
}
|
|
53
|
+
setProxy(propertyIndex, object, key) {
|
|
54
|
+
return this.schemaArray.setProxy(propertyIndex, this._index, object, key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ItemPool } from "../Util/ItemPool";
|
|
2
|
+
import { RecursivePartial } from "../Util/Util.types";
|
|
3
|
+
import { PropertyMetaData } from "./Property/Property.types";
|
|
4
|
+
import { Schema } from "./Schema";
|
|
5
|
+
import { SchemaCreateData, SchemaCursor } from "./Schema.types";
|
|
6
|
+
export declare class SchemaView<Shape extends {} = any> {
|
|
7
|
+
schema: Schema<Shape>;
|
|
8
|
+
id: string;
|
|
9
|
+
meta: PropertyMetaData[];
|
|
10
|
+
byteOffset: number[];
|
|
11
|
+
byteSize: number;
|
|
12
|
+
_createData: SchemaCreateData;
|
|
13
|
+
private _cursorClass;
|
|
14
|
+
_dataPool: ItemPool<unknown>;
|
|
15
|
+
constructor(schema: Schema<Shape>, id: string, meta: PropertyMetaData[], byteOffset: number[], byteSize: number, _createData: SchemaCreateData, _cursorClass: any);
|
|
16
|
+
returnData(returnData: any): void;
|
|
17
|
+
createData(overrides?: RecursivePartial<Shape> | null): any;
|
|
18
|
+
createCursor(): SchemaCursor<Shape>;
|
|
19
|
+
/** Converts data for use of remote components */
|
|
20
|
+
toRemote(cursor: SchemaCursor<Shape>): any;
|
|
21
|
+
/** Converts data for remote data to local data*/
|
|
22
|
+
fromRemote(remoteData: any): any;
|
|
23
|
+
toJSON(cursor: SchemaCursor<Shape>): any;
|
|
24
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ItemPool } from "../Util/ItemPool";
|
|
2
|
+
import { setBinaryObjectData } from "./Functions/createSchemaBinaryObjectCursorClass";
|
|
3
|
+
import { TypedArrayMap } from "./Property/Property.types";
|
|
4
|
+
function traverseCreateJSON(parent, target, source) {
|
|
5
|
+
for (const child of parent.children) {
|
|
6
|
+
if (child.children) {
|
|
7
|
+
target[child.id] ??= {};
|
|
8
|
+
traverseCreateJSON(child, target[child.id], source[child.id]);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
target[child.id] = source[child.id];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
}
|
|
16
|
+
const tempData = [];
|
|
17
|
+
export class SchemaView {
|
|
18
|
+
schema;
|
|
19
|
+
id;
|
|
20
|
+
meta;
|
|
21
|
+
byteOffset;
|
|
22
|
+
byteSize;
|
|
23
|
+
_createData;
|
|
24
|
+
_cursorClass;
|
|
25
|
+
_dataPool = new ItemPool();
|
|
26
|
+
constructor(schema, id, meta, byteOffset, byteSize, _createData, _cursorClass) {
|
|
27
|
+
this.schema = schema;
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.meta = meta;
|
|
30
|
+
this.byteOffset = byteOffset;
|
|
31
|
+
this.byteSize = byteSize;
|
|
32
|
+
this._createData = _createData;
|
|
33
|
+
this._cursorClass = _cursorClass;
|
|
34
|
+
}
|
|
35
|
+
returnData(returnData) {
|
|
36
|
+
this._dataPool.addItem(returnData);
|
|
37
|
+
}
|
|
38
|
+
createData(overrides) {
|
|
39
|
+
const data = this._createData;
|
|
40
|
+
overrides && (tempData.length = 0);
|
|
41
|
+
let baseData = !overrides
|
|
42
|
+
? this.schema._data
|
|
43
|
+
: this.schema.createData(tempData, overrides);
|
|
44
|
+
if (this._dataPool.items.length) {
|
|
45
|
+
const newData = this._dataPool.get();
|
|
46
|
+
if (data.type == "object") {
|
|
47
|
+
for (let i = 0; i < baseData.length; i++) {
|
|
48
|
+
newData[i] =
|
|
49
|
+
typeof baseData[i] == "object"
|
|
50
|
+
? structuredClone(baseData[i])
|
|
51
|
+
: baseData[i];
|
|
52
|
+
}
|
|
53
|
+
return newData;
|
|
54
|
+
}
|
|
55
|
+
if (data.type == "typed-array") {
|
|
56
|
+
newData.set(baseData);
|
|
57
|
+
return newData;
|
|
58
|
+
}
|
|
59
|
+
if (data.type == "binary-object") {
|
|
60
|
+
for (let i = 0; i < baseData.length; i++) {
|
|
61
|
+
const meta = this.meta[i];
|
|
62
|
+
if (!meta.binary)
|
|
63
|
+
continue;
|
|
64
|
+
setBinaryObjectData(newData, meta, this.byteOffset[i], baseData[i]);
|
|
65
|
+
}
|
|
66
|
+
return newData;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (data.type == "object") {
|
|
70
|
+
const newData = new Array(baseData.length);
|
|
71
|
+
for (let i = 0; i < baseData.length; i++) {
|
|
72
|
+
newData[i] =
|
|
73
|
+
typeof baseData[i] == "object"
|
|
74
|
+
? structuredClone(baseData[i])
|
|
75
|
+
: baseData[i];
|
|
76
|
+
}
|
|
77
|
+
return newData;
|
|
78
|
+
}
|
|
79
|
+
if (data.type == "typed-array") {
|
|
80
|
+
const size = baseData.length;
|
|
81
|
+
const typedArrayClass = TypedArrayMap[data.arrayType];
|
|
82
|
+
let byteSize = size * typedArrayClass.BYTES_PER_ELEMENT;
|
|
83
|
+
const typedArray = new typedArrayClass(data.sharedMemory
|
|
84
|
+
? new SharedArrayBuffer(byteSize)
|
|
85
|
+
: new ArrayBuffer(byteSize));
|
|
86
|
+
typedArray.set(baseData);
|
|
87
|
+
return typedArray;
|
|
88
|
+
}
|
|
89
|
+
if (data.type == "binary-object") {
|
|
90
|
+
let byteSize = this.byteSize;
|
|
91
|
+
const buffer = data.sharedMemory
|
|
92
|
+
? new SharedArrayBuffer(byteSize)
|
|
93
|
+
: new ArrayBuffer(byteSize);
|
|
94
|
+
const current = {
|
|
95
|
+
view: new DataView(buffer),
|
|
96
|
+
buffer: new Uint8Array(buffer),
|
|
97
|
+
};
|
|
98
|
+
for (let i = 0; i < baseData.length; i++) {
|
|
99
|
+
const meta = this.meta[i];
|
|
100
|
+
if (!meta.binary)
|
|
101
|
+
continue;
|
|
102
|
+
setBinaryObjectData(current, meta, this.byteOffset[i], baseData[i]);
|
|
103
|
+
}
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Invalid create data`);
|
|
107
|
+
}
|
|
108
|
+
createCursor() {
|
|
109
|
+
return new this._cursorClass(this, this.meta, this._createData, this.byteOffset);
|
|
110
|
+
}
|
|
111
|
+
/** Converts data for use of remote components */
|
|
112
|
+
toRemote(cursor) {
|
|
113
|
+
if (this._createData.type == "object") {
|
|
114
|
+
return cursor.__cursor.data;
|
|
115
|
+
}
|
|
116
|
+
if (this._createData.type == "typed-array") {
|
|
117
|
+
return cursor.__cursor.data;
|
|
118
|
+
}
|
|
119
|
+
if (this._createData.type == "binary-object") {
|
|
120
|
+
return cursor.__cursor.data.buffer;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Converts data for remote data to local data*/
|
|
124
|
+
fromRemote(remoteData) {
|
|
125
|
+
if (this._createData.type == "object") {
|
|
126
|
+
return remoteData;
|
|
127
|
+
}
|
|
128
|
+
if (this._createData.type == "typed-array") {
|
|
129
|
+
return remoteData;
|
|
130
|
+
}
|
|
131
|
+
if (this._createData.type == "binary-object") {
|
|
132
|
+
return {
|
|
133
|
+
view: new DataView(remoteData.buffer),
|
|
134
|
+
buffer: new Uint8Array(remoteData.buffer),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
toJSON(cursor) {
|
|
139
|
+
return traverseCreateJSON(this.schema.root, {}, cursor);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Graph } from "../Graphs/Graph";
|
|
2
|
-
import { SystemRegisterData } from "./
|
|
2
|
+
import { SystemRegisterData } from "./System.types";
|
|
3
3
|
import { QueryInstance } from "../Queries/QueryInstance";
|
|
4
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
5
|
export declare class SystemInstance {
|
|
5
6
|
graph: Graph;
|
|
6
|
-
|
|
7
|
+
proto: SystemRegisterData;
|
|
7
8
|
queries: QueryInstance[];
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
node: NodeCursor;
|
|
10
|
+
constructor(graph: Graph, proto: SystemRegisterData);
|
|
11
|
+
update(): void;
|
|
10
12
|
dispose(): void;
|
|
11
13
|
}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
2
2
|
export class SystemInstance {
|
|
3
3
|
graph;
|
|
4
|
-
|
|
4
|
+
proto;
|
|
5
5
|
queries = [];
|
|
6
|
-
|
|
6
|
+
node = NodeCursor.Get();
|
|
7
|
+
constructor(graph, proto) {
|
|
7
8
|
this.graph = graph;
|
|
8
|
-
this.
|
|
9
|
-
for (const query of
|
|
9
|
+
this.proto = proto;
|
|
10
|
+
for (const query of proto.queries) {
|
|
10
11
|
this.queries.push(query.add(graph));
|
|
11
12
|
}
|
|
13
|
+
this.graph._systems.push(this);
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
update() {
|
|
16
|
+
this.proto.update(this);
|
|
15
17
|
}
|
|
16
18
|
dispose() {
|
|
17
|
-
|
|
19
|
+
for (let i = 0; i < this.graph._systems.length; i++) {
|
|
20
|
+
if (this.graph._systems[i] == this) {
|
|
21
|
+
this.graph._systems.splice(i, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SystemInstance } from "./SystemInstance";
|
|
2
2
|
import { Graph } from "../Graphs/Graph";
|
|
3
|
-
import { SystemRegisterData } from "./
|
|
3
|
+
import { SystemRegisterData } from "./System.types";
|
|
4
4
|
export declare class SystemPrototype {
|
|
5
5
|
data: SystemRegisterData;
|
|
6
6
|
systems: Map<Graph, SystemInstance>;
|
package/Tags/Tag.d.ts
CHANGED
package/Tags/Tag.js
CHANGED
|
@@ -6,19 +6,6 @@ export interface TagMetaData {
|
|
|
6
6
|
description?: string;
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Type representing the data of a tag.
|
|
11
|
-
*/
|
|
12
|
-
export type TagData = {
|
|
13
|
-
/**
|
|
14
|
-
* The type of the tag.
|
|
15
|
-
*/
|
|
16
|
-
id: string;
|
|
17
|
-
/**
|
|
18
|
-
* The namespace of the tag.
|
|
19
|
-
*/
|
|
20
|
-
namespace?: string;
|
|
21
|
-
};
|
|
22
9
|
/**
|
|
23
10
|
* Type representing the data required to register a tag.
|
|
24
11
|
*/
|
|
@@ -27,10 +14,6 @@ export type TagRegisterData = {
|
|
|
27
14
|
* The type of the tag.
|
|
28
15
|
*/
|
|
29
16
|
id: string;
|
|
30
|
-
/**
|
|
31
|
-
* The namespace of the tag.
|
|
32
|
-
*/
|
|
33
|
-
namespace?: string;
|
|
34
17
|
/**
|
|
35
18
|
* The shared meta data of all tags.
|
|
36
19
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Observable } from "../Util/Observable";
|
|
2
|
+
declare class TagArrayObservers {
|
|
3
|
+
tagAdded: Observable<number>;
|
|
4
|
+
componentRemoved: Observable<number>;
|
|
5
|
+
nodeAdded: Observable<number>;
|
|
6
|
+
nodeRemoved: Observable<number>;
|
|
7
|
+
}
|
|
8
|
+
export declare class TagArray {
|
|
9
|
+
typeId: string;
|
|
10
|
+
_freeSlots: number[];
|
|
11
|
+
_node: number[];
|
|
12
|
+
observers: TagArrayObservers;
|
|
13
|
+
typeNumberId: number;
|
|
14
|
+
constructor(typeId: string);
|
|
15
|
+
addTag(node: number): number;
|
|
16
|
+
removeTag(index: number): true | null;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/Tags/TagArray.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Observable } from "../Util/Observable";
|
|
2
|
+
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
|
+
class TagArrayObservers {
|
|
4
|
+
tagAdded = new Observable();
|
|
5
|
+
componentRemoved = new Observable();
|
|
6
|
+
nodeAdded = new Observable();
|
|
7
|
+
nodeRemoved = new Observable();
|
|
8
|
+
}
|
|
9
|
+
export class TagArray {
|
|
10
|
+
typeId;
|
|
11
|
+
_freeSlots = [];
|
|
12
|
+
_node = [];
|
|
13
|
+
observers = new TagArrayObservers();
|
|
14
|
+
typeNumberId;
|
|
15
|
+
constructor(typeId) {
|
|
16
|
+
this.typeId = typeId;
|
|
17
|
+
this.typeNumberId = NCSRegister.tags.idPalette.getNumberId(typeId);
|
|
18
|
+
}
|
|
19
|
+
addTag(node) {
|
|
20
|
+
let slot = this._freeSlots.length
|
|
21
|
+
? this._freeSlots.shift()
|
|
22
|
+
: this._node.length;
|
|
23
|
+
this._node[slot] = node;
|
|
24
|
+
this.observers.tagAdded.notify(slot);
|
|
25
|
+
this.observers.nodeAdded.notify(node);
|
|
26
|
+
return slot;
|
|
27
|
+
}
|
|
28
|
+
removeTag(index) {
|
|
29
|
+
if (this._node[index] === undefined)
|
|
30
|
+
return null;
|
|
31
|
+
this.observers.tagAdded.notify(index);
|
|
32
|
+
this.observers.nodeRemoved.notify(this._node[index]);
|
|
33
|
+
this._freeSlots.push(index);
|
|
34
|
+
this._node[index] = -1;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
2
|
+
import { Tag } from "./Tag";
|
|
3
|
+
import { TagArray } from "./TagArray";
|
|
4
|
+
export declare class TagCursor {
|
|
5
|
+
static Get(): TagCursor;
|
|
6
|
+
static Retrun(cursor: TagCursor): boolean;
|
|
7
|
+
get id(): string;
|
|
8
|
+
private _index;
|
|
9
|
+
get index(): number;
|
|
10
|
+
_type: number;
|
|
11
|
+
get typeId(): number;
|
|
12
|
+
get type(): string;
|
|
13
|
+
tag: Tag;
|
|
14
|
+
node: NodeCursor;
|
|
15
|
+
private constructor();
|
|
16
|
+
tagArray: TagArray;
|
|
17
|
+
setTag(node: NodeCursor, type: number, index: number): this;
|
|
18
|
+
dispose(): true | null;
|
|
19
|
+
toJSON(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NCSRegister } from "../Register/NCSRegister";
|
|
2
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
3
|
+
export class TagCursor {
|
|
4
|
+
static Get() {
|
|
5
|
+
const cursor = NCSPools.tagCursor.get();
|
|
6
|
+
if (!cursor)
|
|
7
|
+
return new TagCursor();
|
|
8
|
+
return cursor;
|
|
9
|
+
}
|
|
10
|
+
static Retrun(cursor) {
|
|
11
|
+
return NCSPools.tagCursor.addItem(cursor);
|
|
12
|
+
}
|
|
13
|
+
get id() {
|
|
14
|
+
return this.tag.id;
|
|
15
|
+
}
|
|
16
|
+
_index = 0;
|
|
17
|
+
get index() {
|
|
18
|
+
return this._index;
|
|
19
|
+
}
|
|
20
|
+
_type = 0;
|
|
21
|
+
get typeId() {
|
|
22
|
+
return this._type;
|
|
23
|
+
}
|
|
24
|
+
get type() {
|
|
25
|
+
return NCSRegister.tags.idPalette.getStringId(this.typeId);
|
|
26
|
+
}
|
|
27
|
+
tag;
|
|
28
|
+
node;
|
|
29
|
+
constructor() { }
|
|
30
|
+
tagArray;
|
|
31
|
+
setTag(node, type, index) {
|
|
32
|
+
this.node = node;
|
|
33
|
+
this._type = type;
|
|
34
|
+
this._index = index;
|
|
35
|
+
this.tagArray = node.graph._tags[type];
|
|
36
|
+
this.tag = NCSRegister.tags.get(this.typeId);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
dispose() {
|
|
40
|
+
return this.tagArray.removeTag(this._index);
|
|
41
|
+
}
|
|
42
|
+
toJSON() {
|
|
43
|
+
return this.id;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class IdPalette {
|
|
2
|
+
private _count;
|
|
3
|
+
_palette: string[];
|
|
4
|
+
_map: Record<string, number>;
|
|
5
|
+
constructor(inital?: ArrayLike<string>);
|
|
6
|
+
get size(): number;
|
|
7
|
+
register(string: string): number;
|
|
8
|
+
get(): string[];
|
|
9
|
+
getMap(): Record<string, number>;
|
|
10
|
+
isRegistered(id: string): boolean;
|
|
11
|
+
getNumberId(id: string): number;
|
|
12
|
+
getStringId(id: number): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class IdPalette {
|
|
2
|
+
_count = 0;
|
|
3
|
+
_palette = [];
|
|
4
|
+
_map = {};
|
|
5
|
+
constructor(inital) {
|
|
6
|
+
if (inital) {
|
|
7
|
+
const length = inital.length;
|
|
8
|
+
for (let i = 0; i < length; i++) {
|
|
9
|
+
this.register(inital[i]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
get size() {
|
|
14
|
+
return this._count;
|
|
15
|
+
}
|
|
16
|
+
register(string) {
|
|
17
|
+
const id = this._count;
|
|
18
|
+
this._count++;
|
|
19
|
+
this._palette[id] = string;
|
|
20
|
+
this._map[string] = id;
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
get() {
|
|
24
|
+
return this._palette;
|
|
25
|
+
}
|
|
26
|
+
getMap() {
|
|
27
|
+
return this._map;
|
|
28
|
+
}
|
|
29
|
+
isRegistered(id) {
|
|
30
|
+
return this._map[id] !== undefined;
|
|
31
|
+
}
|
|
32
|
+
getNumberId(id) {
|
|
33
|
+
return this._map[id];
|
|
34
|
+
}
|
|
35
|
+
getStringId(id) {
|
|
36
|
+
return this._palette[id];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
export class ItemPool {
|
|
2
|
-
maxSize;
|
|
3
2
|
items = [];
|
|
4
|
-
|
|
5
|
-
this.maxSize = maxSize;
|
|
6
|
-
}
|
|
3
|
+
maxSize = Infinity;
|
|
7
4
|
addItem(item) {
|
|
8
5
|
if (this.items.length > this.maxSize)
|
|
9
6
|
return false;
|
|
10
7
|
this.items.push(item);
|
|
8
|
+
return true;
|
|
11
9
|
}
|
|
12
10
|
get() {
|
|
13
11
|
const item = this.items.shift();
|