diff --git a/packages/app/package.json b/packages/app/package.json index 5a0c996dfd..4ec70e9553 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -116,6 +116,7 @@ "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^16.3.0", "@testing-library/user-event": "^14.5.2", + "@total-typescript/shoehorn": "^0.1.2", "@types/crypto-js": "^4", "@types/flat": "^5.0.5", "@types/identity-obj-proxy": "^3", diff --git a/packages/app/src/components/__tests__/DBRowSidePanel.viewTraceTimeFilter.test.tsx b/packages/app/src/components/__tests__/DBRowSidePanel.viewTraceTimeFilter.test.tsx index 16d0dd4055..47ec21f2d9 100644 --- a/packages/app/src/components/__tests__/DBRowSidePanel.viewTraceTimeFilter.test.tsx +++ b/packages/app/src/components/__tests__/DBRowSidePanel.viewTraceTimeFilter.test.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import { TSource } from '@hyperdx/common-utils/dist/types'; +import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types'; import { MantineProvider } from '@mantine/core'; import { fireEvent, render, screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; // Controlled, in-memory replacement for nuqs' useQueryState so each side-panel // URL param can be seeded and its setter inspected independently. Values are @@ -157,14 +158,13 @@ import { DBRowSidePanelInner } from '@/components/DBRowSidePanel'; import useSidePanelStack from '@/hooks/useSidePanelStack'; import { getRowLookupWindow } from '@/utils/rowTimestamps'; -// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -const ROOT_SOURCE = { +const ROOT_SOURCE = fromPartial({ id: 'log-src', - kind: 'log', + kind: SourceKind.Log, traceSourceId: 'trace-src', timestampValueExpression: 'Timestamp', resourceAttributesExpression: 'ResourceAttributes', -} as TSource; +}); const TRACE_ID = '7316d5a2ab0dc2efa72258f64a98a405'; const SPAN_ID = 'e3748131832d6176'; @@ -278,7 +278,7 @@ describe('DBRowSidePanelInner, "View Trace" row lookup time filter', () => { const compositeSource = { ...ROOT_SOURCE, timestampValueExpression: 'EventDate, EventTime', - } as TSource; + }; mockUseRowData.mockReturnValue( rowResult({ diff --git a/packages/app/src/components/__tests__/DBTimeChart.test.tsx b/packages/app/src/components/__tests__/DBTimeChart.test.tsx index 380e832757..e03e671ea1 100644 --- a/packages/app/src/components/__tests__/DBTimeChart.test.tsx +++ b/packages/app/src/components/__tests__/DBTimeChart.test.tsx @@ -1,8 +1,10 @@ import React from 'react'; +import { DisplayType } from '@hyperdx/common-utils/dist/types'; import { MantineProvider } from '@mantine/core'; import { Notifications } from '@mantine/notifications'; import { screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { fromPartial } from '@total-typescript/shoehorn'; import api from '@/api'; import { ChartKeyJoiner } from '@/ChartUtils'; @@ -155,9 +157,11 @@ describe('DBTimeChart', () => { it('passes the same config to useMVOptimizationExplanation, useQueriedChartConfig, and MVOptimizationIndicator', () => { // Mock useSource to return a source so MVOptimizationIndicator is rendered - jest.mocked(useSource).mockReturnValue({ - data: { id: 'test-source', name: 'Test Source' }, - } as any); + jest.mocked(useSource).mockReturnValue( + fromPartial>({ + data: { id: 'test-source', name: 'Test Source' }, + }), + ); renderWithMantine(); @@ -183,9 +187,11 @@ describe('DBTimeChart', () => { }); it('disables the MV-optimization query when both MV and date-range indicators are hidden', () => { - jest.mocked(useSource).mockReturnValue({ - data: { id: 'test-source', name: 'Test Source' }, - } as any); + jest.mocked(useSource).mockReturnValue( + fromPartial>({ + data: { id: 'test-source', name: 'Test Source' }, + }), + ); renderWithMantine( { }); it('keeps the MV-optimization query enabled when only the date-range indicator is shown', () => { - jest.mocked(useSource).mockReturnValue({ - data: { id: 'test-source', name: 'Test Source' }, - } as any); + jest.mocked(useSource).mockReturnValue( + fromPartial>({ + data: { id: 'test-source', name: 'Test Source' }, + }), + ); renderWithMantine( { }; // Mock useMVOptimizationExplanation to return an optimized config with aligned date range - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: { - ...config, - dateRange: [alignedStartDate, alignedEndDate] as [Date, Date], - }, - explanations: [ - { - success: true, - mvConfig: { - minGranularity: '1 minute', - tableName: 'metrics_rollup_1m', - }, + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial>({ + data: { + optimizedConfig: { + ...config, + dateRange: [alignedStartDate, alignedEndDate] as [Date, Date], }, - ], - }, - isLoading: false, - isPlaceholderData: false, - } as any); + explanations: [ + { + success: true, + mvConfig: { + minGranularity: '1 minute', + tableName: 'metrics_rollup_1m', + }, + }, + ], + }, + isLoading: false, + isPlaceholderData: false, + }), + ); renderWithMantine(); @@ -477,14 +487,16 @@ describe('DBTimeChart', () => { }; // Mock useMVOptimizationExplanation to return no optimized config - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: undefined, - explanations: [], - }, - isLoading: false, - isPlaceholderData: false, - } as any); + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial>({ + data: { + optimizedConfig: undefined, + explanations: [], + }, + isLoading: false, + isPlaceholderData: false, + }), + ); renderWithMantine(); @@ -511,7 +523,7 @@ describe('DBTimeChart', () => { sqlTemplate: 'SELECT toStartOfInterval(ts, INTERVAL {intervalSeconds:Int64} SECOND) AS ts, count() AS count FROM logs GROUP BY ts ORDER BY ts ASC', connection: 'test-connection', - displayType: 'line' as any, + displayType: DisplayType.Line, dateRange: [new Date('2024-01-01'), new Date('2024-01-02')] as [ Date, Date, @@ -669,14 +681,16 @@ describe('DBTimeChart', () => { it('does not render DateRangeIndicator when MV optimization has no optimized date range and showDateRangeIndicator is false', () => { // Mock useMVOptimizationExplanation to return data without an optimized config - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: undefined, - explanations: [], - }, - isLoading: false, - isPlaceholderData: false, - } as any); + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial>({ + data: { + optimizedConfig: undefined, + explanations: [], + }, + isLoading: false, + isPlaceholderData: false, + }), + ); renderWithMantine( , diff --git a/packages/app/src/components/__tests__/MetricTableModelForm.test.tsx b/packages/app/src/components/__tests__/MetricTableModelForm.test.tsx index 2f1ce9abab..d995eed787 100644 --- a/packages/app/src/components/__tests__/MetricTableModelForm.test.tsx +++ b/packages/app/src/components/__tests__/MetricTableModelForm.test.tsx @@ -1,8 +1,13 @@ import React, { useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types'; +import { + SourceKind, + TMetricSource, + TSource, +} from '@hyperdx/common-utils/dist/types'; import { MantineProvider } from '@mantine/core'; import { render, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { MetricTableModelForm } from '@/components/Sources/SourceForm/MetricTableModelForm'; @@ -122,8 +127,7 @@ function autofilledTables() { .map(([path, value]) => [path, value]); } -// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -const SAVED_SOURCE: TSource = { +const SAVED_SOURCE = fromPartial({ id: 'metric-source-1', kind: SourceKind.Metric, name: 'Metrics', @@ -134,7 +138,7 @@ const SAVED_SOURCE: TSource = { gauge: 'otel_metrics_gauge', sum: 'otel_metrics_sum', }, -} as any; +}); describe('MetricTableModelForm metric table autofill', () => { beforeEach(() => { @@ -237,12 +241,12 @@ describe('MetricTableModelForm metric table autofill', () => { // A saved source of another kind switched over to OTEL Metrics has no metric // tables to preserve, so it autofills like a new source. it('autofills for an existing source switched to the metrics kind', async () => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion - savedSource = { - ...SAVED_SOURCE, + const { metricTables: _metricTables, ...savedSourceWithoutMetricTables } = + SAVED_SOURCE; + savedSource = fromPartial({ + ...savedSourceWithoutMetricTables, kind: SourceKind.Log, - metricTables: undefined, - } as any; + }); renderHarness( , diff --git a/scripts/ci/ratchet-baseline.json b/scripts/ci/ratchet-baseline.json index 3fd8aa4812..e161daf04f 100644 --- a/scripts/ci/ratchet-baseline.json +++ b/scripts/ci/ratchet-baseline.json @@ -5,9 +5,9 @@ "eslint-disable": 31 }, "app": { - "as-any": 215, + "as-any": 206, "ts-ignore": 0, - "eslint-disable": 144 + "eslint-disable": 141 }, "cli": { "as-any": 0, @@ -29,4 +29,4 @@ "ts-ignore": 0, "eslint-disable": 0 } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index bc64ac7dc8..e077cbb5c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4734,6 +4734,7 @@ __metadata: "@testing-library/jest-dom": "npm:^6.4.2" "@testing-library/react": "npm:^16.3.0" "@testing-library/user-event": "npm:^14.5.2" + "@total-typescript/shoehorn": "npm:^0.1.2" "@types/crypto-js": "npm:^4" "@types/flat": "npm:^5.0.5" "@types/identity-obj-proxy": "npm:^3" @@ -9982,6 +9983,13 @@ __metadata: languageName: node linkType: hard +"@total-typescript/shoehorn@npm:^0.1.2": + version: 0.1.2 + resolution: "@total-typescript/shoehorn@npm:0.1.2" + checksum: 10c0/e1bb904a3c46bd00a3a31a4f24a07a5de8f6c4aebb811f4ac108dfad066d2797c682b49bbcd09e98e2bd12e8b67db9bcb793e02e2ed8a996e1fe0d232a7efcf1 + languageName: node + linkType: hard + "@tsconfig/node10@npm:^1.0.7": version: 1.0.9 resolution: "@tsconfig/node10@npm:1.0.9"