From 7b1a77864c6fd5c4163603bda0656278e6a8a0a2 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:10:51 -0800 Subject: [PATCH 1/4] fix(orm): select/include nullability --- packages/orm/src/client/crud-types.ts | 36 +++++---------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/packages/orm/src/client/crud-types.ts b/packages/orm/src/client/crud-types.ts index 0a46b999..49364b6a 100644 --- a/packages/orm/src/client/crud-types.ts +++ b/packages/orm/src/client/crud-types.ts @@ -698,10 +698,7 @@ export type CreateArgs< > = SimplifyIf< { data: CreateInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -715,13 +712,7 @@ export type CreateManyAndReturnArgs< Schema extends SchemaDef, Model extends GetModels, Simplify extends boolean = false, -> = SimplifyIf< - CreateManyInput & { - select?: SelectInput; - omit?: OmitInput; - }, - Simplify ->; +> = SimplifyIf & Omit, 'include'>, Simplify>; type OptionalWrap, T extends object> = Optional< T, @@ -855,10 +846,7 @@ export type UpdateArgs< { data: UpdateInput; where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -872,13 +860,7 @@ export type UpdateManyAndReturnArgs< Schema extends SchemaDef, Model extends GetModels, Simplify extends boolean = false, -> = SimplifyIf< - UpdateManyPayload & { - select?: SelectInput; - omit?: OmitInput; - }, - Simplify ->; +> = SimplifyIf & Omit, 'include'>, Simplify>; type UpdateManyPayload, Without extends string = never> = { data: OrArray>; @@ -895,10 +877,7 @@ export type UpsertArgs< create: CreateInput; update: UpdateInput; where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -1019,10 +998,7 @@ export type DeleteArgs< > = SimplifyIf< { where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; From 11e17e2015a586ce013da2736b199f59b49724cf Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:20:10 -0800 Subject: [PATCH 2/4] update --- packages/orm/src/client/crud-types.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/orm/src/client/crud-types.ts b/packages/orm/src/client/crud-types.ts index 49364b6a..944d6881 100644 --- a/packages/orm/src/client/crud-types.ts +++ b/packages/orm/src/client/crud-types.ts @@ -451,8 +451,13 @@ export type OmitInput> [Key in NonRelationFields]?: boolean; }; -export type SelectIncludeOmit, AllowCount extends boolean> = { - select?: SelectInput | null; +export type SelectIncludeOmit< + Schema extends SchemaDef, + Model extends GetModels, + AllowCount extends boolean, + AllowRelation extends boolean = true, +> = { + select?: SelectInput | null; include?: IncludeInput | null; omit?: OmitInput | null; }; @@ -712,7 +717,10 @@ export type CreateManyAndReturnArgs< Schema extends SchemaDef, Model extends GetModels, Simplify extends boolean = false, -> = SimplifyIf & Omit, 'include'>, Simplify>; +> = SimplifyIf< + CreateManyInput & Omit, 'include'>, + Simplify +>; type OptionalWrap, T extends object> = Optional< T, @@ -860,7 +868,10 @@ export type UpdateManyAndReturnArgs< Schema extends SchemaDef, Model extends GetModels, Simplify extends boolean = false, -> = SimplifyIf & Omit, 'include'>, Simplify>; +> = SimplifyIf< + UpdateManyPayload & Omit, 'include'>, + Simplify +>; type UpdateManyPayload, Without extends string = never> = { data: OrArray>; From 09e61cd30368a333089127bab72f8872b5883c68 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:23:59 -0800 Subject: [PATCH 3/4] update --- .../orm/src/client/crud/operations/create.ts | 16 ++++++++++------ .../orm/src/client/crud/operations/update.ts | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/orm/src/client/crud/operations/create.ts b/packages/orm/src/client/crud/operations/create.ts index 1e1c9869..b58871c0 100644 --- a/packages/orm/src/client/crud/operations/create.ts +++ b/packages/orm/src/client/crud/operations/create.ts @@ -78,13 +78,17 @@ export class CreateOperationHandler extends BaseOperat const createResult = await this.createMany(tx, this.model, args, true, undefined, selectedFields); if (needReadBack) { - return this.read(tx, this.model, { - select: args.select, - omit: args.omit, - where: { - OR: createResult.map((item) => getIdValues(this.schema, this.model, item) as any), + return this.read( + tx, + this.model, + { + select: args.select, + omit: args.omit, + where: { + OR: createResult.map((item) => getIdValues(this.schema, this.model, item) as any), + }, } as any, // TODO: fix type - }); + ); } else { return createResult; } diff --git a/packages/orm/src/client/crud/operations/update.ts b/packages/orm/src/client/crud/operations/update.ts index 9c81d169..805eb2a8 100644 --- a/packages/orm/src/client/crud/operations/update.ts +++ b/packages/orm/src/client/crud/operations/update.ts @@ -104,13 +104,17 @@ export class UpdateOperationHandler extends BaseOperat ); if (needReadBack) { - const readBackResult = await this.read(tx, this.model, { - select: args.select, - omit: args.omit, - where: { - OR: updateResult.map((item) => getIdValues(this.schema, this.model, item) as any), + const readBackResult = await this.read( + tx, + this.model, + { + select: args.select, + omit: args.omit, + where: { + OR: updateResult.map((item) => getIdValues(this.schema, this.model, item) as any), + }, } as any, // TODO: fix type - }); + ); return { readBackResult, updateResult }; } else { From a13ec7c7526750a529feeedcc13ab89d002ecf8f Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:32:54 -0800 Subject: [PATCH 4/4] update --- .../orm/src/client/crud/validator/index.ts | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/orm/src/client/crud/validator/index.ts b/packages/orm/src/client/crud/validator/index.ts index d6ed8555..4be44346 100644 --- a/packages/orm/src/client/crud/validator/index.ts +++ b/packages/orm/src/client/crud/validator/index.ts @@ -745,9 +745,18 @@ export class InputValidator { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(), } : {}), - select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(), - include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(), - omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(), + select: z + .lazy(() => this.makeSelectSchema(fieldDef.type)) + .optional() + .nullable(), + include: z + .lazy(() => this.makeIncludeSchema(fieldDef.type)) + .optional() + .nullable(), + omit: z + .lazy(() => this.makeOmitSchema(fieldDef.type)) + .optional() + .nullable(), ...(fieldDef.array ? { // to-many relations can be ordered, skipped, taken, and cursor-located @@ -864,9 +873,9 @@ export class InputValidator { const dataSchema = this.makeCreateDataSchema(model, false); let schema: ZodType = z.strictObject({ data: dataSchema, - select: this.makeSelectSchema(model).optional(), - include: this.makeIncludeSchema(model).optional(), - omit: this.makeOmitSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + include: this.makeIncludeSchema(model).optional().nullable(), + omit: this.makeOmitSchema(model).optional().nullable(), }); schema = this.refineForSelectIncludeMutuallyExclusive(schema); schema = this.refineForSelectOmitMutuallyExclusive(schema); @@ -880,8 +889,8 @@ export class InputValidator { private makeCreateManyAndReturnSchema(model: string) { const base = this.makeCreateManyDataSchema(model, []); const result = base.extend({ - select: this.makeSelectSchema(model).optional(), - omit: this.makeOmitSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + omit: this.makeOmitSchema(model).optional().nullable(), }); return this.refineForSelectOmitMutuallyExclusive(result).optional(); } @@ -1142,9 +1151,9 @@ export class InputValidator { let schema: ZodType = z.strictObject({ where: this.makeWhereSchema(model, true), data: this.makeUpdateDataSchema(model), - select: this.makeSelectSchema(model).optional(), - include: this.makeIncludeSchema(model).optional(), - omit: this.makeOmitSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + include: this.makeIncludeSchema(model).optional().nullable(), + omit: this.makeOmitSchema(model).optional().nullable(), }); schema = this.refineForSelectIncludeMutuallyExclusive(schema); schema = this.refineForSelectOmitMutuallyExclusive(schema); @@ -1162,8 +1171,8 @@ export class InputValidator { private makeUpdateManyAndReturnSchema(model: string) { const base = this.makeUpdateManySchema(model); let schema: ZodType = base.extend({ - select: this.makeSelectSchema(model).optional(), - omit: this.makeOmitSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + omit: this.makeOmitSchema(model).optional().nullable(), }); schema = this.refineForSelectOmitMutuallyExclusive(schema); return schema; @@ -1174,9 +1183,9 @@ export class InputValidator { where: this.makeWhereSchema(model, true), create: this.makeCreateDataSchema(model, false), update: this.makeUpdateDataSchema(model), - select: this.makeSelectSchema(model).optional(), - include: this.makeIncludeSchema(model).optional(), - omit: this.makeOmitSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + include: this.makeIncludeSchema(model).optional().nullable(), + omit: this.makeOmitSchema(model).optional().nullable(), }); schema = this.refineForSelectIncludeMutuallyExclusive(schema); schema = this.refineForSelectOmitMutuallyExclusive(schema); @@ -1291,8 +1300,8 @@ export class InputValidator { private makeDeleteSchema(model: GetModels) { let schema: ZodType = z.strictObject({ where: this.makeWhereSchema(model, true), - select: this.makeSelectSchema(model).optional(), - include: this.makeIncludeSchema(model).optional(), + select: this.makeSelectSchema(model).optional().nullable(), + include: this.makeIncludeSchema(model).optional().nullable(), }); schema = this.refineForSelectIncludeMutuallyExclusive(schema); schema = this.refineForSelectOmitMutuallyExclusive(schema);