chore: formatting fixes

This commit is contained in:
haritabh-z01 2025-06-28 11:02:07 +05:30
parent dd6af5e879
commit 119a46c339
167 changed files with 4507 additions and 3248 deletions

View file

@ -1,8 +1,8 @@
import { createTRPCReact } from '@trpc/react-query';
import { createTRPCProxyClient } from '@trpc/client';
import { ipcLink } from 'electron-trpc-experimental/renderer';
import superjson from 'superjson';
import type { AppRouter } from './router';
import { createTRPCReact } from "@trpc/react-query";
import { createTRPCProxyClient } from "@trpc/client";
import { ipcLink } from "electron-trpc-experimental/renderer";
import superjson from "superjson";
import type { AppRouter } from "./router";
// Create the tRPC React hooks
export const api = createTRPCReact<AppRouter>();

View file

@ -1,11 +1,11 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import { vocabularyRouter } from './routers/vocabulary';
import { transcriptionsRouter } from './routers/transcriptions';
import { modelsRouter } from './routers/models';
import { settingsRouter } from './routers/settings';
import { updaterRouter } from './routers/updater';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
import { vocabularyRouter } from "./routers/vocabulary";
import { transcriptionsRouter } from "./routers/transcriptions";
import { modelsRouter } from "./routers/models";
import { settingsRouter } from "./routers/settings";
import { updaterRouter } from "./routers/updater";
const t = initTRPC.create({
isServer: true,
@ -24,7 +24,7 @@ export const router = t.router({
// Example of a simple procedure without input
ping: t.procedure.query(() => {
return {
message: 'pong',
message: "pong",
timestamp: new Date(),
};
}),
@ -39,16 +39,16 @@ export const router = t.router({
// Vocabulary router
vocabulary: vocabularyRouter,
// Transcriptions router
transcriptions: transcriptionsRouter,
// Models router
models: modelsRouter,
// Settings router
settings: settingsRouter,
// Auto-updater router
updater: updaterRouter,
});

View file

@ -1,7 +1,11 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import type { Model, DownloadedModel, DownloadProgress } from '../../constants/models';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
import type {
Model,
DownloadedModel,
DownloadProgress,
} from "../../constants/models";
const t = initTRPC.create({
isServer: true,
@ -24,45 +28,62 @@ export const modelsRouter = t.router({
}),
// Get downloaded models
getDownloadedModels: t.procedure.query(async (): Promise<Record<string, DownloadedModel>> => {
return globalThis.modelManagerService ? await globalThis.modelManagerService.getDownloadedModels() : {};
}),
getDownloadedModels: t.procedure.query(
async (): Promise<Record<string, DownloadedModel>> => {
return globalThis.modelManagerService
? await globalThis.modelManagerService.getDownloadedModels()
: {};
},
),
// Check if model is downloaded
isModelDownloaded: t.procedure
.input(z.object({ modelId: z.string() }))
.query(async ({ input }) => {
return globalThis.modelManagerService ? await globalThis.modelManagerService.isModelDownloaded(input.modelId) : false;
return globalThis.modelManagerService
? await globalThis.modelManagerService.isModelDownloaded(input.modelId)
: false;
}),
// Get download progress
getDownloadProgress: t.procedure
.input(z.object({ modelId: z.string() }))
.query(async ({ input }) => {
return globalThis.modelManagerService?.getDownloadProgress(input.modelId) || null;
return (
globalThis.modelManagerService?.getDownloadProgress(input.modelId) ||
null
);
}),
// Get active downloads
getActiveDownloads: t.procedure.query(async (): Promise<DownloadProgress[]> => {
return globalThis.modelManagerService?.getActiveDownloads() || [];
}),
getActiveDownloads: t.procedure.query(
async (): Promise<DownloadProgress[]> => {
return globalThis.modelManagerService?.getActiveDownloads() || [];
},
),
// Get models directory
getModelsDirectory: t.procedure.query(async () => {
return globalThis.modelManagerService?.getModelsDirectory() || '';
return globalThis.modelManagerService?.getModelsDirectory() || "";
}),
// Local Whisper methods
isLocalWhisperAvailable: t.procedure.query(async () => {
return globalThis.localWhisperClient ? await globalThis.localWhisperClient.isAvailable() : false;
return globalThis.localWhisperClient
? await globalThis.localWhisperClient.isAvailable()
: false;
}),
getLocalWhisperModels: t.procedure.query(async () => {
return globalThis.localWhisperClient ? await globalThis.localWhisperClient.getAvailableModels() : [];
return globalThis.localWhisperClient
? await globalThis.localWhisperClient.getAvailableModels()
: [];
}),
getSelectedModel: t.procedure.query(async () => {
return globalThis.localWhisperClient ? globalThis.localWhisperClient.getSelectedModel() : null;
return globalThis.localWhisperClient
? globalThis.localWhisperClient.getSelectedModel()
: null;
}),
// Mutations
@ -70,7 +91,7 @@ export const modelsRouter = t.router({
.input(z.object({ modelId: z.string() }))
.mutation(async ({ input }) => {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
return await globalThis.modelManagerService.downloadModel(input.modelId);
}),
@ -79,7 +100,7 @@ export const modelsRouter = t.router({
.input(z.object({ modelId: z.string() }))
.mutation(async ({ input }) => {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
return globalThis.modelManagerService.cancelDownload(input.modelId);
}),
@ -88,7 +109,7 @@ export const modelsRouter = t.router({
.input(z.object({ modelId: z.string() }))
.mutation(async ({ input }) => {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
return globalThis.modelManagerService.deleteModel(input.modelId);
}),
@ -97,29 +118,38 @@ export const modelsRouter = t.router({
.input(z.object({ modelId: z.string() }))
.mutation(async ({ input }) => {
if (!globalThis.localWhisperClient) {
throw new Error('Local whisper client not initialized');
throw new Error("Local whisper client not initialized");
}
return await globalThis.localWhisperClient.setSelectedModel(input.modelId);
return await globalThis.localWhisperClient.setSelectedModel(
input.modelId,
);
}),
// Subscriptions using async generators
onDownloadProgress: t.procedure.subscription(async function* () {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
const eventQueue: Array<{ modelId: string; progress: DownloadProgress }> = [];
const eventQueue: Array<{ modelId: string; progress: DownloadProgress }> =
[];
const handleDownloadProgress = (modelId: string, progress: DownloadProgress) => {
const handleDownloadProgress = (
modelId: string,
progress: DownloadProgress,
) => {
eventQueue.push({ modelId, progress });
};
globalThis.modelManagerService.on('download-progress', handleDownloadProgress);
globalThis.modelManagerService.on(
"download-progress",
handleDownloadProgress,
);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const event = eventQueue.shift();
if (event) {
@ -128,27 +158,39 @@ export const modelsRouter = t.router({
}
}
} finally {
globalThis.modelManagerService?.off('download-progress', handleDownloadProgress);
globalThis.modelManagerService?.off(
"download-progress",
handleDownloadProgress,
);
}
}),
onDownloadComplete: t.procedure.subscription(async function* () {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
const eventQueue: Array<{ modelId: string; downloadedModel: DownloadedModel }> = [];
const eventQueue: Array<{
modelId: string;
downloadedModel: DownloadedModel;
}> = [];
const handleDownloadComplete = (modelId: string, downloadedModel: DownloadedModel) => {
const handleDownloadComplete = (
modelId: string,
downloadedModel: DownloadedModel,
) => {
eventQueue.push({ modelId, downloadedModel });
};
globalThis.modelManagerService.on('download-complete', handleDownloadComplete);
globalThis.modelManagerService.on(
"download-complete",
handleDownloadComplete,
);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const event = eventQueue.shift();
if (event) {
@ -157,13 +199,16 @@ export const modelsRouter = t.router({
}
}
} finally {
globalThis.modelManagerService?.off('download-complete', handleDownloadComplete);
globalThis.modelManagerService?.off(
"download-complete",
handleDownloadComplete,
);
}
}),
onDownloadError: t.procedure.subscription(async function* () {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
const eventQueue: Array<{ modelId: string; error: string }> = [];
@ -172,12 +217,12 @@ export const modelsRouter = t.router({
eventQueue.push({ modelId, error: error.message });
};
globalThis.modelManagerService.on('download-error', handleDownloadError);
globalThis.modelManagerService.on("download-error", handleDownloadError);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const event = eventQueue.shift();
if (event) {
@ -186,13 +231,16 @@ export const modelsRouter = t.router({
}
}
} finally {
globalThis.modelManagerService?.off('download-error', handleDownloadError);
globalThis.modelManagerService?.off(
"download-error",
handleDownloadError,
);
}
}),
onDownloadCancelled: t.procedure.subscription(async function* () {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
const eventQueue: Array<{ modelId: string }> = [];
@ -201,12 +249,15 @@ export const modelsRouter = t.router({
eventQueue.push({ modelId });
};
globalThis.modelManagerService.on('download-cancelled', handleDownloadCancelled);
globalThis.modelManagerService.on(
"download-cancelled",
handleDownloadCancelled,
);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const event = eventQueue.shift();
if (event) {
@ -215,13 +266,16 @@ export const modelsRouter = t.router({
}
}
} finally {
globalThis.modelManagerService?.off('download-cancelled', handleDownloadCancelled);
globalThis.modelManagerService?.off(
"download-cancelled",
handleDownloadCancelled,
);
}
}),
onModelDeleted: t.procedure.subscription(async function* () {
if (!globalThis.modelManagerService) {
throw new Error('Model manager service not initialized');
throw new Error("Model manager service not initialized");
}
const eventQueue: Array<{ modelId: string }> = [];
@ -230,12 +284,12 @@ export const modelsRouter = t.router({
eventQueue.push({ modelId });
};
globalThis.modelManagerService.on('model-deleted', handleModelDeleted);
globalThis.modelManagerService.on("model-deleted", handleModelDeleted);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const event = eventQueue.shift();
if (event) {
@ -244,7 +298,7 @@ export const modelsRouter = t.router({
}
}
} finally {
globalThis.modelManagerService?.off('model-deleted', handleModelDeleted);
globalThis.modelManagerService?.off("model-deleted", handleModelDeleted);
}
}),
});

View file

@ -1,7 +1,7 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import { SettingsService } from '../../modules/settings';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
import { SettingsService } from "../../modules/settings";
const t = initTRPC.create({
isServer: true,
@ -10,7 +10,7 @@ const t = initTRPC.create({
// FormatterConfig schema
const FormatterConfigSchema = z.object({
provider: z.literal('openrouter'),
provider: z.literal("openrouter"),
model: z.string(),
apiKey: z.string(),
enabled: z.boolean(),
@ -30,7 +30,7 @@ export const settingsRouter = t.router({
return await settingsService.getFormatterConfig();
} catch (error) {
if (globalThis.logger) {
globalThis.logger.ai.error('Error getting formatter config:', error);
globalThis.logger.ai.error("Error getting formatter config:", error);
}
return null;
}
@ -48,16 +48,16 @@ export const settingsRouter = t.router({
if (globalThis.aiService) {
globalThis.aiService.configureFormatter(input);
if (globalThis.logger) {
globalThis.logger.ai.info('Formatter configuration updated');
globalThis.logger.ai.info("Formatter configuration updated");
}
}
return true;
} catch (error) {
if (globalThis.logger) {
globalThis.logger.ai.error('Error setting formatter config:', error);
globalThis.logger.ai.error("Error setting formatter config:", error);
}
throw error;
}
}),
});
});

View file

@ -1,6 +1,6 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
import {
getTranscriptions,
getTranscriptionById,
@ -9,7 +9,7 @@ import {
deleteTranscription,
getTranscriptionsCount,
searchTranscriptions,
} from '../../db/transcriptions.js';
} from "../../db/transcriptions.js";
const t = initTRPC.create({
isServer: true,
@ -20,8 +20,8 @@ const t = initTRPC.create({
const GetTranscriptionsSchema = z.object({
limit: z.number().optional(),
offset: z.number().optional(),
sortBy: z.enum(['timestamp', 'createdAt']).optional(),
sortOrder: z.enum(['asc', 'desc']).optional(),
sortBy: z.enum(["timestamp", "createdAt"]).optional(),
sortOrder: z.enum(["asc", "desc"]).optional(),
search: z.string().optional(),
});
@ -41,9 +41,11 @@ const UpdateTranscriptionSchema = z.object({
export const transcriptionsRouter = t.router({
// Get transcriptions list with pagination and filtering
getTranscriptions: t.procedure.input(GetTranscriptionsSchema).query(async ({ input }) => {
return await getTranscriptions(input);
}),
getTranscriptions: t.procedure
.input(GetTranscriptionsSchema)
.query(async ({ input }) => {
return await getTranscriptions(input);
}),
// Get transcriptions count
getTranscriptionsCount: t.procedure
@ -53,9 +55,11 @@ export const transcriptionsRouter = t.router({
}),
// Get transcription by ID
getTranscriptionById: t.procedure.input(z.object({ id: z.number() })).query(async ({ input }) => {
return await getTranscriptionById(input.id);
}),
getTranscriptionById: t.procedure
.input(z.object({ id: z.number() }))
.query(async ({ input }) => {
return await getTranscriptionById(input.id);
}),
// Search transcriptions
searchTranscriptions: t.procedure
@ -63,16 +67,18 @@ export const transcriptionsRouter = t.router({
z.object({
searchTerm: z.string(),
limit: z.number().optional(),
})
}),
)
.query(async ({ input }) => {
return await searchTranscriptions(input.searchTerm, input.limit);
}),
// Create transcription
createTranscription: t.procedure.input(CreateTranscriptionSchema).mutation(async ({ input }) => {
return await createTranscription(input);
}),
createTranscription: t.procedure
.input(CreateTranscriptionSchema)
.mutation(async ({ input }) => {
return await createTranscription(input);
}),
// Update transcription
updateTranscription: t.procedure
@ -80,14 +86,16 @@ export const transcriptionsRouter = t.router({
z.object({
id: z.number(),
data: UpdateTranscriptionSchema,
})
}),
)
.mutation(async ({ input }) => {
return await updateTranscription(input.id, input.data);
}),
// Delete transcription
deleteTranscription: t.procedure.input(z.object({ id: z.number() })).mutation(async ({ input }) => {
return await deleteTranscription(input.id);
}),
});
deleteTranscription: t.procedure
.input(z.object({ id: z.number() }))
.mutation(async ({ input }) => {
return await deleteTranscription(input.id);
}),
});

View file

@ -1,6 +1,6 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
// Download progress type from electron-updater
interface DownloadProgress {
@ -24,22 +24,31 @@ declare global {
export const updaterRouter = t.router({
// Check for updates (manual trigger)
checkForUpdates: t.procedure
.input(z.object({ userInitiated: z.boolean().optional().default(false) }).optional())
.input(
z
.object({ userInitiated: z.boolean().optional().default(false) })
.optional(),
)
.mutation(async ({ input }) => {
try {
if (!globalThis.autoUpdaterService) {
throw new Error('Auto-updater service not available');
throw new Error("Auto-updater service not available");
}
const userInitiated = input?.userInitiated ?? false;
await globalThis.autoUpdaterService.checkForUpdates(userInitiated);
globalThis.logger?.updater.info('Update check initiated via tRPC', { userInitiated });
globalThis.logger?.updater.info("Update check initiated via tRPC", {
userInitiated,
});
return { success: true };
} catch (error) {
globalThis.logger?.updater.error('Error checking for updates via tRPC', {
error: error instanceof Error ? error.message : String(error)
});
globalThis.logger?.updater.error(
"Error checking for updates via tRPC",
{
error: error instanceof Error ? error.message : String(error),
},
);
throw error;
}
}),
@ -48,17 +57,22 @@ export const updaterRouter = t.router({
checkForUpdatesAndNotify: t.procedure.mutation(async () => {
try {
if (!globalThis.autoUpdaterService) {
throw new Error('Auto-updater service not available');
throw new Error("Auto-updater service not available");
}
await globalThis.autoUpdaterService.checkForUpdatesAndNotify();
globalThis.logger?.updater.info('Background update check initiated via tRPC');
globalThis.logger?.updater.info(
"Background update check initiated via tRPC",
);
return { success: true };
} catch (error) {
globalThis.logger?.updater.error('Error in background update check via tRPC', {
error: error instanceof Error ? error.message : String(error)
});
globalThis.logger?.updater.error(
"Error in background update check via tRPC",
{
error: error instanceof Error ? error.message : String(error),
},
);
throw error;
}
}),
@ -67,16 +81,16 @@ export const updaterRouter = t.router({
downloadUpdate: t.procedure.mutation(async () => {
try {
if (!globalThis.autoUpdaterService) {
throw new Error('Auto-updater service not available');
throw new Error("Auto-updater service not available");
}
await globalThis.autoUpdaterService.downloadUpdate();
globalThis.logger?.updater.info('Update download initiated via tRPC');
globalThis.logger?.updater.info("Update download initiated via tRPC");
return { success: true };
} catch (error) {
globalThis.logger?.updater.error('Error downloading update via tRPC', {
error: error instanceof Error ? error.message : String(error)
globalThis.logger?.updater.error("Error downloading update via tRPC", {
error: error instanceof Error ? error.message : String(error),
});
throw error;
}
@ -86,17 +100,20 @@ export const updaterRouter = t.router({
quitAndInstall: t.procedure.mutation(async () => {
try {
if (!globalThis.autoUpdaterService) {
throw new Error('Auto-updater service not available');
throw new Error("Auto-updater service not available");
}
globalThis.logger?.updater.info('Quit and install initiated via tRPC');
globalThis.logger?.updater.info("Quit and install initiated via tRPC");
globalThis.autoUpdaterService.quitAndInstall();
return { success: true };
} catch (error) {
globalThis.logger?.updater.error('Error quitting and installing via tRPC', {
error: error instanceof Error ? error.message : String(error)
});
globalThis.logger?.updater.error(
"Error quitting and installing via tRPC",
{
error: error instanceof Error ? error.message : String(error),
},
);
throw error;
}
}),
@ -107,12 +124,15 @@ export const updaterRouter = t.router({
if (!globalThis.autoUpdaterService) {
return false;
}
return globalThis.autoUpdaterService.isCheckingForUpdate();
} catch (error) {
globalThis.logger?.updater.error('Error getting update checking status via tRPC', {
error: error instanceof Error ? error.message : String(error)
});
globalThis.logger?.updater.error(
"Error getting update checking status via tRPC",
{
error: error instanceof Error ? error.message : String(error),
},
);
return false;
}
}),
@ -123,12 +143,15 @@ export const updaterRouter = t.router({
if (!globalThis.autoUpdaterService) {
return false;
}
return globalThis.autoUpdaterService.isUpdateAvailable();
} catch (error) {
globalThis.logger?.updater.error('Error getting update available status via tRPC', {
error: error instanceof Error ? error.message : String(error)
});
globalThis.logger?.updater.error(
"Error getting update available status via tRPC",
{
error: error instanceof Error ? error.message : String(error),
},
);
return false;
}
}),
@ -136,7 +159,7 @@ export const updaterRouter = t.router({
// Subscribe to download progress updates
onDownloadProgress: t.procedure.subscription(async function* () {
if (!globalThis.autoUpdaterService) {
throw new Error('Auto-updater service not initialized');
throw new Error("Auto-updater service not initialized");
}
const eventQueue: Array<DownloadProgress> = [];
@ -145,12 +168,15 @@ export const updaterRouter = t.router({
eventQueue.push(progressObj);
};
globalThis.autoUpdaterService.on('download-progress', handleDownloadProgress);
globalThis.autoUpdaterService.on(
"download-progress",
handleDownloadProgress,
);
try {
while (true) {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
while (eventQueue.length > 0) {
const progress = eventQueue.shift();
if (progress) {
@ -159,7 +185,10 @@ export const updaterRouter = t.router({
}
}
} finally {
globalThis.autoUpdaterService?.off('download-progress', handleDownloadProgress);
globalThis.autoUpdaterService?.off(
"download-progress",
handleDownloadProgress,
);
}
}),
});
});

View file

@ -1,6 +1,6 @@
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import { z } from 'zod';
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { z } from "zod";
import {
getVocabulary,
getVocabularyById,
@ -13,7 +13,7 @@ import {
bulkImportVocabulary,
trackWordUsage,
getMostUsedWords,
} from '../../db/vocabulary';
} from "../../db/vocabulary";
const t = initTRPC.create({
isServer: true,
@ -24,8 +24,8 @@ const t = initTRPC.create({
const GetVocabularySchema = z.object({
limit: z.number().optional(),
offset: z.number().optional(),
sortBy: z.enum(['word', 'dateAdded', 'usageCount']).optional(),
sortOrder: z.enum(['asc', 'desc']).optional(),
sortBy: z.enum(["word", "dateAdded", "usageCount"]).optional(),
sortOrder: z.enum(["asc", "desc"]).optional(),
search: z.string().optional(),
});
@ -44,14 +44,16 @@ const BulkImportSchema = z.array(
z.object({
word: z.string().min(1),
dateAdded: z.date().optional(),
})
}),
);
export const vocabularyRouter = t.router({
// Get vocabulary list with pagination and filtering
getVocabulary: t.procedure.input(GetVocabularySchema).query(async ({ input }) => {
return await getVocabulary(input);
}),
getVocabulary: t.procedure
.input(GetVocabularySchema)
.query(async ({ input }) => {
return await getVocabulary(input);
}),
// Get vocabulary count
getVocabularyCount: t.procedure
@ -61,9 +63,11 @@ export const vocabularyRouter = t.router({
}),
// Get vocabulary by ID
getVocabularyById: t.procedure.input(z.object({ id: z.number() })).query(async ({ input }) => {
return await getVocabularyById(input.id);
}),
getVocabularyById: t.procedure
.input(z.object({ id: z.number() }))
.query(async ({ input }) => {
return await getVocabularyById(input.id);
}),
// Get vocabulary by word
getVocabularyByWord: t.procedure
@ -78,7 +82,7 @@ export const vocabularyRouter = t.router({
z.object({
searchTerm: z.string(),
limit: z.number().optional(),
})
}),
)
.query(async ({ input }) => {
return await searchVocabulary(input.searchTerm, input.limit);
@ -92,9 +96,11 @@ export const vocabularyRouter = t.router({
}),
// Create vocabulary word
createVocabularyWord: t.procedure.input(CreateVocabularySchema).mutation(async ({ input }) => {
return await createVocabularyWord(input);
}),
createVocabularyWord: t.procedure
.input(CreateVocabularySchema)
.mutation(async ({ input }) => {
return await createVocabularyWord(input);
}),
// Update vocabulary word
updateVocabulary: t.procedure
@ -102,24 +108,30 @@ export const vocabularyRouter = t.router({
z.object({
id: z.number(),
data: UpdateVocabularySchema,
})
}),
)
.mutation(async ({ input }) => {
return await updateVocabulary(input.id, input.data);
}),
// Delete vocabulary word
deleteVocabulary: t.procedure.input(z.object({ id: z.number() })).mutation(async ({ input }) => {
return await deleteVocabulary(input.id);
}),
deleteVocabulary: t.procedure
.input(z.object({ id: z.number() }))
.mutation(async ({ input }) => {
return await deleteVocabulary(input.id);
}),
// Track word usage
trackWordUsage: t.procedure.input(z.object({ word: z.string() })).mutation(async ({ input }) => {
return await trackWordUsage(input.word);
}),
trackWordUsage: t.procedure
.input(z.object({ word: z.string() }))
.mutation(async ({ input }) => {
return await trackWordUsage(input.word);
}),
// Bulk import vocabulary
bulkImportVocabulary: t.procedure.input(BulkImportSchema).mutation(async ({ input }) => {
return await bulkImportVocabulary(input);
}),
bulkImportVocabulary: t.procedure
.input(BulkImportSchema)
.mutation(async ({ input }) => {
return await bulkImportVocabulary(input);
}),
});