Skip to content

Commit

Permalink
Delete existing Installation type. Rename InstallationAttributes to I…
Browse files Browse the repository at this point in the history
…nstallation
  • Loading branch information
John Schulz committed Dec 9, 2019
1 parent 71ab5a0 commit c21723f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
5 changes: 2 additions & 3 deletions x-pack/legacy/plugins/epm/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,15 @@ export type PackageListItem = Installable<RegistrySearchResult & PackageAddition
export type PackagesGroupedByStatus = Record<InstallationStatus, PackageList>;
export type PackageInfo = Installable<RegistryPackage & PackageAdditions>;

export type Installation = SavedObject<InstallationAttributes>;
export interface InstallationAttributes extends SavedObjectAttributes {
export interface Installation extends SavedObjectAttributes {
installed: AssetReference[];
}

export type Installable<T> = Installed<T> | NotInstalled<T>;

export type Installed<T = {}> = T & {
status: InstallationStatus.installed;
savedObject: Installation;
savedObject: SavedObject<Installation>;
};

export type NotInstalled<T = {}> = T & {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/legacy/plugins/epm/server/packages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { SavedObjectsClientContract } from 'src/core/server/';
import { SAVED_OBJECT_TYPE_PACKAGES } from '../../common/constants';
import { Installation, InstallationAttributes, Installed, NotInstalled } from '../../common/types';
import { Installation, Installed, NotInstalled } from '../../common/types';
import * as Registry from '../registry';
import { createInstallableFrom } from './index';

Expand Down Expand Up @@ -35,7 +35,7 @@ export async function getPackages(
type: SAVED_OBJECT_TYPE_PACKAGES,
id: `${name}-${version}`,
}));
const results = await savedObjectsClient.bulkGet<InstallationAttributes>(searchObjects);
const results = await savedObjectsClient.bulkGet<Installation>(searchObjects);
const savedObjects = results.saved_objects.filter(o => !o.error); // ignore errors for now
const packageList = registryItems
.map(item =>
Expand Down Expand Up @@ -74,10 +74,10 @@ export async function getPackageInfo(options: {
export async function getInstallationObject(options: {
savedObjectsClient: SavedObjectsClientContract;
pkgkey: string;
}): Promise<Installation | undefined> {
}) {
const { savedObjectsClient, pkgkey } = options;
return savedObjectsClient
.get<InstallationAttributes>(SAVED_OBJECT_TYPE_PACKAGES, pkgkey)
.get<Installation>(SAVED_OBJECT_TYPE_PACKAGES, pkgkey)
.catch(e => undefined);
}

Expand Down
6 changes: 5 additions & 1 deletion x-pack/legacy/plugins/epm/server/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObject } from '../../../../../../src/core/server';
import {
AssetType,
// ElasticsearchAssetType,
Expand All @@ -21,7 +22,10 @@ export * from './remove';
// only Kibana Assets use Saved Objects at this point
export const savedObjectTypes: AssetType[] = Object.values(KibanaAssetType);

export function createInstallableFrom<T>(from: T, savedObject?: Installation): Installable<T> {
export function createInstallableFrom<T>(
from: T,
savedObject?: SavedObject<Installation>
): Installable<T> {
return savedObject
? {
...from,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/epm/server/packages/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { SavedObject, SavedObjectsClientContract } from 'src/core/server/';
import { SAVED_OBJECT_TYPE_PACKAGES } from '../../common/constants';
import { AssetReference, InstallationAttributes, KibanaAssetType } from '../../common/types';
import { AssetReference, Installation, KibanaAssetType } from '../../common/types';
import { installIndexPattern } from '../lib/kibana/index_pattern/install';
import * as Registry from '../registry';
import { getObject } from './get_objects';
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function saveInstallationReferences(options: {

const toInstall = toSave.reduce(mergeRefsReducer, savedRefs || []);

await savedObjectsClient.create<InstallationAttributes>(
await savedObjectsClient.create<Installation>(
SAVED_OBJECT_TYPE_PACKAGES,
{ installed: toInstall },
{ id: pkgkey, overwrite: true }
Expand Down

0 comments on commit c21723f

Please sign in to comment.