,
collapsedState: CollapsedState,
- replyTree: ImmutableReplyTree,
+ replyTree: ReplyTree,
): CollapsedState {
// go down the tree along the path
// and collapse all siblings on the way.
diff --git a/app/routes/quote+/$quoteId.tsx b/app/routes/quote+/$quoteId.tsx
index b9beb8e4..ecc39edd 100644
--- a/app/routes/quote+/$quoteId.tsx
+++ b/app/routes/quote+/$quoteId.tsx
@@ -13,7 +13,7 @@ import {
TabsList,
TabsTrigger,
} from '#app/components/ui/tabs.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { getArtefact } from '#app/modules/claims/artefact-repository.ts'
import { getClaims } from '#app/modules/claims/claim-repository.ts'
import {
@@ -24,8 +24,8 @@ import {
} from '#app/modules/claims/claim-types.ts'
import { getQuoteFallacies } from '#app/modules/claims/quote-fallacy-repository.ts'
import { getQuote } from '#app/modules/claims/quote-repository.ts'
-import { getPollPost } from '#app/modules/posts/polls/poll-repository.ts'
-import { type Poll, PollType } from '#app/modules/posts/post-types.ts'
+import { getFrontPagePoll } from '#app/modules/posts/polls/poll-repository.ts'
+import { type FrontPagePoll, PollType } from '#app/modules/posts/post-types.ts'
import { isValidTweetUrl } from '#app/utils/twitter-utils.ts'
import { useOptionalUser } from '#app/utils/user.ts'
@@ -44,7 +44,7 @@ export async function loader({ params }: LoaderFunctionArgs) {
artefact: Artefact
quote: Quote
claims: Claim[]
- posts: Poll[]
+ posts: FrontPagePoll[]
quoteFallacies: QuoteFallacy[]
} = await db.transaction().execute(async trx => {
const claims = await getClaims(trx, quoteId)
@@ -53,7 +53,7 @@ export async function loader({ params }: LoaderFunctionArgs) {
.map(claim => claim.postId!) // eslint-disable-line @typescript-eslint/no-non-null-assertion
const posts = await Promise.all(
submittedClaimsPostIds.map(
- async postId => await getPollPost(trx, postId),
+ async postId => await getFrontPagePoll(trx, postId),
),
)
const quoteFallacies = await getQuoteFallacies(trx, quoteId)
@@ -301,7 +301,7 @@ function QuotePollPost({
post,
className,
}: {
- post: Poll
+ post: FrontPagePoll
className?: string
}) {
const ageString = moment(post.createdAt).fromNow()
diff --git a/app/routes/resources+/healthcheck.tsx b/app/routes/resources+/healthcheck.tsx
index 8cd3064a..36b2da8c 100644
--- a/app/routes/resources+/healthcheck.tsx
+++ b/app/routes/resources+/healthcheck.tsx
@@ -1,6 +1,6 @@
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import { type LoaderFunctionArgs } from '@remix-run/node'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
export async function loader({ request }: LoaderFunctionArgs) {
const host =
diff --git a/app/routes/settings+/profile.change-email.tsx b/app/routes/settings+/profile.change-email.tsx
index e79a7f34..bdd20809 100644
--- a/app/routes/settings+/profile.change-email.tsx
+++ b/app/routes/settings+/profile.change-email.tsx
@@ -14,7 +14,7 @@ import { z } from 'zod'
import { ErrorList, Field } from '#app/components/forms.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import {
prepareVerification,
requireRecentVerification,
diff --git a/app/routes/settings+/profile.index.tsx b/app/routes/settings+/profile.index.tsx
index 0515d616..6881dc60 100644
--- a/app/routes/settings+/profile.index.tsx
+++ b/app/routes/settings+/profile.index.tsx
@@ -12,7 +12,7 @@ import { z } from 'zod'
import { ErrorList, Field } from '#app/components/forms.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { requireUserId, sessionKey } from '#app/utils/auth.server.ts'
import { validateCSRF } from '#app/utils/csrf.server.ts'
import { invariantResponse, useDoubleCheck } from '#app/utils/misc.tsx'
diff --git a/app/routes/settings+/profile.password.tsx b/app/routes/settings+/profile.password.tsx
index 20dcf17e..b888b805 100644
--- a/app/routes/settings+/profile.password.tsx
+++ b/app/routes/settings+/profile.password.tsx
@@ -14,7 +14,7 @@ import { ErrorList, Field } from '#app/components/forms.tsx'
import { Button } from '#app/components/ui/button.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import {
getPasswordHash,
requireUserId,
diff --git a/app/routes/settings+/profile.password_.create.tsx b/app/routes/settings+/profile.password_.create.tsx
index ef80253d..09d56473 100644
--- a/app/routes/settings+/profile.password_.create.tsx
+++ b/app/routes/settings+/profile.password_.create.tsx
@@ -12,7 +12,7 @@ import { ErrorList, Field } from '#app/components/forms.tsx'
import { Button } from '#app/components/ui/button.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { getPasswordHash, requireUserId } from '#app/utils/auth.server.ts'
import { useIsPending } from '#app/utils/misc.tsx'
import { PasswordAndConfirmPasswordSchema } from '#app/utils/user-validation.ts'
diff --git a/app/routes/settings+/profile.tsx b/app/routes/settings+/profile.tsx
index 2485ed38..9351fbd0 100644
--- a/app/routes/settings+/profile.tsx
+++ b/app/routes/settings+/profile.tsx
@@ -3,7 +3,7 @@ import { json, type LoaderFunctionArgs } from '@remix-run/node'
import { Outlet } from '@remix-run/react'
import { z } from 'zod'
import { Icon } from '#app/components/ui/icon.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { requireUserId } from '#app/utils/auth.server.ts'
import { invariantResponse } from '#app/utils/misc.tsx'
diff --git a/app/routes/settings+/profile.two-factor.disable.tsx b/app/routes/settings+/profile.two-factor.disable.tsx
index e6e33b05..07c8c49d 100644
--- a/app/routes/settings+/profile.two-factor.disable.tsx
+++ b/app/routes/settings+/profile.two-factor.disable.tsx
@@ -8,7 +8,7 @@ import { useFetcher } from '@remix-run/react'
import { AuthenticityTokenInput } from 'remix-utils/csrf/react'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { requireRecentVerification } from '#app/routes/_auth+/verify.tsx'
import { requireUserId } from '#app/utils/auth.server.ts'
import { validateCSRF } from '#app/utils/csrf.server.ts'
diff --git a/app/routes/settings+/profile.two-factor.index.tsx b/app/routes/settings+/profile.two-factor.index.tsx
index d1cbee9d..944f0889 100644
--- a/app/routes/settings+/profile.two-factor.index.tsx
+++ b/app/routes/settings+/profile.two-factor.index.tsx
@@ -10,7 +10,7 @@ import { Link, useFetcher, useLoaderData } from '@remix-run/react'
import { AuthenticityTokenInput } from 'remix-utils/csrf/react'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { requireUserId } from '#app/utils/auth.server.ts'
import { validateCSRF } from '#app/utils/csrf.server.ts'
import { generateTOTP } from '#app/utils/totp.server.ts'
diff --git a/app/routes/settings+/profile.two-factor.verify.tsx b/app/routes/settings+/profile.two-factor.verify.tsx
index 65b85aeb..0769542f 100644
--- a/app/routes/settings+/profile.two-factor.verify.tsx
+++ b/app/routes/settings+/profile.two-factor.verify.tsx
@@ -19,7 +19,7 @@ import { z } from 'zod'
import { ErrorList, Field } from '#app/components/forms.tsx'
import { Icon } from '#app/components/ui/icon.tsx'
import { StatusButton } from '#app/components/ui/status-button.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { isCodeValid } from '#app/routes/_auth+/verify.tsx'
import { requireUserId } from '#app/utils/auth.server.ts'
import { validateCSRF } from '#app/utils/csrf.server.ts'
diff --git a/app/routes/stats.$postId.tsx b/app/routes/stats.$postId.tsx
index 699dbb4e..44d696f7 100644
--- a/app/routes/stats.$postId.tsx
+++ b/app/routes/stats.$postId.tsx
@@ -4,12 +4,12 @@ import invariant from 'tiny-invariant'
import { z } from 'zod'
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
import { Markdown } from '#app/components/markdown.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
+import { type DBEffect } from '#app/database/types.ts'
import { getStatsPost } from '#app/modules/posts/post-repository.ts'
import { type StatsPost } from '#app/modules/posts/post-types.ts'
import { getEffects } from '#app/modules/posts/scoring/effect-repository.ts'
import { relativeEntropy } from '#app/modules/posts/scoring/scoring-utils.ts'
-import { type DBEffect } from '#app/types/db-types.ts'
const postIdSchema = z.coerce.number()
diff --git a/app/routes/tag.$tagId.tsx b/app/routes/tag.$tagId.tsx
index 7e803c6d..d5788d73 100644
--- a/app/routes/tag.$tagId.tsx
+++ b/app/routes/tag.$tagId.tsx
@@ -1,6 +1,7 @@
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'
import { z } from 'zod'
+import { OpenDiscussionPreview } from '#app/components/building-blocks/open-discussion-preview.tsx'
import { PollPostPreview } from '#app/components/building-blocks/poll-post-preview.tsx'
import { Markdown } from '#app/components/markdown.tsx'
import {
@@ -9,12 +10,14 @@ import {
TabsList,
TabsTrigger,
} from '#app/components/ui/tabs.tsx'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { getPostsAndPollsByTagId } from '#app/modules/posts/post-service.ts'
-import { type FrontPagePost, type Poll } from '#app/modules/posts/post-types.ts'
+import {
+ type FrontPagePost,
+ type FrontPagePoll,
+} from '#app/modules/posts/post-types.ts'
import { getTagById } from '#app/modules/tags/tag-repository.ts'
import { type Tag } from '#app/modules/tags/tag-types.ts'
-import { TopLevelPost } from './discussions.tsx'
const tagIdSchema = z.coerce.number()
@@ -27,7 +30,7 @@ export async function loader({ params }: LoaderFunctionArgs) {
}: {
tag: Tag
posts: FrontPagePost[]
- polls: Poll[]
+ polls: FrontPagePoll[]
} = await db.transaction().execute(async trx => {
const tag = await getTagById(trx, tagId)
const { posts, polls } = await getPostsAndPollsByTagId(trx, tag.id)
@@ -76,7 +79,7 @@ export default function TagPage() {
{posts.map(post => {
return (
-
-}
-
-export type PostState = {
- criticalCommentId: number | null
- voteState: VoteState
- voteCount: number
- p: number | null
- effectOnTargetPost: Effect | null
- isDeleted: boolean
-}
-
-export type CommentTreeState = {
- targetPostId: number
- criticalCommentIdToTargetId: {
- [key: number]: number[]
- }
- posts: {
- [key: number]: PostState
- }
-}
-
-export type CollapsedState = {
- currentlyFocussedPostId: number | null
- hidePost: Immutable.Map
- hideChildren: Immutable.Map
-}
-
-export enum Direction {
- Up = 1,
- Down = -1,
- Neutral = 0,
-}
-
-export type VoteState = {
- postId: number
- vote: Direction
- isInformed: boolean
-}
diff --git a/app/types/db-types.ts b/app/types/db-types.ts
deleted file mode 100644
index 0e4d49f3..00000000
--- a/app/types/db-types.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { type Selectable, type Insertable } from 'kysely'
-import type * as schema from '#app/types/kysely-types.ts'
-
-// The types exported from kysely-types (which are generated from prisma.schema) are not used directly in app code.
-// Instead, Kysely wants values of type Selectable, Insertable, etc. This is because what fields are
-// required/optional depend on how the type is being used -- for example IDs are optional when inserting but required
-// when selecting. Now, since it is the Selectable type, which has all fields that should exist in a DB record, that we
-// will generally want to use in App code, for convenience we export all of these in this file.
-
-export type DBUser = Selectable
-export type DBPost = Selectable
-export type DBPassword = Selectable
-export type DBPostStats = Selectable
-export type DBVerification = Selectable
-export type DBScore = Selectable
-export type DBFullScore = Selectable
-export type DBLineage = Selectable
-export type DBEffect = Selectable
-export type DBInsertableScore = Insertable
-export type DBVoteEvent = Selectable
-export type DBVote = Selectable
-export type DBInsertableVoteEvent = Insertable
-export type DBHNItem = Selectable
diff --git a/app/utils/auth.server.ts b/app/utils/auth.server.ts
index d093c8cf..7a04d055 100644
--- a/app/utils/auth.server.ts
+++ b/app/utils/auth.server.ts
@@ -2,8 +2,8 @@ import { createId } from '@paralleldrive/cuid2'
import { redirect } from '@remix-run/node'
import bcrypt from 'bcryptjs'
import { safeRedirect } from 'remix-utils/safe-redirect'
-import { db } from '#app/db.ts'
-import { type DBPassword, type DBUser } from '#app/types/db-types.ts'
+import { db } from '#app/database/db.ts'
+import { type DBPassword, type DBUser } from '#app/database/types.ts'
import { combineHeaders, invariant } from './misc.tsx'
import { authSessionStorage } from './session.server.ts'
@@ -20,11 +20,6 @@ export async function getUserId(request: Request) {
const sessionId = authSession.get(sessionKey)
if (!sessionId) return null
- // const session = await prisma.session.findUnique({
- // select: { user: { select: { id: true } } },
- // where: { id: sessionId, expirationDate: { gt: new Date() } },
- // })
-
const session = await db
.selectFrom('Session')
.innerJoin('User', 'User.id', 'Session.userId')
diff --git a/app/utils/user.ts b/app/utils/user.ts
index 0aa96a37..187d963e 100644
--- a/app/utils/user.ts
+++ b/app/utils/user.ts
@@ -1,7 +1,7 @@
import { type SerializeFrom } from '@remix-run/node'
import { useRouteLoaderData } from '@remix-run/react'
+import { type User } from '#app/modules/auth/auth-types.ts'
import { type loader as rootLoader } from '#app/root.tsx'
-import { type User } from '#app/types/api-types.ts'
function isUser(user: any): user is SerializeFrom['user'] {
return user && typeof user === 'object' && typeof user.id === 'string'
diff --git a/import-hn.ts b/import-hn.ts
index ba72a88c..0e656e18 100644
--- a/import-hn.ts
+++ b/import-hn.ts
@@ -4,7 +4,7 @@ import zlib from 'zlib'
import * as cliProgress from 'cli-progress'
import { glob } from 'glob'
import TurndownService from 'turndown'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { createPost } from '#app/modules/posts/post-service.ts'
const turndownService = new TurndownService({ emDelimiter: '*' })
diff --git a/migrate.ts b/migrate.ts
index 24b3d1ae..32b605df 100644
--- a/migrate.ts
+++ b/migrate.ts
@@ -2,7 +2,7 @@ import { promises as fs } from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'
import { FileMigrationProvider, Migrator } from 'kysely'
-import { db } from './app/db.ts'
+import { db } from './app/database/db.ts'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
diff --git a/other/import-society-library-debatemap.ts b/other/import-society-library-debatemap.ts
index b3e1fc24..04011c15 100644
--- a/other/import-society-library-debatemap.ts
+++ b/other/import-society-library-debatemap.ts
@@ -1,5 +1,5 @@
import fs from 'fs'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { createPost } from '#app/modules/posts/post-service.ts'
import { invariant } from '../app/utils/misc.tsx'
diff --git a/other/replay-vote-events.ts b/other/replay-vote-events.ts
index 7e700f51..f9d91c75 100644
--- a/other/replay-vote-events.ts
+++ b/other/replay-vote-events.ts
@@ -1,6 +1,6 @@
import { sendVoteEvent } from '#app/modules/posts/scoring/global-brain-service.ts'
-import { db } from '../app/db.ts'
-import { type DBVoteEvent } from '../app/types/db-types.ts'
+import { db } from '../app/database/db.ts'
+import { type DBVoteEvent } from '../app/database/types.ts'
async function replayVoteEvents() {
console.log('Replaying vote events')
diff --git a/seed.ts b/seed.ts
index 8b1c874a..f51d6475 100644
--- a/seed.ts
+++ b/seed.ts
@@ -1,8 +1,8 @@
import bcrypt from 'bcryptjs'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { createPost } from '#app/modules/posts/post-service.ts'
+import { VoteDirection } from '#app/modules/posts/post-types.ts'
import { vote } from '#app/modules/posts/scoring/vote-service.ts'
-import { Direction } from '#app/types/api-types.ts'
import { getPasswordHash } from '#app/utils/auth.server.ts'
export async function seed() {
@@ -78,7 +78,7 @@ export async function seed() {
// And also downvotes
db.transaction().execute(
- async trx => await vote(trx, bob, post1, Direction.Down),
+ async trx => await vote(trx, bob, post1, VoteDirection.Down),
)
// And responds to bob's response
@@ -137,27 +137,27 @@ export async function seed() {
})
await db.transaction().execute(async trx => {
- await vote(trx, alice, post6, Direction.Down)
+ await vote(trx, alice, post6, VoteDirection.Down)
// agreed with 2 (shown 3)
- await vote(trx, charlie, post2, Direction.Up)
+ await vote(trx, charlie, post2, VoteDirection.Up)
// changed mind after seeing 2
- await vote(trx, charlie, post1, Direction.Down)
+ await vote(trx, charlie, post1, VoteDirection.Down)
// changed mind back (for no particular reason)
- await vote(trx, charlie, post1, Direction.Up)
+ await vote(trx, charlie, post1, VoteDirection.Up)
// duplicate vote
- await vote(trx, charlie, post1, Direction.Up)
+ await vote(trx, charlie, post1, VoteDirection.Up)
// changed mind back again
- await vote(trx, charlie, post1, Direction.Down)
+ await vote(trx, charlie, post1, VoteDirection.Down)
// and s some other votes
- await vote(trx, charlie, post1, Direction.Down)
- await vote(trx, charlie, post2, Direction.Down)
- await vote(trx, charlie, post2, Direction.Up)
+ await vote(trx, charlie, post1, VoteDirection.Down)
+ await vote(trx, charlie, post2, VoteDirection.Down)
+ await vote(trx, charlie, post2, VoteDirection.Up)
await vote(trx, charlie, 3, 1)
await vote(trx, charlie, 2, -1)
await vote(trx, bob, 6, -1)
diff --git a/tests/db-utils.ts b/tests/db-utils.ts
index 74afb926..81239690 100644
--- a/tests/db-utils.ts
+++ b/tests/db-utils.ts
@@ -3,7 +3,7 @@ import { faker } from '@faker-js/faker'
import bcrypt from 'bcryptjs'
import { UniqueEnforcer } from 'enforce-unique'
import { type Kysely, sql } from 'kysely'
-import { type DB } from '#app/types/kysely-types.ts' // this is the Database interface we defined earlier
+import { type DB } from '#app/database/types.ts'
const uniqueUsernameEnforcer = new UniqueEnforcer()
diff --git a/tests/setup/custom-matchers.ts b/tests/setup/custom-matchers.ts
index 3ed8b029..12ffbfe1 100644
--- a/tests/setup/custom-matchers.ts
+++ b/tests/setup/custom-matchers.ts
@@ -1,6 +1,6 @@
import * as setCookieParser from 'set-cookie-parser'
import { expect } from 'vitest'
-import { db } from '#app/db.ts'
+import { db } from '#app/database/db.ts'
import { sessionKey } from '#app/utils/auth.server.ts'
import { authSessionStorage } from '#app/utils/session.server.ts'
import {
diff --git a/tests/setup/db-setup.ts b/tests/setup/db-setup.ts
index 5b1a686d..04fac465 100644
--- a/tests/setup/db-setup.ts
+++ b/tests/setup/db-setup.ts
@@ -15,7 +15,7 @@ beforeAll(async () => {
// we *must* use dynamic imports here so the process.env.DATABASE_URL is set
// before prisma is imported and initialized
afterEach(async () => {
- const { db } = await import('#app/db.ts')
+ const { db } = await import('#app/database/db.ts')
await cleanupDb(db)
})