IdTransform
IdTransform<
Brand> =object
Defined in: src/adapters/prisma.ts:50
Read/write transform pair and $extends result-component factory for
integrating Id<Brand> with Prisma extensions.
Type Parameters
Section titled “Type Parameters”Brand extends string
Methods
Section titled “Methods”computeField()
Section titled “computeField()”computeField(
fieldName):IdComputeField<Brand>
Defined in: src/adapters/prisma.ts:88
Creates a typed $extends result-component field definition that carries
Id<Brand> through Prisma’s type machinery without a per-call-site cast.
Parameters
Section titled “Parameters”fieldName
Section titled “fieldName”string
The model field to read from (e.g. "id").
Returns
Section titled “Returns”IdComputeField<Brand>
An IdComputeField whose compute return type is statically
Id<Brand>, so the extended-client model field is typed correctly.
Example
Section titled “Example”const xprisma = prisma.$extends({ result: { user: { id: userIdField.computeField("id") }, },});// xprisma.user.findUnique(…).id is typed as Id<"usr"> — no cast requiredcomputeNullableField()
Section titled “computeNullableField()”computeNullableField(
fieldName):NullableIdComputeField<Brand>
Defined in: src/adapters/prisma.ts:126
Like computeField but for nullable columns — compute returns
Id<Brand> | null instead of Id<Brand>.
Parameters
Section titled “Parameters”fieldName
Section titled “fieldName”string
The nullable model field to read from.
Returns
Section titled “Returns”NullableIdComputeField<Brand>
A NullableIdComputeField whose compute returns Id<Brand> | null.
defaultQuery()
Section titled “defaultQuery()”defaultQuery(
fieldName):IdQueryField
Defined in: src/adapters/prisma.ts:118
Creates a $extends query-component model slice that auto-generates
Id<Brand> values for create, createMany, createManyAndReturn, and
upsert operations when the field is absent, undefined, or null in
args.data (or args.create for upsert). When the field is absent,
undefined, or null, a fresh Id<Brand> is injected; when present, the
value is validated via codec.safeParse and IdsError("invalid_id") is
thrown if invalid.
Parameters
Section titled “Parameters”fieldName
Section titled “fieldName”string
The model field to auto-generate (e.g. "id").
Returns
Section titled “Returns”An IdQueryField suitable for the model-level value inside
a Prisma $extends({ query: { modelName: … } }) block.
Remarks
Section titled “Remarks”Nested-relation-write limitation: ID fields inside nested relation writes
(data: { posts: { create: { … } } }, connectOrCreate.create, etc.) are
not reached by any model-level defaultQuery hook. Callers must validate
or generate nested IDs explicitly at the service layer.
Example
Section titled “Example”const xprisma = prisma.$extends({ query: { user: userIdField.defaultQuery("id") }, result: { user: { id: userIdField.computeField("id") } },});// id is auto-filled on create, and typed as Id<"usr"> on readawait xprisma.user.create({ data: { name: "Alice" } });read()
Section titled “read()”read(
value):Id<Brand>
Defined in: src/adapters/prisma.ts:56
Read transform: validates the raw database value via safeParse and returns
Id<Brand>. Throws if the value is missing, malformed, or belongs to a
different brand.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”Id<Brand>
readNullable()
Section titled “readNullable()”readNullable(
value):Id<Brand> |null
Defined in: src/adapters/prisma.ts:61
Nullable read transform: returns null when value is null or undefined;
otherwise delegates to read. Use for optional foreign keys.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”Id<Brand> | null
write()
Section titled “write()”write(
value):string
Defined in: src/adapters/prisma.ts:69
Write transform: validates value via codec.safeParse and returns the
canonical string form. Throws IdsError("invalid_id") if the value is
invalid, belongs to a different brand, or is null/undefined.
Use in a Prisma $extends query component or explicit data mapping.
Parameters
Section titled “Parameters”Id<Brand>
Returns
Section titled “Returns”string