@signaltree/enterprise 4.0.9 → 4.0.12
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/package.json +1 -1
- package/src/index.js +10 -0
- package/src/index.js.map +1 -0
- package/src/lib/diff-engine.d.ts +108 -0
- package/src/lib/diff-engine.js +236 -0
- package/src/lib/diff-engine.js.map +1 -0
- package/src/lib/enterprise-enhancer.d.ts +81 -0
- package/src/lib/enterprise-enhancer.js +78 -0
- package/src/lib/enterprise-enhancer.js.map +1 -0
- package/src/lib/enterprise.d.ts +1 -0
- package/src/lib/enterprise.js +7 -0
- package/src/lib/enterprise.js.map +1 -0
- package/src/lib/path-index.d.ts +119 -0
- package/src/lib/path-index.js +265 -0
- package/src/lib/path-index.js.map +1 -0
- package/src/lib/scheduler.d.ts +2 -0
- package/src/lib/scheduler.js +25 -0
- package/src/lib/scheduler.js.map +1 -0
- package/src/lib/thread-pools.d.ts +4 -0
- package/src/lib/thread-pools.js +14 -0
- package/src/lib/thread-pools.js.map +1 -0
- package/src/lib/update-engine.d.ts +115 -0
- package/src/lib/update-engine.js +287 -0
- package/src/lib/update-engine.js.map +1 -0
- package/src/test-setup.d.ts +1 -0
- package/src/test-setup.js +8 -0
- package/src/test-setup.js.map +1 -0
- package/LICENSE +0 -54
- package/src/lib/diff-engine.spec.ts +0 -384
- package/src/lib/diff-engine.ts +0 -351
- package/src/lib/enterprise-enhancer.ts +0 -136
- package/src/lib/enterprise.spec.ts +0 -7
- package/src/lib/enterprise.ts +0 -3
- package/src/lib/path-index.spec.ts +0 -290
- package/src/lib/path-index.ts +0 -320
- package/src/lib/scheduler.ts +0 -16
- package/src/lib/thread-pools.ts +0 -11
- package/src/lib/update-engine.spec.ts +0 -93
- package/src/lib/update-engine.ts +0 -399
- package/src/test-setup.ts +0 -6
- package/src/types/signaltree-core.d.ts +0 -4
- /package/src/{index.ts → index.d.ts} +0 -0
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import { ChangeType, DiffEngine } from './diff-engine';
|
|
2
|
-
|
|
3
|
-
describe('DiffEngine', () => {
|
|
4
|
-
let engine: DiffEngine;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
engine = new DiffEngine();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('primitive values', () => {
|
|
11
|
-
it('should detect primitive changes', () => {
|
|
12
|
-
const current = { value: 42 };
|
|
13
|
-
const updates = { value: 43 };
|
|
14
|
-
|
|
15
|
-
const diff = engine.diff(current, updates);
|
|
16
|
-
|
|
17
|
-
expect(diff.hasChanges).toBe(true);
|
|
18
|
-
expect(diff.changes).toHaveLength(1);
|
|
19
|
-
expect(diff.changes[0]).toEqual({
|
|
20
|
-
type: ChangeType.UPDATE,
|
|
21
|
-
path: ['value'],
|
|
22
|
-
value: 43,
|
|
23
|
-
oldValue: 42,
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should detect no changes when values are equal', () => {
|
|
28
|
-
const current = { value: 42 };
|
|
29
|
-
const updates = { value: 42 };
|
|
30
|
-
|
|
31
|
-
const diff = engine.diff(current, updates);
|
|
32
|
-
|
|
33
|
-
expect(diff.hasChanges).toBe(false);
|
|
34
|
-
expect(diff.changes).toHaveLength(0);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should detect additions', () => {
|
|
38
|
-
const current = {};
|
|
39
|
-
const updates = { newField: 'hello' };
|
|
40
|
-
|
|
41
|
-
const diff = engine.diff(current, updates);
|
|
42
|
-
|
|
43
|
-
expect(diff.hasChanges).toBe(true);
|
|
44
|
-
expect(diff.changes[0].type).toBe(ChangeType.ADD);
|
|
45
|
-
expect(diff.changes[0].value).toBe('hello');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should detect null values correctly', () => {
|
|
49
|
-
const current = { value: null };
|
|
50
|
-
const updates = { value: 'not null' };
|
|
51
|
-
|
|
52
|
-
const diff = engine.diff(current, updates);
|
|
53
|
-
|
|
54
|
-
expect(diff.hasChanges).toBe(true);
|
|
55
|
-
expect(diff.changes[0].oldValue).toBeNull();
|
|
56
|
-
expect(diff.changes[0].value).toBe('not null');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('nested objects', () => {
|
|
61
|
-
it('should detect deep changes', () => {
|
|
62
|
-
const current = {
|
|
63
|
-
user: {
|
|
64
|
-
profile: {
|
|
65
|
-
name: 'Alice',
|
|
66
|
-
age: 30,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const updates = {
|
|
72
|
-
user: {
|
|
73
|
-
profile: {
|
|
74
|
-
name: 'Alice',
|
|
75
|
-
age: 31, // Changed
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const diff = engine.diff(current, updates);
|
|
81
|
-
|
|
82
|
-
expect(diff.hasChanges).toBe(true);
|
|
83
|
-
expect(diff.changes).toHaveLength(1);
|
|
84
|
-
expect(diff.changes[0]).toEqual({
|
|
85
|
-
type: ChangeType.UPDATE,
|
|
86
|
-
path: ['user', 'profile', 'age'],
|
|
87
|
-
value: 31,
|
|
88
|
-
oldValue: 30,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should detect multiple changes', () => {
|
|
93
|
-
const current = {
|
|
94
|
-
name: 'Alice',
|
|
95
|
-
age: 30,
|
|
96
|
-
city: 'NYC',
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const updates = {
|
|
100
|
-
name: 'Alice',
|
|
101
|
-
age: 31, // Changed
|
|
102
|
-
city: 'SF', // Changed
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const diff = engine.diff(current, updates);
|
|
106
|
-
|
|
107
|
-
expect(diff.hasChanges).toBe(true);
|
|
108
|
-
expect(diff.changes).toHaveLength(2);
|
|
109
|
-
|
|
110
|
-
const paths = diff.changes.map((c) => c.path.join('.'));
|
|
111
|
-
expect(paths).toContain('age');
|
|
112
|
-
expect(paths).toContain('city');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should handle partial updates', () => {
|
|
116
|
-
const current = {
|
|
117
|
-
user: {
|
|
118
|
-
name: 'Alice',
|
|
119
|
-
age: 30,
|
|
120
|
-
email: 'alice@example.com',
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const updates = {
|
|
125
|
-
user: {
|
|
126
|
-
age: 31, // Only updating age
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const diff = engine.diff(current, updates);
|
|
131
|
-
|
|
132
|
-
expect(diff.hasChanges).toBe(true);
|
|
133
|
-
expect(diff.changes).toHaveLength(1);
|
|
134
|
-
expect(diff.changes[0].path).toEqual(['user', 'age']);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('arrays', () => {
|
|
139
|
-
it('should detect array element changes (ordered)', () => {
|
|
140
|
-
const current = { items: [1, 2, 3] };
|
|
141
|
-
const updates = { items: [1, 4, 3] }; // Changed index 1
|
|
142
|
-
|
|
143
|
-
const diff = engine.diff(current, updates);
|
|
144
|
-
|
|
145
|
-
expect(diff.hasChanges).toBe(true);
|
|
146
|
-
expect(diff.changes).toHaveLength(1);
|
|
147
|
-
expect(diff.changes[0]).toEqual({
|
|
148
|
-
type: ChangeType.UPDATE,
|
|
149
|
-
path: ['items', 1],
|
|
150
|
-
value: 4,
|
|
151
|
-
oldValue: 2,
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should detect array additions', () => {
|
|
156
|
-
const current = { items: [1, 2] };
|
|
157
|
-
const updates = { items: [1, 2, 3] }; // Added element
|
|
158
|
-
|
|
159
|
-
const diff = engine.diff(current, updates);
|
|
160
|
-
|
|
161
|
-
expect(diff.hasChanges).toBe(true);
|
|
162
|
-
const addition = diff.changes.find((c) => c.type === ChangeType.ADD);
|
|
163
|
-
expect(addition).toBeDefined();
|
|
164
|
-
expect(addition?.path).toEqual(['items', 2]);
|
|
165
|
-
expect(addition?.value).toBe(3);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should handle empty arrays', () => {
|
|
169
|
-
const current = { items: [] };
|
|
170
|
-
const updates = { items: [1] };
|
|
171
|
-
|
|
172
|
-
const diff = engine.diff(current, updates);
|
|
173
|
-
|
|
174
|
-
expect(diff.hasChanges).toBe(true);
|
|
175
|
-
expect(diff.changes[0].type).toBe(ChangeType.ADD);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should handle nested arrays', () => {
|
|
179
|
-
const current = {
|
|
180
|
-
matrix: [
|
|
181
|
-
[1, 2],
|
|
182
|
-
[3, 4],
|
|
183
|
-
],
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const updates = {
|
|
187
|
-
matrix: [
|
|
188
|
-
[1, 2],
|
|
189
|
-
[3, 5], // Changed [1][1]
|
|
190
|
-
],
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const diff = engine.diff(current, updates);
|
|
194
|
-
|
|
195
|
-
expect(diff.hasChanges).toBe(true);
|
|
196
|
-
expect(diff.changes[0].path).toEqual(['matrix', 1, 1]);
|
|
197
|
-
expect(diff.changes[0].value).toBe(5);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe('type changes', () => {
|
|
202
|
-
it('should detect object to primitive as update', () => {
|
|
203
|
-
const current = { value: { nested: 'object' } };
|
|
204
|
-
const updates = { value: 'string' }; // Type changed
|
|
205
|
-
|
|
206
|
-
const diff = engine.diff(current, updates);
|
|
207
|
-
|
|
208
|
-
expect(diff.hasChanges).toBe(true);
|
|
209
|
-
// Nested object to primitive is UPDATE, not REPLACE
|
|
210
|
-
expect(diff.changes[0].type).toBe(ChangeType.UPDATE);
|
|
211
|
-
expect(diff.changes[0].path).toEqual(['value']);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should replace object with array', () => {
|
|
215
|
-
const current = { data: { a: 1 } };
|
|
216
|
-
const updates = { data: [1, 2, 3] };
|
|
217
|
-
|
|
218
|
-
const diff = engine.diff(current, updates);
|
|
219
|
-
|
|
220
|
-
expect(diff.changes[0].type).toBe(ChangeType.REPLACE);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should replace array with object', () => {
|
|
224
|
-
const current = { data: [1, 2, 3] };
|
|
225
|
-
const updates = { data: { a: 1 } };
|
|
226
|
-
|
|
227
|
-
const diff = engine.diff(current, updates);
|
|
228
|
-
|
|
229
|
-
expect(diff.changes[0].type).toBe(ChangeType.REPLACE);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe('options', () => {
|
|
234
|
-
it('should respect maxDepth option', () => {
|
|
235
|
-
const current = {
|
|
236
|
-
level1: {
|
|
237
|
-
level2: {
|
|
238
|
-
level3: {
|
|
239
|
-
level4: {
|
|
240
|
-
deep: 'value',
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const updates = {
|
|
248
|
-
level1: {
|
|
249
|
-
level2: {
|
|
250
|
-
level3: {
|
|
251
|
-
level4: {
|
|
252
|
-
deep: 'changed',
|
|
253
|
-
},
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const diff = engine.diff(current, updates, { maxDepth: 2 });
|
|
260
|
-
|
|
261
|
-
// Should stop at depth 2, so level3+ changes won't be detected
|
|
262
|
-
expect(diff.changes).toHaveLength(0);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('should detect deletions when enabled', () => {
|
|
266
|
-
const current = { a: 1, b: 2, c: 3 };
|
|
267
|
-
const updates = { a: 1, b: 2 }; // 'c' deleted
|
|
268
|
-
|
|
269
|
-
const diff = engine.diff(current, updates, { detectDeletions: true });
|
|
270
|
-
|
|
271
|
-
const deletion = diff.changes.find((c) => c.type === ChangeType.DELETE);
|
|
272
|
-
expect(deletion).toBeDefined();
|
|
273
|
-
expect(deletion?.path).toEqual(['c']);
|
|
274
|
-
expect(deletion?.oldValue).toBe(3);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('should not detect deletions by default', () => {
|
|
278
|
-
const current = { a: 1, b: 2 };
|
|
279
|
-
const updates = { a: 1 }; // 'b' deleted
|
|
280
|
-
|
|
281
|
-
const diff = engine.diff(current, updates);
|
|
282
|
-
|
|
283
|
-
const deletion = diff.changes.find((c) => c.type === ChangeType.DELETE);
|
|
284
|
-
expect(deletion).toBeUndefined();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should use custom equality function', () => {
|
|
288
|
-
const current = { value: '42' };
|
|
289
|
-
const updates = { value: 42 }; // Different type, same value
|
|
290
|
-
|
|
291
|
-
// Default behavior - detects change
|
|
292
|
-
const diff1 = engine.diff(current, updates);
|
|
293
|
-
expect(diff1.hasChanges).toBe(true);
|
|
294
|
-
|
|
295
|
-
// Custom equality - coerce types
|
|
296
|
-
const diff2 = engine.diff(current, updates, {
|
|
297
|
-
equalityFn: (a, b) => String(a) === String(b),
|
|
298
|
-
});
|
|
299
|
-
expect(diff2.hasChanges).toBe(false);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it('should handle ignoreArrayOrder option', () => {
|
|
303
|
-
const current = { items: [1, 2, 3] };
|
|
304
|
-
const updates = { items: [3, 2, 1] }; // Same values, different order
|
|
305
|
-
|
|
306
|
-
// With ignoreArrayOrder, should detect no changes
|
|
307
|
-
const diff = engine.diff(current, updates, { ignoreArrayOrder: true });
|
|
308
|
-
|
|
309
|
-
expect(diff.hasChanges).toBe(false);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
describe('edge cases', () => {
|
|
314
|
-
it('should handle circular references', () => {
|
|
315
|
-
interface Circular {
|
|
316
|
-
a: number;
|
|
317
|
-
self?: Circular;
|
|
318
|
-
}
|
|
319
|
-
const circular: Circular = { a: 1 };
|
|
320
|
-
circular.self = circular;
|
|
321
|
-
|
|
322
|
-
const updates = { a: 2, self: circular };
|
|
323
|
-
|
|
324
|
-
// Should not throw or hang
|
|
325
|
-
expect(() => {
|
|
326
|
-
engine.diff(circular, updates);
|
|
327
|
-
}).not.toThrow();
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it('should handle undefined values', () => {
|
|
331
|
-
const current = { value: undefined };
|
|
332
|
-
const updates = { value: 'defined' };
|
|
333
|
-
|
|
334
|
-
const diff = engine.diff(current, updates);
|
|
335
|
-
|
|
336
|
-
expect(diff.hasChanges).toBe(true);
|
|
337
|
-
expect(diff.changes[0].oldValue).toBeUndefined();
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
describe('performance', () => {
|
|
342
|
-
it('should handle large objects efficiently', () => {
|
|
343
|
-
const current = {
|
|
344
|
-
items: Array.from({ length: 1000 }, (_, i) => ({
|
|
345
|
-
id: i,
|
|
346
|
-
value: i,
|
|
347
|
-
})),
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
const updates = {
|
|
351
|
-
items: Array.from({ length: 1000 }, (_, i) => ({
|
|
352
|
-
id: i,
|
|
353
|
-
value: i === 500 ? 999 : i, // Only change one item
|
|
354
|
-
})),
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
const start = performance.now();
|
|
358
|
-
const diff = engine.diff(current, updates);
|
|
359
|
-
const duration = performance.now() - start;
|
|
360
|
-
|
|
361
|
-
// Should detect only the one change
|
|
362
|
-
expect(diff.changes).toHaveLength(1);
|
|
363
|
-
expect(diff.changes[0].path).toEqual(['items', 500, 'value']);
|
|
364
|
-
|
|
365
|
-
// Should be reasonably fast
|
|
366
|
-
expect(duration).toBeLessThan(100); // < 100ms for 1000 items
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('should skip dangerous keys during diff', () => {
|
|
370
|
-
const current = {};
|
|
371
|
-
const updates = {
|
|
372
|
-
__proto__: { polluted: true },
|
|
373
|
-
safe: 'value',
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
const diff = engine.diff(current, updates, {
|
|
377
|
-
keyValidator: (key) => !['__proto__', 'constructor'].includes(key),
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
expect(diff.changes.map((c) => c.path[0])).not.toContain('__proto__');
|
|
381
|
-
expect(diff.changes.map((c) => c.path[0])).toContain('safe');
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
});
|