driftdetect-core 0.4.1 → 0.4.3

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 (238) hide show
  1. package/LICENSE +21 -0
  2. package/dist/boundaries/boundary-scanner.d.ts +76 -0
  3. package/dist/boundaries/boundary-scanner.d.ts.map +1 -0
  4. package/dist/boundaries/boundary-scanner.js +801 -0
  5. package/dist/boundaries/boundary-scanner.js.map +1 -0
  6. package/dist/boundaries/data-access-learner.d.ts +126 -0
  7. package/dist/boundaries/data-access-learner.d.ts.map +1 -0
  8. package/dist/boundaries/data-access-learner.js +486 -0
  9. package/dist/boundaries/data-access-learner.js.map +1 -0
  10. package/dist/boundaries/index.d.ts +6 -0
  11. package/dist/boundaries/index.d.ts.map +1 -1
  12. package/dist/boundaries/index.js +6 -0
  13. package/dist/boundaries/index.js.map +1 -1
  14. package/dist/boundaries/security-prioritizer.d.ts +118 -0
  15. package/dist/boundaries/security-prioritizer.d.ts.map +1 -0
  16. package/dist/boundaries/security-prioritizer.js +316 -0
  17. package/dist/boundaries/security-prioritizer.js.map +1 -0
  18. package/dist/call-graph/analysis/coverage-analyzer.d.ts +201 -0
  19. package/dist/call-graph/analysis/coverage-analyzer.d.ts.map +1 -0
  20. package/dist/call-graph/analysis/coverage-analyzer.js +553 -0
  21. package/dist/call-graph/analysis/coverage-analyzer.js.map +1 -0
  22. package/dist/call-graph/analysis/dead-code-detector.d.ts +145 -0
  23. package/dist/call-graph/analysis/dead-code-detector.d.ts.map +1 -0
  24. package/dist/call-graph/analysis/dead-code-detector.js +391 -0
  25. package/dist/call-graph/analysis/dead-code-detector.js.map +1 -0
  26. package/dist/call-graph/analysis/graph-builder.d.ts +142 -0
  27. package/dist/call-graph/analysis/graph-builder.d.ts.map +1 -0
  28. package/dist/call-graph/analysis/graph-builder.js +624 -0
  29. package/dist/call-graph/analysis/graph-builder.js.map +1 -0
  30. package/dist/call-graph/analysis/impact-analyzer.d.ts +150 -0
  31. package/dist/call-graph/analysis/impact-analyzer.d.ts.map +1 -0
  32. package/dist/call-graph/analysis/impact-analyzer.js +329 -0
  33. package/dist/call-graph/analysis/impact-analyzer.js.map +1 -0
  34. package/dist/call-graph/analysis/index.d.ts +11 -0
  35. package/dist/call-graph/analysis/index.d.ts.map +1 -0
  36. package/dist/call-graph/analysis/index.js +9 -0
  37. package/dist/call-graph/analysis/index.js.map +1 -0
  38. package/dist/call-graph/analysis/path-finder.d.ts +117 -0
  39. package/dist/call-graph/analysis/path-finder.d.ts.map +1 -0
  40. package/dist/call-graph/analysis/path-finder.js +360 -0
  41. package/dist/call-graph/analysis/path-finder.js.map +1 -0
  42. package/dist/call-graph/analysis/reachability.d.ts +56 -0
  43. package/dist/call-graph/analysis/reachability.d.ts.map +1 -0
  44. package/dist/call-graph/analysis/reachability.js +357 -0
  45. package/dist/call-graph/analysis/reachability.js.map +1 -0
  46. package/dist/call-graph/demo.d.ts +11 -0
  47. package/dist/call-graph/demo.d.ts.map +1 -0
  48. package/dist/call-graph/demo.js +339 -0
  49. package/dist/call-graph/demo.js.map +1 -0
  50. package/dist/call-graph/enrichment/enrichment-engine.d.ts +126 -0
  51. package/dist/call-graph/enrichment/enrichment-engine.d.ts.map +1 -0
  52. package/dist/call-graph/enrichment/enrichment-engine.js +760 -0
  53. package/dist/call-graph/enrichment/enrichment-engine.js.map +1 -0
  54. package/dist/call-graph/enrichment/impact-scorer.d.ts +59 -0
  55. package/dist/call-graph/enrichment/impact-scorer.d.ts.map +1 -0
  56. package/dist/call-graph/enrichment/impact-scorer.js +328 -0
  57. package/dist/call-graph/enrichment/impact-scorer.js.map +1 -0
  58. package/dist/call-graph/enrichment/index.d.ts +12 -0
  59. package/dist/call-graph/enrichment/index.d.ts.map +1 -0
  60. package/dist/call-graph/enrichment/index.js +15 -0
  61. package/dist/call-graph/enrichment/index.js.map +1 -0
  62. package/dist/call-graph/enrichment/remediation-generator.d.ts +41 -0
  63. package/dist/call-graph/enrichment/remediation-generator.d.ts.map +1 -0
  64. package/dist/call-graph/enrichment/remediation-generator.js +609 -0
  65. package/dist/call-graph/enrichment/remediation-generator.js.map +1 -0
  66. package/dist/call-graph/enrichment/sensitivity-classifier.d.ts +71 -0
  67. package/dist/call-graph/enrichment/sensitivity-classifier.d.ts.map +1 -0
  68. package/dist/call-graph/enrichment/sensitivity-classifier.js +454 -0
  69. package/dist/call-graph/enrichment/sensitivity-classifier.js.map +1 -0
  70. package/dist/call-graph/enrichment/types.d.ts +402 -0
  71. package/dist/call-graph/enrichment/types.d.ts.map +1 -0
  72. package/dist/call-graph/enrichment/types.js +9 -0
  73. package/dist/call-graph/enrichment/types.js.map +1 -0
  74. package/dist/call-graph/extractors/base-extractor.d.ts +112 -0
  75. package/dist/call-graph/extractors/base-extractor.d.ts.map +1 -0
  76. package/dist/call-graph/extractors/base-extractor.js +140 -0
  77. package/dist/call-graph/extractors/base-extractor.js.map +1 -0
  78. package/dist/call-graph/extractors/csharp-data-access-extractor.d.ts +76 -0
  79. package/dist/call-graph/extractors/csharp-data-access-extractor.d.ts.map +1 -0
  80. package/dist/call-graph/extractors/csharp-data-access-extractor.js +387 -0
  81. package/dist/call-graph/extractors/csharp-data-access-extractor.js.map +1 -0
  82. package/dist/call-graph/extractors/csharp-extractor.d.ts +87 -0
  83. package/dist/call-graph/extractors/csharp-extractor.d.ts.map +1 -0
  84. package/dist/call-graph/extractors/csharp-extractor.js +470 -0
  85. package/dist/call-graph/extractors/csharp-extractor.js.map +1 -0
  86. package/dist/call-graph/extractors/data-access-extractor.d.ts +76 -0
  87. package/dist/call-graph/extractors/data-access-extractor.d.ts.map +1 -0
  88. package/dist/call-graph/extractors/data-access-extractor.js +234 -0
  89. package/dist/call-graph/extractors/data-access-extractor.js.map +1 -0
  90. package/dist/call-graph/extractors/index.d.ts +26 -0
  91. package/dist/call-graph/extractors/index.d.ts.map +1 -0
  92. package/dist/call-graph/extractors/index.js +36 -0
  93. package/dist/call-graph/extractors/index.js.map +1 -0
  94. package/dist/call-graph/extractors/java-data-access-extractor.d.ts +101 -0
  95. package/dist/call-graph/extractors/java-data-access-extractor.d.ts.map +1 -0
  96. package/dist/call-graph/extractors/java-data-access-extractor.js +611 -0
  97. package/dist/call-graph/extractors/java-data-access-extractor.js.map +1 -0
  98. package/dist/call-graph/extractors/java-extractor.d.ts +87 -0
  99. package/dist/call-graph/extractors/java-extractor.d.ts.map +1 -0
  100. package/dist/call-graph/extractors/java-extractor.js +510 -0
  101. package/dist/call-graph/extractors/java-extractor.js.map +1 -0
  102. package/dist/call-graph/extractors/php-data-access-extractor.d.ts +93 -0
  103. package/dist/call-graph/extractors/php-data-access-extractor.d.ts.map +1 -0
  104. package/dist/call-graph/extractors/php-data-access-extractor.js +589 -0
  105. package/dist/call-graph/extractors/php-data-access-extractor.js.map +1 -0
  106. package/dist/call-graph/extractors/php-extractor.d.ts +104 -0
  107. package/dist/call-graph/extractors/php-extractor.d.ts.map +1 -0
  108. package/dist/call-graph/extractors/php-extractor.js +619 -0
  109. package/dist/call-graph/extractors/php-extractor.js.map +1 -0
  110. package/dist/call-graph/extractors/python-data-access-extractor.d.ts +90 -0
  111. package/dist/call-graph/extractors/python-data-access-extractor.d.ts.map +1 -0
  112. package/dist/call-graph/extractors/python-data-access-extractor.js +537 -0
  113. package/dist/call-graph/extractors/python-data-access-extractor.js.map +1 -0
  114. package/dist/call-graph/extractors/python-extractor.d.ts +98 -0
  115. package/dist/call-graph/extractors/python-extractor.d.ts.map +1 -0
  116. package/dist/call-graph/extractors/python-extractor.js +681 -0
  117. package/dist/call-graph/extractors/python-extractor.js.map +1 -0
  118. package/dist/call-graph/extractors/semantic-data-access-scanner.d.ts +91 -0
  119. package/dist/call-graph/extractors/semantic-data-access-scanner.d.ts.map +1 -0
  120. package/dist/call-graph/extractors/semantic-data-access-scanner.js +498 -0
  121. package/dist/call-graph/extractors/semantic-data-access-scanner.js.map +1 -0
  122. package/dist/call-graph/extractors/typescript-data-access-extractor.d.ts +122 -0
  123. package/dist/call-graph/extractors/typescript-data-access-extractor.d.ts.map +1 -0
  124. package/dist/call-graph/extractors/typescript-data-access-extractor.js +788 -0
  125. package/dist/call-graph/extractors/typescript-data-access-extractor.js.map +1 -0
  126. package/dist/call-graph/extractors/typescript-extractor.d.ts +145 -0
  127. package/dist/call-graph/extractors/typescript-extractor.d.ts.map +1 -0
  128. package/dist/call-graph/extractors/typescript-extractor.js +904 -0
  129. package/dist/call-graph/extractors/typescript-extractor.js.map +1 -0
  130. package/dist/call-graph/index.d.ts +127 -0
  131. package/dist/call-graph/index.d.ts.map +1 -0
  132. package/dist/call-graph/index.js +247 -0
  133. package/dist/call-graph/index.js.map +1 -0
  134. package/dist/call-graph/store/call-graph-store.d.ts +70 -0
  135. package/dist/call-graph/store/call-graph-store.d.ts.map +1 -0
  136. package/dist/call-graph/store/call-graph-store.js +210 -0
  137. package/dist/call-graph/store/call-graph-store.js.map +1 -0
  138. package/dist/call-graph/store/index.d.ts +7 -0
  139. package/dist/call-graph/store/index.d.ts.map +1 -0
  140. package/dist/call-graph/store/index.js +7 -0
  141. package/dist/call-graph/store/index.js.map +1 -0
  142. package/dist/call-graph/types.d.ts +376 -0
  143. package/dist/call-graph/types.d.ts.map +1 -0
  144. package/dist/call-graph/types.js +8 -0
  145. package/dist/call-graph/types.js.map +1 -0
  146. package/dist/index.d.ts +8 -0
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +12 -0
  149. package/dist/index.js.map +1 -1
  150. package/dist/lake/callgraph-shard-store.d.ts +168 -0
  151. package/dist/lake/callgraph-shard-store.d.ts.map +1 -0
  152. package/dist/lake/callgraph-shard-store.js +466 -0
  153. package/dist/lake/callgraph-shard-store.js.map +1 -0
  154. package/dist/lake/examples-store.d.ts +127 -0
  155. package/dist/lake/examples-store.d.ts.map +1 -0
  156. package/dist/lake/examples-store.js +389 -0
  157. package/dist/lake/examples-store.js.map +1 -0
  158. package/dist/lake/index-store.d.ts +82 -0
  159. package/dist/lake/index-store.d.ts.map +1 -0
  160. package/dist/lake/index-store.js +359 -0
  161. package/dist/lake/index-store.js.map +1 -0
  162. package/dist/lake/index.d.ts +93 -0
  163. package/dist/lake/index.d.ts.map +1 -0
  164. package/dist/lake/index.js +138 -0
  165. package/dist/lake/index.js.map +1 -0
  166. package/dist/lake/lake.bak/index-store.d.ts +82 -0
  167. package/dist/lake/lake.bak/index-store.d.ts.map +1 -0
  168. package/dist/lake/lake.bak/index-store.js +357 -0
  169. package/dist/lake/lake.bak/index-store.js.map +1 -0
  170. package/dist/lake/lake.bak/index.d.ts +81 -0
  171. package/dist/lake/lake.bak/index.d.ts.map +1 -0
  172. package/dist/lake/lake.bak/index.js +114 -0
  173. package/dist/lake/lake.bak/index.js.map +1 -0
  174. package/dist/lake/lake.bak/manifest-store.d.ts +51 -0
  175. package/dist/lake/lake.bak/manifest-store.d.ts.map +1 -0
  176. package/dist/lake/lake.bak/manifest-store.js +347 -0
  177. package/dist/lake/lake.bak/manifest-store.js.map +1 -0
  178. package/dist/lake/lake.bak/query-engine.d.ts +112 -0
  179. package/dist/lake/lake.bak/query-engine.d.ts.map +1 -0
  180. package/dist/lake/lake.bak/query-engine.js +370 -0
  181. package/dist/lake/lake.bak/query-engine.js.map +1 -0
  182. package/dist/lake/lake.bak/types.d.ts +428 -0
  183. package/dist/lake/lake.bak/types.d.ts.map +1 -0
  184. package/dist/lake/lake.bak/types.js +46 -0
  185. package/dist/lake/lake.bak/types.js.map +1 -0
  186. package/dist/lake/lake.bak/view-materializer.d.ts +70 -0
  187. package/dist/lake/lake.bak/view-materializer.d.ts.map +1 -0
  188. package/dist/lake/lake.bak/view-materializer.js +314 -0
  189. package/dist/lake/lake.bak/view-materializer.js.map +1 -0
  190. package/dist/lake/lake.bak/view-store.d.ts +57 -0
  191. package/dist/lake/lake.bak/view-store.d.ts.map +1 -0
  192. package/dist/lake/lake.bak/view-store.js +348 -0
  193. package/dist/lake/lake.bak/view-store.js.map +1 -0
  194. package/dist/lake/manifest-store.d.ts +51 -0
  195. package/dist/lake/manifest-store.d.ts.map +1 -0
  196. package/dist/lake/manifest-store.js +348 -0
  197. package/dist/lake/manifest-store.js.map +1 -0
  198. package/dist/lake/pattern-shard-store.d.ts +87 -0
  199. package/dist/lake/pattern-shard-store.d.ts.map +1 -0
  200. package/dist/lake/pattern-shard-store.js +347 -0
  201. package/dist/lake/pattern-shard-store.js.map +1 -0
  202. package/dist/lake/query-engine.d.ts +124 -0
  203. package/dist/lake/query-engine.d.ts.map +1 -0
  204. package/dist/lake/query-engine.js +453 -0
  205. package/dist/lake/query-engine.js.map +1 -0
  206. package/dist/lake/security-shard-store.d.ts +156 -0
  207. package/dist/lake/security-shard-store.d.ts.map +1 -0
  208. package/dist/lake/security-shard-store.js +498 -0
  209. package/dist/lake/security-shard-store.js.map +1 -0
  210. package/dist/lake/types.d.ts +428 -0
  211. package/dist/lake/types.d.ts.map +1 -0
  212. package/dist/lake/types.js +46 -0
  213. package/dist/lake/types.js.map +1 -0
  214. package/dist/lake/view-materializer.d.ts +70 -0
  215. package/dist/lake/view-materializer.d.ts.map +1 -0
  216. package/dist/lake/view-materializer.js +314 -0
  217. package/dist/lake/view-materializer.js.map +1 -0
  218. package/dist/lake/view-store.d.ts +57 -0
  219. package/dist/lake/view-store.d.ts.map +1 -0
  220. package/dist/lake/view-store.js +348 -0
  221. package/dist/lake/view-store.js.map +1 -0
  222. package/dist/parsers/tree-sitter/index.d.ts +1 -0
  223. package/dist/parsers/tree-sitter/index.d.ts.map +1 -1
  224. package/dist/parsers/tree-sitter/index.js +4 -0
  225. package/dist/parsers/tree-sitter/index.js.map +1 -1
  226. package/dist/parsers/tree-sitter/typescript-loader.d.ts +58 -0
  227. package/dist/parsers/tree-sitter/typescript-loader.d.ts.map +1 -0
  228. package/dist/parsers/tree-sitter/typescript-loader.js +250 -0
  229. package/dist/parsers/tree-sitter/typescript-loader.js.map +1 -0
  230. package/dist/store/project-config.d.ts +154 -0
  231. package/dist/store/project-config.d.ts.map +1 -0
  232. package/dist/store/project-config.js +235 -0
  233. package/dist/store/project-config.js.map +1 -0
  234. package/dist/store/project-registry.d.ts +241 -0
  235. package/dist/store/project-registry.d.ts.map +1 -0
  236. package/dist/store/project-registry.js +557 -0
  237. package/dist/store/project-registry.js.map +1 -0
  238. package/package.json +16 -14
