Encore API setup (#139)

* first encore service

* encore run

* api

* .

* save link

* link

* .

* try deploy

* try

* .
This commit is contained in:
Nikita
2024-09-06 15:24:16 +03:00
committed by GitHub
parent be71156f3d
commit 924a683ed5
10 changed files with 198 additions and 33 deletions

62
api/api/api.ts Normal file
View File

@@ -0,0 +1,62 @@
import { api, APIError } from "encore.dev/api"
import { startWorker } from "jazz-nodejs"
import { ID } from "jazz-tools"
const JAZZ_WORKER_ACCOUNT_ID = process.env.JAZZ_WORKER_ACCOUNT_ID
const JAZZ_WORKER_SECRET = process.env.JAZZ_WORKER_SECRET
const JAZZ_PUBLIC_GLOBAL_GROUP = process.env.JAZZ_PUBLIC_GLOBAL_GROUP
// return all content for GlobalTopic
export const getTopic = api(
{ expose: true, method: "GET", path: "/topic/:topic" },
async ({
topic
}: {
topic: string
// TODO: can return type be inferred like Elysia?
}): Promise<{
links: {
label: string
url: string
}[]
}> => {
const { worker } = await startWorker({
accountID: "co_zhvp7ryXJzDvQagX61F6RCZFJB9",
accountSecret: JAZZ_WORKER_SECRET
})
// TODO: how to get the import from outside this package?
// const globalGroupId = process.env.JAZZ_PUBLIC_GLOBAL_GROUP as ID<any>
// const globalGroup = await PublicGlobalGroup.load(globalGroupId, worker, {
// root: {
// topics: [
// {
// latestGlobalGuide: {
// sections: [
// {
// links: [{}]
// }
// ]
// }
// }
// ],
// forceGraphs: [
// {
// connections: [{}]
// }
// ]
// }
// })
// if (!globalGroup) throw APIError.notFound("GlobalGroup not found")
// const globalGroupId = process.env.JAZZ_PUBLIC_GLOBAL_GROUP as ID<any>
// console.log(globalGroupId)
// console.log(worker)
// console.log("runs..")
const topicContent = {
links: []
}
return topicContent
}
)

39
api/api/links.ts Normal file
View File

@@ -0,0 +1,39 @@
// TODO: not sure if `links` should be separate service
// it is responsible for adding and getting links into LA from API
import { api, APIError } from "encore.dev/api"
import { startWorker } from "jazz-nodejs"
const JAZZ_WORKER_SECRET = process.env.JAZZ_WORKER_SECRET
export const addPersonalLink = api(
{ expose: true, method: "POST", path: "/save-link" },
async ({ url }: { url: string }): Promise<void> => {
// const { worker } = await startWorker({
// accountID: "co_zhvp7ryXJzDvQagX61F6RCZFJB9",
// accountSecret: JAZZ_WORKER_SECRET
// })
}
)
export const getLinkDetails = api(
{ expose: true, method: "GET", path: "/global-link-details/:url" },
async ({
url
}: {
url: string
}): Promise<{
title: string
summary?: string
}> => {
// const { worker } = await startWorker({
// accountID: "co_zhvp7ryXJzDvQagX61F6RCZFJB9",
// accountSecret: JAZZ_WORKER_SECRET
// })
return {
title: "Jazz",
summary: "Jazz is local first framework for building web apps"
}
}
)