import { PermissionService } from '../permissions/permission.service'; import { PondPermissionCache } from '../permissions/pond-permission-cache'; import { PrismaService } from '../prisma/prisma.service'; import { PostgresSearchProvider } from './postgres-search.provider'; /** * `search:reindex` CLI (ADR 0010, issue #49): rebuilds the whole search index * from `page_content_cache`, idempotently — safe to run after a schema change, * a reseed, or a provider swap. It instantiates the PostgreSQL provider * directly (no Nest DI): the CLI is run with `tsx`, whose esbuild transform does * not emit the decorator metadata Nest injection relies on. The provider itself * is still the one bound in the app (proven by the DI test) — only the CLI's * wiring is manual. */ async function main(): Promise { const prisma = new PrismaService(); // Reindexing never asks permission questions, but the provider's search // path needs the service — wire it manually like everything here. const permissions = new PermissionService(prisma, new PondPermissionCache()); const provider = new PostgresSearchProvider(prisma, permissions); try { const count = await provider.reindexAll(); console.log(`search:reindex — indexed ${count} page(s)`); } finally { await prisma.$disconnect(); } } void main().catch((error) => { console.error('search:reindex failed:', error); process.exitCode = 1; });