| 16 | } |
| 17 | |
| 18 | function constructOperationTree(root: OperationRaw | null, operations: OperationRaw[]): Operation | null { |
| 19 | if (root === null) { |
| 20 | return null; |
| 21 | } |
| 22 | |
| 23 | const resolveOperation = root.resolve !== null ? operations.find((operation) => operation.id === root.resolve) : null; |
| 24 | const rejectOperation = root.reject !== null ? operations.find((operation) => operation.id === root.reject) : null; |
| 25 | |
| 26 | if (resolveOperation === undefined || rejectOperation === undefined) { |
| 27 | throw new Error('Undefined reference in operations'); |
| 28 | } |
| 29 | |
| 30 | const operationTree: Operation = { |
| 31 | ...omit(root, 'flow'), |
| 32 | resolve: constructOperationTree(resolveOperation, operations), |
| 33 | reject: constructOperationTree(rejectOperation, operations), |
| 34 | }; |
| 35 | |
| 36 | return operationTree; |
| 37 | } |