mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core): Remove linting exceptions in nodes-base, @typescript-eslint/no-unsafe-argument (no-changelog)
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IPollFunctions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
@@ -72,7 +73,7 @@ export async function notionApiRequest(
|
||||
json: true,
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
if (Object.keys(body).length === 0) {
|
||||
if (Object.keys(body as IDataObject).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
if (!uri) {
|
||||
@@ -80,7 +81,7 @@ export async function notionApiRequest(
|
||||
}
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ export async function notionApiRequestAllItems(
|
||||
} else {
|
||||
body.start_cursor = next_cursor;
|
||||
}
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
if (query.limit && query.limit <= returnData.length) {
|
||||
return returnData;
|
||||
}
|
||||
@@ -192,23 +193,20 @@ function getLink(text: { textLink: string; isLink: boolean }) {
|
||||
return {};
|
||||
}
|
||||
|
||||
function getTexts(
|
||||
texts: [
|
||||
{
|
||||
textType: string;
|
||||
text: string;
|
||||
isLink: boolean;
|
||||
range: boolean;
|
||||
textLink: string;
|
||||
mentionType: string;
|
||||
dateStart: string;
|
||||
dateEnd: string;
|
||||
date: string;
|
||||
annotationUi: IDataObject;
|
||||
expression: string;
|
||||
},
|
||||
],
|
||||
) {
|
||||
type TextData = {
|
||||
textType: string;
|
||||
text: string;
|
||||
isLink: boolean;
|
||||
range: boolean;
|
||||
textLink: string;
|
||||
mentionType: string;
|
||||
dateStart: string;
|
||||
dateEnd: string;
|
||||
date: string;
|
||||
annotationUi: IDataObject;
|
||||
expression: string;
|
||||
};
|
||||
function getTexts(texts: TextData[]) {
|
||||
const results = [];
|
||||
for (const text of texts) {
|
||||
if (text.textType === 'text') {
|
||||
@@ -261,7 +259,7 @@ function getTextBlocks(block: IDataObject) {
|
||||
text:
|
||||
block.richText === false
|
||||
? formatText(block.textContent as string).text
|
||||
: getTexts(((block.text as IDataObject).text as any) || []),
|
||||
: getTexts(((block.text as IDataObject).text as TextData[]) || []),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -305,7 +303,7 @@ function getPropertyKeyValue(
|
||||
if (value.richText === false) {
|
||||
result = { rich_text: [{ text: { content: value.textContent } }] };
|
||||
} else {
|
||||
result = { rich_text: getTexts(value.text.text) };
|
||||
result = { rich_text: getTexts(value.text.text as TextData[]) };
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
@@ -324,10 +322,10 @@ function getPropertyKeyValue(
|
||||
result = {
|
||||
type: 'relation',
|
||||
relation: value.relationValue
|
||||
.filter((relation: any) => {
|
||||
.filter((relation: IDataObject) => {
|
||||
return relation && typeof relation === 'string';
|
||||
})
|
||||
.reduce((acc: [], cur: any) => {
|
||||
.reduce((acc: string[], cur: string) => {
|
||||
return acc.concat(cur.split(',').map((relation: string) => relation.trim()));
|
||||
}, [])
|
||||
.filter((relation: string) => {
|
||||
@@ -384,21 +382,21 @@ function getPropertyKeyValue(
|
||||
};
|
||||
break;
|
||||
case 'date':
|
||||
const format = getDateFormat(value.includeTime);
|
||||
const format = getDateFormat(value.includeTime as boolean);
|
||||
const timezoneValue = value.timezone === 'default' ? timezone : value.timezone;
|
||||
if (value.range === true) {
|
||||
result = {
|
||||
type: 'date',
|
||||
date: {
|
||||
start: moment.tz(value.dateStart, timezoneValue).format(format),
|
||||
end: moment.tz(value.dateEnd, timezoneValue).format(format),
|
||||
start: moment.tz(value.dateStart as number, timezoneValue as string).format(format),
|
||||
end: moment.tz(value.dateEnd as number, timezoneValue as string).format(format),
|
||||
},
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
type: 'date',
|
||||
date: {
|
||||
start: moment.tz(value.date, timezoneValue).format(format),
|
||||
start: moment.tz(value.date as number, timezoneValue as string).format(format),
|
||||
end: null,
|
||||
},
|
||||
};
|
||||
@@ -448,7 +446,13 @@ export function mapProperties(
|
||||
(property) =>
|
||||
[
|
||||
`${property.key.split('|')[0]}`,
|
||||
getPropertyKeyValue.call(this, property, property.key.split('|')[1], timezone, version),
|
||||
getPropertyKeyValue.call(
|
||||
this,
|
||||
property,
|
||||
property.key.split('|')[1] as string,
|
||||
timezone,
|
||||
version,
|
||||
),
|
||||
] as const,
|
||||
)
|
||||
.filter(([, value]) => value)
|
||||
@@ -472,7 +476,7 @@ export function mapSorting(data: SortData[]) {
|
||||
|
||||
export function mapFilters(filtersList: IDataObject[], timezone: string) {
|
||||
return filtersList.reduce((obj, value: { [key: string]: any }) => {
|
||||
let key = getNameAndType(value.key).type;
|
||||
let key = getNameAndType(value.key as string).type;
|
||||
|
||||
let valuePropertyName =
|
||||
key === 'last_edited_time' ? value[camelCase(key)] : value[`${camelCase(key)}Value`];
|
||||
@@ -500,16 +504,16 @@ export function mapFilters(filtersList: IDataObject[], timezone: string) {
|
||||
}
|
||||
|
||||
if (value.type === 'formula') {
|
||||
const vpropertyName = value[`${camelCase(value.returnType)}Value`];
|
||||
const vpropertyName = value[`${camelCase(value.returnType as string)}Value`];
|
||||
|
||||
return Object.assign(obj, {
|
||||
['property']: getNameAndType(value.key).name,
|
||||
['property']: getNameAndType(value.key as string).name,
|
||||
[key]: { [value.returnType]: { [`${value.condition}`]: vpropertyName } },
|
||||
});
|
||||
}
|
||||
|
||||
return Object.assign(obj, {
|
||||
['property']: getNameAndType(value.key).name,
|
||||
['property']: getNameAndType(value.key as string).name,
|
||||
[key]: { [`${value.condition}`]: valuePropertyName },
|
||||
});
|
||||
}, {});
|
||||
@@ -518,9 +522,9 @@ export function mapFilters(filtersList: IDataObject[], timezone: string) {
|
||||
function simplifyProperty(property: any) {
|
||||
let result: any;
|
||||
const type = (property as IDataObject).type as string;
|
||||
if (['text'].includes(property.type)) {
|
||||
if (['text'].includes(property.type as string)) {
|
||||
result = property.plain_text;
|
||||
} else if (['rich_text', 'title'].includes(property.type)) {
|
||||
} else if (['rich_text', 'title'].includes(property.type as string)) {
|
||||
if (Array.isArray(property[type]) && property[type].length !== 0) {
|
||||
result = property[type].map((text: any) => simplifyProperty(text) as string).join('');
|
||||
} else {
|
||||
@@ -536,32 +540,32 @@ function simplifyProperty(property: any) {
|
||||
'email',
|
||||
'phone_number',
|
||||
'date',
|
||||
].includes(property.type)
|
||||
].includes(property.type as string)
|
||||
) {
|
||||
result = property[type];
|
||||
} else if (['created_by', 'last_edited_by', 'select'].includes(property.type)) {
|
||||
} else if (['created_by', 'last_edited_by', 'select'].includes(property.type as string)) {
|
||||
result = property[type] ? property[type].name : null;
|
||||
} else if (['people'].includes(property.type)) {
|
||||
} else if (['people'].includes(property.type as string)) {
|
||||
if (Array.isArray(property[type])) {
|
||||
result = property[type].map((person: any) => person.person?.email || {});
|
||||
} else {
|
||||
result = property[type];
|
||||
}
|
||||
} else if (['multi_select'].includes(property.type)) {
|
||||
} else if (['multi_select'].includes(property.type as string)) {
|
||||
if (Array.isArray(property[type])) {
|
||||
result = property[type].map((e: IDataObject) => e.name || {});
|
||||
} else {
|
||||
result = property[type].options.map((e: IDataObject) => e.name || {});
|
||||
}
|
||||
} else if (['relation'].includes(property.type)) {
|
||||
} else if (['relation'].includes(property.type as string)) {
|
||||
if (Array.isArray(property[type])) {
|
||||
result = property[type].map((e: IDataObject) => e.id || {});
|
||||
} else {
|
||||
result = property[type].database_id;
|
||||
}
|
||||
} else if (['formula'].includes(property.type)) {
|
||||
} else if (['formula'].includes(property.type as string)) {
|
||||
result = property[type][property[type].type];
|
||||
} else if (['rollup'].includes(property.type)) {
|
||||
} else if (['rollup'].includes(property.type as string)) {
|
||||
const rollupFunction = property[type].function as string;
|
||||
if (rollupFunction.startsWith('count') || rollupFunction.includes('empty')) {
|
||||
result = property[type].number;
|
||||
@@ -570,13 +574,13 @@ function simplifyProperty(property: any) {
|
||||
}
|
||||
} else if (rollupFunction.startsWith('show') && property[type].type === 'array') {
|
||||
const elements = property[type].array.map(simplifyProperty).flat();
|
||||
result = rollupFunction === 'show_unique' ? [...new Set(elements)] : elements;
|
||||
result = rollupFunction === 'show_unique' ? [...new Set(elements as string)] : elements;
|
||||
}
|
||||
} else if (['files'].includes(property.type)) {
|
||||
} else if (['files'].includes(property.type as string)) {
|
||||
result = property[type].map(
|
||||
(file: { type: string; [key: string]: any }) => file[file.type].url,
|
||||
);
|
||||
} else if (['status'].includes(property.type)) {
|
||||
} else if (['status'].includes(property.type as string)) {
|
||||
result = property[type].name;
|
||||
}
|
||||
return result;
|
||||
@@ -584,7 +588,7 @@ function simplifyProperty(property: any) {
|
||||
|
||||
export function simplifyProperties(properties: any) {
|
||||
const results: any = {};
|
||||
for (const key of Object.keys(properties)) {
|
||||
for (const key of Object.keys(properties as IDataObject)) {
|
||||
results[`${key}`] = simplifyProperty(properties[key]);
|
||||
}
|
||||
return results;
|
||||
@@ -620,20 +624,20 @@ export function simplifyObjects(objects: any, download = false, version = 2) {
|
||||
} else if (object === 'page' && parent.type === 'database_id') {
|
||||
results.push({
|
||||
id,
|
||||
...(version === 2 ? { name: getPropertyTitle(properties) } : {}),
|
||||
...(version === 2 ? { name: getPropertyTitle(properties as IDataObject) } : {}),
|
||||
...(version === 2 ? { url } : {}),
|
||||
...(version === 2
|
||||
? { ...prepend('property', simplifyProperties(properties)) }
|
||||
? { ...prepend('property', simplifyProperties(properties) as IDataObject) }
|
||||
: { ...simplifyProperties(properties) }),
|
||||
});
|
||||
} as IDataObject);
|
||||
} else if (download && json.object === 'page' && json.parent.type === 'database_id') {
|
||||
results.push({
|
||||
json: {
|
||||
id: json.id,
|
||||
...(version === 2 ? { name: getPropertyTitle(json.properties) } : {}),
|
||||
...(version === 2 ? { name: getPropertyTitle(json.properties as IDataObject) } : {}),
|
||||
...(version === 2 ? { url: json.url } : {}),
|
||||
...(version === 2
|
||||
? { ...prepend('property', simplifyProperties(json.properties)) }
|
||||
? { ...prepend('property', simplifyProperties(json.properties) as IDataObject) }
|
||||
: { ...simplifyProperties(json.properties) }),
|
||||
},
|
||||
binary,
|
||||
@@ -790,8 +794,19 @@ export function getConditions() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
export type FileRecord = {
|
||||
properties: {
|
||||
[key: string]:
|
||||
| any
|
||||
| {
|
||||
id: string;
|
||||
type: string;
|
||||
files: [{ external: { url: string } } | { file: { url: string } }];
|
||||
};
|
||||
};
|
||||
};
|
||||
// prettier-ignore
|
||||
export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: [{ properties: { [key: string]: any | { id: string; type: string; files: [{ external: { url: string } } | { file: { url: string } }] } } }]): Promise<INodeExecutionData[]> {
|
||||
export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: FileRecord[]): Promise<INodeExecutionData[]> {
|
||||
|
||||
const elements: INodeExecutionData[] = [];
|
||||
for (const record of records) {
|
||||
@@ -807,10 +822,10 @@ export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, re
|
||||
'',
|
||||
{},
|
||||
{},
|
||||
file?.file?.url || file?.external?.url,
|
||||
file?.file?.url as string || file?.external?.url as string,
|
||||
{ json: false, encoding: null },
|
||||
);
|
||||
element.binary![`${key}_${index}`] = await this.helpers.prepareBinaryData(data);
|
||||
element.binary![`${key}_${index}`] = await this.helpers.prepareBinaryData(data as Buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user