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; +} diff --git a/src/types/types.ts b/src/types/types.ts index 0150ee4..9900f48 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,34 @@ 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; + } + + // 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; +} + export type CallRecordingPropsMap = { [key: string]: CallJobMetadata; };