@polyprism/core
v0.3.1
Published
Prisma schema IR, reader, annotation parser, and naming layer powering PolyPrism's Prisma 6 & 7 generators. Pure ESM, zero third-party runtime deps.
Downloads
2,093
Maintainers
Readme
@polyprism/core
Internal runtime + IR layer behind PolyPrism — a Prisma 6 & 7 generator that emits TypeScript types from your schema.prisma in whichever shape fits the layer you're writing: interface, type, plain class, or an opinionated domain class with setter-driven @normalise/@coerce data laundering today, with Zod / Valibot / ArkType / TypeBox on the roadmap.
One Prisma schema. Many shapes. Pick your output by changing a single config string.
Pure ESM, Prisma 7-native, zero third-party runtime dependencies on any published @polyprism/* package. CI tests against both Prisma 6 and Prisma 7.
You're probably looking for a pattern package
You don't install @polyprism/core directly — each pattern package pulls it in transitively.
| Install | What it emits |
|---|---|
| @polyprism/ts-interface | export interface User { ... } |
| @polyprism/ts-type | export type User = { ... }; |
| @polyprism/ts-class | export class User { ... } — plain class, public fields |
| @polyprism/ts-domain-class | Opinionated domain class — private fields, getters/setters with @normalise/@coerce data laundering, from(), toJSON(), builder |
What @polyprism/core actually does
It's the brain every pattern package shares:
- IR —
ModelDef,FieldDef,EnumDef,AnnotationSet. A language-agnostic intermediate representation of your Prisma schema that every emitter reads from. - Schema reader — DMMF → IR translation. Internal; never exported. This firewall is what lets pattern packages stay third-party-runtime-dep-free, and keeps Prisma's officially-unstable DMMF surface from leaking into user code.
- Annotation parser —
parseAnnotationsunderstands eight triple-slash annotations:@hide,@deprecated,@json(four forms),@type,@name,@normalise,@coerce,@noCoerce. Plusprisma-json-types-generatorshorthand compatibility (/// [TypeName]). - Naming resolver —
resolveTypeIdent,resolveFieldIdent,resolveTypeFilename. Three-axis (file / type / field) casing config: snake, kebab, Pascal, camel, preserve. With per-identifier@name(NewName)overrides. - Generator runtime —
defineGenerator,GeneratorContext, virtual filesystem for testability. - Shared emitter helpers —
emitEnums,emitJsonTypes,prettyFormatType,createInMemoryFileWriter.
Why this is a separate package
Two reasons:
- Pattern packages stay tiny. Each
@polyprism/ts-*package ships only its emitter and depends on@polyprism/core(plus@polyprism/ts-sharedfor the TS family) — nothing else. Forts-interface,ts-type, andts-class, the generated code imports nothing from PolyPrism either, so you can drop the generator and your output keeps compiling.ts-domain-classis the one exception: it emits imports from@polyprism/runtime— a ~70 LOC, zero-third-party-dep runtime helper — in exchange for setter-driven@normalise/@coercedata laundering. - One brain, many emitters. Every pattern reads the same IR, so the
interfaceversion and theclassversion of your schema agree on field names, file layout, JSON-type handling, and annotation behaviour — by construction, not by convention.
Links
- PolyPrism on GitHub — full feature list, annotation reference, side-by-side pattern examples
- Issue tracker
License
MIT © Travis Fitzgerald
