Skip to content

Commit ec44589

Browse files
committed
branches with step order
1 parent 2ae94f1 commit ec44589

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/core-services/src/services/processing.service.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,44 +83,47 @@ export class ProcessingService implements IBaseService {
8383
const executedSteps: SelectProcessingStep[] = [];
8484
try {
8585
let globalOutput: unknown = content;
86-
const branches = new Map<string, ProcessingPlanStep[]>();
87-
const globalSteps: ProcessingPlanStep[] = [];
8886

89-
for (const step of plan) {
87+
const planWithOrder = plan.map((step, index) => ({
88+
...step,
89+
order: index + 1,
90+
}));
91+
92+
const globalStepsWithOrder: typeof planWithOrder = [];
93+
const branchesWithOrder = new Map<string, typeof planWithOrder>();
94+
95+
for (const step of planWithOrder) {
9096
if (step.branchId) {
91-
if (!branches.has(step.branchId)) {
92-
branches.set(step.branchId, []);
97+
if (!branchesWithOrder.has(step.branchId)) {
98+
branchesWithOrder.set(step.branchId, []);
9399
}
94-
branches.get(step.branchId)!.push(step);
100+
branchesWithOrder.get(step.branchId)!.push(step);
95101
} else {
96-
globalSteps.push(step);
102+
globalStepsWithOrder.push(step);
97103
}
98104
}
99105

100-
let stepOrder = 0;
101-
for (const planStep of globalSteps) {
102-
stepOrder++;
106+
for (const planStep of globalStepsWithOrder) {
103107
const result = await this.executeTransform(
104108
job.id,
105109
globalOutput,
106110
planStep,
107-
stepOrder,
111+
planStep.order,
108112
);
109113
executedSteps.push(result.step);
110114
globalOutput = result.output;
111115
}
112116

113-
const branchPromises = Array.from(branches.values()).map(
117+
const branchPromises = Array.from(branchesWithOrder.values()).map(
114118
async (branch) => {
115119
let branchContent = globalOutput;
116120
for (const planStep of branch) {
117-
stepOrder++;
118121
if (planStep.type === "transformation") {
119122
const result = await this.executeTransform(
120123
job.id,
121124
branchContent,
122125
planStep,
123-
stepOrder,
126+
planStep.order,
124127
);
125128
executedSteps.push(result.step);
126129
branchContent = result.output;
@@ -129,7 +132,7 @@ export class ProcessingService implements IBaseService {
129132
job.id,
130133
branchContent,
131134
planStep,
132-
stepOrder,
135+
planStep.order,
133136
);
134137
executedSteps.push(step);
135138
}

0 commit comments

Comments
 (0)