Skip to content

Commit

Permalink
clean trpc #7
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Aug 4, 2024
1 parent 9597707 commit aaccac0
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/app/[rc_id]/conversations/[conv_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { env } from "~/env";
import { redirect } from "next/navigation";

import { DummySendMessage } from "~/app/_components/dummy-send-message";
import { api } from "~/lib/infrastructure/trpc/server";
import { api } from "~/lib/infrastructure/server/trpc/server-api";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
Expand Down
2 changes: 1 addition & 1 deletion src/app/[rc_id]/conversations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { env } from "~/env";
import { redirect } from "next/navigation";
import { ListConversationsPage } from "../../_components/list-conversations";
import { api } from "~/lib/infrastructure/trpc/server";
import { api } from "~/lib/infrastructure/server/trpc/server-api";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
Expand Down
2 changes: 1 addition & 1 deletion src/app/[rc_id]/sources/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from "~/env";
import { redirect } from "next/navigation";
import { api } from "~/lib/infrastructure/trpc/server";
import { api } from "~/lib/infrastructure/server/trpc/server-api";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { type NextRequest } from "next/server";

import { env } from "~/env";
import { appRouter } from "~/lib/infrastructure/server/config/trpc/root";
import { createTRPCContext } from "~/lib/infrastructure/trpc/trpc";
import { appRouter } from "~/lib/infrastructure/server/trpc/app-router";
import { createTRPCContext } from "~/lib/infrastructure/server/trpc/server";

/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { env } from "~/env";
import { redirect } from "next/navigation";
import { ListResearchContextsPage } from "./_components/list-research-contexts";
import type { ResearchContext } from "@maany_shr/kernel-planckster-sdk-ts";
import { api } from "~/lib/infrastructure/trpc/server";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
import { api } from "~/lib/infrastructure/server/trpc/server-api";
export default async function Home() {
const authGateway = serverContainer.get<AuthGatewayOutputPort>(GATEWAYS.AUTH_GATEWAY);
const session = await authGateway.getSession();
Expand Down
2 changes: 1 addition & 1 deletion src/app/sources/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { env } from "~/env";
import { redirect } from "next/navigation";
import { DummyUploadComponent } from "../_components/dummy-upload";
import { DummyDownloadComponent } from "../_components/dummy-download";
import { api } from "~/lib/infrastructure/trpc/server";
import { api } from "~/lib/infrastructure/server/trpc/server-api";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/infrastructure/client/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { loggerLink, unstable_httpBatchStreamLink } from "@trpc/client";
import { createTRPCReact } from "@trpc/react-query";
import { useState } from "react";
import SuperJSON from "superjson";
import type { AppRouter } from "~/lib/infrastructure/server/config/trpc/root";
import type { AppRouter } from "~/lib/infrastructure/server/trpc/app-router";


const createQueryClient = () => new QueryClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class NextAuthCredentialsProvider {
id: env.KP_CLIENT_ID.toString() || "1",
name: username,
email: "planckster-example@mpi-sws.org",
image: "https://cdn-icons-png.freepik.com/512/3177/3177440.png", // TODO: change this to the actual image
image: "https://api.multiavatar.com/user.svg", // TODO: change this to the actual image
kp: {
client_id: env.KP_CLIENT_ID || 1,
auth_token: env.KP_AUTH_TOKEN
Expand Down
26 changes: 0 additions & 26 deletions src/lib/infrastructure/server/config/trpc/root.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/lib/infrastructure/server/trpc/app-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { postRouter } from "~/lib/infrastructure/server/trpc/routers/post";
import { researchContextRouter } from "~/lib/infrastructure/server/trpc/routers/research-contexts";
import { conversationRouter } from "~/lib/infrastructure/server/trpc/routers/conversations";
import { messageRouter } from "~/lib/infrastructure/server/trpc/routers/messages";
import { sourceDataRouter } from "~/lib/infrastructure/server/trpc/routers/source-data";
import { kernelPlancksterHealthCheckRouter } from "./routers/health-check";
import { createTRPCRouter } from "~/lib/infrastructure/server/trpc/server";


/**
* This is the primary router for your server.
*
* All routers added in /api/routers should be manually added here.
*/
export const appRouter = createTRPCRouter({
post: postRouter,
researchContext: researchContextRouter,
conversation: conversationRouter,
message: messageRouter,
sourceData: sourceDataRouter,
healthCheck: kernelPlancksterHealthCheckRouter,
});

// export type definition of API
export type AppRouter = typeof appRouter;

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { headers } from "next/headers";
import { cache } from "react";
import { createTRPCContext } from "~/lib/infrastructure/trpc/trpc";
import { createTRPCContext } from "~/lib/infrastructure/server/trpc/server";
import { OpenAPI as KERNEL_PLANCKSTER_CONFIG } from "@maany_shr/kernel-planckster-sdk-ts";
import { env } from "~/env";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/lib/infrastructure/trpc/trpc";

import { ClientService as sdk } from "@maany_shr/kernel-planckster-sdk-ts";
import { env } from "~/env";
import { createTRPCRouter, protectedProcedure } from "~/lib/infrastructure/server/trpc/server";

export const conversationRouter = createTRPCRouter({
list: protectedProcedure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';
import { createTRPCRouter, publicProcedure } from '../../trpc/trpc';

import { HealthCheckService as sdk } from '@maany_shr/kernel-planckster-sdk-ts';
import { createTRPCRouter, publicProcedure } from '../server';

export const kernelPlancksterHealthCheckRouter = createTRPCRouter({
ping: publicProcedure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/lib/infrastructure/trpc/trpc";

import { ClientService as sdk } from "@maany_shr/kernel-planckster-sdk-ts";
import { env } from "~/env";
import OpenAIGateway from "~/lib/infrastructure/server/gateway/openai-gateway";
import { createTRPCRouter, protectedProcedure } from "../server";

export const messageRouter = createTRPCRouter({
list: protectedProcedure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { z } from "zod";

import {
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "~/lib/infrastructure/trpc/trpc";
import { createTRPCRouter, publicProcedure, protectedProcedure } from "../server";

let post = {
id: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/lib/infrastructure/trpc/trpc";

import { ClientService as sdk } from "@maany_shr/kernel-planckster-sdk-ts";
import type { NewResearchContextViewModel } from "@maany_shr/kernel-planckster-sdk-ts";
import { env } from "~/env";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "../config/ioc/server-container";
import { GATEWAYS } from "../config/ioc/server-ioc-symbols";
import serverContainer from "../../config/ioc/server-container";
import { GATEWAYS } from "../../config/ioc/server-ioc-symbols";
import { createTRPCRouter, protectedProcedure } from "../server";

export const researchContextRouter = createTRPCRouter({
list: protectedProcedure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/lib/infrastructure/trpc/trpc";

import { ClientService as sdk } from "@maany_shr/kernel-planckster-sdk-ts";

import { downloadFile, uploadFile } from "~/lib/infrastructure/server/repository/file-repository";

import { env } from "~/env";
import { createTRPCRouter, protectedProcedure } from "../server";

export const sourceDataRouter = createTRPCRouter({
listForClient: protectedProcedure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import "server-only";

import { createCallerFactory } from "./trpc";
import { appRouter } from "../server/config/trpc/root";
import createContext from "../server/config/trpc/context";
import { appRouter } from "./app-router";
import createContext from "./context";
import { createCallerFactory } from "./server";

/**
* Create a server-side caller for the tRPC API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";
import type AuthGatewayOutputPort from "~/lib/core/ports/secondary/auth-gateway-output-port";
import serverContainer from "../server/config/ioc/server-container";
import { GATEWAYS } from "../server/config/ioc/server-ioc-symbols";
import serverContainer from "~/lib/infrastructure/server/config/ioc/server-container";
import { GATEWAYS } from "~/lib/infrastructure/server/config/ioc/server-ioc-symbols";


/**
Expand Down

0 comments on commit aaccac0

Please sign in to comment.