Skip to content

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.

Brand extends string

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.

string

The model field to read from (e.g. "id").

IdComputeField<Brand>

An IdComputeField whose compute return type is statically Id<Brand>, so the extended-client model field is typed correctly.

const xprisma = prisma.$extends({
result: {
user: { id: userIdField.computeField("id") },
},
});
// xprisma.user.findUnique(…).id is typed as Id<"usr"> — no cast required

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>.

string

The nullable model field to read from.

NullableIdComputeField<Brand>

A NullableIdComputeField whose compute returns Id<Brand> | null.


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.

string

The model field to auto-generate (e.g. "id").

IdQueryField

An IdQueryField suitable for the model-level value inside a Prisma $extends({ query: { modelName: … } }) block.

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.

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 read
await xprisma.user.create({ data: { name: "Alice" } });

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.

unknown

Id<Brand>


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.

unknown

Id<Brand> | null


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.

Id<Brand>

string