[data.search] Move SearchSource to common directory. (#77823)

This commit is contained in:
Luke Elmers 2020-09-18 11:20:42 -06:00 committed by GitHub
parent bf26dffb72
commit 0f493facd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 206 additions and 112 deletions

View file

@ -20,6 +20,6 @@
export * from './aggs';
export * from './es_search';
export * from './expressions';
export * from './search_source';
export * from './tabify';
export * from './types';
export * from './es_search';

View file

@ -19,9 +19,9 @@
import { createSearchSource as createSearchSourceFactory } from './create_search_source';
import { SearchSourceDependencies } from './search_source';
import { IIndexPattern } from '../../../common/index_patterns';
import { IIndexPattern } from '../../index_patterns';
import { IndexPatternsContract } from '../../index_patterns/index_patterns';
import { Filter } from '../../../common/es_query/filters';
import { Filter } from '../../es_query/filters';
import { BehaviorSubject } from 'rxjs';
describe('createSearchSource', () => {

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { SavedObjectReference } from '../../../../../core/types';
import { Filter } from '../../../common/es_query/filters';
import { SavedObjectReference } from 'src/core/types';
import { Filter } from '../../es_query/filters';
import { SearchSourceFields } from './types';
export const extractReferences = (

View file

@ -17,8 +17,9 @@
* under the License.
*/
import { UI_SETTINGS } from '../../../constants';
import { GetConfigFn } from '../../../types';
import { getSearchParams } from './get_search_params';
import { GetConfigFn, UI_SETTINGS } from '../../../common';
function getConfigStub(config: any = {}): GetConfigFn {
return (key) => config[key];

View file

@ -17,7 +17,9 @@
* under the License.
*/
import { UI_SETTINGS, ISearchRequestParams, GetConfigFn } from '../../../common';
import { UI_SETTINGS } from '../../../constants';
import { GetConfigFn } from '../../../types';
import { ISearchRequestParams } from '../../index';
import { SearchRequest } from './types';
const sessionId = Date.now();

View file

@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { getSearchParams, getSearchParamsFromRequest, getPreference } from './get_search_params';
export { RequestFailure } from './request_error';
export * from './types';

View file

@ -18,7 +18,7 @@
*/
import { SearchResponse } from 'elasticsearch';
import { KbnError } from '../../../../kibana_utils/common';
import { KbnError } from '../../../../../kibana_utils/common';
import { SearchError } from './types';
/**

View file

@ -18,8 +18,8 @@
*/
import { SearchResponse } from 'elasticsearch';
import { GetConfigFn } from '../../../common';
import { LegacyFetchHandlers } from '../legacy/types';
import { GetConfigFn } from '../../../types';
/**
* @internal

View file

@ -23,3 +23,5 @@ export { SortDirection, EsQuerySortValue, SearchSourceFields } from './types';
export { injectReferences } from './inject_references';
export { extractReferences } from './extract_references';
export { parseSearchSourceJSON } from './parse_json';
export * from './fetch';
export * from './legacy';

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { SavedObjectReference } from 'src/core/types';
import { SearchSourceFields } from './types';
import { SavedObjectReference } from '../../../../../core/types';
export const injectReferences = (
searchSourceFields: SearchSourceFields & { indexRefName: string },

View file

@ -18,10 +18,9 @@
*/
import { SearchResponse } from 'elasticsearch';
import { ISearchOptions } from 'src/plugins/data/common';
import { FetchHandlers } from '../fetch';
import { FetchHandlers, SearchRequest } from '../fetch';
import { defaultSearchStrategy } from './default_search_strategy';
import { SearchRequest } from '../index';
import { ISearchOptions } from '../../index';
export function callClient(
searchRequests: SearchRequest[],

View file

@ -17,51 +17,50 @@
* under the License.
*/
import { HttpStart } from 'src/core/public';
import { coreMock } from '../../../../../core/public/mocks';
import { getCallMsearch } from './call_msearch';
import { defaultSearchStrategy } from './default_search_strategy';
import { LegacyFetchHandlers, SearchStrategySearchParams } from './types';
import { BehaviorSubject } from 'rxjs';
const { search } = defaultSearchStrategy;
const msearchMock = jest.fn().mockResolvedValue({ body: { responses: [] } });
describe('defaultSearchStrategy', function () {
describe('search', function () {
describe('defaultSearchStrategy', () => {
describe('search', () => {
let searchArgs: MockedKeys<SearchStrategySearchParams>;
let http: jest.Mocked<HttpStart>;
beforeEach(() => {
msearchMock.mockClear();
http = coreMock.createStart().http;
http.post.mockResolvedValue(msearchMock);
searchArgs = {
searchRequests: [
{
index: { title: 'foo' },
body: {},
},
],
getConfig: jest.fn(),
onResponse: (req, res) => res,
legacy: {
callMsearch: getCallMsearch({ http }),
callMsearch: jest.fn().mockResolvedValue(undefined),
loadingCount$: new BehaviorSubject(0) as any,
} as jest.Mocked<LegacyFetchHandlers>,
};
});
test('calls http.post with the correct arguments', async () => {
test('calls callMsearch with the correct arguments', async () => {
await search({ ...searchArgs });
expect(http.post.mock.calls).toMatchInlineSnapshot(`
expect(searchArgs.legacy.callMsearch.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/internal/_msearch",
Object {
"body": "{\\"searches\\":[{\\"header\\":{\\"index\\":\\"foo\\"}}]}",
"body": Object {
"searches": Array [
Object {
"body": Object {},
"header": Object {
"index": "foo",
"preference": undefined,
},
},
],
},
"signal": AbortSignal {},
},
],

View file

@ -17,12 +17,13 @@
* under the License.
*/
import { fetchSoon } from './fetch_soon';
import { callClient } from './call_client';
import { FetchHandlers } from '../fetch/types';
import { SearchRequest } from '../index';
import { SearchResponse } from 'elasticsearch';
import { GetConfigFn, UI_SETTINGS, ISearchOptions } from '../../../common';
import { UI_SETTINGS } from '../../../constants';
import { GetConfigFn } from '../../../types';
import { FetchHandlers, SearchRequest } from '../fetch';
import { ISearchOptions } from '../../index';
import { callClient } from './call_client';
import { fetchSoon } from './fetch_soon';
function getConfigStub(config: any = {}): GetConfigFn {
return (key) => config[key];

View file

@ -18,10 +18,10 @@
*/
import { SearchResponse } from 'elasticsearch';
import { UI_SETTINGS } from '../../../constants';
import { FetchHandlers, SearchRequest } from '../fetch';
import { ISearchOptions } from '../../index';
import { callClient } from './call_client';
import { FetchHandlers } from '../fetch/types';
import { SearchRequest } from '../index';
import { UI_SETTINGS, ISearchOptions } from '../../../common';
/**
* This function introduces a slight delay in the request process to allow multiple requests to queue

View file

@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { fetchSoon } from './fetch_soon';
export * from './types';

View file

@ -19,8 +19,7 @@
import { BehaviorSubject } from 'rxjs';
import { SearchResponse } from 'elasticsearch';
import { FetchHandlers } from '../fetch';
import { SearchRequest } from '..';
import { FetchHandlers, SearchRequest } from '../fetch';
// @internal
export interface LegacyFetchHandlers {

View file

@ -18,7 +18,7 @@
*/
import { has } from 'lodash';
import { Query } from 'src/plugins/data/public';
import { Query } from '../../query/types';
/**
* Creates a standardized query object from old queries that were either strings or pure ES query DSL

View file

@ -19,7 +19,7 @@
import { normalizeSortRequest } from './normalize_sort_request';
import { SortDirection } from './types';
import { IIndexPattern } from '../..';
import { IIndexPattern } from '../../index_patterns';
describe('SearchSource#normalizeSortRequest', function () {
const scriptedField = {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { IIndexPattern } from '../..';
import { IIndexPattern } from '../../index_patterns';
import { EsQuerySortValue, SortOptions } from './types';
export function normalizeSortRequest(

View file

@ -18,12 +18,12 @@
*/
import { Observable, BehaviorSubject } from 'rxjs';
import { GetConfigFn } from 'src/plugins/data/common';
import { SearchSource, SearchSourceDependencies } from './search_source';
import { IndexPattern, SortDirection } from '../..';
import { fetchSoon } from '../legacy';
import { IndexPattern } from '../../index_patterns';
import { GetConfigFn } from '../../types';
import { fetchSoon } from './legacy';
import { SearchSource, SearchSourceDependencies, SortDirection } from './';
jest.mock('../legacy', () => ({
jest.mock('./legacy', () => ({
fetchSoon: jest.fn().mockResolvedValue({}),
}));

View file

@ -75,9 +75,10 @@ import { map } from 'rxjs/operators';
import { normalizeSortRequest } from './normalize_sort_request';
import { filterDocvalueFields } from './filter_docvalue_fields';
import { fieldWildcardFilter } from '../../../../kibana_utils/common';
import { IIndexPattern, ISearchGeneric } from '../..';
import { IIndexPattern } from '../../index_patterns';
import { ISearchGeneric } from '../..';
import { SearchSourceOptions, SearchSourceFields } from './types';
import { FetchHandlers, RequestFailure, getSearchParamsFromRequest, SearchRequest } from '../fetch';
import { FetchHandlers, RequestFailure, getSearchParamsFromRequest, SearchRequest } from './fetch';
import {
getEsQueryConfig,
@ -87,7 +88,7 @@ import {
ISearchOptions,
} from '../../../common';
import { getHighlightRequest } from '../../../common/field_formats';
import { fetchSoon } from '../legacy';
import { fetchSoon } from './legacy';
import { extractReferences } from './extract_references';
/** @internal */

View file

@ -17,6 +17,22 @@
* under the License.
*/
import { Observable } from 'rxjs';
import { IEsSearchRequest, IEsSearchResponse, ISearchOptions } from '../../common/search';
export type ISearch = (
request: IKibanaSearchRequest,
options?: ISearchOptions
) => Observable<IKibanaSearchResponse>;
export type ISearchGeneric = <
SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest,
SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse
>(
request: SearchStrategyRequest,
options?: ISearchOptions
) => Observable<SearchStrategyResponse>;
export interface IKibanaSearchResponse {
/**
* Some responses may contain a unique id to identify the request this response came from.

View file

@ -64,6 +64,7 @@ import { Required } from '@kbn/utility-types';
import * as Rx from 'rxjs';
import { SavedObject } from 'src/core/server';
import { SavedObject as SavedObject_3 } from 'src/core/public';
import { SavedObjectReference as SavedObjectReference_2 } from 'src/core/types';
import { SavedObjectsClientContract } from 'src/core/public';
import { Search } from '@elastic/elasticsearch/api/requestParams';
import { SearchResponse } from 'elasticsearch';
@ -651,13 +652,12 @@ export type ExistsFilter = Filter & {
// @public (undocumented)
export const expandShorthand: (sh: Record<string, ShorthandFieldMapObject>) => MappingObject;
// Warning: (ae-forgotten-export) The symbol "SavedObjectReference" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "extractReferences" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const extractSearchSourceReferences: (state: SearchSourceFields) => [SearchSourceFields & {
indexRefName?: string;
}, SavedObjectReference[]];
}, SavedObjectReference_2[]];
// Warning: (ae-missing-release-tag) "FieldFormat" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -1371,7 +1371,7 @@ export interface IndexPatternTypeMeta {
// @public (undocumented)
export const injectSearchSourceReferences: (searchSourceFields: SearchSourceFields & {
indexRefName: string;
}, references: SavedObjectReference[]) => SearchSourceFields;
}, references: SavedObjectReference_2[]) => SearchSourceFields;
// Warning: (ae-missing-release-tag) "InputTimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//

View file

@ -38,6 +38,7 @@ import {
getRequestInspectorStats,
getResponseInspectorStats,
IAggConfigs,
ISearchSource,
tabifyAggResponse,
} from '../../../common/search';
@ -48,7 +49,6 @@ import {
getQueryService,
getSearchService,
} from '../../services';
import { ISearchSource } from '../search_source';
import { buildTabularInspectorData } from './build_tabular_inspector_data';
import { serializeAggConfig } from './utils';

View file

@ -17,8 +17,4 @@
* under the License.
*/
export * from './types';
export { getSearchParams, getSearchParamsFromRequest, getPreference } from './get_search_params';
export { RequestFailure } from './request_error';
export { handleResponse } from './handle_response';

View file

@ -19,34 +19,31 @@
export * from './expressions';
export { ISearchSetup, ISearchStart, ISearchStartSearchSource, SearchEnhancements } from './types';
export {
ES_SEARCH_STRATEGY,
EsQuerySortValue,
extractReferences as extractSearchSourceReferences,
getSearchParamsFromRequest,
IEsSearchRequest,
IEsSearchResponse,
IKibanaSearchRequest,
IKibanaSearchResponse,
injectReferences as injectSearchSourceReferences,
ISearch,
ISearchGeneric,
ISearchSetup,
ISearchStart,
ISearchStartSearchSource,
SearchEnhancements,
} from './types';
export { IEsSearchResponse, IEsSearchRequest, ES_SEARCH_STRATEGY } from '../../common/search';
export { getEsPreference } from './es_search';
export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search';
export { SearchError, getSearchParamsFromRequest, SearchRequest } from './fetch';
export {
ISearchSource,
parseSearchSourceJSON,
SearchError,
SearchRequest,
SearchSource,
SearchSourceDependencies,
SearchSourceFields,
EsQuerySortValue,
SortDirection,
extractReferences as extractSearchSourceReferences,
injectReferences as injectSearchSourceReferences,
parseSearchSourceJSON,
} from './search_source';
} from '../../common/search';
export { getEsPreference } from './es_search';
export { SearchInterceptor, SearchInterceptorDeps } from './search_interceptor';
export { RequestTimeoutError } from './request_timeout_error';

View file

@ -0,0 +1,54 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { HttpStart } from 'src/core/public';
import { coreMock } from '../../../../../core/public/mocks';
import { getCallMsearch } from './call_msearch';
describe('callMsearch', () => {
const msearchMock = jest.fn().mockResolvedValue({ body: { responses: [] } });
let http: jest.Mocked<HttpStart>;
beforeEach(() => {
msearchMock.mockClear();
http = coreMock.createStart().http;
http.post.mockResolvedValue(msearchMock);
});
test('calls http.post with the correct arguments', async () => {
const searches = [{ header: { index: 'foo' }, body: {} }];
const callMsearch = getCallMsearch({ http });
await callMsearch({
body: { searches },
signal: new AbortController().signal,
});
expect(http.post.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/internal/_msearch",
Object {
"body": "{\\"searches\\":[{\\"header\\":{\\"index\\":\\"foo\\"},\\"body\\":{}}]}",
"signal": AbortSignal {},
},
],
]
`);
});
});

View file

@ -18,7 +18,7 @@
*/
import { HttpStart } from 'src/core/public';
import { LegacyFetchHandlers } from './types';
import { LegacyFetchHandlers } from '../../../common/search/search_source';
/**
* Wrapper for calling the internal msearch endpoint from the client.

View file

@ -17,4 +17,4 @@
* under the License.
*/
export { fetchSoon } from './fetch_soon';
export * from './call_msearch';

View file

@ -19,9 +19,9 @@
import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks';
import { ISearchSetup, ISearchStart } from './types';
import { searchSourceMock, createSearchSourceMock } from './search_source/mocks';
import { searchSourceMock, createSearchSourceMock } from '../../common/search/search_source/mocks';
export * from './search_source/mocks';
export * from '../../common/search/search_source/mocks';
function createSetupContract(): jest.Mocked<ISearchSetup> {
return {

View file

@ -22,12 +22,16 @@ import { BehaviorSubject } from 'rxjs';
import { ISearchSetup, ISearchStart, SearchEnhancements } from './types';
import { handleResponse } from './fetch';
import { getCallMsearch } from './legacy/call_msearch';
import { createSearchSource, SearchSource, SearchSourceDependencies } from './search_source';
import {
createSearchSource,
ISearchGeneric,
SearchSource,
SearchSourceDependencies,
} from '../../common/search';
import { getCallMsearch } from './legacy';
import { AggsService, AggsStartDependencies } from './aggs';
import { IndexPatternsContract } from '../index_patterns/index_patterns';
import { ISearchInterceptor, SearchInterceptor } from './search_interceptor';
import { ISearchGeneric } from './types';
import { SearchUsageCollector, createUsageCollector } from './collectors';
import { UsageCollectionSetup } from '../../../usage_collection/public';
import { esdsl, esRawResponse } from './expressions';

View file

@ -17,38 +17,18 @@
* under the License.
*/
import { Observable } from 'rxjs';
import { PackageInfo } from 'kibana/server';
import { ISearchInterceptor } from './search_interceptor';
import { ISearchSource, SearchSourceFields } from './search_source';
import { SearchUsageCollector } from './collectors';
import { AggsSetup, AggsSetupDependencies, AggsStartDependencies, AggsStart } from './aggs';
import {
IKibanaSearchRequest,
IKibanaSearchResponse,
IEsSearchRequest,
IEsSearchResponse,
ISearchOptions,
} from '../../common/search';
import { ISearchGeneric, ISearchSource, SearchSourceFields } from '../../common/search';
import { IndexPatternsContract } from '../../common/index_patterns/index_patterns';
import { UsageCollectionSetup } from '../../../usage_collection/public';
export type ISearch = (
request: IKibanaSearchRequest,
options?: ISearchOptions
) => Observable<IKibanaSearchResponse>;
export type ISearchGeneric = <
SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest,
SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse
>(
request: SearchStrategyRequest,
options?: ISearchOptions
) => Observable<SearchStrategyResponse>;
export interface SearchEnhancements {
searchInterceptor: ISearchInterceptor;
}
/**
* The setup contract exposed by the Search plugin exposes the search strategy extension
* point.

View file

@ -35,7 +35,7 @@ jest.mock('./services', () => {
// eslint-disable-next-line
const { BaseVisType } = require('./vis_types/base_vis_type');
// eslint-disable-next-line
const { SearchSource } = require('../../data/public/search/search_source');
const { SearchSource } = require('../../data/common/search/search_source');
// eslint-disable-next-line
const fixturesStubbedLogstashIndexPatternProvider = require('../../../fixtures/stubbed_logstash_index_pattern');
const visType = new BaseVisType({

View file

@ -15,7 +15,7 @@ import {
RENDER_AS,
SOURCE_TYPES,
} from '../../../../common/constants';
import { SearchSource } from '../../../../../../../src/plugins/data/public/search/search_source';
import { SearchSource } from 'src/plugins/data/public';
export class MockSearchSource {
setField = jest.fn();

View file

@ -9,7 +9,7 @@ jest.mock('../../../kibana_services');
jest.mock('./load_index_settings');
import { getIndexPatternService, getSearchService, getHttp } from '../../../kibana_services';
import { SearchSource } from '../../../../../../../src/plugins/data/public/search/search_source';
import { SearchSource } from 'src/plugins/data/public';
// @ts-expect-error
import { loadIndexSettings } from './load_index_settings';