"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_error = require('../primordials/error.js');
const require_constants_sentinels = require('../constants/sentinels.js');
const require_primordials_reflect = require('../primordials/reflect.js');
const require_arrays_predicates = require('../arrays/predicates.js');
const require_objects_predicates = require('./predicates.js');

//#region src/objects/mutate.ts
/**
* @file Object mutation helpers — `merge` (deep recursive), `objectAssign`
*   (alias for native), `objectFreeze` (alias for native). `merge` includes
*   infinite-loop detection via `LOOP_SENTINEL` because `__proto__` and
*   self-referential graphs would otherwise blow the stack on a recursive
*   descent.
*/
/**
* Deep merge source object into target object.
*
* Recursively merges properties from `source` into `target`. Arrays in source
* completely replace arrays in target (no element-wise merging). Objects are
* merged recursively. Includes infinite loop detection for safety.
*
* @example
*   ;```ts
*   merge(
*     { config: { api: 'v1', timeout: 1000 } },
*     { config: { api: 'v2', retries: 3 } },
*   )
*   // { config: { api: 'v2', timeout: 1000, retries: 3 } }
*   ```
*
* @example
*   ;```ts
*   // Arrays are replaced, not merged
*   merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }
*   ```
*
* @param target - The object to merge into (will be modified)
* @param source - The object to merge from.
*
* @returns The modified target object
*/
/*@__NO_SIDE_EFFECTS__*/
function merge(target, source) {
	if (!/* @__PURE__ */ require_objects_predicates.isObject(target) || !/* @__PURE__ */ require_objects_predicates.isObject(source)) return target;
	const queue = [[target, source]];
	let pos = 0;
	let { length: queueLength } = queue;
	while (pos < queueLength) {
		if (pos === 1e6) throw new require_primordials_error.ErrorCtor("Detected infinite loop in object crawl of merge");
		const { 0: currentTarget, 1: currentSource } = queue[pos++];
		if (!currentSource || !currentTarget) continue;
		const isSourceArray = require_arrays_predicates.isArray(currentSource);
		const isTargetArray = require_arrays_predicates.isArray(currentTarget);
		if (isSourceArray || isTargetArray) continue;
		const keys = require_primordials_reflect.ReflectOwnKeys(currentSource);
		for (let i = 0, { length } = keys; i < length; i += 1) {
			const key = keys[i];
			const srcVal = currentSource[key];
			const targetVal = currentTarget[key];
			if (require_arrays_predicates.isArray(srcVal)) currentTarget[key] = srcVal;
			else if (/* @__PURE__ */ require_objects_predicates.isObject(srcVal)) if (/* @__PURE__ */ require_objects_predicates.isObject(targetVal) && !require_arrays_predicates.isArray(targetVal)) queue[queueLength++] = [targetVal, srcVal];
			else currentTarget[key] = srcVal;
			else currentTarget[key] = srcVal;
		}
	}
	return target;
}
/**
* Alias for native `Object.assign`.
*
* Copies all enumerable own properties from one or more source objects to a
* target object and returns the modified target object.
*
* @example
*   ;```ts
*   objectAssign({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
*   ```
*/
const objectAssign = Object.assign;
/**
* Alias for native `Object.freeze`.
*
* Freezes an object, preventing new properties from being added and existing
* properties from being removed or modified. Makes the object immutable.
*
* @example
*   ;```ts
*   const obj = { a: 1 }
*   objectFreeze(obj)
*   obj.a = 2 // Silently fails (or throws in strict mode)
*   ```
*/
const objectFreeze = Object.freeze;

//#endregion
exports.merge = merge;
exports.objectAssign = objectAssign;
exports.objectFreeze = objectFreeze;