[data views] reduce any usage on server side service (#112750)

* remove some any instances from data view
This commit is contained in:
Matthew Kime 2021-09-23 06:59:33 -05:00 committed by GitHub
parent 548944e6d3
commit 7ecae91e64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 12 deletions

View file

@ -10,6 +10,7 @@
import _, { each, reject } from 'lodash';
import { castEsToKbnFieldTypeName } from '@kbn/field-types';
import type { estypes } from '@elastic/elasticsearch';
import { FieldAttrs, FieldAttrSet, DataViewAttributes } from '../..';
import type { RuntimeField } from '../types';
import { DuplicateField } from '../../../../kibana_utils/common';
@ -158,7 +159,7 @@ export class DataView implements IIndexPattern {
};
getComputedFields() {
const scriptFields: Record<string, { script: { source: string; lang: string } }> = {};
const scriptFields: Record<string, estypes.ScriptField> = {};
if (!this.fields) {
return {
storedFields: ['*'],
@ -185,7 +186,7 @@ export class DataView implements IIndexPattern {
scriptFields[field.name] = {
script: {
source: field.script as string,
lang: field.lang as string,
lang: field.lang,
},
};
});

View file

@ -89,8 +89,8 @@ export type OnNotification = (toastInputFields: ToastInputFields) => void;
export type OnError = (error: Error, toastInputFields: ErrorToastOptions) => void;
export interface UiSettingsCommon {
get: (key: string) => Promise<any>;
getAll: () => Promise<Record<string, any>>;
get: <T = any>(key: string) => Promise<T>;
getAll: () => Promise<Record<string, unknown>>;
set: (key: string, value: any) => Promise<void>;
remove: (key: string) => Promise<void>;
}

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { IUiSettingsClient } from 'src/core/public';
import { IUiSettingsClient, PublicUiSettingsParams, UserProvidedValues } from 'src/core/public';
import { UiSettingsCommon } from '../../common';
export class UiSettingsPublicToCommon implements UiSettingsCommon {
@ -14,11 +14,11 @@ export class UiSettingsPublicToCommon implements UiSettingsCommon {
constructor(uiSettings: IUiSettingsClient) {
this.uiSettings = uiSettings;
}
get(key: string) {
get<T = any>(key: string): Promise<T> {
return Promise.resolve(this.uiSettings.get(key));
}
getAll() {
getAll<T = any>(): Promise<Record<string, PublicUiSettingsParams & UserProvidedValues<T>>> {
return Promise.resolve(this.uiSettings.getAll());
}

View file

@ -7,7 +7,7 @@
*/
import { schema } from '@kbn/config-schema';
import { HttpServiceSetup, RequestHandlerContext, StartServicesAccessor } from 'kibana/server';
import { HttpServiceSetup, StartServicesAccessor } from 'kibana/server';
import { IndexPatternsFetcher } from './fetcher';
import { registerCreateIndexPatternRoute } from './routes/create_index_pattern';
import { registerGetIndexPatternRoute } from './routes/get_index_pattern';
@ -154,7 +154,7 @@ export function registerRoutes(
}),
},
},
async (context: RequestHandlerContext, request: any, response: any) => {
async (context, request, response) => {
const { asCurrentUser } = context.core.elasticsearch.client;
const indexPatterns = new IndexPatternsFetcher(asCurrentUser);
const { pattern, interval, look_back: lookBack, meta_fields: metaFields } = request.query;

View file

@ -14,11 +14,11 @@ export class UiSettingsServerToCommon implements UiSettingsCommon {
constructor(uiSettings: IUiSettingsClient) {
this.uiSettings = uiSettings;
}
get(key: string) {
get<T = any>(key: string): Promise<T> {
return this.uiSettings.get(key);
}
getAll() {
getAll<T = any>(): Promise<Record<string, T>> {
return this.uiSettings.getAll();
}

View file

@ -37,7 +37,7 @@ export function buildSearchBody(
},
},
stored_fields: computedFields.storedFields,
script_fields: computedFields.scriptFields as Record<string, estypes.ScriptField>,
script_fields: computedFields.scriptFields,
version: true,
},
};