From ca014cb45606e1f26fcb5f3d4b58776ce2f88a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Fri, 8 Nov 2024 11:48:46 +0100 Subject: [PATCH 1/3] Add guards for types needed for prop types by mobile --- src/types/types.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/types/types.ts b/src/types/types.ts index 0150ee4..302d33a 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -259,6 +259,28 @@ export type Caption = { file_id: string; }; +export function isCaption(obj: unknown): obj is Caption { + if (typeof obj !== 'object' || obj === null) { + return false; + } + + const caption = obj as Caption; + + if (typeof caption.title !== 'string') { + return false; + } + + if (typeof caption.language !== 'string') { + return false; + } + + if (typeof caption.file_id !== 'string') { + return false; + } + + return true; +} + export type JobStopData = { job_id: string; }; @@ -270,6 +292,32 @@ export type CallJobMetadata = { rec_id?: string; }; +export function isCallJobMetadata(obj: unknown): obj is CallJobMetadata { + if (typeof obj !== 'object' || obj === null) { + return false; + } + + const metadata = obj as CallJobMetadata; + + if (typeof metadata.file_id !== 'string') { + return false; + } + + if (typeof metadata.post_id !== 'string') { + return false; + } + + if (metadata.tr_id !== undefined && typeof metadata.tr_id !== 'string') { + return false; + } + + if (metadata.rec_id !== undefined && typeof metadata.rec_id !== 'string') { + return false; + } + + return true; +} + export type CallRecordingPropsMap = { [key: string]: CallJobMetadata; }; From 4895566eaf87a02a4343544ec1a141c130b57752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 12 Nov 2024 13:54:31 +0100 Subject: [PATCH 2/3] Add eslint ignores --- src/types/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/types.ts b/src/types/types.ts index 302d33a..9900f48 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -307,10 +307,12 @@ export function isCallJobMetadata(obj: unknown): obj is CallJobMetadata { return false; } + // eslint-disable-next-line no-undefined if (metadata.tr_id !== undefined && typeof metadata.tr_id !== 'string') { return false; } + // eslint-disable-next-line no-undefined if (metadata.rec_id !== undefined && typeof metadata.rec_id !== 'string') { return false; } From 56672ecb7c61370998910f066b4ac9fe7d978ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 12 Nov 2024 16:27:21 +0100 Subject: [PATCH 3/3] Run build --- lib/types/types.d.ts | 2 ++ lib/types/types.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index 22e5e16..cef72e0 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -187,6 +187,7 @@ export type Caption = { language: string; file_id: string; }; +export declare function isCaption(obj: unknown): obj is Caption; export type JobStopData = { job_id: string; }; @@ -196,6 +197,7 @@ export type CallJobMetadata = { tr_id?: string; rec_id?: string; }; +export declare function isCallJobMetadata(obj: unknown): obj is CallJobMetadata; export type CallRecordingPropsMap = { [key: string]: CallJobMetadata; }; diff --git a/lib/types/types.js b/lib/types/types.js index 665b00a..daf50b3 100644 --- a/lib/types/types.js +++ b/lib/types/types.js @@ -5,3 +5,40 @@ export var TranscribeAPI; TranscribeAPI["WhisperCPP"] = "whisper.cpp"; TranscribeAPI["AzureAI"] = "azure"; })(TranscribeAPI || (TranscribeAPI = {})); +export function isCaption(obj) { + if (typeof obj !== 'object' || obj === null) { + return false; + } + const caption = obj; + if (typeof caption.title !== 'string') { + return false; + } + if (typeof caption.language !== 'string') { + return false; + } + if (typeof caption.file_id !== 'string') { + return false; + } + return true; +} +export function isCallJobMetadata(obj) { + if (typeof obj !== 'object' || obj === null) { + return false; + } + const metadata = obj; + if (typeof metadata.file_id !== 'string') { + return false; + } + if (typeof metadata.post_id !== 'string') { + return false; + } + // eslint-disable-next-line no-undefined + if (metadata.tr_id !== undefined && typeof metadata.tr_id !== 'string') { + return false; + } + // eslint-disable-next-line no-undefined + if (metadata.rec_id !== undefined && typeof metadata.rec_id !== 'string') { + return false; + } + return true; +}