@danielsimonjr/memory-mcp 12.2.3 → 12.5.2

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 (158) hide show
  1. package/README.md +88 -102
  2. package/dist/index.js +6 -0
  3. package/dist/server/toolDefinitions.d.ts.map +1 -1
  4. package/dist/server/toolDefinitions.js +745 -3
  5. package/dist/server/toolHandlers.d.ts +1 -9
  6. package/dist/server/toolHandlers.d.ts.map +1 -1
  7. package/dist/server/toolHandlers.js +859 -11
  8. package/package.json +9 -6
  9. package/dist/core/EntityManager.d.ts +0 -263
  10. package/dist/core/EntityManager.d.ts.map +0 -1
  11. package/dist/core/EntityManager.js +0 -478
  12. package/dist/core/GraphStorage.d.ts +0 -344
  13. package/dist/core/GraphStorage.d.ts.map +0 -1
  14. package/dist/core/GraphStorage.js +0 -708
  15. package/dist/core/GraphTraversal.d.ts +0 -136
  16. package/dist/core/GraphTraversal.d.ts.map +0 -1
  17. package/dist/core/GraphTraversal.js +0 -556
  18. package/dist/core/HierarchyManager.d.ts +0 -111
  19. package/dist/core/HierarchyManager.d.ts.map +0 -1
  20. package/dist/core/HierarchyManager.js +0 -224
  21. package/dist/core/ManagerContext.d.ts +0 -72
  22. package/dist/core/ManagerContext.d.ts.map +0 -1
  23. package/dist/core/ManagerContext.js +0 -118
  24. package/dist/core/ObservationManager.d.ts +0 -85
  25. package/dist/core/ObservationManager.d.ts.map +0 -1
  26. package/dist/core/ObservationManager.js +0 -123
  27. package/dist/core/RelationManager.d.ts +0 -131
  28. package/dist/core/RelationManager.d.ts.map +0 -1
  29. package/dist/core/RelationManager.js +0 -210
  30. package/dist/core/SQLiteStorage.d.ts +0 -354
  31. package/dist/core/SQLiteStorage.d.ts.map +0 -1
  32. package/dist/core/SQLiteStorage.js +0 -917
  33. package/dist/core/StorageFactory.d.ts +0 -45
  34. package/dist/core/StorageFactory.d.ts.map +0 -1
  35. package/dist/core/StorageFactory.js +0 -64
  36. package/dist/core/TransactionManager.d.ts +0 -259
  37. package/dist/core/TransactionManager.d.ts.map +0 -1
  38. package/dist/core/TransactionManager.js +0 -392
  39. package/dist/core/index.d.ts +0 -16
  40. package/dist/core/index.d.ts.map +0 -1
  41. package/dist/core/index.js +0 -17
  42. package/dist/features/AnalyticsManager.d.ts +0 -44
  43. package/dist/features/AnalyticsManager.d.ts.map +0 -1
  44. package/dist/features/AnalyticsManager.js +0 -223
  45. package/dist/features/ArchiveManager.d.ts +0 -121
  46. package/dist/features/ArchiveManager.d.ts.map +0 -1
  47. package/dist/features/ArchiveManager.js +0 -240
  48. package/dist/features/CompressionManager.d.ts +0 -109
  49. package/dist/features/CompressionManager.d.ts.map +0 -1
  50. package/dist/features/CompressionManager.js +0 -404
  51. package/dist/features/IOManager.d.ts +0 -221
  52. package/dist/features/IOManager.d.ts.map +0 -1
  53. package/dist/features/IOManager.js +0 -997
  54. package/dist/features/StreamingExporter.d.ts +0 -105
  55. package/dist/features/StreamingExporter.d.ts.map +0 -1
  56. package/dist/features/StreamingExporter.js +0 -150
  57. package/dist/features/TagManager.d.ts +0 -147
  58. package/dist/features/TagManager.d.ts.map +0 -1
  59. package/dist/features/TagManager.js +0 -210
  60. package/dist/features/index.d.ts +0 -12
  61. package/dist/features/index.d.ts.map +0 -1
  62. package/dist/features/index.js +0 -11
  63. package/dist/search/BasicSearch.d.ts +0 -51
  64. package/dist/search/BasicSearch.d.ts.map +0 -1
  65. package/dist/search/BasicSearch.js +0 -137
  66. package/dist/search/BooleanSearch.d.ts +0 -98
  67. package/dist/search/BooleanSearch.d.ts.map +0 -1
  68. package/dist/search/BooleanSearch.js +0 -430
  69. package/dist/search/EmbeddingService.d.ts +0 -178
  70. package/dist/search/EmbeddingService.d.ts.map +0 -1
  71. package/dist/search/EmbeddingService.js +0 -358
  72. package/dist/search/FuzzySearch.d.ts +0 -118
  73. package/dist/search/FuzzySearch.d.ts.map +0 -1
  74. package/dist/search/FuzzySearch.js +0 -312
  75. package/dist/search/RankedSearch.d.ts +0 -71
  76. package/dist/search/RankedSearch.d.ts.map +0 -1
  77. package/dist/search/RankedSearch.js +0 -238
  78. package/dist/search/SavedSearchManager.d.ts +0 -79
  79. package/dist/search/SavedSearchManager.d.ts.map +0 -1
  80. package/dist/search/SavedSearchManager.js +0 -145
  81. package/dist/search/SearchFilterChain.d.ts +0 -120
  82. package/dist/search/SearchFilterChain.d.ts.map +0 -1
  83. package/dist/search/SearchFilterChain.js +0 -185
  84. package/dist/search/SearchManager.d.ts +0 -285
  85. package/dist/search/SearchManager.d.ts.map +0 -1
  86. package/dist/search/SearchManager.js +0 -338
  87. package/dist/search/SearchSuggestions.d.ts +0 -27
  88. package/dist/search/SearchSuggestions.d.ts.map +0 -1
  89. package/dist/search/SearchSuggestions.js +0 -57
  90. package/dist/search/SemanticSearch.d.ts +0 -146
  91. package/dist/search/SemanticSearch.d.ts.map +0 -1
  92. package/dist/search/SemanticSearch.js +0 -313
  93. package/dist/search/TFIDFIndexManager.d.ts +0 -63
  94. package/dist/search/TFIDFIndexManager.d.ts.map +0 -1
  95. package/dist/search/TFIDFIndexManager.js +0 -215
  96. package/dist/search/VectorStore.d.ts +0 -235
  97. package/dist/search/VectorStore.d.ts.map +0 -1
  98. package/dist/search/VectorStore.js +0 -311
  99. package/dist/search/index.d.ts +0 -18
  100. package/dist/search/index.d.ts.map +0 -1
  101. package/dist/search/index.js +0 -21
  102. package/dist/types/index.d.ts +0 -13
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -12
  105. package/dist/types/types.d.ts +0 -1234
  106. package/dist/types/types.d.ts.map +0 -1
  107. package/dist/types/types.js +0 -9
  108. package/dist/utils/compressedCache.d.ts +0 -192
  109. package/dist/utils/compressedCache.d.ts.map +0 -1
  110. package/dist/utils/compressedCache.js +0 -309
  111. package/dist/utils/compressionUtil.d.ts +0 -214
  112. package/dist/utils/compressionUtil.d.ts.map +0 -1
  113. package/dist/utils/compressionUtil.js +0 -247
  114. package/dist/utils/constants.d.ts +0 -245
  115. package/dist/utils/constants.d.ts.map +0 -1
  116. package/dist/utils/constants.js +0 -252
  117. package/dist/utils/entityUtils.d.ts +0 -321
  118. package/dist/utils/entityUtils.d.ts.map +0 -1
  119. package/dist/utils/entityUtils.js +0 -538
  120. package/dist/utils/errors.d.ts +0 -77
  121. package/dist/utils/errors.d.ts.map +0 -1
  122. package/dist/utils/errors.js +0 -121
  123. package/dist/utils/formatters.d.ts +0 -145
  124. package/dist/utils/formatters.d.ts.map +0 -1
  125. package/dist/utils/formatters.js +0 -132
  126. package/dist/utils/index.d.ts +0 -22
  127. package/dist/utils/index.d.ts.map +0 -1
  128. package/dist/utils/index.js +0 -75
  129. package/dist/utils/indexes.d.ts +0 -270
  130. package/dist/utils/indexes.d.ts.map +0 -1
  131. package/dist/utils/indexes.js +0 -526
  132. package/dist/utils/logger.d.ts +0 -24
  133. package/dist/utils/logger.d.ts.map +0 -1
  134. package/dist/utils/logger.js +0 -33
  135. package/dist/utils/parallelUtils.d.ts +0 -72
  136. package/dist/utils/parallelUtils.d.ts.map +0 -1
  137. package/dist/utils/parallelUtils.js +0 -169
  138. package/dist/utils/schemas.d.ts +0 -374
  139. package/dist/utils/schemas.d.ts.map +0 -1
  140. package/dist/utils/schemas.js +0 -484
  141. package/dist/utils/searchAlgorithms.d.ts +0 -99
  142. package/dist/utils/searchAlgorithms.d.ts.map +0 -1
  143. package/dist/utils/searchAlgorithms.js +0 -167
  144. package/dist/utils/searchCache.d.ts +0 -108
  145. package/dist/utils/searchCache.d.ts.map +0 -1
  146. package/dist/utils/searchCache.js +0 -209
  147. package/dist/utils/taskScheduler.d.ts +0 -290
  148. package/dist/utils/taskScheduler.d.ts.map +0 -1
  149. package/dist/utils/taskScheduler.js +0 -466
  150. package/dist/workers/WorkerPool.d.ts +0 -81
  151. package/dist/workers/WorkerPool.d.ts.map +0 -1
  152. package/dist/workers/WorkerPool.js +0 -121
  153. package/dist/workers/index.d.ts +0 -12
  154. package/dist/workers/index.d.ts.map +0 -1
  155. package/dist/workers/index.js +0 -9
  156. package/dist/workers/levenshteinWorker.d.ts +0 -60
  157. package/dist/workers/levenshteinWorker.d.ts.map +0 -1
  158. package/dist/workers/levenshteinWorker.js +0 -98
