import { createRequire } from "node:module";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";

const requireFromApi = createRequire(pathToFileURL(resolve("apps/api/package.json")));
const Database = requireFromApi("better-sqlite3");
const sqlitePackage = requireFromApi("better-sqlite3/package.json");

const database = new Database(":memory:");
const row = database.prepare("select 1 as value").get();
database.close();

const result = {
  arch: process.arch,
  betterSqlite3: sqlitePackage.version,
  node: process.version.slice(1),
  os: process.platform,
  selectValue: row.value,
  status: row.value === 1 ? "passed" : "failed",
};

console.log(JSON.stringify(result));
if (result.status !== "passed") process.exit(1);
