Files
2026-05-27 23:29:53 +01:00

56 lines
2.8 KiB
Markdown

# Tasks: enterprise-api-plugin-search
**Change ID**: enterprise-api-plugin-search
**Package**: `@suaveplan/api-plugin-search`
**Target path**: `api/data/api-plugin-search`
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/events`, `@suaveplan/rate-limiter`, `@suaveplan/error`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in 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.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold + types + errors + events
- [ ] Create `api/data/api-plugin-search/`; `package.json` v0.0.0; standard tooling.
- [ ] Types: `SearchAdapter`, `SearchDocument`, `SearchQuery`, `SearchResult`, `FacetValue`, `SearchPluginConfig` (Zod).
- [ ] Errors: 4-code union + metadata + registration. Test + doc.
- [ ] Events: `SearchEventMap` (search:indexed, search:reindexed, search:index:failed).
---
## 2. Adapters
- [ ] `src/adapters/search-adapter.port.ts` — `SearchAdapter` interface.
- [ ] `src/adapters/surrealdb-search.ts` — default `SurrealDbSearchAdapter` using SurrealDB `SEARCH ANALYZER` + `SEARCH::SCORE`. `.test.ts` + `.md`.
---
## 3. SearchService (`.test.ts` + `.md`)
- [ ] `index(collection, doc)`, `indexMany(collection, docs)`, `delete(collection, id)`, `search(collection, query)`, `reindex(collection)`.
- [ ] OTel histogram `search.query_duration_ms`; counter `search.queries_total`.
---
## 4. Routes
- [ ] `GET /search?q=...&collection=...` — `requireAuth`; rate-limited; delegates to `SearchService.search`.
- [ ] `POST /search/:collection/index` — admin; bulk index.
- [ ] `POST /search/:collection/reindex` — admin; full reindex.
- [ ] Route `.test.ts` + `.md`.
---
## 5. Plugin factory + integration tests + publish
- [ ] `createSearchPlugin(adapter?, config?)`: `definePlugin`, `dependencies: ["database"]`.
- [ ] Default adapter: `SurrealDbSearchAdapter` (uses DB from `database` plugin).
- [ ] Integration: index docs → search → filter + facets (real SurrealDB).
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-search` — green; 100% coverage.
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-search`.
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-search/`.