custom-storage-adapter
Write a custom storage adapter
The core ships three backends: memory (default), file, and sqlite (via @eleven-labs/nest-profiler/sqlite). Reach for a custom adapter when profiles must live elsewhere — Redis, Postgres/Mongo, S3 — typically to share profiles across instances, or to persist where the local disk does not (ephemeral/serverless filesystems, or across a redeploy that wipes the volume). Note: file and sqlite already survive a plain process restart on a box with a persistent disk — a custom adapter is only warranted when there is no such disk or the store must be shared/remote. Confirm the core is set up first (setup-nest-profiler).
The contract — IProfilerStorageAdapter
Required methods: save(profile), findAll(), findOne(token), clear().
Important optionals:
crossProcess(boolean) — settruefor shared stores (Redis, DB, file). The commander/CLI profiler uses it to warn when command profiles land in a process-local store where the web UI can't see them. Omitted means "assume shared".query(query)— run the dashboard's structured list query (section + filters + sort + pagination) natively so a list render never loads every profile. Implement this for any store that can filter/paginate efficiently. When omitted, the service falls back tofindAll+ in-memory filtering (correct, not scalable).distinct(field, typeIn?)— distinct summary values for dynamic filterselectoptions; falls back to deriving fromfindAll.setIndexAttributesProvider(provider)— called once at startup before the first save; needed if you persist aProfileSummaryfor nativequery/distinct(to populate kind-specificsummary.attributes).close()— release handles on shutdown (DB connection, file locks). Implement it for any native handle.
Wire it via the storage option
storage takes precedence over storageType. Build the adapter (usually async, from ConfigService) and pass the instance: