basic-reference-index.ts 750 B

123456789101112131415161718192021222324
  1. import { ReferenceIndex } from './reference-index'
  2. import { Changes } from './types'
  3. export default class BasicReferenceIndex extends ReferenceIndex {
  4. fileIndex: Map<string, Set<string>> = new Map()
  5. updateIndex({ updates, deletes }: Changes): Set<string> {
  6. for (const path of deletes) {
  7. this.fileIndex.delete(path)
  8. }
  9. for (const { path, content } of updates) {
  10. const fileReferences: Set<string> = new Set()
  11. const entries = this.parseEntries(content)
  12. for (const entry of entries) {
  13. fileReferences.add(entry.EntryKey)
  14. }
  15. this.fileIndex.set(path, fileReferences)
  16. }
  17. this.keys = new Set(
  18. this.fileIndex.values().flatMap(entry => Array.from(entry))
  19. )
  20. return this.keys
  21. }
  22. }