mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-25 00:49:10 +00:00
refactor: improve typing
This commit is contained in:
committed by
Carlos Valente
parent
81a07099ae
commit
b7daf2926a
@@ -208,8 +208,9 @@ export const startServer = async (
|
|||||||
expressServer.listen(serverPort, '0.0.0.0', () => {
|
expressServer.listen(serverPort, '0.0.0.0', () => {
|
||||||
const nif = getNetworkInterfaces();
|
const nif = getNetworkInterfaces();
|
||||||
consoleSuccess(`Local: http://localhost:${serverPort}/editor`);
|
consoleSuccess(`Local: http://localhost:${serverPort}/editor`);
|
||||||
for (const key of Object.keys(nif)) {
|
for (const key in nif) {
|
||||||
consoleSuccess(`Network: http://${nif[key].address}:${serverPort}/editor`);
|
const address = nif[key].address;
|
||||||
|
consoleSuccess(`Network: http://${address}:${serverPort}/editor`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { consoleSubdued, consoleRed } from '../utils/console.js';
|
|||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
private queue: Log[];
|
private queue: Log[];
|
||||||
private escalateErrorFn: (error: string) => void | null;
|
private escalateErrorFn: ((error: string) => void) | null;
|
||||||
private canLog = false;
|
private canLog = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -20,7 +20,7 @@ class Logger {
|
|||||||
/**
|
/**
|
||||||
* Enabling setup logger after init
|
* Enabling setup logger after init
|
||||||
*/
|
*/
|
||||||
init(escalateErrorFn: (error: string) => void) {
|
init(escalateErrorFn?: (error: string) => void) {
|
||||||
// flush logs from queue
|
// flush logs from queue
|
||||||
this.queue.forEach((log) => {
|
this.queue.forEach((log) => {
|
||||||
this._push(log);
|
this._push(log);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DatabaseModel, OntimeRundown, Settings, URLPreset } from 'ontime-types';
|
import { DatabaseModel, OntimeRundown, Settings, URLPreset, ViewSettings } from 'ontime-types';
|
||||||
import { safeMerge } from '../DataProvider.utils.js';
|
import { safeMerge } from '../DataProvider.utils.js';
|
||||||
|
|
||||||
describe('safeMerge', () => {
|
describe('safeMerge', () => {
|
||||||
@@ -49,7 +49,7 @@ describe('safeMerge', () => {
|
|||||||
} as DatabaseModel;
|
} as DatabaseModel;
|
||||||
|
|
||||||
it('returns existing data if new data is not provided', () => {
|
it('returns existing data if new data is not provided', () => {
|
||||||
const mergedData = safeMerge(existing, undefined);
|
const mergedData = safeMerge(existing, {});
|
||||||
expect(mergedData).toEqual(existing);
|
expect(mergedData).toEqual(existing);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -136,6 +136,7 @@ describe('safeMerge', () => {
|
|||||||
rundown: [],
|
rundown: [],
|
||||||
project: {
|
project: {
|
||||||
title: '',
|
title: '',
|
||||||
|
description: '',
|
||||||
publicUrl: '',
|
publicUrl: '',
|
||||||
publicInfo: '',
|
publicInfo: '',
|
||||||
backstageUrl: '',
|
backstageUrl: '',
|
||||||
@@ -153,8 +154,9 @@ describe('safeMerge', () => {
|
|||||||
viewSettings: {
|
viewSettings: {
|
||||||
overrideStyles: false,
|
overrideStyles: false,
|
||||||
endMessage: '',
|
endMessage: '',
|
||||||
},
|
} as ViewSettings,
|
||||||
urlPresets: [],
|
urlPresets: [],
|
||||||
|
customFields: {},
|
||||||
osc: {
|
osc: {
|
||||||
portIn: 8888,
|
portIn: 8888,
|
||||||
portOut: 9999,
|
portOut: 9999,
|
||||||
@@ -163,6 +165,10 @@ describe('safeMerge', () => {
|
|||||||
enabledOut: false,
|
enabledOut: false,
|
||||||
subscriptions: [],
|
subscriptions: [],
|
||||||
},
|
},
|
||||||
|
http: {
|
||||||
|
enabledOut: false,
|
||||||
|
subscriptions: [],
|
||||||
|
},
|
||||||
} as DatabaseModel;
|
} as DatabaseModel;
|
||||||
|
|
||||||
const newData = {
|
const newData = {
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ describe('remove() mutation', () => {
|
|||||||
];
|
];
|
||||||
const { newRundown } = remove({ eventIds: ['1', '2', '3'], persistedRundown: testRundown });
|
const { newRundown } = remove({ eventIds: ['1', '2', '3'], persistedRundown: testRundown });
|
||||||
expect(newRundown.length).toBe(3);
|
expect(newRundown.length).toBe(3);
|
||||||
expect(newRundown.at(0).id).toBe('4');
|
expect(newRundown.at(0)?.id).toBe('4');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class RuntimeService {
|
|||||||
integrationService.dispatch(TimerLifeCycle.onUpdate);
|
integrationService.dispatch(TimerLifeCycle.onUpdate);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.lastIntegrationTimerValue = newState.timer.current;
|
this.lastIntegrationTimerValue = newState.timer.current ?? -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldUpdateClock = getShouldClockUpdate(this.lastIntegrationClockUpdate, newState.clock);
|
const shouldUpdateClock = getShouldClockUpdate(this.lastIntegrationClockUpdate, newState.clock);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { AuthenticationStatus, CustomFields, LogOrigin, MaybeString, OntimeRundown } from 'ontime-types';
|
import { AuthenticationStatus, CustomFields, LogOrigin, MaybeString, OntimeRundown } from 'ontime-types';
|
||||||
|
import { ImportMap, getErrorMessage } from 'ontime-utils';
|
||||||
|
|
||||||
import { sheets, sheets_v4 } from '@googleapis/sheets';
|
import { sheets, sheets_v4 } from '@googleapis/sheets';
|
||||||
import { Credentials, OAuth2Client } from 'google-auth-library';
|
import { Credentials, OAuth2Client } from 'google-auth-library';
|
||||||
@@ -13,7 +14,6 @@ import got from 'got';
|
|||||||
import { resolveSheetsDirectory } from '../../setup/index.js';
|
import { resolveSheetsDirectory } from '../../setup/index.js';
|
||||||
import { ensureDirectory } from '../../utils/fileManagement.js';
|
import { ensureDirectory } from '../../utils/fileManagement.js';
|
||||||
import { cellRequestFromEvent, type ClientSecret, getA1Notation, validateClientSecret } from './sheetUtils.js';
|
import { cellRequestFromEvent, type ClientSecret, getA1Notation, validateClientSecret } from './sheetUtils.js';
|
||||||
import { ImportMap } from 'ontime-utils';
|
|
||||||
import { parseExcel } from '../../utils/parser.js';
|
import { parseExcel } from '../../utils/parser.js';
|
||||||
import { logger } from '../../classes/Logger.js';
|
import { logger } from '../../classes/Logger.js';
|
||||||
import { parseCustomFields, parseRundown } from '../../utils/parserFunctions.js';
|
import { parseCustomFields, parseRundown } from '../../utils/parserFunctions.js';
|
||||||
@@ -208,7 +208,8 @@ async function verifySheet(
|
|||||||
});
|
});
|
||||||
return { worksheetOptions: spreadsheets.data.sheets.map((i) => i.properties.title) };
|
return { worksheetOptions: spreadsheets.data.sheets.map((i) => i.properties.title) };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to verify sheet: ${error.message}`);
|
const errorMessage = getErrorMessage(error);
|
||||||
|
throw new Error(`Failed to verify sheet: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
timeDanger: { row: 1, col: 41 },
|
timeDanger: { row: 1, col: 41 },
|
||||||
};
|
};
|
||||||
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
expect(result.updateCells.rows[0].values[5].userEnteredValue.stringValue).toStrictEqual(event.note);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(5)?.userEnteredValue?.stringValue).toStrictEqual(event.note);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('number to timer', () => {
|
test('number to timer', () => {
|
||||||
@@ -103,9 +103,10 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
timeWarning: { row: 1, col: 40 },
|
timeWarning: { row: 1, col: 40 },
|
||||||
timeDanger: { row: 1, col: 41 },
|
timeDanger: { row: 1, col: 41 },
|
||||||
};
|
};
|
||||||
const result = cellRequestFromEvent(event, 1, 1234, metadata).updateCells.rows[0].values[10].userEnteredValue
|
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
.stringValue;
|
expect(result.updateCells?.rows?.at(0)?.values?.at(10)?.userEnteredValue?.stringValue).toStrictEqual(
|
||||||
expect(result).toStrictEqual(millisToString(event.duration));
|
millisToString(event.duration),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('boolean to TRUE', () => {
|
test('boolean to TRUE', () => {
|
||||||
@@ -149,8 +150,8 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
timeDanger: { row: 1, col: 41 },
|
timeDanger: { row: 1, col: 41 },
|
||||||
};
|
};
|
||||||
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
expect(result.updateCells.rows[0].values[11].userEnteredValue.boolValue).toStrictEqual(true);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(11)?.userEnteredValue?.boolValue).toStrictEqual(true);
|
||||||
expect(result.updateCells.rows[0].values[12].userEnteredValue.boolValue).toStrictEqual(false);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(12)?.userEnteredValue?.boolValue).toStrictEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('spacing in metadata', () => {
|
test('spacing in metadata', () => {
|
||||||
@@ -180,8 +181,8 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
title: { row: 1, col: 6 },
|
title: { row: 1, col: 6 },
|
||||||
};
|
};
|
||||||
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
expect(result.updateCells.rows[0].values[0].userEnteredValue.stringValue).toStrictEqual(event.cue);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(0)?.userEnteredValue?.stringValue).toStrictEqual(event.cue);
|
||||||
expect(result.updateCells.rows[0].values[6].userEnteredValue.stringValue).toStrictEqual(event.title);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(6)?.userEnteredValue?.stringValue).toStrictEqual(event.title);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('metadata offset from zero', () => {
|
test('metadata offset from zero', () => {
|
||||||
@@ -212,8 +213,8 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
user0: { row: 1, col: 16 },
|
user0: { row: 1, col: 16 },
|
||||||
};
|
};
|
||||||
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
const result = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
expect(result.updateCells.rows[0].values[0].userEnteredValue.stringValue).toStrictEqual(event.cue);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(0)?.userEnteredValue?.stringValue).toStrictEqual(event.cue);
|
||||||
expect(result.updateCells.rows[0].values[1].userEnteredValue.stringValue).toStrictEqual(event.title);
|
expect(result.updateCells?.rows?.at(0)?.values?.at(1)?.userEnteredValue?.stringValue).toStrictEqual(event.title);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sheet setup', () => {
|
test('sheet setup', () => {
|
||||||
@@ -243,10 +244,10 @@ describe('cellRequestFromEvent()', () => {
|
|||||||
title: { row: 10, col: 6 },
|
title: { row: 10, col: 6 },
|
||||||
};
|
};
|
||||||
const result1 = cellRequestFromEvent(event, 1, 1234, metadata);
|
const result1 = cellRequestFromEvent(event, 1, 1234, metadata);
|
||||||
expect(result1.updateCells.start.sheetId).toStrictEqual(1234);
|
expect(result1.updateCells?.start?.sheetId).toStrictEqual(1234);
|
||||||
const result2 = cellRequestFromEvent(event, 10, 1234, metadata);
|
const result2 = cellRequestFromEvent(event, 10, 1234, metadata);
|
||||||
expect(result2.updateCells.start.rowIndex).toStrictEqual(21);
|
expect(result2.updateCells?.start?.rowIndex).toStrictEqual(21);
|
||||||
expect(result2.updateCells.start.columnIndex).toStrictEqual(5);
|
expect(result2.updateCells?.start?.columnIndex).toStrictEqual(5);
|
||||||
expect(result2.updateCells.fields).toStrictEqual('userEnteredValue');
|
expect(result2.updateCells?.fields).toStrictEqual('userEnteredValue');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -160,6 +160,10 @@ describe('mutation on runtimeState', () => {
|
|||||||
start();
|
start();
|
||||||
newState = getState();
|
newState = getState();
|
||||||
const firstStart = newState.clock;
|
const firstStart = newState.clock;
|
||||||
|
if (newState.runtime.offset === null) {
|
||||||
|
throw new Error('Value cannot be null at this stage');
|
||||||
|
}
|
||||||
|
|
||||||
expect(newState.runtime.actualStart).toBe(newState.clock);
|
expect(newState.runtime.actualStart).toBe(newState.clock);
|
||||||
expect(newState.runtime.offset).toBe(event1.timeStart - newState.clock);
|
expect(newState.runtime.offset).toBe(event1.timeStart - newState.clock);
|
||||||
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
|
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
|
||||||
@@ -167,7 +171,11 @@ describe('mutation on runtimeState', () => {
|
|||||||
// 3. Next event
|
// 3. Next event
|
||||||
load(event2, [event1, event2]);
|
load(event2, [event1, event2]);
|
||||||
start();
|
start();
|
||||||
|
|
||||||
newState = getState();
|
newState = getState();
|
||||||
|
if (newState.runtime.actualStart === null || newState.runtime.offset === null) {
|
||||||
|
throw new Error('Value cannot be null at this stage');
|
||||||
|
}
|
||||||
|
|
||||||
// there is a case where the calculation time overflows the millisecond which makes
|
// there is a case where the calculation time overflows the millisecond which makes
|
||||||
// tests fail
|
// tests fail
|
||||||
@@ -182,6 +190,10 @@ describe('mutation on runtimeState', () => {
|
|||||||
// 4. Add time
|
// 4. Add time
|
||||||
addTime(10);
|
addTime(10);
|
||||||
newState = getState();
|
newState = getState();
|
||||||
|
if (newState.runtime.offset === null) {
|
||||||
|
throw new Error('Value cannot be null at this stage');
|
||||||
|
}
|
||||||
|
|
||||||
expect(newState.runtime.offset).toBe(delayBefore - 10);
|
expect(newState.runtime.offset).toBe(delayBefore - 10);
|
||||||
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
|
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('mergeObject()', () => {
|
|||||||
test('it handles falsy values', () => {
|
test('it handles falsy values', () => {
|
||||||
const a = {
|
const a = {
|
||||||
first: 'yes',
|
first: 'yes',
|
||||||
second: 'yes',
|
second: 'yes' as string | null,
|
||||||
third: 'yes',
|
third: 'yes',
|
||||||
};
|
};
|
||||||
const b = {
|
const b = {
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ export function getNetworkInterfaces(): { name: string; address: string }[] {
|
|||||||
const results: { name: string; address: string }[] = [];
|
const results: { name: string; address: string }[] = [];
|
||||||
|
|
||||||
for (const name of Object.keys(nets)) {
|
for (const name of Object.keys(nets)) {
|
||||||
for (const net of nets[name]) {
|
const netObjects = nets[name];
|
||||||
|
if (!netObjects) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const net of netObjects) {
|
||||||
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
||||||
if (net.family === 'IPv4' && !net.internal) {
|
if (net.family === 'IPv4' && !net.internal) {
|
||||||
results.push({
|
results.push({
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export function mergeObject<T extends object>(a: T, b: Partial<T>): T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof bValue === 'object' && bValue !== null && typeof aValue === 'object' && aValue !== null) {
|
if (typeof bValue === 'object' && bValue !== null && typeof aValue === 'object' && aValue !== null) {
|
||||||
// @ts-expect-error -- library side, ignore for now
|
// @ts-expect-error -- not sure how to type this
|
||||||
merged[key] = deepmerge(aValue, bValue);
|
merged[key] = deepmerge(aValue, bValue);
|
||||||
} else if (bValue !== undefined) {
|
} else if (bValue !== undefined) {
|
||||||
merged[key] = bValue;
|
merged[key] = bValue;
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"alwaysStrict": true,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"strictBindCallApply": true,
|
||||||
|
"strictFunctionTypes": false,
|
||||||
|
"strictPropertyInitialization": false,
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"noImplicitThis": false,
|
||||||
|
"useUnknownInCatchVariables": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "Node16",
|
"module": "Node16",
|
||||||
"moduleResolution": "Node16",
|
"moduleResolution": "Node16",
|
||||||
|
|||||||
Reference in New Issue
Block a user