n8n-workflow
Advanced tools
Comparing version 0.89.0 to 0.90.0
@@ -24,2 +24,3 @@ "use strict"; | ||
const tmpl = __importStar(require("riot-tmpl")); | ||
const luxon_1 = require("luxon"); | ||
const _1 = require("."); | ||
@@ -54,2 +55,5 @@ tmpl.brackets.set('{{ }}'); | ||
data.document = {}; | ||
data.DateTime = luxon_1.DateTime; | ||
data.Interval = luxon_1.Interval; | ||
data.Duration = luxon_1.Duration; | ||
data.constructor = {}; | ||
@@ -56,0 +60,0 @@ try { |
@@ -777,2 +777,9 @@ /// <reference types="node" /> | ||
$workflow: any; | ||
$: any; | ||
$input: any; | ||
$thisItem: any; | ||
$thisRunIndex: number; | ||
$thisItemIndex: number; | ||
$now: any; | ||
$today: any; | ||
} | ||
@@ -779,0 +786,0 @@ export declare type IWorkflowDataProxyAdditionalKeys = IDataObject; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkflowDataProxy = void 0; | ||
const luxon_1 = require("luxon"); | ||
const jmespath = __importStar(require("jmespath")); | ||
const _1 = require("."); | ||
@@ -101,3 +122,8 @@ class WorkflowDataProxy { | ||
if (!that.runExecutionData.resultData.runData.hasOwnProperty(nodeName)) { | ||
throw new Error(`No execution data found for node "${nodeName}"`); | ||
if (that.workflow.getNode(nodeName)) { | ||
throw new Error(`The node "${nodeName}" hasn't been executed yet, so you can't reference its output data`); | ||
} | ||
else { | ||
throw new Error(`No node called "${nodeName}" in this workflow`); | ||
} | ||
} | ||
@@ -107,4 +133,4 @@ runIndex = runIndex === undefined ? that.defaultReturnRunIndex : runIndex; | ||
runIndex === -1 ? that.runExecutionData.resultData.runData[nodeName].length - 1 : runIndex; | ||
if (that.runExecutionData.resultData.runData[nodeName].length < runIndex) { | ||
throw new Error(`No execution data found for run "${runIndex}" of node "${nodeName}"`); | ||
if (that.runExecutionData.resultData.runData[nodeName].length <= runIndex) { | ||
throw new Error(`Run ${runIndex} of node "${nodeName}" not found`); | ||
} | ||
@@ -124,4 +150,4 @@ const taskData = that.runExecutionData.resultData.runData[nodeName][runIndex].data; | ||
} | ||
if (taskData.main.length < outputIndex) { | ||
throw new Error(`No data found from "main" input with index "${outputIndex}" via which node is connected with.`); | ||
if (taskData.main.length <= outputIndex) { | ||
throw new Error(`Node "${nodeName}" has no branch with index ${outputIndex}.`); | ||
} | ||
@@ -226,3 +252,156 @@ executionData = taskData.main[outputIndex]; | ||
const that = this; | ||
const getNodeOutput = (nodeName, branchIndex, runIndex) => { | ||
let executionData; | ||
if (nodeName === undefined) { | ||
executionData = that.connectionInputData; | ||
} | ||
else { | ||
branchIndex = branchIndex || 0; | ||
runIndex = runIndex === undefined ? -1 : runIndex; | ||
executionData = that.getNodeExecutionData(nodeName, false, branchIndex, runIndex); | ||
} | ||
return executionData; | ||
}; | ||
const jmespathWrapper = (data, query) => { | ||
if (!Array.isArray(data) && typeof data === 'object') { | ||
return jmespath.search({ ...data }, query); | ||
} | ||
return jmespath.search(data, query); | ||
}; | ||
const base = { | ||
$: (nodeName) => { | ||
if (!nodeName) { | ||
throw new Error(`When calling $(), please specify a node`); | ||
} | ||
return new Proxy({}, { | ||
get(target, property, receiver) { | ||
var _a; | ||
if (property === 'pairedItem') { | ||
return () => { | ||
const executionData = getNodeOutput(nodeName, 0, that.runIndex); | ||
if (executionData[that.itemIndex]) { | ||
return executionData[that.itemIndex]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'item') { | ||
return (itemIndex, branchIndex, runIndex) => { | ||
if (itemIndex === undefined) { | ||
itemIndex = that.itemIndex; | ||
branchIndex = 0; | ||
runIndex = that.runIndex; | ||
} | ||
const executionData = getNodeOutput(nodeName, branchIndex, runIndex); | ||
if (executionData[itemIndex]) { | ||
return executionData[itemIndex]; | ||
} | ||
let errorMessage = ''; | ||
if (branchIndex === undefined && runIndex === undefined) { | ||
errorMessage = ` | ||
No item found at index ${itemIndex} | ||
(for node "${nodeName}")`; | ||
throw new Error(errorMessage); | ||
} | ||
if (branchIndex === undefined) { | ||
errorMessage = ` | ||
No item found at index ${itemIndex} | ||
in run ${runIndex || that.runIndex} | ||
(for node "${nodeName}")`; | ||
throw new Error(errorMessage); | ||
} | ||
if (runIndex === undefined) { | ||
errorMessage = ` | ||
No item found at index ${itemIndex} | ||
of branch ${branchIndex || 0} | ||
(for node "${nodeName}")`; | ||
throw new Error(errorMessage); | ||
} | ||
errorMessage = ` | ||
No item found at index ${itemIndex} | ||
of branch ${branchIndex || 0} | ||
in run ${runIndex || that.runIndex} | ||
(for node "${nodeName}")`; | ||
throw new Error(errorMessage); | ||
}; | ||
} | ||
if (property === 'first') { | ||
return (branchIndex, runIndex) => { | ||
const executionData = getNodeOutput(nodeName, branchIndex, runIndex); | ||
if (executionData[0]) | ||
return executionData[0]; | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'last') { | ||
return (branchIndex, runIndex) => { | ||
const executionData = getNodeOutput(nodeName, branchIndex, runIndex); | ||
if (!executionData.length) | ||
return undefined; | ||
if (executionData[executionData.length - 1]) { | ||
return executionData[executionData.length - 1]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'all') { | ||
return (branchIndex, runIndex) => getNodeOutput(nodeName, branchIndex, runIndex); | ||
} | ||
if (property === 'context') { | ||
return that.nodeContextGetter(nodeName); | ||
} | ||
if (property === 'params') { | ||
return (_a = that.workflow.getNode(nodeName)) === null || _a === void 0 ? void 0 : _a.parameters; | ||
} | ||
return Reflect.get(target, property, receiver); | ||
}, | ||
}); | ||
}, | ||
$input: new Proxy({}, { | ||
get(target, property, receiver) { | ||
if (property === 'thisItem') { | ||
return that.connectionInputData[that.itemIndex]; | ||
} | ||
if (property === 'item') { | ||
return (itemIndex) => { | ||
if (itemIndex === undefined) | ||
itemIndex = that.itemIndex; | ||
const result = that.connectionInputData; | ||
if (result[itemIndex]) { | ||
return result[itemIndex]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'first') { | ||
return () => { | ||
const result = that.connectionInputData; | ||
if (result[0]) { | ||
return result[0]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'last') { | ||
return () => { | ||
const result = that.connectionInputData; | ||
if (result.length && result[result.length - 1]) { | ||
return result[result.length - 1]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
if (property === 'all') { | ||
return () => { | ||
const result = that.connectionInputData; | ||
if (result.length) { | ||
return result; | ||
} | ||
return []; | ||
}; | ||
} | ||
return Reflect.get(target, property, receiver); | ||
}, | ||
}), | ||
$thisItem: that.connectionInputData[that.itemIndex], | ||
$binary: {}, | ||
@@ -260,2 +439,10 @@ $data: {}, | ||
$workflow: this.workflowGetter(), | ||
$thisRunIndex: this.runIndex, | ||
$thisItemIndex: this.itemIndex, | ||
$now: luxon_1.DateTime.now(), | ||
$today: luxon_1.DateTime.now().set({ hour: 0, minute: 0, second: 0, millisecond: 0 }), | ||
$jmespath: jmespathWrapper, | ||
DateTime: luxon_1.DateTime, | ||
Interval: luxon_1.Interval, | ||
Duration: luxon_1.Duration, | ||
...that.additionalKeys, | ||
@@ -262,0 +449,0 @@ }; |
{ | ||
"name": "n8n-workflow", | ||
"version": "0.89.0", | ||
"version": "0.90.0", | ||
"description": "Workflow base code of n8n", | ||
@@ -32,4 +32,6 @@ "license": "SEE LICENSE IN LICENSE.md", | ||
"@types/jest": "^26.0.13", | ||
"@types/jmespath": "^0.15.0", | ||
"@types/lodash.get": "^4.4.6", | ||
"@types/lodash.merge": "^4.6.6", | ||
"@types/luxon": "^2.0.9", | ||
"@types/lodash.set": "^4.3.6", | ||
@@ -52,2 +54,3 @@ "@types/node": "14.17.27", | ||
"dependencies": { | ||
"jmespath": "^0.16.0", | ||
"lodash.get": "^4.4.2", | ||
@@ -57,2 +60,3 @@ "lodash.isequal": "^4.5.0", | ||
"lodash.set": "^4.3.2", | ||
"luxon": "^2.3.0", | ||
"riot-tmpl": "^3.0.8", | ||
@@ -59,0 +63,0 @@ "xml2js": "^0.4.23" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
683531
63
10538
8
21
+ Addedjmespath@^0.16.0
+ Addedluxon@^2.3.0
+ Addedjmespath@0.16.0(transitive)
+ Addedluxon@2.5.2(transitive)