@allma/core-sdk
Version:
Core SDK with shared utilities (logging, auth, S3 utils) for building on the Allma serverless AI orchestration platform.
38 lines • 1.54 kB
JavaScript
/**
* A utility to check if an item is a non-array, non-null object.
*/
export function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
/**
* Deeply merges two objects. The source object's properties overwrite the target's.
* Properties with `undefined` values in the source are ignored to prevent accidental overwrites.
* @param target The target object.
* @param source The source object.
* @returns A new object with the merged properties.
*/
export function deepMerge(target, source) {
const output = { ...target };
if (isObject(target) && isObject(source)) {
for (const key of Object.keys(source)) {
const sourceValue = source[key];
// Do not merge if the source value is undefined. This prevents
// optional properties in override objects (like from branch definitions)
// from overwriting existing defined values with 'undefined'.
if (sourceValue === undefined) {
continue;
}
const targetValue = target[key];
if (isObject(targetValue) && isObject(sourceValue)) {
// If both values are objects, recurse
output[key] = deepMerge(targetValue, sourceValue);
}
else {
// Otherwise, the source value (which is not undefined) overwrites the target value
output[key] = sourceValue;
}
}
}
return output;
}
//# sourceMappingURL=objectUtils.js.map