Skip to content

Commit c123d06

Browse files
committed
Merge remote-tracking branch 'upstream/7.x' into backport/7.x/pr-45547
2 parents 6006299 + 323165b commit c123d06

287 files changed

Lines changed: 9109 additions & 1836 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

STYLEGUIDE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,39 @@ function addBar(foos, foo) {
141141
}
142142
```
143143
144+
### Avoid `any` whenever possible
145+
146+
Since TypeScript 3.0 and the introduction of the
147+
[`unknown` type](https://mariusschulz.com/blog/the-unknown-type-in-typescript) there are rarely any
148+
reasons to use `any` as a type. Nearly all places of former `any` usage can be replace by either a
149+
generic or `unknown` (in cases the type is really not known).
150+
151+
You should always prefer using those mechanisms over using `any`, since they are stricter typed and
152+
less likely to introduce bugs in the future due to insufficient types.
153+
154+
If you’re not having `any` in your plugin or are starting a new plugin, you should enable the
155+
[`@typescript-eslint/no-explicit-any`](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md)
156+
linting rule for your plugin via the [`.eslintrc.js`](https://github.com/elastic/kibana/blob/master/.eslintrc.js) config.
157+
158+
### Avoid non-null assertions
159+
160+
You should try avoiding non-null assertions (`!.`) wherever possible. By using them you tell
161+
TypeScript, that something is not null even though by it’s type it could be. Usage of non-null
162+
assertions is most often a side-effect of you actually checked that the variable is not `null`
163+
but TypeScript doesn’t correctly carry on that information till the usage of the variable.
164+
165+
In most cases it’s possible to replace the non-null assertion by structuring your code/checks slightly different
166+
or using [user defined type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards)
167+
to properly tell TypeScript what type a variable has.
168+
169+
Using non-null assertion increases the risk for future bugs. In case the condition under which we assumed that the
170+
variable can’t be null has changed (potentially even due to changes in compeltely different files), the non-null
171+
assertion would now wrongly disable proper type checking for us.
172+
173+
If you’re not using non-null assertions in your plugin or are starting a new plugin, consider enabling the
174+
[`@typescript-eslint/no-non-null-assertion`](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-assertion.md)
175+
linting rule for you plugin in the [`.eslintrc.js`](https://github.com/elastic/kibana/blob/master/.eslintrc.js) config.
176+
144177
### Return/throw early from functions
145178
146179
To avoid deep nesting of if-statements, always return a function's value as early

docs/api/saved-objects/find.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ experimental[] Retrieve a paginated set of {kib} saved objects by various condit
4141
`has_reference`::
4242
(Optional, object) Filters to objects that have a relationship with the type and ID combination.
4343

44+
`filter`::
45+
(Optional, string) The filter is a KQL string with the caveat that if you filter with an attribute from your type saved object.
46+
It should look like that savedObjectType.attributes.title: "myTitle". However, If you used a direct attribute of a saved object like `updatedAt`,
47+
you will have to define your filter like that savedObjectType.updatedAt > 2018-12-22.
48+
4449
NOTE: As objects change in {kib}, the results on each page of the response also
4550
change. Use the find API for traditional paginated results, but avoid using it to export large amounts of data.
4651

docs/development/core/public/kibana-plugin-public.applicationsetup.registermountcontext.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Register a context provider for application mounting. Will only be available to
99
<b>Signature:</b>
1010

1111
```typescript
12-
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountContext, T>): void;
12+
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<App['mount'], T>): void;
1313
```
1414
1515
## Parameters
1616
1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
1919
| contextName | <code>T</code> | The key of [AppMountContext](./kibana-plugin-public.appmountcontext.md) this provider's return value should be attached to. |
20-
| provider | <code>IContextProvider&lt;AppMountContext, T&gt;</code> | A [IContextProvider](./kibana-plugin-public.icontextprovider.md) function |
20+
| provider | <code>IContextProvider&lt;App['mount'], T&gt;</code> | A [IContextProvider](./kibana-plugin-public.icontextprovider.md) function |
2121
2222
<b>Returns:</b>
2323

docs/development/core/public/kibana-plugin-public.applicationstart.registermountcontext.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Register a context provider for application mounting. Will only be available to
99
<b>Signature:</b>
1010

1111
```typescript
12-
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountContext, T>): void;
12+
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<App['mount'], T>): void;
1313
```
1414
1515
## Parameters
1616
1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
1919
| contextName | <code>T</code> | The key of [AppMountContext](./kibana-plugin-public.appmountcontext.md) this provider's return value should be attached to. |
20-
| provider | <code>IContextProvider&lt;AppMountContext, T&gt;</code> | A [IContextProvider](./kibana-plugin-public.icontextprovider.md) function |
20+
| provider | <code>IContextProvider&lt;App['mount'], T&gt;</code> | A [IContextProvider](./kibana-plugin-public.icontextprovider.md) function |
2121
2222
<b>Returns:</b>
2323

docs/development/core/public/kibana-plugin-public.contextsetup.createcontextcontainer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Creates a new [IContextContainer](./kibana-plugin-public.icontextcontainer.md) f
99
<b>Signature:</b>
1010

1111
```typescript
12-
createContextContainer<TContext extends {}, THandlerReturn, THandlerParmaters extends any[] = []>(): IContextContainer<TContext, THandlerReturn, THandlerParmaters>;
12+
createContextContainer<THandler extends HandlerFunction<any>>(): IContextContainer<THandler>;
1313
```
1414
<b>Returns:</b>
1515
16-
`IContextContainer<TContext, THandlerReturn, THandlerParmaters>`
16+
`IContextContainer<THandler>`
1717
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [HandlerContextType](./kibana-plugin-public.handlercontexttype.md)
4+
5+
## HandlerContextType type
6+
7+
Extracts the type of the first argument of a [HandlerFunction](./kibana-plugin-public.handlerfunction.md) to represent the type of the context.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare type HandlerContextType<T extends HandlerFunction<any>> = T extends HandlerFunction<infer U> ? U : never;
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [HandlerFunction](./kibana-plugin-public.handlerfunction.md)
4+
5+
## HandlerFunction type
6+
7+
A function that accepts a context object and an optional number of additional arguments. Used for the generic types in [IContextContainer](./kibana-plugin-public.icontextcontainer.md)
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare type HandlerFunction<T extends object> = (context: T, ...args: any[]) => any;
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [HandlerParameters](./kibana-plugin-public.handlerparameters.md)
4+
5+
## HandlerParameters type
6+
7+
Extracts the types of the additional arguments of a [HandlerFunction](./kibana-plugin-public.handlerfunction.md)<!-- -->, excluding the [HandlerContextType](./kibana-plugin-public.handlercontexttype.md)<!-- -->.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare type HandlerParameters<T extends HandlerFunction<any>> = T extends (context: any, ...args: infer U) => any ? U : never;
13+
```

