mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +00:00
7456205b6e
* chore: build pipeline for v2 * chore: run unit tests * chore: configure sentry build
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/**
|
|
* Merges two data objects
|
|
* @param {object} existing
|
|
* @param {object} newData
|
|
*/
|
|
export function safeMerge(existing, newData) {
|
|
const { rundown, eventData, settings, viewSettings, osc, http, aliases, userFields } = newData || {};
|
|
return {
|
|
...existing,
|
|
rundown: rundown ?? existing.rundown,
|
|
eventData: { ...existing.eventData, ...eventData },
|
|
settings: { ...existing.settings, ...settings },
|
|
viewSettings: { ...existing.viewSettings, ...viewSettings },
|
|
aliases: aliases ?? existing.aliases,
|
|
userFields: {
|
|
...existing.userFields,
|
|
...(userFields && Object.fromEntries(Object.entries(userFields).filter(([_, value]) => value !== null))),
|
|
},
|
|
osc: {
|
|
...existing.osc,
|
|
...osc,
|
|
subscriptions: {
|
|
...existing.osc?.subscriptions,
|
|
...(newData?.osc?.subscriptions || {}),
|
|
...(existing.osc?.subscriptions && newData?.osc?.subscriptions
|
|
? Object.keys(existing.osc.subscriptions).reduce((acc, key) => {
|
|
if (!(key in newData.osc.subscriptions)) {
|
|
acc[key] = existing.osc.subscriptions[key];
|
|
}
|
|
return acc;
|
|
}, {})
|
|
: {}),
|
|
},
|
|
},
|
|
http: { ...existing.http, ...http },
|
|
};
|
|
}
|