| 511 | properties: VertexProperties<TSchema, TVertexLabel>, |
| 512 | ): Vertex<TSchema, TVertexLabel>; |
| 513 | public addVertex(...args: any[]) { |
| 514 | let label: string; |
| 515 | let properties: Record<string, unknown>; |
| 516 | if (args.length === 1 && typeof args[0] === "object" && args[0] !== null) { |
| 517 | label = args[0].label; |
| 518 | properties = args[0].properties; |
| 519 | } else { |
| 520 | label = args[0]; |
| 521 | properties = args[1]; |
| 522 | } |
| 523 | |
| 524 | // Validate and transform properties when validation is enabled |
| 525 | const validateProperties = this.#config.validateProperties ?? true; |
| 526 | if (validateProperties) { |
| 527 | const schemaProperties = this.#config.schema.vertices[label]?.properties; |
| 528 | properties = parseProperties(label, properties, schemaProperties); |
| 529 | } |
| 530 | |
| 531 | const data: StoredVertex = { |
| 532 | "@type": "Vertex", |
| 533 | id: this.generateElementId(label), |
| 534 | properties, |
| 535 | }; |
| 536 | |
| 537 | // Ensure unique indexes are built before checking constraints |
| 538 | this.#indexManager.ensureUniqueIndexesBuilt(label, this.#config.storage.getVertices([label])); |
| 539 | |
| 540 | // Check unique constraints before adding (throws if violated) |
| 541 | this.#indexManager.checkAllUniqueConstraints(label, data.properties as Record<string, unknown>); |
| 542 | |
| 543 | // Add to storage |
| 544 | this.#config.storage.addVertex(data); |
| 545 | |
| 546 | // Add to indexes |
| 547 | this.#indexManager.onElementAdd(data); |
| 548 | |
| 549 | return this.instantiateVertex(data); |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Delete a vertex from the graph. |