@@ -15,6 +15,7 @@ import {
1515import { GenericMapper as TucanaGenericMapper } from "@code0-tech/tucana/pb/shared.data_type_pb.js"
1616import { ConstructedDataTypes , getID } from "../parser.js" ;
1717import { getTranslationConnection } from "./translation.js" ;
18+ import { Value } from "@code0-tech/tucana/pb/shared.struct_pb.js" ;
1819
1920function getDataType ( identifier : string , constructedDataTypes : ConstructedDataTypes ) : DataType | null {
2021 const dataType = constructedDataTypes . constructedDataTypes . find ( dt => dt . identifier === identifier )
@@ -67,7 +68,7 @@ function createRules(rule: DefinitionDataTypeRule[], constructedDataTypes: Const
6768 }
6869 case "itemOfCollection" : {
6970 const ruleConfig : DataTypeRulesItemOfCollectionConfig = {
70- items : r . config . itemOfCollection . items , //TODO: This needs to be checked
71+ items : r . config . itemOfCollection . items . map ( valueToJSON ) ,
7172 }
7273 const rule : DataTypeRule = {
7374 variant : DataTypeRulesVariant . ItemOfCollection ,
@@ -195,7 +196,7 @@ function getDataTypeIdentifier(identifier: TucanaDataTypeIdentifier | undefined,
195196 type : type
196197 }
197198 } ) ,
198- sources : mapper . source . map ( id =>
199+ sourceDataTypeIdentifiers : mapper . source . map ( id =>
199200 getDataTypeIdentifier ( id , constructedDataTypes )
200201 ) . filter ( id => id != null ) ,
201202 target : mapper . target ,
@@ -224,4 +225,27 @@ function getDataTypeIdentifier(identifier: TucanaDataTypeIdentifier | undefined,
224225 return null ;
225226}
226227
228+ // @ts -ignore
229+ function valueToJSON ( value : Value ) {
230+ switch ( value . kind . oneofKind ) {
231+ case "nullValue" :
232+ return null
233+ case "numberValue" :
234+ return value . kind . numberValue
235+ case "stringValue" :
236+ return value . kind . stringValue
237+ case "boolValue" :
238+ return value . kind . boolValue
239+ case "structValue" :
240+ return Object . fromEntries (
241+ // @ts -ignore
242+ Object . entries ( value . kind . structValue . fields ) . map ( ( [ k , v ] ) => {
243+ return [ k , valueToJSON ( v ) ]
244+ } )
245+ )
246+ case "listValue" :
247+ return value . kind . listValue . values . map ( valueToJSON )
248+ }
249+ }
250+
227251export { getDataType , getDataTypeIdentifier }
0 commit comments