Skip to content

Commit

Permalink
[Discover] resolve type error in test
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaanj committed May 21, 2021
1 parent 6388555 commit 720b613
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ import { getEsQuerySort } from './utils/get_es_query_sort';
import { getServices } from '../../../../kibana_services';

export type SurrDocType = 'successors' | 'predecessors';
export type EsHitRecord = Required<estypes.SearchResponse['hits']['hits'][number]> & {
sort: Array<number | string>;
_source: Record<string, string | number>;
export type EsHitRecord = Required<
Pick<
estypes.SearchResponse['hits']['hits'][number],
'_id' | 'fields' | 'sort' | '_index' | '_version'
>
> & {
_source?: Record<string, unknown>;
_score?: number;
isAnchor?: boolean;
};

export type EsHitRecordList = EsHitRecord[];

const DAY_MILLIS = 24 * 60 * 60 * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ export function getEsQuerySearchAfter(
// already surrounding docs -> first or last record is used
const afterTimeRecIdx = type === 'successors' && documents.length ? documents.length - 1 : 0;
const afterTimeDoc = documents[afterTimeRecIdx];
let afterTimeValue = afterTimeDoc.sort[0];
let afterTimeValue = afterTimeDoc.sort[0] as string | number;
if (nanoSeconds) {
afterTimeValue = useNewFieldsApi
? afterTimeDoc.fields[timeFieldName][0]
: afterTimeDoc._source[timeFieldName];
: afterTimeDoc._source?.[timeFieldName];
}
return [afterTimeValue, afterTimeDoc.sort[1]];
return [afterTimeValue, afterTimeDoc.sort[1] as string | number];
}
// if data_nanos adapt timestamp value for sorting, since numeric value was rounded by browser
// ES search_after also works when number is provided as string
const searchAfter = new Array(2) as EsQuerySearchAfter;
searchAfter[0] = anchor.sort[0];
searchAfter[0] = anchor.sort[0] as string | number;
if (nanoSeconds) {
searchAfter[0] = useNewFieldsApi
? anchor.fields[timeFieldName][0]
: anchor._source[timeFieldName];
: anchor._source?.[timeFieldName];
}
searchAfter[1] = anchor.sort[1];
searchAfter[1] = anchor.sort[1] as string | number;
return searchAfter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getQueryParameterActions } from './actions';
import { FilterManager, SortDirection } from '../../../../../../data/public';
import { coreMock } from '../../../../../../../core/public/mocks';
import { ContextAppState, LoadingStatus, QueryParameters } from '../../context_app_state';
import { EsHitRecord } from '../api/context';
const setupMock = coreMock.createSetup();

let state: ContextAppState;
Expand Down Expand Up @@ -39,7 +40,7 @@ beforeEach(() => {
},
rows: {
all: [],
anchor: { isAnchor: true, fields: [], sort: [], _source: [], _id: '' },
anchor: ({ isAnchor: true, fields: [], sort: [], _id: '' } as unknown) as EsHitRecord,
predecessors: [],
successors: [],
},
Expand Down

0 comments on commit 720b613

Please sign in to comment.