Skip to content

Commit

Permalink
Change two names related to Saved Objects. Call SO client with types.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Jul 10, 2019
1 parent 13cef20 commit 98dfac8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/integrations_manager/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from 'src/core/server/saved_objects';

type AssetReference = Pick<SavedObjectReference, 'id' | 'type'>;
export interface Installation extends SavedObjectAttributes {
export interface InstallationAttributes extends SavedObjectAttributes {
installed: AssetReference[];
}

export type InstallationSavedObject = SavedObject<Installation>;
export type Installation = SavedObject<InstallationAttributes>;

// the contract with the registry
export type RegistryList = RegistryListItem[];
Expand Down Expand Up @@ -57,7 +57,7 @@ export type Installable<T> = Installed<T> | NotInstalled<T>;

export type Installed<T = {}> = T & {
status: 'installed';
savedObject: InstallationSavedObject;
savedObject: Installation;
};

export type NotInstalled<T = {}> = T & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SavedObjectsBulkGetObject,
SavedObjectsClientContract,
} from 'src/core/server/saved_objects';
import { InstallationSavedObject, Installable } from '../../common/types';
import { Installation, InstallationAttributes, Installable } from '../../common/types';
import { SAVED_OBJECT_TYPE } from '../../common/constants';
import * as Registry from '../registry';

Expand All @@ -20,8 +20,8 @@ export async function getIntegrations(client: SavedObjectsClientContract) {
id: `${name}-${version}`,
}));

const results = await client.bulkGet(searchObjects);
const savedObjects: InstallationSavedObject[] = results.saved_objects.filter(o => !o.error); // ignore errors for now
const results = await client.bulkGet<InstallationAttributes>(searchObjects);
const savedObjects = results.saved_objects.filter(o => !o.error); // ignore errors for now
const integrationList = registryItems
.map(item =>
createInstallableFrom(
Expand All @@ -44,11 +44,8 @@ export async function getIntegrationInfo(client: SavedObjectsClientContract, pkg
return installation;
}

export async function getInstallationObject(
client: SavedObjectsClientContract,
pkgkey: string
): Promise<InstallationSavedObject | undefined> {
return client.get(SAVED_OBJECT_TYPE, pkgkey).catch(e => undefined);
export async function getInstallationObject(client: SavedObjectsClientContract, pkgkey: string) {
return client.get<InstallationAttributes>(SAVED_OBJECT_TYPE, pkgkey).catch(e => undefined);
}

export async function installAssets(
Expand All @@ -57,10 +54,12 @@ export async function installAssets(
filter = (entry: Registry.ArchiveEntry): boolean => true
) {
const toBeSavedObjects = await Registry.getObjects(pkgkey, filter);
const createResults = await client.bulkCreate(toBeSavedObjects, { overwrite: true });
const createResults = await client.bulkCreate<InstallationAttributes>(toBeSavedObjects, {
overwrite: true,
});
const createdObjects: SavedObject[] = createResults.saved_objects;
const installed = createdObjects.map(({ id, type }) => ({ id, type }));
const results = await client.create(
const results = await client.create<InstallationAttributes>(
SAVED_OBJECT_TYPE,
{ installed },
{ id: pkgkey, overwrite: true }
Expand Down Expand Up @@ -95,7 +94,7 @@ function sortByName(a: { name: string }, b: { name: string }) {
}
}

function createInstallableFrom<T>(from: T, savedObject?: InstallationSavedObject): Installable<T> {
function createInstallableFrom<T>(from: T, savedObject?: Installation): Installable<T> {
return savedObject
? {
...from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request, InstallationSavedObject } from '../../common/types';
import { Request } from '../../common/types';
import { ArchiveEntry, pathParts } from '../registry';
import { getClient } from '../saved_objects';
import { getIntegrations, getIntegrationInfo, installAssets, removeInstallation } from './data';
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function handleGetInfo(req: PackageRequest) {

export async function handleRequestInstall(req: InstallAssetRequest) {
const { pkgkey, asset } = req.params;
const created: InstallationSavedObject[] = [];
const created = [];

if (asset === 'dashboard') {
const client = getClient(req);
Expand Down

0 comments on commit 98dfac8

Please sign in to comment.