-
Notifications
You must be signed in to change notification settings - Fork 1
fix(registry): 为 Hono Context 声明 AuthVariables 类型,消除 genes API 的 Type… #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # cccc 分支 PR 描述(合并时请复制到 GitHub PR 正文) | ||
|
|
||
| --- | ||
|
|
||
| 在 GitHub 创建 PR 时,将下方「PR 正文」整段复制到描述框。PR 合并后,正文中的 6 个 `Closes #N` 会使对应 Issue 自动关闭。 | ||
|
|
||
| --- | ||
|
|
||
| ## PR 正文(复制以下内容) | ||
|
|
||
| ### 概述 | ||
|
|
||
| 本 PR 包含 Web 端错误态与 emoji 替换、Python SDK 最小可用实现、Registry Context 类型修复等改动。 | ||
|
|
||
| Closes #4 | ||
| Closes #5 | ||
| Closes #6 | ||
| Closes #7 | ||
| Closes #8 | ||
| Closes #9 | ||
|
|
||
| ### 关联的 Issues([GeneHub Issues](https://github.com/NoDeskAI/genehub/issues),合并后将自动关闭) | ||
|
|
||
| | Issue | 标题 | | ||
| |-------|------| | ||
| | #9 | [sdk] Python SDK 初始化实现 | | ||
| | #8 | [web] 版本历史加载失败静默吞错 + 违规使用 emoji | | ||
| | #7 | [cli] 实现 genehub info 命令,查看单个基因详情 | | ||
| | #6 | [cli] search 命令未接入联邦搜索,无法搜到外部基因源 | | ||
| | #5 | [sdk] Nanobot Adapter 缺少测试覆盖,config.nanobot 配置注入未实现 | | ||
| | #4 | [registry] 删除基因/基因组/模板时 Gitea 仓库清理失败不抛错,导致数据不一致 | | ||
|
|
||
| ### 主要变更 | ||
|
|
||
| **Web(packages/web)** | ||
| - 列表/版本历史加载失败时展示错误提示;列表失败时重置 totalPages / federatedSources | ||
| - 详情页 slug 变化时清空 error 与数据,避免一直显示错误页 | ||
| - 剩余 emoji 替换为 Lucide 图标(Home 分类、GenomeBrowse 空态、CategoryNav 等) | ||
|
|
||
| **Python SDK(packages/sdk/python)** | ||
| - 新增 GeneHubClient、GeneAdapter、GenericAdapter、LearningEngine(最小可用) | ||
| - 按 Copilot 评论修正:URL 编码、JSON 异常处理、GeneManifest 类型、safe_dump、时间戳、非 JSON 响应测试 | ||
|
|
||
| **Registry(packages/registry)** | ||
| - 为 Hono Context 声明 AuthVariables 类型,消除 genes API 等处的 TypeScript 报错 | ||
|
|
||
| **文档** | ||
| - architecture.md、README、AGENTS.md 等补充/更新 Python SDK 与目录结构 | ||
| - docs/pr-registry-context-types.md、docs/pr-cccc-branch.md(本 PR 说明) | ||
|
|
||
| ### Test plan | ||
|
|
||
| - `pnpm build`、`pnpm test` 全量通过 | ||
| - Web:本地 `pnpm dev` 验证列表/详情错误态与分类图标 | ||
| - Python SDK:`cd packages/sdk/python && uv run pytest tests/ -v` | ||
| - Registry:本地启动后调用需鉴权接口验证行为不变 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # fix(registry): 为 Hono Context 声明 Auth 变量类型,消除 genes 等 API 的 TypeScript 报错 | ||
|
|
||
| ## Summary | ||
|
|
||
| - 修复 Registry 中 `packages/registry/src/api/genes.ts` 等文件因 Hono Context 未声明 `authRole` / `publisherId` / `githubLogin` 导致的 TypeScript 报错(`c.get('authRole')` 等被判定为非法)。 | ||
| - 在 auth 中间件中导出 `AuthVariables` 类型,并在主 App 与 genes 路由上使用 `Hono<{ Variables: AuthVariables }>`,使类型与运行时行为一致。 | ||
|
|
||
| ## Changes | ||
|
|
||
| | 文件 | 变更 | | ||
| |------|------| | ||
| | `packages/registry/src/middleware/auth.ts` | 新增并导出 `AuthVariables` 类型(authRole、publisherId、githubLogin) | | ||
| | `packages/registry/src/app.ts` | 使用 `new Hono<{ Variables: AuthVariables }>()` 创建 App | | ||
| | `packages/registry/src/api/genes.ts` | 使用 `new Hono<{ Variables: AuthVariables }>()` 创建 genesRouter | | ||
|
|
||
| ## Impact | ||
|
|
||
| - **运行时**:无行为变化,auth 中间件原本就会注入上述变量。 | ||
| - **构建 / CI**:带类型检查的构建与 `tsc` 可通过。 | ||
| - **开发体验**:IDE 中相关类型错误与红色波浪线消失。 | ||
|
|
||
| ## Test plan | ||
|
|
||
| - 在 `packages/registry` 下执行 `pnpm build` 与 `pnpm test`,确认通过。 | ||
| - 本地 `pnpm dev` 启动 Registry,调用需鉴权或 optionalAuth 的接口(如 `GET /api/v1/genes?review_status=...`),确认行为与修改前一致。 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import { Hono } from 'hono'; | ||
| import type { AuthVariables } from '../middleware/auth.js'; | ||
| import { optionalAuth, requireAuth } from '../middleware/auth.js'; | ||
| import { paginated, success } from '../middleware/response.js'; | ||
| import { federatedSearch } from '../services/federated-search.js'; | ||
| import * as geneService from '../services/gene-service.js'; | ||
|
|
||
| export const genesRouter = new Hono(); | ||
| export const genesRouter = new Hono<{ Variables: AuthVariables }>(); | ||
|
||
|
|
||
| genesRouter.get('/search', async (c) => { | ||
| const q = c.req.query('q') ?? ''; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.