imbytecat
|
25d7f1c315
|
fix(api): 修正看板和历史统计口径
|
2026-05-12 00:48:16 +08:00 |
|
imbytecat
|
99d9cd1e1d
|
refactor(api): 复用电池业务常量
|
2026-05-11 23:38:37 +08:00 |
|
imbytecat
|
69c4a2e9eb
|
fix(api): 收紧电池列表查询输入
|
2026-05-11 23:16:59 +08:00 |
|
imbytecat
|
dd4a447dcd
|
style: 格式化后端改造代码
|
2026-05-11 23:16:59 +08:00 |
|
imbytecat
|
cf6f91651d
|
feat(api): 支持电池分页和安全预测
|
2026-05-11 22:39:05 +08:00 |
|
imbytecat
|
1a2ff19cf4
|
feat(dashboard): 接入预测结果聚合
|
2026-05-11 22:21:57 +08:00 |
|
imbytecat
|
e722913468
|
refactor(todo): 移除 Todo API 示例
|
2026-05-11 20:51:34 +08:00 |
|
imbytecat
|
4e5ba4b599
|
feat(api): 实现电池 ORPC 路由
|
2026-05-11 20:51:24 +08:00 |
|
imbytecat
|
657c7317f7
|
feat(api): 暴露电池 ORPC 契约
|
2026-05-11 20:51:24 +08:00 |
|
imbytecat
|
fafe02bdbd
|
refactor: 主动审计修复多处可观测性、依赖、代码质量缺口
通过并行 explore + librarian + 自查发现并修复:
代码缺陷
- shutdown.ts: db.$client.end().finally(...) 静默吞错——关闭失败会
谎报 "DB pool closed" 后照常 exit 0。改用 await + try/catch
分别记录成功/失败,setTimeout 也换成 Bun.sleep。
- interceptors.ts: 两条 instanceof ORPCError && instanceof
ValidationError 重复检查,改用 early return + 单 if 分支区分 code。
- types.ts: 移除从未被引用的 RouterInputs 死代码(仅 RouterOutputs
被 TodoItem 用到)。
Bun 原生 API(删/换 Node 兼容层)
- fields.ts: uuid v7 → Bun.randomUUIDv7(),删除 uuid 依赖
- migrate.ts: node:crypto.createHash → Bun.CryptoHasher.hash,
少一个 Promise.all 项 + 一个 import
- shutdown.ts: setTimeout → Bun.sleep(顺带)
Biome 2.4 规则补强
- domains.types: "all"——开启类型感知规则集(noFloatingPromises /
noMisusedPromises / useAwaitThenable / noUnnecessaryConditions
等 Promise/异步陷阱)
- domains.drizzle: "recommended"、domains.react: "recommended"
- 显式开启 suspicious.noImportCycles(2.4 已 promote)
文档
- AGENTS.md 在 Stack & runtime 段加 "Prefer Bun-native APIs"
原则,列出 UUIDv7/SHA-256/sleep/Bun.file 的优先路径
- AGENTS.md 在 Code style (Biome) 段记录本次启用的 lint domain
与 noImportCycles 规则
验证:fix / typecheck / test 3/3 / build 568ms / compile 117M /
docker compose 全套(migrate JSON 日志 ✓、UUIDv7 写入 ✓、SIGTERM
shutdown 正确序列化 ✓)
|
2026-04-25 17:06:22 +08:00 |
|
imbytecat
|
34d2cbb1cd
|
refactor(logging): 二次审计修复 oracle 漏掉的可观测性缺口与占位符冗余
二次深度审计发现:
1. shutdown.ts SIGINT/SIGTERM 路径完全沉默——生产环境 k8s pod 终止时
操作者在日志里看不到任何痕迹。补 getLogger(['shutdown']) 三条日志:
- "Draining for shutdown" {signal, graceMs} (优雅关停起点)
- "Forcing exit on repeated signal" {signal} (二次信号强制退出)
- "DB pool closed, exiting" (干净退出确认)
2. interceptors.ts 与 shutdown.ts 的 {error}/{signal} 占位符在 JSON 模式
下导致 message 字段重复 inspect 转义 properties 里的同一份内容
(Error/对象会被 JSON.stringify 内联进 message,引号被反斜杠转义)。
规则收敛:占位符仅用于"想要内联渲染"的基本类型(id、count、duration),
对象/Error 直接放 properties,message 保持人类可读短句。
3. AGENTS.md Logging 段更新示例与规则,反映实际最佳实践。
端到端验证(compose + Postgres 18-alpine):
- /api/rpc/todo/list 成功 → logger=db level=INFO 输出 SQL ✓
- /api/rpc/todo/create 校验失败 → logger=api level=ERROR
message="Unhandled error in ORPC handler" 干净,properties.error
完整保留 code/status/message/data 字段 ✓
- SIGTERM → 三条 shutdown logger 事件按预期输出 ✓
- typecheck / test 3/3 / build / compile 117M 全绿 ✓
|
2026-04-25 16:24:00 +08:00 |
|
imbytecat
|
cc3a5dc5ad
|
feat(logging): 引入 LogTape 替换 console.* 为结构化日志
为什么选 LogTape(2026 实测):
- pino 在 bun build --compile 编译产物里因 worker_threads + 动态 require 在
/\$bunfs/ 虚拟文件系统中崩溃,与单二进制部署核心目标冲突;
- LogTape 零依赖(5.3KB)、零 worker、纯 ESM、原生 Bun 导出条件,runtime
agnostic,配合 configureSync 完美兼容 --bytecode 模式(无裸 top-level await);
- 一等公民集成:@logtape/drizzle-orm(SQL 查询日志)、@logtape/otel(后续
OpenTelemetry sink 留扩展点)。
变更:
- src/server/logger.ts: configureSync 引导 + getLogger 重导出。format 默认
process.stdout.isTTY ? pretty : json,可经 LOG_FORMAT 显式覆盖(绕开 Bun
bundler 把 process.env.NODE_ENV 在 --minify 时 inline 成字面量的特殊处理)。
- src/server/api/interceptors.ts: logError 改用 getLogger(['api']).error(...) +
结构化 properties,弃 logger.error 顶层 API。
- src/cli/migrate.ts: 所有 console.log 改走 getLogger(['cli','migrate']),logger
在 run() 内 lazy-import 以保持 citty subcommand 模块体 side-effect-free。
- src/server/db/index.ts: env.LOG_DB=true 时挂 DrizzleLogger 适配器,SQL 查询
按类别 ['db'] 在 debug 级输出(含 query/params/formattedQuery 三字段)。
新增 env 旋钮(t3-oss 校验):
- LOG_LEVEL: trace|debug|info|warning|error|fatal,默认 info
- LOG_FORMAT: pretty|json,默认 TTY 自动选
- LOG_DB: stringbool,默认 false
端到端验证(compose + Postgres 18-alpine):
- TTY 终端:pretty 输出含 ✨ 图标 + ANSI 彩色 + 类别·路径 ✓
- 管道/Docker:JSON Lines 一行一条,含 @timestamp/level/logger/properties ✓
- LOG_FORMAT=pretty 强制覆盖 ✓
- ./server migrate 应用 migration 并经 logger 输出 ✓
- ./server serve + RPC round-trip:interceptor logError 与 drizzle SQL 日志
在生产 JSON 模式下结构化输出 ✓
- fix / typecheck / test 3/3 / build / compile 117M 二进制全绿
|
2026-04-25 16:04:31 +08:00 |
|
imbytecat
|
ed257fe4e6
|
refactor: 应用 Oracle round-4 复核,硬化 migrator 与默认安全值
- migrate: 校验已应用 migration 的 SHA-256,拒绝 schema drift;
split 后 trim + skip empty,避免空 statement 触发 SQL 错误
- todo.contract: update 拒绝空 patch
- env: DATABASE_URL 限定 postgres(ql):// scheme,配置错误更早失败
- compile: autoloadDotenv: false,二进制部署不再吞 cwd 的 .env
- Error.tsx: 生产环境隐藏 error.message,避免内部错误泄露
- AGENTS: 同步 generatedFieldKeys / migrator 行为新描述
|
2026-04-25 14:38:44 +08:00 |
|
imbytecat
|
695e826dcf
|
refactor(types): 消除非必要 as 逃逸,锁紧 strict 政策
按 Oracle 复核处置全仓 5 处类型断言:
- fields.ts: as const → satisfies Record<GeneratedFieldKey, true>
- compile.ts: as readonly string[] → ReadonlySet<string>.has()
- embed-migrations.ts: JSON.parse as Journal → Zod schema 运行时校验,JSON.parse 显式 unknown
- interceptors.ts: 唯一保留的跨包断言(ORPC→Zod)注释扩写为完整背景
- router.tsx: satisfies 非 cast,保留
biome.json 增配 noExplicitAny / noTsIgnore / noNonNullAssertion,防止后续漂移。
|
2026-04-25 14:23:08 +08:00 |
|
imbytecat
|
6dc7f9f791
|
test: 启用 bun test 并补 todo contract 示例
- package.json 加 "test": "bun test"
- todo.contract.test.ts 给 starter 一个可复制的 colocated 测试样板
覆盖 valid input / missing field / wrong type 三种 case
|
2026-04-25 13:31:34 +08:00 |
|
imbytecat
|
8f7744ca0d
|
feat(server): 新增统一 logger 入口与 /health liveness 端点
- src/server/logger.ts 包一层 console.*,给后续 pino/otel 迁移留单点
- interceptors.ts 的 logError 改走 logger.error,业务侧禁止直接 console.*
- /health 返回 'ok',纯 liveness(不查 DB),DB 挂时探活仍绿
|
2026-04-25 13:31:25 +08:00 |
|
imbytecat
|
2678a53034
|
refactor(api): 删掉 db ORPC middleware,handler 直接用 db
db middleware 的存在只是为了把 db 注入到 ORPC context——这是 Cloudflare
Workers / 多租户场景的模式(db 依赖 per-request 的 env binding)。在
Bun 单进程 + 模块级 const db 下,这层中间件是纯粹的仪式:一行 import
直接拿到 db,反而更清晰。
- 删除 src/server/api/middlewares/ 整个目录(不留空脚手架,KISS)
- context.ts 去掉 DBContext 与示例注释,只留 BaseContext { headers }
作为未来 auth/tenant 等 middleware 的扩展点
- routers/todo.router.ts 不再 .use(db),handler 内直接 db.query / db.insert
需要 per-request 上下文(auth、tenant、rate-limit)时再按 ORPC 的
os.middleware 模式新增,不在此预先铺陈。
|
2026-04-24 20:37:11 +08:00 |
|
imbytecat
|
d15b22ad1b
|
refactor(db): 去掉 lazy singleton,改为模块级 const db
getDB/closeDB + 可空单例是 Cloudflare Workers 场景的模式——每个请求独
立上下文、不允许模块加载期副作用。在 Bun 单进程长驻服务下这些都是冗余
的仪式,徒增心智。
改为模块级 const db:
- src/server/db/index.ts 直接 export drizzle(...) 实例
- shutdown 插件用 db.$client.end() 收尾
- db.middleware.ts 跟随内部重命名以避免同名遮蔽(本身的去留放到下一
次提交)
|
2026-04-24 20:36:16 +08:00 |
|
imbytecat
|
75c77159b4
|
refactor(db): 适配 drizzle-orm 0.x API 并引入 drizzle-zod
drizzle-orm 从 1.0 beta 降级到 0.45 后,1.0 的 defineRelations、drizzle-orm/zod
子路径以及 RQB v2 的 orderBy 对象语法均不可用。改用 schema 作为 drizzle()
入参、从独立的 drizzle-zod 包导入 schema 生成器,并将 orderBy 改回 0.x 的
回调写法。同时删除因降级而失效的旧迁移。
|
2026-04-24 20:08:41 +08:00 |
|
imbytecat
|
c67e773086
|
refactor: 抽取 UI 组件、改进错误页面、统一导入路径并简化数据库接口
|
2026-04-02 00:13:43 +08:00 |
|
imbytecat
|
cd7b65fda4
|
refactor: flatten monorepo into standalone project
|
2026-04-01 19:43:21 +08:00 |
|