@danielsimonjr/memory-mcp 0.47.1 → 9.8.0
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/LICENSE +22 -0
- package/README.md +2000 -194
- package/dist/__tests__/file-path.test.js +5 -5
- package/dist/__tests__/knowledge-graph.test.js +3 -8
- package/dist/core/EntityManager.d.ts +266 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +85 -133
- package/dist/core/GraphEventEmitter.d.ts +202 -0
- package/dist/core/GraphEventEmitter.d.ts.map +1 -0
- package/dist/core/GraphEventEmitter.js +346 -0
- package/dist/core/GraphStorage.d.ts +395 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +643 -31
- package/dist/core/GraphTraversal.d.ts +141 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +573 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/{features → core}/HierarchyManager.js +14 -9
- package/dist/core/ManagerContext.d.ts +72 -0
- package/dist/core/ManagerContext.d.ts.map +1 -0
- package/dist/core/ManagerContext.js +118 -0
- package/dist/core/ObservationManager.d.ts +85 -0
- package/dist/core/ObservationManager.d.ts.map +1 -0
- package/dist/core/ObservationManager.js +51 -57
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +31 -7
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +917 -0
- package/dist/core/StorageFactory.d.ts +45 -0
- package/dist/core/StorageFactory.d.ts.map +1 -0
- package/dist/core/StorageFactory.js +64 -0
- package/dist/core/TransactionManager.d.ts +464 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +490 -13
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -2
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +14 -13
- package/dist/features/ArchiveManager.d.ts +133 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +221 -14
- package/dist/features/CompressionManager.d.ts +117 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +189 -20
- package/dist/features/IOManager.d.ts +225 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +1041 -0
- package/dist/features/StreamingExporter.d.ts +123 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +203 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +5 -6
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -45
- package/dist/memory.jsonl +1 -18
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +9 -3
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +156 -9
- package/dist/search/EmbeddingService.d.ts +178 -0
- package/dist/search/EmbeddingService.d.ts.map +1 -0
- package/dist/search/EmbeddingService.js +358 -0
- package/dist/search/FuzzySearch.d.ts +118 -0
- package/dist/search/FuzzySearch.d.ts.map +1 -0
- package/dist/search/FuzzySearch.js +241 -25
- package/dist/search/QueryCostEstimator.d.ts +111 -0
- package/dist/search/QueryCostEstimator.d.ts.map +1 -0
- package/dist/search/QueryCostEstimator.js +355 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +54 -6
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +2 -4
- package/dist/search/SearchManager.d.ts +326 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +148 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +1 -1
- package/dist/search/SemanticSearch.d.ts +149 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +323 -0
- package/dist/search/TFIDFEventSync.d.ts +85 -0
- package/dist/search/TFIDFEventSync.d.ts.map +1 -0
- package/dist/search/TFIDFEventSync.js +133 -0
- package/dist/search/TFIDFIndexManager.d.ts +151 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +232 -17
- package/dist/search/VectorStore.d.ts +235 -0
- package/dist/search/VectorStore.d.ts.map +1 -0
- package/dist/search/VectorStore.js +311 -0
- package/dist/search/index.d.ts +21 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +12 -0
- package/dist/server/MCPServer.d.ts +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +4 -4
- package/dist/server/responseCompressor.d.ts +94 -0
- package/dist/server/responseCompressor.d.ts.map +1 -0
- package/dist/server/responseCompressor.js +127 -0
- package/dist/server/toolDefinitions.d.ts +27 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -0
- package/dist/server/toolDefinitions.js +189 -18
- package/dist/server/toolHandlers.d.ts +41 -0
- package/dist/server/toolHandlers.d.ts.map +1 -0
- package/dist/server/toolHandlers.js +467 -75
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/types.d.ts +1654 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +9 -0
- package/dist/utils/compressedCache.d.ts +192 -0
- package/dist/utils/compressedCache.d.ts.map +1 -0
- package/dist/utils/compressedCache.js +309 -0
- package/dist/utils/compressionUtil.d.ts +214 -0
- package/dist/utils/compressionUtil.d.ts.map +1 -0
- package/dist/utils/compressionUtil.js +247 -0
- package/dist/utils/constants.d.ts +245 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +124 -0
- package/dist/utils/entityUtils.d.ts +321 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +434 -4
- package/dist/utils/errors.d.ts +95 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +24 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +69 -31
- package/dist/utils/indexes.d.ts +270 -0
- package/dist/utils/indexes.d.ts.map +1 -0
- package/dist/utils/indexes.js +526 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/operationUtils.d.ts +124 -0
- package/dist/utils/operationUtils.d.ts.map +1 -0
- package/dist/utils/operationUtils.js +175 -0
- package/dist/utils/parallelUtils.d.ts +72 -0
- package/dist/utils/parallelUtils.d.ts.map +1 -0
- package/dist/utils/parallelUtils.js +169 -0
- package/dist/utils/schemas.d.ts +374 -0
- package/dist/utils/schemas.d.ts.map +1 -0
- package/dist/utils/schemas.js +302 -2
- package/dist/utils/searchAlgorithms.d.ts +99 -0
- package/dist/utils/searchAlgorithms.d.ts.map +1 -0
- package/dist/utils/searchAlgorithms.js +167 -0
- package/dist/utils/searchCache.d.ts +108 -0
- package/dist/utils/searchCache.d.ts.map +1 -0
- package/dist/utils/taskScheduler.d.ts +290 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +466 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +9 -0
- package/dist/workers/levenshteinWorker.d.ts +60 -0
- package/dist/workers/levenshteinWorker.d.ts.map +1 -0
- package/dist/workers/levenshteinWorker.js +98 -0
- package/package.json +17 -4
- package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
- package/dist/__tests__/integration/workflows.test.js +0 -449
- package/dist/__tests__/performance/benchmarks.test.js +0 -413
- package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
- package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
- package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
- package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
- package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
- package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
- package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
- package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
- package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
- package/dist/core/KnowledgeGraphManager.js +0 -423
- package/dist/features/BackupManager.js +0 -311
- package/dist/features/ExportManager.js +0 -305
- package/dist/features/ImportExportManager.js +0 -50
- package/dist/features/ImportManager.js +0 -328
- package/dist/types/analytics.types.js +0 -6
- package/dist/types/entity.types.js +0 -7
- package/dist/types/import-export.types.js +0 -7
- package/dist/types/search.types.js +0 -7
- package/dist/types/tag.types.js +0 -6
- package/dist/utils/dateUtils.js +0 -89
- package/dist/utils/filterUtils.js +0 -155
- package/dist/utils/levenshtein.js +0 -62
- package/dist/utils/pathUtils.js +0 -115
- package/dist/utils/responseFormatter.js +0 -55
- package/dist/utils/tagUtils.js +0 -107
- package/dist/utils/tfidf.js +0 -90
- package/dist/utils/validationHelper.js +0 -99
- package/dist/utils/validationUtils.js +0 -109
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Storage
|
|
3
|
+
*
|
|
4
|
+
* Handles file I/O operations for the knowledge graph using JSONL format.
|
|
5
|
+
* Implements IGraphStorage interface for storage abstraction.
|
|
6
|
+
*
|
|
7
|
+
* @module core/GraphStorage
|
|
8
|
+
*/
|
|
9
|
+
import type { KnowledgeGraph, Entity, Relation, ReadonlyKnowledgeGraph, IGraphStorage, LowercaseData } from '../types/index.js';
|
|
10
|
+
import { BatchTransaction } from './TransactionManager.js';
|
|
11
|
+
import { GraphEventEmitter } from './GraphEventEmitter.js';
|
|
12
|
+
/**
|
|
13
|
+
* GraphStorage manages persistence of the knowledge graph to disk.
|
|
14
|
+
*
|
|
15
|
+
* Uses JSONL (JSON Lines) format where each line is a separate JSON object
|
|
16
|
+
* representing either an entity or a relation.
|
|
17
|
+
*
|
|
18
|
+
* OPTIMIZED: Implements in-memory caching to avoid repeated disk reads.
|
|
19
|
+
* Cache is invalidated on every write operation to ensure consistency.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const storage = new GraphStorage('/path/to/memory.jsonl');
|
|
24
|
+
* const graph = await storage.loadGraph();
|
|
25
|
+
* graph.entities.push(newEntity);
|
|
26
|
+
* await storage.saveGraph(graph);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class GraphStorage implements IGraphStorage {
|
|
30
|
+
private memoryFilePath;
|
|
31
|
+
/**
|
|
32
|
+
* Mutex for thread-safe access to storage operations.
|
|
33
|
+
* Prevents concurrent writes from corrupting the file or cache.
|
|
34
|
+
*/
|
|
35
|
+
private mutex;
|
|
36
|
+
/**
|
|
37
|
+
* In-memory cache of the knowledge graph.
|
|
38
|
+
* Null when cache is empty or invalidated.
|
|
39
|
+
*/
|
|
40
|
+
private cache;
|
|
41
|
+
/**
|
|
42
|
+
* Number of pending append operations since last compaction.
|
|
43
|
+
* Used to trigger automatic compaction when threshold is reached.
|
|
44
|
+
*/
|
|
45
|
+
private pendingAppends;
|
|
46
|
+
/**
|
|
47
|
+
* Dynamic threshold for automatic compaction.
|
|
48
|
+
*
|
|
49
|
+
* Returns the larger of 100 or 10% of the current entity count.
|
|
50
|
+
* This scales with graph size to avoid too-frequent compaction on large graphs
|
|
51
|
+
* while maintaining a reasonable minimum for small graphs.
|
|
52
|
+
*
|
|
53
|
+
* @returns Compaction threshold value
|
|
54
|
+
*/
|
|
55
|
+
private get compactionThreshold();
|
|
56
|
+
/**
|
|
57
|
+
* O(1) entity lookup by name.
|
|
58
|
+
*/
|
|
59
|
+
private nameIndex;
|
|
60
|
+
/**
|
|
61
|
+
* O(1) entity lookup by type.
|
|
62
|
+
*/
|
|
63
|
+
private typeIndex;
|
|
64
|
+
/**
|
|
65
|
+
* Pre-computed lowercase strings for search optimization.
|
|
66
|
+
*/
|
|
67
|
+
private lowercaseCache;
|
|
68
|
+
/**
|
|
69
|
+
* O(1) relation lookup by entity name.
|
|
70
|
+
*/
|
|
71
|
+
private relationIndex;
|
|
72
|
+
/**
|
|
73
|
+
* O(1) observation word lookup by entity.
|
|
74
|
+
* Maps words in observations to entity names.
|
|
75
|
+
*/
|
|
76
|
+
private observationIndex;
|
|
77
|
+
/**
|
|
78
|
+
* Phase 10 Sprint 2: Event emitter for graph change notifications.
|
|
79
|
+
* Allows external systems to subscribe to graph changes.
|
|
80
|
+
*/
|
|
81
|
+
private eventEmitter;
|
|
82
|
+
/**
|
|
83
|
+
* Create a new GraphStorage instance.
|
|
84
|
+
*
|
|
85
|
+
* @param memoryFilePath - Absolute path to the JSONL file
|
|
86
|
+
*/
|
|
87
|
+
constructor(memoryFilePath: string);
|
|
88
|
+
/**
|
|
89
|
+
* Get the event emitter for subscribing to graph changes.
|
|
90
|
+
*
|
|
91
|
+
* @returns GraphEventEmitter instance
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
96
|
+
*
|
|
97
|
+
* // Subscribe to entity creation events
|
|
98
|
+
* storage.events.on('entity:created', (event) => {
|
|
99
|
+
* console.log(`Entity ${event.entity.name} created`);
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Subscribe to all events
|
|
103
|
+
* storage.events.onAny((event) => {
|
|
104
|
+
* console.log(`Graph event: ${event.type}`);
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
get events(): GraphEventEmitter;
|
|
109
|
+
/**
|
|
110
|
+
* Write content to file with fsync for durability.
|
|
111
|
+
*
|
|
112
|
+
* @param content - Content to write
|
|
113
|
+
*/
|
|
114
|
+
private durableWriteFile;
|
|
115
|
+
/**
|
|
116
|
+
* Append content to file with fsync for durability.
|
|
117
|
+
*
|
|
118
|
+
* @param content - Content to append
|
|
119
|
+
* @param prependNewline - Whether to prepend a newline
|
|
120
|
+
*/
|
|
121
|
+
private durableAppendFile;
|
|
122
|
+
/**
|
|
123
|
+
* Load the knowledge graph from disk (read-only access).
|
|
124
|
+
*
|
|
125
|
+
* OPTIMIZED: Returns cached reference directly without copying.
|
|
126
|
+
* This is O(1) regardless of graph size. For mutation operations,
|
|
127
|
+
* use getGraphForMutation() instead.
|
|
128
|
+
*
|
|
129
|
+
* @returns Promise resolving to read-only knowledge graph reference
|
|
130
|
+
* @throws Error if file exists but cannot be read or parsed
|
|
131
|
+
*/
|
|
132
|
+
loadGraph(): Promise<ReadonlyKnowledgeGraph>;
|
|
133
|
+
/**
|
|
134
|
+
* Get a mutable copy of the graph for write operations.
|
|
135
|
+
*
|
|
136
|
+
* Creates deep copies of entity and relation arrays to allow
|
|
137
|
+
* safe mutation without affecting the cached data.
|
|
138
|
+
*
|
|
139
|
+
* @returns Promise resolving to mutable knowledge graph copy
|
|
140
|
+
*/
|
|
141
|
+
getGraphForMutation(): Promise<KnowledgeGraph>;
|
|
142
|
+
/**
|
|
143
|
+
* Ensure the cache is loaded from disk.
|
|
144
|
+
*
|
|
145
|
+
* @returns Promise resolving when cache is populated
|
|
146
|
+
*/
|
|
147
|
+
ensureLoaded(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Internal method to load graph from disk into cache.
|
|
150
|
+
*/
|
|
151
|
+
private loadFromDisk;
|
|
152
|
+
/**
|
|
153
|
+
* Build all entity indexes from entity array.
|
|
154
|
+
*/
|
|
155
|
+
private buildEntityIndexes;
|
|
156
|
+
/**
|
|
157
|
+
* Build relation index from relation array.
|
|
158
|
+
*/
|
|
159
|
+
private buildRelationIndex;
|
|
160
|
+
/**
|
|
161
|
+
* Clear all indexes.
|
|
162
|
+
*/
|
|
163
|
+
private clearIndexes;
|
|
164
|
+
/**
|
|
165
|
+
* Save the knowledge graph to disk.
|
|
166
|
+
*
|
|
167
|
+
* OPTIMIZED: Updates cache directly after write to avoid re-reading.
|
|
168
|
+
* THREAD-SAFE: Uses mutex to prevent concurrent write operations.
|
|
169
|
+
*
|
|
170
|
+
* Writes the graph to JSONL format, with one JSON object per line.
|
|
171
|
+
*
|
|
172
|
+
* @param graph - The knowledge graph to save
|
|
173
|
+
* @returns Promise resolving when save is complete
|
|
174
|
+
* @throws Error if file cannot be written
|
|
175
|
+
*/
|
|
176
|
+
saveGraph(graph: KnowledgeGraph): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Append a single entity to the file (O(1) write operation).
|
|
179
|
+
*
|
|
180
|
+
* OPTIMIZED: Uses file append instead of full rewrite.
|
|
181
|
+
* THREAD-SAFE: Uses mutex to prevent concurrent write operations.
|
|
182
|
+
* Updates cache in-place and triggers compaction when threshold is reached.
|
|
183
|
+
*
|
|
184
|
+
* @param entity - The entity to append
|
|
185
|
+
* @returns Promise resolving when append is complete
|
|
186
|
+
*/
|
|
187
|
+
appendEntity(entity: Entity): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Append a single relation to the file (O(1) write operation).
|
|
190
|
+
*
|
|
191
|
+
* OPTIMIZED: Uses file append instead of full rewrite.
|
|
192
|
+
* THREAD-SAFE: Uses mutex to prevent concurrent write operations.
|
|
193
|
+
* Updates cache in-place and triggers compaction when threshold is reached.
|
|
194
|
+
*
|
|
195
|
+
* @param relation - The relation to append
|
|
196
|
+
* @returns Promise resolving when append is complete
|
|
197
|
+
*/
|
|
198
|
+
appendRelation(relation: Relation): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Compact the file by rewriting it with only current cache contents.
|
|
201
|
+
*
|
|
202
|
+
* THREAD-SAFE: Uses mutex to prevent concurrent operations.
|
|
203
|
+
* Removes duplicate entries and cleans up the file.
|
|
204
|
+
* Resets pending appends counter.
|
|
205
|
+
*
|
|
206
|
+
* @returns Promise resolving when compaction is complete
|
|
207
|
+
*/
|
|
208
|
+
compact(): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Internal compact implementation (must be called within mutex).
|
|
211
|
+
*
|
|
212
|
+
* @returns Promise resolving when compaction is complete
|
|
213
|
+
*/
|
|
214
|
+
private compactInternal;
|
|
215
|
+
/**
|
|
216
|
+
* Internal saveGraph implementation (must be called within mutex).
|
|
217
|
+
*
|
|
218
|
+
* @param graph - The knowledge graph to save
|
|
219
|
+
* @returns Promise resolving when save is complete
|
|
220
|
+
*/
|
|
221
|
+
private saveGraphInternal;
|
|
222
|
+
/**
|
|
223
|
+
* Get the current pending appends count.
|
|
224
|
+
*
|
|
225
|
+
* Useful for testing compaction behavior.
|
|
226
|
+
*
|
|
227
|
+
* @returns Number of pending appends since last compaction
|
|
228
|
+
*/
|
|
229
|
+
getPendingAppends(): number;
|
|
230
|
+
/**
|
|
231
|
+
* Update an entity in-place in the cache and append to file.
|
|
232
|
+
*
|
|
233
|
+
* OPTIMIZED: Modifies cache directly and appends updated version to file.
|
|
234
|
+
* THREAD-SAFE: Uses mutex to prevent concurrent write operations.
|
|
235
|
+
* Does not rewrite the entire file - compaction handles deduplication later.
|
|
236
|
+
*
|
|
237
|
+
* @param entityName - Name of the entity to update
|
|
238
|
+
* @param updates - Partial entity updates to apply
|
|
239
|
+
* @returns Promise resolving to true if entity was found and updated, false otherwise
|
|
240
|
+
*/
|
|
241
|
+
updateEntity(entityName: string, updates: Partial<Entity>): Promise<boolean>;
|
|
242
|
+
/**
|
|
243
|
+
* Manually clear the cache.
|
|
244
|
+
*
|
|
245
|
+
* Useful for testing or when external processes modify the file.
|
|
246
|
+
*
|
|
247
|
+
* @returns void
|
|
248
|
+
*/
|
|
249
|
+
clearCache(): void;
|
|
250
|
+
/**
|
|
251
|
+
* Get the file path being used for storage.
|
|
252
|
+
*
|
|
253
|
+
* @returns The memory file path
|
|
254
|
+
*/
|
|
255
|
+
getFilePath(): string;
|
|
256
|
+
/**
|
|
257
|
+
* Get an entity by name in O(1) time.
|
|
258
|
+
*
|
|
259
|
+
* OPTIMIZED: Uses NameIndex for constant-time lookup.
|
|
260
|
+
*
|
|
261
|
+
* @param name - Entity name to look up
|
|
262
|
+
* @returns Entity if found, undefined otherwise
|
|
263
|
+
*/
|
|
264
|
+
getEntityByName(name: string): Entity | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Check if an entity exists by name in O(1) time.
|
|
267
|
+
*
|
|
268
|
+
* @param name - Entity name to check
|
|
269
|
+
* @returns True if entity exists
|
|
270
|
+
*/
|
|
271
|
+
hasEntity(name: string): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Get all entities of a given type in O(1) time.
|
|
274
|
+
*
|
|
275
|
+
* OPTIMIZED: Uses TypeIndex for constant-time lookup of entity names,
|
|
276
|
+
* then uses NameIndex for O(1) entity retrieval.
|
|
277
|
+
*
|
|
278
|
+
* @param entityType - Entity type to filter by (case-insensitive)
|
|
279
|
+
* @returns Array of entities with the given type
|
|
280
|
+
*/
|
|
281
|
+
getEntitiesByType(entityType: string): Entity[];
|
|
282
|
+
/**
|
|
283
|
+
* Get pre-computed lowercase data for an entity.
|
|
284
|
+
*
|
|
285
|
+
* OPTIMIZED: Avoids repeated toLowerCase() calls during search.
|
|
286
|
+
*
|
|
287
|
+
* @param entityName - Entity name to get lowercase data for
|
|
288
|
+
* @returns LowercaseData if entity exists, undefined otherwise
|
|
289
|
+
*/
|
|
290
|
+
getLowercased(entityName: string): LowercaseData | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* Get all unique entity types in the graph.
|
|
293
|
+
*
|
|
294
|
+
* @returns Array of unique entity types (lowercase)
|
|
295
|
+
*/
|
|
296
|
+
getEntityTypes(): string[];
|
|
297
|
+
/**
|
|
298
|
+
* Get all relations where the entity is the source (outgoing relations) in O(1) time.
|
|
299
|
+
*
|
|
300
|
+
* OPTIMIZED: Uses RelationIndex for constant-time lookup.
|
|
301
|
+
*
|
|
302
|
+
* @param entityName - Entity name to look up outgoing relations for
|
|
303
|
+
* @returns Array of relations where entity is the source
|
|
304
|
+
*/
|
|
305
|
+
getRelationsFrom(entityName: string): Relation[];
|
|
306
|
+
/**
|
|
307
|
+
* Get all relations where the entity is the target (incoming relations) in O(1) time.
|
|
308
|
+
*
|
|
309
|
+
* OPTIMIZED: Uses RelationIndex for constant-time lookup.
|
|
310
|
+
*
|
|
311
|
+
* @param entityName - Entity name to look up incoming relations for
|
|
312
|
+
* @returns Array of relations where entity is the target
|
|
313
|
+
*/
|
|
314
|
+
getRelationsTo(entityName: string): Relation[];
|
|
315
|
+
/**
|
|
316
|
+
* Get all relations involving the entity (both incoming and outgoing) in O(1) time.
|
|
317
|
+
*
|
|
318
|
+
* OPTIMIZED: Uses RelationIndex for constant-time lookup.
|
|
319
|
+
*
|
|
320
|
+
* @param entityName - Entity name to look up all relations for
|
|
321
|
+
* @returns Array of all relations involving the entity
|
|
322
|
+
*/
|
|
323
|
+
getRelationsFor(entityName: string): Relation[];
|
|
324
|
+
/**
|
|
325
|
+
* Check if an entity has any relations.
|
|
326
|
+
*
|
|
327
|
+
* @param entityName - Entity name to check
|
|
328
|
+
* @returns True if entity has any relations
|
|
329
|
+
*/
|
|
330
|
+
hasRelations(entityName: string): boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Get entities that have observations containing the given word.
|
|
333
|
+
* Uses the observation index for O(1) lookup.
|
|
334
|
+
*
|
|
335
|
+
* OPTIMIZED: Uses ObservationIndex for constant-time lookup instead of
|
|
336
|
+
* linear scan through all entities and their observations.
|
|
337
|
+
*
|
|
338
|
+
* @param word - Word to search for in observations
|
|
339
|
+
* @returns Set of entity names
|
|
340
|
+
*/
|
|
341
|
+
getEntitiesByObservationWord(word: string): Set<string>;
|
|
342
|
+
/**
|
|
343
|
+
* Get entities that have observations containing ANY of the given words (union).
|
|
344
|
+
* Uses the observation index for O(1) lookup per word.
|
|
345
|
+
*
|
|
346
|
+
* OPTIMIZED: Uses ObservationIndex for constant-time lookups.
|
|
347
|
+
*
|
|
348
|
+
* @param words - Array of words to search for
|
|
349
|
+
* @returns Set of entity names containing any of the words
|
|
350
|
+
*/
|
|
351
|
+
getEntitiesByAnyObservationWord(words: string[]): Set<string>;
|
|
352
|
+
/**
|
|
353
|
+
* Get entities that have observations containing ALL of the given words (intersection).
|
|
354
|
+
* Uses the observation index for O(1) lookup per word.
|
|
355
|
+
*
|
|
356
|
+
* OPTIMIZED: Uses ObservationIndex for constant-time lookups and set intersection.
|
|
357
|
+
*
|
|
358
|
+
* @param words - Array of words that must all be present
|
|
359
|
+
* @returns Set of entity names containing all of the words
|
|
360
|
+
*/
|
|
361
|
+
getEntitiesByAllObservationWords(words: string[]): Set<string>;
|
|
362
|
+
/**
|
|
363
|
+
* Get statistics about the observation index.
|
|
364
|
+
*
|
|
365
|
+
* @returns Object with wordCount and entityCount
|
|
366
|
+
*/
|
|
367
|
+
getObservationIndexStats(): {
|
|
368
|
+
wordCount: number;
|
|
369
|
+
entityCount: number;
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Create a new batch transaction for atomic operations.
|
|
373
|
+
*
|
|
374
|
+
* Returns a BatchTransaction instance that can be used to queue multiple
|
|
375
|
+
* operations and execute them atomically with a single save operation.
|
|
376
|
+
*
|
|
377
|
+
* @returns A new BatchTransaction instance
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
382
|
+
*
|
|
383
|
+
* // Create and execute a batch transaction
|
|
384
|
+
* const result = await storage.transaction()
|
|
385
|
+
* .createEntity({ name: 'Alice', entityType: 'person', observations: ['Developer'] })
|
|
386
|
+
* .createEntity({ name: 'Bob', entityType: 'person', observations: ['Designer'] })
|
|
387
|
+
* .createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' })
|
|
388
|
+
* .execute();
|
|
389
|
+
*
|
|
390
|
+
* console.log(`Batch completed: ${result.operationsExecuted} operations`);
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
transaction(): BatchTransaction;
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=GraphStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphStorage.d.ts","sourceRoot":"","sources":["../../src/core/GraphStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGhI,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,YAAW,aAAa;IAqEpC,OAAO,CAAC,cAAc;IApElC;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAe;IAE5B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAA+B;IAE5C;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;;;;;;;OAQG;IACH,OAAO,KAAK,mBAAmB,GAE9B;IAED;;OAEG;IACH,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