diff --git a/packages/orm/src/client/crud-types.ts b/packages/orm/src/client/crud-types.ts index 0a46b999..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; }; @@ -698,10 +703,7 @@ export type CreateArgs< > = SimplifyIf< { data: CreateInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -716,10 +718,7 @@ export type CreateManyAndReturnArgs< Model extends GetModels, Simplify extends boolean = false, > = SimplifyIf< - CreateManyInput & { - select?: SelectInput; - omit?: OmitInput; - }, + CreateManyInput & Omit, 'include'>, Simplify >; @@ -855,10 +854,7 @@ export type UpdateArgs< { data: UpdateInput; where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -873,10 +869,7 @@ export type UpdateManyAndReturnArgs< Model extends GetModels, Simplify extends boolean = false, > = SimplifyIf< - UpdateManyPayload & { - select?: SelectInput; - omit?: OmitInput; - }, + UpdateManyPayload & Omit, 'include'>, Simplify >; @@ -895,10 +888,7 @@ export type UpsertArgs< create: CreateInput; update: UpdateInput; where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; @@ -1019,10 +1009,7 @@ export type DeleteArgs< > = SimplifyIf< { where: WhereUniqueInput; - select?: SelectInput; - include?: IncludeInput; - omit?: OmitInput; - }, + } & SelectIncludeOmit, Simplify >; 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 { 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);