@vuer-ai/vuer-rtc 0.0.1

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 (169) hide show
  1. package/dist/client/EditBuffer.d.ts +43 -0
  2. package/dist/client/EditBuffer.d.ts.map +1 -0
  3. package/dist/client/EditBuffer.js +96 -0
  4. package/dist/client/EditBuffer.js.map +1 -0
  5. package/dist/client/actions.d.ts +66 -0
  6. package/dist/client/actions.d.ts.map +1 -0
  7. package/dist/client/actions.js +345 -0
  8. package/dist/client/actions.js.map +1 -0
  9. package/dist/client/createGraph.d.ts +30 -0
  10. package/dist/client/createGraph.d.ts.map +1 -0
  11. package/dist/client/createGraph.js +91 -0
  12. package/dist/client/createGraph.js.map +1 -0
  13. package/dist/client/hooks.d.ts +81 -0
  14. package/dist/client/hooks.d.ts.map +1 -0
  15. package/dist/client/hooks.js +161 -0
  16. package/dist/client/hooks.js.map +1 -0
  17. package/dist/client/index.d.ts +8 -0
  18. package/dist/client/index.d.ts.map +1 -0
  19. package/dist/client/index.js +10 -0
  20. package/dist/client/index.js.map +1 -0
  21. package/dist/client/types.d.ts +74 -0
  22. package/dist/client/types.d.ts.map +1 -0
  23. package/dist/client/types.js +11 -0
  24. package/dist/client/types.js.map +1 -0
  25. package/dist/hooks.d.ts +8 -0
  26. package/dist/hooks.d.ts.map +1 -0
  27. package/dist/hooks.js +7 -0
  28. package/dist/hooks.js.map +1 -0
  29. package/dist/index.d.ts +9 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +12 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/operations/OperationTypes.d.ts +239 -0
  34. package/dist/operations/OperationTypes.d.ts.map +1 -0
  35. package/dist/operations/OperationTypes.js +10 -0
  36. package/dist/operations/OperationTypes.js.map +1 -0
  37. package/dist/operations/OperationValidator.d.ts +32 -0
  38. package/dist/operations/OperationValidator.d.ts.map +1 -0
  39. package/dist/operations/OperationValidator.js +208 -0
  40. package/dist/operations/OperationValidator.js.map +1 -0
  41. package/dist/operations/apply/array.d.ts +22 -0
  42. package/dist/operations/apply/array.d.ts.map +1 -0
  43. package/dist/operations/apply/array.js +64 -0
  44. package/dist/operations/apply/array.js.map +1 -0
  45. package/dist/operations/apply/boolean.d.ts +18 -0
  46. package/dist/operations/apply/boolean.d.ts.map +1 -0
  47. package/dist/operations/apply/boolean.js +34 -0
  48. package/dist/operations/apply/boolean.js.map +1 -0
  49. package/dist/operations/apply/color.d.ts +14 -0
  50. package/dist/operations/apply/color.d.ts.map +1 -0
  51. package/dist/operations/apply/color.js +46 -0
  52. package/dist/operations/apply/color.js.map +1 -0
  53. package/dist/operations/apply/index.d.ts +18 -0
  54. package/dist/operations/apply/index.d.ts.map +1 -0
  55. package/dist/operations/apply/index.js +26 -0
  56. package/dist/operations/apply/index.js.map +1 -0
  57. package/dist/operations/apply/node.d.ts +24 -0
  58. package/dist/operations/apply/node.d.ts.map +1 -0
  59. package/dist/operations/apply/node.js +77 -0
  60. package/dist/operations/apply/node.js.map +1 -0
  61. package/dist/operations/apply/number.d.ts +26 -0
  62. package/dist/operations/apply/number.d.ts.map +1 -0
  63. package/dist/operations/apply/number.js +54 -0
  64. package/dist/operations/apply/number.js.map +1 -0
  65. package/dist/operations/apply/object.d.ts +14 -0
  66. package/dist/operations/apply/object.d.ts.map +1 -0
  67. package/dist/operations/apply/object.js +47 -0
  68. package/dist/operations/apply/object.js.map +1 -0
  69. package/dist/operations/apply/quaternion.d.ts +15 -0
  70. package/dist/operations/apply/quaternion.d.ts.map +1 -0
  71. package/dist/operations/apply/quaternion.js +33 -0
  72. package/dist/operations/apply/quaternion.js.map +1 -0
  73. package/dist/operations/apply/string.d.ts +14 -0
  74. package/dist/operations/apply/string.d.ts.map +1 -0
  75. package/dist/operations/apply/string.js +26 -0
  76. package/dist/operations/apply/string.js.map +1 -0
  77. package/dist/operations/apply/types.d.ts +34 -0
  78. package/dist/operations/apply/types.d.ts.map +1 -0
  79. package/dist/operations/apply/types.js +32 -0
  80. package/dist/operations/apply/types.js.map +1 -0
  81. package/dist/operations/apply/vector3.d.ts +18 -0
  82. package/dist/operations/apply/vector3.d.ts.map +1 -0
  83. package/dist/operations/apply/vector3.js +44 -0
  84. package/dist/operations/apply/vector3.js.map +1 -0
  85. package/dist/operations/dispatcher.d.ts +35 -0
  86. package/dist/operations/dispatcher.d.ts.map +1 -0
  87. package/dist/operations/dispatcher.js +107 -0
  88. package/dist/operations/dispatcher.js.map +1 -0
  89. package/dist/operations/index.d.ts +10 -0
  90. package/dist/operations/index.d.ts.map +1 -0
  91. package/dist/operations/index.js +17 -0
  92. package/dist/operations/index.js.map +1 -0
  93. package/dist/state/ConflictResolver.d.ts +36 -0
  94. package/dist/state/ConflictResolver.d.ts.map +1 -0
  95. package/dist/state/ConflictResolver.js +167 -0
  96. package/dist/state/ConflictResolver.js.map +1 -0
  97. package/dist/state/DType.d.ts +160 -0
  98. package/dist/state/DType.d.ts.map +1 -0
  99. package/dist/state/DType.js +282 -0
  100. package/dist/state/DType.js.map +1 -0
  101. package/dist/state/Schema.d.ts +32 -0
  102. package/dist/state/Schema.d.ts.map +1 -0
  103. package/dist/state/Schema.js +175 -0
  104. package/dist/state/Schema.js.map +1 -0
  105. package/dist/state/VectorClock.d.ts +42 -0
  106. package/dist/state/VectorClock.d.ts.map +1 -0
  107. package/dist/state/VectorClock.js +84 -0
  108. package/dist/state/VectorClock.js.map +1 -0
  109. package/dist/state/index.d.ts +11 -0
  110. package/dist/state/index.d.ts.map +1 -0
  111. package/dist/state/index.js +13 -0
  112. package/dist/state/index.js.map +1 -0
  113. package/docs/OPERATION_HINTS.md +222 -0
  114. package/docs/SCENE_GRAPH.md +373 -0
  115. package/docs/TYPE_BEHAVIORS.md +348 -0
  116. package/examples/01-basic-usage.ts +139 -0
  117. package/examples/02-concurrent-edits.ts +208 -0
  118. package/examples/03-scene-building.ts +258 -0
  119. package/examples/04-conflict-resolution.ts +339 -0
  120. package/examples/README.md +86 -0
  121. package/jest.config.js +19 -0
  122. package/package.json +57 -0
  123. package/src/client/EditBuffer.ts +105 -0
  124. package/src/client/actions.ts +397 -0
  125. package/src/client/createGraph.ts +132 -0
  126. package/src/client/hooks.tsx +249 -0
  127. package/src/client/index.ts +35 -0
  128. package/src/client/types.ts +94 -0
  129. package/src/hooks.ts +20 -0
  130. package/src/index.ts +14 -0
  131. package/src/operations/OperationTypes.ts +340 -0
  132. package/src/operations/OperationValidator.ts +260 -0
  133. package/src/operations/apply/array.ts +84 -0
  134. package/src/operations/apply/boolean.ts +48 -0
  135. package/src/operations/apply/color.ts +65 -0
  136. package/src/operations/apply/index.ts +37 -0
  137. package/src/operations/apply/node.ts +98 -0
  138. package/src/operations/apply/number.ts +76 -0
  139. package/src/operations/apply/object.ts +63 -0
  140. package/src/operations/apply/quaternion.ts +47 -0
  141. package/src/operations/apply/string.ts +36 -0
  142. package/src/operations/apply/types.ts +66 -0
  143. package/src/operations/apply/vector3.ts +60 -0
  144. package/src/operations/dispatcher.ts +127 -0
  145. package/src/operations/index.ts +80 -0
  146. package/src/state/ConflictResolver.ts +205 -0
  147. package/src/state/DType.ts +333 -0
  148. package/src/state/Schema.ts +236 -0
  149. package/src/state/VectorClock.ts +98 -0
  150. package/src/state/index.ts +14 -0
  151. package/tests/client/actions.test.ts +371 -0
  152. package/tests/client/edit-buffer.test.ts +117 -0
  153. package/tests/fixtures/array-ops.jsonl +6 -0
  154. package/tests/fixtures/boolean-ops.jsonl +6 -0
  155. package/tests/fixtures/color-ops.jsonl +4 -0
  156. package/tests/fixtures/edit-buffer.jsonl +3 -0
  157. package/tests/fixtures/node-ops.jsonl +6 -0
  158. package/tests/fixtures/number-ops.jsonl +7 -0
  159. package/tests/fixtures/object-ops.jsonl +4 -0
  160. package/tests/fixtures/operations.jsonl +7 -0
  161. package/tests/fixtures/string-ops.jsonl +4 -0
  162. package/tests/fixtures/undo-redo.jsonl +3 -0
  163. package/tests/fixtures/vector-ops.jsonl +9 -0
  164. package/tests/operations/collections.test.ts +193 -0
  165. package/tests/operations/nodes.test.ts +228 -0
  166. package/tests/operations/primitives.test.ts +222 -0
  167. package/tests/operations/vectors.test.ts +150 -0
  168. package/tsconfig.json +21 -0
  169. package/tsconfig.test.json +9 -0
