Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Keep query/mutation/action wrappers thin, put logic in TypeScript functions
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -25% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 112% | 0% |
| case-14 | ✗→✓ | ▲ Improved | -7% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 50% | 0% |
| case-16 | ✗→✓ | ▲ Improved | -12% | 0% |
Most business logic should live in plain TypeScript functions. Keep query, mutation, and action wrappers thin—they should primarily handle arguments and call shared logic.
Bad:
typescriptexport const createPost = mutation({ args: { title: v.string(), content: v.string() }, handler: async (ctx, args) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); const user = await ctx.db .query("users") .withIndex("by_token", q => q.eq("tokenIdentifier", identity.tokenIdentifier)) .unique(); if (!user) throw new Error("User not found"); // ... 50 more lines of logic ... }, });
Good:
typescript// convex/lib/auth.ts export async function getCurrentUser(ctx: QueryCtx | MutationCtx) { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); const user = await ctx.db .query("users") .withIndex("by_token", q => q.eq("tokenIdentifier", identity.tokenIdentifier)) .unique(); if (!user) throw new Error("User not found"); return user; } // convex/posts.ts export const createPost = mutation({ args: { title: v.string(), content: v.string() }, handler: async (ctx, args) => { const user = await getCurrentUser(ctx); return await createPostInternal(ctx, user._id, args); }, }); async function createPostInternal( ctx: MutationCtx, userId: Id<"users">, args: { title: string; content: string } ) { // ... logic here ... return await ctx.db.insert("posts", { userId, title: args.title, content: args.content, createdAt: Date.now(), }); }
Other measured skills in the registry, with their headline benchmark lift.