directus

Форк
0
/
construct-flow-tree.ts 
37 строк · 1.2 Кб
1
import type { Flow, FlowRaw, Operation, OperationRaw } from '@directus/types';
2
import { omit } from 'lodash-es';
3

4
export function constructFlowTree(flow: FlowRaw): Flow {
5
	const rootOperation = flow.operations.find((operation) => operation.id === flow.operation) ?? null;
6

7
	const operationTree = constructOperationTree(rootOperation, flow.operations);
8

9
	const flowTree: Flow = {
10
		...omit(flow, 'operations'),
11
		operation: operationTree,
12
		options: flow.options ?? {},
13
	};
14

15
	return flowTree;
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
}
38

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.