@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,119 @@
1
+ /**
2
+ * PathIndex - Fast signal lookup using Trie data structure
3
+ * @packageDocumentation
4
+ */
5
+ import type { WritableSignal } from '@angular/core';
6
+ /**
7
+ * Path segment (string or number for array indices)
8
+ */
9
+ export type PathSegment = string | number;
10
+ /**
11
+ * Path as array of segments
12
+ */
13
+ export type Path = PathSegment[];
14
+ /**
15
+ * PathIndex
16
+ *
17
+ * Fast signal lookup using a Trie (prefix tree) data structure.
18
+ * Provides O(k) lookup time where k is the path length, regardless of total signals.
19
+ *
20
+ * Features:
21
+ * - Trie-based indexing for O(k) lookup
22
+ * - WeakRef caching for memory efficiency
23
+ * - Automatic cleanup of stale references
24
+ * - Prefix matching for batch operations
25
+ * - Path normalization
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const index = new PathIndex();
30
+ *
31
+ * // Index signals
32
+ * index.set(['user', 'name'], nameSignal);
33
+ * index.set(['user', 'email'], emailSignal);
34
+ *
35
+ * // Fast lookup
36
+ * const signal = index.get(['user', 'name']);
37
+ *
38
+ * // Prefix matching
39
+ * const userSignals = index.getByPrefix(['user']);
40
+ * // Returns: { name: nameSignal, email: emailSignal }
41
+ *
42
+ * // Check if path exists
43
+ * if (index.has(['user', 'name'])) {
44
+ * // ...
45
+ * }
46
+ * ```
47
+ */
48
+ export declare class PathIndex<T extends object = WritableSignal<any>> {
49
+ private root;
50
+ private pathCache;
51
+ private stats;
52
+ /**
53
+ * Set a value at the given path
54
+ *
55
+ * @param path - Path segments
56
+ * @param value - Value to store
57
+ */
58
+ set(path: Path, signal: T): void;
59
+ /**
60
+ * Get value at the given path
61
+ *
62
+ * @param path - Path segments
63
+ * @returns Value if found and not GC'd, null otherwise
64
+ */
65
+ get(path: Path): T | null;
66
+ /**
67
+ * Check if path exists in index
68
+ *
69
+ * @param path - Path segments
70
+ * @returns True if path exists and value is not GC'd
71
+ */
72
+ has(path: Path): boolean;
73
+ /**
74
+ * Get all values matching a prefix
75
+ *
76
+ * @param prefix - Path prefix
77
+ * @returns Map of relative paths to values
78
+ */
79
+ getByPrefix(prefix: Path): Map<string, T>;
80
+ /**
81
+ * Delete value at path
82
+ *
83
+ * @param path - Path segments
84
+ * @returns True if deleted, false if not found
85
+ */
86
+ delete(path: Path): boolean;
87
+ /**
88
+ * Clear all entries
89
+ */
90
+ clear(): void;
91
+ /**
92
+ * Get statistics
93
+ *
94
+ * @returns Index statistics
95
+ */
96
+ getStats(): {
97
+ hits: number;
98
+ misses: number;
99
+ sets: number;
100
+ cleanups: number;
101
+ hitRate: number;
102
+ cacheSize: number;
103
+ };
104
+ /**
105
+ * Build index from a tree structure
106
+ *
107
+ * @param tree - Tree object to index
108
+ * @param path - Current path (for recursion)
109
+ */
110
+ buildFromTree(tree: unknown, path?: Path): void;
111
+ /**
112
+ * Convert path to string for caching
113
+ */
114
+ private pathToString;
115
+ /**
116
+ * Collect all descendant values recursively
117
+ */
118
+ private collectDescendants;
119
+ }
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathIndex = void 0;
4
+ const core_1 = require("@angular/core");
5
+ /**
6
+ * Node in the Trie structure
7
+ */
8
+ class TrieNode {
9
+ constructor() {
10
+ this.value = null;
11
+ this.children = new Map();
12
+ }
13
+ }
14
+ /**
15
+ * PathIndex
16
+ *
17
+ * Fast signal lookup using a Trie (prefix tree) data structure.
18
+ * Provides O(k) lookup time where k is the path length, regardless of total signals.
19
+ *
20
+ * Features:
21
+ * - Trie-based indexing for O(k) lookup
22
+ * - WeakRef caching for memory efficiency
23
+ * - Automatic cleanup of stale references
24
+ * - Prefix matching for batch operations
25
+ * - Path normalization
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const index = new PathIndex();
30
+ *
31
+ * // Index signals
32
+ * index.set(['user', 'name'], nameSignal);
33
+ * index.set(['user', 'email'], emailSignal);
34
+ *
35
+ * // Fast lookup
36
+ * const signal = index.get(['user', 'name']);
37
+ *
38
+ * // Prefix matching
39
+ * const userSignals = index.getByPrefix(['user']);
40
+ * // Returns: { name: nameSignal, email: emailSignal }
41
+ *
42
+ * // Check if path exists
43
+ * if (index.has(['user', 'name'])) {
44
+ * // ...
45
+ * }
46
+ * ```
47
+ */
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ class PathIndex {
50
+ constructor() {
51
+ this.root = new TrieNode();
52
+ this.pathCache = new Map();
53
+ this.stats = {
54
+ hits: 0,
55
+ misses: 0,
56
+ sets: 0,
57
+ cleanups: 0,
58
+ };
59
+ }
60
+ /**
61
+ * Set a value at the given path
62
+ *
63
+ * @param path - Path segments
64
+ * @param value - Value to store
65
+ */
66
+ set(path, signal) {
67
+ const pathStr = this.pathToString(path);
68
+ const ref = new WeakRef(signal);
69
+ // Update trie
70
+ let node = this.root;
71
+ for (const segment of path) {
72
+ const key = String(segment);
73
+ if (!node.children.has(key)) {
74
+ node.children.set(key, new TrieNode());
75
+ }
76
+ const nextNode = node.children.get(key);
77
+ if (!nextNode) {
78
+ throw new Error(`Failed to get node for key: ${key}`);
79
+ }
80
+ node = nextNode;
81
+ }
82
+ node.value = ref;
83
+ // Update cache for fast string lookups
84
+ this.pathCache.set(pathStr, ref);
85
+ this.stats.sets++;
86
+ }
87
+ /**
88
+ * Get value at the given path
89
+ *
90
+ * @param path - Path segments
91
+ * @returns Value if found and not GC'd, null otherwise
92
+ */
93
+ get(path) {
94
+ const pathStr = this.pathToString(path);
95
+ // Try cache first
96
+ const cached = this.pathCache.get(pathStr);
97
+ if (cached) {
98
+ const value = cached.deref();
99
+ if (value) {
100
+ this.stats.hits++;
101
+ return value;
102
+ }
103
+ // Clean up dead reference
104
+ this.pathCache.delete(pathStr);
105
+ this.stats.cleanups++;
106
+ }
107
+ // Try trie
108
+ let node = this.root;
109
+ for (const segment of path) {
110
+ const key = String(segment);
111
+ node = node.children.get(key);
112
+ if (!node) {
113
+ this.stats.misses++;
114
+ return null;
115
+ }
116
+ }
117
+ if (node.value) {
118
+ const value = node.value.deref();
119
+ if (value) {
120
+ // Re-cache for next time
121
+ this.pathCache.set(pathStr, node.value);
122
+ this.stats.hits++;
123
+ return value;
124
+ }
125
+ // Clean up dead reference
126
+ node.value = null;
127
+ this.stats.cleanups++;
128
+ }
129
+ this.stats.misses++;
130
+ return null;
131
+ }
132
+ /**
133
+ * Check if path exists in index
134
+ *
135
+ * @param path - Path segments
136
+ * @returns True if path exists and value is not GC'd
137
+ */
138
+ has(path) {
139
+ return this.get(path) !== null;
140
+ }
141
+ /**
142
+ * Get all values matching a prefix
143
+ *
144
+ * @param prefix - Path prefix
145
+ * @returns Map of relative paths to values
146
+ */
147
+ getByPrefix(prefix) {
148
+ const results = new Map();
149
+ // Find the node at prefix
150
+ let node = this.root;
151
+ for (const segment of prefix) {
152
+ const key = String(segment);
153
+ node = node.children.get(key);
154
+ if (!node) {
155
+ return results; // Empty map
156
+ }
157
+ }
158
+ // Collect all descendants
159
+ this.collectDescendants(node, [], results);
160
+ return results;
161
+ }
162
+ /**
163
+ * Delete value at path
164
+ *
165
+ * @param path - Path segments
166
+ * @returns True if deleted, false if not found
167
+ */
168
+ delete(path) {
169
+ const pathStr = this.pathToString(path);
170
+ // Remove from cache
171
+ this.pathCache.delete(pathStr);
172
+ // Remove from trie
173
+ let node = this.root;
174
+ const nodes = [node];
175
+ for (const segment of path) {
176
+ const key = String(segment);
177
+ node = node.children.get(key);
178
+ if (!node) {
179
+ return false;
180
+ }
181
+ nodes.push(node);
182
+ }
183
+ // Clear value
184
+ const hadValue = node.value !== null;
185
+ node.value = null;
186
+ // Clean up empty nodes (from leaf to root)
187
+ for (let i = nodes.length - 1; i > 0; i--) {
188
+ const current = nodes[i];
189
+ if (current.value === null && current.children.size === 0) {
190
+ const parent = nodes[i - 1];
191
+ const segment = path[i - 1];
192
+ parent.children.delete(String(segment));
193
+ }
194
+ else {
195
+ break; // Stop if node has value or children
196
+ }
197
+ }
198
+ return hadValue;
199
+ }
200
+ /**
201
+ * Clear all entries
202
+ */
203
+ clear() {
204
+ this.root = new TrieNode();
205
+ this.pathCache.clear();
206
+ }
207
+ /**
208
+ * Get statistics
209
+ *
210
+ * @returns Index statistics
211
+ */
212
+ getStats() {
213
+ const total = this.stats.hits + this.stats.misses;
214
+ const hitRate = total > 0 ? this.stats.hits / total : 0;
215
+ return Object.assign(Object.assign({}, this.stats), { hitRate, cacheSize: this.pathCache.size });
216
+ }
217
+ /**
218
+ * Build index from a tree structure
219
+ *
220
+ * @param tree - Tree object to index
221
+ * @param path - Current path (for recursion)
222
+ */
223
+ buildFromTree(tree, path = []) {
224
+ if (!tree) {
225
+ return;
226
+ }
227
+ // Check if it's a signal using Angular's isSignal
228
+ if ((0, core_1.isSignal)(tree)) {
229
+ this.set(path, tree);
230
+ return;
231
+ }
232
+ // Only continue if it's an object (not a signal or primitive)
233
+ if (typeof tree !== 'object') {
234
+ return;
235
+ }
236
+ // Recursively index children
237
+ for (const [key, value] of Object.entries(tree)) {
238
+ this.buildFromTree(value, [...path, key]);
239
+ }
240
+ }
241
+ /**
242
+ * Convert path to string for caching
243
+ */
244
+ pathToString(path) {
245
+ return path.join('.');
246
+ }
247
+ /**
248
+ * Collect all descendant values recursively
249
+ */
250
+ collectDescendants(node, currentPath, results) {
251
+ // Add current node's value if it exists
252
+ if (node.value) {
253
+ const value = node.value.deref();
254
+ if (value) {
255
+ results.set(this.pathToString(currentPath), value);
256
+ }
257
+ }
258
+ // Recursively collect children
259
+ for (const [key, child] of node.children) {
260
+ this.collectDescendants(child, [...currentPath, key], results);
261
+ }
262
+ }
263
+ }
264
+ exports.PathIndex = PathIndex;
265
+ //# sourceMappingURL=path-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-index.js","sourceRoot":"","sources":["../../../../../packages/enterprise/src/lib/path-index.ts"],"names":[],"mappings":";;;AAAA,wC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K,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QAED,+BAA+B;QAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF;AAjQD,8BAiQC"}
@@ -0,0 +1,2 @@
1
+ export type Task = () => void;
2
+ export declare function postTask(t: Task): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postTask = postTask;
4
+ const tslib_1 = require("tslib");
5
+ const q = [];
6
+ function postTask(t) {
7
+ q.push(t);
8
+ if (q.length === 1)
9
+ flush();
10
+ }
11
+ function flush() {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ while (q.length) {
14
+ const t = q.shift();
15
+ try {
16
+ t();
17
+ }
18
+ catch (e) {
19
+ console.error('[EnterpriseScheduler]', e);
20
+ }
21
+ yield Promise.resolve();
22
+ }
23
+ });
24
+ }
25
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../../../packages/enterprise/src/lib/scheduler.ts"],"names":[],"mappings":";;AAIA,4BAGC;;AALD,MAAM,CAAC,GAAW,EAAE,CAAC;AAErB,SAAgB,QAAQ,CAAC,CAAO;IAC9B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,SAAe,KAAK;;QAClB,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAG,CAAC;YACrB,IAAI,CAAC;gBAAC,CAAC,EAAE,CAAC;YAAC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBAAC,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;YAAC,CAAC;YACrE,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;CAAA"}
@@ -0,0 +1,4 @@
1
+ export interface WorkerPool {
2
+ run<T>(fn: (...args: any[]) => T, ...args: any[]): Promise<T>;
3
+ }
4
+ export declare function createMockPool(): WorkerPool;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMockPool = createMockPool;
4
+ const tslib_1 = require("tslib");
5
+ function createMockPool() {
6
+ return {
7
+ run(fn, ...args) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ return fn(...args);
10
+ });
11
+ }
12
+ };
13
+ }
14
+ //# sourceMappingURL=thread-pools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread-pools.js","sourceRoot":"","sources":["../../../../../packages/enterprise/src/lib/thread-pools.ts"],"names":[],"mappings":";;AAIA,wCAMC;;AAND,SAAgB,cAAc;IAC5B,OAAO;QACC,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI;;gBACnB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACrB,CAAC;SAAA;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,115 @@
1
+ import { PathIndex } from './path-index';
2
+ import type { DiffOptions } from './diff-engine';
3
+ /**
4
+ * OptimizedUpdateEngine - High-performance tree updates
5
+ * @packageDocumentation
6
+ */
7
+ /**
8
+ * Update options
9
+ */
10
+ export interface UpdateOptions extends DiffOptions {
11
+ /** Whether to batch updates */
12
+ batch?: boolean;
13
+ /** Batch size for chunked updates */
14
+ batchSize?: number;
15
+ }
16
+ /**
17
+ * Update result
18
+ */
19
+ export interface UpdateResult {
20
+ /** Whether any changes were made */
21
+ changed: boolean;
22
+ /** Update duration in milliseconds */
23
+ duration: number;
24
+ /** List of changed paths */
25
+ changedPaths: string[];
26
+ /** Update statistics */
27
+ stats?: {
28
+ totalPaths: number;
29
+ optimizedPaths: number;
30
+ batchedUpdates: number;
31
+ };
32
+ }
33
+ /**
34
+ * OptimizedUpdateEngine
35
+ *
36
+ * High-performance update engine using path indexing and diffing to minimize
37
+ * unnecessary signal updates.
38
+ *
39
+ * Features:
40
+ * - Diff-based updates (only update what changed)
41
+ * - Path indexing for O(k) lookups
42
+ * - Automatic batching for large updates
43
+ * - Priority-based patch ordering
44
+ * - Skip unchanged values
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const tree = signalTree(data, { useLazySignals: true });
49
+ * const engine = new OptimizedUpdateEngine(tree);
50
+ *
51
+ * // Optimized update - only changes what's different
52
+ * const result = engine.update({
53
+ * user: { name: 'Alice' } // Only updates if name changed
54
+ * });
55
+ *
56
+ * console.log(result.changedPaths); // ['user.name']
57
+ * console.log(result.duration); // ~2ms
58
+ * ```
59
+ */
60
+ export declare class OptimizedUpdateEngine {
61
+ private pathIndex;
62
+ private diffEngine;
63
+ constructor(tree: unknown);
64
+ /**
65
+ * Update tree with optimizations
66
+ *
67
+ * @param tree - Current tree state
68
+ * @param updates - Updates to apply
69
+ * @param options - Update options
70
+ * @returns Update result
71
+ */
72
+ update(tree: unknown, updates: unknown, options?: UpdateOptions): UpdateResult;
73
+ /**
74
+ * Rebuild path index from current tree state
75
+ *
76
+ * @param tree - Current tree
77
+ */
78
+ rebuildIndex(tree: unknown): void;
79
+ /**
80
+ * Get path index statistics
81
+ */
82
+ getIndexStats(): ReturnType<PathIndex['getStats']>;
83
+ /**
84
+ * Creates optimized patches from diff changes
85
+ */
86
+ private createPatches;
87
+ /**
88
+ * Creates a single patch from a change
89
+ */
90
+ private createPatch;
91
+ /**
92
+ * Calculates update priority for optimal ordering
93
+ */
94
+ private calculatePriority;
95
+ /**
96
+ * Sorts patches for optimal application
97
+ */
98
+ private sortPatches;
99
+ /**
100
+ * Applies patches directly (no batching)
101
+ */
102
+ private applyPatches;
103
+ /**
104
+ * Applies patches with batching for better performance
105
+ */
106
+ private batchApplyPatches;
107
+ /**
108
+ * Applies a single patch to the tree object
109
+ */
110
+ private applyPatch;
111
+ /**
112
+ * Check equality
113
+ */
114
+ private isEqual;
115
+ }