/**
 * TypeORM `EntityManager.query()` on UPDATE/DELETE … RETURNING returns
 * `[rows, rowCount]` (see PostgresQueryRunner). SELECT returns a bare
 * row array. Normalise to the matched rows so callers can safely read
 * `rows[0]`.
 */
export function rowsFromUpdateReturning<T extends Record<string, unknown>>(
  result: unknown,
): T[] {
  if (!Array.isArray(result)) return [];
  if (result.length === 2 && Array.isArray(result[0])) {
    return result[0] as T[];
  }
  return result as T[];
}
