@@ -6,85 +6,118 @@ import {RuntimeFunctionDefinition as TucanaFunction} from "@code0-tech/tucana/pb
66import path from "node:path" ;
77import { mapFlowType } from "./mapper/flowTypeMapper.ts" ;
88import { mapFunction } from "./mapper/functionMapper.ts" ;
9- import { DataType , FlowType , FunctionDefinition } from "@code0-tech/sagittarius-graphql-types" ;
9+ import { DataType } from "@code0-tech/sagittarius-graphql-types" ;
1010import { DefinitionDataType } from "@code0-tech/tucana/pb/shared.data_type_pb.ts" ;
11- import { getDataType } from "./mapper/helper .ts" ;
11+ import { getDataType } from "./mapper/dataTypeMapper .ts" ;
1212
1313export interface ConstructedDataTypes {
1414 scannedTucanaTypes : DefinitionDataType [ ]
1515 constructedDataTypes : DataType [ ]
1616}
1717
18- export const Definition = ( rootPath : string ) => {
19- const dataTypes : TucanaDataType [ ] = [ ]
20- const runtimeFunctions : TucanaFunction [ ] = [ ] ;
21- const flowTypes : TucanaFlowType [ ] = [ ] ;
22- console . log ( rootPath )
23- path . join ( )
18+ export const Definition = ( rootPath : string ) : Feature [ ] => {
19+ const dataTypes : { feature : string , type : TucanaDataType } [ ] = [ ]
20+ const runtimeFunctions : { feature : string , func : TucanaFunction } [ ] = [ ] ;
21+ const flowTypes : { feature : string , flow : TucanaFlowType } [ ] = [ ] ;
22+
2423 readdirSync ( rootPath , { withFileTypes : true } ) . forEach ( file => {
25- console . log ( file )
24+ const featureName = file . name . split ( "_" ) [ 0 ]
25+ if ( featureName == null ) {
26+ throw new Error ( "Feature name is null" )
27+ }
28+
2629 const filePath = path . join ( file . parentPath , file . name )
27- console . log ( filePath )
2830
2931 const content = readFileSync ( filePath ) ;
3032 if ( file . name . includes ( "data_type" ) ) {
3133 const decoded = TucanaDataType . fromBinary ( content ) ;
32- dataTypes . push ( decoded )
34+ dataTypes . push (
35+ {
36+ feature : featureName ,
37+ type : decoded ,
38+ }
39+ )
3340 }
3441
3542 if ( file . name . includes ( "function" ) ) {
3643 const decoded = TucanaFunction . fromBinary ( content ) ;
37- runtimeFunctions . push ( decoded )
44+ runtimeFunctions . push (
45+ {
46+ feature : featureName ,
47+ func : decoded ,
48+ }
49+ )
3850 }
3951
4052 if ( file . name . includes ( "flow_type" ) ) {
4153 const decoded = TucanaFlowType . fromBinary ( content ) ;
42- flowTypes . push ( decoded )
54+ flowTypes . push (
55+ {
56+ feature : featureName ,
57+ flow : decoded ,
58+ }
59+ )
4360 }
4461 } )
62+
63+ const features : Feature [ ] = [ ]
4564 const constructed : ConstructedDataTypes = {
46- scannedTucanaTypes : dataTypes ,
65+ scannedTucanaTypes : dataTypes . map ( f => f . type ) ,
4766 constructedDataTypes : [ ]
4867 }
49- dataTypes . map ( f => getDataType ( f . identifier , constructed ) ) . forEach ( ( d : DataType | null ) => console . dir ( d , { depth : null } ) )
50- runtimeFunctions . map ( f => mapFunction ( f , constructed ) ) . forEach ( ( f : FunctionDefinition | null ) => console . dir ( f , { depth : null } ) )
51- flowTypes . map ( f => mapFlowType ( f , constructed ) ) . forEach ( ( f : FlowType | null ) => console . dir ( f , { depth : null } ) )
5268
53- //throw new Error("Not implemented")
54- /*
55- const dt = meta.filter(m => m.type == MetaType.DataType).map(m => {
56- // console.log(m.data)
57- // return DefinitionDataType.fromJsonString(m.data)
58- // console.dir(def, {depth: null})
59- return null;
60- });
61- for (const d of dt) {
62- // console.dir(d, {depth: null})
63- }
64- const sortedDt = sortDataTypes(dt).map(d => mapDataType(d))
69+ function getFeature ( name : string ) : Feature {
70+ const feature = features . find ( ( f ) => f . name === name ) ;
71+ if ( feature != undefined ) {
72+ return feature ;
73+ }
74+
75+ const newFeature = {
76+ name : name ,
77+ dataTypes : [ ] ,
78+ flowTypes : [ ] ,
79+ runtimeFunctions : [ ] ,
80+ } ;
6581
66- for (const dt of sortedDt) {
67- console.log(dt)
82+ features . push ( newFeature ) ;
83+ return newFeature ;
6884 }
6985
70- for (const m of meta) {
71- let feature = features.find((f) => f.name === m.name);
86+ dataTypes . map ( f => {
87+ return {
88+ name : f . feature ,
89+ type : getDataType ( f . type . identifier , constructed )
90+ }
91+ } ) . forEach ( dt => {
92+ if ( dt . type != null ) {
93+ const feature = getFeature ( dt . name )
94+ feature . dataTypes . push ( dt . type )
95+ }
96+ } )
97+
98+ runtimeFunctions . map ( f => {
99+ return {
100+ name : f . feature ,
101+ type : mapFunction ( f . func , constructed )
102+ }
103+ } ) . forEach ( dt => {
104+ if ( dt . type != null ) {
105+ const feature = getFeature ( dt . name )
106+ feature . runtimeFunctions . push ( dt . type )
107+ }
108+ } )
72109
73- if (feature) {
74- appendMeta(feature, m);
75- } else {
76- feature = {
77- name: m.name,
78- dataTypes: [],
79- flowTypes: [],
80- runtimeFunctions: [],
81- };
82- appendMeta(feature, m);
83- features.push(feature);
110+ flowTypes . map ( f => {
111+ return {
112+ name : f . feature ,
113+ type : mapFlowType ( f . flow , constructed )
84114 }
85- }
115+ } ) . forEach ( dt => {
116+ if ( dt . type != null ) {
117+ const feature = getFeature ( dt . name )
118+ feature . flowTypes . push ( dt . type )
119+ }
120+ } )
86121
87122 return features ;
88-
89- */
90123}
0 commit comments