/kavo-skills:mongoose-adapterfrom Kavo Developer Skills
Wires @kavo/mongoose into a NestJS app, using Mongoose models as entity identities, rendering ObjectId as hex strings, and supporting soft delete and ref-path relations.
Ships in Kavo Developer Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
@kavo/mongoose adapts Kavo to a Mongoose connection. The engine, routes,
query grammar, and DTO slots are identical to every other adapter — the
differences below come from MongoDB itself, not from Kavo.
npm install @kavo/core @kavo/nest @kavo/mongoose
mongoose (^7.0.0 || ^8.0.0) is a peer dependency.
Unlike Prisma, there is nothing to declare twice. A Mongoose model is
already a constructor, so it is the identity @Kavo() wants — no marker
class, no entity list (ADR-0018).
// book.model.ts
import mongoose, { Schema } from "mongoose";
const bookSchema = new Schema({
title: { type: String, required: true },
});
export const Book = mongoose.model("Book", bookSchema);
@Kavo(Book) // the model itself
@Controller("books")
export class BookController {}
// app.module.ts
import { Module } from "@nestjs/common";
import { KavoModule } from "@kavo/nest";
import { createInfrastructure } from "@kavo/mongoose";
import mongoose from "mongoose";
import { BookController } from "./book.controller.js";
await mongoose.connect(process.env.MONGO_URL!);
@Module({
imports: [
KavoModule.forRoot({
infrastructure: createInfrastructure(mongoose.connection),
}),
],
controllers: [BookController],
})
export class AppModule {}
createInfrastructure(connection) derives both the entity metadata and the
repository adapter from the connection's own registered models.
Define models at module scope, before connecting. @Kavo() generates its
routes at class-decoration time, and Mongoose buffers commands until
connect() resolves — a model created after the decorator runs is not
registered in time.
_idMongoDB's primary key is _id, and the adapter renders every ObjectId as a
hex string at the boundary. So responses are keyed by _id, not by a
numeric id, and a DTO declares it as a string:
export class BookItemDto {
_id = "";
title = "";
}
A malformed id is a 404, not a 500 — a string that cannot be an
ObjectId names a document that cannot exist.
Mongoose has no @DeleteDateColumn equivalent, so add an ordinary schema
path and name it in config. That declaration is what generates
PATCH /books/:id/restore (ADR-0013):
@Kavo(Book, { delete: { field: "deletedAt" } })
@Controller("books")
export class BookController {}
ref path is the relation and the foreign keyOne schema path gives you all three at once:
GET /books?include=author # embedded, loaded via populate
GET /books?filter[author][eq]=<id> # filterable — it is the FK too
POST /books {"author":"<id>"} # writable by id (ADR-0014)
Mark it includable like any other relation:
@Kavo(Book, { relations: { edges: { author: { includable: true } } } })
@Controller("books")
export class BookController {}
Filtering across a relation is refused. filter[author.name] returns a
400, not an empty result — MongoDB resolves a dotted path inside a
document, never across a ref. Dotted paths into an embedded object work
normally; it is only traversal through a reference that has no equivalent.
kavo-decoratorfilter/sort/fields/include wire grammar → query-grammardto-slotssoft-deleteWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub kavo-labs/kavo --plugin kavo-skills15 skills in this plugin
/composite-primary-keysReference for composite primary key support in @kavo/typeorm — the compositeIdFields metadata field, the ~-delimited route-id encoding, the creatable/updatable split, and every place composite keys don't yet work (other ORM adapters, many-to-many array-mutation, @kavo/graphql). Use when an entity has more than one @PrimaryColumn, or when a route id, association, or array-mutation write on such an entity behaves unexpectedly./dto-slotsReference for Kavo's six optional schema slots (create/update/patch/query/item/list) — entity-derived defaults, the schemaShapeKeys narrowing rule, and serialization order. Use when configuring a DTO class or validator on @Kavo's schema option, or answering "why isn't my field showing/hiding" or "what shape does this response have" questions./error-handlingReference for Kavo's exception hierarchy, KAVO_* error-code catalog, and the RFC 9457 problem-details wire shape every generated route returns on failure. Use when handling/mapping a Kavo error, deciding which exception to throw from a custom handler/@Override, or answering "what does the error response look like" questions./global-configReference for Kavo's global configuration — the KavoSettings precedence chain, built-in defaults table, KavoModule.forRoot/forRootAsync options, and the operations.<id> global-default caveat (ADR-0015). Use when wiring createKavo/KavoModule.forRoot, setting app-wide defaults, or answering "what can I configure globally" questions./graphql-bindingReference for @kavo/graphql and its Nest binding — building a schema over an existing createCrud service, the raw-AST filter/sort args, multi-entity merging, the process-wide type registry, and the zero-code KavoModule graphql option. Use when exposing an entity over GraphQL, or answering "how do I add GraphQL to this entity" questions./kavo-decoratorReference for what @Kavo(Entity, config?) generates and how to configure/override it — routes table, EntityConfig shape (schema/allowed/operations), manual-method-wins, @Override, and fully custom routes. Use when writing or reviewing a @Kavo-decorated controller, or answering "how do I configure/override this route" questions.Other plugins' skills for the same job