-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug][6.x] Revert mappings lib changes (#22004)
* Remove new library * Reinstate old mappings lib * Update paths to mappings lib * Remove remaining mappings lib
- Loading branch information
Showing
27 changed files
with
293 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
src/core/server/saved_objects/mappings/__snapshots__/index_mappings.test.ts.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/server/mappings/__snapshots__/index_mappings.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`server/mapping/index_mapping constructor includes the pluginId from the extension in the _ error message if defined 1`] = `"Property names _foo registered by plugin abc123 are not allowed to start with an underscore (_)"`; | ||
|
||
exports[`server/mapping/index_mapping constructor throws if any of the new properties start with _ 1`] = `"Property names _foo are not allowed to start with an underscore (_)"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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 { cloneDeep, isPlainObject } from 'lodash'; | ||
|
||
import { formatListAsProse } from '../../utils'; | ||
import { getRootProperties, getRootType } from './lib'; | ||
|
||
const DEFAULT_INITIAL_DSL = { | ||
rootType: { | ||
type: 'object', | ||
properties: {}, | ||
}, | ||
}; | ||
|
||
export class IndexMappings { | ||
constructor(initialDsl = DEFAULT_INITIAL_DSL, mappingExtensions = []) { | ||
this._dsl = cloneDeep(initialDsl); | ||
if (!isPlainObject(this._dsl)) { | ||
throw new TypeError('initial mapping must be an object'); | ||
} | ||
|
||
// ensure that we have a properties object in the dsl | ||
// and that the dsl can be parsed with getRootProperties() and kin | ||
this._setProperties(getRootProperties(this._dsl) || {}); | ||
|
||
// extend this._dsl with each extension (which currently come from uiExports.savedObjectMappings) | ||
mappingExtensions.forEach(({ properties, pluginId }) => { | ||
const rootProperties = getRootProperties(this._dsl); | ||
|
||
const conflicts = Object.keys(properties) | ||
.filter(key => rootProperties.hasOwnProperty(key)); | ||
|
||
const illegal = Object.keys(properties) | ||
.filter(key => key.startsWith('_')); | ||
|
||
if (conflicts.length) { | ||
const props = formatListAsProse(conflicts); | ||
const owner = pluginId ? `registered by plugin ${pluginId} ` : ''; | ||
throw new Error( | ||
`Mappings for ${props} ${owner}have already been defined` | ||
); | ||
} | ||
|
||
if (illegal.length) { | ||
const props = formatListAsProse(illegal); | ||
const owner = pluginId ? `registered by plugin ${pluginId} ` : ''; | ||
throw new Error( | ||
`Property name${props.length > 1 ? 's' : ''} ${props} ${owner}are not allowed to start with an underscore (_)` | ||
); | ||
} | ||
|
||
this._setProperties({ | ||
...rootProperties, | ||
...properties | ||
}); | ||
}); | ||
} | ||
|
||
getDsl() { | ||
return cloneDeep(this._dsl); | ||
} | ||
|
||
_setProperties(newProperties) { | ||
const rootType = getRootType(this._dsl); | ||
this._dsl = { | ||
...this._dsl, | ||
[rootType]: { | ||
...this._dsl[rootType], | ||
properties: newProperties | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.