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,60 @@
|
||||
import { ValidationError } from './ValidationError';
|
||||
|
||||
/**
|
||||
* Validates that no disallowed methods are used in the
|
||||
* runCodeForEachItem JS code. Throws `ValidationError` if
|
||||
* a disallowed method is found.
|
||||
*/
|
||||
export function validateNoDisallowedMethodsInRunForEach(code: string, itemIndex: number) {
|
||||
const match = code.match(/\$input\.(?<disallowedMethod>first|last|all|itemMatching)/);
|
||||
|
||||
if (match?.groups?.disallowedMethod) {
|
||||
const { disallowedMethod } = match.groups;
|
||||
|
||||
const lineNumber =
|
||||
code.split('\n').findIndex((line) => {
|
||||
line = line.trimStart();
|
||||
return (
|
||||
line.includes(disallowedMethod) &&
|
||||
!line.startsWith('//') &&
|
||||
!line.startsWith('/*') &&
|
||||
!line.startsWith('*')
|
||||
);
|
||||
}) + 1;
|
||||
|
||||
const disallowedMethodFound = lineNumber !== 0;
|
||||
|
||||
if (disallowedMethodFound) {
|
||||
throw new ValidationError({
|
||||
message: `Can't use .${disallowedMethod}() here`,
|
||||
description: "This is only available in 'Run Once for All Items' mode",
|
||||
itemIndex,
|
||||
lineNumber,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the error message indicates that `items` is not defined and
|
||||
* modifies the error message to suggest using `$input.all()`.
|
||||
*/
|
||||
export function mapItemsNotDefinedErrorIfNeededForRunForAll(code: string, error: Error) {
|
||||
// anticipate user expecting `items` to pre-exist as in Function Item node
|
||||
if (error.message === 'items is not defined' && !/(let|const|var) +items +=/.test(code)) {
|
||||
const quoted = error.message.replace('items', '`items`');
|
||||
error.message = quoted + '. Did you mean `$input.all()`?';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the "item is not defined" error message to provide a more helpful suggestion
|
||||
* for users who may expect `items` to pre-exist
|
||||
*/
|
||||
export function mapItemNotDefinedErrorIfNeededForRunForEach(code: string, error: Error) {
|
||||
// anticipate user expecting `items` to pre-exist as in Function Item node
|
||||
if (error.message === 'item is not defined' && !/(let|const|var) +item +=/.test(code)) {
|
||||
const quoted = error.message.replace('item', '`item`');
|
||||
error.message = quoted + '. Did you mean `$input.item.json`?';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user