@zenstackhq/runtime 3.0.0-beta.1 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4295,9 +4295,17 @@ var FindOperationHandler = class extends BaseOperationHandler {
4295
4295
  }
4296
4296
  async handle(operation, args, validateArgs = true) {
4297
4297
  const normalizedArgs = this.normalizeArgs(args);
4298
- const parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, operation === "findUnique", normalizedArgs) : normalizedArgs;
4298
+ const findOne = operation === "findFirst" || operation === "findUnique";
4299
+ let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, {
4300
+ unique: operation === "findUnique",
4301
+ findOne
4302
+ }) : normalizedArgs;
4303
+ if (findOne) {
4304
+ parsedArgs = parsedArgs ?? {};
4305
+ parsedArgs.take = 1;
4306
+ }
4299
4307
  const result = await this.read(this.client.$qb, this.model, parsedArgs);
4300
- const finalResult = operation === "findMany" ? result : result[0] ?? null;
4308
+ const finalResult = findOne ? result[0] ?? null : result;
4301
4309
  return finalResult;
4302
4310
  }
4303
4311
  };
@@ -4503,10 +4511,8 @@ var InputValidator = class {
4503
4511
  constructor(schema) {
4504
4512
  this.schema = schema;
4505
4513
  }
4506
- validateFindArgs(model, unique, args) {
4507
- return this.validate(model, "find", {
4508
- unique
4509
- }, (model2, options) => this.makeFindSchema(model2, options), args);
4514
+ validateFindArgs(model, args, options) {
4515
+ return this.validate(model, "find", options, (model2, options2) => this.makeFindSchema(model2, options2), args);
4510
4516
  }
4511
4517
  validateCreateArgs(model, args) {
4512
4518
  return this.validate(model, "create", void 0, (model2) => this.makeCreateSchema(model2), args);
@@ -4575,7 +4581,11 @@ var InputValidator = class {
4575
4581
  fields["omit"] = this.makeOmitSchema(model).optional();
4576
4582
  if (!options.unique) {
4577
4583
  fields["skip"] = this.makeSkipSchema().optional();
4578
- fields["take"] = this.makeTakeSchema().optional();
4584
+ if (options.findOne) {
4585
+ fields["take"] = z.literal(1).optional();
4586
+ } else {
4587
+ fields["take"] = this.makeTakeSchema().optional();
4588
+ }
4579
4589
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
4580
4590
  fields["cursor"] = this.makeCursorSchema(model).optional();
4581
4591
  fields["distinct"] = this.makeDistinctSchema(model).optional();