Skip to content

Commit 97207ac

Browse files
committed
fix: add support for loop steps in meta schema
1 parent 60ee576 commit 97207ac

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

meta-schema.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"properties": {
131131
"loop": {
132132
"type": "object",
133-
"required": ["over", "as", "step"],
133+
"required": ["over", "as"],
134134
"properties": {
135135
"over": {
136136
"type": "string",
@@ -152,6 +152,13 @@
152152
"step": {
153153
"$ref": "#/definitions/Step",
154154
"description": "The step to execute for each item in the iteration. Can be any primitive step type."
155+
},
156+
"steps": {
157+
"type": "array",
158+
"description": "An array of steps to execute for each item in the iteration.",
159+
"items": {
160+
"$ref": "#/definitions/Step"
161+
}
155162
}
156163
}
157164
}

src/__tests__/dependency-resolver.test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,61 @@ describe('DependencyResolver', () => {
541541
expect(deps).toContain('step2');
542542
expect(deps).toContain('step3');
543543
});
544+
545+
it('correctly identifies dependencies in loop steps with multiple steps', () => {
546+
const flow: Flow = {
547+
name: 'Test Flow',
548+
description: 'Test flow for loop step dependencies with multiple steps',
549+
steps: [
550+
{
551+
name: 'getUser',
552+
request: {
553+
method: 'user.get',
554+
params: { id: 1 },
555+
},
556+
},
557+
{
558+
name: 'getFriends',
559+
request: {
560+
method: 'user.getFriends',
561+
params: { userId: '${getUser.id}' },
562+
},
563+
},
564+
{
565+
name: 'notifyFriends',
566+
loop: {
567+
over: '${getFriends}',
568+
as: 'friend',
569+
steps: [
570+
{
571+
name: 'validateFriend',
572+
request: {
573+
method: 'friend.validate',
574+
params: { id: '${friend.id}' },
575+
},
576+
},
577+
{
578+
name: 'sendNotification',
579+
request: {
580+
method: 'notification.send',
581+
params: {
582+
userId: '${friend.id}',
583+
message: 'Hello from ${getUser.name}!',
584+
},
585+
},
586+
},
587+
],
588+
},
589+
},
590+
],
591+
};
592+
593+
const resolver = new DependencyResolver(flow, expressionEvaluator, testLogger);
594+
expect(resolver.getDependencies('notifyFriends')).toEqual(['getFriends', 'getUser']);
595+
expect(resolver.getExecutionOrder().map((s) => s.name)).toEqual([
596+
'getUser',
597+
'getFriends',
598+
'notifyFriends',
599+
]);
600+
});
544601
});

src/dependency-resolver.ts

+15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ export class DependencyResolver {
129129
this.loopVars.delete(loopVar);
130130
}
131131
}
132+
133+
// Process the loop's steps if present
134+
if (step.loop.steps) {
135+
// Add the loop variable to loopVars temporarily
136+
const loopVar = step.loop.as;
137+
this.loopVars.add(loopVar);
138+
139+
// Find dependencies in each step
140+
for (const subStep of step.loop.steps) {
141+
this.findStepDependencies(subStep).forEach((dep) => deps.add(dep));
142+
}
143+
144+
// Remove the loop variable from loopVars
145+
this.loopVars.delete(loopVar);
146+
}
132147
}
133148

134149
// Extract references from condition steps

0 commit comments

Comments
 (0)