diff --git a/package-lock.json b/package-lock.json index e4a32a6c7..8ead8e470 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36705,6 +36705,7 @@ "devDependencies": { "@aws-sdk/types": "^3.696.0", "@iot-app-kit/eslint-config": "*", + "@iot-app-kit/helpers": "*", "@iot-app-kit/ts-config": "*", "@iot-app-kit/vite-config": "*", "@types/lodash-es": "^4.17.12", @@ -36770,6 +36771,7 @@ "@iot-app-kit/atoms": "*", "@iot-app-kit/core": "*", "@iot-app-kit/core-util": "*", + "@iot-app-kit/helpers": "*", "@iot-app-kit/react-components": "*", "@iot-app-kit/source-iotsitewise": "*", "@popperjs/core": "^2.11.8", @@ -37025,6 +37027,9 @@ "tsx": "^4.19.2", "typescript": "^5.5.4", "vite": "^5.4.11" + }, + "peerDependencies": { + "@aws-sdk/client-iotsitewise": "^3.696.0" } }, "packages/react-components": { diff --git a/packages/core-util/package.json b/packages/core-util/package.json index 252c66c57..bc39fb42e 100644 --- a/packages/core-util/package.json +++ b/packages/core-util/package.json @@ -51,6 +51,7 @@ "devDependencies": { "@aws-sdk/types": "^3.696.0", "@iot-app-kit/eslint-config": "*", + "@iot-app-kit/helpers": "*", "@iot-app-kit/ts-config": "*", "@iot-app-kit/vite-config": "*", "@types/lodash-es": "^4.17.12", diff --git a/packages/core-util/src/sdks/number.ts b/packages/core-util/src/sdks/number.ts index 1d4123725..6b7fb6fa2 100644 --- a/packages/core-util/src/sdks/number.ts +++ b/packages/core-util/src/sdks/number.ts @@ -1,4 +1,4 @@ -import type { Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; /** * Rounds a number to a given precision diff --git a/packages/core/src/common/dataFilters.ts b/packages/core/src/common/dataFilters.ts index 9fb28b4f0..6d0d1b37d 100644 --- a/packages/core/src/common/dataFilters.ts +++ b/packages/core/src/common/dataFilters.ts @@ -1,9 +1,11 @@ import { bisector } from 'd3-array'; +import type { Primitive } from '@iot-app-kit/helpers'; + import { isHistoricalViewport } from './predicates'; import { parseDuration } from './time'; import type { Viewport } from '../data-module/data-cache/requestTypes'; -import type { DataPoint, Primitive } from '../data-module/types'; +import type { DataPoint } from '../data-module/types'; // By doing the mapping to a date within the bisector // we eliminate the need to iterate over the entire data. diff --git a/packages/core/src/common/number.ts b/packages/core/src/common/number.ts index df32b7d3d..16514672a 100755 --- a/packages/core/src/common/number.ts +++ b/packages/core/src/common/number.ts @@ -1,4 +1,4 @@ -import type { Primitive } from '../data-module/types'; +import type { Primitive } from '@iot-app-kit/helpers'; const MAX_PRECISION = 4; diff --git a/packages/core/src/data-module/data-cache/caching/caching.ts b/packages/core/src/data-module/data-cache/caching/caching.ts index 91d819b5a..4ad595911 100755 --- a/packages/core/src/data-module/data-cache/caching/caching.ts +++ b/packages/core/src/data-module/data-cache/caching/caching.ts @@ -1,3 +1,4 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { MINUTE_IN_MS, SECOND_IN_MS, @@ -14,7 +15,6 @@ import { getExpiredCacheIntervals } from './expiredCacheIntervals'; import { pointBisector } from '../../../common/dataFilters'; import type { DataPoint, - Primitive, RequestInformation, RequestInformationAndRange, } from '../../types'; diff --git a/packages/core/src/data-module/types.ts b/packages/core/src/data-module/types.ts index 390b7f18a..518c78df4 100644 --- a/packages/core/src/data-module/types.ts +++ b/packages/core/src/data-module/types.ts @@ -1,3 +1,7 @@ +import type { Primitive } from '@iot-app-kit/helpers'; + +export type { Primitive } from '@iot-app-kit/helpers'; + import { type AggregateType, type Quality } from '@aws-sdk/client-iotsitewise'; import type { TimeSeriesDataRequest, @@ -27,8 +31,6 @@ export interface DataPoint export type Resolution = number; -export type Primitive = string | number | boolean; - export type DataStreamId = string; export type DataBase = { diff --git a/packages/dashboard/package.json b/packages/dashboard/package.json index bd2f94846..10327a222 100644 --- a/packages/dashboard/package.json +++ b/packages/dashboard/package.json @@ -94,6 +94,7 @@ "@iot-app-kit/atoms": "*", "@iot-app-kit/core": "*", "@iot-app-kit/core-util": "*", + "@iot-app-kit/helpers": "*", "@iot-app-kit/react-components": "*", "@iot-app-kit/source-iotsitewise": "*", "@popperjs/core": "^2.11.8", diff --git a/packages/dashboard/src/components/csvDownloadButton/types.ts b/packages/dashboard/src/components/csvDownloadButton/types.ts index 24b1b7963..b624f2b8d 100644 --- a/packages/dashboard/src/components/csvDownloadButton/types.ts +++ b/packages/dashboard/src/components/csvDownloadButton/types.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { type Quality } from '@aws-sdk/client-iotsitewise'; export type CSVDownloadObject = { diff --git a/packages/dashboard/src/components/dashboard/queryContext.ts b/packages/dashboard/src/components/dashboard/queryContext.ts index c6a2c52a6..b70391bca 100644 --- a/packages/dashboard/src/components/dashboard/queryContext.ts +++ b/packages/dashboard/src/components/dashboard/queryContext.ts @@ -3,11 +3,9 @@ import { useRefreshRate } from '../../customization/hooks/useRefreshRate'; import { alarmModelQueryToSiteWiseAssetQuery } from '../../customization/widgets/utils/alarmModelQueryToAlarmQuery'; import { assetModelQueryToSiteWiseAssetQuery } from '../../customization/widgets/utils/assetModelQueryToAssetQuery'; -import type { - DataStream, - Primitive, - TimeSeriesDataQuery, -} from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; + +import type { DataStream, TimeSeriesDataQuery } from '@iot-app-kit/core'; import type { AlarmDataQuery, SiteWiseAlarmDataStreamQuery, diff --git a/packages/data-mocked/src/iot-sitewise/handlers/batchGetAssetPropertyValue/batchGetAssetPropertyValueHandler.ts b/packages/data-mocked/src/iot-sitewise/handlers/batchGetAssetPropertyValue/batchGetAssetPropertyValueHandler.ts index 8a8051ffe..4dfa80cd6 100644 --- a/packages/data-mocked/src/iot-sitewise/handlers/batchGetAssetPropertyValue/batchGetAssetPropertyValueHandler.ts +++ b/packages/data-mocked/src/iot-sitewise/handlers/batchGetAssetPropertyValue/batchGetAssetPropertyValueHandler.ts @@ -67,8 +67,9 @@ export class AssetPropertyValueFactory { ...this.#createDefaults(), ...partialAssetPropertyValue, value: { + // nullValue: { valueType: 'I' }, integerValue: faker.number.int({ min: 0, max: 100 }), - }, + } as any, }; return assetPropertyValue; @@ -81,8 +82,9 @@ export class AssetPropertyValueFactory { ...this.#createDefaults(), ...partialAssetPropertyValue, value: { + // nullValue: { valueType: 'D' }, doubleValue: faker.number.float({ min: 0, max: 100, precision: 0.001 }), - }, + } as any, }; return assetPropertyValue; @@ -95,8 +97,9 @@ export class AssetPropertyValueFactory { ...this.#createDefaults(), ...partialAssetPropertyValue, value: { + // nullValue: { valueType: 'B' }, booleanValue: faker.datatype.boolean(), - }, + } as any, }; return assetPropertyValue; @@ -109,8 +112,9 @@ export class AssetPropertyValueFactory { ...this.#createDefaults(), ...partialAssetPropertyValue, value: { + // nullValue: { valueType: 'S' }, stringValue: faker.helpers.arrayElement(['ON', 'OFF']), - }, + } as any, }; return assetPropertyValue; @@ -206,6 +210,7 @@ export function batchGetAssetPropertyValueHistoryHandler() { }; await delay(); + return HttpResponse.json(response, { status: 200 }); }); } diff --git a/packages/helpers/package.json b/packages/helpers/package.json index cc16b610e..c0c24c1a4 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -36,6 +36,9 @@ "typescript": "^5.5.4", "vite": "^5.4.11" }, + "peerDependencies": { + "@aws-sdk/client-iotsitewise": "^3.696.0" + }, "iotAppKit": { "scope": "protected" } diff --git a/packages/helpers/src/index.ts b/packages/helpers/src/index.ts index 90a4fb8e3..9a53a7e0c 100644 --- a/packages/helpers/src/index.ts +++ b/packages/helpers/src/index.ts @@ -5,3 +5,7 @@ export { NANO_SECOND_IN_MS, SECOND_IN_MS, } from './constants/time'; + +export { toValue } from './utils/toValue'; + +export type { Primitive } from './types'; diff --git a/packages/helpers/src/types.ts b/packages/helpers/src/types.ts new file mode 100644 index 000000000..76ae0c989 --- /dev/null +++ b/packages/helpers/src/types.ts @@ -0,0 +1 @@ +export type Primitive = string | number | boolean | null; diff --git a/packages/helpers/src/utils/toValue.ts b/packages/helpers/src/utils/toValue.ts new file mode 100644 index 000000000..e66b38e9d --- /dev/null +++ b/packages/helpers/src/utils/toValue.ts @@ -0,0 +1,46 @@ +import type { Primitive } from '../types'; +import type { Variant } from '@aws-sdk/client-iotsitewise'; + +/** + * Extracts the value out of a SiteWise Model Variant + * + * SiteWise Model values can either be a string, number or boolean. + * + * NOTE: Currently we treat booleans as strings. + */ +export const toValue = (variant: Variant | undefined): Primitive => { + if (variant == null) { + throw new Error('variant is undefined'); + } + + const { doubleValue, integerValue, stringValue, booleanValue } = variant; + + if (doubleValue != null) { + return doubleValue; + } + + if (integerValue != null) { + return integerValue; + } + + if (stringValue != null) { + return stringValue; + } + + if (booleanValue != null) { + return booleanValue.toString(); + } + + if ('nullValue' in variant && variant.nullValue != null) { + /** + * nullValue is not a nullish value + * it's an object with the string type of + * what the value should be. + */ + return null; + } + + throw new Error( + 'Expected value to have at least one property value, but instead it has none!' + ); +}; diff --git a/packages/react-components/src/components/bar-chart/hooks/useBarChartAlarms.ts b/packages/react-components/src/components/bar-chart/hooks/useBarChartAlarms.ts index afb3475b3..ff22b91fc 100644 --- a/packages/react-components/src/components/bar-chart/hooks/useBarChartAlarms.ts +++ b/packages/react-components/src/components/bar-chart/hooks/useBarChartAlarms.ts @@ -1,6 +1,6 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { type DataStream, - type Primitive, type ResolutionConfig, type Threshold, type ThresholdValue, diff --git a/packages/react-components/src/components/chart/chartOptions/tooltip/value.tsx b/packages/react-components/src/components/chart/chartOptions/tooltip/value.tsx index 349e6f91a..9ecd355de 100644 --- a/packages/react-components/src/components/chart/chartOptions/tooltip/value.tsx +++ b/packages/react-components/src/components/chart/chartOptions/tooltip/value.tsx @@ -1,10 +1,10 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { isNumeric, round } from '@iot-app-kit/core-util'; export const formatValue = (significantDigits = 4) => (value: Primitive) => - isNumeric(value) ? `${round(value, significantDigits)}` : value.toString(); + isNumeric(value) ? `${round(value, significantDigits)}` : value?.toString(); export type XYPlotTooltipValueOptions = { value?: Primitive; diff --git a/packages/react-components/src/components/chart/hooks/useChartAlarms.ts b/packages/react-components/src/components/chart/hooks/useChartAlarms.ts index a3fbdd232..793dfe48d 100644 --- a/packages/react-components/src/components/chart/hooks/useChartAlarms.ts +++ b/packages/react-components/src/components/chart/hooks/useChartAlarms.ts @@ -1,6 +1,6 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { type DataStream, - type Primitive, type Threshold, type ThresholdValue, } from '@iot-app-kit/core'; diff --git a/packages/react-components/src/components/chart/legend/table/legendTableAdapter.tsx b/packages/react-components/src/components/chart/legend/table/legendTableAdapter.tsx index f8930307c..30951a446 100644 --- a/packages/react-components/src/components/chart/legend/table/legendTableAdapter.tsx +++ b/packages/react-components/src/components/chart/legend/table/legendTableAdapter.tsx @@ -1,4 +1,5 @@ -import { type DataStream, type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import { type DataStream } from '@iot-app-kit/core'; import { type ChartLegend, type ChartOptions } from '../../types'; import { ChartLegendTable } from './table'; import { type DataStreamInformation, type TrendCursor } from './types'; diff --git a/packages/react-components/src/components/chart/legend/table/types.ts b/packages/react-components/src/components/chart/legend/table/types.ts index da64dc055..77f369b65 100644 --- a/packages/react-components/src/components/chart/legend/table/types.ts +++ b/packages/react-components/src/components/chart/legend/table/types.ts @@ -1,4 +1,5 @@ -import { type DataStream, type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import { type DataStream } from '@iot-app-kit/core'; import type { AlarmAssistantContext } from '../../../../common/assistantProps'; export type TrendCursorValues = { [id in string]?: number }; diff --git a/packages/react-components/src/components/chart/multiYAxis/yAxisMenu.tsx b/packages/react-components/src/components/chart/multiYAxis/yAxisMenu.tsx index 3f2d2e1eb..2aaf3b19b 100644 --- a/packages/react-components/src/components/chart/multiYAxis/yAxisMenu.tsx +++ b/packages/react-components/src/components/chart/multiYAxis/yAxisMenu.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; import { useMeasure } from 'react-use'; import { isNumeric, round } from '@iot-app-kit/core-util'; -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import Icon from '@cloudscape-design/components/icon'; import { @@ -24,7 +24,7 @@ import { useHighlightedDataStreams } from '../hooks/useHighlightedDataStreams'; import './yAxisMenu.css'; const getValue = (value: Primitive, significantDigits = 4) => - isNumeric(value) ? `${round(value, significantDigits)}` : value.toString(); + isNumeric(value) ? `${round(value, significantDigits)}` : value?.toString(); const MENU_OFFSET = 5; const MENU_FONT_SIZE = 14; diff --git a/packages/react-components/src/components/chart/types.ts b/packages/react-components/src/components/chart/types.ts index cb8d46aaf..524e0d2ae 100644 --- a/packages/react-components/src/components/chart/types.ts +++ b/packages/react-components/src/components/chart/types.ts @@ -1,6 +1,6 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { type DataStream, - type Primitive, type StyledThreshold, type ThresholdSettings, type Viewport, diff --git a/packages/react-components/src/components/gauge/converters/convertDataset.ts b/packages/react-components/src/components/gauge/converters/convertDataset.ts index 8efce62b3..3df4d6f48 100644 --- a/packages/react-components/src/components/gauge/converters/convertDataset.ts +++ b/packages/react-components/src/components/gauge/converters/convertDataset.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; export const convertDataset = (gaugeValue?: Primitive) => { return { diff --git a/packages/react-components/src/components/gauge/gaugeText.tsx b/packages/react-components/src/components/gauge/gaugeText.tsx index 5c4fa0fa3..785b0714a 100644 --- a/packages/react-components/src/components/gauge/gaugeText.tsx +++ b/packages/react-components/src/components/gauge/gaugeText.tsx @@ -9,7 +9,7 @@ import { import { AlarmStateTextWithAssistant } from '../alarm-components/alarm-state/alarmStateTextWithAssistant'; import { AlarmStateText } from '../alarm-components/alarm-state/alarmStateText'; import { getPreciseValue } from '../../utils/getPreciseValue'; -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { GaugeErrorText } from './gaugeErrorText'; import { type AlarmContent } from '../alarm-components/alarm-content/types'; import { type AssistantProperty } from '../../common/assistantProps'; diff --git a/packages/react-components/src/components/gauge/hooks/useGaugeConfiguration.ts b/packages/react-components/src/components/gauge/hooks/useGaugeConfiguration.ts index 7c5310ec6..1a0fa0cbf 100644 --- a/packages/react-components/src/components/gauge/hooks/useGaugeConfiguration.ts +++ b/packages/react-components/src/components/gauge/hooks/useGaugeConfiguration.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import isEqual from 'lodash-es/isEqual'; import merge from 'lodash-es/merge'; import { useEffect, useReducer } from 'react'; diff --git a/packages/react-components/src/components/gauge/types.ts b/packages/react-components/src/components/gauge/types.ts index afbbb9003..2674fc398 100644 --- a/packages/react-components/src/components/gauge/types.ts +++ b/packages/react-components/src/components/gauge/types.ts @@ -1,8 +1,8 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { type StyleSettingsMap, type Threshold, type Viewport, - type Primitive, } from '@iot-app-kit/core'; import type { WidgetSettings } from '../../common/dataTypes'; import { type AssistantProperty } from '../../common/assistantProps'; diff --git a/packages/react-components/src/components/gauge/utils/thresholdsToColor.ts b/packages/react-components/src/components/gauge/utils/thresholdsToColor.ts index 2b5c1fa38..161d54887 100644 --- a/packages/react-components/src/components/gauge/utils/thresholdsToColor.ts +++ b/packages/react-components/src/components/gauge/utils/thresholdsToColor.ts @@ -1,4 +1,5 @@ -import { type Primitive, type Threshold } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import { type Threshold } from '@iot-app-kit/core'; export const thresholdsToColor = ({ gaugeValue, diff --git a/packages/react-components/src/components/resource-explorers/requests/use-latest-values/create-data-streams-with-latest-value.ts b/packages/react-components/src/components/resource-explorers/requests/use-latest-values/create-data-streams-with-latest-value.ts index b3313953c..b9150d680 100644 --- a/packages/react-components/src/components/resource-explorers/requests/use-latest-values/create-data-streams-with-latest-value.ts +++ b/packages/react-components/src/components/resource-explorers/requests/use-latest-values/create-data-streams-with-latest-value.ts @@ -1,6 +1,7 @@ import type { BatchGetAssetPropertyValueSuccessEntry } from '@aws-sdk/client-iotsitewise'; import type { DataStreamRequestEntry, DataStreamResource } from './types'; import type { DataStreamResourceWithLatestValue } from '../../types/resources'; +import { toValue } from '@iot-app-kit/helpers'; type SuccessEntry = BatchGetAssetPropertyValueSuccessEntry; @@ -41,11 +42,10 @@ function createDataStreamWithLatestValue( requestEntry: DataStreamRequestEntry, successEntry?: SuccessEntry ): DataStreamResourceWithLatestValue { + const variant = successEntry?.assetPropertyValue?.value; const dataStreamWithLatestValue = { ...requestEntry.dataStream, - latestValue: Object.values( - successEntry?.assetPropertyValue?.value ?? {} - ).at(0), + latestValue: variant && toValue(variant), latestValueTimestamp: successEntry?.assetPropertyValue?.timestamp?.timeInSeconds, }; diff --git a/packages/react-components/src/components/resource-explorers/types/resources.ts b/packages/react-components/src/components/resource-explorers/types/resources.ts index e495f1db4..8058f89c5 100644 --- a/packages/react-components/src/components/resource-explorers/types/resources.ts +++ b/packages/react-components/src/components/resource-explorers/types/resources.ts @@ -1,4 +1,5 @@ import type { AssetSummary } from '@aws-sdk/client-iotsitewise'; +import { type Primitive } from '@iot-app-kit/helpers'; export interface AssetModelResource { assetModelId: string; @@ -59,6 +60,6 @@ export type TimeSeriesResourceWithLatestValue = export type DataStreamResourceWithLatestValue = DataStreamResource & { - latestValue?: number | string | boolean; + latestValue?: Primitive; latestValueTimestamp?: number; }; diff --git a/packages/react-components/src/components/shared-components/Value/Value.tsx b/packages/react-components/src/components/shared-components/Value/Value.tsx index 06e214909..0cb026279 100644 --- a/packages/react-components/src/components/shared-components/Value/Value.tsx +++ b/packages/react-components/src/components/shared-components/Value/Value.tsx @@ -1,4 +1,4 @@ -import type { Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { round } from '@iot-app-kit/core-util'; export const Value: React.FC<{ diff --git a/packages/react-components/src/components/table/createTableItems.ts b/packages/react-components/src/components/table/createTableItems.ts index b57514079..817658707 100644 --- a/packages/react-components/src/components/table/createTableItems.ts +++ b/packages/react-components/src/components/table/createTableItems.ts @@ -1,9 +1,5 @@ -import type { - DataStream, - Primitive, - Threshold, - Viewport, -} from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import type { DataStream, Threshold, Viewport } from '@iot-app-kit/core'; import { getDataBeforeDate } from '@iot-app-kit/core'; import { breachedThreshold } from '../../utils/breachedThreshold'; import { createCellItem } from './createCellItem'; @@ -40,7 +36,7 @@ export const createTableItems: ( const alarmItemsWithData = alarms.map((alarm) => { const isLoading = alarm.isLoading; return { - id: alarm.id as Primitive, + id: alarm.id as string, assetId: createCellItem( { value: alarm.assetId, @@ -189,7 +185,7 @@ export const createTableItems: ( const [first] = keyDataPairs; return { - id: first.data.value as Primitive, + id: first.data.value as string | number | boolean, ...keyDataPairs.reduce( (previous, { key, data }) => ({ ...previous, diff --git a/packages/react-components/src/components/table/types.ts b/packages/react-components/src/components/table/types.ts index 0d7b33bf7..461da100a 100644 --- a/packages/react-components/src/components/table/types.ts +++ b/packages/react-components/src/components/table/types.ts @@ -1,10 +1,6 @@ import { type TableProps as CloudscapeTableProps } from '@cloudscape-design/components'; -import type { - DataPoint, - ErrorDetails, - Primitive, - Threshold, -} from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import type { DataPoint, ErrorDetails, Threshold } from '@iot-app-kit/core'; import type { UseCollectionOptions } from '@cloudscape-design/collection-hooks'; import type { TableMessages } from './messages'; import type { AssistantProperty } from '../../common/assistantProps'; diff --git a/packages/react-components/src/hooks/useSingleQueryAlarm/useSingleQueryAlarm.ts b/packages/react-components/src/hooks/useSingleQueryAlarm/useSingleQueryAlarm.ts index 18b6b91d3..6a6193b9f 100644 --- a/packages/react-components/src/hooks/useSingleQueryAlarm/useSingleQueryAlarm.ts +++ b/packages/react-components/src/hooks/useSingleQueryAlarm/useSingleQueryAlarm.ts @@ -1,6 +1,6 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { type DataStream, - type Primitive, type Threshold, type ThresholdValue, type Viewport, diff --git a/packages/react-components/src/queries/useAssetPropertyValues/utils/toDataPoint.ts b/packages/react-components/src/queries/useAssetPropertyValues/utils/toDataPoint.ts index cbd7c30bd..8132fa78a 100644 --- a/packages/react-components/src/queries/useAssetPropertyValues/utils/toDataPoint.ts +++ b/packages/react-components/src/queries/useAssetPropertyValues/utils/toDataPoint.ts @@ -1,5 +1,6 @@ import { NANO_SECOND_IN_MS, SECOND_IN_MS } from './timeConstants'; -import type { DataPoint, Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import type { DataPoint } from '@iot-app-kit/core'; import type { AssetPropertyValue, TimeInNanos, diff --git a/packages/react-components/src/utils/breachedThreshold.ts b/packages/react-components/src/utils/breachedThreshold.ts index 6f51706b1..bf4148ed1 100644 --- a/packages/react-components/src/utils/breachedThreshold.ts +++ b/packages/react-components/src/utils/breachedThreshold.ts @@ -1,3 +1,4 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { getBreachedThreshold } from './thresholdUtils'; import { isDefined } from './predicates'; import { closestPoint } from './closestPoint'; @@ -6,7 +7,6 @@ import type { Threshold, DataStream, DataStreamId, - Primitive, StyledThreshold, } from '@iot-app-kit/core'; diff --git a/packages/react-components/src/utils/closestPoint.ts b/packages/react-components/src/utils/closestPoint.ts index 5c053833d..c514cdf3b 100644 --- a/packages/react-components/src/utils/closestPoint.ts +++ b/packages/react-components/src/utils/closestPoint.ts @@ -1,6 +1,7 @@ +import type { Primitive } from '@iot-app-kit/helpers'; import { pointBisector } from '@iot-app-kit/core'; import { DATA_ALIGNMENT } from '../common/constants'; -import type { DataPoint, Primitive } from '@iot-app-kit/core'; +import type { DataPoint } from '@iot-app-kit/core'; /** * Closest Points diff --git a/packages/react-components/src/utils/getPreciseValue.ts b/packages/react-components/src/utils/getPreciseValue.ts index eccc8200e..79f558039 100644 --- a/packages/react-components/src/utils/getPreciseValue.ts +++ b/packages/react-components/src/utils/getPreciseValue.ts @@ -1,5 +1,5 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { isNumeric, round } from '@iot-app-kit/core-util'; export const getPreciseValue = (value: Primitive, significantDigits = 4) => - isNumeric(value) ? `${round(value, significantDigits)}` : value.toString(); + isNumeric(value) ? `${round(value, significantDigits)}` : value?.toString(); diff --git a/packages/react-components/src/utils/sort.ts b/packages/react-components/src/utils/sort.ts index fb24e82f6..c6bec7d4f 100644 --- a/packages/react-components/src/utils/sort.ts +++ b/packages/react-components/src/utils/sort.ts @@ -1,4 +1,5 @@ -import type { DataPoint, Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import type { DataPoint } from '@iot-app-kit/core'; /** * Sorts points in order of their points values. diff --git a/packages/react-components/src/utils/thresholdUtils.ts b/packages/react-components/src/utils/thresholdUtils.ts index c29061148..fbd56fbdb 100644 --- a/packages/react-components/src/utils/thresholdUtils.ts +++ b/packages/react-components/src/utils/thresholdUtils.ts @@ -1,10 +1,7 @@ import { bisector } from 'd3-array'; +import type { Primitive } from '@iot-app-kit/helpers'; import { isNumeric } from '@iot-app-kit/core-util'; -import { - COMPARISON_OPERATOR, - type Threshold, - type Primitive, -} from '@iot-app-kit/core'; +import { COMPARISON_OPERATOR, type Threshold } from '@iot-app-kit/core'; import { isValid } from './predicates'; @@ -226,7 +223,11 @@ export const getBreachedThreshold = ( return undefined; } - if (typeof value === 'string' || typeof value === 'boolean') { + if ( + typeof value === 'string' || + typeof value === 'boolean' || + value === null + ) { return ( thresholds.find((threshold) => isThresholdBreached(value, threshold)) || undefined diff --git a/packages/scene-composer/src/components/three-fiber/DataOverlayComponent/DataOverlayDataRow.tsx b/packages/scene-composer/src/components/three-fiber/DataOverlayComponent/DataOverlayDataRow.tsx index e6fa25538..f9ad825db 100644 --- a/packages/scene-composer/src/components/three-fiber/DataOverlayComponent/DataOverlayDataRow.tsx +++ b/packages/scene-composer/src/components/three-fiber/DataOverlayComponent/DataOverlayDataRow.tsx @@ -1,5 +1,5 @@ import { type ReactElement, useCallback, useEffect, useMemo, useState } from 'react'; -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { useSceneComposerId } from '../../../common/sceneComposerIdContext'; import { type ITwinMakerEntityDataBindingContext } from '../../../interfaces'; diff --git a/packages/scene-composer/src/components/three-fiber/MotionIndicatorComponent/MotionIndicatorComponent.tsx b/packages/scene-composer/src/components/three-fiber/MotionIndicatorComponent/MotionIndicatorComponent.tsx index b7fe5aaef..0ee901ade 100644 --- a/packages/scene-composer/src/components/three-fiber/MotionIndicatorComponent/MotionIndicatorComponent.tsx +++ b/packages/scene-composer/src/components/three-fiber/MotionIndicatorComponent/MotionIndicatorComponent.tsx @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { useMemo } from 'react'; import { Color } from 'three'; diff --git a/packages/scene-composer/src/hooks/useBindingData.ts b/packages/scene-composer/src/hooks/useBindingData.ts index 67b6f9182..11a619dd7 100644 --- a/packages/scene-composer/src/hooks/useBindingData.ts +++ b/packages/scene-composer/src/hooks/useBindingData.ts @@ -1,4 +1,5 @@ -import { type DataBase, type DurationViewport, type Primitive, type TimeSeriesData } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import { type DataBase, type DurationViewport, type TimeSeriesData } from '@iot-app-kit/core'; import { type ITwinMakerEntityDataBindingContext } from '@iot-app-kit/source-iottwinmaker'; import isEmpty from 'lodash-es/isEmpty'; import { useEffect, useMemo, useRef, useState } from 'react'; diff --git a/packages/scene-composer/src/hooks/useRuleResult.ts b/packages/scene-composer/src/hooks/useRuleResult.ts index c138c74a3..ba9a7da8d 100644 --- a/packages/scene-composer/src/hooks/useRuleResult.ts +++ b/packages/scene-composer/src/hooks/useRuleResult.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import { useMemo } from 'react'; import { useSceneComposerId } from '../common/sceneComposerIdContext'; diff --git a/packages/scene-composer/src/utils/dataBindingUtils.ts b/packages/scene-composer/src/utils/dataBindingUtils.ts index ce221df66..090da5109 100644 --- a/packages/scene-composer/src/utils/dataBindingUtils.ts +++ b/packages/scene-composer/src/utils/dataBindingUtils.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; import jexl from 'jexl'; import isEqual from 'lodash-es/isEqual'; import pick from 'lodash-es/pick'; diff --git a/packages/scene-composer/src/utils/dataBindingVariableUtils.ts b/packages/scene-composer/src/utils/dataBindingVariableUtils.ts index 65b7695b9..931dd45b4 100644 --- a/packages/scene-composer/src/utils/dataBindingVariableUtils.ts +++ b/packages/scene-composer/src/utils/dataBindingVariableUtils.ts @@ -1,4 +1,4 @@ -import { type Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; // Match ${xyz} where xyz can be anything except new line, and as few as possible const bindingVariableRegex = /\$\{.+?\}/gi; diff --git a/packages/source-iotsitewise/src/alarms/iotevents/siteWiseAlarmModule.ts b/packages/source-iotsitewise/src/alarms/iotevents/siteWiseAlarmModule.ts index 14a03533c..9f2eeba30 100644 --- a/packages/source-iotsitewise/src/alarms/iotevents/siteWiseAlarmModule.ts +++ b/packages/source-iotsitewise/src/alarms/iotevents/siteWiseAlarmModule.ts @@ -5,13 +5,13 @@ import { getAlarmModelName } from './util/getAlarmModelName'; import { parseAlarmData } from './util/parseAlarmData'; import { getPropertyId } from './util/getPropertyId'; import { COMPARISON_SYMBOL } from './constants'; -import { toValue } from '../../time-series-data/util/toDataPoint'; import { type SiteWiseAssetModule, type SiteWiseAssetSession, } from '../../asset-modules'; import { getAlarmSourceProperty } from './util/getAlarmSourceProperty'; import type { Alarm, AlarmModel } from './types'; +import { toValue } from '@iot-app-kit/helpers'; export class SiteWiseAlarmModule { private readonly client: EventsClient; @@ -110,7 +110,8 @@ export class SiteWiseAlarmModule { inputPropertyId, thresholdPropertyId, comparisonOperator, - threshold, + // old synchro charts type does not support null + threshold: threshold === null ? '' : threshold, severity, rule, state, diff --git a/packages/source-iotsitewise/src/alarms/iotevents/util/completeAlarmStream.ts b/packages/source-iotsitewise/src/alarms/iotevents/util/completeAlarmStream.ts index 51392b632..834186a1d 100644 --- a/packages/source-iotsitewise/src/alarms/iotevents/util/completeAlarmStream.ts +++ b/packages/source-iotsitewise/src/alarms/iotevents/util/completeAlarmStream.ts @@ -35,7 +35,7 @@ export const completeAlarmStream = ({ if (!assetModel) { if ( isIoTEventsAlarmStateProperty( - dataStream.data[dataStream.data?.length - 1]?.y + dataStream.data[dataStream.data?.length - 1]?.y ?? undefined ) ) { return { diff --git a/packages/source-iotsitewise/src/time-series-data/util/toDataPoint.ts b/packages/source-iotsitewise/src/time-series-data/util/toDataPoint.ts index a0923cb7f..cd99db510 100644 --- a/packages/source-iotsitewise/src/time-series-data/util/toDataPoint.ts +++ b/packages/source-iotsitewise/src/time-series-data/util/toDataPoint.ts @@ -1,12 +1,12 @@ import { NANO_SECOND_IN_MS, SECOND_IN_MS } from './timeConstants'; -import type { DataPoint, Primitive } from '@iot-app-kit/core'; +import type { DataPoint } from '@iot-app-kit/core'; import type { AssetPropertyValue, TimeInNanos, - Variant, Aggregates, AggregatedValue, } from '@aws-sdk/client-iotsitewise'; +import { toValue } from '@iot-app-kit/helpers'; /** converts the TimeInNanos to milliseconds */ const toTimestamp = (time: TimeInNanos | undefined): number => @@ -17,41 +17,6 @@ const toTimestamp = (time: TimeInNanos | undefined): number => )) || 0; -/** - * Extracts the value out of a SiteWise Model Variant - * - * SiteWise Model values can either be a string, number or boolean. - * - * NOTE: Currently we treat booleans as strings. - */ -export const toValue = (variant: Variant | undefined): Primitive => { - if (variant == null) { - throw new Error('variant is undefined'); - } - - const { doubleValue, integerValue, stringValue, booleanValue } = variant; - - if (doubleValue != null) { - return doubleValue; - } - - if (integerValue != null) { - return integerValue; - } - - if (stringValue != null) { - return stringValue; - } - - if (booleanValue != null) { - return booleanValue.toString(); - } - - throw new Error( - 'Expected value to have at least one property value, but instead it has none!' - ); -}; - /** * Converts a SiteWise response for data into a data point understood by IoT App Kit. */ diff --git a/packages/source-iottwinmaker/src/common/types.ts b/packages/source-iottwinmaker/src/common/types.ts index 090519945..d1d4d64f7 100644 --- a/packages/source-iottwinmaker/src/common/types.ts +++ b/packages/source-iottwinmaker/src/common/types.ts @@ -1 +1 @@ -export type { Primitive } from '@iot-app-kit/core'; +export type { Primitive } from '@iot-app-kit/helpers'; diff --git a/packages/source-iottwinmaker/src/utils/propertyValueUtils.ts b/packages/source-iottwinmaker/src/utils/propertyValueUtils.ts index a952e5250..ec5c82f18 100644 --- a/packages/source-iottwinmaker/src/utils/propertyValueUtils.ts +++ b/packages/source-iottwinmaker/src/utils/propertyValueUtils.ts @@ -3,7 +3,8 @@ import type { DataType as TMDataType, } from '@aws-sdk/client-iottwinmaker'; import { Type } from '@aws-sdk/client-iottwinmaker'; -import type { DataType, Primitive } from '@iot-app-kit/core'; +import type { Primitive } from '@iot-app-kit/helpers'; +import type { DataType } from '@iot-app-kit/core'; import { DATA_TYPE } from '@iot-app-kit/core'; import isEmpty from 'lodash-es/isEmpty'; import isNil from 'lodash-es/isNil';