import { isEmpty, isString } from 'lodash'; import { FakeSleepForJob, FakeSleepForMultiJob, } from '../../../test/session/unit/utils/job_runner/FakeSleepForJob'; import { AvatarDownload } from './jobs/AvatarDownloadJob'; import { ConfigurationDumpSync } from './jobs/ConfigurationSyncDumpJob'; import { ConfigurationSync } from './jobs/ConfigurationSyncJob'; import { PersistedJob, TypeOfPersistedData } from './PersistedJob'; export function persistedJobFromData( data: T ): PersistedJob | null { if (!data || isEmpty(data.jobType) || !isString(data?.jobType)) { return null; } switch (data.jobType) { case 'ConfigurationSyncJobType': return (new ConfigurationSync.ConfigurationSyncJob(data) as unknown) as PersistedJob; case 'ConfigurationSyncDumpJobType': return (new ConfigurationDumpSync.ConfigurationSyncDumpJob(data) as unknown) as PersistedJob< T >; case 'AvatarDownloadJobType': return (new AvatarDownload.AvatarDownloadJob(data) as unknown) as PersistedJob; case 'FakeSleepForJobType': return (new FakeSleepForJob(data) as unknown) as PersistedJob; case 'FakeSleepForJobMultiType': return (new FakeSleepForMultiJob(data) as unknown) as PersistedJob; default: window?.log?.error('unknown persisted job type:', (data as any).jobType); return null; } }