mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-25 01:38:35 +02:00
Encore API setup (#139)
* first encore service * encore run * api * . * save link * link * . * try deploy * try * .
This commit is contained in:
6
api/.gitignore
vendored
Normal file
6
api/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.encore
|
||||||
|
encore.gen.go
|
||||||
|
encore.gen.cue
|
||||||
|
/.encore
|
||||||
|
node_modules
|
||||||
|
/encore.gen
|
||||||
62
api/api/api.ts
Normal file
62
api/api/api.ts
Normal 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
39
api/api/links.ts
Normal 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
BIN
api/bun.lockb
Executable file
Binary file not shown.
4
api/encore.app
Normal file
4
api/encore.app
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"id": "encore-test-76k2",
|
||||||
|
"lang": "typescript"
|
||||||
|
}
|
||||||
22
api/package.json
Normal file
22
api/package.json
Normal 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
1
api/readme.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Using [Encore](https://encore.dev).
|
||||||
31
api/tsconfig.json
Normal file
31
api/tsconfig.json
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
66
package.json
66
package.json
@@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
"name": "learn-anything",
|
"name": "learn-anything",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun web",
|
"dev": "bun web",
|
||||||
"web": "cd web && bun dev",
|
"web": "cd web && bun dev",
|
||||||
"web:build": "bun run --filter '*' build",
|
"web:build": "bun run --filter '*' build",
|
||||||
"cli": "bun run --watch cli/run.ts",
|
"cli": "bun run --watch cli/run.ts",
|
||||||
"seed": "bun --watch cli/seed.ts",
|
"seed": "bun --watch cli/seed.ts",
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"app:build": "bun tauri build -b dmg -v"
|
"app:build": "bun tauri build -b dmg -v"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"web"
|
"web"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/cli": "^2.0.0-rc.11",
|
"@tauri-apps/cli": "^2.0.0-rc.11",
|
||||||
"@tauri-apps/plugin-fs": "^2.0.0-rc.2",
|
"@tauri-apps/plugin-fs": "^2.0.0-rc.2",
|
||||||
"jazz-nodejs": "0.7.35-unique.2",
|
"jazz-nodejs": "0.7.35-unique.2",
|
||||||
"react-icons": "^5.3.0"
|
"react-icons": "^5.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bun-types": "^1.1.26"
|
"bun-types": "^1.1.26"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"prettier-plugin-tailwindcss"
|
"prettier-plugin-tailwindcss"
|
||||||
],
|
],
|
||||||
"useTabs": true,
|
"useTabs": true,
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"printWidth": 120,
|
"printWidth": 120,
|
||||||
"arrowParens": "avoid"
|
"arrowParens": "avoid"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user