All files / src/services/elevenLabsInternalAPI/history response.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90    1x           10x           1x       1x                                                                         11x                                     1x             1x                
import { z } from "zod";
 
const DialogueItemSchema = z
    .object({
        text: z.string(),
        voice_id: z.string(),
        voice_name: z.string(),
    })
    .transform(({ voice_id, voice_name, ...rest }) => ({
        ...rest,
        voiceID: voice_id,
        voiceName: voice_name,
    }));
 
const SettingsSchema = z.object({
    stability: z.number(),
});
 
const HistoryItemSchema = z
    .object({
        history_item_id: z.string(),
        request_id: z.string(),
        voice_id: z.string().nullable(),
        model_id: z.string(),
        voice_name: z.string().nullable(),
        voice_category: z.string().nullable(),
        text: z.string().nullable(),
        date_unix: z.number(),
        character_count_change_from: z.number(),
        character_count_change_to: z.number(),
        content_type: z.string(),
        state: z.string(),
        settings: SettingsSchema,
        feedback: z.unknown().nullable(),
        share_link_id: z.string().nullable(),
        source: z.string(),
        alignments: z.unknown().nullable(),
        dialogue: z.array(DialogueItemSchema).nullable(),
        output_format: z.string(),
    })
    .transform(
        ({
            history_item_id,
            request_id,
            voice_id,
            model_id,
            voice_name,
            voice_category,
            date_unix,
            character_count_change_from,
            character_count_change_to,
            content_type,
            share_link_id,
            output_format,
            ...rest
        }) => ({
            ...rest,
            historyItemID: history_item_id,
            requestID: request_id,
            voiceID: voice_id,
            modelID: model_id,
            voiceName: voice_name,
            voiceCategory: voice_category,
            dateUnix: date_unix,
            characterCountChange: {
                from: character_count_change_from,
                to: character_count_change_to,
            },
            contentType: content_type,
            shareLinkID: share_link_id,
            outputFormat: output_format,
        }),
    );
 
export const ResponseSchema = z
    .object({
        history: z.array(HistoryItemSchema),
        last_history_item_id: z.string().nullable(),
        has_more: z.boolean(),
        scanned_until: z.number().nullable(),
    })
    .transform(({ history, last_history_item_id, has_more, scanned_until }) => ({
        history,
        lastHistoryItemID: last_history_item_id,
        more: has_more,
        scannedUntil: scanned_until,
    }));
 
export type HistoryResponse = z.output<typeof ResponseSchema>;