* Push an element into the storage, updating properties individually if the * element already exists. This ensures that updateProperty is called for each * property change, which maintains index consistency. * * Note: In AsyncGraphStorage, we don't have an IndexManager directly. * Thi
(element: StoredEdge | StoredVertex)
| 149 | * would work correctly. For now, it provides consistent update semantics. |
| 150 | */ |
| 151 | public push(element: StoredEdge | StoredVertex): void { |
| 152 | if (element["@type"] === "Vertex") { |
| 153 | const existing = this.vertices.get(element.id); |
| 154 | if (existing != null) { |
| 155 | // Update each property individually instead of using Object.assign |
| 156 | // to maintain consistency with updateProperty semantics |
| 157 | for (const [key, value] of Object.entries(element.properties)) { |
| 158 | this.updateProperty(element.id, key, value); |
| 159 | } |
| 160 | } else { |
| 161 | this.addVertex(element); |
| 162 | } |
| 163 | } else if (element["@type"] === "Edge") { |
| 164 | const existing = this.edges.get(element.id); |
| 165 | if (existing != null) { |
| 166 | // Update each property individually instead of using Object.assign |
| 167 | // to maintain consistency with updateProperty semantics |
| 168 | for (const [key, value] of Object.entries(element.properties)) { |
| 169 | this.updateProperty(element.id, key, value); |
| 170 | } |
| 171 | } else { |
| 172 | this.addEdge(element); |
| 173 | } |
| 174 | } else { |
| 175 | throw new Error(`Unknown element type: ${element["@type"]}`); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | export async function* handleAsyncCommand<TSchema extends GraphSchema>( |
no test coverage detected