#!/usr/bin/env node
import "dotenv/config";
import "../hub.js";
import { prisma } from "../db.js";

async function main(): Promise<void> {
  let queryFailure: unknown;
  try {
    await prisma.$queryRawUnsafe("SELECT 1");
  } catch (error) {
    queryFailure = error;
  }

  let disconnectFailure: unknown;
  try {
    await prisma.$disconnect();
  } catch (error) {
    disconnectFailure = error;
  }

  const failures = [queryFailure, disconnectFailure].filter((failure) => failure !== undefined);
  if (failures.length > 0) {
    throw new AggregateError(failures, "Hub dependency load or authenticated database query failed");
  }
  console.log("[service-runtime-probe] Hub dependencies and PostgreSQL query succeeded");
}

main().catch((error: unknown) => {
  console.error("[service-runtime-probe] failed:", error);
  process.exitCode = 1;
});
