From 7a2209a728b7b355f4fd7eb5685d7ac8804f786f Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Tue, 24 Dec 2024 14:13:14 +0300 Subject: [PATCH] Server type fixes --- server/src/trpc/context.ts | 2 +- server/src/trpc/utils/auth.ts | 14 +++++++++----- server/src/utils/item.ts | 12 +++++++----- server/src/vector/client.ts | 8 ++++---- tsconfig.json | 3 ++- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/server/src/trpc/context.ts b/server/src/trpc/context.ts index 20cfe13ce..2f352c44f 100644 --- a/server/src/trpc/context.ts +++ b/server/src/trpc/context.ts @@ -4,7 +4,7 @@ import { DbClient } from '../db/client'; import { VectorClient } from '../vector/client'; import { AiClient } from '../integrations/ai/client'; import { type R2Bucket } from '@cloudflare/workers-types'; -import { GeojsonStorageService } from 'src/services/geojsonStorage'; +import { GeojsonStorageService } from '../services/geojsonStorage'; let DB: D1Database; diff --git a/server/src/trpc/utils/auth.ts b/server/src/trpc/utils/auth.ts index 75b9cadb2..85ee5d78e 100644 --- a/server/src/trpc/utils/auth.ts +++ b/server/src/trpc/utils/auth.ts @@ -1,6 +1,6 @@ import { TRPCError } from '@trpc/server'; import { User as UserRepository } from '../../drizzle/methods/User'; -import { type User } from 'src/db/schema'; +import { type User } from '../../db/schema'; import * as jwt from 'hono/jwt'; // import * as jwt from 'hono/jwt'; @@ -35,13 +35,17 @@ const extractToken = (req: Request): string | null => { * @param {string} jwtSecret - The JWT secret. * @returns {Promise} - The user associated with the token. Resolves to null if token couldn't be verified or user is not found. */ -const findUser = async (token: string, jwtSecret: string): Promise => { +const findUser = async ( + token: string, + jwtSecret: string, +): Promise => { const userRepository = new UserRepository(); - let user: User = null; - // const user: any = await userClass.validateResetToken(token, jwtSecret); + let user: User | null = null; try { const decoded = await jwt.verify(token, jwtSecret); - user = await userRepository.findUser({ userId: decoded.id as string }); + user = (await userRepository.findUser({ + userId: decoded.id as string, + })) as User; } catch { // pass } diff --git a/server/src/utils/item.ts b/server/src/utils/item.ts index ef2e3051d..cc56105a6 100644 --- a/server/src/utils/item.ts +++ b/server/src/utils/item.ts @@ -1,6 +1,6 @@ // import { prisma } from '../prisma'; -import { Item } from 'src/db/schema'; +import { Item } from '../db/schema'; // /** // * Validates the item data and creates a new item. @@ -49,10 +49,12 @@ export const summarizeItem = (item: Item & { category?: { name: string } }) => { const details = item.productDetails; const description = item.description; - const parsedProductDetails = Object.entries(details).reduce( - (acc, [key, value]) => `${acc},${key}:${value}`, - '', - ); + const parsedProductDetails = details + ? Object.entries(details).reduce( + (acc, [key, value]) => `${acc},${key}:${value}`, + '', + ) + : ''; return `Title: ${productName}\nCategory: ${category}\nDetails: ${parsedProductDetails}\nDescription: ${description}`; }; diff --git a/server/src/vector/client.ts b/server/src/vector/client.ts index 59738a1cf..9afc95b3c 100644 --- a/server/src/vector/client.ts +++ b/server/src/vector/client.ts @@ -209,7 +209,7 @@ class VectorClient { metadata: Metadata; }>, ) { - const contentList = []; + const contentList: string[] = []; for (const record of records) { contentList.push(record.content); } @@ -219,10 +219,10 @@ class VectorClient { namespace: string; metadata: Metadata; }>(contentList, (embedding, index) => ({ - id: records[index].id, + id: records[index]!.id, values: embedding, - namespace: records[index].namespace, - metadata: records[index].metadata, + namespace: records[index]!.namespace, + metadata: records[index]!.metadata, })); await this.upsert(values); diff --git a/tsconfig.json b/tsconfig.json index bfcc8bd77..4c4fbca20 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "strictNullChecks": true, "noUncheckedIndexedAccess": true, - "module": "commonJS", + "module": "node16", + "moduleResolution": "node16", "paths": { "app/*": ["./packages/app/*"], "@packrat/api/*": ["./packages/api/*"],