(options: DAGNodeFactoryOptions = {})
| 63 | * ``` |
| 64 | */ |
| 65 | export function createDAGNode(options: DAGNodeFactoryOptions = {}): DAGNode { |
| 66 | const id = options.id ?? `node-${generateRandomString(6)}` |
| 67 | const block = |
| 68 | options.block ?? |
| 69 | createSerializedBlock({ |
| 70 | id, |
| 71 | type: options.type ?? 'function', |
| 72 | params: options.params, |
| 73 | }) |
| 74 | |
| 75 | const outgoingEdges = new Map<string, DAGEdge>() |
| 76 | if (options.outgoingEdges) { |
| 77 | options.outgoingEdges.forEach((edge, i) => { |
| 78 | outgoingEdges.set(`edge-${i}`, edge) |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | return { |
| 83 | id, |
| 84 | block, |
| 85 | outgoingEdges, |
| 86 | incomingEdges: new Set(options.incomingEdges ?? []), |
| 87 | metadata: options.metadata ?? {}, |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Creates a DAG structure from a list of node IDs. |
no test coverage detected