Skip to content

Commit

Permalink
fixed faling typechecks
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Jan 7, 2021
1 parent b36f0db commit c1d7a14
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ElasticsearchServiceStart,
ILegacyClusterClient,
SavedObjectsClientContract,
SavedObjectsBulkGetObject,
} from '../../../../src/core/server';

import {
Expand Down Expand Up @@ -333,7 +334,11 @@ export class ActionsPlugin implements Plugin<Promise<PluginSetupContract>, Plugi

this.eventLogService!.registerSavedObjectProvider('action', (request) => {
const client = secureGetActionsClientWithRequest(request);
return async (type: string, id: string) => (await client).get({ id });
return async (objects?: SavedObjectsBulkGetObject[]) => {
if (objects) {
Promise.all(objects.map(async (objectItem) => (await client).get({ id: objectItem.id })));
}
};
});

const getScopedSavedObjectsClientWithoutAccessToActions = (request: KibanaRequest) =>
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/alerts/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
ILegacyClusterClient,
StatusServiceSetup,
ServiceStatus,
SavedObjectsBulkGetObject,
} from '../../../../src/core/server';

import {
Expand Down Expand Up @@ -370,7 +371,11 @@ export class AlertingPlugin {

this.eventLogService!.registerSavedObjectProvider('alert', (request) => {
const client = getAlertsClientWithRequest(request);
return (type: string, id: string) => client.get({ id });
return async (objects?: SavedObjectsBulkGetObject[]) => {
if (objects) {
Promise.all(objects.map(async (objectItem) => (await client).get({ id: objectItem.id })));
}
};
});

scheduleAlertingTelemetry(this.telemetryLogger, plugins.taskManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { KibanaRequest, SavedObjectsClientContract } from 'src/core/server';
import { fromNullable, getOrElse } from 'fp-ts/lib/Option';
import { pipe } from 'fp-ts/lib/pipeable';

export type SavedObjectGetter = (
...params: Parameters<SavedObjectsClientContract['get']>
) => Promise<unknown>;

export type SavedObjectBulkGetter = (
...params: Parameters<SavedObjectsClientContract['bulkGet']>
) => Promise<unknown>;
Expand Down Expand Up @@ -58,7 +62,10 @@ export class SavedObjectProviderRegistry {
const scopedProviders = new Map<string, SavedObjectBulkGetter>();
const defaultGetter = this.defaultProvider(request);
return (type: string, ids: string[]) => {
const objects = [{ type, id: ids[0] }];
const objects = ids.reduce(
(prev: Array<{ type: string; id: string }>, id) => [...prev, { type, id }],
[]
);
const getter = pipe(
fromNullable(scopedProviders.get(type)),
getOrElse(() => {
Expand Down

0 comments on commit c1d7a14

Please sign in to comment.