@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.
Files changed (181) hide show
  1. package/Components/Component.types.d.ts +78 -0
  2. package/Components/ComponentArray.d.ts +30 -0
  3. package/Components/ComponentArray.js +82 -0
  4. package/Components/ComponentCursor.d.ts +27 -0
  5. package/Components/ComponentCursor.js +72 -0
  6. package/Contexts/Context.types.d.ts +76 -0
  7. package/Contexts/ContextArray.d.ts +14 -0
  8. package/Contexts/ContextArray.js +47 -0
  9. package/Contexts/ContextCursor.d.ts +20 -0
  10. package/Contexts/ContextCursor.js +39 -0
  11. package/Data/SerializedData.types.d.ts +44 -0
  12. package/Data/deserializeComponent.d.ts +3 -0
  13. package/Data/deserializeComponent.js +3 -0
  14. package/Data/deserializeNode.d.ts +3 -0
  15. package/Data/deserializeNode.js +34 -0
  16. package/Data/serializeComponent.d.ts +7 -0
  17. package/Data/serializeComponent.js +36 -0
  18. package/Data/serializeNode.d.ts +13 -0
  19. package/Data/serializeNode.js +83 -0
  20. package/Functional.d.ts +12 -0
  21. package/Functional.js +31 -0
  22. package/Graphs/Graph.d.ts +19 -21
  23. package/Graphs/Graph.js +85 -74
  24. package/NCS.d.ts +79 -48
  25. package/NCS.js +108 -32
  26. package/Nodes/Node.types.d.ts +39 -0
  27. package/Nodes/Node.types.js +16 -0
  28. package/Nodes/NodeArray.d.ts +25 -0
  29. package/Nodes/NodeArray.js +96 -0
  30. package/Nodes/NodeComponents.d.ts +19 -0
  31. package/Nodes/NodeComponents.js +180 -0
  32. package/Nodes/NodeContext.d.ts +14 -0
  33. package/Nodes/NodeContext.js +107 -0
  34. package/Nodes/NodeCursor.d.ts +65 -0
  35. package/Nodes/NodeCursor.js +348 -0
  36. package/Nodes/NodeEvents.d.ts +10 -13
  37. package/Nodes/NodeEvents.js +51 -26
  38. package/Nodes/NodeId.d.ts +4 -13
  39. package/Nodes/NodeId.js +16 -48
  40. package/Nodes/NodeObservers.d.ts +35 -20
  41. package/Nodes/NodeObservers.js +162 -37
  42. package/Nodes/NodeTags.d.ts +17 -0
  43. package/Nodes/NodeTags.js +102 -0
  44. package/Pools/NCSPools.d.ts +27 -4
  45. package/Pools/NCSPools.js +14 -2
  46. package/Queries/Query.types.d.ts +8 -0
  47. package/Queries/QueryInstance.d.ts +6 -4
  48. package/Queries/QueryInstance.js +89 -44
  49. package/Queries/QueryPrototype.d.ts +1 -1
  50. package/Register/NCSRegister.d.ts +17 -9
  51. package/Register/NCSRegister.js +25 -2
  52. package/Register/registerComponent.d.ts +31 -25
  53. package/Register/registerComponent.js +88 -36
  54. package/Register/registerContext.d.ts +10 -13
  55. package/Register/registerContext.js +13 -18
  56. package/Register/registerSystem.d.ts +1 -1
  57. package/Register/registerSystem.js +1 -1
  58. package/Register/registerTag.d.ts +15 -17
  59. package/Register/registerTag.js +20 -23
  60. package/Schema/Functions/createBaseSchemaCursor.d.ts +18 -0
  61. package/Schema/Functions/createBaseSchemaCursor.js +34 -0
  62. package/Schema/Functions/createSchemaBinaryObjectCursorClass.d.ts +22 -0
  63. package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +134 -0
  64. package/Schema/Functions/createSchemaIndex.d.ts +3 -0
  65. package/Schema/Functions/createSchemaIndex.js +18 -0
  66. package/Schema/Functions/createSchemaObjectCursorClass.d.ts +18 -0
  67. package/Schema/Functions/createSchemaObjectCursorClass.js +66 -0
  68. package/Schema/Functions/createSchemaTypedArrayCursorClass.d.ts +17 -0
  69. package/Schema/Functions/createSchemaTypedArrayCursorClass.js +66 -0
  70. package/Schema/Property/Property.d.ts +11 -0
  71. package/Schema/Property/Property.js +16 -0
  72. package/Schema/Property/Property.types.d.ts +26 -0
  73. package/Schema/Property/Property.types.js +20 -0
  74. package/Schema/Schema.d.ts +28 -0
  75. package/Schema/Schema.js +223 -0
  76. package/Schema/Schema.types.d.ts +59 -0
  77. package/Schema/Schema.types.js +8 -0
  78. package/Schema/SchemaArray.d.ts +23 -0
  79. package/Schema/SchemaArray.js +87 -0
  80. package/Schema/SchemaArrayCursor.d.ts +19 -0
  81. package/Schema/SchemaArrayCursor.js +56 -0
  82. package/Schema/SchemaView.d.ts +24 -0
  83. package/Schema/SchemaView.js +141 -0
  84. package/Systems/{SystemData.d.ts → System.types.d.ts} +0 -4
  85. package/Systems/SystemInstance.d.ts +6 -4
  86. package/Systems/SystemInstance.js +14 -8
  87. package/Systems/SystemPrototype.d.ts +1 -1
  88. package/Systems/SystemPrototype.js +0 -1
  89. package/Tags/Tag.d.ts +1 -1
  90. package/Tags/Tag.js +1 -1
  91. package/Tags/{TagData.d.ts → Tag.types.d.ts} +0 -17
  92. package/Tags/TagArray.d.ts +18 -0
  93. package/Tags/TagArray.js +37 -0
  94. package/Tags/TagCursor.d.ts +20 -0
  95. package/Tags/TagCursor.js +45 -0
  96. package/Util/IdPalette.d.ts +13 -0
  97. package/Util/IdPalette.js +38 -0
  98. package/{Pools → Util}/ItemPool.d.ts +2 -3
  99. package/{Pools → Util}/ItemPool.js +2 -4
  100. package/Util/Observable.d.ts +28 -0
  101. package/Util/Observable.js +58 -0
  102. package/Util/Util.types.d.ts +4 -0
  103. package/index.d.ts +16 -6
  104. package/index.js +24 -6
  105. package/package.json +1 -1
  106. package/Components/ComponentData.d.ts +0 -112
  107. package/Components/ComponentInstance.d.ts +0 -36
  108. package/Components/ComponentInstance.js +0 -125
  109. package/Components/ComponentInstanceMap.d.ts +0 -7
  110. package/Components/ComponentInstanceMap.js +0 -15
  111. package/Components/ComponentObservers.d.ts +0 -8
  112. package/Components/ComponentObservers.js +0 -13
  113. package/Components/ComponentPipelines.d.ts +0 -16
  114. package/Components/ComponentPipelines.js +0 -33
  115. package/Components/ComponentPrototype.d.ts +0 -17
  116. package/Components/ComponentPrototype.js +0 -73
  117. package/Contexts/ContextData.d.ts +0 -59
  118. package/Contexts/ContextInstance.d.ts +0 -14
  119. package/Contexts/ContextInstance.js +0 -26
  120. package/Contexts/ContextInstanceAnchor.d.ts +0 -15
  121. package/Contexts/ContextInstanceAnchor.js +0 -33
  122. package/Contexts/ContextPrototype.d.ts +0 -9
  123. package/Contexts/ContextPrototype.js +0 -19
  124. package/Graphs/GraphEvents.d.ts +0 -9
  125. package/Graphs/GraphEvents.js +0 -35
  126. package/Graphs/GraphObservers.d.ts +0 -9
  127. package/Graphs/GraphObservers.js +0 -6
  128. package/Graphs/GraphUpdate.d.ts +0 -13
  129. package/Graphs/GraphUpdate.js +0 -38
  130. package/Maps/ItemGraphMap.d.ts +0 -11
  131. package/Maps/ItemGraphMap.js +0 -30
  132. package/Maps/ItemNodeMap.d.ts +0 -17
  133. package/Maps/ItemNodeMap.js +0 -41
  134. package/Nodes/Components/NodeComponentObservers.d.ts +0 -15
  135. package/Nodes/Components/NodeComponentObservers.js +0 -33
  136. package/Nodes/Components/NodeComponents.d.ts +0 -22
  137. package/Nodes/Components/NodeComponents.js +0 -107
  138. package/Nodes/Context/NodeContext.d.ts +0 -13
  139. package/Nodes/Context/NodeContext.js +0 -45
  140. package/Nodes/NodeData.d.ts +0 -40
  141. package/Nodes/NodeInstance.d.ts +0 -50
  142. package/Nodes/NodeInstance.js +0 -202
  143. package/Nodes/NodePipelines.d.ts +0 -16
  144. package/Nodes/NodePipelines.js +0 -33
  145. package/Nodes/Tags/NodeTagObservers.d.ts +0 -15
  146. package/Nodes/Tags/NodeTagObservers.js +0 -33
  147. package/Nodes/Tags/NodeTags.d.ts +0 -21
  148. package/Nodes/Tags/NodeTags.js +0 -95
  149. package/Queries/QueryData.d.ts +0 -8
  150. package/Register/ItemRegister.d.ts +0 -7
  151. package/Register/ItemRegister.js +0 -24
  152. package/Register/registerTrait.d.ts +0 -15
  153. package/Register/registerTrait.js +0 -39
  154. package/Tags/TagInstance.d.ts +0 -13
  155. package/Tags/TagInstance.js +0 -17
  156. package/Tags/TagInstanceMap.d.ts +0 -7
  157. package/Tags/TagInstanceMap.js +0 -15
  158. package/Tags/TagPrototype.d.ts +0 -16
  159. package/Tags/TagPrototype.js +0 -34
  160. package/Traits/TraitContaienrObservers.d.ts +0 -15
  161. package/Traits/TraitContaienrObservers.js +0 -33
  162. package/Traits/TraitContainer.d.ts +0 -22
  163. package/Traits/TraitContainer.js +0 -114
  164. package/Traits/TraitData.d.ts +0 -106
  165. package/Traits/TraitInstance.d.ts +0 -35
  166. package/Traits/TraitInstance.js +0 -115
  167. package/Traits/TraitInstanceMap.d.ts +0 -7
  168. package/Traits/TraitInstanceMap.js +0 -15
  169. package/Traits/TraitObservers.d.ts +0 -8
  170. package/Traits/TraitObservers.js +0 -13
  171. package/Traits/TraitPipelines.d.ts +0 -16
  172. package/Traits/TraitPipelines.js +0 -33
  173. package/Traits/TraitPrototype.d.ts +0 -16
  174. package/Traits/TraitPrototype.js +0 -74
  175. /package/Components/{ComponentData.js → Component.types.js} +0 -0
  176. /package/Contexts/{ContextData.js → Context.types.js} +0 -0
  177. /package/{Nodes/NodeData.js → Data/SerializedData.types.js} +0 -0
  178. /package/Queries/{QueryData.js → Query.types.js} +0 -0
  179. /package/Systems/{SystemData.js → System.types.js} +0 -0
  180. /package/Tags/{TagData.js → Tag.types.js} +0 -0
  181. /package/{Traits/TraitData.js → Util/Util.types.js} +0 -0
