"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addCustomInspect = addCustomInspect;
const shell_bson_1 = require("@mongosh/shell-bson");
const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom');
function customDocumentInspect(depth, inspectOptions, inspect) {
    const newInspectOptions = {
        ...inspectOptions,
        depth: Infinity,
        maxArrayLength: Infinity,
        maxStringLength: Infinity,
    };
    const copyToInspect = Array.isArray(this) ? this.slice() : { ...this };
    delete copyToInspect[customInspectSymbol];
    return inspect(copyToInspect, newInspectOptions);
}
function addInspectSymbol(obj) {
    if (!obj[customInspectSymbol]) {
        try {
            Object.defineProperty(obj, customInspectSymbol, {
                value: customDocumentInspect,
                enumerable: false,
                writable: true,
                configurable: true,
            });
        }
        catch {
        }
    }
}
function addCustomInspect(obj) {
    if (Array.isArray(obj)) {
        addInspectSymbol(obj);
        for (const item of obj) {
            addCustomInspect(item);
        }
    }
    else if (obj &&
        typeof obj === 'object' &&
        obj !== null &&
        !(0, shell_bson_1.getBsonType)(obj) &&
        !['[object Date]', '[object RegExp]'].includes(Object.prototype.toString.call(obj))) {
        addInspectSymbol(obj);
        for (const value of Object.values(obj)) {
            addCustomInspect(value);
        }
    }
}
//# sourceMappingURL=custom-inspect.js.map