"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectKeys = objectKeys;
exports.objectAssign = objectAssign;
exports.objectEntries = objectEntries;
exports.extractValues = extractValues;
exports.extractUpdates = extractUpdates;
exports.patchObject = patchObject;
exports.extractKV = extractKV;
const node_util_1 = require("node:util");
function objectKeys(object) {
    return Object.keys(object);
}
function objectAssign(object, ...values) {
    return Object.assign(object, ...values);
}
function objectEntries(object) {
    return Object.entries(object);
}
function extractValues(state, fields) {
    const result = {};
    for (const key of fields) {
        if (state[key] !== undefined)
            result[key] = state[key];
    }
    return result;
}
function extractUpdates(state, updates, fields = objectKeys(updates), method = 'equals') {
    const result = {};
    for (const key of fields) {
        const update = updates[key];
        if (update !== undefined && !doesMatch(state[key], update, method))
            result[key] = update;
    }
    return result;
}
function patchObject(state, updates, fields, method) {
    return objectAssign(state, extractUpdates(state, updates, fields, method));
}
function extractKV(items, keyColumn, valueColumn) {
    return items.reduce((acc, item) => {
        acc[String(item[keyColumn])] = item[valueColumn];
        return acc;
    }, {});
}
function doesMatch(original, update, method) {
    if (method === 'matches' && isPlainObject(original) && isPlainObject(update)) {
        return objectEntries(update).every(([key, value]) => doesMatch(original[String(key)], value, 'matches'));
    }
    return (0, node_util_1.isDeepStrictEqual)(original, update);
}
function isPlainObject(value) {
    return !!value && typeof value === 'object' && !Array.isArray(value);
}
//# sourceMappingURL=objects.js.map