@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,121 +0,0 @@
1
- /**
2
- * Custom Error Types
3
- *
4
- * Defines custom error classes for better error handling and debugging.
5
- *
6
- * @module utils/errors
7
- */
8
- /**
9
- * Base error class for all knowledge graph errors.
10
- * Extends the native Error class with additional context.
11
- */
12
- export class KnowledgeGraphError extends Error {
13
- code;
14
- constructor(message, code) {
15
- super(message);
16
- this.code = code;
17
- this.name = 'KnowledgeGraphError';
18
- // Maintains proper stack trace in V8 engines
19
- if (Error.captureStackTrace) {
20
- Error.captureStackTrace(this, this.constructor);
21
- }
22
- }
23
- }
24
- /**
25
- * Error thrown when an entity is not found.
26
- */
27
- export class EntityNotFoundError extends KnowledgeGraphError {
28
- constructor(entityName) {
29
- super(`Entity "${entityName}" not found`, 'ENTITY_NOT_FOUND');
30
- this.name = 'EntityNotFoundError';
31
- }
32
- }
33
- /**
34
- * Error thrown when a relation is not found.
35
- */
36
- export class RelationNotFoundError extends KnowledgeGraphError {
37
- constructor(from, to, relationType) {
38
- const desc = relationType
39
- ? `Relation "${from}" --[${relationType}]--> "${to}"`
40
- : `Relation from "${from}" to "${to}"`;
41
- super(`${desc} not found`, 'RELATION_NOT_FOUND');
42
- this.name = 'RelationNotFoundError';
43
- }
44
- }
45
- /**
46
- * Error thrown when attempting to create a duplicate entity.
47
- */
48
- export class DuplicateEntityError extends KnowledgeGraphError {
49
- constructor(entityName) {
50
- super(`Entity "${entityName}" already exists`, 'DUPLICATE_ENTITY');
51
- this.name = 'DuplicateEntityError';
52
- }
53
- }
54
- /**
55
- * Error thrown when validation fails.
56
- */
57
- export class ValidationError extends KnowledgeGraphError {
58
- errors;
59
- constructor(message, errors) {
60
- super(message, 'VALIDATION_ERROR');
61
- this.errors = errors;
62
- this.name = 'ValidationError';
63
- }
64
- }
65
- /**
66
- * Error thrown when a cycle is detected in hierarchies.
67
- */
68
- export class CycleDetectedError extends KnowledgeGraphError {
69
- constructor(entityName, parentName) {
70
- super(`Setting parent "${parentName}" for entity "${entityName}" would create a cycle`, 'CYCLE_DETECTED');
71
- this.name = 'CycleDetectedError';
72
- }
73
- }
74
- /**
75
- * Error thrown when an invalid importance value is provided.
76
- */
77
- export class InvalidImportanceError extends KnowledgeGraphError {
78
- constructor(value, min = 0, max = 10) {
79
- super(`Importance must be between ${min} and ${max}, got ${value}`, 'INVALID_IMPORTANCE');
80
- this.name = 'InvalidImportanceError';
81
- }
82
- }
83
- /**
84
- * Error thrown when a file operation fails.
85
- */
86
- export class FileOperationError extends KnowledgeGraphError {
87
- constructor(operation, filePath, cause) {
88
- super(`Failed to ${operation} file: ${filePath}${cause ? ` - ${cause.message}` : ''}`, 'FILE_OPERATION_ERROR');
89
- this.name = 'FileOperationError';
90
- if (cause) {
91
- this.cause = cause;
92
- }
93
- }
94
- }
95
- /**
96
- * Error thrown when an import operation fails.
97
- */
98
- export class ImportError extends KnowledgeGraphError {
99
- constructor(format, message) {
100
- super(`Import failed (${format}): ${message}`, 'IMPORT_ERROR');
101
- this.name = 'ImportError';
102
- }
103
- }
104
- /**
105
- * Error thrown when an export operation fails.
106
- */
107
- export class ExportError extends KnowledgeGraphError {
108
- constructor(format, message) {
109
- super(`Export failed (${format}): ${message}`, 'EXPORT_ERROR');
110
- this.name = 'ExportError';
111
- }
112
- }
113
- /**
114
- * Error thrown when insufficient entities are provided for an operation.
115
- */
116
- export class InsufficientEntitiesError extends KnowledgeGraphError {
117
- constructor(operation, required, provided) {
118
- super(`${operation} requires at least ${required} entities, got ${provided}`, 'INSUFFICIENT_ENTITIES');
119
- this.name = 'InsufficientEntitiesError';
120
- }
121
- }
@@ -1,145 +0,0 @@
1
- /**
2
- * Response and Pagination Formatters
3
- *
4
- * Consolidated module for MCP tool response formatting and pagination utilities.
5
- * Centralizes response formatting for MCP tool calls to eliminate redundant patterns.
6
- *
7
- * @module utils/formatters
8
- */
9
- /**
10
- * MCP Tool Response type - uses the exact shape expected by the SDK.
11
- * The 'as const' assertion ensures the type literal is preserved.
12
- */
13
- export type ToolResponse = {
14
- content: Array<{
15
- type: 'text';
16
- text: string;
17
- }>;
18
- isError?: boolean;
19
- };
20
- /**
21
- * Formats data as an MCP tool response with JSON content.
22
- * Centralizes the response format to ensure consistency and reduce duplication.
23
- *
24
- * @param data - Any data to be JSON stringified
25
- * @returns Formatted MCP tool response
26
- */
27
- export declare function formatToolResponse(data: unknown): {
28
- content: {
29
- type: "text";
30
- text: string;
31
- }[];
32
- };
33
- /**
34
- * Formats a simple text message as an MCP tool response.
35
- * Use for success messages that don't need JSON formatting.
36
- *
37
- * @param message - Plain text message
38
- * @returns Formatted MCP tool response
39
- */
40
- export declare function formatTextResponse(message: string): {
41
- content: {
42
- type: "text";
43
- text: string;
44
- }[];
45
- };
46
- /**
47
- * Formats raw string content as an MCP tool response.
48
- * Use for export formats that return pre-formatted strings (markdown, CSV, etc.)
49
- *
50
- * @param content - Raw string content
51
- * @returns Formatted MCP tool response
52
- */
53
- export declare function formatRawResponse(content: string): {
54
- content: {
55
- type: "text";
56
- text: string;
57
- }[];
58
- };
59
- /**
60
- * Formats an error as an MCP tool response with isError flag.
61
- *
62
- * @param error - Error object or message string
63
- * @returns Formatted MCP tool error response
64
- */
65
- export declare function formatErrorResponse(error: Error | string): {
66
- content: {
67
- type: "text";
68
- text: string;
69
- }[];
70
- isError: boolean;
71
- };
72
- /**
73
- * Validated pagination parameters with helper methods.
74
- */
75
- export interface ValidatedPagination {
76
- /** Validated offset (guaranteed >= 0) */
77
- offset: number;
78
- /** Validated limit (guaranteed within SEARCH_LIMITS.MIN to SEARCH_LIMITS.MAX) */
79
- limit: number;
80
- /**
81
- * Check if there are more results beyond the current page.
82
- * @param totalCount - Total number of items
83
- * @returns true if there are more items after this page
84
- */
85
- hasMore: (totalCount: number) => boolean;
86
- }
87
- /**
88
- * Validates and normalizes pagination parameters.
89
- * Ensures offset is non-negative and limit is within configured bounds.
90
- *
91
- * @param offset - Starting position (default: 0)
92
- * @param limit - Maximum results to return (default: SEARCH_LIMITS.DEFAULT)
93
- * @returns Validated pagination parameters with helper methods
94
- *
95
- * @example
96
- * ```typescript
97
- * const pagination = validatePagination(10, 50);
98
- * const results = items.slice(pagination.offset, pagination.offset + pagination.limit);
99
- * if (pagination.hasMore(items.length)) {
100
- * console.log('More results available');
101
- * }
102
- * ```
103
- */
104
- export declare function validatePagination(offset?: number, limit?: number): ValidatedPagination;
105
- /**
106
- * Applies pagination to an array of items.
107
- *
108
- * @param items - Array to paginate
109
- * @param pagination - Validated pagination parameters
110
- * @returns Paginated slice of the array
111
- *
112
- * @example
113
- * ```typescript
114
- * const pagination = validatePagination(offset, limit);
115
- * const pageResults = applyPagination(allResults, pagination);
116
- * ```
117
- */
118
- export declare function applyPagination<T>(items: T[], pagination: ValidatedPagination): T[];
119
- /**
120
- * Applies pagination using raw offset and limit values.
121
- * Combines validation and application in one call.
122
- *
123
- * @param items - Array to paginate
124
- * @param offset - Starting position
125
- * @param limit - Maximum results
126
- * @returns Paginated slice of the array
127
- */
128
- export declare function paginateArray<T>(items: T[], offset?: number, limit?: number): T[];
129
- /**
130
- * Calculates pagination metadata for a result set.
131
- *
132
- * @param totalCount - Total number of items
133
- * @param offset - Current offset
134
- * @param limit - Current limit
135
- * @returns Pagination metadata
136
- */
137
- export declare function getPaginationMeta(totalCount: number, offset?: number, limit?: number): {
138
- totalCount: number;
139
- offset: number;
140
- limit: number;
141
- hasMore: boolean;
142
- pageNumber: number;
143
- totalPages: number;
144
- };
145
- //# sourceMappingURL=formatters.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,KAAK,CAAC;QAAE,I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ACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAWA"}
@@ -1,132 +0,0 @@
1
- /**
2
- * Response and Pagination Formatters
3
- *
4
- * Consolidated module for MCP tool response formatting and pagination utilities.
5
- * Centralizes response formatting for MCP tool calls to eliminate redundant patterns.
6
- *
7
- * @module utils/formatters
8
- */
9
- import { SEARCH_LIMITS } from './constants.js';
10
- /**
11
- * Formats data as an MCP tool response with JSON content.
12
- * Centralizes the response format to ensure consistency and reduce duplication.
13
- *
14
- * @param data - Any data to be JSON stringified
15
- * @returns Formatted MCP tool response
16
- */
17
- export function formatToolResponse(data) {
18
- return {
19
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
20
- };
21
- }
22
- /**
23
- * Formats a simple text message as an MCP tool response.
24
- * Use for success messages that don't need JSON formatting.
25
- *
26
- * @param message - Plain text message
27
- * @returns Formatted MCP tool response
28
- */
29
- export function formatTextResponse(message) {
30
- return {
31
- content: [{ type: 'text', text: message }],
32
- };
33
- }
34
- /**
35
- * Formats raw string content as an MCP tool response.
36
- * Use for export formats that return pre-formatted strings (markdown, CSV, etc.)
37
- *
38
- * @param content - Raw string content
39
- * @returns Formatted MCP tool response
40
- */
41
- export function formatRawResponse(content) {
42
- return {
43
- content: [{ type: 'text', text: content }],
44
- };
45
- }
46
- /**
47
- * Formats an error as an MCP tool response with isError flag.
48
- *
49
- * @param error - Error object or message string
50
- * @returns Formatted MCP tool error response
51
- */
52
- export function formatErrorResponse(error) {
53
- const message = error instanceof Error ? error.message : error;
54
- return {
55
- content: [{ type: 'text', text: message }],
56
- isError: true,
57
- };
58
- }
59
- /**
60
- * Validates and normalizes pagination parameters.
61
- * Ensures offset is non-negative and limit is within configured bounds.
62
- *
63
- * @param offset - Starting position (default: 0)
64
- * @param limit - Maximum results to return (default: SEARCH_LIMITS.DEFAULT)
65
- * @returns Validated pagination parameters with helper methods
66
- *
67
- * @example
68
- * ```typescript
69
- * const pagination = validatePagination(10, 50);
70
- * const results = items.slice(pagination.offset, pagination.offset + pagination.limit);
71
- * if (pagination.hasMore(items.length)) {
72
- * console.log('More results available');
73
- * }
74
- * ```
75
- */
76
- export function validatePagination(offset = 0, limit = SEARCH_LIMITS.DEFAULT) {
77
- const validatedOffset = Math.max(0, offset);
78
- const validatedLimit = Math.min(Math.max(SEARCH_LIMITS.MIN, limit), SEARCH_LIMITS.MAX);
79
- return {
80
- offset: validatedOffset,
81
- limit: validatedLimit,
82
- hasMore: (totalCount) => validatedOffset + validatedLimit < totalCount,
83
- };
84
- }
85
- /**
86
- * Applies pagination to an array of items.
87
- *
88
- * @param items - Array to paginate
89
- * @param pagination - Validated pagination parameters
90
- * @returns Paginated slice of the array
91
- *
92
- * @example
93
- * ```typescript
94
- * const pagination = validatePagination(offset, limit);
95
- * const pageResults = applyPagination(allResults, pagination);
96
- * ```
97
- */
98
- export function applyPagination(items, pagination) {
99
- return items.slice(pagination.offset, pagination.offset + pagination.limit);
100
- }
101
- /**
102
- * Applies pagination using raw offset and limit values.
103
- * Combines validation and application in one call.
104
- *
105
- * @param items - Array to paginate
106
- * @param offset - Starting position
107
- * @param limit - Maximum results
108
- * @returns Paginated slice of the array
109
- */
110
- export function paginateArray(items, offset = 0, limit = SEARCH_LIMITS.DEFAULT) {
111
- const pagination = validatePagination(offset, limit);
112
- return applyPagination(items, pagination);
113
- }
114
- /**
115
- * Calculates pagination metadata for a result set.
116
- *
117
- * @param totalCount - Total number of items
118
- * @param offset - Current offset
119
- * @param limit - Current limit
120
- * @returns Pagination metadata
121
- */
122
- export function getPaginationMeta(totalCount, offset = 0, limit = SEARCH_LIMITS.DEFAULT) {
123
- const pagination = validatePagination(offset, limit);
124
- return {
125
- totalCount,
126
- offset: pagination.offset,
127
- limit: pagination.limit,
128
- hasMore: pagination.hasMore(totalCount),
129
- pageNumber: Math.floor(pagination.offset / pagination.limit) + 1,
130
- totalPages: Math.ceil(totalCount / pagination.limit),
131
- };
132
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Utilities Module Barrel Export
3
- *
4
- * Centralizes all utility exports for convenient importing.
5
- * Consolidated from 17 files to 9 focused modules (Phase 5 cleanup).
6
- *
7
- * @module utils
8
- */
9
- export { KnowledgeGraphError, EntityNotFoundError, RelationNotFoundError, DuplicateEntityError, ValidationError, CycleDetectedError, InvalidImportanceError, FileOperationError, ImportError, ExportError, InsufficientEntitiesError, } from './errors.js';
10
- export { FILE_EXTENSIONS, FILE_SUFFIXES, DEFAULT_FILE_NAMES, ENV_VARS, DEFAULT_BASE_DIR, LOG_PREFIXES, SIMILARITY_WEIGHTS, DEFAULT_DUPLICATE_THRESHOLD, SEARCH_LIMITS, IMPORTANCE_RANGE, GRAPH_LIMITS, QUERY_LIMITS, COMPRESSION_CONFIG, STREAMING_CONFIG, type CompressionQuality, } from './constants.js';
11
- export { compress, decompress, compressFile, decompressFile, compressToBase64, decompressFromBase64, hasBrotliExtension, getCompressionRatio, createMetadata, createUncompressedMetadata, type CompressionOptions, type CompressionResult, type CompressionMetadata, } from './compressionUtil.js';
12
- export { CompressedCache, type CompressedCacheOptions, type CompressedCacheStats, } from './compressedCache.js';
13
- export { logger } from './logger.js';
14
- export { levenshteinDistance, calculateTF, calculateIDF, calculateIDFFromTokenSets, calculateTFIDF, tokenize, } from './searchAlgorithms.js';
15
- export { NameIndex, TypeIndex, LowercaseCache, RelationIndex, } from './indexes.js';
16
- export { SearchCache, searchCaches, clearAllSearchCaches, getAllCacheStats, cleanupAllCaches, type CacheStats, } from './searchCache.js';
17
- export { EntitySchema, CreateEntitySchema, UpdateEntitySchema, RelationSchema, CreateRelationSchema, SearchQuerySchema, DateRangeSchema, TagAliasSchema, ExportFormatSchema, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema, AddObservationInputSchema, AddObservationsInputSchema, DeleteObservationInputSchema, DeleteObservationsInputSchema, ArchiveCriteriaSchema, SavedSearchInputSchema, SavedSearchUpdateSchema, ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema, OptionalTagsSchema, OptionalEntityNamesSchema, type EntityInput, type CreateEntityInput, type UpdateEntityInput, type RelationInput, type CreateRelationInput, type SearchQuery, type DateRange, type TagAlias, type ExportFormat, type AddObservationInput, type DeleteObservationInput, type ArchiveCriteriaInput, type SavedSearchInput, type SavedSearchUpdateInput, type ImportFormat, type ExtendedExportFormat, type MergeStrategy, type ExportFilterInput, type ValidationResult, formatZodErrors, validateWithSchema, validateSafe, validateArrayWithSchema, validateEntity, validateRelation, validateImportance, validateTags, } from './schemas.js';
18
- export { formatToolResponse, formatTextResponse, formatRawResponse, formatErrorResponse, type ToolResponse, validatePagination, applyPagination, paginateArray, getPaginationMeta, type ValidatedPagination, } from './formatters.js';
19
- export { findEntityByName, findEntitiesByNames, entityExists, getEntityIndex, removeEntityByName, getEntityNameSet, groupEntitiesByType, touchEntity, normalizeTag, normalizeTags, hasMatchingTag, hasAllTags, filterByTags, addUniqueTags, removeTags, isWithinDateRange, parseDateRange, isValidISODate, getCurrentTimestamp, isWithinImportanceRange, filterByImportance, filterByCreatedDate, filterByModifiedDate, filterByEntityType, entityPassesFilters, type CommonSearchFilters, validateFilePath, defaultMemoryPath, ensureMemoryFilePath, } from './entityUtils.js';
20
- export { parallelMap, parallelFilter, getPoolStats, shutdownParallelUtils, } from './parallelUtils.js';
21
- export { TaskPriority, TaskStatus, type Task, type TaskResult, type ProgressCallback, type BatchOptions, type QueueStats, TaskQueue, batchProcess, rateLimitedProcess, withRetry, debounce, throttle, } from './taskScheduler.js';
22
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACp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AmB,EAExB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAEL,YAAY,EACZ,UAAU,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,SAAS,EAET,YAAY,EACZ,kBAAkB,EAClB,SAAS,EAET,QAAQ,EACR,QAAQ,GACT,MAAM,oBAAoB,CAAC"}
@@ -1,75 +0,0 @@
1
- /**
2
- * Utilities Module Barrel Export
3
- *
4
- * Centralizes all utility exports for convenient importing.
5
- * Consolidated from 17 files to 9 focused modules (Phase 5 cleanup).
6
- *
7
- * @module utils
8
- */
9
- // ==================== Error Types ====================
10
- export { KnowledgeGraphError, EntityNotFoundError, RelationNotFoundError, DuplicateEntityError, ValidationError, CycleDetectedError, InvalidImportanceError, FileOperationError, ImportError, ExportError, InsufficientEntitiesError, } from './errors.js';
11
- // ==================== Constants ====================
12
- export { FILE_EXTENSIONS, FILE_SUFFIXES, DEFAULT_FILE_NAMES, ENV_VARS, DEFAULT_BASE_DIR, LOG_PREFIXES, SIMILARITY_WEIGHTS, DEFAULT_DUPLICATE_THRESHOLD, SEARCH_LIMITS, IMPORTANCE_RANGE, GRAPH_LIMITS, QUERY_LIMITS, COMPRESSION_CONFIG, STREAMING_CONFIG, } from './constants.js';
13
- // ==================== Compression Utilities ====================
14
- export { compress, decompress, compressFile, decompressFile, compressToBase64, decompressFromBase64, hasBrotliExtension, getCompressionRatio, createMetadata, createUncompressedMetadata, } from './compressionUtil.js';
15
- // ==================== Compressed Cache ====================
16
- export { CompressedCache, } from './compressedCache.js';
17
- // ==================== Logger ====================
18
- export { logger } from './logger.js';
19
- // ==================== Search Algorithms ====================
20
- export { levenshteinDistance, calculateTF, calculateIDF, calculateIDFFromTokenSets, calculateTFIDF, tokenize, } from './searchAlgorithms.js';
21
- // ==================== Indexes ====================
22
- export { NameIndex, TypeIndex, LowercaseCache, RelationIndex, } from './indexes.js';
23
- // ==================== Search Cache ====================
24
- export { SearchCache, searchCaches, clearAllSearchCaches, getAllCacheStats, cleanupAllCaches, } from './searchCache.js';
25
- // ==================== Schemas and Validation ====================
26
- // Consolidated from: schemas.ts, validationHelper.ts, validationUtils.ts
27
- export {
28
- // Zod schemas - Entity/Relation
29
- EntitySchema, CreateEntitySchema, UpdateEntitySchema, RelationSchema, CreateRelationSchema, SearchQuerySchema, DateRangeSchema, TagAliasSchema, ExportFormatSchema, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema,
30
- // Zod schemas - Observations
31
- AddObservationInputSchema, AddObservationsInputSchema, DeleteObservationInputSchema, DeleteObservationsInputSchema,
32
- // Zod schemas - Archive
33
- ArchiveCriteriaSchema,
34
- // Zod schemas - Saved Search
35
- SavedSearchInputSchema, SavedSearchUpdateSchema,
36
- // Zod schemas - Import/Export
37
- ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema,
38
- // Zod schemas - Search
39
- OptionalTagsSchema, OptionalEntityNamesSchema,
40
- // Zod helpers
41
- formatZodErrors, validateWithSchema, validateSafe, validateArrayWithSchema,
42
- // Manual validation functions
43
- validateEntity, validateRelation, validateImportance, validateTags, } from './schemas.js';
44
- // ==================== Formatters ====================
45
- // Consolidated from: responseFormatter.ts, paginationUtils.ts
46
- export {
47
- // Response formatting
48
- formatToolResponse, formatTextResponse, formatRawResponse, formatErrorResponse,
49
- // Pagination utilities
50
- validatePagination, applyPagination, paginateArray, getPaginationMeta, } from './formatters.js';
51
- // ==================== Entity Utilities ====================
52
- // Consolidated from: entityUtils.ts, tagUtils.ts, dateUtils.ts, filterUtils.ts, pathUtils.ts
53
- export {
54
- // Entity lookup
55
- findEntityByName, findEntitiesByNames, entityExists, getEntityIndex, removeEntityByName, getEntityNameSet, groupEntitiesByType, touchEntity,
56
- // Tag utilities
57
- normalizeTag, normalizeTags, hasMatchingTag, hasAllTags, filterByTags, addUniqueTags, removeTags,
58
- // Date utilities
59
- isWithinDateRange, parseDateRange, isValidISODate, getCurrentTimestamp,
60
- // Filter utilities
61
- isWithinImportanceRange, filterByImportance, filterByCreatedDate, filterByModifiedDate, filterByEntityType, entityPassesFilters,
62
- // Path utilities
63
- validateFilePath, defaultMemoryPath, ensureMemoryFilePath, } from './entityUtils.js';
64
- // ==================== Parallel Utilities ====================
65
- export { parallelMap, parallelFilter, getPoolStats, shutdownParallelUtils, } from './parallelUtils.js';
66
- // ==================== Task Scheduler ====================
67
- export {
68
- // Types and Enums
69
- TaskPriority, TaskStatus,
70
- // Task Queue
71
- TaskQueue,
72
- // Batch Processing
73
- batchProcess, rateLimitedProcess, withRetry,
74
- // Rate Limiting
75
- debounce, throttle, } from './taskScheduler.js';