-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handling references for kibana_context and get_index_pattern expressi…
- Loading branch information
Showing
15 changed files
with
234 additions
and
130 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
...lic/kibana-plugin-plugins-expressions-public.executioncontext.getsavedobject.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
...ver/kibana-plugin-plugins-expressions-server.executioncontext.getsavedobject.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/plugins/data/public/search/expressions/kibana_context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { StartServicesAccessor } from 'src/core/public'; | ||
import { getKibanaContextFn } from '../../../common/search/expressions'; | ||
import { DataPublicPluginStart, DataStartDependencies } from '../../types'; | ||
import { SavedObjectsClientCommon } from '../../../common/index_patterns'; | ||
|
||
/** | ||
* This is some glue code that takes in `core.getStartServices`, extracts the dependencies | ||
* needed for this function, and wraps them behind a `getStartDependencies` function that | ||
* is then called at runtime. | ||
* | ||
* We do this so that we can be explicit about exactly which dependencies the function | ||
* requires, without cluttering up the top-level `plugin.ts` with this logic. It also | ||
* makes testing the expression function a bit easier since `getStartDependencies` is | ||
* the only thing you should need to mock. | ||
* | ||
* @param getStartServices - core's StartServicesAccessor for this plugin | ||
* | ||
* @internal | ||
*/ | ||
export function getKibanaContext({ | ||
getStartServices, | ||
}: { | ||
getStartServices: StartServicesAccessor<DataStartDependencies, DataPublicPluginStart>; | ||
}) { | ||
return getKibanaContextFn(async () => { | ||
const [core] = await getStartServices(); | ||
return { | ||
savedObjectsClient: (core.savedObjects.client as unknown) as SavedObjectsClientCommon, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/plugins/data/server/search/expressions/kibana_context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { StartServicesAccessor } from 'src/core/server'; | ||
import { getKibanaContextFn } from '../../../common/search/expressions'; | ||
import { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; | ||
import { SavedObjectsClientCommon } from '../../../common/index_patterns'; | ||
|
||
/** | ||
* This is some glue code that takes in `core.getStartServices`, extracts the dependencies | ||
* needed for this function, and wraps them behind a `getStartDependencies` function that | ||
* is then called at runtime. | ||
* | ||
* We do this so that we can be explicit about exactly which dependencies the function | ||
* requires, without cluttering up the top-level `plugin.ts` with this logic. It also | ||
* makes testing the expression function a bit easier since `getStartDependencies` is | ||
* the only thing you should need to mock. | ||
* | ||
* @param getStartServices - core's StartServicesAccessor for this plugin | ||
* | ||
* @internal | ||
*/ | ||
export function getKibanaContext({ | ||
getStartServices, | ||
}: { | ||
getStartServices: StartServicesAccessor<DataPluginStartDependencies, DataPluginStart>; | ||
}) { | ||
return getKibanaContextFn(async (getKibanaRequest) => { | ||
const request = getKibanaRequest && getKibanaRequest(); | ||
if (!request) { | ||
throw new Error('KIBANA_CONTEXT_KIBANA_REQUEST_MISSING'); | ||
} | ||
|
||
const [{ savedObjects }] = await getStartServices(); | ||
return { | ||
savedObjectsClient: (savedObjects.getScopedClient( | ||
request | ||
) as any) as SavedObjectsClientCommon, | ||
}; | ||
}); | ||
} |
Oops, something went wrong.