1+ import { SingleValidationInputData } from "./readSingle" ;
2+ import {
3+ DataType ,
4+ Flow ,
5+ FunctionDefinition ,
6+ LiteralValue ,
7+ NodeFunction ,
8+ NodeParameter ,
9+ NodeParameterValue , ParameterDefinition ,
10+ } from "@code0-tech/sagittarius-graphql-types" ;
11+ import {
12+ DefinitionDataType ,
13+ NodeFunction as TucanaNodeFunction ,
14+ NodeParameter as TucanaNodeParameter , RuntimeFunctionDefinition , RuntimeParameterDefinition ,
15+ ValidationFlow ,
16+ } from "@code0-tech/tucana/shared" ;
17+ import { toAllowedValue } from "@code0-tech/tucana/helpers" ;
18+
19+ export type TriangulumFlowValidationInput = {
20+ flow ?: Flow ,
21+ functions ?: FunctionDefinition [ ] ,
22+ dataTypes ?: DataType [ ]
23+ }
24+
25+ export function mapToFlowValidation ( data : SingleValidationInputData ) : TriangulumFlowValidationInput {
26+ return {
27+ flow : mapFlow ( data . flow ! ) ,
28+ functions : data . functions . map ( mapFunctionDefinition ) ,
29+ dataTypes : data . dataTypes . map ( mapDataType )
30+ }
31+ }
32+
33+ function gid ( type : string , id : bigint | number ) {
34+ return `gid://sagittarius/${ type } /${ Number ( id ) } ` ;
35+ }
36+
37+ function mapFlow ( flow : ValidationFlow ) : Flow {
38+ return {
39+ __typename : "Flow" ,
40+ id : gid ( 'Flow' , flow . flowId ) as Flow [ 'id' ] ,
41+ inputType : flow . inputType ,
42+ returnType : flow . returnType ,
43+ startingNodeId : gid ( 'NodeFunction' , flow . startingNodeId ) as NodeFunction [ 'id' ] ,
44+ nodes : {
45+ nodes : flow . nodeFunctions . map ( mapNodeFunction )
46+ }
47+ } ;
48+ }
49+
50+ function mapNodeFunction ( nodeFunction : TucanaNodeFunction ) : NodeFunction {
51+ return {
52+ id : gid ( 'NodeFunction' , nodeFunction . databaseId ) as NodeFunction [ 'id' ] ,
53+ functionDefinition : {
54+ identifier : nodeFunction . runtimeFunctionId
55+ } ,
56+ nextNodeId : nodeFunction . nextNodeId ? gid ( 'NodeFunction' , nodeFunction . nextNodeId ) as NodeFunction [ 'id' ] : undefined ,
57+ parameters : {
58+ nodes : nodeFunction . parameters . map ( mapNodeParameter )
59+ }
60+ }
61+ }
62+
63+ function mapNodeParameter ( nodeParameter : TucanaNodeParameter ) : NodeParameter {
64+ let value : NodeParameterValue = { }
65+ const nodeParameterValue = nodeParameter . value ?. value
66+
67+ if ( nodeParameterValue ?. oneofKind === 'literalValue' ) {
68+ value = {
69+ __typename : 'LiteralValue' ,
70+ value : toAllowedValue ( nodeParameterValue . literalValue )
71+ } ;
72+ } else if ( nodeParameterValue ?. oneofKind === 'referenceValue' ) {
73+ const target = nodeParameterValue . referenceValue . target ;
74+
75+ value = {
76+ __typename : 'ReferenceValue' ,
77+ referencePath : nodeParameterValue . referenceValue . paths . map ( p => ( {
78+ __typename : 'ReferencePath' ,
79+ path : p . path ,
80+ arrayIndex : Number ( p . arrayIndex )
81+ } ) )
82+ }
83+
84+ if ( target . oneofKind === 'nodeId' ) {
85+ value . nodeFunctionId = gid ( 'NodeFunction' , target . nodeId ) as NodeFunction [ 'id' ]
86+ } else if ( target . oneofKind === 'inputType' ) {
87+ value . nodeFunctionId = gid ( 'NodeFunction' , target . inputType . nodeId ) as NodeFunction [ 'id' ]
88+ value . parameterIndex = Number ( target . inputType . parameterIndex )
89+ value . inputIndex = Number ( target . inputType . inputIndex )
90+ }
91+ } else if ( nodeParameterValue ?. oneofKind === 'nodeFunctionId' ) {
92+ value = {
93+ __typename : 'NodeFunctionIdWrapper' ,
94+ id : gid ( 'NodeFunction' , nodeParameterValue . nodeFunctionId ) as NodeFunction [ 'id' ]
95+ }
96+ }
97+
98+ return {
99+ id : gid ( 'NodeParameter' , nodeParameter . databaseId ) as NodeParameter [ 'id' ] ,
100+ value
101+ }
102+ }
103+
104+ function mapFunctionDefinition ( functionDefinition : RuntimeFunctionDefinition ) : FunctionDefinition {
105+ return {
106+ identifier : functionDefinition . runtimeName ,
107+ signature : functionDefinition . signature ,
108+ parameterDefinitions : {
109+ nodes : functionDefinition . runtimeParameterDefinitions . map ( mapParameterDefinition )
110+ }
111+ }
112+ }
113+
114+ function mapParameterDefinition ( parameterDefinition : RuntimeParameterDefinition ) : ParameterDefinition {
115+ return {
116+ identifier : parameterDefinition . runtimeName ,
117+ }
118+ }
119+
120+ function mapDataType ( dataType : DefinitionDataType ) : DataType {
121+ return {
122+ identifier : dataType . identifier ,
123+ type : dataType . type ,
124+ genericKeys : dataType . genericKeys
125+ } ;
126+ }
0 commit comments