(edge: StoredEdge)
| 317 | } |
| 318 | |
| 319 | public addEdge(edge: StoredEdge): void { |
| 320 | const [label, uuid] = parseElementId(edge.id); |
| 321 | const schema = this.#config.schema.edges[label]; |
| 322 | if (schema == null) { |
| 323 | throw new LabelNotFoundError(label); |
| 324 | } |
| 325 | // inV is the target vertex, outV is the source vertex |
| 326 | const inVMap = this.getVertexMap(edge.inV); |
| 327 | const outVMap = this.getVertexMap(edge.outV); |
| 328 | const collection = this.getEdgeCollectionMap(label); |
| 329 | this.transact(() => { |
| 330 | const map = new Y.Map<unknown>(); |
| 331 | map.set($InVKey, edge.inV); |
| 332 | map.set($OutVKey, edge.outV); |
| 333 | collection.set(uuid, map); |
| 334 | for (const key of Object.keys(schema.properties)) { |
| 335 | const value = edge.properties[key as keyof typeof edge.properties]; |
| 336 | if (value === undefined) { |
| 337 | continue; |
| 338 | } |
| 339 | map.set(key, value); |
| 340 | } |
| 341 | |
| 342 | // inV (target) receives incoming edges |
| 343 | let incomingEdges = inVMap.get($InEKey) as undefined | Y.Map<unknown>; |
| 344 | if (incomingEdges == null) { |
| 345 | incomingEdges = new Y.Map<unknown>([[edge.id, true]]); |
| 346 | inVMap.set($InEKey, incomingEdges); |
| 347 | } else { |
| 348 | incomingEdges.set(edge.id, true); |
| 349 | } |
| 350 | // outV (source) has outgoing edges |
| 351 | let outgoingEdges = outVMap.get($OutEKey) as undefined | Y.Map<unknown>; |
| 352 | if (outgoingEdges == null) { |
| 353 | outgoingEdges = new Y.Map<unknown>([[edge.id, true]]); |
| 354 | outVMap.set($OutEKey, outgoingEdges); |
| 355 | } else { |
| 356 | outgoingEdges.set(edge.id, true); |
| 357 | } |
| 358 | }); |
| 359 | } |
| 360 | |
| 361 | public deleteEdge(id: ElementId): void { |
| 362 | const [label, uuid] = parseElementId(id); |
nothing calls this directly
no test coverage detected