mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-01 20:39:18 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { AutomationSettings, DatabaseModel, NormalisedAutomation, Trigger } from 'ontime-types';
|
|
|
|
import { getPartialProject } from '../../models/dataModel.js';
|
|
import type { ErrorEmitter } from '../../utils/parserUtils.js';
|
|
|
|
export function parseAutomationSettings(data: Partial<DatabaseModel>, emitError?: ErrorEmitter): AutomationSettings {
|
|
const defaultAutomation: AutomationSettings = getPartialProject('automation');
|
|
|
|
if (!data.automation) {
|
|
emitError?.('No data found to import');
|
|
return defaultAutomation;
|
|
}
|
|
console.log('Found Automation settings, importing...');
|
|
|
|
return {
|
|
enabledAutomations: data.automation.enabledAutomations ?? defaultAutomation.enabledAutomations,
|
|
enabledOscIn: data.automation.enabledOscIn ?? defaultAutomation.enabledOscIn,
|
|
oscPortIn: data.automation.oscPortIn ?? defaultAutomation.oscPortIn,
|
|
triggers: parseTriggers(data.automation.triggers),
|
|
automations: parseAutomations(data.automation.automations),
|
|
};
|
|
}
|
|
|
|
function parseTriggers(maybeAutomations: unknown): Trigger[] {
|
|
if (!Array.isArray(maybeAutomations)) return [];
|
|
return maybeAutomations as Trigger[];
|
|
}
|
|
|
|
function parseAutomations(maybeAutomation: unknown): NormalisedAutomation {
|
|
if (typeof maybeAutomation !== 'object' || maybeAutomation === null) return {};
|
|
return maybeAutomation as NormalisedAutomation;
|
|
}
|