@polyprism/ts-interface
v0.3.1
Published
Prisma 6 & 7 generator that emits TypeScript interfaces (`export interface User { ... }`) from your schema. Pure ESM, zero runtime deps, configurable naming + annotations. Part of PolyPrism.
Maintainers
Readme
@polyprism/ts-interface
A Prisma 6 & 7 generator that emits TypeScript interfaces from your schema.prisma. Part of PolyPrism.
export interface User {
id: string;
email: string;
name: string | null;
role: Role;
}Pure ESM, Prisma 7-native, zero third-party runtime dependencies. CI tests against both Prisma 6 and Prisma 7. The generated code imports nothing from PolyPrism itself — drop the generator and your output keeps compiling.
Install
pnpm add -D prisma @polyprism/ts-interfaceConfigure
generator polyprismCodegen {
provider = "polyprism-ts-interface"
output = "../generated"
}⚠️ The provider string is the bin name (no
@scope/prefix). Bin names can't contain/, so you writepolyprism-ts-interface, not@polyprism/ts-interface.
Run
pnpm prisma generateOutput
// generated/User.ts
import type { Role } from "./enums/Role.js";
export interface User {
id: string;
email: string;
name: string | null;
role: Role;
}Every enum is also emitted as its own standalone ESM file at <output>/enums/<EnumName>.ts, so you can Object.values(MyEnum) directly without re-exporting through @prisma/client (whose CJS shape doesn't always play nicely with ESM consumers).
What you get out of the box
- Prisma 6 & 7 compatibility — same generator binary, both Prisma majors. CI tests against both, including the Prisma 7
prisma.config.tslayout. - Pure ESM from day one — not retrofitted from a CJS codebase. No
require(), no.cjsre-export shims, no surprise. - Zero third-party runtime dependencies. This package depends only on
@polyprism/coreand@polyprism/ts-shared, neither of which has a third-party runtime dep. - Eight
///annotations — see Annotations below. - Three-axis naming config — independently control file, type, and field naming (
snake_case,kebab-case,PascalCase,camelCase, orpreserve). - Per-identifier
@name(NewName)override — escape hatch for the global naming rule. @db.X(p, s)precision captured as JSDoc so the schema-level info survives codegen.- Optional barrel (
emitIndex = true). - Pretty-formatted inline JSON types — multi-property objects from
@json({ ... })get broken onto multiple lines instead of collapsed onto one. prisma-json-types-generatorshorthand compatibility —/// [TypeName]accepted as an alias for@json(TypeName), so existing schemas migrate cleanly.
Config options
All keys go on the generator polyprismCodegen { ... } block:
| Key | Default | Options |
|---|---|---|
| output | — | Path to the output directory (relative to the schema). |
| fileNaming | PascalCase | PascalCase | camelCase | kebab-case | snake_case | preserve |
| typeNaming | PascalCase | PascalCase | camelCase | snake_case | preserve |
| fieldNaming | preserve | camelCase | snake_case | preserve |
| emitIndex | false | "true" to emit a barrel index.ts. |
Annotations
All annotations live in Prisma triple-slash doc comments (///):
| Annotation | What it does |
|---|---|
| @hide | Drop a field/enum-value from the generated output entirely. |
| @deprecated("reason") | Emit a @deprecated JSDoc tag. Reason optional. |
| @json(Type) | Brand a Json field with a TypeScript type. Four forms: bare, with-import, inline-anonymous, inline-named. |
| @type(MyType from "./path") | Override the inferred TS type entirely. |
| @name(NewIdent) | Rename the emitted identifier (escapes global casing). |
| @normalise(...) | Parsed across all patterns; runtime behaviour fires only in @polyprism/ts-domain-class (trim / lowercase / uppercase / nullEmptyToNull on setter assignment). |
| @coerce(...) / @noCoerce | Parsed across all patterns; runtime behaviour fires only in @polyprism/ts-domain-class (Int/Float/Decimal/BigInt/DateTime coerce-by-default; opt out per-field). |
Full grammar in the root README.
Sibling patterns
Same schema, different output shape — just swap the provider:
@polyprism/ts-type—export type User = { ... };@polyprism/ts-class—export class User { ... }with real initializer expressions@polyprism/ts-domain-class— opinionated domain class with getters/setters,@normalise/@coercedata laundering,from(),toJSON(), and a fluent builder
More patterns on the roadmap: Zod, Valibot, ArkType, TypeBox.
License
MIT © Travis Fitzgerald
