diff --git a/src/core/server/saved_objects/saved_objects_service.ts b/src/core/server/saved_objects/saved_objects_service.ts index e586e7189b3e6..02f2c013ee6bb 100644 --- a/src/core/server/saved_objects/saved_objects_service.ts +++ b/src/core/server/saved_objects/saved_objects_service.ts @@ -35,7 +35,7 @@ import { KibanaConfigType } from '../kibana_config'; import { migrationsRetryCallCluster } from '../elasticsearch/retry_call_cluster'; import { SavedObjectsConfigType } from './saved_objects_config'; import { KibanaRequest } from '../http'; -import { SavedObjectsClientContract, SavedObjectsLegacyMapping } from './types'; +import { SavedObjectsClientContract } from './types'; import { ISavedObjectsRepository, SavedObjectsRepository } from './service/lib/repository'; import { SavedObjectsClientFactoryProvider, @@ -46,7 +46,7 @@ import { SavedObjectsTypeMapping } from './mappings'; import { MigrationDefinition } from './migrations/core/document_migrator'; import { SavedObjectsSchemaDefinition } from './schema'; import { PropertyValidators } from './validation'; -// import { PluginOpaqueId } from '..'; +import { convertLegacyMappings } from './utils'; /** * Saved Objects is Kibana's data persistence mechanism allowing plugins to @@ -377,18 +377,3 @@ export class SavedObjectsService }); } } - -const convertLegacyMappings = ( - legacyMappings: SavedObjectsLegacyMapping[] -): SavedObjectsTypeMapping[] => { - return legacyMappings.reduce((mappings, { pluginId, properties }) => { - return [ - ...mappings, - ...Object.entries(properties).map(([type, definition]) => ({ - pluginId, - type, - definition, - })), - ]; - }, [] as SavedObjectsTypeMapping[]); -}; diff --git a/src/core/server/saved_objects/utils.ts b/src/core/server/saved_objects/utils.ts new file mode 100644 index 0000000000000..5da7c6d73522b --- /dev/null +++ b/src/core/server/saved_objects/utils.ts @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsLegacyMapping } from './types'; +import { SavedObjectsTypeMapping } from './mappings'; + +export const convertLegacyMappings = ( + legacyMappings: SavedObjectsLegacyMapping[] +): SavedObjectsTypeMapping[] => { + return legacyMappings.reduce((mappings, { pluginId, properties }) => { + return [ + ...mappings, + ...Object.entries(properties).map(([type, definition]) => ({ + pluginId, + type, + definition, + })), + ]; + }, [] as SavedObjectsTypeMapping[]); +}; diff --git a/src/es_archiver/lib/indices/kibana_index.js b/src/es_archiver/lib/indices/kibana_index.js index 744132bdcef69..202e7c4ea9590 100644 --- a/src/es_archiver/lib/indices/kibana_index.js +++ b/src/es_archiver/lib/indices/kibana_index.js @@ -26,6 +26,7 @@ import { toArray } from 'rxjs/operators'; import { deleteIndex } from './delete_index'; import { collectUiExports } from '../../../legacy/ui/ui_exports'; import { KibanaMigrator } from '../../../core/server/saved_objects/migrations'; +import { convertLegacyMappings } from '../../../core/server/saved_objects/utils'; import { SavedObjectsSchema } from '../../../core/server/saved_objects'; import { findPluginSpecs } from '../../../legacy/plugin_discovery'; @@ -103,7 +104,7 @@ export async function migrateKibanaIndex({ client, log, kibanaPluginIds }) { }, version: kibanaVersion, savedObjectSchemas: new SavedObjectsSchema(uiExports.savedObjectSchemas), - savedObjectMappings: uiExports.savedObjectMappings, + savedObjectMappings: convertLegacyMappings(uiExports.savedObjectMappings), savedObjectMigrations: uiExports.savedObjectMigrations, savedObjectValidations: uiExports.savedObjectValidations, callCluster: (path, ...args) => _.get(client, path).call(client, ...args),