From cd86b81b82f3cf28edc47f56bab900bd43214d9c Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Thu, 3 Sep 2020 11:57:03 +0300 Subject: [PATCH 01/10] Move streams utils to the core (#76397) * move utils/streams to the KP * allow imports from src/core/server/utils * ts-ify * import streams from KP * remove unnecessary ts-expect-error * fix kbn-es-archiver build * lost export * copy array in createListStream * remove streams from legacy utils Co-authored-by: spalger --- .eslintrc.js | 2 ++ src/cli_keystore/add.js | 2 +- .../get_sorted_objects_for_export.test.ts | 2 +- .../export/get_sorted_objects_for_export.ts | 2 +- .../import/collect_saved_objects.ts | 2 +- .../import/create_limit_stream.test.ts | 2 +- .../server/saved_objects/routes/export.ts | 6 +--- .../routes/integration_tests/export.test.ts | 2 +- .../server/saved_objects/routes/utils.test.ts | 2 +- src/core/server/saved_objects/routes/utils.ts | 6 +--- src/core/server/utils/index.ts | 1 + .../utils/streams/concat_stream.test.ts} | 2 +- .../server/utils/streams/concat_stream.ts} | 2 +- .../streams/concat_stream_providers.test.ts} | 0 .../utils/streams/concat_stream_providers.ts} | 7 ++-- .../utils/streams/filter_stream.test.ts | 2 +- .../server}/utils/streams/filter_stream.ts | 0 .../server/utils/streams/index.ts} | 0 .../utils/streams/intersperse_stream.test.ts} | 2 +- .../utils/streams/intersperse_stream.ts} | 4 +-- .../server/utils/streams/list_stream.test.ts} | 2 +- .../server/utils/streams/list_stream.ts} | 4 +-- .../server/utils/streams/map_stream.test.ts} | 4 +-- .../server/utils/streams/map_stream.ts} | 2 +- .../streams/promise_from_streams.test.ts} | 7 ++-- .../utils/streams/promise_from_streams.ts} | 16 ++++++--- .../utils/streams/reduce_stream.test.ts} | 11 +++--- .../server/utils/streams/reduce_stream.ts} | 5 ++- .../utils/streams/replace_stream.test.ts} | 12 ++++--- .../server/utils/streams/replace_stream.ts} | 3 +- .../utils/streams/split_stream.test.ts} | 8 ++--- .../server/utils/streams/split_stream.ts} | 6 ++-- src/dev/build/lib/watch_stdio_for_line.ts | 2 +- src/legacy/server/i18n/index.ts | 1 - .../server/logging/log_format_json.test.js | 2 +- .../server/logging/log_format_string.test.js | 2 +- src/legacy/utils/artifact_type.ts | 1 - src/legacy/utils/index.d.ts | 13 ------- src/legacy/utils/index.js | 12 ------- src/legacy/utils/streams/index.d.ts | 36 ------------------- .../routes/rules/import_rules_route.ts | 2 +- .../routes/rules/utils.test.ts | 2 +- .../create_rules_stream_from_ndjson.test.ts | 2 +- .../rules/create_rules_stream_from_ndjson.ts | 2 +- .../create_timelines_stream_from_ndjson.ts | 2 +- .../routes/import_timelines_route.test.ts | 4 +-- .../lib/timeline/routes/utils/common.ts | 2 +- .../timeline/routes/utils/import_timelines.ts | 2 +- .../utils/install_prepacked_timelines.test.ts | 2 +- .../read_stream/create_stream_from_ndjson.ts | 2 +- .../create_copy_to_space_mocks.ts | 2 +- 51 files changed, 85 insertions(+), 136 deletions(-) rename src/{legacy/utils/streams/concat_stream.test.js => core/server/utils/streams/concat_stream.test.ts} (98%) rename src/{legacy/utils/streams/concat_stream.js => core/server/utils/streams/concat_stream.ts} (96%) rename src/{legacy/utils/streams/concat_stream_providers.test.js => core/server/utils/streams/concat_stream_providers.test.ts} (100%) rename src/{legacy/utils/streams/concat_stream_providers.js => core/server/utils/streams/concat_stream_providers.ts} (91%) rename src/{legacy => core/server}/utils/streams/filter_stream.test.ts (99%) rename src/{legacy => core/server}/utils/streams/filter_stream.ts (100%) rename src/{legacy/utils/streams/index.js => core/server/utils/streams/index.ts} (100%) rename src/{legacy/utils/streams/intersperse_stream.test.js => core/server/utils/streams/intersperse_stream.test.ts} (99%) rename src/{legacy/utils/streams/intersperse_stream.js => core/server/utils/streams/intersperse_stream.ts} (95%) rename src/{legacy/utils/streams/list_stream.test.js => core/server/utils/streams/list_stream.test.ts} (97%) rename src/{legacy/utils/streams/list_stream.js => core/server/utils/streams/list_stream.ts} (90%) rename src/{legacy/utils/streams/map_stream.test.js => core/server/utils/streams/map_stream.test.ts} (95%) rename src/{legacy/utils/streams/map_stream.js => core/server/utils/streams/map_stream.ts} (93%) rename src/{legacy/utils/streams/promise_from_streams.test.js => core/server/utils/streams/promise_from_streams.test.ts} (96%) rename src/{legacy/utils/streams/promise_from_streams.js => core/server/utils/streams/promise_from_streams.ts} (80%) rename src/{legacy/utils/streams/reduce_stream.test.js => core/server/utils/streams/reduce_stream.test.ts} (92%) rename src/{legacy/utils/streams/reduce_stream.js => core/server/utils/streams/reduce_stream.ts} (95%) rename src/{legacy/utils/streams/replace_stream.test.js => core/server/utils/streams/replace_stream.test.ts} (91%) rename src/{legacy/utils/streams/replace_stream.js => core/server/utils/streams/replace_stream.ts} (96%) rename src/{legacy/utils/streams/split_stream.test.js => core/server/utils/streams/split_stream.test.ts} (93%) rename src/{legacy/utils/streams/split_stream.js => core/server/utils/streams/split_stream.ts} (95%) delete mode 100644 src/legacy/utils/streams/index.d.ts diff --git a/.eslintrc.js b/.eslintrc.js index 9b75c36c95abd..3161a25b70870 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -305,6 +305,8 @@ module.exports = { '!src/core/server/mocks{,.ts}', '!src/core/server/types{,.ts}', '!src/core/server/test_utils{,.ts}', + '!src/core/server/utils', // ts alias + '!src/core/server/utils/**/*', // for absolute imports until fixed in // https://github.com/elastic/kibana/issues/36096 '!src/core/server/*.test.mocks{,.ts}', diff --git a/src/cli_keystore/add.js b/src/cli_keystore/add.js index 44737e387c2d2..462259ec942dd 100644 --- a/src/cli_keystore/add.js +++ b/src/cli_keystore/add.js @@ -19,7 +19,7 @@ import { Logger } from '../cli_plugin/lib/logger'; import { confirm, question } from '../legacy/server/utils'; -import { createPromiseFromStreams, createConcatStream } from '../legacy/utils'; +import { createPromiseFromStreams, createConcatStream } from '../core/server/utils'; /** * @param {Keystore} keystore diff --git a/src/core/server/saved_objects/export/get_sorted_objects_for_export.test.ts b/src/core/server/saved_objects/export/get_sorted_objects_for_export.test.ts index 85b3a281aef7f..c084125f43127 100644 --- a/src/core/server/saved_objects/export/get_sorted_objects_for_export.test.ts +++ b/src/core/server/saved_objects/export/get_sorted_objects_for_export.test.ts @@ -20,7 +20,7 @@ import { exportSavedObjectsToStream } from './get_sorted_objects_for_export'; import { savedObjectsClientMock } from '../service/saved_objects_client.mock'; import { Readable } from 'stream'; -import { createPromiseFromStreams, createConcatStream } from '../../../../legacy/utils/streams'; +import { createPromiseFromStreams, createConcatStream } from '../../utils/streams'; async function readStreamToCompletion(stream: Readable) { return createPromiseFromStreams([stream, createConcatStream([])]); diff --git a/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts b/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts index 94f727e238ecf..214b51db7dd6b 100644 --- a/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts +++ b/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts @@ -18,7 +18,7 @@ */ import Boom from 'boom'; -import { createListStream } from '../../../../legacy/utils/streams'; +import { createListStream } from '../../utils/streams'; import { SavedObjectsClientContract, SavedObject } from '../types'; import { fetchNestedDependencies } from './inject_nested_depdendencies'; import { sortObjects } from './sort_objects'; diff --git a/src/core/server/saved_objects/import/collect_saved_objects.ts b/src/core/server/saved_objects/import/collect_saved_objects.ts index f55e6bf0d2af4..8e84f864cf449 100644 --- a/src/core/server/saved_objects/import/collect_saved_objects.ts +++ b/src/core/server/saved_objects/import/collect_saved_objects.ts @@ -23,7 +23,7 @@ import { createFilterStream, createMapStream, createPromiseFromStreams, -} from '../../../../legacy/utils/streams'; +} from '../../utils/streams'; import { SavedObject } from '../types'; import { createLimitStream } from './create_limit_stream'; import { SavedObjectsImportError } from './types'; diff --git a/src/core/server/saved_objects/import/create_limit_stream.test.ts b/src/core/server/saved_objects/import/create_limit_stream.test.ts index 736cfadcb6222..a7e689710a564 100644 --- a/src/core/server/saved_objects/import/create_limit_stream.test.ts +++ b/src/core/server/saved_objects/import/create_limit_stream.test.ts @@ -21,7 +21,7 @@ import { createConcatStream, createListStream, createPromiseFromStreams, -} from '../../../../legacy/utils/streams'; +} from '../../utils/streams'; import { createLimitStream } from './create_limit_stream'; describe('createLimitStream()', () => { diff --git a/src/core/server/saved_objects/routes/export.ts b/src/core/server/saved_objects/routes/export.ts index 9445c144ecda4..35a65d8d9651f 100644 --- a/src/core/server/saved_objects/routes/export.ts +++ b/src/core/server/saved_objects/routes/export.ts @@ -19,11 +19,7 @@ import { schema } from '@kbn/config-schema'; import stringify from 'json-stable-stringify'; -import { - createPromiseFromStreams, - createMapStream, - createConcatStream, -} from '../../../../legacy/utils/streams'; +import { createPromiseFromStreams, createMapStream, createConcatStream } from '../../utils/streams'; import { IRouter } from '../../http'; import { SavedObjectConfig } from '../saved_objects_config'; import { exportSavedObjectsToStream } from '../export'; diff --git a/src/core/server/saved_objects/routes/integration_tests/export.test.ts b/src/core/server/saved_objects/routes/integration_tests/export.test.ts index d47f7c6050d8f..a3891712fd22b 100644 --- a/src/core/server/saved_objects/routes/integration_tests/export.test.ts +++ b/src/core/server/saved_objects/routes/integration_tests/export.test.ts @@ -22,7 +22,7 @@ jest.mock('../../export', () => ({ })); import * as exportMock from '../../export'; -import { createListStream } from '../../../../../legacy/utils/streams'; +import { createListStream } from '../../../utils/streams'; import supertest from 'supertest'; import { UnwrapPromise } from '@kbn/utility-types'; import { SavedObjectConfig } from '../../saved_objects_config'; diff --git a/src/core/server/saved_objects/routes/utils.test.ts b/src/core/server/saved_objects/routes/utils.test.ts index 24719724785af..fd3bdad8606ed 100644 --- a/src/core/server/saved_objects/routes/utils.test.ts +++ b/src/core/server/saved_objects/routes/utils.test.ts @@ -19,7 +19,7 @@ import { createSavedObjectsStreamFromNdJson, validateTypes, validateObjects } from './utils'; import { Readable } from 'stream'; -import { createPromiseFromStreams, createConcatStream } from '../../../../legacy/utils/streams'; +import { createPromiseFromStreams, createConcatStream } from '../../utils/streams'; async function readStreamToCompletion(stream: Readable) { return createPromiseFromStreams([stream, createConcatStream([])]); diff --git a/src/core/server/saved_objects/routes/utils.ts b/src/core/server/saved_objects/routes/utils.ts index 3963833a9c718..f16a6e471257d 100644 --- a/src/core/server/saved_objects/routes/utils.ts +++ b/src/core/server/saved_objects/routes/utils.ts @@ -19,11 +19,7 @@ import { Readable } from 'stream'; import { SavedObject, SavedObjectsExportResultDetails } from 'src/core/server'; -import { - createSplitStream, - createMapStream, - createFilterStream, -} from '../../../../legacy/utils/streams'; +import { createSplitStream, createMapStream, createFilterStream } from '../../utils/streams'; export function createSavedObjectsStreamFromNdJson(ndJsonStream: Readable) { return ndJsonStream diff --git a/src/core/server/utils/index.ts b/src/core/server/utils/index.ts index b01a4c4e04899..d9c4217c4117f 100644 --- a/src/core/server/utils/index.ts +++ b/src/core/server/utils/index.ts @@ -20,3 +20,4 @@ export * from './crypto'; export * from './from_root'; export * from './package_json'; +export * from './streams'; diff --git a/src/legacy/utils/streams/concat_stream.test.js b/src/core/server/utils/streams/concat_stream.test.ts similarity index 98% rename from src/legacy/utils/streams/concat_stream.test.js rename to src/core/server/utils/streams/concat_stream.test.ts index 1498334013d1a..e964ab2a7a97e 100644 --- a/src/legacy/utils/streams/concat_stream.test.js +++ b/src/core/server/utils/streams/concat_stream.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { createListStream, createPromiseFromStreams, createConcatStream } from './'; +import { createListStream, createPromiseFromStreams, createConcatStream } from './index'; describe('concatStream', () => { test('accepts an initial value', async () => { diff --git a/src/legacy/utils/streams/concat_stream.js b/src/core/server/utils/streams/concat_stream.ts similarity index 96% rename from src/legacy/utils/streams/concat_stream.js rename to src/core/server/utils/streams/concat_stream.ts index e3f8f7261d2b7..03450cb51b832 100644 --- a/src/legacy/utils/streams/concat_stream.js +++ b/src/core/server/utils/streams/concat_stream.ts @@ -41,6 +41,6 @@ import { createReduceStream } from './reduce_stream'; * items will concat with * @return {Transform} */ -export function createConcatStream(initial) { +export function createConcatStream(initial?: T) { return createReduceStream((acc, chunk) => acc.concat(chunk), initial); } diff --git a/src/legacy/utils/streams/concat_stream_providers.test.js b/src/core/server/utils/streams/concat_stream_providers.test.ts similarity index 100% rename from src/legacy/utils/streams/concat_stream_providers.test.js rename to src/core/server/utils/streams/concat_stream_providers.test.ts diff --git a/src/legacy/utils/streams/concat_stream_providers.js b/src/core/server/utils/streams/concat_stream_providers.ts similarity index 91% rename from src/legacy/utils/streams/concat_stream_providers.js rename to src/core/server/utils/streams/concat_stream_providers.ts index 11dfb84284df3..bb836e3d73787 100644 --- a/src/legacy/utils/streams/concat_stream_providers.js +++ b/src/core/server/utils/streams/concat_stream_providers.ts @@ -17,7 +17,7 @@ * under the License. */ -import { PassThrough } from 'stream'; +import { Readable, PassThrough, TransformOptions } from 'stream'; /** * Write the data and errors from a list of stream providers @@ -29,7 +29,10 @@ import { PassThrough } from 'stream'; * @param {PassThroughOptions} options options passed to the PassThrough constructor * @return {WritableStream} combined stream */ -export function concatStreamProviders(sourceProviders, options = {}) { +export function concatStreamProviders( + sourceProviders: Array<() => Readable>, + options?: TransformOptions +) { const destination = new PassThrough(options); const queue = sourceProviders.slice(); diff --git a/src/legacy/utils/streams/filter_stream.test.ts b/src/core/server/utils/streams/filter_stream.test.ts similarity index 99% rename from src/legacy/utils/streams/filter_stream.test.ts rename to src/core/server/utils/streams/filter_stream.test.ts index 28b7f2588628e..41073e54b0a84 100644 --- a/src/legacy/utils/streams/filter_stream.test.ts +++ b/src/core/server/utils/streams/filter_stream.test.ts @@ -22,7 +22,7 @@ import { createFilterStream, createListStream, createPromiseFromStreams, -} from './'; +} from './index'; describe('createFilterStream()', () => { test('calls the function with each item in the source stream', async () => { diff --git a/src/legacy/utils/streams/filter_stream.ts b/src/core/server/utils/streams/filter_stream.ts similarity index 100% rename from src/legacy/utils/streams/filter_stream.ts rename to src/core/server/utils/streams/filter_stream.ts diff --git a/src/legacy/utils/streams/index.js b/src/core/server/utils/streams/index.ts similarity index 100% rename from src/legacy/utils/streams/index.js rename to src/core/server/utils/streams/index.ts diff --git a/src/legacy/utils/streams/intersperse_stream.test.js b/src/core/server/utils/streams/intersperse_stream.test.ts similarity index 99% rename from src/legacy/utils/streams/intersperse_stream.test.js rename to src/core/server/utils/streams/intersperse_stream.test.ts index e11b36d77106a..9aa15035d2a1c 100644 --- a/src/legacy/utils/streams/intersperse_stream.test.js +++ b/src/core/server/utils/streams/intersperse_stream.test.ts @@ -22,7 +22,7 @@ import { createListStream, createIntersperseStream, createConcatStream, -} from './'; +} from './index'; describe('intersperseStream', () => { test('places the intersperse value between each provided value', async () => { diff --git a/src/legacy/utils/streams/intersperse_stream.js b/src/core/server/utils/streams/intersperse_stream.ts similarity index 95% rename from src/legacy/utils/streams/intersperse_stream.js rename to src/core/server/utils/streams/intersperse_stream.ts index 5f9f0b03cd7eb..272507221caff 100644 --- a/src/legacy/utils/streams/intersperse_stream.js +++ b/src/core/server/utils/streams/intersperse_stream.ts @@ -40,7 +40,7 @@ import { Transform } from 'stream'; * @param {String|Buffer} intersperseChunk * @return {Transform} */ -export function createIntersperseStream(intersperseChunk) { +export function createIntersperseStream(intersperseChunk: string | Buffer) { let first = true; return new Transform({ @@ -55,7 +55,7 @@ export function createIntersperseStream(intersperseChunk) { } this.push(chunk); - callback(null); + callback(); } catch (err) { callback(err); } diff --git a/src/legacy/utils/streams/list_stream.test.js b/src/core/server/utils/streams/list_stream.test.ts similarity index 97% rename from src/legacy/utils/streams/list_stream.test.js rename to src/core/server/utils/streams/list_stream.test.ts index 12e20696b0510..2a20c929db6b9 100644 --- a/src/legacy/utils/streams/list_stream.test.js +++ b/src/core/server/utils/streams/list_stream.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { createListStream } from './'; +import { createListStream } from './index'; describe('listStream', () => { test('provides the values in the initial list', async () => { diff --git a/src/legacy/utils/streams/list_stream.js b/src/core/server/utils/streams/list_stream.ts similarity index 90% rename from src/legacy/utils/streams/list_stream.js rename to src/core/server/utils/streams/list_stream.ts index a614620b054b7..e62f6d3fa930b 100644 --- a/src/legacy/utils/streams/list_stream.js +++ b/src/core/server/utils/streams/list_stream.ts @@ -26,8 +26,8 @@ import { Readable } from 'stream'; * @param {Array} items - the list of items to provide * @return {Readable} */ -export function createListStream(items = []) { - const queue = [].concat(items); +export function createListStream(items: T | T[] = []) { + const queue = Array.isArray(items) ? [...items] : [items]; return new Readable({ objectMode: true, diff --git a/src/legacy/utils/streams/map_stream.test.js b/src/core/server/utils/streams/map_stream.test.ts similarity index 95% rename from src/legacy/utils/streams/map_stream.test.js rename to src/core/server/utils/streams/map_stream.test.ts index d86da178f0c1b..bf0cab39c21f4 100644 --- a/src/legacy/utils/streams/map_stream.test.js +++ b/src/core/server/utils/streams/map_stream.test.ts @@ -39,7 +39,7 @@ describe('createMapStream()', () => { test('send the return value from the mapper on the output stream', async () => { const result = await createPromiseFromStreams([ createListStream([1, 2, 3]), - createMapStream((n) => n * 100), + createMapStream((n: number) => n * 100), createConcatStream([]), ]); @@ -49,7 +49,7 @@ describe('createMapStream()', () => { test('supports async mappers', async () => { const result = await createPromiseFromStreams([ createListStream([1, 2, 3]), - createMapStream(async (n, i) => { + createMapStream(async (n: number, i: number) => { await delay(n); return n * i; }), diff --git a/src/legacy/utils/streams/map_stream.js b/src/core/server/utils/streams/map_stream.ts similarity index 93% rename from src/legacy/utils/streams/map_stream.js rename to src/core/server/utils/streams/map_stream.ts index 4e906471330f1..aad53cc526626 100644 --- a/src/legacy/utils/streams/map_stream.js +++ b/src/core/server/utils/streams/map_stream.ts @@ -19,7 +19,7 @@ import { Transform } from 'stream'; -export function createMapStream(fn) { +export function createMapStream(fn: (value: T, i: number) => void) { let i = 0; return new Transform({ diff --git a/src/legacy/utils/streams/promise_from_streams.test.js b/src/core/server/utils/streams/promise_from_streams.test.ts similarity index 96% rename from src/legacy/utils/streams/promise_from_streams.test.js rename to src/core/server/utils/streams/promise_from_streams.test.ts index e4d9835106f12..1f2596c16a6fa 100644 --- a/src/legacy/utils/streams/promise_from_streams.test.js +++ b/src/core/server/utils/streams/promise_from_streams.test.ts @@ -19,7 +19,7 @@ import { Readable, Writable, Duplex, Transform } from 'stream'; -import { createListStream, createPromiseFromStreams, createReduceStream } from './'; +import { createListStream, createPromiseFromStreams, createReduceStream } from './index'; describe('promiseFromStreams', () => { test('pipes together an array of streams', async () => { @@ -76,14 +76,13 @@ describe('promiseFromStreams', () => { test('waits for writing and resolves to final value', async () => { let written = ''; - const duplexReadQueue = []; + const duplexReadQueue: Array> = []; const duplexItemsToPush = ['foo', 'bar', null]; const result = await createPromiseFromStreams([ createListStream(['a', 'b', 'c']), new Duplex({ async read() { - const result = await duplexReadQueue.shift(); - this.push(result); + this.push(await duplexReadQueue.shift()); }, write(chunk, enc, cb) { diff --git a/src/legacy/utils/streams/promise_from_streams.js b/src/core/server/utils/streams/promise_from_streams.ts similarity index 80% rename from src/legacy/utils/streams/promise_from_streams.js rename to src/core/server/utils/streams/promise_from_streams.ts index 05f6a08aa1a09..f5fc4af62bc83 100644 --- a/src/legacy/utils/streams/promise_from_streams.js +++ b/src/core/server/utils/streams/promise_from_streams.ts @@ -34,16 +34,20 @@ * @return {Promise} */ -import { pipeline, Writable } from 'stream'; +import { pipeline, Writable, Readable } from 'stream'; -export async function createPromiseFromStreams(streams) { - let finalChunk; +function isReadable(stream: Readable | Writable): stream is Readable { + return 'read' in stream && typeof stream.read === 'function'; +} + +export async function createPromiseFromStreams(streams: [Readable, ...Writable[]]): Promise { + let finalChunk: any; const last = streams[streams.length - 1]; - if (typeof last.read !== 'function' && streams.length === 1) { + if (!isReadable(last) && streams.length === 1) { // For a nicer error than what stream.pipeline throws throw new Error('A minimum of 2 streams is required when a non-readable stream is given'); } - if (typeof last.read === 'function') { + if (isReadable(last)) { // We are pushing a writable stream to capture the last chunk streams.push( new Writable({ @@ -57,7 +61,9 @@ export async function createPromiseFromStreams(streams) { }) ); } + return new Promise((resolve, reject) => { + // @ts-expect-error 'pipeline' doesn't support variable length of arguments pipeline(...streams, (err) => { if (err) return reject(err); resolve(finalChunk); diff --git a/src/legacy/utils/streams/reduce_stream.test.js b/src/core/server/utils/streams/reduce_stream.test.ts similarity index 92% rename from src/legacy/utils/streams/reduce_stream.test.js rename to src/core/server/utils/streams/reduce_stream.test.ts index 2c073f67f82a8..e4a7dc1cef491 100644 --- a/src/legacy/utils/streams/reduce_stream.test.js +++ b/src/core/server/utils/streams/reduce_stream.test.ts @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +import { Transform } from 'stream'; +import { createReduceStream, createPromiseFromStreams, createListStream } from './index'; -import { createReduceStream, createPromiseFromStreams, createListStream } from './'; - -const promiseFromEvent = (name, emitter) => +const promiseFromEvent = (name: string, emitter: Transform) => new Promise((resolve) => emitter.on(name, () => resolve(name))); describe('reduceStream', () => { @@ -47,7 +47,10 @@ describe('reduceStream', () => { }); test('emits an error if an iteration fails', async () => { - const reduce = createReduceStream((acc, i) => expect(i).toBe(1), 0); + const reduce = createReduceStream((acc, i) => { + expect(i).toBe(1); + return acc; + }, 0); const errorEvent = promiseFromEvent('error', reduce); reduce.write(1); diff --git a/src/legacy/utils/streams/reduce_stream.js b/src/core/server/utils/streams/reduce_stream.ts similarity index 95% rename from src/legacy/utils/streams/reduce_stream.js rename to src/core/server/utils/streams/reduce_stream.ts index d66b0124d1dab..9129df096ad13 100644 --- a/src/legacy/utils/streams/reduce_stream.js +++ b/src/core/server/utils/streams/reduce_stream.ts @@ -32,7 +32,10 @@ import { Transform } from 'stream'; * initial value. * @return {Transform} */ -export function createReduceStream(reducer, initial) { +export function createReduceStream( + reducer: (value: any, chunk: T, enc: string) => T, + initial?: T +) { let i = -1; let value = initial; diff --git a/src/legacy/utils/streams/replace_stream.test.js b/src/core/server/utils/streams/replace_stream.test.ts similarity index 91% rename from src/legacy/utils/streams/replace_stream.test.js rename to src/core/server/utils/streams/replace_stream.test.ts index 01b89f93e5af0..c9da42395fb85 100644 --- a/src/legacy/utils/streams/replace_stream.test.js +++ b/src/core/server/utils/streams/replace_stream.test.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import { Writable, Readable } from 'stream'; import { createReplaceStream, @@ -23,19 +24,19 @@ import { createPromiseFromStreams, createListStream, createMapStream, -} from './'; +} from './index'; -async function concatToString(streams) { +async function concatToString(streams: [Readable, ...Writable[]]) { return await createPromiseFromStreams([ ...streams, - createMapStream((buff) => buff.toString('utf8')), + createMapStream((buff: Buffer) => buff.toString('utf8')), createConcatStream(''), ]); } describe('replaceStream', () => { test('produces buffers when it receives buffers', async () => { - const chunks = await createPromiseFromStreams([ + const chunks = await createPromiseFromStreams([ createListStream([Buffer.from('foo'), Buffer.from('bar')]), createReplaceStream('o', '0'), createConcatStream([]), @@ -47,7 +48,7 @@ describe('replaceStream', () => { }); test('produces buffers when it receives strings', async () => { - const chunks = await createPromiseFromStreams([ + const chunks = await createPromiseFromStreams([ createListStream(['foo', 'bar']), createReplaceStream('o', '0'), createConcatStream([]), @@ -59,6 +60,7 @@ describe('replaceStream', () => { }); test('expects toReplace to be a string', () => { + // @ts-expect-error expect(() => createReplaceStream(Buffer.from('foo'))).toThrowError(/be a string/); }); diff --git a/src/legacy/utils/streams/replace_stream.js b/src/core/server/utils/streams/replace_stream.ts similarity index 96% rename from src/legacy/utils/streams/replace_stream.js rename to src/core/server/utils/streams/replace_stream.ts index 7309bd241fa52..05391bb3341c2 100644 --- a/src/legacy/utils/streams/replace_stream.js +++ b/src/core/server/utils/streams/replace_stream.ts @@ -19,7 +19,7 @@ import { Transform } from 'stream'; -export function createReplaceStream(toReplace, replacement) { +export function createReplaceStream(toReplace: string, replacement: string | Buffer) { if (typeof toReplace !== 'string') { throw new TypeError('toReplace must be a string'); } @@ -78,6 +78,7 @@ export function createReplaceStream(toReplace, replacement) { this.push(buffer); } + // @ts-expect-error buffer = null; callback(); }, diff --git a/src/legacy/utils/streams/split_stream.test.js b/src/core/server/utils/streams/split_stream.test.ts similarity index 93% rename from src/legacy/utils/streams/split_stream.test.js rename to src/core/server/utils/streams/split_stream.test.ts index e0736d220ba5c..f131bd0661e54 100644 --- a/src/legacy/utils/streams/split_stream.test.js +++ b/src/core/server/utils/streams/split_stream.test.ts @@ -16,16 +16,16 @@ * specific language governing permissions and limitations * under the License. */ +import { Transform } from 'stream'; +import { createSplitStream, createConcatStream, createPromiseFromStreams } from './index'; -import { createSplitStream, createConcatStream, createPromiseFromStreams } from './'; - -async function split(stream, input) { +async function split(stream: Transform, input: Array) { const concat = createConcatStream(); concat.write([]); stream.pipe(concat); const output = createPromiseFromStreams([concat]); - input.forEach((i) => { + input.forEach((i: any) => { stream.write(i); }); stream.end(); diff --git a/src/legacy/utils/streams/split_stream.js b/src/core/server/utils/streams/split_stream.ts similarity index 95% rename from src/legacy/utils/streams/split_stream.js rename to src/core/server/utils/streams/split_stream.ts index f55cbc7bd290d..ae820f60abbf6 100644 --- a/src/legacy/utils/streams/split_stream.js +++ b/src/core/server/utils/streams/split_stream.ts @@ -38,7 +38,7 @@ import { Transform } from 'stream'; * @param {String} splitChunk * @return {Transform} */ -export function createSplitStream(splitChunk) { +export function createSplitStream(splitChunk: string | Uint8Array) { let unsplitBuffer = Buffer.alloc(0); return new Transform({ @@ -55,7 +55,7 @@ export function createSplitStream(splitChunk) { } unsplitBuffer = toSplit; - callback(null); + callback(); } catch (err) { callback(err); } @@ -65,7 +65,7 @@ export function createSplitStream(splitChunk) { try { this.push(unsplitBuffer.toString('utf8')); - callback(null); + callback(); } catch (err) { callback(err); } diff --git a/src/dev/build/lib/watch_stdio_for_line.ts b/src/dev/build/lib/watch_stdio_for_line.ts index 2322d017abc61..3d7929ccfc33a 100644 --- a/src/dev/build/lib/watch_stdio_for_line.ts +++ b/src/dev/build/lib/watch_stdio_for_line.ts @@ -24,7 +24,7 @@ import { createPromiseFromStreams, createSplitStream, createMapStream, -} from '../../../legacy/utils/streams'; +} from '../../../core/server/utils'; // creates a stream that skips empty lines unless they are followed by // another line, preventing the empty lines produced by splitStream diff --git a/src/legacy/server/i18n/index.ts b/src/legacy/server/i18n/index.ts index 09f7022436049..e895f83fe6901 100644 --- a/src/legacy/server/i18n/index.ts +++ b/src/legacy/server/i18n/index.ts @@ -20,7 +20,6 @@ import { i18n, i18nLoader } from '@kbn/i18n'; import { basename } from 'path'; import { Server } from 'hapi'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { fromRoot } from '../../../core/server/utils'; import { getTranslationPaths } from './get_translations_path'; import { I18N_RC } from './constants'; diff --git a/src/legacy/server/logging/log_format_json.test.js b/src/legacy/server/logging/log_format_json.test.js index 31e622ecae611..f4fb939750566 100644 --- a/src/legacy/server/logging/log_format_json.test.js +++ b/src/legacy/server/logging/log_format_json.test.js @@ -21,7 +21,7 @@ import moment from 'moment'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { attachMetaData } from '../../../../src/core/server/legacy/logging/legacy_logging_server'; -import { createListStream, createPromiseFromStreams } from '../../utils'; +import { createListStream, createPromiseFromStreams } from '../../../core/server/utils'; import KbnLoggerJsonFormat from './log_format_json'; diff --git a/src/legacy/server/logging/log_format_string.test.js b/src/legacy/server/logging/log_format_string.test.js index 067ad70380961..842325865cce2 100644 --- a/src/legacy/server/logging/log_format_string.test.js +++ b/src/legacy/server/logging/log_format_string.test.js @@ -21,7 +21,7 @@ import moment from 'moment'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { attachMetaData } from '../../../../src/core/server/legacy/logging/legacy_logging_server'; -import { createListStream, createPromiseFromStreams } from '../../utils'; +import { createListStream, createPromiseFromStreams } from '../../../core/server/utils'; import KbnLoggerStringFormat from './log_format_string'; diff --git a/src/legacy/utils/artifact_type.ts b/src/legacy/utils/artifact_type.ts index 69f728e9e2220..ef471ef8e050d 100644 --- a/src/legacy/utils/artifact_type.ts +++ b/src/legacy/utils/artifact_type.ts @@ -17,7 +17,6 @@ * under the License. */ -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { pkg } from '../../core/server/utils'; export const IS_KIBANA_DISTRIBUTABLE = pkg.build && pkg.build.distributable === true; export const IS_KIBANA_RELEASE = pkg.build && pkg.build.release === true; diff --git a/src/legacy/utils/index.d.ts b/src/legacy/utils/index.d.ts index c294c79542bbe..a57caad1d34bf 100644 --- a/src/legacy/utils/index.d.ts +++ b/src/legacy/utils/index.d.ts @@ -18,16 +18,3 @@ */ export function unset(object: object, rawPath: string): void; - -export { - concatStreamProviders, - createConcatStream, - createFilterStream, - createIntersperseStream, - createListStream, - createMapStream, - createPromiseFromStreams, - createReduceStream, - createReplaceStream, - createSplitStream, -} from './streams'; diff --git a/src/legacy/utils/index.js b/src/legacy/utils/index.js index 4274fb2e4901a..529b1ddfd8a4d 100644 --- a/src/legacy/utils/index.js +++ b/src/legacy/utils/index.js @@ -23,15 +23,3 @@ export { deepCloneWithBuffers } from './deep_clone_with_buffers'; export { unset } from './unset'; export { IS_KIBANA_DISTRIBUTABLE } from './artifact_type'; export { IS_KIBANA_RELEASE } from './artifact_type'; - -export { - concatStreamProviders, - createConcatStream, - createIntersperseStream, - createListStream, - createPromiseFromStreams, - createReduceStream, - createSplitStream, - createMapStream, - createReplaceStream, -} from './streams'; diff --git a/src/legacy/utils/streams/index.d.ts b/src/legacy/utils/streams/index.d.ts deleted file mode 100644 index 470b5d9fa3505..0000000000000 --- a/src/legacy/utils/streams/index.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 { Readable, Writable, Transform, TransformOptions } from 'stream'; - -export function concatStreamProviders( - sourceProviders: Array<() => Readable>, - options: TransformOptions -): Transform; -export function createIntersperseStream(intersperseChunk: string | Buffer): Transform; -export function createSplitStream(splitChunk: T): Transform; -export function createListStream(items: any | any[]): Readable; -export function createReduceStream(reducer: (value: any, chunk: T, enc: string) => T): Transform; -export function createPromiseFromStreams([first, ...rest]: [Readable, ...Writable[]]): Promise< - T ->; -export function createConcatStream(initial?: any): Transform; -export function createMapStream(fn: (value: T, i: number) => void): Transform; -export function createReplaceStream(toReplace: string, replacement: string | Buffer): Transform; -export function createFilterStream(fn: (obj: T) => boolean): Transform; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts index 18eea7c45585f..8a7215e5a5bad 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts @@ -20,7 +20,7 @@ import { importRulesSchema as importRulesResponseSchema, } from '../../../../../common/detection_engine/schemas/response/import_rules_schema'; import { IRouter } from '../../../../../../../../src/core/server'; -import { createPromiseFromStreams } from '../../../../../../../../src/legacy/utils/streams'; +import { createPromiseFromStreams } from '../../../../../../../../src/core/server/utils/'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { ConfigType } from '../../../../config'; import { SetupPlugins } from '../../../../plugin'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts index 3122db1919c3c..11f74c264ae0c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts @@ -22,7 +22,7 @@ import { INTERNAL_IDENTIFIER } from '../../../../../common/constants'; import { RuleTypeParams } from '../../types'; import { BulkError, ImportSuccessError } from '../utils'; import { getOutputRuleAlertForRest } from '../__mocks__/utils'; -import { createPromiseFromStreams } from '../../../../../../../../src/legacy/utils/streams'; +import { createPromiseFromStreams } from '../../../../../../../../src/core/server/utils'; import { PartialAlert } from '../../../../../../alerts/server'; import { SanitizedAlert } from '../../../../../../alerts/server/types'; import { createRulesStreamFromNdJson } from '../../rules/create_rules_stream_from_ndjson'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts index f2061ce1d36de..60071bc2cef41 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts @@ -5,7 +5,7 @@ */ import { Readable } from 'stream'; import { createRulesStreamFromNdJson } from './create_rules_stream_from_ndjson'; -import { createPromiseFromStreams } from 'src/legacy/utils/streams'; +import { createPromiseFromStreams } from 'src/core/server/utils'; import { BadRequestError } from '../errors/bad_request_error'; import { ImportRulesSchemaDecoded } from '../../../../common/detection_engine/schemas/request/import_rules_schema'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts index d7723232ca921..cd574a8d95615 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts @@ -19,7 +19,7 @@ import { createSplitStream, createMapStream, createConcatStream, -} from '../../../../../../../src/legacy/utils/streams'; +} from '../../../../../../../src/core/server/utils'; import { BadRequestError } from '../errors/bad_request_error'; import { parseNdjsonStrings, diff --git a/x-pack/plugins/security_solution/server/lib/timeline/create_timelines_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/lib/timeline/create_timelines_stream_from_ndjson.ts index 6b4017b5e4d5c..2827cd373d5e7 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/create_timelines_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/create_timelines_stream_from_ndjson.ts @@ -13,7 +13,7 @@ import { createConcatStream, createSplitStream, createMapStream, -} from '../../../../../../src/legacy/utils'; +} from '../../../../../../src/core/server/utils'; import { parseNdjsonStrings, filterExportedCounts, diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.test.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.test.ts index ff76045db90cb..388ab5db3e852 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.test.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.test.ts @@ -79,7 +79,7 @@ describe('import timelines', () => { }; }); - jest.doMock('../../../../../../../src/legacy/utils', () => { + jest.doMock('../../../../../../../src/core/server/utils', () => { return { createPromiseFromStreams: jest.fn().mockReturnValue(mockParsedObjects), }; @@ -543,7 +543,7 @@ describe('import timeline templates', () => { }; }); - jest.doMock('../../../../../../../src/legacy/utils', () => { + jest.doMock('../../../../../../../src/core/server/utils', () => { return { createPromiseFromStreams: jest.fn().mockReturnValue(mockParsedTemplateTimelineObjects), }; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/common.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/common.ts index fc25f1a48194e..9a3dbf365e026 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/common.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/common.ts @@ -10,7 +10,7 @@ import { Readable } from 'stream'; import { KibanaRequest, RequestHandlerContext } from 'src/core/server'; -import { createListStream } from '../../../../../../../../src/legacy/utils'; +import { createListStream } from '../../../../../../../../src/core/server/utils'; import { SetupPlugins } from '../../../../plugin'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/import_timelines.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/import_timelines.ts index f62f02cc7bba9..a19b18e7d89b1 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/import_timelines.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/import_timelines.ts @@ -21,7 +21,7 @@ import { createBulkErrorObject, BulkError } from '../../../detection_engine/rout import { createTimelines } from './create_timelines'; import { FrameworkRequest } from '../../../framework'; import { createTimelinesStreamFromNdJson } from '../../create_timelines_stream_from_ndjson'; -import { createPromiseFromStreams } from '../../../../../../../../src/legacy/utils'; +import { createPromiseFromStreams } from '../../../../../../../../src/core/server/utils'; import { getTupleDuplicateErrorsAndUniqueTimeline } from './get_timelines_from_stream'; import { CompareTimelinesStatus } from './compare_timelines_status'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/install_prepacked_timelines.test.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/install_prepacked_timelines.test.ts index 66f16db01a508..c63978a1f046e 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/install_prepacked_timelines.test.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/utils/install_prepacked_timelines.test.ts @@ -5,7 +5,7 @@ */ import { join, resolve } from 'path'; -import { createPromiseFromStreams } from '../../../../../../../../src/legacy/utils/streams'; +import { createPromiseFromStreams } from '../../../../../../../../src/core/server/utils'; import { SecurityPluginSetup } from '../../../../../../security/server'; import { FrameworkRequest } from '../../../framework'; diff --git a/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts index 0eb021bfe2a83..4446e82f99de4 100644 --- a/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts @@ -16,7 +16,7 @@ import { ImportRulesSchema, } from '../../../common/detection_engine/schemas/request/import_rules_schema'; import { exactCheck } from '../../../common/exact_check'; -import { createMapStream, createFilterStream } from '../../../../../../src/legacy/utils/streams'; +import { createMapStream, createFilterStream } from '../../../../../../src/core/server/utils'; import { BadRequestError } from '../../lib/detection_engine/errors/bad_request_error'; export interface RulesObjectsExportResultDetails { diff --git a/x-pack/plugins/spaces/server/routes/api/__fixtures__/create_copy_to_space_mocks.ts b/x-pack/plugins/spaces/server/routes/api/__fixtures__/create_copy_to_space_mocks.ts index 0e117b3f16e3f..ef6f5e1541a46 100644 --- a/x-pack/plugins/spaces/server/routes/api/__fixtures__/create_copy_to_space_mocks.ts +++ b/x-pack/plugins/spaces/server/routes/api/__fixtures__/create_copy_to_space_mocks.ts @@ -5,7 +5,7 @@ */ import { Readable } from 'stream'; -import { createPromiseFromStreams, createConcatStream } from 'src/legacy/utils'; +import { createPromiseFromStreams, createConcatStream } from 'src/core/server/utils'; async function readStreamToCompletion(stream: Readable) { return (await (createPromiseFromStreams([stream, createConcatStream([])]) as unknown)) as any[]; From 411048ae0963c2193f753552f37dcda6277d1c5b Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Thu, 3 Sep 2020 12:30:31 +0300 Subject: [PATCH 02/10] Replace FetchOptions with ISearchOptions (#76538) * Replace FetchOptions with ISearchOptions and update usage * Merge the client and server ISearchOption types into common * docs --- ...ns-data-public.fetchoptions.abortsignal.md | 11 -------- ...plugin-plugins-data-public.fetchoptions.md | 19 -------------- ...ta-public.fetchoptions.searchstrategyid.md | 11 -------- ...-data-public.isearchoptions.abortsignal.md | 13 ++++++++++ ...ugin-plugins-data-public.isearchoptions.md | 4 +-- ...ugins-data-public.isearchoptions.signal.md | 11 -------- ...ins-data-public.isearchoptions.strategy.md | 2 ++ .../kibana-plugin-plugins-data-public.md | 1 - ...data-server.isearchoptions.abortsignal.md} | 6 ++--- ...ugin-plugins-data-server.isearchoptions.md | 4 +-- ...ins-data-server.isearchoptions.strategy.md | 2 ++ .../data/common/search/aggs/agg_config.ts | 9 ++++--- .../data/common/search/aggs/agg_configs.ts | 4 +-- .../common/search/aggs/param_types/base.ts | 4 +-- .../data/common/search/es_search/index.ts | 1 + .../data/common/search/es_search/types.ts | 11 ++++++++ src/plugins/data/common/search/index.ts | 1 + src/plugins/data/public/index.ts | 4 +-- src/plugins/data/public/public.api.md | 16 ++---------- .../data/public/search/expressions/esdsl.ts | 2 +- src/plugins/data/public/search/fetch/types.ts | 5 ---- src/plugins/data/public/search/index.ts | 11 ++------ .../data/public/search/legacy/call_client.ts | 9 ++++--- .../public/search/legacy/fetch_soon.test.ts | 6 ++--- .../data/public/search/legacy/fetch_soon.ts | 10 ++++---- .../public/search/search_interceptor.test.ts | 6 +++-- .../data/public/search/search_interceptor.ts | 12 ++++++--- .../search/search_source/search_source.ts | 25 +++++++++++-------- src/plugins/data/public/search/types.ts | 6 +---- src/plugins/data/server/index.ts | 2 +- src/plugins/data/server/search/index.ts | 8 +----- src/plugins/data/server/search/routes.ts | 4 +-- .../data/server/search/search_service.ts | 12 +++++---- src/plugins/data/server/search/types.ts | 10 +------- src/plugins/data/server/server.api.md | 5 ++-- .../public/data_model/search_api.ts | 2 +- .../public/search/search_interceptor.test.ts | 4 +-- .../server/search/es_search_strategy.ts | 3 +-- .../hosts/first_last_seen/index.tsx | 2 +- .../public/hosts/containers/hosts/index.tsx | 2 +- .../containers/hosts/overview/_index.tsx | 2 +- .../network/containers/network_http/index.tsx | 2 +- .../public/network/containers/tls/index.tsx | 2 +- 43 files changed, 117 insertions(+), 169 deletions(-) delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.signal.md rename docs/development/plugins/data/server/{kibana-plugin-plugins-data-server.isearchoptions.signal.md => kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md} (62%) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md deleted file mode 100644 index 791f1b63e6539..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) > [abortSignal](./kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md) - -## FetchOptions.abortSignal property - -Signature: - -```typescript -abortSignal?: AbortSignal; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.md deleted file mode 100644 index f07fdd4280533..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.md +++ /dev/null @@ -1,19 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) - -## FetchOptions interface - -Signature: - -```typescript -export interface FetchOptions -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [abortSignal](./kibana-plugin-plugins-data-public.fetchoptions.abortsignal.md) | AbortSignal | | -| [searchStrategyId](./kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md) | string | | - diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md deleted file mode 100644 index 8824529eb4eca..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) > [searchStrategyId](./kibana-plugin-plugins-data-public.fetchoptions.searchstrategyid.md) - -## FetchOptions.searchStrategyId property - -Signature: - -```typescript -searchStrategyId?: string; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md new file mode 100644 index 0000000000000..fd8d322d54b26 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) > [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. + +Signature: + +```typescript +abortSignal?: AbortSignal; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.md index 3eb38dc7d52e0..c9018b0048aa3 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.md @@ -14,6 +14,6 @@ export interface ISearchOptions | Property | Type | Description | | --- | --- | --- | -| [signal](./kibana-plugin-plugins-data-public.isearchoptions.signal.md) | AbortSignal | | -| [strategy](./kibana-plugin-plugins-data-public.isearchoptions.strategy.md) | string | | +| [abortSignal](./kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md) | AbortSignal | An AbortSignal that allows the caller of search to abort a search request. | +| [strategy](./kibana-plugin-plugins-data-public.isearchoptions.strategy.md) | string | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.signal.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.signal.md deleted file mode 100644 index 10bd186d55baa..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.signal.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) > [signal](./kibana-plugin-plugins-data-public.isearchoptions.signal.md) - -## ISearchOptions.signal property - -Signature: - -```typescript -signal?: AbortSignal; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.strategy.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.strategy.md index df7e050691a8f..bd2580957f6c1 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.strategy.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.strategy.md @@ -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. + Signature: ```typescript diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index 0ab86e0f4dab2..b651480a85899 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -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) | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md similarity index 62% rename from docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md rename to docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md index 948dfd66da7a0..693345f480a9a 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md @@ -1,13 +1,13 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) > [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) > [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. Signature: ```typescript -signal?: AbortSignal; +abortSignal?: AbortSignal; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md index 002ce864a1aa4..21ddaef3a0b94 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md @@ -14,6 +14,6 @@ export interface ISearchOptions | Property | Type | Description | | --- | --- | --- | -| [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) | AbortSignal | An AbortSignal that allows the caller of search to abort a search request. | -| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | string | | +| [abortSignal](./kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md) | AbortSignal | An AbortSignal that allows the caller of search to abort a search request. | +| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | string | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md index 6df72d023e2c0..65da7fddd13f6 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md @@ -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. + Signature: ```typescript diff --git a/src/plugins/data/common/search/aggs/agg_config.ts b/src/plugins/data/common/search/aggs/agg_config.ts index b5747ce7bb9bd..201e9f1ec402c 100644 --- a/src/plugins/data/common/search/aggs/agg_config.ts +++ b/src/plugins/data/common/search/aggs/agg_config.ts @@ -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'; @@ -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} */ - onSearchRequestStart(searchSource: ISearchSource, options?: FetchOptions) { + onSearchRequestStart(searchSource: ISearchSource, options?: ISearchOptions) { if (!this.type) { return Promise.resolve(); } diff --git a/src/plugins/data/common/search/aggs/agg_configs.ts b/src/plugins/data/common/search/aggs/agg_configs.ts index 203eda3a907ee..282e6f3b538a4 100644 --- a/src/plugins/data/common/search/aggs/agg_configs.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.ts @@ -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'; @@ -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)) diff --git a/src/plugins/data/common/search/aggs/param_types/base.ts b/src/plugins/data/common/search/aggs/param_types/base.ts index 3a12a9a54500f..c0316c974e26f 100644 --- a/src/plugins/data/common/search/aggs/param_types/base.ts +++ b/src/plugins/data/common/search/aggs/param_types/base.ts @@ -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'; @@ -56,7 +56,7 @@ export class BaseParamType { modifyAggConfigOnSearchRequestStart: ( aggConfig: TAggConfig, searchSource?: ISearchSource, - options?: FetchOptions + options?: ISearchOptions ) => void; constructor(config: Record) { diff --git a/src/plugins/data/common/search/es_search/index.ts b/src/plugins/data/common/search/es_search/index.ts index 7bc9cada8f0ee..54757b53b8665 100644 --- a/src/plugins/data/common/search/es_search/index.ts +++ b/src/plugins/data/common/search/es_search/index.ts @@ -22,4 +22,5 @@ export { IEsSearchRequest, IEsSearchResponse, ES_SEARCH_STRATEGY, + ISearchOptions, } from './types'; diff --git a/src/plugins/data/common/search/es_search/types.ts b/src/plugins/data/common/search/es_search/types.ts index 3184fbe341705..89faa5b7119c8 100644 --- a/src/plugins/data/common/search/es_search/types.ts +++ b/src/plugins/data/common/search/es_search/types.ts @@ -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> = { trackTotalHits?: boolean; } & Search; diff --git a/src/plugins/data/common/search/index.ts b/src/plugins/data/common/search/index.ts index d8184551b7f3d..3bfb0ddb89aa9 100644 --- a/src/plugins/data/common/search/index.ts +++ b/src/plugins/data/common/search/index.ts @@ -28,4 +28,5 @@ export { IEsSearchResponse, ES_SEARCH_STRATEGY, ISearchRequestParams, + ISearchOptions, } from './es_search'; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index a9714a95ff338..f7b4111df5172 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -342,7 +342,6 @@ export { ES_SEARCH_STRATEGY, EsQuerySortValue, extractSearchSourceReferences, - FetchOptions, getEsPreference, getSearchParamsFromRequest, IEsSearchRequest, @@ -352,7 +351,6 @@ export { injectSearchSourceReferences, ISearch, ISearchGeneric, - ISearchOptions, ISearchSource, parseSearchSourceJSON, RequestTimeoutError, @@ -367,6 +365,8 @@ export { EsRawResponseExpressionTypeDefinition, } from './search'; +export { ISearchOptions } from '../common'; + // Search namespace export const search = { aggs: { diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index e72fea160cc28..9f727d86b06e1 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -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'; @@ -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) @@ -1233,9 +1223,7 @@ export type ISearchGeneric = ({ body: dsl, }, }, - { signal: abortSignal } + { abortSignal } ) .toPromise(); diff --git a/src/plugins/data/public/search/fetch/types.ts b/src/plugins/data/public/search/fetch/types.ts index 670c4f731971a..81146c6b74c05 100644 --- a/src/plugins/data/public/search/fetch/types.ts +++ b/src/plugins/data/public/search/fetch/types.ts @@ -29,11 +29,6 @@ import { ISearchStartLegacy } from '../types'; */ export type SearchRequest = Record; -export interface FetchOptions { - abortSignal?: AbortSignal; - searchStrategyId?: string; -} - export interface FetchHandlers { legacySearchService: ISearchStartLegacy; config: { get: GetConfigFn }; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index 14eff13b378ee..a6a1736ac91da 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -19,14 +19,7 @@ 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'; @@ -34,7 +27,7 @@ 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, diff --git a/src/plugins/data/public/search/legacy/call_client.ts b/src/plugins/data/public/search/legacy/call_client.ts index 3dcf11f72a742..d66796b9427a1 100644 --- a/src/plugins/data/public/search/legacy/call_client.ts +++ b/src/plugins/data/public/search/legacy/call_client.ts @@ -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(requestOptionEntries); + const requestOptionsMap = new Map(requestOptionEntries); const requestResponseMap = new Map>>(); const { searching, abort } = defaultSearchStrategy.search({ diff --git a/src/plugins/data/public/search/legacy/fetch_soon.test.ts b/src/plugins/data/public/search/legacy/fetch_soon.test.ts index d7a85e65b475d..d38a41cf5ffbc 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.test.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.test.ts @@ -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]; @@ -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); diff --git a/src/plugins/data/public/search/legacy/fetch_soon.ts b/src/plugins/data/public/search/legacy/fetch_soon.ts index 16920a8a4dd97..37c3827bb7bba 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.ts @@ -19,9 +19,9 @@ import { SearchResponse } from 'elasticsearch'; import { callClient } from './call_client'; -import { FetchHandlers, FetchOptions } from '../fetch/types'; +import { FetchHandlers } from '../fetch/types'; import { SearchRequest } from '../index'; -import { UI_SETTINGS } from '../../../common'; +import { UI_SETTINGS, ISearchOptions } from '../../../common'; /** * This function introduces a slight delay in the request process to allow multiple requests to queue @@ -29,7 +29,7 @@ import { UI_SETTINGS } from '../../../common'; */ export async function fetchSoon( request: SearchRequest, - options: FetchOptions, + options: ISearchOptions, fetchHandlers: FetchHandlers ) { const msToDelay = fetchHandlers.config.get(UI_SETTINGS.COURIER_BATCH_SEARCHES) ? 50 : 0; @@ -51,7 +51,7 @@ function delay(fn: (...args: any) => T, ms: number): Promise { // The current batch/queue of requests to fetch let requestsToFetch: SearchRequest[] = []; -let requestOptions: FetchOptions[] = []; +let requestOptions: ISearchOptions[] = []; // The in-progress fetch (if there is one) let fetchInProgress: any = null; @@ -65,7 +65,7 @@ let fetchInProgress: any = null; */ async function delayedFetch( request: SearchRequest, - options: FetchOptions, + options: ISearchOptions, fetchHandlers: FetchHandlers, ms: number ): Promise> { diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts index 2eded17bda88c..da60f39b522ac 100644 --- a/src/plugins/data/public/search/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor.test.ts @@ -112,7 +112,9 @@ describe('SearchInterceptor', () => { const mockRequest: IEsSearchRequest = { params: {}, }; - const response = searchInterceptor.search(mockRequest, { signal: abortController.signal }); + const response = searchInterceptor.search(mockRequest, { + abortSignal: abortController.signal, + }); const next = jest.fn(); const error = (e: any) => { @@ -131,7 +133,7 @@ describe('SearchInterceptor', () => { const mockRequest: IEsSearchRequest = { params: {}, }; - const response = searchInterceptor.search(mockRequest, { signal: abort.signal }); + const response = searchInterceptor.search(mockRequest, { abortSignal: abort.signal }); abort.abort(); const error = (e: any) => { diff --git a/src/plugins/data/public/search/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor.ts index 30e509edd4987..c6c03267163c9 100644 --- a/src/plugins/data/public/search/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor.ts @@ -22,8 +22,12 @@ import { BehaviorSubject, throwError, timer, Subscription, defer, from, Observab import { finalize, filter } from 'rxjs/operators'; import { Toast, CoreStart, ToastsSetup, CoreSetup } from 'kibana/public'; import { getCombinedSignal, AbortError } from '../../common/utils'; -import { IEsSearchRequest, IEsSearchResponse, ES_SEARCH_STRATEGY } from '../../common/search'; -import { ISearchOptions } from './types'; +import { + IEsSearchRequest, + IEsSearchResponse, + ISearchOptions, + ES_SEARCH_STRATEGY, +} from '../../common/search'; import { getLongQueryNotification } from './long_query_notification'; import { SearchUsageCollector } from './collectors'; @@ -128,7 +132,7 @@ export class SearchInterceptor { ): Observable { // Defer the following logic until `subscribe` is actually called return defer(() => { - if (options?.signal?.aborted) { + if (options?.abortSignal?.aborted) { return throwError(new AbortError()); } @@ -164,7 +168,7 @@ export class SearchInterceptor { const signals = [ this.abortController.signal, timeoutSignal, - ...(options?.signal ? [options.signal] : []), + ...(options?.abortSignal ? [options.abortSignal] : []), ]; const combinedSignal = getCombinedSignal(signals); diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index d2e3370762059..3a567501a7540 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -78,14 +78,19 @@ import { fieldWildcardFilter } from '../../../../kibana_utils/common'; import { IIndexPattern, ISearchGeneric } from '../..'; import { SearchSourceOptions, SearchSourceFields } from './types'; import { - FetchOptions, RequestFailure, handleResponse, getSearchParamsFromRequest, SearchRequest, } from '../fetch'; -import { getEsQueryConfig, buildEsQuery, Filter, UI_SETTINGS } from '../../../common'; +import { + getEsQueryConfig, + buildEsQuery, + Filter, + UI_SETTINGS, + ISearchOptions, +} from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; import { GetConfigFn } from '../../../common/types'; import { fetchSoon } from '../legacy'; @@ -121,7 +126,7 @@ export class SearchSource { private searchStrategyId?: string; private parent?: SearchSource; private requestStartHandlers: Array< - (searchSource: SearchSource, options?: FetchOptions) => Promise + (searchSource: SearchSource, options?: ISearchOptions) => Promise > = []; private inheritOptions: SearchSourceOptions = {}; public history: SearchRequest[] = []; @@ -225,7 +230,7 @@ export class SearchSource { * Run a search using the search service * @return {Observable>} */ - private fetch$(searchRequest: SearchRequest, signal?: AbortSignal) { + private fetch$(searchRequest: SearchRequest, options: ISearchOptions) { const { search, esShardTimeout, getConfig } = this.dependencies; const params = getSearchParamsFromRequest(searchRequest, { @@ -233,7 +238,7 @@ export class SearchSource { getConfig, }); - return search({ params, indexType: searchRequest.indexType }, { signal }).pipe( + return search({ params, indexType: searchRequest.indexType }, options).pipe( map(({ rawResponse }) => handleResponse(searchRequest, rawResponse)) ); } @@ -242,7 +247,7 @@ export class SearchSource { * Run a search using the search service * @return {Promise>} */ - private async legacyFetch(searchRequest: SearchRequest, options: FetchOptions) { + private async legacyFetch(searchRequest: SearchRequest, options: ISearchOptions) { const { esShardTimeout, legacySearch, getConfig } = this.dependencies; return await fetchSoon( @@ -263,7 +268,7 @@ export class SearchSource { * * @async */ - async fetch(options: FetchOptions = {}) { + async fetch(options: ISearchOptions = {}) { const { getConfig } = this.dependencies; await this.requestIsStarting(options); @@ -274,7 +279,7 @@ export class SearchSource { if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) { response = await this.legacyFetch(searchRequest, options); } else { - response = await this.fetch$(searchRequest, options.abortSignal).toPromise(); + response = await this.fetch$(searchRequest, options).toPromise(); } // TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved @@ -291,7 +296,7 @@ export class SearchSource { * @return {undefined} */ onRequestStart( - handler: (searchSource: SearchSource, options?: FetchOptions) => Promise + handler: (searchSource: SearchSource, options?: ISearchOptions) => Promise ) { this.requestStartHandlers.push(handler); } @@ -318,7 +323,7 @@ export class SearchSource { * @param options * @return {Promise} */ - private requestIsStarting(options: FetchOptions = {}) { + private requestIsStarting(options: ISearchOptions = {}) { const handlers = [...this.requestStartHandlers]; // If callParentStartHandlers has been set to true, we also call all // handlers of parent search sources. diff --git a/src/plugins/data/public/search/types.ts b/src/plugins/data/public/search/types.ts index 55726e40f5a77..b0ac730d8afb1 100644 --- a/src/plugins/data/public/search/types.ts +++ b/src/plugins/data/public/search/types.ts @@ -29,15 +29,11 @@ import { IKibanaSearchResponse, IEsSearchRequest, IEsSearchResponse, + ISearchOptions, } from '../../common/search'; import { IndexPatternsContract } from '../../common/index_patterns/index_patterns'; import { UsageCollectionSetup } from '../../../usage_collection/public'; -export interface ISearchOptions { - signal?: AbortSignal; - strategy?: string; -} - export type ISearch = ( request: IKibanaSearchRequest, options?: ISearchOptions diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index c3b06992dba0e..f300fb0779e38 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -198,6 +198,7 @@ export { OptionedValueProp, ParsedInterval, // search + ISearchOptions, IEsSearchRequest, IEsSearchResponse, // tabify @@ -208,7 +209,6 @@ export { export { ISearchStrategy, - ISearchOptions, ISearchSetup, ISearchStart, getDefaultSearchParams, diff --git a/src/plugins/data/server/search/index.ts b/src/plugins/data/server/search/index.ts index 02c21c3254645..8a74c51f52f51 100644 --- a/src/plugins/data/server/search/index.ts +++ b/src/plugins/data/server/search/index.ts @@ -17,13 +17,7 @@ * under the License. */ -export { - ISearchStrategy, - ISearchOptions, - ISearchSetup, - ISearchStart, - SearchEnhancements, -} from './types'; +export { ISearchStrategy, ISearchSetup, ISearchStart, SearchEnhancements } from './types'; export { getDefaultSearchParams, getTotalLoaded } from './es_search'; diff --git a/src/plugins/data/server/search/routes.ts b/src/plugins/data/server/search/routes.ts index 3d813f745305f..be5c8d035edff 100644 --- a/src/plugins/data/server/search/routes.ts +++ b/src/plugins/data/server/search/routes.ts @@ -42,7 +42,7 @@ export function registerSearchRoute(core: CoreSetup): v async (context, request, res) => { const searchRequest = request.body; const { strategy, id } = request.params; - const signal = getRequestAbortedSignal(request.events.aborted$); + const abortSignal = getRequestAbortedSignal(request.events.aborted$); const [, , selfStart] = await core.getStartServices(); @@ -51,7 +51,7 @@ export function registerSearchRoute(core: CoreSetup): v context, { ...searchRequest, id }, { - signal, + abortSignal, strategy, } ); diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index edc94961c79d8..da14995af1fa4 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -37,7 +37,7 @@ import { UsageCollectionSetup } from '../../../usage_collection/server'; import { registerUsageCollector } from './collectors/register'; import { usageProvider } from './collectors/usage'; import { searchTelemetry } from '../saved_objects'; -import { IEsSearchRequest, IEsSearchResponse } from '../../common'; +import { IEsSearchRequest, IEsSearchResponse, ISearchOptions } from '../../common'; type StrategyMap< SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest, @@ -102,11 +102,13 @@ export class SearchService implements Plugin { private search( context: RequestHandlerContext, searchRequest: IEsSearchRequest, - options: Record + options: ISearchOptions ) { - return this.getSearchStrategy( - options.strategy || this.defaultSearchStrategyName - ).search(context, searchRequest, { signal: options.signal }); + return this.getSearchStrategy(options.strategy || this.defaultSearchStrategyName).search( + context, + searchRequest, + options + ); } public start( diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 5ce1bb3e6b9f8..6ce8430d0573b 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -18,7 +18,7 @@ */ import { RequestHandlerContext } from '../../../../core/server'; -import { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; +import { IKibanaSearchResponse, IKibanaSearchRequest, ISearchOptions } from '../../common/search'; import { AggsSetup, AggsStart } from './aggs'; import { SearchUsage } from './collectors/usage'; import { IEsSearchRequest, IEsSearchResponse } from './es_search'; @@ -27,14 +27,6 @@ export interface SearchEnhancements { defaultStrategy: string; } -export interface ISearchOptions { - /** - * An `AbortSignal` that allows the caller of `search` to abort a search request. - */ - signal?: AbortSignal; - strategy?: string; -} - export interface ISearchSetup { aggs: AggsSetup; /** diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 9497a41b45ff9..93f924493c3b4 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -48,7 +48,6 @@ import { ExistsParams } from 'elasticsearch'; import { ExplainParams } from 'elasticsearch'; import { ExpressionAstFunction } from 'src/plugins/expressions/common'; import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; -import { FetchOptions } from 'src/plugins/data/public'; import { FieldStatsParams } from 'elasticsearch'; import { GenericParams } from 'elasticsearch'; import { GetParams } from 'elasticsearch'; @@ -99,6 +98,7 @@ import { IngestDeletePipelineParams } from 'elasticsearch'; import { IngestGetPipelineParams } from 'elasticsearch'; import { IngestPutPipelineParams } from 'elasticsearch'; import { IngestSimulateParams } from 'elasticsearch'; +import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public'; import { ISearchSource } from 'src/plugins/data/public'; import { KibanaClient } from '@elastic/elasticsearch/api/kibana'; import { KibanaConfigType as KibanaConfigType_2 } from 'src/core/server/kibana_config'; @@ -678,8 +678,7 @@ export class IndexPatternsFetcher { // // @public (undocumented) export interface ISearchOptions { - signal?: AbortSignal; - // (undocumented) + abortSignal?: AbortSignal; strategy?: string; } diff --git a/src/plugins/vis_type_vega/public/data_model/search_api.ts b/src/plugins/vis_type_vega/public/data_model/search_api.ts index d2ce8c95b9f90..8a1541ecae0d4 100644 --- a/src/plugins/vis_type_vega/public/data_model/search_api.ts +++ b/src/plugins/vis_type_vega/public/data_model/search_api.ts @@ -62,7 +62,7 @@ export class SearchAPI { requestResponders[requestId].json(params.body); } - return search({ params }, { signal: this.abortSignal }).pipe( + return search({ params }, { abortSignal: this.abortSignal }).pipe( tap((data) => this.inspectSearchResult(data, requestResponders[requestId])), map((data) => ({ name: requestId, diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts index fe954f1602cd3..1e2c7987b7041 100644 --- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts @@ -189,7 +189,7 @@ describe('EnhancedSearchInterceptor', () => { const abortController = new AbortController(); abortController.abort(); - const response = searchInterceptor.search({}, { signal: abortController.signal }); + const response = searchInterceptor.search({}, { abortSignal: abortController.signal }); response.subscribe({ next, error }); await timeTravel(500); @@ -225,7 +225,7 @@ describe('EnhancedSearchInterceptor', () => { const response = searchInterceptor.search( {}, - { signal: abortController.signal, pollInterval: 0 } + { abortSignal: abortController.signal, pollInterval: 0 } ); response.subscribe({ next, error }); diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 46609af52d072..67a42b9954c9d 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -19,11 +19,10 @@ import { getTotalLoaded, ISearchStrategy, SearchUsage, - ISearchOptions, } from '../../../../../src/plugins/data/server'; import { IEnhancedEsSearchRequest } from '../../common'; import { shimHitsTotal } from './shim_hits_total'; -import { IEsSearchResponse } from '../../../../../src/plugins/data/common/search/es_search'; +import { ISearchOptions, IEsSearchResponse } from '../../../../../src/plugins/data/common/search'; function isEnhancedEsSearchResponse(response: any): response is IEsSearchResponse { return response.hasOwnProperty('isPartial') && response.hasOwnProperty('isRunning'); diff --git a/x-pack/plugins/security_solution/public/hosts/containers/hosts/first_last_seen/index.tsx b/x-pack/plugins/security_solution/public/hosts/containers/hosts/first_last_seen/index.tsx index 3a93b1ee46e7b..169fe58e9a2cc 100644 --- a/x-pack/plugins/security_solution/public/hosts/containers/hosts/first_last_seen/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/containers/hosts/first_last_seen/index.tsx @@ -68,7 +68,7 @@ export const useFirstLastSeenHost = ({ const searchSubscription$ = data.search .search(request, { strategy: 'securitySolutionSearchStrategy', - signal: abortCtrl.current.signal, + abortSignal: abortCtrl.current.signal, }) .subscribe({ next: (response) => { diff --git a/x-pack/plugins/security_solution/public/hosts/containers/hosts/index.tsx b/x-pack/plugins/security_solution/public/hosts/containers/hosts/index.tsx index bc711d08065e2..c545a7a75457b 100644 --- a/x-pack/plugins/security_solution/public/hosts/containers/hosts/index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/containers/hosts/index.tsx @@ -131,7 +131,7 @@ export const useAllHost = ({ const searchSubscription$ = data.search .search(request, { strategy: 'securitySolutionSearchStrategy', - signal: abortCtrl.current.signal, + abortSignal: abortCtrl.current.signal, }) .subscribe({ next: (response) => { diff --git a/x-pack/plugins/security_solution/public/hosts/containers/hosts/overview/_index.tsx b/x-pack/plugins/security_solution/public/hosts/containers/hosts/overview/_index.tsx index a72ef0ff1c46e..b28f479634d42 100644 --- a/x-pack/plugins/security_solution/public/hosts/containers/hosts/overview/_index.tsx +++ b/x-pack/plugins/security_solution/public/hosts/containers/hosts/overview/_index.tsx @@ -89,7 +89,7 @@ export const useHostOverview = ({ const searchSubscription$ = data.search .search(request, { strategy: 'securitySolutionSearchStrategy', - signal: abortCtrl.current.signal, + abortSignal: abortCtrl.current.signal, }) .subscribe({ next: (response) => { diff --git a/x-pack/plugins/security_solution/public/network/containers/network_http/index.tsx b/x-pack/plugins/security_solution/public/network/containers/network_http/index.tsx index d71953eec026f..857d7fe0229b2 100644 --- a/x-pack/plugins/security_solution/public/network/containers/network_http/index.tsx +++ b/x-pack/plugins/security_solution/public/network/containers/network_http/index.tsx @@ -126,7 +126,7 @@ export const useNetworkHttp = ({ const searchSubscription$ = data.search .search(request, { strategy: 'securitySolutionSearchStrategy', - signal: abortCtrl.current.signal, + abortSignal: abortCtrl.current.signal, }) .subscribe({ next: (response) => { diff --git a/x-pack/plugins/security_solution/public/network/containers/tls/index.tsx b/x-pack/plugins/security_solution/public/network/containers/tls/index.tsx index 1c2604ee65552..df02acf208603 100644 --- a/x-pack/plugins/security_solution/public/network/containers/tls/index.tsx +++ b/x-pack/plugins/security_solution/public/network/containers/tls/index.tsx @@ -125,7 +125,7 @@ export const useNetworkTls = ({ const searchSubscription$ = data.search .search(request, { strategy: 'securitySolutionSearchStrategy', - signal: abortCtrl.current.signal, + abortSignal: abortCtrl.current.signal, }) .subscribe({ next: (response) => { From 7134cd7b7e4fb6b43727df1e6fc5681666baca88 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 3 Sep 2020 11:36:27 +0200 Subject: [PATCH 03/10] [Discover] Fix sidebar element focus behavior when adding / removing columns (#75749) * Use field.name instead of idx for key in li element * onClick adds focus to button * prevent Chrome jumping back to last focused element --- .../public/application/angular/discover.html | 9 ++++---- .../components/sidebar/discover_field.tsx | 6 +++++ .../components/sidebar/discover_sidebar.tsx | 22 +++++++++---------- .../sidebar/discover_sidebar_directive.ts | 1 - .../public/field_button/field_button.tsx | 11 +++++++++- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/plugins/discover/public/application/angular/discover.html b/src/plugins/discover/public/application/angular/discover.html index d3d4f524873d8..94f13e1cd8132 100644 --- a/src/plugins/discover/public/application/angular/discover.html +++ b/src/plugins/discover/public/application/angular/discover.html @@ -31,7 +31,6 @@

{{screenTitle}}

on-remove-field="removeColumn" selected-index-pattern="searchSource.getField('index')" set-index-pattern="setIndexPattern" - state="state" > @@ -78,11 +77,11 @@

{{screenTitle}}

class="dscTimechart" ng-if="opts.timefield" > - ) => { + if (ev.type === 'click') { + ev.currentTarget.focus(); + } ev.preventDefault(); ev.stopPropagation(); toggleDisplay(field); @@ -155,6 +158,9 @@ export function DiscoverField({ iconType="cross" className="dscSidebarItem__action" onClick={(ev: React.MouseEvent) => { + if (ev.type === 'click') { + ev.currentTarget.focus(); + } ev.preventDefault(); ev.stopPropagation(); toggleDisplay(field); diff --git a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx index 361c0707fef6b..850624888b24a 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx +++ b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx @@ -30,7 +30,6 @@ import { SavedObject } from '../../../../../../core/types'; import { FIELDS_LIMIT_SETTING } from '../../../../common'; import { groupFields } from './lib/group_fields'; import { IndexPatternField, IndexPattern, UI_SETTINGS } from '../../../../../data/public'; -import { AppState } from '../../angular/discover_state'; import { getDetails } from './lib/get_details'; import { getDefaultFieldFilter, setFieldFilterProp } from './lib/field_filter'; import { getIndexPatternFieldList } from './lib/get_index_pattern_field_list'; @@ -74,10 +73,6 @@ export interface DiscoverSidebarProps { * Callback function to select another index pattern */ setIndexPattern: (id: string) => void; - /** - * Current app state, used for generating a link to visualize - */ - state: AppState; } export function DiscoverSidebar({ @@ -90,7 +85,6 @@ export function DiscoverSidebar({ onRemoveField, selectedIndexPattern, setIndexPattern, - state, }: DiscoverSidebarProps) { const [showFields, setShowFields] = useState(false); const [fields, setFields] = useState(null); @@ -185,10 +179,10 @@ export function DiscoverSidebar({ aria-labelledby="selected_fields" data-test-subj={`fieldList-selected`} > - {selectedFields.map((field: IndexPatternField, idx: number) => { + {selectedFields.map((field: IndexPatternField) => { return (
  • @@ -260,10 +254,10 @@ export function DiscoverSidebar({ aria-labelledby="available_fields available_fields_popular" data-test-subj={`fieldList-popular`} > - {popularFields.map((field: IndexPatternField, idx: number) => { + {popularFields.map((field: IndexPatternField) => { return (
  • @@ -290,9 +284,13 @@ export function DiscoverSidebar({ aria-labelledby="available_fields" data-test-subj={`fieldList-unpopular`} > - {unpopularFields.map((field: IndexPatternField, idx: number) => { + {unpopularFields.map((field: IndexPatternField) => { return ( -
  • +
  • -