/kavo-skills:composite-primary-keysfrom Kavo Developer Skills
Documents composite primary key support in @kavo/typeorm: compositeIdFields metadata, ~-delimited route ids, creatable/updatable split, and known gaps in other ORM adapters or many-to-many writes.
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/typeorm)An entity with more than one @PrimaryColumn — a natural key with no
surrogate id — is supported, TypeORM only:
@Entity()
export class UserSentence {
@PrimaryColumn("uuid")
userId!: string;
@PrimaryColumn()
topic!: string;
@Column()
key!: string;
}
EntityMetadata.compositeIdFields reports the key columns, in declaration
order. idField still exists (the first declared column, for callers that
only ever need one name) but nothing that addresses a row's real identity
may rely on it alone once compositeIdFields is set.
One path segment, key columns joined by ~:
GET /user-sentences/u1~billing → { userId: "u1", topic: "billing" }
A literal ~ inside a value is escaped by doubling it (~~) — the id has
already passed URL decoding by the time Kavo sees it, so percent-escaping
the separator would be silently invisible. encodeCompositeId/
decodeCompositeId (@kavo/core's barrel) implement the codec; a malformed
id (wrong part count) is a clean 400, never a driver error.
Key columns are creatable but not updatable: createOne accepts them
(a natural key the client supplies), updateOne/patchOne silently drop
them from the body — the row's identity doesn't change after creation.
This is the one case where creatable's and updatable's shared default
diverges; narrow either explicitly (see the kavo-decorator skill) if that
default is wrong for an entity.
Offset, page, cursor, and since all work. Cursor/since force the sort's
tail to the full compositeIdFields tuple, in declaration order, instead
of a single idField — sort=-createdAt,userId,topic, not
sort=-createdAt,userId. A since token's id half reuses the same
~-delimited encoding a route id uses.
Works in both directions:
include= it normally.{ owner: { userId: "u1", topic: "billing" } }) or the bare
~-delimited scalar ({ owner: "u1~billing" }). Either narrows to the
target's real column names before it reaches the adapter.| Area | Status |
|---|---|
@kavo/prisma, @kavo/mongoose, @kavo/mikroorm | Not supported. Each still requires exactly one primary column; none populates compositeIdFields. This is @kavo/typeorm only. |
Many-to-many array-mutation writes (replaceRelation/patchRelation/the resource strategy) on a composite entity's own relation | Not supported. TypeORM's RelationQueryBuilder.add/.set validate the member value's shape against the owning side's join-column count — 2+ for a composite owner, unsatisfiable by any bare member id on the other side. Upstream TypeORM behavior, not a Kavo choice. createCrud refuses this at bootstrap (ConfigurationException), not on first request. |
| One-to-many array-mutation writes on a composite entity's own relation | Supported. The foreign key lives on the child row, not a junction table, so the limitation above doesn't apply. |
@kavo/graphql | Not usable for a composite-key entity. The generated schema types every id argument as a non-null GraphQL Int (schema.ts), so a composite entity's string id can never pass GraphQL's own type coercion. Pre-dates composite-key support; also blocks any string/UUID-keyed entity. |
@kavo/mcp | Works. Its id argument schema already accepts string | number. |
@kavo/nest routes / @nestjs/swagger | Works. :id is an untyped route param already; the generated ApiParam doesn't spell out the ~-delimited format, but nothing rejects it. |
Bulk operations (createMany, updateMany, …) | Not built for any entity yet — unrelated to composite keys. |
Full design and the exact upstream TypeORM check:
docs/internals/adr/0039-composite-primary-keys-are-typeorm-only.md.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
15 skills in this plugin
/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./mcp-bindingReference for @kavo/mcp and its Nest binding — the standard per-entity toolset, findMany's raw-AST filter/sort args, flat update/patch args, isError result mapping, the zero-config KavoModule mcp option, and the fact that the default MCP route carries no auth guard. Use when exposing entities to an MCP client, or answering "how do I add MCP tools to this entity" questions.npx claudepluginhub kavo-labs/kavo --plugin kavo-skillsOther plugins' skills for the same job