@@ -1,79 +0,0 @@
1
- /**
2
- * Saved Search Manager
3
- *
4
- * Manages persistent saved searches with JSONL storage.
5
- *
6
- * @module search/SavedSearchManager
7
- */
8
- import type { SavedSearch, KnowledgeGraph } from '../types/index.js';
9
- import type { BasicSearch } from './BasicSearch.js';
10
- /**
11
- * Manages saved search queries with usage tracking.
12
- */
13
- export declare class SavedSearchManager {
14
- private savedSearchesFilePath;
15
- private basicSearch;
16
- constructor(savedSearchesFilePath: string, basicSearch: BasicSearch);
17
- /**
18
- * Load all saved searches from JSONL file.
19
- *
20
- * @returns Array of saved searches
21
- */
22
- private loadSavedSearches;
23
- /**
24
- * Save searches to JSONL file.
25
- *
26
- * @param searches - Array of saved searches
27
- */
28
- private saveSavedSearches;
29
- /**
30
- * Save a search query for later reuse.
31
- *
32
- * @param search - Search parameters (without createdAt, useCount, lastUsed)
33
- * @returns The newly created saved search
34
- * @throws Error if search name already exists
35
- */
36
- saveSearch(search: Omit<SavedSearch, 'createdAt' | 'useCount' | 'lastUsed'>): Promise<SavedSearch>;
37
- /**
38
- * List all saved searches.
39
- *
40
- * @returns Array of all saved searches
41
- */
42
- listSavedSearches(): Promise<SavedSearch[]>;
43
- /**
44
- * Get a specific saved search by name.
45
- *
46
- * @param name - Search name
47
- * @returns Saved search or null if not found
48
- */
49
- getSavedSearch(name: string): Promise<SavedSearch | null>;
50
- /**
51
- * Execute a saved search by name.
52
- *
53
- * Updates usage statistics (lastUsed, useCount) before executing.
54
- *
55
- * @param name - Search name
56
- * @returns Search results as knowledge graph
57
- * @throws Error if search not found
58
- */
59
- executeSavedSearch(name: string): Promise<KnowledgeGraph>;
60
- /**
61
- * Delete a saved search.
62
- *
63
- * @param name - Search name
64
- * @returns True if deleted, false if not found
65
- */
66
- deleteSavedSearch(name: string): Promise<boolean>;
67
- /**
68
- * Update a saved search.
69
- *
70
- * Cannot update name, createdAt, useCount, or lastUsed fields.
71
- *
72
- * @param name - Search name
73
- * @param updates - Partial search with fields to update
74
- * @returns Updated saved search
75
- * @throws Error if search not found
76
- */
77
- updateSavedSearch(name: string, updates: Partial<Omit<SavedSearch, 'name' | 'createdAt' | 'useCount' | 'lastUsed'>>): Promise<SavedSearch>;
78
- }
79
- //# sourceMappingURL=SavedSearchManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SavedSearchManager.d.ts","sourceRoot":"","sources":["../../src/search/SavedSearchManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;GAEG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,WAAW;gBADX,qBAAqB,EAAE,MAAM,EAC7B,WAAW,EAAE,WAAW;IAGlC;;;;OAIG;YACW,iBAAiB;IAa/B;;;;OAIG;YACW,iBAAiB;IAK/B;;;;;;OAMG;IACG,UAAU,CACd,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC,GAC/D,OAAO,CAAC,WAAW,CAAC;IAoBvB;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAIjD;;;;;OAKG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAK/D;;;;;;;;OAQG;IACG,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAsB/D;;;;;OAKG;IACG,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAavD;;;;;;;;;OASG;IACG,iBAAiB,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,GAClF,OAAO,CAAC,WAAW,CAAC;CAcxB"}
@@ -1,145 +0,0 @@
1
- /**
2
- * Saved Search Manager
3
- *
4
- * Manages persistent saved searches with JSONL storage.
5
- *
6
- * @module search/SavedSearchManager
7
- */
8
- import * as fs from 'fs/promises';
9
- /**
10
- * Manages saved search queries with usage tracking.
11
- */
12
- export class SavedSearchManager {
13
- savedSearchesFilePath;
14
- basicSearch;
15
- constructor(savedSearchesFilePath, basicSearch) {
16
- this.savedSearchesFilePath = savedSearchesFilePath;
17
- this.basicSearch = basicSearch;
18
- }
19
- /**
20
- * Load all saved searches from JSONL file.
21
- *
22
- * @returns Array of saved searches
23
- */
24
- async loadSavedSearches() {
25
- try {
26
- const data = await fs.readFile(this.savedSearchesFilePath, 'utf-8');
27
- const lines = data.split('\n').filter((line) => line.trim() !== '');
28
- return lines.map((line) => JSON.parse(line));
29
- }
30
- catch (error) {
31
- if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
32
- return [];
33
- }
34
- throw error;
35
- }
36
- }
37
- /**
38
- * Save searches to JSONL file.
39
- *
40
- * @param searches - Array of saved searches
41
- */
42
- async saveSavedSearches(searches) {
43
- const lines = searches.map(s => JSON.stringify(s));
44
- await fs.writeFile(this.savedSearchesFilePath, lines.join('\n'));
45
- }
46
- /**
47
- * Save a search query for later reuse.
48
- *
49
- * @param search - Search parameters (without createdAt, useCount, lastUsed)
50
- * @returns The newly created saved search
51
- * @throws Error if search name already exists
52
- */
53
- async saveSearch(search) {
54
- const searches = await this.loadSavedSearches();
55
- // Check if name already exists
56
- if (searches.some(s => s.name === search.name)) {
57
- throw new Error(`Saved search with name "${search.name}" already exists`);
58
- }
59
- const newSearch = {
60
- ...search,
61
- createdAt: new Date().toISOString(),
62
- useCount: 0,
63
- };
64
- searches.push(newSearch);
65
- await this.saveSavedSearches(searches);
66
- return newSearch;
67
- }
68
- /**
69
- * List all saved searches.
70
- *
71
- * @returns Array of all saved searches
72
- */
73
- async listSavedSearches() {
74
- return await this.loadSavedSearches();
75
- }
76
- /**
77
- * Get a specific saved search by name.
78
- *
79
- * @param name - Search name
80
- * @returns Saved search or null if not found
81
- */
82
- async getSavedSearch(name) {
83
- const searches = await this.loadSavedSearches();
84
- return searches.find(s => s.name === name) || null;
85
- }
86
- /**
87
- * Execute a saved search by name.
88
- *
89
- * Updates usage statistics (lastUsed, useCount) before executing.
90
- *
91
- * @param name - Search name
92
- * @returns Search results as knowledge graph
93
- * @throws Error if search not found
94
- */
95
- async executeSavedSearch(name) {
96
- const searches = await this.loadSavedSearches();
97
- const search = searches.find(s => s.name === name);
98
- if (!search) {
99
- throw new Error(`Saved search "${name}" not found`);
100
- }
101
- // Update usage statistics
102
- search.lastUsed = new Date().toISOString();
103
- search.useCount++;
104
- await this.saveSavedSearches(searches);
105
- // Execute the search using BasicSearch
106
- return await this.basicSearch.searchNodes(search.query, search.tags, search.minImportance, search.maxImportance);
107
- }
108
- /**
109
- * Delete a saved search.
110
- *
111
- * @param name - Search name
112
- * @returns True if deleted, false if not found
113
- */
114
- async deleteSavedSearch(name) {
115
- const searches = await this.loadSavedSearches();
116
- const initialLength = searches.length;
117
- const filtered = searches.filter(s => s.name !== name);
118
- if (filtered.length === initialLength) {
119
- return false; // Search not found
120
- }
121
- await this.saveSavedSearches(filtered);
122
- return true;
123
- }
124
- /**
125
- * Update a saved search.
126
- *
127
- * Cannot update name, createdAt, useCount, or lastUsed fields.
128
- *
129
- * @param name - Search name
130
- * @param updates - Partial search with fields to update
131
- * @returns Updated saved search
132
- * @throws Error if search not found
133
- */
134
- async updateSavedSearch(name, updates) {
135
- const searches = await this.loadSavedSearches();
136
- const search = searches.find(s => s.name === name);
137
- if (!search) {
138
- throw new Error(`Saved search "${name}" not found`);
139
- }
140
- // Apply updates
141
- Object.assign(search, updates);
142
- await this.saveSavedSearches(searches);
143
- return search;
144
- }
145
- }
@@ -1,120 +0,0 @@
1
- /**
2
- * Search Filter Chain
3
- *
4
- * Centralizes filter logic for all search implementations to eliminate
5
- * duplicate filtering code across BasicSearch, BooleanSearch, FuzzySearch,
6
- * and RankedSearch.
7
- *
8
- * @module search/SearchFilterChain
9
- */
10
- import type { Entity } from '../types/index.js';
11
- import { type ValidatedPagination } from '../utils/index.js';
12
- /**
13
- * Search filter configuration options.
14
- * All filters are optional - entities pass if filter is not specified.
15
- */
16
- export interface SearchFilters {
17
- /** Tags to filter by (any match) */
18
- tags?: string[];
19
- /** Minimum importance (0-10, inclusive) */
20
- minImportance?: number;
21
- /** Maximum importance (0-10, inclusive) */
22
- maxImportance?: number;
23
- /** Entity type to filter by (exact match) */
24
- entityType?: string;
25
- /** Created after date (ISO 8601, inclusive) */
26
- createdAfter?: string;
27
- /** Created before date (ISO 8601, inclusive) */
28
- createdBefore?: string;
29
- /** Modified after date (ISO 8601, inclusive) */
30
- modifiedAfter?: string;
31
- /** Modified before date (ISO 8601, inclusive) */
32
- modifiedBefore?: string;
33
- }
34
- /**
35
- * Centralized filter chain for all search implementations.
36
- * Ensures consistent filtering behavior across search types.
37
- *
38
- * @example
39
- * ```typescript
40
- * const filters: SearchFilters = { tags: ['important'], minImportance: 5 };
41
- * const filtered = SearchFilterChain.applyFilters(entities, filters);
42
- * const pagination = SearchFilterChain.validatePagination(0, 50);
43
- * const result = SearchFilterChain.paginate(filtered, pagination);
44
- * ```
45
- */
46
- export declare class SearchFilterChain {
47
- /**
48
- * Applies all filters to an array of entities.
49
- * Entities must pass ALL specified filters to be included.
50
- *
51
- * @param entities - Entities to filter
52
- * @param filters - Filter criteria to apply
53
- * @returns Filtered entities array
54
- */
55
- static applyFilters(entities: readonly Entity[], filters: SearchFilters): Entity[];
56
- /**
57
- * Checks if an entity passes all active filters.
58
- * Short-circuits on first failing filter for performance.
59
- *
60
- * @param entity - Entity to check
61
- * @param filters - Filter criteria
62
- * @param normalizedSearchTags - Pre-normalized search tags (for efficiency)
63
- * @returns true if entity passes all filters
64
- */
65
- static entityPassesFilters(entity: Entity, filters: SearchFilters, normalizedSearchTags?: string[]): boolean;
66
- /**
67
- * Checks if any filters are actually specified.
68
- * Used for early return optimization.
69
- *
70
- * @param filters - Filter criteria to check
71
- * @returns true if at least one filter is active
72
- */
73
- static hasActiveFilters(filters: SearchFilters): boolean;
74
- /**
75
- * Validates and returns pagination parameters.
76
- * Delegates to paginationUtils.validatePagination.
77
- *
78
- * @param offset - Starting position
79
- * @param limit - Maximum results
80
- * @returns Validated pagination object
81
- */
82
- static validatePagination(offset?: number, limit?: number): ValidatedPagination;
83
- /**
84
- * Applies pagination to a filtered result set.
85
- *
86
- * @param entities - Entities to paginate
87
- * @param pagination - Validated pagination parameters
88
- * @returns Paginated slice of entities
89
- */
90
- static paginate(entities: Entity[], pagination: ValidatedPagination): Entity[];
91
- /**
92
- * Convenience method to apply both filters and pagination in one call.
93
- *
94
- * @param entities - Entities to process
95
- * @param filters - Filter criteria
96
- * @param offset - Pagination offset
97
- * @param limit - Pagination limit
98
- * @returns Filtered and paginated entities
99
- */
100
- static filterAndPaginate(entities: Entity[], filters: SearchFilters, offset?: number, limit?: number): Entity[];
101
- /**
102
- * Applies tag filter only. Useful when other filters are handled separately.
103
- *
104
- * @param entities - Entities to filter
105
- * @param tags - Tags to filter by
106
- * @returns Filtered entities
107
- */
108
- static filterByTags(entities: Entity[], tags?: string[]): Entity[];
109
- /**
110
- * Applies importance filter only. Useful when other filters are handled separately.
111
- *
112
- * @param entities - Entities to filter
113
- * @param minImportance - Minimum importance
114
- * @param maxImportance - Maximum importance
115
- * @returns Filtered entities
116
- */
117
- static filterByImportance(entities: Entity[], minImportance?: number, maxImportance?: number): Entity[];
118
- }
119
- export type { ValidatedPagination };
120
- //# sourceMappingURL=SearchFilterChain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchFilterChain.d.ts","sourceRoot":"","sources":["../../src/search/SearchFilterChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAiB;IAC5B;;;;;;;OAOG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE;IAgBlF;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,oBAAoB,CAAC,EAAE,MAAM,EAAE,GAC9B,OAAO;IAsDV;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAaxD;;;;;;;OAOG;IACH,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAE,MAAU,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,mBAAmB;IAIlF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,mBAAmB,GAAG,MAAM,EAAE;IAI9E;;;;;;;;OAQG;IACH,MAAM,CAAC,iBAAiB,CACtB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,aAAa,EACtB,MAAM,GAAE,MAAU,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,EAAE;IAMX;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAclE;;;;;;;OAOG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAQ,EAAE,MAAM,EAAE,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,EAAE;CASZ;AAGD,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
@@ -1,185 +0,0 @@
1
- /**
2
- * Search Filter Chain
3
- *
4
- * Centralizes filter logic for all search implementations to eliminate
5
- * duplicate filtering code across BasicSearch, BooleanSearch, FuzzySearch,
6
- * and RankedSearch.
7
- *
8
- * @module search/SearchFilterChain
9
- */
10
- import { normalizeTags, hasMatchingTag, isWithinImportanceRange, validatePagination, applyPagination, } from '../utils/index.js';
11
- /**
12
- * Centralized filter chain for all search implementations.
13
- * Ensures consistent filtering behavior across search types.
14
- *
15
- * @example
16
- * ```typescript
17
- * const filters: SearchFilters = { tags: ['important'], minImportance: 5 };
18
- * const filtered = SearchFilterChain.applyFilters(entities, filters);
19
- * const pagination = SearchFilterChain.validatePagination(0, 50);
20
- * const result = SearchFilterChain.paginate(filtered, pagination);
21
- * ```
22
- */
23
- export class SearchFilterChain {
24
- /**
25
- * Applies all filters to an array of entities.
26
- * Entities must pass ALL specified filters to be included.
27
- *
28
- * @param entities - Entities to filter
29
- * @param filters - Filter criteria to apply
30
- * @returns Filtered entities array
31
- */
32
- static applyFilters(entities, filters) {
33
- // Early return if no filters are active
34
- if (!this.hasActiveFilters(filters)) {
35
- return [...entities];
36
- }
37
- // Pre-normalize tags once for efficiency
38
- const normalizedSearchTags = filters.tags?.length
39
- ? normalizeTags(filters.tags)
40
- : undefined;
41
- return entities.filter(entity => this.entityPassesFilters(entity, filters, normalizedSearchTags));
42
- }
43
- /**
44
- * Checks if an entity passes all active filters.
45
- * Short-circuits on first failing filter for performance.
46
- *
47
- * @param entity - Entity to check
48
- * @param filters - Filter criteria
49
- * @param normalizedSearchTags - Pre-normalized search tags (for efficiency)
50
- * @returns true if entity passes all filters
51
- */
52
- static entityPassesFilters(entity, filters, normalizedSearchTags) {
53
- // Tag filter - check if entity has any matching tag
54
- if (normalizedSearchTags && normalizedSearchTags.length > 0) {
55
- if (!entity.tags || entity.tags.length === 0) {
56
- return false;
57
- }
58
- const entityTags = normalizeTags(entity.tags);
59
- const hasMatch = normalizedSearchTags.some(tag => entityTags.includes(tag));
60
- if (!hasMatch) {
61
- return false;
62
- }
63
- }
64
- // Importance filter
65
- if (!isWithinImportanceRange(entity.importance, filters.minImportance, filters.maxImportance)) {
66
- return false;
67
- }
68
- // Entity type filter
69
- if (filters.entityType && entity.entityType !== filters.entityType) {
70
- return false;
71
- }
72
- // Created date filter
73
- if (filters.createdAfter || filters.createdBefore) {
74
- if (!entity.createdAt) {
75
- return false;
76
- }
77
- const createdAt = new Date(entity.createdAt);
78
- if (filters.createdAfter && createdAt < new Date(filters.createdAfter)) {
79
- return false;
80
- }
81
- if (filters.createdBefore && createdAt > new Date(filters.createdBefore)) {
82
- return false;
83
- }
84
- }
85
- // Modified date filter
86
- if (filters.modifiedAfter || filters.modifiedBefore) {
87
- if (!entity.lastModified) {
88
- return false;
89
- }
90
- const modifiedAt = new Date(entity.lastModified);
91
- if (filters.modifiedAfter && modifiedAt < new Date(filters.modifiedAfter)) {
92
- return false;
93
- }
94
- if (filters.modifiedBefore && modifiedAt > new Date(filters.modifiedBefore)) {
95
- return false;
96
- }
97
- }
98
- return true;
99
- }
100
- /**
101
- * Checks if any filters are actually specified.
102
- * Used for early return optimization.
103
- *
104
- * @param filters - Filter criteria to check
105
- * @returns true if at least one filter is active
106
- */
107
- static hasActiveFilters(filters) {
108
- return !!((filters.tags && filters.tags.length > 0) ||
109
- filters.minImportance !== undefined ||
110
- filters.maxImportance !== undefined ||
111
- filters.entityType ||
112
- filters.createdAfter ||
113
- filters.createdBefore ||
114
- filters.modifiedAfter ||
115
- filters.modifiedBefore);
116
- }
117
- /**
118
- * Validates and returns pagination parameters.
119
- * Delegates to paginationUtils.validatePagination.
120
- *
121
- * @param offset - Starting position
122
- * @param limit - Maximum results
123
- * @returns Validated pagination object
124
- */
125
- static validatePagination(offset = 0, limit) {
126
- return validatePagination(offset, limit);
127
- }
128
- /**
129
- * Applies pagination to a filtered result set.
130
- *
131
- * @param entities - Entities to paginate
132
- * @param pagination - Validated pagination parameters
133
- * @returns Paginated slice of entities
134
- */
135
- static paginate(entities, pagination) {
136
- return applyPagination(entities, pagination);
137
- }
138
- /**
139
- * Convenience method to apply both filters and pagination in one call.
140
- *
141
- * @param entities - Entities to process
142
- * @param filters - Filter criteria
143
- * @param offset - Pagination offset
144
- * @param limit - Pagination limit
145
- * @returns Filtered and paginated entities
146
- */
147
- static filterAndPaginate(entities, filters, offset = 0, limit) {
148
- const filtered = this.applyFilters(entities, filters);
149
- const pagination = this.validatePagination(offset, limit);
150
- return this.paginate(filtered, pagination);
151
- }
152
- /**
153
- * Applies tag filter only. Useful when other filters are handled separately.
154
- *
155
- * @param entities - Entities to filter
156
- * @param tags - Tags to filter by
157
- * @returns Filtered entities
158
- */
159
- static filterByTags(entities, tags) {
160
- if (!tags || tags.length === 0) {
161
- return entities;
162
- }
163
- const normalizedTags = normalizeTags(tags);
164
- return entities.filter(entity => {
165
- if (!entity.tags || entity.tags.length === 0) {
166
- return false;
167
- }
168
- return hasMatchingTag(entity.tags, normalizedTags);
169
- });
170
- }
171
- /**
172
- * Applies importance filter only. Useful when other filters are handled separately.
173
- *
174
- * @param entities - Entities to filter
175
- * @param minImportance - Minimum importance
176
- * @param maxImportance - Maximum importance
177
- * @returns Filtered entities
178
- */
179
- static filterByImportance(entities, minImportance, maxImportance) {
180
- if (minImportance === undefined && maxImportance === undefined) {
181
- return entities;
182
- }
183
- return entities.filter(entity => isWithinImportanceRange(entity.importance, minImportance, maxImportance));
184
- }
185
- }