mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(editor): Reintroduce item and items to CodeNodeEditor (#4553)
* ⚡ Alias legacy refs to new syntax * 📘 Adjust types * 👕 Switch `item` lint error to warning * ⚡ Add completions for legacy vars * ✏️ Add descriptions to completions * ⚡ Add lintings * 📘 Skip `any` for now * ⚡ Expand regex
This commit is contained in:
@@ -79,6 +79,7 @@ export class Code implements INodeType {
|
||||
const jsCodeAllItems = this.getNodeParameter('jsCode', 0) as string;
|
||||
|
||||
const context = getSandboxContext.call(this);
|
||||
context.items = context.$input.all();
|
||||
const sandbox = new Sandbox(context, workflowMode, nodeMode);
|
||||
|
||||
if (workflowMode === 'manual') {
|
||||
@@ -111,6 +112,7 @@ export class Code implements INodeType {
|
||||
const jsCodeEachItem = this.getNodeParameter('jsCode', index) as string;
|
||||
|
||||
const context = getSandboxContext.call(this, index);
|
||||
context.item = context.$input.item;
|
||||
const sandbox = new Sandbox(context, workflowMode, nodeMode);
|
||||
|
||||
if (workflowMode === 'manual') {
|
||||
|
||||
@@ -250,16 +250,19 @@ export class Sandbox extends NodeVM {
|
||||
}
|
||||
|
||||
export function getSandboxContext(this: IExecuteFunctions, index?: number) {
|
||||
const sandboxContext: Record<string, unknown> & { $item: (i: number) => IWorkflowDataProxyData } =
|
||||
{
|
||||
// from NodeExecuteFunctions
|
||||
$getNodeParameter: this.getNodeParameter,
|
||||
$getWorkflowStaticData: this.getWorkflowStaticData,
|
||||
helpers: this.helpers,
|
||||
const sandboxContext: Record<string, unknown> & {
|
||||
$item: (i: number) => IWorkflowDataProxyData;
|
||||
$input: any; // tslint:disable-line: no-any
|
||||
} = {
|
||||
// from NodeExecuteFunctions
|
||||
$getNodeParameter: this.getNodeParameter,
|
||||
$getWorkflowStaticData: this.getWorkflowStaticData,
|
||||
helpers: this.helpers,
|
||||
|
||||
// to bring in all $-prefixed vars and methods from WorkflowDataProxy
|
||||
$item: this.getWorkflowDataProxy,
|
||||
};
|
||||
// to bring in all $-prefixed vars and methods from WorkflowDataProxy
|
||||
$item: this.getWorkflowDataProxy,
|
||||
$input: null,
|
||||
};
|
||||
|
||||
// $node, $items(), $parameter, $json, $env, etc.
|
||||
Object.assign(sandboxContext, sandboxContext.$item(index ?? 0));
|
||||
|
||||
Reference in New Issue
Block a user