( graph: Graph<TSchema>, command: AsyncTransaction, )
| 201 | } |
| 202 | |
| 203 | function* handleAsyncTransaction<TSchema extends GraphSchema>( |
| 204 | graph: Graph<TSchema>, |
| 205 | command: AsyncTransaction, |
| 206 | ): Iterable<AsyncTransactionOperationResult> { |
| 207 | for (const operation of command.operations) { |
| 208 | try { |
| 209 | switch (operation["@type"]) { |
| 210 | case "AddVertexOperation": { |
| 211 | graph.storage.addVertex(operation.vertex); |
| 212 | yield { |
| 213 | "@type": "AsyncOperationSuccess", |
| 214 | }; |
| 215 | break; |
| 216 | } |
| 217 | case "AddEdgeOperation": { |
| 218 | graph.storage.addEdge(operation.edge); |
| 219 | yield { |
| 220 | "@type": "AsyncOperationSuccess", |
| 221 | }; |
| 222 | break; |
| 223 | } |
| 224 | case "DeleteVertexOperation": { |
| 225 | graph.storage.deleteVertex(operation.id); |
| 226 | yield { |
| 227 | "@type": "AsyncOperationSuccess", |
| 228 | }; |
| 229 | break; |
| 230 | } |
| 231 | case "DeleteEdgeOperation": { |
| 232 | graph.storage.deleteEdge(operation.id); |
| 233 | yield { |
| 234 | "@type": "AsyncOperationSuccess", |
| 235 | }; |
| 236 | break; |
| 237 | } |
| 238 | case "UpdatePropertyOperation": { |
| 239 | graph.storage.updateProperty(operation.id, operation.key, operation.value); |
| 240 | yield { |
| 241 | "@type": "AsyncOperationSuccess", |
| 242 | }; |
| 243 | break; |
| 244 | } |
| 245 | default: { |
| 246 | throw new Error(`Unknown operation type: ${operation["@type"]}`); |
| 247 | } |
| 248 | } |
| 249 | } catch (error) { |
| 250 | yield { |
| 251 | "@type": "AsyncOperationFailure", |
| 252 | operation: operation, |
| 253 | error: error instanceof Error ? error.message : String(error), |
| 254 | }; |
| 255 | } |
| 256 | } |
| 257 | } |
no test coverage detected