mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 09:23:51 +00:00
refactor: remove legacy service
This commit is contained in:
committed by
Carlos Valente
parent
1f71d4578c
commit
2cc434b0e9
@@ -314,7 +314,7 @@ describe('test parser edge cases', () => {
|
||||
//@ts-expect-error -- we know this is wrong, testing imports outside domain
|
||||
const { data, errors } = parseDatabaseModel(testData);
|
||||
expect(data.rundown.length).toBe(1);
|
||||
expect(errors.length).toBe(7);
|
||||
expect(errors.length).toBe(5);
|
||||
});
|
||||
|
||||
it('handles incomplete datasets', () => {
|
||||
@@ -724,8 +724,6 @@ describe('test import of v2 datamodel', () => {
|
||||
);
|
||||
// @ts-expect-error -- checking if the field is removed
|
||||
expect(parsed?.userFields).toBeUndefined();
|
||||
expect(parsed.osc).toMatchObject({ subscriptions: [] });
|
||||
expect(parsed.http).toMatchObject({ enabledOut: false, subscriptions: [] });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,12 +2,8 @@ import {
|
||||
CustomFields,
|
||||
DatabaseModel,
|
||||
EndAction,
|
||||
HttpSettings,
|
||||
HttpSubscription,
|
||||
OSCSettings,
|
||||
OntimeEvent,
|
||||
OntimeRundown,
|
||||
OscSubscription,
|
||||
Settings,
|
||||
SupportedEvent,
|
||||
TimeStrategy,
|
||||
@@ -17,16 +13,12 @@ import {
|
||||
|
||||
import {
|
||||
parseCustomFields,
|
||||
parseHttp,
|
||||
parseOsc,
|
||||
parseProject,
|
||||
parseRundown,
|
||||
parseSettings,
|
||||
parseUrlPresets,
|
||||
parseViewSettings,
|
||||
sanitiseCustomFields,
|
||||
sanitiseHttpSubscriptions,
|
||||
sanitiseOscSubscriptions,
|
||||
} from '../parserFunctions.js';
|
||||
|
||||
describe('parseRundown()', () => {
|
||||
@@ -111,66 +103,6 @@ describe('parseViewSettings()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseOsc()', () => {
|
||||
it('returns an a base model if nothing is given', () => {
|
||||
const errorEmitter = vi.fn();
|
||||
const result = parseOsc({}, errorEmitter);
|
||||
expect(result).toBeTypeOf('object');
|
||||
expect(errorEmitter).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('parses data, skipping invalid results', () => {
|
||||
const errorEmitter = vi.fn();
|
||||
const osc = {
|
||||
subscriptions: [
|
||||
{ id: '1', cycle: 'onLoad', address: '/test', payload: 'test', enabled: true }, // OK
|
||||
{}, // no data
|
||||
{ id: '2', cycle: 'onStart', payload: 'test', enabled: true }, // no address
|
||||
],
|
||||
} as OSCSettings;
|
||||
const result = parseOsc({ osc }, errorEmitter);
|
||||
expect(result.subscriptions.length).toEqual(1);
|
||||
expect(result.subscriptions.at(0)).toMatchObject({
|
||||
id: '1',
|
||||
cycle: 'onLoad',
|
||||
address: '/test',
|
||||
payload: 'test',
|
||||
enabled: true,
|
||||
});
|
||||
expect(errorEmitter).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseHttp()', () => {
|
||||
it('returns an a base model if nothing is given', () => {
|
||||
const errorEmitter = vi.fn();
|
||||
const result = parseHttp({}, errorEmitter);
|
||||
expect(result).toBeTypeOf('object');
|
||||
expect(errorEmitter).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('parses data, skipping invalid results', () => {
|
||||
const errorEmitter = vi.fn();
|
||||
const http = {
|
||||
subscriptions: [
|
||||
{ id: '1', cycle: 'onLoad', message: 'http://', enabled: true }, // OK
|
||||
{}, // no data
|
||||
{ id: '2', cycle: 'onStart', enabled: true }, // no message
|
||||
{ id: '3', cycle: 'onLoad', message: '/test', enabled: true }, // doesnt start with http
|
||||
],
|
||||
} as HttpSettings;
|
||||
const result = parseHttp({ http }, errorEmitter);
|
||||
expect(result.subscriptions.length).toEqual(1);
|
||||
expect(result.subscriptions.at(0)).toMatchObject({
|
||||
id: '1',
|
||||
cycle: 'onLoad',
|
||||
message: 'http://',
|
||||
enabled: true,
|
||||
});
|
||||
expect(errorEmitter).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseUrlPresets()', () => {
|
||||
it('returns an a base model if nothing is given', () => {
|
||||
const errorEmitter = vi.fn();
|
||||
@@ -223,81 +155,6 @@ describe('parseCustomFields()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitiseOscSubscriptions()', () => {
|
||||
it('throws if not an array an empty array if not an array', () => {
|
||||
expect(() => sanitiseOscSubscriptions(undefined)).toThrow();
|
||||
// @ts-expect-error -- data is external, we check bad types
|
||||
expect(() => sanitiseOscSubscriptions({})).toThrow();
|
||||
expect(() => sanitiseOscSubscriptions(null)).toThrow();
|
||||
});
|
||||
|
||||
it('returns an array of valid entries', () => {
|
||||
const oscSubscriptions: OscSubscription[] = [
|
||||
{ id: '1', cycle: 'onLoad', address: '/test', payload: 'test', enabled: true },
|
||||
{ id: '2', cycle: 'onStart', address: '/test', payload: 'test', enabled: false },
|
||||
{ id: '3', cycle: 'onPause', address: '/test', payload: 'test', enabled: true },
|
||||
{ id: '4', cycle: 'onStop', address: '/test', payload: 'test', enabled: false },
|
||||
{ id: '5', cycle: 'onUpdate', address: '/test', payload: 'test', enabled: true },
|
||||
{ id: '6', cycle: 'onFinish', address: '/test', payload: 'test', enabled: false },
|
||||
{ id: '7', cycle: 'onWarning', address: '/test', payload: 'test', enabled: false },
|
||||
{ id: '8', cycle: 'onDanger', address: '/test', payload: 'test', enabled: false },
|
||||
];
|
||||
const sanitationResult = sanitiseOscSubscriptions(oscSubscriptions);
|
||||
expect(sanitationResult).toStrictEqual(oscSubscriptions);
|
||||
});
|
||||
|
||||
it('filters invalid entries', () => {
|
||||
const oscSubscriptions = [
|
||||
{ id: '1', cycle: 'onLoad', address: 4, payload: 'test', enabled: true },
|
||||
{ cycle: 'onLoad', payload: 'test', enabled: true },
|
||||
{ id: '2', cycle: 'unknown', payload: 'test', enabled: false },
|
||||
{ id: '3', payload: 'test', enabled: true },
|
||||
{ id: '4', cycle: 'onStop', enabled: false },
|
||||
{ id: '5', cycle: 'onUpdate', payload: 'test' },
|
||||
{ id: '6', cycle: 'onFinish', payload: 'test', enabled: 'true' },
|
||||
] as OscSubscription[];
|
||||
const sanitationResult = sanitiseOscSubscriptions(oscSubscriptions);
|
||||
expect(sanitationResult.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitiseHttpSubscriptions()', () => {
|
||||
it('throws if the data is unexpected', () => {
|
||||
expect(() => sanitiseHttpSubscriptions(undefined)).toThrow();
|
||||
// @ts-expect-error -- data is external, we check bad types
|
||||
expect(() => sanitiseHttpSubscriptions({})).toThrow();
|
||||
expect(() => sanitiseHttpSubscriptions(null)).toThrow();
|
||||
});
|
||||
|
||||
it('returns an array of valid entries', () => {
|
||||
const httpSubscription: HttpSubscription[] = [
|
||||
{ id: '1', cycle: 'onLoad', message: 'http://test', enabled: true },
|
||||
{ id: '2', cycle: 'onStart', message: 'http://test', enabled: false },
|
||||
{ id: '3', cycle: 'onPause', message: 'http://test', enabled: true },
|
||||
{ id: '4', cycle: 'onStop', message: 'http://test', enabled: false },
|
||||
{ id: '5', cycle: 'onUpdate', message: 'http://test', enabled: true },
|
||||
{ id: '6', cycle: 'onFinish', message: 'http://test', enabled: false },
|
||||
{ id: '7', cycle: 'onWarning', message: 'http://test', enabled: false },
|
||||
{ id: '8', cycle: 'onDanger', message: 'http://test', enabled: false },
|
||||
];
|
||||
const sanitationResult = sanitiseHttpSubscriptions(httpSubscription);
|
||||
expect(sanitationResult).toStrictEqual(httpSubscription);
|
||||
});
|
||||
|
||||
it('filters invalid entries', () => {
|
||||
const httpSubscription = [
|
||||
{ cycle: 'onLoad', message: 'http://test', enabled: true },
|
||||
{ id: '2', cycle: 'unknown', message: 'http://test', enabled: false },
|
||||
{ id: '3', message: 'http://test', enabled: true },
|
||||
{ id: '4', cycle: 'onStop', enabled: false },
|
||||
{ id: '5', cycle: 'onUpdate', message: 'http://test' },
|
||||
{ id: '6', cycle: 'onFinish', message: 'ftp://test', enabled: 'true' },
|
||||
];
|
||||
const sanitationResult = sanitiseHttpSubscriptions(httpSubscription as HttpSubscription[]);
|
||||
expect(sanitationResult.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitiseCustomFields()', () => {
|
||||
it('returns an empty array if not an array', () => {
|
||||
expect(sanitiseCustomFields({})).toEqual({});
|
||||
|
||||
@@ -27,15 +27,7 @@ import { logger } from '../classes/Logger.js';
|
||||
import { event as eventDef } from '../models/eventsDefinition.js';
|
||||
|
||||
import { makeString } from './parserUtils.js';
|
||||
import {
|
||||
parseHttp,
|
||||
parseOsc,
|
||||
parseProject,
|
||||
parseRundown,
|
||||
parseSettings,
|
||||
parseUrlPresets,
|
||||
parseViewSettings,
|
||||
} from './parserFunctions.js';
|
||||
import { parseProject, parseRundown, parseSettings, parseUrlPresets, parseViewSettings } from './parserFunctions.js';
|
||||
import { parseExcelDate } from './time.js';
|
||||
|
||||
export type ErrorEmitter = (message: string) => void;
|
||||
@@ -334,8 +326,6 @@ export function parseDatabaseModel(jsonData: Partial<DatabaseModel>): { data: Da
|
||||
viewSettings: parseViewSettings(jsonData, makeEmitError('View Settings')),
|
||||
urlPresets: parseUrlPresets(jsonData, makeEmitError('URL Presets')),
|
||||
customFields,
|
||||
osc: parseOsc(jsonData, makeEmitError('OSC')),
|
||||
http: parseHttp(jsonData, makeEmitError('HTTP')),
|
||||
automation: parseAutomationSettings(jsonData),
|
||||
};
|
||||
|
||||
|
||||
@@ -2,25 +2,20 @@ import {
|
||||
CustomField,
|
||||
CustomFields,
|
||||
DatabaseModel,
|
||||
HttpSettings,
|
||||
HttpSubscription,
|
||||
OSCSettings,
|
||||
OntimeBlock,
|
||||
OntimeDelay,
|
||||
OntimeEvent,
|
||||
OntimeRundown,
|
||||
OscSubscription,
|
||||
ProjectData,
|
||||
Settings,
|
||||
TimerType,
|
||||
URLPreset,
|
||||
ViewSettings,
|
||||
isOntimeBlock,
|
||||
isOntimeCycle,
|
||||
isOntimeDelay,
|
||||
isOntimeEvent,
|
||||
} from 'ontime-types';
|
||||
import { customFieldLabelToKey, generateId, getErrorMessage, isAlphanumericWithSpace } from 'ontime-utils';
|
||||
import { customFieldLabelToKey, generateId, isAlphanumericWithSpace } from 'ontime-utils';
|
||||
|
||||
import { dbModel } from '../models/dataModel.js';
|
||||
import { block as blockDef, delay as delayDef } from '../models/eventsDefinition.js';
|
||||
@@ -165,102 +160,6 @@ export function parseViewSettings(data: Partial<DatabaseModel>, emitError?: Erro
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitises an OSC Subscriptions array
|
||||
*/
|
||||
export function sanitiseOscSubscriptions(subscriptions?: OscSubscription[]): OscSubscription[] {
|
||||
if (!Array.isArray(subscriptions)) {
|
||||
throw new Error('ERROR: invalid OSC subscriptions');
|
||||
}
|
||||
|
||||
return subscriptions.filter(
|
||||
({ id, cycle, address, payload, enabled }) =>
|
||||
typeof id === 'string' &&
|
||||
isOntimeCycle(cycle) &&
|
||||
typeof address === 'string' &&
|
||||
typeof payload === 'string' &&
|
||||
typeof enabled === 'boolean',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse osc portion of an entry
|
||||
*/
|
||||
export function parseOsc(data: Partial<DatabaseModel>, emitError?: ErrorEmitter): OSCSettings {
|
||||
if (!data.osc) {
|
||||
emitError?.('No data found to import');
|
||||
return { ...dbModel.osc };
|
||||
}
|
||||
|
||||
console.log('Found OSC settings, importing...');
|
||||
|
||||
let newSubscriptions: OscSubscription[] = [];
|
||||
try {
|
||||
newSubscriptions = sanitiseOscSubscriptions(data.osc.subscriptions);
|
||||
} catch (error) {
|
||||
emitError?.(getErrorMessage(error));
|
||||
}
|
||||
|
||||
if (newSubscriptions.length !== data.osc.subscriptions.length) {
|
||||
emitError?.('Skipped invalid subscriptions');
|
||||
}
|
||||
|
||||
return {
|
||||
portIn: data.osc.portIn ?? dbModel.osc.portIn,
|
||||
portOut: data.osc.portOut ?? dbModel.osc.portOut,
|
||||
targetIP: data.osc.targetIP ?? dbModel.osc.targetIP,
|
||||
enabledIn: data.osc.enabledIn ?? dbModel.osc.enabledIn,
|
||||
enabledOut: data.osc.enabledOut ?? dbModel.osc.enabledOut,
|
||||
subscriptions: newSubscriptions,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitises an HTTP Subscriptions array
|
||||
*/
|
||||
export function sanitiseHttpSubscriptions(subscriptions?: HttpSubscription[]): HttpSubscription[] {
|
||||
if (!Array.isArray(subscriptions)) {
|
||||
throw new Error('ERROR: invalid HTTP subscriptions');
|
||||
}
|
||||
|
||||
return subscriptions.filter(
|
||||
({ id, cycle, message, enabled }) =>
|
||||
typeof id === 'string' &&
|
||||
isOntimeCycle(cycle) &&
|
||||
typeof message === 'string' &&
|
||||
message.startsWith('http://') &&
|
||||
typeof enabled === 'boolean',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Http portion of an entry
|
||||
*/
|
||||
export function parseHttp(data: Partial<DatabaseModel>, emitError?: ErrorEmitter): HttpSettings {
|
||||
if (!data.http) {
|
||||
emitError?.('No data found to import');
|
||||
return { ...dbModel.http };
|
||||
}
|
||||
|
||||
console.log('Found HTTP settings, importing...');
|
||||
|
||||
let newSubscriptions: HttpSubscription[] = [];
|
||||
try {
|
||||
newSubscriptions = sanitiseHttpSubscriptions(data.http.subscriptions);
|
||||
} catch (error) {
|
||||
emitError?.(getErrorMessage(error));
|
||||
}
|
||||
|
||||
if (newSubscriptions.length !== data.http?.subscriptions.length) {
|
||||
emitError?.('Skipped invalid subscriptions');
|
||||
}
|
||||
|
||||
return {
|
||||
enabledOut: data.http.enabledOut ?? dbModel.http.enabledOut,
|
||||
subscriptions: newSubscriptions,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse URL preset portion of an entry
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user