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 { sleep, NodeOperationError, jsonParse, NodeConnectionTypes } from 'n8n-workflow';
|
||||
import type {
|
||||
IDataObject,
|
||||
ITriggerFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
executionDurationProperty,
|
||||
iconSelector,
|
||||
jsonOutputProperty,
|
||||
subtitleProperty,
|
||||
} from './descriptions';
|
||||
import { loadOptions } from './methods';
|
||||
|
||||
export class SimulateTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
hidden: true,
|
||||
displayName: 'Simulate Trigger',
|
||||
name: 'simulateTrigger',
|
||||
subtitle: '={{$parameter.subtitle || undefined}}',
|
||||
icon: 'fa:arrow-right',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Simulate a trigger node',
|
||||
defaults: {
|
||||
name: 'Simulate Trigger',
|
||||
color: '#b0b0b0',
|
||||
},
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
properties: [
|
||||
{ ...iconSelector, default: 'n8n-nodes-base.manualTrigger' },
|
||||
subtitleProperty,
|
||||
{ ...jsonOutputProperty, displayName: 'Output (JSON)' },
|
||||
executionDurationProperty,
|
||||
],
|
||||
};
|
||||
|
||||
methods = { loadOptions };
|
||||
|
||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||
const returnItems: INodeExecutionData[] = [];
|
||||
|
||||
let jsonOutput = this.getNodeParameter('jsonOutput', 0);
|
||||
|
||||
if (typeof jsonOutput === 'string') {
|
||||
try {
|
||||
jsonOutput = jsonParse<IDataObject>(jsonOutput);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), 'Invalid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(jsonOutput)) {
|
||||
jsonOutput = [jsonOutput];
|
||||
}
|
||||
|
||||
for (const item of jsonOutput as IDataObject[]) {
|
||||
returnItems.push({ json: item });
|
||||
}
|
||||
|
||||
const executionDuration = this.getNodeParameter('executionDuration', 0) as number;
|
||||
|
||||
if (executionDuration > 0) {
|
||||
await sleep(executionDuration);
|
||||
}
|
||||
|
||||
const manualTriggerFunction = async () => {
|
||||
this.emit([returnItems]);
|
||||
};
|
||||
|
||||
return {
|
||||
manualTriggerFunction,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user