| 6280 | } |
| 6281 | |
| 6282 | public *traverse( |
| 6283 | source: GraphSource<any>, |
| 6284 | input: Iterable<TraversalPath<any, any, any>>, |
| 6285 | _context?: QueryContext, |
| 6286 | ): IterableIterator<TraversalPath<any, any, any>> { |
| 6287 | const { items } = this.config; |
| 6288 | |
| 6289 | for (const path of input) { |
| 6290 | this.traversed++; |
| 6291 | |
| 6292 | for (const item of items) { |
| 6293 | if (item.type === "property") { |
| 6294 | const elementPath = path.get(item.variable); |
| 6295 | if (!elementPath) { |
| 6296 | throw new Error(`REMOVE: Variable '${item.variable}' not found in path`); |
| 6297 | } |
| 6298 | const element = elementPath.value; |
| 6299 | if (element instanceof Vertex || element instanceof Edge) { |
| 6300 | // Set property to undefined to remove it |
| 6301 | element.set(item.property as never, undefined as never); |
| 6302 | } else { |
| 6303 | throw new Error(`REMOVE: Variable '${item.variable}' is not a vertex or edge`); |
| 6304 | } |
| 6305 | } else if (item.type === "label") { |
| 6306 | // Label removal validated in astToSteps, but keep runtime check as fallback |
| 6307 | throw new Error( |
| 6308 | `REMOVE: Label removal is not supported. Labels are immutable. ` + |
| 6309 | `Cannot remove label '${item.label}' from '${item.variable}'.`, |
| 6310 | ); |
| 6311 | } |
| 6312 | } |
| 6313 | |
| 6314 | this.emitted++; |
| 6315 | yield path; |
| 6316 | } |
| 6317 | } |
| 6318 | |
| 6319 | public override clone(partial?: Partial<RemoveStepConfig>) { |
| 6320 | return new RemoveStep({ |