Skip to content

Commit b02e9db

Browse files
committed
Started using 'getEventType'.
1 parent ab5998f commit b02e9db

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

src/common/helpers.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,23 @@ const EVENT_TYPE_TRANSLATION_TABLE = {
2323
"EXTRACTION_ATTACHMENTS_CONTINUE": EventType.ExtractionAttachmentsContinue,
2424
"EXTRACTION_DATA_DELETE": EventType.ExtractionDataDelete,
2525
"EXTRACTION_ATTACHMENTS_DELETE": EventType.ExtractionAttachmentsDelete,
26-
27-
"EXTRACTION_EXTERNAL_SYNC_UNITS_DONE": ExtractorEventType.ExtractionExternalSyncUnitsDone,
28-
"EXTRACTION_EXTERNAL_SYNC_UNITS_ERROR": ExtractorEventType.ExtractionExternalSyncUnitsError,
29-
"EXTRACTION_METADATA_DONE": ExtractorEventType.ExtractionMetadataDone,
30-
"EXTRACTION_METADATA_ERROR": ExtractorEventType.ExtractionMetadataError,
31-
"EXTRACTION_DATA_PROGRESS": ExtractorEventType.ExtractionDataProgress,
32-
"EXTRACTION_DATA_DELAY": ExtractorEventType.ExtractionDataDelay,
33-
"EXTRACTION_DATA_DONE": ExtractorEventType.ExtractionDataDone,
34-
"EXTRACTION_DATA_ERROR": ExtractorEventType.ExtractionDataError,
35-
"EXTRACTION_ATTACHMENTS_PROGRESS": ExtractorEventType.ExtractionAttachmentsProgress,
36-
"EXTRACTION_ATTACHMENTS_DELAY": ExtractorEventType.ExtractionAttachmentsDelay,
37-
"EXTRACTION_ATTACHMENTS_DONE": ExtractorEventType.ExtractionAttachmentsDone,
38-
"EXTRACTION_ATTACHMENTS_ERROR": ExtractorEventType.ExtractionAttachmentsError,
39-
"EXTRACTION_DATA_DELETE_DONE": ExtractorEventType.ExtractionDataDeleteDone,
40-
"EXTRACTION_DATA_DELETE_ERROR": ExtractorEventType.ExtractionDataDeleteError,
41-
"EXTRACTION_ATTACHMENTS_DELETE_DONE": ExtractorEventType.ExtractionAttachmentsDeleteDone,
42-
"EXTRACTION_ATTACHMENTS_DELETE_ERROR": ExtractorEventType.ExtractionAttachmentsDeleteError
4326
};
4427

4528
/**
4629
* Translates Event type from the old naming scheme to the new one
4730
*/
48-
export function getEventType(eventType: string): EventType | ExtractorEventType {
31+
export function getEventType(eventType: string): EventType {
4932
// If we notice that the event has a newer translation, translate to that
5033
if(eventType in EVENT_TYPE_TRANSLATION_TABLE){
5134
return EVENT_TYPE_TRANSLATION_TABLE[eventType as keyof typeof EVENT_TYPE_TRANSLATION_TABLE];
5235
}
5336

54-
// Return the correct event type
55-
if (eventType in ExtractorEventType) {
56-
return eventType as ExtractorEventType;
57-
}else if (eventType in EventType) {
37+
// Event type doesn't need translation, return
38+
if (eventType in EventType) {
5839
return eventType as EventType;
5940
}
6041

61-
return ExtractorEventType.UnknownEventType;
42+
return EventType.UnknownEventType;
6243
}
6344

6445
export function getTimeoutErrorEventType(eventType: EventType): {

src/types/extraction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export enum EventType {
3131
ContinueLoadingAttachments = 'CONTINUE_LOADING_ATTACHMENTS',
3232
StartDeletingLoaderState = 'START_DELETING_LOADER_STATE',
3333
StartDeletingLoaderAttachmentState = 'START_DELETING_LOADER_ATTACHMENT_STATE',
34+
35+
// Unknown
36+
UnknownEventType = 'UNKNOWN_EVENT_TYPE',
3437
}
3538

3639
/**

src/workers/spawn.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ExtractorEventType,
99
} from '../types/extraction';
1010
import { emit } from '../common/control-protocol';
11-
import { getTimeoutErrorEventType } from '../common/helpers';
11+
import { getEventType, getTimeoutErrorEventType } from '../common/helpers';
1212
import { Logger, serializeError } from '../logger/logger';
1313
import {
1414
GetWorkerPathInterface,
@@ -93,6 +93,7 @@ export async function spawn<ConnectorState>({
9393
initialDomainMapping,
9494
options,
9595
}: SpawnFactoryInterface<ConnectorState>): Promise<void> {
96+
event.payload.event_type = getEventType(event.payload.event_type);
9697
const logger = new Logger({ event, options });
9798
const script = getWorkerPath({
9899
event,

0 commit comments

Comments
 (0)