Skip to content

Commit

Permalink
core doesn't use Record<string, unknown> for public API (elastic#41448)
Browse files Browse the repository at this point in the history
* core contracts don't use unknown to support type assignment

limitations of https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#-k-string-unknown--is-no-longer-a-wildcard-assignment-target

* regenereate docs

* remove type over-write
  • Loading branch information
mshustov committed Jul 23, 2019
1 parent 3d04609 commit c3d913d
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<b>Signature:</b>

```typescript
export declare type APICaller = (endpoint: string, clientParams: Record<string, unknown>, options?: CallAPIOptions) => Promise<unknown>;
export declare type APICaller = (endpoint: string, clientParams: Record<string, any>, options?: CallAPIOptions) => Promise<unknown>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface AuthResultData
| Property | Type | Description |
| --- | --- | --- |
| [headers](./kibana-plugin-server.authresultdata.headers.md) | <code>AuthHeaders</code> | Auth specific headers to authenticate a user against Elasticsearch. |
| [state](./kibana-plugin-server.authresultdata.state.md) | <code>Record&lt;string, unknown&gt;</code> | Data to associate with an incoming request. Any downstream plugin may get access to the data. |
| [state](./kibana-plugin-server.authresultdata.state.md) | <code>Record&lt;string, any&gt;</code> | Data to associate with an incoming request. Any downstream plugin may get access to the data. |

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Data to associate with an incoming request. Any downstream plugin may get access
<b>Signature:</b>

```typescript
state: Record<string, unknown>;
state: Record<string, any>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Calls specified endpoint with provided clientParams on behalf of the Kibana inte
<b>Signature:</b>

```typescript
callAsInternalUser: (endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions | undefined) => Promise<any>;
callAsInternalUser: (endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions | undefined) => Promise<any>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export declare class ClusterClient

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [callAsInternalUser](./kibana-plugin-server.clusterclient.callasinternaluser.md) | | <code>(endpoint: string, clientParams?: Record&lt;string, unknown&gt;, options?: CallAPIOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Calls specified endpoint with provided clientParams on behalf of the Kibana internal user. |
| [callAsInternalUser](./kibana-plugin-server.clusterclient.callasinternaluser.md) | | <code>(endpoint: string, clientParams?: Record&lt;string, any&gt;, options?: CallAPIOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Calls specified endpoint with provided clientParams on behalf of the Kibana internal user. |

## Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Calls specified `endpoint` with provided `clientParams` on behalf of the user in
<b>Signature:</b>

```typescript
callAsCurrentUser(endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions): Promise<unknown>;
callAsCurrentUser(endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions): Promise<unknown>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| endpoint | <code>string</code> | String descriptor of the endpoint e.g. <code>cluster.getSettings</code> or <code>ping</code>. |
| clientParams | <code>Record&lt;string, unknown&gt;</code> | A dictionary of parameters that will be passed directly to the Elasticsearch JS client. |
| clientParams | <code>Record&lt;string, any&gt;</code> | A dictionary of parameters that will be passed directly to the Elasticsearch JS client. |
| options | <code>CallAPIOptions</code> | Options that affect the way we call the API and process the result. |

<b>Returns:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Calls specified `endpoint` with provided `clientParams` on behalf of the Kibana
<b>Signature:</b>

