-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,075 additions
and
22 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
.../development/core/public/kibana-plugin-public.contextcontainer.createhandler.md
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,28 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextContainer](./kibana-plugin-public.contextcontainer.md) > [createHandler](./kibana-plugin-public.contextcontainer.createhandler.md) | ||
|
||
## ContextContainer.createHandler() method | ||
|
||
Create a new handler function pre-wired to context for the plugin. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
createHandler(handler: Handler<TContext, THandlerReturn, THandlerParameters>): (...rest: THandlerParameters) => Promise<THandlerReturn>; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| handler | <code>Handler<TContext, THandlerReturn, THandlerParameters></code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`(...rest: THandlerParameters) => Promise<THandlerReturn>` | ||
|
||
## Remarks | ||
|
||
This must be called when the handler is registered by the consuming plugin. If this is called later in the lifecycle it will throw an exception. | ||
|
27 changes: 27 additions & 0 deletions
27
docs/development/core/public/kibana-plugin-public.contextcontainer.md
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,27 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextContainer](./kibana-plugin-public.contextcontainer.md) | ||
|
||
## ContextContainer interface | ||
|
||
An object that handles registration of context providers and building of new context objects. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface ContextContainer<TContext extends {}, THandlerReturn, THandlerParameters extends any[] = []> | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [createHandler(handler)](./kibana-plugin-public.contextcontainer.createhandler.md) | Create a new handler function pre-wired to context for the plugin. | | ||
| [registerContext(contextName, provider)](./kibana-plugin-public.contextcontainer.registercontext.md) | Register a new context provider. Throws an exception if more than one provider is registered for the same context key. | | ||
|
||
## Remarks | ||
|
||
A `ContextContainer` can be used by any Core service or plugin (known as the "service owner") which wishes to expose APIs in a handler function. The container object will manage registering context providers and building a context object for a handler with all of the contexts that should be exposed to the handler's plugin. This is dependent on the dependencies that the handler's plugin declares. | ||
|
||
Contexts providers are executed in the order they were registered. Each provider gets access to context values provided by any plugins that it depends on. | ||
|
27 changes: 27 additions & 0 deletions
27
...evelopment/core/public/kibana-plugin-public.contextcontainer.registercontext.md
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,27 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextContainer](./kibana-plugin-public.contextcontainer.md) > [registerContext](./kibana-plugin-public.contextcontainer.registercontext.md) | ||
|
||
## ContextContainer.registerContext() method | ||
|
||
Register a new context provider. Throws an exception if more than one provider is registered for the same context key. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
registerContext<TContextName extends keyof TContext>(contextName: TContextName, provider: ContextProvider<TContext, TContextName, THandlerParameters>): this; | ||
``` | ||
## Parameters | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| contextName | <code>TContextName</code> | The key of the <code>TContext</code> object this provider supplies the value for. | | ||
| provider | <code>ContextProvider<TContext, TContextName, THandlerParameters></code> | A [ContextProvider](./kibana-plugin-public.contextprovider.md) to be called each time a new context is created. | | ||
<b>Returns:</b> | ||
`this` | ||
The `ContextContainer` for method chaining. | ||
18 changes: 18 additions & 0 deletions
18
docs/development/core/public/kibana-plugin-public.contextprovider.md
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,18 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextProvider](./kibana-plugin-public.contextprovider.md) | ||
|
||
## ContextProvider type | ||
|
||
A function that returns a context value for a specific key of given context type. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type ContextProvider<TContext extends {}, TContextName extends keyof TContext, TProviderParameters extends any[] = []> = (context: Partial<TContext>, ...rest: TProviderParameters) => Promise<TContext[TContextName]> | TContext[TContextName]; | ||
``` | ||
|
||
## Remarks | ||
|
||
This function will be called each time a new context is built for a handler invocation. | ||
|
17 changes: 17 additions & 0 deletions
17
...lopment/core/public/kibana-plugin-public.contextsetup.createcontextcontainer.md
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,17 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextSetup](./kibana-plugin-public.contextsetup.md) > [createContextContainer](./kibana-plugin-public.contextsetup.createcontextcontainer.md) | ||
|
||
## ContextSetup.createContextContainer() method | ||
|
||
Creates a new [ContextContainer](./kibana-plugin-public.contextcontainer.md) for a service owner. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
createContextContainer<TContext extends {}, TProviderParameters extends any[] = []>(): ContextContainer<TContext, TProviderParameters>; | ||
``` | ||
<b>Returns:</b> | ||
`ContextContainer<TContext, TProviderParameters>` | ||
52 changes: 52 additions & 0 deletions
52
docs/development/core/public/kibana-plugin-public.contextsetup.md
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,52 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ContextSetup](./kibana-plugin-public.contextsetup.md) | ||
|
||
## ContextSetup interface | ||
|
||
An object that handles registration of context providers and building of new context objects. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface ContextSetup | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [createContextContainer()](./kibana-plugin-public.contextsetup.createcontextcontainer.md) | Creates a new [ContextContainer](./kibana-plugin-public.contextcontainer.md) for a service owner. | | ||
|
||
## Remarks | ||
|
||
A `ContextContainer` can be used by any Core service or plugin (known as the "service owner") which wishes to expose APIs in a handler function. The container object will manage registering context providers and building a context object for a handler with all of the contexts that should be exposed to the handler's plugin. This is dependent on the dependencies that the handler's plugin declares. | ||
|
||
Contexts providers are executed in the order they were registered. Each provider gets access to context values provided by any plugins that it depends on. | ||
|
||
## Example | ||
|
||
How to create your own context | ||
|
||
```ts | ||
class MyPlugin { | ||
setup(core) { | ||
this.myHandlers = new Map<string, Handler>(); | ||
this.contextContainer = core.createContextContainer(); | ||
return { | ||
registerContext: this.contextContainer.register, | ||
registerHandler: (endpoint, handler) => | ||
// `createHandler` must be called immediately. | ||
this.myHandlers.set(endpoint, this.contextContainer.createHandler(handler)), | ||
}; | ||
} | ||
|
||
start() { | ||
return { | ||
registerContext: this.contextContainer.register, | ||
}; | ||
} | ||
} | ||
|
||
``` | ||
|
13 changes: 13 additions & 0 deletions
13
docs/development/core/public/kibana-plugin-public.coresetup.context.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [CoreSetup](./kibana-plugin-public.coresetup.md) > [context](./kibana-plugin-public.coresetup.context.md) | ||
|
||
## CoreSetup.context property | ||
|
||
[ContextSetup](./kibana-plugin-public.contextsetup.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
context: Pick<ContextSetup, 'createContextContainer'>; | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ContextContainerImplementation } from './context'; | ||
|
||
export type ContextContainerMock = jest.Mocked< | ||
PublicMethodsOf<ContextContainerImplementation<any, any, any>> | ||
>; | ||
|
||
const createContextMock = () => { | ||
const contextMock: ContextContainerMock = { | ||
registerContext: jest.fn(), | ||
createHandler: jest.fn(), | ||
setCurrentPlugin: jest.fn(), | ||
}; | ||
return contextMock; | ||
}; | ||
|
||
export const contextMock = { | ||
create: createContextMock, | ||
}; |
Oops, something went wrong.