aboutsummaryrefslogtreecommitdiffstats
path: root/packages/benchmarks/src/trpc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/benchmarks/src/trpc.ts')
-rw-r--r--packages/benchmarks/src/trpc.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/benchmarks/src/trpc.ts b/packages/benchmarks/src/trpc.ts
new file mode 100644
index 00000000..3a8cfe37
--- /dev/null
+++ b/packages/benchmarks/src/trpc.ts
@@ -0,0 +1,26 @@
+import { createTRPCClient, httpBatchLink } from "@trpc/client";
+import superjson from "superjson";
+
+import type { AppRouter } from "@karakeep/trpc/routers/_app";
+
+export type TrpcClient = ReturnType<typeof getTrpcClient>;
+
+export function getTrpcClient(apiKey?: string) {
+ if (!process.env.KARAKEEP_PORT) {
+ throw new Error("KARAKEEP_PORT is not set. Did you start the containers?");
+ }
+
+ return createTRPCClient<AppRouter>({
+ links: [
+ httpBatchLink({
+ transformer: superjson,
+ url: `http://localhost:${process.env.KARAKEEP_PORT}/api/trpc`,
+ headers() {
+ return {
+ authorization: apiKey ? `Bearer ${apiKey}` : undefined,
+ };
+ },
+ }),
+ ],
+ });
+}