@@ -0,0 +1,389 @@
1
+ /**
2
+ * Examples Store
3
+ *
4
+ * Manages pre-extracted code examples for patterns.
5
+ * This allows drift_code_examples to return instantly without reading source files.
6
+ *
7
+ * Storage structure:
8
+ * .drift/lake/examples/
9
+ * ├── index.json # Example index (pattern -> file mapping)
10
+ * └── patterns/
11
+ * ├── {pattern-id}.json # Pre-extracted examples for each pattern
12
+ * └── ...
13
+ *
14
+ * Key features:
15
+ * - Pre-extracted code snippets with context
16
+ * - Quality scoring for example selection
17
+ * - Incremental updates per pattern
18
+ */
19
+ import * as fs from 'node:fs/promises';
20
+ import * as path from 'node:path';
21
+ import * as crypto from 'node:crypto';
22
+ import { EventEmitter } from 'node:events';
23
+ import { LAKE_DIRS, DEFAULT_DATA_LAKE_CONFIG, } from './types.js';
24
+ // ============================================================================
25
+ // Constants
26
+ // ============================================================================
27
+ const EXAMPLES_DIR = 'examples';
28
+ const PATTERNS_SUBDIR = 'patterns';
29
+ const INDEX_FILE = 'index.json';
30
+ const STORE_VERSION = '1.0.0';
31
+ // Default context lines around examples
32
+ const DEFAULT_CONTEXT_LINES = 5;
33
+ // ============================================================================
34
+ // Helper Functions
35
+ // ============================================================================
36
+ async function fileExists(filePath) {
37
+ try {
38
+ await fs.access(filePath);
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ async function ensureDir(dirPath) {
46
+ await fs.mkdir(dirPath, { recursive: true });
47
+ }
48
+ function generateChecksum(data) {
49
+ const content = JSON.stringify(data);
50
+ return crypto.createHash('sha256').update(content).digest('hex').slice(0, 16);
51
+ }
52
+ function sanitizePatternId(id) {
53
+ // Convert pattern ID to safe filename
54
+ return id.replace(/[^a-zA-Z0-9_-]/g, '_').toLowerCase();
55
+ }
56
+ // ============================================================================
57
+ // Examples Store Class
58
+ // ============================================================================
59
+ export class ExamplesStore extends EventEmitter {
60
+ config;
61
+ examplesDir;
62
+ patternsDir;
63
+ // In-memory cache
64
+ indexCache = null;
65
+ examplesCache = new Map();
66
+ constructor(config = {}) {
67
+ super();
68
+ this.config = { ...DEFAULT_DATA_LAKE_CONFIG, ...config };
69
+ this.examplesDir = path.join(this.config.rootDir, LAKE_DIRS.root, LAKE_DIRS.lake, EXAMPLES_DIR);
70
+ this.patternsDir = path.join(this.examplesDir, PATTERNS_SUBDIR);
71
+ }
72
+ // ==========================================================================
73
+ // Initialization
74
+ // ==========================================================================
75
+ async initialize() {
76
+ await ensureDir(this.examplesDir);
77
+ await ensureDir(this.patternsDir);
78
+ }
79
+ // ==========================================================================
80
+ // Index Operations
81
+ // ==========================================================================
82
+ /**
83
+ * Get the examples index
84
+ */
85
+ async getIndex() {
86
+ if (this.indexCache) {
87
+ return this.indexCache;
88
+ }
89
+ const indexPath = path.join(this.examplesDir, INDEX_FILE);
90
+ if (!(await fileExists(indexPath))) {
91
+ return null;
92
+ }
93
+ try {
94
+ const content = await fs.readFile(indexPath, 'utf-8');
95
+ this.indexCache = JSON.parse(content);
96
+ return this.indexCache;
97
+ }
98
+ catch {
99
+ return null;
100
+ }
101
+ }
102
+ /**
103
+ * Save the examples index
104
+ */
105
+ async saveIndex(index) {
106
+ await ensureDir(this.examplesDir);
107
+ const indexPath = path.join(this.examplesDir, INDEX_FILE);
108
+ await fs.writeFile(indexPath, JSON.stringify(index, null, 2));
109
+ this.indexCache = index;
110
+ this.emit('index:saved');
111
+ }
112
+ /**
113
+ * Build examples index from pattern examples
114
+ */
115
+ async buildIndex() {
116
+ const patternIds = await this.listPatterns();
117
+ const entries = [];
118
+ let totalExamples = 0;
119
+ for (const patternId of patternIds) {
120
+ const examples = await this.getPatternExamples(patternId);
121
+ if (!examples)
122
+ continue;
123
+ const bestQuality = examples.examples.length > 0
124
+ ? Math.max(...examples.examples.map(e => e.quality))
125
+ : 0;
126
+ totalExamples += examples.examples.length;
127
+ entries.push({
128
+ patternId: examples.patternId,
129
+ patternName: examples.patternName,
130
+ category: examples.category,
131
+ exampleCount: examples.examples.length,
132
+ bestQuality,
133
+ lastUpdated: examples.generatedAt,
134
+ });
135
+ }
136
+ const index = {
137
+ version: STORE_VERSION,
138
+ generatedAt: new Date().toISOString(),
139
+ totalPatterns: entries.length,
140
+ totalExamples,
141
+ patterns: entries,
142
+ };
143
+ await this.saveIndex(index);
144
+ return index;
145
+ }
146
+ // ==========================================================================
147
+ // Pattern Examples Operations
148
+ // ==========================================================================
149
+ /**
150
+ * Get examples for a specific pattern
151
+ */
152
+ async getPatternExamples(patternId) {
153
+ // Check cache first
154
+ const cached = this.examplesCache.get(patternId);
155
+ if (cached) {
156
+ return cached;
157
+ }
158
+ const filePath = path.join(this.patternsDir, `${sanitizePatternId(patternId)}.json`);
159
+ if (!(await fileExists(filePath))) {
160
+ return null;
161
+ }
162
+ try {
163
+ const content = await fs.readFile(filePath, 'utf-8');
164
+ const data = JSON.parse(content);
165
+ const examples = {
166
+ patternId: data.patternId,
167
+ patternName: data.patternName,
168
+ category: data.category,
169
+ generatedAt: data.generatedAt,
170
+ examples: data.examples,
171
+ };
172
+ this.examplesCache.set(patternId, examples);
173
+ return examples;
174
+ }
175
+ catch {
176
+ return null;
177
+ }
178
+ }
179
+ /**
180
+ * Save examples for a pattern
181
+ */
182
+ async savePatternExamples(examples) {
183
+ await ensureDir(this.patternsDir);
184
+ const filePath = path.join(this.patternsDir, `${sanitizePatternId(examples.patternId)}.json`);
185
+ const examplesFile = {
186
+ version: STORE_VERSION,
187
+ checksum: generateChecksum(examples.examples),
188
+ ...examples,
189
+ };
190
+ await fs.writeFile(filePath, JSON.stringify(examplesFile, null, 2));
191
+ this.examplesCache.set(examples.patternId, examples);
192
+ this.emit('examples:saved', examples.patternId);
193
+ }
194
+ /**
195
+ * Get examples for multiple patterns
196
+ */
197
+ async getMultiplePatternExamples(patternIds) {
198
+ const results = [];
199
+ const examples = await Promise.all(patternIds.map(id => this.getPatternExamples(id)));
200
+ for (const ex of examples) {
201
+ if (ex) {
202
+ results.push(ex);
203
+ }
204
+ }
205
+ return results;
206
+ }
207
+ /**
208
+ * Get examples by category
209
+ */
210
+ async getExamplesByCategory(category) {
211
+ const index = await this.getIndex();
212
+ if (!index)
213
+ return [];
214
+ const patternIds = index.patterns
215
+ .filter(p => p.category === category)
216
+ .map(p => p.patternId);
217
+ return this.getMultiplePatternExamples(patternIds);
218
+ }
219
+ /**
220
+ * List all patterns with examples
221
+ */
222
+ async listPatterns() {
223
+ if (!(await fileExists(this.patternsDir))) {
224
+ return [];
225
+ }
226
+ const files = await fs.readdir(this.patternsDir);
227
+ return files
228
+ .filter(f => f.endsWith('.json'))
229
+ .map(f => f.replace('.json', ''));
230
+ }
231
+ /**
232
+ * Delete examples for a pattern
233
+ */
234
+ async deletePatternExamples(patternId) {
235
+ const filePath = path.join(this.patternsDir, `${sanitizePatternId(patternId)}.json`);
236
+ try {
237
+ await fs.unlink(filePath);
238
+ this.examplesCache.delete(patternId);
239
+ this.emit('examples:deleted', patternId);
240
+ }
241
+ catch {
242
+ // Ignore if doesn't exist
243
+ }
244
+ }
245
+ // ==========================================================================
246
+ // Example Extraction
247
+ // ==========================================================================
248
+ /**
249
+ * Extract examples from source code for a pattern
250
+ *
251
+ * This method reads source files and extracts code snippets with context.
252
+ * It's called during scan/materialize, not at query time.
253
+ */
254
+ async extractExamples(patternId, patternName, category, locations, outliers, options = {}) {
255
+ const { maxExamples = 5, contextLines = DEFAULT_CONTEXT_LINES, minQuality = 0.3, includeOutliers = true, } = options;
256
+ const examples = [];
257
+ // Extract from regular locations
258
+ for (const loc of locations) {
259
+ if (examples.length >= maxExamples)
260
+ break;
261
+ const example = await this.extractSingleExample(loc.file, loc.line, loc.endLine, contextLines, false);
262
+ if (example && example.quality >= minQuality) {
263
+ examples.push(example);
264
+ }
265
+ }
266
+ // Extract from outliers if requested
267
+ if (includeOutliers && examples.length < maxExamples) {
268
+ for (const out of outliers) {
269
+ if (examples.length >= maxExamples)
270
+ break;
271
+ const example = await this.extractSingleExample(out.file, out.line, out.endLine, contextLines, true);
272
+ if (example && example.quality >= minQuality) {
273
+ examples.push(example);
274
+ }
275
+ }
276
+ }
277
+ // Sort by quality (best first)
278
+ examples.sort((a, b) => b.quality - a.quality);
279
+ const patternExamples = {
280
+ patternId,
281
+ patternName,
282
+ category,
283
+ generatedAt: new Date().toISOString(),
284
+ examples,
285
+ };
286
+ await this.savePatternExamples(patternExamples);
287
+ return patternExamples;
288
+ }
289
+ /**
290
+ * Extract a single example from a source file
291
+ */
292
+ async extractSingleExample(file, line, endLine, contextLines, isOutlier) {
293
+ const filePath = path.join(this.config.rootDir, file);
294
+ if (!(await fileExists(filePath))) {
295
+ return null;
296
+ }
297
+ try {
298
+ const content = await fs.readFile(filePath, 'utf-8');
299
+ const lines = content.split('\n');
300
+ const actualEndLine = endLine ?? line;
301
+ const startContext = Math.max(0, line - contextLines - 1);
302
+ const endContext = Math.min(lines.length, actualEndLine + contextLines);
303
+ // Extract the main code
304
+ const codeLines = lines.slice(line - 1, actualEndLine);
305
+ const code = codeLines.join('\n');
306
+ // Extract context (before and after)
307
+ const contextBefore = lines.slice(startContext, line - 1).join('\n');
308
+ const contextAfter = lines.slice(actualEndLine, endContext).join('\n');
309
+ const context = [contextBefore, code, contextAfter].filter(Boolean).join('\n');
310
+ // Calculate quality score
311
+ const quality = this.calculateExampleQuality(code, lines.length, isOutlier);
312
+ return {
313
+ file,
314
+ line,
315
+ endLine: actualEndLine,
316
+ code,
317
+ context,
318
+ quality,
319
+ isOutlier,
320
+ };
321
+ }
322
+ catch {
323
+ return null;
324
+ }
325
+ }
326
+ /**
327
+ * Calculate quality score for an example
328
+ */
329
+ calculateExampleQuality(code, totalLines, isOutlier) {
330
+ let score = 0.5; // Base score
331
+ // Prefer shorter, focused examples
332
+ const codeLines = code.split('\n').length;
333
+ if (codeLines >= 3 && codeLines <= 20) {
334
+ score += 0.2;
335
+ }
336
+ else if (codeLines > 50) {
337
+ score -= 0.2;
338
+ }
339
+ // Prefer examples from larger files (more context)
340
+ if (totalLines > 100) {
341
+ score += 0.1;
342
+ }
343
+ // Penalize outliers slightly
344
+ if (isOutlier) {
345
+ score -= 0.1;
346
+ }
347
+ // Prefer examples with meaningful content
348
+ if (code.includes('function') || code.includes('class') || code.includes('const')) {
349
+ score += 0.1;
350
+ }
351
+ // Penalize examples that are mostly comments
352
+ const commentLines = code.split('\n').filter(l => l.trim().startsWith('//') || l.trim().startsWith('*') || l.trim().startsWith('/*')).length;
353
+ if (commentLines > codeLines / 2) {
354
+ score -= 0.2;
355
+ }
356
+ return Math.max(0, Math.min(1, score));
357
+ }
358
+ // ==========================================================================
359
+ // Cache Management
360
+ // ==========================================================================
361
+ /**
362
+ * Invalidate caches
363
+ */
364
+ invalidateCache(patternId) {
365
+ if (patternId) {
366
+ this.examplesCache.delete(patternId);
367
+ }
368
+ else {
369
+ this.indexCache = null;
370
+ this.examplesCache.clear();
371
+ }
372
+ }
373
+ /**
374
+ * Get cache stats
375
+ */
376
+ getCacheStats() {
377
+ return {
378
+ cachedPatterns: this.examplesCache.size,
379
+ hasIndex: this.indexCache !== null,
380
+ };
381
+ }
382
+ }
383
+ // ============================================================================
384
+ // Factory Function
385
+ // ============================================================================
386
+ export function createExamplesStore(config = {}) {
387
+ return new ExamplesStore(config);
388
+ }
389
+ //# sourceMappingURL=examples-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples-store.js","sourceRoot":"","sources":["../../src/lake/examples-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,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AAe,CAAC,SAAkB;QAChC,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;YACvC,QAAQ,EAAE,IAAI,CAAC,UAAU,KAAK,IAAI;SACnC,CAAC;IACJ,CAAC;CACF;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,MAAM,UAAU,mBAAmB,CAAC,SAAkC,EAAE;IACtE,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Index Store
3
+ *
4
+ * Manages pre-built indexes for fast lookups.
5
+ * Indexes map common query dimensions to IDs for O(1) access.
6
+ *
7
+ * Key indexes:
8
+ * - by-file: file path → pattern/function/access IDs
9
+ * - by-category: category → pattern IDs
10
+ * - by-table: table name → access point/function IDs
11
+ * - by-entry-point: entry point → reachable function IDs
12
+ */
13
+ import { EventEmitter } from 'node:events';
14
+ import type { FileIndex, CategoryIndex, TableIndex, EntryPointIndex, DataLakeConfig, IndexType } from './types.js';
15
+ import type { Pattern, PatternCategory } from '../store/types.js';
16
+ export declare class IndexStore extends EventEmitter {
17
+ private readonly config;
18
+ private readonly indexesDir;
19
+ private fileIndexCache;
20
+ private categoryIndexCache;
21
+ private tableIndexCache;
22
+ private entryPointIndexCache;
23
+ constructor(config?: Partial<DataLakeConfig>);
24
+ initialize(): Promise<void>;
25
+ getFileIndex(): Promise<FileIndex | null>;
26
+ saveFileIndex(index: FileIndex): Promise<void>;
27
+ /**
28
+ * Build file index from patterns
29
+ */
30
+ buildFileIndex(patterns: Pattern[]): FileIndex;
31
+ /**
32
+ * Get pattern IDs for a specific file
33
+ */
34
+ getPatternIdsForFile(file: string): Promise<string[]>;
35
+ /**
36
+ * Update file index for specific files (incremental)
37
+ */
38
+ updateFileIndex(file: string, patternIds: string[], accessPointIds?: string[], functionIds?: string[]): Promise<void>;
39
+ getCategoryIndex(): Promise<CategoryIndex | null>;
40
+ saveCategoryIndex(index: CategoryIndex): Promise<void>;
41
+ /**
42
+ * Build category index from patterns
43
+ */
44
+ buildCategoryIndex(patterns: Pattern[]): CategoryIndex;
45
+ /**
46
+ * Get pattern IDs for a specific category
47
+ */
48
+ getPatternIdsForCategory(category: PatternCategory): Promise<string[]>;
49
+ getTableIndex(): Promise<TableIndex | null>;
50
+ saveTableIndex(index: TableIndex): Promise<void>;
51
+ /**
52
+ * Get access point IDs for a specific table
53
+ */
54
+ getAccessPointIdsForTable(table: string): Promise<string[]>;
55
+ /**
56
+ * Get function IDs that access a specific table
57
+ */
58
+ getAccessorIdsForTable(table: string): Promise<string[]>;
59
+ getEntryPointIndex(): Promise<EntryPointIndex | null>;
60
+ saveEntryPointIndex(index: EntryPointIndex): Promise<void>;
61
+ /**
62
+ * Get reachable function IDs from an entry point
63
+ */
64
+ getReachableFunctions(entryPointId: string): Promise<string[]>;
65
+ /**
66
+ * Get tables reachable from an entry point
67
+ */
68
+ getReachableTables(entryPointId: string): Promise<string[]>;
69
+ /**
70
+ * Get sensitive data reachable from an entry point
71
+ */
72
+ getReachableSensitiveData(entryPointId: string): Promise<string[]>;
73
+ invalidateCache(index?: IndexType): void;
74
+ hasIndex(index: IndexType): Promise<boolean>;
75
+ deleteIndex(index: IndexType): Promise<void>;
76
+ /**
77
+ * Rebuild all indexes from patterns
78
+ */
79
+ rebuildAllIndexes(patterns: Pattern[]): Promise<void>;
80
+ }
81
+ export declare function createIndexStore(config?: Partial<DataLakeConfig>): IndexStore;
82
+ //# sourceMappingURL=index-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-store.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