Skip to content

Commit

Permalink
Replace FetchOptions with ISearchOptions (elastic#76538)
Browse files Browse the repository at this point in the history
* Replace FetchOptions with ISearchOptions and update usage

* Merge the client and server ISearchOption types into common

* docs
  • Loading branch information
lizozom authored and Liza K committed Sep 3, 2020
1 parent 148459f commit 6166e07
Show file tree
Hide file tree
Showing 43 changed files with 117 additions and 169 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) &gt; [abortSignal](./kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md)

## ISearchOptions.abortSignal property

An `AbortSignal` that allows the caller of `search` to abort a search request.

<b>Signature:</b>

```typescript
abortSignal?: AbortSignal;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export interface ISearchOptions

| Property | Type | Description |
| --- | --- | --- |
| [signal](./kibana-plugin-plugins-data-public.isearchoptions.signal.md) | <code>AbortSignal</code> | |
| [strategy](./kibana-plugin-plugins-data-public.isearchoptions.strategy.md) | <code>string</code> | |
| [abortSignal](./kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md) | <code>AbortSignal</code> | An <code>AbortSignal</code> that allows the caller of <code>search</code> to abort a search request. |
| [strategy](./kibana-plugin-plugins-data-public.isearchoptions.strategy.md) | <code>string</code> | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ISearchOptions.strategy property

Use this option to force using a specific server side search strategy. Leave empty to use the default strategy.

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
| [DataPublicPluginSetup](./kibana-plugin-plugins-data-public.datapublicpluginsetup.md) | |
| [DataPublicPluginStart](./kibana-plugin-plugins-data-public.datapublicpluginstart.md) | |
| [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | |
| [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | |
| [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) | |
| [Filter](./kibana-plugin-plugins-data-public.filter.md) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) &gt; [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) &gt; [abortSignal](./kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md)

## ISearchOptions.signal property
## ISearchOptions.abortSignal property

An `AbortSignal` that allows the caller of `search` to abort a search request.

<b>Signature:</b>

```typescript
signal?: AbortSignal;
abortSignal?: AbortSignal;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export interface ISearchOptions

| Property | Type | Description |
| --- | --- | --- |
| [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) | <code>AbortSignal</code> | An <code>AbortSignal</code> that allows the caller of <code>search</code> to abort a search request. |
| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | <code>string</code> | |
| [abortSignal](./kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md) | <code>AbortSignal</code> | An <code>AbortSignal</code> that allows the caller of <code>search</code> to abort a search request. |
| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | <code>string</code> | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ISearchOptions.strategy property

Use this option to force using a specific server side search strategy. Leave empty to use the default strategy.

<b>Signature:</b>

