@signaltree/enterprise 4.0.7 → 4.0.9

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 (42) hide show
  1. package/LICENSE +54 -0
  2. package/package.json +1 -1
  3. package/src/lib/diff-engine.spec.ts +384 -0
  4. package/src/lib/diff-engine.ts +351 -0
  5. package/src/lib/enterprise-enhancer.ts +136 -0
  6. package/src/lib/enterprise.spec.ts +7 -0
  7. package/src/lib/enterprise.ts +3 -0
  8. package/src/lib/path-index.spec.ts +290 -0
  9. package/src/lib/path-index.ts +320 -0
  10. package/src/lib/scheduler.ts +16 -0
  11. package/src/lib/thread-pools.ts +11 -0
  12. package/src/lib/update-engine.spec.ts +93 -0
  13. package/src/lib/update-engine.ts +399 -0
  14. package/src/test-setup.ts +6 -0
  15. package/src/types/signaltree-core.d.ts +4 -0
  16. package/src/index.js +0 -10
  17. package/src/index.js.map +0 -1
  18. package/src/lib/diff-engine.d.ts +0 -108
  19. package/src/lib/diff-engine.js +0 -236
  20. package/src/lib/diff-engine.js.map +0 -1
  21. package/src/lib/enterprise-enhancer.d.ts +0 -81
  22. package/src/lib/enterprise-enhancer.js +0 -78
  23. package/src/lib/enterprise-enhancer.js.map +0 -1
  24. package/src/lib/enterprise.d.ts +0 -1
  25. package/src/lib/enterprise.js +0 -7
  26. package/src/lib/enterprise.js.map +0 -1
  27. package/src/lib/path-index.d.ts +0 -119
  28. package/src/lib/path-index.js +0 -265
  29. package/src/lib/path-index.js.map +0 -1
  30. package/src/lib/scheduler.d.ts +0 -2
  31. package/src/lib/scheduler.js +0 -25
  32. package/src/lib/scheduler.js.map +0 -1
  33. package/src/lib/thread-pools.d.ts +0 -4
  34. package/src/lib/thread-pools.js +0 -14
  35. package/src/lib/thread-pools.js.map +0 -1
  36. package/src/lib/update-engine.d.ts +0 -115
  37. package/src/lib/update-engine.js +0 -287
  38. package/src/lib/update-engine.js.map +0 -1
  39. package/src/test-setup.d.ts +0 -1
  40. package/src/test-setup.js +0 -8
  41. package/src/test-setup.js.map +0 -1
  42. /package/src/{index.d.ts → index.ts} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,54 @@
1
+ BUSINESS SOURCE LICENSE 1.1
2
+
3
+ Copyright (c) 2025 Jonathan D Borgia
4
+
5
+ This Business Source License 1.1 ("License") governs the use of the software and associated documentation files (the "Software"). You are granted a limited license to use the Software under the terms of this License.
6
+
7
+ 1. Definitions
8
+
9
+ "Change Date" means the date on which the Change License set out in section 6 will apply to the Software. The Change Date for this release is 2028-09-05.
10
+
11
+ "Change License" means the open source license that will apply to the Software on and after the Change Date. The Change License for this release is the MIT License.
12
+
13
+ "Licensor" means the copyright owner granting rights under this License (Jonathan D Borgia).
14
+
15
+ "You" ("Licensee") means an individual or legal entity exercising rights under this License who has not violated the terms of this License or had their rights terminated.
16
+
17
+ 2. License Grant
18
+
19
+ Subject to the terms and conditions of this License, Licensor hereby grants You a non-exclusive, non-transferable, worldwide license to use, reproduce, display, perform, and distribute the Software, and to make modifications and derivative works for internal use, until the Change Date.
20
+
21
+ 3. Commercial Use
22
+
23
+ You may use the Software in commercial applications, including for providing services, selling products that include the Software, or otherwise exploiting the Software commercially, subject to the other terms of this License.
24
+
25
+ 4. Limitations and Conditions
26
+
27
+ a. You may not remove or alter this License, the copyright notice, or notices of the Change Date.
28
+
29
+ b. You may not publicly offer a modified version of the Software that would directly compete with Licensor's public offering of the Software if doing so would circumvent the intent of this License.
30
+
31
+ c. Except as expressly provided in this License, no rights are granted to You under any patent or trademark of Licensor.
32
+
33
+ 5. Disclaimer and Limitation of Liability
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. TO THE FULLEST EXTENT PERMITTED BY LAW, LICENSOR WILL NOT BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM OR RELATING TO THE SOFTWARE.
36
+
37
+ 6. Change License
38
+
39
+ On and after the Change Date specified above, the Software will be licensed under the Change License (MIT License) on the same terms and conditions as set forth by that Change License.
40
+
41
+ 7. Governing Law
42
+
43
+ This License will be governed by and construed in accordance with the laws of the State of New York, USA, without regard to conflict of law principles.
44
+
45
+ 8. Accepting this License
46
+
47
+ You accept this License by copying, modifying, or distributing the Software or any portion thereof.
48
+
49
+ ---
50
+
51
+ LICENSE NOTE
52
+
53
+ - Original license file replaced on 2025-09-05 to Business Source License 1.1. Change Date: 2028-09-05. Change License: MIT.
54
+ or standard modifications for your own applications.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaltree/enterprise",
3
- "version": "4.0.7",
3
+ "version": "4.0.9",
4
4
  "description": "Enterprise-grade optimizations for SignalTree. Provides diff-based updates, bulk operation optimization, and advanced change tracking for large-scale applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -0,0 +1,384 @@
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
+ });