@zenstackhq/runtime 3.0.0-alpha.10 → 3.0.0-alpha.12

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.cjs CHANGED
@@ -2564,13 +2564,13 @@ var BaseOperationHandler = class {
2564
2564
  inMemoryDistinct = distinct;
2565
2565
  }
2566
2566
  }
2567
- if (args?.select) {
2568
- query = this.buildFieldSelection(model, query, args?.select, model);
2567
+ if (args && "select" in args && args.select) {
2568
+ query = this.buildFieldSelection(model, query, args.select, model);
2569
2569
  } else {
2570
2570
  query = this.buildSelectAllScalarFields(model, query, args?.omit);
2571
2571
  }
2572
- if (args?.include) {
2573
- query = this.buildFieldSelection(model, query, args?.include, model);
2572
+ if (args && "include" in args && args.include) {
2573
+ query = this.buildFieldSelection(model, query, args.include, model);
2574
2574
  }
2575
2575
  if (args?.cursor) {
2576
2576
  query = this.buildCursorFilter(model, query, args.cursor, args.orderBy, negateOrderBy);
@@ -3577,7 +3577,7 @@ ${parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
3577
3577
  }, {});
3578
3578
  }
3579
3579
  trimResult(data, args) {
3580
- if (!args.select) {
3580
+ if (!("select" in args) || !args.select) {
3581
3581
  return data;
3582
3582
  }
3583
3583
  return Object.keys(args.select).reduce((acc, field) => {
@@ -3587,9 +3587,9 @@ ${parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
3587
3587
  }
3588
3588
  needReturnRelations(model, args) {
3589
3589
  let returnRelation = false;
3590
- if (args.include) {
3590
+ if ("include" in args && args.include) {
3591
3591
  returnRelation = Object.keys(args.include).length > 0;
3592
- } else if (args.select) {
3592
+ } else if ("select" in args && args.select) {
3593
3593
  returnRelation = Object.entries(args.select).some(([K, v]) => {
3594
3594
  const fieldDef = this.requireField(model, K);
3595
3595
  return fieldDef.relation && v;
@@ -3858,8 +3858,8 @@ var FindOperationHandler = class extends BaseOperationHandler {
3858
3858
  __name(this, "FindOperationHandler");
3859
3859
  }
3860
3860
  async handle(operation, args, validateArgs = true) {
3861
- const normalizeArgs = this.normalizeArgs(args);
3862
- const parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, operation === "findUnique", normalizeArgs) : normalizeArgs;
3861
+ const normalizedArgs = this.normalizeArgs(args);
3862
+ const parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, operation === "findUnique", normalizedArgs) : normalizedArgs;
3863
3863
  const result = await this.read(this.client.$qb, this.model, parsedArgs);
3864
3864
  const finalResult = operation === "findMany" ? result : result[0] ?? null;
3865
3865
  return finalResult;
@@ -4670,8 +4670,8 @@ var InputValidator = class {
4670
4670
  return this.refineForSelectIncludeMutuallyExclusive(schema);
4671
4671
  }
4672
4672
  makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
4673
- const regularAndFkFields = {};
4674
- const regularAndRelationFields = {};
4673
+ const uncheckedVariantFields = {};
4674
+ const checkedVariantFields = {};
4675
4675
  const modelDef = requireModel(this.schema, model);
4676
4676
  const hasRelation = Object.entries(modelDef.fields).some(([key, value]) => value.relation && !withoutFields.includes(key));
4677
4677
  Object.keys(modelDef.fields).forEach((field) => {
@@ -4696,7 +4696,10 @@ var InputValidator = class {
4696
4696
  if (fieldDef.optional && !fieldDef.array) {
4697
4697
  fieldSchema = fieldSchema.nullable();
4698
4698
  }
4699
- regularAndRelationFields[field] = fieldSchema;
4699
+ checkedVariantFields[field] = fieldSchema;
4700
+ if (fieldDef.array || !fieldDef.relation.references) {
4701
+ uncheckedVariantFields[field] = fieldSchema;
4702
+ }
4700
4703
  } else {
4701
4704
  let fieldSchema = this.makePrimitiveSchema(fieldDef.type).optional();
4702
4705
  if (this.isNumericField(fieldDef)) {
@@ -4723,18 +4726,18 @@ var InputValidator = class {
4723
4726
  if (fieldDef.optional) {
4724
4727
  fieldSchema = fieldSchema.nullable();
4725
4728
  }
4726
- regularAndFkFields[field] = fieldSchema;
4729
+ uncheckedVariantFields[field] = fieldSchema;
4727
4730
  if (!fieldDef.foreignKeyFor) {
4728
- regularAndRelationFields[field] = fieldSchema;
4731
+ checkedVariantFields[field] = fieldSchema;
4729
4732
  }
4730
4733
  }
4731
4734
  });
4732
4735
  if (!hasRelation) {
4733
- return import_zod.z.object(regularAndFkFields).strict();
4736
+ return import_zod.z.object(uncheckedVariantFields).strict();
4734
4737
  } else {
4735
4738
  return import_zod.z.union([
4736
- import_zod.z.object(regularAndFkFields).strict(),
4737
- import_zod.z.object(regularAndRelationFields).strict()
4739
+ import_zod.z.object(uncheckedVariantFields).strict(),
4740
+ import_zod.z.object(checkedVariantFields).strict()
4738
4741
  ]);
4739
4742
  }
4740
4743
  }