← All procedures

dag.getTopologicalOrder

This function gives the topological order: a flat list, leaves first.

CLI
Package
@procedures/dag · README
Path
["dag","getTopologicalOrder"]
CLI
mark dag getTopologicalOrder --dag <object>
As data
{"$proc":["dag","getTopologicalOrder"],"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","getTopologicalOrder"], { dag: {} });
console.log(JSON.stringify(result));

From the command line

$ mark dag getTopologicalOrder --dag <object>

As data, in a program

{ "$proc": ["dag", "getTopologicalOrder"], "input": { "dag": {} } }

Input

FieldTypeRequiredDefaultDescription
dagobjectyes

Output

The schema does not list fields (object[]).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "dag": {
        "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": {}
      }
    },
    "required": [
      "dag"
    ],
    "additionalProperties": false
  },
  "output": {
    "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": {}
    }
  }
}