@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,150 @@
1
+ /**
2
+ * Tests for vector operations: vector3, quaternion
3
+ */
4
+
5
+ import { describe, it, expect, beforeEach } from '@jest/globals';
6
+ import { readFileSync } from 'fs';
7
+ import { join, dirname } from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import { createEmptyGraph, applyMessage } from '../../src/index.js';
10
+ import type { SceneGraph, CRDTMessage, Operation } from '../../src/operations/OperationTypes.js';
11
+
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+
14
+ interface OpFixture {
15
+ name: string;
16
+ op: Operation;
17
+ }
18
+
19
+ function loadOps(filename: string): OpFixture[] {
20
+ const filepath = join(__dirname, '../fixtures', filename);
21
+ const content = readFileSync(filepath, 'utf-8');
22
+ return content
23
+ .trim()
24
+ .split('\n')
25
+ .map((line) => JSON.parse(line));
26
+ }
27
+
28
+ function createMsg(op: Operation, lamport = 1): CRDTMessage {
29
+ return {
30
+ id: `msg-${Math.random().toString(36).slice(2)}`,
31
+ sessionId: 'test-session',
32
+ clock: { 'test-session': lamport },
33
+ lamportTime: lamport,
34
+ timestamp: Date.now(),
35
+ ops: [op],
36
+ };
37
+ }
38
+
39
+ function createNodeWithProps(
40
+ graph: SceneGraph,
41
+ key: string,
42
+ props: Record<string, unknown>
43
+ ): SceneGraph {
44
+ const nodeOp: Operation = {
45
+ key: '',
46
+ otype: 'node.insert',
47
+ path: 'children',
48
+ value: {
49
+ key,
50
+ id: `uuid-${key}`,
51
+ tag: 'Mesh',
52
+ name: key,
53
+ ...props,
54
+ },
55
+ };
56
+ return applyMessage(graph, createMsg(nodeOp, 0));
57
+ }
58
+
59
+ describe('Vector3 Operations', () => {
60
+ let vectorOps: OpFixture[];
61
+ let graph: SceneGraph;
62
+
63
+ beforeEach(() => {
64
+ vectorOps = loadOps('vector-ops.jsonl');
65
+ graph = createEmptyGraph();
66
+ graph = createNodeWithProps(graph, 'node-1', {
67
+ position: [0, 0, 0],
68
+ scale: [1, 1, 1],
69
+ });
70
+ });
71
+
72
+ it('vector3.set should replace value', () => {
73
+ const op = vectorOps.find((f) => f.name === 'vector3_set')!.op;
74
+ const result = applyMessage(graph, createMsg(op));
75
+ expect(result.nodes['node-1'].position).toEqual([1, 2, 3]);
76
+ });
77
+
78
+ it('vector3.set to zero should work', () => {
79
+ graph = createNodeWithProps(createEmptyGraph(), 'node-1', { position: [5, 5, 5] });
80
+ const op = vectorOps.find((f) => f.name === 'vector3_set_zero')!.op;
81
+ const result = applyMessage(graph, createMsg(op));
82
+ expect(result.nodes['node-1'].position).toEqual([0, 0, 0]);
83
+ });
84
+
85
+ it('vector3.add should add components', () => {
86
+ const op = vectorOps.find((f) => f.name === 'vector3_add')!.op;
87
+ const result = applyMessage(graph, createMsg(op));
88
+ expect(result.nodes['node-1'].position).toEqual([0.5, 0.5, 0.5]);
89
+ });
90
+
91
+ it('vector3.add with negative should subtract', () => {
92
+ graph = createNodeWithProps(createEmptyGraph(), 'node-1', { position: [5, 5, 5] });
93
+ const op = vectorOps.find((f) => f.name === 'vector3_add_negative')!.op;
94
+ const result = applyMessage(graph, createMsg(op));
95
+ expect(result.nodes['node-1'].position).toEqual([4, 4, 4]);
96
+ });
97
+
98
+ it('vector3.multiply should multiply components', () => {
99
+ const op = vectorOps.find((f) => f.name === 'vector3_multiply')!.op;
100
+ const result = applyMessage(graph, createMsg(op));
101
+ expect(result.nodes['node-1'].scale).toEqual([2, 2, 2]);
102
+ });
103
+
104
+ it('vector3.multiply non-uniform should scale each component', () => {
105
+ const op = vectorOps.find((f) => f.name === 'vector3_multiply_non_uniform')!.op;
106
+ const result = applyMessage(graph, createMsg(op));
107
+ expect(result.nodes['node-1'].scale).toEqual([1, 2, 3]);
108
+ });
109
+
110
+ it('vector3.add should accumulate multiple operations', () => {
111
+ const op = vectorOps.find((f) => f.name === 'vector3_add')!.op;
112
+ let result = applyMessage(graph, createMsg(op, 1));
113
+ result = applyMessage(result, createMsg(op, 2));
114
+ result = applyMessage(result, createMsg(op, 3));
115
+ expect(result.nodes['node-1'].position).toEqual([1.5, 1.5, 1.5]);
116
+ });
117
+ });
118
+
119
+ describe('Quaternion Operations', () => {
120
+ let vectorOps: OpFixture[];
121
+ let graph: SceneGraph;
122
+
123
+ beforeEach(() => {
124
+ vectorOps = loadOps('vector-ops.jsonl');
125
+ graph = createEmptyGraph();
126
+ graph = createNodeWithProps(graph, 'node-1', {
127
+ rotation: [0, 0, 0, 1], // identity quaternion
128
+ });
129
+ });
130
+
131
+ it('quaternion.set should replace value', () => {
132
+ const op = vectorOps.find((f) => f.name === 'quaternion_set')!.op;
133
+ const result = applyMessage(graph, createMsg(op));
134
+ expect(result.nodes['node-1'].rotation).toEqual([0, 0, 0, 1]);
135
+ });
136
+
137
+ it('quaternion.set with rotation should work', () => {
138
+ const op = vectorOps.find((f) => f.name === 'quaternion_set_rotated')!.op;
139
+ const result = applyMessage(graph, createMsg(op));
140
+ expect(result.nodes['node-1'].rotation).toEqual([0, 0.7071, 0, 0.7071]);
141
+ });
142
+
143
+ it('quaternion.multiply should compose rotations', () => {
144
+ const op = vectorOps.find((f) => f.name === 'quaternion_multiply')!.op;
145
+ const result = applyMessage(graph, createMsg(op));
146
+ // Result is the composed rotation
147
+ expect(result.nodes['node-1'].rotation).toBeDefined();
148
+ expect(Array.isArray(result.nodes['node-1'].rotation)).toBe(true);
149
+ });
150
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2023", "DOM"],
7
+ "jsx": "react-jsx",
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "rootDir": "./src",
13
+ "strict": true,
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "resolveJsonModule": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "noEmit": true,
6
+ "isolatedModules": true
7
+ },
8
+ "include": ["src/**/*", "tests/**/*"]
9
+ }