@polyprism/ts-shared
v0.3.1
Published
Shared TypeScript rendering primitives used by PolyPrism's Prisma 6 & 7 generators (ts-interface, ts-type, ts-class, ts-domain-class). Pure ESM.
Maintainers
Readme
@polyprism/ts-shared
TypeScript rendering primitives shared by every ts-* pattern in 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.
Pure ESM, Prisma 7-native, zero third-party runtime dependencies on any published @polyprism/* package.
You're probably looking for a pattern package
You don't install @polyprism/ts-shared directly — each ts-* 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 lives here
The TypeScript-specific layer between @polyprism/core's language-agnostic IR and the per-pattern emitters:
renderModel({ declarationStyle })— emits one model file, parameterised by"interface" | "type" | "class" | "domain-class". The three "flat" styles (interface,type,class) share one code path; only the declaration keyword and default-value handling differ. The fourth (domain-class) delegates to a sibling renderer (renderDomainClass) because private fields, accessor pairs, and theInitinterface are different enough in shape that branching the flat path got messy. All four still share the same import handling, JSON-type plumbing, naming resolution, and JSDoc emission — agreement by construction, not by convention.renderIndex({ declarationStyle })— emits the optional barrel (index.ts) with class-mode awareness, so it usesexport { User }for class / domain-class output andexport type { User }for interface/type output.mapFieldTsType— IR field → TypeScript type expression. Handles enums,Json-typed fields (with the four@json(...)annotation forms),Decimal,BigInt,Bytes, arrays, and nullability.ImportCollector— deduped, sorted, type-vs-value-aware import block builder. Auto-promotes atypeimport to a value import when the same symbol appears as a runtime default in class mode.renderJsDoc— JSDoc emission for///docs,@deprecatedtags, and@db.X(p, s)precision metadata so the schema-level info survives codegen.
Why this is split out from @polyprism/core
@polyprism/core is deliberately language-agnostic — IR, Prisma schema reader, annotation parser, naming resolver. @polyprism/ts-shared is where TypeScript-specific concerns live. Every ts-* pattern in PolyPrism shares one TypeScript rendering layer, so they agree on import handling, naming, and JSDoc emission 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
