MCPcopy Create free account
hub / github.com/codemix/graph / push

Method push

packages/graph/src/AsyncGraph.ts:151–177  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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
180export async function* handleAsyncCommand<TSchema extends GraphSchema>(

Callers 1

instantiateResultMethod · 0.45

Calls 4

getMethod · 0.65
updatePropertyMethod · 0.65
addVertexMethod · 0.65
addEdgeMethod · 0.65

Tested by

no test coverage detected