```ts
/**
 * Performs topological sort on a directed acyclic graph (DAG).
 * @param nodes - Array of node names.
 * @param edges - Array of [from, to] edges where from must come before to.
 * @returns An array representing the topologically sorted order of nodes.
 */
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    const graph: { [key: string]: string[] } = {};
    const inDegree: { [key: string]: number } = {};

    // Initialize the graph and in-degree map
    for (const node of nodes) {
        graph[node] = [];
        inDegree[node] = 0;
    }

    // Build the graph and populate in-degree map
    for (const [from, to] of edges) {
        if (!nodes.includes(from)) throw new Error(`Node ${from} not found`);
        if (!nodes.includes(to)) throw new Error(`Node ${to} not found`);

        graph[from].push(to);
        inDegree[to]++;
    }

    // Queue for nodes with zero in-degree
    const queue: string[] = [];
    for (const node of nodes) {
        if (inDegree[node] === 0) {
            queue.push(node);
        }
    }

    // Topological sort result array
    const sortedNodes: string[] = [];

    while (queue.length > 0) {
        const node = queue.shift()!;
        sortedNodes.push(node);

        for (const neighbor of graph[node]) {
            inDegree[neighbor]--;
            if (inDegree[neighbor] === 0) {
                queue.push(neighbor);
            }
        }
    }

    // Check for cycles
    if (sortedNodes.length !== nodes.length) {
        throw new Error('Cycle detected');
    }

    return sortedNodes;
}
```