diff --git a/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts b/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts index 57158b84b86f9..af767b2be410e 100644 --- a/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts +++ b/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts @@ -9,11 +9,23 @@ import type { Type } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; -import { - PRIMITIVE_RUNTIME_FIELD_TYPES, - RUNTIME_FIELD_COMPOSITE_TYPE, +import type { + PrimitiveRuntimeFieldTypes, + RuntimeFieldCompositeType, } from '@kbn/data-views-plugin/common'; +const PRIMITIVE_RUNTIME_FIELD_TYPES: PrimitiveRuntimeFieldTypes = [ + 'keyword', + 'long', + 'double', + 'date', + 'ip', + 'boolean', + 'geo_point', +]; + +const RUNTIME_FIELD_COMPOSITE_TYPE: RuntimeFieldCompositeType = 'composite'; + const MAX_NAME_LENGTH = 1000; /** diff --git a/src/platform/packages/shared/as-code/data-views-schema/tsconfig.json b/src/platform/packages/shared/as-code/data-views-schema/tsconfig.json index d9b8689ec3554..0e45c4892d286 100644 --- a/src/platform/packages/shared/as-code/data-views-schema/tsconfig.json +++ b/src/platform/packages/shared/as-code/data-views-schema/tsconfig.json @@ -7,6 +7,6 @@ "exclude": ["target/**/*"], "kbn_references": [ "@kbn/config-schema", - "@kbn/data-views-plugin", + "@kbn/data-views-plugin" ] } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts index 8269d91948a99..b570a4c511b5b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts @@ -6,6 +6,7 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { DatatableState } from './datatable'; import { datatableStateSchema } from './datatable'; @@ -16,9 +17,9 @@ type DatatableWithoutDefaultsConfig = Omit { const baseDatatableConfig: Omit = { type: 'data_table', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, }; @@ -450,7 +451,7 @@ describe('Datatable Schema', () => { it('throws when using term buckets operation in an esql configuration', () => { const input: DatatableWithoutDefaultsConfig = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -473,7 +474,7 @@ describe('Datatable Schema', () => { it('throws when esql datatable has no metrics and no rows', () => { const input: Omit = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -487,7 +488,7 @@ describe('Datatable Schema', () => { it('throws on empty metrics array for esql', () => { const input: DatatableWithoutDefaultsConfig = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -505,7 +506,7 @@ describe('Datatable Schema', () => { it('throws on empty rows array for esql', () => { const input: DatatableWithoutDefaultsConfig = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -752,7 +753,7 @@ describe('Datatable Schema', () => { type: 'data_table', title: 'Datatable', description: 'ESQL table full configuration', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -838,7 +839,7 @@ describe('Datatable Schema', () => { type: 'data_table', title: 'Datatable', description: 'ESQL table without metrics', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts index fc6d070a07235..cf463b3a9b7a6 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts @@ -12,7 +12,7 @@ import { schema } from '@kbn/config-schema'; import { DEFAULT_HEADER_ROW_HEIGHT_LINES, DEFAULT_ROW_HEIGHT_LINES } from '@kbn/lens-common'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { applyColorToSchema, colorByValueSchema, colorMappingSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, dslOnlyPanelInfoSchema, @@ -379,7 +379,7 @@ export const datatableStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...datatableStateSharedOptionsSchema, /** * Metric columns configuration, must define operation. @@ -431,7 +431,7 @@ export const datatableStateSchemaESQL = schema.object( type: schema.literal('data_table'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...datatableStateSharedOptionsSchema, /** * Metric columns configuration, must define operation. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts index 92ca177ca8c2f..89ed4bc75b9e5 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { ColorByValueType } from '../color'; import type { GaugeState } from './gauge'; @@ -15,9 +16,9 @@ import { gaugeStateSchema } from './gauge'; describe('Gauge Schema', () => { const baseGaugeConfig = { type: 'gauge', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, } satisfies Partial; @@ -140,7 +141,7 @@ describe('Gauge Schema', () => { it('validates ESQL configuration', () => { const input = { type: 'gauge', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -157,7 +158,7 @@ describe('Gauge Schema', () => { it('validates ES|QL full configuration with bullet shape', () => { const input = { type: 'gauge', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -198,7 +199,7 @@ describe('Gauge Schema', () => { it('throws on mixed DSL and ES|QL configs', () => { const input = { type: 'gauge', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts index 904249f9170d1..7ff0455ae30a8 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts @@ -15,7 +15,7 @@ import { metricOperationDefinitionSchema, } from '../metric_ops'; import { colorByValueSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { dslOnlyPanelInfoSchema, layerSettingsSchema, sharedPanelInfoSchema } from '../shared'; import { mergeAllMetricsWithChartDimensionSchema } from './shared'; import { builderEnums } from '../enums'; @@ -152,7 +152,7 @@ export const gaugeStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...gaugeStateSharedOptionsSchema, /** * Primary value configuration, must define operation. @@ -170,7 +170,7 @@ export const gaugeStateSchemaESQL = schema.object( type: schema.literal('gauge'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...gaugeStateSharedOptionsSchema, /** * Primary value configuration, must define operation. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts index 0afc17892da26..ddc66f7e99485 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts @@ -11,7 +11,7 @@ import { omit } from 'lodash'; import { schema, type TypeOf } from '@kbn/config-schema'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { colorByValueSchema } from '../color'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { @@ -151,7 +151,7 @@ export const heatmapStateSchemaNoESQL = schema.object( ...heatmapSharedStateSchema, ...heatmapAxesStateSchemaProps, ...dslOnlyPanelInfoSchema, - ...datasetSchema, + ...dataSourceSchema, metric: mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( heatmapStateMetricOptionsSchemaProps ), @@ -163,7 +163,7 @@ export const heatmapStateSchemaESQL = schema.object( { ...heatmapSharedStateSchema, ...heatmapAxesStateESQLSchemaProps, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, metric: esqlColumnWithFormatSchema.extends(heatmapStateMetricOptionsSchemaProps), }, { meta: { id: 'heatmapESQL', title: 'Heatmap Chart (ES|QL)' } } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts index bdf5e435f32e1..b32583f8e1246 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { LegacyMetricState } from './legacy_metric'; import { legacyMetricStateSchema } from './legacy_metric'; @@ -14,9 +15,9 @@ import { legacyMetricStateSchema } from './legacy_metric'; describe('Legacy Metric Schema', () => { const baseLegacyMetricConfig = { type: 'legacy_metric', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, } satisfies Partial; @@ -217,7 +218,7 @@ describe('Legacy Metric Schema', () => { it('validates esql configuration', () => { const input = { type: 'legacy_metric', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts index 639bcc6135ddb..4521c44a15c58 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts @@ -10,7 +10,7 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { esqlColumnWithFormatSchema } from '../metric_ops'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { layerSettingsSchema, sharedPanelInfoSchema, dslOnlyPanelInfoSchema } from '../shared'; import { applyColorToSchema, @@ -86,7 +86,7 @@ export const legacyMetricStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, /** * Metric configuration, must define operation. */ @@ -100,7 +100,7 @@ const esqlLegacyMetricState = schema.object( type: schema.literal('legacy_metric'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, /** * Metric configuration, must define operation. */ diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts index 8d3fdf811a8b0..ef2d02ad43a9a 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { MetricState } from './metric'; import { metricStateSchema } from './metric'; @@ -14,9 +15,9 @@ import { metricStateSchema } from './metric'; describe('Metric Schema', () => { const baseMetricConfig = { type: 'metric', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, } satisfies Partial; @@ -577,7 +578,7 @@ describe('Metric Schema', () => { it('validates esql configuration', () => { const input = { type: 'metric', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts index f0e5001d3f02d..7c51a68421ac8 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts @@ -26,7 +26,7 @@ import { esqlColumnWithFormatSchema, } from '../metric_ops'; import { staticColorSchema, applyColorToSchema, colorByValueSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, layerSettingsSchema, @@ -404,7 +404,7 @@ function validateMetrics(metrics: (PrimaryMetricType | SecondaryMetricType)[]) { } } -const primaryMetricSchemaNoESQL = mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps({ +export const primaryMetricSchemaNoESQL = mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps({ ...metricStatePrimaryMetricOptionsSchema, ...metricStateBackgroundChartSchemaNoESQL, }); @@ -418,7 +418,7 @@ export const metricStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, styling: schema.maybe(metricStylingSchema), /** * Primary value configuration, must define operation. @@ -460,7 +460,7 @@ export const esqlMetricState = schema.object( type: schema.literal('metric'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, styling: schema.maybe(metricStylingSchema), /** * Primary value configuration, must define operation. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts index 98258096be257..e7bce0f2ca18b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts @@ -7,18 +7,19 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { MosaicState, MosaicStateESQL, MosaicStateNoESQL } from './mosaic'; import { mosaicStateSchema } from './mosaic'; describe('Mosaic Schema', () => { const baseMosaicConfig: Pick< MosaicStateNoESQL, - 'type' | 'dataset' | 'ignore_global_filters' | 'sampling' + 'type' | 'data_source' | 'ignore_global_filters' | 'sampling' > = { type: 'mosaic', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, ignore_global_filters: false, sampling: 0, @@ -565,10 +566,10 @@ describe('Mosaic Schema', () => { describe('ES|QL Schema', () => { const baseESQLMosaicConfig: Pick< MosaicStateESQL, - 'type' | 'dataset' | 'ignore_global_filters' | 'sampling' + 'type' | 'data_source' | 'ignore_global_filters' | 'sampling' > = { type: 'mosaic', - dataset: { + data_source: { type: 'esql', query: 'FROM blah | KEEP foo, bar', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts index c30c3b44e2d4d..f7a2250a1da4a 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts @@ -11,7 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { colorMappingSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, dslOnlyPanelInfoSchema, @@ -97,7 +97,7 @@ export const mosaicStateSchemaNoESQL = schema.object( type: schema.literal('mosaic'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...dslOnlyPanelInfoSchema, ...mosaicStateSharedSchema, ...dslOnlyPanelInfoSchema, @@ -149,7 +149,7 @@ export const mosaicStateSchemaESQL = schema.object( type: schema.literal('mosaic'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...mosaicStateSharedSchema, /** * Primary value configuration, must define operation. In ES|QL mode, uses column-based configuration. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts index 5c2c634e696e2..fa3e0e8704a9c 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { PieStateESQL, PieStateNoESQL } from './pie'; import { pieStateSchema } from './pie'; @@ -15,9 +16,9 @@ describe('Pie Schema', () => { describe('Non-ES|QL Schema', () => { const basePieConfig = { type: 'pie', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, ignore_global_filters: false, sampling: 1, @@ -701,7 +702,7 @@ describe('Pie Schema', () => { describe('ES|QL Schema', () => { const baseESQLPieConfig = { type: 'pie', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | STATS count() BY category', }, @@ -719,7 +720,7 @@ describe('Pie Schema', () => { }; const validated = pieStateSchema.validate(input); - expect(validated.dataset.type).toBe('esql'); + expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts index ef8f57f6a51c5..0e2f14485fa67 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts @@ -11,7 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { colorMappingSchema, staticColorSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, dslOnlyPanelInfoSchema, @@ -127,7 +127,7 @@ export const pieStateSchemaNoESQL = schema.object( type: pieTypeSchema, ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...dslOnlyPanelInfoSchema, ...pieStateSharedSchema, ...dslOnlyPanelInfoSchema, @@ -170,7 +170,7 @@ export const pieStateSchemaESQL = schema.object( type: pieTypeSchema, ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...pieStateSharedSchema, metrics: schema.arrayOf( esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema, { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts index 611f7e1f7fbd3..e3f40b89d9d13 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { RegionMapState } from './region_map'; import { regionMapStateSchema } from './region_map'; @@ -22,9 +23,9 @@ interface RegionMapTermsRegionBaseConfig { describe('Region Map Schema', () => { const baseRegionMapConfig: Omit = { type: 'region_map', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, }; @@ -180,7 +181,7 @@ describe('Region Map Schema', () => { it('throw when using term buckets operation in an esql configuration', () => { const input: RegionMapWithoutDefaultsConfig = { type: 'region_map', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -227,7 +228,7 @@ describe('Region Map Schema', () => { type: 'region_map', title: 'Region map', description: 'Top 10 countries by average bytes', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts index 4c85bc601203c..2e1b2b4a4a802 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts @@ -14,7 +14,7 @@ import { esqlColumnSchema, esqlColumnWithFormatSchema, } from '../metric_ops'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { dslOnlyPanelInfoSchema, layerSettingsSchema, sharedPanelInfoSchema } from '../shared'; import { mergeAllBucketsWithChartDimensionSchema } from './shared'; @@ -33,7 +33,7 @@ export const regionMapStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, /** * Metric configuration */ @@ -51,7 +51,7 @@ export const regionMapStateSchemaESQL = schema.object( type: schema.literal('region_map'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, /** * Metric configuration */ diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts index 9ce6ea155717f..f4413d5b48605 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts @@ -7,15 +7,16 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import { tagcloudStateSchema } from './tagcloud'; describe('Tagcloud Schema', () => { const baseTagcloudConfig = { type: 'tag_cloud', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, }; @@ -322,7 +323,7 @@ describe('Tagcloud Schema', () => { it('throw when missing DSL and esql operation in a configuration', () => { const input = { type: 'tag_cloud', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | LIMIT 100', }, @@ -404,7 +405,7 @@ describe('Tagcloud Schema', () => { it('validates esql configuration', () => { const input = { type: 'tag_cloud', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | STATS count() BY category | LIMIT 100', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts index 27bd7a517942d..8c8e0f982969d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts @@ -12,7 +12,7 @@ import { schema } from '@kbn/config-schema'; import { LENS_TAGCLOUD_DEFAULT_STATE } from '@kbn/lens-common'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { colorMappingSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { dslOnlyPanelInfoSchema, layerSettingsSchema, sharedPanelInfoSchema } from '../shared'; import { builderEnums } from '../enums'; import { @@ -78,7 +78,7 @@ export const tagcloudStateSchemaNoESQL = schema.object( ...sharedPanelInfoSchema, ...dslOnlyPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...tagcloudStateSharedOptionsSchema, /** * Primary value configuration, must define operation. @@ -97,7 +97,7 @@ export const tagcloudStateSchemaESQL = schema.object( type: schema.literal('tag_cloud'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...tagcloudStateSharedOptionsSchema, /** * Primary value configuration, must define operation. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts index 90e2cc23d5b53..a21866ffcd7e9 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { TreemapStateESQL, TreemapStateNoESQL } from './treemap'; import { treemapStateSchema } from './treemap'; @@ -14,9 +15,9 @@ describe('Treemap Schema', () => { describe('Non-ES|QL Schema', () => { const baseTreemapConfig = { type: 'treemap', - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, ignore_global_filters: false, sampling: 1, @@ -535,7 +536,7 @@ describe('Treemap Schema', () => { describe('ES|QL Schema', () => { const baseESQLTreemapConfig = { type: 'treemap', - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | STATS ...', }, @@ -554,7 +555,7 @@ describe('Treemap Schema', () => { }; const validated = treemapStateSchema.validate(input); - expect(validated.dataset.type).toBe('esql'); + expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts index 3690436ebfec8..68b4c318f9b26 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts @@ -11,7 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { colorMappingSchema, staticColorSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, @@ -118,7 +118,7 @@ export const treemapStateSchemaNoESQL = schema.object( type: schema.literal('treemap'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...dslOnlyPanelInfoSchema, ...treemapSharedStateSchema, ...dslOnlyPanelInfoSchema, @@ -165,7 +165,7 @@ export const treemapStateSchemaESQL = schema.object( type: schema.literal('treemap'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...treemapSharedStateSchema, /** * Primary value configuration, must define operation. In ES|QL mode, uses column-based configuration. diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts index 4ae7536d74a80..67709e250bd7e 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { WaffleStateNoESQL, WaffleStateESQL } from './waffle'; import { waffleStateSchema } from './waffle'; @@ -16,9 +17,9 @@ describe('Waffle Schema', () => { type: 'waffle', ignore_global_filters: false, sampling: 1, - dataset: { - type: 'dataView', - id: 'test-data-view', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-data-view', }, } satisfies Partial; @@ -450,7 +451,7 @@ describe('Waffle Schema', () => { type: 'waffle', ignore_global_filters: false, sampling: 1, - dataset: { + data_source: { type: 'esql', query: 'FROM my-index | STATS count() BY category', }, @@ -467,7 +468,7 @@ describe('Waffle Schema', () => { }; const validated = waffleStateSchema.validate(input); - expect(validated.dataset.type).toBe('esql'); + expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts index de9d2cc326dab..3e93374e19c77 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts @@ -11,7 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { esqlColumnWithFormatSchema } from '../metric_ops'; import { colorMappingSchema, staticColorSchema } from '../color'; -import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; +import { dataSourceSchema, dataSourceEsqlTableSchema } from '../data_source'; import { collapseBySchema, dslOnlyPanelInfoSchema, @@ -87,7 +87,7 @@ export const waffleStateSchemaNoESQL = schema.object( type: schema.literal('waffle'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...dslOnlyPanelInfoSchema, ...waffleStateSharedSchema, ...dslOnlyPanelInfoSchema, @@ -130,7 +130,7 @@ export const waffleStateSchemaESQL = schema.object( type: schema.literal('waffle'), ...sharedPanelInfoSchema, ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...waffleStateSharedSchema, metrics: schema.arrayOf( esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema), diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts index 8a07a02f31f0e..8d5e16de58490 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts @@ -7,15 +7,20 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { DatasetTypeESQL } from '../dataset'; -import type { XYState } from './xy'; +import type { TypeOf } from '@kbn/config-schema'; +import type { DataSourceTypeESQL } from '../data_source'; +import type { xyDataLayerSharedSchema, XYState } from './xy'; import { statisticsOptionsSize, statisticsSchema, xyStateSchema } from './xy'; +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; describe('XY', () => { const minimalLayer = { - dataset: { type: 'dataView', id: 'myDataView' as const }, - type: 'bar' as const, - y: [{ operation: 'count' as const }], + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, + type: 'bar', + y: [{ operation: 'count' }], }; const universalTypes = [ 'bar', @@ -25,14 +30,14 @@ describe('XY', () => { 'area_stacked', 'bar_horizontal', 'bar_horizontal_stacked', - ] as const; + ] satisfies TypeOf[]; const typesWithBreakdown = [ 'bar_percentage', 'area_percentage', 'bar_horizontal_percentage', - ] as const; - const anyType = [...universalTypes, ...typesWithBreakdown] as const; + ] satisfies TypeOf[]; + const anyType = [...universalTypes, ...typesWithBreakdown]; describe('minimal xy charts', () => { it.each([ 'bar', @@ -42,23 +47,25 @@ describe('XY', () => { 'area_stacked', 'bar_horizontal', 'bar_horizontal_stacked', - ] as const)('should pass validation for simple %s', (type) => { - expect(() => - xyStateSchema.validate({ + ] satisfies TypeOf[])( + 'should pass validation for simple %s', + (type) => { + const input = { type: 'xy', title: `${type} Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, ignore_global_filters: false, sampling: 1, y: [{ operation: 'count', empty_as_null: false }], }, ], - } satisfies XYState) - ).not.toThrow(); - }); + } satisfies XYState; + expect(() => xyStateSchema.validate(input)).not.toThrow(); + } + ); it.each(anyType)('should pass validation for %s with breakdown', (type) => { expect(() => @@ -67,7 +74,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, ignore_global_filters: false, sampling: 1, @@ -88,7 +95,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, ignore_global_filters: false, sampling: 1, @@ -115,7 +122,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_simple_logs_data | STATS count = count() BY buckets = BUCKET(3 hours, order_date), product', @@ -139,7 +146,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, ignore_global_filters: false, sampling: 1, @@ -158,7 +165,7 @@ describe('XY', () => { }, }, { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type: 'referenceLines', ignore_global_filters: false, sampling: 1, @@ -184,7 +191,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, ignore_global_filters: false, sampling: 1, @@ -201,9 +208,9 @@ describe('XY', () => { { type: 'annotations', ignore_global_filters: false, - dataset: { - type: 'dataView', - id: 'metrics-*', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'metrics-*', }, events: [ { @@ -237,7 +244,7 @@ describe('XY', () => { title: `Mixed Chart`, layers: [ { - dataset: { type: 'dataView', id: 'companyAIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyAIndex' }, type: type1, ignore_global_filters: false, sampling: 1, @@ -255,7 +262,7 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, { - dataset: { type: 'dataView', id: 'companyBIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyBIndex' }, type: type2, ignore_global_filters: false, sampling: 1, @@ -287,7 +294,7 @@ describe('XY', () => { title: `Mixed Chart`, layers: [ { - dataset: { type: 'dataView', id: 'companyAIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyAIndex' }, type: type1, ignore_global_filters: false, sampling: 1, @@ -305,7 +312,7 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, { - dataset: { type: 'dataView', id: 'companyBIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyBIndex' }, type: type2, ignore_global_filters: false, sampling: 1, @@ -323,7 +330,7 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type: 'referenceLines', ignore_global_filters: false, sampling: 1, @@ -347,9 +354,9 @@ describe('XY', () => { { type: 'annotations', ignore_global_filters: false, - dataset: { - type: 'dataView', - id: 'metrics-*', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'metrics-*', }, events: [ { @@ -413,7 +420,7 @@ describe('XY', () => { title: `Mixed Chart`, layers: [ { - dataset: { type: 'dataView', id: 'companyAIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyAIndex' }, type: type1, ignore_global_filters: false, sampling: 1, @@ -441,7 +448,7 @@ describe('XY', () => { }, }, { - dataset: { type: 'dataView', id: 'companyBIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyBIndex' }, type: type2, ignore_global_filters: false, sampling: 1, @@ -469,7 +476,11 @@ describe('XY', () => { }, }, { - dataset: { type: 'index', index: 'companyIndex', time_field: '@timestamp' }, + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'companyIndex', + time_field: '@timestamp', + }, type: 'referenceLines', ignore_global_filters: false, sampling: 1, @@ -495,9 +506,9 @@ describe('XY', () => { { type: 'annotations', ignore_global_filters: false, - dataset: { - type: 'dataView', - id: 'metrics-*', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'metrics-*', }, events: [ { @@ -567,7 +578,7 @@ describe('XY', () => { ).toThrow(); }); - it('should not let mix esql dataset with dsl operations', () => { + it('should not let mix esql data_source with dsl operations', () => { expect(() => xyStateSchema.validate({ type: 'xy', @@ -575,7 +586,7 @@ describe('XY', () => { layers: [ // @ts-expect-error - mixing not allowed { - dataset: { type: 'esql', query: 'FROM company_index' }, + data_source: { type: 'esql', query: 'FROM company_index' }, type: 'bar', ignore_global_filters: false, sampling: 1, @@ -604,7 +615,7 @@ describe('XY', () => { title: `Faulty Chart`, layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type: 'bar', ignore_global_filters: false, sampling: 1, @@ -621,11 +632,11 @@ describe('XY', () => { type: 'annotations', ignore_global_filters: false, // @ts-expect-error - mixing not allowed - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_simple_logs_data | EVAL timestamp = order_date | FILTER product == "xyz" ', - } satisfies DatasetTypeESQL, + } satisfies DataSourceTypeESQL, events: [ { type: 'point', @@ -651,7 +662,7 @@ describe('XY', () => { title: 'Mixed mode chart', layers: [ { - dataset: { type: 'dataView', id: 'companyAIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyAIndex' }, type: 'bar', ignore_global_filters: false, sampling: 1, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts index c6585b69f3214..e133c1bf2cf72 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts @@ -18,7 +18,7 @@ import { legendTruncateAfterLinesSchema, sharedPanelInfoSchema, } from '../shared'; -import { datasetEsqlTableSchema, datasetSchema } from '../dataset'; +import { dataSourceEsqlTableSchema, dataSourceSchema } from '../data_source'; import { legendSizeSchema, legendVisibilitySchemaWithAuto, @@ -178,7 +178,7 @@ const yAxisSchema = schema.object( /** * Chart types available for data layers in XY visualizations */ -const xyDataLayerSharedSchema = { +export const xyDataLayerSharedSchema = { type: schema.oneOf( [ schema.literal('area'), @@ -561,7 +561,7 @@ const xySharedSettings = { const xyDataLayerSchemaNoESQL = schema.object( { ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, ...xyDataLayerSharedSchema, breakdown_by: schema.maybe( mergeAllBucketsWithChartDimensionSchema({ @@ -598,7 +598,7 @@ const xyDataLayerSchemaNoESQL = schema.object( const xyDataLayerSchemaESQL = schema.object( { ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, ...xyDataLayerSharedSchema, breakdown_by: schema.maybe( esqlColumnWithFormatSchema.extends( @@ -705,7 +705,7 @@ const referenceLineLayerShared = { const referenceLineLayerSchemaNoESQL = schema.object( { ...layerSettingsSchema, - ...datasetSchema, + ...dataSourceSchema, type: schema.literal('referenceLines'), thresholds: schema.arrayOf( mergeAllMetricsWithChartDimensionSchemaWithStaticOps(referenceLineLayerShared), @@ -727,7 +727,7 @@ const referenceLineLayerSchemaNoESQL = schema.object( const referenceLineLayerSchemaESQL = schema.object( { ...layerSettingsSchema, - ...datasetEsqlTableSchema, + ...dataSourceEsqlTableSchema, type: schema.literal('referenceLines'), thresholds: schema.arrayOf(esqlColumnWithFormatSchema.extends(referenceLineLayerShared), { meta: { description: 'Array of ES|QL-based reference line thresholds' }, @@ -884,7 +884,7 @@ const annotationManualRange = schema.object( const annotationLayerByValueSchema = schema.object( { ...ignoringGlobalFiltersSchemaRaw, - ...datasetSchema, + ...dataSourceSchema, type: schema.literal('annotations'), events: schema.arrayOf( schema.oneOf([annotationQuery, annotationManualEvent, annotationManualRange]), diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.test.ts new file mode 100644 index 0000000000000..5949eba63b6c2 --- /dev/null +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.test.ts @@ -0,0 +1,203 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import type { Datatable } from '@kbn/expressions-plugin/common'; +import type { DataSourceTypeESQL, DataSourceTypeNoESQL } from './data_source'; +import { dataSourceSchema, dataSourceEsqlTableTypeSchema } from './data_source'; +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, + dataViewSchema, +} from '@kbn/as-code-data-views-schema'; + +describe('DataSource Schema', () => { + describe('DataViewReference type', () => { + it('validates a valid dataView configuration', () => { + const input = { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-data-view', + } satisfies DataSourceTypeNoESQL; + + const validated = dataViewSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('throws on missing name', () => { + const input = { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + // @ts-expect-error - ignore required name for test purposes + } satisfies DataSourceTypeNoESQL; + + expect(() => dataViewSchema.validate(input)).toThrow( + `[ref_id]: expected value of type [string] but got [undefined]` + ); + }); + }); + + describe('index type', () => { + it('validates a valid index configuration', () => { + const input = { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'my-index-*', + time_field: '@timestamp', + } satisfies DataSourceTypeNoESQL; + + const validated = dataViewSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('validates index configuration with runtime fields', () => { + const input = { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'my-index-*', + time_field: '@timestamp', + runtime_fields: [ + { + type: 'keyword', + name: 'my_runtime_field', + format: { type: 'string', params: { id: 'string' } }, + }, + { + type: 'long', + name: 'another_field', + }, + ], + } satisfies DataSourceTypeNoESQL; + + const validated = dataViewSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('throws on missing required fields', () => { + const input = { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + time_field: '@timestamp', + // @ts-expect-error - ignore required fields for test purposes + } satisfies DataSourceTypeNoESQL; + + expect(() => dataViewSchema.validate(input)).toThrow( + '[index_pattern]: expected value of type [string] but got [undefined]' + ); + }); + }); + + describe('esql type', () => { + it('validates a valid esql configuration', () => { + const input = { + type: 'esql', + query: 'FROM my-index | LIMIT 100', + } satisfies DataSourceTypeESQL; + + const validated = dataSourceEsqlTableTypeSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('throws on missing query', () => { + const input = { + type: 'esql', + // @ts-expect-error - ignore query prop for test purposes + } satisfies DataSourceTypeESQL; + + expect(() => dataSourceEsqlTableTypeSchema.validate(input)).toThrow( + /\[0.query\]: expected value of type/ + ); + }); + }); + + describe('table type', () => { + it('validates a valid table configuration', () => { + const mockTable: Datatable = { + type: 'datatable', + columns: [{ id: 'col1', name: 'Column 1', meta: { type: 'string' } }], + rows: [{ col1: 'value1' }], + }; + + const input = { + type: 'table', + table: mockTable, + } satisfies DataSourceTypeESQL; + + const validated = dataSourceEsqlTableTypeSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('throws on missing table', () => { + const input = { + type: 'table' as const, + }; + + expect(() => dataSourceEsqlTableTypeSchema.validate(input)).toThrow( + /\[1.table\]: expected value of type/ + ); + }); + }); + + describe('DataSource schema wrapper', () => { + it('validates datasource property with valid configuration', () => { + const input = { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-data-view', + } satisfies DataSourceTypeNoESQL; + + const validated = dataSourceSchema.data_source.validate(input); + expect(validated).toEqual(input); + }); + + it('throws on invalid datasource type', () => { + const input = { + type: 'invalid', + id: 'my-data-view', + }; + + expect(() => dataSourceSchema.data_source.validate(input)).toThrow(); + }); + }); + + describe('edge cases', () => { + it('validates index configuration with empty runtime fields array', () => { + const input = { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'my-index-*', + time_field: '@timestamp', + runtime_fields: [], + } satisfies DataSourceTypeNoESQL; + + const validated = dataViewSchema.validate(input); + expect(validated).toEqual(input); + }); + + it('validates runtime fields with various format configurations', () => { + const input = { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'my-index-*', + time_field: '@timestamp', + runtime_fields: [ + { + type: 'date', + name: 'date_field', + format: { + type: 'date', + params: { + pattern: 'YYYY-MM-DD', + }, + }, + }, + { + type: 'double', + name: 'number_field', + format: { type: '', params: { decimals: 2 } }, + }, + ], + } satisfies DataSourceTypeNoESQL; + + const validated = dataViewSchema.validate(input); + expect(validated).toEqual(input); + }); + }); +}); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.ts new file mode 100644 index 0000000000000..5f6b542e59dfc --- /dev/null +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/data_source.ts @@ -0,0 +1,64 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { schema, type TypeOf } from '@kbn/config-schema'; +import { dataViewSchema } from '@kbn/as-code-data-views-schema'; + +export const dataSourceSchema = { + data_source: dataViewSchema, +}; + +export const dataSourceEsqlTableTypeSchema = schema.oneOf([ + // ESQL datasource type + schema.object( + { + type: schema.literal('esql'), + /** + * The ESQL query string to use as the data source. + * Example: 'FROM my-index | LIMIT 100' + */ + query: schema.string({ + meta: { + description: + 'The ESQL query string to use as the data source. Example: "FROM my-index | LIMIT 100".', + }, + }), + }, + { meta: { id: 'esqlDataset', title: 'ES|QL Dataset' } } + ), + // Table datasource type + schema.object( + { + type: schema.literal('table'), + /** + * The Kibana datatable object to use as the data source. The structure should match the Kibana Datatable contract. + */ + table: schema.any({ + meta: { + description: + 'The Kibana datatable object to use as the data source. Structure should match the Kibana Datatable contract.', + }, + }), + }, + { meta: { id: 'tableESQLDataset', title: 'ES|QL Table Dataset' } } + ), +]); + +export const dataSourceEsqlTableSchema = { + data_source: dataSourceEsqlTableTypeSchema, +}; + +const anyDataSourceSchema = schema.oneOf([dataViewSchema, dataSourceEsqlTableTypeSchema], { + meta: { id: 'viz_data_source', title: 'Data Source configuration' }, +}); + +export type DataSourceTypeNoESQL = TypeOf; +export type DataSourceTypeESQL = TypeOf; + +export type DataSourceType = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.test.ts deleted file mode 100644 index 5090f124178ca..0000000000000 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.test.ts +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import type { Datatable } from '@kbn/expressions-plugin/common'; -import { datasetSchema, datasetTypeSchema, datasetEsqlTableTypeSchema } from './dataset'; - -describe('Dataset Schema', () => { - describe('dataView type', () => { - it('validates a valid dataView configuration', () => { - const input = { - type: 'dataView' as const, - id: 'my-data-view', - }; - - const validated = datasetTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('throws on missing name', () => { - const input = { - type: 'dataView' as const, - }; - - expect(() => datasetTypeSchema.validate(input)).toThrow(/\[0.id\]: expected value of type/); - }); - }); - - describe('index type', () => { - it('validates a valid index configuration', () => { - const input = { - type: 'index' as const, - index: 'my-index-*', - time_field: '@timestamp', - }; - - const validated = datasetTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates index configuration with runtime fields', () => { - const input = { - type: 'index' as const, - index: 'my-index-*', - time_field: '@timestamp', - runtime_fields: [ - { - type: 'keyword', - name: 'my_runtime_field', - format: { id: 'string' }, - }, - { - type: 'long', - name: 'another_field', - }, - ], - }; - - const validated = datasetTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('throws on missing required fields', () => { - const input = { - type: 'index' as const, - time_field: '@timestamp', - }; - - expect(() => datasetTypeSchema.validate(input)).toThrow( - /\[1.index\]: expected value of type/ - ); - }); - }); - - describe('esql type', () => { - it('validates a valid esql configuration', () => { - const input = { - type: 'esql' as const, - query: 'FROM my-index | LIMIT 100', - }; - - const validated = datasetEsqlTableTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('throws on missing query', () => { - const input = { - type: 'esql' as const, - }; - - expect(() => datasetEsqlTableTypeSchema.validate(input)).toThrow( - /\[0.query\]: expected value of type/ - ); - }); - }); - - describe('table type', () => { - it('validates a valid table configuration', () => { - const mockTable: Datatable = { - type: 'datatable', - columns: [{ id: 'col1', name: 'Column 1', meta: { type: 'string' } }], - rows: [{ col1: 'value1' }], - }; - - const input = { - type: 'table' as const, - table: mockTable, - }; - - const validated = datasetEsqlTableTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('throws on missing table', () => { - const input = { - type: 'table' as const, - }; - - expect(() => datasetEsqlTableTypeSchema.validate(input)).toThrow( - /\[1.table\]: expected value of type/ - ); - }); - }); - - describe('dataset schema wrapper', () => { - it('validates dataset property with valid configuration', () => { - const input = { - dataset: { - type: 'dataView' as const, - id: 'my-data-view', - }, - }; - - const validated = datasetSchema.dataset.validate(input.dataset); - expect(validated).toEqual(input.dataset); - }); - - it('throws on invalid dataset type', () => { - const input = { - dataset: { - type: 'invalid' as const, - id: 'my-data-view', - }, - }; - - expect(() => datasetSchema.dataset.validate(input.dataset)).toThrow(); - }); - }); - - describe('edge cases', () => { - it('validates index configuration with empty runtime fields array', () => { - const input = { - type: 'index' as const, - index: 'my-index-*', - time_field: '@timestamp', - runtime_fields: [], - }; - - const validated = datasetTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates runtime fields with various format configurations', () => { - const input = { - type: 'index' as const, - index: 'my-index-*', - time_field: '@timestamp', - runtime_fields: [ - { - type: 'date', - name: 'date_field', - format: { pattern: 'YYYY-MM-DD' }, - }, - { - type: 'number', - name: 'number_field', - format: { decimals: 2 }, - }, - ], - }; - - const validated = datasetTypeSchema.validate(input); - expect(validated).toEqual(input); - }); - }); -}); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.ts deleted file mode 100644 index 3bb22bdfeff4d..0000000000000 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/dataset.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import { schema, type TypeOf } from '@kbn/config-schema'; - -export const datasetTypeSchema = schema.oneOf([ - // DataView dataset type - schema.object( - { - type: schema.literal('dataView'), - /** - * The name of the Kibana data view to use as the data source. - * Example: 'my-data-view' - */ - id: schema.string({ - meta: { - description: - 'The id of the Kibana data view to use as the data source. Example: "my-data-view".', - }, - }), - }, - { meta: { id: 'dataViewDataset', title: 'Data View Dataset' } } - ), - // Index dataset type - schema.object( - { - type: schema.literal('index'), - /** - * The name of the Elasticsearch index to use as the data source. - * Example: 'my-index-*' - */ - index: schema.string({ - meta: { - description: - 'The name of the Elasticsearch index to use as the data source. Example: "my-index-*".', - }, - }), - /** - * The name of the time field in the index. Used for time-based filtering. - * Example: '@timestamp' - */ - time_field: schema.maybe( - schema.string({ - meta: { - description: - 'The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".', - }, - }) - ), - /** - * Optional array of runtime fields to define on the index. Each runtime field describes a computed field available at query time. - * If not provided, no runtime fields are used. - */ - runtime_fields: schema.maybe( - schema.arrayOf( - schema.object({ - /** - * The type of the runtime field (e.g., 'keyword', 'long', 'date'). - * Example: 'keyword' - */ - type: schema.string({ - meta: { - description: 'The type of the runtime field (e.g., "keyword", "long", "date").', - }, - }), - /** - * The name of the runtime field. - * Example: 'my_runtime_field' - */ - name: schema.string({ - meta: { - description: 'The name of the runtime field. Example: "my_runtime_field".', - }, - }), - /** - * Optional format definition for the runtime field. The structure depends on the field type and use case. - * If not provided, no format is applied. - */ - format: schema.maybe( - schema.any({ - meta: { - description: 'The type of the runtime field (e.g., "keyword", "long", "date").', - }, - }) - ), - }), - { maxSize: 100 } - ) - ), - }, - { meta: { id: 'indexDataset', title: 'Index Dataset' } } - ), -]); - -export const datasetSchema = { - /** - * The dataset configuration. Can be one of the following types: - * - `dataView`: Use a Kibana data view as the data source. Requires a `name` property with the name of the data view. - * - `index`: Use a Elasticsearch index as the data source. Requires an `index` property with the name of the index, and optionally a `time_field` property with the name of the time field in the index. - * - `esql`: Use an ESQL query string as the data source. Requires a `query` property with the ESQL query string. - * - `table`: Use a Kibana datatable object as the data source. Requires a `table` property with the Kibana datatable object, which should match the Kibana Datatable contract. - */ - dataset: datasetTypeSchema, -}; - -export const datasetEsqlTableTypeSchema = schema.oneOf([ - // ESQL dataset type - schema.object( - { - type: schema.literal('esql'), - /** - * The ESQL query string to use as the data source. - * Example: 'FROM my-index | LIMIT 100' - */ - query: schema.string({ - meta: { - description: - 'The ESQL query string to use as the data source. Example: "FROM my-index | LIMIT 100".', - }, - }), - }, - { meta: { id: 'esqlDataset', title: 'ES|QL Dataset' } } - ), - // Table dataset type - schema.object( - { - type: schema.literal('table'), - /** - * The Kibana datatable object to use as the data source. The structure should match the Kibana Datatable contract. - */ - table: schema.any({ - meta: { - description: - 'The Kibana datatable object to use as the data source. Structure should match the Kibana Datatable contract.', - }, - }), - }, - { meta: { id: 'tableESQLDataset', title: 'ES|QL Table Dataset' } } - ), -]); - -export const datasetEsqlTableSchema = { - dataset: datasetEsqlTableTypeSchema, -}; - -const anyDatasetSchema = schema.oneOf([datasetTypeSchema, datasetEsqlTableTypeSchema], { - meta: { id: 'dataset', title: 'Dataset' }, -}); - -export type DatasetType = TypeOf; -export type DatasetTypeNoESQL = TypeOf; -export type DatasetTypeESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/shared.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/shared.ts index 7d989b4352409..2517e2c76de12 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/shared.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/shared.ts @@ -98,9 +98,9 @@ export const ignoringGlobalFiltersSchemaRaw = { export const layerSettingsSchema = { /** - * The sampling factor for the dataset. + * The sampling factor for the data source. * - * Determines the proportion of the dataset to be used. Must be a number between 0 and 1 (inclusive). + * Determines the proportion of the data source to be used. Must be a number between 0 and 1 (inclusive). * - 0: No sampling (use none of the data) * - 1: Full sampling (use all data) * - Any value between 0 and 1: Use that proportion of the data diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts index 96d57b49491e1..e30a5ba108a90 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts @@ -7,6 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; import type { DatatableState, DatatableStateNoESQL } from '../../schema'; /** @@ -15,9 +19,9 @@ import type { DatatableState, DatatableStateNoESQL } from '../../schema'; export const singleMetricDatatableWithAdhocDataView: DatatableState = { title: 'Single metric', type: 'data_table', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, sampling: 1, @@ -36,9 +40,9 @@ export const singleMetricDatatableWithAdhocDataView: DatatableState = { export const multiMetricRowSplitByDatatableWithAdhocDataView: DatatableState = { title: 'Multiple metrics, rows, split by with ad hoc dataView', type: 'data_table', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, sampling: 1, @@ -112,9 +116,9 @@ export const multiMetricRowSplitByDatatableWithAdhocDataView: DatatableState = { export const fullConfigDatatableWithAdhocDataView: DatatableState = { title: 'Multiple metrics, rows, split by with full config', type: 'data_table', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, sampling: 1, @@ -277,9 +281,9 @@ export const fullConfigDatatableWithAdhocDataView: DatatableState = { export const fullConfigDatatableWithDataView: DatatableState = { title: 'Multiple metrics, rows, split by with full config', type: 'data_table', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, sampling: 1, ignore_global_filters: false, @@ -440,9 +444,9 @@ export const fullConfigDatatableWithDataView: DatatableState = { export const sortedByPivotedMetricColumnDatatable: DatatableState = { title: 'Sorted by a pivoted metric column', type: 'data_table', - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, sampling: 1, ignore_global_filters: false, @@ -609,9 +613,9 @@ export const sortedByPivotedMetricColumnDatatable: DatatableState = { export const sortedByRowDatatable: DatatableState = { title: 'Sorted by row column', type: 'data_table', - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, sampling: 1, ignore_global_filters: false, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts index 046fe08656ba2..72ea542e4611f 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts @@ -15,7 +15,7 @@ import type { DatatableState, DatatableStateESQL } from '../../schema'; export const singleMetricESQLDatatable: DatatableState = { title: 'Single metric', type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | LIMIT 100', }, @@ -34,7 +34,7 @@ export const singleMetricESQLDatatable: DatatableState = { export const multipleMetricRowSplitESQLDatatable: DatatableState = { title: 'Multiple metrics, rows, split by', type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | LIMIT 10', }, @@ -72,7 +72,7 @@ export const multipleMetricRowSplitESQLDatatable: DatatableState = { export const fullConfigESQLDatatable: DatatableState = { title: 'Full config', type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | LIMIT 10', }, @@ -163,7 +163,7 @@ export const fullConfigESQLDatatable: DatatableState = { export const sortedByPivotedMetricColumnESQLDatatable: DatatableState = { title: 'Sorted by pivoted metric column', type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | LIMIT 10', }, @@ -260,7 +260,7 @@ export const sortedByPivotedMetricColumnESQLDatatable: DatatableState = { export const sortedByRowColumnESQLDatatable: DatatableState = { title: 'Sorted by row column', type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | LIMIT 10', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts index 068cc6f567fe5..6eca38c9d5d0d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts @@ -35,7 +35,7 @@ describe('Gauge', () => { validateConverter(gaugeAttributesWithPercentageColorMode, gaugeStateSchema); }); - it('should convert a gauge chart with ESQL dataset', () => { + it('should convert a gauge chart with ESQL datasource', () => { validateConverter(gaugeESQLAttributes, gaugeStateSchema); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts index 5a8bb83693e5d..ef6aa94a68e94 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts @@ -7,6 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; import type { GaugeState } from '../../schema/charts/gauge'; /** @@ -15,9 +19,9 @@ import type { GaugeState } from '../../schema/charts/gauge'; export const basicGaugeWithAdHocDataView: GaugeState = { type: 'gauge', title: 'Test Gauge', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, metric: { @@ -36,9 +40,9 @@ export const basicGaugeWithDataView: GaugeState = { type: 'gauge', title: 'Test Gauge', description: 'A test gauge chart', - dataset: { - type: 'dataView', - id: 'test-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-id', }, metric: { operation: 'count', @@ -56,7 +60,7 @@ export const esqlGauge: GaugeState = { type: 'gauge', title: 'Test ESQL Gauge', description: 'A test gauge chart using ESQL', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS count = COUNT(*)', }, @@ -74,9 +78,9 @@ export const comprehensiveGaugeWithAdHocDataView: GaugeState = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'index', - index: 'comprehensive-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'comprehensive-index', time_field: '@timestamp', }, metric: { @@ -112,9 +116,9 @@ export const comprehensiveGaugeWithDataView: GaugeState = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, metric: { operation: 'average', @@ -148,7 +152,7 @@ export const comprehensiveEsqlGauge: GaugeState = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS countA = COUNT(*) WHERE a > 1, countB = COUNT(*) WHERE b > 1', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts index 55cf435f19fed..900ac5b99966a 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts @@ -7,6 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; import type { LegacyMetricState } from '../../schema/charts/legacy_metric'; /** @@ -15,9 +19,9 @@ import type { LegacyMetricState } from '../../schema/charts/legacy_metric'; export const basicLegacyMetricWithAdHocDataView: LegacyMetricState = { type: 'legacy_metric', title: 'Test Metric', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, metric: { @@ -36,9 +40,9 @@ export const basicLegacyMetricWithDataView: LegacyMetricState = { type: 'legacy_metric', title: 'Test Metric', description: 'A test metric chart', - dataset: { - type: 'dataView', - id: 'test-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-id', }, metric: { operation: 'count', @@ -56,7 +60,7 @@ export const esqlLegacyMetric: LegacyMetricState = { type: 'legacy_metric', title: 'Test ESQL Metric', description: 'A test metric chart using ESQL', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS count = COUNT(*)', }, @@ -74,9 +78,9 @@ export const comprehensiveLegacyMetricWithAdHocDataView: LegacyMetricState = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'index', - index: 'comprehensive-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'comprehensive-index', time_field: '@timestamp', }, metric: { @@ -108,9 +112,9 @@ export const comprehensiveLegacyMetricWithDataView: LegacyMetricState = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, metric: { operation: 'average', @@ -141,7 +145,7 @@ export const comprehensiveEsqlLegacyMetric: LegacyMetricState = { type: 'legacy_metric', title: 'Test ESQL Metric', description: 'A test metric chart using ESQL', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS countA = COUNT(*) WHERE a > 1, countB = COUNT(*) WHERE b > 1', }, @@ -172,9 +176,9 @@ export const legacyMetricWithApplyColorToWithoutColor: LegacyMetricState = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, metric: { operation: 'average', @@ -196,9 +200,9 @@ export const legacyMetricWithColorWithoutApplyColorTo: LegacyMetricState = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, metric: { operation: 'average', diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts index 222545b38d01e..deeab6bcd4a26 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts @@ -7,14 +7,16 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { MetricState } from '../../schema'; +import type { MetricStateNoESQL } from '../../schema/charts/metric'; import { DEFAULT_PRIMARY_VALUE_ALIGNMENT } from '../../transforms/charts/metric/defaults'; export const breakdownMetricAPIAttributes = { type: 'metric', title: 'Metric - Breakdown', description: 'Metric with breakdown', - dataset: { type: 'dataView', id: 'testId' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'testId' }, metrics: [ { type: 'primary', @@ -37,13 +39,13 @@ export const breakdownMetricAPIAttributes = { fields: ['extension.keyword'], limit: 5, }, -} as MetricState; +} as MetricStateNoESQL; export const complexMetricAPIAttributes = { type: 'metric', title: 'Metric - Complex case', description: 'Metric with background chart and breakdown', - dataset: { type: 'dataView', id: 'testId' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'testId' }, metrics: [ { type: 'primary', @@ -92,7 +94,7 @@ export const simpleMetricAPIAttributes = { type: 'metric', title: 'Simple Metric', description: 'A simple metric visualization', - dataset: { type: 'dataView', id: 'testId' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'testId' }, metrics: [ { type: 'primary', @@ -107,7 +109,7 @@ export const complexESQLMetricAPIAttributes = { type: 'metric', title: 'Metric - ESQL Complex case', description: 'ESQL Metric with background chart and breakdown', - dataset: { type: 'esql', query: 'FROM logs | STATS ...' }, + data_source: { type: 'esql', query: 'FROM logs | STATS ...' }, metrics: [ { type: 'primary', @@ -144,7 +146,7 @@ export const metricAPIWithTermsRankedBySecondary = { type: 'metric', title: 'Metric - Breakdown ranked by secondary', description: 'Metric with breakdown ranked by secondary metric', - dataset: { type: 'dataView', id: 'testId' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'testId' }, ignore_global_filters: false, sampling: 1, metrics: [ diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts index f005eff78c78d..f1b9e84696643 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts @@ -11,7 +11,7 @@ import type { MosaicState } from '../../schema/charts/mosaic'; import type { PieState } from '../../schema/charts/pie'; import type { TreemapState } from '../../schema/charts/treemap'; import type { WaffleState } from '../../schema/charts/waffle'; - +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; type PartitionConfig = PieState | MosaicState | TreemapState | WaffleState; export const esqlCharts: Array = [ @@ -46,9 +46,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -98,9 +98,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -151,9 +151,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -197,9 +197,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -245,9 +245,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -305,9 +305,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -370,9 +370,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -436,9 +436,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -497,9 +497,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'auto', @@ -569,9 +569,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -646,9 +646,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -710,9 +710,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -771,9 +771,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -843,9 +843,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -953,9 +953,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1025,9 +1025,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1135,9 +1135,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1233,9 +1233,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1327,9 +1327,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1408,9 +1408,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1444,7 +1444,7 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_ecommerce | STATS count = COUNT(*) BY category.keyword', }, @@ -1480,7 +1480,7 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_ecommerce | STATS count = COUNT(*) BY category.keyword', }, @@ -1510,7 +1510,7 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_ecommerce | STATS count = COUNT(*) BY category.keyword', }, @@ -1567,9 +1567,9 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, legend: { visibility: 'visible', @@ -1602,7 +1602,7 @@ export const esqlCharts: Array = [ }, }, ], - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_ecommerce | STATS count = COUNT(*) BY category.keyword', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts index c1da283903c70..2b99631c41cd2 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts @@ -7,6 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; import type { RegionMapState } from '../../schema'; /** @@ -15,9 +19,9 @@ import type { RegionMapState } from '../../schema'; export const basicRegionMapWithAdHocDataView = { title: 'Test Region Map', type: 'region_map', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, metric: { @@ -47,9 +51,9 @@ export const basicRegionMapWithAdHocDataView = { export const basicRegionMapWithDataView = { title: 'Test Region Map', type: 'region_map', - dataset: { - type: 'dataView', - id: 'test-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-id', }, metric: { operation: 'percentile', @@ -83,7 +87,7 @@ export const basicRegionMapWithDataView = { export const basicEsqlRegionMap = { title: 'Test Region Map', type: 'region_map', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS bytes=AVG(bytes) BY geo.dest', }, @@ -107,9 +111,9 @@ export const basicEsqlRegionMap = { export const comprehensiveRegionMapWithAdHocDataView = { title: 'Comprehensive Test Region Map', type: 'region_map', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, metric: { @@ -142,9 +146,9 @@ export const comprehensiveRegionMapWithAdHocDataView = { export const comprehensiveRegionMapWithDataView = { title: 'Comprehensive Test Region Map', type: 'region_map', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, metric: { operation: 'count', @@ -176,7 +180,7 @@ export const comprehensiveRegionMapWithDataView = { export const comprehensiveEsqlRegionMap = { title: 'Comprehensive Test Region Map', type: 'region_map', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS bytes=AVG(bytes) BY geo.dest', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts index 4d5f209f1e168..52ea7f2d03a25 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts @@ -8,6 +8,10 @@ */ import type { TagcloudState } from '../../schema'; +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; /** * Basic tagcloud chart with ad hoc dataView @@ -15,9 +19,9 @@ import type { TagcloudState } from '../../schema'; export const basicTagcloudWithAdHocDataView = { title: 'Test Tagcloud', type: 'tag_cloud', - dataset: { - type: 'index', - index: 'test-index', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', time_field: '@timestamp', }, metric: { @@ -41,9 +45,9 @@ export const basicTagcloudWithAdHocDataView = { export const basicTagcloudWithDataView = { title: 'Test Tagcloud', type: 'tag_cloud', - dataset: { - type: 'dataView', - id: 'test-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'test-id', }, metric: { operation: 'average', @@ -66,7 +70,7 @@ export const basicTagcloudWithDataView = { export const basicEsqlTagcloud = { title: 'Test Tagcloud', type: 'tag_cloud', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS bytes=AVG(bytes) BY geo.dest', }, @@ -86,9 +90,10 @@ export const basicEsqlTagcloud = { export const comprehensiveTagcloudWithAdHocDataView = { title: 'Comprehensive Test Tagcloud', type: 'tag_cloud', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test-index', + time_field: '@timestamp', }, orientation: 'angled', font_size: { @@ -149,9 +154,9 @@ export const comprehensiveTagcloudWithAdHocDataView = { export const comprehensiveTagcloudWithDataView = { title: 'Comprehensive Test Tagcloud', type: 'tag_cloud', - dataset: { - type: 'dataView', - id: 'my-custom-data-view-id', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'my-custom-data-view-id', }, orientation: 'angled', font_size: { @@ -212,7 +217,7 @@ export const comprehensiveTagcloudWithDataView = { export const comprehensiveEsqlTagcloud = { title: 'Comprehensive Test Tagcloud', type: 'tag_cloud', - dataset: { + data_source: { type: 'esql', query: 'FROM test-index | STATS bytes=AVG(bytes) BY geo.dest', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts index e5663b24b4bde..f6519d4844ee4 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts @@ -19,6 +19,7 @@ import type { import type { LensAttributes } from '../../types'; import type { LensApiState } from '../../schema'; import { LENS_ITEM_LATEST_VERSION } from '@kbn/lens-common/content_management/constants'; +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; export const minimalAttributesXY: LensAttributes = { visualizationType: 'lnsXY', @@ -1118,9 +1119,9 @@ export const apiXYWithNoYTitleAndInsideLegend: LensApiState = { layers: [ { type: 'bar_stacked', - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, sampling: 1, ignore_global_filters: false, @@ -1211,9 +1212,9 @@ export const apiXYWithTopListWithTruncationLegend: LensApiState = { layers: [ { type: 'bar_stacked', - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, sampling: 1, ignore_global_filters: false, @@ -1299,9 +1300,9 @@ export const apiXYWithNoTitleAndCustomOutsideLegend: LensApiState = { layers: [ { type: 'bar_stacked', - dataset: { - type: 'dataView', - id: '90943e30-9a47-11e8-b64d-95841ca0b247', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: '90943e30-9a47-11e8-b64d-95841ca0b247', }, sampling: 1, ignore_global_filters: false, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts index 2a8243a348732..0b68db1f78001 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts @@ -30,6 +30,10 @@ import { esqlChartWithBreakdownColorMapping, esqlXYWithCollapseByBreakdown, } from './esqlXY.mock'; +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; function setSeriesType(attributes: LensAttributes, seriesType: 'bar' | 'line' | 'area') { return { @@ -281,7 +285,7 @@ describe('XY', () => { { ignore_global_filters: false, sampling: 1, - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type, y: [{ operation: 'count', empty_as_null: false }], }, @@ -298,7 +302,7 @@ describe('XY', () => { title: `${type} Chart`, layers: [ { - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_simple_logs_data | STATS count = count() BY buckets = BUCKET(3 hours, order_date), product', @@ -325,7 +329,7 @@ describe('XY', () => { title: `${type} Chart with collapse`, layers: [ { - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs', }, @@ -352,7 +356,7 @@ describe('XY', () => { title: `${type} Chart with Color Mapping`, layers: [ { - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data | STATS count = count() BY category, buckets = BUCKET(3 hours, order_date)', @@ -391,7 +395,7 @@ describe('XY', () => { title: `Mixed Chart`, layers: [ { - dataset: { type: 'dataView', id: 'companyAIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyBIndex' }, type: type1, ignore_global_filters: false, sampling: 1, @@ -419,7 +423,7 @@ describe('XY', () => { }, }, { - dataset: { type: 'dataView', id: 'companyBIndex' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'companyBIndex' }, type: type2, ignore_global_filters: false, sampling: 1, @@ -447,7 +451,11 @@ describe('XY', () => { }, }, { - dataset: { type: 'index', index: 'companyIndex', time_field: '@timestamp' }, + data_source: { + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'companyIndex', + time_field: '@timestamp', + }, type: 'referenceLines', ignore_global_filters: false, sampling: 1, @@ -473,9 +481,9 @@ describe('XY', () => { { type: 'annotations', ignore_global_filters: false, - dataset: { - type: 'dataView', - id: 'metrics-*', + data_source: { + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'metrics-*', }, events: [ { @@ -553,7 +561,7 @@ describe('XY', () => { title: 'Chart with by-ref annotation', layers: [ { - dataset: { type: 'dataView', id: 'myDataView' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'myDataView' }, type: 'line', ignore_global_filters: false, sampling: 1, @@ -584,7 +592,7 @@ describe('XY', () => { { ignore_global_filters: false, sampling: 1, - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | STATS count = count() BY buckets = BUCKET(@timestamp, 1 hour)', @@ -613,7 +621,7 @@ describe('XY', () => { { ignore_global_filters: false, sampling: 1, - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | STATS count = count() BY bytes', }, @@ -636,7 +644,7 @@ describe('XY', () => { { ignore_global_filters: false, sampling: 1, - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | STATS count = count() BY bytes', }, @@ -664,7 +672,7 @@ describe('XY', () => { { ignore_global_filters: false, sampling: 1, - dataset: { + data_source: { type: 'esql', query: 'FROM kibana_sample_data_logs | STATS count = count() BY bytes', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts index 7c89352313605..b8ac9429a1e4d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts @@ -11,8 +11,8 @@ import type { SavedObjectReference } from '@kbn/core/server'; import type { DataViewSpec } from '@kbn/data-views-plugin/common'; import type { DatatableState } from '../../../../schema'; import { - buildDatasetStateESQL, - buildDatasetStateNoESQL, + buildDataSourceStateESQL, + buildDataSourceStateNoESQL, generateApiLayer, isTextBasedLayer, } from '../../../utils'; @@ -28,20 +28,20 @@ export function buildVisualizationAPI( adhocReferences?: SavedObjectReference[] ): DatatableState { if (isTextBasedLayer(layer)) { - const dataset = buildDatasetStateESQL(layer); + const dataSource = buildDataSourceStateESQL(layer); const { columnIdMapping, ...columns } = convertDatatableColumnsToAPI(layer, visualization); return { type: 'data_table', - dataset, + data_source: dataSource, ...generateApiLayer(layer), ...columns, ...convertAppearanceToAPIFormat(visualization, columnIdMapping), }; } - const dataset = buildDatasetStateNoESQL( + const dataSource = buildDataSourceStateNoESQL( layer, layerId, adHocDataViews, @@ -53,7 +53,7 @@ export function buildVisualizationAPI( return { type: 'data_table', - dataset, + data_source: dataSource, ...generateApiLayer(layer), ...columns, ...convertAppearanceToAPIFormat(visualization, columnIdMapping), diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts index 86144557d1738..5ff05c6170c2c 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts @@ -15,7 +15,7 @@ describe('Datatable ES|QL column ordering', () => { it('should order visualization columns as rows, split_metrics_by, then metrics', () => { const config: DatatableState = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM test | LIMIT 10', }, @@ -41,7 +41,7 @@ describe('Datatable ES|QL column ordering', () => { it('should mark row columns as isMetric: false and metric columns as isMetric: true', () => { const config: DatatableState = { type: 'data_table', - dataset: { + data_source: { type: 'esql', query: 'FROM test | LIMIT 10', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts index 97d837e39abea..4f914af3a2e9f 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts @@ -23,7 +23,7 @@ import { DEFAULT_LAYER_ID } from '../../constants'; import type { DeepMutable, DeepPartial } from '../utils'; import { addLayerColumn, - buildDatasetState, + buildDataSourceState, buildDatasourceStates, buildReferences, generateApiLayer, @@ -42,7 +42,7 @@ import type { GaugeStateESQL, GaugeStateNoESQL } from '../../schema/charts/gauge import { fromMetricAPItoLensState } from '../columns/metric'; import type { LensApiAllMetricOperations } from '../../schema/metric_ops'; import { getValueApiColumn, getValueColumn } from '../columns/esql_column'; -import { isEsqlTableTypeDataset } from '../../utils'; +import { isEsqlTableTypeDataSource } from '../../utils'; const ACCESSOR = 'gauge_accessor'; @@ -96,10 +96,16 @@ function reverseBuildVisualizationState( throw new Error('Metric accessor is missing in the visualization state'); } - const dataset = buildDatasetState(layer, layerId, adHocDataViews, references, adhocReferences); + const dataSource = buildDataSourceState( + layer, + layerId, + adHocDataViews, + references, + adhocReferences + ); - if (!dataset || dataset.type == null) { - throw new Error('Unsupported dataset type'); + if (!dataSource || dataSource.type == null) { + throw new Error('Unsupported DataSource type'); } const props: DeepPartial> = { @@ -112,7 +118,7 @@ function reverseBuildVisualizationState( : { type: visualization.shape === 'semiCircle' ? 'semi_circle' : visualization.shape, }, - metric: isEsqlTableTypeDataset(dataset) + metric: isEsqlTableTypeDataSource(dataSource) ? { ...getValueApiColumn(metricAccessor, layer as TextBasedLayer), ...(visualization.minAccessor @@ -184,7 +190,7 @@ function reverseBuildVisualizationState( return { type: 'gauge', - dataset: dataset satisfies GaugeState['dataset'], + data_source: dataSource satisfies GaugeState['data_source'], ...props, } as GaugeState; } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts index 4d3b9291143f7..dde6942683153 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts @@ -28,8 +28,8 @@ import type { HeatmapState } from '../../../schema'; import { fromColorByValueLensStateToAPI } from '../../coloring'; import { type LensAttributes } from '../../../types'; import { - buildDatasetStateESQL, - buildDatasetStateNoESQL, + buildDataSourceStateESQL, + buildDataSourceStateNoESQL, generateApiLayer, isTextBasedLayer, operationFromColumn, @@ -121,11 +121,11 @@ function reverseBuildVisualizationState( throw new Error('xAccessor is missing in the visualization state'); } - const dataset = buildDatasetStateESQL(layer); + const dataSource = buildDataSourceStateESQL(layer); return { ...sharedProps, - dataset, + data_source: dataSource, metric: { ...getValueApiColumn(valueAccessor, layer), ...paletteProps, @@ -135,7 +135,7 @@ function reverseBuildVisualizationState( } satisfies HeatmapStateESQL; } - const dataset = buildDatasetStateNoESQL( + const dataSource = buildDataSourceStateNoESQL( layer, layerId, adHocDataViews, @@ -145,7 +145,7 @@ function reverseBuildVisualizationState( return { ...sharedProps, - dataset, + data_source: dataSource, metric: { ...operationFromColumn(valueAccessor, layer), ...paletteProps, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts index f431700d20580..b6e00559b29fd 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts @@ -20,7 +20,7 @@ import type { LensAttributes } from '../../types'; import { DEFAULT_LAYER_ID } from '../../constants'; import { addLayerColumn, - buildDatasetState, + buildDataSourceState, buildDatasourceStates, buildReferences, generateApiLayer, @@ -47,7 +47,7 @@ import { fromColorByValueLensStateToAPI, isColorByValueAbsolute, } from '../coloring'; -import { isEsqlTableTypeDataset } from '../../utils'; +import { isEsqlTableTypeDataSource } from '../../utils'; const ACCESSOR = 'legacy_metric_accessor'; @@ -82,15 +82,21 @@ function reverseBuildVisualizationState( throw new Error('Metric accessor is missing in the visualization state'); } - const dataset = buildDatasetState(layer, layerId, adHocDataViews, references, adhocReferences); + const dataSource = buildDataSourceState( + layer, + layerId, + adHocDataViews, + references, + adhocReferences + ); - if (!dataset || dataset.type == null) { - throw new Error('Unsupported dataset type'); + if (!dataSource || dataSource.type == null) { + throw new Error('Unsupported DataSource type'); } const props: DeepPartial> = { ...generateApiLayer(layer), - metric: isEsqlTableTypeDataset(dataset) + metric: isEsqlTableTypeDataSource(dataSource) ? getValueApiColumn(visualization.accessor, layer as TextBasedLayer) : operationFromColumn(visualization.accessor, layer as FormBasedLayer), } as LegacyMetricState; @@ -126,7 +132,7 @@ function reverseBuildVisualizationState( return { type: 'legacy_metric', - dataset: dataset satisfies LegacyMetricState['dataset'], + data_source: dataSource satisfies LegacyMetricState['data_source'], ...props, } as LegacyMetricState; } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts index 02ba4238c8695..a7093488e7fdb 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts @@ -31,7 +31,7 @@ import { import { DEFAULT_LAYER_ID } from '../../constants'; import { addLayerColumn, - buildDatasetState, + buildDataSourceState, buildDatasourceStates, buildReferences, generateApiLayer, @@ -73,7 +73,7 @@ import { isAPIColumnOfBucketType, isAPIColumnOfMetricType } from '../columns/uti type MetricApiCompareType = Extract, { compare: any }>['compare']; -type WritableMetricStateWithoutDataset = DeepWriteable>; +type WritableMetricStateWithoutDataset = DeepWriteable>; const ACCESSOR = 'metric_accessor'; const HISTOGRAM_COLUMN_NAME = 'x_date_histogram'; @@ -528,14 +528,20 @@ function reverseBuildVisualizationState( throw new Error('Metric accessor is missing in the visualization state'); } - const dataset = buildDatasetState(layer, layerId, adHocDataViews, references, adhocReferences); + const dataSource = buildDataSourceState( + layer, + layerId, + adHocDataViews, + references, + adhocReferences + ); - if (!dataset || dataset.type == null) { - throw new Error('Unsupported dataset type'); + if (!dataSource || dataSource.type == null) { + throw new Error('Unsupported DataSource type'); } return { - dataset: dataset satisfies MetricState['dataset'], + data_source: dataSource satisfies MetricState['data_source'], ...(isTextBasedLayer(layer) ? buildFromTextBasedLayer(layer, metricAccessor, visualization) : buildFromFormBasedLayer(layer, metricAccessor, visualization)), diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts index f4a13536f7ca4..3ff91f736a74d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts @@ -25,8 +25,8 @@ import type { import { type LensAttributes } from '../../types'; import type { DataSourceStateLayer } from '../utils'; import { - buildDatasetStateESQL, - buildDatasetStateNoESQL, + buildDataSourceStateESQL, + buildDataSourceStateNoESQL, buildDatasourceStates, generateLayer, isFormBasedLayer, @@ -44,7 +44,7 @@ import { stripUndefined, } from './utils'; import { legendSizeCompat } from './legend_sizes'; -import { addLayerColumn, groupIsNotCollapsed, isEsqlTableTypeDataset } from '../../utils'; +import { addLayerColumn, groupIsNotCollapsed, isEsqlTableTypeDataSource } from '../../utils'; import { fromMetricAPItoLensState } from '../columns/metric'; import { fromBucketLensApiToLensState } from '../columns/buckets'; import { DEFAULT_LAYER_ID } from '../../constants'; @@ -89,7 +89,7 @@ function isAPIPartitionLayer(layer: unknown): layer is PartitionState { } function isESQLPartitionLayer(layer: PartitionState): layer is PartitionStateESQL { - return isEsqlTableTypeDataset(layer.dataset); + return isEsqlTableTypeDataSource(layer.data_source); } function isAPIPieChartLayer(layer: PartitionState): layer is PieState { @@ -486,22 +486,22 @@ function fromLensStateToAPIDataset( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences: SavedObjectReference[] -): Pick { +): Pick { const layerId = visualization.layers[0].layerId; if (layer) { if (isTextBasedLayer(layer)) { - return { dataset: buildDatasetStateESQL(layer) as PartitionStateESQL['dataset'] }; + return { data_source: buildDataSourceStateESQL(layer) as PartitionStateESQL['data_source'] }; } if (isFormBasedLayer(layer)) { return { - dataset: buildDatasetStateNoESQL( + data_source: buildDataSourceStateNoESQL( layer, layerId, adHocDataViews, references, adhocReferences - ) as PartitionState['dataset'], + ) as PartitionState['data_source'], }; } } @@ -543,7 +543,7 @@ function getUniqueIds(array: string[]): string[] { return Array.from(new Set(array)); } -// Helper function to overcome the failure of partition chart migrations (found in integration dataset) +// Helper function to overcome the failure of partition chart migrations (found in integration data_source) function getGroups(vizLayer: LensPartitionVisualizationState['layers'][0]): string[] { if ('groups' in vizLayer && Array.isArray(vizLayer.groups)) { return getUniqueIds(vizLayer.groups); @@ -551,7 +551,7 @@ function getGroups(vizLayer: LensPartitionVisualizationState['layers'][0]): stri return getUniqueIds(vizLayer.primaryGroups ?? []); } -// Helper function to overcome the failure of partition chart migrations (found in integration dataset) +// Helper function to overcome the failure of partition chart migrations (found in integration data_source) function getMetrics(vizLayer: LensPartitionVisualizationState['layers'][0]): string[] { if ('metric' in vizLayer && typeof vizLayer.metric === 'string') { return [vizLayer.metric]; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts index 330a687bad3a2..a241d1aa8a618 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts @@ -29,7 +29,7 @@ import type { LensAttributes } from '../../types'; import { DEFAULT_LAYER_ID } from '../../constants'; import { addLayerColumn, - buildDatasetState, + buildDataSourceState, buildDatasourceStates, buildReferences, generateApiLayer, @@ -72,14 +72,20 @@ function getRegionMapDataset( references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [], layerId: string -): RegionMapState['dataset'] { - const dataset = buildDatasetState(layer, layerId, adHocDataViews, references, adhocReferences); +): RegionMapState['data_source'] { + const dataSource = buildDataSourceState( + layer, + layerId, + adHocDataViews, + references, + adhocReferences + ); - if (!dataset || dataset.type == null) { - throw new Error('Unsupported dataset type'); + if (!dataSource || dataSource.type == null) { + throw new Error('Unsupported DataSource type'); } - return dataset; + return dataSource; } function getRegionMapMetric( @@ -124,13 +130,19 @@ function reverseBuildVisualizationState( references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] ): RegionMapState { - const dataset = getRegionMapDataset(layer, adHocDataViews, references, adhocReferences, layerId); + const dataSource = getRegionMapDataset( + layer, + adHocDataViews, + references, + adhocReferences, + layerId + ); const metric = getRegionMapMetric(layer, visualization); const region = getRegionMapRegion(layer, visualization); return { type: 'region_map', - dataset, + data_source: dataSource, ...generateApiLayer(layer), metric, region, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts index a19a0ebb263cd..b555dcdfb5dce 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts @@ -30,7 +30,7 @@ import type { LensAttributes } from '../../types'; import { DEFAULT_LAYER_ID } from '../../constants'; import { addLayerColumn, - buildDatasetState, + buildDataSourceState, buildDatasourceStates, buildReferences, generateApiLayer, @@ -82,14 +82,20 @@ function getTagcloudDataset( references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [], layerId: string -): TagcloudState['dataset'] { - const dataset = buildDatasetState(layer, layerId, adHocDataViews, references, adhocReferences); +): TagcloudState['data_source'] { + const dataSource = buildDataSourceState( + layer, + layerId, + adHocDataViews, + references, + adhocReferences + ); - if (!dataset || dataset.type == null) { - throw new Error('Unsupported dataset type'); + if (!dataSource || dataSource.type == null) { + throw new Error('Unsupported DataSource type'); } - return dataset; + return dataSource; } function getTagcloudMetric( @@ -136,13 +142,19 @@ function reverseBuildVisualizationState( references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] ): TagcloudState { - const dataset = getTagcloudDataset(layer, adHocDataViews, references, adhocReferences, layerId); + const dataSource = getTagcloudDataset( + layer, + adHocDataViews, + references, + adhocReferences, + layerId + ); const metric = getTagcloudMetric(layer, visualization); const tagBy = getTagcloudTagBy(layer, visualization); return { type: 'tag_cloud', - dataset, + data_source: dataSource, ...generateApiLayer(layer), metric, tag_by: tagBy, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/api_layers.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/api_layers.ts index 3e7e1af1b63b9..6b6bcefc223a0 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/api_layers.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/api_layers.ts @@ -26,6 +26,8 @@ import { isPersistedByReferenceAnnotationsLayer, isPersistedLinkedByValueAnnotationsLayer, } from '@kbn/lens-common'; +import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; +import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import type { AnnotationLayerByValueType, AnnotationLayerType, @@ -37,9 +39,9 @@ import type { ReferenceLineLayerTypeNoESQL, } from '../../../schema/charts/xy'; import { LENS_IGNORE_GLOBAL_FILTERS_DEFAULT_VALUE } from '../../../schema/constants'; -import type { DatasetType } from '../../../schema/dataset'; +import type { DataSourceType } from '../../../schema/data_source'; import type { LensApiStaticValueOperation } from '../../../schema/metric_ops'; -import { isEsqlTableTypeDataset } from '../../../utils'; +import { isEsqlTableTypeDataSource } from '../../../utils'; import { fromColorMappingLensStateToAPI, fromStaticColorLensStateToAPI } from '../../coloring'; import { getValueApiColumn } from '../../columns/esql_column'; import { toApiFilterLanguage } from '../../columns/filter'; @@ -49,7 +51,7 @@ import { isAPIColumnOfType, } from '../../columns/utils'; import { - buildDatasetState, + buildDataSourceState, generateApiLayer, isDataViewSpec, isFormBasedLayer, @@ -62,15 +64,17 @@ import { stripUndefined } from '../utils'; function convertDataLayerToAPI( visualization: XYDataLayerConfig, layer: Omit -): Omit; +): Omit; function convertDataLayerToAPI( visualization: XYDataLayerConfig, layer: TextBasedLayer -): Omit; +): Omit; function convertDataLayerToAPI( visualization: XYDataLayerConfig, layer: Omit | TextBasedLayer -): Omit | Omit { +): + | Omit + | Omit { const yConfigMap = new Map(visualization.yConfig?.map((y) => [y.forAccessor, y])); if (isFormBasedLayer(layer)) { const x = visualization.xAccessor @@ -197,7 +201,7 @@ export function buildAPIDataLayer( ): DataLayerType { const type = convertSeriesTypeToAPIFormat(visualization.seriesType); if (isTextBasedLayer(layer)) { - const dataset = buildDatasetState( + const dataSource = buildDataSourceState( layer, visualization.layerId, adHocDataViews, @@ -205,17 +209,17 @@ export function buildAPIDataLayer( adhocReferences ); const baseLayer = convertDataLayerToAPI(visualization, layer); - if (isEsqlTableTypeDataset(dataset)) { + if (isEsqlTableTypeDataSource(dataSource)) { return { type, - dataset, + data_source: dataSource, ...baseLayer, }; } // this should be a never as schema should ensure this scenario never happens throw new Error('Text based layers can only be used with ESQL or Table datasets'); } - const dataset = buildDatasetState( + const dataSource = buildDataSourceState( layer, visualization.layerId, adHocDataViews, @@ -223,7 +227,7 @@ export function buildAPIDataLayer( adhocReferences ); - if (isEsqlTableTypeDataset(dataset)) { + if (isEsqlTableTypeDataSource(dataSource)) { // this should be a never as schema should ensure this scenario never happens throw new Error('Form based layers cannot be used with ESQL or Table datasets'); } @@ -231,7 +235,7 @@ export function buildAPIDataLayer( return { type, - dataset, + data_source: dataSource, ...baseLayer, }; } @@ -275,15 +279,15 @@ function getLabelFromLayer( function convertReferenceLineLayerToAPI( visualization: XYReferenceLineLayerConfig, layer: Omit -): Omit; +): Omit; function convertReferenceLineLayerToAPI( visualization: XYReferenceLineLayerConfig, layer: TextBasedLayer -): Omit; +): Omit; function convertReferenceLineLayerToAPI( visualization: XYReferenceLineLayerConfig, layer: Omit | TextBasedLayer -): Omit { +): Omit { const yConfigMap = new Map(visualization.yConfig?.map((y) => [y.forAccessor, y])); const thresholds = (visualization.accessors ?.map((accessor): ReferenceLineDef | undefined => { @@ -330,7 +334,7 @@ export function buildAPIReferenceLinesLayer( references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] ): ReferenceLineLayerType { - const dataset = buildDatasetState( + const dataSource = buildDataSourceState( layer, visualization.layerId, adHocDataViews, @@ -338,21 +342,21 @@ export function buildAPIReferenceLinesLayer( adhocReferences ); if (isTextBasedLayer(layer)) { - if (isEsqlTableTypeDataset(dataset)) { + if (isEsqlTableTypeDataSource(dataSource)) { return { type: 'referenceLines', - dataset, + data_source: dataSource, ...convertReferenceLineLayerToAPI(visualization, layer), }; } throw new Error('Text based layers can only be used with ESQL or Table datasets'); } - if (isEsqlTableTypeDataset(dataset)) { + if (isEsqlTableTypeDataSource(dataSource)) { throw new Error('Form based layers cannot be used with ESQL or Table datasets'); } return { type: 'referenceLines', - dataset, + data_source: dataSource, ...convertReferenceLineLayerToAPI(visualization, layer), }; } @@ -425,21 +429,24 @@ export function buildAPIAnnotationsLayer( layer.ignoreGlobalFilters ?? LENS_IGNORE_GLOBAL_FILTERS_DEFAULT_VALUE; const adHocDataView = adHocDataViews[layer.layerId]; const referencedDataView = findAnnotationDataView(layer.layerId, references); - const dataset = ( + const dataSource = ( isDataViewSpec(adHocDataView) && adHocDataView?.id === indexPatternId ? { - type: 'index', - index: indexPatternId, - time_field: adHocDataView.timeFieldName!, + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: indexPatternId, + time_field: adHocDataView.timeFieldName, } : { - type: 'dataView', - id: referencedDataView ?? indexPatternId, + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: referencedDataView ?? indexPatternId, } - ) satisfies Extract; + ) satisfies Extract< + DataSourceType, + { type: typeof AS_CODE_DATA_VIEW_REFERENCE_TYPE | typeof AS_CODE_DATA_VIEW_SPEC_TYPE } + >; return { type: 'annotations', - dataset, + data_source: dataSource, ignore_global_filters, events: layer.annotations.map((annotation) => { if (isQueryAnnotationConfig(annotation)) { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/helpers.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/helpers.ts index ee3fc86c5670c..3ff5e48bcc540 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/helpers.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/helpers.ts @@ -15,7 +15,7 @@ import type { LayerTypeNoESQL, ReferenceLineLayerType, } from '../../../schema/charts/xy'; -import { isEsqlTableTypeDataset } from '../../../utils'; +import { isEsqlTableTypeDataSource } from '../../../utils'; import { AVAILABLE_XY_LAYER_TYPES, XY_ANNOTATION_LAYER_TYPES, @@ -63,7 +63,7 @@ export function isAPIXYLayer(layer: unknown): layer is XYLayer { } export function isAPIesqlXYLayer(layer: XYLayer): layer is LayerTypeESQL { - return 'dataset' in layer && isEsqlTableTypeDataset(layer.dataset); + return 'data_source' in layer && isEsqlTableTypeDataSource(layer.data_source); } export function isLensStateDataLayer( diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts index e34b49832d517..5986ed70c8175 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts @@ -10,11 +10,11 @@ import { buildDatasourceStates, buildReferences, - getDatasetIndex, + getDataSourceIndex, addLayerColumn, getDefaultReferences, operationFromColumn, - buildDatasetState, + buildDataSourceState, isSingleLayer, generateLayer, filtersAndQueryToLensState, @@ -27,6 +27,7 @@ import type { ReferenceBasedIndexPatternColumn, } from '@kbn/lens-common'; import type { TextBasedLayer } from '@kbn/lens-common'; +import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; import type { LensApiState, MetricState } from '../schema'; import type { AggregateQuery, Filter, Query } from '@kbn/es-query'; import type { LensAttributes } from '../types'; @@ -56,9 +57,9 @@ test('build references correctly builds references', () => { describe('getDatasetIndex', () => { test('returns index if provided', () => { - const result = getDatasetIndex({ - type: 'index', - index: 'test', + const result = getDataSourceIndex({ + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: 'test', time_field: '@timestamp', }); expect(result).toMatchInlineSnapshot(` @@ -70,7 +71,7 @@ describe('getDatasetIndex', () => { }); test('extracts index from esql query', () => { - const result = getDatasetIndex({ + const result = getDataSourceIndex({ type: 'esql', query: 'from test_index | limit 10', }); @@ -84,7 +85,7 @@ describe('getDatasetIndex', () => { }); test('returns undefined if no query or iundex provided', () => { - const result = getDatasetIndex({ + const result = getDataSourceIndex({ type: 'table', table: { columns: [], @@ -236,7 +237,7 @@ describe('buildDatasourceStates', () => { { type: 'metric', title: 'test', - dataset: { + data_source: { type: 'esql', query: 'from test | limit 10', }, @@ -361,8 +362,8 @@ describe('operationFromColumn', () => { }); }); -describe('buildDatasetState', () => { - test('builds esql dataset state', () => { +describe('buildDataSourceState', () => { + test('builds esql data_source state', () => { const textBasedLayer = { index: 'my-index', query: { esql: 'from my-index | limit 10' }, @@ -370,7 +371,7 @@ describe('buildDatasetState', () => { allColumns: [], } as TextBasedLayer; - const result = buildDatasetState( + const result = buildDataSourceState( textBasedLayer, 'layer_0', {}, @@ -391,30 +392,30 @@ describe('buildDatasetState', () => { `); }); - test('builds dataView dataset state', () => { + test('builds dataView data_source state', () => { const formBasedLayer = { indexPatternId: 'my-dataview-id', columns: {}, columnOrder: [], } as FormBasedLayer; - const result = buildDatasetState(formBasedLayer, 'layer_0', {}, [], []); + const result = buildDataSourceState(formBasedLayer, 'layer_0', {}, [], []); expect(result).toMatchInlineSnapshot(` Object { - "id": "my-dataview-id", - "type": "dataView", + "ref_id": "my-dataview-id", + "type": "data_view_reference", } `); }); - test('builds index dataset state', () => { + test('builds index data_source state', () => { const formBasedLayer = { indexPatternId: 'my-adhoc-dataview-id', columns: {}, columnOrder: [], } as FormBasedLayer; - const result = buildDatasetState( + const result = buildDataSourceState( formBasedLayer, 'layer_1', { @@ -435,9 +436,9 @@ describe('buildDatasetState', () => { ); expect(result).toMatchInlineSnapshot(` Object { - "index": "my-adhoc-dataview-id", + "index_pattern": "my-adhoc-dataview-id", "time_field": "@timestamp", - "type": "index", + "type": "data_view_spec", } `); }); @@ -511,7 +512,7 @@ describe('filtersAndQueryToLensState', () => { const apiState: LensApiState = { type: 'metric', title: 'test metric', - dataset: { + data_source: { type: 'esql', query: 'from test | limit 10', }, @@ -564,7 +565,7 @@ describe('filtersAndQueryToLensState', () => { const apiState: LensApiState = { type: 'metric', title: 'test metric', - dataset: { + data_source: { type: 'esql', query: 'from test | limit 10', }, @@ -596,7 +597,7 @@ describe('filtersAndQueryToLensState', () => { const apiState: LensApiState = { type: 'metric', title: 'test metric', - dataset: { + data_source: { type: 'esql', query: 'from test | limit 10', }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts index b2bcd1fd23e5d..4930b3095a21d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts @@ -27,6 +27,11 @@ import type { DataViewSpec } from '@kbn/data-views-plugin/common'; import { FILTERS, isOfAggregateQueryType, type Filter, type Query } from '@kbn/es-query'; import type { AsCodeFilter } from '@kbn/as-code-filters-schema'; import { fromStoredFilters, toStoredFilters } from '@kbn/as-code-filters-transforms'; +import { + AS_CODE_DATA_VIEW_REFERENCE_TYPE, + AS_CODE_DATA_VIEW_SPEC_TYPE, +} from '@kbn/as-code-data-views-schema'; +import type { AsCodeDataViewReference } from '@kbn/as-code-data-views-schema'; import type { LensAttributes, LensDatatableDataset } from '../types'; import type { LensApiAllOperations, LensApiState, NarrowByType } from '../schema'; import { fromBucketLensStateToAPI } from './columns/buckets'; @@ -40,7 +45,11 @@ import { } from '../schema/constants'; import type { LayerSettingsSchema } from '../schema/shared'; import type { LensApiFilterType } from '../schema/filter'; -import type { DatasetType, DatasetTypeESQL, DatasetTypeNoESQL } from '../schema/dataset'; +import type { + DataSourceType, + DataSourceTypeESQL, + DataSourceTypeNoESQL, +} from '../schema/data_source'; import type { LayerTypeESQL } from '../schema/charts/xy'; import type { XScaleSchemaType } from '../schema/charts/shared'; import { fromFilterLensStateToAPI, toLensStateFilterLanguage } from './columns/filter'; @@ -187,7 +196,7 @@ export const getAdhocDataviews = (dataviews: Record ref.name === `${LENS_LAYER_SUFFIX}${layerId}`; } -export function buildDatasetStateNoESQL( +export function buildDataSourceStateNoESQL( layer: FormBasedLayer | Omit, layerId: string, adHocDataViews: Record, references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [] -): DatasetTypeNoESQL { +): DataSourceTypeNoESQL { const referenceCriteria = getReferenceCriteria(layerId); const adhocReference = adhocReferences?.find(referenceCriteria); if (adhocReference && adHocDataViews?.[adhocReference.id]) { const dataViewSpec = adHocDataViews[adhocReference.id]; - if (isDataViewSpec(dataViewSpec)) { + if (isDataViewSpec(dataViewSpec) && dataViewSpec.title) { return { - type: 'index', - index: dataViewSpec.title!, + type: AS_CODE_DATA_VIEW_SPEC_TYPE, + index_pattern: dataViewSpec.title, time_field: dataViewSpec.timeFieldName, }; } @@ -226,34 +235,34 @@ export function buildDatasetStateNoESQL( const reference = references?.find(referenceCriteria); if (reference) { return { - type: 'dataView', - id: reference.id, + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: reference.id, }; } return { - type: 'dataView', - id: 'indexPatternId' in layer ? layer.indexPatternId ?? '' : '', + type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, + ref_id: 'indexPatternId' in layer ? layer.indexPatternId ?? '' : '', }; } /** - * Builds dataset state from the layer configuration + * Builds Data Source State from the layer configuration * * @deprecated use `buildDatasetStateESQL` or `buildDatasetStateNoESQL` instead */ -export function buildDatasetState( +export function buildDataSourceState( layer: FormBasedLayer | Omit | TextBasedLayer, layerId: string, adHocDataViews: Record, references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [] -): DatasetType { +): DataSourceType { if (isTextBasedLayer(layer)) { - return buildDatasetStateESQL(layer); + return buildDataSourceStateESQL(layer); } - return buildDatasetStateNoESQL(layer, layerId, adHocDataViews, references, adhocReferences); + return buildDataSourceStateNoESQL(layer, layerId, adHocDataViews, references, adhocReferences); } // builds Lens State references from list of dataviews @@ -274,35 +283,35 @@ export function isSingleLayer( } /** - * Gets DataView from the dataset configuration + * Gets DataView from the DataSource configuration * - * @param dataset + * @param dataSource * @param dataViewsAPI * @returns */ -export function getDatasetIndex(dataset: DatasetType) { +export function getDataSourceIndex(dataSource: DataSourceType) { const timeFieldName: string = LENS_DEFAULT_TIME_FIELD; - switch (dataset.type) { - case 'index': + switch (dataSource.type) { + case AS_CODE_DATA_VIEW_SPEC_TYPE: return { - index: dataset.index, - timeFieldName, + index: dataSource.index_pattern, + timeFieldName: dataSource.time_field ?? timeFieldName, }; case 'esql': return { - index: getIndexPatternFromESQLQuery(dataset.query), - timeFieldName: getTimeFieldFromESQLQuery(dataset.query), - esqlQuery: dataset.query, + index: getIndexPatternFromESQLQuery(dataSource.query), + timeFieldName: getTimeFieldFromESQLQuery(dataSource.query), + esqlQuery: dataSource.query, }; - case 'dataView': + case AS_CODE_DATA_VIEW_REFERENCE_TYPE: return { - index: dataset.id, + index: dataSource.ref_id, timeFieldName, }; case 'table': return; default: - throw Error('dataset type not supported'); + throw Error('Data Source type not supported'); } } @@ -310,8 +319,8 @@ export function getDatasetIndex(dataset: DatasetType) { function buildDatasourceStatesLayer( layer: unknown, i: number, - dataset: DatasetType, - datasetIndex: { index: string; timeFieldName: string | undefined; esqlQuery?: string }, + dataSource: DataSourceType, + dataSourceIndex: { index: string; timeFieldName: string | undefined; esqlQuery?: string }, buildDataLayer: ( config: unknown, i: number, @@ -326,7 +335,7 @@ function buildDatasourceStatesLayer( ): [LensDatasourceId, DataSourceStateLayer | undefined] { function buildValueLayer( config: unknown, - ds: NarrowByType + ds: NarrowByType ): TextBasedPersistedState['layers'][0] { const table = ds.table as LensDatatableDataset; const xAxisScale = @@ -350,27 +359,27 @@ function buildDatasourceStatesLayer( function buildESQLLayer( config: unknown, - ds: NarrowByType + ds: NarrowByType ): TextBasedPersistedState['layers'][0] { const xAxisScale = fullConfig.type === 'xy' && fullConfig.axis?.x ? fullConfig.axis.x.scale : undefined; const columns = getValueColumns(config, i, xAxisScale); return { - index: generateAdHocDataViewId({ ...datasetIndex, dataSourceType: 'esql' }), + index: generateAdHocDataViewId({ ...dataSourceIndex, dataSourceType: 'esql' }), query: { esql: ds.query }, - timeField: datasetIndex.timeFieldName || undefined, + timeField: dataSourceIndex.timeFieldName || undefined, columns, }; } - if (dataset.type === 'esql') { - return [LENS_DATASOURCE_ID.TEXT_BASED, buildESQLLayer(layer, dataset)]; + if (dataSource.type === 'esql') { + return [LENS_DATASOURCE_ID.TEXT_BASED, buildESQLLayer(layer, dataSource)]; } - if (dataset.type === 'table') { - return [LENS_DATASOURCE_ID.TEXT_BASED, buildValueLayer(layer, dataset)]; + if (dataSource.type === 'table') { + return [LENS_DATASOURCE_ID.TEXT_BASED, buildValueLayer(layer, dataSource)]; } - return [LENS_DATASOURCE_ID.FORM_BASED, buildDataLayer(layer, i, datasetIndex)]; + return [LENS_DATASOURCE_ID.FORM_BASED, buildDataLayer(layer, i, dataSourceIndex)]; } /** @@ -378,8 +387,8 @@ function buildDatasourceStatesLayer( * * @param config lens api state * @param dataviews list to which dataviews are added - * @param buildFormulaLayers function used when dataset type is index or dataView - * @param getValueColumns function used when dataset type is table or esql + * @param buildFormulaLayers function used when data_source type is index or dataView + * @param getValueColumns function used when data_source type is table or esql * @param dataViewsAPI dataViews service * @returns lens datasource states * @@ -398,8 +407,8 @@ export const buildDatasourceStates = ( } => { let layers: Partial = {}; - // XY charts have dataset encoded per layer not at the root level - const mainDataset = ('dataset' in config && config.dataset) || undefined; + // XY charts have data_source encoded per layer not at the root level + const mainDataset = ('data_source' in config && config.data_source) || undefined; const usedDataviews: Record = {}; // a few charts types support multiple layers const hasMultipleLayers = 'layers' in config; @@ -411,28 +420,28 @@ export const buildDatasourceStates = ( hasMultipleLayers && 'type' in layer ? `${layer.type}_${layerPosition}` : `layer_${layerPosition}`; - const dataset = 'dataset' in layer ? layer.dataset : mainDataset; + const dataSource = 'data_source' in layer ? layer.data_source : mainDataset; - if (!dataset) { + if (!dataSource) { if ('type' in layer && layer.type === 'annotation_group' && 'group_id' in layer) { - // by-ref annotation layers don't require a dataset + // by-ref annotation layers don't require a data_source continue; } - throw Error('dataset must be defined'); + throw Error('DataSource must be defined'); } - // This datasetIndex is always defined, but it can be empty if the dataset is a table - // TODO evaluate the table dataset type and return the correct dataset index - const datasetIndex = getDatasetIndex(dataset); - if (!datasetIndex) { - throw Error('dataset index must be defined'); + // This datasetIndex is always defined, but it can be empty if the data_source is a table + // TODO evaluate the table data_source type and return the correct data_source index + const dataSourceIndex = getDataSourceIndex(dataSource); + if (!dataSourceIndex) { + throw Error('DataSource index must be defined'); } const [type, layerConfig] = buildDatasourceStatesLayer( layer, layerPosition, - dataset, - datasetIndex, + dataSource, + dataSourceIndex, buildDataLayers, getValueColumns, config @@ -455,13 +464,13 @@ export const buildDatasourceStates = ( : Object.keys(layerConfig); for (const id of newLayerIds) { usedDataviews[id] = - dataset.type === 'dataView' - ? { type: 'dataView', id: dataset.id } + dataSource.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE + ? { type: 'dataView', id: (dataSource as AsCodeDataViewReference).ref_id } : { type: 'adHocDataView', - ...datasetIndex, - ...(dataset.type === 'esql' - ? { dataSourceType: 'esql', esqlQuery: dataset.query } + ...dataSourceIndex, + ...(dataSource.type === 'esql' + ? { dataSourceType: 'esql', esqlQuery: dataSource.query } : {}), }; } @@ -640,16 +649,17 @@ export const filtersAndQueryToApiFormat = ( }; function extraQueryFromAPIState(state: LensApiState): { esql: string } | Query | undefined { - if ('dataset' in state && state.dataset.type === 'esql') { - return { esql: state.dataset.query }; + if ('data_source' in state && state.data_source.type === 'esql') { + return { esql: state.data_source.query }; } if ('layers' in state && Array.isArray(state.layers)) { // pick only the first one for now const esqlLayer = state.layers.find( - (layer): layer is LayerTypeESQL => 'dataset' in layer && layer.dataset?.type === 'esql' + (layer): layer is LayerTypeESQL => + 'data_source' in layer && layer.data_source?.type === 'esql' ); - if (esqlLayer && 'query' in esqlLayer.dataset) { - return { esql: esqlLayer.dataset.query }; + if (esqlLayer && 'query' in esqlLayer.data_source) { + return { esql: esqlLayer.data_source.query }; } } if ('query' in state && state.query) { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts index c36efbf61fcda..ade06c2ea1a27 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts @@ -38,7 +38,7 @@ import type { LensESQLDataset, } from './types'; import type { LensApiState } from './schema'; -import type { DatasetType } from './schema/dataset'; +import type { DataSourceType } from './schema/data_source'; type DataSourceStateLayer = | FormBasedPersistedState['layers'] // metric chart can return 2 layers (one for the metric and one for the trendline) @@ -364,10 +364,10 @@ export function isLensLegacyAttributes(config: unknown): config is LensAttribute ); } -export function isEsqlTableTypeDataset( - dataset: DatasetType -): dataset is Extract { - return dataset.type === 'esql' || dataset.type === 'table'; +export function isEsqlTableTypeDataSource( + dataSource: DataSourceType +): dataSource is Extract { + return dataSource.type === 'esql' || dataSource.type === 'table'; } export function groupIsNotCollapsed(def: { @@ -378,6 +378,8 @@ export function groupIsNotCollapsed(def: { export function isLensESQLConfig(config: LensApiState): boolean { if (config.type === 'xy') - return config.layers.some((layer) => 'dataset' in layer && layer.dataset?.type === 'esql'); - return config.dataset?.type === 'esql'; + return config.layers.some( + (layer) => 'data_source' in layer && layer.data_source?.type === 'esql' + ); + return config.data_source?.type === 'esql'; } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/moon.yml b/src/platform/packages/shared/kbn-lens-embeddable-utils/moon.yml index 8909afaf2c25c..adbb15174a253 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/moon.yml +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/moon.yml @@ -19,6 +19,7 @@ project: dependsOn: - '@kbn/core' - '@kbn/as-code-filters-schema' + - '@kbn/as-code-data-views-schema' - '@kbn/as-code-filters-transforms' - '@kbn/data-views-plugin' - '@kbn/event-annotation-common' diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/tsconfig.json b/src/platform/packages/shared/kbn-lens-embeddable-utils/tsconfig.json index ceeebe3648aba..8116c28b534bb 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/tsconfig.json +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/tsconfig.json @@ -9,6 +9,7 @@ "kbn_references": [ "@kbn/core", "@kbn/as-code-filters-schema", + "@kbn/as-code-data-views-schema", "@kbn/as-code-filters-transforms", "@kbn/data-views-plugin", "@kbn/event-annotation-common", diff --git a/src/platform/plugins/shared/data_views/common/constants.ts b/src/platform/plugins/shared/data_views/common/constants.ts index 10c152178f480..69fe5e429c212 100644 --- a/src/platform/plugins/shared/data_views/common/constants.ts +++ b/src/platform/plugins/shared/data_views/common/constants.ts @@ -13,6 +13,8 @@ */ export const RUNTIME_FIELD_COMPOSITE_TYPE = 'composite' as const; +export type RuntimeFieldCompositeType = typeof RUNTIME_FIELD_COMPOSITE_TYPE; + export const PRIMITIVE_RUNTIME_FIELD_TYPES = [ 'keyword', 'long', @@ -23,6 +25,8 @@ export const PRIMITIVE_RUNTIME_FIELD_TYPES = [ 'geo_point', ] as const; +export type PrimitiveRuntimeFieldTypes = typeof PRIMITIVE_RUNTIME_FIELD_TYPES; + export const RUNTIME_FIELD_TYPES = [ ...PRIMITIVE_RUNTIME_FIELD_TYPES, RUNTIME_FIELD_COMPOSITE_TYPE, diff --git a/src/platform/plugins/shared/data_views/common/index.ts b/src/platform/plugins/shared/data_views/common/index.ts index 2912701bc7e70..4d62ec2b7e78a 100644 --- a/src/platform/plugins/shared/data_views/common/index.ts +++ b/src/platform/plugins/shared/data_views/common/index.ts @@ -17,6 +17,7 @@ export { MAX_DATA_VIEW_FIELD_DESCRIPTION_LENGTH, HasEsDataFailureReason, } from './constants'; +export type { PrimitiveRuntimeFieldTypes, RuntimeFieldCompositeType } from './constants'; export { LATEST_VERSION } from './content_management/v1/constants'; diff --git a/x-pack/examples/lens_config_builder_example/public/app.tsx b/x-pack/examples/lens_config_builder_example/public/app.tsx index e003fac7b8980..1922a5caed5dc 100644 --- a/x-pack/examples/lens_config_builder_example/public/app.tsx +++ b/x-pack/examples/lens_config_builder_example/public/app.tsx @@ -50,7 +50,7 @@ export const App = (props: { const [lensConfig, setLensConfig] = useState({ type: 'metric', title: 'Total Sales', - dataset: { + data_source: { type: 'esql', query: 'from kibana_sample_data_logs | stats totalBytes = sum(bytes)', }, diff --git a/x-pack/platform/test/api_integration/apis/lens/examples.ts b/x-pack/platform/test/api_integration/apis/lens/examples.ts index 3636f54da31b5..2a6fa702b8992 100644 --- a/x-pack/platform/test/api_integration/apis/lens/examples.ts +++ b/x-pack/platform/test/api_integration/apis/lens/examples.ts @@ -20,7 +20,7 @@ export const getExampleLensBody = ( description, ignore_global_filters: false, sampling: 1, - dataset: { type: 'dataView', id: SAMPLE_DATA_VIEW_ID }, + data_source: { type: 'data_view_reference', ref_id: SAMPLE_DATA_VIEW_ID }, metrics: [ { type: 'primary',