Open-Source Wikis

/

Prisma

/

Packages

/

client-generator-ts

prisma/prisma

client-generator-ts

Active contributors: jacek-prisma, Oleksii Orlenko

Purpose

packages/client-generator-ts implements the new prisma-client generator. When a user declares a generator block with provider = "prisma-client", this package emits the TypeScript code that becomes their @prisma/client import.

It is the modern counterpart to client-generator-js, which targets the older prisma-client-js provider. Both generators ship simultaneously in Prisma 7 — the legacy generator is kept for users who haven't migrated.

What it produces

Given a Prisma schema, this generator emits:

  • A PrismaClient class typed for the user's models
  • A namespace (Prisma) with input/output/where types per model
  • Per-model selector/filter types
  • Validators for runtime checks

The output goes to the path declared by the user's output directive. The legacy generator wrote to node_modules/.prisma/client; the new generator's recommended pattern is an explicit project-relative output = "../generated" so the artifact is committed-or-not on the user's terms.

Directory layout

packages/client-generator-ts/src/
├── TSClient/
│   ├── file-generators/
│   │   └── PrismaNamespaceFile.ts    # buildClientOptions for the Prisma namespace
│   └── ...                            # The TSClient class hierarchy
├── ...
└── (helpers, fixtures, test scaffolding)

Key abstractions

Symbol File What it does
buildClientOptions function packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts Emits the TypeScript declaration for PrismaClientOptions
File generator classes packages/client-generator-ts/src/TSClient/file-generators/ Each one emits a specific output file (model types, namespace, runtime, …)

Generators use @prisma/ts-builders for fluent TypeScript code emission — interfaces, types, properties with doc comments — instead of templating strings.

Generation flow

graph LR
    Schema[schema.prisma] --> Wasm[prisma-schema-wasm]
    Wasm --> DMMF[DMMF AST]
    DMMF --> Generator[client-generator-ts]
    Generator --> Builders[@prisma/ts-builders]
    Builders --> Files[Generated TS files]
    Files --> Output[(./generated)]

The CLI calls into @prisma/internals.getGenerators to enumerate registered generators, then dispatches each generator with the DMMF AST and project config. client-generator-ts and client-generator-js are both registered through @prisma/client-generator-registry.

Prisma client options synchronization

Adding a new field to PrismaClient constructor options requires touching both generators:

  • packages/client-generator-js/src/TSClient/PrismaClient.tsbuildClientOptions method
  • packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.tsbuildClientOptions function

These two files emit the user-visible PrismaClientOptions type for their respective generated clients. The runtime validation is shared (in @prisma/client), but the type needs to be emitted in two flavors. See @prisma/client for the full five-step procedure.

Integration points

  • Schema input — DMMF from @prisma/internals.getDMMF (which calls @prisma/prisma-schema-wasm)
  • Output emission@prisma/ts-builders for type/interface/property declarations
  • Registration@prisma/client-generator-registry
  • Output target — files imported by the user's import { PrismaClient } from './generated/client'
  • Runtime imports — generated clients import @prisma/client/runtime/... for the actual implementation

Entry points for modification

  • Change a generated type's shape: find the file generator under src/TSClient/file-generators/ and edit
  • Add a new generated file: add a new file generator class and register it where the others are
  • Match a new constructor option: edit PrismaNamespaceFile.ts buildClientOptions (and its sibling in client-generator-js)
  • Output formatting: file generators produce ts-builders AST; the textual output is determined by ts-builders' renderer

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

client-generator-ts – Prisma wiki | Factory