FRE-592: Implement character database and relationship mapping
Add full character management system with enriched profiles (bio, traits, arcs, motivation, conflict, secrets), relationship mapping between characters with types and strength, character search/filter by role and arc type, and character statistics (scene count, dialogue, screen time). Includes database schema, tRPC router procedures, SolidJS components, API hooks, and unit tests. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
41
server/trpc/router.ts
Normal file
41
server/trpc/router.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { initTRPC, TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
import type { TRPCContext } from './types';
|
||||
|
||||
// Initialize tRPC with context
|
||||
const t = initTRPC.context<TRPCContext>().create();
|
||||
|
||||
// Middleware for authentication
|
||||
const isAuthenticated = t.middleware(({ ctx, next }) => {
|
||||
if (!ctx.userId) {
|
||||
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not authenticated' });
|
||||
}
|
||||
return next({ ctx: { ...ctx, userId: ctx.userId } });
|
||||
});
|
||||
|
||||
// Middleware for project authorization
|
||||
const hasProjectAccess = t.middleware(({ ctx, next }) => {
|
||||
const projectId = ctx.projectId;
|
||||
if (!projectId) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: 'Project access required' });
|
||||
}
|
||||
return next({ ctx: { ...ctx, projectId } });
|
||||
});
|
||||
|
||||
// Base router
|
||||
export const baseRouter = t.router;
|
||||
|
||||
// Procedure builders
|
||||
export const publicProcedure = t.procedure;
|
||||
export const protectedProcedure = t.procedure.use(isAuthenticated);
|
||||
export const projectProcedure = t.procedure.use(hasProjectAccess);
|
||||
|
||||
// Validation middleware
|
||||
export const validateInput = <T extends z.ZodTypeAny>(schema: T) => {
|
||||
return t.middleware(({ input, next }) => {
|
||||
const validated = schema.parse(input);
|
||||
return next({ input: validated });
|
||||
});
|
||||
};
|
||||
|
||||
export { t, TRPCError };
|
||||
Reference in New Issue
Block a user