From 2657bead8f030d2016f19a47248f84513736ceca Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 09:24:38 +0800 Subject: [PATCH 01/22] feat: implement libsql for db --- .gitignore | 1 + apps/web/package.json | 2 + apps/web/src/lib/db.ts | 10 +- packages/db/package.json | 4 +- packages/db/prisma/schema.prisma | 133 +++++++++--------- yarn.lock | 234 ++++++++++++++++++++++++++++--- 6 files changed, 297 insertions(+), 87 deletions(-) diff --git a/.gitignore b/.gitignore index 849425fe..f5337031 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ yarn-error.log* # turbo .turbo +.vercel diff --git a/apps/web/package.json b/apps/web/package.json index 21caf04f..3d8880dd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -16,7 +16,9 @@ "@as-integrations/next": "^2.0.2", "@hcaptcha/react-hcaptcha": "^1.4.4", "@headlessui/react": "^1.7.15", + "@libsql/client": "^0.6.0", "@next-auth/prisma-adapter": "^1.0.5", + "@prisma/adapter-libsql": "^5.12.1", "@tanstack/react-query": "^5.4.3", "@umamin/db": "*", "@umamin/generated": "*", diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index 7e1e25a2..7b553a37 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -1,7 +1,15 @@ import { PrismaClient } from '@umamin/db'; +import { createClient } from '@libsql/client'; +import { PrismaLibSQL } from '@prisma/adapter-libsql'; + +const libsql = createClient({ + url: `${process.env.TURSO_DATABASE_URL}`, + authToken: `${process.env.TURSO_AUTH_TOKEN}`, +}); const prismaClientSingleton = () => { - return new PrismaClient(); + const adapter = new PrismaLibSQL(libsql); + return new PrismaClient({ adapter }); }; type PrismaClientSingleton = ReturnType; diff --git a/packages/db/package.json b/packages/db/package.json index d8c7e834..93bdd91a 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -15,10 +15,10 @@ "author": "", "license": "ISC", "dependencies": { - "@prisma/client": "^5.4.2" + "@prisma/client": "^5.12.1" }, "devDependencies": { - "prisma": "^5.4.2", + "prisma": "^5.12.1", "typescript": "^4.7.4" } } diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 638b8574..af951cc3 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -2,91 +2,92 @@ // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] } datasource db { - provider = "mysql" - url = env("DATABASE_URL") - relationMode = "prisma" + provider = "sqlite" + url = "file:./dev.db" + relationMode = "prisma" } model Account { - id String @id @default(cuid()) - userId String - type String - provider String - providerAccountId String - refresh_token String? @db.Text - access_token String? @db.Text - expires_at Int? - token_type String? - scope String? - id_token String? @db.Text - session_state String? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@unique([provider, providerAccountId]) - @@index([userId]) + id String @id @default(cuid()) + userId String + type String + provider String + providerAccountId String + refresh_token String? + access_token String? + expires_at Int? + token_type String? + scope String? + id_token String? + session_state String? + + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@unique([provider, providerAccountId]) + @@index([userId]) } model User { - id String @id @default(cuid()) - name String? - createdAt DateTime @default(now()) - email String? @unique - emailVerified DateTime? - username String? @unique - password String? - image String? - message String @default("Send me an anonymous message!") @db.VarChar(100) - - accounts Account[] - sentMessages Message[] @relation("sentMessages") - sentGlobalMessages GlobalMessage[] @relation("sentGlobalMessages") - receivedMessages Message[] @relation("receivedMessages") - - @@index([email, username]) + id String @id @default(cuid()) + name String? + createdAt DateTime @default(now()) + email String? @unique + emailVerified DateTime? + username String? @unique + password String? + image String? + message String @default("Send me an anonymous message!") + + accounts Account[] + sentMessages Message[] @relation("sentMessages") + sentGlobalMessages GlobalMessage[] @relation("sentGlobalMessages") + receivedMessages Message[] @relation("receivedMessages") + + @@index([email, username]) } model VerificationToken { - identifier String - token String @unique - expires DateTime + identifier String + token String @unique + expires DateTime - @@unique([identifier, token]) + @@unique([identifier, token]) } model Message { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - content String @db.VarChar(255) - receiverMsg String @db.VarChar(255) - isOpened Boolean @default(false) - reply String? @db.VarChar(255) - clue String? @db.VarChar(255) - - senderId String? - sender User? @relation(name: "sentMessages", fields: [senderId], references: [id]) - receiverUsername String? - receiverId String - receiver User @relation(name: "receivedMessages", fields: [receiverId], references: [id], onDelete: Cascade) - - @@index([senderId, createdAt(sort: Desc)]) - @@index([receiverId, createdAt(sort: Desc)]) + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + content String + receiverMsg String + isOpened Boolean @default(false) + reply String? + clue String? + + senderId String? + sender User? @relation(name: "sentMessages", fields: [senderId], references: [id]) + receiverUsername String? + receiverId String + receiver User @relation(name: "receivedMessages", fields: [receiverId], references: [id], onDelete: Cascade) + + @@index([senderId, createdAt(sort: Desc)]) + @@index([receiverId, createdAt(sort: Desc)]) } model GlobalMessage { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - content String @db.VarChar(500) - isAnonymous Boolean @default(true) + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + content String + isAnonymous Boolean @default(true) - userId String? - user User? @relation(name: "sentGlobalMessages", fields: [userId], references: [id], onDelete: Cascade) + userId String? + user User? @relation(name: "sentGlobalMessages", fields: [userId], references: [id], onDelete: Cascade) - @@index([userId, updatedAt(sort: Desc)]) + @@index([userId, updatedAt(sort: Desc)]) } diff --git a/yarn.lock b/yarn.lock index 8d86a282..5470924f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2225,6 +2225,81 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@libsql/client@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@libsql/client/-/client-0.6.0.tgz#bbae2beba4e9c1a3d71ba2593e9e21d0858ae7d1" + integrity sha512-qhQzTG/y2IEVbL3+9PULDvlQFWJ/RnjFXECr/Nc3nRngGiiMysDaOV5VUzYk7DulUX98EA4wi+z3FspKrUplUA== + dependencies: + "@libsql/core" "^0.6.0" + "@libsql/hrana-client" "^0.6.0" + js-base64 "^3.7.5" + libsql "^0.3.10" + +"@libsql/core@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@libsql/core/-/core-0.6.0.tgz#8eb8468bf452efe73847d699a1a8238803eba9a1" + integrity sha512-affAB8vSqQwqI9NBDJ5uJCVaHoOAS2pOpbv1kWConh1SBbmJBnHHd4KG73RAJ2sgd2+NbT9WA+XJBqxgp28YSw== + dependencies: + js-base64 "^3.7.5" + +"@libsql/darwin-arm64@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/darwin-arm64/-/darwin-arm64-0.3.10.tgz#50834ec7c2d9a5d92dd42a46bc99c1c82a11ab7a" + integrity sha512-RaexEFfPAFogd6dJlqkpCkTxdr6K14Z0286lodIJ8Ny77mWuWyBkWKxf70OYWXXAMxMJFUW+6al1F3/Osf/pTg== + +"@libsql/darwin-x64@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/darwin-x64/-/darwin-x64-0.3.10.tgz#341d61b92e02c3c66ff14dc5b8a3c1a664f84512" + integrity sha512-SNVN6n4qNUdMW1fJMFmx4qn4n5RnXsxjFbczpkzG/V7m/5VeTFt1chhGcrahTHCr3+K6eRJWJUEQHRGqjBwPkw== + +"@libsql/hrana-client@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@libsql/hrana-client/-/hrana-client-0.6.0.tgz#051466f7e6c3d7402499de9af20a5deca6b82e9f" + integrity sha512-k+fqzdjqg3IvWfKmVJK5StsbjeTcyNAXFelUbXbGNz3yH1gEVT9mZ6kmhsIXP30ZSyVV0AE1Gi25p82mxC9hwg== + dependencies: + "@libsql/isomorphic-fetch" "^0.2.1" + "@libsql/isomorphic-ws" "^0.1.5" + js-base64 "^3.7.5" + node-fetch "^3.3.2" + +"@libsql/isomorphic-fetch@^0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@libsql/isomorphic-fetch/-/isomorphic-fetch-0.2.1.tgz#8dc17476cd1625efb0c0bd613857fd319b7e11b5" + integrity sha512-Sv07QP1Aw8A5OOrmKgRUBKe2fFhF2hpGJhtHe3d1aRnTESZCGkn//0zDycMKTGamVWb3oLYRroOsCV8Ukes9GA== + +"@libsql/isomorphic-ws@^0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz#e2d1faf965ba0f3be9301fbf5640164d03c4e606" + integrity sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg== + dependencies: + "@types/ws" "^8.5.4" + ws "^8.13.0" + +"@libsql/linux-arm64-gnu@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.3.10.tgz#695a94bdca68722c3303c181a62f5193acc7af31" + integrity sha512-2uXpi9d8qtyIOr7pyG4a88j6YXgemyIHEs2Wbp+PPletlCIPsFS+E7IQHbz8VwTohchOzcokGUm1Bc5QC+A7wg== + +"@libsql/linux-arm64-musl@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.3.10.tgz#4ae8badda2869974589198bc2bd3cba1cc6cc27c" + integrity sha512-72SN1FUavLvzHddCS861ynSpQndcW5oLGKA3U8CyMfgIZIwJAPc7+48Uj1plW00htXBx4GBpcntFp68KKIx3YQ== + +"@libsql/linux-x64-gnu@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.3.10.tgz#a0c7852087e2b0ac6bedda3d1c9d7d5f864c3ef6" + integrity sha512-hXyNqVRi7ONuyWZ1SX6setxL0QaQ7InyS3bHLupsi9s7NpOGD5vcpTaYicJOqmIIm+6kt8vJfmo7ZxlarIHy7Q== + +"@libsql/linux-x64-musl@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/linux-x64-musl/-/linux-x64-musl-0.3.10.tgz#fc46c27b94fff0a565f28cb7bbd8ca7a77e55364" + integrity sha512-kNmIRxomVwt9S+cLyYS497F/3gXFF4r8wW12YSBQgxG75JYft07AHVd8J7HINg+oqRkLzT0s+mVX5dM6nk68EQ== + +"@libsql/win32-x64-msvc@0.3.10": + version "0.3.10" + resolved "https://registry.yarnpkg.com/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.3.10.tgz#32805c76c63f5ae3a1628f986bd56bcac1566aec" + integrity sha512-c/6rjdtGULKrJkLgfLobFefObfOtxjXGmCfPxv6pr0epPCeUEssfDbDIeEH9fQUgzogIMWEHwT8so52UJ/iT1Q== + "@mapbox/node-pre-gyp@^1.0.10": version "1.0.10" resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz#8e6735ccebbb1581e5a7e652244cadc8a844d03c" @@ -2240,6 +2315,11 @@ semver "^7.3.5" tar "^6.1.11" +"@neon-rs/load@^0.0.4": + version "0.0.4" + resolved "https://registry.yarnpkg.com/@neon-rs/load/-/load-0.0.4.tgz#2a2a3292c6f1fef043f49886712d3c96a547532e" + integrity sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw== + "@next-auth/prisma-adapter@^1.0.5": version "1.0.5" resolved "https://registry.yarnpkg.com/@next-auth/prisma-adapter/-/prisma-adapter-1.0.5.tgz#41a2fc7b44907054b81d456b426164e58becf4ed" @@ -2426,22 +2506,61 @@ tslib "^2.4.0" webcrypto-core "^1.7.4" -"@prisma/client@^5.4.2": - version "5.4.2" - resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.4.2.tgz#786f9c1d8f06d955933004ac638d14da4bf14025" - integrity sha512-2xsPaz4EaMKj1WS9iW6MlPhmbqtBsXAOeVttSePp8vTFTtvzh2hZbDgswwBdSCgPzmmwF+tLB259QzggvCmJqA== +"@prisma/adapter-libsql@^5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/adapter-libsql/-/adapter-libsql-5.12.1.tgz#f359898cb5c1160fa56c4e630172d98910015f8d" + integrity sha512-tbXcgzS/xS8fD8gI1g6DJ483viNx4oWyk4vB2Ls9YYEyrZR25cSRCzFhNf5Tpg4+1C4WtHj9XoE9ZHk5km0dTg== + dependencies: + "@prisma/driver-adapter-utils" "5.12.1" + async-mutex "0.5.0" + +"@prisma/client@^5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.12.1.tgz#c26a674fea76754b3a9e8b90a11e617f90212f76" + integrity sha512-6/JnizEdlSBxDIdiLbrBdMW5NqDxOmhXAJaNXiPpgzAPr/nLZResT6MMpbOHLo5yAbQ1Vv5UU8PTPRzb0WIxdA== + +"@prisma/debug@5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.12.1.tgz#007c8ad2e466d565bcd0671b8846c27f8700c722" + integrity sha512-kd/wNsR0klrv79o1ITsbWxYyh4QWuBidvxsXSParPsYSu0ircUmNk3q4ojsgNc3/81b0ozg76iastOG43tbf8A== + +"@prisma/driver-adapter-utils@5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/driver-adapter-utils/-/driver-adapter-utils-5.12.1.tgz#2d6b26883d95feec3b7e5b7695bdbcc6a96041bd" + integrity sha512-s5EHANHIyWID/3WLNYn3wy1SUGC2OFH2thYriq+sKo4GZxEduX9oraOVlPruZZBt/roN9ojZcph4R2oecWzfXg== + dependencies: + "@prisma/debug" "5.12.1" + +"@prisma/engines-version@5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab": + version "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab.tgz#c78d099a3fe86d446db7442e64e56987e39e7f32" + integrity sha512-6yvO8s80Tym61aB4QNtYZfWVmE3pwqe807jEtzm8C5VDe7nw8O1FGX3TXUaXmWV0fQTIAfRbeL2Gwrndabp/0g== + +"@prisma/engines@5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.12.1.tgz#a50649427d627a9af962a188a84c65d61c6e2b3f" + integrity sha512-HQDdglLw2bZR/TXD2Y+YfDMvi5Q8H+acbswqOsWyq9pPjBLYJ6gzM+ptlTU/AV6tl0XSZLU1/7F4qaWa8bqpJA== dependencies: - "@prisma/engines-version" "5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574" + "@prisma/debug" "5.12.1" + "@prisma/engines-version" "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + "@prisma/fetch-engine" "5.12.1" + "@prisma/get-platform" "5.12.1" -"@prisma/engines-version@5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574": - version "5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574" - resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574.tgz#ff14f2926890edee47e8f1d08df7b4f392ee34bf" - integrity sha512-wvupDL4AA1vf4TQNANg7kR7y98ITqPsk6aacfBxZKtrJKRIsWjURHkZCGcQliHdqCiW/hGreO6d6ZuSv9MhdAA== +"@prisma/fetch-engine@5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.12.1.tgz#c38e9fa17fdc535b4c83cbb7645569ad0a511fa9" + integrity sha512-qSs3KcX1HKcea1A+hlJVK/ljj0PNIUHDxAayGMvgJBqmaN32P9tCidlKz1EGv6WoRFICYnk3Dd/YFLBwnFIozA== + dependencies: + "@prisma/debug" "5.12.1" + "@prisma/engines-version" "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab" + "@prisma/get-platform" "5.12.1" -"@prisma/engines@5.4.2": - version "5.4.2" - resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.4.2.tgz#ba2b7faeb227c76e423e88f962afe6a031319f3f" - integrity sha512-fqeucJ3LH0e1eyFdT0zRx+oETLancu5+n4lhiYECyEz6H2RDskPJHJYHkVc0LhkU4Uv7fuEnppKU3nVKNzMh8g== +"@prisma/get-platform@5.12.1": + version "5.12.1" + resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.12.1.tgz#33f427f6d744dee62a9e06858889691d78b50804" + integrity sha512-pgIR+pSvhYHiUcqXVEZS31NrFOTENC9yFUdEAcx7cdQBoZPmHVjtjN4Ss6NzVDMYPrKJJ51U14EhEoeuBlMioQ== + dependencies: + "@prisma/debug" "5.12.1" "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": version "1.1.2" @@ -2937,6 +3056,13 @@ dependencies: "@types/node" "*" +"@types/ws@^8.5.4": + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== + dependencies: + "@types/node" "*" + "@typescript-eslint/parser@^5.21.0", "@typescript-eslint/parser@^5.30.5": version "5.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.31.0.tgz#7f42d7dcc68a0a6d80a0f3d9a65063aee7bb8d2c" @@ -3277,6 +3403,13 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== +async-mutex@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.5.0.tgz#353c69a0b9e75250971a64ac203b0ebfddd75482" + integrity sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA== + dependencies: + tslib "^2.4.0" + async-retry@^1.2.1: version "1.3.3" resolved "https://registry.yarnpkg.com/async-retry/-/async-retry-1.3.3.tgz#0e7f36c04d8478e7a58bdbed80cedf977785f280" @@ -4024,6 +4157,11 @@ damerau-levenshtein@^1.0.7, damerau-levenshtein@^1.0.8: resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7" integrity sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA== +data-uri-to-buffer@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e" + integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== + dataloader@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/dataloader/-/dataloader-2.2.2.tgz#216dc509b5abe39d43a9b9d97e6e5e473dfbe3e0" @@ -4162,6 +4300,11 @@ detect-indent@^6.0.0: resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.1.0.tgz#592485ebbbf6b3b1ab2be175c8393d04ca0d57e6" integrity sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA== +detect-libc@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.2.tgz#8ccf2ba9315350e1241b88d0ac3b0e1fbd99605d" + integrity sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw== + detect-libc@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" @@ -4816,6 +4959,14 @@ fbjs@^3.0.0: setimmediate "^1.0.5" ua-parser-js "^0.7.30" +fetch-blob@^3.1.2, fetch-blob@^3.1.4: + version "3.2.0" + resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9" + integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ== + dependencies: + node-domexception "^1.0.0" + web-streams-polyfill "^3.0.3" + fflate@^0.7.3: version "0.7.4" resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.7.4.tgz#61587e5d958fdabb5a9368a302c25363f4f69f50" @@ -4941,6 +5092,13 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +formdata-polyfill@^4.0.10: + version "4.0.10" + resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" + integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== + dependencies: + fetch-blob "^3.1.2" + forwarded@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" @@ -5754,6 +5912,11 @@ jose@^4.9.3: resolved "https://registry.yarnpkg.com/jose/-/jose-4.11.2.tgz#d9699307c02e18ff56825843ba90e2fae9f09e23" integrity sha512-njj0VL2TsIxCtgzhO+9RRobBvws4oYyCM8TpvoUQwl/MbIM3NFJRR9+e6x0sS5xXaP1t6OCBkaBME98OV9zU5A== +js-base64@^3.7.5: + version "3.7.7" + resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79" + integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -5900,6 +6063,22 @@ libphonenumber-js@^1.10.14: resolved "https://registry.yarnpkg.com/libphonenumber-js/-/libphonenumber-js-1.10.37.tgz#185264130c9375f17d0c487a288223294579929c" integrity sha512-Z10PCaOCiAxbUxLyR31DNeeNugSVP6iv/m7UrSKS5JHziEMApJtgku4e9Q69pzzSC9LnQiM09sqsGf2ticZnMw== +libsql@^0.3.10: + version "0.3.10" + resolved "https://registry.yarnpkg.com/libsql/-/libsql-0.3.10.tgz#e4eebc7da5cfbbddcac15248df7442e13ff07942" + integrity sha512-/8YMTbwWFPmrDWY+YFK3kYqVPFkMgQre0DGmBaOmjogMdSe+7GHm1/q9AZ61AWkEub/vHmi+bA4tqIzVhKnqzg== + dependencies: + "@neon-rs/load" "^0.0.4" + detect-libc "2.0.2" + optionalDependencies: + "@libsql/darwin-arm64" "0.3.10" + "@libsql/darwin-x64" "0.3.10" + "@libsql/linux-arm64-gnu" "0.3.10" + "@libsql/linux-arm64-musl" "0.3.10" + "@libsql/linux-x64-gnu" "0.3.10" + "@libsql/linux-x64-musl" "0.3.10" + "@libsql/win32-x64-msvc" "0.3.10" + lie@~3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a" @@ -6768,6 +6947,11 @@ node-addon-api@^7.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.0.0.tgz#8136add2f510997b3b94814f4af1cce0b0e3962e" integrity sha512-vgbBJTS4m5/KkE16t5Ly0WW9hz46swAstv0hYYwMtbG7AznRhNyfLRe8HZAiWIpcHzoO7HxhLuBQj9rJ/Ho0ZA== +node-domexception@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" + integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== + node-fetch@2.6.7, node-fetch@^2.6.1, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" @@ -6775,6 +6959,15 @@ node-fetch@2.6.7, node-fetch@^2.6.1, node-fetch@^2.6.7: dependencies: whatwg-url "^5.0.0" +node-fetch@^3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b" + integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA== + dependencies: + data-uri-to-buffer "^4.0.0" + fetch-blob "^3.1.4" + formdata-polyfill "^4.0.10" + node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -7301,12 +7494,12 @@ pretty-format@^3.8.0: resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-3.8.0.tgz#bfbed56d5e9a776645f4b1ff7aa1a3ac4fa3c385" integrity sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew== -prisma@^5.4.2: - version "5.4.2" - resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.4.2.tgz#7eac9276439ec7073ec697c6c0dfa259d96e955e" - integrity sha512-GDMZwZy7mysB2oXU+angQqJ90iaPFdD0rHaZNkn+dio5NRkGLmMqmXs31//tg/qXT3iB0cTQwnGGQNuirhSTZg== +prisma@^5.12.1: + version "5.12.1" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.12.1.tgz#db4596253bb066afc9f08744642f200a398d8d51" + integrity sha512-SkMnb6wyIxTv9ACqiHBI2u9gD6y98qXRoCoLEnZsF6yee5Qg828G+ARrESN+lQHdw4maSZFFSBPPDpvSiVTo0Q== dependencies: - "@prisma/engines" "5.4.2" + "@prisma/engines" "5.12.1" process-nextick-args@~2.0.0: version "2.0.1" @@ -8976,6 +9169,11 @@ wcwidth@^1.0.1: dependencies: defaults "^1.0.3" +web-streams-polyfill@^3.0.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b" + integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw== + web-streams-polyfill@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" From 139c4f2015d05e76ba2b03649285a21e61021fd6 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 09:26:33 +0800 Subject: [PATCH 02/22] chore: add turso db env to ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58a0c7be..588e8782 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,4 +31,6 @@ jobs: run: yarn lint - name: Build project + env: + TURSO_DATABASE_URL: ${{ secrets.TURSO_DATABASE_URL }} run: yarn build From 78950426816ed31069bb8ef4a3901fdaab03579b Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 14:35:08 +0800 Subject: [PATCH 03/22] chore: minor changes --- apps/web/src/pages/_app.tsx | 4 ++++ apps/web/src/pages/api/graphql.ts | 2 +- packages/db/.gitignore | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/src/pages/_app.tsx b/apps/web/src/pages/_app.tsx index dbbf1df0..398b72c6 100644 --- a/apps/web/src/pages/_app.tsx +++ b/apps/web/src/pages/_app.tsx @@ -53,8 +53,10 @@ function MyApp({ queryCache: new QueryCache({ onError: (err: any) => { if (err.response?.errors?.length) { + console.log(err); toast.error(err.response.errors[0].message); } else { + console.log(err); toast.error(err.message); } }, @@ -63,8 +65,10 @@ function MyApp({ mutationCache: new MutationCache({ onError: (err: any) => { if (err.response?.errors?.length) { + console.log(err); toast.error(err.response.errors[0].message); } else { + console.log(err); toast.error(err.message); } }, diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 6be364d6..0ad2bb17 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -37,7 +37,7 @@ const _handler = startServerAndCreateNextHandler(server, { export default function handler(req: NextApiRequest, res: NextApiResponse) { res.setHeader( 'Access-Control-Allow-Origin', - process.env.NEXT_PUBLIC_GQL_ENDPOINT as string + process.env.NEXT_PUBLIC_GQL_ENDPOINT ?? 'http://localhost:3000' ); res.setHeader('Content-Type', 'application/json'); res.setHeader('Cache-Control', 's-maxage=86400'); diff --git a/packages/db/.gitignore b/packages/db/.gitignore index 8f9e781f..22fb428b 100644 --- a/packages/db/.gitignore +++ b/packages/db/.gitignore @@ -1,5 +1,6 @@ dist/ .turbo/ node_modules/ +prisma/dev.* .env From eab2f12bddd8f004bef6447b7a8852366cafbb67 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 22:42:51 +0800 Subject: [PATCH 04/22] chore: update global prisma --- apps/web/src/lib/db.ts | 19 ++++++++++--------- .../global-message.resolvers.ts | 6 +++--- .../src/schema/message/message.resolvers.ts | 8 ++++---- apps/web/src/schema/user/user.resolvers.ts | 12 ++++++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index 7b553a37..c5554430 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -1,10 +1,12 @@ + /* eslint-disable */ + import { PrismaClient } from '@umamin/db'; -import { createClient } from '@libsql/client'; import { PrismaLibSQL } from '@prisma/adapter-libsql'; +import { createClient } from '@libsql/client'; const libsql = createClient({ - url: `${process.env.TURSO_DATABASE_URL}`, - authToken: `${process.env.TURSO_AUTH_TOKEN}`, + url: process.env.TURSO_DATABASE_URL!, + authToken: process.env.TURSO_AUTH_TOKEN, }); const prismaClientSingleton = () => { @@ -12,14 +14,13 @@ const prismaClientSingleton = () => { return new PrismaClient({ adapter }); }; -type PrismaClientSingleton = ReturnType; -const globalForPrisma = globalThis as unknown as { - prisma: PrismaClientSingleton | undefined; -}; +declare global { + var prismaGlobal: undefined | ReturnType; +} -const prisma = globalForPrisma.prisma ?? prismaClientSingleton(); +const prisma = globalThis.prismaGlobal ?? prismaClientSingleton(); export default prisma; -if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma; +if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma; diff --git a/apps/web/src/schema/global-message/global-message.resolvers.ts b/apps/web/src/schema/global-message/global-message.resolvers.ts index 108d990c..b38830f5 100644 --- a/apps/web/src/schema/global-message/global-message.resolvers.ts +++ b/apps/web/src/schema/global-message/global-message.resolvers.ts @@ -57,7 +57,7 @@ export class GlobalMessageResolver { cursorId: messages[messages.length - 1].id, }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -87,7 +87,7 @@ export class GlobalMessageResolver { } } } catch (err) { - console.error(err); + console.log(err); throw err; } @@ -133,7 +133,7 @@ export class GlobalMessageResolver { return { data: message }; } catch (err) { - console.error(err); + console.log(err); throw err; } } diff --git a/apps/web/src/schema/message/message.resolvers.ts b/apps/web/src/schema/message/message.resolvers.ts index 5e848dd3..9b6998a0 100644 --- a/apps/web/src/schema/message/message.resolvers.ts +++ b/apps/web/src/schema/message/message.resolvers.ts @@ -56,7 +56,7 @@ export class MessageResolver { cursorId: messages[messages.length - 1].id, }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -81,7 +81,7 @@ export class MessageResolver { return message.content; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -94,7 +94,7 @@ export class MessageResolver { try { await prisma.message.delete({ where: { id } }); } catch (err) { - console.error(err); + console.log(err); throw err; } @@ -113,7 +113,7 @@ export class MessageResolver { data: { reply: content }, }); } catch (err) { - console.error(err); + console.log(err); throw err; } diff --git a/apps/web/src/schema/user/user.resolvers.ts b/apps/web/src/schema/user/user.resolvers.ts index f868ac4e..f2166913 100644 --- a/apps/web/src/schema/user/user.resolvers.ts +++ b/apps/web/src/schema/user/user.resolvers.ts @@ -26,7 +26,7 @@ export class UserResolver { return data; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -62,7 +62,7 @@ export class UserResolver { return { error: null }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -80,7 +80,7 @@ export class UserResolver { return { error: null }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -110,7 +110,7 @@ export class UserResolver { return { error: null }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -136,7 +136,7 @@ export class UserResolver { return { error: null }; } catch (err) { - console.error(err); + console.log(err); throw err; } } @@ -150,7 +150,7 @@ export class UserResolver { return { error: null }; } catch (err) { - console.error(err); + console.log(err); throw err; } } From f005ae028d4c524da4d2dd801fb46b6d51d8fdb1 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 22:47:57 +0800 Subject: [PATCH 05/22] chore: initialize migration --- .../20240407070104_init/migration.sql | 90 +++++++++++++++++++ .../db/prisma/migrations/migration_lock.toml | 3 + 2 files changed, 93 insertions(+) create mode 100644 packages/db/prisma/migrations/20240407070104_init/migration.sql create mode 100644 packages/db/prisma/migrations/migration_lock.toml diff --git a/packages/db/prisma/migrations/20240407070104_init/migration.sql b/packages/db/prisma/migrations/20240407070104_init/migration.sql new file mode 100644 index 00000000..dbca6d49 --- /dev/null +++ b/packages/db/prisma/migrations/20240407070104_init/migration.sql @@ -0,0 +1,90 @@ +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "email" TEXT, + "emailVerified" DATETIME, + "username" TEXT, + "password" TEXT, + "image" TEXT, + "message" TEXT NOT NULL DEFAULT 'Send me an anonymous message!' +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Message" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "content" TEXT NOT NULL, + "receiverMsg" TEXT NOT NULL, + "isOpened" BOOLEAN NOT NULL DEFAULT false, + "reply" TEXT, + "clue" TEXT, + "senderId" TEXT, + "receiverUsername" TEXT, + "receiverId" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "GlobalMessage" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "content" TEXT NOT NULL, + "isAnonymous" BOOLEAN NOT NULL DEFAULT true, + "userId" TEXT +); + +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +-- CreateIndex +CREATE INDEX "User_email_username_idx" ON "User"("email", "username"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- CreateIndex +CREATE INDEX "Message_senderId_createdAt_idx" ON "Message"("senderId", "createdAt" DESC); + +-- CreateIndex +CREATE INDEX "Message_receiverId_createdAt_idx" ON "Message"("receiverId", "createdAt" DESC); + +-- CreateIndex +CREATE INDEX "GlobalMessage_userId_updatedAt_idx" ON "GlobalMessage"("userId", "updatedAt" DESC); diff --git a/packages/db/prisma/migrations/migration_lock.toml b/packages/db/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..e5e5c470 --- /dev/null +++ b/packages/db/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file From d60624cc7a9d4821c48782abc05d9056890742d4 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 22:50:10 +0800 Subject: [PATCH 06/22] chore(temp): enable console logs --- apps/web/next.config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 339eba75..a8b6188c 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -11,9 +11,9 @@ const withPWA = require('next-pwa')({ module.exports = withPWA({ reactStrictMode: true, - compiler: { - removeConsole: process.env.NODE_ENV === 'production', - }, + // compiler: { + // removeConsole: process.env.NODE_ENV === 'production', + // }, transpilePackages: ['@umamin/db', '@umamin/generated'], modularizeImports: { 'date-fns': { From d0afb091defab2cf8f8da1c58e360fa873418ee6 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 23:18:22 +0800 Subject: [PATCH 07/22] chore: allow methods in cors --- apps/web/src/pages/api/graphql.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 0ad2bb17..8a4e132e 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -37,8 +37,9 @@ const _handler = startServerAndCreateNextHandler(server, { export default function handler(req: NextApiRequest, res: NextApiResponse) { res.setHeader( 'Access-Control-Allow-Origin', - process.env.NEXT_PUBLIC_GQL_ENDPOINT ?? 'http://localhost:3000' + process.env.NEXT_PUBLIC_GQL_ENDPOINT ?? 'http://localhost:3000' ); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); res.setHeader('Content-Type', 'application/json'); res.setHeader('Cache-Control', 's-maxage=86400'); From c84ad9945be6465f6a0671a5ec925b9429fbe536 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 23:27:32 +0800 Subject: [PATCH 08/22] chore: update origin in cors" --- apps/web/src/pages/api/graphql.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 8a4e132e..47cfd814 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -37,7 +37,7 @@ const _handler = startServerAndCreateNextHandler(server, { export default function handler(req: NextApiRequest, res: NextApiResponse) { res.setHeader( 'Access-Control-Allow-Origin', - process.env.NEXT_PUBLIC_GQL_ENDPOINT ?? 'http://localhost:3000' + process.env.NEXTAUTH_URL ?? 'http://localhost:3000' ); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); res.setHeader('Content-Type', 'application/json'); From ba68a893288b8fdd1fd61498bea40f7abaad1f78 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Sun, 7 Apr 2024 23:34:52 +0800 Subject: [PATCH 09/22] chore(temp): remove cors --- apps/web/src/pages/api/graphql.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 47cfd814..8d09e666 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -35,12 +35,12 @@ const _handler = startServerAndCreateNextHandler(server, { }); export default function handler(req: NextApiRequest, res: NextApiResponse) { - res.setHeader( - 'Access-Control-Allow-Origin', - process.env.NEXTAUTH_URL ?? 'http://localhost:3000' - ); - res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); - res.setHeader('Content-Type', 'application/json'); + // res.setHeader( + // 'Access-Control-Allow-Origin', + // process.env.NEXTAUTH_URL ?? 'http://localhost:3000' + // ); + // res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + // res.setHeader('Content-Type', 'application/json'); res.setHeader('Cache-Control', 's-maxage=86400'); return _handler(req, res); From bfbd20727905d6517a3cbbe2557d309db31d6608 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 00:02:09 +0800 Subject: [PATCH 10/22] chore: update libsql client import --- apps/web/src/lib/db.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index c5554430..058fb19e 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -1,8 +1,8 @@ - /* eslint-disable */ +/* eslint-disable */ import { PrismaClient } from '@umamin/db'; import { PrismaLibSQL } from '@prisma/adapter-libsql'; -import { createClient } from '@libsql/client'; +import { createClient } from '@libsql/client/web'; const libsql = createClient({ url: process.env.TURSO_DATABASE_URL!, @@ -11,10 +11,10 @@ const libsql = createClient({ const prismaClientSingleton = () => { const adapter = new PrismaLibSQL(libsql); - return new PrismaClient({ adapter }); + const prisma = new PrismaClient({ adapter }); + return prisma; }; - declare global { var prismaGlobal: undefined | ReturnType; } From a138ca58f9862fa06524143948ba7b5df53380da Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 08:35:40 +0800 Subject: [PATCH 11/22] chore: instantiate prisma in the server --- apps/web/src/lib/db.ts | 4 ++-- apps/web/src/pages/api/graphql.ts | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index 058fb19e..165b873a 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -2,10 +2,10 @@ import { PrismaClient } from '@umamin/db'; import { PrismaLibSQL } from '@prisma/adapter-libsql'; -import { createClient } from '@libsql/client/web'; +import { createClient } from '@libsql/client'; const libsql = createClient({ - url: process.env.TURSO_DATABASE_URL!, + url: `${process.env.TURSO_DATABASE_URL}`, authToken: process.env.TURSO_AUTH_TOKEN, }); diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 8d09e666..0f120764 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -6,7 +6,10 @@ import { ApolloServer } from '@apollo/server'; import { getSession } from 'next-auth/react'; import { buildSchema } from 'type-graphql'; -import prisma from '@/lib/db'; +import { PrismaClient } from '@umamin/db'; +import { createClient } from '@libsql/client'; +import { PrismaLibSQL } from '@prisma/adapter-libsql'; + import { UserResolver } from '@/schema/user'; import { MessageResolver } from '@/schema/message'; import { GlobalMessageResolver } from '@/schema/global-message'; @@ -26,6 +29,14 @@ const server = new ApolloServer({ plugins: [responseCachePlugin()], }); +const libsql = createClient({ + url: `${process.env.TURSO_DATABASE_URL}`, + authToken: process.env.TURSO_AUTH_TOKEN, +}); + +const adapter = new PrismaLibSQL(libsql); +const prisma = new PrismaClient({ adapter }); + const _handler = startServerAndCreateNextHandler(server, { context: async (req) => { const session = await getSession({ req }); @@ -35,12 +46,12 @@ const _handler = startServerAndCreateNextHandler(server, { }); export default function handler(req: NextApiRequest, res: NextApiResponse) { - // res.setHeader( - // 'Access-Control-Allow-Origin', - // process.env.NEXTAUTH_URL ?? 'http://localhost:3000' - // ); - // res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); - // res.setHeader('Content-Type', 'application/json'); + res.setHeader( + 'Access-Control-Allow-Origin', + process.env.NEXTAUTH_URL ?? 'http://localhost:3000' + ); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + res.setHeader('Content-Type', 'application/json'); res.setHeader('Cache-Control', 's-maxage=86400'); return _handler(req, res); From 56dbdec74faeeb88defc6a3b286dcd1adb44d5d9 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 08:51:24 +0800 Subject: [PATCH 12/22] refactor(temp): move prisma to apps/web --- apps/web/package.json | 6 +- apps/web/prisma/dev.db | Bin 0 -> 90112 bytes apps/web/prisma/dev.db-journal | Bin 0 -> 8720 bytes .../20240407070104_init/migration.sql | 90 +++++++++++++++++ .../web/prisma/migrations/migration_lock.toml | 3 + apps/web/prisma/schema.prisma | 93 ++++++++++++++++++ apps/web/prisma/seed.js | 41 ++++++++ apps/web/src/lib/db.ts | 4 +- apps/web/src/pages/api/graphql.ts | 13 +-- packages/db/package.json | 3 - 10 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 apps/web/prisma/dev.db create mode 100644 apps/web/prisma/dev.db-journal create mode 100644 apps/web/prisma/migrations/20240407070104_init/migration.sql create mode 100644 apps/web/prisma/migrations/migration_lock.toml create mode 100644 apps/web/prisma/schema.prisma create mode 100644 apps/web/prisma/seed.js diff --git a/apps/web/package.json b/apps/web/package.json index 3d8880dd..fd3d85bd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -8,7 +8,8 @@ "start": "next start", "lint": "next lint", "clean": "rimraf .next/ .turbo/ node_modules/", - "clean:cache": "rimraf .next/ .turbo/" + "clean:cache": "rimraf .next/ .turbo/", + "postinstall": "prisma generate" }, "dependencies": { "@apollo/server": "^4.9.4", @@ -19,8 +20,8 @@ "@libsql/client": "^0.6.0", "@next-auth/prisma-adapter": "^1.0.5", "@prisma/adapter-libsql": "^5.12.1", + "@prisma/client": "^5.12.1", "@tanstack/react-query": "^5.4.3", - "@umamin/db": "*", "@umamin/generated": "*", "@vercel/og": "^0.5.20", "bcrypt": "^5.1.0", @@ -76,6 +77,7 @@ "postcss": "^8.4.14", "prettier": "^2.7.1", "prettier-plugin-tailwindcss": "^0.1.11", + "prisma": "^5.12.1", "tailwindcss": "^3.1.4", "typescript": "4.7.4" } diff --git a/apps/web/prisma/dev.db b/apps/web/prisma/dev.db new file mode 100644 index 0000000000000000000000000000000000000000..4eea6b724bd8f3927887b7e0bd3a28da4738333c GIT binary patch literal 90112 zcmeI&U2ogg8NhKdwxvXgV>hiUU>-0|DBuc>6G@h18^eIAjuvRM<;IrUX4pW`5|t3q z+eoTQFbsv#u9y1?19sE|_-&XIe=-2*xtt>)$ zjRi(O-AZL1?_0Fkb+xk;O8`_3dZE3?nOLvS`+0o2aIO5IY^Gdm1 zQLD9wm56)F8Pl#*=-KUZrU?`p|H-&mZ` z;&W!x38EGzbMHQa;HhVq~$y2U+lb7333`ldreH3bK?ogYIr?SC2+eh&jhnKD zdilMR%IsvPzMWRZOI#dTwO;wCuGY@PcjM$legC|AT0VcG{-*Net{*d=NyN+}X4!i6 zv@!{QSou}CaZ*>08|UYhT3vIGUewE{@5_^?XVTe|gYx@5N6Zd0iO7SdUGDXJFT4Gr zomJmEJ3FbAYxA``*3bwl^rZd5(z&CX$;|1FlJGji{zFGR259=w>3iE+$V)4PHgA3U zlk2I>_O|l*O%Ga5q4LL#Fm5nu$A&eyx18Efm${z}jGiHe$5QmR-mwF9%NTTC`XvRu z+8G+59pn3lH{fJckVivKK%p~&gVotVn$GRsNM_30%lcJzhgOhp(xZDRG3VV^Uip1F zcbk~oaXs9>bH}rjo(^toiyi$bK75VIwi_=7re%m>J$F^5bFXS^sm#`v^4TZe;B$H0 z?_@YFch^)VGZ`$nl)W3kwEqvfw*7f|x;Sr-kL3=XpkY&&=3E8?-M0VOw`3Q~NV6-R z`$A)(>pu(5HZhofb}qzokJ>d@W95>Vl!DWNtvqW;-tjven}$P96#FGc)a zKY@jG^=4C0EjS>@sHThQxmv4N9#zhRT)oG*Nyc)w-RuW#kbBJ5f^uz9op?CZY)3pb z`>BYFdiA?5YS}ogAm6Ng`dcNHDHN2?HLs_{{ok~^y4E$HTHceVJ-_E#xc}w@LS5jXnIonUoXGZh6J?v(~=Y?*u(xq+oO#7M9@@yyJGuO#XSrx6mMJ++?vd^6&l4p=F6#P;*Ri!8v+& zAgj{{gN`W*vK?b!Yu?kEo1Yv+TYBU3@DWgM|3vg#ZEwAbQ3fB*srAb6+eEuKD zUL$7&5I_I{1Q0*~0R#|0009J|3Gn%UG%unNKmY**5I_I{1Q0*~0R#|;qX3`($FbMQ z836y|1^E0wj=e_C2q1s} z0tg_000IagfB*srL=#~BAI*zs1Q0*~0R#|0009ILKmY**;wZrSKaRad&IllY00Iag zfB*srAbI009ILKmY**5I_I{1mY;b`ah1nM$QNzfB*srAbi)aK8KmY**5I_I{1Q0*~0R-YG!1_Oqy++OmAbTYy~sk6$?VKr!A30X9z3${4%k?Uy}fuHZ)D>o96W=C;GayH zgybv7ImDL>{LCvrvpBi>5D1Rwwb2tWV=5P$##AOHafyj9>lZGN}sx%19VW_{8` zTtaJ|#a5-HwinhmWfSwFLV4^wjpl<-Svl4^iZ%``Av1SmA(cWY)Gq0@%R?+?y^KR4 z_PcBpl8`7V#hOg|zd!7c&Gq)TSzXrmx`ccE1Gwc|kHjztKmY;|fB*y_009U<00Izz M00cfvV9U416N%?23;+NC literal 0 HcmV?d00001 diff --git a/apps/web/prisma/migrations/20240407070104_init/migration.sql b/apps/web/prisma/migrations/20240407070104_init/migration.sql new file mode 100644 index 00000000..dbca6d49 --- /dev/null +++ b/apps/web/prisma/migrations/20240407070104_init/migration.sql @@ -0,0 +1,90 @@ +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "email" TEXT, + "emailVerified" DATETIME, + "username" TEXT, + "password" TEXT, + "image" TEXT, + "message" TEXT NOT NULL DEFAULT 'Send me an anonymous message!' +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Message" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "content" TEXT NOT NULL, + "receiverMsg" TEXT NOT NULL, + "isOpened" BOOLEAN NOT NULL DEFAULT false, + "reply" TEXT, + "clue" TEXT, + "senderId" TEXT, + "receiverUsername" TEXT, + "receiverId" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "GlobalMessage" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "content" TEXT NOT NULL, + "isAnonymous" BOOLEAN NOT NULL DEFAULT true, + "userId" TEXT +); + +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +-- CreateIndex +CREATE INDEX "User_email_username_idx" ON "User"("email", "username"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- CreateIndex +CREATE INDEX "Message_senderId_createdAt_idx" ON "Message"("senderId", "createdAt" DESC); + +-- CreateIndex +CREATE INDEX "Message_receiverId_createdAt_idx" ON "Message"("receiverId", "createdAt" DESC); + +-- CreateIndex +CREATE INDEX "GlobalMessage_userId_updatedAt_idx" ON "GlobalMessage"("userId", "updatedAt" DESC); diff --git a/apps/web/prisma/migrations/migration_lock.toml b/apps/web/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..e5e5c470 --- /dev/null +++ b/apps/web/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma new file mode 100644 index 00000000..af951cc3 --- /dev/null +++ b/apps/web/prisma/schema.prisma @@ -0,0 +1,93 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "sqlite" + url = "file:./dev.db" + relationMode = "prisma" +} + +model Account { + id String @id @default(cuid()) + userId String + type String + provider String + providerAccountId String + refresh_token String? + access_token String? + expires_at Int? + token_type String? + scope String? + id_token String? + session_state String? + + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@unique([provider, providerAccountId]) + @@index([userId]) +} + +model User { + id String @id @default(cuid()) + name String? + createdAt DateTime @default(now()) + email String? @unique + emailVerified DateTime? + username String? @unique + password String? + image String? + message String @default("Send me an anonymous message!") + + accounts Account[] + sentMessages Message[] @relation("sentMessages") + sentGlobalMessages GlobalMessage[] @relation("sentGlobalMessages") + receivedMessages Message[] @relation("receivedMessages") + + @@index([email, username]) +} + +model VerificationToken { + identifier String + token String @unique + expires DateTime + + @@unique([identifier, token]) +} + +model Message { + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + content String + receiverMsg String + isOpened Boolean @default(false) + reply String? + clue String? + + senderId String? + sender User? @relation(name: "sentMessages", fields: [senderId], references: [id]) + receiverUsername String? + receiverId String + receiver User @relation(name: "receivedMessages", fields: [receiverId], references: [id], onDelete: Cascade) + + @@index([senderId, createdAt(sort: Desc)]) + @@index([receiverId, createdAt(sort: Desc)]) +} + +model GlobalMessage { + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + content String + isAnonymous Boolean @default(true) + + userId String? + user User? @relation(name: "sentGlobalMessages", fields: [userId], references: [id], onDelete: Cascade) + + @@index([userId, updatedAt(sort: Desc)]) +} diff --git a/apps/web/prisma/seed.js b/apps/web/prisma/seed.js new file mode 100644 index 00000000..81755cb9 --- /dev/null +++ b/apps/web/prisma/seed.js @@ -0,0 +1,41 @@ +const { PrismaClient } = require('@prisma/client'); + +const prisma = new PrismaClient(); + +const reset = async () => { + await prisma.user.deleteMany(); + await prisma.message.deleteMany(); +}; + +const main = async () => { + console.log('resetting db...'); + await reset(); + + console.log('seeding...'); + const sender = await prisma.user.create({ + data: { password: 'sender', username: 'sender' }, + }); + const receiver = await prisma.user.create({ + data: { password: 'receiver', username: 'receiver' }, + }); + + const message = await prisma.message.create({ + data: { + content: 'test message', + /** + * OR use username to connect + * sender: { connect: { username: sender.username } }, + * receiver : { connect: { username: receiver.username } }, + */ + senderId: sender.id, + receiverId: receiver.id, + }, + }); + + console.log( + `${sender.username} sent "${message.content}" to ${receiver.username}` + ); +}; + +// eslint-disable-next-line no-console +main().catch(console.error); diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index 165b873a..f5ff3e11 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -1,12 +1,12 @@ /* eslint-disable */ -import { PrismaClient } from '@umamin/db'; +import { PrismaClient } from '@prisma/client'; import { PrismaLibSQL } from '@prisma/adapter-libsql'; import { createClient } from '@libsql/client'; const libsql = createClient({ url: `${process.env.TURSO_DATABASE_URL}`, - authToken: process.env.TURSO_AUTH_TOKEN, + authToken: `${process.env.TURSO_AUTH_TOKEN}`, }); const prismaClientSingleton = () => { diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 0f120764..47cfd814 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -6,10 +6,7 @@ import { ApolloServer } from '@apollo/server'; import { getSession } from 'next-auth/react'; import { buildSchema } from 'type-graphql'; -import { PrismaClient } from '@umamin/db'; -import { createClient } from '@libsql/client'; -import { PrismaLibSQL } from '@prisma/adapter-libsql'; - +import prisma from '@/lib/db'; import { UserResolver } from '@/schema/user'; import { MessageResolver } from '@/schema/message'; import { GlobalMessageResolver } from '@/schema/global-message'; @@ -29,14 +26,6 @@ const server = new ApolloServer({ plugins: [responseCachePlugin()], }); -const libsql = createClient({ - url: `${process.env.TURSO_DATABASE_URL}`, - authToken: process.env.TURSO_AUTH_TOKEN, -}); - -const adapter = new PrismaLibSQL(libsql); -const prisma = new PrismaClient({ adapter }); - const _handler = startServerAndCreateNextHandler(server, { context: async (req) => { const session = await getSession({ req }); diff --git a/packages/db/package.json b/packages/db/package.json index 93bdd91a..3548f663 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -5,9 +5,6 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "dev": "prisma generate && tsc", - "build": "prisma generate && tsc", - "generate": "prisma generate && tsc", "clean": "rimraf dist/ .turbo/ node_modules/", "clean:cache": "rimraf dist/ .turbo/" }, From dec0190fa117c57c7f327588e1589bb19cc8dc28 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 09:23:13 +0800 Subject: [PATCH 13/22] refactor: remove db package --- apps/web/next.config.js | 2 +- apps/web/prisma/seed.js | 41 -------- packages/db/.env.example | 1 - packages/db/.gitignore | 6 -- packages/db/index.ts | 1 - packages/db/package.json | 21 ----- .../20240407070104_init/migration.sql | 90 ------------------ .../db/prisma/migrations/migration_lock.toml | 3 - packages/db/prisma/schema.prisma | 93 ------------------- packages/db/prisma/seed.js | 41 -------- packages/db/tsconfig.json | 17 ---- 11 files changed, 1 insertion(+), 315 deletions(-) delete mode 100644 apps/web/prisma/seed.js delete mode 100644 packages/db/.env.example delete mode 100644 packages/db/.gitignore delete mode 100644 packages/db/index.ts delete mode 100644 packages/db/package.json delete mode 100644 packages/db/prisma/migrations/20240407070104_init/migration.sql delete mode 100644 packages/db/prisma/migrations/migration_lock.toml delete mode 100644 packages/db/prisma/schema.prisma delete mode 100644 packages/db/prisma/seed.js delete mode 100644 packages/db/tsconfig.json diff --git a/apps/web/next.config.js b/apps/web/next.config.js index a8b6188c..3e92a147 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -14,7 +14,7 @@ module.exports = withPWA({ // compiler: { // removeConsole: process.env.NODE_ENV === 'production', // }, - transpilePackages: ['@umamin/db', '@umamin/generated'], + transpilePackages: ['@umamin/generated'], modularizeImports: { 'date-fns': { transform: 'date-fns/{{member}}', diff --git a/apps/web/prisma/seed.js b/apps/web/prisma/seed.js deleted file mode 100644 index 81755cb9..00000000 --- a/apps/web/prisma/seed.js +++ /dev/null @@ -1,41 +0,0 @@ -const { PrismaClient } = require('@prisma/client'); - -const prisma = new PrismaClient(); - -const reset = async () => { - await prisma.user.deleteMany(); - await prisma.message.deleteMany(); -}; - -const main = async () => { - console.log('resetting db...'); - await reset(); - - console.log('seeding...'); - const sender = await prisma.user.create({ - data: { password: 'sender', username: 'sender' }, - }); - const receiver = await prisma.user.create({ - data: { password: 'receiver', username: 'receiver' }, - }); - - const message = await prisma.message.create({ - data: { - content: 'test message', - /** - * OR use username to connect - * sender: { connect: { username: sender.username } }, - * receiver : { connect: { username: receiver.username } }, - */ - senderId: sender.id, - receiverId: receiver.id, - }, - }); - - console.log( - `${sender.username} sent "${message.content}" to ${receiver.username}` - ); -}; - -// eslint-disable-next-line no-console -main().catch(console.error); diff --git a/packages/db/.env.example b/packages/db/.env.example deleted file mode 100644 index c03ed2d9..00000000 --- a/packages/db/.env.example +++ /dev/null @@ -1 +0,0 @@ -DATABASE_URL="mysql://root:mysql@localhost:6033/umamin-db" diff --git a/packages/db/.gitignore b/packages/db/.gitignore deleted file mode 100644 index 22fb428b..00000000 --- a/packages/db/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -dist/ -.turbo/ -node_modules/ -prisma/dev.* - -.env diff --git a/packages/db/index.ts b/packages/db/index.ts deleted file mode 100644 index bf4e0f87..00000000 --- a/packages/db/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "@prisma/client" diff --git a/packages/db/package.json b/packages/db/package.json deleted file mode 100644 index 3548f663..00000000 --- a/packages/db/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@umamin/db", - "version": "1.0.0", - "description": "", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "scripts": { - "clean": "rimraf dist/ .turbo/ node_modules/", - "clean:cache": "rimraf dist/ .turbo/" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@prisma/client": "^5.12.1" - }, - "devDependencies": { - "prisma": "^5.12.1", - "typescript": "^4.7.4" - } -} diff --git a/packages/db/prisma/migrations/20240407070104_init/migration.sql b/packages/db/prisma/migrations/20240407070104_init/migration.sql deleted file mode 100644 index dbca6d49..00000000 --- a/packages/db/prisma/migrations/20240407070104_init/migration.sql +++ /dev/null @@ -1,90 +0,0 @@ --- CreateTable -CREATE TABLE "Account" ( - "id" TEXT NOT NULL PRIMARY KEY, - "userId" TEXT NOT NULL, - "type" TEXT NOT NULL, - "provider" TEXT NOT NULL, - "providerAccountId" TEXT NOT NULL, - "refresh_token" TEXT, - "access_token" TEXT, - "expires_at" INTEGER, - "token_type" TEXT, - "scope" TEXT, - "id_token" TEXT, - "session_state" TEXT -); - --- CreateTable -CREATE TABLE "User" ( - "id" TEXT NOT NULL PRIMARY KEY, - "name" TEXT, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "email" TEXT, - "emailVerified" DATETIME, - "username" TEXT, - "password" TEXT, - "image" TEXT, - "message" TEXT NOT NULL DEFAULT 'Send me an anonymous message!' -); - --- CreateTable -CREATE TABLE "VerificationToken" ( - "identifier" TEXT NOT NULL, - "token" TEXT NOT NULL, - "expires" DATETIME NOT NULL -); - --- CreateTable -CREATE TABLE "Message" ( - "id" TEXT NOT NULL PRIMARY KEY, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL, - "content" TEXT NOT NULL, - "receiverMsg" TEXT NOT NULL, - "isOpened" BOOLEAN NOT NULL DEFAULT false, - "reply" TEXT, - "clue" TEXT, - "senderId" TEXT, - "receiverUsername" TEXT, - "receiverId" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "GlobalMessage" ( - "id" TEXT NOT NULL PRIMARY KEY, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL, - "content" TEXT NOT NULL, - "isAnonymous" BOOLEAN NOT NULL DEFAULT true, - "userId" TEXT -); - --- CreateIndex -CREATE INDEX "Account_userId_idx" ON "Account"("userId"); - --- CreateIndex -CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); - --- CreateIndex -CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - --- CreateIndex -CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); - --- CreateIndex -CREATE INDEX "User_email_username_idx" ON "User"("email", "username"); - --- CreateIndex -CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); - --- CreateIndex -CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); - --- CreateIndex -CREATE INDEX "Message_senderId_createdAt_idx" ON "Message"("senderId", "createdAt" DESC); - --- CreateIndex -CREATE INDEX "Message_receiverId_createdAt_idx" ON "Message"("receiverId", "createdAt" DESC); - --- CreateIndex -CREATE INDEX "GlobalMessage_userId_updatedAt_idx" ON "GlobalMessage"("userId", "updatedAt" DESC); diff --git a/packages/db/prisma/migrations/migration_lock.toml b/packages/db/prisma/migrations/migration_lock.toml deleted file mode 100644 index e5e5c470..00000000 --- a/packages/db/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "sqlite" \ No newline at end of file diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma deleted file mode 100644 index af951cc3..00000000 --- a/packages/db/prisma/schema.prisma +++ /dev/null @@ -1,93 +0,0 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -generator client { - provider = "prisma-client-js" - previewFeatures = ["driverAdapters"] -} - -datasource db { - provider = "sqlite" - url = "file:./dev.db" - relationMode = "prisma" -} - -model Account { - id String @id @default(cuid()) - userId String - type String - provider String - providerAccountId String - refresh_token String? - access_token String? - expires_at Int? - token_type String? - scope String? - id_token String? - session_state String? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@unique([provider, providerAccountId]) - @@index([userId]) -} - -model User { - id String @id @default(cuid()) - name String? - createdAt DateTime @default(now()) - email String? @unique - emailVerified DateTime? - username String? @unique - password String? - image String? - message String @default("Send me an anonymous message!") - - accounts Account[] - sentMessages Message[] @relation("sentMessages") - sentGlobalMessages GlobalMessage[] @relation("sentGlobalMessages") - receivedMessages Message[] @relation("receivedMessages") - - @@index([email, username]) -} - -model VerificationToken { - identifier String - token String @unique - expires DateTime - - @@unique([identifier, token]) -} - -model Message { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - content String - receiverMsg String - isOpened Boolean @default(false) - reply String? - clue String? - - senderId String? - sender User? @relation(name: "sentMessages", fields: [senderId], references: [id]) - receiverUsername String? - receiverId String - receiver User @relation(name: "receivedMessages", fields: [receiverId], references: [id], onDelete: Cascade) - - @@index([senderId, createdAt(sort: Desc)]) - @@index([receiverId, createdAt(sort: Desc)]) -} - -model GlobalMessage { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - content String - isAnonymous Boolean @default(true) - - userId String? - user User? @relation(name: "sentGlobalMessages", fields: [userId], references: [id], onDelete: Cascade) - - @@index([userId, updatedAt(sort: Desc)]) -} diff --git a/packages/db/prisma/seed.js b/packages/db/prisma/seed.js deleted file mode 100644 index 81755cb9..00000000 --- a/packages/db/prisma/seed.js +++ /dev/null @@ -1,41 +0,0 @@ -const { PrismaClient } = require('@prisma/client'); - -const prisma = new PrismaClient(); - -const reset = async () => { - await prisma.user.deleteMany(); - await prisma.message.deleteMany(); -}; - -const main = async () => { - console.log('resetting db...'); - await reset(); - - console.log('seeding...'); - const sender = await prisma.user.create({ - data: { password: 'sender', username: 'sender' }, - }); - const receiver = await prisma.user.create({ - data: { password: 'receiver', username: 'receiver' }, - }); - - const message = await prisma.message.create({ - data: { - content: 'test message', - /** - * OR use username to connect - * sender: { connect: { username: sender.username } }, - * receiver : { connect: { username: receiver.username } }, - */ - senderId: sender.id, - receiverId: receiver.id, - }, - }); - - console.log( - `${sender.username} sent "${message.content}" to ${receiver.username}` - ); -}; - -// eslint-disable-next-line no-console -main().catch(console.error); diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json deleted file mode 100644 index 1da9b1ee..00000000 --- a/packages/db/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "display": "@umamin/db", - "compilerOptions": { - "target": "ES6", - "lib": ["ESNext"], - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "esModuleInterop": true, - "module": "commonjs", - "outDir": "dist", - "skipLibCheck": true, - "strict": true - }, - "exclude": ["node_modules", "dist"] -} From 11e5c1e8d306cb86fc61030c8f994c9b430c1b70 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 09:40:40 +0800 Subject: [PATCH 14/22] chore: update maintenance page --- apps/web/src/components/Maintenance.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/Maintenance.tsx b/apps/web/src/components/Maintenance.tsx index 228412f8..ad73b2e9 100644 --- a/apps/web/src/components/Maintenance.tsx +++ b/apps/web/src/components/Maintenance.tsx @@ -1,13 +1,13 @@ import React from 'react'; import Image from 'next/image'; -import { FaDiscord, FaFacebook } from 'react-icons/fa'; +import { FaFacebook, FaInstagram } from 'react-icons/fa'; import { Footer } from '.'; export const Maintenance = () => { return ( <> -
+
logo { />
-

+

{process.env.NEXT_PUBLIC_MAINTENANCE_TITLE}

@@ -27,13 +27,13 @@ export const Maintenance = () => {

- -

Join Discord Server

+ +

Instagram

{ className='btn flex items-center space-x-2 rounded bg-[#2374e1] hover:bg-[#2374e1]/80' > -

Like Facebook Page

+

Facebook

{process.env.NEXT_PUBLIC_MAINTENANCE_URL && ( From 29070912fcb6895198474efff5a974727799574c Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 10:30:55 +0800 Subject: [PATCH 15/22] chore(temp): instantiate prisma in handler --- apps/web/src/lib/db.ts | 8 +++----- apps/web/src/pages/api/graphql.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index f5ff3e11..470089cd 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -1,18 +1,16 @@ /* eslint-disable */ - import { PrismaClient } from '@prisma/client'; import { PrismaLibSQL } from '@prisma/adapter-libsql'; import { createClient } from '@libsql/client'; const libsql = createClient({ - url: `${process.env.TURSO_DATABASE_URL}`, - authToken: `${process.env.TURSO_AUTH_TOKEN}`, + url: process.env.TURSO_DATABASE_URL!, + authToken: process.env.TURSO_AUTH_TOKEN, }); const prismaClientSingleton = () => { const adapter = new PrismaLibSQL(libsql); - const prisma = new PrismaClient({ adapter }); - return prisma; + return new PrismaClient({ adapter }); }; declare global { diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 47cfd814..1f5b14bc 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -6,6 +6,10 @@ import { ApolloServer } from '@apollo/server'; import { getSession } from 'next-auth/react'; import { buildSchema } from 'type-graphql'; +import { PrismaClient } from '@prisma/client'; +import { PrismaLibSQL } from '@prisma/adapter-libsql'; +import { createClient } from '@libsql/client'; + import prisma from '@/lib/db'; import { UserResolver } from '@/schema/user'; import { MessageResolver } from '@/schema/message'; @@ -28,7 +32,16 @@ const server = new ApolloServer({ const _handler = startServerAndCreateNextHandler(server, { context: async (req) => { + const libsql = createClient({ + url: process.env.TURSO_DATABASE_URL!, + authToken: process.env.TURSO_AUTH_TOKEN, + }); + + const adapter = new PrismaLibSQL(libsql); + const prisma = new PrismaClient({ adapter }); + const session = await getSession({ req }); + const id = session?.user?.id; return { prisma, id, req }; }, From 375fd04d7bbf932d42acf36c0a522bd1d6dfa407 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 10:56:27 +0800 Subject: [PATCH 16/22] chore: upgrade to node 18 --- .github/workflows/ci.yml | 2 +- apps/web/package.json | 2 +- package.json | 2 +- yarn.lock | 68 +++++++++++++++++++++------------------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 588e8782..80926dcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Setup node uses: actions/setup-node@v1 with: - node-version: 16 + node-version: 18 - name: Install dependencies run: yarn diff --git a/apps/web/package.json b/apps/web/package.json index fd3d85bd..aa923a33 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -37,7 +37,7 @@ "lru-cache": "^10.0.0", "nanoid": "^4.0.0", "next": "13.4.12", - "next-auth": "^4.18.8", + "next-auth": "4.24.6", "next-pwa": "^5.6.0", "next-seo": "^5.4.0", "nprogress": "^0.2.0", diff --git a/package.json b/package.json index f73b2983..b0f9f4a9 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "engines": { "npm": ">=7.0.0", - "node": ">=14.0.0" + "node": ">=18.0.0" }, "packageManager": "yarn@1.22.19" } diff --git a/yarn.lock b/yarn.lock index 5470924f..deaca906 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1163,6 +1163,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.20.13": + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.4.tgz#de795accd698007a66ba44add6cc86542aff1edd" + integrity sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/runtime@^7.23.7": version "7.23.9" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.9.tgz#47791a15e4603bb5f905bc0753801cf21d6345f7" @@ -2403,10 +2410,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@panva/hkdf@^1.0.1": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@panva/hkdf/-/hkdf-1.0.2.tgz#bab0f09d09de9fd83628220d496627681bc440d6" - integrity sha512-MSAs9t3Go7GUkMhpKC44T58DJ5KGk2vBo+h1cqQeqlMfdGkxaVB78ZWpv9gYi/g2fa4sopag9gJsNvS8XGgWJA== +"@panva/hkdf@^1.0.2": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@panva/hkdf/-/hkdf-1.1.1.tgz#ab9cd8755d1976e72fc77a00f7655a64efe6cd5d" + integrity sha512-dhPeilub1NuIG0X5Kvhh9lH4iW3ZsHlnzwgwbOlgwQ2wG1IqFzsgHqmKPk3WzsdWAeaxKJxgM0+W433RmN45GA== "@parcel/watcher-android-arm64@2.2.0": version "2.2.0" @@ -5897,20 +5904,15 @@ jiti@^1.17.1, jiti@^1.18.2: resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.18.2.tgz#80c3ef3d486ebf2450d9335122b32d121f2a83cd" integrity sha512-QAdOptna2NYiSSpv0O/BwoHBSmz4YhpzJHyi+fnMRTXFjp7B8i/YG5Z8IfusxB1ufjcD2Sre1F3R+nX3fvy7gg== -jose@^4.1.4: - version "4.8.3" - resolved "https://registry.yarnpkg.com/jose/-/jose-4.8.3.tgz#5a754fb4aa5f2806608d083f438e6916b11087da" - integrity sha512-7rySkpW78d8LBp4YU70Wb7+OTgE3OwAALNVZxhoIhp4Kscp+p/fBkdpxGAMKxvCAMV4QfXBU9m6l9nX/vGwd2g== - jose@^4.11.4: version "4.14.4" resolved "https://registry.yarnpkg.com/jose/-/jose-4.14.4.tgz#59e09204e2670c3164ee24cbfe7115c6f8bff9ca" integrity sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g== -jose@^4.9.3: - version "4.11.2" - resolved "https://registry.yarnpkg.com/jose/-/jose-4.11.2.tgz#d9699307c02e18ff56825843ba90e2fae9f09e23" - integrity sha512-njj0VL2TsIxCtgzhO+9RRobBvws4oYyCM8TpvoUQwl/MbIM3NFJRR9+e6x0sS5xXaP1t6OCBkaBME98OV9zU5A== +jose@^4.15.5: + version "4.15.5" + resolved "https://registry.yarnpkg.com/jose/-/jose-4.15.5.tgz#6475d0f467ecd3c630a1b5dadd2735a7288df706" + integrity sha512-jc7BFxgKPKi94uOvEmzlSWFFe2+vASyXaKUpdQKatWAESU2MWjDfFf0fdfc83CDKcA5QecabZeNLyfhe3yKNkg== js-base64@^3.7.5: version "3.7.7" @@ -6861,17 +6863,17 @@ negotiator@0.6.3, negotiator@^0.6.3: resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd" integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg== -next-auth@^4.18.8: - version "4.18.8" - resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.18.8.tgz#34012ac107702b27779647e8787715cea948812a" - integrity sha512-USP8ihmvB7iCGtkS0+toe2QPrzdbZfkydQZX56JOI9Ft5n/BardOXh3D4wQ2An+vpq/jDKojGlgfv21wVElW7A== +next-auth@4.24.6: + version "4.24.6" + resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.24.6.tgz#8cb1848197fdb2479eac2f10e4efa1f1b6b0daaa" + integrity sha512-djQt3ZEaWEIxcsuh3HTW2uuzLfXMRjHH+ugAsichlQSbH4iA5MRcgMA2HvTNvsDTDLh44tyU72+/gWsxgTbAKg== dependencies: - "@babel/runtime" "^7.16.3" - "@panva/hkdf" "^1.0.1" + "@babel/runtime" "^7.20.13" + "@panva/hkdf" "^1.0.2" cookie "^0.5.0" - jose "^4.9.3" + jose "^4.11.4" oauth "^0.9.15" - openid-client "^5.1.0" + openid-client "^5.4.0" preact "^10.6.3" preact-render-to-string "^5.1.19" uuid "^8.3.2" @@ -7032,7 +7034,7 @@ object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1 resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== -object-hash@^2.0.1: +object-hash@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.2.0.tgz#5ad518581eefc443bd763472b8ff2e9c2c0d54a5" integrity sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw== @@ -7097,10 +7099,10 @@ object.values@^1.1.5: define-properties "^1.1.3" es-abstract "^1.19.1" -oidc-token-hash@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/oidc-token-hash/-/oidc-token-hash-5.0.1.tgz#ae6beec3ec20f0fd885e5400d175191d6e2f10c6" - integrity sha512-EvoOtz6FIEBzE+9q253HsLCVRiK/0doEJ2HCvvqMQb3dHZrP3WlJKYtJ55CRTw4jmYomzH4wkPuCj/I3ZvpKxQ== +oidc-token-hash@^5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz#9a229f0a1ce9d4fc89bcaee5478c97a889e7b7b6" + integrity sha512-IF4PcGgzAr6XXSff26Sk/+P4KZFJVuHAJZj3wgO3vX2bMdNVp/QXTP3P7CEm9V1IdG8lDLY3HhiqpsE/nOwpPw== on-finished@2.4.1: version "2.4.1" @@ -7123,15 +7125,15 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -openid-client@^5.1.0: - version "5.1.8" - resolved "https://registry.yarnpkg.com/openid-client/-/openid-client-5.1.8.tgz#3a24910288b32c32f548fb6e391f44178ce6370f" - integrity sha512-EPxJY6bT7YIYQEXSGxRC5flQ3GUhLy98ufdto6+BVBrFGPmwjUpy4xBcYuU/Wt9nPkO/3EgljBrr6Ezx4lp1RQ== +openid-client@^5.4.0: + version "5.6.5" + resolved "https://registry.yarnpkg.com/openid-client/-/openid-client-5.6.5.tgz#c149ad07b9c399476dc347097e297bbe288b8b00" + integrity sha512-5P4qO9nGJzB5PI0LFlhj4Dzg3m4odt0qsJTfyEtZyOlkgpILwEioOhVVJOrS1iVH494S4Ee5OCjjg6Bf5WOj3w== dependencies: - jose "^4.1.4" + jose "^4.15.5" lru-cache "^6.0.0" - object-hash "^2.0.1" - oidc-token-hash "^5.0.1" + object-hash "^2.2.0" + oidc-token-hash "^5.0.3" optionator@^0.9.1: version "0.9.1" From da4bcc33e5611d53211ab48040aae369bee45d3e Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 11:04:01 +0800 Subject: [PATCH 17/22] chore: revert prisma instantiation on handler --- apps/web/src/lib/db.ts | 3 ++- apps/web/src/pages/api/graphql.ts | 13 ------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/apps/web/src/lib/db.ts b/apps/web/src/lib/db.ts index 470089cd..a83795be 100644 --- a/apps/web/src/lib/db.ts +++ b/apps/web/src/lib/db.ts @@ -10,7 +10,8 @@ const libsql = createClient({ const prismaClientSingleton = () => { const adapter = new PrismaLibSQL(libsql); - return new PrismaClient({ adapter }); + const prisma = new PrismaClient({ adapter }); + return prisma; }; declare global { diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 1f5b14bc..47cfd814 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -6,10 +6,6 @@ import { ApolloServer } from '@apollo/server'; import { getSession } from 'next-auth/react'; import { buildSchema } from 'type-graphql'; -import { PrismaClient } from '@prisma/client'; -import { PrismaLibSQL } from '@prisma/adapter-libsql'; -import { createClient } from '@libsql/client'; - import prisma from '@/lib/db'; import { UserResolver } from '@/schema/user'; import { MessageResolver } from '@/schema/message'; @@ -32,16 +28,7 @@ const server = new ApolloServer({ const _handler = startServerAndCreateNextHandler(server, { context: async (req) => { - const libsql = createClient({ - url: process.env.TURSO_DATABASE_URL!, - authToken: process.env.TURSO_AUTH_TOKEN, - }); - - const adapter = new PrismaLibSQL(libsql); - const prisma = new PrismaClient({ adapter }); - const session = await getSession({ req }); - const id = session?.user?.id; return { prisma, id, req }; }, From 65ea7f123fdf1f4c2222dea2ae6776fbf53fdcda Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 12:21:33 +0800 Subject: [PATCH 18/22] fix(temp): pass userId as param --- apps/web/src/components/InboxTabs/InboxTab.tsx | 11 ++++++----- apps/web/src/schema/message/message.resolvers.ts | 5 +++-- packages/generated/graphql/message.graphql | 4 ++-- packages/generated/index.ts | 6 ++++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/InboxTabs/InboxTab.tsx b/apps/web/src/components/InboxTabs/InboxTab.tsx index cabca85a..d374e841 100644 --- a/apps/web/src/components/InboxTabs/InboxTab.tsx +++ b/apps/web/src/components/InboxTabs/InboxTab.tsx @@ -2,7 +2,6 @@ import React from 'react'; import dynamic from 'next/dynamic'; import toast from 'react-hot-toast'; import { IoIosCopy } from 'react-icons/io'; -import { useSession } from 'next-auth/react'; import { useInfiniteQuery } from '@tanstack/react-query'; import { getMessages } from '@/api'; @@ -22,7 +21,6 @@ interface Props { } export const InboxTab = ({ type }: Props) => { - const { data: session } = useSession(); const { user } = useInboxContext(); const triggerEvent = useLogEvent(); @@ -35,7 +33,8 @@ export const InboxTab = ({ type }: Props) => { isFetchingNextPage, } = useInfiniteQuery({ queryKey: [`${type}_messages`, { type, userId: user?.id }], - queryFn: ({ pageParam }) => getMessages({ cursorId: pageParam, type }), + queryFn: ({ pageParam }) => + getMessages({ cursorId: pageParam, userId: user?.id!, type }), initialPageParam: '', getNextPageParam: (lastPage) => lastPage.getMessages?.cursorId, select: (data) => data.pages.flatMap((page) => page.getMessages?.data), @@ -73,7 +72,7 @@ export const InboxTab = ({ type }: Props) => {
@@ -109,7 +108,9 @@ export const InboxTab = ({ type }: Props) => {
{messages?.map((m, i) => (
- {(i + 1) % 3 === 0 && } + {(i + 1) % 3 === 0 && ( + + )} diff --git a/apps/web/src/schema/message/message.resolvers.ts b/apps/web/src/schema/message/message.resolvers.ts index 9b6998a0..872869e7 100644 --- a/apps/web/src/schema/message/message.resolvers.ts +++ b/apps/web/src/schema/message/message.resolvers.ts @@ -16,12 +16,13 @@ export class MessageResolver { @Query(() => MessagesData, { nullable: true }) async getMessages( @Arg('type', () => String) type: 'recent' | 'sent', + @Arg('userId', () => ID) userId: string, @Arg('cursorId', () => ID, { nullable: true }) cursorId: string, - @Ctx() { prisma, id }: TContext + @Ctx() { prisma }: TContext ): Promise { try { const messages = await prisma.message.findMany({ - where: type === 'recent' ? { receiverId: id } : { senderId: id }, + where: type === 'recent' ? { receiverId: userId } : { senderId: userId }, orderBy: { createdAt: 'desc' }, take: 5, select: { diff --git a/packages/generated/graphql/message.graphql b/packages/generated/graphql/message.graphql index 601680e6..63b34df6 100644 --- a/packages/generated/graphql/message.graphql +++ b/packages/generated/graphql/message.graphql @@ -16,8 +16,8 @@ query getGlobalMessages($cursorId: ID) { } } -query getMessages($type: String!, $cursorId: ID) { - getMessages(type: $type, cursorId: $cursorId) { +query getMessages($type: String!, $userId: ID!, $cursorId: ID) { + getMessages(type: $type, userId: $userId, cursorId: $cursorId) { data { id clue diff --git a/packages/generated/index.ts b/packages/generated/index.ts index f24af880..b0323bfd 100644 --- a/packages/generated/index.ts +++ b/packages/generated/index.ts @@ -135,6 +135,7 @@ export type QueryGetGlobalMessagesArgs = { export type QueryGetMessagesArgs = { cursorId?: InputMaybe; type: Scalars['String']['input']; + userId: Scalars['ID']['input']; }; @@ -181,6 +182,7 @@ export type GetGlobalMessagesQuery = { __typename?: 'Query', getGlobalMessages?: export type GetMessagesQueryVariables = Exact<{ type: Scalars['String']['input']; + userId: Scalars['ID']['input']; cursorId?: InputMaybe; }>; @@ -279,8 +281,8 @@ export const GetGlobalMessagesDocument = gql` } `; export const GetMessagesDocument = gql` - query getMessages($type: String!, $cursorId: ID) { - getMessages(type: $type, cursorId: $cursorId) { + query getMessages($type: String!, $userId: ID!, $cursorId: ID) { + getMessages(type: $type, userId: $userId, cursorId: $cursorId) { data { id clue From e9d09055324bf2415843030a86a6950cd132403b Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 12:42:16 +0800 Subject: [PATCH 19/22] refactor: remove session in context and pass userId param --- apps/web/src/components/Create.tsx | 30 +++++++------- apps/web/src/components/Dialog/SendGlobal.tsx | 41 ++++++++++--------- apps/web/src/components/Dialog/Settings.tsx | 5 ++- apps/web/src/pages/api/graphql.ts | 6 +-- apps/web/src/pages/to/[username].tsx | 3 +- .../global-message.resolvers.ts | 12 +++--- .../global-message/global-message.types.ts | 3 ++ .../src/schema/message/message.resolvers.ts | 9 ++-- apps/web/src/schema/message/message.types.ts | 3 ++ apps/web/src/schema/user/user.resolvers.ts | 26 +++++++----- packages/generated/graphql/user.graphql | 18 ++++---- packages/generated/index.ts | 35 +++++++++++----- 12 files changed, 112 insertions(+), 79 deletions(-) diff --git a/apps/web/src/components/Create.tsx b/apps/web/src/components/Create.tsx index 561f80cd..a29f5180 100644 --- a/apps/web/src/components/Create.tsx +++ b/apps/web/src/components/Create.tsx @@ -12,26 +12,28 @@ const AdContainer = dynamic(() => import('@/components/AdContainer'), { }); export const Create = () => { - const { refetchUser } = useInboxContext(); + const { user, refetchUser } = useInboxContext(); const { mutate } = useMutation({ mutationFn: editUsername }); const [username, setUsername] = useState(''); const handleSubmit: React.FormEventHandler = (e) => { e.preventDefault(); - mutate( - { username }, - { - onSuccess: (data) => { - if (data.editUsername.error) { - toast.error(data.editUsername.error); - return; - } - - refetchUser(); - }, - } - ); + if (user?.id) { + mutate( + { userId: user.id, username }, + { + onSuccess: (data) => { + if (data.editUsername.error) { + toast.error(data.editUsername.error); + return; + } + + refetchUser(); + }, + } + ); + } setUsername(''); }; diff --git a/apps/web/src/components/Dialog/SendGlobal.tsx b/apps/web/src/components/Dialog/SendGlobal.tsx index 95a9f1f3..19a5ec15 100644 --- a/apps/web/src/components/Dialog/SendGlobal.tsx +++ b/apps/web/src/components/Dialog/SendGlobal.tsx @@ -29,24 +29,27 @@ export const SendGlobalModal = ({ const handleSend: React.FormEventHandler = (e) => { e.preventDefault(); - mutate( - { input: { content: message, isAnonymous } }, - { - onSuccess: (data) => { - if (data.sendGlobalMessage.error) { - toast.error(data.sendGlobalMessage.error); - return; - } - setMessageData(data.sendGlobalMessage.data); - toast.success('Message posted'); + if (user?.id) { + mutate( + { input: { userId: user.id, content: message, isAnonymous } }, + { + onSuccess: (data) => { + if (data.sendGlobalMessage.error) { + toast.error(data.sendGlobalMessage.error); + return; + } - setTimeout(() => { - setMessage(''); - }, 500); - }, - } - ); + setMessageData(data.sendGlobalMessage.data); + toast.success('Message posted'); + + setTimeout(() => { + setMessage(''); + }, 500); + }, + } + ); + } setIsOpen(false); }; @@ -58,12 +61,12 @@ export const SendGlobalModal = ({ className='msg-card flex flex-col space-y-4 p-6' >
-
+

{user?.username}

@@ -84,7 +87,7 @@ export const SendGlobalModal = ({ />
- diff --git a/apps/web/src/components/Dialog/Settings.tsx b/apps/web/src/components/Dialog/Settings.tsx index 2b96f060..1eee5bff 100644 --- a/apps/web/src/components/Dialog/Settings.tsx +++ b/apps/web/src/components/Dialog/Settings.tsx @@ -65,6 +65,7 @@ export const SettingsDialog = ({ setIsOpen, ...rest }: Props) => { if (currentOption === 'message' && message !== user.message) { editUserMessageMutate( { + userId: user.id, message, }, { @@ -82,6 +83,7 @@ export const SettingsDialog = ({ setIsOpen, ...rest }: Props) => { if (currentOption === 'username' && username !== user.username) { editUsernameMutate( { + userId: user.id, username, }, { @@ -118,6 +120,7 @@ export const SettingsDialog = ({ setIsOpen, ...rest }: Props) => { } else { changePasswordMutate( { + userId: user.id, newPassword: newPass, }, { @@ -135,7 +138,7 @@ export const SettingsDialog = ({ setIsOpen, ...rest }: Props) => { const handleDeleteUser = () => { if (user?.id) { deleteUserMutate( - {}, + { userId: user.id }, { onSuccess: async () => { toast.success('User deleted'); diff --git a/apps/web/src/pages/api/graphql.ts b/apps/web/src/pages/api/graphql.ts index 47cfd814..d27cbd67 100644 --- a/apps/web/src/pages/api/graphql.ts +++ b/apps/web/src/pages/api/graphql.ts @@ -3,7 +3,6 @@ import { startServerAndCreateNextHandler } from '@as-integrations/next'; import responseCachePlugin from '@apollo/server-plugin-response-cache'; import { NextApiRequest, NextApiResponse } from 'next/types'; import { ApolloServer } from '@apollo/server'; -import { getSession } from 'next-auth/react'; import { buildSchema } from 'type-graphql'; import prisma from '@/lib/db'; @@ -13,7 +12,6 @@ import { GlobalMessageResolver } from '@/schema/global-message'; export interface TContext { prisma: typeof prisma; - id?: string; req: NextApiRequest; } @@ -28,9 +26,7 @@ const server = new ApolloServer({ const _handler = startServerAndCreateNextHandler(server, { context: async (req) => { - const session = await getSession({ req }); - const id = session?.user?.id; - return { prisma, id, req }; + return { prisma, req }; }, }); diff --git a/apps/web/src/pages/to/[username].tsx b/apps/web/src/pages/to/[username].tsx index 983c0989..0e95fc90 100644 --- a/apps/web/src/pages/to/[username].tsx +++ b/apps/web/src/pages/to/[username].tsx @@ -59,6 +59,7 @@ const SendTo: NextPageWithLayout< mutate( { input: { + userId: user.id, receiverUsername: username, content: message, receiverMsg: user?.message, @@ -158,7 +159,7 @@ const SendTo: NextPageWithLayout< {username}

-

+

umamin

diff --git a/apps/web/src/schema/global-message/global-message.resolvers.ts b/apps/web/src/schema/global-message/global-message.resolvers.ts index b38830f5..7e2fb41d 100644 --- a/apps/web/src/schema/global-message/global-message.resolvers.ts +++ b/apps/web/src/schema/global-message/global-message.resolvers.ts @@ -54,7 +54,7 @@ export class GlobalMessageResolver { return { data: messages, - cursorId: messages[messages.length - 1].id, + cursorId: messages[messages.length - 1].userId, }; } catch (err) { console.log(err); @@ -66,14 +66,14 @@ export class GlobalMessageResolver { @Mutation(() => SendGlobalMessage) async sendGlobalMessage( @Arg('input', () => SendGlobalMessageInput) - { content, isAnonymous }: SendGlobalMessageInput, - @Ctx() { prisma, id }: TContext + { userId, content, isAnonymous }: SendGlobalMessageInput, + @Ctx() { prisma }: TContext ): Promise { let latestMessage: Omit | null; try { latestMessage = await prisma.globalMessage.findFirst({ - where: { userId: id }, + where: { userId }, orderBy: { updatedAt: 'desc' }, }); @@ -99,7 +99,7 @@ export class GlobalMessageResolver { data: { content, isAnonymous, - user: id ? { connect: { id } } : undefined, + user: userId ? { connect: { id: userId } } : undefined, }, include: { user: { @@ -117,7 +117,7 @@ export class GlobalMessageResolver { data: { content, isAnonymous, - user: id ? { connect: { id } } : undefined, + user: userId ? { connect: { id: userId } } : undefined, }, include: { user: { diff --git a/apps/web/src/schema/global-message/global-message.types.ts b/apps/web/src/schema/global-message/global-message.types.ts index c4a09974..3701b571 100644 --- a/apps/web/src/schema/global-message/global-message.types.ts +++ b/apps/web/src/schema/global-message/global-message.types.ts @@ -53,6 +53,9 @@ export class SendGlobalMessage extends ErrorResponse { @InputType() export class SendGlobalMessageInput { + @Field(() => ID) + userId: string; + @IsNotEmpty() @MinLength(1) @MaxLength(500) diff --git a/apps/web/src/schema/message/message.resolvers.ts b/apps/web/src/schema/message/message.resolvers.ts index 872869e7..3b582133 100644 --- a/apps/web/src/schema/message/message.resolvers.ts +++ b/apps/web/src/schema/message/message.resolvers.ts @@ -22,7 +22,8 @@ export class MessageResolver { ): Promise { try { const messages = await prisma.message.findMany({ - where: type === 'recent' ? { receiverId: userId } : { senderId: userId }, + where: + type === 'recent' ? { receiverId: userId } : { senderId: userId }, orderBy: { createdAt: 'desc' }, take: 5, select: { @@ -65,8 +66,8 @@ export class MessageResolver { @Mutation(() => String) async sendMessage( @Arg('input', () => SendMessageInput) - { clue, content, receiverMsg, receiverUsername }: SendMessageInput, - @Ctx() { prisma, id }: TContext + { userId, clue, content, receiverMsg, receiverUsername }: SendMessageInput, + @Ctx() { prisma }: TContext ): Promise { try { const message = await prisma.message.create({ @@ -74,7 +75,7 @@ export class MessageResolver { clue, content, receiverMsg, - sender: id ? { connect: { id } } : undefined, + sender: userId ? { connect: { id: userId } } : undefined, receiver: { connect: { username: receiverUsername } }, receiverUsername, }, diff --git a/apps/web/src/schema/message/message.types.ts b/apps/web/src/schema/message/message.types.ts index df2aee12..62e167b3 100644 --- a/apps/web/src/schema/message/message.types.ts +++ b/apps/web/src/schema/message/message.types.ts @@ -37,6 +37,9 @@ export class MessagesData { @InputType() export class SendMessageInput { + @Field(() => ID) + userId: string; + @IsNotEmpty() @MinLength(1) @MaxLength(200) diff --git a/apps/web/src/schema/user/user.resolvers.ts b/apps/web/src/schema/user/user.resolvers.ts index f2166913..1c9ab06f 100644 --- a/apps/web/src/schema/user/user.resolvers.ts +++ b/apps/web/src/schema/user/user.resolvers.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { Resolver, Query, Mutation, Arg, Ctx } from 'type-graphql'; +import { Resolver, Query, Mutation, Arg, Ctx, ID } from 'type-graphql'; import { hashPassword } from '@/utils/helpers'; import type { TContext } from '@/pages/api/graphql'; @@ -69,12 +69,13 @@ export class UserResolver { @Mutation(() => ErrorResponse) async editUserMessage( + @Arg('userId', () => ID) userId: string, @Arg('message', () => String) message: string, - @Ctx() { prisma, id }: TContext + @Ctx() { prisma }: TContext ): Promise { try { await prisma.user.update({ - where: { id }, + where: { id: userId }, data: { message }, }); @@ -87,8 +88,9 @@ export class UserResolver { @Mutation(() => ErrorResponse) async editUsername( + @Arg('userId', () => ID) userId: string, @Arg('username', () => String) username: string, - @Ctx() { prisma, id }: TContext + @Ctx() { prisma }: TContext ): Promise { const usernameRegex = /^[a-zA-Z0-9]+$/; @@ -104,7 +106,7 @@ export class UserResolver { } await prisma.user.update({ - where: { id }, + where: { id: userId }, data: { username }, }); @@ -117,18 +119,19 @@ export class UserResolver { @Mutation(() => ErrorResponse) async changePassword( + @Arg('userId', () => ID) userId: string, @Arg('newPassword', () => String) newPassword: string, - @Ctx() { prisma, id }: TContext + @Ctx() { prisma }: TContext ): Promise { const hashedPassword = hashPassword(newPassword); try { await prisma.user.findUnique({ - where: { id }, + where: { id: userId }, }); await prisma.user.update({ - where: { id }, + where: { id: userId }, data: { password: hashedPassword, }, @@ -142,10 +145,13 @@ export class UserResolver { } @Mutation(() => ErrorResponse) - async deleteUser(@Ctx() { prisma, id }: TContext): Promise { + async deleteUser( + @Arg('userId', () => ID) userId: string, + @Ctx() { prisma }: TContext + ): Promise { try { await prisma.user.delete({ - where: { id }, + where: { id: userId }, }); return { error: null }; diff --git a/packages/generated/graphql/user.graphql b/packages/generated/graphql/user.graphql index 4c5b9a49..a2c00d53 100644 --- a/packages/generated/graphql/user.graphql +++ b/packages/generated/graphql/user.graphql @@ -15,26 +15,26 @@ mutation createUser($username: String!, $password: String!) { } } -mutation editUsername($username: String!) { - editUsername(username: $username) { +mutation editUsername($userId: ID!, $username: String!) { + editUsername(userId: $userId, username: $username) { error } } -mutation editUserMessage($message: String!) { - editUserMessage(message: $message) { - error +mutation editUserMessage($userId: ID!, $message: String!) { + editUserMessage(userId: $userId, message: $message) { + error } } -mutation changePassword($newPassword: String!) { - changePassword(newPassword: $newPassword) { +mutation changePassword($userId: ID!, $newPassword: String!) { + changePassword(userId: $userId, newPassword: $newPassword) { error } } -mutation deleteUser { - deleteUser { +mutation deleteUser($userId: ID!) { + deleteUser(userId: $userId) { error } } diff --git a/packages/generated/index.ts b/packages/generated/index.ts index b0323bfd..2624ee5c 100644 --- a/packages/generated/index.ts +++ b/packages/generated/index.ts @@ -85,6 +85,7 @@ export type MutationAddReplyArgs = { export type MutationChangePasswordArgs = { newPassword: Scalars['String']['input']; + userId: Scalars['ID']['input']; }; @@ -99,12 +100,19 @@ export type MutationDeleteMessageArgs = { }; +export type MutationDeleteUserArgs = { + userId: Scalars['ID']['input']; +}; + + export type MutationEditUserMessageArgs = { message: Scalars['String']['input']; + userId: Scalars['ID']['input']; }; export type MutationEditUsernameArgs = { + userId: Scalars['ID']['input']; username: Scalars['String']['input']; }; @@ -153,6 +161,7 @@ export type SendGlobalMessage = { export type SendGlobalMessageInput = { content: Scalars['String']['input']; isAnonymous: Scalars['Boolean']['input']; + userId: Scalars['ID']['input']; }; export type SendMessageInput = { @@ -160,6 +169,7 @@ export type SendMessageInput = { content: Scalars['String']['input']; receiverMsg: Scalars['String']['input']; receiverUsername: Scalars['String']['input']; + userId: Scalars['ID']['input']; }; export type User = { @@ -235,6 +245,7 @@ export type CreateUserMutationVariables = Exact<{ export type CreateUserMutation = { __typename?: 'Mutation', createUser: { __typename?: 'ErrorResponse', error?: string | null } }; export type EditUsernameMutationVariables = Exact<{ + userId: Scalars['ID']['input']; username: Scalars['String']['input']; }>; @@ -242,6 +253,7 @@ export type EditUsernameMutationVariables = Exact<{ export type EditUsernameMutation = { __typename?: 'Mutation', editUsername: { __typename?: 'ErrorResponse', error?: string | null } }; export type EditUserMessageMutationVariables = Exact<{ + userId: Scalars['ID']['input']; message: Scalars['String']['input']; }>; @@ -249,13 +261,16 @@ export type EditUserMessageMutationVariables = Exact<{ export type EditUserMessageMutation = { __typename?: 'Mutation', editUserMessage: { __typename?: 'ErrorResponse', error?: string | null } }; export type ChangePasswordMutationVariables = Exact<{ + userId: Scalars['ID']['input']; newPassword: Scalars['String']['input']; }>; export type ChangePasswordMutation = { __typename?: 'Mutation', changePassword: { __typename?: 'ErrorResponse', error?: string | null } }; -export type DeleteUserMutationVariables = Exact<{ [key: string]: never; }>; +export type DeleteUserMutationVariables = Exact<{ + userId: Scalars['ID']['input']; +}>; export type DeleteUserMutation = { __typename?: 'Mutation', deleteUser: { __typename?: 'ErrorResponse', error?: string | null } }; @@ -350,29 +365,29 @@ export const CreateUserDocument = gql` } `; export const EditUsernameDocument = gql` - mutation editUsername($username: String!) { - editUsername(username: $username) { + mutation editUsername($userId: ID!, $username: String!) { + editUsername(userId: $userId, username: $username) { error } } `; export const EditUserMessageDocument = gql` - mutation editUserMessage($message: String!) { - editUserMessage(message: $message) { + mutation editUserMessage($userId: ID!, $message: String!) { + editUserMessage(userId: $userId, message: $message) { error } } `; export const ChangePasswordDocument = gql` - mutation changePassword($newPassword: String!) { - changePassword(newPassword: $newPassword) { + mutation changePassword($userId: ID!, $newPassword: String!) { + changePassword(userId: $userId, newPassword: $newPassword) { error } } `; export const DeleteUserDocument = gql` - mutation deleteUser { - deleteUser { + mutation deleteUser($userId: ID!) { + deleteUser(userId: $userId) { error } } @@ -418,7 +433,7 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = changePassword(variables: ChangePasswordMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise { return withWrapper((wrappedRequestHeaders) => client.request(ChangePasswordDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'changePassword', 'mutation'); }, - deleteUser(variables?: DeleteUserMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise { + deleteUser(variables: DeleteUserMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise { return withWrapper((wrappedRequestHeaders) => client.request(DeleteUserDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'deleteUser', 'mutation'); } }; From b4ff2fc452d52beba28571c0ece1c5653df94119 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 13:17:40 +0800 Subject: [PATCH 20/22] fix: update global message id in cursor --- apps/web/src/schema/global-message/global-message.resolvers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/schema/global-message/global-message.resolvers.ts b/apps/web/src/schema/global-message/global-message.resolvers.ts index 7e2fb41d..78213cbc 100644 --- a/apps/web/src/schema/global-message/global-message.resolvers.ts +++ b/apps/web/src/schema/global-message/global-message.resolvers.ts @@ -54,7 +54,7 @@ export class GlobalMessageResolver { return { data: messages, - cursorId: messages[messages.length - 1].userId, + cursorId: messages[messages.length - 1].id, }; } catch (err) { console.log(err); From a511013d384b4f7e99409c64c4dd9abc4662e0c1 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Mon, 8 Apr 2024 13:30:59 +0800 Subject: [PATCH 21/22] fix: update index in global message --- apps/web/prisma/dev.db | Bin 90112 -> 94208 bytes apps/web/prisma/dev.db-journal | Bin 8720 -> 12824 bytes apps/web/prisma/schema.prisma | 3 ++- 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/prisma/dev.db b/apps/web/prisma/dev.db index 4eea6b724bd8f3927887b7e0bd3a28da4738333c..c5600955037ab5b63aaacd6d0d555f2d33f50abb 100644 GIT binary patch delta 411 zcmZoTz}oPDb%L~@2m=FyI1s~t@I)PB9uWq;v{$_RKN!RqohD{$F`ood3s+e*vWT&Z zJF7D`YG>x9q*l1+NO_@)*YC#I*ymlmWXmZYXQmc(bKph}5Pe#j_0nUzUd0;WVs z!NoP$S+h)(UECIEoap2=j8c;?Fq%x}V^Y}cz;uL{gNg3~1AhVEh0THjNBHU+Wtq4_ z8+loS85meO4U7^k4Gc|^bS+bp%ydmG%`J5;(hN;?4U#O3jZ)1_j8YO)(u@pEQxZ)~ zQ!FggQVb0ejf{;KjQ!`TovqVcn zgEYpzJ$m<@jSP%T3``6x6b(#`ERBug6H`*+)4`sO&n-@m2L}R3<-O;V3*@J8F!8Tv n;9t*wW3!;bVtySB=1@jroXVum96Gs1UbV?!nE|80A_oBglSFd} delta 176 zcmZp8z}j$tb%L~@00RSq7!bpNz(gHm9svfuv{$_RKNv(A7fsC8VqCOYP=JR~xlu-x zT|7{ovC%g(FD13YJtsdYF~>KxxHvIAHNLbswa7DNavY=d`5? NHS(%W2FnZ>4FJv$FqQxS diff --git a/apps/web/prisma/dev.db-journal b/apps/web/prisma/dev.db-journal index 7fccf9db48101d19f3190830ab54335d216e9032..6e9f97fd8d041c623c1c0dbd93ec9f9ff58703dc 100644 GIT binary patch literal 12824 zcmeHM&2QsG6p#B6x7lXf{m5FPNNX&lZp5awoo^u|vTdjWO}cFp*hL^~VvoC4^M&m! ztq?-#E_>X60f`HDI3OXeaN>Xv+9M|n=#iD!G9#Bs7La9S}|lX&L6dG9yB_vX#m zjYR16KWAVr4g}0yd=gph!56(K1C#;E0A+wOKpCJ6PzERilmW^BWq>m9Trn`<=3ZPxWm96akd|>SBWp<0WhtwnOjautbxjhHoR%{M zF^wfH@3iDR7R6jn&C0TxYv!^zCyNDD&E~RV4izO)mqj@vX2gP+m5XUvL7Jub_Rmbzd`8v1OrStn@8xRy3vG(~ym|lC2opX+Y!J_F=hHFY}e! zPWcWm1Y}c33;cd za73O6!uq>W9w?#(a7NZ0NJ9rcq}Uafs{o|e0+1{WujL%JhWZX$#OT%OfToX`gyU;X z1+#gX-q zhc`q3YXBUQ#>J^VpUs4ah3EpMzC(vq|9DFF(ve@xAVmw^1I0U|4zEkIG`|xS( z?eVt{E7j8BUH+}|-J71yu#!OKfht?CRLdjvo$?!{#$KJ@ZX6z#Yjwqu9@R_L+hp)~ zC7m4X+wXR4s16fAh|sV~oo?r>-R)Zfe`|k#uUx8yz1wCV`wm^EJ!7$C@j{fVZZHuy z7}f_ZI0h)FZ+G3c65vab0?m~NFD$X#`a1LIf=e_hq2y;dNUmSBpBq~Jy`^d$&*FW* zhdUV3VKA=$G8z<(ru|-e-5O_(5Be6z#SY8 z70ZTGvj+th^}^E@HJO|uk(zuGrVsDg@Zz=E?;yGPui zUaw_ Date: Mon, 8 Apr 2024 13:52:05 +0800 Subject: [PATCH 22/22] chore: add migrations for global index --- .../20240408052932_add_global_msg_index/migration.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 apps/web/prisma/migrations/20240408052932_add_global_msg_index/migration.sql diff --git a/apps/web/prisma/migrations/20240408052932_add_global_msg_index/migration.sql b/apps/web/prisma/migrations/20240408052932_add_global_msg_index/migration.sql new file mode 100644 index 00000000..0c99db31 --- /dev/null +++ b/apps/web/prisma/migrations/20240408052932_add_global_msg_index/migration.sql @@ -0,0 +1,8 @@ +-- DropIndex +DROP INDEX "GlobalMessage_userId_updatedAt_idx"; + +-- CreateIndex +CREATE INDEX "GlobalMessage_userId_idx" ON "GlobalMessage"("userId"); + +-- CreateIndex +CREATE INDEX "GlobalMessage_updatedAt_idx" ON "GlobalMessage"("updatedAt" DESC);