Skip to content

Commit 61494e2

Browse files
authored
fix(types): log type (#1139)
1 parent 703b445 commit 61494e2

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

packages/client-common/src/__tests__/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ import { WaitablePromise } from '..';
33
export function waitResponses(responses: Array<Readonly<WaitablePromise<any>>>) {
44
return Promise.all(responses.map(response => response.wait()));
55
}
6+
7+
export type KeysOfType<TType, TRequiredType> = {
8+
[TKey in keyof TType]: TType[TKey] extends TRequiredType ? TKey : never;
9+
}[keyof TType];
10+
export type RequiredKeys<TType> = Exclude<
11+
KeysOfType<TType, Exclude<TType[keyof TType], undefined>>,
12+
undefined
13+
>;

packages/client-search/src/__tests__/integration/get-logs.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Log } from '../..';
2+
import { RequiredKeys } from '../../../../client-common/src/__tests__/helpers';
13
import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite';
24

35
const testSuite = new TestSuite('get_logs');
@@ -15,5 +17,18 @@ test(testSuite.testName, async () => {
1517
type: 'all',
1618
});
1719

18-
await expect(getLogsResponse.logs).toHaveLength(2);
20+
expect(getLogsResponse.logs).toHaveLength(2);
21+
const keys: Array<RequiredKeys<Log>> = [
22+
'timestamp',
23+
'method',
24+
'answer_code',
25+
'query_body',
26+
'answer',
27+
'url',
28+
'ip',
29+
'sha1',
30+
'query_headers',
31+
'processing_time_ms',
32+
];
33+
expect(Object.keys(getLogsResponse.logs[0])).toEqual(expect.arrayContaining(keys));
1934
});

packages/client-search/src/types/Log.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type Log = {
22
/**
33
* Timestamp in ISO-8601 format.
44
*/
5-
readonly timeStamp: string;
5+
readonly timestamp: string;
66

77
/**
88
* Rest type of the method.
@@ -12,12 +12,12 @@ export type Log = {
1212
/**
1313
* Http response code.
1414
*/
15-
readonly answerCode: string;
15+
readonly answer_code: string;
1616

1717
/**
1818
* Request body. It’s truncated after 1000 characters.
1919
*/
20-
readonly queryBody: string;
20+
readonly query_body: string;
2121

2222
/**
2323
* Answer body. It’s truncated after 1000 characters.
@@ -42,22 +42,22 @@ export type Log = {
4242
/**
4343
* Request Headers (API Key is obfuscated).
4444
*/
45-
readonly queryHeaders: string;
45+
readonly query_headers: string;
4646

4747
/**
4848
* Number Of Api Calls
4949
*/
50-
readonly numberOfApiCalls: string;
50+
readonly nb_api_calls?: string;
5151

5252
/**
5353
* Processing time for the query. This does not include network time.
5454
*/
55-
readonly processingTimeMS: string;
55+
readonly processing_time_ms: string;
5656

5757
/**
5858
* Number of hits returned for the query.
5959
*/
60-
readonly numberOfQueryHits: string;
60+
readonly query_nb_hits?: string;
6161

6262
/**
6363
* Exhaustive flags used during the query.
@@ -67,5 +67,5 @@ export type Log = {
6767
/**
6868
* Index name of the log
6969
*/
70-
readonly index: string;
70+
readonly index?: string;
7171
};

0 commit comments

Comments
 (0)