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

6
api/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
.encore
encore.gen.go
encore.gen.cue
/.encore
node_modules
/encore.gen

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"
}
}
)

BIN
api/bun.lockb Executable file

Binary file not shown.

4
api/encore.app Normal file
View File

@@ -0,0 +1,4 @@
{
"id": "encore-test-76k2",
"lang": "typescript"
}

22
api/package.json Normal file
View File

@@ -0,0 +1,22 @@
{
"name": "api",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"test": "vitest",
"dev": "encore run"
},
"devDependencies": {
"@types/node": "^20.5.7",
"typescript": "^5.2.2",
"vitest": "^1.5.0"
},
"dependencies": {
"encore.dev": "^1.35.3",
"jazz-nodejs": "^0.7.34"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.13.0"
}
}

1
api/readme.md Normal file
View File

@@ -0,0 +1 @@
Using [Encore](https://encore.dev).

31
api/tsconfig.json Normal file
View File

@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
/* Basic Options */
"lib": ["ES2022"],
"target": "ES2022",
"module": "ES2022",
"types": ["node"],
"paths": {
"~encore/*": ["./encore.gen/*"]
},
/* Workspace Settings */
"composite": true,
/* Strict Type-Checking Options */
"strict": true,
/* Module Resolution Options */
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"sourceMap": true,
"declaration": true,
/* Advanced Options */
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
}
}

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,35 +1,35 @@
{
"name": "learn-anything",
"scripts": {
"dev": "bun web",
"web": "cd web && bun dev",
"web:build": "bun run --filter '*' build",
"cli": "bun run --watch cli/run.ts",
"seed": "bun --watch cli/seed.ts",
"tauri": "tauri",
"app:build": "bun tauri build -b dmg -v"
},
"workspaces": [
"web"
],
"dependencies": {
"@tauri-apps/cli": "^2.0.0-rc.11",
"@tauri-apps/plugin-fs": "^2.0.0-rc.2",
"jazz-nodejs": "0.7.35-unique.2",
"react-icons": "^5.3.0"
},
"devDependencies": {
"bun-types": "^1.1.26"
},
"prettier": {
"plugins": [
"prettier-plugin-tailwindcss"
],
"useTabs": true,
"semi": false,
"trailingComma": "none",
"printWidth": 120,
"arrowParens": "avoid"
},
"license": "MIT"
"name": "learn-anything",
"scripts": {
"dev": "bun web",
"web": "cd web && bun dev",
"web:build": "bun run --filter '*' build",
"cli": "bun run --watch cli/run.ts",
"seed": "bun --watch cli/seed.ts",
"tauri": "tauri",
"app:build": "bun tauri build -b dmg -v"
},
"workspaces": [
"web"
],
"dependencies": {
"@tauri-apps/cli": "^2.0.0-rc.11",
"@tauri-apps/plugin-fs": "^2.0.0-rc.2",
"jazz-nodejs": "0.7.35-unique.2",
"react-icons": "^5.3.0"
},
"devDependencies": {
"bun-types": "^1.1.26"
},
"prettier": {
"plugins": [
"prettier-plugin-tailwindcss"
],
"useTabs": true,
"semi": false,
"trailingComma": "none",
"printWidth": 120,
"arrowParens": "avoid"
},
"license": "MIT"
}