```typescript
callAsInternalUser(endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions): Promise<unknown>;
callAsInternalUser(endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions): Promise<unknown>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| endpoint | <code>string</code> | String descriptor of the endpoint e.g. <code>cluster.getSettings</code> or <code>ping</code>. |
| clientParams | <code>Record&lt;string, unknown&gt;</code> | A dictionary of parameters that will be passed directly to the Elasticsearch JS client. |
| clientParams | <code>Record&lt;string, any&gt;</code> | A dictionary of parameters that will be passed directly to the Elasticsearch JS client. |
| options | <code>CallAPIOptions</code> | Options that affect the way we call the API and process the result. |

<b>Returns:</b>
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/elasticsearch/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface CallAPIOptions {
async function callAPI(
client: Client,
endpoint: string,
clientParams: Record<string, unknown> = {},
clientParams: Record<string, any> = {},
options: CallAPIOptions = { wrap401Errors: true }
): Promise<any> {
const clientPath = endpoint.split('.');
Expand Down Expand Up @@ -150,7 +150,7 @@ export class ClusterClient {
*/
public callAsInternalUser = async (
endpoint: string,
clientParams: Record<string, unknown> = {},
clientParams: Record<string, any> = {},
options?: CallAPIOptions
) => {
this.assertIsNotClosed();
Expand Down Expand Up @@ -216,7 +216,7 @@ export class ClusterClient {
*/
private callAsCurrentUser = async (
endpoint: string,
clientParams: Record<string, unknown> = {},
clientParams: Record<string, any> = {},
options?: CallAPIOptions
) => {
this.assertIsNotClosed();
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/elasticsearch/scoped_cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export { Headers };
/** @public */
export type APICaller = (
endpoint: string,
clientParams: Record<string, unknown>,
clientParams: Record<string, any>,
options?: CallAPIOptions
) => Promise<unknown>;

Expand Down Expand Up @@ -58,7 +58,7 @@ export class ScopedClusterClient {
*/
public callAsInternalUser(
endpoint: string,
clientParams: Record<string, unknown> = {},
clientParams: Record<string, any> = {},
options?: CallAPIOptions
) {
return this.internalAPICaller(endpoint, clientParams, options);
Expand All @@ -73,7 +73,7 @@ export class ScopedClusterClient {
*/
public callAsCurrentUser(
endpoint: string,
clientParams: Record<string, unknown> = {},
clientParams: Record<string, any> = {},
options?: CallAPIOptions
) {
const defaultHeaders = this.headers;
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/http/http_server.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { KibanaRequest, RouteMethod } from './router';

interface RequestFixtureOptions {
headers?: Record<string, string>;
params?: Record<string, unknown>;
body?: Record<string, unknown>;
query?: Record<string, unknown>;
params?: Record<string, any>;
body?: Record<string, any>;
query?: Record<string, any>;
path?: string;
method?: RouteMethod;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/http/lifecycle/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface AuthResultData {
/**
* Data to associate with an incoming request. Any downstream plugin may get access to the data.
*/
state: Record<string, unknown>;
state: Record<string, any>;
/**
* Auth specific headers to authenticate a user against Elasticsearch.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { TypeOf } from '@kbn/config-schema';
import { Url } from 'url';

// @public (undocumented)
export type APICaller = (endpoint: string, clientParams: Record<string, unknown>, options?: CallAPIOptions) => Promise<unknown>;
export type APICaller = (endpoint: string, clientParams: Record<string, any>, options?: CallAPIOptions) => Promise<unknown>;

// Warning: (ae-forgotten-export) The symbol "AuthResult" needs to be exported by the entry point index.d.ts
//
Expand All @@ -34,7 +34,7 @@ export type AuthHeaders = Record<string, string>;
// @public
export interface AuthResultData {
headers: AuthHeaders;
state: Record<string, unknown>;
state: Record<string, any>;
}

// @public
Expand All @@ -61,7 +61,7 @@ export interface CallAPIOptions {
export class ClusterClient {
constructor(config: ElasticsearchClientConfig, log: Logger, getAuthHeaders?: GetAuthHeaders);
asScoped(request?: KibanaRequest | LegacyRequest | FakeRequest): ScopedClusterClient;
callAsInternalUser: (endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions | undefined) => Promise<any>;
callAsInternalUser: (endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions | undefined) => Promise<any>;
close(): void;
}

Expand Down Expand Up @@ -670,8 +670,8 @@ export interface SavedObjectsUpdateResponse<T extends SavedObjectAttributes = an
// @public
export class ScopedClusterClient {
constructor(internalAPICaller: APICaller, scopedAPICaller: APICaller, headers?: Record<string, string | string[] | undefined> | undefined);
callAsCurrentUser(endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions): Promise<unknown>;
callAsInternalUser(endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions): Promise<unknown>;
callAsCurrentUser(endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions): Promise<unknown>;
callAsInternalUser(endpoint: string, clientParams?: Record<string, any>, options?: CallAPIOptions): Promise<unknown>;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security/server/authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function setupAuthentication({

if (authenticationResult.succeeded()) {
return t.authenticated({
state: (authenticationResult.user as unknown) as Record<string, unknown>,
state: authenticationResult.user,
headers: authenticationResult.authHeaders,
});
}
Expand Down

0 comments on commit c3d913d

Please sign in to comment.