-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuseLoadRegistry.ts
More file actions
71 lines (62 loc) · 2 KB
/
useLoadRegistry.ts
File metadata and controls
71 lines (62 loc) · 2 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
import { useQuery } from "react-query";
import mergedFVTypes, { genericFVType } from "../parsers/mergedFVTypes";
import parseEntityRelationships, {
EntityRelation,
} from "../parsers/parseEntityRelationships";
import parseIndirectRelationships from "../parsers/parseIndirectRelationships";
import { feast } from "../protos";
interface FeatureStoreAllData {
project: string;
description?: string;
objects: feast.core.Registry;
relationships: EntityRelation[];
mergedFVMap: Record<string, genericFVType>;
mergedFVList: genericFVType[];
indirectRelationships: EntityRelation[];
}
const useLoadRegistry = (url: string) => {
return useQuery(
`registry:${url}`,
() => {
return fetch(url, {
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.arrayBuffer();
})
.then<FeatureStoreAllData>((arrayBuffer) => {
const objects = feast.core.Registry.decode(new Uint8Array(arrayBuffer));
// const objects = FeastRegistrySchema.parse(json);
const { mergedFVMap, mergedFVList } = mergedFVTypes(objects);
const relationships = parseEntityRelationships(objects);
// Only contains Entity -> FS or DS -> FS relationships
const indirectRelationships = parseIndirectRelationships(
relationships,
objects
);
// console.log({
// objects,
// mergedFVMap,
// mergedFVList,
// relationships,
// indirectRelationships,
// });
return {
project: objects.projects[0].spec?.name!,
objects,
mergedFVMap,
mergedFVList,
relationships,
indirectRelationships,
};
});
},
{
staleTime: Infinity, // Given that we are reading from a registry dump, this seems reasonable for now.
}
);
};
export default useLoadRegistry;
export type { FeatureStoreAllData };