diff --git a/apps/desktop/src/trpc/router.ts b/apps/desktop/src/trpc/router.ts index d247f1a..72da159 100644 --- a/apps/desktop/src/trpc/router.ts +++ b/apps/desktop/src/trpc/router.ts @@ -1,5 +1,3 @@ -import { initTRPC } from "@trpc/server"; -import superjson from "superjson"; import { z } from "zod"; import { vocabularyRouter } from "./routers/vocabulary"; import { transcriptionsRouter } from "./routers/transcriptions"; @@ -7,16 +5,11 @@ import { modelsRouter } from "./routers/models"; import { settingsRouter } from "./routers/settings"; import { updaterRouter } from "./routers/updater"; import { recordingRouter } from "./routers/recording"; -import type { Context } from "./context"; +import { createRouter, procedure } from "./trpc"; -const t = initTRPC.context().create({ - isServer: true, - transformer: superjson, -}); - -export const router = t.router({ +export const router = createRouter({ // Test procedures - greeting: t.procedure.input(z.object({ name: z.string() })).query((req) => { + greeting: procedure.input(z.object({ name: z.string() })).query((req) => { return { text: `Hello ${req.input.name}`, timestamp: new Date(), // Date objects require transformation @@ -24,7 +17,7 @@ export const router = t.router({ }), // Example of a simple procedure without input - ping: t.procedure.query(() => { + ping: procedure.query(() => { return { message: "pong", timestamp: new Date(), @@ -32,7 +25,7 @@ export const router = t.router({ }), // Example mutation - echo: t.procedure.input(z.object({ message: z.string() })).mutation((req) => { + echo: procedure.input(z.object({ message: z.string() })).mutation((req) => { return { echo: req.input.message, timestamp: new Date(), @@ -58,7 +51,4 @@ export const router = t.router({ recording: recordingRouter, }); -export const procedure = t.procedure; -export const createRouter = t.router; - export type AppRouter = typeof router; diff --git a/apps/desktop/src/trpc/routers/models.ts b/apps/desktop/src/trpc/routers/models.ts index db273be..e99c6b1 100644 --- a/apps/desktop/src/trpc/routers/models.ts +++ b/apps/desktop/src/trpc/routers/models.ts @@ -1,6 +1,6 @@ import { observable } from "@trpc/server/observable"; import { z } from "zod"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; import type { Model, DownloadProgress } from "../../constants/models"; import type { DownloadedModel } from "../../db/schema"; diff --git a/apps/desktop/src/trpc/routers/recording.ts b/apps/desktop/src/trpc/routers/recording.ts index a7d0509..0cfcfd2 100644 --- a/apps/desktop/src/trpc/routers/recording.ts +++ b/apps/desktop/src/trpc/routers/recording.ts @@ -1,5 +1,5 @@ import { observable } from "@trpc/server/observable"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; import type { RecordingState } from "../../types/recording"; export const recordingRouter = createRouter({ diff --git a/apps/desktop/src/trpc/routers/settings.ts b/apps/desktop/src/trpc/routers/settings.ts index dcffd77..b1d0c79 100644 --- a/apps/desktop/src/trpc/routers/settings.ts +++ b/apps/desktop/src/trpc/routers/settings.ts @@ -1,6 +1,6 @@ import { observable } from "@trpc/server/observable"; import { z } from "zod"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; // FormatterConfig schema const FormatterConfigSchema = z.object({ diff --git a/apps/desktop/src/trpc/routers/transcriptions.ts b/apps/desktop/src/trpc/routers/transcriptions.ts index 618c719..4154ad3 100644 --- a/apps/desktop/src/trpc/routers/transcriptions.ts +++ b/apps/desktop/src/trpc/routers/transcriptions.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { dialog } from "electron"; import * as fs from "node:fs"; import * as path from "node:path"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; import { getTranscriptions, getTranscriptionById, diff --git a/apps/desktop/src/trpc/routers/updater.ts b/apps/desktop/src/trpc/routers/updater.ts index 76329d7..32cd327 100644 --- a/apps/desktop/src/trpc/routers/updater.ts +++ b/apps/desktop/src/trpc/routers/updater.ts @@ -1,6 +1,6 @@ import { observable } from "@trpc/server/observable"; import { z } from "zod"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; // Download progress type from electron-updater interface DownloadProgress { diff --git a/apps/desktop/src/trpc/routers/vocabulary.ts b/apps/desktop/src/trpc/routers/vocabulary.ts index 7e81a25..58b8282 100644 --- a/apps/desktop/src/trpc/routers/vocabulary.ts +++ b/apps/desktop/src/trpc/routers/vocabulary.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { createRouter, procedure } from "../router"; +import { createRouter, procedure } from "../trpc"; import { getVocabulary, getVocabularyById, diff --git a/apps/desktop/src/trpc/trpc.ts b/apps/desktop/src/trpc/trpc.ts new file mode 100644 index 0000000..0bd1c6c --- /dev/null +++ b/apps/desktop/src/trpc/trpc.ts @@ -0,0 +1,11 @@ +import { initTRPC } from "@trpc/server"; +import superjson from "superjson"; +import type { Context } from "./context"; + +const t = initTRPC.context().create({ + isServer: true, + transformer: superjson, +}); + +export const procedure = t.procedure; +export const createRouter = t.router;