@signaltree/enterprise 4.0.3 → 4.0.6

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.
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OptimizedUpdateEngine = void 0;
4
+ const core_1 = require("@angular/core");
5
+ const diff_engine_1 = require("./diff-engine");
6
+ const path_index_1 = require("./path-index");
7
+ /**
8
+ * OptimizedUpdateEngine
9
+ *
10
+ * High-performance update engine using path indexing and diffing to minimize
11
+ * unnecessary signal updates.
12
+ *
13
+ * Features:
14
+ * - Diff-based updates (only update what changed)
15
+ * - Path indexing for O(k) lookups
16
+ * - Automatic batching for large updates
17
+ * - Priority-based patch ordering
18
+ * - Skip unchanged values
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const tree = signalTree(data, { useLazySignals: true });
23
+ * const engine = new OptimizedUpdateEngine(tree);
24
+ *
25
+ * // Optimized update - only changes what's different
26
+ * const result = engine.update({
27
+ * user: { name: 'Alice' } // Only updates if name changed
28
+ * });
29
+ *
30
+ * console.log(result.changedPaths); // ['user.name']
31
+ * console.log(result.duration); // ~2ms
32
+ * ```
33
+ */
34
+ class OptimizedUpdateEngine {
35
+ constructor(tree) {
36
+ this.pathIndex = new path_index_1.PathIndex();
37
+ this.diffEngine = new diff_engine_1.DiffEngine();
38
+ // Build initial index
39
+ this.pathIndex.buildFromTree(tree);
40
+ }
41
+ /**
42
+ * Update tree with optimizations
43
+ *
44
+ * @param tree - Current tree state
45
+ * @param updates - Updates to apply
46
+ * @param options - Update options
47
+ * @returns Update result
48
+ */
49
+ update(tree, updates, options = {}) {
50
+ const startTime = performance.now();
51
+ // Step 1: Generate diff to find actual changes
52
+ const diffOptions = {};
53
+ if (options.maxDepth !== undefined)
54
+ diffOptions.maxDepth = options.maxDepth;
55
+ if (options.ignoreArrayOrder !== undefined)
56
+ diffOptions.ignoreArrayOrder = options.ignoreArrayOrder;
57
+ if (options.equalityFn !== undefined)
58
+ diffOptions.equalityFn = options.equalityFn;
59
+ const diff = this.diffEngine.diff(tree, updates, diffOptions);
60
+ if (diff.changes.length === 0) {
61
+ // No actual changes, skip update entirely
62
+ return {
63
+ changed: false,
64
+ duration: performance.now() - startTime,
65
+ changedPaths: [],
66
+ };
67
+ }
68
+ // Step 2: Convert diff to optimized patches
69
+ const patches = this.createPatches(diff.changes);
70
+ // Step 3: Sort patches for optimal application order
71
+ const sortedPatches = this.sortPatches(patches);
72
+ // Step 4: Apply patches with optional batching
73
+ const result = options.batch
74
+ ? this.batchApplyPatches(tree, sortedPatches, options.batchSize)
75
+ : this.applyPatches(tree, sortedPatches);
76
+ const duration = performance.now() - startTime;
77
+ return {
78
+ changed: true,
79
+ duration,
80
+ changedPaths: result.appliedPaths,
81
+ stats: {
82
+ totalPaths: diff.changes.length,
83
+ optimizedPaths: patches.length,
84
+ batchedUpdates: result.batchCount,
85
+ },
86
+ };
87
+ }
88
+ /**
89
+ * Rebuild path index from current tree state
90
+ *
91
+ * @param tree - Current tree
92
+ */
93
+ rebuildIndex(tree) {
94
+ this.pathIndex.clear();
95
+ this.pathIndex.buildFromTree(tree);
96
+ }
97
+ /**
98
+ * Get path index statistics
99
+ */
100
+ getIndexStats() {
101
+ return this.pathIndex.getStats();
102
+ }
103
+ /**
104
+ * Creates optimized patches from diff changes
105
+ */
106
+ createPatches(changes) {
107
+ const patches = [];
108
+ const processedPaths = new Set();
109
+ for (const change of changes) {
110
+ const pathStr = change.path.join('.');
111
+ // Skip if parent path already processed (optimization)
112
+ let skipPath = false;
113
+ for (const processed of processedPaths) {
114
+ if (pathStr.startsWith(processed + '.')) {
115
+ skipPath = true;
116
+ break;
117
+ }
118
+ }
119
+ if (skipPath) {
120
+ continue;
121
+ }
122
+ // Create patch based on change type
123
+ const patch = this.createPatch(change);
124
+ patches.push(patch);
125
+ // Mark path as processed
126
+ processedPaths.add(pathStr);
127
+ // If this is an object replacement, skip child paths
128
+ if (change.type === diff_engine_1.ChangeType.REPLACE &&
129
+ typeof change.value === 'object') {
130
+ processedPaths.add(pathStr);
131
+ }
132
+ }
133
+ return patches;
134
+ }
135
+ /**
136
+ * Creates a single patch from a change
137
+ */
138
+ createPatch(change) {
139
+ return {
140
+ type: change.type,
141
+ path: change.path,
142
+ value: change.value,
143
+ oldValue: change.oldValue,
144
+ priority: this.calculatePriority(change),
145
+ signal: this.pathIndex.get(change.path),
146
+ };
147
+ }
148
+ /**
149
+ * Calculates update priority for optimal ordering
150
+ */
151
+ calculatePriority(change) {
152
+ let priority = 0;
153
+ // Shallow updates have higher priority
154
+ priority += (10 - change.path.length) * 10;
155
+ // Array updates have lower priority (more expensive)
156
+ if (change.path.some((p) => typeof p === 'number')) {
157
+ priority -= 20;
158
+ }
159
+ // Replace operations have higher priority than nested updates
160
+ if (change.type === diff_engine_1.ChangeType.REPLACE) {
161
+ priority += 30;
162
+ }
163
+ return priority;
164
+ }
165
+ /**
166
+ * Sorts patches for optimal application
167
+ */
168
+ sortPatches(patches) {
169
+ return patches.sort((a, b) => {
170
+ // Sort by priority (higher first)
171
+ if (a.priority !== b.priority) {
172
+ return b.priority - a.priority;
173
+ }
174
+ // Then by path depth (shallow first)
175
+ return a.path.length - b.path.length;
176
+ });
177
+ }
178
+ /**
179
+ * Applies patches directly (no batching)
180
+ */
181
+ applyPatches(tree, patches) {
182
+ const appliedPaths = [];
183
+ let updateCount = 0;
184
+ for (const patch of patches) {
185
+ if (this.applyPatch(patch, tree)) {
186
+ appliedPaths.push(patch.path.join('.'));
187
+ updateCount++;
188
+ }
189
+ }
190
+ return {
191
+ appliedPaths,
192
+ updateCount,
193
+ batchCount: 1,
194
+ };
195
+ }
196
+ /**
197
+ * Applies patches with batching for better performance
198
+ */
199
+ batchApplyPatches(tree, patches, batchSize = 50) {
200
+ const batches = [];
201
+ for (let i = 0; i < patches.length; i += batchSize) {
202
+ batches.push(patches.slice(i, i + batchSize));
203
+ }
204
+ const appliedPaths = [];
205
+ let updateCount = 0;
206
+ // Process patches in batches
207
+ for (const currentBatch of batches) {
208
+ for (const patch of currentBatch) {
209
+ if (this.applyPatch(patch, tree)) {
210
+ appliedPaths.push(patch.path.join('.'));
211
+ updateCount++;
212
+ }
213
+ }
214
+ }
215
+ return {
216
+ appliedPaths,
217
+ updateCount,
218
+ batchCount: batches.length,
219
+ };
220
+ }
221
+ /**
222
+ * Applies a single patch to the tree object
223
+ */
224
+ applyPatch(patch, tree) {
225
+ try {
226
+ // First, try to update via signal if available
227
+ if (patch.signal && (0, core_1.isSignal)(patch.signal) && 'set' in patch.signal) {
228
+ const currentValue = patch.signal();
229
+ // Only update if value actually changed
230
+ if (this.isEqual(currentValue, patch.value)) {
231
+ return false;
232
+ }
233
+ // Update the signal - this will handle reactivity
234
+ patch.signal.set(patch.value);
235
+ // After successful ADD, update the index
236
+ if (patch.type === diff_engine_1.ChangeType.ADD && patch.value !== undefined) {
237
+ this.pathIndex.set(patch.path, patch.signal);
238
+ }
239
+ return true;
240
+ } // Fallback: Navigate to parent object and update directly
241
+ let current = tree;
242
+ for (let i = 0; i < patch.path.length - 1; i++) {
243
+ const key = patch.path[i];
244
+ current = current[key];
245
+ if (!current || typeof current !== 'object') {
246
+ return false;
247
+ }
248
+ }
249
+ const lastKey = patch.path[patch.path.length - 1];
250
+ // Only update if value actually changed
251
+ if (this.isEqual(current[lastKey], patch.value)) {
252
+ return false;
253
+ }
254
+ // Apply update directly to object
255
+ current[lastKey] = patch.value;
256
+ return true;
257
+ }
258
+ catch (error) {
259
+ console.error(`Failed to apply patch at ${patch.path.join('.')}:`, error);
260
+ return false;
261
+ }
262
+ }
263
+ /**
264
+ * Check equality
265
+ */
266
+ isEqual(a, b) {
267
+ // Fast path for primitives
268
+ if (a === b) {
269
+ return true;
270
+ }
271
+ if (typeof a !== typeof b) {
272
+ return false;
273
+ }
274
+ if (typeof a !== 'object' || a === null || b === null) {
275
+ return false;
276
+ }
277
+ // Deep equality for objects (simple version)
278
+ try {
279
+ return JSON.stringify(a) === JSON.stringify(b);
280
+ }
281
+ catch (_a) {
282
+ return false;
283
+ }
284
+ }
285
+ }
286
+ exports.OptimizedUpdateEngine = OptimizedUpdateEngine;
287
+ //# sourceMappingURL=update-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-engine.js","sourceRoot":"","sources":["../../../../../packages/enterprise/src/lib/update-engine.ts"],"names":[],"mappings":";;;AAAA,wCAAyC;AAEzC,+CAAuD;AACvD,6CAAyC;AA8DzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,qBAAqB;IAIhC,YAAY,IAAa;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAS,EAAE,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,wBAAU,EAAE,CAAC;QAEnC,sBAAsB;QACtB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CACJ,IAAa,EACb,OAAgB,EAChB,UAAyB,EAAE;QAE3B,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEpC,+CAA+C;QAC/C,MAAM,WAAW,GAAyB,EAAE,CAAC;QAC7C,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS;YAAE,WAAW,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC5E,IAAI,OAAO,CAAC,gBAAgB,KAAK,SAAS;YACxC,WAAW,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QAC1D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAClC,WAAW,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAE9C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAE9D,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EA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C,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD;;OAEG;IACK,OAAO,CAAC,CAAU,EAAE,CAAU;QACpC,2BAA2B;QAC3B,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACtD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,6CAA6C;QAC7C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAlTD,sDAkTC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const zone_1 = require("jest-preset-angular/setup-env/zone");
4
+ (0, zone_1.setupZoneTestEnv)({
5
+ errorOnUnknownElements: true,
6
+ errorOnUnknownProperties: true,
7
+ });
8
+ //# sourceMappingURL=test-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../packages/enterprise/src/test-setup.ts"],"names":[],"mappings":";;AAAA,6DAAsE;AAEtE,IAAA,uBAAgB,EAAC;IACf,sBAAsB,EAAE,IAAI;IAC5B,wBAAwB,EAAE,IAAI;CAC/B,CAAC,CAAC"}
package/README.md DELETED
@@ -1,203 +0,0 @@
1
- # @signaltree/enterprise
2
-
3
- Enterprise-grade optimizations for SignalTree. Designed for large-scale applications with 500+ signals and high-frequency bulk updates.
4
-
5
- ## Features
6
-
7
- - **Diff-based updates** - Only update signals that actually changed
8
- - **Bulk operation optimization** - 2-5x faster for large state updates
9
- - **Advanced change tracking** - Detailed statistics and monitoring
10
- - **Path indexing** - Optimized signal lookup for large trees
11
- - **Lazy initialization** - Zero overhead until first use
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @signaltree/core @signaltree/enterprise
17
- ```
18
-
19
- ## Quick Start
20
-
21
- ```typescript
22
- import { signalTree } from '@signaltree/core';
23
- import { withEnterprise } from '@signaltree/enterprise';
24
-
25
- const tree = signalTree(largeState).with(withEnterprise());
26
-
27
- // Use optimized bulk updates
28
- const result = tree.updateOptimized(newData, {
29
- ignoreArrayOrder: true,
30
- maxDepth: 10,
31
- });
32
-
33
- console.log(result.stats);
34
- // { totalChanges: 45, adds: 10, updates: 30, deletes: 5 }
35
- ```
36
-
37
- ## When to Use
38
-
39
- ### ✅ Use @signaltree/enterprise when:
40
-
41
- - You have 500+ signals in your state tree
42
- - Bulk updates happen at high frequency (60Hz+)
43
- - You need real-time dashboards or data feeds
44
- - You're building enterprise-scale applications
45
- - You need detailed update monitoring and statistics
46
-
47
- ### ❌ Skip @signaltree/enterprise when:
48
-
49
- - Small to medium apps (<100 signals)
50
- - Infrequent state updates
51
- - Startup/prototype projects
52
- - Bundle size is critical (adds +2.4KB gzipped)
53
-
54
- ## API
55
-
56
- ### `withEnterprise()`
57
-
58
- Enhancer that adds enterprise optimizations to a SignalTree.
59
-
60
- ```typescript
61
- import { signalTree } from '@signaltree/core';
62
- import { withEnterprise } from '@signaltree/enterprise';
63
-
64
- const tree = signalTree(initialState).with(withEnterprise());
65
- ```
66
-
67
- ### `tree.updateOptimized(updates, options?)`
68
-
69
- Performs optimized bulk updates using diff-based change detection.
70
-
71
- **Parameters:**
72
-
73
- - `updates: Partial<T>` - The new state values
74
- - `options?: UpdateOptions` - Configuration options
75
-
76
- **Options:**
77
-
78
- ```typescript
79
- {
80
- maxDepth?: number; // Maximum depth to traverse (default: 100)
81
- ignoreArrayOrder?: boolean; // Ignore array element order (default: false)
82
- equalityFn?: (a, b) => boolean; // Custom equality function
83
- autoBatch?: boolean; // Automatically batch updates (default: true)
84
- batchSize?: number; // Patches per batch (default: 10)
85
- }
86
- ```
87
-
88
- **Returns:**
89
-
90
- ```typescript
91
- {
92
- changed: boolean; // Whether any changes were made
93
- stats: {
94
- totalChanges: number; // Total number of changes
95
- adds: number; // New properties added
96
- updates: number; // Properties updated
97
- deletes: number; // Properties deleted
98
- }
99
- }
100
- ```
101
-
102
- ### `tree.getPathIndex()`
103
-
104
- Get the PathIndex for debugging/monitoring. Returns `null` if `updateOptimized` hasn't been called yet (lazy initialization).
105
-
106
- ```typescript
107
- const index = tree.getPathIndex();
108
- if (index) {
109
- console.log('Path index active');
110
- }
111
- ```
112
-
113
- ## Examples
114
-
115
- ### Real-time Dashboard
116
-
117
- ```typescript
118
- import { signalTree } from '@signaltree/core';
119
- import { withEnterprise } from '@signaltree/enterprise';
120
-
121
- interface DashboardState {
122
- metrics: Record<string, number>;
123
- alerts: Alert[];
124
- users: User[];
125
- // ... hundreds more properties
126
- }
127
-
128
- const dashboard = signalTree<DashboardState>(initialState).with(withEnterprise());
129
-
130
- // High-frequency updates from WebSocket
131
- socket.on('metrics', (newMetrics) => {
132
- const result = dashboard.updateOptimized({ metrics: newMetrics }, { ignoreArrayOrder: true });
133
-
134
- console.log(`Updated ${result.stats.updates} metrics`);
135
- });
136
- ```
137
-
138
- ### Data Grid with Bulk Operations
139
-
140
- ```typescript
141
- import { signalTree } from '@signaltree/core';
142
- import { withEnterprise } from '@signaltree/enterprise';
143
-
144
- const grid = signalTree({
145
- rows: [] as GridRow[],
146
- columns: [] as GridColumn[],
147
- filters: {} as FilterState,
148
- selection: new Set<string>(),
149
- }).with(withEnterprise());
150
-
151
- // Bulk update from API
152
- async function loadData() {
153
- const data = await fetchGridData();
154
-
155
- const result = grid.updateOptimized(data, {
156
- maxDepth: 5,
157
- autoBatch: true,
158
- });
159
-
160
- console.log(`Loaded ${result.stats.adds} rows in bulk`);
161
- }
162
- ```
163
-
164
- ### Custom Equality for Complex Objects
165
-
166
- ```typescript
167
- const tree = signalTree(complexState).with(withEnterprise());
168
-
169
- tree.updateOptimized(newState, {
170
- equalityFn: (a, b) => {
171
- // Custom deep equality for specific object types
172
- if (a instanceof Date && b instanceof Date) {
173
- return a.getTime() === b.getTime();
174
- }
175
- return a === b;
176
- },
177
- });
178
- ```
179
-
180
- ## Performance
181
-
182
- **Bundle Size:**
183
-
184
- - Adds +2.4KB gzipped to your bundle
185
- - Zero overhead until first `updateOptimized()` call (lazy initialization)
186
-
187
- **Performance Gains:**
188
-
189
- - 2-5x faster for bulk updates on large state trees
190
- - Scales efficiently with tree depth and complexity
191
- - Minimal memory overhead with path indexing
192
-
193
- ## License
194
-
195
- Business Source License 1.1 (BSL-1.1) - See [LICENSE](../../LICENSE) for details.
196
-
197
- Converts to MIT license on the Change Date specified in the license.
198
-
199
- ## Related Packages
200
-
201
- - [@signaltree/core](../core) - Core SignalTree functionality
202
- - [@signaltree/ng-forms](../ng-forms) - Angular forms integration
203
- - [@signaltree/callable-syntax](../callable-syntax) - Callable syntax transform