@@ -0,0 +1,18 @@
1
+ function traverse(parent, properties) {
2
+ for (let i = 0; i < properties.length; i++) {
3
+ const property = properties[i];
4
+ const index = property.index;
5
+ if (!property.children) {
6
+ parent[property.id] = index;
7
+ continue;
8
+ }
9
+ const newParent = {};
10
+ traverse(newParent, property.children);
11
+ parent[property.id] = newParent;
12
+ }
13
+ }
14
+ export function createSchemaIndex(schema) {
15
+ const data = {};
16
+ traverse(data, schema.root.children);
17
+ return data;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { Schema } from "../Schema";
2
+ import { SchemaArray } from "../../Schema/SchemaArray";
3
+ import { SchemaArrayCursor } from "../SchemaArrayCursor";
4
+ export declare function createSchemaObjectCursorClass(schema: Schema): {
5
+ new (__view: import("../SchemaView").SchemaView<any>): {
6
+ __cursor: SchemaArrayCursor;
7
+ __cursors: never[];
8
+ __view: import("../SchemaView").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,66 @@
1
+ import { createBaseSchemaCursor } from "./createBaseSchemaCursor";
2
+ function traverse(parent, properties) {
3
+ for (let i = 0; i < properties.length; i++) {
4
+ const property = properties[i];
5
+ const index = property.index;
6
+ if (!property.children) {
7
+ Object.defineProperty(parent.prototype, property.id, {
8
+ get() {
9
+ if (this.__cursor.hasProxy(index)) {
10
+ return this.__cursor.fetchProxyData(index);
11
+ }
12
+ return this.__cursor.data[index];
13
+ },
14
+ set(value) {
15
+ let obs = this.__cursor.getObserver(index);
16
+ let proxy = this.__cursor.hasProxy(index);
17
+ if (obs) {
18
+ const oldVale = proxy
19
+ ? this.__cursor.fetchProxyData(index)
20
+ : this.__cursor.data[index];
21
+ if (oldVale != value) {
22
+ this.__cursor.data[index] = value;
23
+ if (proxy) {
24
+ this.__cursor.setProxyData(index, value);
25
+ }
26
+ obs.notify(value);
27
+ return;
28
+ }
29
+ }
30
+ this.__cursor.data[index] = value;
31
+ if (proxy) {
32
+ this.__cursor.setProxyData(index, value);
33
+ }
34
+ },
35
+ });
36
+ continue;
37
+ }
38
+ class SchemaCursorProperty {
39
+ __cursor;
40
+ __cursors;
41
+ constructor(__cursor, __cursors) {
42
+ this.__cursor = __cursor;
43
+ this.__cursors = __cursors;
44
+ }
45
+ }
46
+ traverse(SchemaCursorProperty, property.children);
47
+ Object.defineProperty(parent.prototype, property.id, {
48
+ get() {
49
+ let v = this.__cursors[index];
50
+ if (!v) {
51
+ v = new SchemaCursorProperty(this.__cursor, this.__cursors);
52
+ this.__cursors[index] = v;
53
+ }
54
+ return v;
55
+ },
56
+ set(value) {
57
+ // (this as SchemaClassBase).__data.current[index] = value;
58
+ },
59
+ });
60
+ }
61
+ }
62
+ export function createSchemaObjectCursorClass(schema) {
63
+ const SchemaCursor = createBaseSchemaCursor();
64
+ traverse(SchemaCursor, schema.root.children);
65
+ return SchemaCursor;
66
+ }
@@ -0,0 +1,17 @@
1
+ import { Schema } from "../Schema";
2
+ import { SchemaArrayCursor } from "Schema/SchemaArrayCursor";
3
+ export declare function createSchemaTypedArrayCursorClass(schema: Schema): {
4
+ new (__view: import("../SchemaView").SchemaView<any>): {
5
+ __cursor: SchemaArrayCursor;
6
+ __cursors: never[];
7
+ __view: import("../SchemaView").SchemaView<any>;
8
+ __array: import("../SchemaArray").SchemaArray;
9
+ __index: number;
10
+ setInstance(index: number): void;
11
+ getInstance(): number;
12
+ getCursor(): SchemaArrayCursor;
13
+ getSchemaIndex(): import("../Schema.types").SchemaCursorIndex<any>;
14
+ clone(): any;
15
+ toJSON(): any;
16
+ };
17
+ };
@@ -0,0 +1,66 @@
1
+ import { createBaseSchemaCursor } from "./createBaseSchemaCursor";
2
+ function traverse(parent, properties) {
3
+ for (let i = 0; i < properties.length; i++) {
4
+ const property = properties[i];
5
+ const index = property.index;
6
+ if (!property.children) {
7
+ Object.defineProperty(parent.prototype, property.id, {
8
+ get() {
9
+ if (this.__cursor.hasProxy(index)) {
10
+ return this.__cursor.fetchProxyData(index);
11
+ }
12
+ return this.__cursor.data[index];
13
+ },
14
+ set(value) {
15
+ let obs = this.__cursor.getObserver(index);
16
+ let proxy = this.__cursor.hasProxy(index);
17
+ if (obs) {
18
+ const oldVale = proxy
19
+ ? this.__cursor.fetchProxyData(index)
20
+ : this.__cursor.data[index];
21
+ if (oldVale != value) {
22
+ this.__cursor.data[index] = value;
23
+ if (proxy) {
24
+ this.__cursor.setProxyData(index, value);
25
+ }
26
+ obs.notify(value);
27
+ return;
28
+ }
29
+ }
30
+ this.__cursor.data[index] = value;
31
+ if (proxy) {
32
+ this.__cursor.setProxyData(index, value);
33
+ }
34
+ },
35
+ });
36
+ continue;
37
+ }
38
+ class SchemaCursorProperty {
39
+ __cursor;
40
+ __cursors;
41
+ constructor(__cursor, __cursors) {
42
+ this.__cursor = __cursor;
43
+ this.__cursors = __cursors;
44
+ }
45
+ }
46
+ traverse(SchemaCursorProperty, property.children);
47
+ Object.defineProperty(parent.prototype, property.id, {
48
+ get() {
49
+ let v = this.__cursors[index];
50
+ if (!v) {
51
+ v = new SchemaCursorProperty(this.__cursor, this.__cursors);
52
+ this.__cursors[index] = v;
53
+ }
54
+ return v;
55
+ },
56
+ set(value) {
57
+ // (this as SchemaClassBase).__data.current[index] = value;
58
+ },
59
+ });
60
+ }
61
+ }
62
+ export function createSchemaTypedArrayCursorClass(schema) {
63
+ const SchemaCursor = createBaseSchemaCursor();
64
+ traverse(SchemaCursor, schema.root.children);
65
+ return SchemaCursor;
66
+ }
@@ -0,0 +1,11 @@
1
+ import { PropertyData, PropertyMetaData } from "./Property.types";
2
+ export declare class Property implements PropertyData {
3
+ readonly index: number;
4
+ id: string;
5
+ name?: string;
6
+ type: string;
7
+ meta?: PropertyMetaData;
8
+ value: null;
9
+ children?: Property[];
10
+ constructor(data: PropertyData, index: number);
11
+ }
@@ -0,0 +1,16 @@
1
+ export class Property {
2
+ index;
3
+ id = "";
4
+ name;
5
+ type = "";
6
+ meta;
7
+ value = null;
8
+ children;
9
+ constructor(data, index) {
10
+ this.index = index;
11
+ this.id = data.id;
12
+ this.name = data.name;
13
+ this.value = data.value;
14
+ this.meta = data.meta;
15
+ }
16
+ }
@@ -0,0 +1,26 @@
1
+ export interface PropertyData<Meta extends {} = {}> {
2
+ id: string;
3
+ name?: string;
4
+ value: any;
5
+ meta?: PropertyMetaData<Meta>;
6
+ children?: PropertyData[];
7
+ }
8
+ export type BinaryPropertyTypes = "i8" | "ui8" | "i16" | "ui16" | "i32" | "ui32" | "f32" | "f64";
9
+ export type TypedArrays = typeof Int8Array | typeof Uint8Array | typeof Int16Array | typeof Uint16Array | typeof Int32Array | typeof Uint32Array | typeof Float32Array | typeof Float64Array;
10
+ export declare const TypedArrayMap: Record<BinaryPropertyTypes, TypedArrays>;
11
+ export declare const BinaryPropertyTypeSizeMap: Record<BinaryPropertyTypes, number>;
12
+ export type BinaryPropertyData = BinaryPropertyTypes | {
13
+ byteSize: number;
14
+ set(data: DataView, meta: any, index: number, value: any): void;
15
+ get(data: DataView, meta: any, index: number): any;
16
+ };
17
+ export type PropertyMetaData<MetaData extends {} = any> = {
18
+ binary?: BinaryPropertyData;
19
+ data?: MetaData;
20
+ /**If the property was created from an object */
21
+ child?: true;
22
+ type?: string;
23
+ units?: string;
24
+ options?: string[] | [string, string | number][];
25
+ name?: string;
26
+ };
@@ -0,0 +1,20 @@
1
+ export const TypedArrayMap = {
2
+ i8: Int8Array,
3
+ ui8: Uint8Array,
4
+ i16: Int16Array,
5
+ ui16: Uint16Array,
6
+ i32: Int32Array,
7
+ ui32: Uint32Array,
8
+ f32: Float32Array,
9
+ f64: Float64Array,
10
+ };
11
+ export const BinaryPropertyTypeSizeMap = {
12
+ i8: Int8Array.BYTES_PER_ELEMENT,
13
+ ui8: Uint8Array.BYTES_PER_ELEMENT,
14
+ i16: Int16Array.BYTES_PER_ELEMENT,
15
+ ui16: Uint16Array.BYTES_PER_ELEMENT,
16
+ i32: Int32Array.BYTES_PER_ELEMENT,
17
+ ui32: Uint32Array.BYTES_PER_ELEMENT,
18
+ f32: Float32Array.BYTES_PER_ELEMENT,
19
+ f64: Float64Array.BYTES_PER_ELEMENT,
20
+ };
@@ -0,0 +1,28 @@
1
+ import { Property } from "./Property/Property";
2
+ import { BinaryPropertyTypes, PropertyMetaData } from "./Property/Property.types";
3
+ import { SchemaData, SchemaCursorIndex, SchemaCreateData, SchemaMetaOverrideData } from "./Schema.types";
4
+ import { SchemaView } from "./SchemaView";
5
+ import { RecursivePartial } from "../Util/Util.types";
6
+ import { SchemaArray } from "./SchemaArray";
7
+ import { IdPalette } from "../Util/IdPalette";
8
+ export declare class Schema<Shape extends Record<string, any> = {}> {
9
+ static FromObject<Shape extends Record<string, any>>(shape: Shape): Schema<Shape>;
10
+ readonly root: Property;
11
+ private _objectCursorClass;
12
+ private _typedArrayCursorClass;
13
+ private _binaryObjectCursorClass;
14
+ readonly index: SchemaCursorIndex<Shape>;
15
+ readonly shape: Shape;
16
+ readonly _data: any[];
17
+ readonly _meta: PropertyMetaData[];
18
+ viewIdPalettew: IdPalette;
19
+ views: SchemaView[];
20
+ array: SchemaArray;
21
+ constructor(data: SchemaData);
22
+ createData(newData: any[] | undefined, overrides: RecursivePartial<Shape>): any[];
23
+ getView(id: string): SchemaView<any> | null;
24
+ createView(data: SchemaCreateData): SchemaView<any>;
25
+ createObjectView(id: string, meta?: SchemaMetaOverrideData | null): SchemaView<Shape>;
26
+ createBinaryObjectView(id: string, sharedMemory?: boolean, meta?: SchemaMetaOverrideData | null): SchemaView<Shape>;
27
+ createTypedArrayView(id: string, arrayType: BinaryPropertyTypes, sharedMemory?: boolean, meta?: SchemaMetaOverrideData | null): SchemaView<Shape>;
28
+ }
@@ -0,0 +1,223 @@
1
+ import { createSchemaObjectCursorClass } from "./Functions/createSchemaObjectCursorClass";
2
+ import { createSchemaIndex } from "./Functions/createSchemaIndex";
3
+ import { Property } from "./Property/Property";
4
+ import { BinaryPropertyTypeSizeMap, } from "./Property/Property.types";
5
+ import { createSchemaTypedArrayCursorClass } from "./Functions/createSchemaTypedArrayCursorClass";
6
+ import { createSchemaBinaryObjectCursorClass } from "./Functions/createSchemaBinaryObjectCursorClass";
7
+ import { SchemaView } from "./SchemaView";
8
+ import { SchemaArray } from "./SchemaArray";
9
+ import { IdPalette } from "../Util/IdPalette";
10
+ const traverseCreate = (parent, properties, index) => {
11
+ parent.children ??= [];
12
+ for (let i = 0; i < properties.length; i++) {
13
+ const data = properties[i];
14
+ if (typeof data.value == "object" && !data.children) {
15
+ data.children ??= [];
16
+ for (const key in data.value) {
17
+ const value = data.value[key];
18
+ const meta = structuredClone(data.meta || {});
19
+ meta.child = true;
20
+ data.children.push({
21
+ id: key,
22
+ meta,
23
+ value,
24
+ });
25
+ }
26
+ }
27
+ if (data.children) {
28
+ const newChild = new Property(data, index + 1);
29
+ parent.children.push(newChild);
30
+ index = traverseCreate(newChild, data.children, index);
31
+ continue;
32
+ }
33
+ else {
34
+ index++;
35
+ parent.children.push(new Property(data, index));
36
+ }
37
+ }
38
+ return index;
39
+ };
40
+ const buildBinaryData = (meta) => {
41
+ let byteSize = 0;
42
+ const byteOffsets = [];
43
+ for (let i = 0; i < meta.length; i++) {
44
+ const metaData = meta[i];
45
+ if (!metaData || !metaData.binary)
46
+ continue;
47
+ byteOffsets[i] = byteSize;
48
+ if (typeof metaData.binary == "object") {
49
+ byteSize += metaData.binary.byteSize;
50
+ continue;
51
+ }
52
+ if (typeof metaData.binary == "string") {
53
+ byteSize += BinaryPropertyTypeSizeMap[metaData.binary];
54
+ continue;
55
+ }
56
+ }
57
+ return { byteSize, byteOffsets };
58
+ };
59
+ const traverseArray = (parent, data, meta) => {
60
+ for (let i = 0; i < parent.children.length; i++) {
61
+ const property = parent.children[i];
62
+ if (!property.children) {
63
+ data[Number(property.index)] = structuredClone(property.value);
64
+ property.meta && (meta[property.index] = structuredClone(property.meta));
65
+ }
66
+ else {
67
+ traverseArray(property, data, meta);
68
+ }
69
+ }
70
+ return data;
71
+ };
72
+ function buildMeta(data, meta, metaOverrides) {
73
+ let newMeta = [...meta];
74
+ for (let i = 0; i < data.length; i++) {
75
+ if (!metaOverrides[i])
76
+ continue;
77
+ newMeta[i] = metaOverrides[i];
78
+ }
79
+ return newMeta;
80
+ }
81
+ function traverseCreateFromObject(object, property) {
82
+ for (const id in object) {
83
+ const value = object[id];
84
+ if (typeof value == "object") {
85
+ property.children.push(traverseCreateFromObject(value, {
86
+ id,
87
+ value: {},
88
+ children: [],
89
+ }));
90
+ }
91
+ else {
92
+ property.children.push({
93
+ id,
94
+ value,
95
+ });
96
+ }
97
+ }
98
+ return property;
99
+ }
100
+ function traverseCreateData(parent, target, source) {
101
+ for (const property of parent.children) {
102
+ if (typeof source[property.id] === "undefined")
103
+ continue;
104
+ if (property.children) {
105
+ traverseCreateData(property, target, source[property.id]);
106
+ }
107
+ else {
108
+ target[property.index] = source[property.id];
109
+ }
110
+ }
111
+ return target;
112
+ }
113
+ export class Schema {
114
+ static FromObject(shape) {
115
+ const data = [];
116
+ for (const id in shape) {
117
+ const value = shape[id];
118
+ if (typeof value == "object") {
119
+ data.push(traverseCreateFromObject(value, {
120
+ id,
121
+ value: {},
122
+ children: [],
123
+ }));
124
+ }
125
+ else {
126
+ data.push({
127
+ id,
128
+ value,
129
+ });
130
+ }
131
+ }
132
+ return new Schema(data);
133
+ }
134
+ root = new Property({
135
+ id: "__root__",
136
+ meta: {},
137
+ value: {},
138
+ }, -1);
139
+ _objectCursorClass;
140
+ _typedArrayCursorClass;
141
+ _binaryObjectCursorClass;
142
+ index;
143
+ shape;
144
+ _data = [];
145
+ _meta = [];
146
+ viewIdPalettew = new IdPalette();
147
+ views = [];
148
+ array;
149
+ constructor(data) {
150
+ traverseCreate(this.root, data, -1);
151
+ this.index = createSchemaIndex(this);
152
+ traverseArray(this.root, this._data, this._meta);
153
+ this.createObjectView("default");
154
+ this.array = new SchemaArray(this);
155
+ }
156
+ createData(newData = [], overrides) {
157
+ for (let i = 0; i < this._data.length; i++) {
158
+ newData[i] =
159
+ typeof this._data[i] == "object"
160
+ ? structuredClone(this._data[i])
161
+ : this._data[i];
162
+ }
163
+ traverseCreateData(this.root, newData, overrides);
164
+ return newData;
165
+ }
166
+ getView(id) {
167
+ if (!this.viewIdPalettew.isRegistered(id))
168
+ return null;
169
+ return this.views[this.viewIdPalettew.getNumberId(id)];
170
+ }
171
+ createView(data) {
172
+ let view = null;
173
+ let meta = this._meta;
174
+ if (data.meta)
175
+ meta = buildMeta(this._data, meta, data.meta);
176
+ if (data.type == "object") {
177
+ if (!this._objectCursorClass)
178
+ this._objectCursorClass = createSchemaObjectCursorClass(this);
179
+ view = new SchemaView(this, data.id, meta, [], 0, data, this._objectCursorClass);
180
+ }
181
+ if (data.type == "typed-array") {
182
+ if (!this._typedArrayCursorClass)
183
+ this._typedArrayCursorClass = createSchemaTypedArrayCursorClass(this);
184
+ view = new SchemaView(this, data.id, meta, [], 0, data, this._typedArrayCursorClass);
185
+ }
186
+ if (data.type == "binary-object") {
187
+ if (!this._binaryObjectCursorClass)
188
+ this._binaryObjectCursorClass =
189
+ createSchemaBinaryObjectCursorClass(this);
190
+ const { byteSize, byteOffsets } = buildBinaryData(meta);
191
+ view = new SchemaView(this, data.id, meta, byteOffsets, byteSize, data, this._binaryObjectCursorClass);
192
+ }
193
+ if (!view)
194
+ throw new Error(`Invalid data`);
195
+ const viewIndex = this.viewIdPalettew.register(data.id);
196
+ this.views[viewIndex] = view;
197
+ return view;
198
+ }
199
+ createObjectView(id, meta = null) {
200
+ return this.createView({
201
+ id,
202
+ type: "object",
203
+ meta,
204
+ });
205
+ }
206
+ createBinaryObjectView(id, sharedMemory = false, meta = null) {
207
+ return this.createView({
208
+ id,
209
+ type: "binary-object",
210
+ meta,
211
+ sharedMemory: sharedMemory || undefined,
212
+ });
213
+ }
214
+ createTypedArrayView(id, arrayType, sharedMemory = false, meta = null) {
215
+ return this.createView({
216
+ id,
217
+ type: "typed-array",
218
+ meta,
219
+ arrayType,
220
+ sharedMemory: sharedMemory || undefined,
221
+ });
222
+ }
223
+ }
@@ -0,0 +1,59 @@
1
+ import { BinaryPropertyTypes, PropertyData, PropertyMetaData } from "./Property/Property.types";
2
+ import { SchemaView } from "./SchemaView";
3
+ import { SchemaArrayCursor } from "./SchemaArrayCursor";
4
+ export type SchemaTypes = "object" | "binay";
5
+ export type SchemaData = PropertyData[];
6
+ export type SchemaProxyData<T extends Record<string | number, any> = {}> = [
7
+ object: T,
8
+ key: keyof T
9
+ ];
10
+ export type BinaryObjectSchemaView = {
11
+ view: DataView;
12
+ buffer: Uint8Array;
13
+ };
14
+ export type SchemaCursor<Shape extends {} = {}> = SchemaCursorBase<Shape> & Shape;
15
+ export interface SchemaCursorBase<Shape extends {} = any> {
16
+ __view: SchemaView<Shape>;
17
+ __cursor: SchemaArrayCursor;
18
+ getSchemaIndex(): SchemaCursorIndex<Shape>;
19
+ getInstance(): number;
20
+ setInstance(index: number): void;
21
+ getCursor(): SchemaArrayCursor;
22
+ clone(): SchemaCursorBase<Shape>;
23
+ toJSON(): Shape;
24
+ }
25
+ export type SchemaMetaOverrideData = PropertyMetaData[] | Record<number, PropertyMetaData>;
26
+ export type SchemaCreateData = {
27
+ id: string;
28
+ type: "object";
29
+ meta?: SchemaMetaOverrideData | null;
30
+ } | {
31
+ id: string;
32
+ type: "typed-array";
33
+ arrayType: BinaryPropertyTypes;
34
+ sharedMemory?: true;
35
+ meta?: SchemaMetaOverrideData | null;
36
+ } | {
37
+ id: string;
38
+ type: "binary-object";
39
+ sharedMemory?: true;
40
+ meta?: SchemaMetaOverrideData | null;
41
+ };
42
+ export interface SchemaCursorClassBase extends SchemaCursorBase {
43
+ __index: number;
44
+ __cursor: SchemaArrayCursor;
45
+ __cursors: any[];
46
+ }
47
+ export type SchemaCursorIndex<T> = {
48
+ [K in keyof T]: T[K] extends string | number | boolean | bigint | symbol | undefined | null ? number : T[K] extends object ? SchemaCursorIndex<T[K]> : never;
49
+ };
50
+ export declare class SchemaProperty<T extends any> {
51
+ value: T;
52
+ meta: PropertyMetaData;
53
+ constructor(value: T, meta: PropertyMetaData);
54
+ }
55
+ export type ExtractSchemaClass<T> = T extends SchemaProperty<infer U> ? U extends object ? {
56
+ [K in keyof U]: ExtractSchemaClass<U[K]>;
57
+ } : U : T extends object ? {
58
+ [K in keyof T]: ExtractSchemaClass<T[K]>;
59
+ } : T;
@@ -0,0 +1,8 @@
1
+ export class SchemaProperty {
2
+ value;
3
+ meta;
4
+ constructor(value, meta) {
5
+ this.value = value;
6
+ this.meta = meta;
7
+ }
8
+ }
@@ -0,0 +1,23 @@
1
+ import { Observable } from "../Util/Observable";
2
+ import { BinaryObjectSchemaView } from "./Schema.types";
3
+ import { Schema } from "./Schema";
4
+ export declare class SchemaArray {
5
+ schema: Schema;
6
+ _data: (any[] | BinaryObjectSchemaView)[];
7
+ _dataViews: number[];
8
+ _observers: Observable<any>[][];
9
+ _proxyObjects: any[][];
10
+ _proxyKeys: any[][];
11
+ constructor(schema: Schema);
12
+ createViewCursor(index: number): any;
13
+ setData(index: number, data: any, view?: string | null): void;
14
+ getViewAt(index: number): import("./SchemaView").SchemaView<any> | null;
15
+ removeData(index: number): boolean;
16
+ getObserver(propertyIndex: number, arrayIndex: number): Observable<any> | null;
17
+ setObserver(propertyIndex: number, arrayIndex: number, value: Observable<any> | null): void;
18
+ hasProxy(propertyIndex: number, arrayIndex: number): boolean;
19
+ fetchProxyData(propertyIndex: number, arrayIndex: number): any;
20
+ setProxyData(propertyIndex: number, arrayIndex: number, value: any): void;
21
+ removeProxy(propertyIndex: number, arrayIndex: number): void;
22
+ setProxy<T extends Record<string | number, any> = {}>(propertyIndex: number, arrayIndex: number, object: T, key: keyof T): void;
23
+ }