function isRecord(value) {
  return !!value && typeof value === "object" && !Array.isArray(value);
}
function readPathValue(source, field) {
  if (!isRecord(source)) return void 0;
  return field.split(".").reduce((current, segment) => {
    if (!isRecord(current)) return void 0;
    return current[segment];
  }, source);
}
function normalizeChangeRow(field, value, snapshotBefore) {
  const beforeValue = readPathValue(snapshotBefore, field);
  if (isRecord(value) && ("from" in value || "to" in value || "old" in value || "new" in value)) {
    return {
      field,
      from: value.from ?? value.old ?? beforeValue,
      to: value.to ?? value.new ?? null
    };
  }
  return {
    field,
    from: beforeValue,
    to: value
  };
}
function extractChangeRows(changes, snapshotBefore) {
  if (!isRecord(changes)) return [];
  return Object.entries(changes).map(([field, value]) => normalizeChangeRow(field, value, snapshotBefore)).sort((left, right) => left.field.localeCompare(right.field));
}
export {
  extractChangeRows,
  isRecord
};
//# sourceMappingURL=changeRows.js.map
