import { assert } from "../../../shared/src/asserts.js";
import "js-xxhash";
import { stringify } from "../../../shared/src/bigint-json.js";
function normalizedKeyOrder(rowKey) {
  let last = "";
  let empty = true;
  for (const col in rowKey) {
    empty = false;
    if (last > col) {
      const entries = Object.entries(rowKey).sort(
        ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
      );
      assert(entries.length > 0, "empty row key");
      return Object.fromEntries(entries);
    }
    last = col;
  }
  assert(!empty, "empty row key");
  return rowKey;
}
function tuples(key) {
  return Object.entries(normalizedKeyOrder(key)).flat();
}
const rowIDStrings = /* @__PURE__ */ new WeakMap();
function rowIDString(id) {
  let val = rowIDStrings.get(id);
  if (val) {
    return val;
  }
  val = stringify([id.schema, id.table, ...tuples(id.rowKey)]);
  rowIDStrings.set(id, val);
  return val;
}
export {
  normalizedKeyOrder,
  rowIDString
};
//# sourceMappingURL=row-key.js.map
