Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename zodSchema to schema
  • Loading branch information
kingston committed Nov 20, 2025
commit c38be4868342e1b1d9574283db50e1c604f33e9b
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function fileField<
: { connect: { id: string } } | undefined
> {
return {
zodSchema: fileInputSchema as TOptional extends true
schema: fileInputSchema as TOptional extends true
? z.ZodOptional<z.ZodNullable<typeof fileInputSchema>>
: typeof fileInputSchema,
processInput: async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ export function generateCreateSchema<
TFields extends Record<string, AnyFieldDefinition>,
>(fields: TFields): InferInputSchema<TFields> {
const shape = Object.fromEntries(
Object.entries(fields).map(([key, field]) => [key, field.zodSchema]),
Object.entries(fields).map(([key, field]) => [key, field.schema]),
) as {
[K in keyof TFields]: TFields[K]['zodSchema'];
[K in keyof TFields]: TFields[K]['schema'];
};

return z.object(shape);
Expand Down Expand Up @@ -615,7 +615,7 @@ type UpdateOperationFunction<
input: UpdateOperationInput<TModelName, TFields, TQueryArgs>,
) => Promise<GetPayload<TModelName, TQueryArgs>>) & {
$dataSchema: z.ZodObject<{
[k in keyof TFields]: z.ZodOptional<TFields[k]['zodSchema']>;
[k in keyof TFields]: z.ZodOptional<TFields[k]['schema']>;
}>;
};
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Payload } from '@prisma/client/runtime/client';

import { z } from 'zod';
import type { z } from 'zod';

import { prisma } from '@src/services/prisma.js';

Expand All @@ -23,7 +22,11 @@ import type {
TransactionalOperationContext,
} from './types.js';

import { invokeHooks, transformFields } from './define-operations.js';
import {
generateCreateSchema,
invokeHooks,
transformFields,
} from './define-operations.js';
import { makeGenericPrismaDelegate } from './prisma-utils.js';

/**
Expand Down Expand Up @@ -74,7 +77,7 @@ export function scalarField<
},
): FieldDefinition<TSchema, TTransformed, TTransformed> {
return {
zodSchema: schema,
schema,
processInput: (value) => {
// Apply transform if provided
const transformed = options?.transform
Expand Down Expand Up @@ -266,16 +269,7 @@ export function nestedOneToOneField<
undefined | { delete: true }
> {
return {
zodSchema: (
z.object(
Object.fromEntries(
Object.entries(config.fields).map(([key, field]) => [
key,
field.zodSchema,
]),
),
) as InferInputSchema<TFields>
).nullish(),
schema: generateCreateSchema(config.fields).nullish(),
processInput: async (value, processCtx) => {
// Handle null - delete the relation
if (value === null) {
Expand Down Expand Up @@ -595,18 +589,7 @@ export function nestedOneToManyField<
};

return {
zodSchema: z
.array(
z.object(
Object.fromEntries(
Object.entries(config.fields).map(([key, field]) => [
key,
field.zodSchema,
]),
),
) as InferInputSchema<TFields>,
)
.optional(),
schema: generateCreateSchema(config.fields).array().optional(),
processInput: async (value, processCtx) => {
const { serviceContext, loadExisting } = processCtx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export interface FieldDefinition<
* This schema can be extracted and reused for validation in other contexts
* (e.g., GraphQL mutations, REST endpoints, tRPC procedures).
*/
zodSchema: TInputSchema;
schema: TInputSchema;

/**
* Processes and transforms an input value.
Expand Down