Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { runtimeFieldSchema } from './schema_runtime_field';
export const dataViewReferenceSchema = schema.object(
{
type: schema.literal(AS_CODE_DATA_VIEW_REFERENCE_TYPE),
id: schema.string({
ref_id: schema.string({
meta: {
description:
'The id of the Kibana data view to use as the data source. Example: "my-data-view".',
},
}),
},
{ meta: { id: 'dataViewReferenceDataSourceTypeSchema' } }
{ meta: { id: 'kbn-data-view-reference-schema', title: 'Data view reference' } }
);

export const dataViewSpecSchema = schema.object(
Expand All @@ -43,7 +43,7 @@ export const dataViewSpecSchema = schema.object(
),
runtime_fields: schema.maybe(schema.arrayOf(runtimeFieldSchema, { maxSize: 100 })),
},
{ meta: { id: 'dataViewSpecDataSourceTypeSchema' } }
{ meta: { id: 'kbn-data-view-spec-schema', title: 'Data view inline spec' } }
);

export const dataViewSchema = schema.discriminatedUnion('type', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const commonRuntimeFieldSchema = {
minLength: 1,
maxLength: MAX_NAME_LENGTH,
meta: {
id: 'kbn-runtime-field-name',
title: 'Name',
description: 'The name of the runtime field. Example: "my_runtime_field".',
},
}),
Expand All @@ -39,6 +41,8 @@ const commonRuntimeFieldSchema = {
schema.string({
minLength: 1,
meta: {
id: 'kbn-runtime-field-script',
title: 'Script',
description:
"The script that defines the runtime field. This should be a painless script that computes the field value at query time. Runtime fields without a script retrieve values from _source. If the field doesn't exist in _source, a search request returns no value.",
},
Expand All @@ -57,7 +61,14 @@ const commonFieldSchema = {
type: schema.oneOf(
PRIMITIVE_RUNTIME_FIELD_TYPES.map((type) => schema.literal(type)) as [
Type<(typeof PRIMITIVE_RUNTIME_FIELD_TYPES)[number]>
]
],
{
meta: {
id: 'kbn-runtime-field-type',
title: 'Type',
description: 'The type of the runtime field (e.g., "keyword", "long", "date").',
},
}
),
/**
* Optional format definition for the runtime field. The structure depends on the field type and use case.
Expand All @@ -71,6 +82,8 @@ const commonFieldSchema = {
},
{
meta: {
id: 'kbn-runtime-field-format',
title: 'Format',
description:
'Set your preferred format for displaying the value. Changing the format can affect the value and prevent highlighting in Discover.',
},
Expand All @@ -81,6 +94,8 @@ const commonFieldSchema = {
schema.string({
minLength: 1,
meta: {
id: 'kbn-runtime-field-custom-label',
title: 'Custom label',
description:
'Create a label to display in place of the field name in Discover, Maps, Lens, Visualize, and TSVB. Useful for shortening a long field name. Queries and filters use the original field name.',
},
Expand All @@ -90,40 +105,48 @@ const commonFieldSchema = {
schema.string({
minLength: 1,
meta: {
id: 'kbn-runtime-field-custom-description',
title: 'Custom description',
description:
"Add a description to the field. It's displayed next to the field on the Discover, Lens, and Data View Management pages.",
},
})
),
};

export const primitiveRuntimeFieldSchema = schema.object({
...commonFieldSchema,
...commonRuntimeFieldSchema,
});
export const primitiveRuntimeFieldSchema = schema.object(
{
...commonFieldSchema,
...commonRuntimeFieldSchema,
},
{ meta: { id: 'kbn-runtime-field-schema', title: 'Runtime field' } }
);

export const compositeRuntimeFieldSchema = schema.object({
type: schema.literal(RUNTIME_FIELD_COMPOSITE_TYPE),
fields: schema.arrayOf(
schema.object({
/**
* The name of the subfield.
* If the name is "field" and this subname is "name" the full name of the subfield will be "field.name".
*/
name: schema.string({
minLength: 1,
maxLength: MAX_NAME_LENGTH,
meta: {
description:
'The name of the runtime subfield, it gets appended to the parent field name. Example: "parent_name.my_runtime_subfield".',
},
export const compositeRuntimeFieldSchema = schema.object(
{
type: schema.literal(RUNTIME_FIELD_COMPOSITE_TYPE),
fields: schema.arrayOf(
schema.object({
/**
* The name of the subfield.
* If the name is "field" and this subname is "name" the full name of the subfield will be "field.name".
*/
name: schema.string({
minLength: 1,
maxLength: MAX_NAME_LENGTH,
meta: {
description:
'The name of the runtime subfield, it gets appended to the parent field name. Example: "parent_name.my_runtime_subfield".',
},
}),
...commonFieldSchema,
}),
...commonFieldSchema,
}),
{ maxSize: 100 }
),
...commonRuntimeFieldSchema,
});
{ maxSize: 100 }
),
...commonRuntimeFieldSchema,
},
{ meta: { id: 'kbn-composite-runtime-field-schema', title: 'Composite runtime field' } }
);

export const runtimeFieldSchema = schema.discriminatedUnion('type', [
primitiveRuntimeFieldSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function fromStoredDataView(
): AsCodeDataView {
if (!index) throw new Error('Cannot derive data view from empty index');
if (typeof index === 'string') {
return { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: index };
return { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: index };
}
if (!index.title) throw new Error('Cannot derive data view without `title` or `id`');
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('toStoredDataView', () => {
it('converts data_view_reference data_source to string id', () => {
const dataView: AsCodeDataViewReference = {
type: AS_CODE_DATA_VIEW_REFERENCE_TYPE,
id: 'my-data-view-id',
ref_id: 'my-data-view-id',
};
const result = toStoredDataView(dataView);
expect(result).toBe('my-data-view-id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
* @returns Value suitable for `SerializedSearchSourceFields.index`
*/
export function toStoredDataView(dataView: AsCodeDataView): string | DataViewSpec {
if (dataView.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE) return dataView.id;
if (dataView.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE) return dataView.ref_id;
const runtimeFieldMap = toStoredRuntimeFields(dataView.runtime_fields);
const fieldFormats = toStoredFieldFormats(dataView.runtime_fields);
const fieldAttrs = toStoredFieldAttributes(dataView.runtime_fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('searchEmbeddableTransforms', () => {
expect(density).toBe(DataGridDensity.COMPACT);
expect(dataSource).toEqual({
type: AS_CODE_DATA_VIEW_REFERENCE_TYPE,
id: 'data-view-1',
ref_id: 'data-view-1',
});
expect(mockDrilldownTransforms.transformOut).toHaveBeenCalledWith(state, references);
});
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('searchEmbeddableTransforms', () => {
filters: [],
rows_per_page: 100,
sample_size: 1000,
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' },
},
],
};
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('searchEmbeddableTransforms', () => {
row_height: 3,
query: { language: 'kuery', query: '' },
filters: [],
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-id-123' },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-id-123' },
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('search embeddable transform utils', () => {

expect('tabs' in result && result.tabs).toBeDefined();
expect('tabs' in result && result.tabs?.[0]).toMatchObject({
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId },
});
});
});
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('search embeddable transform utils', () => {
row_height: 'auto',
query: { language: 'kuery', query: '' },
filters: [],
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' },
},
],
};
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('search embeddable transform utils', () => {
header_row_height: 3,
data_source: {
type: AS_CODE_DATA_VIEW_REFERENCE_TYPE,
id: 'c7d7a1f5-19da-4ba9-af15-5919e8cd2528',
ref_id: 'c7d7a1f5-19da-4ba9-af15-5919e8cd2528',
},
},
],
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('search embeddable transform utils', () => {
filters: [],
rows_per_page: 100,
sample_size: 1000,
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' },
},
],
};
Expand Down Expand Up @@ -1000,7 +1000,7 @@ describe('search embeddable transform utils', () => {
expect(result.density).toBe(DataGridDensity.COMPACT);
expect('data_source' in result && result.data_source).toEqual({
type: AS_CODE_DATA_VIEW_REFERENCE_TYPE,
id: 'data-view-1',
ref_id: 'data-view-1',
});
expect('view_mode' in result && result.view_mode).toBe(VIEW_MODE.DOCUMENT_LEVEL);
});
Expand All @@ -1020,7 +1020,7 @@ describe('search embeddable transform utils', () => {
filters: [],
rows_per_page: 100,
sample_size: 500,
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' },
};
const { state, references } = toStoredTab(apiTab);
expect(references).toContainEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Serialization utils', () => {
filters: [],
rows_per_page: 100,
sample_size: 100,
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId },
},
],
};
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('Serialization utils', () => {
sort: [{ name: 'order_date', direction: 'desc' }],
view_mode: VIEW_MODE.DOCUMENT_LEVEL,
density: DataGridDensity.COMPACT,
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId },
data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId },
}),
],
});
Expand Down
Loading