From c332b30c42ccb85020eb5d76bf46aab7fe2b1c64 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Thu, 7 May 2020 13:08:36 -0400 Subject: [PATCH] Require type checking. --- .../ml/common/types/data_recognizer.ts | 26 +++++---- .../uptime/common/runtime_types/common.ts | 2 + .../common/runtime_types/monitor/details.ts | 8 +++ .../common/runtime_types/monitor/duration.ts | 31 +++++++++++ .../common/runtime_types/monitor/index.ts | 1 + .../common/runtime_types/ping/histogram.ts | 54 +++++++++++-------- x-pack/plugins/uptime/common/types/index.ts | 20 ------- .../charts/__tests__/duration_charts.test.tsx | 2 +- .../common/charts/duration_chart.tsx | 2 +- .../charts/duration_line_series_list.tsx | 2 +- .../monitor_duration/monitor_duration.tsx | 2 +- .../uptime/public/state/actions/monitor.ts | 12 ++--- .../public/state/actions/monitor_duration.ts | 2 +- .../uptime/public/state/api/certificates.ts | 2 +- .../public/state/api/dynamic_settings.ts | 2 +- .../uptime/public/state/api/index_pattern.ts | 3 +- .../uptime/public/state/api/index_status.ts | 2 +- .../uptime/public/state/api/ml_anomaly.ts | 11 +++- .../uptime/public/state/api/monitor.ts | 4 +- .../public/state/api/monitor_duration.ts | 3 +- .../uptime/public/state/api/monitor_list.ts | 2 +- .../uptime/public/state/api/monitor_status.ts | 4 +- .../public/state/api/overview_filters.ts | 2 +- .../plugins/uptime/public/state/api/ping.ts | 7 +-- .../uptime/public/state/api/snapshot.ts | 2 +- .../plugins/uptime/public/state/api/utils.ts | 25 +++++---- .../uptime/public/state/reducers/monitor.ts | 3 +- .../public/state/reducers/monitor_duration.ts | 2 +- .../lib/requests/get_monitor_duration.ts | 2 +- .../server/lib/requests/uptime_requests.ts | 2 +- 30 files changed, 144 insertions(+), 98 deletions(-) create mode 100644 x-pack/plugins/uptime/common/runtime_types/monitor/duration.ts diff --git a/x-pack/plugins/ml/common/types/data_recognizer.ts b/x-pack/plugins/ml/common/types/data_recognizer.ts index 2f77cc8c33896..6a110c7363f42 100644 --- a/x-pack/plugins/ml/common/types/data_recognizer.ts +++ b/x-pack/plugins/ml/common/types/data_recognizer.ts @@ -4,14 +4,20 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface JobStat { - id: string; - earliestTimestampMs: number; - latestTimestampMs: number; - latestResultsTimestampMs: number; -} +import * as t from 'io-ts'; -export interface JobExistResult { - jobsExist: boolean; - jobs: JobStat[]; -} +export const JobStatType = t.type({ + id: t.string, + earliestTimestampMs: t.number, + latestTimestampMs: t.number, + latestResultsTimestampMs: t.number, +}); + +export type JobStat = t.TypeOf; + +export const JobExistResultType = t.type({ + jobsExist: t.boolean, + jobs: t.array(JobStatType), +}); + +export type JobExistResult = t.TypeOf; diff --git a/x-pack/plugins/uptime/common/runtime_types/common.ts b/x-pack/plugins/uptime/common/runtime_types/common.ts index e07c46fa01cfe..7183cfd8561ec 100644 --- a/x-pack/plugins/uptime/common/runtime_types/common.ts +++ b/x-pack/plugins/uptime/common/runtime_types/common.ts @@ -32,6 +32,8 @@ export const DateRangeType = t.type({ to: t.string, }); +export const EmptyType = t.type({}); + export type Summary = t.TypeOf; export type Location = t.TypeOf; export type StatesIndexStatus = t.TypeOf; diff --git a/x-pack/plugins/uptime/common/runtime_types/monitor/details.ts b/x-pack/plugins/uptime/common/runtime_types/monitor/details.ts index bf81c91bae633..b5f10143f525b 100644 --- a/x-pack/plugins/uptime/common/runtime_types/monitor/details.ts +++ b/x-pack/plugins/uptime/common/runtime_types/monitor/details.ts @@ -21,4 +21,12 @@ export const MonitorDetailsType = t.intersection([ t.partial({ error: MonitorErrorType }), t.partial({ timestamp: t.string }), ]); + export type MonitorDetails = t.TypeOf; + +export const MonitorDetailsStateType = t.type({ + monitorId: t.string, + error: MonitorErrorType, +}); + +export type MonitorDetailsState = t.TypeOf; diff --git a/x-pack/plugins/uptime/common/runtime_types/monitor/duration.ts b/x-pack/plugins/uptime/common/runtime_types/monitor/duration.ts new file mode 100644 index 0000000000000..3000e7ec3037e --- /dev/null +++ b/x-pack/plugins/uptime/common/runtime_types/monitor/duration.ts @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import * as t from 'io-ts'; + +export const MonitorDurationAveragePointType = t.intersection([ + t.type({ + x: t.number, + }), + t.partial({ + y: t.union([t.number, t.null]), + }), +]); + +export type MonitorDurationAveragePoint = t.TypeOf; + +export const LocationDurationLineType = t.type({ + name: t.string, + line: t.array(MonitorDurationAveragePointType), +}); + +export type LocationDurationLine = t.TypeOf; + +export const MonitorDurationResultType = t.type({ + locationDurationLines: t.array(LocationDurationLineType), +}); + +export type MonitorDurationResult = t.TypeOf; diff --git a/x-pack/plugins/uptime/common/runtime_types/monitor/index.ts b/x-pack/plugins/uptime/common/runtime_types/monitor/index.ts index 46b19d8442a94..baa46fa3cd4ad 100644 --- a/x-pack/plugins/uptime/common/runtime_types/monitor/index.ts +++ b/x-pack/plugins/uptime/common/runtime_types/monitor/index.ts @@ -5,5 +5,6 @@ */ export * from './details'; +export * from './duration'; export * from './locations'; export * from './state'; diff --git a/x-pack/plugins/uptime/common/runtime_types/ping/histogram.ts b/x-pack/plugins/uptime/common/runtime_types/ping/histogram.ts index 209770a19f4aa..177d7956ef3aa 100644 --- a/x-pack/plugins/uptime/common/runtime_types/ping/histogram.ts +++ b/x-pack/plugins/uptime/common/runtime_types/ping/histogram.ts @@ -4,29 +4,37 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface HistogramDataPoint { - upCount?: number; - - downCount?: number; - - x?: number; - - x0?: number; - - y?: number; -} - -export interface GetPingHistogramParams { - dateStart: string; - dateEnd: string; - filters?: string; - monitorId?: string; -} - -export interface HistogramResult { - histogram: HistogramDataPoint[]; - interval: string; -} +import * as t from 'io-ts'; + +export const HistogramDataPointType = t.partial({ + upCount: t.number, + downCount: t.number, + x: t.number, + x0: t.number, + y: t.number, +}); + +export type HistogramDataPoint = t.TypeOf; + +export const GetPingHistogramParamsType = t.intersection([ + t.type({ + dateStart: t.string, + dateEnd: t.string, + }), + t.partial({ + filters: t.string, + monitorId: t.string, + }), +]); + +export type GetPingHistogramParams = t.TypeOf; + +export const HistogramResultType = t.type({ + histogram: t.array(HistogramDataPointType), + interval: t.string, +}); + +export type HistogramResult = t.TypeOf; export interface HistogramQueryResult { key: number; diff --git a/x-pack/plugins/uptime/common/types/index.ts b/x-pack/plugins/uptime/common/types/index.ts index 71ccd54dd3cdc..042ebab26feb2 100644 --- a/x-pack/plugins/uptime/common/types/index.ts +++ b/x-pack/plugins/uptime/common/types/index.ts @@ -4,26 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -/** Represents the average monitor duration ms at a point in time. */ -export interface MonitorDurationAveragePoint { - /** The timeseries value for this point. */ - x: number; - /** The average duration ms for the monitor. */ - y?: number | null; -} - -export interface LocationDurationLine { - name: string; - - line: MonitorDurationAveragePoint[]; -} - -/** The data used to populate the monitor charts. */ -export interface MonitorDurationResult { - /** The average values for the monitor duration. */ - locationDurationLines: LocationDurationLine[]; -} - export interface MonitorIdParam { monitorId: string; } diff --git a/x-pack/plugins/uptime/public/components/common/charts/__tests__/duration_charts.test.tsx b/x-pack/plugins/uptime/public/components/common/charts/__tests__/duration_charts.test.tsx index 589fbc6bceb45..9fb1728cb78cb 100644 --- a/x-pack/plugins/uptime/public/components/common/charts/__tests__/duration_charts.test.tsx +++ b/x-pack/plugins/uptime/public/components/common/charts/__tests__/duration_charts.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; import DateMath from '@elastic/datemath'; import { DurationChartComponent } from '../duration_chart'; -import { MonitorDurationResult } from '../../../../../common/types'; +import { MonitorDurationResult } from '../../../../../common/runtime_types'; import { shallowWithRouter } from '../../../../lib'; describe('MonitorCharts component', () => { diff --git a/x-pack/plugins/uptime/public/components/common/charts/duration_chart.tsx b/x-pack/plugins/uptime/public/components/common/charts/duration_chart.tsx index f9de385a7ce2c..5b0888ed98847 100644 --- a/x-pack/plugins/uptime/public/components/common/charts/duration_chart.tsx +++ b/x-pack/plugins/uptime/public/components/common/charts/duration_chart.tsx @@ -18,7 +18,7 @@ import { BrushEndListener, } from '@elastic/charts'; import { getChartDateLabel } from '../../../lib/helper'; -import { LocationDurationLine } from '../../../../common/types'; +import { LocationDurationLine } from '../../../../common/runtime_types'; import { DurationLineSeriesList } from './duration_line_series_list'; import { ChartWrapper } from './chart_wrapper'; import { useUrlParams } from '../../../hooks'; diff --git a/x-pack/plugins/uptime/public/components/common/charts/duration_line_series_list.tsx b/x-pack/plugins/uptime/public/components/common/charts/duration_line_series_list.tsx index 4223e918393b6..c742607f3e4ec 100644 --- a/x-pack/plugins/uptime/public/components/common/charts/duration_line_series_list.tsx +++ b/x-pack/plugins/uptime/public/components/common/charts/duration_line_series_list.tsx @@ -6,7 +6,7 @@ import React from 'react'; import { LineSeries, CurveType } from '@elastic/charts'; -import { LocationDurationLine } from '../../../../common/types'; +import { LocationDurationLine } from '../../../../common/runtime_types'; import { convertMicrosecondsToMilliseconds as microsToMillis } from '../../../lib/helper'; interface Props { diff --git a/x-pack/plugins/uptime/public/components/monitor/monitor_duration/monitor_duration.tsx b/x-pack/plugins/uptime/public/components/monitor/monitor_duration/monitor_duration.tsx index af1c8dbdc49e3..b8b646bbec804 100644 --- a/x-pack/plugins/uptime/public/components/monitor/monitor_duration/monitor_duration.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/monitor_duration/monitor_duration.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiTitle } from '@elastic/eui'; -import { LocationDurationLine } from '../../../../common/types'; +import { LocationDurationLine } from '../../../../common/runtime_types'; import { MLIntegrationComponent } from '../ml/ml_integeration'; import { AnomalyRecords } from '../../../state/actions'; import { DurationChartComponent } from '../../common/charts'; diff --git a/x-pack/plugins/uptime/public/state/actions/monitor.ts b/x-pack/plugins/uptime/public/state/actions/monitor.ts index 30ea8e71265e0..cd8d932f13cbf 100644 --- a/x-pack/plugins/uptime/public/state/actions/monitor.ts +++ b/x-pack/plugins/uptime/public/state/actions/monitor.ts @@ -6,31 +6,29 @@ import { createAction } from 'redux-actions'; import { MonitorDetailsActionPayload } from './types'; -import { MonitorError } from '../../../common/runtime_types'; -import { MonitorLocations } from '../../../common/runtime_types'; +import { MonitorLocations, MonitorDetailsState } from '../../../common/runtime_types'; import { QueryParams } from './types'; export interface MonitorLocationsPayload extends QueryParams { monitorId: string; } -export interface MonitorDetailsState { - monitorId: string; - error: MonitorError; -} - export const getMonitorDetailsAction = createAction( 'GET_MONITOR_DETAILS' ); + export const getMonitorDetailsActionSuccess = createAction( 'GET_MONITOR_DETAILS_SUCCESS' ); + export const getMonitorDetailsActionFail = createAction('GET_MONITOR_DETAILS_FAIL'); export const getMonitorLocationsAction = createAction( 'GET_MONITOR_LOCATIONS' ); + export const getMonitorLocationsActionSuccess = createAction( 'GET_MONITOR_LOCATIONS_SUCCESS' ); + export const getMonitorLocationsActionFail = createAction('GET_MONITOR_LOCATIONS_FAIL'); diff --git a/x-pack/plugins/uptime/public/state/actions/monitor_duration.ts b/x-pack/plugins/uptime/public/state/actions/monitor_duration.ts index 524044f873687..74979ca86d744 100644 --- a/x-pack/plugins/uptime/public/state/actions/monitor_duration.ts +++ b/x-pack/plugins/uptime/public/state/actions/monitor_duration.ts @@ -6,7 +6,7 @@ import { createAction } from 'redux-actions'; import { QueryParams } from './types'; -import { MonitorDurationResult } from '../../../common/types'; +import { MonitorDurationResult } from '../../../common/runtime_types'; import { IHttpFetchError } from '../../../../../../target/types/core/public/http'; type MonitorQueryParams = QueryParams & { monitorId: string }; diff --git a/x-pack/plugins/uptime/public/state/api/certificates.ts b/x-pack/plugins/uptime/public/state/api/certificates.ts index 78267e659d233..bc0684f54a45e 100644 --- a/x-pack/plugins/uptime/public/state/api/certificates.ts +++ b/x-pack/plugins/uptime/public/state/api/certificates.ts @@ -9,5 +9,5 @@ import { apiService } from './utils'; import { CertResultType, GetCertsParams } from '../../../common/runtime_types'; export const fetchCertificates = async (params: GetCertsParams) => { - return await apiService.get(API_URLS.CERTS, params, CertResultType); + return await apiService.get(API_URLS.CERTS, CertResultType, params); }; diff --git a/x-pack/plugins/uptime/public/state/api/dynamic_settings.ts b/x-pack/plugins/uptime/public/state/api/dynamic_settings.ts index e52e40c53513c..0e16749513fb6 100644 --- a/x-pack/plugins/uptime/public/state/api/dynamic_settings.ts +++ b/x-pack/plugins/uptime/public/state/api/dynamic_settings.ts @@ -19,7 +19,7 @@ interface SaveApiRequest { } export const getDynamicSettings = async (): Promise => { - return await apiService.get(apiPath, undefined, DynamicSettingsType); + return await apiService.get(apiPath, DynamicSettingsType); }; export const setDynamicSettings = async ({ diff --git a/x-pack/plugins/uptime/public/state/api/index_pattern.ts b/x-pack/plugins/uptime/public/state/api/index_pattern.ts index 1eecbc75c5bf4..cece85420f87b 100644 --- a/x-pack/plugins/uptime/public/state/api/index_pattern.ts +++ b/x-pack/plugins/uptime/public/state/api/index_pattern.ts @@ -5,8 +5,9 @@ */ import { API_URLS } from '../../../common/constants'; +import { EmptyType } from '../../../common/runtime_types'; import { apiService } from './utils'; export const fetchIndexPattern = async () => { - return await apiService.get(API_URLS.INDEX_PATTERN); + return await apiService.get(API_URLS.INDEX_PATTERN, EmptyType); }; diff --git a/x-pack/plugins/uptime/public/state/api/index_status.ts b/x-pack/plugins/uptime/public/state/api/index_status.ts index 0e33ab617777a..a64c1e5d61c46 100644 --- a/x-pack/plugins/uptime/public/state/api/index_status.ts +++ b/x-pack/plugins/uptime/public/state/api/index_status.ts @@ -9,5 +9,5 @@ import { StatesIndexStatus, StatesIndexStatusType } from '../../../common/runtim import { apiService } from './utils'; export const fetchIndexStatus = async (): Promise => { - return await apiService.get(API_URLS.INDEX_STATUS, undefined, StatesIndexStatusType); + return await apiService.get(API_URLS.INDEX_STATUS, StatesIndexStatusType, undefined); }; diff --git a/x-pack/plugins/uptime/public/state/api/ml_anomaly.ts b/x-pack/plugins/uptime/public/state/api/ml_anomaly.ts index 158d7b631a8b8..627526625d2e8 100644 --- a/x-pack/plugins/uptime/public/state/api/ml_anomaly.ts +++ b/x-pack/plugins/uptime/public/state/api/ml_anomaly.ts @@ -19,6 +19,11 @@ import { MonitorIdParam, HeartbeatIndicesParam, } from '../actions/types'; +import { DataRecognizerConfigResponse } from '../../../../../plugins/ml/common/types/modules'; +import { + JobExistResult, + JobExistResultType, +} from '../../../../../plugins/ml/common/types/data_recognizer'; const getJobPrefix = (monitorId: string) => { // ML App doesn't support upper case characters in job name @@ -41,11 +46,13 @@ const getJobPrefix = (monitorId: string) => { export const getMLJobId = (monitorId: string) => `${getJobPrefix(monitorId)}${ML_JOB_ID}`; export const getMLCapabilities = async (): Promise => { - return await apiService.get(API_URLS.ML_CAPABILITIES); + // @ts-ignore we're relying on ML types here, and opting for an empty type + // rather than trying to modify their internal typing to use io-ts + return await apiService.get(API_URLS.ML_CAPABILITIES, EmptyType); }; export const getExistingJobs = async (): Promise => { - return await apiService.get(API_URLS.ML_MODULE_JOBS + ML_MODULE_ID); + return await apiService.get(API_URLS.ML_MODULE_JOBS + ML_MODULE_ID, JobExistResultType); }; export const createMLJob = async ({ diff --git a/x-pack/plugins/uptime/public/state/api/monitor.ts b/x-pack/plugins/uptime/public/state/api/monitor.ts index c3d0a0180cf51..dd767630ab0f4 100644 --- a/x-pack/plugins/uptime/public/state/api/monitor.ts +++ b/x-pack/plugins/uptime/public/state/api/monitor.ts @@ -26,7 +26,7 @@ export const fetchMonitorDetails = async ({ dateStart, dateEnd, }; - return await apiService.get(API_URLS.MONITOR_DETAILS, params, MonitorDetailsType); + return await apiService.get(API_URLS.MONITOR_DETAILS, MonitorDetailsType, params); }; type ApiParams = QueryParams & ApiRequest; @@ -37,5 +37,5 @@ export const fetchMonitorLocations = async ({ monitorId, dateStart, dateEnd }: A dateEnd, monitorId, }; - return await apiService.get(API_URLS.MONITOR_LOCATIONS, params, MonitorLocationsType); + return await apiService.get(API_URLS.MONITOR_LOCATIONS, MonitorLocationsType, params); }; diff --git a/x-pack/plugins/uptime/public/state/api/monitor_duration.ts b/x-pack/plugins/uptime/public/state/api/monitor_duration.ts index 91034f1784b15..920f181beea35 100644 --- a/x-pack/plugins/uptime/public/state/api/monitor_duration.ts +++ b/x-pack/plugins/uptime/public/state/api/monitor_duration.ts @@ -7,6 +7,7 @@ import { BaseParams } from './types'; import { apiService } from './utils'; import { API_URLS } from '../../../common/constants'; +import { MonitorDurationResultType } from '../../../common/runtime_types'; export const fetchMonitorDuration = async ({ monitorId, dateStart, dateEnd }: BaseParams) => { const queryParams = { @@ -15,5 +16,5 @@ export const fetchMonitorDuration = async ({ monitorId, dateStart, dateEnd }: Ba dateEnd, }; - return await apiService.get(API_URLS.MONITOR_DURATION, queryParams); + return await apiService.get(API_URLS.MONITOR_DURATION, MonitorDurationResultType, queryParams); }; diff --git a/x-pack/plugins/uptime/public/state/api/monitor_list.ts b/x-pack/plugins/uptime/public/state/api/monitor_list.ts index 084bcb4bd2a91..1b35d3ec5e016 100644 --- a/x-pack/plugins/uptime/public/state/api/monitor_list.ts +++ b/x-pack/plugins/uptime/public/state/api/monitor_list.ts @@ -15,5 +15,5 @@ import { export const fetchMonitorList = async ( params: FetchMonitorStatesQueryArgs ): Promise => { - return await apiService.get(API_URLS.MONITOR_LIST, params, MonitorSummaryResultType); + return await apiService.get(API_URLS.MONITOR_LIST, MonitorSummaryResultType, params); }; diff --git a/x-pack/plugins/uptime/public/state/api/monitor_status.ts b/x-pack/plugins/uptime/public/state/api/monitor_status.ts index 7c8ab3518b5a0..a2d9afa59b874 100644 --- a/x-pack/plugins/uptime/public/state/api/monitor_status.ts +++ b/x-pack/plugins/uptime/public/state/api/monitor_status.ts @@ -5,7 +5,7 @@ */ import { QueryParams } from '../actions/types'; -import { Ping } from '../../../common/runtime_types'; +import { Ping, PingType } from '../../../common/runtime_types'; import { API_URLS } from '../../../common/constants'; import { apiService } from './utils'; @@ -20,5 +20,5 @@ export const fetchMonitorStatus = async ({ dateEnd, }; - return await apiService.get(API_URLS.MONITOR_STATUS, queryParams); + return await apiService.get(API_URLS.MONITOR_STATUS, PingType, queryParams); }; diff --git a/x-pack/plugins/uptime/public/state/api/overview_filters.ts b/x-pack/plugins/uptime/public/state/api/overview_filters.ts index 6330d8a912210..7d99d526c29c8 100644 --- a/x-pack/plugins/uptime/public/state/api/overview_filters.ts +++ b/x-pack/plugins/uptime/public/state/api/overview_filters.ts @@ -28,5 +28,5 @@ export const fetchOverviewFilters = async ({ search, }; - return await apiService.get(API_URLS.FILTERS, queryParams, OverviewFiltersType); + return await apiService.get(API_URLS.FILTERS, OverviewFiltersType, queryParams); }; diff --git a/x-pack/plugins/uptime/public/state/api/ping.ts b/x-pack/plugins/uptime/public/state/api/ping.ts index a2937c9c794dd..279c6599fec29 100644 --- a/x-pack/plugins/uptime/public/state/api/ping.ts +++ b/x-pack/plugins/uptime/public/state/api/ping.ts @@ -9,8 +9,9 @@ import { PingsResponseType, PingsResponse, GetPingsParams, - GetPingHistogramParams, HistogramResult, + HistogramResultType, + GetPingHistogramParams, } from '../../../common/runtime_types'; import { apiService } from './utils'; import { API_URLS } from '../../../common/constants'; @@ -18,7 +19,7 @@ import { API_URLS } from '../../../common/constants'; export const fetchPings: APIFn = async ({ dateRange: { from, to }, ...optional -}) => await apiService.get(API_URLS.PINGS, { from, to, ...optional }, PingsResponseType); +}) => await apiService.get(API_URLS.PINGS, PingsResponseType, { from, to, ...optional }); export const fetchPingHistogram: APIFn = async ({ monitorId, @@ -33,5 +34,5 @@ export const fetchPingHistogram: APIFn filters, }; - return await apiService.get(API_URLS.PING_HISTOGRAM, queryParams); + return await apiService.get(API_URLS.PING_HISTOGRAM, HistogramResultType, queryParams); }; diff --git a/x-pack/plugins/uptime/public/state/api/snapshot.ts b/x-pack/plugins/uptime/public/state/api/snapshot.ts index 9ee53dd2cbcef..a109e0eb8cddd 100644 --- a/x-pack/plugins/uptime/public/state/api/snapshot.ts +++ b/x-pack/plugins/uptime/public/state/api/snapshot.ts @@ -28,5 +28,5 @@ export const fetchSnapshotCount = async ({ ...(statusFilter && { statusFilter }), }; - return await apiService.get(API_URLS.SNAPSHOT_COUNT, queryParams, SnapshotType); + return await apiService.get(API_URLS.SNAPSHOT_COUNT, SnapshotType, queryParams); }; diff --git a/x-pack/plugins/uptime/public/state/api/utils.ts b/x-pack/plugins/uptime/public/state/api/utils.ts index acd9bec5a74bc..c018661cd4f74 100644 --- a/x-pack/plugins/uptime/public/state/api/utils.ts +++ b/x-pack/plugins/uptime/public/state/api/utils.ts @@ -6,6 +6,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { isRight } from 'fp-ts/lib/Either'; +import { Decoder } from 'io-ts'; import { HttpFetchQuery, HttpSetup } from '../../../../../../target/types/core/public'; class ApiService { @@ -30,19 +31,21 @@ class ApiService { return ApiService.instance; } - public async get(apiUrl: string, params?: HttpFetchQuery, decodeType?: any) { + public async get( + apiUrl: string, + decodeType: Decoder, + params?: HttpFetchQuery + ): Promise { const response = await this._http!.get(apiUrl, { query: params }); - if (decodeType) { - const decoded = decodeType.decode(response); - if (isRight(decoded)) { - return decoded.right; - } else { - // eslint-disable-next-line no-console - console.error( - `API ${apiUrl} is not returning expected response, ${PathReporter.report(decoded)}` - ); - } + const decoded = decodeType.decode(response); + if (isRight(decoded)) { + return decoded.right; + } else { + // eslint-disable-next-line no-console + console.error( + `API ${apiUrl} is not returning expected response, ${PathReporter.report(decoded)}` + ); } return response; diff --git a/x-pack/plugins/uptime/public/state/reducers/monitor.ts b/x-pack/plugins/uptime/public/state/reducers/monitor.ts index 632f3a270e1a1..1d6212412d180 100644 --- a/x-pack/plugins/uptime/public/state/reducers/monitor.ts +++ b/x-pack/plugins/uptime/public/state/reducers/monitor.ts @@ -6,7 +6,6 @@ import { Action } from 'redux-actions'; import { - MonitorDetailsState, getMonitorDetailsAction, getMonitorLocationsAction, getMonitorDetailsActionSuccess, @@ -14,7 +13,7 @@ import { getMonitorLocationsActionSuccess, getMonitorLocationsActionFail, } from '../actions/monitor'; -import { MonitorLocations } from '../../../common/runtime_types'; +import { MonitorDetailsState, MonitorLocations } from '../../../common/runtime_types'; type MonitorLocationsList = Map; diff --git a/x-pack/plugins/uptime/public/state/reducers/monitor_duration.ts b/x-pack/plugins/uptime/public/state/reducers/monitor_duration.ts index ec6b374c1057c..9719b1a5b10ef 100644 --- a/x-pack/plugins/uptime/public/state/reducers/monitor_duration.ts +++ b/x-pack/plugins/uptime/public/state/reducers/monitor_duration.ts @@ -10,7 +10,7 @@ import { getMonitorDurationActionSuccess, getMonitorDurationActionFail, } from '../actions'; -import { MonitorDurationResult } from '../../../common/types'; +import { MonitorDurationResult } from '../../../common/runtime_types'; export interface MonitorDuration { durationLines: MonitorDurationResult | null; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts index ea2a7e790652b..b7fe903f001d6 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts @@ -5,7 +5,7 @@ */ import { UMElasticsearchQueryFn } from '../adapters'; -import { LocationDurationLine, MonitorDurationResult } from '../../../common/types'; +import { LocationDurationLine, MonitorDurationResult } from '../../../common/runtime_types'; import { QUERY } from '../../../common/constants'; export interface GetMonitorChartsParams { diff --git a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts index 367db924cf1c6..45916f0c9cbfe 100644 --- a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts +++ b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts @@ -17,8 +17,8 @@ import { GetCertsParams, GetPingsParams, CertResult, + MonitorDurationResult, } from '../../../common/runtime_types'; -import { MonitorDurationResult } from '../../../common/types'; import { GetFilterBarParams,