| 73 | } |
| 74 | |
| 75 | export class InMemoryGraphStore implements GraphStore { |
| 76 | private nodes = new Map<string, StoredNode>(); |
| 77 | private rels = new Map<string, StoredRel>(); |
| 78 | /** Adjacency index: nodeId → set of outgoing relationship IDs. */ |
| 79 | private outgoing = new Map<string, Set<string>>(); |
| 80 | /** Adjacency index: nodeId → set of incoming relationship IDs. */ |
| 81 | private incoming = new Map<string, Set<string>>(); |
| 82 | private sourceCache = new Map< |
| 83 | string, |
| 84 | { content: string; path: string; binary?: boolean } |
| 85 | >(); |
| 86 | |
| 87 | hasData(): boolean { |
| 88 | return this.nodes.size > 0; |
| 89 | } |
| 90 | |
| 91 | async importBatch(batch: ImportBatchRequest): Promise<ImportBatchResponse> { |
| 92 | const t0 = performance.now(); |
| 93 | let nodesCreated = 0; |
| 94 | let relsCreated = 0; |
| 95 | |
| 96 | for (const n of batch.nodes) { |
| 97 | const existing = this.nodes.get(n.id); |
| 98 | if (existing) { |
| 99 | // Merge properties into existing node (e.g. summary update) |
| 100 | existing.properties = { |
| 101 | ...existing.properties, |
| 102 | ...(n.properties ?? {}), |
| 103 | }; |
| 104 | } else { |
| 105 | nodesCreated++; |
| 106 | this.nodes.set(n.id, { |
| 107 | id: n.id, |
| 108 | type: n.type, |
| 109 | name: n.name, |
| 110 | properties: n.properties ?? {}, |
| 111 | }); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | for (const r of batch.relationships) { |
| 116 | if (!this.rels.has(r.id)) relsCreated++; |
| 117 | this.rels.set(r.id, { |
| 118 | id: r.id, |
| 119 | type: r.type, |
| 120 | source_id: r.source_id, |
| 121 | target_id: r.target_id, |
| 122 | properties: r.properties ?? {}, |
| 123 | }); |
| 124 | |
| 125 | // Maintain adjacency indexes |
| 126 | let outSet = this.outgoing.get(r.source_id); |
| 127 | if (!outSet) { |
| 128 | outSet = new Set(); |
| 129 | this.outgoing.set(r.source_id, outSet); |
| 130 | } |
| 131 | outSet.add(r.id); |
| 132 |
nothing calls this directly
no outgoing calls
no test coverage detected