-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathparseEntityRelationships.ts
More file actions
126 lines (116 loc) · 3.07 KB
/
parseEntityRelationships.ts
File metadata and controls
126 lines (116 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { FEAST_FCO_TYPES } from "./types";
import { feast } from "../protos";
interface EntityReference {
type: FEAST_FCO_TYPES;
name: string;
}
interface EntityRelation {
source: EntityReference;
target: EntityReference;
}
const parseEntityRelationships = (objects: feast.core.Registry) => {
const links: EntityRelation[] = [];
objects.featureServices?.forEach((fs) => {
fs.spec?.features!.forEach((feature) => {
links.push({
source: {
type: FEAST_FCO_TYPES["featureView"],
name: feature?.featureViewName!,
},
target: {
type: FEAST_FCO_TYPES["featureService"],
name: fs.spec?.name!,
},
});
});
});
objects.featureViews?.forEach((fv) => {
fv.spec?.entities?.forEach((ent) => {
links.push({
source: {
type: FEAST_FCO_TYPES["entity"],
name: ent,
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
});
if (fv.spec?.batchSource) {
links.push({
source: {
type: FEAST_FCO_TYPES["dataSource"],
name: fv.spec.batchSource.name || "",
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
}
});
objects.onDemandFeatureViews?.forEach((fv) => {
Object.values(fv.spec?.sources!).forEach(
(input: { [key: string]: any }) => {
if (input.requestDataSource) {
links.push({
source: {
type: FEAST_FCO_TYPES["dataSource"],
name: input.requestDataSource.name,
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
} else if (input.featureViewProjection?.featureViewName) {
const source_fv = objects.featureViews?.find(
(el) =>
el.spec?.name === input.featureViewProjection.featureViewName,
);
if (!source_fv) {
return;
}
links.push({
source: {
type: FEAST_FCO_TYPES["dataSource"],
name: source_fv.spec?.batchSource?.name || "",
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
}
},
);
});
objects.streamFeatureViews?.forEach((fv) => {
// stream source
links.push({
source: {
type: FEAST_FCO_TYPES["dataSource"],
name: fv.spec?.streamSource?.name!,
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
// batch source
links.push({
source: {
type: FEAST_FCO_TYPES["dataSource"],
name: fv.spec?.batchSource?.name!,
},
target: {
type: FEAST_FCO_TYPES["featureView"],
name: fv.spec?.name!,
},
});
});
return links;
};
export default parseEntityRelationships;
export type { EntityRelation, EntityReference };