```typescript
/**
 * Implements topological sorting on a graph defined by node names and edges.
 * @param nodes - An array of node names.
 * @param edges - An array of [from, to] tuples representing dependencies.
 * @returns A sorted array of nodes satisfying all dependencies.
 * @throws Error if there is a cycle or if an edge targets a non-existent node.
 */
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const graph = new Map<string, Set<string>>();
  const indegree = new Map<string, number>();

  // Build the graph and calculate indegrees
  for (const [from, to] of edges) {
    if (!nodes.includes(from) || !nodes.includes(to)) {
      throw new Error('Edge targets a non-existent node');
    }
    if (!graph.has(from)) {
      graph.set(from, new Set());
    }
    graph.get(from)?.add(to);
    indegree.set(to, (indegree.get(to) || 0) + 1);
  }

  // Collect all nodes with no incoming edges
  const ready: string[] = [];
  for (const node of nodes) {
    if (!indegree.has(node)) {
      ready.push(node);
    }
  }

  const result: string[] = [];

  while (ready.length > 0) {
    const current = ready.shift()!;
    result.push(current);

    // Decrease indegrees of neighbors
    for (const neighbor of graph.get(current) || []) {
      indegree.set(neighbor, indegree.get(neighbor)! - 1);
      if (indegree.get(neighbor) === 0) {
        ready.push(neighbor);
      }
    }
  }

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

  return result;
}
```