← All procedures

dag.buildLeveledDAG

This function builds a leveled DAG from nodes, with Kahn's algorithm.

CLI
Package
@procedures/dag · README
Path
["dag","buildLeveledDAG"]
CLI
mark dag buildLeveledDAG --nodes <any[][]>
As data
{"$proc":["dag","buildLeveledDAG"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/dag/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["dag","buildLeveledDAG"], { nodes: [] });
console.log(JSON.stringify(result));

From the command line

$ mark dag buildLeveledDAG --nodes <any[][]>

As data, in a program

{ "$proc": ["dag", "buildLeveledDAG"], "input": { "nodes": [] } }

Input

FieldTypeRequiredDefaultDescription
nodesany[][]yes

Output

FieldTypeRequiredDefaultDescription
nodesany[][]yesAll nodes in the DAG
levelsobject[][]yesNodes grouped by level for parallel execution
rootsstring[]yesRoot nodes (no dependents in the DAG)
leavesstring[]yesLeaf nodes (no dependencies in the DAG)
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "nodes": {
        "type": "array",
        "items": {
          "type": "array",
          "items": [
            {
              "type": "string"
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Unique identifier for this node"
                },
                "dependencies": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Names/IDs of nodes this node depends on"
                },
                "level": {
                  "type": "number",
                  "description": "Topological level (0 = leaves, computed by Kahn's algorithm)"
                },
                "data": {
                  "description": "Optional user data associated with this node"
                }
              },
              "required": [
                "id",
                "dependencies"
              ],
              "additionalProperties": {}
            }
          ],
          "additionalItems": {},
          "minItems": 2,
          "maxItems": 2
        },
        "x-procedures-codec": "map"
      }
    },
    "required": [
      "nodes"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "nodes": {
        "type": "array",
        "items": {
          "type": "array",
          "items": [
            {
              "type": "string"
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Unique identifier for this node"
                },
                "dependencies": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Names/IDs of nodes this node depends on"
                },
                "level": {
                  "type": "number",
                  "description": "Topological level (0 = leaves, computed by Kahn's algorithm)"
                },
                "data": {
                  "description": "Optional user data associated with this node"
                }
              },
              "required": [
                "id",
                "dependencies"
              ],
              "additionalProperties": {}
            }
          ],
          "additionalItems": {},
          "minItems": 2,
          "maxItems": 2
        },
        "x-procedures-codec": "map",
        "description": "All nodes in the DAG"
      },
      "levels": {
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "description": "Unique identifier for this node"
              },
              "dependencies": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Names/IDs of nodes this node depends on"
              },
              "level": {
                "type": "number",
                "description": "Topological level (0 = leaves, computed by Kahn's algorithm)"
              },
              "data": {
                "description": "Optional user data associated with this node"
              }
            },
            "required": [
              "id",
              "dependencies"
            ],
            "additionalProperties": {}
          }
        },
        "description": "Nodes grouped by level for parallel execution"
      },
      "roots": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Root nodes (no dependents in the DAG)"
      },
      "leaves": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Leaf nodes (no dependencies in the DAG)"
      }
    },
    "required": [
      "nodes",
      "levels",
      "roots",
      "leaves"
    ],
    "additionalProperties": {}
  }
}