@danielsimonjr/memory-mcp 11.0.1 → 11.1.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 (172) hide show
  1. package/LICENSE +22 -22
  2. package/dist/core/EntityManager.d.ts +10 -15
  3. package/dist/core/EntityManager.d.ts.map +1 -1
  4. package/dist/core/EntityManager.js +21 -54
  5. package/dist/core/GraphStorage.d.ts +0 -51
  6. package/dist/core/GraphStorage.d.ts.map +1 -1
  7. package/dist/core/GraphStorage.js +2 -79
  8. package/dist/core/GraphTraversal.d.ts +2 -7
  9. package/dist/core/GraphTraversal.d.ts.map +1 -1
  10. package/dist/core/GraphTraversal.js +2 -19
  11. package/dist/core/ManagerContext.d.ts +0 -4
  12. package/dist/core/ManagerContext.d.ts.map +1 -1
  13. package/dist/core/ManagerContext.js +2 -12
  14. package/dist/core/RelationManager.d.ts.map +1 -1
  15. package/dist/core/RelationManager.js +4 -5
  16. package/dist/core/SQLiteStorage.d.ts.map +1 -1
  17. package/dist/core/SQLiteStorage.js +2 -3
  18. package/dist/core/TransactionManager.d.ts +2 -207
  19. package/dist/core/TransactionManager.d.ts.map +1 -1
  20. package/dist/core/TransactionManager.js +6 -482
  21. package/dist/core/index.d.ts +1 -2
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +1 -3
  24. package/dist/features/ArchiveManager.d.ts +2 -14
  25. package/dist/features/ArchiveManager.d.ts.map +1 -1
  26. package/dist/features/ArchiveManager.js +3 -44
  27. package/dist/features/CompressionManager.d.ts +4 -14
  28. package/dist/features/CompressionManager.d.ts.map +1 -1
  29. package/dist/features/CompressionManager.js +9 -74
  30. package/dist/features/IOManager.d.ts +2 -6
  31. package/dist/features/IOManager.d.ts.map +1 -1
  32. package/dist/features/IOManager.js +10 -105
  33. package/dist/features/StreamingExporter.d.ts +4 -27
  34. package/dist/features/StreamingExporter.d.ts.map +1 -1
  35. package/dist/features/StreamingExporter.js +4 -65
  36. package/dist/features/index.d.ts +0 -2
  37. package/dist/features/index.d.ts.map +1 -1
  38. package/dist/features/index.js +0 -3
  39. package/dist/search/EmbeddingService.d.ts +9 -108
  40. package/dist/search/EmbeddingService.d.ts.map +1 -1
  41. package/dist/search/EmbeddingService.js +15 -187
  42. package/dist/search/FuzzySearch.js +1 -1
  43. package/dist/search/SavedSearchManager.d.ts.map +1 -1
  44. package/dist/search/SavedSearchManager.js +2 -3
  45. package/dist/search/SearchManager.d.ts +1 -42
  46. package/dist/search/SearchManager.d.ts.map +1 -1
  47. package/dist/search/SearchManager.js +0 -115
  48. package/dist/search/SemanticSearch.d.ts +1 -4
  49. package/dist/search/SemanticSearch.d.ts.map +1 -1
  50. package/dist/search/SemanticSearch.js +2 -12
  51. package/dist/search/TFIDFIndexManager.d.ts +0 -88
  52. package/dist/search/TFIDFIndexManager.d.ts.map +1 -1
  53. package/dist/search/TFIDFIndexManager.js +0 -217
  54. package/dist/search/index.d.ts +1 -18
  55. package/dist/search/index.d.ts.map +1 -1
  56. package/dist/search/index.js +1 -32
  57. package/dist/server/MCPServer.d.ts.map +1 -1
  58. package/dist/server/MCPServer.js +4 -1
  59. package/dist/server/responseCompressor.js +5 -5
  60. package/dist/server/toolDefinitions.d.ts.map +1 -1
  61. package/dist/server/toolDefinitions.js +5 -1
  62. package/dist/server/toolHandlers.d.ts +9 -5
  63. package/dist/server/toolHandlers.d.ts.map +1 -1
  64. package/dist/server/toolHandlers.js +23 -8
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/types.d.ts +2 -579
  68. package/dist/types/types.d.ts.map +1 -1
  69. package/dist/utils/compressedCache.d.ts +0 -29
  70. package/dist/utils/compressedCache.d.ts.map +1 -1
  71. package/dist/utils/compressedCache.js +0 -39
  72. package/dist/utils/entityUtils.d.ts +1 -59
  73. package/dist/utils/entityUtils.d.ts.map +1 -1
  74. package/dist/utils/entityUtils.js +3 -113
  75. package/dist/utils/errors.d.ts +0 -18
  76. package/dist/utils/errors.d.ts.map +1 -1
  77. package/dist/utils/errors.js +0 -24
  78. package/dist/utils/index.d.ts +2 -6
  79. package/dist/utils/index.d.ts.map +1 -1
  80. package/dist/utils/index.js +2 -14
  81. package/dist/utils/logger.d.ts +0 -7
  82. package/dist/utils/logger.d.ts.map +1 -1
  83. package/dist/utils/logger.js +2 -9
  84. package/dist/utils/parallelUtils.d.ts +1 -5
  85. package/dist/utils/parallelUtils.d.ts.map +1 -1
  86. package/dist/utils/parallelUtils.js +1 -23
  87. package/dist/utils/schemas.d.ts +16 -16
  88. package/dist/utils/schemas.d.ts.map +1 -1
  89. package/dist/utils/schemas.js +12 -12
  90. package/dist/utils/taskScheduler.d.ts +0 -4
  91. package/dist/utils/taskScheduler.d.ts.map +1 -1
  92. package/dist/utils/taskScheduler.js +1 -21
  93. package/dist/workers/WorkerPool.d.ts +81 -0
  94. package/dist/workers/WorkerPool.d.ts.map +1 -0
  95. package/dist/workers/WorkerPool.js +121 -0
  96. package/dist/workers/index.d.ts +1 -1
  97. package/dist/workers/index.d.ts.map +1 -1
  98. package/dist/workers/levenshteinWorker.js +1 -1
  99. package/package.json +1 -4
  100. package/dist/__tests__/file-path.test.js +0 -119
  101. package/dist/__tests__/knowledge-graph.test.js +0 -318
  102. package/dist/core/GraphEventEmitter.d.ts +0 -202
  103. package/dist/core/GraphEventEmitter.d.ts.map +0 -1
  104. package/dist/core/GraphEventEmitter.js +0 -346
  105. package/dist/features/KeywordExtractor.d.ts +0 -61
  106. package/dist/features/KeywordExtractor.d.ts.map +0 -1
  107. package/dist/features/KeywordExtractor.js +0 -126
  108. package/dist/features/ObservationNormalizer.d.ts +0 -90
  109. package/dist/features/ObservationNormalizer.d.ts.map +0 -1
  110. package/dist/features/ObservationNormalizer.js +0 -193
  111. package/dist/memory.jsonl +0 -1
  112. package/dist/search/BM25Search.d.ts +0 -148
  113. package/dist/search/BM25Search.d.ts.map +0 -1
  114. package/dist/search/BM25Search.js +0 -339
  115. package/dist/search/EarlyTerminationManager.d.ts +0 -140
  116. package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
  117. package/dist/search/EarlyTerminationManager.js +0 -279
  118. package/dist/search/EmbeddingCache.d.ts +0 -175
  119. package/dist/search/EmbeddingCache.d.ts.map +0 -1
  120. package/dist/search/EmbeddingCache.js +0 -246
  121. package/dist/search/HybridScorer.d.ts +0 -181
  122. package/dist/search/HybridScorer.d.ts.map +0 -1
  123. package/dist/search/HybridScorer.js +0 -257
  124. package/dist/search/HybridSearchManager.d.ts +0 -80
  125. package/dist/search/HybridSearchManager.d.ts.map +0 -1
  126. package/dist/search/HybridSearchManager.js +0 -187
  127. package/dist/search/IncrementalIndexer.d.ts +0 -201
  128. package/dist/search/IncrementalIndexer.d.ts.map +0 -1
  129. package/dist/search/IncrementalIndexer.js +0 -342
  130. package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
  131. package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
  132. package/dist/search/OptimizedInvertedIndex.js +0 -358
  133. package/dist/search/ParallelSearchExecutor.d.ts +0 -172
  134. package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
  135. package/dist/search/ParallelSearchExecutor.js +0 -309
  136. package/dist/search/QuantizedVectorStore.d.ts +0 -171
  137. package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
  138. package/dist/search/QuantizedVectorStore.js +0 -307
  139. package/dist/search/QueryAnalyzer.d.ts +0 -76
  140. package/dist/search/QueryAnalyzer.d.ts.map +0 -1
  141. package/dist/search/QueryAnalyzer.js +0 -227
  142. package/dist/search/QueryCostEstimator.d.ts +0 -244
  143. package/dist/search/QueryCostEstimator.d.ts.map +0 -1
  144. package/dist/search/QueryCostEstimator.js +0 -652
  145. package/dist/search/QueryPlanCache.d.ts +0 -220
  146. package/dist/search/QueryPlanCache.d.ts.map +0 -1
  147. package/dist/search/QueryPlanCache.js +0 -379
  148. package/dist/search/QueryPlanner.d.ts +0 -58
  149. package/dist/search/QueryPlanner.d.ts.map +0 -1
  150. package/dist/search/QueryPlanner.js +0 -137
  151. package/dist/search/ReflectionManager.d.ts +0 -120
  152. package/dist/search/ReflectionManager.d.ts.map +0 -1
  153. package/dist/search/ReflectionManager.js +0 -231
  154. package/dist/search/SymbolicSearch.d.ts +0 -61
  155. package/dist/search/SymbolicSearch.d.ts.map +0 -1
  156. package/dist/search/SymbolicSearch.js +0 -163
  157. package/dist/search/TFIDFEventSync.d.ts +0 -85
  158. package/dist/search/TFIDFEventSync.d.ts.map +0 -1
  159. package/dist/search/TFIDFEventSync.js +0 -133
  160. package/dist/utils/BatchProcessor.d.ts +0 -271
  161. package/dist/utils/BatchProcessor.d.ts.map +0 -1
  162. package/dist/utils/BatchProcessor.js +0 -376
  163. package/dist/utils/MemoryMonitor.d.ts +0 -176
  164. package/dist/utils/MemoryMonitor.d.ts.map +0 -1
  165. package/dist/utils/MemoryMonitor.js +0 -305
  166. package/dist/utils/WorkerPoolManager.d.ts +0 -233
  167. package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
  168. package/dist/utils/WorkerPoolManager.js +0 -420
  169. package/dist/utils/operationUtils.d.ts +0 -124
  170. package/dist/utils/operationUtils.d.ts.map +0 -1
  171. package/dist/utils/operationUtils.js +0 -175
  172. package/dist/vitest.config.js +0 -13
