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,80 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
ISupplyDataFunctions,
|
||||
IWorkflowDataProxyData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { validateRunCodeAllItems, validateRunCodeEachItem } from './result-validation';
|
||||
|
||||
interface SandboxTextKeys {
|
||||
object: {
|
||||
singular: string;
|
||||
plural: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SandboxContext extends IWorkflowDataProxyData {
|
||||
$getNodeParameter: IExecuteFunctions['getNodeParameter'];
|
||||
$getWorkflowStaticData: IExecuteFunctions['getWorkflowStaticData'];
|
||||
helpers: IExecuteFunctions['helpers'];
|
||||
}
|
||||
|
||||
export function getSandboxContext(
|
||||
this: IExecuteFunctions | ISupplyDataFunctions,
|
||||
index: number,
|
||||
): SandboxContext {
|
||||
const helpers = {
|
||||
...this.helpers,
|
||||
httpRequestWithAuthentication: this.helpers.httpRequestWithAuthentication.bind(this),
|
||||
requestWithAuthenticationPaginated: this.helpers.requestWithAuthenticationPaginated.bind(this),
|
||||
};
|
||||
return {
|
||||
// from NodeExecuteFunctions
|
||||
$getNodeParameter: this.getNodeParameter.bind(this),
|
||||
$getWorkflowStaticData: this.getWorkflowStaticData.bind(this),
|
||||
helpers,
|
||||
|
||||
// to bring in all $-prefixed vars and methods from WorkflowDataProxy
|
||||
// $node, $items(), $parameter, $json, $env, etc.
|
||||
...this.getWorkflowDataProxy(index),
|
||||
};
|
||||
}
|
||||
|
||||
export abstract class Sandbox extends EventEmitter {
|
||||
constructor(
|
||||
private textKeys: SandboxTextKeys,
|
||||
protected helpers: IExecuteFunctions['helpers'],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
abstract runCode<T = unknown>(): Promise<T>;
|
||||
|
||||
abstract runCodeAllItems(): Promise<INodeExecutionData[] | INodeExecutionData[][]>;
|
||||
|
||||
abstract runCodeEachItem(itemIndex: number): Promise<INodeExecutionData | undefined>;
|
||||
|
||||
validateRunCodeEachItem(
|
||||
executionResult: INodeExecutionData | undefined,
|
||||
itemIndex: number,
|
||||
): INodeExecutionData {
|
||||
return validateRunCodeEachItem(
|
||||
executionResult,
|
||||
itemIndex,
|
||||
this.textKeys,
|
||||
this.helpers.normalizeItems.bind(this.helpers),
|
||||
);
|
||||
}
|
||||
|
||||
validateRunCodeAllItems(
|
||||
executionResult: INodeExecutionData | INodeExecutionData[] | undefined,
|
||||
): INodeExecutionData[] {
|
||||
return validateRunCodeAllItems(
|
||||
executionResult,
|
||||
this.textKeys,
|
||||
this.helpers.normalizeItems.bind(this.helpers),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user