Skip to content

Commit

Permalink
Use enhancement pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Aug 23, 2020
1 parent 70eea0f commit c3137d4
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export interface ISearchSetup
| Property | Type | Description |
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-server.isearchsetup.aggs.md) | <code>AggsSetup</code> | |
<<<<<<< HEAD
| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | <code>(name: string, strategy: ISearchStrategy) =&gt; void</code> | Extension point exposed for other plugins to register their own search strategies. |
| [setDefaultSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.setdefaultsearchstrategy.md) | <code>(name: string) =&gt; void</code> | |
=======
| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | <code>&lt;SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest, SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse&gt;(name: string, strategy: ISearchStrategy&lt;SearchStrategyRequest, SearchStrategyResponse&gt;) =&gt; void</code> | Extension point exposed for other plugins to register their own search strategies. |
>>>>>>> 6dbc4be8f7f418315a96532562fad683c7a493d4
| [usage](./kibana-plugin-plugins-data-server.isearchsetup.usage.md) | <code>SearchUsage</code> | Used internally for telemetry |

This file was deleted.

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

```typescript
setup(core: CoreSetup<DataPluginStartDependencies, DataPluginStart>, { expressions, usageCollection }: DataPluginSetupDependencies): {
__enhance: (enhancements: DataEnhancements) => void;
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
Expand All @@ -25,6 +26,7 @@ setup(core: CoreSetup<DataPluginStartDependencies, DataPluginStart>, { expressio
<b>Returns:</b>

`{
__enhance: (enhancements: DataEnhancements) => void;
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
Expand Down
23 changes: 18 additions & 5 deletions src/plugins/data/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from '
import { ExpressionsServerSetup } from 'src/plugins/expressions/server';
import { ConfigSchema } from '../config';
import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns';
import { ISearchSetup, ISearchStart } from './search';
import { ISearchSetup, ISearchStart, SearchEnhancements } from './search';
import { SearchService } from './search/search_service';
import { QueryService } from './query/query_service';
import { ScriptsService } from './scripts';
Expand All @@ -31,9 +31,17 @@ import { AutocompleteService } from './autocomplete';
import { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats';
import { getUiSettings } from './ui_settings';

export interface DataEnhancements {
search: SearchEnhancements;
}

export interface DataPluginSetup {
search: ISearchSetup;
fieldFormats: FieldFormatsSetup;
/**
* @internal
*/
__enhance: (enhancements: DataEnhancements) => void;
}

export interface DataPluginStart {
Expand Down Expand Up @@ -87,11 +95,16 @@ export class DataServerPlugin

core.uiSettings.register(getUiSettings());

const searchSetup = this.searchService.setup(core, {
registerFunction: expressions.registerFunction,
usageCollection,
});

return {
search: this.searchService.setup(core, {
registerFunction: expressions.registerFunction,
usageCollection,
}),
__enhance: (enhancements: DataEnhancements) => {
searchSetup.__enhance(enhancements.search);
},
search: searchSetup,
fieldFormats: this.fieldFormats.setup(),
};
}
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/data/server/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
* under the License.
*/

export { ISearchStrategy, ISearchOptions, ISearchSetup, ISearchStart } from './types';
export {
ISearchStrategy,
ISearchOptions,
ISearchSetup,
ISearchStart,
SearchEnhancements,
} from './types';

export { getDefaultSearchParams, getTotalLoaded } from './es_search';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function createSearchSetupMock(): jest.Mocked<ISearchSetup> {
return {
aggs: searchAggsSetupMock(),
registerSearchStrategy: jest.fn(),
setDefaultSearchStrategy: jest.fn(),
__enhance: jest.fn(),
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
PluginInitializerContext,
RequestHandlerContext,
} from '../../../../core/server';
import { ISearchSetup, ISearchStart, ISearchStrategy } from './types';
import { ISearchSetup, ISearchStart, ISearchStrategy, SearchEnhancements } from './types';

import { AggsService, AggsSetupDependencies } from './aggs';

Expand Down Expand Up @@ -88,13 +88,13 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
registerSearchRoute(core);

return {
aggs: this.aggsService.setup({ registerFunction }),
registerSearchStrategy: this.registerSearchStrategy,
setDefaultSearchStrategy: (name: string) => {
if (this.searchStrategies.hasOwnProperty(name)) {
this.defaultSearchStrategyName = name;
__enhance: (enhancements: SearchEnhancements) => {
if (this.searchStrategies.hasOwnProperty(enhancements.defaultStrategy)) {
this.defaultSearchStrategyName = enhancements.defaultStrategy;
}
},
aggs: this.aggsService.setup({ registerFunction }),
registerSearchStrategy: this.registerSearchStrategy,
usage,
};
}
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/data/server/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import { AggsSetup, AggsStart } from './aggs';
import { SearchUsage } from './collectors/usage';
import { IEsSearchRequest, IEsSearchResponse } from './es_search';

export interface SearchEnhancements {
defaultStrategy: string;
}

export interface ISearchOptions {
/**
* An `AbortSignal` that allows the caller of `search` to abort a search request.
Expand All @@ -45,12 +49,15 @@ export interface ISearchSetup {
strategy: ISearchStrategy<SearchStrategyRequest, SearchStrategyResponse>
) => void;

setDefaultSearchStrategy: (name: string) => void;

/**
* Used internally for telemetry
*/
usage?: SearchUsage;

/**
* @internal
*/
__enhance: (enhancements: SearchEnhancements) => void;
}

export interface ISearchStart<
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,17 +685,15 @@ export interface ISearchOptions {
//
// @public (undocumented)
export interface ISearchSetup {
// Warning: (ae-forgotten-export) The symbol "SearchEnhancements" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
__enhance: (enhancements: SearchEnhancements) => void;
// Warning: (ae-forgotten-export) The symbol "AggsSetup" needs to be exported by the entry point index.d.ts
//
// (undocumented)
aggs: AggsSetup;
<<<<<<< HEAD
registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void;
// (undocumented)
setDefaultSearchStrategy: (name: string) => void;
=======
registerSearchStrategy: <SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest, SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse>(name: string, strategy: ISearchStrategy<SearchStrategyRequest, SearchStrategyResponse>) => void;
>>>>>>> 6dbc4be8f7f418315a96532562fad683c7a493d4
usage?: SearchUsage;
}

Expand Down Expand Up @@ -861,6 +859,7 @@ export class Plugin implements Plugin_2<PluginSetup, PluginStart, DataPluginSetu
constructor(initializerContext: PluginInitializerContext_2<ConfigSchema>);
// (undocumented)
setup(core: CoreSetup<DataPluginStartDependencies, PluginStart>, { expressions, usageCollection }: DataPluginSetupDependencies): {
__enhance: (enhancements: DataEnhancements) => void;
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
Expand Down Expand Up @@ -889,6 +888,8 @@ export function plugin(initializerContext: PluginInitializerContext<ConfigSchema
//
// @public (undocumented)
export interface PluginSetup {
// @internal (undocumented)
__enhance: (enhancements: DataEnhancements) => void;
// Warning: (ae-forgotten-export) The symbol "FieldFormatsSetup" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -1096,6 +1097,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage;
// src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/data_enhanced/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export class EnhancedDataServerPlugin implements Plugin<void, void, SetupDepende
)
);

deps.data.search.setDefaultSearchStrategy(ENHANCED_ES_SEARCH_STRATEGY);
deps.data.__enhance({
search: {
defaultStrategy: ENHANCED_ES_SEARCH_STRATEGY,
},
});
}

public start(core: CoreStart) {}
Expand Down

0 comments on commit c3137d4

Please sign in to comment.