Skip to content

Commit 4836d31

Browse files
committed
feat: added correct feature export
1 parent 34a7c46 commit 4836d31

File tree

5 files changed

+96
-60
lines changed

5 files changed

+96
-60
lines changed

reader/ts/src/mapper/helper.ts renamed to reader/ts/src/mapper/dataTypeMapper.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "@code0-tech/tucana/pb/shared.data_type_pb.ts"
1616
import {GenericMapper as TucanaGenericMapper} from "@code0-tech/tucana/pb/shared.data_type_pb.ts"
1717
import {ConstructedDataTypes} from "../parser.js";
18+
import {getTranslationConnection} from "./translation.js";
1819

1920
export enum GenericMapper_GenericCombinationStrategy {
2021
UNKNOWN = 0,
@@ -53,9 +54,7 @@ function getDataType(identifier: string, constructedDataTypes: ConstructedDataTy
5354
if (dataType == undefined) {
5455
const tucanaDataType = constructedDataTypes.scannedTucanaTypes.find(dt => dt.identifier === identifier)
5556
if (tucanaDataType == undefined) {
56-
console.dir(constructedDataTypes, {depth: null})
57-
console.log("just skipping identifier")
58-
console.log(identifier)
57+
console.error("Skipping Identifier because it can't be identified:" + identifier)
5958
return null
6059
}
6160
const constructed = {
@@ -252,11 +251,4 @@ function getDataTypeIdentifier(identifier: TucanaDataTypeIdentifier | undefined,
252251
return null;
253252
}
254253

255-
function getTranslationConnection(translation: Translation[]): TranslationConnection {
256-
return {
257-
count: translation.length,
258-
nodes: translation,
259-
}
260-
}
261-
262-
export {getDataType, getDataTypeIdentifier, getTranslationConnection}
254+
export {getDataType, getDataTypeIdentifier}

reader/ts/src/mapper/flowTypeMapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {FlowType as TucanaFlowType, FlowTypeSetting as TucanaFlowTypeSetting} from "@code0-tech/tucana/pb/shared.flow_definition_pb.ts"
22
import {FlowType, FlowTypeSetting} from "@code0-tech/sagittarius-graphql-types";
3-
import {getDataType, getTranslationConnection} from "./helper.ts";
3+
import {getDataType} from "./dataTypeMapper.ts";
44
import {ConstructedDataTypes} from "../parser.ts";
5+
import {getTranslationConnection} from "./translation.js";
56

67
function mapFlowType(flowType: TucanaFlowType, constructed: ConstructedDataTypes): FlowType | null {
78
return {

reader/ts/src/mapper/functionMapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
RuntimeFunctionDefinition as TucanaFunction,
44
RuntimeParameterDefinition
55
} from "@code0-tech/tucana/pb/shared.runtime_function_pb.ts";
6-
import {getDataTypeIdentifier, getTranslationConnection} from "./helper.ts";
6+
import {getDataTypeIdentifier} from "./dataTypeMapper.ts";
77
import {ConstructedDataTypes} from "../parser.ts";
8+
import {getTranslationConnection} from "./translation.js";
89

910
function mapFunction(func: TucanaFunction, constructed: ConstructedDataTypes): FunctionDefinition | null {
1011
return {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Translation} from "@code0-tech/tucana/pb/shared.translation_pb.js";
2+
import {TranslationConnection} from "@code0-tech/sagittarius-graphql-types";
3+
4+
export function getTranslationConnection(translation: Translation[]): TranslationConnection {
5+
return {
6+
count: translation.length,
7+
nodes: translation,
8+
}
9+
}

reader/ts/src/parser.ts

Lines changed: 80 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,118 @@ import {RuntimeFunctionDefinition as TucanaFunction} from "@code0-tech/tucana/pb
66
import path from "node:path";
77
import {mapFlowType} from "./mapper/flowTypeMapper.ts";
88
import {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";
1010
import {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

1313
export 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

Comments
 (0)