pqb 0.2.7 → 0.2.9

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.d.ts CHANGED
@@ -751,19 +751,19 @@ declare type UpdateBelongsToData<T extends Query, Rel extends BelongsToRelation>
751
751
  update: UpdateData<Rel['model']>;
752
752
  } | {
753
753
  create: InsertData<Rel['nestedCreateQuery']>;
754
- } | (T['returnType'] extends 'one' | 'oneOrThrow' ? {
754
+ } | (T['returnType'] extends 'all' ? never : {
755
755
  upsert: {
756
756
  update: UpdateData<Rel['model']>;
757
757
  create: InsertData<Rel['nestedCreateQuery']>;
758
758
  };
759
- } : never);
759
+ });
760
760
  declare type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> = {
761
761
  disconnect: boolean;
762
762
  } | {
763
763
  delete: boolean;
764
764
  } | {
765
765
  update: UpdateData<Rel['model']>;
766
- } | (T['returnType'] extends 'one' | 'oneOrThrow' ? {
766
+ } | (T['returnType'] extends 'all' ? never : {
767
767
  set: WhereArg<Rel['model']>;
768
768
  } | {
769
769
  upsert: {
@@ -772,7 +772,7 @@ declare type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> = {
772
772
  };
773
773
  } | {
774
774
  create: InsertData<Rel['nestedCreateQuery']>;
775
- } : never);
775
+ });
776
776
  declare type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
777
777
  disconnect?: MaybeArray<WhereArg<Rel['model']>>;
778
778
  delete?: MaybeArray<WhereArg<Rel['model']>>;
@@ -780,10 +780,10 @@ declare type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
780
780
  where: MaybeArray<WhereArg<Rel['model']>>;
781
781
  data: UpdateData<Rel['model']>;
782
782
  };
783
- } & (T['returnType'] extends 'one' | 'oneOrThrow' ? {
783
+ } & (T['returnType'] extends 'all' ? EmptyObject : {
784
784
  set?: MaybeArray<WhereArg<Rel['model']>>;
785
785
  create?: InsertData<Rel['nestedCreateQuery']>[];
786
- } : EmptyObject);
786
+ });
787
787
  declare type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
788
788
  disconnect?: MaybeArray<WhereArg<Rel['model']>>;
789
789
  set?: MaybeArray<WhereArg<Rel['model']>>;
package/dist/index.esm.js CHANGED
@@ -3248,10 +3248,10 @@ class QueryGet {
3248
3248
 
3249
3249
  const queryMethodByReturnType = {
3250
3250
  all: "query",
3251
- one: "query",
3252
- oneOrThrow: "query",
3253
3251
  rows: "arrays",
3254
3252
  pluck: "arrays",
3253
+ one: "query",
3254
+ oneOrThrow: "query",
3255
3255
  value: "arrays",
3256
3256
  valueOrThrow: "arrays",
3257
3257
  rowCount: "arrays",
@@ -4553,6 +4553,10 @@ const applyCountChange = (self, op, data) => {
4553
4553
  pushQueryValue(self, "data", map);
4554
4554
  return self;
4555
4555
  };
4556
+ const checkIfUpdateIsEmpty = (q) => {
4557
+ var _a;
4558
+ return !((_a = q.data) == null ? void 0 : _a.some((item) => isRaw(item) || Object.keys(item).length));
4559
+ };
4556
4560
  class Update {
4557
4561
  update(...args) {
4558
4562
  const q = this.clone();
@@ -4571,11 +4575,12 @@ class Update {
4571
4575
  if (isRaw(data)) {
4572
4576
  pushQueryValue(this, "data", data);
4573
4577
  } else {
4578
+ const update = __spreadValues$2({}, data);
4579
+ pushQueryValue(this, "data", update);
4574
4580
  const relations = this.relations;
4575
4581
  const prependRelations = {};
4576
4582
  const appendRelations = {};
4577
4583
  const originalReturnType = this.query.returnType;
4578
- const update = __spreadValues$2({}, data);
4579
4584
  for (const key in data) {
4580
4585
  if (relations[key]) {
4581
4586
  delete update[key];
@@ -4594,15 +4599,14 @@ class Update {
4594
4599
  }
4595
4600
  const state = {};
4596
4601
  const prependRelationKeys = Object.keys(prependRelations);
4602
+ let willSetKeys = false;
4597
4603
  if (prependRelationKeys.length) {
4598
- const willSetKeys = prependRelationKeys.some((relationName) => {
4604
+ willSetKeys = prependRelationKeys.some((relationName) => {
4599
4605
  const data2 = prependRelations[relationName];
4600
4606
  return relations[relationName].nestedUpdate(this, update, data2, state);
4601
4607
  });
4602
- if (!willSetKeys && !Object.keys(update).length) {
4603
- delete this.query.type;
4604
- }
4605
- } else if (!Object.keys(update).length) {
4608
+ }
4609
+ if (!willSetKeys && checkIfUpdateIsEmpty(this.query)) {
4606
4610
  delete this.query.type;
4607
4611
  }
4608
4612
  const appendRelationKeys = Object.keys(appendRelations);
@@ -4657,7 +4661,6 @@ class Update {
4657
4661
  if (prependRelationKeys.length || appendRelationKeys.length) {
4658
4662
  query.wrapInTransaction = true;
4659
4663
  }
4660
- pushQueryValue(this, "data", update);
4661
4664
  }
4662
4665
  if (!query.select) {
4663
4666
  this.query.returnType = "rowCount";