Skip to content

Commit

Permalink
[Maps] move MapSavedObject type out of telemetry (#60127)
Browse files Browse the repository at this point in the history
* [Maps] move MapSavedObject type out of telemetry

* move SavedObject from server to core/types

* review feedback

* results from check_published_api_changes
  • Loading branch information
nreese authored Mar 16, 2020
1 parent 537fa8c commit ef32611
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

## SavedObject interface


<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

## SavedObject interface


<b>Signature:</b>

```typescript
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ export type RecursiveReadonly<T> = T extends (...args: any[]) => any ? T : T ext
[K in keyof T]: RecursiveReadonly<T[K]>;
}> : T;

// Warning: (ae-missing-release-tag) "SavedObject" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface SavedObject<T = unknown> {
attributes: T;
Expand Down
13 changes: 8 additions & 5 deletions src/core/public/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ export {
export { SimpleSavedObject } from './simple_saved_object';
export { SavedObjectsStart, SavedObjectsService } from './saved_objects_service';
export {
SavedObject,
SavedObjectAttribute,
SavedObjectAttributes,
SavedObjectAttributeSingle,
SavedObjectReference,
SavedObjectsBaseOptions,
SavedObjectsFindOptions,
SavedObjectsMigrationVersion,
Expand All @@ -48,3 +43,11 @@ export {
SavedObjectsImportError,
SavedObjectsImportRetry,
} from '../../server/types';

export {
SavedObject,
SavedObjectAttribute,
SavedObjectAttributes,
SavedObjectAttributeSingle,
SavedObjectReference,
} from '../../types';
59 changes: 5 additions & 54 deletions src/core/server/saved_objects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,66 +35,17 @@ export {
import { LegacyConfig } from '../legacy';
import { SavedObjectUnsanitizedDoc } from './serialization';
import { SavedObjectsMigrationLogger } from './migrations/core/migration_logger';
import { SavedObject } from '../../types';

export {
SavedObjectAttributes,
SavedObjectAttribute,
SavedObjectAttributeSingle,
SavedObject,
SavedObjectReference,
SavedObjectsMigrationVersion,
} from '../../types';

/**
* Information about the migrations that have been applied to this SavedObject.
* When Kibana starts up, KibanaMigrator detects outdated documents and
* migrates them based on this value. For each migration that has been applied,
* the plugin's name is used as a key and the latest migration version as the
* value.
*
* @example
* migrationVersion: {
* dashboard: '7.1.1',
* space: '6.6.6',
* }
*
* @public
*/
export interface SavedObjectsMigrationVersion {
[pluginName: string]: string;
}

/**
* @public
*/
export interface SavedObject<T = unknown> {
/** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */
id: string;
/** The type of Saved Object. Each plugin can define it's own custom Saved Object types. */
type: string;
/** An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. */
version?: string;
/** Timestamp of the last time this document had been updated. */
updated_at?: string;
error?: {
message: string;
statusCode: number;
};
/** {@inheritdoc SavedObjectAttributes} */
attributes: T;
/** {@inheritdoc SavedObjectReference} */
references: SavedObjectReference[];
/** {@inheritdoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
}

/**
* A reference to another saved object.
*
* @public
*/
export interface SavedObjectReference {
name: string;
type: string;
id: string;
}

/**
*
* @public
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ export interface RouteValidatorOptions {
// @public
export type SafeRouteMethod = 'get' | 'options';

// Warning: (ae-missing-release-tag) "SavedObject" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface SavedObject<T = unknown> {
attributes: T;
Expand Down
51 changes: 51 additions & 0 deletions src/core/types/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,54 @@ export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttri
export interface SavedObjectAttributes {
[key: string]: SavedObjectAttribute;
}

/**
* A reference to another saved object.
*
* @public
*/
export interface SavedObjectReference {
name: string;
type: string;
id: string;
}

/**
* Information about the migrations that have been applied to this SavedObject.
* When Kibana starts up, KibanaMigrator detects outdated documents and
* migrates them based on this value. For each migration that has been applied,
* the plugin's name is used as a key and the latest migration version as the
* value.
*
* @example
* migrationVersion: {
* dashboard: '7.1.1',
* space: '6.6.6',
* }
*
* @public
*/
export interface SavedObjectsMigrationVersion {
[pluginName: string]: string;
}

export interface SavedObject<T = unknown> {
/** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */
id: string;
/** The type of Saved Object. Each plugin can define it's own custom Saved Object types. */
type: string;
/** An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. */
version?: string;
/** Timestamp of the last time this document had been updated. */
updated_at?: string;
error?: {
message: string;
statusCode: number;
};
/** {@inheritdoc SavedObjectAttributes} */
attributes: T;
/** {@inheritdoc SavedObjectReference} */
references: SavedObjectReference[];
/** {@inheritdoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
}
32 changes: 3 additions & 29 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
// @ts-ignore
} from '../../common/constants';
import { LayerDescriptor } from '../../common/descriptor_types';
import { MapSavedObject } from '../../../../../plugins/maps/common/map_saved_object_type';

interface IStats {
[key: string]: {
Expand All @@ -32,33 +33,6 @@ interface ILayerTypeCount {
[key: string]: number;
}

interface IMapSavedObject {
[key: string]: any;
fields: IFieldType[];
title: string;
id?: string;
type?: string;
timeFieldName?: string;
fieldFormatMap?: Record<
string,
{
id: string;
params: unknown;
}
>;
attributes?: {
title?: string;
description?: string;
mapStateJSON?: string;
layerListJSON?: string;
uiStateJSON?: string;
bounds?: {
type?: string;
coordinates?: [];
};
};
}

function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) {
const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map(lTypes => Object.keys(lTypes))));

Expand Down Expand Up @@ -102,7 +76,7 @@ export function buildMapsTelemetry({
indexPatternSavedObjects,
settings,
}: {
mapSavedObjects: IMapSavedObject[];
mapSavedObjects: MapSavedObject[];
indexPatternSavedObjects: IIndexPattern[];
settings: SavedObjectAttribute;
}): SavedObjectAttributes {
Expand Down Expand Up @@ -183,7 +157,7 @@ export async function getMapsTelemetry(
savedObjectsClient: SavedObjectsClientContract,
config: Function
) {
const mapSavedObjects: IMapSavedObject[] = await getMapSavedObjects(savedObjectsClient);
const mapSavedObjects: MapSavedObject[] = await getMapSavedObjects(savedObjectsClient);
const indexPatternSavedObjects: IIndexPattern[] = await getIndexPatternSavedObjects(
savedObjectsClient
);
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/maps/common/map_saved_object_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { SavedObject } from '../../../../src/core/types/saved_objects';

export type MapSavedObjectAttributes = {
title?: string;
description?: string;
mapStateJSON?: string;
layerListJSON?: string;
uiStateJSON?: string;
bounds?: {
type?: string;
coordinates?: [];
};
};

export type MapSavedObject = SavedObject<MapSavedObjectAttributes>;

0 comments on commit ef32611

Please sign in to comment.