-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
267 additions
and
16 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
...development/core/server/kibana-plugin-server.icontextcontainer.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,27 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IContextContainer](./kibana-plugin-server.icontextcontainer.md) > [createHandler](./kibana-plugin-server.icontextcontainer.createhandler.md) | ||
|
||
## IContextContainer.createHandler() method | ||
|
||
Create a new handler function pre-wired to context for the plugin. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
createHandler(pluginOpaqueId: PluginOpaqueId, handler: IContextHandler<TContext, THandlerReturn, THandlerParameters>): (...rest: THandlerParameters) => THandlerReturn extends Promise<any> ? THandlerReturn : Promise<THandlerReturn>; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| pluginOpaqueId | <code>PluginOpaqueId</code> | The plugin opaque ID for the plugin that registers this handler. | | ||
| handler | <code>IContextHandler<TContext, THandlerReturn, THandlerParameters></code> | Handler function to pass context object to. | | ||
|
||
<b>Returns:</b> | ||
|
||
`(...rest: THandlerParameters) => THandlerReturn extends Promise<any> ? THandlerReturn : Promise<THandlerReturn>` | ||
|
||
A function that takes `THandlerParameters`<!-- -->, calls `handler` with a new context, and returns a Promise of the `handler` return value. | ||
|
80 changes: 80 additions & 0 deletions
80
docs/development/core/server/kibana-plugin-server.icontextcontainer.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,80 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IContextContainer](./kibana-plugin-server.icontextcontainer.md) | ||
|
||
## IContextContainer interface | ||
|
||
An object that handles registration of context providers and configuring handlers with context. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface IContextContainer<TContext extends {}, THandlerReturn, THandlerParameters extends any[] = []> | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [createHandler(pluginOpaqueId, handler)](./kibana-plugin-server.icontextcontainer.createhandler.md) | Create a new handler function pre-wired to context for the plugin. | | ||
| [registerContext(pluginOpaqueId, contextName, provider)](./kibana-plugin-server.icontextcontainer.registercontext.md) | Register a new context provider. | | ||
|
||
## Remarks | ||
|
||
A [IContextContainer](./kibana-plugin-server.icontextcontainer.md) 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 configuring 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. | ||
|
||
In order to configure a handler with context, you must call the [IContextContainer.createHandler()](./kibana-plugin-server.icontextcontainer.createhandler.md) function and use the returned handler which will automatically build a context object when called. | ||
|
||
When registering context or creating handlers, the \_calling plugin's opaque id\_ must be provided. This id is passed in via the plugin's initializer and can be accessed from the [PluginInitializerContext.opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) Note this should NOT be the context service owner's id, but the plugin that is actually registering the context or handler. | ||
|
||
```ts | ||
// Correct | ||
class MyPlugin { | ||
private readonly handlers = new Map(); | ||
|
||
setup(core) { | ||
this.contextContainer = core.context.createContextContainer(); | ||
return { | ||
registerContext(pluginOpaqueId, contextName, provider) { | ||
this.contextContainer.registerContext(pluginOpaqueId, contextName, provider); | ||
}, | ||
registerRoute(pluginOpaqueId, path, handler) { | ||
this.handlers.set( | ||
path, | ||
this.contextContainer.createHandler(pluginOpaqueId, handler) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Incorrect | ||
class MyPlugin { | ||
private readonly handlers = new Map(); | ||
|
||
constructor(private readonly initContext: PluginInitializerContext) {} | ||
|
||
setup(core) { | ||
this.contextContainer = core.context.createContextContainer(); | ||
return { | ||
registerContext(contextName, provider) { | ||
// BUG! | ||
// This would leak this context to all handlers rather that only plugins that depend on the calling plugin. | ||
this.contextContainer.registerContext(this.initContext.opaqueId, contextName, provider); | ||
}, | ||
registerRoute(path, handler) { | ||
this.handlers.set( | ||
path, | ||
// BUG! | ||
// This handler will not receive any contexts provided by other dependencies of the calling plugin. | ||
this.contextContainer.createHandler(this.initContext.opaqueId, handler) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
34 changes: 34 additions & 0 deletions
34
...velopment/core/server/kibana-plugin-server.icontextcontainer.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,34 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IContextContainer](./kibana-plugin-server.icontextcontainer.md) > [registerContext](./kibana-plugin-server.icontextcontainer.registercontext.md) | ||
|
||
## IContextContainer.registerContext() method | ||
|
||
Register a new context provider. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
registerContext<TContextName extends keyof TContext>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider<TContext, TContextName, THandlerParameters>): this; | ||
``` | ||
## Parameters | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| pluginOpaqueId | <code>PluginOpaqueId</code> | The plugin opaque ID for the plugin that registers this context. | | ||
| contextName | <code>TContextName</code> | The key of the <code>TContext</code> object this provider supplies the value for. | | ||
| provider | <code>IContextProvider<TContext, TContextName, THandlerParameters></code> | A [IContextProvider](./kibana-plugin-server.icontextprovider.md) to be called each time a new context is created. | | ||
<b>Returns:</b> | ||
`this` | ||
The [IContextContainer](./kibana-plugin-server.icontextcontainer.md) for method chaining. | ||
## Remarks | ||
The value (or resolved Promise value) returned by the `provider` function will be attached to the context object on the key specified by `contextName`<!-- -->. | ||
Throws an exception if more than one provider is registered for the same `contextName`<!-- -->. | ||
18 changes: 18 additions & 0 deletions
18
docs/development/core/server/kibana-plugin-server.icontexthandler.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-server](./kibana-plugin-server.md) > [IContextHandler](./kibana-plugin-server.icontexthandler.md) | ||
|
||
## IContextHandler type | ||
|
||
A function registered by a plugin to perform some action. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type IContextHandler<TContext extends {}, TReturn, THandlerParameters extends any[] = []> = (context: TContext, ...rest: THandlerParameters) => TReturn; | ||
``` | ||
|
||
## Remarks | ||
|
||
A new `TContext` will be built for each handler before invoking. | ||
|
18 changes: 18 additions & 0 deletions
18
docs/development/core/server/kibana-plugin-server.icontextprovider.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-server](./kibana-plugin-server.md) > [IContextProvider](./kibana-plugin-server.icontextprovider.md) | ||
|
||
## IContextProvider type | ||
|
||
A function that returns a context value for a specific key of given context type. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type IContextProvider<TContext extends Record<string, any>, 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. | ||
|
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
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
Oops, something went wrong.