Initial Commit
This commit is contained in:
82
openspec/changes/enterprise-api-plugin-search/proposal.md
Normal file
82
openspec/changes/enterprise-api-plugin-search/proposal.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# OpenSpec Change: enterprise-api-plugin-search
|
||||
|
||||
- **Change ID**: enterprise-api-plugin-search
|
||||
- **Package**: `@suaveplan/api-plugin-search`
|
||||
- **Category**: api/data
|
||||
- **Target path**: `api/data/api-plugin-search`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-search.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/api-plugin-search` on the genesis branch from scratch at enterprise quality. Full-text and structured search plugin with pluggable backend adapters (SurrealDB built-in FTS, Meilisearch, Typesense, Elasticsearch). `SearchAdapter` port abstracts the backend; `SearchService` indexes documents and queries with filters, facets, pagination, and typo-tolerance. Routes under `/search`. Typed bus events: `search:indexed`, `search:reindexed`. Consumed by `@suaveplan/api-plugin-cms`, contacts, analytics, and others.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
|
||||
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
|
||||
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth` |
|
||||
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB default FTS |
|
||||
| `@suaveplan/events` (`workspace:^`) | Event bus |
|
||||
| `@suaveplan/error` (`workspace:^`) | `SearchError` hierarchy |
|
||||
| `@suaveplan/rate-limiter` (`workspace:^`) | Rate limits |
|
||||
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
|
||||
| `@opentelemetry/api` | OTel |
|
||||
|
||||
---
|
||||
|
||||
## Public API surface
|
||||
|
||||
```ts
|
||||
function createSearchPlugin(adapter?: SearchAdapter, config?: SearchPluginConfig): PluginDescriptor
|
||||
|
||||
interface SearchAdapter {
|
||||
index(collection: string, doc: SearchDocument): Promise<void>
|
||||
indexMany(collection: string, docs: SearchDocument[]): Promise<void>
|
||||
delete(collection: string, id: string): Promise<void>
|
||||
search(collection: string, query: SearchQuery): Promise<SearchResult>
|
||||
reindex(collection: string): Promise<void>
|
||||
}
|
||||
|
||||
interface SearchDocument { id: string; [key: string]: unknown }
|
||||
interface SearchQuery { q: string; filters?: Record<string, unknown>; facets?: string[]; page?: number; pageSize?: number }
|
||||
interface SearchResult { hits: SearchDocument[]; total: number; facets?: Record<string, FacetValue[]>; took: number }
|
||||
```
|
||||
|
||||
### Error codes
|
||||
|
||||
```ts
|
||||
type SearchErrorCode =
|
||||
| "SEARCH_ADAPTER_ERROR"
|
||||
| "SEARCH_COLLECTION_NOT_FOUND"
|
||||
| "SEARCH_INDEX_FAILED"
|
||||
| "SEARCH_QUERY_INVALID"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
api/data/api-plugin-search/
|
||||
package.json tsconfig.json vitest.config.ts
|
||||
src/
|
||||
index.ts events.ts types/ errors/
|
||||
adapters/search-adapter.port.ts adapters/surrealdb-search.ts
|
||||
services/search/
|
||||
routes/search/
|
||||
tests/integration.test.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Impact
|
||||
|
||||
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`.
|
||||
55
openspec/changes/enterprise-api-plugin-search/tasks.md
Normal file
55
openspec/changes/enterprise-api-plugin-search/tasks.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# 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/`.
|
||||
Reference in New Issue
Block a user