P
Prisma7mo ago
vpjm

What does DevTypeMapDef represent, and how is it intended to be used?

Everything's in the title
4 Replies
Prisma AI Help
Prisma AI Help7mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul7mo ago
Can you elaborate please? Where did you encounter DevTypeMapDef?
vpjm
vpjmOP6mo ago
I don't understand the TypeMap constructed by https://github.com/prisma/prisma/blob/f8f315bf2638b1c0de3bd10aa7c9006520b27fd6/packages/client-generator-js/src/TSClient/PrismaClient.ts#L28 — does it represent an actual runtime value, or is it just a type built from another structure like the DMMF?
GitHub
prisma/packages/client-generator-js/src/TSClient/PrismaClient.ts at...
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - prisma/prisma
vpjm
vpjmOP6mo ago
export type $ModelPayload<ExtArgs extends $Extensions.InternalArgs = $Extensions.DefaultArgs> = {
name: "Model"
objects: {
relations_model2: Prisma.$Model2Payload<ExtArgs>
}
scalars: $Extensions.GetPayloadResult<{
fk_model2_id: number
field1: string | null
}>
}
export type $ModelPayload<ExtArgs extends $Extensions.InternalArgs = $Extensions.DefaultArgs> = {
name: "Model"
objects: {
relations_model2: Prisma.$Model2Payload<ExtArgs>
}
scalars: $Extensions.GetPayloadResult<{
fk_model2_id: number
field1: string | null
}>
}
export declare interface FieldRef<Model, FieldType> {
readonly modelName: Model;
readonly name: string;
readonly typeName: FieldType;
readonly isList: boolean;
}
export declare interface FieldRef<Model, FieldType> {
readonly modelName: Model;
readonly name: string;
readonly typeName: FieldType;
readonly isList: boolean;
}
Then in the TypeMap, there's something like:
globalOmitOptions: {
omit: GlobalOmitOptions
},
meta: {
modelProps: "model" | "model2",
txIsolationLevel: Prisma.TransactionIsolationLevel
},
model: {
Model: {
payload: Prisma.$ModelPayload<ExtArgs>,
fields: Prisma.ModelFieldRefs,
operations: {
findUnique: {
args: Prisma.ModelFindUniqueArgs<ExtArgs>,
result: $Utils.PayloadToResult<Prisma.$ModelPayload> | null
},
...
}
},
...
},
other: {
payload: any,
operations: {
$executeRaw: { ... },
...
}
}
globalOmitOptions: {
omit: GlobalOmitOptions
},
meta: {
modelProps: "model" | "model2",
txIsolationLevel: Prisma.TransactionIsolationLevel
},
model: {
Model: {
payload: Prisma.$ModelPayload<ExtArgs>,
fields: Prisma.ModelFieldRefs,
operations: {
findUnique: {
args: Prisma.ModelFindUniqueArgs<ExtArgs>,
result: $Utils.PayloadToResult<Prisma.$ModelPayload> | null
},
...
}
},
...
},
other: {
payload: any,
operations: {
$executeRaw: { ... },
...
}
}
It seems like TypeMap is used as the source of truth for typing — it provides the types used throughout the rest of the codebase. My goal is to understand how Prisma types its client so that I can then design an interface or type that describes what a model is, what metadata is associated with a model, etc. Once that's defined, the idea is that this interface would take a TypeMap as a generic parameter — and from that, we could derive the required operations, metadata, and so on. This would be a step toward a solution that’s less tightly coupled to Prisma’s current client implementation, and more focused on how Prisma views and describes the underlying data layer. Eventually, this could open the door to using a different ORM that still respects the same principles — such as providing a TypeMap, model metadata, and associated operations. But honestly, right now I don’t understand much. I know what each part represents, but I don’t know how they were generated, why they were designed that way, or why all of it is necessary. For example, payload seems to contain a lot of information, and I don’t really see why fields would be needed on top of that. That’s why I need help from someone more experienced with databases and Prisma internals. By the way, I don't know what this is: RenameAndNestPayloadKeys
export interface Prisma__Model1Client<T, Null = never, ExtArgs extends $Extensions.InternalArgs = $Extensions.DefaultArgs, GlobalOmitOptions = {}> extends Prisma.PrismaPromise<T> {
readonly [Symbol.toStringTag]: "PrismaPromise"
relations_model2<T extends Model1$relations_model2Args<ExtArgs> = {}>(args?: Subset<T, Model1$relations_model2Args<ExtArgs>>): Prisma.PrismaPromise<$Result.GetResult<Prisma.$CandidatePayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
export interface Prisma__Model1Client<T, Null = never, ExtArgs extends $Extensions.InternalArgs = $Extensions.DefaultArgs, GlobalOmitOptions = {}> extends Prisma.PrismaPromise<T> {
readonly [Symbol.toStringTag]: "PrismaPromise"
relations_model2<T extends Model1$relations_model2Args<ExtArgs> = {}>(args?: Subset<T, Model1$relations_model2Args<ExtArgs>>): Prisma.PrismaPromise<$Result.GetResult<Prisma.$CandidatePayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
By the way, what is this? Why do I have relations_ fields (foreign fields)?

Did you find this page helpful?