first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import set from 'lodash/set';
|
||||
import { ApplicationError, type IDataObject, type NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import type { UpdateRecord } from './interfaces';
|
||||
|
||||
export function removeIgnored(data: IDataObject, ignore: string | string[]) {
|
||||
if (ignore) {
|
||||
let ignoreFields: string[] = [];
|
||||
|
||||
if (typeof ignore === 'string') {
|
||||
ignoreFields = ignore.split(',').map((field) => field.trim());
|
||||
} else {
|
||||
ignoreFields = ignore;
|
||||
}
|
||||
|
||||
const newData: IDataObject = {};
|
||||
|
||||
for (const field of Object.keys(data)) {
|
||||
if (!ignoreFields.includes(field)) {
|
||||
newData[field] = data[field];
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export function findMatches(
|
||||
data: UpdateRecord[],
|
||||
keys: string[],
|
||||
fields: IDataObject,
|
||||
updateAll?: boolean,
|
||||
) {
|
||||
if (updateAll) {
|
||||
const matches = data.filter((record) => {
|
||||
for (const key of keys) {
|
||||
if (record.fields[key] !== fields[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!matches?.length) {
|
||||
throw new ApplicationError('No records match provided keys', { level: 'warning' });
|
||||
}
|
||||
|
||||
return matches;
|
||||
} else {
|
||||
const match = data.find((record) => {
|
||||
for (const key of keys) {
|
||||
if (record.fields[key] !== fields[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!match) {
|
||||
throw new ApplicationError('Record matching provided keys was not found', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
return [match];
|
||||
}
|
||||
}
|
||||
|
||||
export function processAirtableError(error: NodeApiError, id?: string, itemIndex?: number) {
|
||||
if (error.description === 'NOT_FOUND' && id) {
|
||||
error.description = `${id} is not a valid Record ID`;
|
||||
}
|
||||
if (error.description?.includes('You must provide an array of up to 10 record objects') && id) {
|
||||
error.description = `${id} is not a valid Record ID`;
|
||||
}
|
||||
|
||||
if (itemIndex !== undefined) {
|
||||
set(error, 'context.itemIndex', itemIndex);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
export const flattenOutput = (record: IDataObject) => {
|
||||
const { fields, ...rest } = record;
|
||||
return {
|
||||
...rest,
|
||||
...(fields as IDataObject),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user