|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { i18n } from '@kbn/i18n'; |
| 21 | +import { ExpressionFunctionDefinition } from '../../../../../plugins/expressions/public'; |
| 22 | +import { getIndexPatterns } from '../../services'; |
| 23 | +import { IndexPatternSpec } from '../../../common/index_patterns'; |
| 24 | + |
| 25 | +const name = 'indexPatternLoad'; |
| 26 | + |
| 27 | +type Input = null; |
| 28 | +type Output = Promise<{ type: 'index_pattern'; value: IndexPatternSpec }>; |
| 29 | + |
| 30 | +interface Arguments { |
| 31 | + id: string; |
| 32 | +} |
| 33 | + |
| 34 | +export const indexPatternLoad = (): ExpressionFunctionDefinition< |
| 35 | + typeof name, |
| 36 | + Input, |
| 37 | + Arguments, |
| 38 | + Output |
| 39 | +> => ({ |
| 40 | + name, |
| 41 | + type: 'index_pattern', |
| 42 | + inputTypes: ['null'], |
| 43 | + help: i18n.translate('data.functions.indexPatternLoad.help', { |
| 44 | + defaultMessage: 'Loads an index pattern', |
| 45 | + }), |
| 46 | + args: { |
| 47 | + id: { |
| 48 | + types: ['string'], |
| 49 | + required: true, |
| 50 | + help: i18n.translate('data.functions.indexPatternLoad.id.help', { |
| 51 | + defaultMessage: 'index pattern id to load', |
| 52 | + }), |
| 53 | + }, |
| 54 | + }, |
| 55 | + async fn(input, args) { |
| 56 | + const indexPatterns = getIndexPatterns(); |
| 57 | + |
| 58 | + const indexPattern = await indexPatterns.get(args.id); |
| 59 | + |
| 60 | + return { type: 'index_pattern', value: indexPattern.toSpec() }; |
| 61 | + }, |
| 62 | +}); |
0 commit comments