Skip to content

Commit

Permalink
Cleanup - Typescript some of src/legacy/server/index_patterns (elas…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp authored Dec 19, 2019
1 parent c1d47fb commit d20a6bc
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ returns `basePath` value, specific for an incoming request.
<b>Signature:</b>

```typescript
get: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest) => string;
get: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>) => string;
```
4 changes: 2 additions & 2 deletions docs/development/core/server/kibana-plugin-server.basepath.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export declare class BasePath

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [get](./kibana-plugin-server.basepath.get.md) | | <code>(request: KibanaRequest&lt;unknown, unknown, unknown, any&gt; &#124; LegacyRequest) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [get](./kibana-plugin-server.basepath.get.md) | | <code>(request: LegacyRequest &#124; KibanaRequest&lt;unknown, unknown, unknown, any&gt;) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [prepend](./kibana-plugin-server.basepath.prepend.md) | | <code>(path: string) =&gt; string</code> | Prepends <code>path</code> with the basePath. |
| [remove](./kibana-plugin-server.basepath.remove.md) | | <code>(path: string) =&gt; string</code> | Removes the prepended basePath from the <code>path</code>. |
| [serverBasePath](./kibana-plugin-server.basepath.serverbasepath.md) | | <code>string</code> | returns the server's basePath<!-- -->See [BasePath.get](./kibana-plugin-server.basepath.get.md) for getting the basePath value for a specific request |
| [set](./kibana-plugin-server.basepath.set.md) | | <code>(request: KibanaRequest&lt;unknown, unknown, unknown, any&gt; &#124; LegacyRequest, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |
| [set](./kibana-plugin-server.basepath.set.md) | | <code>(request: LegacyRequest &#124; KibanaRequest&lt;unknown, unknown, unknown, any&gt;, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |

## Remarks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ sets `basePath` value, specific for an incoming request.
<b>Signature:</b>

```typescript
set: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest, requestSpecificBasePath: string) => void;
set: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>, requestSpecificBasePath: string) => void;
```
4 changes: 2 additions & 2 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ export interface AuthToolkit {
export class BasePath {
// @internal
constructor(serverBasePath?: string);
get: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest) => string;
get: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>) => string;
prepend: (path: string) => string;
remove: (path: string) => string;
readonly serverBasePath: string;
set: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest, requestSpecificBasePath: string) => void;
set: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>, requestSpecificBasePath: string) => void;
}

// Warning: (ae-forgotten-export) The symbol "BootstrapArgs" needs to be exported by the entry point index.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { APICaller } from 'src/core/server';
import { APICaller } from 'kibana/server';

import { getFieldCapabilities, resolveTimePattern, createNoMatchingIndicesError } from './lib';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { APICaller } from 'src/core/server';
import { APICaller } from 'kibana/server';
import { convertEsError } from './errors';
import { FieldCapsResponse } from './field_capabilities';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { defaults, indexBy, sortBy } from 'lodash';

import { APICaller } from 'src/core/server';
import { APICaller } from 'kibana/server';
import { callFieldCapsApi } from '../es_api';
import { FieldCapsResponse, readFieldCapsResponse } from './field_caps_response';
import { mergeOverrides } from './overrides';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { chain } from 'lodash';
import moment from 'moment';

import { APICaller } from 'src/core/server';
import { APICaller } from 'kibana/server';

import { timePatternToWildcard } from './time_pattern_to_wildcard';
import { callIndexAliasApi, IndicesAliasResponse } from './es_api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
* under the License.
*/

import { CoreSetup } from 'kibana/server';
import { Plugin } from '../../../../core/server';
import { CoreSetup, Plugin } from 'kibana/server';
import { registerRoutes } from './routes';

export class IndexPatternsService implements Plugin<void> {
public setup({ http, elasticsearch }: CoreSetup) {
registerRoutes(http, elasticsearch);
public setup({ http }: CoreSetup) {
registerRoutes(http);
}

public start() {}
Expand Down
29 changes: 7 additions & 22 deletions src/plugins/data/server/index_patterns/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,11 @@
* under the License.
*/

import { first } from 'rxjs/operators';
import { schema } from '@kbn/config-schema';
import {
CoreSetup,
KibanaRequest,
RequestHandlerContext,
APICaller,
CallAPIOptions,
} from '../../../../core/server';
import { HttpServiceSetup, RequestHandlerContext } from 'kibana/server';
import { IndexPatternsFetcher } from './fetcher';

export function registerRoutes(http: CoreSetup['http'], elasticsearch: CoreSetup['elasticsearch']) {
const getIndexPatternsService = async (request: KibanaRequest): Promise<IndexPatternsFetcher> => {
const client = await elasticsearch.dataClient$.pipe(first()).toPromise();
const callCluster: APICaller = (
endpoint: string,
params?: Record<string, any>,
options?: CallAPIOptions
) => client.asScoped(request).callAsCurrentUser(endpoint, params, options);
return new Promise(resolve => resolve(new IndexPatternsFetcher(callCluster)));
};

export function registerRoutes(http: HttpServiceSetup) {
const parseMetaFields = (metaFields: string | string[]) => {
let parsedFields: string[] = [];
if (typeof metaFields === 'string') {
Expand All @@ -62,8 +45,9 @@ export function registerRoutes(http: CoreSetup['http'], elasticsearch: CoreSetup
}),
},
},
async (context: RequestHandlerContext, request: any, response: any) => {
const indexPatterns = await getIndexPatternsService(request);
async (context, request, response) => {
const { callAsCurrentUser } = context.core.elasticsearch.dataClient;
const indexPatterns = new IndexPatternsFetcher(callAsCurrentUser);
const { pattern, meta_fields: metaFields } = request.query;

let parsedFields: string[] = [];
Expand Down Expand Up @@ -106,7 +90,8 @@ export function registerRoutes(http: CoreSetup['http'], elasticsearch: CoreSetup
},
},
async (context: RequestHandlerContext, request: any, response: any) => {
const indexPatterns = await getIndexPatternsService(request);
const { callAsCurrentUser } = context.core.elasticsearch.dataClient;
const indexPatterns = new IndexPatternsFetcher(callAsCurrentUser);
const { pattern, interval, look_back: lookBack, meta_fields: metaFields } = request.query;

let parsedFields: string[] = [];
Expand Down

0 comments on commit d20a6bc

Please sign in to comment.