Module setup
How your app hands Kavo its infrastructure and app-wide options: KavoModule.forRoot/forRootAsync, and building KavoContext.app from the request.
Global config (KavoModule.forRoot / forRootAsync)
ts
KavoModule.forRootAsync({
useFactory: () => ({
infrastructure: createInfrastructure(dataSource),
defaults: {/* KavoSettings, see Settings */},
paginationStrategies: [],
}),
provideServices: true,
graphql: true,
});| Field | Type | What it does |
|---|---|---|
infrastructure | KavoInfrastructure | Where entity metadata and the repository adapter come from: createInfrastructure(dataSource) or createInfrastructure(client, opts). Required for any @Kavo route to run. |
defaults | DeepPartial<KavoSettings> | App-wide settings, one level below the built-in defaults and above every entity's own config. See Settings for what's in KavoSettings. |
paginationStrategies | readonly PaginationStrategy[] | Registers custom pagination strategies beyond the built-in "offset", so pagination.strategy can name one of these instead. |
realtimeTransports | readonly RealtimeTransport[] | Registers the transports (e.g. createTransport(...) from @kavo/sse) that every entity's write events publish to. This is process-wide, not per entity (ADR-0023). An entity still needs its own realtime: { events: {...} } (any object; see realtime) before its writes publish anything. Registering a transport alone does not turn realtime on. |
cacheStore | CacheStore | The store every entity's cache reads and writes. Process-wide and shared by every entity, not per entity (ADR-0031). Defaults to an in-process createMemoryCacheStore(); hand one instance to every root for a process-wide cache, or implement get/set/invalidate over a shared backend. Registering a store alone does not turn caching on; an entity still needs its own cache: { ttl: ... } (see Result cache). |
app | (request) => KavoAppContext | Builds the application's request-scoped context every generated route puts on KavoContext.app — e.g. (request) => request.user as KavoAppContext. Unset leaves KavoContext.app as {}. See Wiring your own auth. |
useFactory | (...args) => KavoModuleOptions | (forRootAsync only) Builds the options object, e.g. after awaiting dataSource.initialize(). |
inject | readonly (string | symbol | Type)[] | (forRootAsync only) DI tokens injected as useFactory's arguments. |
provideServices | boolean | Also provides getKavoServiceToken(Entity) as a real DI provider for every @Kavo-decorated class the process has seen. Needed only if some other class constructor-injects a @Kavo entity's service directly. |
graphql | boolean | { path?: string } | Mounts a default GraphQL controller merging every entity that called registerKavoGraphQLTypes onto one schema. true mounts at POST /graphql; { path } mounts elsewhere. Implies provideServices. |
mcp | boolean | { path?: string } | Mounts a default MCP controller (Streamable HTTP, stateless) exposing every @Kavo entity's full standard toolset, with no per-entity opt-in. true mounts at POST /mcp; { path } mounts elsewhere. Implies provideServices. Requires @modelcontextprotocol/sdk installed. Carries no auth guard of its own: a guard on an entity's REST controller does not extend to this route. Write your own controller extending BaseKavoMcpController instead if the MCP surface needs auth. |
See Wiring your own auth for how app builds KavoContext.app from the request, and how to type it.