(model: string, operation: CoreCrudOperations, options?: CreateSchemaOptions)
| 308 | |
| 309 | @cache() |
| 310 | private makeFindSchema(model: string, operation: CoreCrudOperations, options?: CreateSchemaOptions) { |
| 311 | const fields: Record<string, z.ZodSchema> = {}; |
| 312 | const unique = operation === 'findUnique'; |
| 313 | const findOne = operation === 'findUnique' || operation === 'findFirst'; |
| 314 | const where = this.makeWhereSchema(model, unique, false, false, options); |
| 315 | if (unique) { |
| 316 | fields['where'] = where; |
| 317 | } else { |
| 318 | fields['where'] = where.optional(); |
| 319 | } |
| 320 | |
| 321 | fields['select'] = this.makeSelectSchema(model, options).optional().nullable(); |
| 322 | fields['include'] = this.makeIncludeSchema(model, options).optional().nullable(); |
| 323 | fields['omit'] = this.makeOmitSchema(model).optional().nullable(); |
| 324 | |
| 325 | if (!unique) { |
| 326 | fields['skip'] = this.makeSkipSchema().optional(); |
| 327 | if (findOne) { |
| 328 | fields['take'] = z.literal(1).optional(); |
| 329 | } else { |
| 330 | fields['take'] = this.makeTakeSchema().optional(); |
| 331 | } |
| 332 | fields['orderBy'] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional(); |
| 333 | fields['cursor'] = this.makeCursorSchema(model, options).optional(); |
| 334 | fields['distinct'] = this.makeDistinctSchema(model).optional(); |
| 335 | } |
| 336 | |
| 337 | const baseSchema = z.strictObject(fields); |
| 338 | let result: ZodType = this.mergePluginArgsSchema(baseSchema, operation); |
| 339 | result = this.refineForSelectIncludeMutuallyExclusive(result); |
| 340 | result = this.refineForSelectOmitMutuallyExclusive(result); |
| 341 | result = this.refineForSelectHasTruthyField(result); |
| 342 | |
| 343 | if (!unique) { |
| 344 | result = result.optional(); |
| 345 | } |
| 346 | this.registerSchema(`${model}${upperCaseFirst(operation)}Args`, result); |
| 347 | return result; |
| 348 | } |
| 349 | |
| 350 | @cache() |
| 351 | makeExistsSchema<Model extends GetModels<Schema>>( |
no test coverage detected