```ts
/**
 * Performs a topological sort on given nodes and edges.
 *
 * @param nodes - An array of node names representing the nodes to be sorted.
 * @param edges - An array of pairs [from, to], where 'from' must come before 'to'.
 * @returns An array of node names ordered according to the topological sort.
 * @throws An Error if a cycle is detected in the graph or an edge references a non-existent node.
 */
export function topologicalSort(nodes: readonly string[], edges: readonly (readonly [string, string])[]): string[] {
  const adjacencyList = new Map<string, string[]>(nodes.map(node => [node, []]));
  const inDegree = new Map<string, number>(nodes.map(node => [node, 0]));

  for (const [from, to] of edges) {
    if (!adjacencyList.has(from) || !adjacencyList.has(to)) {
      throw new Error(`Edge references non-existent node: (${from}, ${to})`);
    }
    adjacencyList.get(from)!.push(to);
    inDegree.set(to, (inDegree.get(to) || 0) + 1);
  }

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

  const result: string[] = [];
  while (queue.length > 0) {
    if (queue.length !== 1) {
      throw new Error('Cycle detected');
    }
    const node = queue.shift()!;
    result.push(node);

    for (const neighbor of adjacencyList.get(node)!) {
      inDegree.set(neighbor, (inDegree.get(neighbor)! - 1));
      if (inDegree.get(neighbor)! === 0) {
        queue.push(neighbor);
      }
    }
  }

  // Check if all nodes are included in the result
  if (result.length !== nodes.length) {
    throw new Error('Cycle detected');
  }

  return result;
}
```