docs/development/core/public/kibana-plugin-public.icontextcontainer.createhandler.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ Create a new handler function pre-wired to context for the plugin.
99
<b>Signature:</b>
1010

1111
```typescript
12-
createHandler(pluginOpaqueId: PluginOpaqueId, handler: IContextHandler<TContext, THandlerReturn, THandlerParameters>): (...rest: THandlerParameters) => THandlerReturn extends Promise<any> ? THandlerReturn : Promise<THandlerReturn>;
12+
createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters<THandler>) => ShallowPromise<ReturnType<THandler>>;
1313
```
1414

1515
## Parameters
1616

1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
1919
| pluginOpaqueId | <code>PluginOpaqueId</code> | The plugin opaque ID for the plugin that registers this handler. |
20-
| handler | <code>IContextHandler&lt;TContext, THandlerReturn, THandlerParameters&gt;</code> | Handler function to pass context object to. |
20+
| handler | <code>THandler</code> | Handler function to pass context object to. |
2121

2222
<b>Returns:</b>
2323

24-
`(...rest: THandlerParameters) => THandlerReturn extends Promise<any> ? THandlerReturn : Promise<THandlerReturn>`
24+
`(...rest: HandlerParameters<THandler>) => ShallowPromise<ReturnType<THandler>>`
2525

2626
A function that takes `THandlerParameters`<!-- -->, calls `handler` with a new context, and returns a Promise of the `handler` return value.
2727

docs/development/core/public/kibana-plugin-public.icontextcontainer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ An object that handles registration of context providers and configuring handler
99
<b>Signature:</b>
1010

1111
```typescript
12-
export interface IContextContainer<TContext extends {}, THandlerReturn, THandlerParameters extends any[] = []>
12+
export interface IContextContainer<THandler extends HandlerFunction<any>>
1313
```
1414

1515
## Methods

0 commit comments

Comments
 (0)