Skip to content

Commit

Permalink
add support for arrays in workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Jun 7, 2023
1 parent 7a2e44a commit 05d20e2
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Workflow/Services/RunWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ComponentMetadata, {
NodeType,
Port,
} from 'Common/Types/Workflow/Component';
import JSONFunctions from 'Common/Types/JSONFunctions';
import WorkflowService from 'CommonServer/Services/WorkflowService';
import ComponentCode, {
RunReturnType,
Expand Down Expand Up @@ -388,20 +387,38 @@ export default class RunWorkflow {
path: string
): JSONValue => {
const paths: Array<string> = path.split('.');
let current: any = JSONFunctions.parse(JSON.stringify(obj));
let current: any = JSON.parse(JSON.stringify(obj));

for (let i: number = 0; i < paths.length; ++i) {
if (
current &&
paths[i] &&
(current[(paths as any)[i] as any] as any) === undefined
) {
const key: string | undefined = paths[i];

if (!key) {
return undefined;
}
const openBracketIndex: number = key.indexOf('[');
const closeBracketIndex: number = key.indexOf(']');

if (openBracketIndex !== -1 && closeBracketIndex !== -1) {
const arrayKey: string = key.slice(0, openBracketIndex);
const index: number = parseInt(
key.slice(openBracketIndex + 1, closeBracketIndex)
);

if (
Array.isArray(current[arrayKey]) &&
current[arrayKey][index]
) {
current = current[arrayKey][index];
} else {
return undefined;
}
} else if (current && current[key] !== undefined) {
current = current[key];
} else {
return undefined;
} else if (current[paths[i] as string] === null) {
return null;
}
current = current[paths[i] as string];
}

return current;
};

Expand Down

0 comments on commit 05d20e2

Please sign in to comment.