Merge tsconfig and x-pack/tsconfig files (#94519)

* merge all the typings at root level

* merge x-pack/tsconfig into tsconfig.json

* fix tsconfig after changes in master

* remove unnecessary typings

* update paths to the global typings

* update paths to the global elaticsearch typings

* fix import

* fix path to typings/elasticsearch in fleet plugin

* remove file deleted from master

* fix lint errors
This commit is contained in:
Mikhail Shustov 2021-03-16 15:13:49 +01:00 committed by GitHub
parent b71c6092c9
commit ee84e0b0b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
101 changed files with 188 additions and 352 deletions

9
typings/cytoscape_dagre.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
declare module 'cytoscape-dagre';

466
typings/elasticsearch/aggregations.d.ts vendored Normal file
View file

@ -0,0 +1,466 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { Unionize, UnionToIntersection } from 'utility-types';
import { ESSearchHit, MaybeReadonlyArray, ESSourceOptions, ESHitsOf } from '.';
export type SortOrder = 'asc' | 'desc';
type SortInstruction = Record<string, SortOrder | { order: SortOrder }>;
export type SortOptions = SortOrder | SortInstruction | SortInstruction[];
type Script =
| string
| {
lang?: string;
id?: string;
source?: string;
params?: Record<string, string | number>;
};
type BucketsPath = string | Record<string, string>;
type AggregationSourceOptions =
| {
field: string;
missing?: unknown;
}
| {
script: Script;
};
interface MetricsAggregationResponsePart {
value: number | null;
}
interface DateHistogramBucket {
doc_count: number;
key: number;
key_as_string: string;
}
type GetCompositeKeys<
TAggregationOptionsMap extends AggregationOptionsMap
> = TAggregationOptionsMap extends {
composite: { sources: Array<infer Source> };
}
? keyof Source
: never;
type CompositeOptionsSource = Record<
string,
| {
terms: ({ field: string } | { script: Script }) & {
missing_bucket?: boolean;
};
}
| undefined
>;
export interface AggregationOptionsByType {
terms: {
size?: number;
order?: SortOptions;
execution_hint?: 'map' | 'global_ordinals';
} & AggregationSourceOptions;
date_histogram: {
format?: string;
min_doc_count?: number;
extended_bounds?: {
min: number;
max: number;
};
} & ({ calendar_interval: string } | { fixed_interval: string }) &
AggregationSourceOptions;
histogram: {
interval: number;
min_doc_count?: number;
extended_bounds?: {
min?: number | string;
max?: number | string;
};
} & AggregationSourceOptions;
avg: AggregationSourceOptions;
max: AggregationSourceOptions;
min: AggregationSourceOptions;
sum: AggregationSourceOptions;
value_count: AggregationSourceOptions;
cardinality: AggregationSourceOptions & {
precision_threshold?: number;
};
percentiles: {
percents?: number[];
hdr?: { number_of_significant_value_digits: number };
} & AggregationSourceOptions;
stats: {
field: string;
};
extended_stats: {
field: string;
};
string_stats: { field: string };
top_hits: {
from?: number;
size?: number;
sort?: SortOptions;
_source?: ESSourceOptions;
fields?: MaybeReadonlyArray<string>;
docvalue_fields?: MaybeReadonlyArray<string>;
};
filter: Record<string, any>;
filters: {
filters: Record<string, any> | any[];
};
sampler: {
shard_size?: number;
};
derivative: {
buckets_path: BucketsPath;
};
bucket_script: {
buckets_path: BucketsPath;
script?: Script;
};
composite: {
size?: number;
sources: CompositeOptionsSource[];
after?: Record<string, string | number | null>;
};
diversified_sampler: {
shard_size?: number;
max_docs_per_value?: number;
} & ({ script: Script } | { field: string }); // TODO use MetricsAggregationOptions if possible
scripted_metric: {
params?: Record<string, any>;
init_script?: Script;
map_script: Script;
combine_script: Script;
reduce_script: Script;
};
date_range: {
format?: string;
ranges: Array<
| { from: string | number }
| { to: string | number }
| { from: string | number; to: string | number }
>;
keyed?: boolean;
} & AggregationSourceOptions;
range: {
field: string;
ranges: Array<
| { key?: string; from: string | number }
| { key?: string; to: string | number }
| { key?: string; from: string | number; to: string | number }
>;
keyed?: boolean;
};
auto_date_histogram: {
buckets: number;
} & AggregationSourceOptions;
percentile_ranks: {
values: Array<string | number>;
keyed?: boolean;
hdr?: { number_of_significant_value_digits: number };
} & AggregationSourceOptions;
bucket_sort: {
sort?: SortOptions;
from?: number;
size?: number;
};
significant_terms: {
size?: number;
field?: string;
background_filter?: Record<string, any>;
} & AggregationSourceOptions;
bucket_selector: {
buckets_path: {
[x: string]: string;
};
script: string;
};
top_metrics: {
metrics: { field: string } | MaybeReadonlyArray<{ field: string }>;
sort: SortOptions;
};
avg_bucket: {
buckets_path: string;
gap_policy?: 'skip' | 'insert_zeros';
format?: string;
};
rate: {
unit: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
} & (
| {
field: string;
mode: 'sum' | 'value_count';
}
| {}
);
}
type AggregationType = keyof AggregationOptionsByType;
type AggregationOptionsMap = Unionize<
{
[TAggregationType in AggregationType]: AggregationOptionsByType[TAggregationType];
}
> & { aggs?: AggregationInputMap };
interface DateRangeBucket {
key: string;
to?: number;
from?: number;
to_as_string?: string;
from_as_string?: string;
doc_count: number;
}
export interface AggregationInputMap {
[key: string]: AggregationOptionsMap;
}
type SubAggregationResponseOf<
TAggregationInputMap extends AggregationInputMap | undefined,
TDocument
> = TAggregationInputMap extends AggregationInputMap
? AggregationResponseMap<TAggregationInputMap, TDocument>
: {};
interface AggregationResponsePart<TAggregationOptionsMap extends AggregationOptionsMap, TDocument> {
terms: {
buckets: Array<
{
doc_count: number;
key: string | number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
doc_count_error_upper_bound?: number;
sum_other_doc_count?: number;
};
histogram: {
buckets: Array<
{
doc_count: number;
key: number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
};
date_histogram: {
buckets: Array<
DateHistogramBucket & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
};
avg: MetricsAggregationResponsePart;
sum: MetricsAggregationResponsePart;
max: MetricsAggregationResponsePart;
min: MetricsAggregationResponsePart;
value_count: { value: number };
cardinality: {
value: number;
};
percentiles: {
values: Record<string, number | null>;
};
stats: {
count: number;
min: number | null;
max: number | null;
avg: number | null;
sum: number | null;
};
extended_stats: {
count: number;
min: number | null;
max: number | null;
avg: number | null;
sum: number | null;
sum_of_squares: number | null;
variance: number | null;
std_deviation: number | null;
std_deviation_bounds: {
upper: number | null;
lower: number | null;
};
};
string_stats: {
count: number;
min_length: number;
max_length: number;
avg_length: number;
entropy: number;
};
top_hits: {
hits: {
total: {
value: number;
relation: 'eq' | 'gte';
};
max_score: number | null;
hits: TAggregationOptionsMap extends { top_hits: AggregationOptionsByType['top_hits'] }
? ESHitsOf<TAggregationOptionsMap['top_hits'], TDocument>
: ESSearchHit[];
};
};
filter: {
doc_count: number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>;
filters: TAggregationOptionsMap extends { filters: { filters: any[] } }
? Array<
{ doc_count: number } & AggregationResponseMap<TAggregationOptionsMap['aggs'], TDocument>
>
: TAggregationOptionsMap extends {
filters: {
filters: Record<string, any>;
};
}
? {
buckets: {
[key in keyof TAggregationOptionsMap['filters']['filters']]: {
doc_count: number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>;
};
}
: never;
sampler: {
doc_count: number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>;
derivative:
| {
value: number;
}
| undefined;
bucket_script:
| {
value: number | null;
}
| undefined;
composite: {
after_key: {
[key in GetCompositeKeys<TAggregationOptionsMap>]: TAggregationOptionsMap;
};
buckets: Array<
{
key: Record<GetCompositeKeys<TAggregationOptionsMap>, string | number>;
doc_count: number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
};
diversified_sampler: {
doc_count: number;
} & AggregationResponseMap<TAggregationOptionsMap['aggs'], TDocument>;
scripted_metric: {
value: unknown;
};
date_range: {
buckets: TAggregationOptionsMap extends { date_range: { keyed: true } }
? Record<string, DateRangeBucket>
: { buckets: DateRangeBucket[] };
};
range: {
buckets: TAggregationOptionsMap extends { range: { keyed: true } }
? Record<
string,
DateRangeBucket & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>
: Array<
DateRangeBucket & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
};
auto_date_histogram: {
buckets: Array<
DateHistogramBucket & AggregationResponseMap<TAggregationOptionsMap['aggs'], TDocument>
>;
interval: string;
};
percentile_ranks: {
values: TAggregationOptionsMap extends {
percentile_ranks: { keyed: false };
}
? Array<{ key: number; value: number }>
: Record<string, number>;
};
significant_terms: {
doc_count: number;
bg_count: number;
buckets: Array<
{
score: number;
bg_count: number;
doc_count: number;
key: string | number;
} & SubAggregationResponseOf<TAggregationOptionsMap['aggs'], TDocument>
>;
};
bucket_sort: undefined;
bucket_selector: undefined;
top_metrics: {
top: [
{
sort: [string | number];
metrics: UnionToIntersection<
TAggregationOptionsMap extends {
top_metrics: { metrics: { field: infer TFieldName } };
}
? TopMetricsMap<TFieldName>
: TAggregationOptionsMap extends {
top_metrics: { metrics: MaybeReadonlyArray<{ field: infer TFieldName }> };
}
? TopMetricsMap<TFieldName>
: TopMetricsMap<string>
>;
}
];
};
avg_bucket: {
value: number | null;
};
rate: {
value: number | null;
};
}
type TopMetricsMap<TFieldName> = TFieldName extends string
? Record<TFieldName, string | number | null>
: Record<string, string | number>;
// Type for debugging purposes. If you see an error in AggregationResponseMap
// similar to "cannot be used to index type", uncomment the type below and hover
// over it to see what aggregation response types are missing compared to the
// input map.
// type MissingAggregationResponseTypes = Exclude<
// AggregationType,
// keyof AggregationResponsePart<{}, unknown>
// >;
// ensures aggregations work with requests where aggregation options are a union type,
// e.g. { transaction_groups: { composite: any } | { terms: any } }.
// Union keys are not included in keyof. The type will fall back to keyof T if
// UnionToIntersection fails, which happens when there are conflicts between the union
// types, e.g. { foo: string; bar?: undefined } | { foo?: undefined; bar: string };
export type ValidAggregationKeysOf<
T extends Record<string, any>
> = keyof (UnionToIntersection<T> extends never ? T : UnionToIntersection<T>);
export type AggregationResultOf<
TAggregationOptionsMap extends AggregationOptionsMap,
TDocument
> = AggregationResponsePart<TAggregationOptionsMap, TDocument>[AggregationType &
ValidAggregationKeysOf<TAggregationOptionsMap>];
export type AggregationResponseMap<
TAggregationInputMap extends AggregationInputMap | undefined,
TDocument
> = TAggregationInputMap extends AggregationInputMap
? {
[TName in keyof TAggregationInputMap]: AggregationResponsePart<
TAggregationInputMap[TName],
TDocument
>[AggregationType & ValidAggregationKeysOf<TAggregationInputMap[TName]>];
}
: undefined;

140
typings/elasticsearch/index.d.ts vendored Normal file
View file

@ -0,0 +1,140 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ValuesType } from 'utility-types';
import { Explanation, SearchParams, SearchResponse } from 'elasticsearch';
import { RequestParams } from '@elastic/elasticsearch';
import { AggregationResponseMap, AggregationInputMap, SortOptions } from './aggregations';
export {
AggregationInputMap,
AggregationOptionsByType,
AggregationResponseMap,
AggregationResultOf,
SortOptions,
ValidAggregationKeysOf,
} from './aggregations';
// Typings for Elasticsearch queries and aggregations. These are intended to be
// moved to the Elasticsearch JS client at some point (see #77720.)
export type MaybeReadonlyArray<T> = T[] | readonly T[];
interface CollapseQuery {
field: string;
inner_hits?: {
name: string;
size?: number;
sort?: SortOptions;
_source?:
| string
| string[]
| {
includes?: string | string[];
excludes?: string | string[];
};
collapse?: {
field: string;
};
};
max_concurrent_group_searches?: number;
}
export type ESSourceOptions = boolean | string | string[];
export type ESHitsOf<
TOptions extends
| {
size?: number;
_source?: ESSourceOptions;
docvalue_fields?: MaybeReadonlyArray<string>;
fields?: MaybeReadonlyArray<string>;
}
| undefined,
TDocument extends unknown
> = Array<
ESSearchHit<
TOptions extends { _source: false } ? undefined : TDocument,
TOptions extends { fields: MaybeReadonlyArray<string> } ? TOptions['fields'] : undefined,
TOptions extends { docvalue_fields: MaybeReadonlyArray<string> }
? TOptions['docvalue_fields']
: undefined
>
>;
export interface ESSearchBody {
query?: any;
size?: number;
from?: number;
aggs?: AggregationInputMap;
track_total_hits?: boolean | number;
collapse?: CollapseQuery;
search_after?: Array<string | number>;
_source?: ESSourceOptions;
}
export type ESSearchRequest = RequestParams.Search<ESSearchBody>;
export interface ESSearchOptions {
restTotalHitsAsInt: boolean;
}
export type ESSearchHit<
TSource extends any = unknown,
TFields extends MaybeReadonlyArray<string> | undefined = undefined,
TDocValueFields extends MaybeReadonlyArray<string> | undefined = undefined
> = {
_index: string;
_type: string;
_id: string;
_score: number;
_version?: number;
_explanation?: Explanation;
highlight?: any;
inner_hits?: any;
matched_queries?: string[];
sort?: string[];
} & (TSource extends false ? {} : { _source: TSource }) &
(TFields extends MaybeReadonlyArray<string>
? {
fields: Partial<Record<ValuesType<TFields>, unknown[]>>;
}
: {}) &
(TDocValueFields extends MaybeReadonlyArray<string>
? {
fields: Partial<Record<ValuesType<TDocValueFields>, unknown[]>>;
}
: {});
export type ESSearchResponse<
TDocument,
TSearchRequest extends ESSearchRequest,
TOptions extends ESSearchOptions = { restTotalHitsAsInt: false }
> = Omit<SearchResponse<TDocument>, 'aggregations' | 'hits'> &
(TSearchRequest extends { body: { aggs: AggregationInputMap } }
? {
aggregations?: AggregationResponseMap<TSearchRequest['body']['aggs'], TDocument>;
}
: {}) & {
hits: Omit<SearchResponse<TDocument>['hits'], 'total' | 'hits'> &
(TOptions['restTotalHitsAsInt'] extends true
? {
total: number;
}
: {
total: {
value: number;
relation: 'eq' | 'gte';
};
}) & { hits: ESHitsOf<TSearchRequest['body'], TDocument> };
};
export interface ESFilter {
[key: string]: {
[key: string]: string | string[] | number | boolean | Record<string, unknown> | ESFilter[];
};
}

11
typings/global_fetch.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
// This type needs to still exist due to apollo-link-http-common hasn't yet updated
// it's usage (https://github.com/apollographql/apollo-link/issues/1131)
declare type GlobalFetch = WindowOrWorkerGlobalScope;

2
typings/index.d.ts vendored
View file

@ -24,6 +24,8 @@ declare module '*.svg' {
export default content;
}
declare module 'axios/lib/adapters/xhr';
// Storybook references this module. It's @ts-ignored in the codebase but when
// built into its dist it strips that out. Add it here to avoid a type checking
// error.

12
typings/js_levenshtein.d.ts vendored Normal file
View file

@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
declare module 'js-levenshtein' {
const levenshtein: (a: string, b: string) => number;
export = levenshtein;
}

9
typings/react_vis.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
declare module 'react-vis';