From 9aaec7ad5744e3c46eb0be2fa0444ced1ebf26ad Mon Sep 17 00:00:00 2001 From: Egor Didenko Date: Wed, 15 Nov 2023 17:10:33 +0300 Subject: [PATCH] types(rest-client/addons): refactor types and their exports --- packages/rest-client/src/index.ts | 13 ++++- packages/rest-client/src/types/AppData.ts | 57 ++++++++----------- .../src/types/ConversionOptions.ts | 2 +- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 5ebec750..e5409393 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -7,16 +7,22 @@ export { AddonParams, AddonUcClamavVirusScanParams, AddonAwsRekognitionDetectLabelsParams, + AddonAwsRekognitionModerationLabelsParams, AddonRemoveBgParams } from './types/AddonParams' export { + AddonData, + AwsLabel, AppData, ClamavVirusScan, AwsRekognitionDetectLabelParent, AwsRekognitionDetectLabelInstance, AwsRekognitionDetectLabel, AwsRekognitionDetectLabels, - RemoveBg + AwsRekognitionDetectModerationLabels, + AwsRekognitionDetectModerationLabel, + RemoveBg, + TechFieldsAppData } from './types/AppData' export { BatchResponse, BatchResponseStatus } from './types/BatchResponse' export { ConversionStatus } from './types/ConversionStatus' @@ -30,7 +36,10 @@ export { WebhookEvent } from './types/WebhookEvent' export { StoreValue } from '@uploadcare/api-client-utils' export { Paginatable } from './types/Paginatable' export { Md5Function } from './lib/md5/Md5Function' -export { ConversionOptions } from './types/ConversionOptions' +export { + ConversionOptions, + BaseConversionOption +} from './types/ConversionOptions' export { ConversionResponse } from './types/ConversionResponse' export { ConversionStatusOptions } from './types/ConversionStatusOptions' export { ConversionStatusResponse } from './types/ConversionStatusResponse' diff --git a/packages/rest-client/src/types/AppData.ts b/packages/rest-client/src/types/AppData.ts index 24048e20..3eb9d242 100644 --- a/packages/rest-client/src/types/AppData.ts +++ b/packages/rest-client/src/types/AppData.ts @@ -6,12 +6,12 @@ export type TechFieldsAppData = { datetime_updated: string } -export type ClamavVirusScan = { - data: { - infected: boolean - infected_with: string - } -} & TechFieldsAppData +export type AddonData = TechFieldsAppData & { data: T } + +export type ClamavVirusScan = AddonData<{ + infected: boolean + infected_with: string +}> export type AwsRekognitionDetectLabelParent = { Name: string @@ -27,41 +27,34 @@ export type AwsRekognitionDetectLabelInstance = { } } -export type AwsRekognitionDetectLabel = { - Confidence: number - Name: string +export type AwsLabel = T & { Confidence: number; Name: string } + +export type AwsRekognitionDetectLabel = AwsLabel<{ Parents: AwsRekognitionDetectLabelParent[] Instances: AwsRekognitionDetectLabelInstance[] -} +}> -export type AwsRekognitionDetectLabels = { - data: { - LabelModelVersion: string - Labels: AwsRekognitionDetectLabel[] - } -} & TechFieldsAppData +export type AwsRekognitionDetectLabels = AddonData<{ + LabelModelVersion: string + Labels: AwsRekognitionDetectLabel[] +}> -export type AwsRekognitionDetectModerationLabel = Pick< - AwsRekognitionDetectLabel, - 'Confidence' | 'Name' -> & { ParentName: string } +export type AwsRekognitionDetectModerationLabel = AwsLabel<{ + ParentName: string +}> -export type AwsRekognitionDetectModerationLabels = { - data: { - ModerationModelVersion: string - ModerationLabels: AwsRekognitionDetectModerationLabel[] - } -} & TechFieldsAppData +export type AwsRekognitionDetectModerationLabels = AddonData<{ + ModerationModelVersion: string + ModerationLabels: AwsRekognitionDetectModerationLabel[] +}> -export type RemoveBg = { - data: { - foreground_type: string - } -} & TechFieldsAppData +export type RemoveBg = AddonData<{ + foreground_type: string +}> export type AppData = { [AddonName.UC_CLAMAV_VIRUS_SCAN]?: ClamavVirusScan [AddonName.AWS_REKOGNITION_DETECT_LABELS]?: AwsRekognitionDetectLabels - [AddonName.AWS_REKOGNITION_DETECT_MODERATION_LABELS]: AwsRekognitionDetectModerationLabels + [AddonName.AWS_REKOGNITION_DETECT_MODERATION_LABELS]?: AwsRekognitionDetectModerationLabels [AddonName.REMOVE_BG]?: RemoveBg } diff --git a/packages/rest-client/src/types/ConversionOptions.ts b/packages/rest-client/src/types/ConversionOptions.ts index bf4e5940..b4dde244 100644 --- a/packages/rest-client/src/types/ConversionOptions.ts +++ b/packages/rest-client/src/types/ConversionOptions.ts @@ -2,7 +2,7 @@ import { ConversionType } from './ConversionType' import { StoreValue } from '@uploadcare/api-client-utils' import { ValueOf } from './ValueOf' -type BaseConversionOption = { +export type BaseConversionOption = { type: T paths: string[] store?: StoreValue