MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / makeFindSchema

Method makeFindSchema

packages/orm/src/client/zod/factory.ts:310–348  ·  view source on GitHub ↗
(model: string, operation: CoreCrudOperations, options?: CreateSchemaOptions)

Source from the content-addressed store, hash-verified

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

Callers 3

makeFindUniqueSchemaMethod · 0.95
makeFindFirstSchemaMethod · 0.95
makeFindManySchemaMethod · 0.95

Calls 15

makeWhereSchemaMethod · 0.95
makeSelectSchemaMethod · 0.95
makeIncludeSchemaMethod · 0.95
makeOmitSchemaMethod · 0.95
makeSkipSchemaMethod · 0.95
makeTakeSchemaMethod · 0.95
orArrayMethod · 0.95
makeOrderBySchemaMethod · 0.95
makeCursorSchemaMethod · 0.95
makeDistinctSchemaMethod · 0.95
mergePluginArgsSchemaMethod · 0.95

Tested by

no test coverage detected