function isUniqueViolation(err) {
  if (!err || typeof err !== "object") return false;
  const code = err.code;
  if (code === "23505") return true;
  const message = err.message;
  return typeof message === "string" && /duplicate key value|unique constraint/i.test(message);
}
const TRANSIENT_CONNECTION_SQLSTATES = /* @__PURE__ */ new Set([
  "53300",
  // too_many_connections
  "53400",
  // configuration_limit_exceeded
  "57P01",
  // admin_shutdown
  "57P02",
  // crash_shutdown
  "57P03",
  // cannot_connect_now (db starting up)
  "08000",
  // connection_exception
  "08001",
  // sqlclient_unable_to_establish_sqlconnection
  "08003",
  // connection_does_not_exist
  "08006"
  // connection_failure
]);
const TRANSIENT_DB_MESSAGE_PATTERNS = [
  /too many clients already/i,
  /unable to acquire a connection/i,
  /timeout acquiring a connection/i,
  /connection terminated/i,
  /the database system is (starting up|shutting down|in recovery)/i
];
function isTransientDbError(err) {
  if (!err || typeof err !== "object") {
    return false;
  }
  const code = err.code;
  if (typeof code === "string" && TRANSIENT_CONNECTION_SQLSTATES.has(code)) {
    return true;
  }
  const message = err.message;
  if (typeof message === "string" && TRANSIENT_DB_MESSAGE_PATTERNS.some((pattern) => pattern.test(message))) {
    return true;
  }
  return false;
}
export {
  isTransientDbError,
  isUniqueViolation
};
//# sourceMappingURL=pg-errors.js.map