@@ -1,420 +0,0 @@
1
- /**
2
- * Worker Pool Manager
3
- *
4
- * Phase 12 Sprint 2: Unified worker pool management for all parallelizable operations.
5
- * Provides centralized lifecycle management, configuration, and statistics.
6
- *
7
- * @module utils/WorkerPoolManager
8
- */
9
- import workerpool from '@danielsimonjr/workerpool';
10
- /**
11
- * Default configuration values.
12
- */
13
- const DEFAULT_CONFIG = {
14
- maxWorkers: Math.max(1, workerpool.cpus - 1),
15
- workerType: 'thread',
16
- workerPath: '',
17
- minParallelSize: 200,
18
- defaultTimeout: 30000,
19
- };
20
- /**
21
- * WorkerPoolManager - Unified worker pool management
22
- *
23
- * Provides centralized management of worker pools for parallel processing.
24
- * Features:
25
- * - Named pool registration with automatic lifecycle management
26
- * - Pool cleanup on process exit
27
- * - Statistics tracking per pool
28
- * - Event callbacks for monitoring
29
- *
30
- * @example
31
- * ```typescript
32
- * const manager = WorkerPoolManager.getInstance();
33
- *
34
- * // Get or create a pool
35
- * const pool = manager.getPool('fuzzySearch', {
36
- * maxWorkers: 4,
37
- * workerPath: '/path/to/worker.js'
38
- * });
39
- *
40
- * // Execute task
41
- * const result = await pool.exec('searchEntities', [data]);
42
- *
43
- * // Get statistics
44
- * const stats = manager.getPoolStats('fuzzySearch');
45
- *
46
- * // Shutdown all pools on exit
47
- * await manager.shutdownAll();
48
- * ```
49
- */
50
- export class WorkerPoolManager {
51
- static instance = null;
52
- pools = new Map();
53
- eventCallbacks = [];
54
- isShuttingDown = false;
55
- shutdownRegistered = false;
56
- /**
57
- * Private constructor for singleton pattern.
58
- */
59
- constructor() {
60
- this.registerShutdownHandlers();
61
- }
62
- /**
63
- * Get the singleton instance of WorkerPoolManager.
64
- *
65
- * @returns The WorkerPoolManager instance
66
- */
67
- static getInstance() {
68
- if (!WorkerPoolManager.instance) {
69
- WorkerPoolManager.instance = new WorkerPoolManager();
70
- }
71
- return WorkerPoolManager.instance;
72
- }
73
- /**
74
- * Reset the singleton instance (primarily for testing).
75
- */
76
- static resetInstance() {
77
- if (WorkerPoolManager.instance) {
78
- WorkerPoolManager.instance.shutdownAll().catch(() => {
79
- // Ignore errors during reset
80
- });
81
- WorkerPoolManager.instance = null;
82
- }
83
- }
84
- /**
85
- * Register process exit handlers for cleanup.
86
- */
87
- registerShutdownHandlers() {
88
- if (this.shutdownRegistered)
89
- return;
90
- this.shutdownRegistered = true;
91
- const shutdownHandler = () => {
92
- if (!this.isShuttingDown) {
93
- this.shutdownAllSync();
94
- }
95
- };
96
- // Register for various exit signals
97
- process.on('exit', shutdownHandler);
98
- process.on('SIGINT', () => {
99
- this.shutdownAll().then(() => process.exit(0)).catch(() => process.exit(1));
100
- });
101
- process.on('SIGTERM', () => {
102
- this.shutdownAll().then(() => process.exit(0)).catch(() => process.exit(1));
103
- });
104
- process.on('uncaughtException', (err) => {
105
- console.error('Uncaught exception:', err);
106
- this.shutdownAllSync();
107
- process.exit(1);
108
- });
109
- }
110
- /**
111
- * Get or create a named worker pool.
112
- *
113
- * If a pool with the given ID exists, returns the existing pool.
114
- * Otherwise, creates a new pool with the provided configuration.
115
- *
116
- * @param poolId - Unique identifier for the pool
117
- * @param config - Pool configuration options
118
- * @returns The worker pool instance
119
- */
120
- getPool(poolId, config = {}) {
121
- const existing = this.pools.get(poolId);
122
- if (existing) {
123
- return existing.pool;
124
- }
125
- return this.createPool(poolId, config);
126
- }
127
- /**
128
- * Create a new worker pool with the given ID.
129
- *
130
- * @param poolId - Unique identifier for the pool
131
- * @param config - Pool configuration options
132
- * @returns The newly created worker pool
133
- * @throws Error if a pool with the same ID already exists
134
- */
135
- createPool(poolId, config = {}) {
136
- if (this.pools.has(poolId)) {
137
- throw new Error(`Pool with ID '${poolId}' already exists`);
138
- }
139
- const mergedConfig = { ...DEFAULT_CONFIG, ...config };
140
- // Create pool options with inline type definition
141
- // Using inline type since WorkerPoolOptions is not directly exported
142
- const poolOptions = {
143
- maxWorkers: mergedConfig.maxWorkers,
144
- workerType: mergedConfig.workerType,
145
- };
146
- // Add worker thread options for ESM support
147
- if (mergedConfig.workerType === 'thread') {
148
- poolOptions.workerThreadOpts = { type: 'module' };
149
- }
150
- // Create pool with or without worker script
151
- let pool;
152
- if (mergedConfig.workerPath) {
153
- pool = workerpool.pool(mergedConfig.workerPath, poolOptions);
154
- }
155
- else {
156
- pool = workerpool.pool(poolOptions);
157
- }
158
- const entry = {
159
- pool,
160
- config: mergedConfig,
161
- createdAt: Date.now(),
162
- totalTasksExecuted: 0,
163
- totalExecutionTime: 0,
164
- };
165
- this.pools.set(poolId, entry);
166
- this.emitEvent(poolId, 'created');
167
- return pool;
168
- }
169
- /**
170
- * Check if a pool with the given ID exists.
171
- *
172
- * @param poolId - Pool identifier to check
173
- * @returns True if pool exists
174
- */
175
- hasPool(poolId) {
176
- return this.pools.has(poolId);
177
- }
178
- /**
179
- * Get the configuration for a pool.
180
- *
181
- * @param poolId - Pool identifier
182
- * @returns Pool configuration or undefined if not found
183
- */
184
- getPoolConfig(poolId) {
185
- const entry = this.pools.get(poolId);
186
- return entry ? { ...entry.config } : undefined;
187
- }
188
- /**
189
- * Get extended statistics for a pool.
190
- *
191
- * @param poolId - Pool identifier
192
- * @returns Extended pool statistics or undefined if not found
193
- */
194
- getPoolStats(poolId) {
195
- const entry = this.pools.get(poolId);
196
- if (!entry)
197
- return undefined;
198
- const baseStats = entry.pool.stats();
199
- return {
200
- ...baseStats,
201
- poolId,
202
- createdAt: entry.createdAt,
203
- totalTasksExecuted: entry.totalTasksExecuted,
204
- totalExecutionTime: entry.totalExecutionTime,
205
- averageExecutionTime: entry.totalTasksExecuted > 0
206
- ? entry.totalExecutionTime / entry.totalTasksExecuted
207
- : 0,
208
- };
209
- }
210
- /**
211
- * Get statistics for all pools.
212
- *
213
- * @returns Map of pool IDs to their statistics
214
- */
215
- getAllPoolStats() {
216
- const stats = new Map();
217
- for (const poolId of this.pools.keys()) {
218
- const poolStats = this.getPoolStats(poolId);
219
- if (poolStats) {
220
- stats.set(poolId, poolStats);
221
- }
222
- }
223
- return stats;
224
- }
225
- /**
226
- * Record task execution for statistics tracking.
227
- *
228
- * @param poolId - Pool identifier
229
- * @param executionTimeMs - Task execution time in milliseconds
230
- */
231
- recordTaskExecution(poolId, executionTimeMs) {
232
- const entry = this.pools.get(poolId);
233
- if (entry) {
234
- entry.totalTasksExecuted++;
235
- entry.totalExecutionTime += executionTimeMs;
236
- }
237
- }
238
- /**
239
- * Execute a task on a pool with automatic statistics tracking.
240
- *
241
- * @template T - Result type
242
- * @param poolId - Pool identifier
243
- * @param method - Method name to execute (for worker script pools) or inline function
244
- * @param args - Arguments to pass to the method/function
245
- * @param timeout - Optional timeout in milliseconds
246
- * @returns Promise resolving to the task result
247
- */
248
- async executeTask(poolId, method, args = [], timeout) {
249
- const entry = this.pools.get(poolId);
250
- if (!entry) {
251
- throw new Error(`Pool '${poolId}' not found`);
252
- }
253
- const effectiveTimeout = timeout ?? entry.config.defaultTimeout ?? DEFAULT_CONFIG.defaultTimeout;
254
- const startTime = Date.now();
255
- try {
256
- let result;
257
- if (typeof method === 'string') {
258
- // Execute named method from worker script
259
- result = await entry.pool.exec(method, args).timeout(effectiveTimeout);
260
- }
261
- else {
262
- // Execute inline function
263
- result = await entry.pool.exec(method, args).timeout(effectiveTimeout);
264
- }
265
- const executionTime = Date.now() - startTime;
266
- this.recordTaskExecution(poolId, executionTime);
267
- return result;
268
- }
269
- catch (error) {
270
- const executionTime = Date.now() - startTime;
271
- this.recordTaskExecution(poolId, executionTime);
272
- throw error;
273
- }
274
- }
275
- /**
276
- * Shutdown a specific pool.
277
- *
278
- * @param poolId - Pool identifier
279
- * @param force - If true, forcefully terminate workers (default: false)
280
- * @returns Promise resolving when shutdown is complete
281
- */
282
- async shutdownPool(poolId, force = false) {
283
- const entry = this.pools.get(poolId);
284
- if (!entry)
285
- return;
286
- try {
287
- await entry.pool.terminate(force);
288
- this.emitEvent(poolId, 'shutdown');
289
- }
290
- catch (error) {
291
- this.emitEvent(poolId, 'error', error);
292
- throw error;
293
- }
294
- finally {
295
- this.pools.delete(poolId);
296
- }
297
- }
298
- /**
299
- * Shutdown all pools asynchronously.
300
- *
301
- * @param force - If true, forcefully terminate workers (default: false)
302
- * @returns Promise resolving when all pools are shut down
303
- */
304
- async shutdownAll(force = false) {
305
- if (this.isShuttingDown)
306
- return;
307
- this.isShuttingDown = true;
308
- const shutdownPromises = [];
309
- for (const poolId of this.pools.keys()) {
310
- shutdownPromises.push(this.shutdownPool(poolId, force));
311
- }
312
- try {
313
- await Promise.allSettled(shutdownPromises);
314
- }
315
- finally {
316
- this.pools.clear();
317
- this.isShuttingDown = false;
318
- }
319
- }
320
- /**
321
- * Synchronous shutdown for process exit handlers.
322
- * Forces immediate termination of all pools.
323
- */
324
- shutdownAllSync() {
325
- if (this.isShuttingDown)
326
- return;
327
- this.isShuttingDown = true;
328
- for (const [poolId, entry] of this.pools) {
329
- try {
330
- entry.pool.terminate(true);
331
- this.emitEvent(poolId, 'shutdown');
332
- }
333
- catch {
334
- // Ignore errors during sync shutdown
335
- }
336
- }
337
- this.pools.clear();
338
- this.isShuttingDown = false;
339
- }
340
- /**
341
- * Register an event callback for pool events.
342
- *
343
- * @param callback - Callback function to invoke on events
344
- * @returns Unsubscribe function
345
- */
346
- onEvent(callback) {
347
- this.eventCallbacks.push(callback);
348
- return () => {
349
- const index = this.eventCallbacks.indexOf(callback);
350
- if (index >= 0) {
351
- this.eventCallbacks.splice(index, 1);
352
- }
353
- };
354
- }
355
- /**
356
- * Emit an event to all registered callbacks.
357
- */
358
- emitEvent(poolId, event, data) {
359
- for (const callback of this.eventCallbacks) {
360
- try {
361
- callback(poolId, event, data);
362
- }
363
- catch {
364
- // Ignore callback errors
365
- }
366
- }
367
- }
368
- /**
369
- * Get the number of active pools.
370
- *
371
- * @returns Number of pools currently managed
372
- */
373
- get poolCount() {
374
- return this.pools.size;
375
- }
376
- /**
377
- * Get all pool IDs.
378
- *
379
- * @returns Array of pool identifiers
380
- */
381
- getPoolIds() {
382
- return Array.from(this.pools.keys());
383
- }
384
- /**
385
- * Check if the minimum parallel size threshold is met.
386
- *
387
- * @param poolId - Pool identifier
388
- * @param size - Size of the data to process
389
- * @returns True if size meets or exceeds minimum threshold
390
- */
391
- shouldUseParallel(poolId, size) {
392
- const entry = this.pools.get(poolId);
393
- const minSize = entry?.config.minParallelSize ?? DEFAULT_CONFIG.minParallelSize;
394
- return size >= minSize;
395
- }
396
- /**
397
- * Get the default configuration values.
398
- *
399
- * @returns Copy of default configuration
400
- */
401
- static getDefaultConfig() {
402
- return { ...DEFAULT_CONFIG };
403
- }
404
- /**
405
- * Get the CPU count available for workers.
406
- *
407
- * @returns Number of CPUs
408
- */
409
- static getCpuCount() {
410
- return workerpool.cpus;
411
- }
412
- }
413
- /**
414
- * Convenience function to get the WorkerPoolManager instance.
415
- *
416
- * @returns The WorkerPoolManager singleton
417
- */
418
- export function getWorkerPoolManager() {
419
- return WorkerPoolManager.getInstance();
420
- }
@@ -1,124 +0,0 @@
1
- /**
2
- * Operation Utilities
3
- *
4
- * Phase 9B: Utilities for long-running operations with progress tracking
5
- * and cancellation support.
6
- *
7
- * @module utils/operationUtils
8
- */
9
- import type { ProgressCallback } from './taskScheduler.js';
10
- /**
11
- * Check if an operation has been cancelled via AbortSignal.
12
- * Throws OperationCancelledError if the signal is aborted.
13
- *
14
- * @param signal - Optional AbortSignal to check
15
- * @param operation - Optional operation name for error message
16
- * @throws OperationCancelledError if signal is aborted
17
- *
18
- * @example
19
- * ```typescript
20
- * for (const item of items) {
21
- * checkCancellation(options?.signal, 'batch processing');
22
- * await processItem(item);
23
- * }
24
- * ```
25
- */
26
- export declare function checkCancellation(signal?: AbortSignal, operation?: string): void;
27
- /**
28
- * Create a throttled progress reporter to avoid excessive callback invocations.
29
- * Returns undefined if no callback is provided.
30
- *
31
- * @param callback - Optional progress callback to throttle
32
- * @param throttleMs - Minimum time between callbacks (default: 100ms)
33
- * @returns Throttled callback or undefined
34
- *
35
- * @example
36
- * ```typescript
37
- * const reportProgress = createProgressReporter(options?.onProgress, 50);
38
- * for (let i = 0; i < total; i++) {
39
- * reportProgress?.({ completed: i, total, percentage: (i / total) * 100 });
40
- * }
41
- * ```
42
- */
43
- export declare function createProgressReporter(callback?: ProgressCallback, throttleMs?: number): ProgressCallback | undefined;
44
- /**
45
- * Create a progress object for reporting.
46
- *
47
- * @param completed - Number of completed items
48
- * @param total - Total number of items
49
- * @param currentTaskId - Optional current task identifier
50
- * @returns Progress object suitable for ProgressCallback
51
- *
52
- * @example
53
- * ```typescript
54
- * reportProgress?.(createProgress(50, 100, 'processing entities'));
55
- * // { completed: 50, total: 100, percentage: 50, currentTaskId: 'processing entities' }
56
- * ```
57
- */
58
- export declare function createProgress(completed: number, total: number, currentTaskId?: string): {
59
- completed: number;
60
- total: number;
61
- percentage: number;
62
- currentTaskId?: string;
63
- };
64
- /**
65
- * Phase definition for executeWithPhases.
66
- */
67
- export interface PhaseDefinition<T> {
68
- /** Phase name (used for progress reporting and cancellation error messages) */
69
- name: string;
70
- /** Weight of this phase relative to others (higher = more of total progress) */
71
- weight: number;
72
- /** Executor function that performs the phase work */
73
- execute: (phaseProgress: (pct: number) => void) => Promise<T>;
74
- }
75
- /**
76
- * Execute an operation with multiple distinct phases.
77
- * Useful when an operation has multiple distinct phases with different weights.
78
- *
79
- * @param phases - Array of phase definitions with weight and executor
80
- * @param onProgress - Optional progress callback
81
- * @param signal - Optional abort signal
82
- * @returns Array of results from each phase
83
- * @throws OperationCancelledError if cancelled during any phase
84
- *
85
- * @example
86
- * ```typescript
87
- * const [parseResult, processResult, saveResult] = await executeWithPhases([
88
- * { name: 'parsing', weight: 20, execute: () => parseData() },
89
- * { name: 'processing', weight: 60, execute: () => processEntities() },
90
- * { name: 'saving', weight: 20, execute: () => saveResults() },
91
- * ], options?.onProgress, options?.signal);
92
- * ```
93
- */
94
- export declare function executeWithPhases<T>(phases: PhaseDefinition<T>[], onProgress?: ProgressCallback, signal?: AbortSignal): Promise<T[]>;
95
- /**
96
- * Execute an operation in batches with progress tracking and cancellation support.
97
- *
98
- * @param items - Array of items to process
99
- * @param batchSize - Size of each batch
100
- * @param processBatch - Function to process each batch
101
- * @param onProgress - Optional progress callback
102
- * @param signal - Optional abort signal
103
- * @param operationName - Optional operation name for cancellation error
104
- * @returns Array of results from all batches
105
- *
106
- * @example
107
- * ```typescript
108
- * const results = await processBatchesWithProgress(
109
- * entities,
110
- * 100,
111
- * async (batch) => {
112
- * for (const entity of batch) {
113
- * await saveEntity(entity);
114
- * }
115
- * return batch.length;
116
- * },
117
- * options?.onProgress,
118
- * options?.signal,
119
- * 'createEntities'
120
- * );
121
- * ```
122
- */
123
- export declare function processBatchesWithProgress<T, R>(items: T[], batchSize: number, processBatch: (batch: T[], batchIndex: number) => Promise<R>, onProgress?: ProgressCallback, signal?: AbortSignal, operationName?: string): Promise<R[]>;
124
- //# sourceMappingURL=operationUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/operationUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAIhF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,CAAC,EAAE,gBAAgB,EAC3B,UAAU,GAAE,MAAY,GACvB,gBAAgB,GAAG,SAAS,CAa9B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,GACrB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAOlF;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,EAC5B,UAAU,CAAC,EAAE,gBAAgB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,EAAE,CAAC,CAkCd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,0BAA0B,CAAC,CAAC,EAAE,CAAC,EACnD,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC5D,UAAU,CAAC,EAAE,gBAAgB,EAC7B,MAAM,CAAC,EAAE,WAAW,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC,CAqBd"}