mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
refactor(core): Remove more dead code from event bus (no-changelog) (#9697)
This commit is contained in:
parent
6ba789aa6d
commit
c0e4f69fe6
|
@ -1,102 +0,0 @@
|
|||
import type { EventMessageTypes } from '.';
|
||||
import type { EventMessageGenericOptions } from './EventMessageGeneric';
|
||||
import { EventMessageGeneric } from './EventMessageGeneric';
|
||||
import type { AbstractEventMessageOptions } from './AbstractEventMessageOptions';
|
||||
import type { EventMessageWorkflowOptions } from './EventMessageWorkflow';
|
||||
import { EventMessageWorkflow } from './EventMessageWorkflow';
|
||||
import { EventMessageTypeNames } from 'n8n-workflow';
|
||||
import type { EventMessageAuditOptions } from './EventMessageAudit';
|
||||
import { EventMessageAudit } from './EventMessageAudit';
|
||||
import type { EventMessageNodeOptions } from './EventMessageNode';
|
||||
import { EventMessageNode } from './EventMessageNode';
|
||||
|
||||
export const getEventMessageObjectByType = (
|
||||
message: AbstractEventMessageOptions,
|
||||
): EventMessageTypes | null => {
|
||||
switch (message.__type as EventMessageTypeNames) {
|
||||
case EventMessageTypeNames.generic:
|
||||
return new EventMessageGeneric(message as EventMessageGenericOptions);
|
||||
case EventMessageTypeNames.workflow:
|
||||
return new EventMessageWorkflow(message as EventMessageWorkflowOptions);
|
||||
case EventMessageTypeNames.audit:
|
||||
return new EventMessageAudit(message as EventMessageAuditOptions);
|
||||
case EventMessageTypeNames.node:
|
||||
return new EventMessageNode(message as EventMessageNodeOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
interface StringIndexedObject {
|
||||
[key: string]: StringIndexedObject | string;
|
||||
}
|
||||
|
||||
export function eventGroupFromEventName(eventName: string): string | undefined {
|
||||
const matches = eventName.match(/^[\w\s]+\.[\w\s]+/);
|
||||
if (matches && matches?.length > 0) {
|
||||
return matches[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function dotsToObject2(dottedString: string, o?: StringIndexedObject): StringIndexedObject {
|
||||
const rootObject: StringIndexedObject = o ?? {};
|
||||
if (!dottedString) return rootObject;
|
||||
|
||||
const parts = dottedString.split('.'); /*?*/
|
||||
|
||||
let part: string | undefined;
|
||||
let obj: StringIndexedObject = rootObject;
|
||||
while ((part = parts.shift())) {
|
||||
if (typeof obj[part] !== 'object') {
|
||||
obj[part] = {
|
||||
__name: part,
|
||||
};
|
||||
}
|
||||
obj = obj[part] as StringIndexedObject;
|
||||
}
|
||||
return rootObject;
|
||||
}
|
||||
|
||||
export function eventListToObject(dottedList: string[]): object {
|
||||
const result = {};
|
||||
dottedList.forEach((e) => {
|
||||
dotsToObject2(e, result);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
interface StringIndexedChild {
|
||||
name: string;
|
||||
children: StringIndexedChild[];
|
||||
}
|
||||
|
||||
export function eventListToObjectTree(dottedList: string[]): StringIndexedChild {
|
||||
const x: StringIndexedChild = {
|
||||
name: 'eventTree',
|
||||
children: [] as unknown as StringIndexedChild[],
|
||||
};
|
||||
dottedList.forEach((dottedString: string) => {
|
||||
const parts = dottedString.split('.');
|
||||
|
||||
let part: string | undefined;
|
||||
let children = x.children;
|
||||
while ((part = parts.shift())) {
|
||||
if (part) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
||||
const foundChild = children.find((e) => e.name === part);
|
||||
if (foundChild) {
|
||||
children = foundChild.children;
|
||||
} else {
|
||||
const newChild: StringIndexedChild = {
|
||||
name: part,
|
||||
children: [],
|
||||
};
|
||||
children.push(newChild);
|
||||
children = newChild.children;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return x;
|
||||
}
|
|
@ -6,10 +6,18 @@ import path, { parse } from 'path';
|
|||
import { Worker } from 'worker_threads';
|
||||
import { createReadStream, existsSync, rmSync } from 'fs';
|
||||
import readline from 'readline';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
import remove from 'lodash/remove';
|
||||
import config from '@/config';
|
||||
import { getEventMessageObjectByType } from '../EventMessageClasses/Helpers';
|
||||
import type { EventMessageGenericOptions } from '../EventMessageClasses/EventMessageGeneric';
|
||||
import { EventMessageGeneric } from '../EventMessageClasses/EventMessageGeneric';
|
||||
import type { AbstractEventMessageOptions } from '../EventMessageClasses/AbstractEventMessageOptions';
|
||||
import type { EventMessageWorkflowOptions } from '../EventMessageClasses/EventMessageWorkflow';
|
||||
import { EventMessageWorkflow } from '../EventMessageClasses/EventMessageWorkflow';
|
||||
import { EventMessageTypeNames, jsonParse } from 'n8n-workflow';
|
||||
import type { EventMessageAuditOptions } from '../EventMessageClasses/EventMessageAudit';
|
||||
import { EventMessageAudit } from '../EventMessageClasses/EventMessageAudit';
|
||||
import type { EventMessageNodeOptions } from '../EventMessageClasses/EventMessageNode';
|
||||
import { EventMessageNode } from '../EventMessageClasses/EventMessageNode';
|
||||
import type { EventMessageReturnMode } from '../MessageEventBus/MessageEventBus';
|
||||
import type { EventMessageTypes } from '../EventMessageClasses';
|
||||
import type { EventMessageConfirmSource } from '../EventMessageClasses/EventMessageConfirm';
|
||||
|
@ -200,7 +208,7 @@ export class MessageEventBusLogWriter {
|
|||
try {
|
||||
const json = jsonParse(line);
|
||||
if (isEventMessageOptions(json) && json.__type !== undefined) {
|
||||
const msg = getEventMessageObjectByType(json);
|
||||
const msg = this.getEventMessageObjectByType(json);
|
||||
if (msg !== null) results.loggedMessages.push(msg);
|
||||
if (msg?.eventName && msg.payload?.executionId) {
|
||||
const executionId = msg.payload.executionId as string;
|
||||
|
@ -302,7 +310,7 @@ export class MessageEventBusLogWriter {
|
|||
json.__type !== undefined &&
|
||||
json.payload?.executionId === executionId
|
||||
) {
|
||||
const msg = getEventMessageObjectByType(json);
|
||||
const msg = this.getEventMessageObjectByType(json);
|
||||
if (msg !== null) messages.push(msg);
|
||||
}
|
||||
} catch {
|
||||
|
@ -346,4 +354,19 @@ export class MessageEventBusLogWriter {
|
|||
unfinishedExecutions: result.unfinishedExecutions,
|
||||
};
|
||||
}
|
||||
|
||||
getEventMessageObjectByType(message: AbstractEventMessageOptions): EventMessageTypes | null {
|
||||
switch (message.__type as EventMessageTypeNames) {
|
||||
case EventMessageTypeNames.generic:
|
||||
return new EventMessageGeneric(message as EventMessageGenericOptions);
|
||||
case EventMessageTypeNames.workflow:
|
||||
return new EventMessageWorkflow(message as EventMessageWorkflowOptions);
|
||||
case EventMessageTypeNames.audit:
|
||||
return new EventMessageAudit(message as EventMessageAuditOptions);
|
||||
case EventMessageTypeNames.node:
|
||||
return new EventMessageNode(message as EventMessageNodeOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue