diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 00000000..30a613ef --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,6 @@ +.encore +encore.gen.go +encore.gen.cue +/.encore +node_modules +/encore.gen diff --git a/api/api/api.ts b/api/api/api.ts new file mode 100644 index 00000000..e4b52d6c --- /dev/null +++ b/api/api/api.ts @@ -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 + // 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 + // console.log(globalGroupId) + // console.log(worker) + // console.log("runs..") + + const topicContent = { + links: [] + } + return topicContent + } +) diff --git a/api/api/links.ts b/api/api/links.ts new file mode 100644 index 00000000..ccb4f5c3 --- /dev/null +++ b/api/api/links.ts @@ -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 => { + // 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" + } + } +) diff --git a/api/bun.lockb b/api/bun.lockb new file mode 100755 index 00000000..470f8e98 Binary files /dev/null and b/api/bun.lockb differ diff --git a/api/encore.app b/api/encore.app new file mode 100644 index 00000000..a95572f9 --- /dev/null +++ b/api/encore.app @@ -0,0 +1,4 @@ +{ + "id": "encore-test-76k2", + "lang": "typescript" +} diff --git a/api/package.json b/api/package.json new file mode 100644 index 00000000..b0d34260 --- /dev/null +++ b/api/package.json @@ -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" + } +} diff --git a/api/readme.md b/api/readme.md new file mode 100644 index 00000000..437b2b1c --- /dev/null +++ b/api/readme.md @@ -0,0 +1 @@ +Using [Encore](https://encore.dev). diff --git a/api/tsconfig.json b/api/tsconfig.json new file mode 100644 index 00000000..ffe650c7 --- /dev/null +++ b/api/tsconfig.json @@ -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 + } +} diff --git a/bun.lockb b/bun.lockb index b2cb3516..84e6f77a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index f3eee142..372187e9 100644 --- a/package.json +++ b/package.json @@ -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" }