Skip to content

refactor: type the drizzle client for real - #5

Open
fengmk2 wants to merge 1 commit into
enable-type-aware-lintfrom
enable-typed-db
Open

refactor: type the drizzle client for real#5
fengmk2 wants to merge 1 commit into
enable-type-aware-lintfrom
enable-typed-db

Conversation

@fengmk2

@fengmk2 fengmk2 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

OpenSpec

  • This PR implements an OpenSpec change: <!-- change name -->
  • No OpenSpec change is needed (small doc/fix, no shipped behavior change).

Verification

  • pnpm verify passed.
  • A subset was run instead: <!-- commands --> because <!-- reason -->.

Impact Checklist

  • App code (apps/, packages/)
  • API behavior / OpenAPI contract (apps/api/src/routes/*.ts zod-openapi declarations, api/openapi.json via pnpm gen:openapi)
  • Database schema or migration (packages/db)
  • Deployment (deployment/)
  • Documentation (README.md, docs/, wiki/)
  • CI / scripts (.github/workflows/, scripts/, package.json)
  • Secret handling: no real .env, tokens, cookies, private keys, database URLs, or user data committed.

Migration / Deployment Notes

Replace @cnode/db's escape hatch (export type DB = any) with the real
drizzle client type, plus a Database alias (PgDatabase over the schema)
for helpers that only run queries, so they accept the client, a
transaction, or drizzle.mock() in tests.

All surfaced type errors are fixed without changing any JSON response:

- transaction callbacks rely on inference instead of tx: DB annotations
- insertReply returns the narrowed ReplyForCreation shape
- password compares guard pass being null (GitHub-only accounts) and
  keep answering 403
- nullable row fields feeding non-null contract slots are coalesced
  (?? "" / ?? 0 / ?? undefined) and Date fields serialize explicitly
  via toISOString, which JSON.stringify already produced on the wire
- /messages keeps emitting the empty topic.author placeholder it always
  produced; populating it for real is a behavior change split into the
  next stacked layer
- the reply-data-consistency test mocks drizzle with the exact schema
  namespace now exported from @cnode/db
@fengmk2
fengmk2 marked this pull request as ready for review August 5, 2026 08:35

@thonatos thonatos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: LGTM

消灭 DB = any,拆 DB/Database 两面,事务 tx 获得真实类型;顺带修复 GitHub 账号 user.pass 为 null 时登录/改密崩溃等真 bug。

非阻塞:

  1. 可空时间字段序列化不一致:create_at null→"",而 last_reply_at/update_at 保留 null,建议统一。
  2. 消息列表 reply 缺省值 {}{id:"",content:"",ups:[],create_at:""},属 wire 变化,前端需知悉。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants