11import { readdir , readFile } from "node:fs/promises" ;
22import { join , extname } from "node:path" ;
3-
4- import { FlowType } from "@code0-tech/tucana/pb/shared.flow_definition_pb.js" ;
5- import { RuntimeFunctionDefinition } from "@code0-tech/tucana/pb/shared.runtime_function_pb.js" ;
6- import { DefinitionDataType } from "@code0-tech/tucana/pb/shared.data_type_pb.js" ;
3+ import { DefinitionDataType , FlowType , FunctionDefinition , RuntimeFunctionDefinition } from "@code0-tech/tucana/shared" ;
74
85export const enum MetaType {
96 FlowType = "FlowType" ,
107 DataType = "DataType" ,
118 RuntimeFunction = "RuntimeFunction" ,
9+ Function = "Function"
1210}
1311
1412export interface DefinitionError {
@@ -22,6 +20,7 @@ export interface Feature {
2220 data_types : DefinitionDataType [ ] ;
2321 flow_types : FlowType [ ] ;
2422 runtime_functions : RuntimeFunctionDefinition [ ] ;
23+ functions : FunctionDefinition [ ] ;
2524 errors : DefinitionError [ ] ;
2625}
2726
@@ -58,14 +57,16 @@ const toMetaType = (folder: string): MetaType | null =>
5857 ( {
5958 flow_type : MetaType . FlowType ,
6059 data_type : MetaType . DataType ,
61- runtime_definition : MetaType . RuntimeFunction
60+ runtime_definition : MetaType . RuntimeFunction ,
61+ function : MetaType . Function ,
6262 } as const ) [ folder ] ?? null ;
6363
6464const emptyFeature = ( name : string ) : Feature => ( {
6565 name,
6666 data_types : [ ] ,
6767 flow_types : [ ] ,
6868 runtime_functions : [ ] ,
69+ functions : [ ] ,
6970 errors : [ ] ,
7071} ) ;
7172
@@ -93,9 +94,22 @@ const collectJsonFiles = async (dir: string): Promise<string[]> => {
9394
9495const addDefinition = ( feature : Feature , def : string , type : MetaType ) => {
9596 try {
96- if ( type === MetaType . DataType ) feature . data_types . push ( DefinitionDataType . fromJsonString ( def ) ) ;
97- else if ( type === MetaType . FlowType ) feature . flow_types . push ( FlowType . fromJsonString ( def ) ) ;
98- else feature . runtime_functions . push ( RuntimeFunctionDefinition . fromJsonString ( def ) ) ;
97+ switch ( type ) {
98+ case MetaType . DataType :
99+ feature . data_types . push ( DefinitionDataType . fromJsonString ( def ) ) ;
100+ break
101+ case MetaType . FlowType :
102+ feature . flow_types . push ( FlowType . fromJsonString ( def ) ) ;
103+ break
104+ case MetaType . RuntimeFunction :
105+ feature . runtime_functions . push ( RuntimeFunctionDefinition . fromJsonString ( def ) ) ;
106+ break
107+ case MetaType . Function :
108+ feature . functions . push ( FunctionDefinition . fromJsonString ( def ) ) ;
109+ break
110+ default :
111+ throw new Error ( `Unknown MetaType: ${ type } ` ) ;
112+ }
99113 } catch ( err ) {
100114 feature . errors . push ( {
101115 definition : extractIdentifier ( def , type ) ,
0 commit comments