|
1 | 1 | import {ReactiveArrayService} from "../../utils"; |
2 | | -import type { |
| 2 | +import { |
| 3 | + DataTypeIdentifier, |
| 4 | + DataTypeIdentifierInput, |
3 | 5 | Flow, |
4 | | - FlowSetting, LiteralValue, |
| 6 | + FlowInput, |
| 7 | + FlowSetting, |
| 8 | + LiteralValue, |
5 | 9 | NamespacesProjectsFlowsCreateInput, |
6 | 10 | NamespacesProjectsFlowsCreatePayload, |
7 | 11 | NamespacesProjectsFlowsDeleteInput, |
8 | | - NamespacesProjectsFlowsDeletePayload, NamespacesProjectsFlowsUpdateInput, NamespacesProjectsFlowsUpdatePayload, |
9 | | - NodeFunction, NodeFunctionIdWrapper, |
10 | | - NodeParameter, ReferenceValue |
| 12 | + NamespacesProjectsFlowsDeletePayload, |
| 13 | + NamespacesProjectsFlowsUpdateInput, |
| 14 | + NamespacesProjectsFlowsUpdatePayload, |
| 15 | + NodeFunction, |
| 16 | + NodeFunctionIdWrapper, |
| 17 | + NodeParameter, |
| 18 | + ReferenceValue |
11 | 19 | } from "@code0-tech/sagittarius-graphql-types"; |
12 | 20 |
|
13 | 21 |
|
@@ -43,6 +51,67 @@ export abstract class DFlowReactiveService extends ReactiveArrayService<Flow> { |
43 | 51 | return this.getById(flowId)?.nodes?.nodes?.find(node => node?.id === nodeId)!! |
44 | 52 | } |
45 | 53 |
|
| 54 | + getPayloadById(flowId: Flow['id']): FlowInput | undefined { |
| 55 | + const flow = this.getById(flowId) |
| 56 | + |
| 57 | + const getDataTypeIdentifierPayload = (identifier: DataTypeIdentifier): DataTypeIdentifierInput => { |
| 58 | + return { |
| 59 | + ...(identifier?.dataType ? { |
| 60 | + dataTypeId: identifier?.dataType?.id |
| 61 | + } : {}), |
| 62 | + ...(identifier?.genericKey ? { |
| 63 | + genericKey: identifier?.genericKey |
| 64 | + } : {}), |
| 65 | + ...(identifier?.genericType ? { |
| 66 | + genericType: { |
| 67 | + dataTypeId: identifier?.genericType?.dataType?.id!, |
| 68 | + genericMappers: identifier?.genericType?.genericMappers?.map(genericMap => ({ |
| 69 | + target: genericMap.target!, |
| 70 | + sourceDataTypeIdentifiers: genericMap.sourceDataTypeIdentifiers?.map(getDataTypeIdentifierPayload) ?? [] |
| 71 | + })) ?? [] |
| 72 | + } |
| 73 | + } : {}) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + return { |
| 78 | + name: flow?.name!, |
| 79 | + type: flow?.type?.id!, |
| 80 | + settings: flow?.settings?.nodes?.map(setting => { |
| 81 | + return { |
| 82 | + flowSettingIdentifier: setting?.flowSettingIdentifier!, |
| 83 | + value: setting?.value!, |
| 84 | + } |
| 85 | + }), |
| 86 | + nodes: flow?.nodes?.nodes?.map(node => { |
| 87 | + return { |
| 88 | + id: node?.id!, |
| 89 | + nextNodeId: node?.nextNodeId!, |
| 90 | + parameters: node?.parameters?.nodes?.map(parameter => { |
| 91 | + return { |
| 92 | + runtimeParameterDefinitionId: parameter?.runtimeParameter?.id!, |
| 93 | + value: parameter?.value?.__typename === "NodeFunctionIdWrapper" ? { |
| 94 | + nodeFunctionId: parameter.value.id! |
| 95 | + } : parameter?.value?.__typename === "LiteralValue" ? { |
| 96 | + literalValue: parameter.value.value! |
| 97 | + } : { |
| 98 | + referenceValue: { |
| 99 | + dataTypeIdentifier: getDataTypeIdentifierPayload((parameter?.value as ReferenceValue).dataTypeIdentifier!), |
| 100 | + depth: (parameter?.value as ReferenceValue).depth!, |
| 101 | + node: (parameter?.value as ReferenceValue).node!, |
| 102 | + nodeFunctionId: (parameter?.value as ReferenceValue).nodeFunctionId!, |
| 103 | + referencePath: (parameter?.value as ReferenceValue).referencePath!, |
| 104 | + scope: (parameter?.value as ReferenceValue).scope!, |
| 105 | + } |
| 106 | + }, |
| 107 | + } |
| 108 | + }) ?? [], |
| 109 | + runtimeFunctionId: node?.functionDefinition?.runtimeFunctionDefinition?.id! |
| 110 | + } |
| 111 | + }) ?? [], |
| 112 | + startingNodeId: flow?.startingNodeId!, |
| 113 | + } |
| 114 | + } |
46 | 115 |
|
47 | 116 | async deleteNodeById(flowId: Flow['id'], nodeId: NodeFunction['id']): Promise<void> { |
48 | 117 | const flow = this.getById(flowId) |
@@ -132,7 +201,9 @@ export abstract class DFlowReactiveService extends ReactiveArrayService<Flow> { |
132 | 201 | } |
133 | 202 |
|
134 | 203 | abstract flowCreate(payload: NamespacesProjectsFlowsCreateInput): Promise<NamespacesProjectsFlowsCreatePayload | undefined> |
| 204 | + |
135 | 205 | abstract flowDelete(payload: NamespacesProjectsFlowsDeleteInput): Promise<NamespacesProjectsFlowsDeletePayload | undefined> |
| 206 | + |
136 | 207 | abstract flowUpdate(payload: NamespacesProjectsFlowsUpdateInput): Promise<NamespacesProjectsFlowsUpdatePayload | undefined> |
137 | 208 | } |
138 | 209 |
|
0 commit comments