From harness-claude
Uses generated Prisma types (XxxCreateInput, XxxWhereInput, $Enums, validator) for type-safe service layers, DTOs, and query payloads.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:prisma-type-generationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Use generated Prisma types like XxxCreateInput, XxxWhereInput, $Enums, and validator utilities
Use generated Prisma types like XxxCreateInput, XxxWhereInput, $Enums, and validator utilities
npx prisma generate
This runs automatically after migrate dev but must be run manually after editing the schema without migrating.
@prisma/client:import { Prisma, User, Post, Role } from '@prisma/client';
User, Post — model types (the shape returned by queries)Role — enum typePrisma — namespace containing all input/output typesimport { Prisma } from '@prisma/client';
async function createUser(data: Prisma.UserCreateInput) {
return prisma.user.create({ data });
}
async function findUsers(where: Prisma.UserWhereInput) {
return prisma.user.findMany({ where });
}
$Enums export or directly:import { Role } from '@prisma/client';
// Use as a type
function isAdmin(role: Role): boolean {
return role === 'ADMIN';
}
// Use enum values
const defaultRole: Role = 'USER';
Prisma.UserGetPayload:type UserWithPosts = Prisma.UserGetPayload<{
include: { posts: true };
}>;
// UserWithPosts = User & { posts: Post[] }
select queries:type UserSummary = Prisma.UserGetPayload<{
select: { id: true; name: true; email: true };
}>;
// UserSummary = { id: string; name: string | null; email: string }
Prisma.validator to create reusable, type-checked query objects:const userWithPosts = Prisma.validator<Prisma.UserDefaultArgs>()({
include: { posts: true },
});
// Use in queries
const user = await prisma.user.findUnique({
where: { id },
...userWithPosts,
});
const userSelect = Prisma.validator<Prisma.UserSelect>()({
id: true,
email: true,
name: true,
});
type PublicUser = Prisma.UserGetPayload<{ select: typeof userSelect }>;
async function getPublicUser(id: string): Promise<PublicUser | null> {
return prisma.user.findUnique({ where: { id }, select: userSelect });
}
Prisma.UserScalarFieldEnum for dynamic field selection:const sortableFields = ['createdAt', 'name', 'email'] as const;
function buildOrderBy(field: (typeof sortableFields)[number]): Prisma.UserOrderByWithRelationInput {
return { [field]: 'desc' };
}
JsonValue types from Json fields:import { Prisma } from '@prisma/client';
// Prisma.JsonValue = string | number | boolean | null | Prisma.JsonObject | Prisma.JsonArray
function parseMetadata(json: Prisma.JsonValue): Record<string, unknown> {
if (typeof json === 'object' && json !== null && !Array.isArray(json)) {
return json as Record<string, unknown>;
}
return {};
}
Prisma generates TypeScript types in node_modules/.prisma/client/index.d.ts based on your schema. These types power autocompletion, compile-time checking, and the entire Prisma Client API.
Type categories:
User, Post) — plain objects representing a full database rowUserCreateInput, UserUpdateInput, UserWhereInput) — types for query argumentsUserGetPayload<T>) — types derived from specific select/include combinationsRole, Status) — string literal unions matching schema enumsUserScalarFieldEnum) — union of field name stringsUserCreateInput vs UserUncheckedCreateInput: The Create input uses relation fields (author: { connect: { id } }). The Unchecked variant uses raw foreign keys (authorId: string). Both produce the same SQL. Use the standard version for type safety; use the unchecked version when working with raw IDs.
Keeping types in sync: Types are generated into node_modules and are not committed to version control. Run prisma generate in CI before type-checking. Add it to your build pipeline:
{ "scripts": { "build": "prisma generate && tsc" } }
Zod integration: Use zod-prisma-types or prisma-zod-generator to auto-generate Zod schemas from your Prisma models. This eliminates manual synchronization between Prisma types and runtime validation:
generator zod {
provider = "zod-prisma-types"
}
https://prisma.io/docs/orm/prisma-client/type-safety
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeDesigns Prisma schemas with datasource, generator, models, field types, and attributes. Helps create new schemas, add models, or configure providers.
Production patterns and non-obvious traps for Prisma ORM in TypeScript backends — schema design, query optimization, transactions, pagination, bulk operations, migrations, and serverless deployment gotchas.
Provides fast reference for Prisma 5+ ORM: schema design, migrations, type-safe CRUD, relations, transactions, error handling, testing, and integrations with Supabase, PlanetScale, Neon for TypeScript/JavaScript database access.