抽自 docs/dacli/ssw-dacli/SqliteCacheService.java + ApiService.java + DocService.java
(PG 用户建议改 SQLite, 更优: 无外部依赖, 单文件 ~/.dacli/cache.db, 跟 Java 对齐)
新增:
- src/core/sqlite_cache.ts (TS 版 SqliteCacheService, 110 行):
- better-sqlite3 (WAL 模式, sync API 比 async 快)
- 公开: get/set/del/delByPattern/clearAll/stats/resetDbFile
- 自动目录创建 ~/.dacli/, 启动时清过期项
- 进程退出自动 close (SIGINT/SIGTERM 处理)
- 路径可配: $DACLI_CACHE_DIR/cache.db
升级:
- apis/_cache.ts: in-memory Map → SQLite (12h TTL)
- prefix: dacli:apidoc: (openapi/index/loaded/pid)
- 跨 process 命中 (之前每次 npx tsx 都重拉 /v3/api-docs)
- PID 失效检测用 'process.pid + 启动分钟' 兜底 (Node 跨平台 jps 不可靠)
- doc/_parser.ts: in-memory Map → SQLite (mtime 缓存)
- prefix: dacli:doc: (mtime:{hash}/raw:{hash}/section:{hash}:{id})
- 7 天 TTL, mtime 一致直接命中
- section 索引/listSections 走 SQLite LIKE 查询
- package.json: better-sqlite3 从 optionalDependencies 升到 dependencies
(跨平台 native binding, rebuild 自动)
实战验证:
- 第一次 dacli apis info: 拉 /v3/api-docs (1MB) 写 SQLite
- 第二次 dacli apis status: loaded=true source=sqlite pathCount=846
- 跨 process 持久化: ~/.dacli/cache.db 1.2MB, 7 rows
- 之前 in-memory 每次 npx tsx 都重拉, 现在零延迟命中
Co-Authored-By: Claude <[email protected]>
42 lines
1.0 KiB
JSON
42 lines
1.0 KiB
JSON
{
|
|
"name": "dacli-ts",
|
|
"version": "0.1.0",
|
|
"description": "TypeScript-based dacli CLI for JNPF platform — 0 差错 baseline replication.",
|
|
"type": "module",
|
|
"private": true,
|
|
"bin": {
|
|
"dacli": "src/cli.ts"
|
|
},
|
|
"scripts": {
|
|
"dacli": "tsx src/cli.ts",
|
|
"test": "vitest run",
|
|
"test:watch": "vitest",
|
|
"test:e2e": "playwright test",
|
|
"extract": "tsx scripts/extract-all.mjs",
|
|
"verify:baseline": "bash .claude/skills/dacli-ts/examples/baseline/all.sh",
|
|
"typecheck": "tsc --noEmit"
|
|
},
|
|
"dependencies": {
|
|
"@vue/compiler-sfc": "^3.5.0",
|
|
"better-sqlite3": "^11.10.0",
|
|
"commander": "^12.1.0",
|
|
"crypto-js": "^4.2.0",
|
|
"vue": "^3.5.0",
|
|
"yaml": "^2.9.0"
|
|
},
|
|
"devDependencies": {
|
|
"@playwright/test": "^1.48.0",
|
|
"@types/better-sqlite3": "^7.6.11",
|
|
"@types/crypto-js": "^4.2.2",
|
|
"@types/node": "^22.0.0",
|
|
"mysql2": "^3.22.5",
|
|
"pixelmatch": "^6.0.0",
|
|
"tsx": "^4.19.0",
|
|
"typescript": "^5.6.0",
|
|
"vitest": "^2.1.0"
|
|
},
|
|
"engines": {
|
|
"node": ">=20"
|
|
}
|
|
}
|