chore: marke change api call async

This commit is contained in:
arc-alex
2025-12-15 14:15:12 +01:00
committed by Carlos Valente
parent ba75d52d29
commit 6beda1575a
3 changed files with 10 additions and 18 deletions
@@ -20,13 +20,11 @@ import { eventStore } from '../stores/EventStore.js';
import * as assert from '../utils/assert.js';
import { parseProperty, isValidChangeProperty } from './integration.utils.js';
import { socket } from '../adapters/WebsocketAdapter.js';
import { throttle } from '../utils/throttle.js';
import { coerceEnum } from '../utils/coerceType.js';
import { editEntry } from '../api-data/rundown/rundown.service.js';
import { willCauseRegeneration } from '../api-data/rundown/rundown.utils.js';
import { getCurrentRundown } from '../api-data/rundown/rundown.dao.js';
const throttledEditEvent = throttle(editEntry, 20);
let lastRequest: Date | null = null;
export function dispatchFromAdapter(tag: string, payload: unknown, _source?: 'osc' | 'ws' | 'http') {
@@ -45,7 +43,9 @@ export function getLastRequest() {
return lastRequest;
}
type ActionHandler = (payload: unknown) => { payload: unknown };
type ActionHandler =
| ((payload: unknown) => { payload: unknown })
| ((payload: unknown) => Promise<{ payload: unknown }>);
const actionHandlers: Record<ApiActionTag, ActionHandler> = {
/* General */
@@ -53,7 +53,7 @@ const actionHandlers: Record<ApiActionTag, ActionHandler> = {
poll: () => ({
payload: eventStore.poll(),
}),
change: (payload) => {
change: async (payload) => {
assert.isObject(payload);
if (Object.keys(payload).length === 0) {
throw new Error('Payload is empty');
@@ -89,16 +89,8 @@ const actionHandlers: Record<ApiActionTag, ActionHandler> = {
Object.assign(patchEntry, newObjectProperty);
}
});
if (shouldThrottle) {
if (throttledEditEvent(patchEntry)) {
return { payload: 'throttled' };
}
} else {
editEntry(patchEntry).catch((_error) => {
/** No error handling */
});
}
//TODO: windowed edit function
await editEntry(patchEntry);
return { payload: 'success' };
},
/* Message Service */