2.8 KiB
2.8 KiB
Tasks: enterprise-api-plugin-database
Change ID: enterprise-api-plugin-database
Package: @suaveplan/api-plugin-database
Target path: api/data/api-plugin-database
Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/db, @suaveplan/error, @suaveplan/events, @suaveplan/logger, @suaveplan/types
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold + types + errors + events
- Create
api/data/api-plugin-database/;package.jsonv0.0.0,"sideEffects": ["src/events.ts"]; standard tooling. - Types:
DatabasePluginConfig(Zod),DatabaseStats,MigrationResult. - Errors: 4-code union + metadata + registration. Test + doc.
- Events:
DatabaseEventMap(database:connected, database:error, database:migration:complete).
2. DatabaseService (.test.ts + .md)
getDb()— returnsDatabaseAdapter; throwsDatabasePluginError(DB_NOT_INITIALIZED)if called beforeonInit.runMigrations(path)— reads.surqlfiles from path ordered by filename; executes each idempotently; returnsMigrationResult.healthCheck()— executes a lightweight query; measures latency; emitsdatabase:erroron failure.getStats()— returns connection count, query count from adapter internals.- OTel span on each method.
3. Health route
GET /health/db— callshealthCheck(); returns 200{status: "ok"}or 503{status: "degraded"}.health.test.ts+health.md.
4. Plugin factory
createDatabasePlugin(config):definePluginwith name"database", no dependencies.onInit: open DB connection; run migrations atconfig.migrationsBasePath; registerDatabaseService; emitdatabase:connected.onClose: close DB connection; emitdatabase:disconnected.
5. Integration tests + publish
- Connect to real SurrealDB; run sample migrations; health-check returns ok; stats non-zero.
bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-database— green; 100% coverage.bun scripts/publish.ts --package @suaveplan/api-plugin-database.- Archive →
openspec/archive/2026-04-24-enterprise-api-plugin-database/.