Skip to content

Commit 2ef0ded

Browse files
committed
Fix types for performance advisor api response
1 parent a4cbc8b commit 2ef0ded

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/common/atlas/performanceAdvisorUtils.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ interface SuggestedIndex {
1818
weight?: number;
1919
}
2020

21+
interface SuggestedIndexesResponse {
22+
content: {
23+
suggestedIndexes?: SuggestedIndex[];
24+
};
25+
}
26+
27+
interface DropIndexesResponse {
28+
content: {
29+
hiddenIndexes?: DropIndexSuggestion[];
30+
redundantIndexes?: DropIndexSuggestion[];
31+
unusedIndexes?: DropIndexSuggestion[];
32+
};
33+
}
34+
35+
interface SchemaAdviceResponse {
36+
content: {
37+
recommendations?: SchemaRecommendation[];
38+
};
39+
}
40+
41+
interface SlowQueriesResponse {
42+
slowQueries?: SlowQueryLog[];
43+
}
44+
2145
interface DropIndexSuggestion {
2246
accessCount?: number;
2347
index?: Array<{ [key: string]: 1 | -1 }>;
@@ -105,7 +129,9 @@ export async function getSuggestedIndexes(
105129
},
106130
},
107131
});
108-
return { suggestedIndexes: response?.content?.suggestedIndexes ?? [] };
132+
return {
133+
suggestedIndexes: (response as SuggestedIndexesResponse).content.suggestedIndexes ?? [],
134+
};
109135
} catch (err) {
110136
apiClient.logger.debug({
111137
id: LogId.atlasPaSuggestedIndexesFailure,
@@ -135,9 +161,9 @@ export async function getDropIndexSuggestions(
135161
},
136162
});
137163
return {
138-
hiddenIndexes: response?.content?.hiddenIndexes ?? [],
139-
redundantIndexes: response?.content?.redundantIndexes ?? [],
140-
unusedIndexes: response?.content?.unusedIndexes ?? [],
164+
hiddenIndexes: (response as DropIndexesResponse).content.hiddenIndexes ?? [],
165+
redundantIndexes: (response as DropIndexesResponse).content.redundantIndexes ?? [],
166+
unusedIndexes: (response as DropIndexesResponse).content.unusedIndexes ?? [],
141167
};
142168
} catch (err) {
143169
apiClient.logger.debug({
@@ -163,7 +189,7 @@ export async function getSchemaAdvice(
163189
},
164190
},
165191
});
166-
return { recommendations: response?.content?.recommendations ?? [] };
192+
return { recommendations: (response as SchemaAdviceResponse).content.recommendations ?? [] };
167193
} catch (err) {
168194
apiClient.logger.debug({
169195
id: LogId.atlasPaSchemaAdviceFailure,
@@ -202,7 +228,7 @@ export async function getSlowQueries(
202228
},
203229
});
204230

205-
return { slowQueryLogs: response?.slowQueries ?? [] };
231+
return { slowQueryLogs: (response as SlowQueriesResponse).slowQueries ?? [] };
206232
} catch (err) {
207233
apiClient.logger.debug({
208234
id: LogId.atlasPaSlowQueryLogsFailure,

0 commit comments

Comments
 (0)