nesor
v0.1.1
Published
Generate clean, modular TypeScript domain entities from your Prisma schema. One file per model, doc-comment-driven exclusion, variants, and static metadata for your own mappers.
Maintainers
Readme
nesor
A Prisma generator that emits clean, modular TypeScript domain entities — one file per model, doc-comment-driven exclusion, variants, branded IDs, and static EntityMeta for your own mappers. Prisma comes bundled, so pnpm add -D nesor is the only install you need.
Quick start
Three commands from zero to generated entities:
pnpm add -D nesor
pnpm nesor init # bootstraps prisma/schema.prisma + adds the nesor block
pnpm nesor generate # writes one <model>.entity.ts per modelThat's it. Under the hood Nesor wraps the full Prisma CLI, so nesor migrate dev, nesor studio, nesor format, nesor db pull, and any other prisma subcommand are forwarded verbatim. You can still call pnpm prisma <...> directly if you prefer; both paths hit the same prisma that ships with Nesor.
What you get
For this schema:
/// A primary domain entity.
/// @nesor-variant Compact include=id,name
model ModelA {
/// @nesor-brand ModelAId
id String @id
name String
count Int
/// @nesor-secret
apiKey String
}Nesor emits a single file, fully typed, zero runtime deps:
// AUTO-GENERATED BY NESOR — DO NOT EDIT
export type ModelAId = string & { readonly __brand: 'ModelAId' }
/** A primary domain entity. */
export interface ModelAEntity {
id: ModelAId
name: string
count: number
}
export interface ModelACompactEntity {
id: ModelAId
name: string
}
export const ModelAEntityMeta = {
prismaModel: 'ModelA',
entityName: 'ModelAEntity',
fields: {
id: { source: 'id', kind: 'scalar', tsType: 'ModelAId', brand: 'ModelAId' },
name: { source: 'name', kind: 'scalar', tsType: 'string' },
count: { source: 'count', kind: 'scalar', tsType: 'number' },
},
excluded: ['apiKey'],
secrets: ['apiKey'],
variants: {
Compact: { include: ['id', 'name'] },
},
} as constapiKey is omitted from every interface, but recorded in excluded and secrets so audit code (or @nesor/mapper) can still see that it existed.
Why Nesor
- One file per model. Browse your domain like you browse your features.
- Schema is the source of truth. Nesor never modifies
schema.prisma. - Name-agnostic. No hardcoded knowledge of
email,password,createdAt. Everything flows from the DMMF and your///tags. - No business logic in emitted code. Mapping a Prisma row to an entity is your job. Use
@nesor/mapperfor trivial cases or roll your own. - Generated files are committed. Diff review is the safety net. Output is deterministic and formatter-friendly.
- Zero runtime deps in emitted code. Imports point at your enums (configurable) and other entity files — that's it.
CLI
nesor --help # full subcommand list
nesor init # bootstrap schema.prisma + add the nesor block
nesor generate # regenerate entities
nesor watch # watch + regenerate on schema change
nesor check # CI-friendly: fail if generated files drift from diskAny subcommand Nesor doesn't recognise is forwarded straight to the bundled prisma, so nesor migrate dev, nesor studio, nesor format, nesor db pull, etc. all work without leaving the nesor CLI.
Docs
- CONFIG — every option of the generator block.
- DSL — every
///tag. - VARIANTS — declaring and consuming variants.
- META — the
EntityMetashape. - MAPPER — the optional row-to-entity helper.
- RECIPES — clean architecture, soft delete, branded IDs, modules.
- COMPARISON — how Nesor differs from neighbouring tools.
Compatibility
- Node 20+
- Prisma 6.x (bundled —
pnpm add -D nesorbrings it in; you don't install it separately) @prisma/client6.x is still a runtime dep of your own app
License
MIT
