"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var record_utils_exports = {};
__export(record_utils_exports, {
  filterValues: () => filterValues,
  mapKeys: () => mapKeys,
  mapValues: () => mapValues,
  mapValuesAsync: () => mapValuesAsync,
  mergeRecords: () => mergeRecords,
  setNullOnMissingValues: () => setNullOnMissingValues,
  zipObjects: () => zipObjects
});
module.exports = __toCommonJS(record_utils_exports);
var import_bluebird = __toESM(require("bluebird"));
var import_lodash = __toESM(require("lodash"));
const setNullOnMissingValues = (record = {}, oldRecord = {}) => {
  const newRecord = {};
  for (const [key, value] of Object.entries(record)) {
    newRecord[key] = value;
  }
  for (const value of Object.keys(oldRecord)) {
    if (!record[value]) {
      newRecord[value] = null;
    }
  }
  return newRecord;
};
const zipObjects = (recordA, recordB) => {
  const allKeys = /* @__PURE__ */ new Set([...Object.keys(recordA), ...Object.keys(recordB)]);
  const newRecord = {};
  for (const key of allKeys) {
    newRecord[key] = [recordA[key] ?? null, recordB[key] ?? null];
  }
  return newRecord;
};
const mapValues = (record, fn) => {
  const newRecord = {};
  for (const [key, value] of Object.entries(record)) {
    newRecord[key] = fn(value, key);
  }
  return newRecord;
};
const mapValuesAsync = async (record, fn) => {
  const entries = Object.entries(record);
  const newEntries = await import_bluebird.default.map(
    entries,
    async ([key, value]) => [key, await fn(value, key)]
  );
  return Object.fromEntries(newEntries);
};
const mapKeys = (record, fn) => {
  const newRecord = {};
  for (const [key, value] of Object.entries(record)) {
    const newKey = fn(value, key);
    newRecord[newKey] = value;
  }
  return newRecord;
};
function filterValues(record, fn) {
  const newRecord = {};
  for (const [key, value] of Object.entries(record)) {
    if (fn(value, key)) {
      newRecord[key] = value;
    }
  }
  return newRecord;
}
const mergeRecords = (a, b, merge) => {
  const keys = import_lodash.default.uniq([...Object.keys(a), ...Object.keys(b)]);
  const result = {};
  for (const key of keys) {
    const aValue = a[key];
    const bValue = b[key];
    if (aValue && bValue) {
      result[key] = merge(aValue, bValue);
    } else if (aValue) {
      result[key] = aValue;
    } else if (bValue) {
      result[key] = bValue;
    }
  }
  return result;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  filterValues,
  mapKeys,
  mapValues,
  mapValuesAsync,
  mergeRecords,
  setNullOnMissingValues,
  zipObjects
});
//# sourceMappingURL=record-utils.js.map
