Skip to content

Commit

Permalink
rename and export public types
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 24, 2020
1 parent 33691d9 commit abb6b19
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export {
SavedObjectsRepository,
SavedObjectsDeleteByNamespaceOptions,
SavedObjectsIncrementCounterOptions,
SavedObjectsComplexFieldMapping,
SavedObjectsCoreFieldMapping,
SavedObjectsFieldMapping,
SavedObjectsTypeMappingDefinitions,
SavedObjectsTypeMappingDefinition,
SavedObjectsMappingProperties,
} from './saved_objects';

export {
Expand Down
9 changes: 9 additions & 0 deletions src/core/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ export {
SavedObjectsDeleteByNamespaceOptions,
} from './service/lib/repository';

export {
SavedObjectsCoreFieldMapping,
SavedObjectsComplexFieldMapping,
SavedObjectsFieldMapping,
SavedObjectsMappingProperties,
SavedObjectsTypeMappingDefinition,
SavedObjectsTypeMappingDefinitions,
} from './mappings';

export { config } from './saved_objects_config';
6 changes: 4 additions & 2 deletions src/core/server/saved_objects/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
export { getTypes, getProperty, getRootProperties, getRootPropertiesObjects } from './lib';
export {
SavedObjectsMapping,
SavedObjectsComplexFieldMapping,
SavedObjectsCoreFieldMapping,
SavedObjectsTypeMapping,
SavedObjectsTypeMappingDefinition,
SavedObjectsTypeMappingDefinitions,
SavedObjectsMappingProperties,
SavedObjectsFieldMapping,
MappingMeta,
IndexMappingMeta,
IndexMapping,
} from './types';
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/mappings/lib/get_property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import toPath from 'lodash/internal/toPath';
import { CoreFieldMapping, SavedObjectsFieldMapping, IndexMapping } from '../types';
import { SavedObjectsCoreFieldMapping, SavedObjectsFieldMapping, IndexMapping } from '../types';

function getPropertyMappingFromObjectMapping(
mapping: IndexMapping | SavedObjectsFieldMapping,
path: string[]
): SavedObjectsFieldMapping | undefined {
const props =
(mapping && (mapping as IndexMapping).properties) ||
(mapping && (mapping as CoreFieldMapping).fields);
(mapping && (mapping as SavedObjectsCoreFieldMapping).fields);

if (!props) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* under the License.
*/

import { ComplexFieldMapping, IndexMapping, SavedObjectsMappingProperties } from '../types';
import {
SavedObjectsComplexFieldMapping,
IndexMapping,
SavedObjectsMappingProperties,
} from '../types';
import { getRootProperties } from './get_root_properties';

/**
Expand All @@ -43,7 +47,7 @@ export function getRootPropertiesObjects(mappings: IndexMapping) {
// we consider the existence of the properties or type of object to designate that this is an object datatype
if (
!blacklist.includes(key) &&
((value as ComplexFieldMapping).properties || value.type === 'object')
((value as SavedObjectsComplexFieldMapping).properties || value.type === 'object')
) {
acc[key] = value;
}
Expand Down
18 changes: 12 additions & 6 deletions src/core/server/saved_objects/mappings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @internal
*/
export interface SavedObjectsMapping {
export interface SavedObjectsTypeMapping {
pluginId: string;
type: string;
definition: SavedObjectsTypeMappingDefinition;
Expand Down Expand Up @@ -52,6 +52,8 @@ export interface SavedObjectsMapping {
* }
* }
* ```
*
* @public
*/
export interface SavedObjectsTypeMappingDefinition {
properties: SavedObjectsMappingProperties;
Expand Down Expand Up @@ -108,7 +110,9 @@ export interface SavedObjectsMappingProperties {
*
* @public
*/
export type SavedObjectsFieldMapping = CoreFieldMapping | ComplexFieldMapping;
export type SavedObjectsFieldMapping =
| SavedObjectsCoreFieldMapping
| SavedObjectsComplexFieldMapping;

// INDEX MAPPING

Expand All @@ -118,11 +122,11 @@ export type SavedObjectsFieldMapping = CoreFieldMapping | ComplexFieldMapping;
export interface IndexMapping {
dynamic?: string;
properties: SavedObjectsMappingProperties;
_meta?: MappingMeta;
_meta?: IndexMappingMeta;
}

/** @internal */
export interface MappingMeta {
export interface IndexMappingMeta {
// A dictionary of key -> md5 hash (e.g. 'dashboard': '24234qdfa3aefa3wa')
// with each key being a root-level mapping property, and each value being
// the md5 hash of that mapping's value when the index was created.
Expand All @@ -131,7 +135,8 @@ export interface MappingMeta {

// FieldMapping isn't 1:1 with the options available,
// modify as needed.
export interface CoreFieldMapping {
/** @public */
export interface SavedObjectsCoreFieldMapping {
type: string;
index?: boolean;
enabled?: boolean;
Expand All @@ -144,7 +149,8 @@ export interface CoreFieldMapping {

// FieldMapping isn't 1:1 with the options available,
// modify as needed.
export interface ComplexFieldMapping {
/** @public */
export interface SavedObjectsComplexFieldMapping {
dynamic?: string;
type?: string;
properties: SavedObjectsMappingProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { KibanaMigrator } from './kibana_migrator';
import { buildActiveMappings } from '../core';
import { SavedObjectsMapping } from '../../mappings';
import { SavedObjectsTypeMapping } from '../../mappings';
const { mergeTypes } = jest.requireActual('./kibana_migrator');

const defaultSavedObjectMappings = [
Expand All @@ -38,7 +38,7 @@ const createMigrator = (
{
savedObjectMappings,
}: {
savedObjectMappings: SavedObjectsMapping[];
savedObjectMappings: SavedObjectsTypeMapping[];
} = { savedObjectMappings: defaultSavedObjectMappings }
) => {
const mockMigrator: jest.Mocked<PublicMethodsOf<KibanaMigrator>> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { Logger } from 'src/core/server/logging';
import { KibanaConfigType } from 'src/core/server/kibana_config';
import {
SavedObjectsMapping,
SavedObjectsTypeMapping,
IndexMapping,
SavedObjectsTypeMappingDefinitions,
} from '../../mappings';
Expand All @@ -49,7 +49,7 @@ export interface KibanaMigratorOptions {
kibanaConfig: KibanaConfigType;
kibanaVersion: string;
logger: Logger;
savedObjectMappings: SavedObjectsMapping[];
savedObjectMappings: SavedObjectsTypeMapping[];
savedObjectMigrations: MigrationDefinition;
savedObjectSchemas: SavedObjectsSchema;
savedObjectValidations: PropertyValidators;
Expand Down Expand Up @@ -181,7 +181,9 @@ export class KibanaMigrator {
* Merges savedObjectMappings properties into a single object, verifying that
* no mappings are redefined.
*/
export function mergeTypes(mappings: SavedObjectsMapping[]): SavedObjectsTypeMappingDefinitions {
export function mergeTypes(
mappings: SavedObjectsTypeMapping[]
): SavedObjectsTypeMappingDefinitions {
return mappings.reduce((acc, { pluginId, type, definition }) => {
const duplicate = acc.hasOwnProperty(type);
if (duplicate) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
SavedObjectsClientWrapperFactory,
} from './service/lib/scoped_client_provider';
import { Logger } from '../logging';
import { SavedObjectsMapping } from './mappings';
import { SavedObjectsTypeMapping } from './mappings';
import { MigrationDefinition } from './migrations/core/document_migrator';
import { SavedObjectsSchemaDefinition } from './schema';
import { PropertyValidators } from './validation';
Expand Down Expand Up @@ -211,7 +211,7 @@ export class SavedObjectsService
private clientFactoryProvider?: SavedObjectsClientFactoryProvider;
private clientFactoryWrappers: WrappedClientFactoryWrapper[] = [];

private mappings: SavedObjectsMapping[] = [];
private mappings: SavedObjectsTypeMapping[] = [];
private migrations: MigrationDefinition = {};
private schemas: SavedObjectsSchemaDefinition = {};
private validations: PropertyValidators = {};
Expand Down Expand Up @@ -364,7 +364,7 @@ export class SavedObjectsService

const convertLegacyMappings = (
legacyMappings: SavedObjectsLegacyMapping[]
): SavedObjectsMapping[] => {
): SavedObjectsTypeMapping[] => {
return legacyMappings.reduce((mappings, { pluginId, properties }) => {
return [
...mappings,
Expand All @@ -374,5 +374,5 @@ const convertLegacyMappings = (
definition,
})),
];
}, [] as SavedObjectsMapping[]);
}, [] as SavedObjectsTypeMapping[]);
};

0 comments on commit abb6b19

Please sign in to comment.