Skip to content

Commit 0efab52

Browse files
committed
fix: commit repository method wrong types
1 parent 2f77ec7 commit 0efab52

File tree

27 files changed

+90
-133
lines changed

27 files changed

+90
-133
lines changed

apps/gateway/src/common/documents/getData.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ export async function publishDocumentRunRequestedEvent({
234234
const user = await findFirstUserInWorkspace(workspace)
235235

236236
const commitsScope = new CommitsRepository(workspace.id)
237-
const headCommit = await commitsScope
238-
.getHeadCommit(project.id)
239-
.then((r) => r.unwrap())
237+
const headCommit = await commitsScope.getHeadCommit(project.id)
240238

241239
if (user) {
242240
publisher.publishLater({

apps/gateway/src/routes/api/v3/projects/versions/get/getCommit.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BadRequestError } from '@latitude-data/constants/errors'
44
import { AppRouteHandler } from '$/openApi/types'
55
import { getVersionRoute } from './getCommit.route'
66

7-
// @ts-expect-error: broken types
7+
// @ts-expect-error: Types are not working as expected
88
export const getVersionHandler: AppRouteHandler<
99
typeof getVersionRoute
1010
> = async (c: Context) => {

apps/gateway/src/routes/webhook/integration/webhook.handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ async function resolveWorkspaceAndCommit(
4343
return Result.ok({ workspace, commit })
4444
}
4545

46-
const headCommitResult = await commitsRepo.getHeadCommit(rawTrigger.projectId)
47-
const commit = headCommitResult.unwrap()
46+
const commit = await commitsRepo.getHeadCommit(rawTrigger.projectId)
4847
if (!commit) {
4948
return Result.error(
5049
new NotFoundError(

apps/web/src/actions/sdk/runDocumentAction.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export async function runDocumentAction({
3333
const { workspace, user } = await getCurrentUserOrRedirect()
3434

3535
const commitsScope = new CommitsRepository(workspace.id)
36-
const headCommit = await commitsScope
37-
.getHeadCommit(projectId)
38-
.then((r) => r.unwrap())
36+
const headCommit = await commitsScope.getHeadCommit(projectId)
3937

4038
publisher.publishLater({
4139
type: 'documentRunRequested',

apps/web/src/app/(private)/_data-access/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ export const getHeadCommitCached = cache(
179179
projectId: number
180180
}) => {
181181
const commitsScope = new CommitsRepository(workspace.id)
182-
const headCommitResult = await commitsScope.getHeadCommit(projectId)
183-
return headCommitResult.value
182+
return await commitsScope.getHeadCommit(projectId)
184183
},
185184
)
186185

apps/web/src/app/api/documents/[documentUuid]/run/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ export const POST = errorHandler(
6565
).then((r) => r.unwrap())
6666

6767
const commitsScope = new CommitsRepository(workspace.id)
68-
const headCommit = await commitsScope
69-
.getHeadCommit(projectId)
70-
.then((r) => r.unwrap())
68+
const headCommit = await commitsScope.getHeadCommit(projectId)
7169

7270
// Publish document run event
7371
publisher.publishLater({

packages/core/src/lib/analytics/AnalyticsClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class AnalyticsClient {
7878

7979
const repo = new WorkspacesRepository(user.id)
8080

81-
// TODO: remove, it's very expensive to have a read operation on each analytics event
81+
// TODO: remove, it's very expensive to have a read operation on each analytics event
8282
const result = await repo.find(this.workspaceId)
8383

8484
if (result.error) return undefined

packages/core/src/repositories/commitsRepository/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@ export class CommitsRepository extends RepositoryLegacy<
7171
return Result.error(new NotFoundError('Project ID is required'))
7272
}
7373

74-
const headCommit = await this.getHeadCommit(projectId).then((r) =>
75-
r.unwrap(),
76-
)
77-
if (!headCommit) {
74+
const headCommit = await this.getHeadCommit(projectId)
75+
if (!headCommit)
7876
return Result.error(new NotFoundError('Head commit not found'))
79-
}
8077

8178
return Result.ok(headCommit)
8279
}

packages/core/src/repositories/commitsRepository/utils/getHeadCommit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { and, desc, eq, isNotNull } from 'drizzle-orm'
22

33
import { database } from '../../../client'
44
import { InferedReturnType } from '../../../lib/commonTypes'
5-
import { Result } from '../../../lib/Result'
65
import { buildCommitsScope } from './buildCommitsScope'
6+
import { Commit } from '../../../browser'
77

88
export async function getHeadCommitForProject(
99
{
@@ -27,5 +27,5 @@ export async function getHeadCommitForProject(
2727
.orderBy(desc(commitsScope.mergedAt))
2828
.limit(1)
2929

30-
return Result.ok(result[0])
30+
return result[0] as Commit | undefined
3131
}

packages/core/src/services/actions/cloneAgent.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ async function getSampleAgent(
113113
}
114114

115115
const commitsRepository = new CommitsRepository(workspace.id, db)
116-
const gettingco = await commitsRepository.getHeadCommit(project.id)
117-
if (gettingco.error) {
118-
return Result.error(gettingco.error)
119-
}
120-
const commit = gettingco.unwrap()
116+
const commit = await commitsRepository.getHeadCommit(project.id)
121117
if (!commit) {
122118
return Result.error(
123119
new UnprocessableEntityError('Sample Agents commit not found'),

0 commit comments

Comments
 (0)