Skip to content

Commit

Permalink
change default attributes type to unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 21, 2020
1 parent b769c2a commit b97d4c1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/core/server/saved_objects/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SavedObjectsMigrationLogger } from './core/migration_logger';
*
* @example
* ```typescript
* const migrateProperty: SavedObjectMigrationFn = (doc, { log }) => {
* const migrateProperty: SavedObjectMigrationFn<MyUnmigratedAttributes, MyMigratedAttributes> = (doc, { log }) => {
* if(doc.attributes.someProp === null) {
* log.warn('Skipping migration');
* } else {
Expand All @@ -39,10 +39,10 @@ import { SavedObjectsMigrationLogger } from './core/migration_logger';
*
* @public
*/
export type SavedObjectMigrationFn<InputProps = any, MigratedProps = any> = (
doc: SavedObjectUnsanitizedDoc<InputProps>,
export type SavedObjectMigrationFn<InputAttributes = unknown, MigratedAttributes = unknown> = (
doc: SavedObjectUnsanitizedDoc<InputAttributes>,
context: SavedObjectMigrationContext
) => SavedObjectUnsanitizedDoc<MigratedProps>;
) => SavedObjectUnsanitizedDoc<MigratedAttributes>;

/**
* Migration context provided when invoking a {@link SavedObjectMigrationFn | migration handler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SavedObjectMigrationFn } from 'kibana/server';
import { get } from 'lodash';
import { DEFAULT_QUERY_LANGUAGE } from '../../../../../../plugins/data/common';

export const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
export const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = doc => {
const searchSourceJSON = get<string>(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');

if (searchSourceJSON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { flow, omit } from 'lodash';
import { SavedObjectMigrationFn } from 'kibana/server';

const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn = doc => ({
const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn<any, any> = doc => ({
...doc,
attributes: {
...doc.attributes,
Expand All @@ -29,7 +29,7 @@ const migrateAttributeTypeAndAttributeTypeMeta: SavedObjectMigrationFn = doc =>
},
});

const migrateSubTypeAndParentFieldProperties: SavedObjectMigrationFn = doc => {
const migrateSubTypeAndParentFieldProperties: SavedObjectMigrationFn<any, any> = doc => {
if (!doc.attributes.fields) return doc;

const fieldsString = doc.attributes.fields;
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/data/server/saved_objects/search_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { flow, get } from 'lodash';
import { SavedObjectMigrationFn } from 'kibana/server';
import { DEFAULT_QUERY_LANGUAGE } from '../../common';

const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = doc => {
const searchSourceJSON = get<string>(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');

if (searchSourceJSON) {
Expand Down Expand Up @@ -55,7 +55,7 @@ const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
return doc;
};

const migrateIndexPattern: SavedObjectMigrationFn = doc => {
const migrateIndexPattern: SavedObjectMigrationFn<any, any> = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (typeof searchSourceJSON !== 'string') {
return doc;
Expand Down Expand Up @@ -97,13 +97,13 @@ const migrateIndexPattern: SavedObjectMigrationFn = doc => {
return doc;
};

const setNewReferences: SavedObjectMigrationFn = (doc, context) => {
const setNewReferences: SavedObjectMigrationFn<any, any> = (doc, context) => {
doc.references = doc.references || [];
// Migrate index pattern
return migrateIndexPattern(doc, context);
};

const migrateSearchSortToNestedArray: SavedObjectMigrationFn = doc => {
const migrateSearchSortToNestedArray: SavedObjectMigrationFn<any, any> = doc => {
const sort = get(doc, 'attributes.sort');
if (!sort) return doc;

Expand All @@ -122,7 +122,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn = doc => {
};

export const searchSavedObjectTypeMigrations = {
'6.7.2': flow<SavedObjectMigrationFn>(migrateMatchAllQuery),
'7.0.0': flow<SavedObjectMigrationFn>(setNewReferences),
'7.4.0': flow<SavedObjectMigrationFn>(migrateSearchSortToNestedArray),
'6.7.2': flow<SavedObjectMigrationFn<any, any>>(migrateMatchAllQuery),
'7.0.0': flow<SavedObjectMigrationFn<any, any>>(setNewReferences),
'7.4.0': flow<SavedObjectMigrationFn<any, any>>(migrateSearchSortToNestedArray),
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { flow } from 'lodash';
import { SavedObjectMigrationFn, SavedObjectsType } from 'kibana/server';

const resetCount: SavedObjectMigrationFn = doc => ({
const resetCount: SavedObjectMigrationFn<any, any> = doc => ({
...doc,
attributes: {
...doc.attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SavedObjectMigrationFn } from 'kibana/server';
import { cloneDeep, get, omit, has, flow } from 'lodash';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';

const migrateIndexPattern: SavedObjectMigrationFn = doc => {
const migrateIndexPattern: SavedObjectMigrationFn<any, any> = doc => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
if (typeof searchSourceJSON !== 'string') {
return doc;
Expand Down Expand Up @@ -64,7 +64,7 @@ const migrateIndexPattern: SavedObjectMigrationFn = doc => {
};

// [TSVB] Migrate percentile-rank aggregation (value -> values)
const migratePercentileRankAggregation: SavedObjectMigrationFn = doc => {
const migratePercentileRankAggregation: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');
let visState;

Expand Down Expand Up @@ -100,7 +100,7 @@ const migratePercentileRankAggregation: SavedObjectMigrationFn = doc => {
};

// [TSVB] Remove stale opperator key
const migrateOperatorKeyTypo: SavedObjectMigrationFn = doc => {
const migrateOperatorKeyTypo: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');
let visState;

Expand Down Expand Up @@ -132,7 +132,7 @@ const migrateOperatorKeyTypo: SavedObjectMigrationFn = doc => {
};

// Migrate date histogram aggregation (remove customInterval)
const migrateDateHistogramAggregation: SavedObjectMigrationFn = doc => {
const migrateDateHistogramAggregation: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');
let visState;

Expand Down Expand Up @@ -174,7 +174,7 @@ const migrateDateHistogramAggregation: SavedObjectMigrationFn = doc => {
return doc;
};

const removeDateHistogramTimeZones: SavedObjectMigrationFn = doc => {
const removeDateHistogramTimeZones: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');
if (visStateJSON) {
let visState;
Expand Down Expand Up @@ -206,7 +206,7 @@ const removeDateHistogramTimeZones: SavedObjectMigrationFn = doc => {

// migrate gauge verticalSplit to alignment
// https://github.com/elastic/kibana/issues/34636
const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn = (doc, logger) => {
const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');

if (visStateJSON) {
Expand Down Expand Up @@ -241,7 +241,7 @@ const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn = (doc, logge
Path to the series array is thus:
attributes.visState.
*/
const transformFilterStringToQueryObject: SavedObjectMigrationFn = (doc, logger) => {
const transformFilterStringToQueryObject: SavedObjectMigrationFn<any, any> = (doc, logger) => {
// Migrate filters
// If any filters exist and they are a string, we assume it to be lucene and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
Expand Down Expand Up @@ -325,7 +325,7 @@ const transformFilterStringToQueryObject: SavedObjectMigrationFn = (doc, logger)
return newDoc;
};

const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn = doc => {
const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn<any, any> = doc => {
// Migrate split_filters in TSVB objects that weren't migrated in 7.3
// If any filters exist and they are a string, we assume them to be lucene syntax and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
Expand Down Expand Up @@ -370,7 +370,7 @@ const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn = doc =>
return newDoc;
};

const migrateFiltersAggQuery: SavedObjectMigrationFn = doc => {
const migrateFiltersAggQuery: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');

if (visStateJSON) {
Expand Down Expand Up @@ -402,7 +402,7 @@ const migrateFiltersAggQuery: SavedObjectMigrationFn = doc => {
return doc;
};

const replaceMovAvgToMovFn: SavedObjectMigrationFn = (doc, logger) => {
const replaceMovAvgToMovFn: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
let visState;

Expand Down Expand Up @@ -450,7 +450,7 @@ const replaceMovAvgToMovFn: SavedObjectMigrationFn = (doc, logger) => {
return doc;
};

const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn = (doc, logger) => {
const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');

if (visStateJSON) {
Expand Down Expand Up @@ -483,12 +483,12 @@ const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn = (doc, logger
return doc;
};

const addDocReferences: SavedObjectMigrationFn = doc => ({
const addDocReferences: SavedObjectMigrationFn<any, any> = doc => ({
...doc,
references: doc.references || [],
});

const migrateSavedSearch: SavedObjectMigrationFn = doc => {
const migrateSavedSearch: SavedObjectMigrationFn<any, any> = doc => {
const savedSearchId = get<string>(doc, 'attributes.savedSearchId');

if (savedSearchId && doc.references) {
Expand All @@ -505,7 +505,7 @@ const migrateSavedSearch: SavedObjectMigrationFn = doc => {
return doc;
};

const migrateControls: SavedObjectMigrationFn = doc => {
const migrateControls: SavedObjectMigrationFn<any, any> = doc => {
const visStateJSON = get<string>(doc, 'attributes.visState');

if (visStateJSON) {
Expand Down Expand Up @@ -536,7 +536,7 @@ const migrateControls: SavedObjectMigrationFn = doc => {
return doc;
};

const migrateTableSplits: SavedObjectMigrationFn = doc => {
const migrateTableSplits: SavedObjectMigrationFn<any, any> = doc => {
try {
const visState = JSON.parse(doc.attributes.visState);
if (get(visState, 'type') !== 'table') {
Expand Down Expand Up @@ -572,7 +572,7 @@ const migrateTableSplits: SavedObjectMigrationFn = doc => {
}
};

const migrateMatchAllQuery: SavedObjectMigrationFn = doc => {
const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = doc => {
const searchSourceJSON = get<string>(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');

if (searchSourceJSON) {
Expand Down Expand Up @@ -617,26 +617,29 @@ export const visualizationSavedObjectTypeMigrations = {
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
'6.7.2': flow<SavedObjectMigrationFn>(migrateMatchAllQuery, removeDateHistogramTimeZones),
'7.0.0': flow<SavedObjectMigrationFn>(
'6.7.2': flow<SavedObjectMigrationFn<any, any>>(
migrateMatchAllQuery,
removeDateHistogramTimeZones
),
'7.0.0': flow<SavedObjectMigrationFn<any, any>>(
addDocReferences,
migrateIndexPattern,
migrateSavedSearch,
migrateControls,
migrateTableSplits
),
'7.0.1': flow<SavedObjectMigrationFn>(removeDateHistogramTimeZones),
'7.2.0': flow<SavedObjectMigrationFn>(
'7.0.1': flow<SavedObjectMigrationFn<any, any>>(removeDateHistogramTimeZones),
'7.2.0': flow<SavedObjectMigrationFn<any, any>>(
migratePercentileRankAggregation,
migrateDateHistogramAggregation
),
'7.3.0': flow<SavedObjectMigrationFn>(
'7.3.0': flow<SavedObjectMigrationFn<any, any>>(
migrateGaugeVerticalSplitToAlignment,
transformFilterStringToQueryObject,
migrateFiltersAggQuery,
replaceMovAvgToMovFn
),
'7.3.1': flow<SavedObjectMigrationFn>(migrateFiltersAggQueryStringQueries),
'7.4.2': flow<SavedObjectMigrationFn>(transformSplitFiltersStringToQueryObject),
'7.7.0': flow<SavedObjectMigrationFn>(migrateOperatorKeyTypo),
'7.3.1': flow<SavedObjectMigrationFn<any, any>>(migrateFiltersAggQueryStringQueries),
'7.4.2': flow<SavedObjectMigrationFn<any, any>>(transformSplitFiltersStringToQueryObject),
'7.7.0': flow<SavedObjectMigrationFn<any, any>>(migrateOperatorKeyTypo),
};
3 changes: 2 additions & 1 deletion x-pack/plugins/lens/server/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ interface XYLayerPre77 {
accessors: string[];
}

export const migrations: Record<string, SavedObjectMigrationFn> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const migrations: Record<string, SavedObjectMigrationFn<any, any>> = {
'7.7.0': doc => {
const newDoc = cloneDeep(doc);
if (newDoc.attributes?.visualizationType === 'lnsXY') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { SavedObjectMigrationFn } from 'src/core/server';

export const migrateToKibana660: SavedObjectMigrationFn = doc => {
export const migrateToKibana660: SavedObjectMigrationFn<any, any> = doc => {
if (!doc.attributes.hasOwnProperty('disabledFeatures')) {
doc.attributes.disabledFeatures = [];
}
Expand Down

0 comments on commit b97d4c1

Please sign in to comment.