diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/exists.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/exists.js deleted file mode 100644 index 6c149b6b8a98d5..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/exists.js +++ /dev/null @@ -1,55 +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 expect from '@kbn/expect'; -import { convertExistsFilter } from '../exists'; - -describe('filter to kuery migration', function () { - - describe('exists filter', function () { - - it('should return a kuery node equivalent to the given filter', function () { - const filter = { - meta: { - type: 'exists', - key: 'foo', - } - }; - const result = convertExistsFilter(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'exists'); - expect(result.arguments[0].value).to.be('foo'); - }); - - it('should throw an exception if the given filter is not of type "exists"', function () { - const filter = { - meta: { - type: 'foo' - } - }; - - expect(convertExistsFilter).withArgs(filter).to.throwException( - /Expected filter of type "exists", got "foo"/ - ); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/filter_to_kuery.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/filter_to_kuery.js deleted file mode 100644 index 1e5656f85eb89d..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/filter_to_kuery.js +++ /dev/null @@ -1,70 +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 _ from 'lodash'; -import expect from '@kbn/expect'; -import { filterToKueryAST } from '../filter_to_kuery'; - -describe('filter to kuery migration', function () { - - describe('filterToKueryAST', function () { - - it('should hand off conversion of known filter types to the appropriate converter', function () { - const filter = { - meta: { - type: 'exists', - key: 'foo', - } - }; - const result = filterToKueryAST(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'exists'); - }); - - it('should thrown an error when an unknown filter type is encountered', function () { - const filter = { - meta: { - type: 'foo', - } - }; - - expect(filterToKueryAST).withArgs(filter).to.throwException(/Couldn't convert that filter to a kuery/); - }); - - it('should wrap the AST node of negated filters in a "not" function', function () { - const filter = { - meta: { - type: 'exists', - key: 'foo', - } - }; - const negatedFilter = _.set(_.cloneDeep(filter), 'meta.negate', true); - - const result = filterToKueryAST(filter); - const negatedResult = filterToKueryAST(negatedFilter); - - expect(negatedResult).to.have.property('type', 'function'); - expect(negatedResult).to.have.property('function', 'not'); - expect(negatedResult.arguments[0]).to.eql(result); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_bounding_box.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_bounding_box.js deleted file mode 100644 index e4cb6d30bbf481..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_bounding_box.js +++ /dev/null @@ -1,72 +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 _ from 'lodash'; -import expect from '@kbn/expect'; -import { convertGeoBoundingBox } from '../geo_bounding_box'; - -describe('filter to kuery migration', function () { - - describe('geo_bounding_box filter', function () { - - it('should return a kuery node equivalent to the given filter', function () { - const filter = { - meta: { - type: 'geo_bounding_box', - key: 'foo', - params: { - topLeft: { - lat: 10, - lon: 20, - }, - bottomRight: { - lat: 30, - lon: 40, - }, - }, - } - }; - const result = convertGeoBoundingBox(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'geoBoundingBox'); - - const { arguments: [ { value: fieldName }, ...args ] } = result; - expect(fieldName).to.be('foo'); - - const argByName = _.mapKeys(args, 'name'); - expect(argByName.topLeft.value.value).to.be('10, 20'); - expect(argByName.bottomRight.value.value).to.be('30, 40'); - }); - - it('should throw an exception if the given filter is not of type "geo_bounding_box"', function () { - const filter = { - meta: { - type: 'foo' - } - }; - - expect(convertGeoBoundingBox).withArgs(filter).to.throwException( - /Expected filter of type "geo_bounding_box", got "foo"/ - ); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_polygon.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_polygon.js deleted file mode 100644 index e1b2a09edaba37..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/geo_polygon.js +++ /dev/null @@ -1,72 +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 expect from '@kbn/expect'; -import { convertGeoPolygon } from '../geo_polygon'; - -describe('filter to kuery migration', function () { - - describe('geo_polygon filter', function () { - - it('should return a kuery node equivalent to the given filter', function () { - const filter = { - meta: { - type: 'geo_polygon', - key: 'foo', - params: { - points: [ - { - lat: 10, - lon: 20, - }, - { - lat: 30, - lon: 40, - }, - ] - } - } - }; - const result = convertGeoPolygon(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'geoPolygon'); - - const { arguments: [ { value: fieldName }, ...args ] } = result; - expect(fieldName).to.be('foo'); - - expect(args[0].value).to.be('10, 20'); - expect(args[1].value).to.be('30, 40'); - }); - - it('should throw an exception if the given filter is not of type "geo_polygon"', function () { - const filter = { - meta: { - type: 'foo' - } - }; - - expect(convertGeoPolygon).withArgs(filter).to.throwException( - /Expected filter of type "geo_polygon", got "foo"/ - ); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/phrase.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/phrase.js deleted file mode 100644 index b2a7c097a3f95d..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/phrase.js +++ /dev/null @@ -1,61 +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 expect from '@kbn/expect'; -import { convertPhraseFilter } from '../phrase'; - -describe('filter to kuery migration', function () { - - describe('phrase filter', function () { - - it('should return a kuery node equivalent to the given filter', function () { - const filter = { - meta: { - type: 'phrase', - key: 'foo', - params: { - query: 'bar' - }, - } - }; - const result = convertPhraseFilter(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'is'); - - const { arguments: [ { value: fieldName }, { value: value } ] } = result; - expect(fieldName).to.be('foo'); - expect(value).to.be('bar'); - }); - - it('should throw an exception if the given filter is not of type "phrase"', function () { - const filter = { - meta: { - type: 'foo' - } - }; - - expect(convertPhraseFilter).withArgs(filter).to.throwException( - /Expected filter of type "phrase", got "foo"/ - ); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/range.js b/packages/kbn-es-query/src/kuery/filter_migration/__tests__/range.js deleted file mode 100644 index 2cad37cc0ad3ac..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/__tests__/range.js +++ /dev/null @@ -1,66 +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 _ from 'lodash'; -import expect from '@kbn/expect'; -import { convertRangeFilter } from '../range'; - -describe('filter to kuery migration', function () { - - describe('range filter', function () { - - it('should return a kuery node equivalent to the given filter', function () { - const filter = { - meta: { - type: 'range', - key: 'foo', - params: { - gt: 1000, - lt: 8000, - }, - } - }; - const result = convertRangeFilter(filter); - - expect(result).to.have.property('type', 'function'); - expect(result).to.have.property('function', 'range'); - - const { arguments: [ { value: fieldName }, ...args ] } = result; - expect(fieldName).to.be('foo'); - - const argByName = _.mapKeys(args, 'name'); - expect(argByName.gt.value.value).to.be(1000); - expect(argByName.lt.value.value).to.be(8000); - }); - - it('should throw an exception if the given filter is not of type "range"', function () { - const filter = { - meta: { - type: 'foo' - } - }; - - expect(convertRangeFilter).withArgs(filter).to.throwException( - /Expected filter of type "range", got "foo"/ - ); - }); - - }); - -}); diff --git a/packages/kbn-es-query/src/kuery/filter_migration/exists.js b/packages/kbn-es-query/src/kuery/filter_migration/exists.js deleted file mode 100644 index ce6403d681b564..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/exists.js +++ /dev/null @@ -1,29 +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 { nodeTypes } from '../node_types'; - -export function convertExistsFilter(filter) { - if (filter.meta.type !== 'exists') { - throw new Error(`Expected filter of type "exists", got "${filter.meta.type}"`); - } - - const { key } = filter.meta; - return nodeTypes.function.buildNode('exists', key); -} diff --git a/packages/kbn-es-query/src/kuery/filter_migration/filter_to_kuery.js b/packages/kbn-es-query/src/kuery/filter_migration/filter_to_kuery.js deleted file mode 100644 index 18c53938d6c36f..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/filter_to_kuery.js +++ /dev/null @@ -1,54 +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 { nodeTypes } from '../node_types'; -import { convertPhraseFilter } from './phrase'; -import { convertRangeFilter } from './range'; -import { convertExistsFilter } from './exists'; -import { convertGeoBoundingBox } from './geo_bounding_box'; -import { convertGeoPolygon } from './geo_polygon'; - -const conversionChain = [ - convertPhraseFilter, - convertRangeFilter, - convertExistsFilter, - convertGeoBoundingBox, - convertGeoPolygon, -]; - -export function filterToKueryAST(filter) { - const { negate } = filter.meta; - - const node = conversionChain.reduce((acc, converter) => { - if (acc !== null) return acc; - - try { - return converter(filter); - } - catch (ex) { - return null; - } - }, null); - - if (!node) { - throw new Error(`Couldn't convert that filter to a kuery`); - } - - return negate ? nodeTypes.function.buildNode('not', node) : node; -} diff --git a/packages/kbn-es-query/src/kuery/filter_migration/geo_bounding_box.js b/packages/kbn-es-query/src/kuery/filter_migration/geo_bounding_box.js deleted file mode 100644 index deaf258418ed49..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/geo_bounding_box.js +++ /dev/null @@ -1,31 +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 _ from 'lodash'; -import { nodeTypes } from '../node_types'; - -export function convertGeoBoundingBox(filter) { - if (filter.meta.type !== 'geo_bounding_box') { - throw new Error(`Expected filter of type "geo_bounding_box", got "${filter.meta.type}"`); - } - - const { key, params } = filter.meta; - const camelParams = _.mapKeys(params, (value, key) => _.camelCase(key)); - return nodeTypes.function.buildNode('geoBoundingBox', key, camelParams); -} diff --git a/packages/kbn-es-query/src/kuery/filter_migration/geo_polygon.js b/packages/kbn-es-query/src/kuery/filter_migration/geo_polygon.js deleted file mode 100644 index 33701a0e4d8560..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/geo_polygon.js +++ /dev/null @@ -1,29 +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 { nodeTypes } from '../node_types'; - -export function convertGeoPolygon(filter) { - if (filter.meta.type !== 'geo_polygon') { - throw new Error(`Expected filter of type "geo_polygon", got "${filter.meta.type}"`); - } - - const { key, params: { points } } = filter.meta; - return nodeTypes.function.buildNode('geoPolygon', key, points); -} diff --git a/packages/kbn-es-query/src/kuery/filter_migration/index.js b/packages/kbn-es-query/src/kuery/filter_migration/index.js deleted file mode 100644 index f0dbb8f0a6a6af..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/index.js +++ /dev/null @@ -1,20 +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. - */ - -export { filterToKueryAST } from './filter_to_kuery'; diff --git a/packages/kbn-es-query/src/kuery/filter_migration/phrase.js b/packages/kbn-es-query/src/kuery/filter_migration/phrase.js deleted file mode 100644 index 49cde8aa97448f..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/phrase.js +++ /dev/null @@ -1,29 +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 { nodeTypes } from '../node_types'; - -export function convertPhraseFilter(filter) { - if (filter.meta.type !== 'phrase') { - throw new Error(`Expected filter of type "phrase", got "${filter.meta.type}"`); - } - - const { key, params } = filter.meta; - return nodeTypes.function.buildNode('is', key, params.query); -} diff --git a/packages/kbn-es-query/src/kuery/filter_migration/range.js b/packages/kbn-es-query/src/kuery/filter_migration/range.js deleted file mode 100644 index 438ab979e1395a..00000000000000 --- a/packages/kbn-es-query/src/kuery/filter_migration/range.js +++ /dev/null @@ -1,29 +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 { nodeTypes } from '../node_types'; - -export function convertRangeFilter(filter) { - if (filter.meta.type !== 'range') { - throw new Error(`Expected filter of type "range", got "${filter.meta.type}"`); - } - - const { key, params } = filter.meta; - return nodeTypes.function.buildNode('range', key, params); -} diff --git a/packages/kbn-es-query/src/kuery/index.js b/packages/kbn-es-query/src/kuery/index.js index 08fa9829d4a566..e0cacada7f274e 100644 --- a/packages/kbn-es-query/src/kuery/index.js +++ b/packages/kbn-es-query/src/kuery/index.js @@ -18,6 +18,5 @@ */ export * from './ast'; -export * from './filter_migration'; export { nodeTypes } from './node_types'; export * from './errors';