From ee3146e7ac379cc4980f1c95c6511d12a0f45cc2 Mon Sep 17 00:00:00 2001 From: Harshith Mullapudi Date: Tue, 27 May 2025 23:24:50 +0530 Subject: [PATCH] Feat: added database --- .../app/components/layout/LoginPageLayout.tsx | 4 +- apps/webapp/app/db.server.ts | 41 ++++++++++++------- apps/webapp/app/models/user.server.ts | 24 ++++++++--- apps/webapp/app/root.tsx | 4 +- apps/webapp/app/utils/singleton.ts | 6 +-- apps/webapp/package.json | 2 +- package.json | 2 +- packages/database/package.json | 2 +- pnpm-lock.yaml | 6 +-- 9 files changed, 58 insertions(+), 33 deletions(-) diff --git a/apps/webapp/app/components/layout/LoginPageLayout.tsx b/apps/webapp/app/components/layout/LoginPageLayout.tsx index c5b7f5e..24cca4a 100644 --- a/apps/webapp/app/components/layout/LoginPageLayout.tsx +++ b/apps/webapp/app/components/layout/LoginPageLayout.tsx @@ -12,11 +12,11 @@ interface QuoteType { const quotes: QuoteType[] = [ { quote: - "Echo remembers that I prefer emails in dark mode and hate promotional content. It automatically filters and formats my communications just the way I like.", + "Recall remembers that I prefer emails in dark mode and hate promotional content. It automatically filters and formats my communications just the way I like.", }, { quote: - "When I mention liking Nike's latest running shoes, Echo remembers this preference and helps surface relevant product launches and deals across my browsing.", + "When I mention liking Nike's latest running shoes, Recall remembers this preference and helps surface relevant product launches and deals across my browsing.", }, { quote: diff --git a/apps/webapp/app/db.server.ts b/apps/webapp/app/db.server.ts index ee06a04..777d4a2 100644 --- a/apps/webapp/app/db.server.ts +++ b/apps/webapp/app/db.server.ts @@ -6,7 +6,7 @@ import { type PrismaTransactionClient, type PrismaTransactionOptions, $transaction as transac, -} from "@echo/database"; +} from "@recall/database"; import invariant from "tiny-invariant"; import { z } from "zod"; import { env } from "./env.server"; @@ -27,18 +27,20 @@ export async function $transaction( prisma: PrismaClientOrTransaction, name: string, fn: (prisma: PrismaTransactionClient, span?: Span) => Promise, - options?: PrismaTransactionOptions + options?: PrismaTransactionOptions, ): Promise; export async function $transaction( prisma: PrismaClientOrTransaction, fn: (prisma: PrismaTransactionClient) => Promise, - options?: PrismaTransactionOptions + options?: PrismaTransactionOptions, ): Promise; export async function $transaction( prisma: PrismaClientOrTransaction, fnOrName: ((prisma: PrismaTransactionClient) => Promise) | string, - fnOrOptions?: ((prisma: PrismaTransactionClient) => Promise) | PrismaTransactionOptions, - options?: PrismaTransactionOptions + fnOrOptions?: + | ((prisma: PrismaTransactionClient) => Promise) + | PrismaTransactionOptions, + options?: PrismaTransactionOptions, ): Promise { if (typeof fnOrName === "string") { const fn = fnOrOptions as (prisma: PrismaTransactionClient) => Promise; @@ -55,7 +57,7 @@ export async function $transaction( name: error.name, }); }, - options + options, ); } else { return transac( @@ -70,7 +72,7 @@ export async function $transaction( name: error.name, }); }, - typeof fnOrOptions === "function" ? undefined : fnOrOptions + typeof fnOrOptions === "function" ? undefined : fnOrOptions, ); } } @@ -81,7 +83,7 @@ export const prisma = singleton("prisma", getClient); export const $replica: PrismaReplicaClient = singleton( "replica", - () => getReplicaClient() ?? prisma + () => getReplicaClient() ?? prisma, ); function getClient() { @@ -94,7 +96,9 @@ function getClient() { connection_timeout: env.DATABASE_CONNECTION_TIMEOUT.toString(), }); - console.log(`🔌 setting up prisma client to ${redactUrlSecrets(databaseUrl)}`); + console.log( + `🔌 setting up prisma client to ${redactUrlSecrets(databaseUrl)}`, + ); const client = new PrismaClient({ datasources: { @@ -122,7 +126,7 @@ function getClient() { { emit: "event", level: "query" }, { emit: "stdout", level: "query" }, ] - : [] + : [], ), }); @@ -146,7 +150,9 @@ function getReplicaClient() { connection_timeout: env.DATABASE_CONNECTION_TIMEOUT.toString(), }); - console.log(`🔌 setting up read replica connection to ${redactUrlSecrets(replicaUrl)}`); + console.log( + `🔌 setting up read replica connection to ${redactUrlSecrets(replicaUrl)}`, + ); const replicaClient = new PrismaClient({ datasources: { @@ -174,7 +180,7 @@ function getReplicaClient() { { emit: "event", level: "query" }, { emit: "stdout", level: "query" }, ] - : [] + : [], ), }); @@ -186,7 +192,10 @@ function getReplicaClient() { return replicaClient; } -function extendQueryParams(hrefOrUrl: string | URL, queryParams: Record) { +function extendQueryParams( + hrefOrUrl: string | URL, + queryParams: Record, +) { const url = new URL(hrefOrUrl); const query = url.searchParams; @@ -205,7 +214,7 @@ function redactUrlSecrets(hrefOrUrl: string | URL) { return url.href; } -export type { PrismaClient } from "@echo/database"; +export type { PrismaClient } from "@recall/database"; export const PrismaErrorSchema = z.object({ code: z.string(), @@ -220,7 +229,9 @@ function getDatabaseSchema() { const schemaFromSearchParam = databaseUrl.searchParams.get("schema"); if (!schemaFromSearchParam) { - console.debug("❗ database schema unspecified, will default to `public` schema"); + console.debug( + "❗ database schema unspecified, will default to `public` schema", + ); return "public"; } diff --git a/apps/webapp/app/models/user.server.ts b/apps/webapp/app/models/user.server.ts index 2da0727..5ab5f9a 100644 --- a/apps/webapp/app/models/user.server.ts +++ b/apps/webapp/app/models/user.server.ts @@ -1,7 +1,7 @@ -import type { Prisma, User } from "@echo/database"; +import type { Prisma, User } from "@recall/database"; import type { GoogleProfile } from "remix-auth-google"; import { prisma } from "~/db.server"; -export type { User } from "@echo/database"; +export type { User } from "@recall/database"; type FindOrCreateGoogle = { authenticationMethod: "GOOGLE"; @@ -17,7 +17,9 @@ type LoggedInUser = { isNewUser: boolean; }; -export async function findOrCreateUser(input: FindOrCreateUser): Promise { +export async function findOrCreateUser( + input: FindOrCreateUser, +): Promise { return findOrCreateGoogleUser(input); } @@ -137,11 +139,23 @@ export function updateUser({ }) { return prisma.user.update({ where: { id }, - data: { name, email, marketingEmails, referralSource, confirmedBasicDetails: true }, + data: { + name, + email, + marketingEmails, + referralSource, + confirmedBasicDetails: true, + }, }); } -export async function grantUserCloudAccess({ id, inviteCode }: { id: string; inviteCode: string }) { +export async function grantUserCloudAccess({ + id, + inviteCode, +}: { + id: string; + inviteCode: string; +}) { return prisma.user.update({ where: { id }, data: { diff --git a/apps/webapp/app/root.tsx b/apps/webapp/app/root.tsx index 8f8b713..0d14263 100644 --- a/apps/webapp/app/root.tsx +++ b/apps/webapp/app/root.tsx @@ -67,7 +67,7 @@ export const meta: MetaFunction = ({ data }) => { const typedData = data as UseDataFunctionReturn; return [ - { title: `Echo${typedData && appEnvTitleTag(typedData.appEnv)}` }, + { title: `Recall${typedData && appEnvTitleTag(typedData.appEnv)}` }, { name: "viewport", content: "width=1024, initial-scale=1", @@ -76,7 +76,7 @@ export const meta: MetaFunction = ({ data }) => { name: "robots", content: typeof window === "undefined" || - window.location.hostname !== "echo.mysigma.ai" + window.location.hostname !== "recall.mysigma.ai" ? "noindex, nofollow" : "index, follow", }, diff --git a/apps/webapp/app/utils/singleton.ts b/apps/webapp/app/utils/singleton.ts index 6aac987..9b28165 100644 --- a/apps/webapp/app/utils/singleton.ts +++ b/apps/webapp/app/utils/singleton.ts @@ -1,6 +1,6 @@ export function singleton(name: string, getValue: () => T): T { const thusly = globalThis as any; - thusly.__echo_singletons ??= {}; - thusly.__echo_singletons[name] ??= getValue(); - return thusly.__echo_singletons[name]; + thusly.__recall_singletons ??= {}; + thusly.__recall_singletons[name] ??= getValue(); + return thusly.__recall_singletons[name]; } diff --git a/apps/webapp/package.json b/apps/webapp/package.json index 5abd635..b5b2f22 100644 --- a/apps/webapp/package.json +++ b/apps/webapp/package.json @@ -11,7 +11,7 @@ "typecheck": "tsc" }, "dependencies": { - "@echo/database": "workspace:*", + "@recall/database": "workspace:*", "@opentelemetry/api": "1.9.0", "@radix-ui/react-slot": "^1.2.3", "@remix-run/express": "2.16.7", diff --git a/package.json b/package.json index a7b7974..1eedf2c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "echo", + "name": "recall", "private": true, "workspaces": [ "apps/*", "packages/*" ] diff --git a/packages/database/package.json b/packages/database/package.json index dfbbba3..af2516f 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -1,5 +1,5 @@ { - "name": "@echo/database", + "name": "@recall/database", "private": true, "version": "0.0.1", "main": "./dist/index.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52e597f..a0bacdd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,15 +30,15 @@ importers: apps/webapp: dependencies: - '@echo/database': - specifier: workspace:* - version: link:../../packages/database '@opentelemetry/api': specifier: 1.9.0 version: 1.9.0 '@radix-ui/react-slot': specifier: ^1.2.3 version: 1.2.3(@types/react@18.3.23)(react@18.3.1) + '@recall/database': + specifier: workspace:* + version: link:../../packages/database '@remix-run/express': specifier: 2.16.7 version: 2.16.7(express@4.21.2)(typescript@5.8.3)