Skip to content

Add support for loop steps in meta schema #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion meta-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"properties": {
"loop": {
"type": "object",
"required": ["over", "as", "step"],
"required": ["over", "as"],
"properties": {
"over": {
"type": "string",
Expand All @@ -152,6 +152,13 @@
"step": {
"$ref": "#/definitions/Step",
"description": "The step to execute for each item in the iteration. Can be any primitive step type."
},
"steps": {
"type": "array",
"description": "An array of steps to execute for each item in the iteration.",
"items": {
"$ref": "#/definitions/Step"
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions src/__tests__/dependency-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,61 @@ describe('DependencyResolver', () => {
expect(deps).toContain('step2');
expect(deps).toContain('step3');
});

it('correctly identifies dependencies in loop steps with multiple steps', () => {
const flow: Flow = {
name: 'Test Flow',
description: 'Test flow for loop step dependencies with multiple steps',
steps: [
{
name: 'getUser',
request: {
method: 'user.get',
params: { id: 1 },
},
},
{
name: 'getFriends',
request: {
method: 'user.getFriends',
params: { userId: '${getUser.id}' },
},
},
{
name: 'notifyFriends',
loop: {
over: '${getFriends}',
as: 'friend',
steps: [
{
name: 'validateFriend',
request: {
method: 'friend.validate',
params: { id: '${friend.id}' },
},
},
{
name: 'sendNotification',
request: {
method: 'notification.send',
params: {
userId: '${friend.id}',
message: 'Hello from ${getUser.name}!',
},
},
},
],
},
},
],
};

const resolver = new DependencyResolver(flow, expressionEvaluator, testLogger);
expect(resolver.getDependencies('notifyFriends')).toEqual(['getFriends', 'getUser']);
expect(resolver.getExecutionOrder().map((s) => s.name)).toEqual([
'getUser',
'getFriends',
'notifyFriends',
]);
});
});
15 changes: 15 additions & 0 deletions src/dependency-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ export class DependencyResolver {
this.loopVars.delete(loopVar);
}
}

// Process the loop's steps if present
if (step.loop.steps) {
// Add the loop variable to loopVars temporarily
const loopVar = step.loop.as;
this.loopVars.add(loopVar);

// Find dependencies in each step
for (const subStep of step.loop.steps) {
this.findStepDependencies(subStep).forEach((dep) => deps.add(dep));
}

// Remove the loop variable from loopVars
this.loopVars.delete(loopVar);
}
}

// Extract references from condition steps
Expand Down
Loading