mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 03:43:50 +00:00
Alpha 3 cleanup (#857)
This commit is contained in:
@@ -18,32 +18,34 @@ import { data, db } from '../../setup/loadDb.js';
|
||||
import { safeMerge } from './DataProvider.utils.js';
|
||||
import { isTest } from '../../setup/index.js';
|
||||
|
||||
type ReadonlyPromise<T> = Promise<Readonly<T>>;
|
||||
|
||||
export class DataProvider {
|
||||
static getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
static async setProjectData(newData: Partial<ProjectData>) {
|
||||
static async setProjectData(newData: Partial<ProjectData>): ReadonlyPromise<ProjectData> {
|
||||
data.project = { ...data.project, ...newData };
|
||||
this.persist();
|
||||
return data.project;
|
||||
}
|
||||
|
||||
static getProjectData() {
|
||||
static getProjectData(): Readonly<ProjectData> {
|
||||
return data.project;
|
||||
}
|
||||
|
||||
static async setCustomFields(newData: CustomFields): Promise<CustomFields> {
|
||||
static async setCustomFields(newData: CustomFields): ReadonlyPromise<CustomFields> {
|
||||
data.customFields = { ...newData };
|
||||
this.persist();
|
||||
return data.customFields;
|
||||
}
|
||||
|
||||
static getCustomFields(): CustomFields {
|
||||
static getCustomFields(): Readonly<CustomFields> {
|
||||
return data.customFields;
|
||||
}
|
||||
|
||||
static async setRundown(newData: OntimeRundown) {
|
||||
static async setRundown(newData: OntimeRundown): ReadonlyPromise<OntimeRundown> {
|
||||
data.rundown = [...newData];
|
||||
this.persist();
|
||||
return data.rundown;
|
||||
@@ -53,64 +55,64 @@ export class DataProvider {
|
||||
return data.settings;
|
||||
}
|
||||
|
||||
static async setSettings(newData: Settings) {
|
||||
static async setSettings(newData: Settings): ReadonlyPromise<Settings> {
|
||||
data.settings = { ...newData };
|
||||
this.persist();
|
||||
return data.settings;
|
||||
}
|
||||
|
||||
static getOsc(): OSCSettings {
|
||||
static getOsc(): Readonly<OSCSettings> {
|
||||
return data.osc;
|
||||
}
|
||||
|
||||
static getHttp(): HttpSettings {
|
||||
static getHttp(): Readonly<HttpSettings> {
|
||||
return data.http;
|
||||
}
|
||||
|
||||
static getUrlPresets(): URLPreset[] {
|
||||
static getUrlPresets(): Readonly<URLPreset[]> {
|
||||
return data.urlPresets;
|
||||
}
|
||||
|
||||
static async setUrlPresets(newData: URLPreset[]) {
|
||||
static async setUrlPresets(newData: URLPreset[]): ReadonlyPromise<URLPreset[]> {
|
||||
data.urlPresets = newData;
|
||||
this.persist();
|
||||
return data.urlPresets;
|
||||
}
|
||||
|
||||
static getViewSettings() {
|
||||
return { ...data.viewSettings };
|
||||
static getViewSettings(): Readonly<ViewSettings> {
|
||||
return data.viewSettings;
|
||||
}
|
||||
|
||||
static async setViewSettings(newData: ViewSettings) {
|
||||
static async setViewSettings(newData: ViewSettings): ReadonlyPromise<ViewSettings> {
|
||||
data.viewSettings = { ...newData };
|
||||
this.persist();
|
||||
return data.viewSettings;
|
||||
}
|
||||
|
||||
static async setOsc(newData: OSCSettings): Promise<OSCSettings> {
|
||||
static async setOsc(newData: OSCSettings): ReadonlyPromise<OSCSettings> {
|
||||
data.osc = { ...newData };
|
||||
this.persist();
|
||||
return data.osc;
|
||||
}
|
||||
|
||||
static async setHttp(newData: HttpSettings): Promise<HttpSettings> {
|
||||
static async setHttp(newData: HttpSettings): ReadonlyPromise<HttpSettings> {
|
||||
data.http = { ...newData };
|
||||
this.persist();
|
||||
return data.http;
|
||||
}
|
||||
|
||||
static getRundown() {
|
||||
return [...data.rundown];
|
||||
static getRundown(): Readonly<OntimeRundown> {
|
||||
return data.rundown;
|
||||
}
|
||||
|
||||
static async persist() {
|
||||
private static async persist() {
|
||||
if (isTest) {
|
||||
return;
|
||||
}
|
||||
await db.write();
|
||||
}
|
||||
|
||||
static async mergeIntoData(newData: Partial<DatabaseModel>) {
|
||||
static async mergeIntoData(newData: Partial<DatabaseModel>): ReadonlyPromise<DatabaseModel> {
|
||||
const mergedData = safeMerge(data, newData);
|
||||
data.project = mergedData.project;
|
||||
data.settings = mergedData.settings;
|
||||
|
||||
Reference in New Issue
Block a user