feat: automation service

This commit is contained in:
Carlos Valente
2024-11-23 22:20:07 +01:00
committed by Carlos Valente
parent a8fe4c8e68
commit 05e61e7bf8
28 changed files with 1220 additions and 8 deletions
+17
View File
@@ -21,3 +21,20 @@ export function isObject(value: unknown): asserts value is object {
throw new Error(`Unexpected payload type: ${String(value)}`);
}
}
export function isArray(value: unknown): asserts value is unknown[] {
if (!Array.isArray(value)) {
throw new Error(`Unexpected payload type: ${String(value)}`);
}
}
export function hasKeys<T extends object, K extends keyof any>(
value: T,
keys: K[],
): asserts value is T & Record<K, unknown> {
for (const key of keys) {
if (!(key in value)) {
throw new Error(`Key not found: ${String(key)}`);
}
}
}
+4
View File
@@ -22,8 +22,10 @@ import {
TimeStrategy,
} from 'ontime-types';
import { parseAutomationSettings } from '../api-data/automation/automation.parser.js';
import { logger } from '../classes/Logger.js';
import { event as eventDef } from '../models/eventsDefinition.js';
import { makeString } from './parserUtils.js';
import {
parseHttp,
@@ -36,6 +38,7 @@ import {
} from './parserFunctions.js';
import { parseExcelDate } from './time.js';
export type ErrorEmitter = (message: string) => void;
export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
export const JSON_MIME = 'application/json';
@@ -333,6 +336,7 @@ export function parseDatabaseModel(jsonData: Partial<DatabaseModel>): { data: Da
customFields,
osc: parseOsc(jsonData, makeEmitError('OSC')),
http: parseHttp(jsonData, makeEmitError('HTTP')),
automation: parseAutomationSettings(jsonData),
};
return { data, errors };
+1 -3
View File
@@ -24,9 +24,7 @@ import { customFieldLabelToKey, generateId, getErrorMessage, isAlphanumericWithS
import { dbModel } from '../models/dataModel.js';
import { block as blockDef, delay as delayDef } from '../models/eventsDefinition.js';
import { createEvent } from './parser.js';
type ErrorEmitter = (message: string) => void;
import { createEvent, type ErrorEmitter } from './parser.js';
/**
* Parse rundown array of an entry