"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var serialization_exports = {};
__export(serialization_exports, {
  CRAWL_TTL_MS: () => CRAWL_TTL_MS,
  SCHEMA_VERSION: () => SCHEMA_VERSION,
  assertSchemaVersion: () => assertSchemaVersion,
  normalizeUrl: () => normalizeUrl,
  nowTimestamp: () => nowTimestamp,
  validateTimestamp: () => validateTimestamp
});
module.exports = __toCommonJS(serialization_exports);
const SCHEMA_VERSION = 1;
const CRAWL_TTL_MS = 30 * 60 * 1e3;
function normalizeUrl(raw) {
  const url = new URL(raw);
  url.hash = "";
  if (url.protocol === "http:" && url.port === "80" || url.protocol === "https:" && url.port === "443")
    url.port = "";
  if (url.search) {
    const params = Array.from(url.searchParams.entries());
    params.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
    url.search = "";
    for (const [k, v] of params)
      url.searchParams.append(k, v);
  }
  let pathname = url.pathname;
  if (pathname.length > 1 && pathname.endsWith("/"))
    pathname = pathname.replace(/\/+$/, "");
  const normalizedPath = pathname.replace(/%[0-9a-f]{2}/g, (m) => m.toUpperCase());
  const normalizedSearch = url.search.replace(/%[0-9a-f]{2}/g, (m) => m.toUpperCase());
  const origin = `${url.protocol}//${url.host}`;
  return `${origin}${normalizedPath}${normalizedSearch}`;
}
function validateTimestamp(value) {
  const parsed = new Date(value);
  if (Number.isNaN(parsed.getTime()))
    throw new Error(`Invalid ISO-8601 timestamp: ${JSON.stringify(value)}`);
  const roundTripped = parsed.toISOString();
  if (roundTripped !== value)
    throw new Error(`Timestamp not in canonical ISO-8601 UTC form (got ${JSON.stringify(value)}, expected ${JSON.stringify(roundTripped)})`);
  return value;
}
function nowTimestamp() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
function assertSchemaVersion(version) {
  if (version !== SCHEMA_VERSION)
    throw new Error(`Unsupported schemaVersion: got ${version}, expected ${SCHEMA_VERSION}`);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CRAWL_TTL_MS,
  SCHEMA_VERSION,
  assertSchemaVersion,
  normalizeUrl,
  nowTimestamp,
  validateTimestamp
});
