```ts
/**
 * Performs topological sorting on a directed acyclic graph (DAG).
 * @param nodes - An array of node names.
 * @param edges - An array of [from, to] edges indicating dependencies.
 * @returns A string array representing the topologically sorted order of nodes.
 * @throws Error if a cycle is detected or an edge references a non-existent node.
 */
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
    const graph: Record<string, Set<string>> = {};
    const inDegree: Record<string, number> = {};

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

    // Build the graph and compute in-degrees
    for (const [from, to] of edges) {
        if (!graph[from]) throw new Error(`Node ${from} not found`);
        if (!graph[to]) throw new Error(`Node ${to} not found`);

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

    const queue: string[] = [];
    for (const node of nodes) {
        if (inDegree[node] === 0) {
            queue.push(node);
        }
    }

    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);
            }
        }
    }

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

    return sortedNodes;
}
```