"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepFreeze = deepFreeze;
exports.maybeDeepFreeze = maybeDeepFreeze;
const environment_1 = require("@apollo/client/utilities/environment");
const objects_js_1 = require("./objects.cjs");
/** @internal only to be imported in tests */
function deepFreeze(value) {
    const workSet = new Set([value]);
    workSet.forEach((obj) => {
        if ((0, objects_js_1.isNonNullObject)(obj) && shallowFreeze(obj) === obj) {
            Object.getOwnPropertyNames(obj).forEach((name) => {
                if ((0, objects_js_1.isNonNullObject)(obj[name]))
                    workSet.add(obj[name]);
            });
        }
    });
    return value;
}
function shallowFreeze(obj) {
    if (environment_1.__DEV__ && !Object.isFrozen(obj)) {
        try {
            Object.freeze(obj);
        }
        catch (e) {
            // Some types like Uint8Array and Node.js's Buffer cannot be frozen, but
            // they all throw a TypeError when you try, so we re-throw any exceptions
            // that are not TypeErrors, since that would be unexpected.
            if (e instanceof TypeError)
                return null;
            throw e;
        }
    }
    return obj;
}
function maybeDeepFreeze(obj) {
    if (environment_1.__DEV__) {
        deepFreeze(obj);
    }
    return obj;
}
//# sourceMappingURL=maybeDeepFreeze.cjs.map