@@ -0,0 +1,282 @@
1
+ /**
2
+ * DType - Data type system with merge operations
3
+ *
4
+ * Based on test-data/datatypes.ts
5
+ *
6
+ * Each dtype has supported operations that define merge behavior
7
+ * for concurrent updates.
8
+ */
9
+ /**
10
+ * DType definitions
11
+ */
12
+ export const DType = {
13
+ // ============================================
14
+ // PRIMITIVES
15
+ // ============================================
16
+ /**
17
+ * Number operations
18
+ */
19
+ number: {
20
+ /**
21
+ * SET - Last-Write-Wins
22
+ */
23
+ set: ((values) => {
24
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
25
+ return sorted[0].value;
26
+ }),
27
+ /**
28
+ * ADD - Sum all values
29
+ */
30
+ add: ((values) => {
31
+ return values.reduce((sum, v) => sum + v.value, 0);
32
+ }),
33
+ /**
34
+ * MULTIPLY - Multiply all values
35
+ */
36
+ multiply: ((values) => {
37
+ return values.reduce((product, v) => product * v.value, 1);
38
+ }),
39
+ /**
40
+ * MIN - Take minimum
41
+ */
42
+ min: ((values) => {
43
+ return Math.min(...values.map((v) => v.value));
44
+ }),
45
+ /**
46
+ * MAX - Take maximum
47
+ */
48
+ max: ((values) => {
49
+ return Math.max(...values.map((v) => v.value));
50
+ }),
51
+ },
52
+ /**
53
+ * String operations
54
+ */
55
+ string: {
56
+ /**
57
+ * SET - Last-Write-Wins
58
+ */
59
+ set: ((values) => {
60
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
61
+ return sorted[0].value;
62
+ }),
63
+ /**
64
+ * CONCAT - Concatenate (ordered by lamport)
65
+ */
66
+ concat: ((values, separator = '\n') => {
67
+ const sorted = [...values].sort((a, b) => a.lamportTime - b.lamportTime);
68
+ return sorted.map((v) => v.value).join(separator);
69
+ }),
70
+ },
71
+ /**
72
+ * Boolean operations
73
+ */
74
+ boolean: {
75
+ /**
76
+ * SET - Last-Write-Wins
77
+ */
78
+ set: ((values) => {
79
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
80
+ return sorted[0].value;
81
+ }),
82
+ /**
83
+ * OR - Logical OR (enable wins)
84
+ */
85
+ or: ((values) => {
86
+ return values.some((v) => v.value === true);
87
+ }),
88
+ /**
89
+ * AND - Logical AND (disable wins)
90
+ */
91
+ and: ((values) => {
92
+ return values.every((v) => v.value === true);
93
+ }),
94
+ },
95
+ // ============================================
96
+ // COMPOUND TYPES (3D GRAPHICS)
97
+ // ============================================
98
+ /**
99
+ * Vector3 operations - [x, y, z]
100
+ */
101
+ vector3: {
102
+ /**
103
+ * SET - Replace entire vector (preserves user intent)
104
+ */
105
+ set: ((values) => {
106
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
107
+ return sorted[0].value;
108
+ }),
109
+ /**
110
+ * ADD - Component-wise addition
111
+ */
112
+ add: ((values) => {
113
+ const sum = [0, 0, 0];
114
+ for (const v of values) {
115
+ sum[0] += v.value[0];
116
+ sum[1] += v.value[1];
117
+ sum[2] += v.value[2];
118
+ }
119
+ return sum;
120
+ }),
121
+ /**
122
+ * MULTIPLY - Component-wise multiplication
123
+ */
124
+ multiply: ((values) => {
125
+ const product = [1, 1, 1];
126
+ for (const v of values) {
127
+ product[0] *= v.value[0];
128
+ product[1] *= v.value[1];
129
+ product[2] *= v.value[2];
130
+ }
131
+ return product;
132
+ }),
133
+ },
134
+ /**
135
+ * Quaternion operations - [x, y, z, w]
136
+ */
137
+ quaternion: {
138
+ /**
139
+ * SET - Replace entire quaternion
140
+ */
141
+ set: ((values) => {
142
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
143
+ return sorted[0].value;
144
+ }),
145
+ /**
146
+ * MULTIPLY - Quaternion multiplication (composition)
147
+ */
148
+ multiply: ((values) => {
149
+ const sorted = [...values].sort((a, b) => a.lamportTime - b.lamportTime);
150
+ let result = sorted[0].value;
151
+ for (let i = 1; i < sorted.length; i++) {
152
+ result = multiplyQuaternions(result, sorted[i].value);
153
+ }
154
+ return result;
155
+ }),
156
+ },
157
+ /**
158
+ * Color operations
159
+ */
160
+ color: {
161
+ /**
162
+ * SET - Replace color
163
+ */
164
+ set: ((values) => {
165
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
166
+ return sorted[0].value;
167
+ }),
168
+ /**
169
+ * BLEND - Average colors
170
+ */
171
+ blend: ((values) => {
172
+ const rgbs = values.map((v) => hexToRgb(v.value));
173
+ const avgR = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.r, 0) / rgbs.length);
174
+ const avgG = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.g, 0) / rgbs.length);
175
+ const avgB = Math.round(rgbs.reduce((sum, rgb) => sum + rgb.b, 0) / rgbs.length);
176
+ return rgbToHex(avgR, avgG, avgB);
177
+ }),
178
+ },
179
+ // ============================================
180
+ // COLLECTIONS
181
+ // ============================================
182
+ /**
183
+ * Array operations
184
+ */
185
+ array: {
186
+ /**
187
+ * SET - Replace entire array
188
+ */
189
+ set: ((values) => {
190
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
191
+ return sorted[0].value;
192
+ }),
193
+ /**
194
+ * UNION - Merge unique elements
195
+ */
196
+ union: ((values) => {
197
+ const allElements = values.flatMap((v) => v.value);
198
+ return [...new Set(allElements)];
199
+ }),
200
+ /**
201
+ * APPEND - Append all (ordered by lamport)
202
+ */
203
+ append: ((values) => {
204
+ const sorted = [...values].sort((a, b) => a.lamportTime - b.lamportTime);
205
+ return sorted.flatMap((v) => v.value);
206
+ }),
207
+ },
208
+ /**
209
+ * Object operations
210
+ */
211
+ object: {
212
+ /**
213
+ * SET - Replace entire object
214
+ */
215
+ set: ((values) => {
216
+ const sorted = [...values].sort((a, b) => b.lamportTime - a.lamportTime);
217
+ return sorted[0].value;
218
+ }),
219
+ /**
220
+ * LWW_PER_KEY - Last-Write-Wins per key
221
+ */
222
+ lwwPerKey: ((values) => {
223
+ const result = {};
224
+ const latestTimes = {};
225
+ for (const v of values) {
226
+ for (const [key, value] of Object.entries(v.value)) {
227
+ if (!latestTimes[key] || v.lamportTime > latestTimes[key]) {
228
+ result[key] = value;
229
+ latestTimes[key] = v.lamportTime;
230
+ }
231
+ }
232
+ }
233
+ return result;
234
+ }),
235
+ },
236
+ // ============================================
237
+ // SPECIAL
238
+ // ============================================
239
+ /**
240
+ * Immutable - Cannot be changed
241
+ */
242
+ immutable: {
243
+ set: ((values) => {
244
+ // Return first value (creation value)
245
+ const sorted = [...values].sort((a, b) => a.lamportTime - b.lamportTime);
246
+ return sorted[0].value;
247
+ }),
248
+ },
249
+ };
250
+ /**
251
+ * Helper: Multiply quaternions
252
+ */
253
+ function multiplyQuaternions(a, b) {
254
+ const [ax, ay, az, aw] = a;
255
+ const [bx, by, bz, bw] = b;
256
+ return [
257
+ aw * bx + ax * bw + ay * bz - az * by,
258
+ aw * by - ax * bz + ay * bw + az * bx,
259
+ aw * bz + ax * by - ay * bx + az * bw,
260
+ aw * bw - ax * bx - ay * by - az * bz,
261
+ ];
262
+ }
263
+ /**
264
+ * Helper: Hex to RGB
265
+ */
266
+ function hexToRgb(hex) {
267
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
268
+ return result
269
+ ? {
270
+ r: parseInt(result[1], 16),
271
+ g: parseInt(result[2], 16),
272
+ b: parseInt(result[3], 16),
273
+ }
274
+ : { r: 0, g: 0, b: 0 };
275
+ }
276
+ /**
277
+ * Helper: RGB to Hex
278
+ */
279
+ function rgbToHex(r, g, b) {
280
+ return '#' + [r, g, b].map((x) => x.toString(16).padStart(2, '0')).join('');
281
+ }
282
+ //# sourceMappingURL=DType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DType.js","sourceRoot":"","sources":["../../src/state/DType.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAg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AAC;AAC9E,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Schema - Property schema definitions
3
+ *
4
+ * Defines dtype and operation for each property,
5
+ * determining how concurrent updates are merged.
6
+ *
7
+ * Based on test-data/schema-example.ts
8
+ */
9
+ /**
10
+ * Property Schema Definition
11
+ */
12
+ export interface PropertySchema {
13
+ dtype: 'string' | 'number' | 'boolean' | 'vector3' | 'quaternion' | 'color' | 'array' | 'object' | 'any';
14
+ operation: 'set' | 'add' | 'multiply' | 'min' | 'max' | 'or' | 'and' | 'union' | 'append' | 'rga' | 'lww-per-key' | 'lww-per-component' | 'blend' | 'immutable';
15
+ default?: any;
16
+ }
17
+ /**
18
+ * Scene Node Schema
19
+ *
20
+ * Defines merge behavior for all scene node properties.
21
+ */
22
+ export declare const sceneNodeSchema: Record<string, PropertySchema>;
23
+ /**
24
+ * Get schema for a property
25
+ * Returns default schema if not found
26
+ */
27
+ export declare function getPropertySchema(propertyName: string): PropertySchema;
28
+ /**
29
+ * Check if a property is immutable
30
+ */
31
+ export declare function isImmutable(propertyName: string): boolean;
32
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/state/Schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EACD,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,YAAY,GACZ,OAAO,GACP,OAAO,GACP,QAAQ,GACR,KAAK,CAAC;IAEV,SAAS,EACL,KAAK,GACL,KAAK,GACL,UAAU,GACV,KAAK,GACL,KAAK,GACL,IAAI,GACJ,KAAK,GACL,OAAO,GACP,QAAQ,GACR,KAAK,GACL,aAAa,GACb,mBAAmB,GACnB,OAAO,GACP,WAAW,CAAC;IAEhB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAsK1D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAOtE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAGzD"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Schema - Property schema definitions
3
+ *
4
+ * Defines dtype and operation for each property,
5
+ * determining how concurrent updates are merged.
6
+ *
7
+ * Based on test-data/schema-example.ts
8
+ */
9
+ /**
10
+ * Scene Node Schema
11
+ *
12
+ * Defines merge behavior for all scene node properties.
13
+ */
14
+ export const sceneNodeSchema = {
15
+ // ========================================
16
+ // Identity (immutable)
17
+ // ========================================
18
+ id: {
19
+ dtype: 'string',
20
+ operation: 'immutable',
21
+ },
22
+ tag: {
23
+ dtype: 'string',
24
+ operation: 'immutable',
25
+ },
26
+ key: {
27
+ dtype: 'string',
28
+ operation: 'set',
29
+ default: '',
30
+ },
31
+ name: {
32
+ dtype: 'string',
33
+ operation: 'set',
34
+ default: '',
35
+ },
36
+ // ========================================
37
+ // Tree Structure
38
+ // ========================================
39
+ children: {
40
+ dtype: 'array',
41
+ operation: 'set', // Phase 2: Simple LWW
42
+ default: [],
43
+ },
44
+ // ========================================
45
+ // Transform (LWW)
46
+ // ========================================
47
+ 'transform.position': {
48
+ dtype: 'vector3',
49
+ operation: 'set',
50
+ default: [0, 0, 0],
51
+ },
52
+ 'transform.rotation': {
53
+ dtype: 'quaternion',
54
+ operation: 'set',
55
+ default: [0, 0, 0, 1],
56
+ },
57
+ 'transform.scale': {
58
+ dtype: 'vector3',
59
+ operation: 'set',
60
+ default: [1, 1, 1],
61
+ },
62
+ // ========================================
63
+ // Common Properties (LWW)
64
+ // ========================================
65
+ visible: {
66
+ dtype: 'boolean',
67
+ operation: 'set',
68
+ default: true,
69
+ },
70
+ color: {
71
+ dtype: 'color',
72
+ operation: 'set',
73
+ default: '#ffffff',
74
+ },
75
+ opacity: {
76
+ dtype: 'number',
77
+ operation: 'set',
78
+ default: 1.0,
79
+ },
80
+ // ========================================
81
+ // Material Properties (LWW)
82
+ // ========================================
83
+ material: {
84
+ dtype: 'string',
85
+ operation: 'set',
86
+ default: '',
87
+ },
88
+ geometry: {
89
+ dtype: 'string',
90
+ operation: 'set',
91
+ default: '',
92
+ },
93
+ metalness: {
94
+ dtype: 'number',
95
+ operation: 'set',
96
+ default: 0,
97
+ },
98
+ roughness: {
99
+ dtype: 'number',
100
+ operation: 'set',
101
+ default: 1,
102
+ },
103
+ // ========================================
104
+ // Additive Properties
105
+ // ========================================
106
+ score: {
107
+ dtype: 'number',
108
+ operation: 'add',
109
+ default: 0,
110
+ },
111
+ damage: {
112
+ dtype: 'number',
113
+ operation: 'add',
114
+ default: 0,
115
+ },
116
+ // ========================================
117
+ // Collection Properties
118
+ // ========================================
119
+ tags: {
120
+ dtype: 'array',
121
+ operation: 'union',
122
+ default: [],
123
+ },
124
+ // ========================================
125
+ // Object Properties (LWW per key)
126
+ // ========================================
127
+ properties: {
128
+ dtype: 'object',
129
+ operation: 'lww-per-key',
130
+ default: {},
131
+ },
132
+ // ========================================
133
+ // CRDT Metadata
134
+ // ========================================
135
+ clock: {
136
+ dtype: 'object',
137
+ operation: 'lww-per-key',
138
+ default: {},
139
+ },
140
+ lamportTime: {
141
+ dtype: 'number',
142
+ operation: 'set',
143
+ default: 0,
144
+ },
145
+ createdAt: {
146
+ dtype: 'number',
147
+ operation: 'immutable',
148
+ },
149
+ updatedAt: {
150
+ dtype: 'number',
151
+ operation: 'set',
152
+ },
153
+ deletedAt: {
154
+ dtype: 'number',
155
+ operation: 'set',
156
+ },
157
+ };
158
+ /**
159
+ * Get schema for a property
160
+ * Returns default schema if not found
161
+ */
162
+ export function getPropertySchema(propertyName) {
163
+ return (sceneNodeSchema[propertyName] || {
164
+ dtype: 'any',
165
+ operation: 'set', // Default to LWW
166
+ });
167
+ }
168
+ /**
169
+ * Check if a property is immutable
170
+ */
171
+ export function isImmutable(propertyName) {
172
+ const schema = getPropertySchema(propertyName);
173
+ return schema.operation === 'immutable';
174
+ }
175
+ //# sourceMappingURL=Schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/state/Schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAmC;IAC7D,2CAA2C;IAC3C,uBAAuB;IACvB,2CAA2C;IAC3C,EAAE,EAAE;QACF,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,WAAW;KACvB;IAED,GAAG,EAAE;QACH,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,WAAW;KACvB;IAED,GAAG,EAAE;QACH,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,EAAE;KACZ;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,EAAE;KACZ;IAED,2CAA2C;IAC3C,iBAAiB;IACjB,2CAA2C;IAC3C,QAAQ,EAAE;QACR,KAAK,EAAE,OAAO;QACd,SAAS,EAAE,KAAK,EAAE,sBAAsB;QACxC,OAAO,EAAE,EAAE;KACZ;IAED,2CAA2C;IAC3C,kBAAkB;IAClB,2CAA2C;IAC3C,oBAAoB,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACnB;IAED,oBAAoB,EAAE;QACpB,KAAK,EAAE,YAAY;QACnB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACtB;IAED,iBAAiB,EAAE;QACjB,KAAK,EAAE,SAAS;QAChB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,CAAC,CAAC,EAAE,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;QACf,SAAS,EAAE,aAAa;QACxB,OAAO,EAAE,EAAE;KACZ;IAED,2CAA2C;IAC3C,gBAAgB;IAChB,2CAA2C;IAC3C,KAAK,EAAE;QACL,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,aAAa;QACxB,OAAO,EAAE,EAAE;KACZ;IAED,WAAW,EAAE;QACX,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,CAAC;KACX;IAED,SAAS,EAAE;QACT,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,WAAW;KACvB;IAED,SAAS,EAAE;QACT,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,KAAK;KACjB;IAED,SAAS,EAAE;QACT,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,OAAO,CACL,eAAe,CAAC,YAAY,CAAC,IAAI;QAC/B,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,KAAK,EAAE,iBAAiB;KACpC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * VectorClock - CRDT-inspired vector clock implementation
3
+ *
4
+ * Vector clocks provide causal ordering of operations in a distributed system.
5
+ * Each session maintains a counter, and clocks are compared to detect:
6
+ * - Causal ordering (A happened before B)
7
+ * - Concurrent operations (A and B are independent)
8
+ */
9
+ export type VectorClock = Record<string, number>;
10
+ export declare class VectorClockManager {
11
+ /**
12
+ * Create a new vector clock for a session
13
+ * Initializes the session's counter to 0
14
+ */
15
+ create(sessionId: string): VectorClock;
16
+ /**
17
+ * Increment the counter for a session
18
+ * Returns a new clock (immutable)
19
+ */
20
+ increment(clock: VectorClock, sessionId: string): VectorClock;
21
+ /**
22
+ * Merge two vector clocks
23
+ * Takes the maximum value for each session
24
+ * Used when receiving remote operations
25
+ */
26
+ merge(clock1: VectorClock, clock2: VectorClock): VectorClock;
27
+ /**
28
+ * Compare two vector clocks
29
+ *
30
+ * Returns:
31
+ * 1 if clock1 > clock2 (clock1 causally after clock2)
32
+ * -1 if clock1 < clock2 (clock1 causally before clock2)
33
+ * 0 if concurrent (neither causally precedes the other)
34
+ */
35
+ compare(clock1: VectorClock, clock2: VectorClock): number;
36
+ /**
37
+ * Check if two operations are concurrent
38
+ * (neither causally precedes the other)
39
+ */
40
+ areConcurrent(clock1: VectorClock, clock2: VectorClock): boolean;
41
+ }
42
+ //# sourceMappingURL=VectorClock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorClock.d.ts","sourceRoot":"","sources":["../../src/state/VectorClock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD,qBAAa,kBAAkB;IAC7B;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW;IAItC;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW;IAQ7D;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,WAAW;IAU5D;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM;IAmCzD;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO;CAGjE"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * VectorClock - CRDT-inspired vector clock implementation
3
+ *
4
+ * Vector clocks provide causal ordering of operations in a distributed system.
5
+ * Each session maintains a counter, and clocks are compared to detect:
6
+ * - Causal ordering (A happened before B)
7
+ * - Concurrent operations (A and B are independent)
8
+ */
9
+ export class VectorClockManager {
10
+ /**
11
+ * Create a new vector clock for a session
12
+ * Initializes the session's counter to 0
13
+ */
14
+ create(sessionId) {
15
+ return { [sessionId]: 0 };
16
+ }
17
+ /**
18
+ * Increment the counter for a session
19
+ * Returns a new clock (immutable)
20
+ */
21
+ increment(clock, sessionId) {
22
+ const currentValue = clock[sessionId] || 0;
23
+ return {
24
+ ...clock,
25
+ [sessionId]: currentValue + 1,
26
+ };
27
+ }
28
+ /**
29
+ * Merge two vector clocks
30
+ * Takes the maximum value for each session
31
+ * Used when receiving remote operations
32
+ */
33
+ merge(clock1, clock2) {
34
+ const merged = { ...clock1 };
35
+ Object.entries(clock2).forEach(([sessionId, count]) => {
36
+ merged[sessionId] = Math.max(merged[sessionId] || 0, count);
37
+ });
38
+ return merged;
39
+ }
40
+ /**
41
+ * Compare two vector clocks
42
+ *
43
+ * Returns:
44
+ * 1 if clock1 > clock2 (clock1 causally after clock2)
45
+ * -1 if clock1 < clock2 (clock1 causally before clock2)
46
+ * 0 if concurrent (neither causally precedes the other)
47
+ */
48
+ compare(clock1, clock2) {
49
+ const allSessionIds = new Set([
50
+ ...Object.keys(clock1),
51
+ ...Object.keys(clock2),
52
+ ]);
53
+ let clock1Greater = false;
54
+ let clock2Greater = false;
55
+ allSessionIds.forEach((sessionId) => {
56
+ const val1 = clock1[sessionId] || 0;
57
+ const val2 = clock2[sessionId] || 0;
58
+ if (val1 > val2) {
59
+ clock1Greater = true;
60
+ }
61
+ if (val2 > val1) {
62
+ clock2Greater = true;
63
+ }
64
+ });
65
+ // If clock1 is greater in all dimensions, it causally follows clock2
66
+ if (clock1Greater && !clock2Greater) {
67
+ return 1;
68
+ }
69
+ // If clock2 is greater in all dimensions, it causally follows clock1
70
+ if (clock2Greater && !clock1Greater) {
71
+ return -1;
72
+ }
73
+ // Otherwise, they are concurrent (or identical)
74
+ return 0;
75
+ }
76
+ /**
77
+ * Check if two operations are concurrent
78
+ * (neither causally precedes the other)
79
+ */
80
+ areConcurrent(clock1, clock2) {
81
+ return this.compare(clock1, clock2) === 0;
82
+ }
83
+ }
84
+ //# sourceMappingURL=VectorClock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorClock.js","sourceRoot":"","sources":["../../src/state/VectorClock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,OAAO,kBAAkB;IAC7B;;;OAGG;IACH,MAAM,CAAC,SAAiB;QACtB,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,KAAkB,EAAE,SAAiB;QAC7C,MAAM,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO;YACL,GAAG,KAAK;YACR,CAAC,SAAS,CAAC,EAAE,YAAY,GAAG,CAAC;SAC9B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAmB,EAAE,MAAmB;QAC5C,MAAM,MAAM,GAAgB,EAAE,GAAG,MAAM,EAAE,CAAC;QAE1C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;YACpD,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,MAAmB,EAAE,MAAmB;QAC9C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;YAC5B,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACtB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,CAAC,CAAC;QAEH,IAAI,aAAa,GAAG,KAAK,CAAC;QAC1B,IAAI,aAAa,GAAG,KAAK,CAAC;QAE1B,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAClC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAEpC,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;gBAChB,aAAa,GAAG,IAAI,CAAC;YACvB,CAAC;YACD,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;gBAChB,aAAa,GAAG,IAAI,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,qEAAqE;QACrE,IAAI,aAAa,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,qEAAqE;QACrE,IAAI,aAAa,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QAED,gDAAgD;QAChD,OAAO,CAAC,CAAC;IACX,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,MAAmB,EAAE,MAAmB;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * State module exports
3
+ *
4
+ * - VectorClock: Used by client for causal ordering
5
+ * - DType, Schema, ConflictResolver: Server-side conflict resolution for concurrent updates
6
+ */
7
+ export { VectorClockManager, type VectorClock } from './VectorClock.js';
8
+ export { DType, type ValueWithMeta, type MergeFn } from './DType.js';
9
+ export { sceneNodeSchema, getPropertySchema, isImmutable, type PropertySchema } from './Schema.js';
10
+ export { ConflictResolver } from './ConflictResolver.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxE,OAAO,EAAE,KAAK,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * State module exports
3
+ *
4
+ * - VectorClock: Used by client for causal ordering
5
+ * - DType, Schema, ConflictResolver: Server-side conflict resolution for concurrent updates
6
+ */
7
+ // Vector clock (used by client and server)
8
+ export { VectorClockManager } from './VectorClock.js';
9
+ // Server-side conflict resolution utilities
10
+ export { DType } from './DType.js';
11
+ export { sceneNodeSchema, getPropertySchema, isImmutable } from './Schema.js';
12
+ export { ConflictResolver } from './ConflictResolver.js';
13
+ //# sourceMappingURL=index.js.map