```typescript
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { Assign, Ensure } from '@kbn/utility-types';

import { FetchOptions, ISearchSource } from 'src/plugins/data/public';
import { ISearchSource } from 'src/plugins/data/public';
import {
ExpressionAstFunction,
ExpressionAstArgument,
SerializedFieldFormat,
} from 'src/plugins/expressions/common';
import { ISearchOptions } from '../es_search';

import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
Expand Down Expand Up @@ -213,11 +214,11 @@ export class AggConfig {

/**
* Hook for pre-flight logic, see AggType#onSearchRequestStart
* @param {Courier.SearchSource} searchSource
* @param {Courier.FetchOptions} options
* @param {SearchSource} searchSource
* @param {ISearchOptions} options
* @return {Promise<undefined>}
*/
onSearchRequestStart(searchSource: ISearchSource, options?: FetchOptions) {
onSearchRequestStart(searchSource: ISearchSource, options?: ISearchOptions) {
if (!this.type) {
return Promise.resolve();
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import _ from 'lodash';
import { Assign } from '@kbn/utility-types';

import { FetchOptions, ISearchSource } from 'src/plugins/data/public';
import { ISearchOptions, ISearchSource } from 'src/plugins/data/public';
import { AggConfig, AggConfigSerialized, IAggConfig } from './agg_config';
import { IAggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
Expand Down Expand Up @@ -300,7 +300,7 @@ export class AggConfigs {
return _.find(reqAgg.getResponseAggs(), { id });
}

onSearchRequestStart(searchSource: ISearchSource, options?: FetchOptions) {
onSearchRequestStart(searchSource: ISearchSource, options?: ISearchOptions) {
return Promise.all(
// @ts-ignore
this.getRequestAggs().map((agg: AggConfig) => agg.onSearchRequestStart(searchSource, options))
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/aggs/param_types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { FetchOptions, ISearchSource } from 'src/plugins/data/public';
import { ISearchOptions, ISearchSource } from 'src/plugins/data/public';
import { ExpressionAstFunction } from 'src/plugins/expressions/common';
import { IAggConfigs } from '../agg_configs';
import { IAggConfig } from '../agg_config';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class BaseParamType<TAggConfig extends IAggConfig = IAggConfig> {
modifyAggConfigOnSearchRequestStart: (
aggConfig: TAggConfig,
searchSource?: ISearchSource,
options?: FetchOptions
options?: ISearchOptions
) => void;

constructor(config: Record<string, any>) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/es_search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export {
IEsSearchRequest,
IEsSearchResponse,
ES_SEARCH_STRATEGY,
ISearchOptions,
} from './types';
11 changes: 11 additions & 0 deletions src/plugins/data/common/search/es_search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ import { IKibanaSearchRequest, IKibanaSearchResponse } from '../types';

export const ES_SEARCH_STRATEGY = 'es';

export interface ISearchOptions {
/**
* An `AbortSignal` that allows the caller of `search` to abort a search request.
*/
abortSignal?: AbortSignal;
/**
* Use this option to force using a specific server side search strategy. Leave empty to use the default strategy.
*/
strategy?: string;
}

export type ISearchRequestParams<T = Record<string, any>> = {
trackTotalHits?: boolean;
} & Search<T>;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export {
IEsSearchResponse,
ES_SEARCH_STRATEGY,
ISearchRequestParams,
ISearchOptions,
} from './es_search';
4 changes: 2 additions & 2 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ export {
ES_SEARCH_STRATEGY,
EsQuerySortValue,
extractSearchSourceReferences,
FetchOptions,
getEsPreference,
getSearchParamsFromRequest,
IEsSearchRequest,
Expand All @@ -352,7 +351,6 @@ export {
injectSearchSourceReferences,
ISearch,
ISearchGeneric,
ISearchOptions,
ISearchSource,
parseSearchSourceJSON,
RequestTimeoutError,
Expand All @@ -367,6 +365,8 @@ export {
EsRawResponseExpressionTypeDefinition,
} from './search';

export { ISearchOptions } from '../common';

// Search namespace
export const search = {
aggs: {
Expand Down
16 changes: 2 additions & 14 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { EuiGlobalToastListToast } from '@elastic/eui';
import { ExclusiveUnion } from '@elastic/eui';
import { ExpressionAstFunction } from 'src/plugins/expressions/common';
import { ExpressionsSetup } from 'src/plugins/expressions/public';
import { FetchOptions as FetchOptions_2 } from 'src/plugins/data/public';
import { History } from 'history';
import { Href } from 'history';
import { IconType } from '@elastic/eui';
import { InjectedIntl } from '@kbn/i18n/react';
import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public';
import { ISearchSource as ISearchSource_2 } from 'src/plugins/data/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { IUiSettingsClient } from 'src/core/public';
Expand Down Expand Up @@ -486,16 +486,6 @@ export const extractSearchSourceReferences: (state: SearchSourceFields) => [Sear
indexRefName?: string;
}, SavedObjectReference[]];

// Warning: (ae-missing-release-tag) "FetchOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface FetchOptions {
// (undocumented)
abortSignal?: AbortSignal;
// (undocumented)
searchStrategyId?: string;
}

// Warning: (ae-missing-release-tag) "FieldFormat" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1245,9 +1235,7 @@ export type ISearchGeneric = <SearchStrategyRequest extends IEsSearchRequest = I
//
// @public (undocumented)
export interface ISearchOptions {
// (undocumented)
signal?: AbortSignal;
// (undocumented)
abortSignal?: AbortSignal;
strategy?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/expressions/esdsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const esdsl = (): EsdslExpressionFunctionDefinition => ({
body: dsl,
},
},
{ signal: abortSignal }
{ abortSignal }
)
.toPromise();

Expand Down
5 changes: 0 additions & 5 deletions src/plugins/data/public/search/fetch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import { ISearchStartLegacy } from '../types';
*/
export type SearchRequest = Record<string, any>;

export interface FetchOptions {
abortSignal?: AbortSignal;
searchStrategyId?: string;
}

export interface FetchHandlers {
legacySearchService: ISearchStartLegacy;
config: { get: GetConfigFn };
Expand Down
11 changes: 2 additions & 9 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,15 @@

export * from './expressions';

export {
ISearch,
ISearchOptions,
ISearchGeneric,
ISearchSetup,
ISearchStart,
SearchEnhancements,
} from './types';
export { ISearch, ISearchGeneric, ISearchSetup, ISearchStart, 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, FetchOptions, getSearchParamsFromRequest, SearchRequest } from './fetch';
export { SearchError, getSearchParamsFromRequest, SearchRequest } from './fetch';

export {
ISearchSource,
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/data/public/search/legacy/call_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
*/

import { SearchResponse } from 'elasticsearch';
import { FetchOptions, FetchHandlers, handleResponse } from '../fetch';
import { ISearchOptions } from 'src/plugins/data/common';
import { FetchHandlers, handleResponse } from '../fetch';
import { defaultSearchStrategy } from './default_search_strategy';
import { SearchRequest } from '../index';

export function callClient(
searchRequests: SearchRequest[],
requestsOptions: FetchOptions[] = [],
requestsOptions: ISearchOptions[] = [],
fetchHandlers: FetchHandlers
) {
// Correlate the options with the request that they're associated with
const requestOptionEntries: Array<[
SearchRequest,
FetchOptions
ISearchOptions
]> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
const requestOptionsMap = new Map<SearchRequest, FetchOptions>(requestOptionEntries);
const requestOptionsMap = new Map<SearchRequest, ISearchOptions>(requestOptionEntries);
const requestResponseMap = new Map<SearchRequest, Promise<SearchResponse<any>>>();

const { searching, abort } = defaultSearchStrategy.search({
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/public/search/legacy/fetch_soon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import { fetchSoon } from './fetch_soon';
import { callClient } from './call_client';
import { FetchHandlers, FetchOptions } from '../fetch/types';
import { FetchHandlers } from '../fetch/types';
import { SearchRequest } from '../index';
import { SearchResponse } from 'elasticsearch';
import { GetConfigFn, UI_SETTINGS } from '../../../common';
import { GetConfigFn, UI_SETTINGS, ISearchOptions } from '../../../common';

function getConfigStub(config: any = {}): GetConfigFn {
return (key) => config[key];
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('fetchSoon', () => {
const options = [{ bar: 1 }, { bar: 2 }];

requests.forEach((request, i) => {
fetchSoon(request, options[i] as FetchOptions, { config } as FetchHandlers);
fetchSoon(request, options[i] as ISearchOptions, { config } as FetchHandlers);
});

jest.advanceTimersByTime(50);
Expand Down
Loading

0 comments on commit 6166e07

Please sign in to comment.