-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: api fetch prompts by commit and path
This commit tweaks queries and implements an example on how to find a prompt by path and commit uuid. It also removes unnecessary table documentSnapshots.
- Loading branch information
Showing
52 changed files
with
2,420 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import EnvVars from '@src/common/EnvVars' | ||
import EnvVars from '$src/common/EnvVars' | ||
|
||
import server from './server' | ||
|
||
const SERVER_START_MSG = 'Express server started on port: ' + EnvVars.PORT | ||
|
||
server.listen(EnvVars.PORT, () => console.info(SERVER_START_MSG)) | ||
server.listen(EnvVars.PORT, () => { | ||
console.info(SERVER_START_MSG) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Paths from '$src/common/Paths' | ||
import { Router } from 'express' | ||
|
||
import { promptRoute } from './routes' | ||
|
||
const router = Router() | ||
|
||
router.get(Paths.Api.V1.Commits.Prompt, promptRoute) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { materializeDocumentsAtCommit, Node, toTree } from '@latitude-data/core' | ||
import HttpStatusCodes from '$src/common/HttpStatusCodes' | ||
import { BadRequestError, NotFoundError } from '$core/lib/errors' | ||
import { Request, Response } from 'express' | ||
|
||
function findNode({ rootNode, path }: { rootNode: Node; path: string }) { | ||
const pathParts = path.split('/') | ||
|
||
let currentNode = rootNode | ||
let currentPart = pathParts.shift() | ||
while (currentPart) { | ||
const child = currentNode.children.find( | ||
// NOTE: sanitaze name before comparing | ||
(child) => child.doc?.name === currentPart, | ||
) | ||
if (!child) return null | ||
|
||
currentNode = child | ||
currentPart = pathParts.shift() | ||
} | ||
|
||
return currentNode | ||
} | ||
|
||
export async function promptRoute(req: Request, res: Response) { | ||
const commitUuid = req.params.commitUuid | ||
const path = req.params[0] | ||
if (!path) throw new BadRequestError('Invalid prompt path') | ||
|
||
const result = await materializeDocumentsAtCommit({ commitUuid: commitUuid! }) | ||
const rootNode = toTree(result.unwrap()) | ||
const node = findNode({ rootNode, path }) | ||
|
||
if (!node) { | ||
throw new NotFoundError('Prompt not found') | ||
} else { | ||
return res.status(HttpStatusCodes.OK).json(node.doc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import Paths from '@src/common/Paths' | ||
import Paths from '$src/common/Paths' | ||
import { Router } from 'express' | ||
|
||
import chatRouter from './chat' | ||
import commitsRouter from './commits' | ||
|
||
const router = Router() | ||
|
||
router.use(Paths.Api.V1.Chat.Base, chatRouter) | ||
router.use(Paths.Api.V1.Commits.Base, commitsRouter) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use server' | ||
|
||
import { createCommit } from '@latitude-data/core' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const createCommitAction = withProject | ||
.createServerAction() | ||
.handler(async ({ input }) => { | ||
const result = await createCommit({ projectId: input.projectId }) | ||
return result.unwrap() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use server' | ||
|
||
import { listCommits } from '@latitude-data/core' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const getCommitsAction = withProject | ||
.createServerAction() | ||
.handler(() => listCommits()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use server' | ||
|
||
import { materializeDocumentsAtCommit } from '@latitude-data/core' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const getDocumentsAtCommitAction = withProject | ||
.createServerAction() | ||
.input(z.object({ commitUuid: z.string() })) | ||
.handler(async ({ input }) => { | ||
const result = await materializeDocumentsAtCommit({ | ||
commitUuid: input.commitUuid, | ||
}) | ||
|
||
return result.unwrap() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { DocumentVersion, toTree } from '@latitude-data/core' | ||
|
||
export function useTree({ documents }: { documents: DocumentVersion[] }) { | ||
return useMemo(() => toTree(documents), [documents]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,14 @@ | ||
import { materializeDocumentsAtCommit } from '@latitude-data/core' | ||
import { listCommits, materializeDocumentsAtCommit } from '@latitude-data/core' | ||
|
||
import DocumentTree, { CreateNode } from './DocumentTree' | ||
import DocumentTree from './DocumentTree' | ||
|
||
export default async function Sidebar({ | ||
commitUuid, | ||
projectId, | ||
}: { | ||
commitUuid: string | ||
projectId: number | ||
}) { | ||
const documentsResult = await materializeDocumentsAtCommit({ | ||
projectId, | ||
export default async function Sidebar({ commitUuid }: { commitUuid: string }) { | ||
const docsResult = await materializeDocumentsAtCommit({ | ||
commitUuid, | ||
}) | ||
const documents = documentsResult.unwrap() | ||
|
||
return ( | ||
<div className='flex flex-col gap-4 p-4'> | ||
<div className='flex flex-row align-items justify-between'> | ||
<h2>Prompts</h2> | ||
<div className='flex flex-row gap-2 align-items'> | ||
<CreateNode /> | ||
</div> | ||
</div> | ||
<DocumentTree documents={documents} /> | ||
</div> | ||
) | ||
// TODO: wrap data-access reads in transaction blocks and make use of result | ||
const commits = await listCommits() | ||
|
||
return <DocumentTree commits={commits} documents={docsResult.unwrap()} /> | ||
} |
Oops, something went wrong.