mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Remove linting exceptions in nodes-base (no-changelog) (#4944)
This commit is contained in:
@@ -14,6 +14,94 @@ import {
|
||||
SplunkSearchResponse,
|
||||
} from './types';
|
||||
|
||||
// ----------------------------------------
|
||||
// entry formatting
|
||||
// ----------------------------------------
|
||||
function compactEntryContent(splunkObject: any): any {
|
||||
if (typeof splunkObject !== 'object') {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (Array.isArray(splunkObject)) {
|
||||
return splunkObject.reduce((acc, cur) => {
|
||||
acc = { ...acc, ...compactEntryContent(cur) };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (splunkObject['s:dict']) {
|
||||
const obj = splunkObject['s:dict']['s:key'];
|
||||
return { [splunkObject.$.name]: compactEntryContent(obj) };
|
||||
}
|
||||
|
||||
if (splunkObject['s:list']) {
|
||||
const items = splunkObject['s:list']['s:item'];
|
||||
return { [splunkObject.$.name]: items };
|
||||
}
|
||||
|
||||
if (splunkObject._) {
|
||||
return {
|
||||
[splunkObject.$.name]: splunkObject._,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
[splunkObject.$.name]: '',
|
||||
};
|
||||
}
|
||||
|
||||
function formatEntryContent(content: any): any {
|
||||
return content['s:dict']['s:key'].reduce((acc: any, cur: any) => {
|
||||
acc = { ...acc, ...compactEntryContent(cur) };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function formatEntry(entry: any): any {
|
||||
const { content, link, ...rest } = entry;
|
||||
const formattedEntry = { ...rest, ...formatEntryContent(content) };
|
||||
|
||||
if (formattedEntry.id) {
|
||||
formattedEntry.entryUrl = formattedEntry.id;
|
||||
formattedEntry.id = formattedEntry.id.split('/').pop();
|
||||
}
|
||||
|
||||
return formattedEntry;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// search formatting
|
||||
// ----------------------------------------
|
||||
|
||||
export function formatSearch(responseData: SplunkSearchResponse) {
|
||||
const { entry: entries } = responseData;
|
||||
|
||||
if (!entries) return [];
|
||||
|
||||
return Array.isArray(entries) ? entries.map(formatEntry) : [formatEntry(entries)];
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// utils
|
||||
// ----------------------------------------
|
||||
|
||||
export async function parseXml(xml: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
parseString(xml, { explicitArray: false }, (error, result) => {
|
||||
error ? reject(error) : resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function extractErrorDescription(rawError: SplunkError) {
|
||||
const messages = rawError.response?.messages;
|
||||
return messages ? { [messages.msg.$.type.toLowerCase()]: messages.msg._ } : rawError;
|
||||
}
|
||||
|
||||
export function toUnixEpoch(timestamp: string) {
|
||||
return Date.parse(timestamp) / 1000;
|
||||
}
|
||||
|
||||
export async function splunkApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
@@ -65,39 +153,6 @@ export async function splunkApiRequest(
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// utils
|
||||
// ----------------------------------------
|
||||
|
||||
export async function parseXml(xml: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
parseString(xml, { explicitArray: false }, (error, result) => {
|
||||
error ? reject(error) : resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function extractErrorDescription(rawError: SplunkError) {
|
||||
const messages = rawError.response?.messages;
|
||||
return messages ? { [messages.msg.$.type.toLowerCase()]: messages.msg._ } : rawError;
|
||||
}
|
||||
|
||||
export function toUnixEpoch(timestamp: string) {
|
||||
return Date.parse(timestamp) / 1000;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// search formatting
|
||||
// ----------------------------------------
|
||||
|
||||
export function formatSearch(responseData: SplunkSearchResponse) {
|
||||
const { entry: entries } = responseData;
|
||||
|
||||
if (!entries) return [];
|
||||
|
||||
return Array.isArray(entries) ? entries.map(formatEntry) : [formatEntry(entries)];
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// feed formatting
|
||||
// ----------------------------------------
|
||||
@@ -113,25 +168,6 @@ export function formatFeed(responseData: SplunkFeedResponse) {
|
||||
// ----------------------------------------
|
||||
// result formatting
|
||||
// ----------------------------------------
|
||||
|
||||
export function formatResults(responseData: SplunkResultResponse) {
|
||||
const results = responseData.results.result;
|
||||
if (!results) return [];
|
||||
|
||||
return Array.isArray(results)
|
||||
? results.map((r) => formatResult(r.field))
|
||||
: [formatResult(results.field)];
|
||||
}
|
||||
|
||||
/* tslint:disable: no-any */
|
||||
|
||||
function formatResult(field: any): any {
|
||||
return field.reduce((acc: any, cur: any) => {
|
||||
acc = { ...acc, ...compactResult(cur) };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function compactResult(splunkObject: any): any {
|
||||
if (typeof splunkObject !== 'object') {
|
||||
return {};
|
||||
@@ -152,60 +188,20 @@ function compactResult(splunkObject: any): any {
|
||||
};
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// entry formatting
|
||||
// ----------------------------------------
|
||||
|
||||
function formatEntry(entry: any): any {
|
||||
const { content, link, ...rest } = entry;
|
||||
const formattedEntry = { ...rest, ...formatEntryContent(content) };
|
||||
|
||||
if (formattedEntry.id) {
|
||||
formattedEntry.entryUrl = formattedEntry.id;
|
||||
formattedEntry.id = formattedEntry.id.split('/').pop();
|
||||
}
|
||||
|
||||
return formattedEntry;
|
||||
}
|
||||
|
||||
function formatEntryContent(content: any): any {
|
||||
return content['s:dict']['s:key'].reduce((acc: any, cur: any) => {
|
||||
acc = { ...acc, ...compactEntryContent(cur) };
|
||||
function formatResult(field: any): any {
|
||||
return field.reduce((acc: any, cur: any) => {
|
||||
acc = { ...acc, ...compactResult(cur) };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function compactEntryContent(splunkObject: any): any {
|
||||
if (typeof splunkObject !== 'object') {
|
||||
return {};
|
||||
}
|
||||
export function formatResults(responseData: SplunkResultResponse) {
|
||||
const results = responseData.results.result;
|
||||
if (!results) return [];
|
||||
|
||||
if (Array.isArray(splunkObject)) {
|
||||
return splunkObject.reduce((acc, cur) => {
|
||||
acc = { ...acc, ...compactEntryContent(cur) };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (splunkObject['s:dict']) {
|
||||
const obj = splunkObject['s:dict']['s:key'];
|
||||
return { [splunkObject.$.name]: compactEntryContent(obj) };
|
||||
}
|
||||
|
||||
if (splunkObject['s:list']) {
|
||||
const items = splunkObject['s:list']['s:item'];
|
||||
return { [splunkObject.$.name]: items };
|
||||
}
|
||||
|
||||
if (splunkObject._) {
|
||||
return {
|
||||
[splunkObject.$.name]: splunkObject._,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
[splunkObject.$.name]: '',
|
||||
};
|
||||
return Array.isArray(results)
|
||||
? results.map((r) => formatResult(r.field))
|
||||
: [formatResult(results.field)];
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user